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
test/unit/profile_categorization_test.rb
| ... | ... | @@ -13,8 +13,10 @@ class ProfileCategorizationTest < ActiveSupport::TestCase |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 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 | 21 | p = create_user('testuser').person |
| 20 | 22 | |
| ... | ... | @@ -26,9 +28,13 @@ class ProfileCategorizationTest < ActiveSupport::TestCase |
| 26 | 28 | end |
| 27 | 29 | |
| 28 | 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 | 39 | p = create_user('testuser').person |
| 34 | 40 | |
| ... | ... | @@ -39,9 +45,13 @@ class ProfileCategorizationTest < ActiveSupport::TestCase |
| 39 | 45 | end |
| 40 | 46 | |
| 41 | 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 | 56 | p = create_user('testuser').person |
| 47 | 57 | |
| ... | ... | @@ -55,7 +65,7 @@ class ProfileCategorizationTest < ActiveSupport::TestCase |
| 55 | 65 | |
| 56 | 66 | [ Region, State, City ].each do |klass| |
| 57 | 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 | 69 | p = create_user('testuser').person |
| 60 | 70 | p.region = region |
| 61 | 71 | p.save! | ... | ... |