Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ def show
@answer = Answer.new
show!
end

def update
params[:question][:solution_id] != @question.solution_id ? update!(:notice => "Okay! We've selected that answer") : update!
end
end
3 changes: 3 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ class Question

key :title, String
key :description, String
key :solution_id, ObjectId

belongs_to :user
many :answers

one :answer, :in => :solution_id

validates_presence_of :title, :description

Expand Down
4 changes: 4 additions & 0 deletions app/views/answers/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
= link_to 'Edit', edit_question_answer_path(@question, list)
- if can? :destroy, list
= link_to 'Delete', question_answer_path(@question, list), :confirm => 'Are you sure?', :method => :delete
- if can? :update, @question
= simple_form_for(@question, :url => question_path(@question)) do |f|
= f.hidden_field :solution_id, :value => list.id
= f.button :submit, :value => "This answer is correct", :class => "primary btn"
2 changes: 1 addition & 1 deletion app/views/questions/_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%tr.item
%tr.item{:id=>list.id}
%td= list.title
%td= list.description
%td= link_to "Show", resource_path(list)
Expand Down
11 changes: 10 additions & 1 deletion features/answers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ Feature: CRUD actions for question
And I press "Post Answer"
Then I should see "Answer Posted!"
And I should see "My Answer" within ".answers"
And I should see "Answered by test" within ".answer"
And I should see "Answered by test" within ".answer"

Scenario: Select an answer
Given I have created a question with title "My Title" and description "My Description"
And that someone has provided an answer for my question
And I am on the questions index
And I follow "Show" for my question
And I press "This answer is correct"
Then I should see "Okay! We've selected that answer"

5 changes: 5 additions & 0 deletions features/step_definitions/answer_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Given /^that someone has provided an answer for my question$/ do
other_user = Fabricate(:user)
other_user.save!
@question.answers.build(:description => "Some solution", :user => other_user).save!
end
6 changes: 5 additions & 1 deletion features/step_definitions/question_steps.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Given /^I have created a question with title "([^"]*)" and description "([^"]*)"$/ do |title, description|
@user.questions.build(:title => "#{title}", :description =>"#{description}").save!
@question = @user.questions.build(:title => "#{title}", :description =>"#{description}")
@question.save!
end

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

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