respect opting out

pull/1/head
Jared Cosulich 9 years ago
parent fa02cee295
commit f310d59568

@ -22,6 +22,7 @@ class RecipientSchedule < ApplicationRecord
end
def attempt_question(question: next_question)
return if recipient.opted_out?
attempt = recipient.attempts.create(
schedule: schedule,
recipient_schedule: self,

@ -2,7 +2,7 @@
.col
%p
%strong School:
= @school.name
= link_to @school.name, school_admin_path(@school)
%p
%strong Recipient:
= @recipient.name

@ -104,5 +104,30 @@ describe "survey:attempt_questions" do
end
end
end
describe 'Opted Out Recipient' do
before :each do
recipients[1].update_attributes(opted_out: true)
Timecop.freeze
subject.invoke
end
it 'should create the first attempt for each recipient' do
recipients.each_with_index do |recipient, index|
recipient.reload
if index == 1
expect(recipient.attempts.count).to eq(0)
expect(recipient.attempts.first).to be_nil
else
expect(recipient.attempts.count).to eq(1)
attempt = recipient.attempts.first
expect(attempt.sent_at).to be_present
expect(attempt.answer_index).to be_nil
end
end
end
end
end
end

@ -57,6 +57,20 @@ RSpec.describe RecipientSchedule, type: :model do
Timecop.freeze
end
describe 'with an opted out recipient' do
before :each do
recipient_schedule.recipient.update_attributes(opted_out: true)
end
let!(:attempt) { recipient_schedule.attempt_question }
it 'should not do anything' do
expect(attempt).to be_nil
end
end
describe 'with an opted in recipient' do
let!(:attempt) { recipient_schedule.attempt_question }
it 'should make an attempt to ask the next question' do
@ -85,4 +99,5 @@ RSpec.describe RecipientSchedule, type: :model do
expect(recipient_schedule.next_attempt_at.to_i).to eq((Time.new + (60 * 60 * schedule.frequency_hours)).to_i)
end
end
end
end

Loading…
Cancel
Save