diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index b9ab97891..fb2e65873 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -27,7 +27,7 @@ class Budget delegate :budget, :budget_id, to: :group, allow_nil: true scope :i18n, -> { includes(:translations) } - scope :with_group, -> { joins(group: :translations).where("budget_group_translations.locale = ?", I18n.locale) } + scope :with_group, -> { includes(group: :translations) } scope :order_by_group_name, -> { i18n.with_group.order("budget_group_translations.name DESC") } scope :order_by_heading_name, -> { i18n.with_group.order("budget_heading_translations.name") } scope :order_by_name, -> { i18n.with_group.order_by_group_name.order_by_heading_name } diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index ca90a1c40..893772d58 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -60,6 +60,25 @@ feature 'Budgets' do end end + scenario "Show groups and headings for missing translations" do + group1 = create(:budget_group, budget: last_budget) + group2 = create(:budget_group, budget: last_budget) + + heading1 = create(:budget_heading, group: group1) + heading2 = create(:budget_heading, group: group2) + + visit budgets_path locale: :es + + within("#budget_info") do + expect(page).to have_content group1.name + expect(page).to have_content group2.name + expect(page).to have_content heading1.name + expect(page).to have_content last_budget.formatted_heading_price(heading1) + expect(page).to have_content heading2.name + expect(page).to have_content last_budget.formatted_heading_price(heading2) + end + end + scenario "Show informing index without links" do budget.update_attributes(phase: "informing") group = create(:budget_group, budget: budget) diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb index bf76720d6..94447c07e 100644 --- a/spec/models/budget/heading_spec.rb +++ b/spec/models/budget/heading_spec.rb @@ -281,9 +281,9 @@ describe Budget::Heading do end describe "scope order_by_group_name" do - it "only sort headings using the group name (DESC) in the current locale" do - last_group = create(:budget_group, name_en: "CCC", name_es: "BBB") - first_group = create(:budget_group, name_en: "DDD", name_es: "AAA") + it "sorts headings using the group name (DESC) in any locale" do + last_group = create(:budget_group, name_en: "CCC", name_es: "AAA") + first_group = create(:budget_group, name_en: "DDD", name_es: "BBB") last_heading = create(:budget_heading, group: last_group, name: "Name") first_heading = create(:budget_heading, group: first_group, name: "Name")