Skip to content

Commit

Permalink
Yes! Fixed bug so that grouped_scope option on existing association i…
Browse files Browse the repository at this point in the history
…s not there.
  • Loading branch information
metaskills committed Sep 22, 2008
1 parent 882a208 commit 1dbcddb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/grouped_scope/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def grouped_scope(*args)
end
grouped_scopes[association] = true
grouped_assoc = grouped_scope_for(association)
has_many grouped_assoc, existing_assoc.options
has_many grouped_assoc, existing_assoc.options.dup
reflect_on_association(grouped_assoc).options[:grouped_scope] = true
end
include InstanceMethods
Expand Down
12 changes: 8 additions & 4 deletions test/grouped_scope/class_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ def setup
Employee.class_eval { has_many(:foobars) ; grouped_scope(:foobars) }
end

should 'create a has_many named :grouped_scope_* with orig association suffix' do
should 'create a has_many assoc named :grouped_scope_* using existing association as a suffix' do
grouped_reports_assoc = Employee.reflect_on_association(:grouped_scope_reports)
assert_instance_of ActiveRecord::Reflection::AssociationReflection, grouped_reports_assoc
end

should 'mirror existing options for has_many association' do
should 'not add the :grouped_scope option to existing reflection' do
assert_nil Employee.reflect_on_association(:reports).options[:grouped_scope]
end

should 'mirror existing options for has_many association, minus :grouped_scope option' do
reports_assoc = Employee.reflect_on_association(:reports)
grouped_reports_assoc = Employee.reflect_on_association(:grouped_scope_reports)
assert_equal reports_assoc.options, grouped_reports_assoc.options
assert_equal({:grouped_scope=>true}, grouped_reports_assoc.options.diff(reports_assoc.options))
reports_assoc = LegacyEmployee.reflect_on_association(:reports)
grouped_reports_assoc = LegacyEmployee.reflect_on_association(:grouped_scope_reports)
assert_equal reports_assoc.options, grouped_reports_assoc.options
assert_equal({:grouped_scope=>true}, grouped_reports_assoc.options.diff(reports_assoc.options))
end

end
Expand Down

0 comments on commit 1dbcddb

Please sign in to comment.