Merge pull request #2491 from consul/2487-feasible_undecided_investment_authors_segment

Fix UserSegment feasible and undecided investment authors
This commit is contained in:
Alberto Calderón Queimadelos
2018-02-28 18:01:54 +01:00
committed by GitHub
4 changed files with 30 additions and 15 deletions

View File

@@ -521,8 +521,8 @@ en:
administrators: Administrators
proposal_authors: Proposal authors
investment_authors: Investment authors in the current budget
feasible_and_undecided_investment_authors: Authors of feasible or undecided investments in the current budget
selected_investment_authors: Authors of investments selected for the final vote in the current budget
feasible_and_undecided_investment_authors: "Authors of some investment in the current budget that does not comply with: [valuation finished unfesasible]"
selected_investment_authors: Authors of selected investments in the current budget
winner_investment_authors: Authors of winner investments in the current budget
invalid_recipients_segment: "Recipients user segment is invalid"
newsletters:

View File

@@ -519,10 +519,10 @@ es:
all_users: Todos los usuarios
administrators: Administradores
proposal_authors: Usuarios autores de propuestas
investment_authors: Autores de proyectos de gasto en los actuales presupuestos
feasible_and_undecided_investment_authors: Autores de proyectos de gasto viables o sin decidir en los actuales presupuestos
selected_investment_authors: Autores de proyectos de gasto seleccionados para la votación final en los actuales presupuestos
winner_investment_authors: Autores de proyectos de gasto ganadoras en los actuales presupuestos
investment_authors: Usuarios autores de proyectos de gasto en los actuales presupuestos
feasible_and_undecided_investment_authors: "Usuarios autores de algún proyecto de gasto en los actuales presupuestos que no cumpla: [evaluación finalizada inviable]"
selected_investment_authors: Usuarios autores de proyectos de gasto seleccionadas en los actuales presupuestos
winner_investment_authors: Usuarios autores de proyectos de gasto ganadoras en los actuales presupuestos
invalid_recipients_segment: "El segmento de destinatarios es inválido"
newsletters:
create_success: Newsletter creada correctamente

View File

@@ -24,8 +24,9 @@ class UserSegments
end
def self.feasible_and_undecided_investment_authors
feasibility = %w(feasible undecided)
author_ids(current_budget_investments.where(feasibility: feasibility).pluck(:author_id).uniq)
unfeasible_and_finished_condition = "feasibility = 'unfeasible' and valuation_finished = true"
investments = current_budget_investments.where.not(unfeasible_and_finished_condition)
author_ids(investments.pluck(:author_id).uniq)
end
def self.selected_investment_authors

View File

@@ -70,18 +70,32 @@ describe UserSegments do
describe "#feasible_and_undecided_investment_authors" do
it "returns authors of a feasible or an undecided budget investment" do
feasible_investment = create(:budget_investment, :feasible, author: user1)
undecided_investment = create(:budget_investment, :undecided, author: user2)
unfeasible_investment = create(:budget_investment, :unfeasible, author: user3)
user4 = create(:user)
user5 = create(:user)
user6 = create(:user)
feasible_investment_finished = create(:budget_investment, :feasible, :finished, author: user1)
undecided_investment_finished = create(:budget_investment, :undecided, :finished, author: user2)
feasible_investment_unfinished = create(:budget_investment, :feasible, author: user3)
undecided_investment_unfinished = create(:budget_investment, :undecided, author: user4)
unfeasible_investment_unfinished = create(:budget_investment, :unfeasible, author: user5)
unfeasible_investment_finished = create(:budget_investment, :unfeasible, :finished, author: user6)
budget = create(:budget)
feasible_investment.update(budget: budget)
undecided_investment.update(budget: budget)
unfeasible_investment.update(budget: budget)
feasible_investment_finished.update(budget: budget)
undecided_investment_finished.update(budget: budget)
feasible_investment_unfinished.update(budget: budget)
undecided_investment_unfinished.update(budget: budget)
unfeasible_investment_unfinished.update(budget: budget)
unfeasible_investment_finished.update(budget: budget)
investment_authors = described_class.feasible_and_undecided_investment_authors
expect(investment_authors).to include user1
expect(investment_authors).to include user2
expect(investment_authors).not_to include user3
expect(investment_authors).to include user3
expect(investment_authors).to include user4
expect(investment_authors).to include user5
expect(investment_authors).not_to include user6
end
it "does not return duplicated users" do