Skip to content

Commit 0b6d37c

Browse files
committed
Now this is it, fixing remaining trash code
1 parent 58e5dfc commit 0b6d37c

4 files changed

Lines changed: 36 additions & 17 deletions

File tree

app/presenters/socle_de_base_presenter.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ def candidate_description
1818
end
1919

2020
def buyer_category_label
21-
I18n.t("form_fields.buyer.categories.#{category_key}", default: category_key.humanize)
21+
subcategory&.category&.buyer_label || category_key.humanize
2222
end
2323

2424
def buyer_subcategory_label
25-
I18n.t("form_fields.buyer.subcategories.#{subcategory_key}", default: subcategory_key.humanize)
25+
subcategory&.buyer_label || subcategory_key.humanize
2626
end
2727

2828
def candidate_category_label
29-
I18n.t("form_fields.candidate.categories.#{category_key}", default: category_key.humanize)
29+
subcategory&.category&.candidate_label || category_key.humanize
3030
end
3131

3232
def candidate_subcategory_label
33-
I18n.t("form_fields.candidate.subcategories.#{subcategory_key}", default: subcategory_key.humanize)
33+
subcategory&.candidate_label || subcategory_key.humanize
3434
end
3535

3636
def mandatory_badge
@@ -67,5 +67,5 @@ def market_type_badges
6767
end
6868
end
6969

70-
delegate :key, :category_key, :subcategory_key, :mandatory?, :from_api?, :api_name, to: :@market_attribute
70+
delegate :key, :category_key, :subcategory_key, :subcategory, :mandatory?, :from_api?, :api_name, to: :@market_attribute
7171
end

db/queue_schema.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@
116116
create_table "market_attributes", force: :cascade do |t|
117117
t.string "api_key"
118118
t.string "api_name"
119-
t.text "buyer_description"
120-
t.string "buyer_name"
121-
t.text "candidate_description"
122-
t.string "candidate_name"
123119
t.string "category_key", null: false
124120
t.datetime "created_at", null: false
125121
t.datetime "deleted_at"

db/schema.rb

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/presenters/socle_de_base_presenter_spec.rb

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
require 'rails_helper'
44

55
RSpec.describe SocleDeBasePresenter do
6+
let(:category) do
7+
create(:category, key: 'identite_entreprise',
8+
buyer_label: "Identité de l'entreprise",
9+
candidate_label: 'Les informations du marché et de votre entreprise')
10+
end
11+
let(:subcategory) do
12+
create(:subcategory, category:, key: 'identite_entreprise_identification',
13+
buyer_label: "Identification de l'entreprise",
14+
candidate_label: 'Informations de votre entreprise')
15+
end
616
let(:market_attribute) do
717
build(:market_attribute,
818
key: 'identite_entreprise_identification_siret',
919
category_key: 'identite_entreprise',
1020
subcategory_key: 'identite_entreprise_identification',
21+
subcategory:,
1122
mandatory: true,
1223
api_name: 'Insee')
1324
end
@@ -55,25 +66,41 @@
5566
end
5667

5768
describe '#buyer_category_label' do
58-
it 'returns the buyer category label from i18n' do
69+
it 'returns the buyer label from the category record' do
5970
expect(presenter.buyer_category_label).to eq("Identité de l'entreprise")
6071
end
72+
73+
context 'when subcategory is nil' do
74+
let(:market_attribute) { build(:market_attribute, subcategory: nil, category_key: 'identite_entreprise') }
75+
76+
it 'falls back to humanized category_key' do
77+
expect(presenter.buyer_category_label).to eq('Identite entreprise')
78+
end
79+
end
6180
end
6281

6382
describe '#buyer_subcategory_label' do
64-
it 'returns the buyer subcategory label from i18n' do
83+
it 'returns the buyer label from the subcategory record' do
6584
expect(presenter.buyer_subcategory_label).to eq("Identification de l'entreprise")
6685
end
86+
87+
context 'when subcategory is nil' do
88+
let(:market_attribute) { build(:market_attribute, subcategory: nil, subcategory_key: 'some_key') }
89+
90+
it 'falls back to humanized subcategory_key' do
91+
expect(presenter.buyer_subcategory_label).to eq('Some key')
92+
end
93+
end
6794
end
6895

6996
describe '#candidate_category_label' do
70-
it 'returns the candidate category label from i18n' do
97+
it 'returns the candidate label from the category record' do
7198
expect(presenter.candidate_category_label).to eq('Les informations du marché et de votre entreprise')
7299
end
73100
end
74101

75102
describe '#candidate_subcategory_label' do
76-
it 'returns the candidate subcategory label from i18n' do
103+
it 'returns the candidate label from the subcategory record' do
77104
expect(presenter.candidate_subcategory_label).to eq('Informations de votre entreprise')
78105
end
79106
end

0 commit comments

Comments
 (0)