Skip to content

Commit

Permalink
Fix spec by setting ColorSeeder.attribute_names_for_lookups to allow …
Browse files Browse the repository at this point in the history
…existing colors to be looked up
  • Loading branch information
dombesz committed Nov 8, 2024
1 parent 6db31d1 commit 0871469
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/seeders/basic_data/color_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module BasicData
class ColorSeeder < ModelSeeder
self.model_class = Color
self.seed_data_model_key = "colors"
self.attribute_names_for_lookups = %i[name]

def model_attributes(color_data)
{
Expand Down
5 changes: 4 additions & 1 deletion app/seeders/source/seed_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def find_reference(reference, *fallbacks, default: :__unset__)
default
else
references = [reference, *fallbacks].map(&:inspect)
message = "Nothing registered with #{'reference'.pluralize(references.count)} #{references.to_sentence(locale: false)}"
message = <<~STRING
Nothing registered with #{'reference'.pluralize(references.count)} #{references.to_sentence(locale: false)}
Perhaps you forgot to add the `attribute_names_for_lookups` for your seeder?
STRING
raise ArgumentError, message
end
end
Expand Down
1 change: 1 addition & 0 deletions modules/bim/app/seeders/bim/basic_data_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def data_seeder_classes
::BasicData::TimeEntryActivitySeeder,
::BasicData::ColorSeeder,
::BasicData::ColorSchemeSeeder,
::BasicData::LifeCycleSeeder,
::BasicData::WorkflowSeeder,
::BasicData::PrioritySeeder,
::Bim::BasicData::SettingSeeder,
Expand Down
2 changes: 2 additions & 0 deletions spec/seeders/root_seeder_standard_edition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
expect(VersionSetting.count).to eq 4
expect(Boards::Grid.count).to eq 5
expect(Boards::Grid.count { |grid| grid.options.has_key?(:filters) }).to eq 1
expect(LifeCycle.count).to eq 4
end

it "links work packages to their version" do
Expand Down Expand Up @@ -171,6 +172,7 @@
expect(Version.count).to eq 4
expect(VersionSetting.count).to eq 4
expect(Boards::Grid.count).to eq 5
expect(LifeCycle.count).to eq 4
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/seeders/source/seed_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@

it "raises an error if the reference is not found" do
expect { seed_data.find_reference(:ref) }
.to raise_error(ArgumentError, "Nothing registered with reference :ref")
.to raise_error(ArgumentError, /Nothing registered with reference :ref/)
expect { seed_data.find_reference(:ref, :other_ref) }
.to raise_error(ArgumentError, "Nothing registered with references :ref and :other_ref")
.to raise_error(ArgumentError, /Nothing registered with references :ref and :other_ref/)
expect { seed_data.find_reference(:ref, :other_ref, :yet_another_ref) }
.to raise_error(ArgumentError, "Nothing registered with references :ref, :other_ref, and :yet_another_ref")
.to raise_error(ArgumentError, /Nothing registered with references :ref, :other_ref, and :yet_another_ref/)
end

it "returns the given default value if the reference is not found" do
Expand Down

0 comments on commit 0871469

Please sign in to comment.