Skip to content

Commit 3b61294

Browse files
authored
Merge pull request #563 from coopdevs/develop
v2.3.0
2 parents da19296 + 37f32a5 commit 3b61294

File tree

10 files changed

+79
-102
lines changed

10 files changed

+79
-102
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ group :development, :test do
5151
end
5252

5353
group :test do
54-
gem "rspec-rails", '~> 3.8.2'
54+
gem "rspec-rails", '~> 3.9'
5555
gem "database_cleaner", '1.6.2'
5656
gem 'shoulda-matchers', '~> 3.1.2'
5757
gem 'fabrication', '~> 2.20'

Gemfile.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,23 @@ GEM
288288
rexml (3.2.4)
289289
rollbar (2.8.3)
290290
multi_json
291-
rspec-core (3.8.0)
292-
rspec-support (~> 3.8.0)
293-
rspec-expectations (3.8.2)
291+
rspec-core (3.9.1)
292+
rspec-support (~> 3.9.1)
293+
rspec-expectations (3.9.0)
294294
diff-lcs (>= 1.2.0, < 2.0)
295-
rspec-support (~> 3.8.0)
296-
rspec-mocks (3.8.0)
295+
rspec-support (~> 3.9.0)
296+
rspec-mocks (3.9.1)
297297
diff-lcs (>= 1.2.0, < 2.0)
298-
rspec-support (~> 3.8.0)
299-
rspec-rails (3.8.2)
298+
rspec-support (~> 3.9.0)
299+
rspec-rails (3.9.0)
300300
actionpack (>= 3.0)
301301
activesupport (>= 3.0)
302302
railties (>= 3.0)
303-
rspec-core (~> 3.8.0)
304-
rspec-expectations (~> 3.8.0)
305-
rspec-mocks (~> 3.8.0)
306-
rspec-support (~> 3.8.0)
307-
rspec-support (3.8.0)
303+
rspec-core (~> 3.9.0)
304+
rspec-expectations (~> 3.9.0)
305+
rspec-mocks (~> 3.9.0)
306+
rspec-support (~> 3.9.0)
307+
rspec-support (3.9.2)
308308
rubocop (0.80.0)
309309
jaro_winkler (~> 1.5.1)
310310
parallel (~> 1.10)
@@ -433,7 +433,7 @@ DEPENDENCIES
433433
rails-i18n
434434
rdiscount
435435
rollbar (= 2.8.3)
436-
rspec-rails (~> 3.8.2)
436+
rspec-rails (~> 3.9)
437437
rubocop (~> 0.80.0)
438438
sass-rails (~> 5.0.7)
439439
select2-rails

app/jobs/organization_notifier_job.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Strategy: go throught all organizations and take latest active posts from last week
44
# posted by active members. Send an email to all active and online members
5-
# with the email notifications enabled with those posts.
5+
# with the email notifications enabled with those posts. Group emails by user's locale.
66

77
# Schedule defined in config/schedule.yml file.
88

@@ -12,9 +12,23 @@ class OrganizationNotifierJob < ActiveJob::Base
1212
def perform
1313
Organization.all.find_each do |org|
1414
posts = org.posts.active.of_active_members.from_last_week
15+
1516
if posts.present?
16-
OrganizationNotifier.recent_posts(posts).deliver_now
17+
users_by_locale(org).each do |locale, users|
18+
OrganizationNotifier.recent_posts(posts, locale, users).deliver_now
19+
end
1720
end
1821
end
1922
end
23+
24+
private
25+
26+
def users_by_locale(organization)
27+
with_notifications = organization.users.online_active.actives.notifications
28+
org_locales = with_notifications.pluck(:locale).uniq
29+
30+
org_locales.each_with_object({}) do |locale, hash|
31+
hash[locale] = with_notifications.where(locale: locale)
32+
end
33+
end
2034
end
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
class OrganizationNotifier < ActionMailer::Base
22
default from: "\"TimeOverflow\" <[email protected]>"
33

4-
# Subject can be set in your I18n file at config/locales/en.yml
5-
# with the following lookup:
6-
#
7-
# en.organization_notifier.recent_posts.subject
8-
#
9-
def recent_posts(posts)
4+
def recent_posts(posts, locale, users)
105
# last 10 posts of offers and inquiries
116
@offers = posts.where(type: "Offer").take(10)
127
@inquiries = posts.where(type: "Inquiry").take(10)
138

149
@organization_name = posts.take.organization.name
1510

16-
mail(bcc: emails_newsletter(posts))
17-
end
18-
19-
private
20-
21-
def emails_newsletter(posts)
22-
posts.take.organization.users.online_active.actives.
23-
notifications.pluck(:email)
11+
I18n.with_locale(locale) do
12+
mail(bcc: users.map(&:email))
13+
end
2414
end
2515
end

config/locales/en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ en:
347347
mailers_globals:
348348
footer:
349349
text: "%{organization_name} from"
350-
text_donation: The ADBdT association offers TimeOverflow for free to Time Banks. With a donation of %{href} you can help maintain and improve the platform.
351-
text_donation_link: 1€ a month
350+
text_donation: The ADBdT association offers TimeOverflow for free to Time Banks. If you want to help maintain and improve the platform %{href}.
351+
text_donation_link: visit this website
352352
offers:
353353
edit:
354354
submit: Change offer

spec/controllers/offers_controller_spec.rb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@
100100
get :show, id: offer.id
101101
expect(assigns(:destination_account)).to eq(member.account)
102102
end
103-
104-
it 'displays the offer\'s user details' do
105-
get :show, id: offer.id
106-
expect(response.body).to include(offer.user.email)
107-
end
108103
end
109104
end
110105
end
@@ -118,11 +113,6 @@
118113
allow(controller).to receive(:@current_organization).and_return(another_organization)
119114
end
120115

121-
it 'displays the offer\'s user details' do
122-
get :show, id: offer.id
123-
expect(response.body).to include(offer.user.email)
124-
end
125-
126116
it 'sets the offer\'s organization as user\'s current organization' do
127117
get :show, id: offer.id
128118
expect(session[:current_organization_id]).to eq(offer.organization_id)
@@ -136,23 +126,14 @@
136126
let(:another_user) { Fabricate(:user) }
137127

138128
before { login(another_user) }
139-
140-
it 'doesn\'t display the offer\'s user details' do
141-
get :show, id: offer.id
142-
expect(response.body).to_not include(offer.user.email)
143-
end
144129
end
145130

146131
context 'when the user is not logged in' do
147132
it 'assigns the requested offer to @offer' do
148133
get :show, id: offer.id
149134
expect(assigns(:offer)).to eq(offer)
150135
end
151-
152-
it 'doesn\'t display the offer\'s user details' do
153-
get :show, id: offer.id
154-
expect(response.body).to_not include(offer.user.email)
155-
end
136+
156137
end
157138
end
158139

spec/controllers/organizations_controller_spec.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
let(:member) { Fabricate(:member, organization: organization) }
66
let(:user) { member.user }
77

8-
describe 'GET #show' do
9-
it 'displays the organization page' do
10-
get 'show', id: organization.id
11-
12-
expect(assigns(:organization)).to eq(organization)
13-
expect(response.status).to eq(200)
14-
expect(response.body).to include(organization.name)
15-
end
16-
end
17-
188
describe 'GET #index' do
199
it 'populates and array of organizations' do
2010
get :index
@@ -23,6 +13,15 @@
2313
end
2414
end
2515

