Skip to content

Instantly share code, notes, and snippets.

@GustavoCaso
Created July 3, 2014 08:03
Show Gist options
  • Save GustavoCaso/2122342c68da9db1c48c to your computer and use it in GitHub Desktop.
Save GustavoCaso/2122342c68da9db1c48c to your computer and use it in GitHub Desktop.
Error with shared examples rspec, always return undefined method id for nil class
require 'spec_helper'
describe ReviewsController do
before(:each) do
signin_user
@video = Fabricate(:video)
end
describe 'Post Create' do
context 'Authenticated user Valid data' do
it 'create a new review with valid data' do
expect{
post :create, review: {rating: "1", description: "icdgivbwi"}, video_id: @video.id
}.to change(Review,:count).by(1)
end
it 'will redirect_to video show after creation' do
post :create, review: {rating: "1", description: "icdgivbwi"}, video_id: @video.id
expect(response).to redirect_to video_path(@video)
end
it 'will fill flash[:info] variable' do
post :create, review: {rating: "1", description: "icdgivbwi"}, video_id: @video.id
expect(flash[:info]).to_not be_empty
end
end
context 'Authenticated user Invalid data' do
it 'will not create a review' do
expect{
post :create, review: {rating: "1"}, video_id: @video.id
}.to_not change(Review,:count)
end
it 'will render videos show' do
post :create, review: {rating: "1"}, video_id: @video.id
expect(response).to render_template 'videos/show'
end
it 'will fill flash[:danger] variable' do
post :create, review: {rating: "1"}, video_id: @video.id
expect(flash[:danger]).to_not be_empty
end
end
it_behaves_like "unauthenticated user" do
let(:action) { post :create, review: {rating: "1", description: "icdgivbwi"}, video_id: @video }
end
end
end
shared_examples "unauthenticated user" do
it "redirect to sigin page if you are not log in" do
logout_user
action
expect(response).to redirect_to signin_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment