File tree Expand file tree Collapse file tree 4 files changed +29
-7
lines changed
Expand file tree Collapse file tree 4 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,13 @@ def fetch(opts = {})
4747 return @parent . attributes [ @name ] unless @params . any? || @parent . attributes [ @name ] . blank?
4848 return @opts [ :default ] . try ( :dup ) if @parent . new?
4949
50- path = build_association_path lambda { "#{ @parent . request_path ( @params ) } #{ @opts [ :path ] } " }
51- @klass . get ( path , @params ) . tap do |result |
52- @cached_result = result unless @params . any?
50+ if @params . values . include? ( [ ] ) and !self . is_a? ( HasOneAssociation )
51+ Her ::Collection . new
52+ else
53+ path = build_association_path lambda { "#{ @parent . request_path ( @params ) } #{ @opts [ :path ] } " }
54+ @klass . get ( path , @params ) . tap do |result |
55+ @cached_result = result unless @params . any?
56+ end
5357 end
5458 end
5559
Original file line number Diff line number Diff line change @@ -65,10 +65,14 @@ def kind_of?(thing)
6565 # @private
6666 def fetch
6767 @_fetch ||= begin
68- path = @parent . build_request_path ( @parent . collection_path , @params )
69- method = @parent . method_for ( :find )
70- @parent . request ( @params . merge ( :_method => method , :_path => path ) ) do |parsed_data , response |
71- @parent . new_collection ( parsed_data )
68+ if @params . values . include? ( [ ] )
69+ Her ::Collection . new
70+ else
71+ path = @parent . build_request_path ( @parent . collection_path , @params )
72+ method = @parent . method_for ( :find )
73+ @parent . request ( @params . merge ( :_method => method , :_path => path ) ) do |parsed_data , response |
74+ @parent . new_collection ( parsed_data )
75+ end
7276 end
7377 end
7478 end
Original file line number Diff line number Diff line change 236236 expect { @user_without_included_data . comments . reload } . to change { @user_without_included_data . comments . first . object_id }
237237 end
238238
239+ it "returns an empty collection without fetching when [] is a parameter" do
240+ Foo ::Comment . should_not_receive ( :request )
241+ comments = @user_without_included_data . comments . where ( :foo_id => [ ] )
242+ comments . should respond_to ( :length )
243+ comments . size . should eql 0
244+ end
245+
239246 it "maps an array of included data through has_one" do
240247 expect ( @user_with_included_data . role ) . to be_a ( Foo ::Role )
241248 expect ( @user_with_included_data . role . object_id ) . to eq ( @user_with_included_data . role . object_id )
Original file line number Diff line number Diff line change 5959 expect ( Foo ::User . create ( fullname : "George Michael Bluth" ) . id ) . to eq ( 3 )
6060 expect ( Foo ::User . all . size ) . to eql 3
6161 end
62+
63+ it "returns an empty collection without fetching when [] is given" do
64+ Foo ::User . should_not_receive ( :request )
65+ users = Foo ::User . where ( :fullname => [ ] )
66+ users . should respond_to ( :length )
67+ users . size . should eql 0
68+ end
6269 end
6370
6471 context "for parent class" do
You can’t perform that action at this time.
0 commit comments