govdelivery-tms 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/Gemfile +1 -1
  2. data/README.md +8 -8
  3. data/govdelivery-tms.gemspec +2 -2
  4. data/lib/{govdelivery-tms → govdelivery/tms}/base.rb +4 -4
  5. data/lib/{govdelivery-tms → govdelivery/tms}/client.rb +9 -9
  6. data/lib/{govdelivery-tms → govdelivery/tms}/collection_resource.rb +2 -2
  7. data/lib/{govdelivery-tms → govdelivery/tms}/connection.rb +4 -4
  8. data/lib/{govdelivery-tms → govdelivery/tms}/errors.rb +1 -1
  9. data/lib/govdelivery/tms/instance_resource.rb +219 -0
  10. data/lib/{govdelivery-tms → govdelivery/tms}/link_header.rb +0 -0
  11. data/lib/{govdelivery-tms → govdelivery/tms}/logger.rb +1 -1
  12. data/lib/{govdelivery-tms → govdelivery/tms}/mail/delivery_method.rb +11 -11
  13. data/lib/govdelivery/tms/resource/collections.rb +98 -0
  14. data/lib/{govdelivery-tms → govdelivery/tms}/resource/command.rb +7 -7
  15. data/lib/{govdelivery-tms → govdelivery/tms}/resource/command_action.rb +1 -1
  16. data/lib/{govdelivery-tms → govdelivery/tms}/resource/command_type.rb +1 -1
  17. data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_message.rb +1 -1
  18. data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_recipient.rb +1 -1
  19. data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_recipient_click.rb +1 -1
  20. data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_recipient_open.rb +1 -1
  21. data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_template.rb +1 -1
  22. data/lib/{govdelivery-tms → govdelivery/tms}/resource/from_address.rb +1 -1
  23. data/lib/{govdelivery-tms → govdelivery/tms}/resource/inbound_sms_message.rb +1 -1
  24. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_acknowledgement.rb +1 -1
  25. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_alert.rb +1 -1
  26. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_category.rb +1 -1
  27. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_cog_profile.rb +1 -1
  28. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_event_code.rb +1 -1
  29. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_nwem_area.rb +1 -1
  30. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_nwem_authorization.rb +1 -1
  31. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_nwem_auxilary_data.rb +1 -1
  32. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_response_type.rb +1 -1
  33. data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_static_resource.rb +2 -2
  34. data/lib/{govdelivery-tms → govdelivery/tms}/resource/keyword.rb +1 -1
  35. data/lib/{govdelivery-tms → govdelivery/tms}/resource/recipient.rb +1 -1
  36. data/lib/{govdelivery-tms → govdelivery/tms}/resource/sms_message.rb +1 -1
  37. data/lib/{govdelivery-tms → govdelivery/tms}/resource/webhook.rb +1 -1
  38. data/lib/{govdelivery-tms → govdelivery/tms}/util/core_ext.rb +1 -1
  39. data/lib/{govdelivery-tms → govdelivery/tms}/util/hal_link_parser.rb +2 -2
  40. data/lib/govdelivery/tms/version.rb +5 -0
  41. data/lib/govdelivery-tms/instance_resource.rb +7 -7
  42. data/lib/govdelivery-tms.rb +38 -36
  43. data/spec/client_spec.rb +18 -18
  44. data/spec/command_types_spec.rb +6 -6
  45. data/spec/email_message_spec.rb +58 -58
  46. data/spec/email_template_spec.rb +39 -39
  47. data/spec/errors_spec.rb +3 -3
  48. data/spec/from_address_spec.rb +22 -22
  49. data/spec/inbound_sms_messages_spec.rb +5 -5
  50. data/spec/instance_resource_spec.rb +14 -14
  51. data/spec/ipaws_acknowledgement_spec.rb +6 -6
  52. data/spec/ipaws_alerts_spec.rb +31 -31
  53. data/spec/ipaws_cog_profile_spec.rb +26 -26
  54. data/spec/ipaws_event_codes_spec.rb +5 -5
  55. data/spec/ipaws_nwem_areas_spec.rb +22 -22
  56. data/spec/ipaws_nwem_authorization_spec.rb +6 -6
  57. data/spec/keyword_spec.rb +23 -23
  58. data/spec/keywords_spec.rb +5 -5
  59. data/spec/mail/delivery_method_spec.rb +19 -19
  60. data/spec/sms_message_spec.rb +29 -29
  61. data/spec/sms_messages_spec.rb +7 -7
  62. data/spec/spec_helper.rb +2 -3
  63. data/spec/tms_spec.rb +2 -2
  64. metadata +50 -41
  65. checksums.yaml +0 -15
  66. data/lib/govdelivery-tms/resource/collections.rb +0 -98
  67. data/lib/govdelivery-tms/version.rb +0 -3
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsCategory
3
3
 
