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 @@ -48,9 +48,13 @@ def fetch(opts = {})
4848 return @parent . attributes [ @name ] unless @params . any? || @parent . attributes [ @name ] . blank?
4949 return @opts [ :default ] . try ( :dup ) if @parent . new?
5050
51- path = build_association_path -> { "#{ @parent . request_path ( @params ) } #{ @opts [ :path ] } " }
52- @klass . get ( path , @params ) . tap do |result |
53- @cached_result = result unless @params . any?
51+ if @params . values . include? ( [ ] ) && !is_a? ( HasOneAssociation )
52+ Her ::Collection . new
53+ else
54+ path = build_association_path -> { "#{ @parent . request_path ( @params ) } #{ @opts [ :path ] } " }
55+ @klass . get ( path , @params ) . tap do |result |
56+ @cached_result = result unless @params . any?
57+ end
5458 end
5559 end
5660
Original file line number Diff line number Diff line change @@ -67,10 +67,14 @@ def kind_of?(thing)
6767 # @private
6868 def fetch
6969 @_fetch ||= begin
70- path = @parent . build_request_path ( @parent . collection_path , @params )
71- method = @parent . method_for ( :find )
72- @parent . request ( @params . merge ( :_method => method , :_path => path ) ) do |parsed_data , _ |
73- @parent . new_collection ( parsed_data )
70+ if @params . values . include? ( [ ] )
71+ Her ::Collection . new
72+ else
73+ path = @parent . build_request_path ( @parent . collection_path , @params )
74+ method = @parent . method_for ( :find )
75+ @parent . request ( @params . merge ( :_method => method , :_path => path ) ) do |parsed_data , _ |
76+ @parent . new_collection ( parsed_data )
77+ end
7478 end
7579 end
7680 end
Original file line number Diff line number Diff line change 440440 expect ( user . organization . respond_to? ( :empty? ) ) . to be_truthy
441441 expect ( user . organization ) . not_to be_empty
442442 end
443+
444+ it "returns an empty collection without fetching when [] is a parameter" do
445+ Foo ::Comment . should_not_receive ( :request )
446+ comments = user . comments . where ( :foo_id => [ ] )
447+ comments . should respond_to ( :length )
448+ comments . size . should eql 0
449+ end
443450 end
444451
445452 context "without included parent data" do
Original file line number Diff line number Diff line change 6060 expect ( Foo ::User . create ( fullname : "George Michael Bluth" ) . id ) . to eq ( 3 )
6161 expect ( Foo ::User . all . size ) . to eql 3
6262 end
63+
64+ it "returns an empty collection without fetching when [] is given" do
65+ Foo ::User . should_not_receive ( :request )
66+ users = Foo ::User . where ( :fullname => [ ] )
67+ users . should respond_to ( :length )
68+ users . size . should eql 0
69+ end
6370 end
6471
6572 context "for parent class" do
You can’t perform that action at this time.
0 commit comments