Skip to content

Instantly share code, notes, and snippets.

@lkrych
Last active October 18, 2016 15:09
Show Gist options
  • Save lkrych/20a98e53e519a288dc17b1d586f8760e to your computer and use it in GitHub Desktop.
Save lkrych/20a98e53e519a288dc17b1d586f8760e to your computer and use it in GitHub Desktop.
Test the basic functionality of the movies_controller create function
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 "POST #create" do
it "saves the new movie in the database" do
expect {
post :create, movie: @mock_movie_attributes
}.to change(Movie,:count).by(1)
end
it "assigns the saved movie to @movie" do
post :create, movie: @mock_movie_attributes
expect(assigns(:movie).title).to include("Space Balls")
end
it "redirects to the home page" do
post :create, movie: @mock_movie_attributes
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