Skip to content

Commit

Permalink
replace data if passed
Browse files Browse the repository at this point in the history
  • Loading branch information
rowansmith committed May 8, 2018
1 parent 004f9f2 commit 601c7b4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
6 changes: 2 additions & 4 deletions lib/jsender/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ def error(message: "An error has occurred")
}.to_json
end

def failure(message: "A failure has occurred", data: {})
def failure(message: "A failure has occurred", data: nil)
{
'status' => 'fail',
'data' => {
'message' => message
}.merge(data)
'data' => data || { 'message' => message }
}.to_json
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jsender/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def error(code: 500, flow_id: nil, message: "An error has occurred", body_as_arr
]
end

def failure(code: 400, flow_id: nil, message: "A failure has occurred", data: {}, body_as_array: false)
def failure(code: 400, flow_id: nil, message: "A failure has occurred", data: nil, body_as_array: false)
[
code,
headers(flow_id: flow_id),
Expand Down
2 changes: 1 addition & 1 deletion lib/jsender/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Jsender
VERSION = "2.0.0"
VERSION = "2.0.1"
end
4 changes: 1 addition & 3 deletions spec/jsender_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
it 'should return a json encoded hash with provided data' do
expected_result = {
'status' => 'fail',
'data' => {
'message' => message
}.merge(data)
'data' => data
}.to_json
expect(subject.failure(message: message, data: data)).to eq(expected_result)
end
Expand Down
4 changes: 1 addition & 3 deletions spec/jsender_rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@
},
{
'status' => 'fail',
'data' => {
'message' => message,
}.merge(data)
'data' => data
}.to_json
]
expect(subject.failure(message: message, data: data)).to eq(expected_result)
Expand Down

0 comments on commit 601c7b4

Please sign in to comment.