diff --git a/app/models/recipient_list.rb b/app/models/recipient_list.rb index 87ea2331..98a0a2df 100644 --- a/app/models/recipient_list.rb +++ b/app/models/recipient_list.rb @@ -4,7 +4,6 @@ class RecipientList < ApplicationRecord validates_associated :school validates :name, presence: true - validates :recipient_ids, presence: true attr_accessor :recipient_id_array before_validation :convert_recipient_id_array @@ -24,8 +23,8 @@ class RecipientList < ApplicationRecord end def set_recipient_id_array - return if recipient_ids.blank? - self.recipient_id_array = recipient_ids.split(',').map(&:to_i) + return if recipient_id_array.present? + self.recipient_id_array = (recipient_ids || '').split(',').map(&:to_i) end def sync_recipient_schedules diff --git a/app/views/recipient_lists/show.html.haml b/app/views/recipient_lists/show.html.haml index efbd416b..0a387918 100644 --- a/app/views/recipient_lists/show.html.haml +++ b/app/views/recipient_lists/show.html.haml @@ -10,7 +10,7 @@ %p %b Recipients: - @recipient_list.recipients.each do |recipient| - %p= recipient.name + %p= link_to recipient.name, [@school, recipient] = link_to 'Edit', edit_school_recipient_list_path(@recipient_list.school, @recipient_list) | diff --git a/db/migrate/20170225150432_create_recipients.rb b/db/migrate/20170225150432_create_recipients.rb index b749e24c..f4fa2207 100644 --- a/db/migrate/20170225150432_create_recipients.rb +++ b/db/migrate/20170225150432_create_recipients.rb @@ -9,7 +9,7 @@ class CreateRecipients < ActiveRecord::Migration[5.0] t.string :ethnicity t.integer :home_language_id t.string :income - t.boolean :opted_out + t.boolean :opted_out, default: false t.integer :school_id t.timestamps diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 07ad6954..35350811 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -159,11 +159,6 @@ namespace :data do next end - recipient_list = school.recipient_lists.find_by_name("#{recipients.titleize} List") - if recipient_list.nil? - school.recipient_lists.create(name: "#{recipients.titleize} List") - end - respondent_id = row['RespondentID'] recipient_id = respondent_map[respondent_id] if recipient_id.present? @@ -174,6 +169,11 @@ namespace :data do ) respondent_map[respondent_id] = recipient.id end + + recipient_list = school.recipient_lists.find_by_name("#{recipients.titleize} List") + if recipient_list.nil? + recipient_list = school.recipient_lists.create(name: "#{recipients.titleize} List") + end recipient_list.recipient_id_array << recipient.id recipient_list.save! diff --git a/spec/controllers/recipient_lists_controller_spec.rb b/spec/controllers/recipient_lists_controller_spec.rb index b3ccd509..9178053a 100644 --- a/spec/controllers/recipient_lists_controller_spec.rb +++ b/spec/controllers/recipient_lists_controller_spec.rb @@ -35,7 +35,7 @@ RSpec.describe RecipientListsController, type: :controller do } let(:invalid_attributes) { - {school_id: school.id, name: 'Empty List', recipient_id_array: ['']} + {school_id: school.id, name: ''} } # This should return the minimal set of values that should be in the session