4
4
  include IpawsStaticResource
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsCogProfile
3
3
 
4
4
  include InstanceResource
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsEventCode
3
3
 
4
4
  include IpawsStaticResource
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsNwemArea
3
3
 
4
4
  include InstanceResource
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsNwemAuthorization
3
3
 
4
4
  include InstanceResource
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsNwemAuxilaryData
3
3
 
4
4
  include InstanceResource
@@ -1,4 +1,4 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  class IpawsResponseType
3
3
 
4
4
  include IpawsStaticResource
@@ -1,7 +1,7 @@
1
- module TMS
1
+ module GovDelivery::TMS
2
2
  module IpawsStaticResource
3
3
  def self.included(base)
4
- base.send(:include, TMS::InstanceResource)
4
+ base.send(:include, GovDelivery::TMS::InstanceResource)
5
5
  base.readonly_attributes :value, :description, :cap_exchange, :core_ipaws_profile, :nwem, :eas_and_public, :cmas
6
6
  end
7
7
  end
@@ -1,4 +1,4 @@
1
- module TMS #:nodoc:
1
+ module GovDelivery::TMS #:nodoc:
2
2
  # A Keyword is a word that TMS will detect in an incoming SMS message. Keywords can have Commands, and
3
3
  # when an incoming text message has a keyword, TMS will execute the keyword's Commands. Keywords may
4
4
  # also have a response text field. If the response text is not blank, the system will send an SMS reply to the user
@@ -1,4 +1,4 @@
1
- module TMS #:nodoc:
1
+ module GovDelivery::TMS #:nodoc:
2
2
  class Recipient
3
3
  include InstanceResource
4
4
  # @!parse attr_accessor :phone
@@ -1,4 +1,4 @@
1
- module TMS #:nodoc:
1
+ module GovDelivery::TMS #:nodoc:
2
2
  # An SMSMessage is used to create and send a text message to a collection of Recipient
3
3
  # objects.
4
4
  #
@@ -1,4 +1,4 @@
1
- module TMS #:nodoc:
1
+ module GovDelivery::TMS #:nodoc:
2
2
  # A Webhook gets invoked when a recipient enters a queued or final state
3
3
  #
4
4
  # @attr url [String] The URL to POST webhooks to
@@ -1,6 +1,6 @@
1
1
  require 'active_support/inflector'
2
2
 
3
- module TMS::CoreExt
3
+ module GovDelivery::TMS::CoreExt
4
4
  def demodulize(path)
5
5
  ActiveSupport::Inflector.demodulize(path)
6
6
  end
@@ -1,4 +1,4 @@
1
- module TMS::Util
1
+ module GovDelivery::TMS::Util
2
2
  module HalLinkParser
3
3
 
4
4
  def parse_links(_links)
@@ -39,7 +39,7 @@ module TMS::Util
39
39
  end
40
40
 
41
41
  def relation_class(rel)
42
- ::TMS.const_get(classify(rel)) rescue nil
42
+ ::GovDelivery::TMS.const_get(classify(rel)) rescue nil
43
43
  end
44
44
 
45
45
  def setup_subresource(link)
@@ -0,0 +1,5 @@
1
+ module GovDelivery
2
+ module TMS #:nodoc:
3
+ VERSION = "0.8.1"
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- module TMS::InstanceResource
1
+ module GovDelivery::TMS::InstanceResource
2
2
  def self.included(base)
