Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix a bunch of issues and failing select input specs around #where vs…

… #all and collection_from_association
  • Loading branch information...
commit 4134c1218e64394dcd4082b737ead846a6a46e93 1 parent 764b795
@justinfrench authored
View
14 lib/formtastic/inputs/new_base/collections.rb
@@ -55,14 +55,16 @@ def collection_from_options
def collection_from_association
if reflection
find_options_from_options = options[:find_options] || {}
- conditions_from_options = find_options_from_options[:conditions]
- conditions_from_reflection = reflection.options[:conditions]
-
- if conditions_from_options
- reflection.klass.where(conditions_from_reflection).where(conditions_from_options)
+ conditions_from_options = find_options_from_options[:conditions] || {}
+ conditions_from_reflection = reflection.options[:conditions] || {}
+
+ if conditions_from_options.any?
+ reflection.klass.where(
+ conditions_from_reflection.merge(conditions_from_options)
+ )
else
find_options_from_options.merge!(:include => group_by) if group_by
- reflection.klass.all(find_options_from_options)
+ reflection.klass.where(conditions_from_reflection.merge(find_options_from_options))
end
end
end
View
10 spec/inputs/select_input_spec.rb
@@ -205,8 +205,7 @@
end
it "should call author.find with association conditions" do
- ::Author.should_receive(:merge_conditions).with({:active => true}, nil).and_return(:active => true)
- ::Author.should_receive(:all).with(:conditions => {:active => true})
+ ::Author.should_receive(:where).with(:active => true)
semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => :select))
@@ -214,9 +213,8 @@
end
it "should call author.find with association conditions and find_options conditions" do
- ::Author.should_receive(:merge_conditions).with({:active => true}, {:publisher => true}).and_return(:active => true, :publisher => true)
- ::Author.should_receive(:all).with(:conditions => {:active => true, :publisher => true})
-
+ ::Author.should_receive(:where).with({:active => true, :publisher => true})
+
semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
end
@@ -284,7 +282,7 @@
end
it 'should call find with :include for more optimized queries' do
- Author.should_receive(:all).with(:include => :continent)
+ Author.should_receive(:where).with(:include => :continent)
semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => :select, :group_by => :continent ) )
View
2  spec/spec_helper.rb
@@ -153,6 +153,7 @@ def new_author_path; "/authors/new"; end
::Author.stub!(:find).and_return([@fred, @bob])
::Author.stub!(:all).and_return([@fred, @bob])
+ ::Author.stub!(:where).and_return([@fred, @bob])
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
::Author.stub!(:human_name).and_return('::Author')
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
@@ -219,6 +220,7 @@ def new_author_path; "/authors/new"; end
end
::Post.stub!(:find).and_return([@freds_post])
::Post.stub!(:all).and_return([@freds_post])
+ ::Post.stub!(:where).and_return([@freds_post])
::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
::Post.stub!(:to_key).and_return(nil)
::Post.stub!(:persisted?).and_return(nil)
View
2  spec/support/custom_macros.rb
@@ -234,7 +234,7 @@ def it_should_apply_error_logic_for_input_type(type)
def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
it "should call find on the association class when no collection is provided" do
- ::Author.should_receive(:all)
+ ::Author.should_receive(:where)
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:author, :as => as))
end)
Please sign in to comment.
Something went wrong with that request. Please try again.