I have a Posts controller and I have just installed Devise to add some authentication quickly and easily. Before I installed Devise, I had created some tests for the 'new' action of my Posts controller. After installing Devise, my tests were failing until i added the
config.include Devise::TestHelpers, :type => :controller
line to my spec_helper.rb file.
I also have the line
before_filter :authenticate_user!, :except => [:show, :index]
in my PostsController.
Now when I run my tests, they all pass except these 2:
it "should be successful" do
get :new
response.should be_success
end
it "should have the right title" do
get :new
response.should have_selector('title', :content => @base_title + " | New post")
end
I'm using Factory girl as well. The error is cause by the before_filter except parameter. I need to be able to sign in the user in rspec with a factory user. How do I sign the Factory user in from within the Rspec controller test? How do I define the Factory user?
I have tried this in my factories.rb:
Factory.define :user do |user|
user.name "Test User"
user.email "user@example.com"
user.password "password"
user.password_confirmation "password"
end
But then I get the error:
NoMethodError:
undefined method `password_salt=' for #<User:0x00000103cac958>
Any help would be much appreciated. Thanks.