From d54b99135e0ea32a1b0927238cec3991901adcd5 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 8 Sep 2016 11:52:34 -0500 Subject: [PATCH] rubocop noise: introduced and resolved rails specific cop http://rubocop.readthedocs.io/en/latest/cops/#rails --- .rubocop.yml | 3 +++ app/models/candidate.rb | 6 +++--- app/models/user.rb | 2 +- app/workers/quiz_status.rb | 4 +--- config/initializers/custom_error_wrapper.rb | 2 +- test/workers/candidate_quiz_question_test.rb | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b02a7d9..f6f0f20 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -54,3 +54,6 @@ Metrics/LineLength: Metrics/MethodLength: Exclude: - db/migrate/* + +Rails: + Enabled: true diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 69c4b2b..dea8c95 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -9,9 +9,9 @@ class Candidate < ApplicationRecord before_validation(:generate_test_hash, on: :create) - validates_presence_of :recruiter_id - validates_presence_of :name - validates_presence_of :experience + validates :recruiter_id, presence: true + validates :name, presence: true + validates :experience, presence: true validates :email, uniqueness: true, presence: true, email_format: true validates :test_hash, uniqueness: true, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 8f24471..00bbdad 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,7 +18,7 @@ class User < ApplicationRecord def gen_reset_token loop do self[:reset_token] = SecureRandom.urlsafe_base64(10) - self[:reset_timestamp] = DateTime.now + self[:reset_timestamp] = DateTime.current break unless User.exists?(reset_token: self[:reset_token]) end end diff --git a/app/workers/quiz_status.rb b/app/workers/quiz_status.rb index bde0c82..df3e50f 100644 --- a/app/workers/quiz_status.rb +++ b/app/workers/quiz_status.rb @@ -14,9 +14,7 @@ class QuizStatus candidate.submitted_answers.count == candidate.questions.count end - def completed - candidate.completed - end + delegate :completed, to: :candidate def can_submit on_summary && diff --git a/config/initializers/custom_error_wrapper.rb b/config/initializers/custom_error_wrapper.rb index 0d627f3..6602606 100644 --- a/config/initializers/custom_error_wrapper.rb +++ b/config/initializers/custom_error_wrapper.rb @@ -2,5 +2,5 @@ # TODO: needs better wrapping instead of nuking # https://rubyplus.com/articles/3401 ActionView::Base.field_error_proc = proc do |html_tag, _instance| - html_tag.html_safe + html_tag end diff --git a/test/workers/candidate_quiz_question_test.rb b/test/workers/candidate_quiz_question_test.rb index 85b08d2..ac967eb 100644 --- a/test/workers/candidate_quiz_question_test.rb +++ b/test/workers/candidate_quiz_question_test.rb @@ -8,7 +8,7 @@ class CandidateQuizQuestionTest < ActiveSupport::TestCase "input_options" => %w(one two three).to_yaml, "answer" => { test: 1, foo: 'bar', cheer: 'huzzah!' }.to_yaml, "saved" => false, "submitted" => true, - "updated_at" => DateTime.parse('20160816') } + "updated_at" => DateTime.parse('20160816').in_time_zone } end test "propper dot attributes work" do @@ -22,7 +22,7 @@ class CandidateQuizQuestionTest < ActiveSupport::TestCase assert_equal 'text', question.input_type assert_equal false, question.saved assert_equal true, question.submitted - assert_equal DateTime.parse('20160816'), question.updated_at + assert_equal DateTime.parse('20160816').in_time_zone, question.updated_at end test 'should handle array of input options' do