ruby on rails - Testing devise invitable -


i using devise invitable in app. have overwritten devise invitable invitations controller custom behavior. when try , write controller tests following error:

nomethoderror: undefined method 'name' nil:nilclass 

that happens when doing get :new.

the route setup directed in setup directions:

devise_for :users, controllers: { sessions: 'users/sessions', invitations: 'users/invitations', registrations: :registrations } 

the controller under /app/controllers/users/invitations_controller.rb , name spaced correctly within file users::invitationscontroller same test /tests/controllers/users/invitations_controller.rb users::invitationscontrollertest

this test:

context '#new'   context 'while not signed in'     should 'redirect login page'       :new       assert_redirected_to new_user_session_path     end   end end 

this action:

def new   self.resource = resource_class.new   self.resource.build_group if current_inviter.is_admin?   self.resource.group = current_inviter.group if current_inviter.is_manager?   render :new end 

appreciate thanks.

you need set devise.mappings before every request(or in setup block) follows -

@request.env["devise.mapping"] = devise.mappings[:user]

this devise map routes correctly in tests.

more info can found here - https://github.com/plataformatec/devise/wiki/how-to:-test-controllers-with-rails-3-and-4-(and-rspec)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -