Use correct scope to sort headings by name
This commit is contained in:
@@ -60,9 +60,19 @@ feature 'Budgets' do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Show headings ordered by name" do
|
||||
group = create(:budget_group, budget: budget)
|
||||
last_heading = create(:budget_heading, group: group, name: "BBB")
|
||||
first_heading = create(:budget_heading, group: group, name: "AAA")
|
||||
|
||||
visit budgets_path
|
||||
|
||||
expect(first_heading.name).to appear_before(last_heading.name)
|
||||
end
|
||||
|
||||
scenario "Show groups and headings for missing translations" do
|
||||
group1 = create(:budget_group, budget: last_budget)
|
||||
group2 = create(:budget_group, budget: last_budget)
|
||||
group1 = create(:budget_group, budget: budget)
|
||||
group2 = create(:budget_group, budget: budget)
|
||||
|
||||
heading1 = create(:budget_heading, group: group1)
|
||||
heading2 = create(:budget_heading, group: group2)
|
||||
@@ -73,9 +83,9 @@ feature 'Budgets' 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 budget.formatted_heading_price(heading1)
|
||||
expect(page).to have_content heading2.name
|
||||
expect(page).to have_content last_budget.formatted_heading_price(heading2)
|
||||
expect(page).to have_content budget.formatted_heading_price(heading2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
19
spec/features/budgets/groups_spec.rb
Normal file
19
spec/features/budgets/groups_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require "rails_helper"
|
||||
|
||||
feature "Budget Groups" do
|
||||
|
||||
let(:budget) { create(:budget) }
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
|
||||
context "Show" do
|
||||
scenario "Headings are sorted by name" do
|
||||
last_heading = create(:budget_heading, group: group, name: "BBB")
|
||||
first_heading = create(:budget_heading, group: group, name: "AAA")
|
||||
|
||||
visit budget_group_path(budget, group)
|
||||
|
||||
expect(first_heading.name).to appear_before(last_heading.name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -280,21 +280,8 @@ describe Budget::Heading do
|
||||
end
|
||||
end
|
||||
|
||||
describe "scope order_by_group_name" do
|
||||
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")
|
||||
describe ".sort_by_name" do
|
||||
|
||||
last_heading = create(:budget_heading, group: last_group, name: "Name")
|
||||
first_heading = create(:budget_heading, group: first_group, name: "Name")
|
||||
|
||||
expect(Budget::Heading.order_by_group_name.count).to be 2
|
||||
expect(Budget::Heading.order_by_group_name.first).to eq first_heading
|
||||
expect(Budget::Heading.order_by_group_name.last).to eq last_heading
|
||||
end
|
||||
end
|
||||
|
||||
describe "scope order_by_name" do
|
||||
it "returns headings sorted by DESC group name first and then ASC heading name" do
|
||||
last_group = create(:budget_group, name: "Group A")
|
||||
first_group = create(:budget_group, name: "Group B")
|
||||
@@ -305,8 +292,21 @@ describe Budget::Heading do
|
||||
heading1 = create(:budget_heading, group: first_group, name: "Name C")
|
||||
|
||||
sorted_headings = [heading1, heading2, heading3, heading4]
|
||||
expect(Budget::Heading.order_by_name.to_a).to eq sorted_headings
|
||||
expect(Budget::Heading.sort_by_name).to eq sorted_headings
|
||||
end
|
||||
|
||||
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")
|
||||
|
||||
last_heading = create(:budget_heading, group: last_group, name: "Name")
|
||||
first_heading = create(:budget_heading, group: first_group, name: "Name")
|
||||
|
||||
expect(Budget::Heading.sort_by_name.size).to be 2
|
||||
expect(Budget::Heading.sort_by_name.first).to eq first_heading
|
||||
expect(Budget::Heading.sort_by_name.last).to eq last_heading
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "scope allow_custom_content" do
|
||||
|
||||
Reference in New Issue
Block a user