3
3
  base.send(:include, TMS::Base)
4
4
  base.extend(ClassMethods)
@@ -73,12 +73,12 @@ module TMS::InstanceResource
73
73
  def collection_attribute(attr, tms_class)
74
74
  @collection_attributes ||= []
75
75
  @collection_attributes.push(attr).uniq!
76
- setup_collection(attr, TMS.const_get(tms_class))
76
+ setup_collection(attr, GovDelivery::TMS.const_get(tms_class))
77
77
  end
78
78
 
79
79
  ##
80
- # Read-only collection attributes don't get POSTed.
81
- # Use this for collections that are represented as attributes, but cannot be modified.
80
+ # Read-only collection attributes don't get POSTed.
81
+ # Use this for collections that are represented as attributes, but cannot be modified.
82
82
  #
83
83
  # @example
84
84
  # readonly_collection_attribute :opens
@@ -86,7 +86,7 @@ module TMS::InstanceResource
86
86
  def readonly_collection_attribute(attr, tms_class)
87
87
  @readonly_collection_attributes ||= []
88
88
  @readonly_collection_attributes.push(attr).uniq!
89
- setup_collection(attr, TMS.const_get(tms_class))
89
+ setup_collection(attr, GovDelivery::TMS.const_get(tms_class))
90
90
  end
91
91
 
92
92
  def setup_attributes(attrs, readonly=false)
@@ -100,7 +100,7 @@ module TMS::InstanceResource
100
100
  if klass
101
101
  custom_class_names[property] = klass
102
102
  else
103
- klass ||= TMS.const_get(property.to_s.capitalize)
103
+ klass ||= GovDelivery::TMS.const_get(property.to_s.capitalize)
104
104
  end
105
105
 
106
106
  self.send :define_method, property.to_sym, &lambda { @attributes[property] ||= klass.new(self.client, nil, nil) }
@@ -205,7 +205,7 @@ module TMS::InstanceResource
205
205
  def set_attributes_from_hash(hash)
206
206
  hash.reject { |k, _| k=~/^_/ }.each do |property, value|
207
207
  if self.class.collection_attributes.include?(property.to_sym)
208
- klass = self.class.custom_class_names[property] || TMS.const_get(property.to_s.capitalize)
208
+ klass = self.class.custom_class_names[property] || GovDelivery::TMS.const_get(property.to_s.capitalize)
209
209
  @attributes[property.to_sym] = klass.new(client, nil, value)
210
210
  else
211
211
  @attributes[property.to_sym] = value
@@ -1,43 +1,45 @@
1
- module TMS #:nodoc:
1
+ module GovDelivery
2
+ module TMS #:nodoc:
3
+ end
2
4
  end
3
5
 
4
6
  require 'active_support/core_ext/hash'
5
- require 'govdelivery-tms/version'
7
+ require 'govdelivery/tms/version'
6
8
  require 'faraday'
7
9
  require 'faraday_middleware'
8
10
 
9
- require 'govdelivery-tms/link_header'
10
- require 'govdelivery-tms/util/hal_link_parser'
11
- require 'govdelivery-tms/util/core_ext'
12
- require 'govdelivery-tms/connection'
13
- require 'govdelivery-tms/client'
14
- require 'govdelivery-tms/logger'
15
- require 'govdelivery-tms/base'
16
- require 'govdelivery-tms/instance_resource'
17
- require 'govdelivery-tms/collection_resource'
18
- require 'govdelivery-tms/errors'
11
+ require 'govdelivery/tms/link_header'
12
+ require 'govdelivery/tms/util/hal_link_parser'
13
+ require 'govdelivery/tms/util/core_ext'
14
+ require 'govdelivery/tms/connection'
15
+ require 'govdelivery/tms/client'
16
+ require 'govdelivery/tms/logger'
17
+ require 'govdelivery/tms/base'
18
+ require 'govdelivery/tms/instance_resource'
19
+ require 'govdelivery/tms/collection_resource'
20
+ require 'govdelivery/tms/errors'
19
21
 
