-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from coopdevs/develop
v2.3.0
- Loading branch information
Showing
10 changed files
with
79 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
class OrganizationNotifier < ActionMailer::Base | ||
default from: "\"TimeOverflow\" <[email protected]>" | ||
|
||
# Subject can be set in your I18n file at config/locales/en.yml | ||
# with the following lookup: | ||
# | ||
# en.organization_notifier.recent_posts.subject | ||
# | ||
def recent_posts(posts) | ||
def recent_posts(posts, locale, users) | ||
# last 10 posts of offers and inquiries | ||
@offers = posts.where(type: "Offer").take(10) | ||
@inquiries = posts.where(type: "Inquiry").take(10) | ||
|
||
@organization_name = posts.take.organization.name | ||
|
||
mail(bcc: emails_newsletter(posts)) | ||
end | ||
|
||
private | ||
|
||
def emails_newsletter(posts) | ||
posts.take.organization.users.online_active.actives. | ||
notifications.pluck(:email) | ||
I18n.with_locale(locale) do | ||
mail(bcc: users.map(&:email)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe OrganizationNotifierJob, type: :job do | ||
let!(:org) { Fabricate(:organization) } | ||
let!(:user) { Fabricate(:user, locale: :en, sign_in_count: 1) } | ||
let!(:member) { Fabricate(:member, organization: org, user: user) } | ||
let!(:user2) { Fabricate(:user, locale: :ca, sign_in_count: 2) } | ||
let!(:member2) { Fabricate(:member, organization: org, user: user2) } | ||
let!(:offer) { Fabricate(:offer, organization: org, user: user) } | ||
let!(:inquiry) { Fabricate(:inquiry, organization: org, user: user2) } | ||
|
||
describe '#perform' do | ||
it "should send emails in user's locale" do | ||
expect { | ||
OrganizationNotifierJob.perform_now | ||
}.to change { ActionMailer::Base.deliveries.count }.by(2) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,30 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe OrganizationNotifier do | ||
let (:test_organization) { Fabricate(:organization) } | ||
let! (:offer) { Fabricate(:offer, organization: test_organization) } | ||
let! (:inquiry) { Fabricate(:inquiry, organization: test_organization) } | ||
let (:user) do | ||
Fabricate(:user, sign_in_count: 2, email: "[email protected]") | ||
end | ||
let (:another_user) { Fabricate(:user, sign_in_count: 1) } | ||
let (:yet_another_user) { Fabricate(:user, sign_in_count: 0) } | ||
let! (:member) do | ||
Fabricate(:member, | ||
organization: test_organization, | ||
user: user, | ||
active: true) | ||
end | ||
let! (:another_member) do | ||
Fabricate(:member, | ||
organization: test_organization, | ||
user: another_user, | ||
active: false) | ||
end | ||
let! (:yet_another_member) do | ||
Fabricate(:member, | ||
organization: test_organization, | ||
user: yet_another_user, | ||
active: true) | ||
end | ||
|
||
before(:each) do | ||
ActionMailer::Base.delivery_method = :test | ||
ActionMailer::Base.perform_deliveries = true | ||
ActionMailer::Base.deliveries = [] | ||
OrganizationNotifier.recent_posts(test_organization.posts).deliver_now | ||
end | ||
|
||
after(:each) do | ||
ActionMailer::Base.deliveries.clear | ||
end | ||
let(:test_organization) { Fabricate(:organization) } | ||
let!(:offer) { Fabricate(:offer, organization: test_organization) } | ||
let!(:inquiry) { Fabricate(:inquiry, organization: test_organization) } | ||
let(:user) { Fabricate(:user, email: "[email protected]", locale: :en) } | ||
let(:member) { Fabricate(:member, organization: test_organization, user: user) } | ||
|
||
describe "send an email" do | ||
it "should send an email" do | ||
expect(ActionMailer::Base.deliveries.count).to eq(1) | ||
expect { | ||
OrganizationNotifier.recent_posts(test_organization.posts, :en, [user]).deliver_now | ||
}.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
end | ||
end | ||
|
||
describe "recent posts" do | ||
let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts) } | ||
let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts, :en, [user]) } | ||
|
||
it "receive email only active and online users" do | ||
expect(mail.bcc).to eql(["[email protected]"]) | ||
end | ||
it "to should be null" do | ||
expect(mail.to).to be_nil | ||
end | ||
it "assigns @organization_name" do | ||
it "body contains organization name" do | ||
expect(mail.body.encoded).to match(test_organization.name) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters