Skip to content

Commit

Permalink
Send community digest only to active students (pupilfirst#501)
Browse files Browse the repository at this point in the history
This also contains a fix for an unrelated spec that could randomly fail.
  • Loading branch information
harigopal authored Oct 9, 2020
1 parent 6d29795 commit 42fedcc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/services/daily_digest_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute
cache_new_and_popular_topics
cache_older_topics_with_recent_activity

students = User.joins(founders: :communities).merge(Founder.not_dropped_out).distinct.select(:id)
students = User.joins(founders: :communities).merge(Founder.active).distinct.select(:id)
coaches = User.joins(:faculty).select(:id)

User.where(id: coaches).or(User.where(id: students))
Expand Down
14 changes: 14 additions & 0 deletions spec/services/daily_digest_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@
expect(body_2).to include(topic_c2_reactivated_4.title)
end

context 'when there is a student whose access has ended' do
let(:team_access_ended) { create :team, access_ends_at: 1.day.ago }
let(:student_access_ended) { create :founder, startup: team_access_ended }
let!(:user_access_ended) { student_access_ended.user }
let(:community_1) { create :community, school: school, courses: [team_access_ended.course] }
let(:community_2) { create :community, school: school, courses: [team_access_ended.course] }

it 'does not send digest to student whose access has ended' do
subject.execute
open_email(user_access_ended.email)
expect(current_email).to eq(nil)
end
end

context 'when there is a dropped out student' do
let(:team_dropped_out) { create :team, dropped_out_at: 1.day.ago }
let(:student_dropped_out) { create :founder, startup: team_dropped_out }
Expand Down
4 changes: 4 additions & 0 deletions spec/system/community/community_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@
end

scenario 'user searches for topics in community' do
# Let's set the titles for both topics to completely different sentences to avoid confusing the fuzzy search algo.
topic_1.update!(title: 'Hello World')
topic_2.update!(title: 'Completely Different Sentence')

sign_in_user(coach.user, referrer: community_path(community))

expect(page).to have_text(topic_2.title)
Expand Down

0 comments on commit 42fedcc

Please sign in to comment.