English 中文(简体)
A. 工厂女童的建造
原标题:trouble building with factory girl

因此,问题是,邮件不添加到“行动邮件:基本交付”。

Girl.create正在返回Nil。 我做了什么错误?

FactoryGirl.define do 
  factory :provisional_user do
    sequence(:email) { |n| "bangbang_#{n}@example.com" }
    first_name "Provisional"
    last_name "User"
    partner "source2"
    unsubscribed false
  end

  factory(:unsubscribed_user, :parent => :provisional_user, :class => ProvisionalUser) do
    sequence(:email) { |n| "[email protected]" }
    first_name "Unsubscribed"
    last_name "User"
    partner "source2"
    unsubscribed true
  end


  factory(:subscribed_user, :class => ProvisionalUser) do
    sequence(:email) { |n| "[email protected]" }
    first_name "Subscribed"
    last_name "User"
    partner "source2"
    unsubscribed false
  end
  ...
end

然后,在我的试验中(我还审判了GeGirl。 如果没有储蓄创造! a. 在以下各行:

require "rspec"
require "spec_helper"
require "action_mailer"

describe "unsubscribe functionality" do

  before(:each) do
    ActionMailer::Base.deliveries = []
  end

  it "should send emails to subscribed users only" do
    unsubscribed_user = FactoryGirl.build(:unsubscribed_user)
    unsubscribed_user.save!

    subscribed_user = FactoryGirl.create(:subscribed_user)
    puts "the user is" + subscribed_user.to_s
    CoRegEmailWorker.perform
    #sent.length.should == 1
    sent.first.email.should =~ subscribed_user.email
    sent.first.email.should_not =~ unsubscribed_user.email
  end

  def sent
    ActionMailer::Base.deliveries
  end

end

但它未能做到这一点:

Failure/Error: sent.first.email.should =~ subscribed_user.email
  NoMethodError:
   undefined method `email  for nil:NilClass
  # ./spec/mailers/provisional_users_notifier_spec.rb:21
问题回答

In the code you put here, you only have defined unsubscribed_user, but no subscribed_user, so subscribed_user would be nil, and there may be the problem.

贵国用户类别是否有一对一或一对一的协会? 我发出了类似的错误信息,并通过将协会包括在内,制造我的工厂目标,解决了错误信息。 这有助于:

• 如何在工厂女童中创建协会。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签