Permalink
Browse files

refactor email and tests

  • Loading branch information...
1 parent 401a1f4 commit 84def7d76f1bab3b796e6ba615f69bf86049b4d0 @interstateone committed Oct 22, 2012
Showing with 30 additions and 6 deletions.
  1. +5 −5 app/models/user.rb
  2. +25 −1 spec/standards_spec.rb
View
@@ -54,21 +54,21 @@ def self.authenticate(email, pass)
nil
end
- def check_today?
- return !(self.checks.count :date => Date.today).zero?
- end
-
def remaining_tasks
completeTasks = self.checks(:date => Date.today.to_time.in_time_zone(self.timezone).to_date).task.to_a
incompleteTasks = self.tasks.to_a - completeTasks
return incompleteTasks.map { |t| t.title }
end
+ def check_today?
+ return !self.checks(:date => Date.today.to_time.in_time_zone(self.timezone).to_date).count.zero?
+ end
+
def send_reminder_email
return unless self.daily_reminder_permission
user_time = Time.now.in_time_zone(self.timezone)
puts "checking #{self.id}"
- unless (self.check_today?)
+ unless self.check_today?
puts "no checks for #{self.id}"
if ((user_time.hour == self.daily_reminder_time) && (user_time.min == 0)) || ((user_time.hour == self.daily_reminder_time - 1) && (user_time.min.between?(55,60)))
puts "sending email to #{self.id}"
View
@@ -12,7 +12,7 @@ def only(*whitelist)
module UserSpecHelper
def valid_user_attributes
- { :email => 'Test@gmail.com',
+ { :email => 'Test@localhost',
:name => 'Mike',
:password => 'Tes7yasdf' }
end
@@ -66,6 +66,30 @@ def valid_user_attributes
@check = Check.create(:user => @user, :task => @task1, :date => Date.today)
@user.remaining_tasks.should == ['Task 2']
end
+
+ describe 'when checking to remind' do
+ it 'should log "checking"' do
+ @user.attributes = valid_user_attributes
+ @user.daily_reminder_permission = true
+ @user.save
+ result = capture_stdout do
+ @user.send_reminder_email
+ end
+ result.string.should include 'checking'
+ end
+
+ it 'should log "sending email" at the right time' do
+ @user.attributes = valid_user_attributes
+ @user.daily_reminder_permission = true
+ @user.daily_reminder_time = Time.now.hour
+ @user.save
+ Timecop.freeze(Time.new(2012, 1, 2, Time.now.hour))
+ result = capture_stdout do
+ @user.send_reminder_email
+ end
+ result.string.should include 'sending email'
+ end
+ end
end
describe 'A task' do

0 comments on commit 84def7d

Please sign in to comment.