Autoformat code with rubocop

pull/1/head
Nelson Jovel 4 years ago
parent 68dde8a6ef
commit ed7a3b8a3d

@ -1,6 +1,6 @@
class CategoriesController < SqmApplicationController
def show
@categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
@categories = Category.sorted.map { |category| CategoryPresenter.new(category:) }
@category = CategoryPresenter.new(category: Category.find_by_slug(params[:id]))
end

@ -3,6 +3,6 @@ class HomeController < ApplicationController
@districts = District.all.order(:name)
@schools = School.all.includes([:district]).order(:name)
@categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
@categories = Category.sorted.map { |category| CategoryPresenter.new(category:) }
end
end

@ -1,7 +1,7 @@
class OverviewController < SqmApplicationController
def index
@variance_chart_row_presenters = Measure.all.map(&method(:presenter_for_measure))
@category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
@category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category:) }
end
private
@ -9,6 +9,6 @@ class OverviewController < SqmApplicationController
def presenter_for_measure(measure)
score = measure.score(school: @school, academic_year: @academic_year)
VarianceChartRowPresenter.new(measure: measure, score: score)
VarianceChartRowPresenter.new(measure:, score:)
end
end

@ -39,7 +39,7 @@ module GaugeHelper
end
def arc_end_point_for(radius:, percentage:)
angle = angle_for(percentage: percentage)
angle = angle_for(percentage:)
x = arc_center.x + radius * Math.cos(angle)
y = arc_center.y + radius * Math.sin(angle)
@ -47,8 +47,8 @@ module GaugeHelper
end
def arc_end_line_destination(radius:, percentage:)
x = arc_center.x + radius * Math.cos(angle_for(percentage: percentage))
y = arc_center.y + radius * Math.sin(angle_for(percentage: percentage))
x = arc_center.x + radius * Math.cos(angle_for(percentage:))
y = arc_center.y + radius * Math.sin(angle_for(percentage:))
Point.new(x, y)
end
@ -62,8 +62,8 @@ module GaugeHelper
def draw_arc(radius:, percentage:, clockwise:)
sweep_flag = clockwise ? 1 : 0
"A #{arc_radius(radius)} 0 0 #{sweep_flag} #{coordinates_for(arc_end_point_for(radius: radius,
percentage: percentage))}"
"A #{arc_radius(radius)} 0 0 #{sweep_flag} #{coordinates_for(arc_end_point_for(radius:,
percentage:))}"
end
def draw_line_to(point:)

@ -26,7 +26,7 @@ module HeaderHelper
end
def link_weight(path:)
active?(path: path) ? 'weight-700' : 'weight-400'
active?(path:) ? 'weight-700' : 'weight-400'
end
private

@ -14,5 +14,4 @@ class AcademicYear < ActiveRecord::Base
years = range.split('-')
"#{years.first} 20#{years.second}"
end
end

@ -2,7 +2,7 @@ class Category < ActiveRecord::Base
include FriendlyId
friendly_id :name, use: [:slugged]
scope :sorted, -> { order(:sort_index)}
scope :sorted, -> { order(:sort_index) }
has_many :subcategories
has_many :measures, through: :subcategories

@ -58,9 +58,9 @@ module Legacy
def save_response(answer_index: nil, twilio_details: nil, responded_at: Time.new)
update(
answer_index: answer_index,
twilio_details: twilio_details,
responded_at: responded_at
answer_index:,
twilio_details:,
responded_at:
)
recipient_schedule.update(next_attempt_at: Time.new) if recipient_schedule.queued_question_ids.present?

@ -22,7 +22,7 @@ module Legacy
validates :option4, presence: true
validates :option5, presence: true
scope :for_category, ->(category) { where(category: category) }
scope :for_category, ->(category) { where(category:) }
scope :created_in, ->(year) { where("extract(year from #{table_name}.created_at) = ?", year) }
enum target_group: %i[unknown for_students for_teachers for_parents]

