mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Rewrite hm:t#create tests using assert_no_difference and assert_difference
This commit is contained in:
parent
ad28e0037b
commit
d0f891ae02
1 changed files with 8 additions and 12 deletions
|
@ -180,27 +180,23 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_associate_with_create_and_invalid_options
|
||||
peeps = companies(:first_firm).developers.count
|
||||
assert_nothing_raised { companies(:first_firm).developers.create(:name => '0') }
|
||||
assert_equal peeps, companies(:first_firm).developers.count
|
||||
firm = companies(:first_firm)
|
||||
assert_no_difference('firm.developers.count') { assert_nothing_raised { firm.developers.create(:name => '0') } }
|
||||
end
|
||||
|
||||
def test_associate_with_create_and_valid_options
|
||||
peeps = companies(:first_firm).developers.count
|
||||
assert_nothing_raised { companies(:first_firm).developers.create(:name => 'developer') }
|
||||
assert_equal peeps + 1, companies(:first_firm).developers.count
|
||||
firm = companies(:first_firm)
|
||||
assert_difference('firm.developers.count', 1) { firm.developers.create(:name => 'developer') }
|
||||
end
|
||||
|
||||
def test_associate_with_create_bang_and_invalid_options
|
||||
peeps = companies(:first_firm).developers.count
|
||||
assert_raises(ActiveRecord::RecordInvalid) { companies(:first_firm).developers.create!(:name => '0') }
|
||||
assert_equal peeps, companies(:first_firm).developers.count
|
||||
firm = companies(:first_firm)
|
||||
assert_no_difference('firm.developers.count') { assert_raises(ActiveRecord::RecordInvalid) { firm.developers.create!(:name => '0') } }
|
||||
end
|
||||
|
||||
def test_associate_with_create_bang_and_valid_options
|
||||
peeps = companies(:first_firm).developers.count
|
||||
assert_nothing_raised { companies(:first_firm).developers.create!(:name => 'developer') }
|
||||
assert_equal peeps + 1, companies(:first_firm).developers.count
|
||||
firm = companies(:first_firm)
|
||||
assert_difference('firm.developers.count', 1) { firm.developers.create!(:name => 'developer') }
|
||||
end
|
||||
|
||||
def test_clear_associations
|
||||
|
|
Loading…
Reference in a new issue