Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Expand test coverage just in case

  • Loading branch information...
commit 9e6dfe8fc9bdc07500ab4ab87aff86475d40e235 1 parent 444faaf
@mike-burns mike-burns authored
View
12 app/models/user.rb
@@ -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
@@ -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
@@ -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
View
30 features/motivators.feature
@@ -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"
@@ -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
View
4 features/step_definitions/time_steps.rb
@@ -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
View
7 lib/tasks/instalover.rake
@@ -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
View
6 spec/factories.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.