/spec/instagram/client/users_spec.rb

https://github.com/mizzy/instagram-ruby-gem · Ruby · 400 lines · 324 code · 76 blank · 0 comment · 14 complexity · 8d26c72fb49d56f41cc615dbc16e8f3d MD5 · raw file

  1. require File.expand_path('../../../spec_helper', __FILE__)
  2. describe Instagram::Client do
  3. Instagram::Configuration::VALID_FORMATS.each do |format|
  4. context ".new(:format => '#{format}')" do
  5. before do
  6. @client = Instagram::Client.new(:format => format, :client_id => 'CID', :client_secret => 'CS', :access_token => 'AT')
  7. end
  8. describe ".user" do
  9. context "with user ID passed" do
  10. before do
  11. stub_get("users/4.#{format}").
  12. with(:query => {:access_token => @client.access_token}).
  13. to_return(:body => fixture("mikeyk.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  14. end
  15. it "should get the correct resource" do
  16. @client.user(4)
  17. a_get("users/4.#{format}").
  18. with(:query => {:access_token => @client.access_token}).
  19. should have_been_made
  20. end
  21. it "should return extended information of a given user" do
  22. user = @client.user(4)
  23. user.full_name.should == "Mike Krieger"
  24. end
  25. end
  26. context "without user ID passed" do
  27. before do
  28. stub_get("users/self.#{format}").
  29. with(:query => {:access_token => @client.access_token}).
  30. to_return(:body => fixture("shayne.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  31. end
  32. it "should get the correct resource" do
  33. @client.user()
  34. a_get("users/self.#{format}").
  35. with(:query => {:access_token => @client.access_token}).
  36. should have_been_made
  37. end
  38. end
  39. end
  40. describe ".user_search" do
  41. before do
  42. stub_get("users/search.#{format}").
  43. with(:query => {:access_token => @client.access_token}).
  44. with(:query => {:q => "Shayne Sweeney"}).
  45. to_return(:body => fixture("user_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  46. end
  47. it "should get the correct resource" do
  48. @client.user_search("Shayne Sweeney")
  49. a_get("users/search.#{format}").
  50. with(:query => {:access_token => @client.access_token}).
  51. with(:query => {:q => "Shayne Sweeney"}).
  52. should have_been_made
  53. end
  54. it "should return an array of user search results" do
  55. users = @client.user_search("Shayne Sweeney")
  56. users.should be_a Array
  57. users.first.username.should == "shayne"
  58. end
  59. end
  60. describe ".user_follows" do
  61. context "with user ID passed" do
  62. before do
  63. stub_get("users/4/follows.#{format}").
  64. with(:query => {:access_token => @client.access_token}).
  65. to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  66. end
  67. it "should get the correct resource" do
  68. @client.user_follows(4)
  69. a_get("users/4/follows.#{format}").
  70. with(:query => {:access_token => @client.access_token}).
  71. should have_been_made
  72. end
  73. it "should return a list of users whom a given user follows" do
  74. follows = @client.user_follows(4)
  75. follows.should be_a Array
  76. follows.first.username.should == "heartsf"
  77. end
  78. end
  79. context "without user ID passed" do
  80. before do
  81. stub_get("users/self/follows.#{format}").
  82. with(:query => {:access_token => @client.access_token}).
  83. to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  84. end
  85. it "should get the correct resource" do
  86. @client.user_follows
  87. a_get("users/self/follows.#{format}").
  88. with(:query => {:access_token => @client.access_token}).
  89. should have_been_made
  90. end
  91. end
  92. end
  93. describe ".user_followed_by" do
  94. context "with user ID passed" do
  95. before do
  96. stub_get("users/4/followed-by.#{format}").
  97. with(:query => {:access_token => @client.access_token}).
  98. to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  99. end
  100. it "should get the correct resource" do
  101. @client.user_followed_by(4)
  102. a_get("users/4/followed-by.#{format}").
  103. with(:query => {:access_token => @client.access_token}).
  104. should have_been_made
  105. end
  106. it "should return a list of users whom a given user is followed by" do
  107. followed_by = @client.user_followed_by(4)
  108. followed_by.should be_a Array
  109. followed_by.first.username.should == "bojieyang"
  110. end
  111. end
  112. context "without user ID passed" do
  113. before do
  114. stub_get("users/self/followed-by.#{format}").
  115. with(:query => {:access_token => @client.access_token}).
  116. to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  117. end
  118. it "should get the correct resource" do
  119. @client.user_followed_by
  120. a_get("users/self/followed-by.#{format}").
  121. with(:query => {:access_token => @client.access_token}).
  122. should have_been_made
  123. end
  124. end
  125. end
  126. describe ".user_media_feed" do
  127. before do
  128. stub_get("users/self/feed.#{format}").
  129. with(:query => {:access_token => @client.access_token}).
  130. to_return(:body => fixture("user_media_feed.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  131. end
  132. it "should get the correct resource" do
  133. @client.user_media_feed
  134. a_get("users/self/feed.#{format}").
  135. with(:query => {:access_token => @client.access_token}).
  136. should have_been_made
  137. end
  138. end
  139. describe ".user_liked_media" do
  140. before do
  141. stub_get("users/self/media/liked.#{format}").
  142. with(:query => {:access_token => @client.access_token}).
  143. to_return(:body => fixture("liked_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  144. end
  145. it "should get the correct resource" do
  146. @client.user_liked_media
  147. a_get("users/self/media/liked.#{format}").
  148. with(:query => {:access_token => @client.access_token}).
  149. should have_been_made
  150. end
  151. end
  152. describe ".user_recent_media" do
  153. context "with user ID passed" do
  154. before do
  155. stub_get("users/4/media/recent.#{format}").
  156. with(:query => {:access_token => @client.access_token}).
  157. to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  158. end
  159. it "should get the correct resource" do
  160. @client.user_recent_media(4)
  161. a_get("users/4/media/recent.#{format}").
  162. with(:query => {:access_token => @client.access_token}).
  163. should have_been_made
  164. end
  165. it "should return a list of recent media items for the given user" do
  166. recent_media = @client.user_recent_media(4)
  167. recent_media.should be_a Array
  168. recent_media.first.user.username.should == "shayne"
  169. end
  170. end
  171. context "without user ID passed" do
  172. before do
  173. stub_get("users/self/media/recent.#{format}").
  174. with(:query => {:access_token => @client.access_token}).
  175. to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  176. end
  177. it "should get the correct resource" do
  178. @client.user_recent_media
  179. a_get("users/self/media/recent.#{format}").
  180. with(:query => {:access_token => @client.access_token}).
  181. should have_been_made
  182. end
  183. end
  184. end
  185. describe ".user_requested_by" do
  186. before do
  187. stub_get("users/self/requested-by.#{format}").
  188. with(:query => {:access_token => @client.access_token}).
  189. to_return(:body => fixture("requested_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  190. end
  191. it "should get the correct resource" do
  192. @client.user_requested_by
  193. a_get("users/self/requested-by.#{format}").
  194. with(:query => {:access_token => @client.access_token}).
  195. should have_been_made
  196. end
  197. it "should return a list of users awaiting approval" do
  198. users = @client.user_requested_by
  199. users.should be_a Array
  200. users.first.username.should == "shayne"
  201. end
  202. end
  203. describe ".user_relationship" do
  204. before do
  205. stub_get("users/4/relationship.#{format}").
  206. with(:query => {:access_token => @client.access_token}).
  207. to_return(:body => fixture("relationship.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  208. end
  209. it "should get the correct resource" do
  210. @client.user_relationship(4)
  211. a_get("users/4/relationship.#{format}").
  212. with(:query => {:access_token => @client.access_token}).
  213. should have_been_made
  214. end
  215. it "should return a relationship status response" do
  216. status = @client.user_relationship(4)
  217. status.incoming_status.should == "requested_by"
  218. end
  219. end
  220. describe ".follow_user" do
  221. before do
  222. stub_post("users/4/relationship.#{format}").
  223. with(:body => {:action => "follow", :access_token => @client.access_token}).
  224. to_return(:body => fixture("follow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  225. end
  226. it "should get the correct resource" do
  227. @client.follow_user(4)
  228. a_post("users/4/relationship.#{format}").
  229. with(:body => {:action => "follow", :access_token => @client.access_token}).
  230. should have_been_made
  231. end
  232. it "should return a relationship status response" do
  233. status = @client.follow_user(4)
  234. status.outgoing_status.should == "requested"
  235. end
  236. end
  237. describe ".unfollow_user" do
  238. before do
  239. stub_post("users/4/relationship.#{format}").
  240. with(:body => {:action => "unfollow", :access_token => @client.access_token}).
  241. to_return(:body => fixture("unfollow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  242. end
  243. it "should get the correct resource" do
  244. @client.unfollow_user(4)
  245. a_post("users/4/relationship.#{format}").
  246. with(:body => {:action => "unfollow", :access_token => @client.access_token}).
  247. should have_been_made
  248. end
  249. it "should return a relationship status response" do
  250. status = @client.unfollow_user(4)
  251. status.outgoing_status.should == "none"
  252. end
  253. end
  254. describe ".block_user" do
  255. before do
  256. stub_post("users/4/relationship.#{format}").
  257. with(:body => {:action => "block", :access_token => @client.access_token}).
  258. to_return(:body => fixture("block_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  259. end
  260. it "should get the correct resource" do
  261. @client.block_user(4)
  262. a_post("users/4/relationship.#{format}").
  263. with(:body => {:action => "block", :access_token => @client.access_token}).
  264. should have_been_made
  265. end
  266. it "should return a relationship status response" do
  267. status = @client.block_user(4)
  268. status.outgoing_status.should == "none"
  269. end
  270. end
  271. describe ".unblock_user" do
  272. before do
  273. stub_post("users/4/relationship.#{format}").
  274. with(:body => {:action => "unblock", :access_token => @client.access_token}).
  275. to_return(:body => fixture("unblock_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  276. end
  277. it "should get the correct resource" do
  278. @client.unblock_user(4)
  279. a_post("users/4/relationship.#{format}").
  280. with(:body => {:action => "unblock", :access_token => @client.access_token}).
  281. should have_been_made
  282. end
  283. it "should return a relationship status response" do
  284. status = @client.unblock_user(4)
  285. status.outgoing_status.should == "none"
  286. end
  287. end
  288. describe ".approve_user" do
  289. before do
  290. stub_post("users/4/relationship.#{format}").
  291. with(:body => {:action => "approve", :access_token => @client.access_token}).
  292. to_return(:body => fixture("approve_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  293. end
  294. it "should get the correct resource" do
  295. @client.approve_user(4)
  296. a_post("users/4/relationship.#{format}").
  297. with(:body => {:action => "approve", :access_token => @client.access_token}).
  298. should have_been_made
  299. end
  300. it "should return a relationship status response" do
  301. status = @client.approve_user(4)
  302. status.outgoing_status.should == "follows"
  303. end
  304. end
  305. describe ".deny_user" do
  306. before do
  307. stub_post("users/4/relationship.#{format}").
  308. with(:body => {:action => "deny", :access_token => @client.access_token}).
  309. to_return(:body => fixture("deny_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  310. end
  311. it "should get the correct resource" do
  312. @client.deny_user(4)
  313. a_post("users/4/relationship.#{format}").
  314. with(:body => {:action => "deny", :access_token => @client.access_token}).
  315. should have_been_made
  316. end
  317. it "should return a relationship status response" do
  318. status = @client.deny_user(4)
  319. status.outgoing_status.should == "none"
  320. end
  321. end
  322. end
  323. end
  324. end