test/spec/proxy.rb in rod-rest-0.0.1.1 vs test/spec/proxy.rb in rod-rest-0.5.0
- old
+ new
@@ -33,11 +33,11 @@
}
let(:drivers_association_name) { "drivers"}
let(:car_type) { "Test::Car" }
let(:mercedes_300_hash) { { rod_id: mercedes_300_id, name: mercedes_300_name, type: car_type,
- owner: { rod_id: schumaher_id, type: person_type}, drivers: { count: drivers_count } } }
+ owner: schumaher_hash, drivers: { count: drivers_count } } }
let(:mercedes_300_id) { 1 }
let(:mercedes_300_name) { "Mercedes 300" }
let(:person_type) { "Test::Person" }
let(:drivers_count) { 1 }
@@ -72,15 +72,63 @@
it "has a valid 'name' field" do
mercedes_300.name.should == mercedes_300_name
end
- it "has an valid 'owner' singular association" do
+ it "has a valid 'owner' singular association" do
mercedes_300.owner.should == owner_object
end
+ it "caches 'owner' singular association" do
+ mercedes_300.owner
+ mercedes_300.owner
+ expect(client).to have_received.fetch_object(schumaher_hash) { schumaher_object }.once
+ end
+
it "has a valid 'drivers' plural association" do
mercedes_300.drivers.should == collection_proxy
+ end
+
+ it "caches 'drivers' plural association" do
+ mercedes_300.drivers
+ mercedes_300.drivers
+ expect(collection_proxy_factory).to have_received.new(anything,drivers_association_name,drivers_count,client) { collection_proxy }.once
+ end
+
+ describe "#inspect" do
+ it "reports that it is a proxy" do
+ mercedes_300.inspect.should match(/Proxy/)
+ end
+
+ it "reports the type of the object" do
+ mercedes_300.inspect.should match(/#{car_type}/)
+ end
+
+ it "reports the id of the object" do
+ mercedes_300.inspect.should match(/#{mercedes_300_id}/)
+ end
+
+ it "reports the name of the car" do
+ mercedes_300.inspect.should match(/name:#{mercedes_300_name}/)
+ end
+
+ it "reports the owner of the car" do
+ mercedes_300.inspect.should match(/owner:#{person_type}:#{schumaher_id}/)
+ end
+
+ it "reports the drivers of the car" do
+ mercedes_300.inspect.should match(/drivers\[#{drivers_count}\]/)
+ end
+ end
+
+ describe "#to_s" do
+ it "reports the type of the object" do
+ mercedes_300.to_s.should match(/#{car_type}/)
+ end
+
+ it "reports the id of the object" do
+ mercedes_300.to_s.should match(/#{mercedes_300_id}/)
+ end
end
end
end
end
end