Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fteem
Created May 13, 2013 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fteem/5568642 to your computer and use it in GitHub Desktop.
Save fteem/5568642 to your computer and use it in GitHub Desktop.
describe ".send_surveys" do
it "sends those users an email with survey" do
SurveySender.should_receive(:unsurveyed_users).and_return [user, user2]
SurveyMailer.should_receive(:send_survey).with(user).and_return mailer = double(:mailer)
mailer.should_receive(:deliver)
user.should_receive(:email)
Rails.logger.should_receive(:info)
SurveyMailer.should_receive(:send_survey).with(user2).and_return mailer = double(:mailer)
mailer.should_receive(:deliver)
user2.should_receive(:email)
Rails.logger.should_receive(:info)
SurveySender.send_surveys
end
it "sets users survey-sent flag" do
SurveyMailer.stub(:send_survey).with(user).and_return mailer = double(:mailer, :deliver => true)
SurveySender.should_receive(:unsurveyed_users).and_return [user]
user.should_receive(:email)
Rails.logger.should_receive(:info)
user.should_receive(:survey_sent=).with(true)
user.should_receive(:save)
SurveySender.send_surveys
end
it 'sends a message to the Rails logger when survey is sent' do
SurveySender.should_receive(:unsurveyed_users)
SurveyMailer.should_receive(:send_survey).with(user)
mailer.should_receive(:deliver)
user.should_receive(:email).and_return user.email
Rails.logger.should_receive(:info).with("[Survey Sender] Survey sent to #{user.email}")
SurveyMailer.should_receive(:send_survey).with(user2)
mailer.should_receive(:deliver)
user2.should_receive(:email).and_return user2.email
Rails.logger.should_receive(:info).with("[Survey Sender] Survey sent to #{user2.email}")
SurveySender.send_surveys
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment