action_kit_rest 0.4.3 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +24 -0
  3. data/.rubocop.yml +26 -0
  4. data/.ruby-version +1 -1
  5. data/Gemfile +11 -9
  6. data/README.md +2 -2
  7. data/Rakefile +15 -18
  8. data/action_kit_rest.gemspec +28 -34
  9. data/lib/action_kit_rest/action.rb +3 -1
  10. data/lib/action_kit_rest/actions/event_create_action.rb +5 -3
  11. data/lib/action_kit_rest/actions/event_signup_action.rb +6 -3
  12. data/lib/action_kit_rest/actions/unsubscribe_action.rb +3 -1
  13. data/lib/action_kit_rest/allowed_user_field.rb +3 -1
  14. data/lib/action_kit_rest/api.rb +9 -7
  15. data/lib/action_kit_rest/base.rb +5 -4
  16. data/lib/action_kit_rest/client.rb +5 -3
  17. data/lib/action_kit_rest/event.rb +3 -1
  18. data/lib/action_kit_rest/event_signup.rb +3 -1
  19. data/lib/action_kit_rest/language.rb +3 -1
  20. data/lib/action_kit_rest/list.rb +3 -1
  21. data/lib/action_kit_rest/page.rb +4 -2
  22. data/lib/action_kit_rest/pages/base.rb +4 -5
  23. data/lib/action_kit_rest/pages/donation_page.rb +3 -1
  24. data/lib/action_kit_rest/pages/event_campaign_page.rb +4 -2
  25. data/lib/action_kit_rest/pages/import_page.rb +3 -1
  26. data/lib/action_kit_rest/pages/signup_page.rb +3 -1
  27. data/lib/action_kit_rest/pages/unsubscribe_page.rb +3 -1
  28. data/lib/action_kit_rest/phone.rb +2 -0
  29. data/lib/action_kit_rest/railties.rb +3 -1
  30. data/lib/action_kit_rest/response/collection.rb +4 -4
  31. data/lib/action_kit_rest/response/raise_error.rb +15 -12
  32. data/lib/action_kit_rest/response/validation_error.rb +20 -9
  33. data/lib/action_kit_rest/response/wrapper.rb +10 -10
  34. data/lib/action_kit_rest/tag.rb +6 -6
  35. data/lib/action_kit_rest/user.rb +3 -1
  36. data/lib/action_kit_rest/version.rb +3 -1
  37. data/lib/action_kit_rest.rb +2 -0
  38. data/spec/lib/action_kit_rest/actions/event_create_action_spec.rb +6 -4
  39. data/spec/lib/action_kit_rest/actions/event_signup_action_spec.rb +6 -4
  40. data/spec/lib/action_kit_rest/allowed_user_field_spec.rb +9 -7
  41. data/spec/lib/action_kit_rest/api_spec.rb +95 -0
  42. data/spec/lib/action_kit_rest/logger_spec.rb +7 -5
  43. data/spec/lib/action_kit_rest/page_spec.rb +28 -28
  44. data/spec/lib/action_kit_rest/pages/event_campaign_page_spec.rb +25 -20
  45. data/spec/lib/action_kit_rest/pages/import_page_spec.rb +21 -17
  46. data/spec/lib/action_kit_rest/response/collection_spec.rb +13 -11
  47. data/spec/lib/action_kit_rest/response/validation_error_spec.rb +16 -4
  48. data/spec/lib/action_kit_rest/response/wrapper_spec.rb +6 -4
  49. data/spec/lib/action_kit_rest/user_spec.rb +11 -9
  50. data/spec/spec_helper.rb +6 -4
  51. data/spec/support/shared_contexts/stub_logger.rb +4 -2
  52. metadata +61 -57
  53. data/.travis.yml +0 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A class responsible for proxing to faraday response &
2
4
  # or a pagination collection.
3
5
  module ActionKitRest
@@ -5,9 +7,7 @@ module ActionKitRest
5
7
  class Collection
6
8
  include Enumerable
7
9
 
8
- attr_reader :meta
9
- attr_reader :objects
10
-
10
+ attr_reader :meta, :objects
11
11
 
12
12
  def initialize(meta, objects)
13
13
  @meta = meta
@@ -15,7 +15,7 @@ module ActionKitRest
15
15
  end
16
16
 
17
17
  def each(&block)
