action_sms 0.0.3 → 0.1.0

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,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActionSms::ConnectionAdapters::TropoAdapter do
4
+ let (:adapter_name) { "tropo" }
5
+ context "is not in test mode" do
6
+ let(:adapter) {
7
+ ActionSms::Base.tropo_connection(
8
+ :adapter => adapter_name
9
+ )
10
+ }
11
+
12
+ it "should not respond to #sample_configuration" do
13
+ adapter.should_not be_respond_to(:sample_configuration)
14
+ end
15
+
16
+ it "should not respond to #sample_delivery_response" do
17
+ adapter.should_not be_respond_to(:sample_delivery_response)
18
+ end
19
+
20
+ it "should not respond to #sample_incoming_sms" do
21
+ adapter.should_not be_respond_to(:sample_incoming_sms)
22
+ end
23
+ end
24
+
25
+ context "is in test mode" do
26
+ let(:adapter) {
27
+ ActionSms::Base.tropo_connection(
28
+ :adapter => adapter_name,
29
+ :environment => "test"
30
+ )
31
+ }
32
+
33
+ # Additional methods available in test mode
34
+
35
+ describe "#sample_configuration" do
36
+ it "should contain Tropo specific configuration" do
37
+ adapter.sample_configuration.should include(
38
+ :outgoing_token
39
+ )
40
+ end
41
+ it "should contain the correct adapter name" do
42
+ adapter.sample_configuration.should include(
43
+ :adapter => "tropo"
44
+ )
45
+ end
46
+ context "with options" do
47
+ context "authentication_key => true" do
48
+ it "should contain an authentication key" do
49
+ adapter.sample_configuration(
50
+ :authentication_key => true
51
+ ).should include(:authentication_key)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#sample_delivery_response" do
58
+ context "with no options" do
59
+ it "should return a successful delivery response" do
60
+ adapter.sample_delivery_response.should == "<session><success>true</success></session>"
61
+ end
62
+ end
63
+ context "with options" do
64
+ context "'failed'" do
65
+ it "should return a failed delivery response" do
66
+ adapter.sample_delivery_response(:failed => true).should == "<session><success>false</success><token></token><reason>FAILED TO ROUTE TOKEN</reason></session>"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "#sample_incoming_sms" do
73
+ context "with no options" do
74
+ it "should return the default values" do
75
+ session = adapter.sample_incoming_sms["session"]
76
+ session.should include(
77
+ "timestamp", "initial_text"
78
+ )
79
+ session["to"].should include("id")
80
+ session["from"].should include("id")
81
+ end
82
+ end
83
+ context "with options" do
84
+ context "'authentic'" do
85
+ it "should include an authentication key" do
86
+ adapter.sample_incoming_sms(:authentic => true).should include(
87
+ "authentication_key"
88
+ )
89
+ end
90
+ end
91
+ context "'message'" do
92
+ it "should include the option" do
93
+ session = adapter.sample_incoming_sms(
94
+ :message => "hello"
95
+ )["session"]
96
+ session.should include(
97
+ "initial_text" => "hello"
98
+ )
99
+ end
100
+ end
101
+ context "'to'" do
102
+ it "should include the option" do
103
+ session = adapter.sample_incoming_sms(
104
+ :to => "someone"
105
+ )["session"]
106
+ session["to"].should include(
107
+ "id" => "someone"
108
+ )
109
+ end
110
+ end
111
+ context "'from'" do
112
+ it "should include the option" do
113
+ session = adapter.sample_incoming_sms(
114
+ :from => "anyone"
115
+ )["session"]
116
+ session["from"].should include(
117
+ "id" => "anyone"
118
+ )
119
+ end
120
+ end
121
+ context "'date'" do
122
+ it "should include the option" do
123
+ session = adapter.sample_incoming_sms(
124
+ :date => "today"
125
+ )["session"]
126
+ session.should include(
127
+ "timestamp" => "today"
128
+ )
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
@@ -0,0 +1,198 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActionSms::ConnectionAdapters::TropoAdapter do
4
+ let(:adapter) { ActionSms::ConnectionAdapters::TropoAdapter.new }
5
+
6
+ describe "#deliver" do
7
+ let(:sms) { mock("sms").as_null_object }
8
+ let(:response) { "<session><success>true</success><token>my_secret_token</token></session>" }
9
+ before do
10
+ adapter.stub!(:send_http_request).and_return(response)
11
+ end
12
+
13
+ it "should try to send the sms to the correct url" do
14
+ adapter.should_receive(:send_http_request).with(
15
+ "http://api.tropo.com/1.0/sessions",
16
+ anything
17
+ )
18
+ adapter.deliver(sms)
19
+ end
20
+
21
+ it "should try to send the sms with the 'outgoing_token' configuration value" do
22
+ config = adapter.instance_variable_get(:@config)
23
+ adapter.instance_variable_set(
24
+ :@config, config.merge(:outgoing_token => "my_token")
25
+ )
26
+ adapter.should_receive(:send_http_request).with(
27
+ anything,
28
+ /my_token/
29
+ )
30
+ adapter.deliver(sms)
31
+ end
32
+
33
+ it "should try to send the sms with the result from 'sms#recipient'" do
34
+ sms.stub!(:recipient).and_return("somebody")
35
+ adapter.should_receive(:send_http_request).with(
36
+ anything,
37
+ /somebody/
38
+ )
39
+ adapter.deliver(sms)
40
+ end
41
+
42
+ context "sms#body is not nil" do
43
+ before do
44
+ sms.stub!(:body).and_return("something")
45
+ end
46
+
47
+ it "should try to send the sms with the sms' body" do
48
+ adapter.should_receive(:send_http_request).with(
49
+ anything,
50
+ /something/
51
+ )
52
+ adapter.deliver(sms)
53
+ end
54
+ end
55
+
56
+ context "sms#body is nil" do
57
+ before do
58
+ sms.stub!(:body).and_return(nil)
59
+ end
60
+
61
+ it "should try to send the sms with blank text" do
62
+ adapter.should_receive(:send_http_request).with(
63
+ anything,
64
+ /text/
65
+ )
66
+ adapter.deliver(sms)
67
+ end
68
+ end
69
+
70
+ context "sms' responds to '#from'" do
71
+ before do
72
+ sms.stub!(:from).and_return("anybody")
73
+ end
74
+ it "should try to send the sms with the result from 'sms#from'" do
75
+ adapter.should_receive(:send_http_request).with(
76
+ anything,
77
+ /anybody/
78
+ )
79
+ adapter.deliver(sms)
80
+ end
81
+ end
82
+
83
+ context "sms does not respond to '#from'" do
84
+ before do
85
+ sms.stub!(:respond_to?).and_return(false)
86
+ end
87
+ it "should try to send the sms without 'from'" do
88
+ adapter.should_receive(:send_http_request).with(
89
+ anything,
90
+ /^((?!from).)*$/
91
+ )
92
+ adapter.deliver(sms)
93
+ end
94
+ end
95
+
96
+ context ":filter_response => true" do
97
+ it "should not return the token" do
98
+ adapter.deliver(
99
+ sms, :filter_response => true
100
+ ).should == "<session><success>true</success></session>"
101
+ end
102
+ end
103
+
104
+ context ":filter_response => false" do
105
+ it "should return the token" do
106
+ adapter.deliver(
107
+ sms, :filter_response => false
108
+ ).should == response
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "#delivery_request_successful?" do
114
+ context "the gateway response was successful" do
115
+ let (:delivery_response) {
116
+ "<session><success>true</success></session>"
117
+ }
118
+ it "should not return nil" do
119
+ adapter.delivery_request_successful?(delivery_response).should_not be_nil
120
+ end
121
+ end
122
+ context "the gateway response was not successful" do
123
+ let (:delivery_response) { "<session><success>false</success><token></token><reason>FAILED TO ROUTE TOKEN</reason></session>" }
124
+ it "should return nil" do
125
+ adapter.delivery_request_successful?(delivery_response).should be_nil
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "#message_id" do
131
+ it "should return nil" do
132
+ adapter.message_id("any text").should be_nil
133
+ end
134
+ end
135
+
136
+ describe "#message_text" do
137
+ let (:request_params) { { "session" => {} } }
138
+ context "given valid incoming message request params" do
139
+ before do
140
+ request_params["session"]["initial_text"] = "ANYTHING"
141
+ end
142
+ it "should return the message" do
143
+ adapter.message_text(request_params).should_not be_nil
144
+ end
145
+ end
146
+ context "given invalid incoming message request params" do
147
+ it "should return nil" do
148
+ adapter.message_text(request_params).should be_nil
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "#sender" do
154
+ let (:request_params) { {"session" => { "from" => {} }}}
155
+ context "given valid incoming message request params" do
156
+ before do
157
+ request_params["session"]["from"]["id"] = "ANYTHING"
158
+ end
159
+ it "should return the message" do
160
+ adapter.sender(request_params).should_not be_nil
161
+ end
162
+ end
163
+ context "given invalid incoming message request params" do
164
+ it "should return nil" do
165
+ adapter.sender(request_params).should be_nil
166
+ end
167
+ end
168
+ end
169
+
170
+ describe "#service_url" do
171
+ it "should be the Tropo service url" do
172
+ adapter.service_url.should == "http://api.tropo.com/1.0/sessions"
173
+ end
174
+ context "#use_ssl=false" do
175
+ before do
176
+ adapter.use_ssl = false
177
+ end
178
+ it "should be 'http'" do
179
+ URI.parse(adapter.service_url).scheme.should == "http"
180
+ end
181
+ end
182
+ context "#use_ssl=true" do
183
+ before do
184
+ adapter.use_ssl = true
185
+ end
186
+ it "should be 'https'" do
187
+ URI.parse(adapter.service_url).scheme.should == "https"
188
+ end
189
+ end
190
+ end
191
+
192
+ describe "#status" do
193
+ it "should return nil" do
194
+ adapter.status({"status" => "success"}).should be_nil
195
+ end
196
+ end
197
+ end
198
+
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'action_sms'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+
data/todo CHANGED
@@ -1,2 +0,0 @@
1
- Add some tests
2
-
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Wilkie
@@ -14,41 +14,66 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-14 00:00:00 +07:00
17
+ date: 2010-11-12 00:00:00 +07:00
18
18
  default_executable:
