Skip to content

Commit

Permalink
Gather the missing colors from the life cycle seeds instead of using …
Browse files Browse the repository at this point in the history
…a constant.
  • Loading branch information
dombesz committed Nov 14, 2024
1 parent df3f826 commit 6775f44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 2 additions & 8 deletions app/seeders/basic_data/life_cycle_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
#++
module BasicData
class LifeCycleSeeder < ModelSeeder
REQUIRED_COLOURS = %i[
default_color_orange_dark
default_color_red_dark
default_color_magenta_light
default_color_green_yellow
].freeze

self.model_class = LifeCycle
self.seed_data_model_key = "life_cycles"
self.needs = [
Expand Down Expand Up @@ -68,7 +61,8 @@ def color_seeder
def missing_colors
# Build map for color names and references for a reverse lookup
# ie: { "Orange (dark)" => :default_color_orange_dark, "Red (dark)"=>:default_color_red_dark }
required_color_map = REQUIRED_COLOURS.each_with_object({}) do |reference, colors|
required_colors = models_data.pluck("color_name")
required_color_map = required_colors.each_with_object({}) do |reference, colors|
color_name = color_seeder.mapped_models_data.dig(reference, :name) or
raise ArgumentError, "Could not find required color #{reference} in seed data definition."
colors[color_name] = reference
Expand Down
14 changes: 13 additions & 1 deletion spec/seeders/basic_data/life_cycle_seeder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
name: Initiating
type: Stage
color_name: :default_color_orange_dark
- reference: :default_life_cycle_ready_for_executing
name: Ready for Executing
type: Gate
color_name: :default_color_purple
- reference: :default_life_cycle_planning
name: Planning
type: Stage
Expand All @@ -62,10 +66,13 @@

shared_examples_for "creates the life_cycles seeds" do
it "creates the corresponding life cycles with the given attributes" do
expect(LifeCycle.count).to eq(4)
expect(LifeCycle.count).to eq(5)
expect(Stage.find_by(name: "Initiating")).to have_attributes(
color_id: Color.find_by(name: "Orange (dark)").id
)
expect(Gate.find_by(name: "Ready for Executing")).to have_attributes(
color_id: Color.find_by(name: "Purple").id
)
expect(Stage.find_by(name: "Planning")).to have_attributes(
color_id: Color.find_by(name: "Red (dark)").id
)
Expand Down Expand Up @@ -97,6 +104,8 @@
# using the first seed data as the expected value
expect(second_seed_data.find_reference(:default_life_cycle_initiating))
.to eq(seed_data.find_reference(:default_life_cycle_initiating))
expect(second_seed_data.find_reference(:default_life_cycle_ready_for_executing))
.to eq(seed_data.find_reference(:default_life_cycle_ready_for_executing))
expect(second_seed_data.find_reference(:default_life_cycle_planning))
.to eq(seed_data.find_reference(:default_life_cycle_planning))
expect(second_seed_data.find_reference(:default_life_cycle_executing))
Expand Down Expand Up @@ -128,6 +137,9 @@
- reference: :default_color_red_dark
name: Red (dark)
hexcode: "#F05823"
- reference: :default_color_purple
name: Purple
hexcode: "#682D91"
- reference: :default_color_magenta_light
name: Magenta (light)
hexcode: "#EC038A"
Expand Down

0 comments on commit 6775f44

Please sign in to comment.