Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Text 'man', 'woman', 'other', or 'whatever'

  • Loading branch information...
commit 36d4492cfc0b16458b16293f4b2c584efab9931f 1 parent 2df6ede
Mike Burns authored November 12, 2010
8  app/models/meetup.rb
@@ -7,6 +7,7 @@ class Meetup < ActiveRecord::Base
7 7
   has_many :dflns
8 8
 
9 9
   after_save :schedule_jobs
  10
+  before_validation :set_default_desired_genders
10 11
 
11 12
   validates_presence_of :first_user_id
12 13
 
@@ -97,4 +98,11 @@ def schedule_jobs
97 98
       QUEUE.enqueue_at(morning_after, MorningAfterCheckerUpper, { :meetup_id => self.id })
98 99
     end
99 100
   end
  101
+
  102
+  def set_default_desired_genders
  103
+    self.desires_male   = !!first_user.looking_for_male   if desires_male.nil?
  104
+    self.desires_female = !!first_user.looking_for_female if desires_female.nil?
  105
+    self.desires_other  = !!first_user.looking_for_other  if desires_other.nil?
  106
+    true
  107
+  end
100 108
 end
23  app/models/message.rb
@@ -82,6 +82,14 @@ def self.handle_incoming(phone_number, message_text)
82 82
       handle_safeword(user)
83 83
     elsif message_text =~ /^\s*#{COMMANDS[:retry].gsub(' ','.*')}/i
84 84
       handle_retry(user)
  85
+    elsif message_text =~ /^\s*#{COMMANDS[:women_only].gsub(' ','.*')}/i
  86
+      handle_new_date(user, :desires_male => false, :desires_female => true, :desires_other => false)
  87
+    elsif message_text =~ /^\s*#{COMMANDS[:men_only].gsub(' ','.*')}/i
  88
+      handle_new_date(user, :desires_male => true, :desires_female => false, :desires_other => false)
  89
+    elsif message_text =~ /^\s*#{COMMANDS[:other_only].gsub(' ','.*')}/i
  90
+      handle_new_date(user, :desires_male => false, :desires_female => false, :desires_other => true)
  91
+    elsif message_text =~ /^\s*#{COMMANDS[:anything].gsub(' ','.*')}/i
  92
+      handle_new_date(user, :desires_male => true, :desires_female => true, :desires_other => true)
85 93
     else
86 94
       handle_unknown(user)
87 95
     end
@@ -95,7 +103,7 @@ def self.handle_texting_proxy(user, message)
95 103
     end
96 104
   end
97 105
 
98  
-  def self.handle_new_date(user)
  106
+  def self.handle_new_date(user, meetup_restrictions = {})
99 107
     if within_dating_hours?
100 108
       user.founded_meetups.proposed.destroy_all
101 109
 
@@ -104,10 +112,11 @@ def self.handle_new_date(user)
104 112
       else
105 113
         user.offers.cancel_all
106 114
 
107  
-        meetup = Meetup.create({
108  
-          :first_user => user,
109  
-          :description => DateSuggestion.next_place_and_time
110  
-        })
  115
+        meetup = Meetup.create(
  116
+          meetup_restrictions.merge(
  117
+            :first_user => user,
  118
+            :description => DateSuggestion.next_place_and_time)
  119
+        )
111 120
 
112 121
 
113 122
         user.tell("Should we find you a date at #{meetup.description}? Reply 'ok' or 'new date' to try again.")
@@ -122,7 +131,7 @@ def self.handle_retry(user)
122 131
     if within_dating_hours?
123 132
       if meetup = user.founded_meetups.retryable.last
124 133
         meetup.unschedule!
125  
-        user.matching.first(5).each do |matching_user|
  134
+        user.matching_for_meetup(meetup).first(5).each do |matching_user|
126 135
           Offer.create(:offered_user => matching_user, :meetup => meetup)
127 136
         end
128 137
         QUEUE.enqueue_at(5.minutes.from_now, RejectMessageDelayer, :user_id => user.id)
@@ -149,7 +158,7 @@ def self.handle_ok(user)
149 158
     meetup = user.founded_meetups.proposed.first
150 159
     if meetup
151 160
       meetup.unschedule!
152  
-      user.matching.first(5).each do |matching_user|
  161
+      user.matching_for_meetup(meetup).first(5).each do |matching_user|
153 162
         Offer.create(:offered_user => matching_user, :meetup => meetup)
154 163
       end
155 164
       QUEUE.enqueue_at(5.minutes.from_now, RejectMessageDelayer, :user_id => user.id)
12  app/models/user.rb
@@ -55,11 +55,11 @@ def self.other
55 55
     where('users.other')
56 56
   end
57 57
 
58  
-  def self.looking_for_gender(user)
  58
+  def self.looking_for_gender(meetup)
59 59
     wheres = []
60  
-    wheres << 'users.male'   if user.looking_for_male
61  
-    wheres << 'users.female' if user.looking_for_female
62  
-    wheres << 'users.other'  if user.looking_for_other
  60
+    wheres << 'users.male'   if meetup.desires_male
  61
