Skip to content

Commit

Permalink
Testing association extensions can work in front/behind group reflect…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
metaskills committed Sep 24, 2008
1 parent bf5ae5f commit d70de93
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions test/grouped_scope/has_many_association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ def setup
end
end

context 'calling association extensions' do

setup do
@e1 = Factory(:employee_with_reports, :group_id => 1)
@e2 = Factory(:employee, :group_id => 1)
@urget_report = Factory.build(:report, :title => 'URGET')
@e1.reports << @urget_report
@e1.save!
end

should 'find urget report via normal ungrouped association' do
assert_equal [@urget_report], @e1.reports(true).urget
end

should 'find urget report via grouped reflection' do
assert_equal [@urget_report], @e2.group.reports.urget
end

should 'use extension sql along with group reflection' do
assert_sql(/'URGET'/,/"reports".employee_id IN/) do
@e2.group.reports.urget
end
end

end

end

context 'for a LegacyEmployee' do
Expand Down
6 changes: 5 additions & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def setup_database(options)
end

class Employee < ActiveRecord::Base
has_many :reports
has_many :reports do
def urget
all(:conditions => {:title => 'URGET'})
end
end
grouped_scope :reports
end

Expand Down

0 comments on commit d70de93

Please sign in to comment.