taskrabbit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +22 -0
  4. data/Guardfile +8 -0
  5. data/README.md +132 -0
  6. data/Rakefile +53 -0
  7. data/lib/taskrabbit.rb +21 -0
  8. data/lib/taskrabbit/account.rb +7 -0
  9. data/lib/taskrabbit/api.rb +47 -0
  10. data/lib/taskrabbit/association.rb +52 -0
  11. data/lib/taskrabbit/city.rb +19 -0
  12. data/lib/taskrabbit/client.rb +47 -0
  13. data/lib/taskrabbit/collection.rb +17 -0
  14. data/lib/taskrabbit/config.rb +43 -0
  15. data/lib/taskrabbit/error.rb +10 -0
  16. data/lib/taskrabbit/location.rb +19 -0
  17. data/lib/taskrabbit/proxy.rb +62 -0
  18. data/lib/taskrabbit/smash.rb +82 -0
  19. data/lib/taskrabbit/task.rb +54 -0
  20. data/lib/taskrabbit/transformer.rb +5 -0
  21. data/lib/taskrabbit/user.rb +26 -0
  22. data/lib/taskrabbit/version.rb +3 -0
  23. data/spec/spec_helper.rb +33 -0
  24. data/spec/support/cassettes/account/no_user.yml +30 -0
  25. data/spec/support/cassettes/account/properties.yml +32 -0
  26. data/spec/support/cassettes/account/tasks.yml +63 -0
  27. data/spec/support/cassettes/account/with_user.yml +32 -0
  28. data/spec/support/cassettes/cities/all.yml +32 -0
  29. data/spec/support/cassettes/cities/find.yml +32 -0
  30. data/spec/support/cassettes/cities/properties.yml +32 -0
  31. data/spec/support/cassettes/errors/404.yml +362 -0
  32. data/spec/support/cassettes/locations/properties.yml +63 -0
  33. data/spec/support/cassettes/tasks/all.yml +32 -0
  34. data/spec/support/cassettes/tasks/create/default.yml +30 -0
  35. data/spec/support/cassettes/tasks/create/using_account.yml +30 -0
  36. data/spec/support/cassettes/tasks/create/with_location.yml +32 -0
  37. data/spec/support/cassettes/tasks/create/without_credit_card.yml +30 -0
  38. data/spec/support/cassettes/tasks/create/without_user.yml +30 -0
  39. data/spec/support/cassettes/tasks/delete.yml +63 -0
  40. data/spec/support/cassettes/tasks/find.yml +32 -0
  41. data/spec/support/cassettes/tasks/properties.yml +32 -0
  42. data/spec/support/cassettes/tasks/save.yml +63 -0
  43. data/spec/support/cassettes/tasks/update.yml +63 -0
  44. data/spec/support/cassettes/tasks/without_client.yml +30 -0
  45. data/spec/support/cassettes/users/find.yml +32 -0
  46. data/spec/support/cassettes/users/properties.yml +32 -0
  47. data/spec/support/cassettes/users/tasks/all.yml +32 -0
  48. data/spec/taskrabbit/account_spec.rb +65 -0
  49. data/spec/taskrabbit/api_spec.rb +34 -0
  50. data/spec/taskrabbit/city_spec.rb +61 -0
  51. data/spec/taskrabbit/collection_spec.rb +17 -0
  52. data/spec/taskrabbit/error_spec.rb +13 -0
  53. data/spec/taskrabbit/location_spec.rb +26 -0
  54. data/spec/taskrabbit/proxy_spec.rb +23 -0
  55. data/spec/taskrabbit/smash_spec.rb +129 -0
  56. data/spec/taskrabbit/task_spec.rb +235 -0
  57. data/spec/taskrabbit/taskrabbit_spec.rb +31 -0
  58. data/spec/taskrabbit/user_spec.rb +70 -0
  59. data/taskrabbit.gemspec +26 -0
  60. metadata +194 -0
