Make the `all` method from test models return a `Relation`.
This commit is contained in:
parent
c17a9c0c0b
commit
a87096cc22
|
@ -25,7 +25,7 @@ class AssociationTest < ActionView::TestCase
|
||||||
test 'builder association forwards collection to simple_fields_for' do
|
test 'builder association forwards collection to simple_fields_for' do
|
||||||
calls = 0
|
calls = 0
|
||||||
simple_form_for @user do |f|
|
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
|
calls += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,16 +7,16 @@ Column = Struct.new(:name, :type, :limit) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Relation = Struct.new(:all) do
|
Relation = Struct.new(:records) do
|
||||||
def where(conditions = nil)
|
def where(conditions = nil)
|
||||||
self.class.new conditions ? all.first : all
|
self.class.new conditions ? records.first : records
|
||||||
end
|
end
|
||||||
|
|
||||||
def order(conditions = nil)
|
def order(conditions = nil)
|
||||||
self.class.new conditions ? all.last : all
|
self.class.new conditions ? records.last : records
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :to_a, :all
|
alias_method :to_a, :records
|
||||||
end
|
end
|
||||||
|
|
||||||
Picture = Struct.new(:id, :name) do
|
Picture = Struct.new(:id, :name) do
|
||||||
|
@ -28,11 +28,11 @@ Picture = Struct.new(:id, :name) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._relation
|
def self._relation
|
||||||
Relation.new(all)
|
all
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
(1..3).map { |i| new(i, "#{name} #{i}") }
|
Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
|
||||||
end
|
end
|
||||||
|
|
||||||
def persisted?
|
def persisted?
|
||||||
|
@ -49,11 +49,11 @@ Company = Struct.new(:id, :name) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._relation
|
def self._relation
|
||||||
Relation.new(all)
|
all
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.all
|
def self.all
|
||||||
(1..3).map { |i| new(i, "#{name} #{i}") }
|
Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
|
||||||
end
|
end
|
||||||
|
|
||||||
def persisted?
|
def persisted?
|
||||||
|
|
Loading…
Reference in New Issue