20
- require 'govdelivery-tms/resource/collections'
21
- require 'govdelivery-tms/resource/recipient'
22
- require 'govdelivery-tms/resource/email_recipient'
23
- require 'govdelivery-tms/resource/email_recipient_open'
24
- require 'govdelivery-tms/resource/email_recipient_click'
25
- require 'govdelivery-tms/resource/from_address'
26
- require 'govdelivery-tms/resource/email_template'
27
- require 'govdelivery-tms/resource/sms_message'
28
- require 'govdelivery-tms/resource/email_message'
29
- require 'govdelivery-tms/resource/inbound_sms_message'
30
- require 'govdelivery-tms/resource/command_type'
31
- require 'govdelivery-tms/resource/command_action'
32
- require 'govdelivery-tms/resource/command'
33
- require 'govdelivery-tms/resource/keyword'
34
- require 'govdelivery-tms/resource/ipaws_static_resource'
35
- require 'govdelivery-tms/resource/ipaws_category'
36
- require 'govdelivery-tms/resource/ipaws_event_code'
37
- require 'govdelivery-tms/resource/ipaws_response_type'
38
- require 'govdelivery-tms/resource/ipaws_acknowledgement'
39
- require 'govdelivery-tms/resource/ipaws_cog_profile'
40
- require 'govdelivery-tms/resource/ipaws_nwem_authorization'
41
- require 'govdelivery-tms/resource/ipaws_nwem_area'
42
- require 'govdelivery-tms/resource/ipaws_alert'
43
- require 'govdelivery-tms/resource/webhook'
22
+ require 'govdelivery/tms/resource/collections'
23
+ require 'govdelivery/tms/resource/recipient'
24
+ require 'govdelivery/tms/resource/email_recipient'
25
+ require 'govdelivery/tms/resource/email_recipient_open'
26
+ require 'govdelivery/tms/resource/email_recipient_click'
27
+ require 'govdelivery/tms/resource/from_address'
28
+ require 'govdelivery/tms/resource/email_template'
29
+ require 'govdelivery/tms/resource/sms_message'
30
+ require 'govdelivery/tms/resource/email_message'
31
+ require 'govdelivery/tms/resource/inbound_sms_message'
32
+ require 'govdelivery/tms/resource/command_type'
33
+ require 'govdelivery/tms/resource/command_action'
34
+ require 'govdelivery/tms/resource/command'
35
+ require 'govdelivery/tms/resource/keyword'
36
+ require 'govdelivery/tms/resource/ipaws_static_resource'
37
+ require 'govdelivery/tms/resource/ipaws_category'
38
+ require 'govdelivery/tms/resource/ipaws_event_code'
39
+ require 'govdelivery/tms/resource/ipaws_response_type'
40
+ require 'govdelivery/tms/resource/ipaws_acknowledgement'
41
+ require 'govdelivery/tms/resource/ipaws_cog_profile'
42
+ require 'govdelivery/tms/resource/ipaws_nwem_authorization'
43
+ require 'govdelivery/tms/resource/ipaws_nwem_area'
44
+ require 'govdelivery/tms/resource/ipaws_alert'
45
+ require 'govdelivery/tms/resource/webhook'
data/spec/client_spec.rb CHANGED
@@ -1,41 +1,41 @@
1
1
  require 'spec_helper'
2
- describe TMS::Client do
2
+ describe GovDelivery::TMS::Client do
3
3
  context "creating a new client" do
4
4
  before do
5
- response = double('response', :status => 200, :body => {"_links" => [{"self" => "/"}, {"horse" => "/horses/new"}, {"rabbits" => "/rabbits"}]})
6
- @raw_connection = double('raw_connection', :get => response)
7
- @connection = TMS::Connection.stub(:new).and_return(double('connection', :connection => @raw_connection))
8
- @client = TMS::Client.new('auth_token', :api_root => 'null_url')
5
+ response = double('response', status: 200, body: {"_links" => [{"self" => "/"}, {"horse" => "/horses/new"}, {"rabbits" => "/rabbits"}]})
6
+ @raw_connection = double('raw_connection', get: response)
7
+ @connection = allow(GovDelivery::TMS::Connection).to receive(:new).and_return(double('connection', connection: @raw_connection))
8
+ @client = GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url')
9
9
  end
