From 60eba685804356f846eb70655c035ab8dba00375 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Wed, 2 Apr 2014 17:46:23 -0300 Subject: [PATCH] Make `Relation` respond to `to_ary` and `each`, to avoid calling `Model.all.to_a` in tests. --- test/form_builder/association_test.rb | 2 +- test/support/models.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/form_builder/association_test.rb b/test/form_builder/association_test.rb index 8df91e74..e62f970e 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.to_a do |c| + f.association :company, collection: Company.all do |c| calls += 1 end end diff --git a/test/support/models.rb b/test/support/models.rb index 70c57ce9..fa8eb481 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -8,6 +8,8 @@ Column = Struct.new(:name, :type, :limit) do end Relation = Struct.new(:records) do + delegate :each, to: :records + def where(conditions = nil) self.class.new conditions ? records.first : records end @@ -16,7 +18,8 @@ Relation = Struct.new(:records) do self.class.new conditions ? records.last : records end - alias_method :to_a, :records + alias_method :to_a, :records + alias_method :to_ary, :records end Picture = Struct.new(:id, :name) do