Move default color to the column

This commit is contained in:
Jorge Manrubia
2025-11-14 11:15:09 +01:00
parent b1e087e7c9
commit 06b762c0a8
5 changed files with 8 additions and 9 deletions
+1 -3
View File
@@ -1,9 +1,7 @@
module Card::Colored
extend ActiveSupport::Concern
DEFAULT_COLOR = Color::COLORS.first
def color
column&.color || DEFAULT_COLOR
column&.color || Column::Colored::DEFAULT_COLOR
end
end
+4 -3
View File
@@ -1,12 +1,13 @@
module Column::Colored
extend ActiveSupport::Concern
DEFAULT_COLOR = Color::COLORS.first
included do
before_validation -> { self[:color] ||= Card::Colored::DEFAULT_COLOR.value }
before_validation -> { self[:color] ||= DEFAULT_COLOR.value }
end
def color
color_value = super
Color.for_value(color_value) || Card::Colored::DEFAULT_COLOR
Color.for_value(super) || DEFAULT_COLOR
end
end
@@ -5,7 +5,7 @@
<div class="color-picker__colors">
<% Color::COLORS.each do |color| %>
<label class="btn txt-small borderless" style="--btn-background: <%= color %>" title="<%= color.name %>">
<%= form.radio_button :color, color.value, checked: (column.color == color || (column.new_record? && color == Card::Colored::DEFAULT_COLOR)) %>
<%= form.radio_button :color, color.value, checked: (column.color == color || (column.new_record? && color == Column::Colored::DEFAULT_COLOR)) %>
<%= icon_tag "check", class: "checked" %>
<span class="for-screen-reader"><%= color.name %></span>
</label>
+1 -1
View File
@@ -3,7 +3,7 @@ require "test_helper"
class Card::ColoredTest < ActiveSupport::TestCase
test "use default color if no column" do
cards(:logo).update! column: nil
assert_equal Card::Colored::DEFAULT_COLOR, cards(:logo).color
assert_equal Column::Colored::DEFAULT_COLOR, cards(:logo).color
end
test "infer color from column" do
+1 -1
View File
@@ -4,7 +4,7 @@ class Column::ColoredTest < ActiveSupport::TestCase
test "creates column with default color when color not provided" do
column = boards(:writebook).columns.create!(name: "New Column")
assert_equal Card::Colored::DEFAULT_COLOR, column.color
assert_equal Column::Colored::DEFAULT_COLOR, column.color
end
test "update the column color" do