I am trying to run controller specifications using app 1.3.4. (and factory girl) I followed the instructions in the wiki for git for the project. I can log in as a user using the login_user method created in the macro, but login_admin does not work with the following error:
...
sign_in Factory.create(:admin)
Could not find a valid mapping for
Factory:
Factory.define :user do |f|
f.sequence(:username) {|n| "user#{n}"}
f.sequence(:email) {|n| "user#{n}@gmail.com"}
f.email_confirmation {|fac| fac.email }
f.password "a12345Den123"
f.password_confirmation "a12345Den123"
end
Factory.define :admin, :class => User do |f|
f.sequence(:username) {|n| "admin#{n}"}
f.sequence(:email) {|n| "admin#{n}@gmail.com"}
f.email_confirmation {|fac| fac.email }
f.password "a12345Den123"
f.password_confirmation "a12345Den123"
f.admin 1
end
Controller macro module:
module ControllerMacros
def login_admin
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@admin = Factory.create(:admin)
sign_in @admin
end
end
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@user = Factory.create(:user)
sign_in @user
end
end
end
routes
devise_for :users
devise_for :admins, :class_name => 'User'
One solution is to set cache_classes = false, however this is not ideal since I use spork and do not want to restart it after changing the model.
Any help?
source
share