diff options
-rw-r--r-- | app/controllers/answers_controller.rb | 16 | ||||
-rw-r--r-- | app/models/answer.rb | 20 | ||||
-rw-r--r-- | app/views/answers/edit.dryml | 2 | ||||
-rw-r--r-- | app/views/questions/show.dryml | 2 | ||||
-rw-r--r-- | app/views/taglibs/detailed.dryml | 2 | ||||
-rw-r--r-- | features/reference_answers.feature | 45 |
6 files changed, 79 insertions, 8 deletions
diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index 3c8aa8f..a8dc49e 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -6,9 +6,15 @@ class AnswersController < ApplicationController auto_actions_for :question, :new index_action :my_recruits, :my_recruits_cat - def create - # This creates answer with type deduced from params - # (as opposed answer with type Answer) - hobo_create Answer.new_from params - end + def update + # This creates answer with type deduced from params + # (as opposed answer with type Answer) + hobo_update Answer.find(params['id']),:attributes => Answer.update_from(params) + end + + def create + # This creates answer with type deduced from params + # (as opposed answer with type Answer) + hobo_create Answer.new_from params + end end diff --git a/app/models/answer.rb b/app/models/answer.rb index 2f091cd..43ce232 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -63,6 +63,26 @@ class Answer < ActiveRecord::Base User.user_is_mentor_of?(acting_user, owner) end + def self.update_from(params) + ans = Answer.find(params['id']) + + if ans.class == Answer + update = params["answer"] || [] + elsif ans.class == MultipleChoiceAnswer + params["multiple_choice_answer"] = {} unless params["multiple_choice_answer"] + params["multiple_choice_answer"]["options"] = params["options"].inject(Array.new){ |a, cur| a.push cur.to_i } + update = params["multiple_choice_answer"] + end + + result = ans.attributes + + for u in update + result[u[0]] = u[1] + end + + result + end + def self.new_from(params) if params.include? "answer" diff --git a/app/views/answers/edit.dryml b/app/views/answers/edit.dryml index c14feb5..d963e6d 100644 --- a/app/views/answers/edit.dryml +++ b/app/views/answers/edit.dryml @@ -5,6 +5,6 @@ # but result is alway posted to AnswersController#update # so action must be specified explicitly %> - <form action="&update_answer_path"/> + <form action="&update_answer_path(this.id)" method="PUT"/> </content:> </edit-page> diff --git a/app/views/questions/show.dryml b/app/views/questions/show.dryml index 6fd2341..964971b 100644 --- a/app/views/questions/show.dryml +++ b/app/views/questions/show.dryml @@ -25,7 +25,7 @@ </else> <if test="&this.reference_answer.try.viewable_by? current_user"> <br/> - <a:reference_answer>View reference answer</a>. + <a href="&answer_path(this.reference_answer)">View reference answer</a>. </if> </content:> </show-page> diff --git a/app/views/taglibs/detailed.dryml b/app/views/taglibs/detailed.dryml index b760421..3ff9792 100644 --- a/app/views/taglibs/detailed.dryml +++ b/app/views/taglibs/detailed.dryml @@ -32,7 +32,7 @@ <with:owner><name/></with> for question "<with:question><name/></with> - <a action="edit" if="&can_edit?">(Edit)</a> + <a href="&edit_answer_path(this)" if="&can_edit?">(Edit)</a> </h2> <h5>Question:</h5> <with:question><view:content/></with> diff --git a/features/reference_answers.feature b/features/reference_answers.feature new file mode 100644 index 0000000..944a196 --- /dev/null +++ b/features/reference_answers.feature @@ -0,0 +1,45 @@ +Feature: Reference answers + As recruiter + I want to be able to record and edit reference answers + So answers of recruits can be compared against them + And Recruits can get instant feedback on their answers for multiple choice questions + + Scenario: Record reference answer for text question and edit it as different recruiter + Given I am logged in as "recruiter1" who is "recruiter" + And text content "some question?" for question "question" + When I am on show "question" question page + And I follow "Answer it" + And I check "answer[reference]" + And I fill in "some answer" for "answer[content]" + And I press "Create Answer" + Then I should see "The answer was created successfully" within ".flash.notice" + + When I follow "Log out" + And I am logged in as "other-recruiter" who is "recruiter" + And I am on show "question" question page + And I follow "View reference answer" + And I follow "(Edit)" + And I fill in "some other answer" for "answer[content]" + And I press "Save" + Then I should see "Changes to the answer were saved" within ".flash.notice" + + Scenario: Record reference answer for multiple choice question and edit it as different recruiter + Given I am logged in as "recruiter1" who is "recruiter" + And a multiple choice content "Chose some" for "question" + And following options for "question": + |Opt 1|Opt 2|Opt 3| + When I am on show "question" question page + And I follow "Answer it" + And I check "multiple_choice_answer[reference]" + And I check "Opt 1" + And I press "Create Answer" + Then I should see "The multiple choice answer was created successfully" within ".flash.notice" + + When I follow "Log out" + And I am logged in as "other-recruiter" who is "recruiter" + And I am on show "question" question page + And I follow "View reference answer" + And I follow "(Edit)" + And I check "Opt 2" + And I press "Save" + Then I should see "Changes to the multiple choice answer were saved" within ".flash.notice" |