@@ -0,0 +1,63 @@
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: task[name]=My%20First%20Task&task[named_price]=20&task[city_id]=4
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: 200
15
+ message: OK
16
+ headers:
17
+ etag:
18
+ - "\"3e2534e6d1fbd01d8fd94342e21bf9c3\""
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ x-runtime:
22
+ - "4727"
23
+ server:
24
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
25
+ date:
26
+ - Sat, 17 Mar 2012 23:12:59 GMT
27
+ content-length:
28
+ - "677"
29
+ cache-control:
30
+ - private, max-age=0, must-revalidate
31
+ body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"charge_price\":20,\"private_runner\":false,\"named_price\":20,\"complete_by_time\":1332093600,\"id\":22680,\"state_changed_at\":1332025978,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--54\",\"get\":\"/api/v1/tasks/22680\",\"delete\":\"/api/v1/tasks/22680\",\"put\":\"/api/v1/tasks/22680\",\"authenticated\":\"http://local.taskrabbit.com/go/ee139b2757bbbf6c4eee502816d10ccc2e8ed72f608a44f3a3ba4d902e7d9f42f7411102b41821050c3f0a2be896dd812140\"},\"runners\":{\"items\":[]},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"}"
32
+ http_version: "1.1"
33
+ - !ruby/struct:VCR::HTTPInteraction
34
+ request: !ruby/struct:VCR::Request
35
+ method: :put
36
+ uri: http://localhost:3000/api/v1/tasks/22680?
37
+ body: name=New%20Name&id=22680
38
+ headers:
39
+ x-client-application:
40
+ - euqmQpzV04GmN1dJTY639PdI7eiSjCjI3lKTkPWn
41
+ authorization:
42
+ - OAuth RhyRtRg1bRNyqmdozkY6JJJ3eGDpoRGTm9AXUudp
43
+ response: !ruby/struct:VCR::Response
44
+ status: !ruby/struct:VCR::ResponseStatus
45
+ code: 200
46
+ message: OK
47
+ headers:
48
+ etag:
49
+ - "\"8331cd17eb90f131337fc675d2d0fc5a\""
50
+ content-type:
51
+ - application/json; charset=utf-8
52
+ x-runtime:
53
+ - "2003"
54
+ server:
55
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
56
+ date:
57
+ - Sat, 17 Mar 2012 23:13:02 GMT
58
+ content-length:
59
+ - "666"
60
+ cache-control:
61
+ - private, max-age=0, must-revalidate
62
+ body: "{\"name\":\"New Name\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"charge_price\":20,\"private_runner\":false,\"named_price\":20,\"complete_by_time\":1332093600,\"id\":22680,\"state_changed_at\":1332025978,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/new-name--4\",\"get\":\"/api/v1/tasks/22680\",\"delete\":\"/api/v1/tasks/22680\",\"put\":\"/api/v1/tasks/22680\",\"authenticated\":\"http://local.taskrabbit.com/go/78196cf7905ad6c4b1fb0e4df943b284253a8880163ee3675cdf4b06a9b9de63f6b1cc198064ac121d7afce702d81be0fb03\"},\"runners\":{\"items\":[]},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"}"
63
+ http_version: "1.1"
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://localhost:3000/api/v1/tasks?
6
+ body:
7
+ headers:
8
+ x-client-application:
9
+ - ""
10
+ authorization:
11
+ - OAuth
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 403
15
+ message: Forbidden
16
+ headers:
17
+ content-type:
18
+ - application/json; charset=utf-8
19
+ x-runtime:
20
+ - "628"
21
+ server:
22
+ - WEBrick/1.3.1 (Ruby/1.8.7/2010-04-19)
23
+ date:
24
+ - Wed, 02 Nov 2011 02:35:53 GMT
25
+ content-length:
26
+ - "44"
27
+ cache-control:
28
+ - no-cache
29
+ body: "{\"error\":\"Missing valid client application\"}"
30
+ http_version: "1.1"
@@ -0,0 +1,32 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://localhost:3000/api/v1/users/49719?
6
+ body:
7
+ headers:
8
+ x-client-application:
9
+ - euqmQpzV04GmN1dJTY639PdI7eiSjCjI3lKTkPWn
10
+ authorization:
11
+ - OAuth
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ etag:
18
+ - "\"b17a2574110c83735c6cf13a269251f1\""
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ x-runtime:
22
+ - "198"
23
+ server:
24
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
25
+ date:
26
+ - Sat, 17 Mar 2012 23:13:19 GMT
27
+ content-length:
28
+ - "200"
29
+ cache-control:
30
+ - private, max-age=0, must-revalidate
31
+ body: "{\"id\":49719,\"short_name\":\"John\",\"full_name\":\"John D.\",\"links\":{\"get\":\"/api/v1/users/49719\",\"avatar_url\":\"http://local.taskrabbit.com/images/default_avatars/poster_thumb.png\"},\"display_name\":\"John D.\"}"
32
+ http_version: "1.1"
@@ -0,0 +1,32 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://localhost:3000/api/v1/users/49720?
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: 200
15
+ message: OK
16
+ headers:
17
+ etag:
18
+ - "\"d6539897f406d89d093ac69eadc07e59\""
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ x-runtime:
22
+ - "644"
23
+ server:
24
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
25
+ date:
26
+ - Sat, 17 Mar 2012 23:13:18 GMT
27
+ content-length:
28
+ - "397"
29
+ cache-control:
30
+ - private, max-age=0, must-revalidate
31
+ body: "{\"city\":{\"name\":\"SF Bay Area\",\"lng\":-122.419416,\"id\":3,\"links\":{\"get\":\"/api/v1/cities/3\"},\"lat\":37.77493},\"zip_code\":\"64321\",\"id\":49720,\"short_name\":\"Bob\",\"full_name\":\"Bob Sponge\",\"last_name\":\"Sponge\",\"links\":{\"get\":\"/api/v1/users/49720\",\"avatar_url\":\"http://local.taskrabbit.com/images/default_avatars/poster_thumb.png\"},\"display_name\":\"Bob S.\",\"email\":\"bobsponge@example.com\",\"first_name\":\"Bob\"}"
32
+ http_version: "1.1"
@@ -0,0 +1,32 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://localhost:3000/api/v1/users/49720/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: 200
15
+ message: OK
16
+ headers:
17
+ etag:
18
+ - "\"81c43af66182714b81997a339b33bbd0\""
19
+ content-type:
20
+ - application/json; charset=utf-8
21
+ x-runtime:
22
+ - "6667"
23
+ server:
24
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
25
+ date:
26
+ - Sat, 17 Mar 2012 23:13:27 GMT
27
+ content-length:
28
+ - "4186"
29
+ cache-control:
30
+ - private, max-age=0, must-revalidate
31
+ body: "{\"items\":[{\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"name\":\"My First Task\",\"charge_price\":20,\"named_price\":20,\"private_runner\":false,\"complete_by_time\":1332093600,\"cost_in_cents\":0,\"state_changed_at\":1332025380,\"id\":22673,\"runners\":{\"items\":[]},\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--47\",\"get\":\"/api/v1/tasks/22673\",\"delete\":\"/api/v1/tasks/22673\",\"put\":\"/api/v1/tasks/22673\",\"authenticated\":\"http://local.taskrabbit.com/go/2f249e87a04016d741f163fe991468737e367c8e334eb5d5a53a63d741ce0019ba1a9c33366a76cadc06bdcb9259c5549a44\"},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"},{\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"name\":\"New Name\",\"charge_price\":20,\"named_price\":20,\"private_runner\":false,\"complete_by_time\":1332093600,\"cost_in_cents\":0,\"state_changed_at\":1332025387,\"id\":22674,\"runners\":{\"items\":[]},\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/new-name--3\",\"get\":\"/api/v1/tasks/22674\",\"delete\":\"/api/v1/tasks/22674\",\"put\":\"/api/v1/tasks/22674\",\"authenticated\":\"http://local.taskrabbit.com/go/459b5e05e7a6542891148717ed9cdd4a25fb5d5f71f094c098a93beb25ba26303c4ea5e2c8e01da3743703abbe1da5b46980\"},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"},{\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"name\":\"My First Task\",\"charge_price\":20,\"named_price\":20,\"private_runner\":false,\"complete_by_time\":1332093600,\"cost_in_cents\":0,\"state_changed_at\":1332025394,\"id\":22675,\"runners\":{\"items\":[]},\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--49\",\"get\":\"/api/v1/tasks/22675\",\"delete\":\"/api/v1/tasks/22675\",\"put\":\"/api/v1/tasks/22675\",\"authenticated\":\"http://local.taskrabbit.com/go/a89862d84f6a3b8b3175c46bc824ba3c4086519395730898237d56ef90ad672e540e62370c6a87b6c6ec2f601c10e2486ba7\"},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"},{\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"name\":\"My First Task\",\"charge_price\":20,\"named_price\":20,\"private_runner\":false,\"complete_by_time\":1332093600,\"cost_in_cents\":0,\"state_changed_at\":1332025970,\"id\":22679,\"runners\":{\"items\":[]},\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--53\",\"get\":\"/api/v1/tasks/22679\",\"delete\":\"/api/v1/tasks/22679\",\"put\":\"/api/v1/tasks/22679\",\"authenticated\":\"http://local.taskrabbit.com/go/5a5d27db65887f4b787f19c3c32dbfcf59aabd1943575f7b5d9030f9b984573dbbca1e58d2cd4297b6bf0ec7ccaa3e849db9\"},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"},{\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"name\":\"New Name\",\"charge_price\":20,\"named_price\":20,\"private_runner\":false,\"complete_by_time\":1332093600,\"cost_in_cents\":0,\"state_changed_at\":1332025978,\"id\":22680,\"runners\":{\"items\":[]},\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/new-name--4\",\"get\":\"/api/v1/tasks/22680\",\"delete\":\"/api/v1/tasks/22680\",\"put\":\"/api/v1/tasks/22680\",\"authenticated\":\"http://local.taskrabbit.com/go/78196cf7905ad6c4b1fb0e4df943b284253a8880163ee3675cdf4b06a9b9de63f6b1cc198064ac121d7afce702d81be0fb03\"},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"},{\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"name\":\"My First Task\",\"charge_price\":20,\"named_price\":20,\"private_runner\":false,\"complete_by_time\":1332093600,\"cost_in_cents\":0,\"state_changed_at\":1332025986,\"id\":22681,\"runners\":{\"items\":[]},\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--55\",\"get\":\"/api/v1/tasks/22681\",\"delete\":\"/api/v1/tasks/22681\",\"put\":\"/api/v1/tasks/22681\",\"authenticated\":\"http://local.taskrabbit.com/go/aee487c3c205df11defb1eeb83dab50de7f670769edcd82455eae92f776d6e6ef0dd7b1aacbea7c05ede923baf3a1343bcc6\"},\"state_label\":\"posted\",\"assign_by_time\":1332082800,\"state\":\"opened\"}],\"links\":{\"get\":\"/api/v1/users/49720/tasks\",\"last\":\"/api/v1/users/49720/tasks?page=1\",\"first\":\"/api/v1/users/49720/tasks?page=1\"}}"
32
+ http_version: "1.1"
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::Account do
4
+ describe "account properties" do
5
+ before :all do
6
+ tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
7
+ VCR.use_cassette('account/properties', :record => :new_episodes) do
8
+ @user = tr.account
9
+ @user.fetch
10
+ end
11
+ end
12
+
13
+ subject { @user }
14
+
15
+ its(:id) { should == TR_USERS[:with_card][:id] }
16
+ its(:short_name) { should == "Bob" }
17
+ its(:first_name) { should == "Bob" }
18
+ its(:full_name) { should == "Bob Sponge" }
19
+ its(:display_name) { should == "Bob S." }
20
+ its(:runner) { should == false }
21
+ its(:email) { should == 'bobsponge@example.com' }
22
+ its(:mobile_phone) { should == nil }
23
+ its(:home_phone) { should == nil }
24
+ its(:tasks) { should be_a(Taskrabbit::Collection) } # TaskRabbit returns tasks in the json
25
+ its(:city) { should be_instance_of(Taskrabbit::City) }
26
+ its(:zip_code) { should == "64321" }
27
+ its(:locations) { should be_a(Taskrabbit::Collection) } # TaskRabbit returns locations in the json
28
+ its(:links) { should be_instance_of(Hash) }
29
+ end
30
+
31
+ describe "api endpoints" do
32
+ describe ".account" do
33
+ it "should return an error if the user is not passed" do
34
+ tr = Taskrabbit::Api.new
35
+ VCR.use_cassette('account/no_user', :record => :new_episodes) do
36
+ tr_account = nil
37
+ expect { tr_account = tr.account }.to_not raise_error
38
+ expect { tr_account = tr_account.short_name }.to raise_error(Taskrabbit::Error, 'There must be an authenticated user for this action')
39
+ end
40
+ end
41
+
42
+ it "should return the account of the user" do
43
+ tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
44
+ VCR.use_cassette('account/with_user', :record => :new_episodes) do
45
+ tr_account = nil
46
+ expect { tr_account = tr.account }.to_not raise_error
47
+ tr_account.short_name.should == 'Bob'
48
+ end
49
+ end
50
+ end
51
+
52
+ describe ".tasks" do
53
+ it "should fetch the tasks of the user" do
54
+ tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
55
+ VCR.use_cassette('account/tasks', :record => :new_episodes) do
56
+ tr_account = nil
57
+ expect { tr_account = tr.account }.to_not raise_error
58
+ account_tasks = tr_account.tasks.all
59
+ account_tasks.should be_a(Taskrabbit::Collection)
60
+ account_tasks.first.should be_instance_of(Taskrabbit::Task)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::Api do
4
+
5
+ describe "#new" do
6
+ it "should initialize without params" do
7
+ expect { Taskrabbit::Api.new }.to_not raise_error
8
+ end
9
+
10
+ it "should initialize with user_token" do
11
+ expect {
12
+ tr = Taskrabbit::Api.new("sometoken")
13
+ tr.user_token.should == "sometoken"
14
+ }.to_not raise_error
15
+ end
16
+ end
17
+
18
+ it "should return an error if the client is not set" do
19
+ secret = Taskrabbit.client_secret
20
+ Taskrabbit.client_secret = nil
21
+ tr = Taskrabbit::Api.new
22
+ VCR.use_cassette('tasks/without_client', :record => :new_episodes) do
23
+ expect { tr.tasks.all }.to raise_error(Taskrabbit::Error, 'Missing valid client application')
24
+ end
25
+ Taskrabbit.client_secret = secret
26
+ end
27
+
28
+ it "should return an error if the client is not set" do
29
+ tr = Taskrabbit::Api.new
30
+ VCR.use_cassette('errors/404', :record => :new_episodes) do
31
+ expect { tr.tasks.find('something-that-doesnot-exists').name }.to raise_error(Taskrabbit::Error, '404 Not Found')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::City do
4
+
5
+ describe "city properties" do
6
+
7
+ before :all do
8
+ tr = Taskrabbit::Api.new
9
+ VCR.use_cassette('cities/properties', :record => :new_episodes) do
10
+ @city = tr.cities.find(3)
11
+ @city.fetch
12
+ end
13
+ end
14
+
15
+ subject { @city }
16
+
17
+ its(:id) { should == 3 }
18
+ its(:name) { should == "SF Bay Area" }
19
+ its(:lat) { should be_instance_of(Float) }
20
+ its(:lng) { should be_instance_of(Float) }
21
+ its(:links) { should be_instance_of(Hash) }
22
+ end
23
+
24
+ describe "api endpoints" do
25
+ describe "#all" do
26
+ it "should fetch all cities" do
27
+ tr = Taskrabbit::Api.new
28
+ VCR.use_cassette('cities/all', :record => :new_episodes) do
29
+ cities = nil
30
+ expect { cities = tr.cities }.to_not raise_error
31
+ cities.should == Taskrabbit::City
32
+ cities.count.should > 0
33
+ cities.keys.should == ["items", "links"]
34
+ cities.links
35
+ cities.each do |city|
36
+ city.should be_instance_of Taskrabbit::City
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#find" do
43
+ it "should not fetch if not accessing an existing param" do
44
+ tr = Taskrabbit::Api.new
45
+ city = nil
46
+ expect { city = tr.cities.find(3) }.to_not raise_error
47
+ city.id.should == 3
48
+ end
49
+
50
+ it "should should fetch the city" do
51
+ tr = Taskrabbit::Api.new
52
+ VCR.use_cassette('cities/find', :record => :new_episodes) do
53
+ city = nil
54
+ expect { city = tr.cities.find(3) }.to_not raise_error
55
+ city.id.should == 3
56
+ city.name.should == 'SF Bay Area'
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::Collection do
4
+ subject { Taskrabbit::Collection.new }
5
+
6
+ Taskrabbit::Collection::ARRAY_METHODS.each do |method|
7
+ it "should define #{method}" do
8
+ subject.should_receive(method)
9
+ expect { subject.send(method) }.to_not raise_error
10
+ end
11
+
12
+ it "should call the #{method} on items" do
13
+ subject.items.should_receive(method)
14
+ expect { subject.send(method) }.to_not raise_error
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::Error do
4
+ it "saves the error message" do
5
+ e = Taskrabbit::Error.new('something')
6
+ e.message.should == 'something'
7
+ end
8
+
9
+ it "saves the response" do
10
+ e = Taskrabbit::Error.new('something', {:errors => ['test']})
11
+ e.response.should == {:errors => ['test']}
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::Location do
4
+
5
+ describe "location properties" do
6
+
7
+ before :all do
8
+ tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
9
+ VCR.use_cassette('locations/properties', :record => :new_episodes) do
10
+ @location = tr.account.locations.first
11
+ end
12
+ end
13
+
14
+ subject { @location }
15
+
16
+ its(:id ) { should == 37439 }
17
+ its(:name ) { should == "Home" }
18
+ its(:address ) { should == "432 example" }
19
+ its(:approximate_radius) { should == 0 }
20
+ its(:city ) { should == "San Francisco" }
21
+ its(:zip ) { should == "94123" }
22
+ its(:partial ) { should == "example, San Francisco, Ca 94123" }
23
+ its(:state ) { should == "Ca" }
24
+ its(:complete ) { should == "432 example, San Francisco, Ca 94123" }
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Taskrabbit::Proxy do
4
+
5
+ class Collection
6
+ end
7
+
8
+ subject { Taskrabbit::Proxy.new(anything, Collection) }
9
+
10
+ Taskrabbit::Proxy::COLLECTION_DELEGATE.each do |method|
11
+ it "should define #{method}" do
12
+ subject.should_receive(method)
13
+ expect { subject.send(method) }.to_not raise_error
14
+ end
15
+
16
+ it "should call the #{method} after fetching the collection" do
17
+ the_mock = mock
18
+ the_mock.should_receive(method)
19
+ Collection.should_receive(:all).and_return the_mock
20
+ expect { subject.send(method) }.to_not raise_error
21
+ end
22
+ end
23
+ end