Skip to content

Commit

Permalink
to_json all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcc committed Mar 3, 2015
1 parent a5e41bb commit 152e883
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/messenger/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def self.obfuscate(url)
def self.build_message(channel, display_name, body)
msg = { channel: channel, username: display_name }

return msg.merge({ text: body }) if body.is_a?(String)
if body.is_a?(String)
msg.merge!({ text: body })

if body.is_a?(Array)
elsif body.is_a?(Array)
msg['attachments'] = body
end

if body.is_a?(Hash)
elsif body.is_a?(Hash)
msg['attachments'] = []
msg['attachments'].push(body)
end
Expand Down
4 changes: 2 additions & 2 deletions test/messenger/slack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Messenger::SlackTest < Test::Unit::TestCase
end

should "post a successful message as a string" do
HTTParty.expects(:post).with("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", :body => { channel: '#room', username: 'displayname', text: 'hello world!' }, :headers => { "Content-Type" => "application/json"}).returns(@success_response)
HTTParty.expects(:post).with("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", :body => { channel: '#room', username: 'displayname', text: 'hello world!' }.to_json, :headers => { "Content-Type" => "application/json"}).returns(@success_response)
result = Messenger::Slack.deliver("slack://displayname@hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room", 'hello world!')
assert result.success?
assert_equal @success_response, result.response
Expand All @@ -30,7 +30,7 @@ class Messenger::SlackTest < Test::Unit::TestCase
end

should "post a failed message" do
HTTParty.expects(:post).with("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", :body => { channel: '#room', username: 'displayname', text: 'hello world!' }, :headers => { "Content-Type" => "application/json"}).returns(@failure_response)
HTTParty.expects(:post).with("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", :body => { channel: '#room', username: 'displayname', text: 'hello world!' }.to_json, :headers => { "Content-Type" => "application/json"}).returns(@failure_response)
result = Messenger::Slack.deliver("slack://displayname@hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX/#room", 'hello world!')
assert_equal false, result.success?
assert_equal @failure_response, result.response
Expand Down

0 comments on commit 152e883

Please sign in to comment.