|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | | -describe UnansweredQuestionHider, '#hide_answer_to_question' do |
4 | | - it 'returns a hidden summary' do |
5 | | - question = build_stubbed(:question) |
| 3 | +describe UnansweredQuestionHider, '#summary_or_hidden_answer' do |
| 4 | + it 'returns a hidden summary given a user without an answer' do |
| 5 | + summarizer = stub('summarizer') |
| 6 | + user = build_stubbed(:user) |
| 7 | + question = stub_answered_question(user, false) |
6 | 8 | hider = UnansweredQuestionHider.new |
7 | 9 |
|
8 | | - result = hider.hide_answer_to_question(question) |
| 10 | + result = hider.summary_or_hidden_answer(summarizer, question, user) |
9 | 11 |
|
10 | 12 | result.title.should eq question.title |
11 | 13 | result.value.should eq UnansweredQuestionHider::NO_ANSWER |
12 | 14 | end |
13 | | -end |
14 | 15 |
|
15 | | -describe UnansweredQuestionHider, '#hide_unanswered_question?' do |
16 | | - it 'returns true given a user without an answer' do |
17 | | - user = build_stubbed(:user) |
18 | | - question = stub_answered_question(user, false) |
19 | | - hider = UnansweredQuestionHider.new |
20 | | - |
21 | | - hider.hide_unanswered_question?(question, user).should be_true |
22 | | - end |
23 | | - |
24 | | - it 'returns false given a user with an answer' do |
| 16 | + it 'delegates to the summarizer given a user with an answer' do |
| 17 | + summary = stub('summary') |
25 | 18 | user = build_stubbed(:user) |
26 | 19 | question = stub_answered_question(user, true) |
| 20 | + summarizer = stub_summarizer(question, summary) |
27 | 21 | hider = UnansweredQuestionHider.new |
28 | 22 |
|
29 | | - hider.hide_unanswered_question?(question, user).should be_false |
| 23 | + result = hider.summary_or_hidden_answer(summarizer, question, user) |
| 24 | + |
| 25 | + result.should eq summary |
30 | 26 | end |
31 | 27 |
|
32 | | - it 'returns false without a user' do |
| 28 | + it 'delegates to the summarizer without a user' do |
| 29 | + summary = stub('summary') |
33 | 30 | question = build_stubbed(:question) |
| 31 | + summarizer = stub_summarizer(question, summary) |
34 | 32 | hider = UnansweredQuestionHider.new |
35 | 33 |
|
36 | | - hider.hide_unanswered_question?(question, nil).should be_false |
| 34 | + result = hider.summary_or_hidden_answer(summarizer, question, nil) |
| 35 | + |
| 36 | + result.should eq summary |
| 37 | + end |
| 38 | + |
| 39 | + def stub_summarizer(question, summary) |
| 40 | + stub('summarizer').tap do |summarizer| |
| 41 | + question.stubs(:summary_using).with(summarizer).returns(summary) |
| 42 | + end |
37 | 43 | end |
38 | 44 |
|
39 | 45 | def stub_answered_question(user, answered) |
|
0 commit comments