10
10
  it 'should set up logging' do
11
- @client.logger.should_not be_nil
12
- @client.logger.level.should eq(Logger::INFO)
11
+ expect(@client.logger).not_to be_nil
12
+ expect(@client.logger.level).to eq(Logger::INFO)
13
13
  end
14
14
  it 'should discover endpoints for known services' do
15
- @client.horse.should be_kind_of(TMS::Horse)
16
- @client.rabbits.should be_kind_of(TMS::Rabbits)
15
+ expect(@client.horse).to be_kind_of(GovDelivery::TMS::Horse)
16
+ expect(@client.rabbits).to be_kind_of(GovDelivery::TMS::Rabbits)
17
17
  end
18
18
  it 'should handle 4xx responses' do
19
- @raw_connection.stub(:get).and_return(double('response', :status => 404, :body => {'message' => 'hi'}))
20
- expect { @client.get('/blargh') }.to raise_error(TMS::Request::Error)
19
+ allow(@raw_connection).to receive(:get).and_return(double('response', status: 404, body: {'message' => 'hi'}))
20
+ expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::Error)
21
21
  end
22
22
  it 'should handle 5xx responses' do
23
- @raw_connection.stub(:get).and_return(double('response', :status => 503, :body => {'message' => 'oops'}))
24
- expect { @client.get('/blargh') }.to raise_error(TMS::Request::Error)
23
+ allow(@raw_connection).to receive(:get).and_return(double('response', status: 503, body: {'message' => 'oops'}))
24
+ expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::Error)
25
25
  end
26
26
  it 'should handle 202 responses' do
27
- @raw_connection.stub(:get).and_return(double('response', :status => 202, :body => {'message' => 'hi'}))
28
- expect { @client.get('/blargh') }.to raise_error(TMS::Request::InProgress)
27
+ allow(@raw_connection).to receive(:get).and_return(double('response', status: 202, body: {'message' => 'hi'}))
28
+ expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::InProgress)
29
29
  end
30
30
 
31
31
  context 'creating a new client without output' do
