Skip to content

Commit

Permalink
remove deprecated :group_by and :group_label options
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Jul 11, 2013
1 parent b621eed commit 08c6244
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 191 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
master

* Removed deprecated `:hint_class` option
* Removed deprecated :group_by and :group_label options
* Removed deprecated `:error_class` option

2.3.0.rc2

Expand Down
3 changes: 0 additions & 3 deletions lib/formtastic/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def initialize(builder, template, object, object_name, method, options)

warn_deprecated_option!(:value, ":input_html => { :value => '...'}")
warn_deprecated_option!(:error_class, "default_error_class configuration")
warn_deprecated_option!(:group_by, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
warn_deprecated_option!(:group_label, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
warn_deprecated_option!(:find_options, "YourModel.find(...)")
end

Expand Down Expand Up @@ -48,7 +46,6 @@ def removed_option!(old_option_name)
autoload :Database
autoload :Errors
autoload :Fileish
autoload :GroupedCollections
autoload :Hints
autoload :Html
autoload :Labelling
Expand Down
2 changes: 0 additions & 2 deletions lib/formtastic/inputs/base/collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ def collection_from_association
else

if Util.rails3?
find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
reflection.klass.scoped(scope_conditions).where(find_options_from_options)
else
coll = reflection.klass.where(scope_conditions)
coll = coll.includes(group_by) if self.respond_to?(:group_by) && group_by
coll.where(find_options_from_options)
end
end
Expand Down
77 changes: 0 additions & 77 deletions lib/formtastic/inputs/base/grouped_collections.rb

This file was deleted.

16 changes: 1 addition & 15 deletions lib/formtastic/inputs/select_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,19 @@ module Inputs
class SelectInput
include Base
include Base::Collections
include Base::GroupedCollections

def to_html
input_wrapping do
hidden_input <<
label_html <<
(options[:group_by] ? grouped_select_html : select_html)
select_html
end
end

def select_html
builder.select(input_name, collection, input_options, input_html_options)
end

def grouped_select_html
builder.grouped_collection_select(
input_name,
grouped_collection,
group_association,
group_label_method,
value_method,
label_method,
input_options,
input_html_options
)
end

def include_blank
options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)
end
Expand Down
94 changes: 0 additions & 94 deletions spec/inputs/select_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,6 @@
end
end

describe "for a belongs_to association with :group_by => :author" do
it "should call author.posts" do
::Author.stub!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Post, :name => :posts)] : []}

[@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") }
@fred.should_receive(:posts)

with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
end)
end
end
end

describe "for a belongs_to association with :conditions" do
before do
::Post.stub!(:reflect_on_association).with(:author).and_return do
Expand Down Expand Up @@ -255,85 +240,6 @@
end
end

describe 'for a belongs_to association with :group_by => :continent' do
before do
@authors = [@bob, @fred, @fred, @fred]
::Author.stub!(:find).and_return(@authors)
@continent_names = %w(Europe Africa)
@continents = (0..1).map { |i| c = ::Continent.new; c.stub!(:id).and_return(100 - i);c }
@authors[0..1].each_with_index { |author, i| author.stub!(:continent).and_return(@continents[i]) }

::Continent.stub!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Author, :name => :authors)] : [] }
::Continent.stub!(:reflect_on_association).and_return {|column_name| mock('reflection', :klass => Author) if column_name == :authors}
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Continent, :macro => :belongs_to) if column_name == :continent }


@continents.each_with_index do |continent, i|
continent.stub!(:to_label).and_return(@continent_names[i])
continent.stub!(:authors).and_return([@authors[i]])
end

with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => :select, :group_by => :continent ) )
concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
end)
end
end

it_should_have_input_wrapper_with_class("select")
it_should_have_input_wrapper_with_id("post_author_input")
it_should_have_label_with_text(/Author/)
it_should_have_label_for('post_author_id')

# TODO, need to find a way to repeat some of the specs and logic from the belongs_to specs without grouping

0.upto(1) do |i|
it 'should have all option groups and the right values' do
output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
end

it 'should have custom group labels' do
output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
end

it 'should have custom author labels' do
output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
end

it 'should have custom author and group labels' do
output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
end
end

it 'should have no duplicate groups' do
output_buffer.should have_tag('form li select optgroup', :count => 8)
end

it 'should sort the groups on the label method' do
output_buffer.should have_tag("form li select optgroup[@label='Africa']")
output_buffer.should have_tag("form li select optgroup[@label='99']")
end

it 'should call find with :include for more optimized queries' do
if Formtastic::Util.rails3?
Author.should_receive(:where).with(:include => :continent)
else
proxy = author_array_or_scope(@authors)
Author.should_receive(:where).and_return(proxy)
proxy.should_receive(:includes).with(:continent).and_call_original
end

with_deprecation_silenced do
semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => :select, :group_by => :continent ) )
end
end
end
end

describe 'for a has_many association' do
before do
concat(semantic_form_for(@fred) do |builder|
Expand Down

0 comments on commit 08c6244

Please sign in to comment.