+    wheres << 'users.female' if meetup.desires_female
  62
+    wheres << 'users.other'  if meetup.desires_other
63 63
     where(wheres.join(' OR '))
64 64
   end
65 65
 
@@ -92,13 +92,13 @@ def date
92 92
     Meetup.for(self).scheduled.newest.first.try(:for, self)
93 93
   end
94 94
 
95  
-  def matching
  95
+  def matching_for_meetup(meetup)
96 96
     User.
97 97
       within_age_range(self.looking_for_minimum_age, self.looking_for_maximum_age).
98 98
       looking_for(self).
99 99
       without_offers.
100 100
       without_founded_meetups_in_progress.
101  
-      looking_for_gender(self).
  101
+      looking_for_gender(meetup).
102 102
       exclude(self).
103 103
       sort_by_least_offered
104 104
   end
11  app/views/pages/how-does-this-work.html.erb
@@ -2,9 +2,18 @@
2 2
 
3 3
 <ul>
4 4
   <li><span><%= COMMANDS[:new_date] %></span> &mdash; request a new date</li>
5  
-  <li><span><%= COMMANDS[:retry] %></span> &mdash; ask more people out on a date</li>
6 5
   <li><span><%= COMMANDS[:ok] %></span> &mdash; confirm time and place for your date</li>
7 6
   <li><span><%= COMMANDS[:accept] %></span> &mdash; accept a date request</li>
8 7
   <li><span><%= COMMANDS[:sext] %> [your message]</span> &mdash; send a text to your date </li>
9 8
   <li><span><%= COMMANDS[:quit] %></span> &mdash; cancel your account</li>
10 9
 </ul>
  10
+
  11
+<h2>Or get fancy with these advanced commands:</h2>
  12
+
  13
+<ul>
  14
+  <li><span><%= COMMANDS[:retry] %></span> &mdash; ask more people out on a date to the same place</li>
  15
+  <li><span><%= COMMANDS[:women_only] %></span> &mdash; only ask out women</li>
  16
+  <li><span><%= COMMANDS[:men_only] %></span> &mdash; only ask out men</li>
  17
+  <li><span><%= COMMANDS[:other_only] %></span> &mdash; only ask out people who identify as something else</li>
  18
+  <li><span><%= COMMANDS[:anything] %></span> &mdash; ask out everything we have</li>
  19
+</ul>
16  config/initializers/commands.rb
... ...
@@ -1,8 +1,12 @@
1 1
 COMMANDS = {
2  
-  :new_date => 'new date',
3  
-  :ok       => 'ok',
4  
-  :accept   => 'accept',
5  
-  :sext     => 'say',
6  
-  :quit     => 'safeword',
7  
-  :retry    => 'retry'
  2
+  :new_date   => 'new date',
  3
+  :ok         => 'ok',
  4
+  :accept     => 'accept',
  5
+  :sext       => 'say',
  6
+  :quit       => 'safeword',
  7
+  :retry      => 'retry',
  8
+  :women_only => 'woman',
  9
+  :men_only   => 'man',
  10
+  :other_only => 'other',
  11
+  :anything   => 'whatever'
8 12
 }
13  db/migrate/20101112195124_add_desires_to_meetups.rb
... ...
@@ -0,0 +1,13 @@
  1
+class AddDesiresToMeetups < ActiveRecord::Migration
  2
+  def self.up
  3
+    add_column :meetups, :desires_female, :boolean
  4
+    add_column :meetups, :desires_male, :boolean
  5
+    add_column :meetups, :desires_other, :boolean
  6
+  end
  7
+
  8
+  def self.down
  9
+    remove_column :meetups, :desires_other
  10
+    remove_column :meetups, :desires_male
  11
+    remove_column :meetups, :desires_female
  12
+  end
  13
+end
5  features/step_definitions/matching_steps.rb
@@ -3,6 +3,9 @@
3 3
 
4 4
   user = User.find_by_name!(user_name)
5 5
   expected_matches = list_of_match_names.map { |match_name| User.find_by_name!(match_name) }
  6
+  meetup = Meetup.create(:first_user => user, :state => 'proposed')
6 7
 
7  
-  user.matching.map(&:phone_number).should =~ expected_matches.map(&:phone_number)
  8
+  user.matching_for_meetup(meetup).map(&:phone_number).should =~ expected_matches.map(&:phone_number)
  9
+
  10
+  meetup.destroy
8 11
 end
62  features/the_app.feature
@@ -2,10 +2,10 @@ Feature: The whole app
2 2
 
3 3
   Background:
4 4
     Given the following users exist:
5  
-      | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob          | Looking For Minimum Age | Looking For Maximum Age | Description | Name  |
6  
-      | 11111111111  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | red hair    | Mike  |
7  
-      | 12222222222  | true | false  | false            | true               | 10/20/1989   | 18                      | 34                      | black shirt | Jason |
8  
-      | 18004688487  | false| true   | true             | false              | 12/31/1977   | 14                      | 22                      | super hot   | Emma  |
  5
+      | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob          | Looking For Minimum Age | Looking For Maximum Age | Name  |
  6
