Updated

app/models/archived / rejection.rb

B
30 lines of codes
2 methods
2.0 complexity/method
3 churn
3.96 complexity
18 duplications
require_dependency 'archived' module Archived class Rejection < ActiveRecord::Base
  1. Archived::Rejection has no descriptive comment
CODES = %w[duplicate irrelevant no-action honours fake-name foi libellous offensive] HIDDEN_CODES = %w[libellous offensive] belongs_to :petition, touch: true validates :petition, presence: true validates :code, presence: true, inclusion: { in: CODES } validates :details, length: { maximum: 4000 }, allow_blank: true after_create do
  1. Identical code found in 2 nodes Locations: 0 1
if petition.rejected_at? petition.update!(state: state_for_petition) else petition.update!(state: state_for_petition, rejected_at: Time.current) end end def hide_petition? code.in?(HIDDEN_CODES) end def state_for_petition hide_petition? ? Petition::HIDDEN_STATE : Petition::REJECTED_STATE end end end