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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWJiZmZlZWIxMDViNmIxNGE3MzE2NWYzYzZlY2M1MWIyNDg0MzkxNQ==
4
+ ZTcwM2ZhN2QyZDFjZjc3NDk5NDhmN2NkYTNiNGIyZDdlNzdkMjEwYQ==
5
5
  data.tar.gz: !binary |-
6
- ZDY0YmNkNzdjYmNhNDZkMDBhYjMxZTliNDdkYmNkZmVkMDhhMjk2MQ==
6
+ MDQ3Yzc3ZWRhNGM3YWJlNGE3N2JjZjY3NTcyNWQ0MDUxYTZhNzQ4NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjE3NDJkODAwNThiOTZhYTQ0Y2EwZmQ5YzYxYzU2ZTgwZTQwNWQwODQwYzM0
10
- ODcwZWU1NDIwODE3NmJiMDA0OWM2Y2VjZjg4OWI2NDUxMjNkYWY5ZDA5ZjE2
11
- M2VhY2U4NzlmNGRjYjMyYzQ0ZGZjZGFmY2IyZThmZjFjODEyOGM=
9
+ NWIyMWI2YzEwYWFiNjYyZWMzYmRiODViZmRjYzMzODlkZTUwNDVhOTA5YTFm
10
+ OWM3ZTk1OWYxMTE3NjEzZTkwZmNlMjQ0MzM0ZTg4NDFkYTQ3YWQwMTQ5MTE2
11
+ YjFhZmFmZDRlOTI5YjliYTg3MzY1YTNkMjI4NWE4YmIyZmI4MmM=
12
12
  data.tar.gz: !binary |-
13
- MzllZTE0OGZiZTg0ZTg0NTEyYWM5NjllYjMzZDMxMzY4ZmI2YzcwYWU5YTBl
14
- NTA0ZWIzYzEyYmFmYzhiZjFmOWY5NGFhODcyNTg1MGM1ODE3MTkxYTc4ZTNi
15
- M2VjNzA5NDk1YWY3NzU3NzkyMWRlMDk5ZmM1ODkwZGE5OWFmNjY=
13
+ MWZlOWM0ZjhjY2QzYzZiY2U3YTgwZjRmNTM4OTY1NzAzM2MwOGMzZDkxMzM2
14
+ Zjc4M2RkODY2M2MwYzU4OTJjMWVhYTk1Yzk2YzhjMGJhNzI2ODkxODY2MjU4
15
+ MTNjN2U5ZjEwMDQwZWM3OWE2Y2UzM2Q4ZGI4OTc5ODE2OTFhYzg=
@@ -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
- missing_fields = ATTRIBUTES.reject { |attr| __send__(attr) }
51
- if 1 == missing_fields.count
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
@@ -1,3 +1,3 @@
1
1
  module Mblox
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -1,26 +1,61 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Mblox::SmsResponse do
4
- let(:args) { { :request => Mblox::SmsResponse::Result.new(9, "SomeRequest"), :result => Mblox::SmsResponse::Result.new(10, "SomeResult") , :subscriber_result => Mblox::SmsResponse::Result.new(11, "SomeSubscriberResult") } }
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
- [:request, :result, :subscriber_result].each do |attr|
7
- describe attr do
8
- it "cannot be blank" do
9
- expect{described_class.new(args.merge(:"#{attr}" => nil))}.to raise_error(Mblox::ValidationError, "#{attr} cannot be blank")
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
- it "must be a Result" do
12
- expect{described_class.new(args.merge(:"#{attr}" => 123))}.to raise_error(Mblox::ValidationError, "#{attr} must be of type Mblox::SmsResponse::Result")
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
- it "should raise an error if request, result and subscriber_result are missing" do
18
- expect{described_class.new({})}.to raise_error(Mblox::ValidationError, "The following fields cannot be blank: request, result, subscriber_result")
19
- end
20
- it "should raise an error if request, result and subscriber_result are the wrong types" do
21
- 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")
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
- it "should raise an error if an unrecognized attribute is present" do
24
- expect{described_class.new(args.merge(:extra_attribute => 'ABC'))}.to raise_error(::ArgumentError, 'Unrecognized attributes: {:extra_attribute=>"ABC"}')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Betesh