1
0

services_controller_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. require 'spec_helper'
  2. describe ServicesController do
  3. before do
  4. sign_in users(:bob)
  5. OmniAuth.config.test_mode = true
  6. request.env["omniauth.auth"] = JSON.parse(File.read(Rails.root.join('spec/data_fixtures/services/twitter.json')))
  7. end
  8. describe "GET index" do
  9. it "only returns sevices of the current user" do
  10. get :index
  11. assigns(:services).all? {|i| i.user.should == users(:bob) }.should == true
  12. end
  13. end
  14. describe "POST toggle_availability" do
  15. it "should work for service of the user" do
  16. post :toggle_availability, :id => services(:generic).to_param
  17. assigns(:service).should eq(services(:generic))
  18. redirect_to(services_path)
  19. end
  20. it "should not work for a service of another user" do
  21. lambda {
  22. post :toggle_availability, :id => services(:global).to_param
  23. }.should raise_error(ActiveRecord::RecordNotFound)
  24. end
  25. end
  26. describe "DELETE destroy" do
  27. it "destroys only services owned by the current user" do
  28. expect {
  29. delete :destroy, :id => services(:generic).to_param
  30. }.to change(Service, :count).by(-1)
  31. lambda {
  32. delete :destroy, :id => services(:global).to_param
  33. }.should raise_error(ActiveRecord::RecordNotFound)
  34. end
  35. end
  36. describe "accepting a callback url" do
  37. it "should update the user's credentials" do
  38. expect {
  39. get :callback, provider: 'twitter'
  40. }.to change { users(:bob).services.count }.by(1)
  41. end
  42. it "should work with an unknown provider (for now)" do
  43. request.env["omniauth.auth"]['provider'] = 'unknown'
  44. expect {
  45. get :callback, provider: 'unknown'
  46. }.to change { users(:bob).services.count }.by(1)
  47. users(:bob).services.first.provider.should == 'unknown'
  48. end
  49. end
  50. end