Merge branch 'master' into budget

This commit is contained in:
Juanjo Bazán
2016-09-02 12:47:54 +02:00
44 changed files with 684 additions and 126 deletions

View File

@@ -201,8 +201,9 @@ feature 'Emails' do
notification2 = create_proposal_notification(proposal2)
notification3 = create_proposal_notification(proposal3)
email_digest = EmailDigest.new
email_digest.create
email_digest = EmailDigest.new(user)
email_digest.deliver
email_digest.mark_as_emailed
email = open_last_email
expect(email).to have_subject("Proposal notifications in Consul")
@@ -227,6 +228,11 @@ feature 'Emails' do
expect(email).to_not have_body_text(proposal3.title)
expect(email).to have_body_text(/#{account_path}/)
notification1.reload
notification2.reload
expect(notification1.emailed_at).to be
expect(notification2.emailed_at).to be
end
end

View File

@@ -180,9 +180,10 @@ feature "Notifications" do
find(".icon-notification").click
notification_for_user1 = Notification.where(user: user1).first
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "There is one new notification on #{proposal.title}"
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
expect(page).to have_xpath "//a[@href='#{notification_path(notification_for_user1)}']"
logout
login_as user2
@@ -190,9 +191,10 @@ feature "Notifications" do
find(".icon-notification").click
notification_for_user2 = Notification.where(user: user2).first
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "There is one new notification on #{proposal.title}"
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.first)}']"
expect(page).to have_xpath "//a[@href='#{notification_path(notification_for_user2)}']"
logout
login_as user3

View File

@@ -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...")

View File

@@ -2,8 +2,126 @@ require 'rails_helper'
describe EmailDigest do
describe "create" do
pending "only send unread notifications"
describe "notifications" do
it "returns notifications for a user" do
user1 = create(:user)
user2 = create(:user)
proposal_notification = create(:proposal_notification)
notification1 = create(:notification, notifiable: proposal_notification, user: user1)
notification2 = create(:notification, notifiable: proposal_notification, user: user2)
email_digest = EmailDigest.new(user1)
expect(email_digest.notifications).to include(notification1)
expect(email_digest.notifications).to_not include(notification2)
end
it "returns only proposal notifications" do
user = create(:user)
proposal_notification = create(:proposal_notification)
comment = create(:comment)
notification1 = create(:notification, notifiable: proposal_notification, user: user)
notification2 = create(:notification, notifiable: comment, user: user)
email_digest = EmailDigest.new(user)
expect(email_digest.notifications).to include(notification1)
expect(email_digest.notifications).to_not include(notification2)
end
end
describe "pending_notifications?" do
it "returns true when notifications have not been emailed" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user)
email_digest = EmailDigest.new(user)
expect(email_digest.pending_notifications?).to be
end
it "returns false when notifications have been emailed" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.now)
email_digest = EmailDigest.new(user)
expect(email_digest.pending_notifications?).to_not be
end
it "returns false when there are no notifications for a user" do
user = create(:user)
email_digest = EmailDigest.new(user)
expect(email_digest.pending_notifications?).to_not be
end
end
describe "deliver" do
it "delivers email if notifications pending" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user)
reset_mailer
email_digest = EmailDigest.new(user)
email_digest.deliver
email = open_last_email
expect(email).to have_subject("Proposal notifications in Consul")
end
it "does not deliver email if no notifications pending" do
user = create(:user)
proposal_notification = create(:proposal_notification)
notification = create(:notification, notifiable: proposal_notification, user: user, emailed_at: Time.now)
reset_mailer
email_digest = EmailDigest.new(user)
email_digest.deliver
expect(all_emails.count).to eq(0)
end
end
describe "mark_as_emailed" do
it "marks notifications as emailed" do
user1 = create(:user)
user2 = create(:user)
proposal_notification = create(:proposal_notification)
notification1 = create(:notification, notifiable: proposal_notification, user: user1)
notification2 = create(:notification, notifiable: proposal_notification, user: user1)
notification3 = create(:notification, notifiable: proposal_notification, user: user2)
expect(notification1.emailed_at).to_not be
expect(notification2.emailed_at).to_not be
expect(notification3.emailed_at).to_not be
email_digest = EmailDigest.new(user1)
email_digest.mark_as_emailed
notification1.reload
notification2.reload
notification3.reload
expect(notification1.emailed_at).to be
expect(notification2.emailed_at).to be
expect(notification3.emailed_at).to_not be
end
end
end

0
spec/models/custom/.keep Normal file
View File

View File

@@ -0,0 +1,34 @@
require 'rails_helper'
describe Verification::Residence do
let(:residence) { build(:verification_residence, document_number: "12345678Z") }
describe "verification" do
describe "postal code" do
it "should be valid with postal codes starting with 280" do
residence.postal_code = "28012"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(0)
residence.postal_code = "28023"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(0)
end
it "should not be valid with postal codes not starting with 280" do
residence.postal_code = "12345"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(1)
residence.postal_code = "13280"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(1)
expect(residence.errors[:postal_code]).to include("In order to be verified, you must be registered.")
end
end
end
end

View File

@@ -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

View File

@@ -30,29 +30,6 @@ describe Verification::Residence do
expect(residence.errors[:date_of_birth]).to include("You must be at least 16 years old")
end
describe "postal code" do
it "should be valid with postal codes starting with 280" do
residence.postal_code = "28012"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(0)
residence.postal_code = "28023"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(0)
end
it "should not be valid with postal codes not starting with 280" do
residence.postal_code = "12345"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(1)
residence.postal_code = "13280"
residence.valid?
expect(residence.errors[:postal_code].size).to eq(1)
expect(residence.errors[:postal_code]).to include("In order to be verified, you must be registered.")
end
end
it "should validate uniquness of document_number" do
user = create(:user)
residence.user = user

View File

@@ -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")