Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding subscribed flag to ringer to allow ringer unsubscrib and resub…

…scribe to the movement.
  • Loading branch information...
commit ec99204b6e2474819315250d104129b2bd6053b9 1 parent d02ae83
Willa authored
6 lib/crowdring/assigned_phone_number.rb
@@ -5,8 +5,6 @@ def self.included(base)
5 5 include DataMapper::Resource
6 6
7 7 property :phone_number, DataMapper::Property::String, key: true
8   -
9   -
10 8 validates_uniqueness_of :phone_number
11 9
12 10 def phone_number=(number)
@@ -17,7 +15,6 @@ def self.from(number)
17 15 norm_number = Phoner::Phone.parse(number).to_s
18 16 self.first(phone_number: norm_number)
19 17 end
20   -
21 18 end
22 19 end
23 20 end
@@ -46,7 +43,7 @@ def ring(ringer)
46 43
47 44 class AssignedUnsubscribeVoiceNumber < AssignedVoiceNumber
48 45 def ring(ringer)
49   - #ringer rang an unsubscribe number
  46 + ringer.unsubscribe
50 47 end
51 48 end
52 49
@@ -74,6 +71,7 @@ def self.from(type, number)
74 71 def self.handle(type, request)
75 72 number = from(type, request.to)
76 73 ringer = Ringer.from(request.from)
  74 + ringer.subscribe
77 75
78 76 case number
79 77 when AssignedVoiceNumber
3  lib/crowdring/filtered_message.rb
@@ -13,7 +13,7 @@ def tags=(tags)
13 13 end
14 14
15 15 def accept?(ringer)
16   - tag_filter.accept?(ringer)
  16 + tag_filter.accept?(ringer) && ringer.subscribed?
17 17 end
18 18
19 19 def send_message(params)
@@ -26,6 +26,5 @@ def send_message(params)
26 26 false
27 27 end
28 28 end
29   -
30 29 end
31 30 end
17 lib/crowdring/ringer.rb
@@ -14,6 +14,7 @@ class Ringer
14 14 property :id, Serial
15 15 property :phone_number, String, unique: true
16 16 property :created_at, DateTime
  17 + property :subscribed, Boolean, default: true
17 18
18 19 has n, :ringer_taggings, constraint: :destroy
19 20 has n, :tags, through: :ringer_taggings, constraint: :skip
@@ -39,5 +40,21 @@ def add_tags
39 40 tags.concat(RegionTags.tags_for(number))
40 41 save
41 42 end
  43 +
  44 + def unsubscribe
  45 + update(subscribed: false)
  46 + end
  47 +
  48 + def subscribe
  49 + update(subscribed: true)
  50 + end
  51 +
  52 + def subscribed?
  53 + subscribed
  54 + end
  55 +
  56 + def unsubscribed?
  57 + !subscribed
  58 + end
42 59 end
43 60 end
26 spec/assigned_phone_number_spec.rb
@@ -69,4 +69,30 @@
69 69 end
70 70 end
71 71
  72 +describe Crowdring::AssignedUnsubscribeVoiceNumber do
  73 + before(:each) do
  74 + DataMapper.auto_migrate!
  75 + Crowdring::AssignedUnsubscribeVoiceNumber.create(phone_number: '+18002222222')
  76 + end
  77 +
  78 + it 'should unsubscribe a ringer when calls' do
  79 + Crowdring::Ringer.create(phone_number: '+18000000000')
  80 + request = double('request', from: '+18000000000', to:'+18002222222')
  81 + Crowdring::AssignedPhoneNumber.handle(:voice, request)
  82 +
  83 + Crowdring::Ringer.first.unsubscribed?.should be_true
  84 + end
  85 +
  86 + it 'should re-subscribe a ringer when calls after unsubscribing' do
  87 + @campaign = Crowdring::Campaign.create(title: 'test')
  88 + @campaign.voice_numbers.new(phone_number: '+18001111111', description: 'desc')
  89 + @campaign.sms_number = Crowdring::AssignedSMSNumber.new(phone_number: '+18002222222')
  90 + @campaign.save
72 91
  92 + Crowdring::Ringer.create(phone_number: '+18000000000', subscribed: false)
  93 + request = double('request', from: '+18000000000', to:'+18001111111')
  94 + Crowdring::AssignedPhoneNumber.handle(:voice, request)
  95 +
  96 + Crowdring::Ringer.first.subscribed?.should be_true
  97 + end
  98 +end

0 comments on commit ec99204

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