Guest User

Untitled

a guest
May 27th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
  2.  
  3. describe StatusReminder do
  4. fixtures :all
  5.  
  6. before(:each) do
  7. @emails = ActionMailer::Base.deliveries
  8. @emails.clear
  9. @user = User.find(users(:member).id)
  10. end
  11.  
  12. def send_reminders
  13. StatusReminder.send_reminders
  14. end
  15.  
  16. describe "with a user that updated five days ago and hasn't received
  17. a status reminder" do
  18. before(:each) do
  19. @user.status_reminder = true
  20. @user.last_status_created_at = 5.days.ago
  21. @user.last_status_reminder_sent_at = ""
  22. @user.save
  23. end
  24.  
  25. it "should collect the users eligible for status reminders" do
  26. User.should_receive(:find).and_return(@user)
  27. send_reminders
  28. end
  29.  
  30. it "should send an email to each of the users" do
  31. lambda { send_reminders }.should change(@emails, :length).by(1)
  32. end
  33.  
  34. it "should update their last status reminder sent at" do
  35. @user.should_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
  36. send_reminders
  37. end
  38. end
  39.  
  40. describe "with a user that updated over five days ago and hasn't received
  41. a status reminder" do
  42. before(:each) do
  43. @user.status_reminder = true
  44. @user.last_status_created_at = 6.days.ago
  45. @user.last_status_reminder_sent_at = ""
  46. @user.save
  47. end
  48.  
  49. it "should collect the users eligible for status reminders" do
  50. User.should_receive(:find).and_return(@user)
  51. send_reminders
  52. end
  53.  
  54. it "should send an email to each of the users" do
  55. lambda { send_reminders }.should change(@emails, :length).by(1)
  56. end
  57.  
  58. it "should update their last status reminder sent at" do
  59. @user.should_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
  60. send_reminders
  61. end
  62. end
  63.  
  64. describe "with a user that hasn't updated in ten days and their
  65. last status reminder was sent five days ago" do
  66. before(:each) do
  67. @user.status_reminder = true
  68. @user.last_status_created_at = 10.days.ago
  69. @user.last_status_reminder_sent_at = 5.days.ago
  70. @user.save
  71. end
  72.  
  73. it "should collect the users eligible for status reminders" do
  74. User.should_receive(:find).and_return(@user)
  75. send_reminders
  76. end
  77.  
  78. it "should send an email to each of the users" do
  79. lambda { send_reminders }.should change(@emails, :length).by(1)
  80. end
  81.  
  82. it "should update their last status reminder sent at" do
  83. @user.should_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
  84. end
  85. end
  86.  
  87. describe "with a user that updated their status four days ago and hasn't received
  88. a status reminder" do
  89. before(:each) do
  90. @user.status_reminder = true
  91. @user.last_status_reminder_sent_at = 4.days.ago
  92. @user.last_status_reminder_sent_at = ""
  93. @user.save
  94. end
  95.  
  96. it "should collect the users eligible for status reminders" do
  97. User.should_receive(:find).and_return(@user)
  98. send_reminders
  99. end
  100.  
  101. it "should send an email to each of the users" do
  102. lambda { send_reminders }.should_not change(@emails, :length).by(1)
  103. end
  104.  
  105. it "should update their last status reminder sent at" do
  106. @user.should_not_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
  107. end
  108. end
  109.  
  110. describe "with a user that last updated four days ago
  111. and their last status reminder was five days ago" do
  112. before(:each) do
  113. @user.status_reminder = true
  114. @user.last_status_reminder_sent_at = 4.days.ago
  115. @user.save
  116. end
  117.  
  118. it "should collect the users eligible for status reminders" do
  119. User.should_receive(:find).and_return(@user)
  120. send_reminders
  121. end
  122.  
  123. it "should not send an email to the user" do
  124. lambda { send_reminders }.should_not change(@emails, :length).by(1)
  125. end
  126.  
  127. it "should not update their last status reminder sent at" do
  128. @user.should_not_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
  129. end
  130. end
  131.  
  132. describe "with a user with status reminder notifications unchecked" do
  133. before(:each) do
  134. @user.status_reminder = false
  135. @user.last_status_reminder_sent_at = 5.days.ago
  136. @user.save
  137. end
  138.  
  139. it "should not collect the user" do
  140. User.should_receive(:find).and_return(nil)
  141. send_reminders
  142. end
  143.  
  144. it "should not send an email to the user" do
  145. lambda { send_reminders }.should_not change(@emails, :length).by(1)
  146. end
  147.  
  148. it "should not update their last status reminder sent at" do
  149. @user.should_not_receive(:update_attribute).with(:last_status_reminder_sent_at, Time.now)
  150. end
  151. end
  152.  
  153. end
Add Comment
Please, Sign In to add comment