Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove duplication in Answer
* Removes smell Duplicated Code
* Applies refactoring Extract Method
  • Loading branch information
jferris committed Dec 6, 2012
1 parent 8698fd4 commit 1e35c68
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions example_app/app/models/answer.rb
Expand Up @@ -7,11 +7,16 @@ class Answer < ActiveRecord::Base
validates :text, presence: true

def self.for_user(user)
joins(:completion).where(completions: { user_id: user.id }).last ||
NullAnswer.new
joins(:completion).where(completions: { user_id: user.id }).last_or_null
end

def self.most_recent
order(:created_at).last || NullAnswer.new
order(:created_at).last_or_null
end

private

def self.last_or_null
last || NullAnswer.new
end
end

0 comments on commit 1e35c68

Please sign in to comment.