18
- # todo handle pagination somehow!
18
+ # TODO: handle pagination somehow!
19
19
  objects.each do |o|
20
20
  block.call(o)
21
21
  end
@@ -1,43 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionKitRest
2
4
  module Response
3
5
  class RaiseError < Faraday::Response::Middleware
4
-
5
6
  def on_complete(response)
6
7
  status_code = response[:status].to_i
7
8
  if (400...600).include? status_code
8
9
  if status_code == 400
9
10
  response_body = response[:body]
10
- if JSON.parse(response_body)['errors'] == {'mailing_id' => ['Unable to associate this mailing ID with account.']}
11
+ if ActionKitRest::Response::InvalidAkidError.matches?(JSON.parse(response_body)['errors'])
11
12
  raise ActionKitRest::Response::InvalidAkidError.new(url: response[:url].to_s, body: response_body)
12
13
  else
13
14
  raise ActionKitRest::Response::ValidationError.new(url: response[:url].to_s, body: response_body)
14
15
  end
15
16
  elsif status_code == 404
16
- raise ActionKitRest::Response::NotFound.new(response[:url].to_s)
17
+ raise ActionKitRest::Response::NotFound, response[:url].to_s
17
18
  elsif status_code == 401
18
- raise ActionKitRest::Response::Unauthorized.new(response[:url].to_s)
19
- elsif status_code == 500 && response[:body] =~ /\"error\"/
19
+ raise ActionKitRest::Response::Unauthorized, response[:url].to_s
20
+ elsif status_code == 500 && response[:body] =~ /"error"/
20
21
  error_hsh = JSON.parse(response[:body])
21
22
  error_message = error_hsh['error']
22
23
 
23
24
  if error_message == 'Sorry, this request could not be processed. Please try again later.'
24
- raise ActionKitRest::Response::TryAgainLater.new(error_message(response))
25
+ raise ActionKitRest::Response::TryAgainLater, error_message(response)
25
26
  else
26
- raise StandardError.new(error_message(response))
27
+ raise StandardError, error_message(response)
27
28
  end
28
29
  else
29
- raise StandardError.new(error_message(response))
30
+ raise StandardError, error_message(response)
30
31
  end
31
32
  end
32
33
  end
33
34
 
34
35
  def error_message(response)
35
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} \n\n #{response[:body] if response[:body]}"
36
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}"
36
37
  end
37
38
  end
38
39
 
39
- class TryAgainLater < StandardError ; end
40
- class NotFound < StandardError ; end
41
- class Unauthorized < StandardError ; end
40
+ class TryAgainLater < StandardError; end
41
+
42
+ class NotFound < StandardError; end
43
+
44
+ class Unauthorized < StandardError; end
42
45
  end
43
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionKitRest
2
4
  module Response
3
5
  class ValidationError < StandardError
@@ -5,24 +7,33 @@ module ActionKitRest
5
7
 
6
8
  def initialize(params)
7
9
  self.url = params[:url]
8
- self.body = params[:body]
10
+ self.body = params[:body].dup
9
11
  self.errors = JSON.parse(params[:body])['errors']
10
12
  super()
11
13
  end
12
14
 
13
15
  def to_s
14
- begin
15
- "#{super()} \n url: #{url} \n body: #{body} \n errors: #{errors}"
16
- rescue Encoding::CompatibilityError
17
- # Something went gravely wrong trying to construct the error message, so give up on the extra info
18
- # and just raise the name of the exception.
19
- # This will let us at least raise with a backtrace.
20
- super
21
- end
16
+ "#{super()} \n url: #{url} \n body: #{body.force_encoding('UTF-8')} \n errors: #{errors}"
17
+ rescue Encoding::CompatibilityError
18
+ # Something went gravely wrong trying to construct the error message, so give up on the extra info
19
+ # and just raise the name of the exception.
20
+ # This will let us at least raise with a backtrace.
21
+ super
22
22
  end
23
23
  end
24
24
 
25
25
  class InvalidAkidError < ValidationError
