Skip to content

Commit

Permalink
Expand test coverage just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-burns committed Nov 13, 2010
1 parent 444faaf commit 9e6dfe8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def self.exclude(user)
where('users.id <> ?', user.id)
end

def self.incomplete
where('dob IS NULL')
end

# The secret code that the user uses to prove that they have that phone
# number.
def secret_code
Expand Down Expand Up @@ -121,6 +125,10 @@ def incomplete?
dob.nil?
end

def start_annoyer
QUEUE.enqueue_at(7.days.from_now, ProfileAnnoyer, :user_id => self.id)
end

protected

def normalize_phone_number
Expand Down Expand Up @@ -204,8 +212,4 @@ def deliver_confirmation_congratulations
self.tell("Congrats, #{self.name}, you are now an instalover. Text '#{COMMANDS[:new_date]}' to get a new date.")
end
end

def start_annoyer
QUEUE.enqueue_at(7.days.from_now, ProfileAnnoyer, :user_id => self.id)
end
end
30 changes: 29 additions & 1 deletion features/motivators.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Motivate people to use this service

Scenario: Annoy the people who have never filled out their profile
Given the day and time is "November 12, 2010 01:00 est"
Given the following empty user exists:
And the following empty user exists:
| phone number | secret code |
| 18004688487 | tits |
And the day and time is "November 18, 2010 01:00 est"
Expand Down Expand Up @@ -42,5 +42,33 @@ Feature: Motivate people to use this service
And timed jobs are processed
Then "18004688487" should not get a text whose message includes "fill out"

Scenario: Enqueue existing users for the annoyance queue
Given the day and time is "November 12, 2010 01:00 est"
And the following empty unenqueued user exists:
| phone number |
| 18004688487 |
And the following empty user exists:
| phone number |
| 18004688488 |
And the following young person exists:
| phone number |
| 18004688489 |
And the day and time is "November 18, 2010 01:00 est"
Then "18004688487" should not get a text whose message includes "fill out"
Then "18004688488" should not get a text whose message includes "fill out"
Then "18004688489" should not get a text whose message includes "fill out"
When it is 24 hours later
And timed jobs are processed
Then "18004688487" should not get a text whose message includes "fill out"
Then "18004688488" should get a text whose message includes "fill out"
Then "18004688489" should not get a text whose message includes "fill out"
When I run the rake task "instalover:annoy:empty_profiles"
And it is 7 days later
And I clear the text message history
And timed jobs are processed
Then "18004688487" should get a text whose message includes "fill out"
Then "18004688488" should get a text whose message includes "fill out"
Then "18004688489" should not get a text whose message includes "fill out"

@wip
Scenario: Ask out those who have asked for one date on behalf of those who have asked out none
4 changes: 4 additions & 0 deletions features/step_definitions/time_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
Given %r{it is (\d+) hours? later} do |h|
Timecop.freeze(h.to_i.hours.from_now)
end

Given %r{it is (\d+) days? later} do |d|
Timecop.freeze(d.to_i.days.from_now)
end
7 changes: 7 additions & 0 deletions lib/tasks/instalover.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ namespace :instalover do
Message.handle_new_date(w)
end
end

namespace :annoy do
desc "Enqueue users without completed profiles for annoyance"
task :empty_profiles => :environment do
User.incomplete.each(&:start_annoyer)
end
end
end
6 changes: 6 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
user_factory.phone_number { Factory.next :phone_number }
end

Factory.define :empty_unenqueued_user, :parent => :empty_user do |user_factory|
user_factory.after_create do |user|
QUEUE.reset
end
end

Factory.define :young_person, :parent => :user do |u|
u.dob { 21.years.ago }
u.looking_for_minimum_age 20
Expand Down

0 comments on commit 9e6dfe8

Please sign in to comment.