taskrabbit 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ ## v0.0.6
2
+
3
+ * Fix Task#create
4
+ * Add Task#new_record?
5
+
1
6
  ## v0.0.5
2
7
 
3
8
  * add compatibility with ruby 1.9.3
data/README.md CHANGED
@@ -90,6 +90,7 @@ tr.users.find(user_id).tasks
90
90
  ```ruby
91
91
  tr = Taskrabbit::Api.new(user_token)
92
92
  task = tr.tasks.create({:named_price => 32, :name => 'Ikea'})
93
+ task.new_record? #=> false
93
94
  ```
94
95
 
95
96
  or
@@ -34,8 +34,7 @@ module Taskrabbit
34
34
  # check if an error has occured
35
35
  def check_response_errors(response)
36
36
  return unless net_http_response = response.response rescue nil
37
- return unless [Net::HTTPClientError, Net::HTTPServerError].include?(net_http_response.class.superclass)
38
-
37
+ return if ([Net::HTTPClientError, Net::HTTPServerError] & [net_http_response.class, net_http_response.class.superclass]).empty?
39
38
  response_hash = response.to_hash
40
39
  error = response_hash.fetch('error') { "#{net_http_response.code} #{net_http_response.message}".strip }
41
40
 
@@ -32,7 +32,9 @@ module Taskrabbit
32
32
  end
33
33
 
34
34
  def create(api, params)
35
- api.request('post', "tasks", self, :task => params)
35
+ task = api.tasks.new(params)
36
+ task.save
37
+ task
36
38
  end
37
39
  end
38
40
 
@@ -48,6 +50,10 @@ module Taskrabbit
48
50
  end
49
51
  end
50
52
 
53
+ def new_record?
54
+ !id
55
+ end
56
+
51
57
  def delete!
52
58
  reload('delete', "tasks/#{id.to_s}")
53
59
  end
@@ -1,3 +1,3 @@
1
1
  module Taskrabbit
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,34 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://localhost:3000/api/v1/tasks?
6
+ body:
7
+ headers:
8
+ x-client-application:
9
+ - euqmQpzV04GmN1dJTY639PdI7eiSjCjI3lKTkPWn
10
+ authorization:
11
+ - OAuth RhyRtRg1bRNyqmdozkY6JJJ3eGDpoRGTm9AXUudp
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 422
15
+ message:
16
+ headers:
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ x-runtime:
20
+ - '11415'
21
+ content-length:
22
+ - '365'
23
+ set-cookie:
24
+ - current_geo=1053; path=/; expires=Tue, 02-Oct-2012 06:08:56 GMT
25
+ cache-control:
26
+ - no-cache
27
+ server:
28
+ - thin 1.4.1 codename Chromeo
29
+ body: ! '{"errors":{"messages":["Task title can''t be blank","Amount you are willing
30
+ to pay needs to be a whole dollar amount greater than zero"],"fields":[["name","can''t
31
+ be blank"],["named_price","needs to be a whole dollar amount greater than zero"]]},"error":"Task
32
+ title can''t be blank, \nAmount you are willing to pay needs to be a whole dollar
33
+ amount greater than zero"}'
34
+ http_version: '1.1'
@@ -78,6 +78,20 @@ describe Taskrabbit::Task do
78
78
  end
79
79
  end
80
80
 
81
+ describe "#new_record?" do
82
+ subject { Taskrabbit::Task.new }
83
+
84
+ it "returns true if the task has no id" do
85
+ subject.stub(:id => nil)
86
+ subject.should be_new_record
87
+ end
88
+
89
+ it "returns false if the task has an id" do
90
+ subject.stub(:id => 123)
91
+ subject.should_not be_new_record
92
+ end
93
+ end
94
+
81
95
  describe "#find" do
82
96
 
83
97
  it "should fetch tasks" do
@@ -203,10 +217,11 @@ describe Taskrabbit::Task do
203
217
  tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
204
218
  VCR.use_cassette('tasks/create/with_invalid_params', :record => :new_episodes) do
205
219
  tr_task = nil
206
- expect { tr_task = tr.tasks.create(invalid_params) }.to
207
- raise_error(Taskrabbit::Error, "Task title can't be blank,\n" +
208
- "Amount you are willing to pay needs to be a whole dollar amount greater than zero")
209
- tr_task.should be_nil
220
+ tr_task = tr.tasks.create(invalid_params)
221
+ tr_task.should be_instance_of(Taskrabbit::Task)
222
+ 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"],
223
+ "fields"=>[["name", "can't be blank"], ["named_price", "needs to be a whole dollar amount greater than zero"]]}
224
+ 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"
210
225
  end
211
226
  end
212
227
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taskrabbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000 Z
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: api_smith
@@ -119,6 +119,7 @@ files:
119
119
  - spec/support/cassettes/tasks/all.yml
120
120
  - spec/support/cassettes/tasks/create/default.yml
121
121
  - spec/support/cassettes/tasks/create/using_account.yml
122
+ - spec/support/cassettes/tasks/create/with_invalid_params.yml
122
123
  - spec/support/cassettes/tasks/create/with_location.yml
123
124
  - spec/support/cassettes/tasks/create/without_credit_card.yml
124
125
  - spec/support/cassettes/tasks/create/without_user.yml
@@ -157,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
158
  version: '0'
158
159
  segments:
159
160
  - 0
160
- hash: -3232776619035883631
161
+ hash: 1376035083108164495
161
162
  required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  none: false
163
164
  requirements:
@@ -184,6 +185,7 @@ test_files:
184
185
  - spec/support/cassettes/tasks/all.yml
185
186
  - spec/support/cassettes/tasks/create/default.yml
186
187
  - spec/support/cassettes/tasks/create/using_account.yml
188
+ - spec/support/cassettes/tasks/create/with_invalid_params.yml
187
189
  - spec/support/cassettes/tasks/create/with_location.yml
188
190
  - spec/support/cassettes/tasks/create/without_credit_card.yml
189
191
  - spec/support/cassettes/tasks/create/without_user.yml