diff --git a/app/models/recipient_schedule.rb b/app/models/recipient_schedule.rb index a307f709..ffff5d24 100644 --- a/app/models/recipient_schedule.rb +++ b/app/models/recipient_schedule.rb @@ -11,7 +11,7 @@ class RecipientSchedule < ApplicationRecord Question.where(id: upcoming.first).first end - def make_attempt(question: next_question) + def attempt_question(question: next_question) attempt = recipient.attempts.create( schedule: schedule, recipient_schedule: self, diff --git a/lib/tasks/survey.rake b/lib/tasks/survey.rake index 83faa3e6..b2d2fd97 100644 --- a/lib/tasks/survey.rake +++ b/lib/tasks/survey.rake @@ -1,10 +1,10 @@ namespace :survey do desc 'Text all Recipients ready for an Attempt' - task :make_attempts => :environment do + task :attempt_qustions => :environment do Schedule.active.each do |schedule| schedule.recipient_schedules.ready.each do |recipient_schedule| - # recipient_schedule. + recipient_schedule.attempt_question end end end diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 2c009ce5..cf1c49e9 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' -describe "survey:make_attempts" do +describe "survey:attempt_qustions" do include_context "rake" - let(:ready_recipient_schedules) { double('ready recipient schedules') } - let(:recipient_schedules) { double("recipient schedules", ready: []) } + let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) } + let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) } let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) } before do @@ -18,7 +18,8 @@ describe "survey:make_attempts" do end it "finds all active schedules" do - expect(active_schedule).to (receive(:recipient_schedules)) + expect(ready_recipient_schedule).to receive(:attempt_question) + expect(active_schedule).to receive(:recipient_schedules) expect(Schedule).to receive(:active).and_return([active_schedule]) subject.invoke end diff --git a/spec/models/recipient_schedule_spec.rb b/spec/models/recipient_schedule_spec.rb index 5c3e2c91..766f0f26 100644 --- a/spec/models/recipient_schedule_spec.rb +++ b/spec/models/recipient_schedule_spec.rb @@ -54,12 +54,12 @@ RSpec.describe RecipientSchedule, type: :model do end end - describe 'make_attempt' do + describe 'attempt_question' do before :each do Timecop.freeze end - let!(:attempt) { recipient_schedule.make_attempt } + let!(:attempt) { recipient_schedule.attempt_question } it 'should make an attempt to ask the next question' do expect(attempt).to be_persisted