@ -9,7 +9,7 @@ module Legacy
after_initialize :set_question_id_array
def questions
question_id_array.collect { |id| Question.where(id: id).first }.compact
question_id_array.collect { |id| Question.where(id:).first }.compact
end
private

@ -12,7 +12,7 @@ module Legacy
validates :name, presence: true
scope :for_school, ->(school) { where(school: school) }
scope :for_school, ->(school) { where(school:) }
scope :created_in, ->(year) { where('extract(year from recipients.created_at) = ?', year) }
before_destroy :sync_lists

@ -14,7 +14,7 @@ module Legacy
after_save :sync_recipient_schedules
def recipients
recipient_id_array.collect { |id| school.recipients.where(id: id).first }
recipient_id_array.collect { |id| school.recipients.where(id:).first }
end
private

@ -51,7 +51,7 @@ module Legacy
return if recipient.opted_out?
return if question.nil?
return attempt_question(question: question) unless question.for_recipient_students?
return attempt_question(question:) unless question.for_recipient_students?
missing_students = []
recipient_attempts = attempts.for_recipient(recipient).for_question(question)
@ -60,9 +60,9 @@ module Legacy
end
attempt = recipient.attempts.create(
schedule: schedule,
schedule:,
recipient_schedule: self,
question: question,
question:,
student: missing_students.first
)
@ -101,12 +101,12 @@ module Legacy
return if question.nil? && unanswered_attempt.nil?
if unanswered_attempt.nil?
return attempt_question_for_recipient_students(question: question) if question.for_recipient_students?
return attempt_question_for_recipient_students(question:) if question.for_recipient_students?
attempt = recipient.attempts.create(
schedule: schedule,
schedule:,
recipient_schedule: self,
question: question
question:
)
end
@ -159,9 +159,9 @@ module Legacy
end
schedule.recipient_schedules.create(
recipient_id: recipient_id,
recipient_id:,
upcoming_question_ids: question_ids.join(','),
next_attempt_at: next_attempt_at
next_attempt_at:
)
end
end

@ -9,7 +9,7 @@ module Legacy
validates_associated :school_category
scope :for, ->(school, question) { where(school_id: school.id, question_id: question.id) }
scope :in, ->(year) { where(year: year) }
scope :in, ->(year) { where(year:) }
def sync_attempts
attempt_data = Attempt

@ -1,6 +1,6 @@
class AdminDataPresenter < DataItemPresenter
def initialize(measure_id:, admin_data_items:)
super(measure_id: measure_id, has_sufficient_data: false)
super(measure_id:, has_sufficient_data: false)
@admin_data_items = admin_data_items
end

@ -58,9 +58,9 @@ class CategoryPresenter
def subcategories(academic_year:, school:)
@category.subcategories.includes([:measures]).sort_by(&:subcategory_id).map do |subcategory|
SubcategoryPresenter.new(
subcategory: subcategory,
academic_year: academic_year,
school: school
subcategory:,
academic_year:,
school:
)
end
end

@ -31,9 +31,7 @@ class GaugePresenter
end
end
def score
@score
end
attr_reader :score
private

@ -1,6 +1,6 @@
class StudentSurveyPresenter < DataItemPresenter
def initialize(measure_id:, survey_items:, has_sufficient_data:)
super(measure_id: measure_id, has_sufficient_data: has_sufficient_data)
super(measure_id:, has_sufficient_data:)
@survey_items = survey_items
end

@ -37,6 +37,7 @@ class SubcategoryPresenter
def teacher_response_rate
return 'N / A' if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
"#{@subcategory.teacher_response_rate(school: @school, academic_year: @academic_year).rate}%"
end

@ -1,6 +1,6 @@
class TeacherSurveyPresenter < DataItemPresenter
def initialize(measure_id:, survey_items:, has_sufficient_data:)
super(measure_id: measure_id, has_sufficient_data: has_sufficient_data)
super(measure_id:, has_sufficient_data:)
@survey_items = survey_items
end

