mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-09-25 09:44:59 +09:00
Adjust to match in-house style
- Remove comments that explain expected behaviour - Use respond_to instead of separate methods - Return the updated object on update
This commit is contained in:
@@ -18,13 +18,6 @@ class Messages::ByBotsController < MessagesController
|
||||
head :created, location: message_url(@message)
|
||||
end
|
||||
|
||||
# ensure_can_administer still applies, and can_administer? only grants access to
|
||||
# a record the user created, so a bot key reaches that bot's own messages and no others.
|
||||
def update
|
||||
update_message
|
||||
head :ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
super
|
||||
head :no_content
|
||||
|
||||
@@ -34,8 +34,14 @@ class MessagesController < ApplicationController
|
||||
end
|
||||
|
||||
def update
|
||||
update_message
|
||||
redirect_to room_message_url(@room, @message)
|
||||
@message.update!(message_params)
|
||||
|
||||
@message.broadcast_replace_to @room, :messages, target: [ @message, :presentation ], partial: "messages/presentation", attributes: { maintain_scroll: true }
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to room_message_url(@room, @message) }
|
||||
format.json { render :show }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -48,13 +54,6 @@ class MessagesController < ApplicationController
|
||||
@message = @room.messages.find(params[:id])
|
||||
end
|
||||
|
||||
# Extracted so bots can reuse the update and its broadcast while answering with
|
||||
# a status code instead of a redirect.
|
||||
def update_message
|
||||
@message.update!(message_params)
|
||||
@message.broadcast_replace_to @room, :messages, target: [ @message, :presentation ], partial: "messages/presentation", attributes: { maintain_scroll: true }
|
||||
end
|
||||
|
||||
def ensure_can_administer
|
||||
head :forbidden unless Current.user.can_administer?(@message)
|
||||
end
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
json.partial! "messages/message", message: @message
|
||||
@@ -158,6 +158,12 @@ class Messages::ByBotsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_response :ok
|
||||
assert_equal "Deployed.", message.reload.plain_text_body
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
assert_equal message.id, json["id"]
|
||||
assert_equal "Deployed.", json["body"]["plain_text"]
|
||||
assert_equal users(:bender).id, json["creator"]["id"]
|
||||
assert_equal room_message_url(@room, message), json["url"]
|
||||
end
|
||||
|
||||
test "update with UTF-8 content" do
|
||||
@@ -167,6 +173,7 @@ class Messages::ByBotsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_response :ok
|
||||
assert_equal "Deployed 🚀!", message.reload.plain_text_body
|
||||
assert_equal "Deployed 🚀!", JSON.parse(response.body)["body"]["plain_text"]
|
||||
end
|
||||
|
||||
test "update can't touch a message the bot did not create" do
|
||||
|
||||
Reference in New Issue
Block a user