aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/questions_controller.rb3
-rw-r--r--app/models/answer.rb5
-rw-r--r--app/models/question.rb20
-rw-r--r--app/views/questions/doc_feedback_chart.dryml16
-rw-r--r--app/views/questions/show.dryml3
-rw-r--r--features/documentation_feedback.feature25
-rw-r--r--features/step_definitions/documentation_feedback_steps.rb16
-rw-r--r--spec/models/answer_spec.rb16
-rw-r--r--spec/models/question_spec.rb12
9 files changed, 116 insertions, 0 deletions
diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb
index ae35065..0e1ba3c 100644
--- a/app/controllers/questions_controller.rb
+++ b/app/controllers/questions_controller.rb
@@ -30,4 +30,7 @@ class QuestionsController < ApplicationController
def approve_questions
hobo_index Question.questions_to_approve
end
+
+ show_action :doc_feedback_chart
+
end
diff --git a/app/models/answer.rb b/app/models/answer.rb
index f013547..47544b3 100644
--- a/app/models/answer.rb
+++ b/app/models/answer.rb
@@ -47,6 +47,11 @@ class Answer < ActiveRecord::Base
named_scope :in_category, lambda { |category| {
:joins => :question, :conditions => { 'questions.question_category_id', category} } }
+ named_scope :with_feedback, lambda { |opt| {
+ :conditions => { :feedback => opt } } }
+
+ named_scope :with_some_feedback, :conditions => "answers.feedback IS NOT NULL AND answers.feedback <> ''"
+
validates_uniqueness_of :question_id, :scope => :reference, :if => :reference
validates_uniqueness_of :question_id, :scope => :owner_id, :unless => :reference
diff --git a/app/models/question.rb b/app/models/question.rb
index 084f826..294e03e 100644
--- a/app/models/question.rb
+++ b/app/models/question.rb
@@ -160,6 +160,26 @@ class Question < ActiveRecord::Base
after_create :notify_new_question
after_update :notify_approved_question
+ # Returns hash with:
+ # :values - string with coma-separated values
+ # :labels - string with coma-separated, quoted labels for values
+ def feedback_chart_data
+ classes = Answer.new.feedback.class.values - ['']
+ delta = 0.00001
+ result = {}
+ counts = classes.collect{ |opt| answers.with_feedback(opt).count }
+
+ result[:values] = counts.inject(nil) do |res, cur|
+ res.nil? ? (cur + delta).to_s : "#{res}, #{cur + delta}"
+ end
+
+ result[:labels] = classes.inject(nil) do |res, cur|
+ res.nil? ? "\"%%.%% - #{cur} (##)\"" : "#{res}, \"%%.%% - #{cur} (##)\""
+ end
+
+ result
+ end
+
protected
# Sends notification about new question (TODO: check for group).
def notify_new_question
diff --git a/app/views/questions/doc_feedback_chart.dryml b/app/views/questions/doc_feedback_chart.dryml
new file mode 100644
index 0000000..1a02c45
--- /dev/null
+++ b/app/views/questions/doc_feedback_chart.dryml
@@ -0,0 +1,16 @@
+<page>
+ <head:>
+ <javascript name='raphael'/>
+ <javascript name='g.raphael-min'/>
+ <javascript name='g.pie-min'/>
+ </head:>
+ <body:>
+ <script type="text/javascript" charset="utf-8">
+ var r = Raphael(0, 0, 600, 600);
+ <%=
+ dat = this.feedback_chart_data
+ "r.g.piechart(300, 300, 200, [#{dat[:values]}], {legend: [#{dat[:labels]}], legendpos: \"north\"});"
+ %>
+ </script>
+ </body:>
+</page>
diff --git a/app/views/questions/show.dryml b/app/views/questions/show.dryml
index 2e30578..8cb6629 100644
--- a/app/views/questions/show.dryml
+++ b/app/views/questions/show.dryml
@@ -26,5 +26,8 @@
<br/>
<a href="&answer_path(this.reference_answer)">View reference answer</a>.
</if>
+ <if test="&current_user.try.role.try.is_recruiter? && this.answers.with_some_feedback.count > 0">
+ <iframe src="<%= question_doc_feedback_chart_path(this.id) %>" width="600" height="600"/>
+ </if>
</content-body:>
</show-page>
diff --git a/features/documentation_feedback.feature b/features/documentation_feedback.feature
new file mode 100644
index 0000000..c792823
--- /dev/null
+++ b/features/documentation_feedback.feature
@@ -0,0 +1,25 @@
+Feature: Documentation feedback
+ As recruiter I want to see recruits feedback on questions documentation
+ But I don't want non-recruiters to see it
+
+ Scenario: When there is feedback see it as recruiter but not as recruit
+ Given I am logged in as "recruit"
+ And a question "question"
+ When I am on show "question" question page
+ And I follow "Answer it!"
+ And I select "Documentation Ok" from "answer[feedback]"
+ And press "Create Answer"
+
+ When I am on show "question" question page
+ Then I should see no pie chart with feedback
+
+ When I follow "Log out"
+ And I am logged in as "recruiter" who is "recruiter"
+ When I am on show "question" question page
+ Then I should see pie chart with feedback for "question"
+
+ Scenario: Don't see recruits feedback as recruiter when there is none
+ Given I am logged in as "recruiter" who is "recruiter"
+ And a question "question"
+ When I am on show "question" question page
+ Then I should see no pie chart with feedback
diff --git a/features/step_definitions/documentation_feedback_steps.rb b/features/step_definitions/documentation_feedback_steps.rb
new file mode 100644
index 0000000..58dcb98
--- /dev/null
+++ b/features/step_definitions/documentation_feedback_steps.rb
@@ -0,0 +1,16 @@
+Then /^I should see tag <([^<>]*)>$/ do |tag|
+ /#{tag}/.match(response.body).should_not be_nil
+end
+
+Then /^I should not see tag <([^<>]*)>$/ do |tag|
+ /#{tag}/.match(response.body).should be_nil
+end
+
+Then /^I should see pie chart with feedback for "([^"]*)"$/ do |question|
+ Given "a question \"#{question}\""
+ Then "I should see tag <iframe src=\"/questions/#{@question.id}/doc_feedback_chart\">"
+end
+
+Then /^I should see no pie chart with feedback$/ do
+ Then 'I should not see tag <iframe src="/questions/\d+/doc_feedback_chart">'
+end
diff --git a/spec/models/answer_spec.rb b/spec/models/answer_spec.rb
index 9a60bb8..b9cdb05 100644
--- a/spec/models/answer_spec.rb
+++ b/spec/models/answer_spec.rb
@@ -332,4 +332,20 @@ describe Answer do
Answer.new(:owner => user).should be_editable_by(user, :reference)
end
end
+
+ it "should properly return answers with feedback" do
+
+ with_feedback = (Answer.new.feedback.class.values - ['']).collect do |fb|
+ Factory(:answer, :feedback => fb)
+ end
+
+ without_feedback = ['', nil].collect do |fb|
+ Factory(:answer, :feedback => fb)
+ end
+
+ with_feedback.each{ |ans| Answer.with_some_feedback.include?(ans).should be_true }
+ without_feedback.each{ |ans| Answer.with_some_feedback.include?(ans).should be_false }
+
+ Answer.with_some_feedback.count.should == Answer.with_some_feedback.uniq.count
+ end
end
diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb
index 05e81ef..710342f 100644
--- a/spec/models/question_spec.rb
+++ b/spec/models/question_spec.rb
@@ -192,4 +192,16 @@ describe Question do
Factory(:answer, :question => q, :owner=> u)
q.answered?(u).should be_true
end
+
+ it "should count feedback properly" do
+ q = Factory(:question)
+ Factory(:answer, :question => q, :feedback =>'Documentation ok')
+ Factory(:answer, :question => q, :feedback =>'Could not find documentation')
+ Factory(:answer, :question => q, :feedback =>'Could not find documentation')
+ Factory(:answer, :question => q, :feedback =>'Documentation insufficient')
+ Factory(:answer, :question => q, :feedback =>'Documentation insufficient')
+ Factory(:answer, :question => q, :feedback =>'Documentation insufficient')
+
+ q.feedback_chart_data[:values].should == '1.00001, 2.00001, 3.00001'
+ end
end