From 5cb92a248030387df8689bbce56d044e985800da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 30 Mar 2010 02:15:23 +0200 Subject: [PATCH] Remove useless API. --- CHANGELOG.rdoc | 1 + README.rdoc | 15 +++------------ TODO.rdoc | 1 - lib/simple_form/form_builder.rb | 33 +++------------------------------ test/form_builder_test.rb | 32 -------------------------------- 5 files changed, 7 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index e4b8c7c8..92f396f2 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -2,6 +2,7 @@ * bug fix * fix some escaping issues + * removed :conditions, :order, :joins and :include support in f.association == 1.1.0 diff --git a/README.rdoc b/README.rdoc index 4bcd7858..dcf40518 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 diff --git a/TODO.rdoc b/TODO.rdoc index 93b19903..a60fb9a1 100644 --- a/TODO.rdoc +++ b/TODO.rdoc @@ -1,6 +1,5 @@ == General -* HTML 5 support * Pretty buttons == Validations diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 890824a9..38315332 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -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 diff --git a/test/form_builder_test.rb b/test/form_builder_test.rb index 2e47cc01..a8700881 100644 --- a/test/form_builder_test.rb +++ b/test/form_builder_test.rb @@ -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')]