32
- subject { TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
32
+ subject { GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
33
33
  its(:logger){ should be_falsey }
34
- its(:horse) { should be_kind_of(TMS::Horse) }
34
+ its(:horse) { should be_kind_of(GovDelivery::TMS::Horse) }
35
35
  end
36
36
 
37
37
  it 'defaults to the public API URL' do
38
- expect(TMS::Client.new('auth_token').api_root).to eq('https://tms.govdelivery.com')
38
+ expect(GovDelivery::TMS::Client.new('auth_token').api_root).to eq('https://tms.govdelivery.com')
39
39
  end
40
40
  end
41
41
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe TMS::CommandTypes do
3
+ describe GovDelivery::TMS::CommandTypes do
4
4
  context "loading command types" do
5
5
  let(:client) do
6
6
  double('client')
7
7
  end
8
8
  before do
9
- @command_types = TMS::CommandTypes.new(client, '/command_types')
9
+ @command_types = GovDelivery::TMS::CommandTypes.new(client, '/command_types')
10
10
  end
11
11
  it 'should GET ok' do
12
12
  body = [{"name"=>"dcm_unsubscribe",
@@ -18,12 +18,12 @@ describe TMS::CommandTypes do
18
18
  {"name"=>"forward",
19
19
  "string_fields"=>["http_method", "username", "password", "url"],
20
20
  "array_fields"=>[]}]
21
- @command_types.client.should_receive(:get).and_return(double('response', :body => body, :status => 200, :headers => {}))
21
+ expect(@command_types.client).to receive(:get).and_return(double('response', body: body, status: 200, headers: {}))
22
22
  @command_types.get
23
- @command_types.collection.length.should == 3
23
+ expect(@command_types.collection.length).to eq(3)
24
24
  ct = @command_types.collection.find{|c| c.name == "dcm_subscribe"}
25
- ct.array_fields.should eq(["dcm_topic_codes"])
26
- ct.string_fields.should eq(["dcm_account_code"])
25
+ expect(ct.array_fields).to eq(["dcm_topic_codes"])
26
+ expect(ct.string_fields).to eq(["dcm_account_code"])
27
27
  end
28
28
  end
29
29
  end
@@ -1,72 +1,72 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe TMS::EmailMessage do
3
+ describe GovDelivery::TMS::EmailMessage do
4
4
  context "creating a new message" do
5
5
  let(:client) do
6
6
  double('client')
7
7
  end
8
8
  before do
9
- @message = TMS::EmailMessage.new(client, '/messages/email', {
10
- :body => '12345678',
11
- :subject => 'blah',
12
- :created_at => 'BAAAAAD',
13
- :from_email => 'eric@evotest.govdelivery.com',
14
- :errors_to => 'errors@evotest.govdelivery.com',
15
- :reply_to => 'replyto@evotest.govdelivery.com'})
9
+ @message = GovDelivery::TMS::EmailMessage.new(client, '/messages/email', {
10
+ body: '12345678',
11
+ subject: 'blah',
12
+ created_at: 'BAAAAAD',
13
+ from_email: 'eric@evotest.govdelivery.com',
14
+ errors_to: 'errors@evotest.govdelivery.com',
15
+ reply_to: 'replyto@evotest.govdelivery.com'})
16
16
  end
17
17
  it 'should not render readonly attrs in json hash' do
18
- @message.to_json[:body].should == '12345678'
19
- @message.to_json[:created_at].should == nil
18
+ expect(@message.to_json[:body]).to eq('12345678')
19
+ expect(@message.to_json[:created_at]).to eq(nil)
20
20
  end
21
21
  it 'should initialize with attrs and collections' do
22
- @message.body.should == '12345678'
23
- @message.subject.should == 'blah'
24
- @message.from_email.should == 'eric@evotest.govdelivery.com'
25
- @message.reply_to.should == 'replyto@evotest.govdelivery.com'
26
- @message.errors_to.should == 'errors@evotest.govdelivery.com'
27
- @message.recipients.class.should == TMS::EmailRecipients
22
+ expect(@message.body).to eq('12345678')
23
+ expect(@message.subject).to eq('blah')
24
+ expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
25
+ expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
26
+ expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
27
+ expect(@message.recipients.class).to eq(GovDelivery::TMS::EmailRecipients)
28
28
  end
29
29
  it 'should post successfully' do
30
30
  response = {
31
- :body => 'processed',
32
- :subject => 'blah',
33
- :from_email => 'eric@evotest.govdelivery.com',
34
- :errors_to => 'errors@evotest.govdelivery.com',
35
- :reply_to => 'replyto@evotest.govdelivery.com',
36
- :recipients => [{:email => 'billy@evotest.govdelivery.com'}],
37
- :failed => [{:email => 'billy@evotest.govdelivery.com'}],
38
- :sent => [{:email => 'billy@evotest.govdelivery.com'}],
39
- :created_at => 'time'
31
+ body: 'processed',
32
+ subject: 'blah',
33
+ from_email: 'eric@evotest.govdelivery.com',
34
+ errors_to: 'errors@evotest.govdelivery.com',
35
+ reply_to: 'replyto@evotest.govdelivery.com',
36
+ recipients: [{email: 'billy@evotest.govdelivery.com'}],
37
+ failed: [{email: 'billy@evotest.govdelivery.com'}],
38
+ sent: [{email: 'billy@evotest.govdelivery.com'}],
39
+ created_at: 'time'
40
40
  }
41
- @message.client.should_receive('post').with(@message).and_return(double('response', :status => 201, :body => response))
41
+ expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 201, body: response))
42
42
  @message.post
43
- @message.body.should == 'processed'
44
- @message.created_at.should == 'time'
45
- @message.from_email.should == 'eric@evotest.govdelivery.com'
46
- @message.reply_to.should == 'replyto@evotest.govdelivery.com'
47
- @message.errors_to.should == 'errors@evotest.govdelivery.com'
48
- @message.recipients.class.should == TMS::EmailRecipients
49
- @message.recipients.collection.first.class.should == TMS::EmailRecipient
50
- @message.sent.class.should == TMS::EmailRecipients
51
- @message.sent.collection.first.class.should == TMS::EmailRecipient
52
- @message.failed.class.should == TMS::EmailRecipients
53
- @message.failed.collection.first.class.should == TMS::EmailRecipient
43
+ expect(@message.body).to eq('processed')
44
+ expect(@message.created_at).to eq('time')
45
+ expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
46
+ expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
47
+ expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
48
+ expect(@message.recipients.class).to eq(GovDelivery::TMS::EmailRecipients)
49
+ expect(@message.recipients.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
50
+ expect(@message.sent.class).to eq(GovDelivery::TMS::EmailRecipients)
51
+ expect(@message.sent.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
52
+ expect(@message.failed.class).to eq(GovDelivery::TMS::EmailRecipients)
53
+ expect(@message.failed.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
54
54
  end
55
55
  it 'should handle errors' do
56
- response = {'errors' => {:body => "can't be nil"}}
57
- @message.client.should_receive('post').with(@message).and_return(double('response', :status => 422, :body => response))
56
+ response = {'errors' => {body: "can't be nil"}}
57
+ expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 422, body: response))
58
58
  @message.post
59
- @message.body.should == '12345678'
60
- @message.errors.should == {:body => "can't be nil"}
59
+ expect(@message.body).to eq('12345678')
60
+ expect(@message.errors).to eq({body: "can't be nil"})
61
61
  end
62
62
 
63
63
  it 'should handle 401 errors' do
64
- @message.client.should_receive('post').with(@message).and_return(double('response', :status => 401))
64
+ expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 401))
65
65
  expect {@message.post}.to raise_error(StandardError, "401 Not Authorized")
