Add more items to the TODO list.
This commit is contained in:
parent
604aac88ce
commit
371c8cd2fd
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
* Sample CSS
|
* Sample CSS
|
||||||
* Add default size support
|
* Add default size support
|
||||||
|
* HTML 5 support
|
||||||
|
* Pretty buttons
|
||||||
|
|
||||||
== Validations
|
== Validations
|
||||||
|
|
||||||
|
|
|
@ -163,11 +163,13 @@ module SimpleForm
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:collection] ||= begin
|
options[:collection] ||= begin
|
||||||
find_options = options.slice(:conditions, :order, :include, :joins)
|
finders = options.slice(:conditions, :order, :include, :joins)
|
||||||
|
finders[:conditions] = @reflection.klass.merge_conditions(finders[:conditions],
|
||||||
|
@reflection.options[:conditions])
|
||||||
klass = Array(options[:scope]).inject(@reflection.klass) do |klass, scope|
|
klass = Array(options[:scope]).inject(@reflection.klass) do |klass, scope|
|
||||||
klass.send(scope)
|
klass.send(scope)
|
||||||
end
|
end
|
||||||
klass.all(find_options)
|
klass.all(finders)
|
||||||
end
|
end
|
||||||
|
|
||||||
returning(input(attribute, options)) { @reflection = nil }
|
returning(input(attribute, options)) { @reflection = nil }
|
||||||
|
|
|
@ -462,6 +462,14 @@ class FormBuilderTest < ActionView::TestCase
|
||||||
assert_no_select 'form select option[value=3]'
|
assert_no_select 'form select option[value=3]'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'builder should use reflection conditions to find collection' do
|
||||||
|
with_association_for @user, :special_company
|
||||||
|
assert_select 'form select.select#user_special_company_id'
|
||||||
|
assert_select 'form select option[value=1]'
|
||||||
|
assert_no_select 'form select option[value=2]'
|
||||||
|
assert_no_select 'form select option[value=3]'
|
||||||
|
end
|
||||||
|
|
||||||
test 'builder should allow passing order to find collection' do
|
test 'builder should allow passing order to find collection' do
|
||||||
with_association_for @user, :company, :order => 'name'
|
with_association_for @user, :company, :order => 'name'
|
||||||
assert_select 'form select.select#user_company_id'
|
assert_select 'form select.select#user_company_id'
|
||||||
|
|
|
@ -6,19 +6,23 @@ Association = Struct.new(:klass, :name, :macro, :options)
|
||||||
class Company < Struct.new(:id, :name)
|
class Company < Struct.new(:id, :name)
|
||||||
def self.all(options={})
|
def self.all(options={})
|
||||||
all = (1..3).map{|i| Company.new(i, "Company #{i}")}
|
all = (1..3).map{|i| Company.new(i, "Company #{i}")}
|
||||||
return [all.first] if options[:conditions]
|
return [all.first] if options[:conditions].present?
|
||||||
return [all.last] if options[:order]
|
return [all.last] if options[:order].present?
|
||||||
return all[0..1] if options[:include]
|
return all[0..1] if options[:include].present?
|
||||||
return all[1..2] if options[:joins]
|
return all[1..2] if options[:joins].present?
|
||||||
all
|
all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.merge_conditions(a, b)
|
||||||
|
(a || {}).merge(b || {})
|
||||||
|
end
|
||||||
|
|
||||||
def new_record?
|
def new_record?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Tag < Struct.new(:id, :name)
|
class Tag < Company
|
||||||
def self.all(options={})
|
def self.all(options={})
|
||||||
(1..3).map{|i| Tag.new(i, "Tag #{i}")}
|
(1..3).map{|i| Tag.new(i, "Tag #{i}")}
|
||||||
end
|
end
|
||||||
|
@ -79,6 +83,8 @@ class User < OpenStruct
|
||||||
Association.new(Tag, association, :has_many, {})
|
Association.new(Tag, association, :has_many, {})
|
||||||
when :first_company
|
when :first_company
|
||||||
Association.new(Company, association, :has_one, {})
|
Association.new(Company, association, :has_one, {})
|
||||||
|
when :special_company
|
||||||
|
Association.new(Company, association, :belongs_to, { :conditions => { :id => 1 } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue