Skip to content

Commit

Permalink
Adding legacy factories. Another high level test for string primary k…
Browse files Browse the repository at this point in the history
…ey quoting for delegated group association.
  • Loading branch information
metaskills committed Sep 24, 2008
1 parent ade289e commit ddae2db
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
19 changes: 18 additions & 1 deletion test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@
Factory.define :employee_with_reports, :class => 'Employee' do |e|
e.name { "Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
e.reports { |employee| [employee.association(:report),employee.association(:report)] }
e.reports { |employee| [employee.association(:report),employee.association(:report)] }
end


Factory.define :legacy_employee do |e|
e.name { "Legacy Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
end

Factory.define :legacy_report do |r|
r.title { Factory.next(:title) }
r.body 'Legacy bla bla. Legacy. Legacy bla.'
end

Factory.define :legacy_employee_with_reports, :class => 'LegacyEmployee' do |e|
e.name { "Legacy Factory Employee ##{Factory.next(:id)}" }
e.email { Factory.next(:email) }
e.reports { |employee| [employee.association(:legacy_report),employee.association(:legacy_report)] }
end


27 changes: 23 additions & 4 deletions test/grouped_scope/has_many_association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ def setup

context 'for an Employee' do

setup { @employee = Factory(:employee) }

should 'simply work' do
assert_instance_of Array, @employee.reports
setup do
@employee = Factory(:employee)
end

should 'scope existing association to owner' do
Expand All @@ -30,6 +28,27 @@ def setup

end

context 'for a LegacyEmployee' do

setup do
@employee = Factory(:legacy_employee)
end

should 'scope existing association to owner' do
assert_sql(/"legacy_reports".email = '#{@employee.id}'/) do
@employee.reports(true)
end
end

should 'scope group association to group' do
assert_sql(/"legacy_reports".email IN \('#{@employee.id}'\)/) do
@employee.group.reports(true)
end
end

end


end


Expand Down

0 comments on commit ddae2db

Please sign in to comment.