Make the `all` method from test models return a `Relation`.

This commit is contained in:
Lauro Caetano 2014-04-02 11:31:48 -03:00
parent c17a9c0c0b
commit a87096cc22
2 changed files with 9 additions and 9 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 do |c|
f.association :company, collection: Company.all.to_a do |c|
calls += 1
end
end

View File

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