Skip to content

Commit

Permalink
fix: ignore virtual data in column initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Sep 9, 2024
1 parent ab3139c commit 4289aa2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/components/instructeurs/column_picker_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(procedure:, procedure_presentation:)
def displayable_columns_for_select
[
procedure.columns.filter(&:displayable).map { |column| [column.label, column.id] },
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys).id }
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys.except(:virtual)).id } # TODO: remove virtual after migration

Check warning on line 15 in app/components/instructeurs/column_picker_component.rb

View check run for this annotation

Codecov / codecov/patch

app/components/instructeurs/column_picker_component.rb#L15

Added line #L15 was not covered by tests
]
end
end
2 changes: 1 addition & 1 deletion app/models/procedure_presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProcedurePresentation < ApplicationRecord
def displayed_fields_for_headers
[
Column.new(table: 'self', column: 'id', classname: 'number-col'),
*displayed_fields.map { Column.new(**_1.deep_symbolize_keys) },
*displayed_fields.map { Column.new(**_1.deep_symbolize_keys.except(:virtual)) }, # TODO: remove virtual after migration

Check warning on line 32 in app/models/procedure_presentation.rb

View check run for this annotation

Codecov / codecov/patch

app/models/procedure_presentation.rb#L32

Added line #L32 was not covered by tests
Column.new(table: 'self', column: 'state', classname: 'state-col'),
*procedure.sva_svr_columns
]
Expand Down
3 changes: 3 additions & 0 deletions spec/components/instructeurs/column_picker_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
subject { component.displayable_columns_for_select }

before do
procedure_presentation.displayed_fields.first['virtual'] = true
procedure_presentation.save

allow(procedure).to receive(:columns).and_return([
default_user_email,
excluded_displayable_field
Expand Down
8 changes: 6 additions & 2 deletions spec/models/procedure_presentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
assign_to: assign_to,
displayed_fields: [
{ label: "test1", table: "user", column: "email" },
{ label: "test2", table: "type_de_champ", column: first_type_de_champ_id }
{ label: "test2", table: "type_de_champ", column: first_type_de_champ_id, virtual: false }
],
sort: { table: "user", column: "email", "order" => "asc" },
filters: filters)
Expand All @@ -23,7 +23,11 @@
let(:filters) { { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] } }

describe "#displayed_fields" do
it { expect(procedure_presentation.displayed_fields).to eq([{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id }]) }
it { expect(procedure_presentation.displayed_fields).to eq([{ "label" => "test1", "table" => "user", "column" => "email" }, { "label" => "test2", "table" => "type_de_champ", "column" => first_type_de_champ_id, "virtual" => false }]) }
end

describe "#displayed_fields_for_headers" do
it { expect(procedure_presentation.displayed_fields_for_headers.map(&:label)).to eq(["Nº dossier", "test1", "test2", "Statut"]) }
end

describe "#sort" do
Expand Down

0 comments on commit 4289aa2

Please sign in to comment.