1

システムにログインしてルーティングをチェックするキュウリのテストがあります。

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

2 番目の 2 つの最後のステップでは、リンク「Donate as Guest >」をクリックすると、資金管理者がログインしている current_user の種類を確認します。

if current_user.class == AdminUser

ここにヒットするたびに、 current_user は nil です。これがなぜなのか、私は困惑しています。プログラムでログインしようとしましたが、うまくいきません。私が行方不明になっているある種の配線はありますか?

編集:

これに関連する私のルートは次のとおりです。

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
4

1 に答える 1

0

admin.password実際のパスワードを返していますか?それとも暗号化版?

また、管理者ユーザーとしてログインしているため、current_user実際にはcurrent_admin_user. Devise はあなたの Devise マッピングに基づいて関数を作成しますが、必ずしもそうではありませんcurrent_user

これは名前空間にも当てはまります。

namespace :api do
  devise_for :users
end

ヘルパー メソッドが になりますcurrent_api_user

于 2013-07-09T13:53:51.043 に答える