Sha256: 4ff3de8d587ad4e4fb5651e4f7f4fca12f3992e3820b2a1c2c52145122f5a792

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe "SingleObjectAssociationFinder" 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(nil)

		finder = ApiResource::Finders::SingleObjectAssociationFinder.new(
			TestResource,
			stub(
				:remote_path => "test_resources",
				:to_query => "id[]=1&id[]=2",
				:blank_conditions? => false
			)
		)
		finder.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::SingleObjectAssociationFinder.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_record).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

4 entries across 4 versions & 1 rubygems

Version Path
api_resource-0.6.25 spec/lib/finders/single_object_association_finder_spec.rb
api_resource-0.6.24 spec/lib/finders/single_object_association_finder_spec.rb
api_resource-0.6.23 spec/lib/finders/single_object_association_finder_spec.rb
api_resource-0.6.22 spec/lib/finders/single_object_association_finder_spec.rb