mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
Add turbo_stream format to requests on create and update action's tests
This commit is contained in:
parent
4087275751
commit
c6bf21490f
2 changed files with 13 additions and 12 deletions
|
@ -24,12 +24,12 @@ class CategoriesController < ApplicationController
|
|||
|
||||
redirect_target_url = request.referer || categories_path
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url), status: :created }
|
||||
end
|
||||
else
|
||||
set_categories
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace("form", partial: "form", locals: { category: @category, categories: @categories }) }
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace("form", partial: "form", locals: { category: @category, categories: @categories }), status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -42,11 +42,11 @@ class CategoriesController < ApplicationController
|
|||
flash[:notice] = t(".success")
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, categories_path) }
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, categories_path), status: :no_content }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace("form", partial: "form", locals: { category: @category, categories: @categories }) }
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace("form", partial: "form", locals: { category: @category, categories: @categories }), status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,22 +20,23 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
color = Category::COLORS.sample
|
||||
|
||||
assert_difference "Category.count", +1 do
|
||||
post categories_url, params: {
|
||||
post categories_url(format: :turbo_stream), params: {
|
||||
category: {
|
||||
name: "New Category",
|
||||
color: color } }
|
||||
color: color }
|
||||
}
|
||||
end
|
||||
|
||||
new_category = Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to categories_url
|
||||
assert_response :created
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
end
|
||||
|
||||
test "create fails if name is not unique" do
|
||||
assert_no_difference "Category.count" do
|
||||
post categories_url, params: {
|
||||
post categories_url(format: :turbo_stream), params: {
|
||||
category: {
|
||||
name: categories(:food_and_drink).name,
|
||||
color: Category::COLORS.sample } }
|
||||
|
@ -48,7 +49,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
color = Category::COLORS.sample
|
||||
|
||||
assert_difference "Category.count", +1 do
|
||||
post categories_url, params: {
|
||||
post categories_url(format: :turbo_stream), params: {
|
||||
transaction_id: @transaction.id,
|
||||
category: {
|
||||
name: "New Category",
|
||||
|
@ -57,7 +58,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
new_category = Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to categories_url
|
||||
assert_response :created
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
assert_equal @transaction.reload.category, new_category
|
||||
|
@ -73,14 +74,14 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
assert_changes -> { categories(:income).name }, to: "New Name" do
|
||||
assert_changes -> { categories(:income).reload.color }, to: new_color do
|
||||
patch category_url(categories(:income)), params: {
|
||||
patch category_url(categories(:income), format: :turbo_stream), params: {
|
||||
category: {
|
||||
name: "New Name",
|
||||
color: new_color } }
|
||||
end
|
||||
end
|
||||
|
||||
assert_redirected_to categories_url
|
||||
assert_response :no_content
|
||||
end
|
||||
|
||||
test "bootstrap" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue