Commit b928a9bd authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'reminder-emails-member-scope' into 'master'

Add member scope for use in worker

See merge request gitlab-org/gitlab!42841
parents ce014e75 9013fbc0
...@@ -78,7 +78,10 @@ class Member < ApplicationRecord ...@@ -78,7 +78,10 @@ class Member < ApplicationRecord
scope :request, -> { where.not(requested_at: nil) } scope :request, -> { where.not(requested_at: nil) }
scope :non_request, -> { where(requested_at: nil) } scope :non_request, -> { where(requested_at: nil) }
scope :not_accepted_invitations_by_user, -> (user) { invite.where(invite_accepted_at: nil, created_by: user) } scope :not_accepted_invitations, -> { invite.where(invite_accepted_at: nil) }
scope :not_accepted_invitations_by_user, -> (user) { not_accepted_invitations.where(created_by: user) }
scope :not_expired, -> (today = Date.current) { where(arel_table[:expires_at].gt(today).or(arel_table[:expires_at].eq(nil))) }
scope :last_ten_days_excluding_today, -> (today = Date.current) { where(created_at: (today - 10).beginning_of_day..(today - 1).end_of_day) }
scope :has_access, -> { active.where('access_level > 0') } scope :has_access, -> { active.where('access_level > 0') }
......
...@@ -205,6 +205,16 @@ RSpec.describe Member do ...@@ -205,6 +205,16 @@ RSpec.describe Member do
it { expect(described_class.non_request).to include @accepted_request_member } it { expect(described_class.non_request).to include @accepted_request_member }
end end
describe '.not_accepted_invitations' do
let_it_be(:not_accepted_invitation) { create(:project_member, :invited) }
let_it_be(:accepted_invitation) { create(:project_member, :invited, invite_accepted_at: Date.today) }
subject { described_class.not_accepted_invitations }
it { is_expected.to include(not_accepted_invitation) }
it { is_expected.not_to include(accepted_invitation) }
end
describe '.not_accepted_invitations_by_user' do describe '.not_accepted_invitations_by_user' do
let(:invited_by_user) { create(:project_member, :invited, project: project, created_by: @owner_user) } let(:invited_by_user) { create(:project_member, :invited, project: project, created_by: @owner_user) }
...@@ -218,6 +228,29 @@ RSpec.describe Member do ...@@ -218,6 +228,29 @@ RSpec.describe Member do
it { is_expected.to contain_exactly(invited_by_user) } it { is_expected.to contain_exactly(invited_by_user) }
end end
describe '.not_expired' do
let_it_be(:expiring_yesterday) { create(:group_member, expires_at: 1.day.ago) }
let_it_be(:expiring_today) { create(:group_member, expires_at: Date.today) }
let_it_be(:expiring_tomorrow) { create(:group_member, expires_at: 1.day.from_now) }
let_it_be(:not_expiring) { create(:group_member) }
subject { described_class.not_expired }
it { is_expected.not_to include(expiring_yesterday, expiring_today) }
it { is_expected.to include(expiring_tomorrow, not_expiring) }
end
describe '.last_ten_days_excluding_today' do
let_it_be(:created_today) { create(:group_member, created_at: Date.today.beginning_of_day) }
let_it_be(:created_yesterday) { create(:group_member, created_at: 1.day.ago) }
let_it_be(:created_eleven_days_ago) { create(:group_member, created_at: 11.days.ago) }
subject { described_class.last_ten_days_excluding_today }
it { is_expected.to include(created_yesterday) }
it { is_expected.not_to include(created_today, created_eleven_days_ago) }
end
describe '.search_invite_email' do describe '.search_invite_email' do
it 'returns only members the matching e-mail' do it 'returns only members the matching e-mail' do
create(:group_member, :invited) create(:group_member, :invited)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment