Remove useless API.

This commit is contained in:
José Valim 2010-03-30 02:15:23 +02:00
parent 71fdf0620a
commit 5cb92a2480
5 changed files with 7 additions and 75 deletions

View File

@ -2,6 +2,7 @@
* bug fix
* fix some escaping issues
* removed :conditions, :order, :joins and :include support in f.association
== 1.1.0

View File

@ -160,16 +160,7 @@ Simple enough right? This is going to render a :select input for choosing the :c
f.association :company, :as => :radio
f.association :roles, :as => :check_boxes
And you will get a set of radios to select the company and another set of check boxes for the roles. Some options are available for refining the collection for associations: :conditions, :include, :joins, :order. These options are given straight to the find method. Here is an example of how to use these options:
f.association :company, :order => 'name'
f.association :roles, :conditions => { :active => true }
You also have the ability to call named scopes using the association:
f.association :company, :scope => [:active, :available]
The association helper just invokes input under the hood, so all options available to :select, :radio and :check_boxes are also available to association. For example, you can specify the collection by hand, all together with the prompt:
The association helper just invokes input under the hood, so all options available to :select, :radio and :check_boxes are also available to association. Additionally, you can specify the collection by hand, all together with the prompt:
f.association :company, :collection => Company.active.all(:order => 'name'), :prompt => "Choose a Company"
@ -235,8 +226,8 @@ SimpleForm comes with a lot of default mappings:
boolean check box boolean
string text field string
email email field string
url url field string
email email field string with name matching "email"
url url field string with name matching "url"
password password field string with name matching "password"
text text area text
file file field string, responding to file methods

View File

@ -1,6 +1,5 @@
== General
* HTML 5 support
* Pretty buttons
== Validations

View File

@ -96,36 +96,15 @@ module SimpleForm
# supported in input are also supported by association. Some extra options
# can also be given:
#
# == Options
#
# * :conditions - Given as conditions when retrieving the collection
#
# * :include - Given as include when retrieving the collection
#
# * :joins - Given as joins when retrieving the collection
#
# * :order - Given as order when retrieving the collection
#
# * :scope - Given as scopes when retrieving the collection
#
# == Examples
#
# simple_form_for @user do |f|
# f.association :company # Company.all
# end
#
# f.association :company, :order => 'name'
# # Company.all(:order => 'name')
#
# f.association :company, :conditions => { :active => true }
# # Company.all(:conditions => { :active => true })
#
# f.association :company, :collection => Company.all(:order => 'name')
# # Same as using :order option, but overriding collection
#
# f.association :company, :scope => [ :public, :not_broken ]
# # Same as doing Company.public.not_broken.all
#
# == Block
#
# When a block is given, association simple behaves as a proxy to
@ -163,15 +142,9 @@ module SimpleForm
end
end
options[:collection] ||= begin
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(finders)
end
options[:collection] ||= @reflection.klass.all(
:conditions => @reflection.options[:conditions], :order => @reflection.options[:order]
)
returning(input(attribute, options)) { @reflection = nil }
end

View File

@ -414,14 +414,6 @@ class FormBuilderTest < ActionView::TestCase
end
# ASSOCIATIONS - FINDERS
test 'builder should allow passing conditions to find collection' do
with_association_for @user, :company, :conditions => { :id => 1 }
assert_select 'form select.select#user_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 use reflection conditions to find collection' do
with_association_for @user, :special_company
assert_select 'form select.select#user_special_company_id'
@ -430,30 +422,6 @@ class FormBuilderTest < ActionView::TestCase
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'
assert_no_select 'form select option[value=1]'
assert_no_select 'form select option[value=2]'
assert_select 'form select option[value=3]'
end
test 'builder should allow passing include option to find collection' do
with_association_for @user, :company, :include => :city
assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=1]'
assert_select 'form select option[value=2]'
assert_no_select 'form select option[value=3]'
end
test 'builder should allow passing joins option to find collection' do
with_association_for @user, :company, :joins => :city
assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=2]'
assert_select 'form select option[value=3]'
assert_no_select 'form select option[value=1]'
end
test 'builder should allow overriding collection to association input' do
with_association_for @user, :company, :include_blank => false,
:collection => [Company.new(999, 'Teste')]