twilio_contactable 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ class TwilioContactableController < ActionController::Base
4
+ include TwilioContactable::Controller
5
+
6
+ twilio_contactable User
7
+ end
8
+
9
+ begin
10
+ ActionController::Routing::Routes
11
+ rescue
12
+ Rails.application.routes
13
+ end.draw do |map|
14
+ map.route ':controller/:action', :controller => 'twilio_contactable'
15
+ end
16
+
17
+ class UserWithSMSReceiving < User
18
+ def receive_sms(message)
19
+ end
20
+ end
21
+
22
+ class TwilioContactableControllerTest < ActionController::TestCase
23
+
24
+ context "with a user" do
25
+ setup {
26
+ User.delete_all
27
+ @user = User.create! :phone_number => '(206) 335-1596'
28
+ # and we should be able to find @user by this formatted version
29
+ @formatted_phone_number = "2063351596"
30
+ }
31
+ context "receiving sms message" do
32
+ context "receiving BLOCK" do
33
+ setup {
34
+ post :receive_sms_message,
35
+ # this is what an xml request will parse to:
36
+ "request"=>{"block"=>{"recipient"=>{"property"=>{"name"=>"CARRIER", "value"=>"3"}, "id"=>"+1#{@formatted_phone_number}", "type"=>"5"}}, "type" => "BLOCK"}
37
+ }
38
+ should_respond_with :success
39
+ should "block user" do
40
+ assert @user.reload.sms_blocked?
41
+ end
42
+ should_change "user block status" do
43
+ @user.reload.sms_blocked?
44
+ end
45
+ end
46
+ context "receiving MESSAGE" do
47
+ setup {
48
+ # this is what an xml request will parse to:
49
+ @receive_params = {"request"=>{"message"=>{"id" => "ABCDEFG", "recipient"=>{"type"=> "6", "id"=>"12345"}, "sender" => {"type" => "5", "id" => "+1#{@formatted_phone_number}", "property" => {"name" => "CARRIER", "value" => "5"}}, "text" => "This is a text message."}, "type" => "MESSAGE"}}
50
+ }
51
+ context "when the user is not set up to receive" do
52
+ setup {
53
+ @user.expects(:receive_sms).with("This is a text message.").never
54
+ post :receive_sms_message, @receive_params
55
+ }
56
+ should_respond_with :success
57
+ should "not block user" do
58
+ assert !@user.reload.sms_blocked?
59
+ end
60
+ end
61
+ context "when the user is set up to receive" do
62
+ setup {
63
+ User.delete_all
64
+ @new_user = UserWithSMSReceiving.create!(:phone_number => @user.phone_number)
65
+ UserWithSMSReceiving.any_instance.expects(:receive_sms).with("This is a text message.").once
66
+ post :receive_sms_message, @receive_params
67
+ }
68
+ should_respond_with :success
69
+ should "not block user" do
70
+ assert !@new_user.reload.sms_blocked?
71
+ end
72
+ end
73
+ end
74
+ end
75
+ context "initiating a digit-gathering call from Twilio" do
76
+ setup {
77
+ @receive_params = {"FromState"=>"WA", "CallerCountry"=>"US", "CallerZip"=>"98077", "ToState"=>"WA", "Caller"=>"+#{@formatted_phone_number}", "AccountSid"=>"SOME_ACCOUNT", "contactable_type"=>"User", "Direction"=>"outbound-api", "FromCity"=>"WOODINVILLE", "From"=>"+5555555555", "contactable_id"=>"1", "CallerCity"=>"WOODINVILLE", "FromCountry"=>"US", "FromZip"=>"98077", "CallStatus"=>"in-progress", "To"=>"+12069305710", "ToCity"=>"SEATTLE", "Called"=>"+12069305710", "CalledCountry"=>"US", "CalledZip"=>"98188", "ApiVersion"=>"2010-04-01", "CalledCity"=>"SEATTLE", "CallSid"=>"CA76af6e953077fc478c9f2eb330484ea7", "CalledState"=>"WA", "ToCountry"=>"US", "ToZip"=>"98188", "CallerState"=>"WA"}
78
+ get :start_voice_confirmation, @receive_params
79
+ }
80
+ should_respond_with :success
81
+ should_respond_with_content_type :xml
82
+ should "render Gather TwiML node with a Say inside" do
83
+ assert_dom_equal %q{
84
+ <response>
85
+ <gather
86
+ action="http://test.host/twilio_contactable/receive_voice_confirmation?contactable_id=1&amp;contactable_type=User"
87
+ >
88
+ <say>
89
+ Please type the numbers that appear on your screen, followed by the pound sign
90
+ </say>
91
+ </gather>
92
+ </response>
93
+ }, @response.body
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ class TwilioContactableModuleTest < ActiveSupport::TestCase
4
+
5
+ context "standardizing numbers" do
6
+ context "to digits" do
7
+ should "remove all but integers" do
8
+ assert_equal '12345', TwilioContactable.numerize('1-2-3-4-5')
9
+ assert_equal '12345', TwilioContactable.numerize('1 2 3 4 5')
10
+ assert_equal '12345', TwilioContactable.numerize('1,2(3)4.5')
11
+ assert_equal '12345', TwilioContactable.numerize('1,2(3)4.5')
12
+ end
13
+ end
14
+ context "to international format" do
15
+ should "add a '+' to all 11 digit numbers" do
16
+ assert_equal '+12345678901', TwilioContactable.internationalize('12345678901')
17
+ assert_equal '+72345678901', TwilioContactable.internationalize('72345678901')
18
+ end
19
+ should "add a '+1' to any 10 digit number" do
20
+ assert_equal '+12345678901', TwilioContactable.internationalize('2345678901')
21
+ assert_equal '+17345678901', TwilioContactable.internationalize('7345678901')
22
+ end
23
+ should "leave 12 digit numbers unchanged" do
24
+ [ '+' + ('3'*11),
25
+ '+' + ('8'*11),
26
+ '+' + ('4'*11) ].each do |number|
27
+ assert_equal number, TwilioContactable.internationalize(number)
28
+ end
29
+ end
30
+ should "return nil for all bad numbers" do
31
+ assert_equal nil, TwilioContactable.internationalize(nil)
32
+ assert_equal nil, TwilioContactable.internationalize('nil')
33
+ assert_equal nil, TwilioContactable.internationalize('1234')
34
+ assert_equal nil, TwilioContactable.internationalize('11111111111111111111111')
35
+ assert_equal nil, TwilioContactable.internationalize('what?')
36
+ end
37
+ end
38
+ end
39
+
40
+ context "generating codes" do
41
+ setup { @code = TwilioContactable.generate_confirmation_code }
42
+ should "be 6 digits" do
43
+ assert_equal 6, @code.length
44
+ end
45
+ end
46
+
47
+ context "confirmation message" do
48
+ setup {
49
+ @code = 'ABC123'
50
+ @message = TwilioContactable.confirmation_message(@code)
51
+ }
52
+ should "include code" do
53
+ assert @message.include?(@code)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{twilio_contactable}
8
+ s.version = "0.7.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jack Danger Canty"]
12
+ s.date = %q{2010-09-01}
13
+ s.description = %q{Does all the hard work with letting you confirm your user's phone numbers for Voice or TXT over the Twilio API}
14
+ s.email = %q{gitcommit@6brand.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.markdown",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "init.rb",
24
+ "lib/configuration.rb",
25
+ "lib/contactable.rb",
26
+ "lib/controller.rb",
27
+ "lib/gateway.rb",
28
+ "lib/twilio_contactable.rb",
29
+ "test/.gitignore",
30
+ "test/database.yml",
31
+ "test/test_helper.rb",
32
+ "test/twilio_contactable_contactable_test.rb",
33
+ "test/twilio_contactable_controller_test.rb",
34
+ "test/twilio_module_test.rb",
35
+ "twilio_contactable.gemspec"
36
+ ]
37
+ s.homepage = %q{http://github.com/JackDanger/twilio_contactable}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.6}
41
+ s.summary = %q{Help authorize the users of your Rails apps to confirm and use their phone numbers}
42
+ s.test_files = [
43
+ "test/test_helper.rb",
44
+ "test/twilio_contactable_contactable_test.rb",
45
+ "test/twilio_contactable_controller_test.rb",
46
+ "test/twilio_module_test.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<twiliolib>, [">= 2.0.5"])
55
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_development_dependency(%q<mocha>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<twiliolib>, [">= 2.0.5"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<mocha>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<twiliolib>, [">= 2.0.5"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<mocha>, [">= 0"])
66
+ end
67
+ end
68
+
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twilio_contactable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 1
9
+ version: 0.7.1
10
+ platform: ruby
11
+ authors:
12
+ - Jack Danger Canty
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-01 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: twiliolib
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 5
31
+ version: 2.0.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: Does all the hard work with letting you confirm your user's phone numbers for Voice or TXT over the Twilio API
59
+ email: gitcommit@6brand.com
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - README.markdown
66
+ files:
67
+ - MIT-LICENSE
68
+ - README.markdown
69
+ - Rakefile
70
+ - VERSION
71
+ - init.rb
72
+ - lib/configuration.rb
73
+ - lib/contactable.rb
74
+ - lib/controller.rb
75
+ - lib/gateway.rb
76
+ - lib/twilio_contactable.rb
77
+ - test/.gitignore
78
+ - test/database.yml
79
+ - test/test_helper.rb
80
+ - test/twilio_contactable_contactable_test.rb
81
+ - test/twilio_contactable_controller_test.rb
82
+ - test/twilio_module_test.rb
83
+ - twilio_contactable.gemspec
84
+ has_rdoc: true
85
+ homepage: http://github.com/JackDanger/twilio_contactable
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Help authorize the users of your Rails apps to confirm and use their phone numbers
114
+ test_files:
115
+ - test/test_helper.rb
116
+ - test/twilio_contactable_contactable_test.rb
117
+ - test/twilio_contactable_controller_test.rb
118
+ - test/twilio_module_test.rb