Skip to content

Commit 9c2ddc6

Browse files
committed
Replace Subclasses with Strategies: Step Two
* Pull up delegate method into base class
1 parent 7747366 commit 9c2ddc6

File tree

7 files changed

+1
-44
lines changed

7 files changed

+1
-44
lines changed

example_app/app/models/multiple_choice_question.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ def options_for_form
1111
end
1212
end
1313

14-
def score(text)
15-
submittable.score(text)
16-
end
17-
1814
def breakdown
1915
total = answers.count
2016
counts = answers.group(:text).order('COUNT(*) DESC').count

example_app/app/models/open_question.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
class OpenQuestion < Question
2-
def score(text)
3-
submittable.score(text)
4-
end
5-
62
def breakdown
73
text_from_ordered_answers = answers.order(:created_at).pluck(:text)
84
text_from_ordered_answers.join(', ')

example_app/app/models/question.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Question < ActiveRecord::Base
99
belongs_to :survey
1010
has_many :answers
1111

12+
delegate :score, to: :submittable
1213
delegate :title, to: :survey, prefix: true
1314

1415
def most_recent_answer_text

example_app/app/models/scale_question.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ class ScaleQuestion < Question
22
validates :maximum, presence: true
33
validates :minimum, presence: true
44

5-
def score(text)
6-
submittable.score(text)
7-
end
8-
95
def steps
106
(minimum..maximum).to_a
117
end

example_app/spec/models/multiple_choice_question_spec.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@
1515
end
1616
end
1717

18-
describe MultipleChoiceQuestion, '#score' do
19-
it 'returns the score for the option with the given text' do
20-
question = create(:multiple_choice_question)
21-
question.options.target.stubs(score: 2)
22-
23-
result = question.score('two')
24-
25-
question.options.target.should have_received(:score).with('two')
26-
result.should eq 2
27-
end
28-
end
29-
3018
describe MultipleChoiceQuestion, '#breakdown' do
3119
it 'returns a percentage breakdown' do
3220
survey = create(:survey)

example_app/spec/models/open_question_spec.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
describe OpenQuestion, '#score' do
2-
it 'returns zero' do
3-
question = build_stubbed(:open_question)
4-
5-
result = question.score('anything')
6-
7-
result.should eq 0
8-
end
9-
end
10-
111
describe OpenQuestion, '#breakdown' do
122
it 'returns all answers' do
133
survey = create(:survey)

example_app/spec/models/scale_question_spec.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
it { should validate_presence_of(:minimum) }
66
end
77

8-
describe ScaleQuestion, '#score' do
9-
it 'returns the integer value of the text' do
10-
question = build_stubbed(:scale_question)
11-
12-
result = question.score('5')
13-
14-
result.should eq 5
15-
end
16-
end
17-
188
describe ScaleQuestion, '#steps' do
199
it 'returns all numbers starting at the minimum and ending at the maximum' do
2010
question = build_stubbed(:scale_question, minimum: 2, maximum: 5)

0 commit comments

Comments
 (0)