Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix non run test for create.

  • Loading branch information...
commit 45f4432487381c5af009b0889bd4e7ce8161b6d0 1 parent f23aae3
@jrichardlai authored
View
3  lib/taskrabbit/client.rb
@@ -34,8 +34,7 @@ def transform_response(response, options)
# check if an error has occured
def check_response_errors(response)
return unless net_http_response = response.response rescue nil
- return unless [Net::HTTPClientError, Net::HTTPServerError].include?(net_http_response.class.superclass)
-
+ return if ([Net::HTTPClientError, Net::HTTPServerError] & [net_http_response.class, net_http_response.class.superclass]).empty?
response_hash = response.to_hash
error = response_hash.fetch('error') { "#{net_http_response.code} #{net_http_response.message}".strip }
View
4 lib/taskrabbit/task.rb
@@ -32,7 +32,9 @@ def all(scope, options = {})
end
def create(api, params)
- api.request('post', "tasks", self, :task => params)
+ task = api.tasks.new(params)
+ task.save
+ task
end
end
View
34 spec/support/cassettes/tasks/create/with_invalid_params.yml
@@ -0,0 +1,34 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri: http://localhost:3000/api/v1/tasks?
+ body:
+ headers:
+ x-client-application:
+ - euqmQpzV04GmN1dJTY639PdI7eiSjCjI3lKTkPWn
+ authorization:
+ - OAuth RhyRtRg1bRNyqmdozkY6JJJ3eGDpoRGTm9AXUudp
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 422
+ message:
+ headers:
+ content-type:
+ - application/json; charset=utf-8
+ x-runtime:
+ - '11415'
+ content-length:
+ - '365'
+ set-cookie:
+ - current_geo=1053; path=/; expires=Tue, 02-Oct-2012 06:08:56 GMT
+ cache-control:
+ - no-cache
+ server:
+ - thin 1.4.1 codename Chromeo
+ body: ! '{"errors":{"messages":["Task title can''t be blank","Amount you are willing
+ to pay needs to be a whole dollar amount greater than zero"],"fields":[["name","can''t
+ be blank"],["named_price","needs to be a whole dollar amount greater than zero"]]},"error":"Task
+ title can''t be blank, \nAmount you are willing to pay needs to be a whole dollar
+ amount greater than zero"}'
+ http_version: '1.1'
View
9 spec/taskrabbit/task_spec.rb
@@ -203,10 +203,11 @@
tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
VCR.use_cassette('tasks/create/with_invalid_params', :record => :new_episodes) do
tr_task = nil
- expect { tr_task = tr.tasks.create(invalid_params) }.to
- raise_error(Taskrabbit::Error, "Task title can't be blank,\n" +
- "Amount you are willing to pay needs to be a whole dollar amount greater than zero")
- tr_task.should be_nil
+ tr_task = tr.tasks.create(invalid_params)
+ tr_task.should be_instance_of(Taskrabbit::Task)
+ tr_task.errors.should == {"messages"=>["Task title can't be blank", "Amount you are willing to pay needs to be a whole dollar amount greater than zero"],
+ "fields"=>[["name", "can't be blank"], ["named_price", "needs to be a whole dollar amount greater than zero"]]}
+ tr_task.error.should == "Task title can't be blank, \nAmount you are willing to pay needs to be a whole dollar amount greater than zero"
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.