因此,问题是,邮件不添加到“行动邮件:基本交付”。
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