26
+ MATCHING_ERRORS = ['Unable to associate this mailing ID with account.',
27
+ 'לא הצלחנו לקשר בין מספר הזיהוי של רשימת הדיוור הזו לבין החשבון.'].freeze
28
+
29
+ def self.matches?(errors)
30
+ return false unless errors.keys == ['mailing_id']
31
+
32
+ mailing_id_errors = errors['mailing_id']
33
+ return false unless mailing_id_errors.size == 1
34
+
35
+ MATCHING_ERRORS.include?(mailing_id_errors.first)
36
+ end
26
37
  end
27
38
  end
28
39
  end
@@ -1,17 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionKitRest
2
4
  module Response
3
5
  class Wrapper
4
6
  include Enumerable
5
7
  extend Forwardable
6
8
 
7
- attr_reader :response
8
- attr_reader :kind
9
- attr_reader :obj
9
+ attr_reader :response, :kind, :obj
10
10
 
11
11
  def_delegators :body, :empty?, :size, :include?, :length, :to_a, :first, :flatten, :include?, :keys, :[]
12
12
 
13
13
  def initialize(response)
14
- @response = response
14
+ @response = response
15
15
 
16
16
  if response.body.respond_to?(:meta) && response.body.meta
17
17
  @kind = :collection
@@ -42,7 +42,7 @@ module ActionKitRest
42
42
 
43
43
  # Response raw body
44
44
  def body
45
- @body ? @body : response.body
45
+ @body || response.body
46
46
  end
47
47
 
48
48
  # Response status
@@ -70,10 +70,10 @@ module ActionKitRest
70
70
  # Convert any key to string before calling.
71
71
  #
72
72
  def [](key)
73
- if self.body.is_a?(Array)
74
- self.body[key]
73
+ if body.is_a?(Array)
74
+ body[key]
75
75
  else
76
- self.body.send(:"#{key}")
76
+ body.send(:"#{key}")
77
77
  end
78
78
  end
79
79
 
@@ -112,9 +112,9 @@ module ActionKitRest
112
112
  block.call(o)
113
113
  end
114
114
  else
115
- raise("can only iterate over collections")
115
+ raise('can only iterate over collections')
116
116
  end
117
117
  end
118
118
  end
119
119
  end
120
- end
120
+ end
@@ -1,20 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionKitRest
2
4
  class Tag < Base
3
5
  def base_path
4
6
  'tag'
5
7
  end
6
-
8
+
7
9
  def find(name)
8
10
  response = list(name: name)
9
11
  response.obj.first
10
12
  end
11
-
13
+
12
14
  def find_or_create(name)
13
15
  tag = find(name)
14
- if tag.blank?
15
- tag = create(name: name)
16
- end
16
+ tag = create(name: name) if tag.blank?
17
17
  tag
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionKitRest
2
4
  class User < Base
3
5
  def base_path
@@ -17,4 +19,4 @@ module ActionKitRest
17
19
  user
18
20
  end
19
21
  end
20
- end
22
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionKitRest
2
4
  module VERSION
3
5
  MAJOR = 0
4
6
  MINOR = 4
5
- PATCH = 3
7
+ PATCH = 7
6
8
  BUILD = nil
7
9
 
8
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'vertebrae'
2
4
 
3
5
  module ActionKitRest
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe ActionKitRest::Actions::EventCreateAction do
4
6
  describe '#get' do
5
- let(:actionkit) { ActionKitRest.new(host: 'test.com') }
7
+ let(:actionkit) { ActionKitRest.new(host: 'test.com') }
6
8
 
7
9
  before :each do
