Permalink
Browse files

Fix preload collection tests

:preload => false was being used twice making two tests have the same
implementation.

Also the test that was supposed to test :preload => false with a
collection was testing against a non-collection association.
  • Loading branch information...
carlosantoniodasilva committed Oct 26, 2012
1 parent c5f913c commit f3d7ba7c12a4970be89223aed63ecb71ed401c7c
Showing with 10 additions and 7 deletions.
  1. +10 −7 test/form_builder/association_test.rb
@@ -43,6 +43,7 @@ def with_association_for(object, *args)
test 'builder preloads collection association' do
value = @user.tags = Object.new
value.expects(:to_a).returns(value)
+
with_association_for @user, :tags
assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1'
@@ -51,19 +52,21 @@ def with_association_for(object, *args)
end
test 'builder does not preload collection association if preload is false' do
- value = @user.company = Object.new
+ value = @user.tags = Object.new
value.expects(:to_a).never
- with_association_for @user, :company, :preload => false
- assert_select 'form select.select#user_company_id'
- assert_select 'form select option[value=1]', 'Company 1'
- assert_select 'form select option[value=2]', 'Company 2'
- assert_select 'form select option[value=3]', 'Company 3'
+
+ with_association_for @user, :tags, :preload => false
+ assert_select 'form select.select#user_tag_ids'
+ assert_select 'form select option[value=1]', 'Tag 1'
+ assert_select 'form select option[value=2]', 'Tag 2'
+ assert_select 'form select option[value=3]', 'Tag 3'
end
test 'builder does not preload non-collection association' do
value = @user.company = Object.new
value.expects(:to_a).never
- with_association_for @user, :company, :preload => false
+
+ with_association_for @user, :company
assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=1]', 'Company 1'
assert_select 'form select option[value=2]', 'Company 2'

0 comments on commit f3d7ba7

Please sign in to comment.