4info 1.2.0 → 1.2.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.
- data/4info.gemspec +1 -1
- data/README.markdown +11 -0
- data/VERSION +1 -1
- data/lib/contactable.rb +12 -0
- data/test/four_info_contactable_test.rb +6 -3
- data/test/four_info_controller_test.rb +5 -3
- metadata +1 -1
data/4info.gemspec
CHANGED
data/README.markdown
CHANGED
@@ -28,6 +28,17 @@ You can also specify which attributes you'd like to use instead of the defaults
|
|
28
28
|
# Defaults to the name on the left (minus the '_column' at the end)
|
29
29
|
end
|
30
30
|
|
31
|
+
Phone number formatting
|
32
|
+
---
|
33
|
+
|
34
|
+
Whatever is stored in the sms_phone_number_column will be subject to normalized formatting:
|
35
|
+
|
36
|
+
user = User.create :sms_phone_number => '(206) 555-1234'
|
37
|
+
user.sms_phone_number # => 2065551234
|
38
|
+
|
39
|
+
If you want to preserve the format of the number exactly as the user entered it you'll want
|
40
|
+
to save it in a different attribute.
|
41
|
+
|
31
42
|
|
32
43
|
Confirming Phone Number And Sending Messages
|
33
44
|
====
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.1
|
data/lib/contactable.rb
CHANGED
@@ -39,6 +39,18 @@ module FourInfo
|
|
39
39
|
end
|
40
40
|
"
|
41
41
|
end
|
42
|
+
|
43
|
+
# normalize the phone number before it's saved in the database
|
44
|
+
# (only for model classes using callbacks a la ActiveRecord,
|
45
|
+
# other folks will have to do this by hand)
|
46
|
+
if model.respond_to?(:before_save)
|
47
|
+
model.before_save :normalize_sms_phone_number
|
48
|
+
model.class_eval do
|
49
|
+
def normalize_sms_phone_number
|
50
|
+
self.four_info_sms_phone_number = FourInfo.numerize(four_info_sms_phone_number)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
# Sends one or more TXT messages to the contactable record's
|
@@ -54,11 +54,14 @@ class FourInfoContactableTest < ActiveSupport::TestCase
|
|
54
54
|
context "contactable instance" do
|
55
55
|
setup {
|
56
56
|
User.delete_all
|
57
|
-
@user = User.create!
|
57
|
+
@user = User.create! User.sms_phone_number_column => '(555) 123-4567'
|
58
58
|
}
|
59
59
|
|
60
|
+
should "normalize phone number" do
|
61
|
+
assert_equal '5551234567', @user.four_info_sms_phone_number
|
62
|
+
end
|
60
63
|
context "when phone number is blank" do
|
61
|
-
setup { @user.
|
64
|
+
setup { @user.four_info_sms_phone_number = nil}
|
62
65
|
context "confirming phone number" do
|
63
66
|
setup { @user.send_sms_confirmation! }
|
64
67
|
should_not_change "any attributes" do
|
@@ -78,7 +81,7 @@ class FourInfoContactableTest < ActiveSupport::TestCase
|
|
78
81
|
end
|
79
82
|
|
80
83
|
context "when phone number exists" do
|
81
|
-
setup { @user.
|
84
|
+
setup { @user.four_info_sms_phone_number = "206-555-5555"}
|
82
85
|
context "confirming phone number" do
|
83
86
|
setup {
|
84
87
|
FourInfo::Request.any_instance.stubs(:perform).returns(ValidationSuccess)
|
@@ -24,13 +24,15 @@ class FourInfoControllerTest < ActionController::TestCase
|
|
24
24
|
context "with a user" do
|
25
25
|
setup {
|
26
26
|
User.delete_all
|
27
|
-
@user = User.create! :sms_phone_number => '
|
27
|
+
@user = User.create! :sms_phone_number => '(206) 335-1596'
|
28
|
+
# and we should be able to find @user by this formatted version
|
29
|
+
@formatted_phone_number = "2063351596"
|
28
30
|
}
|
29
31
|
context "receiving BLOCK" do
|
30
32
|
setup {
|
31
33
|
post :index,
|
32
34
|
# this is what an xml request will parse to:
|
33
|
-
"request"=>{"block"=>{"recipient"=>{"property"=>{"name"=>"CARRIER", "value"=>"3"}, "id"=>"+1#{@
|
35
|
+
"request"=>{"block"=>{"recipient"=>{"property"=>{"name"=>"CARRIER", "value"=>"3"}, "id"=>"+1#{@formatted_phone_number}", "type"=>"5"}}, "type" => "BLOCK"}
|
34
36
|
}
|
35
37
|
should_respond_with :success
|
36
38
|
should "block user" do
|
@@ -43,7 +45,7 @@ class FourInfoControllerTest < ActionController::TestCase
|
|
43
45
|
context "receiving MESSAGE" do
|
44
46
|
setup {
|
45
47
|
# this is what an xml request will parse to:
|
46
|
-
@receive_params = {"request"=>{"message"=>{"id" => "ABCDEFG", "recipient"=>{"type"=> "6", "id"=>"12345"}, "sender" => {"type" => "5", "id" => "+1#{@
|
48
|
+
@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"}}
|
47
49
|
}
|
48
50
|
context "when the user is not set up to receive" do
|
49
51
|
setup {
|