Commit bb5da52eddea74a3d6720243a98ee5fdd3d304bf
1 parent
ff2a47e2
Exists in
master
and in
29 other branches
Rails3: Fix ProfileCategorizationTest unit tests
Showing
3 changed files
with
23 additions
and
9 deletions
Show diff stats
app/models/category.rb
app/models/environment.rb
@@ -183,6 +183,8 @@ class Environment < ActiveRecord::Base | @@ -183,6 +183,8 @@ class Environment < ActiveRecord::Base | ||
183 | 183 | ||
184 | has_many :product_categories, :conditions => { :type => 'ProductCategory'} | 184 | has_many :product_categories, :conditions => { :type => 'ProductCategory'} |
185 | has_many :regions | 185 | has_many :regions |
186 | + has_many :states | ||
187 | + has_many :cities | ||
186 | 188 | ||
187 | has_many :roles | 189 | has_many :roles |
188 | 190 |
test/unit/profile_categorization_test.rb
@@ -13,8 +13,10 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | @@ -13,8 +13,10 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | ||
13 | end | 13 | end |
14 | 14 | ||
15 | should 'create instances for the entire hierarchy' do | 15 | should 'create instances for the entire hierarchy' do |
16 | - c1 = Category.create!(:name => 'c1', :environment => Environment.default) | ||
17 | - c2 = c1.children.create!(:name => 'c2', :environment => Environment.default) | 16 | + c1 = Environment.default.categories.create!(:name => 'c1') |
17 | + c2 = Environment.default.categories.create!(:name => 'c2').tap do |c| | ||
18 | + c.parent_id = c1.id | ||
19 | + end | ||
18 | 20 | ||
19 | p = create_user('testuser').person | 21 | p = create_user('testuser').person |
20 | 22 | ||
@@ -26,9 +28,13 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | @@ -26,9 +28,13 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | ||
26 | end | 28 | end |
27 | 29 | ||
28 | should 'not duplicate entry for category that is parent of two others' do | 30 | should 'not duplicate entry for category that is parent of two others' do |
29 | - c1 = Category.create!(:name => 'c1', :environment => Environment.default) | ||
30 | - c2 = c1.children.create!(:name => 'c2', :environment => Environment.default) | ||
31 | - c3 = c1.children.create!(:name => 'c3', :environment => Environment.default) | 31 | + c1 = Environment.default.categories.create!(:name => 'c1') |
32 | + c2 = Environment.default.categories.create!(:name => 'c2').tap do |c| | ||
33 | + c.parent_id = c1.id | ||
34 | + end | ||
35 | + c3 = Environment.default.categories.create!(:name => 'c3').tap do |c| | ||
36 | + c.parent_id = c1.id | ||
37 | + end | ||
32 | 38 | ||
33 | p = create_user('testuser').person | 39 | p = create_user('testuser').person |
34 | 40 | ||
@@ -39,9 +45,13 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | @@ -39,9 +45,13 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | ||
39 | end | 45 | end |
40 | 46 | ||
41 | should 'remove all instances for a given profile' do | 47 | should 'remove all instances for a given profile' do |
42 | - c1 = Category.create!(:name => 'c1', :environment => Environment.default) | ||
43 | - c2 = c1.children.create!(:name => 'c2', :environment => Environment.default) | ||
44 | - c3 = c1.children.create!(:name => 'c3', :environment => Environment.default) | 48 | + c1 = Environment.default.categories.create!(:name => 'c1') |
49 | + c2 = Environment.default.categories.create!(:name => 'c2').tap do |c| | ||
50 | + c.parent_id = c1.id | ||
51 | + end | ||
52 | + c3 = Environment.default.categories.create!(:name => 'c3').tap do |c| | ||
53 | + c.parent_id = c1.id | ||
54 | + end | ||
45 | 55 | ||
46 | p = create_user('testuser').person | 56 | p = create_user('testuser').person |
47 | 57 | ||
@@ -55,7 +65,7 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | @@ -55,7 +65,7 @@ class ProfileCategorizationTest < ActiveSupport::TestCase | ||
55 | 65 | ||
56 | [ Region, State, City ].each do |klass| | 66 | [ Region, State, City ].each do |klass| |
57 | should "be able to remove #{klass.name} from profile" do | 67 | should "be able to remove #{klass.name} from profile" do |
58 | - region = klass.create!(:name => 'my region', :environment => Environment.default) | 68 | + region = Environment.default.send(klass.name.underscore.pluralize).create!(:name => 'my region') |
59 | p = create_user('testuser').person | 69 | p = create_user('testuser').person |
60 | p.region = region | 70 | p.region = region |
61 | p.save! | 71 | p.save! |