does not create notifications for blocked or erased users
This commit is contained in:
@@ -99,7 +99,7 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def voters
|
||||
votes_for.voters
|
||||
User.active.where(id: votes_for.voters)
|
||||
end
|
||||
|
||||
def editable?
|
||||
|
||||
@@ -53,6 +53,7 @@ class User < ActiveRecord::Base
|
||||
scope :for_render, -> { includes(:organization) }
|
||||
scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) }
|
||||
scope :email_digest, -> { where(email_digest: true) }
|
||||
scope :active, -> { where(erased_at: nil) }
|
||||
|
||||
before_validation :clean_document_number
|
||||
|
||||
|
||||
@@ -24,6 +24,44 @@ feature 'Proposal Notifications' do
|
||||
expect(page).to have_content "Please share it with others so we can make it happen!"
|
||||
end
|
||||
|
||||
scenario "Send a notification (Active voter)" do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
voter = create(:user, :level_two)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(1)
|
||||
end
|
||||
|
||||
scenario "Send a notification (Blocked voter)" do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
voter = create(:user, :level_two)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
voter.block
|
||||
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(0)
|
||||
end
|
||||
|
||||
scenario "Send a notification (Erased voter)" do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
voter = create(:user, :level_two)
|
||||
create(:vote, voter: voter, votable: proposal)
|
||||
voter.erase
|
||||
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(0)
|
||||
end
|
||||
|
||||
scenario "Show notifications" do
|
||||
proposal = create(:proposal)
|
||||
notification1 = create(:proposal_notification, proposal: proposal, title: "Hey guys", body: "Just wanted to let you know that...")
|
||||
|
||||
@@ -367,6 +367,50 @@ describe Proposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "voters" do
|
||||
|
||||
it "returns users that have voted for the proposal" do
|
||||
proposal = create(:proposal)
|
||||
voter1 = create(:user, :level_two)
|
||||
voter2 = create(:user, :level_two)
|
||||
voter3 = create(:user, :level_two)
|
||||
|
||||
create(:vote, voter: voter1, votable: proposal)
|
||||
create(:vote, voter: voter2, votable: proposal)
|
||||
|
||||
expect(proposal.voters).to include(voter1)
|
||||
expect(proposal.voters).to include(voter2)
|
||||
expect(proposal.voters).to_not include(voter3)
|
||||
end
|
||||
|
||||
it "does not return users that have been erased" do
|
||||
proposal = create(:proposal)
|
||||
voter1 = create(:user, :level_two)
|
||||
voter2 = create(:user, :level_two)
|
||||
|
||||
create(:vote, voter: voter1, votable: proposal)
|
||||
create(:vote, voter: voter2, votable: proposal)
|
||||
voter2.erase
|
||||
|
||||
expect(proposal.voters).to include(voter1)
|
||||
expect(proposal.voters).to_not include(voter2)
|
||||
end
|
||||
|
||||
it "does not return users that have been blocked" do
|
||||
proposal = create(:proposal)
|
||||
voter1 = create(:user, :level_two)
|
||||
voter2 = create(:user, :level_two)
|
||||
|
||||
create(:vote, voter: voter1, votable: proposal)
|
||||
create(:vote, voter: voter2, votable: proposal)
|
||||
voter2.block
|
||||
|
||||
expect(proposal.voters).to include(voter1)
|
||||
expect(proposal.voters).to_not include(voter2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "search" do
|
||||
|
||||
context "attributes" do
|
||||
|
||||
@@ -325,6 +325,34 @@ describe User do
|
||||
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
|
||||
describe "active" do
|
||||
|
||||
it "returns users that have not been erased" do
|
||||
user1 = create(:user, erased_at: nil)
|
||||
user2 = create(:user, erased_at: nil)
|
||||
user3 = create(:user, erased_at: Time.now)
|
||||
|
||||
expect(User.active).to include(user1)
|
||||
expect(User.active).to include(user2)
|
||||
expect(User.active).to_not include(user3)
|
||||
end
|
||||
|
||||
it "returns users that have not been blocked" do
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
user3 = create(:user)
|
||||
user3.block
|
||||
|
||||
expect(User.active).to include(user1)
|
||||
expect(User.active).to include(user2)
|
||||
expect(User.active).to_not include(user3)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe "self.search" do
|
||||
it "find users by email" do
|
||||
user1 = create(:user, email: "larry@consul.dev")
|
||||
|
||||
Reference in New Issue
Block a user