Commit 4897e7c7e3b58418973978f1ff2be53334d4c201
1 parent
af5fb41d
Exists in
staging
and in
42 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,7 +4,7 @@ class License < ActiveRecord::Base | ||
4 | 4 | ||
5 | validates_presence_of :name, :environment | 5 | validates_presence_of :name, :environment |
6 | validates_presence_of :slug, :if => lambda {|license| license.name.present?} | 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 | before_validation do |license| | 9 | before_validation do |license| |
10 | license.slug ||= license.name.to_slug if license.name.present? | 10 | license.slug ||= license.name.to_slug if license.name.present? |
app/views/licenses/index.html.erb
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | <% @licenses.each do |license| %> | 8 | <% @licenses.each do |license| %> |
9 | <tr> | 9 | <tr> |
10 | <td title="<%= license.name%>"><%= truncate(license.name, 19) %></td> | 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 | <td style='white-space: nowrap;'> | 12 | <td style='white-space: nowrap;'> |
13 | <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> | 13 | <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> |
14 | <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :confirm => _('Are you sure you want to remove this license?') %></td> | 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 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | class LicenseTest < ActiveSupport::TestCase | 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 | license = License.new | 5 | license = License.new |
6 | license.valid? | 6 | license.valid? |
7 | assert license.errors.invalid?(:name) | 7 | assert license.errors.invalid?(:name) |
8 | - assert license.errors.invalid?(:slug) | ||
9 | assert license.errors.invalid?(:environment) | 8 | assert license.errors.invalid?(:environment) |
10 | 9 | ||
11 | license.name = 'GPLv3' | 10 | license.name = 'GPLv3' |
12 | - license.slug = 'gplv3' | ||
13 | license.environment = Environment.default | 11 | license.environment = Environment.default |
14 | license.valid? | 12 | license.valid? |
15 | assert !license.errors.invalid?(:name) | 13 | assert !license.errors.invalid?(:name) |
16 | - assert !license.errors.invalid?(:slug) | ||
17 | assert !license.errors.invalid?(:environment) | 14 | assert !license.errors.invalid?(:environment) |
18 | end | 15 | end |
19 | 16 | ||
@@ -28,5 +25,14 @@ class LicenseTest < ActiveSupport::TestCase | @@ -28,5 +25,14 @@ class LicenseTest < ActiveSupport::TestCase | ||
28 | license.valid? | 25 | license.valid? |
29 | assert_equal 'some-slug', license.slug | 26 | assert_equal 'some-slug', license.slug |
30 | end | 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 | end | 37 | end |
32 | 38 |