Extract method to get a user segment name

We're going to add geozones as user segments, so it's handy to have the
method in the UserSegments class.

We're also changing the `user_segment_emails` parameter name for
consistency and simplicity.
This commit is contained in:
Javi Martín
2021-11-10 20:35:46 +01:00
parent a0416d4d85
commit 78e543f6d3
7 changed files with 36 additions and 18 deletions

View File

@@ -5,6 +5,22 @@ describe UserSegments do
let(:user2) { create(:user) }
let(:user3) { create(:user) }
describe ".segment_name" do
it "returns a readable name of the segment" do
expect(UserSegments.segment_name("all_users")).to eq "All users"
expect(UserSegments.segment_name("administrators")).to eq "Administrators"
expect(UserSegments.segment_name("proposal_authors")).to eq "Proposal authors"
end
it "accepts symbols as parameters" do
expect(UserSegments.segment_name(:all_users)).to eq "All users"
end
it "returns nil for invalid segments" do
expect(UserSegments.segment_name("invalid")).to be nil
end
end
describe ".all_users" do
it "returns all active users enabled" do
active_user = create(:user)