spec/pardot/http_spec.rb in ruby-pardot-1.0.2 vs spec/pardot/http_spec.rb in ruby-pardot-1.1.0

- old
+ new

@@ -66,7 +66,67 @@ @client.should_receive(:handle_expired_api_key) post end end + + describe "getV4" do + + def get object = "foo", path = "/bar", params = {} + @client.version = "4" + @client.get object, path, params + end + + it "should notice errors and raise them as Pardot::ResponseError" do + fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar", + %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n) + + lambda { get }.should raise_error(Pardot::ResponseError) + end + + it "should catch and reraise SocketErrors as Pardot::NetError" do + Pardot::Client.should_receive(:get).and_raise(SocketError) + + lambda { get }.should raise_error(Pardot::NetError) + end + + it "should call handle_expired_api_key when the api key expires" do + fake_get "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar", + %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n) + + @client.should_receive(:handle_expired_api_key) + get + end + + end + + describe "postV4" do + + def post object = "foo", path = "/bar", params = {} + @client.version = "4" + @client.post object, path, params + end + + it "should notice errors and raise them as Pardot::ResponseError" do + fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar", + %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Login failed</err>\n</rsp>\n) + + lambda { post }.should raise_error(Pardot::ResponseError) + end + + it "should catch and reraise SocketErrors as Pardot::NetError" do + Pardot::Client.should_receive(:post).and_raise(SocketError) + + lambda { post }.should raise_error(Pardot::NetError) + end + + it "should call handle_expired_api_key when the api key expires" do + fake_post "/api/foo/version/4/bar?api_key=my_api_key&format=simple&user_key=bar", + %(?xml version="1.0" encoding="UTF-8"?>\n<rsp stat="fail" version="1.0">\n <err code="15">Invalid API key or user key</err>\n</rsp>\n) + + @client.should_receive(:handle_expired_api_key) + post + end + + end end \ No newline at end of file