Create cards via API
This commit is contained in:
committed by
Stanko K.R.
parent
f0c0a87c74
commit
983a19fd8a
@@ -10,8 +10,17 @@ class CardsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
card = @board.cards.find_or_create_by!(creator: Current.user, status: "drafted")
|
||||
redirect_to card
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
card = @board.cards.find_or_create_by!(creator: Current.user, status: "drafted")
|
||||
redirect_to card
|
||||
end
|
||||
|
||||
format.json do
|
||||
card = @board.cards.create! card_params.merge(creator: Current.user)
|
||||
head :created, location: card_path(card, format: :json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
json.partial! "cards/card", card: @card
|
||||
@@ -40,6 +40,14 @@ class ApiTest < ActionDispatch::IntegrationTest
|
||||
assert_equal "My new board", @response.parsed_body["name"]
|
||||
end
|
||||
|
||||
test "create card" do
|
||||
post board_cards_path(boards(:writebook), format: :json), params: { card: { title: "My new card" } }, env: @davids_bearer_token
|
||||
assert_equal card_path(Card.last, format: :json), @response.headers["Location"]
|
||||
|
||||
get card_path(Card.last, format: :json), env: @davids_bearer_token
|
||||
assert_equal "My new card", @response.parsed_body["title"]
|
||||
end
|
||||
|
||||
private
|
||||
def bearer_token_env(token)
|
||||
{ "HTTP_AUTHORIZATION" => "Bearer #{token}" }
|
||||
|
||||
Reference in New Issue
Block a user