Skip to content
Browse files

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

  • Loading branch information...
1 parent 2df6ede commit 36d4492cfc0b16458b16293f4b2c584efab9931f @mike-burns mike-burns committed
View
8 app/models/meetup.rb
@@ -7,6 +7,7 @@ class Meetup < ActiveRecord::Base
has_many :dflns
after_save :schedule_jobs
+ before_validation :set_default_desired_genders
validates_presence_of :first_user_id
@@ -97,4 +98,11 @@ def schedule_jobs
QUEUE.enqueue_at(morning_after, MorningAfterCheckerUpper, { :meetup_id => self.id })
end
end
+
+ def set_default_desired_genders
+ self.desires_male = !!first_user.looking_for_male if desires_male.nil?
+ self.desires_female = !!first_user.looking_for_female if desires_female.nil?
+ self.desires_other = !!first_user.looking_for_other if desires_other.nil?
+ true
+ end
end
View
23 app/models/message.rb
@@ -82,6 +82,14 @@ def self.handle_incoming(phone_number, message_text)
handle_safeword(user)
elsif message_text =~ /^\s*#{COMMANDS[:retry].gsub(' ','.*')}/i
handle_retry(user)
+ elsif message_text =~ /^\s*#{COMMANDS[:women_only].gsub(' ','.*')}/i
+ handle_new_date(user, :desires_male => false, :desires_female => true, :desires_other => false)
+ elsif message_text =~ /^\s*#{COMMANDS[:men_only].gsub(' ','.*')}/i
+ handle_new_date(user, :desires_male => true, :desires_female => false, :desires_other => false)
+ elsif message_text =~ /^\s*#{COMMANDS[:other_only].gsub(' ','.*')}/i
+ handle_new_date(user, :desires_male => false, :desires_female => false, :desires_other => true)
+ elsif message_text =~ /^\s*#{COMMANDS[:anything].gsub(' ','.*')}/i
+ handle_new_date(user, :desires_male => true, :desires_female => true, :desires_other => true)
else
handle_unknown(user)
end
@@ -95,7 +103,7 @@ def self.handle_texting_proxy(user, message)
end
end
- def self.handle_new_date(user)
+ def self.handle_new_date(user, meetup_restrictions = {})
if within_dating_hours?
user.founded_meetups.proposed.destroy_all
@@ -104,10 +112,11 @@ def self.handle_new_date(user)
else
user.offers.cancel_all
- meetup = Meetup.create({
- :first_user => user,
- :description => DateSuggestion.next_place_and_time
- })
+ meetup = Meetup.create(
+ meetup_restrictions.merge(
+ :first_user => user,
+ :description => DateSuggestion.next_place_and_time)
+ )
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)
if within_dating_hours?
if meetup = user.founded_meetups.retryable.last
meetup.unschedule!
- user.matching.first(5).each do |matching_user|
+ user.matching_for_meetup(meetup).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)
@@ -149,7 +158,7 @@ def self.handle_ok(user)
meetup = user.founded_meetups.proposed.first
if meetup
meetup.unschedule!
- user.matching.first(5).each do |matching_user|
+ user.matching_for_meetup(meetup).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)
View
12 app/models/user.rb
@@ -55,11 +55,11 @@ def self.other
where('users.other')
end
- def self.looking_for_gender(user)
+ def self.looking_for_gender(meetup)
wheres = []
- wheres << 'users.male' if user.looking_for_male
- wheres << 'users.female' if user.looking_for_female
- wheres << 'users.other' if user.looking_for_other
+ wheres << 'users.male' if meetup.desires_male
+ wheres << 'users.female' if meetup.desires_female
+ wheres << 'users.other' if meetup.desires_other
where(wheres.join(' OR '))
end
@@ -92,13 +92,13 @@ def date
Meetup.for(self).scheduled.newest.first.try(:for, self)
end
- def matching
+ def matching_for_meetup(meetup)
User.
within_age_range(self.looking_for_minimum_age, self.looking_for_maximum_age).
looking_for(self).
without_offers.
without_founded_meetups_in_progress.
- looking_for_gender(self).
+ looking_for_gender(meetup).
exclude(self).
sort_by_least_offered
end
View
11 app/views/pages/how-does-this-work.html.erb
@@ -2,9 +2,18 @@
<ul>
<li><span><%= COMMANDS[:new_date] %></span> &mdash; request a new date</li>
- <li><span><%= COMMANDS[:retry] %></span> &mdash; ask more people out on a date</li>
<li><span><%= COMMANDS[:ok] %></span> &mdash; confirm time and place for your date</li>
<li><span><%= COMMANDS[:accept] %></span> &mdash; accept a date request</li>
<li><span><%= COMMANDS[:sext] %> [your message]</span> &mdash; send a text to your date </li>
<li><span><%= COMMANDS[:quit] %></span> &mdash; cancel your account</li>
</ul>
+
+<h2>Or get fancy with these advanced commands:</h2>
+
+<ul>
+ <li><span><%= COMMANDS[:retry] %></span> &mdash; ask more people out on a date to the same place</li>
+ <li><span><%= COMMANDS[:women_only] %></span> &mdash; only ask out women</li>
+ <li><span><%= COMMANDS[:men_only] %></span> &mdash; only ask out men</li>
+ <li><span><%= COMMANDS[:other_only] %></span> &mdash; only ask out people who identify as something else</li>
+ <li><span><%= COMMANDS[:anything] %></span> &mdash; ask out everything we have</li>
+</ul>
View
16 config/initializers/commands.rb
@@ -1,8 +1,12 @@
COMMANDS = {
- :new_date => 'new date',
- :ok => 'ok',
- :accept => 'accept',
- :sext => 'say',
- :quit => 'safeword',
- :retry => 'retry'
+ :new_date => 'new date',
+ :ok => 'ok',
+ :accept => 'accept',
+ :sext => 'say',
+ :quit => 'safeword',
+ :retry => 'retry',
+ :women_only => 'woman',
+ :men_only => 'man',
+ :other_only => 'other',
+ :anything => 'whatever'
}
View
13 db/migrate/20101112195124_add_desires_to_meetups.rb
@@ -0,0 +1,13 @@
+class AddDesiresToMeetups < ActiveRecord::Migration
+ def self.up
+ add_column :meetups, :desires_female, :boolean
+ add_column :meetups, :desires_male, :boolean
+ add_column :meetups, :desires_other, :boolean
+ end
+
+ def self.down
+ remove_column :meetups, :desires_other
+ remove_column :meetups, :desires_male
+ remove_column :meetups, :desires_female
+ end
+end
View
5 features/step_definitions/matching_steps.rb
@@ -3,6 +3,9 @@
user = User.find_by_name!(user_name)
expected_matches = list_of_match_names.map { |match_name| User.find_by_name!(match_name) }
+ meetup = Meetup.create(:first_user => user, :state => 'proposed')
- user.matching.map(&:phone_number).should =~ expected_matches.map(&:phone_number)
+ user.matching_for_meetup(meetup).map(&:phone_number).should =~ expected_matches.map(&:phone_number)
+
+ meetup.destroy
end
View
62 features/the_app.feature
@@ -2,10 +2,10 @@ Feature: The whole app
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 |
- | 12222222222 | true | false | false | true | 10/20/1989 | 18 | 34 | black shirt | Jason |
- | 18004688487 | false| true | true | false | 12/31/1977 | 14 | 22 | super hot | Emma |
+ | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob | Looking For Minimum Age | Looking For Maximum Age | Name |
+ | 11111111111 | true | false | false | true | 11/06/1989 | 18 | 34 | Mike |
+ | 12222222222 | true | false | false | true | 10/20/1989 | 18 | 34 | Jason |
+ | 18004688487 | false| true | true | false | 12/31/1977 | 14 | 22 | Emma |
And the day and time is "October 16, 2010 8:00pm est"
And the following date suggestions exist:
| text |
@@ -19,11 +19,11 @@ Feature: The whole app
Scenario: Existing user tries to get some and is happy with everything
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 |
- | 13333333333 | true | false | false | true | 11/06/1989 | 18 | 34 | red hair | Mike |
- | 14444444444 | true | false | false | true | 11/06/1989 | 18 | 34 | red hair | Mike |
- | 15555555555 | true | false | false | true | 11/06/1989 | 18 | 34 | red hair | Mike |
- | 16666666666 | true | false | false | true | 11/06/1989 | 18 | 34 | red hair | Mike |
+ | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob | Looking For Minimum Age | Looking For Maximum Age | Name |
+ | 13333333333 | true | false | false | true | 11/06/1989 | 18 | 34 | Mike |
+ | 14444444444 | true | false | false | true | 11/06/1989 | 18 | 34 | Mike |
+ | 15555555555 | true | false | false | true | 11/06/1989 | 18 | 34 | Mike |
+ | 16666666666 | true | false | false | true | 11/06/1989 | 18 | 34 | Mike |
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."
@@ -189,3 +189,47 @@ Feature: The whole app
And "19998675309" texts instalover with "new date"
Then "19998675309" should get a text whose message includes "Before you can become an instalover you must know this secret code"
And "19998675309" should get a text whose message includes "Visit instalover.com to finish signing up."
+
+ Scenario: Asking for a date with a woman
+ Given the following users exist:
+ | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob | Looking For Minimum Age | Looking For Maximum Age | Name |
+ | 16176060842 | false | true | true | true | 11/06/1989 | 18 | 34 | Becca |
+ When "18004688487" texts instalover with "woman"
+ 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."
+ When "18004688487" texts instalover with "ok"
+ Then "16176060842" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+ But "11111111111" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+
+ Scenario: Asking for a date with a man
+ Given the following users exist:
+ | Phone Number | Male | Female | Looking For Male | Looking For Female | Dob | Looking For Minimum Age | Looking For Maximum Age | Name |
+ | 16176060842 | false | true | true | true | 11/06/1989 | 18 | 34 | Becca |
+ When "18004688487" texts instalover with "man"
+ 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."
+ When "18004688487" texts instalover with "ok"
+ Then "11111111111" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+ But "16176060842" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+
+ Scenario: Asking for a date with other
+ Given the following users exist:
+ | Phone Number | Male | Female | Other | Looking For Male | Looking For Female | Looking For Other | Dob | Looking For Minimum Age | Looking For Maximum Age | Name |
+ | 16176060842 | false | true | false | true | true | true | 11/06/1989 | 18 | 34 | Becca |
+ | 16171231234 | false | false | true | true | true | true | 11/06/1989 | 18 | 34 | Pat |
+ When "18004688487" texts instalover with "other"
+ 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."
+ When "18004688487" texts instalover with "ok"
+ Then "16171231234" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+ But "16176060842" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+ And "11111111111" should not get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+
+ Scenario: Asking for a date with anything
+ Given the following users exist:
+ | Phone Number | Male | Female | Other | Looking For Male | Looking For Female | Looking For Other | Dob | Looking For Minimum Age | Looking For Maximum Age | Name |
+ | 16176060842 | false | true | false | true | true | true | 11/06/1989 | 18 | 34 | Becca |
+ | 16171231234 | false | false | true | true | true | true | 11/06/1989 | 18 | 34 | Pat |
+ When "18004688487" texts instalover with "whatever"
+ 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."
+ When "18004688487" texts instalover with "ok"
+ Then "16171231234" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+ And "16176060842" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
+ And "11111111111" should get a text "Want to go on a date with Emma at Silvertone at 09:00PM? Reply 'accept' or ignore."
View
5 spec/factories.rb
@@ -23,3 +23,8 @@
meetup_factory.association :second_user, :factory => :user
meetup_factory.state 'scheduled'
end
+
+Factory.define :proposed_meetup, :class => Meetup do |meetup_factory|
+ meetup_factory.association :first_user, :factory => :user
+ meetup_factory.state 'proposed'
+end

0 comments on commit 36d4492

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