我有一個黃瓜測試,讓我登錄到系統,然後檢查一些路由黃瓜+設計 - 登錄的問題 - > CURRENT_USER始終爲零
Feature: Donating as a guest
@javascript
Scenario: Logged in as an Admin
Given I login as AdminUser
And I go to the root page
And I click button "$20"
And I click button "Donate"
And I click link "Donate as Guest >"
Then I am redirected to "sign_in_or_sign_up" with flash message stating "You're logged in as an Admin"
這是我一步,我登錄(注黃瓜說:這種通過):
Given(/^I login as AdminUser$/) do
admin = Fabricate(:admin_user)
Fabricate(:fund)
visit '/admin/admin_users/sign_in'
fill_in 'Email', :with => admin.email
fill_in 'Password', :with => admin.password
click_button 'Sign in'
end
在後兩個最後一步,我點擊鏈接「捐贈以來賓>」,我的資金控制器使一個檢查,看看有什麼樣的CURRENT_USER是登錄
。 0if current_user.class == AdminUser
每次碰到這裏時,current_user都是零。我很難過這是爲什麼。我甚至嘗試以編程方式登錄,但沒有去。是否有某種我缺少的接線?
編輯:
這裏是我的路線有關本:
devise_for :admin_users
devise_for :users, :controllers => {:omniauth_callbacks => "user/omniauth_callbacks", :sessions => 'user/sessions', :passwords => 'user/passwords', :confirmations => 'user/confirmations'}
devise_scope :user do
get '/user/auth/:provider' => 'user/omniauth_callbacks#passthru'
get "/user/sign_in" => "devise/sessions#new", :as => :new_user_session
post "/user/sign_in" => "user/sessions#create", :as => :user_session
delete "/user/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session
post "/user/sign_up" => "user/registrations#create", :as => :user_registration
get "/user/sign_in_or_sign_up" => "user/sessions#sign_in_or_sign_up"
post "/user/sign_up_via_dual_login" => "user/registrations#create_via_dual_login"
end
ADMINUSER型號:
class AdminUser < ActiveRecord::Base
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :timeoutable
attr_accessible(
:email,
:password,
:password_confirmation,
:remember_me,
:organization_id,
:organization_role_id,
:super_admin,
:first_name,
:last_name,
:receive_transaction_notifications,
:receive_weekly_transaction_summary
)
belongs_to :organization
has_many :roles, :foreign_key => :api_user_id
belongs_to :organization_role, :class_name => "UserRole", :foreign_key => "organization_role_id"
has_many :permissions
has_many :admin_users_connections
has_many :people, through: :admin_users_connections
has_and_belongs_to_many :todos
has_many :notes, foreign_key: :added_by_id
has_one :profile
scope :admins, where(:super_admin => false, active: true)
scope :super, where(super_admin: true)
scope :receive_weekly_transaction_summaries, where(receive_weekly_transaction_summary: true)
def type
super_admin? && 'SUPER' || 'ADMIN'
end
def super?
super_admin == true
end
end
請粘貼您的路線文件和AdminUser模型。 –
我也有這個問題。 –