Last active
          October 18, 2016 15:09 
        
      - 
      
- 
        Save lkrych/20a98e53e519a288dc17b1d586f8760e to your computer and use it in GitHub Desktop. 
    Test the basic functionality of the movies_controller create function
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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