@ -11,7 +11,7 @@ class SurveyResponsesDataLoader
survey_items = SurveyItem.where(survey_item_id: survey_item_ids)
file.lazy.each_slice(1000) do |lines|
survey_item_responses = CSV.parse(lines.join, headers: headers).map do |row|
survey_item_responses = CSV.parse(lines.join, headers:).map do |row|
process_row row: row, survey_items: survey_items
end
@ -36,18 +36,18 @@ class SurveyResponsesDataLoader
return if school.nil?
survey_items.map do |survey_item|
next if SurveyItemResponse.where(response_id: response_id, survey_item: survey_item).exists?
next if SurveyItemResponse.where(response_id:, survey_item:).exists?
likert_score = row[survey_item.survey_item_id]
next if likert_score.nil?
next unless likert_score.valid_likert_score?
SurveyItemResponse.new(
response_id: response_id,
academic_year: academic_year,
school: school,
survey_item: survey_item,
likert_score: likert_score
response_id:,
academic_year:,
school:,
survey_item:,
likert_score:
)
end.compact
end

@ -4,7 +4,7 @@ Rails.application.configure do
Bullet.alert = false
Bullet.bullet_logger = true
Bullet.console = true
# Bullet.growl = true
# Bullet.growl = true
Bullet.rails_logger = true
Bullet.add_footer = true
end

@ -9,4 +9,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
Rails.application.config.assets.precompile += %w( application.css sqm.css welcome.css)
Rails.application.config.assets.precompile += %w[application.css sqm.css welcome.css]

