Skip to content

Instantly share code, notes, and snippets.

@lkrych
Created October 18, 2016 15:15
Show Gist options
  • Save lkrych/9841bf88df3f8dbf4909b75ff3ae124e to your computer and use it in GitHub Desktop.
Save lkrych/9841bf88df3f8dbf4909b75ff3ae124e to your computer and use it in GitHub Desktop.
Complete RSpec file to test the delete method in the movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
before (:each) do
@mock_movie_attributes = {:title => 'Space Balls', :release_date => '24/6/1987', :rating => 'PG'}
@mock_movie = FactoryGirl.create(:movie)
end
describe "DELETE #destroy" do
it "deletes the movie" do
expect{
delete :destroy, id: @mock_movie
}.to change(Movie,:count).by(-1)
end
it "redirects to the main page " do
delete :destroy, id: @mock_movie
expect(response).to redirect_to(:action => 'index')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment