From a87096cc2271ee11301142b87c4c4be5d9583529 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Wed, 2 Apr 2014 11:31:48 -0300 Subject: [PATCH] Make the `all` method from test models return a `Relation`. --- test/form_builder/association_test.rb | 2 +- test/support/models.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/form_builder/association_test.rb b/test/form_builder/association_test.rb index 35c400e2..9988add3 100644 --- a/test/form_builder/association_test.rb +++ b/test/form_builder/association_test.rb @@ -25,7 +25,7 @@ class AssociationTest < ActionView::TestCase test 'builder association forwards collection to simple_fields_for' do calls = 0 simple_form_for @user do |f| - f.association :company, collection: Company.all do |c| + f.association :company, collection: Company.all.to_a do |c| calls += 1 end end diff --git a/test/support/models.rb b/test/support/models.rb index 71eb4c3a..99e1c6d6 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -7,16 +7,16 @@ Column = Struct.new(:name, :type, :limit) do end end -Relation = Struct.new(:all) do +Relation = Struct.new(:records) do def where(conditions = nil) - self.class.new conditions ? all.first : all + self.class.new conditions ? records.first : records end def order(conditions = nil) - self.class.new conditions ? all.last : all + self.class.new conditions ? records.last : records end - alias_method :to_a, :all + alias_method :to_a, :records end Picture = Struct.new(:id, :name) do @@ -28,11 +28,11 @@ Picture = Struct.new(:id, :name) do end def self._relation - Relation.new(all) + all end def self.all - (1..3).map { |i| new(i, "#{name} #{i}") } + Relation.new((1..3).map { |i| new(i, "#{name} #{i}") }) end def persisted? @@ -49,11 +49,11 @@ Company = Struct.new(:id, :name) do end def self._relation - Relation.new(all) + all end def self.all - (1..3).map { |i| new(i, "#{name} #{i}") } + Relation.new((1..3).map { |i| new(i, "#{name} #{i}") }) end def persisted?