【问题标题】:rspec factory girl not creating userrspec工厂女孩没有创建用户
【发布时间】:2014-08-19 11:04:56
【问题描述】:

我将rails 3.2deviserspecfactory girl 一起使用。我正在尝试登录用户,但似乎首先创建用户时出现问题。

用户工厂:

factory :user do 
    first_name "Test"
    last_name "User"
    sequence(:email) { |n| "foo#{n}@test.com" }
    password "secretpassword"
    confirmed_at Time.now
end

我的规格

feature "BackOffice" do 
  subject { page }
  context "as user" do 
    let(:user) { create(:user) }
    describe "should not have access to backoffice" do 
      before do
        visit "http://domain_name/fr/users/sign_in"
        within ".login-wrapper" do
          fill_in "user_email", with: user.email
          fill_in "user_password", with: user.password
          click_button "S'identifier"
        end
      end
      it { should have_content "Bienvenue"}
    end
  end

错误

    Failure/Error: let(:user) { create(:user) }
         ActionView::Template::Error:
           No route matches {:action=>"edit", :controller=>"users/registrations"}
# ./app/views/user_mailer/welcome.html.erb:3:in `_app_views_user_mailer_welcome_html_erb__212088972377821759_70301344598820'
     # ./app/mailers/user_mailer.rb:31:in `welcome'
     # ./app/models/user.rb:125:in `send_welcome_email'
     # ./spec/requests/backoffice_spec.rb:15:in `block (3 levels) in <top (required)>'
     # ./spec/requests/backoffice_spec.rb:20:in `block (5 levels) in <top (required)>'
     # ./spec/requests/backoffice_spec.rb:19:in `block (4 levels) in <top (required)>'
     # ./spec/support/database_cleaner.rb:17:in `block (2 levels) in <top (required)>'

为什么它应该在创建资源时尝试进入编辑操作?

【问题讨论】:

  • 您不会在创建用户时发送欢迎电子邮件吗?因为这就是它想要做的,所以发送一封电子邮件。您看到的错误是呈现欢迎电子邮件时出现的问题。

标签: ruby-on-rails rspec devise


【解决方案1】:

欢迎电子邮件中的链接存在问题,我添加了以下内容来修复它: config.action_mailer.default_url_options = { protocol: "http", host: "localhost", port: 3000, locale: I18n.locale }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多