spec/lib/finders_spec.rb in api_resource-0.6.16 vs spec/lib/finders_spec.rb in api_resource-0.6.17

- old
+ new

@@ -26,9 +26,34 @@ it "should be able to chain find on top of a scope" do TestResource.connection.expects(:get).with("/test_resources.json?active=true&passive=true") TestResource.active.all(:passive => true) end + it "should be able to find a single object after a scope" do + TestResource.connection.expects(:get) + .with("/test_resources.json?birthday%5Bdate%5D=5&find%5Bids%5D=1").returns([{"id" => 10}]) + + val = TestResource.birthday(5).find(1) + val.should be_a(TestResource) + end + + it "should be able to find multiple objects after a scope" do + TestResource.connection.expects(:get) + .with("/test_resources.json?birthday%5Bdate%5D=5&find%5Bids%5D=1").returns([{"id" => 10}, {"id" => 8}]) + + val = TestResource.birthday(5).find(1) + val.should be_a(Array) + val.first.should be_a(TestResource) + end + + it "should be able to find the first/last object" do + TestResource.connection.expects(:get) + .with("/test_resources.json?first=true").returns([{"id" => 10}]) + + val = TestResource.first + val.should be_a(TestResource) + end + it "should be able to chain find on top of an includes call" do TestResource.connection.expects(:get).with("/test_resources/1.json").returns({"id" => 1, "has_many_object_ids" => [1,2]}) HasManyObject.connection.expects(:get).with("/has_many_objects.json?ids%5B%5D=1&ids%5B%5D=2").returns([]) TestResource.includes(:has_many_objects).find(1) \ No newline at end of file