what is the wrong with this spec and controller code?
- by user1609468
I'm trying to test an existing rails project with rspec. And I want to test a controller but getting an error which I can't solve :S
Here is the my spec code ;
require 'spec_helper'
describe BriefNotesController do
before(:all) do
@customer=Factory(:customer)
@project=Factory(:project_started, :owner => @customer)
end
context 'get :new' do
it 'should redirect to login page for not signed in users' do
get :new, :project_id => @project.id
response.should redirect_to("/kullanici-girisi")
end
it 'should be success and render new brief note page for project owner' do
sign_in @customer
get :new, :project_id => @project.id
response.should be_success
end
end
end
Here is the my controller code ;
class BriefNotesController < ApplicationController
before_filter :authenticate_user!
before_filter :find_project
def new
@brief_note = @project.brief_notes.new
end
def create
@brief_note = @project.brief_notes.build(params[:brief_note])
if @brief_note.save
redirect_to brief_project_path(@project)
else
render :action => :new
end
end
private
def find_project
@project = current_user.projects.find_by_cached_slug([params[:project_id]])
end
end
I think current_user.projects.find_by_cached_slug method don't work. So this is the error;
Failures:
1) BriefNotesController get :new should be success and render new brief note page for project owner
Failure/Error: get :new, :project_id => @project.id
NoMethodError:
undefined method `brief_notes' for nil:NilClass
# ./app/controllers/brief_notes_controller.rb:6:in `new'
# ./spec/controllers/brief_notes_controller_spec.rb:19:in `block (3 levels) in <top (required)>'