Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
- describe StatusReminder do
- fixtures :all
- before(:each) do
- @emails = ActionMailer::Base.deliveries
- @emails.clear
- @user = User.find(users(:member).id)
- end
- def send_reminders
- StatusReminder.send_reminders
- end
- describe "with a user that updated five days ago and hasn't received
- a status reminder" do
- before(:each) do
- @user.status_reminder = true
- @user.last_status_created_at = 5.days.ago
- @user.last_status_reminder_sent_at = ""
- @user.save
- end
- it "should collect the users eligible for status reminders" do
- User.should_receive(:find).and_return(@user)
- send_reminders
- end
- it "should send an email to each of the users" do
- lambda { send_reminders }.should change(@emails, :length).by(1)
- end
- it "should update their last status reminder sent at" do
- @user.should_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
- send_reminders
- end
- end
- describe "with a user that updated over five days ago and hasn't received
- a status reminder" do
- before(:each) do
- @user.status_reminder = true
- @user.last_status_created_at = 6.days.ago
- @user.last_status_reminder_sent_at = ""
- @user.save
- end
- it "should collect the users eligible for status reminders" do
- User.should_receive(:find).and_return(@user)
- send_reminders
- end
- it "should send an email to each of the users" do
- lambda { send_reminders }.should change(@emails, :length).by(1)
- end
- it "should update their last status reminder sent at" do
- @user.should_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
- send_reminders
- end
- end
- describe "with a user that hasn't updated in ten days and their
- last status reminder was sent five days ago" do
- before(:each) do
- @user.status_reminder = true
- @user.last_status_created_at = 10.days.ago
- @user.last_status_reminder_sent_at = 5.days.ago
- @user.save
- end
- it "should collect the users eligible for status reminders" do
- User.should_receive(:find).and_return(@user)
- send_reminders
- end
- it "should send an email to each of the users" do
- lambda { send_reminders }.should change(@emails, :length).by(1)
- end
- it "should update their last status reminder sent at" do
- @user.should_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
- end
- end
- describe "with a user that updated their status four days ago and hasn't received
- a status reminder" do
- before(:each) do
- @user.status_reminder = true
- @user.last_status_reminder_sent_at = 4.days.ago
- @user.last_status_reminder_sent_at = ""
- @user.save
- end
- it "should collect the users eligible for status reminders" do
- User.should_receive(:find).and_return(@user)
- send_reminders
- end
- it "should send an email to each of the users" do
- lambda { send_reminders }.should_not change(@emails, :length).by(1)
- end
- it "should update their last status reminder sent at" do
- @user.should_not_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
- end
- end
- describe "with a user that last updated four days ago
- and their last status reminder was five days ago" do
- before(:each) do
- @user.status_reminder = true
- @user.last_status_reminder_sent_at = 4.days.ago
- @user.save
- end
- it "should collect the users eligible for status reminders" do
- User.should_receive(:find).and_return(@user)
- send_reminders
- end
- it "should not send an email to the user" do
- lambda { send_reminders }.should_not change(@emails, :length).by(1)
- end
- it "should not update their last status reminder sent at" do
- @user.should_not_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
- end
- end
- describe "with a user with status reminder notifications unchecked" do
- before(:each) do
- @user.status_reminder = false
- @user.last_status_reminder_sent_at = 5.days.ago
- @user.save
- end
- it "should not collect the user" do
- User.should_receive(:find).and_return(nil)
- send_reminders
- end
- it "should not send an email to the user" do
- lambda { send_reminders }.should_not change(@emails, :length).by(1)
- end
- it "should not update their last status reminder sent at" do
- @user.should_not_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
- end
- end
- end
Add Comment
Please, Sign In to add comment