From e3091ea907db87d79e1ed184936429efbdcabf21 Mon Sep 17 00:00:00 2001 From: Vincent Coste Date: Mon, 7 Nov 2011 22:41:43 +0100 Subject: [PATCH 1/2] spec added --- .rspec | 2 + Gemfile | 6 ++ Gemfile.lock | 30 +++++++++ lib/foursquare/list.rb | 10 +++ spec/THERE_ARENT_ANY | 4 +- spec/fixtures/item_example.json | 1 + spec/fixtures/list_item_example.json | 1 + spec/fixtures/user_example.json | 1 + spec/fixtures/user_lists_example.json | 1 + spec/quimby/list_item_spec.rb | 75 ++++++++++++++++++++++ spec/quimby/list_spec.rb | 89 +++++++++++++++++++++++++++ spec/quimby/user_spec.rb | 21 +++++++ spec/spec_helper.rb | 21 +++++++ 13 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 spec/fixtures/item_example.json create mode 100644 spec/fixtures/list_item_example.json create mode 100644 spec/fixtures/user_example.json create mode 100644 spec/fixtures/user_lists_example.json create mode 100644 spec/quimby/list_item_spec.rb create mode 100644 spec/quimby/list_spec.rb create mode 100644 spec/quimby/user_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..64ccf3b --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source :rubygems +gemspec + +group :development do + gem 'rspec' +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c044b7a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,30 @@ +PATH + remote: . + specs: + quimby (0.4.4) + json + typhoeus + +GEM + remote: http://rubygems.org/ + specs: + diff-lcs (1.1.2) + json (1.6.1) + mime-types (1.17.2) + rspec (2.5.0) + rspec-core (~> 2.5.0) + rspec-expectations (~> 2.5.0) + rspec-mocks (~> 2.5.0) + rspec-core (2.5.1) + rspec-expectations (2.5.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.5.0) + typhoeus (0.3.2) + mime-types + +PLATFORMS + ruby + +DEPENDENCIES + quimby! + rspec diff --git a/lib/foursquare/list.rb b/lib/foursquare/list.rb index d541cb3..9a04c8d 100644 --- a/lib/foursquare/list.rb +++ b/lib/foursquare/list.rb @@ -26,7 +26,12 @@ def following? @json["following"] end + def followers? + @json["followers"]["count"] != 0 + end + def followers + return [] unless followers? fetch if @json["followers"]["items"].blank? @json["followers"]["items"].map do |user| @@ -34,7 +39,12 @@ def followers end end + def collaborators? + @json["collaborators"]["count"] != 0 + end + def collaborators + return [] unless collaborators? fetch if @json["collaborators"]["items"].blank? @json["collaborators"]["items"].map do |user| diff --git a/spec/THERE_ARENT_ANY b/spec/THERE_ARENT_ANY index cd2b453..74ded94 100644 --- a/spec/THERE_ARENT_ANY +++ b/spec/THERE_ARENT_ANY @@ -1 +1,3 @@ -My bad. Whatevz. \ No newline at end of file +My bad. Whatevz. + +LULZ =) \ No newline at end of file diff --git a/spec/fixtures/item_example.json b/spec/fixtures/item_example.json new file mode 100644 index 0000000..c953cdf --- /dev/null +++ b/spec/fixtures/item_example.json @@ -0,0 +1 @@ +{"id":"t4bccde3770c603bb947898b4","venue":{"id":"4ba2aa53f964a5200e0e38e3","name":"Libre Sens","contact":{},"location":{"address":"33 rue marboeuf","lat":48.869435,"lng":2.305048,"postalCode":"75008","city":"Paris","state":"Ile-de-France"},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French Restaurant","pluralName":"French Restaurants","shortName":"French","icon":"https://foursquare.com/img/categories/food/french.png","parents":["Food"],"primary":true},{"id":"4bf58dd8d48988d1f4941735","name":"Design Studio","pluralName":"Design Studios","shortName":"Design","icon":"https://foursquare.com/img/categories/shops/default.png","parents":["Shops & Services"]},{"id":"4bf58dd8d48988d116941735","name":"Bar","pluralName":"Bars","shortName":"Bar","icon":"https://foursquare.com/img/categories/nightlife/bar.png","parents":["Nightlife Spots"]}],"verified":false,"stats":{"checkinsCount":64,"usersCount":45,"tipCount":6}},"createdAt":1271717431,"todo":false,"done":true,"visitedCount":0,"tip":{"id":"4bccde3770c603bb947898b4","createdAt":1271717431,"text":"Go there for dinner with some friends and ask for the central table in front of the Dj.","status":"done","todo":{"count":2},"done":{"count":3},"user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"}},"listed":{"count":0,"items":[]}} \ No newline at end of file diff --git a/spec/fixtures/list_item_example.json b/spec/fixtures/list_item_example.json new file mode 100644 index 0000000..6270ef7 --- /dev/null +++ b/spec/fixtures/list_item_example.json @@ -0,0 +1 @@ +{"id":"703332/tips","name":"My Tips","description":"","user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"},"editable":false,"public":false,"collaborative":false,"url":"https://foursquare.com/user/703332/list/tips","canonicalUrl":"https://foursquare.com/user/703332/list/tips","doneCount":2,"visitedCount":1,"venueCount":2,"following":false,"followers":{"count":0},"collaborators":{"count":0,"items":[]},"listItems":{"count":2,"items":[{"id":"t4bccde3770c603bb947898b4","venue":{"id":"4ba2aa53f964a5200e0e38e3","name":"Libre Sens","contact":{},"location":{"address":"33 rue marboeuf","lat":48.869435,"lng":2.305048,"postalCode":"75008","city":"Paris","state":"Ile-de-France"},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French Restaurant","pluralName":"French Restaurants","shortName":"French","icon":"https://foursquare.com/img/categories/food/french.png","parents":["Food"],"primary":true},{"id":"4bf58dd8d48988d1f4941735","name":"Design Studio","pluralName":"Design Studios","shortName":"Design","icon":"https://foursquare.com/img/categories/shops/default.png","parents":["Shops & Services"]},{"id":"4bf58dd8d48988d116941735","name":"Bar","pluralName":"Bars","shortName":"Bar","icon":"https://foursquare.com/img/categories/nightlife/bar.png","parents":["Nightlife Spots"]}],"verified":false,"stats":{"checkinsCount":64,"usersCount":45,"tipCount":6}},"createdAt":1271717431,"todo":false,"done":true,"visitedCount":0,"tip":{"id":"4bccde3770c603bb947898b4","createdAt":1271717431,"text":"Go there for dinner with some friends and ask for the central table in front of the Dj.","status":"done","todo":{"count":2},"done":{"count":3},"user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"}},"listed":{"count":0,"items":[]}},{"id":"t4bccdd6970c603bb7f7898b4","venue":{"id":"4adcda07f964a5201f3321e3","name":"Social Club","contact":{"twitter":"ParisSocialClub"},"location":{"address":"142 Rue Montmartre","lat":48.868949291982865,"lng":2.3430919647216797,"postalCode":"75002","city":"Paris","state":"Île de France","country":"France"},"categories":[{"id":"4bf58dd8d48988d11f941735","name":"Nightclub","pluralName":"Nightclubs","shortName":"Nightclub / Discotheque","icon":"https://foursquare.com/img/categories/nightlife/danceparty.png","parents":["Nightlife Spots"],"primary":true},{"id":"4bf58dd8d48988d116941735","name":"Bar","pluralName":"Bars","shortName":"Bar","icon":"https://foursquare.com/img/categories/nightlife/bar.png","parents":["Nightlife Spots"]},{"id":"4bf58dd8d48988d1da941735","name":"Concert Hall","pluralName":"Concert Halls","shortName":"Concert Hall","icon":"https://foursquare.com/img/categories/nightlife/musicvenue.png","parents":["Nightlife Spots","Music Venues"]}],"verified":false,"stats":{"checkinsCount":1261,"usersCount":706,"tipCount":26},"url":"http://parissocialclub.com"},"createdAt":1271717225,"todo":false,"done":true,"visitedCount":4,"tip":{"id":"4bccdd6970c603bb7f7898b4","createdAt":1271717225,"text":"Just go there and enjoy some good electro music!","status":"done","todo":{"count":2},"done":{"count":4},"user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"}},"listed":{"count":0,"items":[]}}]}} \ No newline at end of file diff --git a/spec/fixtures/user_example.json b/spec/fixtures/user_example.json new file mode 100644 index 0000000..3354feb --- /dev/null +++ b/spec/fixtures/user_example.json @@ -0,0 +1 @@ +{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self","type":"user","pings":false,"contact":{"email":"coste.vincent@gmail.com","twitter":"patothon","facebook":"591628902"},"badges":{"count":11},"mayorships":{"count":3,"items":[]},"checkins":{"count":233,"items":[{"id":"4e74bd3045ddd4323f6823c4","createdAt":1316273456,"type":"checkin","timeZone":"Europe/Paris","venue":{"id":"4c8a35721eafb1f780017835","name":"Le Camping","contact":{},"location":{"address":"Place de la Bourse","lat":48.869280981712926,"lng":2.3417186737060547,"postalCode":"75002","city":"Paris","state":"Ile-de-France"},"categories":[{"id":"4bf58dd8d48988d125941735","name":"Tech Startup","pluralName":"Tech Startups","shortName":"Tech Startup","icon":"https://foursquare.com/img/categories/building/default.png","parents":["Professional & Other Places","Offices"],"primary":true},{"id":"4bf58dd8d48988d174941735","name":"Coworking Space","pluralName":"Coworking Spaces","shortName":"Coworking Space","icon":"https://foursquare.com/img/categories/building/default.png","parents":["Professional & Other Places","Offices"]}],"verified":false,"stats":{"checkinsCount":812,"usersCount":261,"tipCount":4}},"event":{"id":"4e74b20c1fc77084d10c53cd","name":"foursquare global hackathon","foreignIds":{"count":0,"items":[]}}}]},"friends":{"count":39,"groups":[{"type":"others","name":"Other friends","count":39,"items":[]}]},"following":{"count":0},"requests":{"count":2},"tips":{"count":2},"todos":{"count":3},"scores":{"recent":68,"max":91,"checkinsCount":16}} \ No newline at end of file diff --git a/spec/fixtures/user_lists_example.json b/spec/fixtures/user_lists_example.json new file mode 100644 index 0000000..6e787fc --- /dev/null +++ b/spec/fixtures/user_lists_example.json @@ -0,0 +1 @@ +{"lists":{"groups":[{"type":"todos","count":1,"items":[{"id":"703332/todos","name":"My To-Do List","description":"","user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"},"editable":false,"public":false,"collaborative":false,"url":"https://foursquare.com/user/703332/list/todos","canonicalUrl":"https://foursquare.com/user/703332/list/todos","followers":{"count":0},"listItems":{"count":3}}]},{"type":"created","name":"Lists I created","count":1,"items":[{"id":"4e7632de1838f9188a2dfe78","name":"date spots","description":"","user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"},"editable":true,"public":true,"collaborative":false,"url":"https://foursquare.com/patothon/list/date-spots","canonicalUrl":"https://foursquare.com/patothon/list/date-spots","createdAt":1316369118,"updatedAt":1316369126,"followers":{"count":0},"listItems":{"count":1}}]},{"type":"edited","name":"Lists I am helping friends make","count":1,"items":[{"id":"4e661678c65b2dc8a1270a73","name":"burgers in Paris","description":"Some places to eat good burgers in Paris","user":{"id":"162808","firstName":"Olivier","lastName":"Desmoulin","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/BY5Q0DA1PIG5YALV.png","gender":"male","homeCity":"Paris, France","relationship":"friend"},"editable":true,"public":true,"collaborative":true,"url":"https://foursquare.com/odesmoulin/list/burgers-in-paris","canonicalUrl":"https://foursquare.com/odesmoulin/list/burgers-in-paris","createdAt":1315313272,"updatedAt":1316253363,"photo":{"id":"4d4be13f38bc2da13ad33573","createdAt":1296818495,"url":"https://playfoursquare.s3.amazonaws.com/pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ.jpg","sizes":{"count":4,"items":[{"url":"https://playfoursquare.s3.amazonaws.com/pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ.jpg","width":537,"height":720},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ_300x300.jpg","width":300,"height":300},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ_100x100.jpg","width":100,"height":100},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ_36x36.jpg","width":36,"height":36}]},"user":{"id":"422771","firstName":"Herve","lastName":"P.","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/4QX3SF0QTPKPQM3H.jpg","gender":"male","homeCity":"Paris, France"},"visibility":"public"},"followers":{"count":12},"listItems":{"count":10}}]},{"type":"followed","name":"Lists I follow","count":1,"items":[{"id":"4e661678c65b2dc8a1270a73","name":"burgers in Paris","description":"Some places to eat good burgers in Paris","user":{"id":"162808","firstName":"Olivier","lastName":"Desmoulin","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/BY5Q0DA1PIG5YALV.png","gender":"male","homeCity":"Paris, France","relationship":"friend"},"editable":true,"public":true,"collaborative":true,"url":"https://foursquare.com/odesmoulin/list/burgers-in-paris","canonicalUrl":"https://foursquare.com/odesmoulin/list/burgers-in-paris","createdAt":1315313272,"updatedAt":1316253363,"photo":{"id":"4d4be13f38bc2da13ad33573","createdAt":1296818495,"url":"https://playfoursquare.s3.amazonaws.com/pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ.jpg","sizes":{"count":4,"items":[{"url":"https://playfoursquare.s3.amazonaws.com/pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ.jpg","width":537,"height":720},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ_300x300.jpg","width":300,"height":300},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ_100x100.jpg","width":100,"height":100},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YZ0SATBBB0YF34C0FYCENELJQKTLEEXFDKLEEPTBDPSQ2VRJ_36x36.jpg","width":36,"height":36}]},"user":{"id":"422771","firstName":"Herve","lastName":"P.","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/4QX3SF0QTPKPQM3H.jpg","gender":"male","homeCity":"Paris, France"},"visibility":"public"},"followers":{"count":12},"listItems":{"count":10}}]},{"type":"suggested","name":"Suggested Lists","items":[{"id":"4e3022b6922e47c929276721","name":"Architecture in NYC","description":"buildings that make me love New York. friends will make the magic happens also (with tips and photos, because they are good friends).","user":{"id":"21366","firstName":"Pierre","lastName":"Valade","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/GS4IUGRUPJRTXWRB.jpg","gender":"male","homeCity":"paris, France","relationship":"friend"},"editable":true,"public":true,"collaborative":true,"url":"https://foursquare.com/pierrevalade/list/architecture-in-nyc","canonicalUrl":"https://foursquare.com/pierrevalade/list/architecture-in-nyc","createdAt":1311777462,"updatedAt":1313940672,"photo":{"id":"4e237313628469a5742ac817","createdAt":1310946067,"url":"https://playfoursquare.s3.amazonaws.com/pix/YTIA1KC2LZFDSDQAXIJQQWSC4XO3LVHJIUAC4FSQHAN312NJ.jpg","sizes":{"count":4,"items":[{"url":"https://playfoursquare.s3.amazonaws.com/pix/YTIA1KC2LZFDSDQAXIJQQWSC4XO3LVHJIUAC4FSQHAN312NJ.jpg","width":612,"height":612},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YTIA1KC2LZFDSDQAXIJQQWSC4XO3LVHJIUAC4FSQHAN312NJ_300x300.jpg","width":300,"height":300},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YTIA1KC2LZFDSDQAXIJQQWSC4XO3LVHJIUAC4FSQHAN312NJ_100x100.jpg","width":100,"height":100},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/YTIA1KC2LZFDSDQAXIJQQWSC4XO3LVHJIUAC4FSQHAN312NJ_36x36.jpg","width":36,"height":36}]},"user":{"id":"21366","firstName":"Pierre","lastName":"Valade","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/GS4IUGRUPJRTXWRB.jpg","gender":"male","homeCity":"paris, France","relationship":"friend"},"visibility":"public"},"followers":{"count":33},"listItems":{"count":34}},{"id":"4e05359b8877394591d81808","name":"NYC Bars","description":"","user":{"id":"21366","firstName":"Pierre","lastName":"Valade","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/GS4IUGRUPJRTXWRB.jpg","gender":"male","homeCity":"paris, France","relationship":"friend"},"editable":false,"public":true,"collaborative":false,"url":"https://foursquare.com/pierrevalade/list/nyc-bars","canonicalUrl":"https://foursquare.com/pierrevalade/list/nyc-bars","createdAt":1308964251,"updatedAt":1313692771,"photo":{"id":"4defa43840a3b72344411729","createdAt":1307550776,"url":"https://playfoursquare.s3.amazonaws.com/pix/1TKUACMVUQ2KDQFQODNCSUW2WTSVWLJPBTWSGF5P0GELJK3E.jpg","sizes":{"count":4,"items":[{"url":"https://playfoursquare.s3.amazonaws.com/pix/1TKUACMVUQ2KDQFQODNCSUW2WTSVWLJPBTWSGF5P0GELJK3E.jpg","width":480,"height":720},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/1TKUACMVUQ2KDQFQODNCSUW2WTSVWLJPBTWSGF5P0GELJK3E_300x300.jpg","width":300,"height":300},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/1TKUACMVUQ2KDQFQODNCSUW2WTSVWLJPBTWSGF5P0GELJK3E_100x100.jpg","width":100,"height":100},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/1TKUACMVUQ2KDQFQODNCSUW2WTSVWLJPBTWSGF5P0GELJK3E_36x36.jpg","width":36,"height":36}]},"user":{"id":"564266","firstName":"Robert","lastName":"R.","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AZX2XBEKBGUHMIKD.png","gender":"male","homeCity":"Palo Alto, CA"},"visibility":"public"},"followers":{"count":5},"listItems":{"count":22}},{"id":"4e307e1a52b1a638f0ff5757","name":"No Reservations","description":"Travel tips from No Reservations, hosted by Anthony Bourdain on Travel Channel.","user":{"id":"4579353","firstName":"Travel Channel","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/LJL3OPUPJLS2MALA.png","gender":"none","homeCity":"Everywhere, United States"},"editable":false,"public":true,"collaborative":false,"url":"https://foursquare.com/travelchannel/list/no-reservations","canonicalUrl":"https://foursquare.com/travelchannel/list/no-reservations","createdAt":1311800858,"updatedAt":1312493413,"photo":{"id":"4e3b0f2b3151eaa7c4399da3","createdAt":1312493355,"url":"https://playfoursquare.s3.amazonaws.com/pix/NV3VQVDFJZLUJVCWF13DJAN1JGZ4I400SQ1Z2BVETFIXG2TP.jpg","sizes":{"count":4,"items":[{"url":"https://playfoursquare.s3.amazonaws.com/pix/NV3VQVDFJZLUJVCWF13DJAN1JGZ4I400SQ1Z2BVETFIXG2TP.jpg","width":596,"height":334},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/NV3VQVDFJZLUJVCWF13DJAN1JGZ4I400SQ1Z2BVETFIXG2TP_300x300.jpg","width":300,"height":300},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/NV3VQVDFJZLUJVCWF13DJAN1JGZ4I400SQ1Z2BVETFIXG2TP_100x100.jpg","width":100,"height":100},{"url":"https://playfoursquare.s3.amazonaws.com/derived_pix/NV3VQVDFJZLUJVCWF13DJAN1JGZ4I400SQ1Z2BVETFIXG2TP_36x36.jpg","width":36,"height":36}]},"user":{"id":"4579353","firstName":"Travel Channel","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/LJL3OPUPJLS2MALA.png","gender":"none","homeCity":"Everywhere, United States"},"visibility":"public"},"followers":{"count":913},"listItems":{"count":34}}]},{"type":"dones","count":2,"items":[{"id":"703332/tips","name":"My Tips","description":"","user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"},"editable":false,"public":false,"collaborative":false,"url":"https://foursquare.com/user/703332/list/tips","canonicalUrl":"https://foursquare.com/user/703332/list/tips","followers":{"count":0},"listItems":{"count":2}},{"id":"703332/dones","name":"My \"done\" List","description":"","user":{"id":"703332","firstName":"Vincent","lastName":"Coste","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/AB5K14C5NQP3KJNV.jpg","gender":"male","homeCity":"Paris, Ile-de-France","relationship":"self"},"editable":false,"public":false,"collaborative":false,"url":"https://foursquare.com/user/703332/list/dones","canonicalUrl":"https://foursquare.com/user/703332/list/dones","followers":{"count":0},"listItems":{"count":14}}]}]}} \ No newline at end of file diff --git a/spec/quimby/list_item_spec.rb b/spec/quimby/list_item_spec.rb new file mode 100644 index 0000000..0967b86 --- /dev/null +++ b/spec/quimby/list_item_spec.rb @@ -0,0 +1,75 @@ +# some mixins over here (to be able to use Object#blank?() for example) +require "spec_helper" + +describe Foursquare::ListItem do + + before(:each) do + @json_item = JSON.parse(File.open("spec/fixtures/item_example.json", "rb") do | file | + file.read + end) + @foursquare = Foursquare::Base.new("ACCESS_TOKEN") + @item = Foursquare::ListItem.new(@foursquare, @json_item) + end + + + + describe "Atomic Attributes" do + + it "should not be done" do + + end + + it "should have a venue" do + @item.venue.should_not be_nil + @item.venue.id.should eql("4ba2aa53f964a5200e0e38e3") + end + + it "should have a tip" do + @item.tip.text.should eql("Go there for dinner with some friends and ask for the central table in front of the Dj.") + end + + it "should not have a note" do + pending + #@item.note.should be_nil + end + + + it "should have been created at 1271717431" do + pending + #@item.created_at.should eql(1271717431) + end + + it "should not wanted to be done" do + @item.todo?.should be_false + end + + it "should be done" do + @item.done?.should be_true + end + + it "should have visited by 0 people" do + pending + #@item.visited_count.should eql(0) + end + + it "should not have a photo" do + pending + #@item.photo.should be_nil + end + + end + + + describe "Composed Attributes" do + + it "should not be listed" do + pending + end + + it "should have an user" do + @item.user.should_not be_nil + end + + end + +end \ No newline at end of file diff --git a/spec/quimby/list_spec.rb b/spec/quimby/list_spec.rb new file mode 100644 index 0000000..bd0fce5 --- /dev/null +++ b/spec/quimby/list_spec.rb @@ -0,0 +1,89 @@ +# some mixins over here (to be able to use Object#blank?() for example) +require 'spec_helper' + + + +describe Foursquare::List do + + before(:each) do + @json_item = JSON.parse(File.open("spec/fixtures/list_item_example.json", "rb") do | file | + file.read + end) + @foursquare = Foursquare::Base.new("ACCESS_TOKEN") + @list = Foursquare::List.new(@foursquare, @json_item) + end + + + describe "Atomical Attributes" do + + it "should get an id" do + @list.id.should eql("703332/tips") + end + + it "should get a name" do + @list.name.should eql("My Tips") + end + + it "should get a description" do + @list.description.should eql("") + end + + it "should not be editable" do + @list.editable?.should eql(false) + end + + it "should not be collaborative" do + @list.collaborative?.should eql(false) + end + + it "should get canonicalUrl" do + @list.canonical_url.should eql("https://foursquare.com/user/703332/list/tips") + end + + it "should get done count" do + @list.done_count.should eql(2) + end + + it "should get visited count" do + @list.visited_count.should eql(1) + end + + it "should have 2 venues" do + @list.venue_count.should eql(2) + end + + + it "should not get photo" do + @list.photo.should_not be_nil + end + + it "should have no followers" do + @list.followers?.should be_false + end + + end + + describe "Composed Attributes" do + + it "should have a user" do + @list.user.first_name.should eql("Vincent") + @list.user.last_name.should eql("Coste") + end + + it "should have 0 followers" do + @list.should have(0).followers + end + + it "should have 0 collaborators" do + @list.should have(0).collaborators + end + + it "should have 2 items" do + @list.should have(2).list_items + @list.list_items[0].id.should eql("t4bccde3770c603bb947898b4") + @list.list_items[1].id.should eql("t4bccdd6970c603bb7f7898b4") + end + + end + +end \ No newline at end of file diff --git a/spec/quimby/user_spec.rb b/spec/quimby/user_spec.rb new file mode 100644 index 0000000..627edc3 --- /dev/null +++ b/spec/quimby/user_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + + +describe Foursquare::User do + + before(:each) do + @json_item = JSON.parse(get_file("spec/fixtures/user_example.json")) + @foursquare = Foursquare::Base.new("X1RBNDKTKO3DJY13PUQIGJDU2YQQ3KXL1KPO1UB2M5LAUPFB") + #@foursquare.stub(:get).with("users/703332/lists", {:group=>{}}).and_return(JSON.parse(get_file("spec/fixtures/user_lists_example.json"))) + @user = Foursquare::User.new(@foursquare, @json_item) + end + + describe "Composed Attributes" do + it "should fetch lists without group" do + pending + # @user.lists[0].name.should eql("My To-Do List") + # @user.lists[1].id.should eql("4e7632de1838f9188a2dfe78") + # @user.lists[2].description.should eql("Some places to eat good burgers in Paris") + end + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..35b34dd --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,21 @@ +require 'rubygems' +require 'bundler/setup' +require 'rspec' +require 'quimby' + +RSpec.configure do |config| + + +end + +def get_file(path) + File.open(path, "rb") do | file | + file.read + end +end + +class Object + def blank? + respond_to?(:empty?) ? empty? : !self + end +end \ No newline at end of file From aa09c57f29f75d147b301e6b95a4f21f9f88cce1 Mon Sep 17 00:00:00 2001 From: Vincent Coste Date: Mon, 7 Nov 2011 22:44:38 +0100 Subject: [PATCH 2/2] forgot stub --- spec/quimby/user_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/quimby/user_spec.rb b/spec/quimby/user_spec.rb index 627edc3..7a6e8e0 100644 --- a/spec/quimby/user_spec.rb +++ b/spec/quimby/user_spec.rb @@ -6,7 +6,7 @@ before(:each) do @json_item = JSON.parse(get_file("spec/fixtures/user_example.json")) @foursquare = Foursquare::Base.new("X1RBNDKTKO3DJY13PUQIGJDU2YQQ3KXL1KPO1UB2M5LAUPFB") - #@foursquare.stub(:get).with("users/703332/lists", {:group=>{}}).and_return(JSON.parse(get_file("spec/fixtures/user_lists_example.json"))) + @foursquare.stub(:get).with("users/703332/lists", {:group=>{}}).and_return(JSON.parse(get_file("spec/fixtures/user_lists_example.json"))) @user = Foursquare::User.new(@foursquare, @json_item) end