+      | 11111111111  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | Mike  |
  7
+      | 12222222222  | true | false  | false            | true               | 10/20/1989   | 18                      | 34                      | Jason |
  8
+      | 18004688487  | false| true   | true             | false              | 12/31/1977   | 14                      | 22                      | Emma  |
9 9
     And the day and time is "October 16, 2010 8:00pm est"
10 10
     And the following date suggestions exist:
11 11
       | text             |
@@ -19,11 +19,11 @@ Feature: The whole app
19 19
 
20 20
   Scenario: Existing user tries to get some and is happy with everything
21 21
     Given the following users exist:
22  
-      | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob          | Looking For Minimum Age | Looking For Maximum Age | Description | Name  |
23  
-      | 13333333333  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | red hair    | Mike  |
24  
-      | 14444444444  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | red hair    | Mike  |
25  
-      | 15555555555  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | red hair    | Mike  |
26  
-      | 16666666666  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | red hair    | Mike  |
  22
+      | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob          | Looking For Minimum Age | Looking For Maximum Age | Name  |
  23
+      | 13333333333  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | Mike  |
  24
+      | 14444444444  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | Mike  |
  25
+      | 15555555555  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | Mike  |
  26
+      | 16666666666  | true | false  | false            | true               | 11/06/1989   | 18                      | 34                      | Mike  |
27 27
     When "18004688487" texts instalover with "new date"
28 28
     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."
29 29
 
@@ -189,3 +189,47 @@ Feature: The whole app
189 189
     And "19998675309" texts instalover with "new date"
190 190
     Then "19998675309" should get a text whose message includes "Before you can become an instalover you must know this secret code"
191 191
     And  "19998675309" should get a text whose message includes "Visit instalover.com to finish signing up."
  192
+
  193
+  Scenario: Asking for a date with a woman
  194
+    Given the following users exist:
  195
+      | Phone Number | Male  | Female | Looking For Male | Looking For Female | Dob          | Looking For Minimum Age | Looking For Maximum Age | Name  |
  196
+      | 16176060842  | false | true   | true             | true               | 11/06/1989   | 18                      | 34                      | Becca |
  197
+    When "18004688487" texts instalover with "woman"
  198
+    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."
  199
+    When "18004688487" texts instalover with "ok"
  200
+    Then "16176060842" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  201
+    But "11111111111" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  202
+
  203
+  Scenario: Asking for a date with a man
  204
+    Given the following users exist:
  205
+      | Phone Number | Male  | Female | Looking For Male | Looking For Female | Dob          | Looking For Minimum Age | Looking For Maximum Age | Name  |
  206
+      | 16176060842  | false | true   | true             | true               | 11/06/1989   | 18                      | 34                      | Becca |
  207
+    When "18004688487" texts instalover with "man"
  208
+    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."
  209
+    When "18004688487" texts instalover with "ok"
  210
+    Then "11111111111" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  211
+    But "16176060842" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  212
+
  213
+  Scenario: Asking for a date with other
  214
+    Given the following users exist:
  215
+      | Phone Number | Male  | Female | Other | Looking For Male | Looking For Female | Looking For Other | Dob          | Looking For Minimum Age | Looking For Maximum Age | Name  |
  216
+      | 16176060842  | false | true   | false | true             | true               | true              | 11/06/1989   | 18                      | 34                      | Becca |
  217
+      | 16171231234  | false | false  | true  | true             | true               | true              | 11/06/1989   | 18                      | 34                      | Pat   |
  218
+    When "18004688487" texts instalover with "other"
  219
+    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."
  220
+    When "18004688487" texts instalover with "ok"
  221
+    Then "16171231234" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  222
+    But "16176060842" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  223
+    And "11111111111" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  224
+
  225
+  Scenario: Asking for a date with anything
  226
+    Given the following users exist:
  227
+      | Phone Number | Male  | Female | Other | Looking For Male | Looking For Female | Looking For Other | Dob          | Looking For Minimum Age | Looking For Maximum Age | Name  |
  228
+      | 16176060842  | false | true   | false | true             | true               | true              | 11/06/1989   | 18                      | 34                      | Becca |
  229
+      | 16171231234  | false | false  | true  | true             | true               | true              | 11/06/1989   | 18                      | 34                      | Pat   |
  230
+    When "18004688487" texts instalover with "whatever"
  231
+    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."
  232
+    When "18004688487" texts instalover with "ok"
  233
+    Then "16171231234" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  234
+    And "16176060842" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
  235
+    And "11111111111" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
5  spec/factories.rb
@@ -23,3 +23,8 @@
23 23
   meetup_factory.association :second_user, :factory => :user
24 24
   meetup_factory.state 'scheduled'
25 25
 end
  26
+
  27
+Factory.define :proposed_meetup, :class => Meetup do |meetup_factory|
  28
+  meetup_factory.association :first_user, :factory => :user
  29
+  meetup_factory.state 'proposed'
  30
+end

0 notes on commit 36d4492

Please sign in to comment.
Something went wrong with that request. Please try again.