8
- stub_request(:get, "https://test.com/rest/v1/eventcreateaction/123/")
9
- .to_return(body: fixture('action/event_create_action.json'), status: '200', headers: {content_type: "application/json; charset=utf-8"})
10
+ stub_request(:get, 'https://test.com/rest/v1/eventcreateaction/123/')
11
+ .to_return(body: fixture('action/event_create_action.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
10
12
  end
11
13
 
12
14
  it 'should retrieve eventcreateaction and aggregate parsed event and user IDs' do
13
15
  ak_event_create_action = actionkit.event_create_action.get('123')
14
16
 
15
- expect(ak_event_create_action.id).to eq(12345)
17
+ expect(ak_event_create_action.id).to eq(12_345)
16
18
  expect(ak_event_create_action.event_id).to eq('999')
17
19
  expect(ak_event_create_action.user_id).to eq('112233')
18
20
  end
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe ActionKitRest::Actions::EventSignupAction do
4
6
  describe '#get' do
5
- let(:actionkit) { ActionKitRest.new(host: 'test.com') }
7
+ let(:actionkit) { ActionKitRest.new(host: 'test.com') }
6
8
 
7
9
  before :each do
8
- stub_request(:get, "https://test.com/rest/v1/eventsignupaction/54321/")
9
- .to_return(body: fixture('action/event_signup_action.json'), status: '200', headers: {content_type: "application/json; charset=utf-8"})
10
+ stub_request(:get, 'https://test.com/rest/v1/eventsignupaction/54321/')
11
+ .to_return(body: fixture('action/event_signup_action.json'), status: '200', headers: { content_type: 'application/json; charset=utf-8' })
10
12
  end
11
13
 
12
14
  it 'should retrieve eventsignupaction and aggregate parsed event sign-up and user IDs' do
13
15
  ak_event_signup_action = actionkit.event_signup_action.get('54321')
14
16
 
15
- expect(ak_event_signup_action.id).to eq(54321)
17
+ expect(ak_event_signup_action.id).to eq(54_321)
16
18
  expect(ak_event_signup_action.event_signup_id).to eq('888')
17
19
  expect(ak_event_signup_action.user_id).to eq('111')
18
20
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe ActionKitRest::AllowedUserField do
4
6
  let(:status) { 200 }
5
- let(:standard_headers) { {content_type: "application/json; charset=utf-8"} }
7
+ let(:standard_headers) { { content_type: 'application/json; charset=utf-8' } }
6
8
 
7
9
  subject { ActionKitRest.new(host: 'test.com', username: 'alice', password: 'somesecret') }
8
10
 
@@ -19,7 +21,7 @@ describe ActionKitRest::AllowedUserField do
19
21
  let(:response_body) { fixture('allowed_user_field/list.json') }
20
22
 
21
23
  before :each do
22
- stub_get(request_path).with(basic_auth: ['alice', 'somesecret'])
24
+ stub_get(request_path).with(basic_auth: %w[alice somesecret])
23
25
  .to_return(body: response_body,
24
26
  status: status,
25
27
  headers: standard_headers)
@@ -38,7 +40,7 @@ describe ActionKitRest::AllowedUserField do
38
40
  let(:response_body) { fixture('allowed_user_field/list_filtered.json') }
39
41
 
40
42
  before :each do
41
- stub_get(request_path).with(basic_auth: ['alice', 'somesecret'])
43
+ stub_get(request_path).with(basic_auth: %w[alice somesecret])
42
44
  .to_return(body: response_body,
43
45
  status: status,
44
46
  headers: standard_headers)
@@ -52,26 +54,26 @@ describe ActionKitRest::AllowedUserField do
52
54
 
53
55
  describe '#create' do
54
56
  let(:create_request_path) { 'alloweduserfield/' }
55
- let(:create_request_body) { {name: 'foo'}.to_json }
57
+ let(:create_request_body) { { name: 'foo' }.to_json }
56
58
  let(:create_status) { 201 }
57
59
  let(:created_url) { 'https://test.com/rest/v1/alloweduserfield/foo/' }
58
60
  let(:get_request_path) { 'alloweduserfield/foo/' }
59
61
  let(:get_response_body) { fixture('allowed_user_field/get.json') }
60
62
 
61
63
  before :each do
62
- stub_post(create_request_path).with(basic_auth: ['alice', 'somesecret'],
64
+ stub_post(create_request_path).with(basic_auth: %w[alice somesecret],
63
65
  body: create_request_body)
64
66
  .to_return(status: create_status,
65
67
  headers: standard_headers.merge(Location: created_url))
66
68
 
67
- stub_get(get_request_path).with(basic_auth: ['alice', 'somesecret'])
69
+ stub_get(get_request_path).with(basic_auth: %w[alice somesecret])
68
70
  .to_return(body: get_response_body,
69
71
  status: status,
70
72
  headers: standard_headers)
71
73
  end
72
74
 
73
75
  it 'should POST to the endpoint, then do a GET on the created object' do
74
- field = subject.allowed_user_field.create({name: 'foo'})
76
+ field = subject.allowed_user_field.create({ name: 'foo' })
75
77
  expect(field.display_name).to eq 'Foo'
76
78
  end
77
79
  end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'support/shared_contexts/stub_logger'
5
+
6
+ describe ActionKitRest::API do
7
+ include_context 'stub_logger'
8
+
9
+ subject { ActionKitRest::API.new(host: 'example.com', username: 'foo', password: 'bar') }
10
+
11
+ describe 'error detection' do
12
+ let(:request_body) { {some: 'data'} }
13
+
14
+ before :each do
15
+ stub_request(:post, 'https://example.com/rest/v1/something/')
16
+ .to_return(status: response_status, body: response_body,
17
+ headers: { content_type: 'application/json; charset=utf-8' })
18
+ end
19
+
20
+ context 'successful response' do
21
+ let(:response_status) { 200 }
22
+ let(:response_body) { '{"message": "good job!"}' }
23
+
24
+ it 'should not raise' do
25
+ subject.post_request('something/', request_body)
26
+ end
27
+ end
28
+
29
+ context '400 response' do
30
+ let(:response_status) { 400 }
31
+
32
+ context 'unable to associate mailing ID' do
33
+ let(:response_body) { '{"errors": {"mailing_id": ["Unable to associate this mailing ID with account."]}}' }
34
+
35
+ it 'should raise an InvalidAkidError' do
36
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::InvalidAkidError)
37
+ end
38
+ end
39
+
40
+ context 'unable to associate mailing ID error in Hebrew' do
41
+ let(:response_body) { '{"errors": {"mailing_id": ["לא הצלחנו לקשר בין מספר הזיהוי של רשימת הדיוור הזו לבין החשבון."]}}' }
42
+
43
+ it 'should raise an InvalidAkidError' do
44
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::InvalidAkidError)
45
+ end
46
+ end
47
+
48
+ context 'other error' do
49
+ let(:response_body) { '{"errors": {"zip": ["There is something wrong with your ZIP code!"]}}' }
50
+
51
+ it 'sould raise a ValidationError' do
52
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::ValidationError)
53
+ end
54
+ end
55
+ end
56
+
57
+ context '401 response' do
58
+ let(:response_status) { 401 }
59
+ let(:response_body) { '{"error": "Your API key is no good"}' }
60
+
61
+ it 'should raise an Unauthorized exception' do
62
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::Unauthorized)
63
+ end
64
+ end
65
+
66
+ context '404 response' do
67
+ let(:response_status) { 404 }
68
+ let(:response_body) { '{"error": "not found"}' }
69
+
70
+ it 'should raise a NotFound exception' do
71
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::NotFound)
72
+ end
73
+ end
74
+
75
+ context '500 response' do
76
+ let(:response_status) { 500 }
77
+
78
+ context 'Try Again Later message' do
79
+ let(:response_body) { '{"error": "Sorry, this request could not be processed. Please try again later."}' }
80
+
81
+ it 'should raise a TryAgainLater exception' do
82
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::TryAgainLater)
83
+ end
84
+ end
85
+
86
+ context 'other error message' do
87
+ let(:response_body) { '{"error": "Something is wrong, we will fix it!"}' }
88
+
89
+ it 'should raise a StandardError' do
90
+ expect{ subject.post_request('something/', request_body) }.to raise_error(StandardError)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -1,20 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe ActionKitRest do
4
6
  describe 'logging' do
