<%= f.label :selected do %>
diff --git a/app/views/budgets/results/_results_table.html.erb b/app/views/budgets/results/_results_table.html.erb
index 993060562..f391e8d50 100644
--- a/app/views/budgets/results/_results_table.html.erb
+++ b/app/views/budgets/results/_results_table.html.erb
@@ -1,4 +1,6 @@
-
+
<%= title %>
@@ -28,7 +30,9 @@
<% amount_available = heading_price %>
<% investments.each do |investment| %>
-
+
|
<% if investment.winner? %>
diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb
index 2343e652c..eb31124ec 100644
--- a/app/views/budgets/results/show.html.erb
+++ b/app/views/budgets/results/show.html.erb
@@ -26,7 +26,8 @@
<% @budget.headings.each do |heading| %>
-
+ <% active_class = heading.id.to_s == params[:heading_id] ? 'bold' : '' %>
+
<%= link_to heading.name,
budget_results_path(@budget, heading_id: heading.id) %>
@@ -34,7 +35,7 @@
- <%= link_to t("budgets.results.hide_discarded_link"), "#", class: "js-toggle-link button hollow margin-bottom", data: {'toggle-selector' => '.js-discarded', 'toggle-text' => t("budgets.results.show_all_link")} %>
+ <%= link_to t("budgets.results.show_all_link"), "#", class: "js-toggle-link button hollow margin-bottom", data: {'toggle-selector' => '.js-discarded', 'toggle-text' => t("budgets.results.hide_discarded_link")} %>
<%= render 'results_table', results_type: :compatible,
@@ -42,8 +43,10 @@
heading_price: @heading.price,
investments: @investments.compatible %>
- <%= render 'results_table', results_type: :incompatible,
- title: t("budgets.results.incompatibles"),
- heading_price: @heading.price,
- investments: @investments.incompatible %>
+ <% if @investments.incompatible.present? %>
+ <%= render 'results_table', results_type: :incompatible,
+ title: t("budgets.results.incompatibles"),
+ heading_price: @heading.price,
+ investments: @investments.incompatible %>
+ <% end %>
diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb
index 57dedcb54..925f105b0 100644
--- a/spec/features/admin/budget_investments_spec.rb
+++ b/spec/features/admin/budget_investments_spec.rb
@@ -312,7 +312,7 @@ feature 'Admin budget investments' do
context "Edit" do
scenario "Change title, incompatible, description or heading" do
- budget_investment = create(:budget_investment, :selected)
+ budget_investment = create(:budget_investment, :incompatible)
create(:budget_heading, group: budget_investment.group, name: "Barbate")
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
@@ -321,7 +321,7 @@ feature 'Admin budget investments' do
fill_in 'budget_investment_title', with: 'Potatoes'
fill_in 'budget_investment_description', with: 'Carrots'
select "#{budget_investment.group.name}: Barbate", from: 'budget_investment[heading_id]'
- check "budget_investment_incompatible"
+ uncheck "budget_investment_incompatible"
check "budget_investment_selected"
click_button 'Update'
@@ -329,10 +329,21 @@ feature 'Admin budget investments' do
expect(page).to have_content 'Potatoes'
expect(page).to have_content 'Carrots'
expect(page).to have_content 'Barbate'
- expect(page).to have_content 'Incompatible'
+ expect(page).to have_content 'Compatibility: Compatible'
expect(page).to have_content 'Selected'
end
+ scenario "Compatible non-winner can't edit incompatibility" do
+ budget_investment = create(:budget_investment, :selected)
+ create(:budget_heading, group: budget_investment.group, name: "Tetuan")
+
+ visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
+ click_link 'Edit'
+
+ expect(page).not_to have_content 'Compatibility'
+ expect(page).not_to have_content 'Mark as incompatible'
+ end
+
scenario "Add administrator" do
budget_investment = create(:budget_investment)
administrator = create(:administrator, user: create(:user, username: 'Marta', email: 'marta@admins.org'))
diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb
index cd9cb0912..3b2d05c65 100644
--- a/spec/features/budgets/results_spec.rb
+++ b/spec/features/budgets/results_spec.rb
@@ -17,6 +17,21 @@ feature 'Results' do
visit budget_path(budget)
click_link "See results"
+ within("#budget-investments-compatible") do
+ expect(page).to have_content investment1.title
+ expect(page).to have_content investment2.title
+ expect(page).not_to have_content investment3.title
+ expect(page).not_to have_content investment4.title
+
+ expect(investment1.title).to appear_before(investment2.title)
+ end
+ end
+
+ scenario "Show non winner & incomaptible investments", :js do
+ visit budget_path(budget)
+ click_link "See results"
+ click_link "Show all"
+
within("#budget-investments-compatible") do
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
@@ -31,21 +46,6 @@ feature 'Results' do
end
end
- scenario "Displays non winner investments", :js do
- visit budget_path(budget)
- click_link "See results"
- click_link "Hide discarded"
-
- within("#budget-investments-compatible") do
- expect(page).to have_content investment1.title
- expect(page).to have_content investment2.title
- expect(page).not_to have_content investment3.title
- expect(page).not_to have_content investment4.title
-
- expect(investment1.title).to appear_before(investment2.title)
- end
- end
-
scenario "If budget is in a phase different from finished results can't be accessed" do
budget.update phase: (Budget::PHASES - ["finished"]).sample
visit budget_path(budget)
@@ -55,4 +55,14 @@ feature 'Results' do
expect(page).to have_content "You do not have permission to carry out the action"
end
+ scenario "No incompatible investments", :js do
+ investment3.incompatible = false
+ investment3.save
+
+ visit budget_path(budget)
+ click_link "See results"
+
+ expect(page).not_to have_content "Incompatibles"
+ end
+
end
diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb
index 85eb14f3e..a650e25c5 100644
--- a/spec/models/budget/result_spec.rb
+++ b/spec/models/budget/result_spec.rb
@@ -15,7 +15,7 @@ describe Budget::Result do
investment4 = create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600, winner: false)
investment5 = create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500, winner: false)
- Budget::Result.new(budget, heading).calculate_winners
+ described_class.new(budget, heading).calculate_winners
expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id])
end
@@ -29,7 +29,7 @@ describe Budget::Result do
investment4 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600)
investment5 = create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500)
- Budget::Result.new(budget, heading).calculate_winners
+ described_class.new(budget, heading).calculate_winners
expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id])
end
@@ -49,6 +49,20 @@ describe Budget::Result do
expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment4.id])
end
end
- end
+ context "When an incompatible is flagged as compatible again" do
+ it "recalculates winners taking it in consideration" do
+ investment1 = create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 900)
+ investment2 = create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800)
+ investment3 = create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700)
+ investment4 = create(:budget_investment, :winner, heading: heading, price: 500, ballot_lines_count: 600)
+ investment5 = create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500)
+
+ investment3.incompatible = false
+ investment3.save
+
+ expect(heading.investments.winners.pluck(:id)).to match_array([investment1.id, investment2.id, investment3.id])
+ end
+ end
+ end
end
|