Skip to content

Commit 41a220a

Browse files
committed
Merge pull request #78 from abhirao/rails3
Choose an answer feature
2 parents 4f793bb + 70634bf commit 41a220a

7 files changed

Lines changed: 32 additions & 3 deletions

File tree

app/controllers/questions_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ def show
1111
@answer = Answer.new
1212
show!
1313
end
14+
15+
def update
16+
params[:question][:solution_id] != @question.solution_id ? update!(:notice => "Okay! We've selected that answer") : update!
17+
end
1418
end

app/models/question.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ class Question
33

44
key :title, String
55
key :description, String
6+
key :solution_id, ObjectId
67

78
belongs_to :user
89
many :answers
10+
11+
one :answer, :in => :solution_id
912

1013
validates_presence_of :title, :description
1114

app/views/answers/_list.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
= link_to 'Edit', edit_question_answer_path(@question, list)
99
- if can? :destroy, list
1010
= link_to 'Delete', question_answer_path(@question, list), :confirm => 'Are you sure?', :method => :delete
11+
- if can? :update, @question
12+
= simple_form_for(@question, :url => question_path(@question)) do |f|
13+
= f.hidden_field :solution_id, :value => list.id
14+
= f.button :submit, :value => "This answer is correct", :class => "primary btn"

app/views/questions/_list.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%tr.item
1+
%tr.item{:id=>list.id}
22
%td= list.title
33
%td= list.description
44
%td= link_to "Show", resource_path(list)

features/answers.feature

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ Feature: CRUD actions for question
1616
And I press "Post Answer"
1717
Then I should see "Answer Posted!"
1818
And I should see "My Answer" within ".answers"
19-
And I should see "Answered by test" within ".answer"
19+
And I should see "Answered by test" within ".answer"
20+
21+
Scenario: Select an answer
22+
Given I have created a question with title "My Title" and description "My Description"
23+
And that someone has provided an answer for my question
24+
And I am on the questions index
25+
And I follow "Show" for my question
26+
And I press "This answer is correct"
27+
Then I should see "Okay! We've selected that answer"
28+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Given /^that someone has provided an answer for my question$/ do
2+
other_user = Fabricate(:user)
3+
other_user.save!
4+
@question.answers.build(:description => "Some solution", :user => other_user).save!
5+
end
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
Given /^I have created a question with title "([^"]*)" and description "([^"]*)"$/ do |title, description|
2-
@user.questions.build(:title => "#{title}", :description =>"#{description}").save!
2+
@question = @user.questions.build(:title => "#{title}", :description =>"#{description}")
3+
@question.save!
34
end
45

56
Given /^there are existing questions$/ do
67
2.times{Fabricate(:question)}
78
end
89

10+
When /^(?:|I )follow "([^"]*)" for my question$/ do |link|
11+
find("##{@question.id}").click_link(link)
12+
end

0 commit comments

Comments
 (0)