Add Segment for users without supports on Budget
Created not_supported_on_current_budget at UserSegment along with model spec scenario and translation strings.
This commit is contained in:
@@ -524,6 +524,7 @@ en:
|
|||||||
feasible_and_undecided_investment_authors: "Authors of some investment in the current budget that does not comply with: [valuation finished unfesasible]"
|
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
|
selected_investment_authors: Authors of selected investments in the current budget
|
||||||
winner_investment_authors: Authors of winner investments in the current budget
|
winner_investment_authors: Authors of winner investments in the current budget
|
||||||
|
not_supported_on_current_budget: Users that haven't supported investments on current budget
|
||||||
invalid_recipients_segment: "Recipients user segment is invalid"
|
invalid_recipients_segment: "Recipients user segment is invalid"
|
||||||
newsletters:
|
newsletters:
|
||||||
create_success: Newsletter created successfully
|
create_success: Newsletter created successfully
|
||||||
|
|||||||
@@ -523,6 +523,7 @@ es:
|
|||||||
feasible_and_undecided_investment_authors: "Usuarios autores de algún proyecto de gasto en los actuales presupuestos que no cumpla: [evaluación finalizada inviable]"
|
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
|
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
|
winner_investment_authors: Usuarios autores de proyectos de gasto ganadoras en los actuales presupuestos
|
||||||
|
not_supported_on_current_budget: Usuarios que no han apoyado proyectos de los actuales presupuestos
|
||||||
invalid_recipients_segment: "El segmento de destinatarios es inválido"
|
invalid_recipients_segment: "El segmento de destinatarios es inválido"
|
||||||
newsletters:
|
newsletters:
|
||||||
create_success: Newsletter creada correctamente
|
create_success: Newsletter creada correctamente
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ class UserSegments
|
|||||||
investment_authors
|
investment_authors
|
||||||
feasible_and_undecided_investment_authors
|
feasible_and_undecided_investment_authors
|
||||||
selected_investment_authors
|
selected_investment_authors
|
||||||
winner_investment_authors)
|
winner_investment_authors
|
||||||
|
not_supported_on_current_budget)
|
||||||
|
|
||||||
def self.all_users
|
def self.all_users
|
||||||
User.active
|
User.active
|
||||||
@@ -37,6 +38,17 @@ class UserSegments
|
|||||||
author_ids(current_budget_investments.winners.pluck(:author_id).uniq)
|
author_ids(current_budget_investments.winners.pluck(:author_id).uniq)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.not_supported_on_current_budget
|
||||||
|
author_ids(
|
||||||
|
User.where(
|
||||||
|
'id NOT IN (SELECT DISTINCT(voter_id) FROM votes'\
|
||||||
|
' WHERE votable_type = ? AND votes.votable_id IN (?))',
|
||||||
|
'Budget::Investment',
|
||||||
|
current_budget_investments.pluck(:id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def self.user_segment_emails(users_segment)
|
def self.user_segment_emails(users_segment)
|
||||||
UserSegments.send(users_segment).newsletter.pluck(:email).compact
|
UserSegments.send(users_segment).newsletter.pluck(:email).compact
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -172,4 +172,22 @@ describe UserSegments do
|
|||||||
expect(current_budget_investments).not_to include investment2
|
expect(current_budget_investments).not_to include investment2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#not_supported_on_current_budget" do
|
||||||
|
it "only returns users that haven't supported investments on current budget" do
|
||||||
|
investment1 = create(:budget_investment)
|
||||||
|
investment2 = create(:budget_investment)
|
||||||
|
budget = create(:budget)
|
||||||
|
investment1.vote_by(voter: user1, vote: 'yes')
|
||||||
|
investment2.vote_by(voter: user2, vote: 'yes')
|
||||||
|
investment1.update(budget: budget)
|
||||||
|
investment2.update(budget: budget)
|
||||||
|
|
||||||
|
not_supported_on_current_budget = described_class.not_supported_on_current_budget
|
||||||
|
expect(not_supported_on_current_budget).to include user3
|
||||||
|
expect(not_supported_on_current_budget).not_to include user1
|
||||||
|
expect(not_supported_on_current_budget).not_to include user2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user