From 36727ba5ea77d80d2eaaf65f106ce31ee6a23ef7 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 17:41:29 -0400 Subject: [PATCH] Introduce a separate controller for collection entropy config which opens the door to rendering turbo frames in the responses to collection edits. --- .../entropy_configurations_controller.rb | 14 ++++++++++++++ app/views/collections/edit/_auto_close.html.erb | 2 +- config/routes.rb | 1 + .../entropy_configurations_controller_test.rb | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/controllers/collections/entropy_configurations_controller.rb create mode 100644 test/controllers/collections/entropy_configurations_controller_test.rb diff --git a/app/controllers/collections/entropy_configurations_controller.rb b/app/controllers/collections/entropy_configurations_controller.rb new file mode 100644 index 000000000..c09edcf98 --- /dev/null +++ b/app/controllers/collections/entropy_configurations_controller.rb @@ -0,0 +1,14 @@ +class Collections::EntropyConfigurationsController < ApplicationController + include CollectionScoped + + def update + @collection.entropy_configuration.update!(entropy_configuration_params) + + redirect_to edit_collection_path(@collection), notice: "Collection updated" + end + + private + def entropy_configuration_params + params.expect(collection: [ :auto_close_period, :auto_reconsider_period ]) + end +end diff --git a/app/views/collections/edit/_auto_close.html.erb b/app/views/collections/edit/_auto_close.html.erb index d222fd5e8..825915756 100644 --- a/app/views/collections/edit/_auto_close.html.erb +++ b/app/views/collections/edit/_auto_close.html.erb @@ -1,4 +1,4 @@
Do or Die - <%= render "entropy/auto_close", model: collection %> + <%= render "entropy/auto_close", model: collection, url: collection_entropy_configuration_path(collection) %>
diff --git a/config/routes.rb b/config/routes.rb index 27fdf59a6..26dbfd3d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,7 @@ Rails.application.routes.draw do resource :workflow, only: :update resource :involvement resource :publication + resource :entropy_configuration end resources :cards diff --git a/test/controllers/collections/entropy_configurations_controller_test.rb b/test/controllers/collections/entropy_configurations_controller_test.rb new file mode 100644 index 000000000..0b2ddf060 --- /dev/null +++ b/test/controllers/collections/entropy_configurations_controller_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +class Collections::EntropyConfigurationsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + @collection = collections(:writebook) + end + + test "update" do + put collection_entropy_configuration_path(@collection), params: { collection: { auto_close_period: 1.day, auto_reconsider_period: 2.days } } + + assert_equal 1.day, @collection.entropy_configuration.reload.auto_close_period + assert_equal 2.days, @collection.entropy_configuration.reload.auto_reconsider_period + + assert_redirected_to edit_collection_path(@collection) + end +end