Skip to content

Commit

Permalink
to fixup test nullify and can import csv
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand authored and E-L-T committed Dec 20, 2024
1 parent aec136e commit a00a156
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def morpheds
expect(type_de_champ.reload.referentiel).to eq Referentiel.last
expect(Referentiel.last.types_de_champ).to eq [type_de_champ]
expect(Referentiel.last.name).to eq referentiel_file.original_filename
expect(ReferentielItem.first.option).to eq({ 'dessert' => 'Éclair au café' })
expect(ReferentielItem.first.data).to eq({ "calorie (kcal)" => "145", "poids (g)" => "60" })
expect(ReferentielItem.first.data).to eq({ "dessert" => "Éclair au café", "poids_g" => "60", "calorie_kcal" => "145" })
expect(ReferentielItem.first.referentiel_id).to eq(Referentiel.last.id)
end
end
Expand All @@ -151,8 +150,7 @@ def morpheds

it 'creates a valid referentiel' do
expect { subject }.to change(Referentiel, :count).by(1).and change(ReferentielItem, :count).by(3)
expect(ReferentielItem.first.option).to eq({ 'dessert' => 'Éclair au café' })
expect(ReferentielItem.first.data).to eq({})
expect(ReferentielItem.first.data).to eq({ 'dessert' => 'Éclair au café' })
end
end

Expand Down Expand Up @@ -327,15 +325,15 @@ def morpheds
keys = csv_to_code.first.keys

csv_to_code.each do |row|
referentiel.items.create!(option: row.slice(keys.first), data: row.except(keys.first))
referentiel.items.create!(data: row)
end
end

subject { delete :nullify_referentiel, params: params, format: :turbo_stream }

context 'working case with multi column file' do
it 'nullifies referentiel' do
expect { subject }.not_to change(Referentiel, :count).and change(ReferentielItem, :count)
expect { subject }.to not_change(Referentiel, :count).and not_change(ReferentielItem, :count)
expect(type_de_champ.reload.referentiel).to be_nil
expect(Referentiel.count).to eq 1
expect(ReferentielItem.count).to eq 3
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
end
end
end

RSpec::Matchers.define_negated_matcher(:not_change, :change)
end

RSpec.configure do |config|
Expand Down

0 comments on commit a00a156

Please sign in to comment.