我正在按照Ryan Bigg的《 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
应用程序.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>