mblox 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/mblox/sms_response.rb +10 -7
- data/lib/mblox/version.rb +1 -1
- data/spec/sms_response_spec.rb +50 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTcwM2ZhN2QyZDFjZjc3NDk5NDhmN2NkYTNiNGIyZDdlNzdkMjEwYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDQ3Yzc3ZWRhNGM3YWJlNGE3N2JjZjY3NTcyNWQ0MDUxYTZhNzQ4NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWIyMWI2YzEwYWFiNjYyZWMzYmRiODViZmRjYzMzODlkZTUwNDVhOTA5YTFm
|
10
|
+
OWM3ZTk1OWYxMTE3NjEzZTkwZmNlMjQ0MzM0ZTg4NDFkYTQ3YWQwMTQ5MTE2
|
11
|
+
YjFhZmFmZDRlOTI5YjliYTg3MzY1YTNkMjI4NWE4YmIyZmI4MmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWZlOWM0ZjhjY2QzYzZiY2U3YTgwZjRmNTM4OTY1NzAzM2MwOGMzZDkxMzM2
|
14
|
+
Zjc4M2RkODY2M2MwYzU4OTJjMWVhYTk1Yzk2YzhjMGJhNzI2ODkxODY2MjU4
|
15
|
+
MTNjN2U5ZjEwMDQwZWM3OWE2Y2UzM2Q4ZGI4OTc5ODE2OTFhYzg=
|
data/lib/mblox/sms_response.rb
CHANGED
@@ -47,18 +47,21 @@ module Mblox
|
|
47
47
|
args.delete(attr)
|
48
48
|
end
|
49
49
|
raise ::ArgumentError, "Unrecognized attributes: #{args.inspect}" unless args.empty?
|
50
|
-
|
51
|
-
|
52
|
-
raise ValidationError, "#{missing_fields.first} cannot be blank"
|
53
|
-
elsif missing_fields.count > 1
|
54
|
-
raise ValidationError, "The following fields cannot be blank: #{missing_fields.join(', ')}"
|
55
|
-
end
|
56
|
-
wrong_type_fields = ATTRIBUTES.reject { |attr| __send__(attr).is_a?(self.class::Result) }
|
50
|
+
|
51
|
+
wrong_type_fields = ATTRIBUTES.reject { |attr| __send__(attr).nil? || __send__(attr).is_a?(self.class::Result) }
|
57
52
|
if 1 == wrong_type_fields.count
|
58
53
|
raise ValidationError, "#{wrong_type_fields.first} must be of type Mblox::SmsResponse::Result"
|
59
54
|
elsif wrong_type_fields.count > 1
|
60
55
|
raise ValidationError, "The following fields must be of type Mblox::SmsResponse::Result: #{wrong_type_fields.join(', ')}"
|
61
56
|
end
|
57
|
+
|
58
|
+
missing_fields = [:request, :result].reject { |attr| __send__(attr) }
|
59
|
+
missing_fields << :subscriber_result if result && result.ok? && subscriber_result.nil?
|
60
|
+
if 1 == missing_fields.count
|
61
|
+
raise ValidationError, "#{missing_fields.first} cannot be blank"
|
62
|
+
elsif missing_fields.count > 1
|
63
|
+
raise ValidationError, "The following fields cannot be blank: #{missing_fields.join(', ')}"
|
64
|
+
end
|
62
65
|
end
|
63
66
|
|
64
67
|
def ok?
|
data/lib/mblox/version.rb
CHANGED
data/spec/sms_response_spec.rb
CHANGED
@@ -1,26 +1,61 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Mblox::SmsResponse do
|
4
|
-
|
4
|
+
describe "validation" do
|
5
|
+
let(:args) { { :request => Mblox::SmsResponse::Result.new(9, "SomeRequest"), :result => Mblox::SmsResponse::Result.new(10, "SomeResult") , :subscriber_result => Mblox::SmsResponse::Result.new(11, "SomeSubscriberResult") } }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
[:request, :result, :subscriber_result].each do |attr|
|
8
|
+
describe attr do
|
9
|
+
it "must be a Result" do
|
10
|
+
expect{described_class.new(args.merge(:"#{attr}" => 123))}.to raise_error(Mblox::ValidationError, "#{attr} must be of type Mblox::SmsResponse::Result")
|
11
|
+
end
|
10
12
|
end
|
11
|
-
|
12
|
-
|
13
|
+
end
|
14
|
+
[:request, :result].each do |attr|
|
15
|
+
describe attr do
|
16
|
+
it "cannot be blank" do
|
17
|
+
expect{described_class.new(args.merge(:"#{attr}" => nil))}.to raise_error(Mblox::ValidationError, "#{attr} cannot be blank")
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
|
-
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
describe :subscriber_result do
|
23
|
+
it "cannot be blank if result is ok" do
|
24
|
+
expect{described_class.new(args.merge(:subscriber_result => nil))}.to_not raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can be blank if result is not ok" do
|
28
|
+
expect{described_class.new(args.merge(:subscriber_result => nil, :result => Mblox::SmsResponse::Result.new(0,'Thumbs Up!')))}.to raise_error(Mblox::ValidationError, "subscriber_result cannot be blank")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "should raise an error if request, result and subscriber_result are missing" do
|
34
|
+
expect{described_class.new({})}.to raise_error(Mblox::ValidationError, "The following fields cannot be blank: request, result")
|
35
|
+
end
|
36
|
+
it "should raise an error if request, result and subscriber_result are the wrong types" do
|
37
|
+
expect{described_class.new(:request => 'A', :result => Time.now, :subscriber_result => 32)}.to raise_error(Mblox::ValidationError, "The following fields must be of type Mblox::SmsResponse::Result: request, result, subscriber_result")
|
38
|
+
end
|
39
|
+
it "should raise an error if an unrecognized attribute is present" do
|
40
|
+
expect{described_class.new(args.merge(:extra_attribute => 'ABC'))}.to raise_error(::ArgumentError, 'Unrecognized attributes: {:extra_attribute=>"ABC"}')
|
41
|
+
end
|
22
42
|
end
|
23
|
-
|
24
|
-
|
43
|
+
|
44
|
+
describe "ok/unroutable" do
|
45
|
+
let(:args) { { :request => Mblox::SmsResponse::Result.new(0, "OKRequest"), :result => Mblox::SmsResponse::Result.new(0, "OKResult") , :subscriber_result => Mblox::SmsResponse::Result.new(0, "OKSubscriberResult") } }
|
46
|
+
|
47
|
+
it "should be ok if all attributes are ok" do
|
48
|
+
described_class.new(args).should be_ok
|
49
|
+
end
|
50
|
+
|
51
|
+
[:request, :result, :subscriber_result].each do |attr|
|
52
|
+
it "should not be ok if #{attr} is not ok" do
|
53
|
+
described_class.new(args.merge(:"#{attr}" => Mblox::SmsResponse::Result.new(1,"NotOK"))).should_not be_ok
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be unroutable if subscriber_result is unroutable and other attirbutes are ok" do
|
58
|
+
described_class.new(args.merge(:subscriber_result => Mblox::SmsResponse::Result::UNROUTABLE)).should be_unroutable
|
59
|
+
end
|
25
60
|
end
|
26
61
|
end
|