Skip to content

Instantly share code, notes, and snippets.

View lkrych's full-sized avatar

Leland Krych lkrych

  • Cisco
  • San Francisco, CA
View GitHub Profile
@lkrych
lkrych / update_movies.rb
Created October 17, 2016 16:26
Update method pulled from movies_controller
class MoviesController < ApplicationController
#some code
def update
@movie = Movie.find params[:id]
@movie.update_attributes!(movie_params)
flash[:notice] = "#{@movie.title} was successfully updated."
redirect_to movie_path(@movie)
end
@lkrych
lkrych / delete_movies.rb
Created October 17, 2016 16:27
Delete method pulled from movies_controler
class MoviesController < ApplicationController
#some code
def destroy
@movie = Movie.find(params[:id])
@movie.destroy
flash[:notice] = "Movie '#{@movie.title}' deleted."
redirect_to movies_path
end
@lkrych
lkrych / movies_controller_spec.rb
Created October 17, 2016 17:09
How to begin testing the movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
describe "POST #create" do
context "with valid attributes" do
it "saves the new movie in the database" do
end
it "assigns the saved movie to @movie" do
end
it "redirects to the home page" do
@lkrych
lkrych / movies_controller_spec_create.rb
Last active October 17, 2016 17:15
The outline for testing the create function in the movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
describe "POST #create" do
it "saves the new movie in the database" do
end
it "assigns the saved movie to @movie" do
end
it "redirects to the home page" do
@lkrych
lkrych / mock_movie.rb
Last active October 18, 2016 14:48
How to specify a mock in rspec
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
### All the unit tests
end
@lkrych
lkrych / updated_movies_controller_create_spec.rb
Last active October 18, 2016 15:09
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
@lkrych
lkrych / movie_factory.rb
Created October 18, 2016 01:03
Factory for movie to test in movies_controler
FactoryGirl.define do
factory :movie do
id '1'
title 'Blazing Saddles'
rating 'R'
release_date '7/2/1974'
end
end
@lkrych
lkrych / complete_movies_controller_spec.rb
Created October 18, 2016 14:51
Complete spec file that tests CRUD functionality in movies_controller
require_relative '../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
context "with valid attributes" do
@lkrych
lkrych / movies_controller_show_spec.rb
Created October 18, 2016 14:55
Empty RSpec for show functionality
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
describe "GET #show" do
it "assigns the requested movie to @movie" do
end
it "renders the :show template" do
end
@lkrych
lkrych / complete_movies_controller_show_spec.rb
Created October 18, 2016 14:58
Completed RSpec file for testing show functionality of 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 "GET #show" do