Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

'retry' command

  • Loading branch information...
commit 0da6646d18cb0fee26eb7d86f1abfff6af9c7650 1 parent b999ee7
@mike-burns mike-burns authored
View
10 app/models/meetup.rb
@@ -28,6 +28,11 @@ def self.proposed
where('state = "proposed"')
end
+ # All dates that are not yet canceled but are not actively being searched.
+ def self.retryable
+ where('state = "retryable"')
+ end
+
# All meetups for the given user
def self.for(user)
where('meetups.first_user_id = :id OR meetups.second_user_id = :id', :id => user.id)
@@ -60,6 +65,11 @@ def cancel!
self.save!
end
+ def retryable!
+ self.state = 'retryable'
+ self.save!
+ end
+
def schedule_with!(second_user)
self.state = 'scheduled'
self.second_user = second_user
View
27 app/models/message.rb
@@ -80,6 +80,8 @@ def self.handle_incoming(phone_number, message_text)
handle_texting_proxy(user, $1)
elsif message_text =~ /^\s*#{COMMANDS[:quit].gsub(' ','.*')}/i
handle_safeword(user)
+ elsif message_text =~ /^\s*#{COMMANDS[:retry].gsub(' ','.*')}/i
+ handle_retry(user)
else
handle_unknown(user)
end
@@ -116,6 +118,27 @@ def self.handle_new_date(user)
end
end
+ def self.handle_retry(user)
+ if within_dating_hours?
+ if meetup = user.founded_meetups.retryable.last
+ meetup.unschedule!
+ user.matching.first(5).each do |matching_user|
+ Offer.create(:offered_user => matching_user, :meetup => meetup)
+ end
+ QUEUE.enqueue_at(5.minutes.from_now, RejectMessageDelayer, :user_id => user.id)
+ user.tell("Trying to get you a date. Back in five.")
+ else
+ handle_unknown_retry(user)
+ end
+ else
+ outside_dating_hours(user)
+ end
+ end
+
+ def self.handle_unknown_retry(user)
+ raise "handle_unknown_retry"
+ end
+
def self.within_dating_hours?
now = Time.zone.now
now.hour >= DATING_START.hour &&
@@ -184,12 +207,12 @@ def self.handle_dfln(user, message)
def self.handle_no_responses(user)
meetup = user.founded_meetups.unscheduled.first
if !meetup.nil?
- user.tell("We called every number in our little black book, but only got answering machines. Try again later? Reply '#{COMMANDS[:new_date]}' to start again.")
+ user.tell("We called every number in our little black book, but only got answering machines. Try again with '#{COMMANDS[:retry]}'.")
meetup.offers.pending.each do |offer|
offer.offered_user.tell("Too slow! Would you like to get a date? Reply '#{COMMANDS[:new_date]}'.")
offer.cancel!
end
- meetup.cancel!
+ meetup.retryable!
end
end
View
2  app/models/user.rb
@@ -22,7 +22,7 @@ class User < ActiveRecord::Base
attr_accessor :secret_code_confirmation
def self.without_offers
- where('users.id NOT IN (SELECT offered_user_id FROM offers WHERE offers.state = "pending" OR (offers.state = "canceled" AND offers.created_at > ?))', 1.hour.ago)
+ where('users.id NOT IN (SELECT offered_user_id FROM offers WHERE offers.state = "pending" OR ((offers.state = "canceled" OR offers.state = "retryable") AND offers.created_at > ?))', 1.hour.ago)
end
def self.sort_by_least_offered
View
3  config/initializers/commands.rb
@@ -3,5 +3,6 @@
:ok => 'ok',
:accept => 'accept',
:sext => 'say',
- :quit => 'safeword'
+ :quit => 'safeword',
+ :retry => 'retry'
}
View
23 features/asking_for_a_date.feature
@@ -1,6 +1,6 @@
Feature: Asking for a date
- Scenario: People ask for dates
+ Background:
Given the following users exist:
| Phone Number | Male | Female | Looking For Male | Looking For Female | Dob | Looking For Minimum Age | Looking For Maximum Age | Description | Name |
| 11111111111 | true | false | false | true | 11/06/1989 | 18 | 34 | red hair | Mike |
@@ -17,13 +17,14 @@ Feature: Asking for a date
| 19999999999 | true | true | 11/06/1989 | 18 | 34 |
| 10000000000 | true | true | 11/06/1989 | 18 | 34 |
| 11111111112 | true | true | 11/06/1989 | 18 | 34 |
- And the day and time is "October 16, 2010 8:00pm edt"
+ And the day and time is "October 16, 2010 8:00pm est"
And the following date suggestions exist:
| text |
| Silvertone |
| Mike's Apartment |
And jobs are cleared
+ Scenario: People ask for dates
When "18004688487" texts instalover with "new date"
Then "18004688487" should get a text "Should we find you a date at Silvertone at 09:00PM? Reply 'ok' or 'new date' to try again."
@@ -37,7 +38,7 @@ Feature: Asking for a date
When jobs in 5 minutes from now are processed
- Then "18004688487" should get a text "We called every number in our little black book, but only got answering machines. Try again later? Reply 'new date' to start again."
+ Then "18004688487" should get a text "We called every number in our little black book, but only got answering machines. Try again with 'retry'."
And "11111111111" should get a text "Too slow! Would you like to get a date? Reply 'new date'."
And "12222222222" should get a text "Too slow! Would you like to get a date? Reply 'new date'."
And "13333333333" should get a text "Too slow! Would you like to get a date? Reply 'new date'."
@@ -75,3 +76,19 @@ Feature: Asking for a date
When "18004688487" texts instalover with "new date"
Then "18004688487" should get a text whose message includes "Reply 'ok' or 'new date'"
When "18004688487" texts instalover with "ok"
+
+ Scenario: Ask for a date then retry
+ When "18004688487" texts instalover with "new date"
+ And "18004688487" texts instalover with "ok"
+ And jobs in 5 minutes from now are processed
+ Then "18004688487" should get a text "We called every number in our little black book, but only got answering machines. Try again with 'retry'."
+ And "11111111111" should get a text "Too slow! Would you like to get a date? Reply 'new date'."
+ Given I clear the text message history
+ When "18004688487" texts instalover with "retry"
+ Then "11111111111" should not get a text whose message includes "Want to go on a date"
+ And "12222222222" should not get a text whose message includes "Want to go on a date"
+ And "13333333333" should not get a text whose message includes "Want to go on a date"
+ And "14444444444" should not get a text whose message includes "Want to go on a date"
+ And "15555555555" should not get a text whose message includes "Want to go on a date"
+ But "16666666666" should get a text whose message includes "Want to go on a date"
+ And "18004688487" should get a text "Trying to get you a date. Back in five."
Please sign in to comment.
Something went wrong with that request. Please try again.