5
- it "should have a logger" do
7
+ it 'should have a logger' do
6
8
  ActionKitRest.respond_to?(:logger).should be_truthy
7
9
  end
8
10
 
9
- it "should be able to log debug methods" do
11
+ it 'should be able to log debug methods' do
10
12
  ActionKitRest.logger.respond_to?(:debug).should be_truthy
11
13
  end
12
14
 
13
- it "should be settable" do
15
+ it 'should be settable' do
14
16
  ActionKitRest.respond_to?(:logger=).should be_truthy
15
- log = double()
17
+ log = double
16
18
  ActionKitRest.logger = log
17
19
  ActionKitRest.logger.should == log
18
20
  end
19
21
  end
20
- end
22
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe ActionKitRest::Page do
@@ -16,7 +18,7 @@ describe ActionKitRest::Page do
16
18
  subject.connection.configuration.host.should == 'test.com'
17
19
  end
18
20
 
19
- it "should have a client" do
21
+ it 'should have a client' do
20
22
  subject.page.client.should_not be_nil
21
23
  end
22
24
 
@@ -29,82 +31,80 @@ describe ActionKitRest::Page do
29
31
  end
30
32
  end
31
33
 
32
-
33
- describe "retrieval" do
34
+ describe 'retrieval' do
34
35
  before(:each) do
