Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Replace Subclasses with Strategies: Step Three
* Move remaining common API into strategies
- Loading branch information
Showing
13 changed files
with
97 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
class OpenQuestion < Question | ||
def breakdown | ||
text_from_ordered_answers = answers.order(:created_at).pluck(:text) | ||
text_from_ordered_answers.join(', ') | ||
end | ||
|
||
def submittable | ||
OpenSubmittable.new | ||
OpenSubmittable.new(self) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
class OpenSubmittable | ||
def initialize(question) | ||
@question = question | ||
end | ||
|
||
def breakdown | ||
text_from_ordered_answers = answers.order(:created_at).pluck(:text) | ||
text_from_ordered_answers.join(', ') | ||
end | ||
|
||
def score(text) | ||
0 | ||
end | ||
|
||
private | ||
|
||
def answers | ||
@question.answers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
class ScaleSubmittable | ||
def initialize(question) | ||
@question = question | ||
end | ||
|
||
def breakdown | ||
sprintf('Average: %.02f', answers.average('text')) | ||
end | ||
|
||
def score(text) | ||
text.to_i | ||
end | ||
|
||
private | ||
|
||
def answers | ||
@question.answers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
example_app/spec/models/multiple_choice_submittable_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +0,0 @@ | ||
describe OpenQuestion, '#breakdown' do | ||
it 'returns all answers' do | ||
survey = create(:survey) | ||
question = create(:open_question, survey: survey) | ||
taker = AnswerCreator.new(survey) | ||
|
||
taker.answer question, 'Hey' | ||
taker.answer question, 'Hi' | ||
taker.answer question, 'Hello' | ||
|
||
question.breakdown.should eq 'Hey, Hi, Hello' | ||
end | ||
end | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters