1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Make Relation respond to to_ary and each, to avoid calling

`Model.all.to_a` in tests.
This commit is contained in:
Lauro Caetano 2014-04-02 17:46:23 -03:00
parent ab0750628b
commit 60eba68580
2 changed files with 5 additions and 2 deletions

View file

@ -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

View file

@ -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