1

RyanBigg著の『 Multitenancy with Rails』の手順に従っています。このエラーに遭遇しましたが、何が間違っているのかわかりません。

エラー:

  1) Accounts Creating an account
     Failure/Error: page.should have_content('Signed in as subscribem@example.com')
       expected there to be text "Signed in as subscribem@example.com" in "Your account has been successfully created. Account Sign Up"
     # ./spec/features/accounts/sign_up_spec.rb:13:in `block (2 levels) in <top (required)>'

sign_up_spec.rb

require 'spec_helper'
feature 'Accounts' do 
  scenario "Creating an account" do
    visit subscribem.root_url
    click_link 'Account Sign Up'
    fill_in 'Name', :with => "Test"
    fill_in 'Email', :with => 'subscribem@example.com'
    password_field_id = 'account_owner_attributes_password'
    fill_in 'Password confirmation', :with => 'password'
    click_button 'Create Account'
    success_message = 'Your account has been successfully created'
    page.should have_content(success_message)
    page.should have_content('Signed in as subscribem@example.com')
  end
end                                                                                         

アカウントモデル

module Subscribem
  class Account < ActiveRecord::Base
    attr_accessible :name, :owner_attributes

    belongs_to :owner, :class_name => 'Subscribem::User'
    accepts_nested_attributes_for :owner
  end
end

ユーザーモデル

module Subscribem
  class User < ActiveRecord::Base
    attr_accessible :email, :password, :password_confirmation
    has_secure_password

  end
end

アプリケーションコントローラー

module Subscribem
  class ApplicationController < ActionController::Base

    def current_user
      if user_signed_in?
        Subscribem::Account.find(env['warden'].user(:scope => :account))
      end
    end

    helper_method :current_account

    def current_user
      if user_signed_in?
        Subscribem::User.find(env['warden'].user(:scope => :user))
      end
    end

    helper_method :current_user

    def user_signed_in?
      env['warden'].authenticated?(:user)
    end

    helper_method :user_signed_in?

  end
end  

アカウントコントローラー

require_dependency "subscribem/application_controller"

module Subscribem
  class AccountsController < ApplicationController

    def new
      @account = Subscribem::Account.new
      @account.build_owner
    end

    def create
      account = Account.create(params[:account])
      env['warden'].set_user(account.owner.id, :scope => :user)
      env['warden'].set_user( account.id, :scope => :account)
      flash[:success] = "Your account has been successfully created."
      redirect_to subscribem.root_url
    end

  end
end

application.html.erb

<body>                                                                             
<% flash.each do |k,v| %>
<div class='flash <%= k %> '><%= v %></div>
<% end %>

<% if current_user %>
Signed in as <%= current_user.email %>
<% end %>

<%= yield %>

</body>
4

2 に答える 2

0

エラーが表示されている可能性があります(subcribem / accounts / show.html。[template_engine])?フラッシュメッセージだけが印刷されているようです。

于 2013-02-17T23:17:17.067 に答える
0

私は同じ問題を抱えていて、別の期待でそれを解決しました:

require 'rails_helper'

feature 'Accounts' do
  scenario 'creating an account' do
    visit subscribem.root_path
    click_link 'Account Sign Up'
    fill_in 'Name', with: 'Test'
    click_button 'Create Account'
    success_message = 'Your Account has been successfully created.'
    expect(find('.flash.success')).to have_content(success_message)
  end
end

解決策は、ページではなく成功メッセージのフラッシュメッセージを見つけることです。これが他の人に役立つことを願っています。

于 2014-08-26T08:54:03.277 に答える