1class GovernmentResponse < ActiveRecord::Base
 
2  belongs_to :petition, touch: true
 
3
 
4  validates :petition, presence: true
 
5  validates :summary, presence: true, length: { maximum: 200 }
 
6  validates :details, length: { maximum: 6000 }, allow_blank: true
 
7  validates :responded_on, presence: true
 
8
 
 9  after_create do
 
10    petition.touch(:government_response_at) unless petition.government_response_at?
 
11  end
 
  • Complexity 1 » saikuro
13  def responded_on
 
14    super || default_responded_on
 
15  end
 
 
17  private
 
  • DuplicateMethodCall - calls 'petition.government_response_at' 2 times » reek
  • Complexity 4 » saikuro
19  def default_responded_on
 
20    if petition && petition.government_response_at
 
21      petition.government_response_at.to_date
 
22    elsif created_at
 
23      created_at.to_date
 
24    elsif new_record?
 
25      Date.current
 
26    end
 
27  end
 
28end