Rename Entropy::Configuration to just Entropy

This commit is contained in:
David Heinemeier Hansson
2025-11-02 13:11:41 +01:00
parent d29e4dcdcf
commit b3474ec97d
29 changed files with 148 additions and 148 deletions
@@ -0,0 +1,11 @@
class Account::EntropiesController < ApplicationController
def update
Entropy.default.update!(entropy_params)
redirect_to account_settings_path, notice: "Account updated"
end
private
def entropy_params
params.expect(entropy: [ :auto_postpone_period ])
end
end
@@ -1,11 +0,0 @@
class Account::EntropyConfigurationsController < ApplicationController
def update
Entropy::Configuration.default.update!(entropy_configuration_params)
redirect_to account_settings_path, notice: "Account updated"
end
private
def entropy_configuration_params
params.expect(entropy_configuration: [ :auto_postpone_period ])
end
end
@@ -0,0 +1,17 @@
class Collections::EntropiesController < ApplicationController
include CollectionScoped
def update
@collection.entropy.update!(entropy_params)
render turbo_stream: [
turbo_stream.replace([ @collection, :entropy], partial: "collections/edit/auto_close", locals: { collection: @collection }),
turbo_stream_flash(notice: "Saved")
]
end
private
def entropy_params
params.expect(collection: [ :auto_postpone_period ])
end
end
@@ -1,17 +0,0 @@
class Collections::EntropyConfigurationsController < ApplicationController
include CollectionScoped
def update
@collection.entropy_configuration.update!(entropy_configuration_params)
render turbo_stream: [
turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection }),
turbo_stream_flash(notice: "Saved")
]
end
private
def entropy_configuration_params
params.expect(collection: [ :auto_postpone_period ])
end
end
+1 -1
View File
@@ -16,7 +16,7 @@ class Account < ApplicationRecord
end end
end end
# To use the account as a generic card container. See +Entropy::Configuration+. # To use the account as a generic card container. See +Entropy+.
def cards def cards
Card.all Card.all
end end
+4 -4
View File
@@ -2,16 +2,16 @@ module Account::Entropic
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_one :default_entropy_configuration, class_name: "Entropy::Configuration", as: :container, dependent: :destroy has_one :default_entropy, class_name: "Entropy", as: :container, dependent: :destroy
before_save :set_default_entropy_configuration before_save :set_default_entropy
end end
private private
DEFAULT_ENTROPY_PERIOD = 30.days DEFAULT_ENTROPY_PERIOD = 30.days
def set_default_entropy_configuration def set_default_entropy
self.default_entropy_configuration ||= build_default_entropy_configuration \ self.default_entropy ||= build_default_entropy \
auto_postpone_period: DEFAULT_ENTROPY_PERIOD auto_postpone_period: DEFAULT_ENTROPY_PERIOD
end end
end end
+6 -6
View File
@@ -4,16 +4,16 @@ module Card::Entropic
included do included do
scope :due_to_be_postponed, -> do scope :due_to_be_postponed, -> do
active active
.left_outer_joins(collection: :entropy_configuration) .left_outer_joins(collection: :entropy)
.where("last_active_at <= DATETIME('now', '-' || COALESCE(entropy_configurations.auto_postpone_period, ?) || ' seconds')", .where("last_active_at <= DATETIME('now', '-' || COALESCE(entropies.auto_postpone_period, ?) || ' seconds')",
Entropy::Configuration.default.auto_postpone_period) Entropy.default.auto_postpone_period)
end end
scope :postponing_soon, -> do scope :postponing_soon, -> do
active active
.left_outer_joins(collection: :entropy_configuration) .left_outer_joins(collection: :entropy)
.where("last_active_at > DATETIME('now', '-' || COALESCE(entropy_configurations.auto_postpone_period, ?) || ' seconds')", Entropy::Configuration.default.auto_postpone_period) .where("last_active_at > DATETIME('now', '-' || COALESCE(entropies.auto_postpone_period, ?) || ' seconds')", Entropy.default.auto_postpone_period)
.where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropy_configurations.auto_postpone_period, ?) * 0.75 AS INTEGER) || ' seconds')", Entropy::Configuration.default.auto_postpone_period) .where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropies.auto_postpone_period, ?) * 0.75 AS INTEGER) || ' seconds')", Entropy.default.auto_postpone_period)
end end
delegate :auto_postpone_period, to: :collection delegate :auto_postpone_period, to: :collection
+1 -1
View File
@@ -8,7 +8,7 @@ class Collection < ApplicationRecord
has_many :tags, -> { distinct }, through: :cards has_many :tags, -> { distinct }, through: :cards
has_many :events has_many :events
has_many :webhooks, dependent: :destroy has_many :webhooks, dependent: :destroy
has_one :entropy_configuration, class_name: "Entropy::Configuration", as: :container, dependent: :destroy has_one :entropy, as: :container, dependent: :destroy
scope :alphabetically, -> { order("lower(name)") } scope :alphabetically, -> { order("lower(name)") }
scope :ordered_by_recently_accessed, -> { merge(Access.ordered_by_recently_accessed) } scope :ordered_by_recently_accessed, -> { merge(Access.ordered_by_recently_accessed) }
+5 -5
View File
@@ -2,15 +2,15 @@ module Collection::Entropic
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
delegate :auto_postpone_period, to: :entropy_configuration delegate :auto_postpone_period, to: :entropy
end end
def entropy_configuration def entropy
super || Entropy::Configuration.default super || Entropy.default
end end
def auto_postpone_period=(new_value) def auto_postpone_period=(new_value)
entropy_configuration ||= association(:entropy_configuration).reader || self.build_entropy_configuration entropy ||= association(:entropy).reader || self.build_entropy
entropy_configuration.update auto_postpone_period: new_value entropy.update auto_postpone_period: new_value
end end
end end
+14 -3
View File
@@ -1,5 +1,16 @@
module Entropy class Entropy < ApplicationRecord
def self.table_name_prefix belongs_to :container, polymorphic: true
"entropy_"
after_commit :touch_all_cards_later
class << self
def default
Account.sole.default_entropy
end
end
private
def touch_all_cards_later
Card::TouchAllJob.perform_later(container)
end end
end end
-16
View File
@@ -1,16 +0,0 @@
class Entropy::Configuration < ApplicationRecord
belongs_to :container, polymorphic: true
after_commit :touch_all_cards_later
class << self
def default
Account.sole.default_entropy_configuration
end
end
private
def touch_all_cards_later
Card::TouchAllJob.perform_later(container)
end
end
@@ -4,5 +4,5 @@
<p class="margin-none-block-start">BOXCAR doesnt let stale cards stick around forever. Cards automatically close as “Not Now” without activity for specific period of time. <em>This is the default, global setting — you can override it on each board.</em></p> <p class="margin-none-block-start">BOXCAR doesnt let stale cards stick around forever. Cards automatically close as “Not Now” without activity for specific period of time. <em>This is the default, global setting — you can override it on each board.</em></p>
</header> </header>
<%= render "entropy/auto_close", model: account.default_entropy_configuration, url: account_entropy_configuration_path %> <%= render "entropy/auto_close", model: account.default_entropy, url: account_entropy_path %>
</div> </div>
+1 -1
View File
@@ -10,5 +10,5 @@
<%= render "account/settings/users", users: @users %> <%= render "account/settings/users", users: @users %>
</div> </div>
<%= render "account/settings/entropy_configuration", account: @account %> <%= render "account/settings/entropy", account: @account %>
</section> </section>
@@ -1,7 +1,7 @@
<%= turbo_frame_tag @collection, :entropy_configuration do %> <%= turbo_frame_tag @collection, :entropy do %>
<div class="margin-block-end"> <div class="margin-block-end">
<h2 class="divider txt-large">Auto close</h2> <h2 class="divider txt-large">Auto close</h2>
<p class="margin-none-block-start">BOXCAR doesnt let stale cards stick around forever. Cards automatically close as “Not now” if no one updates, comments, or moves a card for…</p> <p class="margin-none-block-start">BOXCAR doesnt let stale cards stick around forever. Cards automatically close as “Not now” if no one updates, comments, or moves a card for…</p>
<%= render "entropy/auto_close", model: collection, url: collection_entropy_configuration_path(collection) %> <%= render "entropy/auto_close", model: collection, url: collection_entropy_path(collection) %>
</div> </div>
<% end %> <% end %>
+2 -2
View File
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
post :enter, to: "entries#create" post :enter, to: "entries#create"
resource :join_code resource :join_code
resource :settings resource :settings
resource :entropy_configuration resource :entropy
end end
resources :users do resources :users do
@@ -16,7 +16,7 @@ Rails.application.routes.draw do
resource :subscriptions resource :subscriptions
resource :involvement resource :involvement
resource :publication resource :publication
resource :entropy_configuration resource :entropy
namespace :columns do namespace :columns do
resource :not_now resource :not_now
@@ -0,0 +1,5 @@
class RenameEntropyConfigurationsToEntropies < ActiveRecord::Migration[8.2]
def change
rename_table :entropy_configurations, :entropies
end
end
Generated
+3 -3
View File
@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.2].define(version: 2025_10_29_161222) do ActiveRecord::Schema[8.2].define(version: 2025_11_02_115338) do
create_table "accesses", force: :cascade do |t| create_table "accesses", force: :cascade do |t|
t.datetime "accessed_at" t.datetime "accessed_at"
t.integer "collection_id", null: false t.integer "collection_id", null: false
@@ -220,13 +220,13 @@ ActiveRecord::Schema[8.2].define(version: 2025_10_29_161222) do
t.index ["filter_id"], name: "index_creators_filters_on_filter_id" t.index ["filter_id"], name: "index_creators_filters_on_filter_id"
end end
create_table "entropy_configurations", force: :cascade do |t| create_table "entropies", force: :cascade do |t|
t.bigint "auto_postpone_period", default: 2592000, null: false t.bigint "auto_postpone_period", default: 2592000, null: false
t.integer "container_id", null: false t.integer "container_id", null: false
t.string "container_type", null: false t.string "container_type", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["container_type", "container_id", "auto_postpone_period"], name: "idx_on_container_type_container_id_auto_postpone_pe_47f82c5b73" t.index ["container_type", "container_id", "auto_postpone_period"], name: "idx_on_container_type_container_id_auto_postpone_pe_3d79b50517"
t.index ["container_type", "container_id"], name: "index_entropy_configurations_on_container", unique: true t.index ["container_type", "container_id"], name: "index_entropy_configurations_on_container", unique: true
end end
+8 -8
View File
@@ -606,7 +606,7 @@ columns:
creators_filters: creators_filters:
- *25 - *25
- *19 - *19
entropy_configurations: entropies:
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment: auto_increment:
name: auto_postpone_period name: auto_postpone_period
@@ -1254,7 +1254,7 @@ primary_keys:
columns: id columns: id
comments: id comments: id
creators_filters: creators_filters:
entropy_configurations: id entropies: id
events: id events: id
filters: id filters: id
filters_tags: filters_tags:
@@ -1301,7 +1301,7 @@ data_sources:
columns: true columns: true
comments: true comments: true
creators_filters: true creators_filters: true
entropy_configurations: true entropies: true
events: true events: true
filters: true filters: true
filters_tags: true filters_tags: true
@@ -2031,10 +2031,10 @@ indexes:
nulls_not_distinct: nulls_not_distinct:
comment: comment:
valid: true valid: true
entropy_configurations: entropies:
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: entropy_configurations table: entropies
name: idx_on_container_type_container_id_auto_postpone_pe_47f82c5b73 name: idx_on_container_type_container_id_auto_postpone_pe_3d79b50517
unique: false unique: false
columns: columns:
- container_type - container_type
@@ -2051,7 +2051,7 @@ indexes:
comment: comment:
valid: true valid: true
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: entropy_configurations table: entropies
name: index_entropy_configurations_on_container name: index_entropy_configurations_on_container
unique: true unique: true
columns: columns:
@@ -2879,4 +2879,4 @@ indexes:
nulls_not_distinct: nulls_not_distinct:
comment: comment:
valid: true valid: true
version: 20251029161222 version: 20251102115338
@@ -0,0 +1,15 @@
require "test_helper"
class Account::EntropiesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "update" do
put account_entropy_path, params: { entropy: { auto_postpone_period: 1.day } }
assert_equal 1.day, entropies("37s_account").auto_postpone_period
assert_redirected_to account_settings_path
end
end
@@ -1,15 +0,0 @@
require "test_helper"
class Account::EntropyConfigurationsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "update" do
put account_entropy_configuration_path, params: { entropy_configuration: { auto_postpone_period: 1.day } }
assert_equal 1.day, entropy_configurations("37s_account").auto_postpone_period
assert_redirected_to account_settings_path
end
end
@@ -0,0 +1,16 @@
require "test_helper"
class Collections::EntropiesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
@collection = collections(:writebook)
end
test "update" do
put collection_entropy_path(@collection), params: { collection: { auto_postpone_period: 1.day } }
assert_equal 1.day, @collection.entropy.reload.auto_postpone_period
assert_turbo_stream action: :replace, target: dom_id(@collection, :entropy)
end
end
@@ -1,16 +0,0 @@
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_postpone_period: 1.day } }
assert_equal 1.day, @collection.entropy_configuration.reload.auto_postpone_period
assert_turbo_stream action: :replace, target: dom_id(@collection, :entropy_configuration)
end
end
@@ -44,7 +44,7 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to edit_collection_path(collections(:writebook)) assert_redirected_to edit_collection_path(collections(:writebook))
assert_equal "Writebook bugs", collections(:writebook).reload.name assert_equal "Writebook bugs", collections(:writebook).reload.name
assert_equal users(:kevin, :jz).sort, collections(:writebook).users.sort assert_equal users(:kevin, :jz).sort, collections(:writebook).users.sort
assert_equal 1.day, entropy_configurations(:writebook_collection).auto_postpone_period assert_equal 1.day, entropies(:writebook_collection).auto_postpone_period
assert_not collections(:writebook).all_access? assert_not collections(:writebook).all_access?
end end
+12 -12
View File
@@ -8,8 +8,8 @@ class Card::EntropicTest < ActiveSupport::TestCase
test "auto_postpone_at uses the period defined in the account by default" do test "auto_postpone_at uses the period defined in the account by default" do
freeze_time freeze_time
entropy_configurations(:writebook_collection).destroy entropies(:writebook_collection).destroy
entropy_configurations("37s_account").reload.update! auto_postpone_period: 456.days entropies("37s_account").reload.update! auto_postpone_period: 456.days
cards(:layout).update! last_active_at: 2.day.ago cards(:layout).update! last_active_at: 2.day.ago
assert_equal (456 - 2).days.from_now, cards(:layout).entropy.auto_clean_at assert_equal (456 - 2).days.from_now, cards(:layout).entropy.auto_clean_at
end end
@@ -17,16 +17,16 @@ class Card::EntropicTest < ActiveSupport::TestCase
test "auto_postpone_at infers the period from the collection when present" do test "auto_postpone_at infers the period from the collection when present" do
freeze_time freeze_time
entropy_configurations(:writebook_collection).update! auto_postpone_period: 123.days entropies(:writebook_collection).update! auto_postpone_period: 123.days
cards(:layout).update! last_active_at: 2.day.ago cards(:layout).update! last_active_at: 2.day.ago
assert_equal (123 - 2).days.from_now, cards(:layout).entropy.auto_clean_at assert_equal (123 - 2).days.from_now, cards(:layout).entropy.auto_clean_at
end end
test "auto postpone all due using the default account entropy configuration" do test "auto postpone all due using the default account entropy" do
entropy_configurations(:writebook_collection).destroy entropies(:writebook_collection).destroy
cards(:logo).update!(last_active_at: 1.day.ago - entropy_configurations("37s_account").auto_postpone_period) cards(:logo).update!(last_active_at: 1.day.ago - entropies("37s_account").auto_postpone_period)
cards(:shipping).update!(last_active_at: 1.day.from_now - entropy_configurations("37s_account").auto_postpone_period) cards(:shipping).update!(last_active_at: 1.day.from_now - entropies("37s_account").auto_postpone_period)
assert_difference -> { Card.postponed.count }, +1 do assert_difference -> { Card.postponed.count }, +1 do
Card.auto_postpone_all_due Card.auto_postpone_all_due
@@ -37,9 +37,9 @@ class Card::EntropicTest < ActiveSupport::TestCase
assert_not cards(:shipping).reload.postponed? assert_not cards(:shipping).reload.postponed?
end end
test "auto postpone all due using entropy configuration defined at the collection level" do test "auto postpone all due using entropy defined at the collection level" do
cards(:logo).update!(last_active_at: 1.day.ago - entropy_configurations(:writebook_collection).auto_postpone_period) cards(:logo).update!(last_active_at: 1.day.ago - entropies(:writebook_collection).auto_postpone_period)
cards(:shipping).update!(last_active_at: 1.day.from_now - entropy_configurations(:writebook_collection).auto_postpone_period) cards(:shipping).update!(last_active_at: 1.day.from_now - entropies(:writebook_collection).auto_postpone_period)
assert_difference -> { Card.postponed.count }, +1 do assert_difference -> { Card.postponed.count }, +1 do
Card.auto_postpone_all_due Card.auto_postpone_all_due
@@ -52,8 +52,8 @@ class Card::EntropicTest < ActiveSupport::TestCase
test "postponing soon scope" do test "postponing soon scope" do
cards(:logo, :shipping).each(&:published!) cards(:logo, :shipping).each(&:published!)
cards(:logo).update!(last_active_at: entropy_configurations(:writebook_collection).auto_postpone_period.seconds.ago + 2.days) cards(:logo).update!(last_active_at: entropies(:writebook_collection).auto_postpone_period.seconds.ago + 2.days)
cards(:shipping).update!(last_active_at: entropy_configurations(:writebook_collection).auto_postpone_period.seconds.ago - 2.days) cards(:shipping).update!(last_active_at: entropies(:writebook_collection).auto_postpone_period.seconds.ago - 2.days)
assert_includes Card.postponing_soon, cards(:logo) assert_includes Card.postponing_soon, cards(:logo)
assert_not_includes Card.postponing_soon, cards(:shipping) assert_not_includes Card.postponing_soon, cards(:shipping)
+1 -1
View File
@@ -28,7 +28,7 @@ class Card::StallableTest < ActiveSupport::TestCase
test "a card with an old activity spike is not stalled after being postponed" do test "a card with an old activity spike is not stalled after being postponed" do
card = cards(:logo) card = cards(:logo)
card.update!(last_active_at: 1.day.ago - card.collection.entropy_configuration.auto_postpone_period) card.update!(last_active_at: 1.day.ago - card.collection.entropy.auto_postpone_period)
card.create_activity_spike!(updated_at: 3.months.ago) card.create_activity_spike!(updated_at: 3.months.ago)
assert card.stalled? assert card.stalled?
-20
View File
@@ -1,20 +0,0 @@
require "test_helper"
class Entropy::ConfigurationTest < ActiveSupport::TestCase
test "touch cards when configuration changes for collection container" do
collection = collections(:writebook)
config = collection.entropy_configuration || collection.create_entropy_configuration!(auto_postpone_period: 30.days)
assert_enqueued_with(job: Card::TouchAllJob, args: [ collection ]) do
config.update!(auto_postpone_period: 15.days)
end
end
test "touch cards when configuration changes for account container" do
account = Account.sole
assert_enqueued_with(job: Card::TouchAllJob, args: [ account ]) do
account.default_entropy_configuration.update!(auto_postpone_period: 45.days)
end
end
end
+20
View File
@@ -0,0 +1,20 @@
require "test_helper"
class Entropy::Test < ActiveSupport::TestCase
test "touch cards when entropy changes for collection container" do
collection = collections(:writebook)
config = collection.entropy || collection.create_entropy!(auto_postpone_period: 30.days)
assert_enqueued_with(job: Card::TouchAllJob, args: [ collection ]) do
config.update!(auto_postpone_period: 15.days)
end
end
test "touch cards when entropy changes for account container" do
account = Account.sole
assert_enqueued_with(job: Card::TouchAllJob, args: [ account ]) do
account.default_entropy.update!(auto_postpone_period: 45.days)
end
end
end
+2 -2
View File
@@ -9,7 +9,7 @@ class RouteTest < ActionDispatch::IntegrationTest
assert_recognizes({ controller: "account/settings", action: "show" }, "/account/settings") assert_recognizes({ controller: "account/settings", action: "show" }, "/account/settings")
end end
test "account/entropy_configuration" do test "account/entropy" do
assert_recognizes({ controller: "account/entropy_configurations", action: "show" }, "/account/entropy_configuration") assert_recognizes({ controller: "account/entropies", action: "show" }, "/account/entropy")
end end
end end