Skip to content

Commit

Permalink
Merge pull request mailjet#226 from mailjet/specs-fixes
Browse files Browse the repository at this point in the history
fix specs
  • Loading branch information
Retttro authored Mar 31, 2022
2 parents 2848dae + 8c67ae8 commit 84930d6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/mailjet/rack/endpoint.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rack/request'
require 'json'

module Mailjet
module Rack
Expand All @@ -11,7 +12,7 @@ def initialize(app, path, &block)

def call(env)
if env['PATH_INFO'] == @path && (content = env['rack.input'].read)
@block.call(ActiveSupport::JSON.decode(content))
@block.call(JSON.parse(content))
[200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
else
@app.call(env)
Expand Down
9 changes: 5 additions & 4 deletions lib/mailjet/resource.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'mailjet/connection'
require 'active_support/core_ext/string'
require 'active_support/core_ext/module/delegation'
require 'active_support/hash_with_indifferent_access'
#require 'mail'
require 'json'

Expand Down Expand Up @@ -68,7 +69,7 @@ def all(params = {}, options = {})
def count(options = {})
opts = define_options(options)
response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1}))
response_hash = ActiveSupport::JSON.decode(response_json)
response_hash = JSON.parse(response_json)
response_hash['Total']
end

Expand Down Expand Up @@ -128,7 +129,7 @@ def instanciate_from_api(attributes = {})
end

def parse_api_json(response_json)
response_hash = ActiveSupport::JSON.decode(response_json)
response_hash = JSON.parse(response_json)

#Take the response from the API and put it through a method -- taken from the ActiveSupport library -- which converts
#the date-time from "2014-05-19T15:31:09Z" to "Mon, 19 May 2014 15:31:09 +0000" format.
Expand Down Expand Up @@ -255,7 +256,7 @@ def save(options = {})
if opts[:perform_api_call] && !persisted?
# get attributes only for entity creation
self.attributes = if self.resource_path == 'send'
ActiveSupport::JSON.decode(response)
JSON.parse(response)
else
parse_api_json(response).first
end
Expand Down Expand Up @@ -320,7 +321,7 @@ def formatted_payload
payload.tap { |hs| hs.delete("Persisted") }
payload.inject({}) do |h, (k, v)|
if v.respond_to? :utc
v = v.utc.as_json
v = v.utc.to_s
end
h.merge!({k => v})
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/cassettes/resource/test_contact/update.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions spec/mailjet/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestResource
:accept_encoding => :deflate,
:content_type => :json,
:params => { "Limit" => 1 },
:user_agent => "mailjet-api-v3-ruby/1.6.0"
:user_agent => "mailjet-api-v3-ruby/1.7.0"
}
).and_return('{"Data" : [{ "Test" : "Value" }]}')
end
Expand All @@ -63,7 +63,7 @@ class TestResource
:accept_encoding => :deflate,
:content_type => :json,
:params => {},
:user_agent => "mailjet-api-v3-ruby/1.6.0"
:user_agent => "mailjet-api-v3-ruby/1.7.0"
}
).and_return('{"Data" : [{ "Test" : "Value1" }, { "Test" : "Value2" }]}')
end
Expand All @@ -89,7 +89,7 @@ class TestResource
:accept => :json,
:accept_encoding => :deflate,
:content_type => :json,
:user_agent => "mailjet-api-v3-ruby/1.6.0"
:user_agent => "mailjet-api-v3-ruby/1.7.0"
}
).and_return("{\"Data\" : [{ \"ID\" : #{id}, \"Test\" : \"Value1\" }]}")
end
Expand Down

0 comments on commit 84930d6

Please sign in to comment.