16+
describe 'GET #show' do
17+
it 'displays the organization page' do
18+
get 'show', id: organization.id
19+
20+
expect(assigns(:organization)).to eq(organization)
21+
expect(response.status).to eq(200)
22+
end
23+
end
24+
2625
describe 'POST #create' do
2726
it 'only superdamins are authorized create to new organizations' do
2827
login(member.user)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe OrganizationNotifierJob, type: :job do
4+
let!(:org) { Fabricate(:organization) }
5+
let!(:user) { Fabricate(:user, locale: :en, sign_in_count: 1) }
6+
let!(:member) { Fabricate(:member, organization: org, user: user) }
7+
let!(:user2) { Fabricate(:user, locale: :ca, sign_in_count: 2) }
8+
let!(:member2) { Fabricate(:member, organization: org, user: user2) }
9+
let!(:offer) { Fabricate(:offer, organization: org, user: user) }
10+
let!(:inquiry) { Fabricate(:inquiry, organization: org, user: user2) }
11+
12+
describe '#perform' do
13+
it "should send emails in user's locale" do
14+
expect {
15+
OrganizationNotifierJob.perform_now
16+
}.to change { ActionMailer::Base.deliveries.count }.by(2)
17+
end
18+
end
19+
end

spec/mailers/organization_notifier_spec.rb

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,30 @@
11
require "spec_helper"
22

33
RSpec.describe OrganizationNotifier do
4-
let (:test_organization) { Fabricate(:organization) }
5-
let! (:offer) { Fabricate(:offer, organization: test_organization) }
6-
let! (:inquiry) { Fabricate(:inquiry, organization: test_organization) }
7-
let (:user) do
8-
Fabricate(:user, sign_in_count: 2, email: "[email protected]")
9-
end
10-
let (:another_user) { Fabricate(:user, sign_in_count: 1) }
11-
let (:yet_another_user) { Fabricate(:user, sign_in_count: 0) }
12-
let! (:member) do
13-
Fabricate(:member,
14-
organization: test_organization,
15-
user: user,
16-
active: true)
17-
end
18-
let! (:another_member) do
19-
Fabricate(:member,
20-
organization: test_organization,
21-
user: another_user,
22-
active: false)
23-
end
24-
let! (:yet_another_member) do
25-
Fabricate(:member,
26-
organization: test_organization,
27-
user: yet_another_user,
28-
active: true)
29-
end
30-
31-
before(:each) do
32-
ActionMailer::Base.delivery_method = :test
33-
ActionMailer::Base.perform_deliveries = true
34-
ActionMailer::Base.deliveries = []
35-
OrganizationNotifier.recent_posts(test_organization.posts).deliver_now
36-
end
37-
38-
after(:each) do
39-
ActionMailer::Base.deliveries.clear
40-
end
4+
let(:test_organization) { Fabricate(:organization) }
5+
let!(:offer) { Fabricate(:offer, organization: test_organization) }
6+
let!(:inquiry) { Fabricate(:inquiry, organization: test_organization) }
7+
let(:user) { Fabricate(:user, email: "[email protected]", locale: :en) }
8+
let(:member) { Fabricate(:member, organization: test_organization, user: user) }
419

4210
describe "send an email" do
4311
it "should send an email" do
44-
expect(ActionMailer::Base.deliveries.count).to eq(1)
12+
expect {
13+
OrganizationNotifier.recent_posts(test_organization.posts, :en, [user]).deliver_now
14+
}.to change { ActionMailer::Base.deliveries.count }.by(1)
4515
end
4616
end
4717

4818
describe "recent posts" do
49-
let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts) }
19+
let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts, :en, [user]) }
5020

5121
it "receive email only active and online users" do
5222
expect(mail.bcc).to eql(["[email protected]"])
5323
end
5424
it "to should be null" do
5525
expect(mail.to).to be_nil
5626
end
57-
it "assigns @organization_name" do
27+
it "body contains organization name" do
5828
expect(mail.body.encoded).to match(test_organization.name)
5929
end
6030
end

spec/views/organizations/show.html.erb_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,9 @@
5757
it 'diplays the movements section' do
5858
expect(rendered).to match t('shared.movements.movements')
5959
end
60+
61+
it 'displays the organization page' do
62+
expect(rendered).to match(organization.name)
63+
end
6064
end
6165
end

0 commit comments

Comments
 (0)