19
- dependencies: []
20
-
21
- description:
22
- email: dwilkie@gmail.com
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: tropo_message
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Switch between SMS Gateways at a whim without modifying your application code or tests
34
+ email:
35
+ - dwilkie@gmail.com
23
36
  executables: []
24
37
 
25
38
  extensions: []
26
39
 
27
- extra_rdoc_files:
28
- - README.markdown
40
+ extra_rdoc_files: []
41
+
29
42
  files:
30
43
  - .gitignore
44
+ - Gemfile
31
45
  - MIT-LICENSE
32
46
  - README.markdown
33
47
  - Rakefile
34
- - VERSION
35
48
  - action_sms.gemspec
36
49
  - lib/action_sms.rb
37
50
  - lib/action_sms/base.rb
38
51
  - lib/action_sms/connection_adapters.rb
39
52
  - lib/action_sms/connection_adapters/abstract_adapter.rb
53
+ - lib/action_sms/connection_adapters/sms_global_adapter.rb
54
+ - lib/action_sms/connection_adapters/test_helpers/sms_global.rb
55
+ - lib/action_sms/connection_adapters/test_helpers/tropo.rb
56
+ - lib/action_sms/connection_adapters/tropo_adapter.rb
40
57
  - lib/action_sms/exceptions.rb
