Add API for creating and updating boards
This commit is contained in:
@@ -39,16 +39,25 @@ class BoardsController < ApplicationController
|
||||
@board.update! board_params
|
||||
@board.accesses.revise granted: grantees, revoked: revokees if grantees_changed?
|
||||
|
||||
if @board.accessible_to?(Current.user)
|
||||
redirect_to edit_board_path(@board), notice: "Saved"
|
||||
else
|
||||
redirect_to root_path, notice: "Saved (you were removed from the board)"
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
if @board.accessible_to?(Current.user)
|
||||
redirect_to edit_board_path(@board), notice: "Saved"
|
||||
else
|
||||
redirect_to root_path, notice: "Saved (you were removed from the board)"
|
||||
end
|
||||
end
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@board.destroy
|
||||
redirect_to root_path
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to root_path }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -211,4 +211,23 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :created
|
||||
assert_equal board_path(Board.last, format: :json), @response.headers["Location"]
|
||||
end
|
||||
|
||||
test "update as JSON" do
|
||||
board = boards(:writebook)
|
||||
|
||||
put board_path(board), params: { board: { name: "Updated Name" } }, as: :json
|
||||
|
||||
assert_response :no_content
|
||||
assert_equal "Updated Name", board.reload.name
|
||||
end
|
||||
|
||||
test "destroy as JSON" do
|
||||
board = boards(:writebook)
|
||||
|
||||
assert_difference -> { Board.count }, -1 do
|
||||
delete board_path(board), as: :json
|
||||
end
|
||||
|
||||
assert_response :no_content
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user