Commit 4897e7c7e3b58418973978f1ff2be53334d4c201
1 parent
af5fb41d
Exists in
master
and in
29 other branches
[licenses] Minor fixes
(ActionItem2379)
Showing
3 changed files
with
12 additions
and
6 deletions
Show diff stats
app/models/license.rb
... | ... | @@ -4,7 +4,7 @@ class License < ActiveRecord::Base |
4 | 4 | |
5 | 5 | validates_presence_of :name, :environment |
6 | 6 | validates_presence_of :slug, :if => lambda {|license| license.name.present?} |
7 | - validates_uniqueness_of :slug | |
7 | + validates_uniqueness_of :slug, :scope => :environment_id | |
8 | 8 | |
9 | 9 | before_validation do |license| |
10 | 10 | license.slug ||= license.name.to_slug if license.name.present? | ... | ... |
app/views/licenses/index.html.erb
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | <% @licenses.each do |license| %> |
9 | 9 | <tr> |
10 | 10 | <td title="<%= license.name%>"><%= truncate(license.name, 19) %></td> |
11 | - <td title="<%= license.url %>"><%= link_to(truncate(license.url, 60), license.url, :target => '_blank') %></td> | |
11 | + <td title="<%= license.url %>"><%= license.url.present? ? link_to(truncate(license.url, 60), license.url, :target => '_blank') : '' %></td> | |
12 | 12 | <td style='white-space: nowrap;'> |
13 | 13 | <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> |
14 | 14 | <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :confirm => _('Are you sure you want to remove this license?') %></td> | ... | ... |
test/unit/license_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class LicenseTest < ActiveSupport::TestCase |
4 | - should 'validate presence of name, slug and enviornment' do | |
4 | + should 'validate presence of name and environment' do | |
5 | 5 | license = License.new |
6 | 6 | license.valid? |
7 | 7 | assert license.errors.invalid?(:name) |
8 | - assert license.errors.invalid?(:slug) | |
9 | 8 | assert license.errors.invalid?(:environment) |
10 | 9 | |
11 | 10 | license.name = 'GPLv3' |
12 | - license.slug = 'gplv3' | |
13 | 11 | license.environment = Environment.default |
14 | 12 | license.valid? |
15 | 13 | assert !license.errors.invalid?(:name) |
16 | - assert !license.errors.invalid?(:slug) | |
17 | 14 | assert !license.errors.invalid?(:environment) |
18 | 15 | end |
19 | 16 | |
... | ... | @@ -28,5 +25,14 @@ class LicenseTest < ActiveSupport::TestCase |
28 | 25 | license.valid? |
29 | 26 | assert_equal 'some-slug', license.slug |
30 | 27 | end |
28 | + | |
29 | + should 'allow equal slugs in different environments' do | |
30 | + e1 = fast_create(Environment) | |
31 | + e2 = fast_create(Environment) | |
32 | + License.create!(:name => 'License', :environment => e1) | |
33 | + license = License.new(:name => 'License', :environment => e2) | |
34 | + | |
35 | + assert license.valid? | |
36 | + end | |
31 | 37 | end |
32 | 38 | ... | ... |