diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 9b6f7dd7..e26f78cd 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -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 diff --git a/app/models/question.rb b/app/models/question.rb index c2891693..40ecd00b 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -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 diff --git a/app/views/answers/_list.html.haml b/app/views/answers/_list.html.haml index 86ede310..8b44f738 100644 --- a/app/views/answers/_list.html.haml +++ b/app/views/answers/_list.html.haml @@ -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" diff --git a/app/views/questions/_list.html.haml b/app/views/questions/_list.html.haml index 0d2d0589..a75d806b 100644 --- a/app/views/questions/_list.html.haml +++ b/app/views/questions/_list.html.haml @@ -1,4 +1,4 @@ -%tr.item +%tr.item{:id=>list.id} %td= list.title %td= list.description %td= link_to "Show", resource_path(list) diff --git a/features/answers.feature b/features/answers.feature index 766af692..164be0a6 100644 --- a/features/answers.feature +++ b/features/answers.feature @@ -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" \ No newline at end of file + 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" + diff --git a/features/step_definitions/answer_steps.rb b/features/step_definitions/answer_steps.rb new file mode 100644 index 00000000..c8e2df61 --- /dev/null +++ b/features/step_definitions/answer_steps.rb @@ -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 diff --git a/features/step_definitions/question_steps.rb b/features/step_definitions/question_steps.rb index 00d91e04..255647e0 100644 --- a/features/step_definitions/question_steps.rb +++ b/features/step_definitions/question_steps.rb @@ -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