@ -39,7 +39,7 @@ namespace :data do
task load_survey_responses: :environment do
Dir.glob(Rails.root.join('data', 'survey_responses', '*.csv')).each do |filepath|
puts "=====================> Loading data from csv at path: #{filepath}"
SurveyResponsesDataLoader.load_data filepath: filepath
SurveyResponsesDataLoader.load_data filepath:
end
puts "=====================> Completed loading #{SurveyItemResponse.count} survey responses"
end
@ -192,13 +192,13 @@ namespace :data do
category = nil
question['category'].split('-').each do |external_id|
categories = category.present? ? category.child_categories : Category
category = categories.where(external_id: external_id).first
category = categories.where(external_id:).first
next unless category.nil?
puts 'NOTHING'
puts external_id
puts categories.inspect
category = categories.create(name: question['Category Name'], external_id: external_id)
category = categories.create(name: question['Category Name'], external_id:)
end
question_text = question['text'].gsub(/[[:space:]]/, ' ').strip
if question_text.index('.* teacher').nil?
@ -245,7 +245,7 @@ namespace :data do
question['Category19'].split('-').each do |external_id_raw|
external_id = external_id_raw.gsub(/[[:space:]]/, ' ').strip
categories = category.present? ? category.child_categories : Category
category = categories.where(external_id: external_id).first
category = categories.where(external_id:).first
next unless category.nil?
puts 'NOTHING'
@ -253,7 +253,7 @@ namespace :data do
puts categories.map { |c|
"#{c.name} - |#{c.external_id}| == |#{external_id}|: - #{external_id == c.external_id}"
}.join(' ---- ')
category = categories.create(name: question['Category Name'], external_id: external_id)
category = categories.create(name: question['Category Name'], external_id:)
end
question_text = question['Question Text'].gsub(/[[:space:]]/, ' ').strip
if question_text.index('.* teacher').nil?
@ -402,7 +402,7 @@ namespace :data do
missing_questions[key] = true
next
elsif question.unknown?
question.update_attributes(target_group: target_group)
question.update_attributes(target_group:)
end
if value.to_i.blank?
@ -435,7 +435,7 @@ namespace :data do
Date.today
end
begin
recipient.attempts.create(question: question, answer_index: answer_index, responded_at: responded_at)
recipient.attempts.create(question:, answer_index:, responded_at:)
rescue Exception => e
puts "DATAERROR: INDEX: #{index} Attempt failed for #{recipient.inspect} -> QUESTION: #{question.inspect}, ANSWER_INDEX: #{answer_index}, RESPONDED_AT: #{responded_at}, ERROR: #{e}"
next
@ -481,7 +481,7 @@ namespace :data do
errors << row
next
elsif (benchmark = row['Benchmark']).present?
nonlikert_category.update(benchmark: benchmark)
nonlikert_category.update(benchmark:)
end
district = District.where(name: row['District'], state_id: 1).first
@ -614,9 +614,9 @@ namespace :data do
available_responders = school.available_responders_for(question)
school_question = school_category.school_questions.new(
school: school,
question: question,
school_category: school_category,
school:,
question:,
school_category:,
year: school_category.year,
attempt_count: available_responders,
response_count: attempt_data.response_count,
@ -638,7 +638,7 @@ namespace :data do
School.all.each do |school|
Category.all.each do |category|
school_category = SchoolCategory.for(school, category).in(@year).first
school_category = school.school_categories.create(category: category, year: @year) if school_category.nil?
school_category = school.school_categories.create(category:, year: @year) if school_category.nil?
school_category.sync_aggregated_responses
end
end

@ -16,38 +16,38 @@ module Legacy
end
let(:schedule) do
Schedule.create(name: 'Test Schedule', question_list: question_list, recipient_list: recipient_list)
Schedule.create(name: 'Test Schedule', question_list:, recipient_list:)
end
let(:school) { Legacy::School.create!(name: 'School') }
let(:recipient_schedule) do
RecipientSchedule.create(recipient: recipients.first, schedule: schedule, next_attempt_at: Time.now)
RecipientSchedule.create(recipient: recipients.first, schedule:, next_attempt_at: Time.now)
end
let(:recipient_schedule2) do
RecipientSchedule.create(recipient: recipients.last, schedule: schedule, next_attempt_at: Time.now)
RecipientSchedule.create(recipient: recipients.last, schedule:, next_attempt_at: Time.now)
end
let!(:first_attempt) do
Attempt.create(
schedule: schedule,
schedule:,
recipient: recipients.first,
recipient_schedule: recipient_schedule,
recipient_schedule:,
question: questions.first,
sent_at: Time.new
)
end
let!(:attempt) do
Attempt.create(
schedule: schedule,
schedule:,
recipient: recipients.first,
recipient_schedule: recipient_schedule,
recipient_schedule:,
question: questions.first,
sent_at: Time.new
)
end
let!(:attempt2) do
Attempt.create(
schedule: schedule,
schedule:,
recipient: recipients.last,
recipient_schedule: recipient_schedule2,
question: questions.first,

@ -45,7 +45,7 @@ module Legacy
let(:valid_session) { {} }
before :each do
user.user_schools.create(school: school)
user.user_schools.create(school:)
sign_in user
end

@ -42,7 +42,7 @@ module Legacy
let(:valid_session) { {} }
before :each do
user.user_schools.create(school: school)
user.user_schools.create(school:)
sign_in user
end

@ -57,7 +57,7 @@ module Legacy
let(:valid_session) { {} }
before :each do
user.user_schools.create(school: school)
user.user_schools.create(school:)
sign_in user
end

@ -21,15 +21,15 @@ require 'rails_helper'
module Legacy
RSpec.describe SchoolsController, type: :controller do
let(:district) { District.create! name: 'District' }
let!(:school) { School.create! name: 'school', district: district }
let!(:school) { School.create! name: 'school', district: }
let!(:user) { User.create(email: 'test@example.com', password: '123456') }
let!(:user_school) { user.user_schools.create(school: school) }
let!(:user_school) { user.user_schools.create(school:) }
# This should return the minimal set of attributes required to create a valid
# School. As you add validations to School, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
{ name: 'School', district: district }
{ name: 'School', district: }
end
let(:invalid_attributes) do

@ -17,7 +17,7 @@ module Legacy
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) }
let(:active_schedule) { double('active schedule', recipient_schedules:) }
it 'finds all active schedules' do
date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z'))
@ -64,7 +64,7 @@ module Legacy
Schedule.create!(
name: 'Parent Schedule',
recipient_list_id: recipient_list.id,
question_list: question_list,
question_list:,
frequency_hours: 24 * 7,
start_date: Time.new,
end_date: 1.year.from_now,

@ -16,13 +16,13 @@ module Legacy
end
let(:schedule) do
Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list)
Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list:)
end
let(:recipient_schedule) do
RecipientSchedule.create!(
recipient: recipient,
schedule: schedule,
recipient:,
schedule:,
upcoming_question_ids: "#{question.id},3",
attempted_question_ids: '2',
last_attempt_at: 2.weeks.ago,
@ -32,9 +32,9 @@ module Legacy
let!(:attempt) do
recipient.attempts.create(
schedule: schedule,
recipient_schedule: recipient_schedule,
question: question
schedule:,
recipient_schedule:,
question:
)
end

@ -31,7 +31,7 @@ module Legacy
Schedule.create!(
name: 'Parent Schedule',
recipient_list_id: recipient_list.id,
question_list: question_list,
question_list:,
random: false,
frequency_hours: 24 * 7
)

@ -19,7 +19,7 @@ module Legacy
Schedule.create!(
name: 'Parent Schedule',
recipient_list_id: recipient_list.id,
question_list: question_list,
question_list:,
random: false,
frequency_hours: 24
)
@ -28,8 +28,8 @@ module Legacy
let!(:not_ready_recipient_schedule) do
RecipientSchedule.create!(
recipient: recipient,
schedule: schedule,
recipient:,
schedule:,
upcoming_question_ids: '1,3',
attempted_question_ids: '2',
last_attempt_at: Date.today + (60 * 60 * schedule.frequency_hours),

@ -33,7 +33,7 @@ module Legacy
Schedule.create!(
name: 'Parent Schedule',
recipient_list_id: recipient_list.id,
question_list: question_list,
question_list:,
random: false,
frequency_hours: 24 * 7
)

@ -21,9 +21,9 @@ module Legacy
let(:default_schedule_params) do
{
school: school,
recipient_list: recipient_list,
question_list: question_list,
school:,
recipient_list:,
question_list:,
name: 'Parents Schedule',
description: 'Schedule for parent questions',
start_date: 1.month.ago,

@ -6,33 +6,33 @@ describe CategoryPresenter do
subcategory2 = Subcategory.create(name: 'Another subcategory', subcategory_id: '2')
category = Category.create(name: 'Some Category', subcategories: [subcategory1, subcategory2],
description: 'A description for some Category', short_description: 'A short description for some Category', category_id: '1')
return CategoryPresenter.new(category: category)
description: 'A description for some Category', short_description: 'A short description for some Category', category_id: '1')
return CategoryPresenter.new(category:)
end
let(:teachers_and_leadership_presenter) do
category = create(:category, name: 'Teachers & Leadership')
return CategoryPresenter.new(category: category)
return CategoryPresenter.new(category:)
end
let(:school_culture_presenter) do
category = create(:category, name: 'School Culture')
return CategoryPresenter.new(category: category)
return CategoryPresenter.new(category:)
end
let(:resources_presenter) do
category = create(:category, name: 'Resources')
return CategoryPresenter.new(category: category)
return CategoryPresenter.new(category:)
end
let(:academic_learning_presenter) do
category = create(:category, name: 'Academic Learning')
return CategoryPresenter.new(category: category)
return CategoryPresenter.new(category:)
end
let(:community_and_wellbeing_presenter) do
category = create(:category, name: 'Community & Wellbeing')
return CategoryPresenter.new(category: category)
return CategoryPresenter.new(category:)
end
after :each do

@ -11,7 +11,7 @@ describe GaugePresenter do
end
let(:score) { 3 }
let(:gauge_presenter) { GaugePresenter.new(zones: zones, score: score) }
let(:gauge_presenter) { GaugePresenter.new(zones:, score:) }
it 'returns the key benchmark percentage for the gauge' do
expect(gauge_presenter.key_benchmark_percentage).to eq 0.625

@ -10,7 +10,7 @@ describe SubcategoryCardPresenter do
)
end
let(:subcategory_card_presenter) { SubcategoryCardPresenter.new(name: 'Card name', zones: zones, score: score) }
let(:subcategory_card_presenter) { SubcategoryCardPresenter.new(name: 'Card name', zones:, score:) }
context 'when the given score is in the Warning zone for the given scale' do
let(:score) { 1 }

@ -68,11 +68,11 @@ describe SubcategoryPresenter do
end
it 'returns the student response rate' do
expect(subcategory_presenter.student_response_rate).to eq "25%"
expect(subcategory_presenter.student_response_rate).to eq '25%'
end
it 'returns the teacher response rate' do
expect(subcategory_presenter.teacher_response_rate).to eq "50%"
expect(subcategory_presenter.teacher_response_rate).to eq '50%'
end
it 'returns the admin collection rate' do

@ -1,14 +1,14 @@
require 'simplecov'
SimpleCov.start do
add_filter "/app/models/legacy"
add_filter "/app/views/legacy"
add_filter "/app/controllers/legacy"
add_filter "/spec/models/legacy"
add_filter "/spec/views/legacy"
add_filter "/spec/controllers/legacy"
add_filter "/app/helpers/schedules_helper.rb"
add_filter "/lib/tasks/survey.rake"
add_filter "/spec/lib/tasks/survey_rake_spec.rb"
add_filter '/app/models/legacy'
add_filter '/app/views/legacy'
add_filter '/app/controllers/legacy'
add_filter '/spec/models/legacy'
add_filter '/spec/views/legacy'
add_filter '/spec/controllers/legacy'
add_filter '/app/helpers/schedules_helper.rb'
add_filter '/lib/tasks/survey.rake'
add_filter '/spec/lib/tasks/survey_rake_spec.rb'
end
require 'capybara/rspec'
@ -184,7 +184,7 @@ def create_questions(count, category = nil)
option3: "Option #{i}:#{count} C",
option4: "Option #{i}:#{count} D",
option5: "Option #{i}:#{count} E",
category: category
category:
)
end
questions

