4info 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{4info}
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jack Danger Canty"]
@@ -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.0
1
+ 1.2.1
@@ -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! :sms_phone_number => '555-555-5555'
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.sms_phone_number = nil}
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.sms_phone_number = "206-555-5555"}
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 => '3334445555'
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#{@user.sms_phone_number}", "type"=>"5"}}, "type" => "BLOCK"}
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#{@user.sms_phone_number}", "property" => {"name" => "CARRIER", "value" => "5"}}, "text" => "This is a text message."}, "type" => "MESSAGE"}}
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 {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 4info
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Danger Canty