Sha256: 1f7f89500c74bb88c516c3ef136d9b06c052231c2470e64bfbd620bd2b19b8ca

Contents?: true

Size: 1.31 KB

Versions: 21

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe "MultiObjectAssociationFinder" do

	before(:each) do
		TestResource.reload_resource_definition
	end
	
	it "should build a proper load path and call into the connection" do
		TestResource.connection.expects(:get).with("test_resources.json?id[]=1&id[]=2").returns([])

		ApiResource::Finders::MultiObjectAssociationFinder.new(
			TestResource,
			stub(:remote_path => "test_resources", :to_query => "id[]=1&id[]=2", :blank_conditions? => false)
		).load
	end

	it "should load a has many association properly" do
		# much of this test already lies in resource_finder_spec.rb
		# this just verifies that the data is passed in correctly
		finder = ApiResource::Finders::MultiObjectAssociationFinder.new(
			TestResource,
			stub(
				:remote_path => "test_resources", 
				:blank_conditions? => true,
				:eager_load? => true, 
				:included_objects => [:has_many_objects]
			)
		)

		tr = TestResource.new
		tr.stubs(:id).returns(1)
		tr.stubs(:has_many_object_ids).returns([1,2])
		TestResource.connection.expects(:get).with("test_resources.json").returns([4])
		TestResource.expects(:instantiate_collection).with([4]).returns([tr])

		finder.expects(:load_includes).with(:has_many_objects => [1,2]).returns(5)
		finder.expects(:apply_includes).with([tr], 5).returns(6)

		finder.load.should eql([tr])
	end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
api_resource-0.6.21 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.20 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.19 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.18 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.17 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.16 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.15 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.14 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.13 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.12 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.11 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.9 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.10 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.8 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.7 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.6 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.5 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.4 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.3 spec/lib/finders/multi_object_association_finder_spec.rb
api_resource-0.6.2 spec/lib/finders/multi_object_association_finder_spec.rb