spec/motion-resource/crud_spec.rb in motion-resource-0.1.3 vs spec/motion-resource/crud_spec.rb in motion-resource-0.1.4
- old
+ new
@@ -63,10 +63,39 @@
wait_max 1.0 do
@response.should.not.be.ok
end
end
+
+ it "should include association" do
+ stub_request(:post, "http://example.com/posts.json").to_return(body: "")
+ Post.new.create(:include => :comments) do |result, response|
+ @response = response
+ resume
+ end
+
+ wait_max 1.0 do
+ @response.should.be.ok
+ end
+ end
+
+ it "should include association with _attributes suffix" do
+ stub_request(:post, "http://example.com/posts.json").to_return(body: "")
+ Post.new.create(:include => :comments_attributes) do |result, response|
+ @response = response
+ resume
+ end
+
+ wait_max 1.0 do
+ @response.should.be.ok
+ end
+ end
+
+ it "should raise error when included association is not found" do
+ stub_request(:post, "http://example.com/posts.json").to_return(body: "")
+ lambda { Post.new.create(:include => :foobar) { |result, response| } }.should.raise(ArgumentError)
+ end
end
describe "update" do
it "should update on save if record already exists" do
stub_request(:put, "http://example.com/comments/10.json").to_return(json: { id: 10 })
@@ -127,9 +156,22 @@
resume
end
wait_max 1.0 do
@response.should.not.be.ok
+ end
+ end
+
+
+ it "should include association" do
+ stub_request(:put, "http://example.com/posts/10.json").to_return(body: "")
+ Post.instantiate(:id => 10).update(:include => :comments) do |result, response|
+ @response = response
+ resume
+ end
+
+ wait_max 1.0 do
+ @response.should.be.ok
end
end
end
describe "destroy" do