66
66
  end
67
67
 
68
68
  it 'should handle 404 errors' do
69
- @message.client.should_receive('post').with(@message).and_return(double('response', :status => 404))
69
+ expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 404))
70
70
  expect {@message.post}.to raise_error(StandardError, "Can't POST to /messages/email")
71
71
  end
72
72
  end
@@ -77,24 +77,24 @@ describe TMS::EmailMessage do
77
77
  end
78
78
  before do
79
79
  # blank hash prevents the client from doing a GET in the initialize method
80
- @message = TMS::EmailMessage.new(client, '/messages/99', {})
80
+ @message = GovDelivery::TMS::EmailMessage.new(client, '/messages/99', {})
81
81
  end
82
82
  it 'should GET cleanly' do
83
- response = {:body => 'processed',
84
- :subject => 'hey',
85
- :from_email => 'eric@evotest.govdelivery.com',
86
- :errors_to => 'errors@evotest.govdelivery.com',
87
- :reply_to => 'replyto@evotest.govdelivery.com',
88
- :recipients => [{:email => 'billy@evotest.govdelivery.com'}],
89
- :created_at => 'time'}
90
- @message.client.should_receive('get').with(@message.href).and_return(double('response', :status => 200, :body => response))
83
+ response = {body: 'processed',
84
+ subject: 'hey',
85
+ from_email: 'eric@evotest.govdelivery.com',
86
+ errors_to: 'errors@evotest.govdelivery.com',
87
+ reply_to: 'replyto@evotest.govdelivery.com',
88
+ recipients: [{email: 'billy@evotest.govdelivery.com'}],
89
+ created_at: 'time'}
90
+ expect(@message.client).to receive('get').with(@message.href).and_return(double('response', status: 200, body: response))
91
91
  @message.get
92
- @message.body.should == 'processed'
93
- @message.subject.should == 'hey'
94
- @message.from_email.should == 'eric@evotest.govdelivery.com'
95
- @message.reply_to.should == 'replyto@evotest.govdelivery.com'
96
- @message.errors_to.should == 'errors@evotest.govdelivery.com'
97
- @message.created_at.should == 'time'
92
+ expect(@message.body).to eq('processed')
93
+ expect(@message.subject).to eq('hey')
94
+ expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
95
+ expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
96
+ expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
97
+ expect(@message.created_at).to eq('time')
98
98
  end
99
99
  end
100
100