, поэтому проблема в том, что почта не добавляется в ActionMailer :: Base.deliveries.
FactoryGirl.create возвращает ноль. что я делаю не так?
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| "do_not_contact@example.com" }
first_name "Unsubscribed"
last_name "User"
partner "source2"
unsubscribed true
end
factory(:subscribed_user, :class => ProvisionalUser) do
sequence(:email) { |n| "please_contact@example.com" }
first_name "Subscribed"
last_name "User"
partner "source2"
unsubscribed false
end
...
end
затем в моем тесте (я также пробовал FactoryGirl.create без сохранения! В следующей строке):
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