services_controller_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require 'rails_helper'
  2. describe ServicesController do
  3. before do
  4. sign_in users(:bob)
  5. end
  6. describe "GET index" do
  7. it "only returns sevices of the current user" do
  8. get :index
  9. expect(assigns(:services).all? {|i| expect(i.user).to eq(users(:bob)) }).to eq(true)
  10. end
  11. end
  12. describe "POST toggle_availability" do
  13. it "should work for service of the user" do
  14. post :toggle_availability, params: {:id => services(:generic).to_param}
  15. expect(assigns(:service)).to eq(services(:generic))
  16. redirect_to(services_path)
  17. end
  18. it "should not work for a service of another user" do
  19. expect {
  20. post :toggle_availability, params: {:id => services(:global).to_param}
  21. }.to raise_error(ActiveRecord::RecordNotFound)
  22. end
  23. end
  24. describe "DELETE destroy" do
  25. it "destroys only services owned by the current user" do
  26. expect {
  27. delete :destroy, params: {:id => services(:generic).to_param}
  28. }.to change(Service, :count).by(-1)
  29. expect {
  30. delete :destroy, params: {:id => services(:global).to_param}
  31. }.to raise_error(ActiveRecord::RecordNotFound)
  32. end
  33. end
  34. end