diff --git a/app/models/license.rb b/app/models/license.rb
index 7e59ce4..9b57d08 100644
--- a/app/models/license.rb
+++ b/app/models/license.rb
@@ -4,7 +4,7 @@ class License < ActiveRecord::Base
validates_presence_of :name, :environment
validates_presence_of :slug, :if => lambda {|license| license.name.present?}
- validates_uniqueness_of :slug
+ validates_uniqueness_of :slug, :scope => :environment_id
before_validation do |license|
license.slug ||= license.name.to_slug if license.name.present?
diff --git a/app/views/licenses/index.html.erb b/app/views/licenses/index.html.erb
index e6d1878..af50ba0 100644
--- a/app/views/licenses/index.html.erb
+++ b/app/views/licenses/index.html.erb
@@ -8,7 +8,7 @@
<% @licenses.each do |license| %>
<%= truncate(license.name, 19) %> |
- <%= link_to(truncate(license.url, 60), license.url, :target => '_blank') %> |
+ <%= license.url.present? ? link_to(truncate(license.url, 60), license.url, :target => '_blank') : '' %> |
<%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %>
<%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :confirm => _('Are you sure you want to remove this license?') %> |
diff --git a/test/unit/license_test.rb b/test/unit/license_test.rb
index c880424..8964a0d 100644
--- a/test/unit/license_test.rb
+++ b/test/unit/license_test.rb
@@ -1,19 +1,16 @@
require File.dirname(__FILE__) + '/../test_helper'
class LicenseTest < ActiveSupport::TestCase
- should 'validate presence of name, slug and enviornment' do
+ should 'validate presence of name and environment' do
license = License.new
license.valid?
assert license.errors.invalid?(:name)
- assert license.errors.invalid?(:slug)
assert license.errors.invalid?(:environment)
license.name = 'GPLv3'
- license.slug = 'gplv3'
license.environment = Environment.default
license.valid?
assert !license.errors.invalid?(:name)
- assert !license.errors.invalid?(:slug)
assert !license.errors.invalid?(:environment)
end
@@ -28,5 +25,14 @@ class LicenseTest < ActiveSupport::TestCase
license.valid?
assert_equal 'some-slug', license.slug
end
+
+ should 'allow equal slugs in different environments' do
+ e1 = fast_create(Environment)
+ e2 = fast_create(Environment)
+ License.create!(:name => 'License', :environment => e1)
+ license = License.new(:name => 'License', :environment => e2)
+
+ assert license.valid?
+ end
end
--
libgit2 0.21.2