58
+ - lib/action_sms/version.rb
41
59
  - lib/generators/action_sms/initializer/USAGE
42
60
  - lib/generators/action_sms/initializer/initializer_generator.rb
43
61
  - lib/generators/action_sms/initializer/templates/action_sms.rb
62
+ - spec/base_spec.rb
63
+ - spec/connection_adapters/abstract_adapter_spec.rb
64
+ - spec/connection_adapters/sms_global_adapter_spec.rb
65
+ - spec/connection_adapters/test_helpers/sms_global_spec.rb
66
+ - spec/connection_adapters/test_helpers/tropo_spec.rb
67
+ - spec/connection_adapters/tropo_adapter_spec.rb
68
+ - spec/spec_helper.rb
44
69
  - todo
45
70
  has_rdoc: true
46
71
  homepage: http://github.com/dwilkie/action_sms
47
72
  licenses: []
48
73
 
49
74
  post_install_message:
50
- rdoc_options:
51
- - --charset=UTF-8
75
+ rdoc_options: []
76
+
52
77
  require_paths:
53
78
  - lib
54
79
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,10 +94,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
94
  version: "0"
70
95
  requirements: []
71
96
 
72
- rubyforge_project:
97
+ rubyforge_project: action_sms
73
98
  rubygems_version: 1.3.7
74
99
  signing_key:
75
100
  specification_version: 3
76
- summary: Lightweight SMS wrapper which can use any gateway
101
+ summary: Effortlessly switch between SMS Gateways
77
102
  test_files: []
78
103
 
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.3