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 @@ -50,9 +50,13 @@ def fetch(opts = {})
5050 return @cached_result unless @params . any? || @cached_result . nil?
5151 return @parent . attributes [ @name ] unless @params . any? || @parent . attributes [ @name ] . blank?
5252
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?
53+ if @params . values . include? ( [ ] ) and !self . is_a? ( HasOneAssociation )
54+ Her ::Collection . new
55+ else
56+ path = build_association_path lambda { "#{ @parent . request_path ( @params ) } #{ @opts [ :path ] } " }
57+ @klass . get ( path , @params ) . tap do |result |
58+ @cached_result = result unless @params . any?
59+ end
5660 end
5761 end
5862
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 ( @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 ( @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 223223 expect ( @user_without_included_data . comments . first . object_id ) . not_to eq ( @user_without_included_data . comments . where ( foo_id : 1 ) . first . object_id )
224224 end
225225
226+ it "returns an empty collection without fetching when [] is a parameter" do
227+ Foo ::Comment . should_not_receive ( :request )
228+ comments = @user_without_included_data . comments . where ( :foo_id => [ ] )
229+ comments . should respond_to ( :length )
230+ comments . size . should eql 0
231+ end
232+
226233 it "maps an array of included data through has_one" do
227234 expect ( @user_with_included_data . role ) . to be_a ( Foo ::Role )
228235 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 5151 expect ( Foo ::User . create ( fullname : "George Michael Bluth" ) . id ) . to eq ( 3 )
5252 expect ( Foo ::User . all . size ) . to eql 3
5353 end
54+
55+ it "returns an empty collection without fetching when [] is given" do
56+ Foo ::User . should_not_receive ( :request )
57+ users = Foo ::User . where ( :fullname => [ ] )
58+ users . should respond_to ( :length )
59+ users . size . should eql 0
60+ end
5461 end
5562
5663 context "for parent class" do
You can’t perform that action at this time.
0 commit comments