35
- stub_get(request_path).to_return(:body => body, :status => status,
36
- :headers => {:content_type => "application/json; charset=utf-8"})
36
+ stub_get(request_path).to_return(body: body, status: status,
37
+ headers: { content_type: 'application/json; charset=utf-8' })
37
38
  end
38
39
 
39
- describe ".list" do
40
+ describe '.list' do
40
41
  let(:status) { 200 }
41
42
  let(:body) { fixture('page/collection.json') }
42
43
  let(:request_path) { 'page/' }
43
44
 
44
- it "should allow listing the objects" do
45
+ it 'should allow listing the objects' do
45
46
  pages = subject.page.list
46
47
 
47
48
  pages.should be_an_instance_of(ActionKitRest::Response::Wrapper)
48
49
 
49
- pages.each do | obj |
50
+ pages.each do |obj|
50
51
  obj.should be_an_instance_of(Hashie::Mash)
51
52
  obj.should respond_to(:goal)
52
53
  end
53
54
  end
54
55
  end
55
56
 
56
- describe ".page" do
57
-
57
+ describe '.page' do
58
58
  let(:body) { fixture('page/object.json') }
59
59
  let(:request_path) { 'page/1/' }
60
60
 
61
- describe "success" do
61
+ describe 'success' do
62
62
  let(:status) { 200 }
63
- it "should return a single object" do
63
+ it 'should return a single object' do
64
64
  page = subject.page.get(1)
65
65
  page.goal.should == 10
66
66
  end
67
67
  end
68
68
 
69
- describe "not found" do
69
+ describe 'not found' do
70
70
  let(:status) { 404 }
71
71
 
72
- it "should return nil" do
73
- lambda{ subject.page.get(1).should == nil }.should raise_exception(ActionKitRest::Response::NotFound)
72
+ it 'should return nil' do
73
+ -> { subject.page.get(1).should.nil? }.should raise_exception(ActionKitRest::Response::NotFound)
74
74
  end
75
75
  end
76
-
77
- describe "error" do
76
+
77
+ describe 'error' do
78
78
  let(:status) { 400 }
79
79
  let(:body) { fixture('error.json') }
80
-
81
- it "should raise an ak validation response error" do
82
- lambda{ subject.page.get(1) }.should raise_exception(ActionKitRest::Response::ValidationError)
83
- end
80
+
81
+ it 'should raise an ak validation response error' do
82
+ -> { subject.page.get(1) }.should raise_exception(ActionKitRest::Response::ValidationError)
83
+ end
84
84
  end
85
85
 
86
86
  describe 'mailing ID error' do
87
87
  let(:status) { 400 }
88
88
  let(:body) { '{"errors": {"mailing_id": ["Unable to associate this mailing ID with account."]}}' }
89
89
 
90
- it "should raise an Invalid AKID response error" do
91
- lambda{ subject.page.get(1) }.should raise_exception(ActionKitRest::Response::InvalidAkidError)
90
+ it 'should raise an Invalid AKID response error' do
91
+ -> { subject.page.get(1) }.should raise_exception(ActionKitRest::Response::InvalidAkidError)
92
92
  end
93
93
  end
94
94
 
95
- describe "an error" do
95
+ describe 'an error' do
96
96
  let(:status) { 500 }
97
97
 
98
- it "should return nil" do
99
- lambda{ subject.page.get(1).should == nil }.should raise_exception(StandardError)
98
+ it 'should return nil' do
99
+ -> { subject.page.get(1).should.nil? }.should raise_exception(StandardError)
100
100
  end
101
101
  end
102
102
 
103
103
  describe 'try again' do
104
104
  let(:status) { 500 }
105
105
  let(:body) { '{"error": "Sorry, this request could not be processed. Please try again later."}' }
106
- it "should return nil" do
107
- lambda{ subject.page.get(1).should == nil }.should raise_exception(ActionKitRest::Response::TryAgainLater)
106
+ it 'should return nil' do
107
+ -> { subject.page.get(1).should.nil? }.should raise_exception(ActionKitRest::Response::TryAgainLater)
108
108
  end
109
109
  end
110
110
  end