Add more items to the TODO list.

This commit is contained in:
José Valim 2010-01-10 11:02:15 +01:00
parent 604aac88ce
commit 371c8cd2fd
4 changed files with 25 additions and 7 deletions

View File

@ -2,6 +2,8 @@
* Sample CSS
* Add default size support
* HTML 5 support
* Pretty buttons
== Validations

View File

@ -163,11 +163,13 @@ module SimpleForm
end
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.send(scope)
end
klass.all(find_options)
klass.all(finders)
end
returning(input(attribute, options)) { @reflection = nil }

View File

@ -462,6 +462,14 @@ class FormBuilderTest < ActionView::TestCase
assert_no_select 'form select option[value=3]'
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
with_association_for @user, :company, :order => 'name'
assert_select 'form select.select#user_company_id'

View File

@ -6,19 +6,23 @@ Association = Struct.new(:klass, :name, :macro, :options)
class Company < Struct.new(:id, :name)
def self.all(options={})
all = (1..3).map{|i| Company.new(i, "Company #{i}")}
return [all.first] if options[:conditions]
return [all.last] if options[:order]
return all[0..1] if options[:include]
return all[1..2] if options[:joins]
return [all.first] if options[:conditions].present?
return [all.last] if options[:order].present?
return all[0..1] if options[:include].present?
return all[1..2] if options[:joins].present?
all
end
def self.merge_conditions(a, b)
(a || {}).merge(b || {})
end
def new_record?
false
end
end
class Tag < Struct.new(:id, :name)
class Tag < Company
def self.all(options={})
(1..3).map{|i| Tag.new(i, "Tag #{i}")}
end
@ -79,6 +83,8 @@ class User < OpenStruct
Association.new(Tag, association, :has_many, {})
when :first_company
Association.new(Company, association, :has_one, {})
when :special_company
Association.new(Company, association, :belongs_to, { :conditions => { :id => 1 } })
end
end