@ -2,7 +2,7 @@ require 'rails_helper'
describe 'authentication' do
let(:district) { create(:district) }
let(:school) { create(:school, district: district) }
let(:school) { create(:school, district:) }
let(:academic_year) { create(:academic_year) }
context 'when using the wrong credentials' do

@ -2,11 +2,11 @@ require 'rails_helper'
describe 'SQM Application' do
let(:district) { create(:district) }
let(:school) { create(:school, district: district) }
let(:school) { create(:school, district:) }
let(:academic_year) { create(:academic_year) }
let(:category) { create(:category) }
let(:measure) { create(:measure) }
let(:scale) {create(:scale, measure:)}
let(:scale) { create(:scale, measure:) }
before :each do
driven_by :rack_test
@ -30,7 +30,7 @@ describe 'SQM Application' do
before :each do
teacher_survey_item = create(:teacher_survey_item, scale:)
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item, academic_year: academic_year, school: school)
survey_item: teacher_survey_item, academic_year:, school:)
end
it 'does not show a modal on any page' do

@ -6,7 +6,7 @@ module Legacy
@school = assign(:school, School.create!(name: 'School'))
recipients = ['Jared Cosulich', 'Lauren Cosulich'].collect do |name|
@school.recipients.create!(name: name)
@school.recipients.create!(name:)
end
@recipient_list = assign(:recipient_list, RecipientList.create!(

Loading…
Cancel
Save