From 23895e53aa0e9108eaad23b70da8d4c177fb52df Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Sun, 28 Sep 2025 21:11:07 +0200 Subject: [PATCH] Add tests for new controllers --- .../collections/columns/closeds_controller.rb | 2 +- .../columns/not_nows_controller.rb | 2 +- .../collections/columns/streams_controller.rb | 2 +- .../public/collections/columns_controller.rb | 2 +- .../cards/not_nows_controller_test.rb | 16 ++++++++ .../cards/triages_controller_test.rb | 27 +++++++++++++ test/controllers/cards_controller_test.rb | 2 +- .../columns/closeds_controller_test.rb | 12 ++++++ .../columns/not_nows_controller_test.rb | 12 ++++++ .../columns/streams_controller_test.rb | 12 ++++++ .../collections/columns_controller_test.rb | 39 +++++++++++++++++++ .../collections_controller_test.rb | 5 +++ .../cards/drops/closures_controller_test.rb | 16 ++++++++ .../cards/drops/columns_controller_test.rb | 17 ++++++++ .../cards/drops/not_nows_controller_test.rb | 16 ++++++++ .../cards/drops/streams_controller_test.rb | 16 ++++++++ .../public/collections_controller_test.rb | 6 +++ test/models/collection/triageable_test.rb | 1 - 18 files changed, 199 insertions(+), 6 deletions(-) create mode 100644 test/controllers/cards/not_nows_controller_test.rb create mode 100644 test/controllers/cards/triages_controller_test.rb create mode 100644 test/controllers/collections/columns/closeds_controller_test.rb create mode 100644 test/controllers/collections/columns/not_nows_controller_test.rb create mode 100644 test/controllers/collections/columns/streams_controller_test.rb create mode 100644 test/controllers/collections/columns_controller_test.rb create mode 100644 test/controllers/columns/cards/drops/closures_controller_test.rb create mode 100644 test/controllers/columns/cards/drops/columns_controller_test.rb create mode 100644 test/controllers/columns/cards/drops/not_nows_controller_test.rb create mode 100644 test/controllers/columns/cards/drops/streams_controller_test.rb diff --git a/app/controllers/public/collections/columns/closeds_controller.rb b/app/controllers/public/collections/columns/closeds_controller.rb index db7577958..2b9467504 100644 --- a/app/controllers/public/collections/columns/closeds_controller.rb +++ b/app/controllers/public/collections/columns/closeds_controller.rb @@ -11,4 +11,4 @@ class Public::Collections::Columns::ClosedsController < ApplicationController # To enable caching at intermediate proxies during traffic spikes expires_in 5.seconds, public: true end -end \ No newline at end of file +end diff --git a/app/controllers/public/collections/columns/not_nows_controller.rb b/app/controllers/public/collections/columns/not_nows_controller.rb index 8d1dba303..67c0cd5bf 100644 --- a/app/controllers/public/collections/columns/not_nows_controller.rb +++ b/app/controllers/public/collections/columns/not_nows_controller.rb @@ -11,4 +11,4 @@ class Public::Collections::Columns::NotNowsController < ApplicationController # To enable caching at intermediate proxies during traffic spikes expires_in 5.seconds, public: true end -end \ No newline at end of file +end diff --git a/app/controllers/public/collections/columns/streams_controller.rb b/app/controllers/public/collections/columns/streams_controller.rb index b371a5600..c60144799 100644 --- a/app/controllers/public/collections/columns/streams_controller.rb +++ b/app/controllers/public/collections/columns/streams_controller.rb @@ -11,4 +11,4 @@ class Public::Collections::Columns::StreamsController < ApplicationController # To enable caching at intermediate proxies during traffic spikes expires_in 5.seconds, public: true end -end \ No newline at end of file +end diff --git a/app/controllers/public/collections/columns_controller.rb b/app/controllers/public/collections/columns_controller.rb index 3817c81b7..f074b8188 100644 --- a/app/controllers/public/collections/columns_controller.rb +++ b/app/controllers/public/collections/columns_controller.rb @@ -18,4 +18,4 @@ class Public::Collections::ColumnsController < ApplicationController def set_column @column = @collection.columns.find(params[:id]) end -end \ No newline at end of file +end diff --git a/test/controllers/cards/not_nows_controller_test.rb b/test/controllers/cards/not_nows_controller_test.rb new file mode 100644 index 000000000..0e1313802 --- /dev/null +++ b/test/controllers/cards/not_nows_controller_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +class Cards::NotNowsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "create" do + card = cards(:logo) + + assert_changes -> { card.reload.postponed? }, from: false, to: true do + post card_not_now_path(card) + assert_card_container_rerendered(card) + end + end +end diff --git a/test/controllers/cards/triages_controller_test.rb b/test/controllers/cards/triages_controller_test.rb new file mode 100644 index 000000000..8439d70f9 --- /dev/null +++ b/test/controllers/cards/triages_controller_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +class Cards::TriagesControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "create" do + card = cards(:logo) + original_column = card.column + column = columns(:writebook_in_progress) + + assert_changes -> { card.reload.column }, from: original_column, to: column do + post card_triage_path(card, column_id: column.id) + assert_card_container_rerendered(card) + end + end + + test "destroy" do + card = cards(:shipping) + + assert_changes -> { card.reload.column }, to: nil do + delete card_triage_path(card) + assert_card_container_rerendered(card) + end + end +end diff --git a/test/controllers/cards_controller_test.rb b/test/controllers/cards_controller_test.rb index 4165a6d96..dd17d0b48 100644 --- a/test/controllers/cards_controller_test.rb +++ b/test/controllers/cards_controller_test.rb @@ -16,7 +16,7 @@ class CardsControllerTest < ActionDispatch::IntegrationTest end test "create" do - assert_difference "Card.count", 1 do + assert_difference -> { Card.count }, 1 do post collection_cards_path(collections(:writebook)) end assert_redirected_to card_path(Card.last) diff --git a/test/controllers/collections/columns/closeds_controller_test.rb b/test/controllers/collections/columns/closeds_controller_test.rb new file mode 100644 index 000000000..ceda24a32 --- /dev/null +++ b/test/controllers/collections/columns/closeds_controller_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class Collections::Columns::ClosedsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "show" do + get collection_columns_closed_path(collections(:writebook)) + assert_response :success + end +end diff --git a/test/controllers/collections/columns/not_nows_controller_test.rb b/test/controllers/collections/columns/not_nows_controller_test.rb new file mode 100644 index 000000000..01c8d4950 --- /dev/null +++ b/test/controllers/collections/columns/not_nows_controller_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class Collections::Columns::NotNowsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "show" do + get collection_columns_not_now_path(collections(:writebook)) + assert_response :success + end +end diff --git a/test/controllers/collections/columns/streams_controller_test.rb b/test/controllers/collections/columns/streams_controller_test.rb new file mode 100644 index 000000000..1bf76e55a --- /dev/null +++ b/test/controllers/collections/columns/streams_controller_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class Collections::Columns::StreamsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "show" do + get collection_columns_stream_path(collections(:writebook)) + assert_response :success + end +end diff --git a/test/controllers/collections/columns_controller_test.rb b/test/controllers/collections/columns_controller_test.rb new file mode 100644 index 000000000..1c830ee4a --- /dev/null +++ b/test/controllers/collections/columns_controller_test.rb @@ -0,0 +1,39 @@ +require "test_helper" + +class Collections::ColumnsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "show" do + get collection_column_path(collections(:writebook), columns(:writebook_in_progress)) + assert_response :success + end + + test "create" do + assert_difference -> { collections(:writebook).columns.count }, +1 do + post collection_columns_path(collections(:writebook)), params: { column: { name: "New Column" } }, as: :turbo_stream + assert_response :success + end + + assert_equal "New Column", collections(:writebook).columns.last.name + end + + test "update" do + column = columns(:writebook_in_progress) + + assert_changes -> { column.reload.name }, from: "In progress", to: "Updated Name" do + put collection_column_path(collections(:writebook), column), params: { column: { name: "Updated Name" } }, as: :turbo_stream + assert_response :success + end + end + + test "destroy" do + column = columns(:writebook_on_hold) + + assert_difference -> { collections(:writebook).columns.count }, -1 do + delete collection_column_path(collections(:writebook), column), as: :turbo_stream + assert_response :success + end + end +end diff --git a/test/controllers/collections_controller_test.rb b/test/controllers/collections_controller_test.rb index ed95fe278..4193cbbdd 100644 --- a/test/controllers/collections_controller_test.rb +++ b/test/controllers/collections_controller_test.rb @@ -10,6 +10,11 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "show" do + get collection_path(collections(:writebook)) + assert_response :success + end + test "create" do assert_difference -> { Collection.count }, +1 do post collections_path, params: { collection: { name: "Remodel Punch List" } } diff --git a/test/controllers/columns/cards/drops/closures_controller_test.rb b/test/controllers/columns/cards/drops/closures_controller_test.rb new file mode 100644 index 000000000..6a9d995e4 --- /dev/null +++ b/test/controllers/columns/cards/drops/closures_controller_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +class Columns::Cards::Drops::ClosuresControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "create" do + card = cards(:logo) + + assert_changes -> { card.reload.closed? }, from: false, to: true do + post columns_card_drops_closure_path(card), as: :turbo_stream + assert_response :success + end + end +end diff --git a/test/controllers/columns/cards/drops/columns_controller_test.rb b/test/controllers/columns/cards/drops/columns_controller_test.rb new file mode 100644 index 000000000..eeb670cbf --- /dev/null +++ b/test/controllers/columns/cards/drops/columns_controller_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +class Columns::Cards::Drops::ColumnsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "create" do + card = cards(:logo) + column = columns(:writebook_in_progress) + + assert_changes -> { card.reload.column }, to: column do + post columns_card_drops_column_path(card, column_id: column.id), as: :turbo_stream + assert_response :success + end + end +end diff --git a/test/controllers/columns/cards/drops/not_nows_controller_test.rb b/test/controllers/columns/cards/drops/not_nows_controller_test.rb new file mode 100644 index 000000000..5cd19176a --- /dev/null +++ b/test/controllers/columns/cards/drops/not_nows_controller_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +class Columns::Cards::Drops::NotNowsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "create" do + card = cards(:logo) + + assert_changes -> { card.reload.postponed? }, from: false, to: true do + post columns_card_drops_not_now_path(card), as: :turbo_stream + assert_response :success + end + end +end diff --git a/test/controllers/columns/cards/drops/streams_controller_test.rb b/test/controllers/columns/cards/drops/streams_controller_test.rb new file mode 100644 index 000000000..5bd082e21 --- /dev/null +++ b/test/controllers/columns/cards/drops/streams_controller_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +class Columns::Cards::Drops::StreamsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + end + + test "create" do + card = cards(:text) + + assert_changes -> { card.reload.triaged? }, from: true, to: false do + post columns_card_drops_stream_path(card), as: :turbo_stream + assert_response :success + end + end +end diff --git a/test/controllers/public/collections_controller_test.rb b/test/controllers/public/collections_controller_test.rb index 0cb691c89..0a685c0c6 100644 --- a/test/controllers/public/collections_controller_test.rb +++ b/test/controllers/public/collections_controller_test.rb @@ -20,4 +20,10 @@ class Public::CollectionsControllerTest < ActionDispatch::IntegrationTest assert_response :not_found end + + test "show works without authentication" do + sign_out + get published_collection_path(collections(:writebook)) + assert_response :success + end end diff --git a/test/models/collection/triageable_test.rb b/test/models/collection/triageable_test.rb index 2f07a59b1..d778591e3 100644 --- a/test/models/collection/triageable_test.rb +++ b/test/models/collection/triageable_test.rb @@ -15,4 +15,3 @@ class Collection::TriageableTest < ActiveSupport::TestCase end end end -