Skip to content
Browse files

adding ignore international sms

  • Loading branch information...
1 parent 9d8bdb6 commit c8c1f9cc3cb654691ab4a07539e3e5db3c2e7c0d Willa committed Nov 16, 2012
Showing with 42 additions and 13 deletions.
  1. +1 −1 lib/crowdring/ask.rb
  2. +9 −3 lib/crowdring/filtered_message.rb
  3. +2 −2 lib/crowdring/message.rb
  4. +29 −6 spec/filtered_message_spec.rb
  5. +1 −1 spec/message_spec.rb
View
2 lib/crowdring/ask.rb
@@ -68,7 +68,7 @@ def initial_price_estimate(ringers=Ringer.all, sms_number)
return 0.0 if message.nil?
smss = ringers.map do |ringer|
- text = message.for(ringer)
+ text = message.for(ringer, sms_number)
text && OutgoingSMS.new(from: sms_number, to: ringer, text: text)
end
View
12 lib/crowdring/filtered_message.rb
@@ -12,12 +12,12 @@ def tags=(tags)
self.tag_filter = TagFilter.create(tags: tags)
end
- def accept?(ringer)
- tag_filter.accept?(ringer) && ringer.subscribed?
+ def accept?(ringer, sms_number)
+ tag_filter.accept?(ringer) && ringer.subscribed? && is_local?(ringer.phone_number, sms_number)
end
def send_message(params)
- if tag_filter.accept?(params[:to])
+ if accept?(params[:to], params[:from])
CompositeService.instance.send_sms(
from: params[:from], to: params[:to].phone_number,
msg: message_text)
@@ -26,5 +26,11 @@ def send_message(params)
false
end
end
+
+ def is_local?(phone_number, sms_number)
+ ringer_number = Phoner::Phone.parse phone_number
+ sms_number = Phoner::Phone.parse sms_number
+ ringer_number.country_code == sms_number.country_code
+ end
end
end
View
4 lib/crowdring/message.rb
@@ -29,8 +29,8 @@ def send_message(params)
prioritized_messages.find {|fm| fm.send_message(params) }
end
- def for(ringer)
- prioritized_messages.find {|fm| fm.accept?(ringer) }
+ def for(ringer, sms_number)
+ prioritized_messages.find {|fm| fm.accept?(ringer, sms_number) }
end
def default_message
View
35 spec/filtered_message_spec.rb
@@ -22,10 +22,10 @@
tag_filter.tags << pittsburgh
fm = Crowdring::FilteredMessage.create(tag_filter: tag_filter, priority: 1, message_text: 'msg')
- item1 = double('item1', tags: [pittsburgh], phone_number: @number2)
+ ringer = double('ringer', tags: [pittsburgh], phone_number: @number2, subscribed?: true)
@fooservice.should_receive(:send_sms).once.with(from: @number, to: @number2, msg: 'msg')
- fm.send_message(from: @number, to: item1)
+ fm.send_message(from: @number, to:ringer)
end
it 'should return true if it sent a message to the recipient' do
@@ -34,9 +34,9 @@
tag_filter.tags << pittsburgh
fm = Crowdring::FilteredMessage.create(tag_filter: tag_filter, priority: 1, message_text: 'msg')
- item1 = double('item1', tags: [pittsburgh], phone_number: @number2)
+ ringer = double('ringer', tags: [pittsburgh], phone_number: @number2, subscribed?: true)
- fm.send_message(from: @number, to: item1).should be_true
+ fm.send_message(from: @number, to: ringer).should be_true
end
it 'should return false if it did not send a message to the recipient' do
@@ -46,9 +46,32 @@
tag_filter.tags << chicago
fm = Crowdring::FilteredMessage.create(tag_filter: tag_filter, priority: 1, message_text: 'msg')
- item1 = double('item1', tags: [pittsburgh], phone_number: @number2)
+ ringer = double('ringer', tags: [pittsburgh], phone_number: @number2, subscribed?: true)
- fm.send_message(from: @number, to: item1).should be_false
+ fm.send_message(from: @number, to: ringer).should be_false
+ end
+
+ it 'should not send sms to a ringer who is unsubscribed' do
+ tag_filter = Crowdring::TagFilter.create
+ pittsburgh = Crowdring::Tag.from_str('area code:412')
+ chicago = Crowdring::Tag.from_str('area code:312')
+ tag_filter.tags << chicago
+
+ fm = Crowdring::FilteredMessage.create(tag_filter: tag_filter, priority: 1, message_text: 'msg')
+
+ ringer = double('ringer', tags: [chicago], phone_number: @number2, subscribed?: false)
+ fm.send_message(from: @number, to: ringer).should be_false
+ end
+
+ it 'should not send sms to a ringer who has international phone number' ,focus: true do
+ tag_filter = Crowdring::TagFilter.create
+ chicago = Crowdring::Tag.from_str('area code:312')
+ tag_filter.tags << chicago
+
+ fm = Crowdring::FilteredMessage.create(tag_filter: tag_filter, priority: 1, message_text: 'msg')
+
+ ringer = double('ringer', tags: [chicago], phone_number: '+912222222222', subscribed?: true)
+ fm.send_message(from: @number, to: ringer).should be_false
end
end
View
2 spec/message_spec.rb
@@ -13,7 +13,7 @@
transform_request: @fooresponse,
numbers: [@number],
send_sms: nil)
- @ringer = double('ringer', phone_number: @number2)
+ @ringer = double('ringer', phone_number: @number2, subscribed?: true)
Crowdring::CompositeService.instance.reset
Crowdring::CompositeService.instance.add('foo', @fooservice)
end

0 comments on commit c8c1f9c

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