aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Räty <betelgeuse@gentoo.org>2011-03-19 17:41:57 +0200
committerPetteri Räty <betelgeuse@gentoo.org>2011-03-19 17:41:57 +0200
commit23346baa4a2a88ba76f1e2926260652e7a54b5a3 (patch)
tree5334d8384d84834a1532e385fd3c8f2e008e3883
parentTypo fix destory to destroy (diff)
downloadrecruiting-webapp-23346baa4a2a88ba76f1e2926260652e7a54b5a3.tar.gz
recruiting-webapp-23346baa4a2a88ba76f1e2926260652e7a54b5a3.tar.bz2
recruiting-webapp-23346baa4a2a88ba76f1e2926260652e7a54b5a3.zip
Improve ready recruits listing
Recruits who don't have any categories should not be considered ready. There's plenty people signing and not answering anything so they should not be listed. Fixes bug #355717.
-rw-r--r--app/models/user.rb3
-rw-r--r--features/recruits_who_answered_all_questions.feature2
-rw-r--r--spec/models/user_spec.rb16
-rw-r--r--spec/support/factory_orders.rb11
4 files changed, 18 insertions, 14 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index dff9295..87d9024 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -57,7 +57,8 @@ class User < ActiveRecord::Base
AND NOT EXISTS
(SELECT questions.id FROM questions INNER JOIN user_question_groups ON questions.id = user_question_groups.question_id
WHERE user_question_groups.user_id = users.id AND NOT EXISTS (
- SELECT answers.id FROM answers WHERE answers.question_id = questions.id AND answers.owner_id = users.id))"
+ SELECT answers.id FROM answers WHERE answers.question_id = questions.id AND answers.owner_id = users.id))
+ AND id IN (SELECT user_id FROM user_categories)"
# --- Signup lifecycle --- #
lifecycle do
diff --git a/features/recruits_who_answered_all_questions.feature b/features/recruits_who_answered_all_questions.feature
index d5861c0..33f5110 100644
--- a/features/recruits_who_answered_all_questions.feature
+++ b/features/recruits_who_answered_all_questions.feature
@@ -8,10 +8,8 @@ Feature: Viewing recruits who answered all questions
And recruit "recruit1" in following categories:
|some cat|
And user "recruit1" answered all questions in "some cat"
- And a user "recruit2" who is "recruit"
When I am on ready recruits page
Then I should see "recruit1" within ".user .collection"
- And I should see "recruit2" within ".user .collection"
Scenario: Go to ready recruits from homepage
Given a question "some question" in category "some cat"
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 4fdbbcf..76a1a45 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -123,10 +123,15 @@ describe User do
Factory(:recruit).answered_all_questions?.should be_true
end
+ it "should not consider recruits with no categories as answered all" do
+ r = Factory(:recruit)
+ r.categories.should be_empty
+ User.recruits_answered_all.count.should == 0
+ end
+
it "should return proper recruits with all questions` answered" do
- # recruits that should be returned
- correct_answered_all = [Factory(:recruit)]
- correct_answered_all.push recruit_with_answers_in_categories.recruit
+ # recruit that should be returned
+ correct_answered_all = [recruit_with_answers_in_categories.recruit]
# and some other users
recruit_with_answered_and_unanswered_questions
@@ -134,10 +139,7 @@ describe User do
Factory(:mentor)
Factory(:recruiter)
- answered_all = User.recruits_answered_all
-
- (answered_all - correct_answered_all).should be_empty
- (correct_answered_all - answered_all).should be_empty
+ User.recruits_answered_all.should == correct_answered_all
end
it "should allow recruiters to change nick of other users" do
diff --git a/spec/support/factory_orders.rb b/spec/support/factory_orders.rb
index 9548330..2847809 100644
--- a/spec/support/factory_orders.rb
+++ b/spec/support/factory_orders.rb
@@ -56,20 +56,23 @@ def recruit_with_answers_in_categories(mentor = nil, n_categories = 5, n_ans_in_
r.answers_in_cat = []
r.all_answers = []
for i in 1..n_categories
- r.categories.push Factory(:category)
+ c = Factory(:category)
+ r.categories.push c
+ r.recruit.categories.push c
+
r.answers_in_cat.push []
for i in 1..n_ans_in_cat
- question = Factory(:question_category, :category => r.categories.last).question
+ question = Factory(:question_category, :category => c).question
r.all_answers.push Factory(:answer, :owner => r.recruit, :question => question)
r.answers_in_cat.last.push r.all_answers.last
# group of two questions, answered
group = Factory(:question_group)
question = Factory(:question_category,
- :category => r.categories.last,
+ :category => c,
:question => Factory(:question, :question_group => group)).question
Factory(:question_category,
- :category => r.categories.last,
+ :category => c,
:question => Factory(:question, :question_group => group))
Factory(:user_question_group, :user => r.recruit, :question => question)
r.all_answers.push Factory(:answer, :owner => r.recruit, :question => question)