Permalink
Browse files

Extract Decorator Step One

* Create empty decorator class
* Move method to decorator
  • Loading branch information...
jferris committed Feb 20, 2013
1 parent 15f5b96 commit af2e83186e12b6a141849f3cd743c7588682671d
@@ -1,6 +1,4 @@
class Survey < ActiveRecord::Base
NO_ANSWER = "You haven't answered this question".freeze

include ActiveModel::ForbiddenAttributesProtection

validates_presence_of :title
@@ -19,7 +17,7 @@ def summaries_using(summarizer, options = {})

def summary_or_hidden_answer(summarizer, question, answered_by)
if hide_unanswered_question?(question, answered_by)
hide_answer_to_question(question)
UnansweredQuestionHider.new.hide_answer_to_question(question)
else
question.summary_using(summarizer)
end
@@ -28,8 +26,4 @@ def summary_or_hidden_answer(summarizer, question, answered_by)
def hide_unanswered_question?(question, answered_by)
answered_by && !question.answered_by?(answered_by)
end

def hide_answer_to_question(question)
Summary.new(question.title, NO_ANSWER)
end
end
@@ -0,0 +1,7 @@
class UnansweredQuestionHider
NO_ANSWER = "You haven't answered this question".freeze

def hide_answer_to_question(question)
Summary.new(question.title, NO_ANSWER)
end
end
@@ -0,0 +1,13 @@
require 'spec_helper'

describe UnansweredQuestionHider, '#hide_answer_to_question' do
it 'returns a hidden summary' do
question = build_stubbed(:question)
hider = UnansweredQuestionHider.new

result = hider.hide_answer_to_question(question)

result.title.should eq question.title
result.value.should eq UnansweredQuestionHider::NO_ANSWER
end
end

0 comments on commit af2e831

Please sign in to comment.