diff options
author | 2011-03-12 21:13:18 +0200 | |
---|---|---|
committer | 2011-03-12 21:13:18 +0200 | |
commit | c38161f8d317aee036f197a9b670f96dcd4c9ec3 (patch) | |
tree | 3ba7b4cd90a3bb5ea4a351c3c3221fd8de8603fd /spec | |
parent | Rename QuestionCategory to Category (diff) | |
download | recruiting-webapp-c38161f8d317aee036f197a9b670f96dcd4c9ec3.tar.gz recruiting-webapp-c38161f8d317aee036f197a9b670f96dcd4c9ec3.tar.bz2 recruiting-webapp-c38161f8d317aee036f197a9b670f96dcd4c9ec3.zip |
Questions can belong to many categories
While starting to input quiz questions for the arch tester quizzes we
found out that it would be best if questions could belong to many
categories. Now the relationship between questions and categories is
many to many. Bug #356179.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories.rb | 9 | ||||
-rw-r--r-- | spec/models/answer_spec.rb | 9 | ||||
-rw-r--r-- | spec/models/question_group_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/question_spec.rb | 17 | ||||
-rw-r--r-- | spec/models/user_category_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/user_mailer_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 4 | ||||
-rw-r--r-- | spec/support/factory_orders.rb | 28 |
8 files changed, 51 insertions, 30 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index 2c663af..3ead1e1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -51,6 +51,11 @@ q.name { Factory.next(:category) } end + Factory.define :question_category do |qc| + qc.association :question + qc.association :category + end + Factory.sequence :question do |n| "question-#{n}" end @@ -58,7 +63,9 @@ # it'll belong to new category by default Factory.define :question do |q| q.title { Factory.next(:question) } - q.category { Factory(:category)} + q.after_build { |q| + q.categories = [Factory.build :category] + } end Factory.sequence :answer do |n| diff --git a/spec/models/answer_spec.rb b/spec/models/answer_spec.rb index e300537..61e23a8 100644 --- a/spec/models/answer_spec.rb +++ b/spec/models/answer_spec.rb @@ -250,7 +250,6 @@ describe Answer do (!produced_ans.attributes[i[0]]).should be_true # it can be nil or false end end - end it "should produce proper updated answer from params" do @@ -270,10 +269,10 @@ describe Answer do it "should properly return wrong answers of recruit" do recruit = Factory(:recruit) cat = Factory(:category) - q1 = Factory(:question, :category => cat) - q2 = Factory(:question, :category => cat) - q3 = Factory(:question, :category => cat) - q4 = Factory(:question, :category => cat) + q1 = Factory(:question_category, :category => cat).question + q2 = Factory(:question_category, :category => cat).question + q3 = Factory(:question_category, :category => cat).question + q4 = Factory(:question_category, :category => cat).question Factory(:question_content_text, :question => q4) diff --git a/spec/models/question_group_spec.rb b/spec/models/question_group_spec.rb index b490f89..dc62f83 100644 --- a/spec/models/question_group_spec.rb +++ b/spec/models/question_group_spec.rb @@ -23,7 +23,9 @@ describe QuestionGroup do for n in 1..5 groups_in_cat.push Factory(:question_group) for i in 1..n - Factory(:question, :category => category, :question_group => groups_in_cat.last) + Factory(:question_category, + :category => category, + :question => Factory(:question, :question_group => groups_in_cat.last)) end end @@ -44,7 +46,9 @@ describe QuestionGroup do for n in 1..5 groups_in_cat.push Factory(:question_group) for i in 1..n - Factory(:question, :category => category, :question_group => groups_in_cat.last) + Factory(:question_category, + :category => category, + :question => Factory(:question, :question_group => groups_in_cat.last)) end end diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb index 5dddd70..99a286f 100644 --- a/spec/models/question_spec.rb +++ b/spec/models/question_spec.rb @@ -68,8 +68,8 @@ describe Question do it "should send email notifications to watching recruits when created by recruiter" do category = Factory(:category) recruit = Factory(:recruit, :categories => [category]) - question = Question.new(:title => "new question", - :category => category) + question = Factory.build(:question) + question.categories << category UserMailer.should_receive_delayed(:deliver_new_question, recruit, question) @@ -79,19 +79,19 @@ describe Question do it "should send email notifications to watching recruits when approved" do category = Factory(:category) recruit = Factory(:recruit, :categories => [category]) - question = Factory(:question, :title => "new question", - :category => category, :user => Factory(:recruit)) + question = Factory(:question, :user => Factory(:recruit)) + question.categories << category UserMailer.should_receive_delayed(:deliver_new_question, recruit, question) question.approved = true question.save! end - it "should not send email notifications to watching recruits when approved is changed" do + it "should not send email notifications to watching recruits when approved is not changed" do category = Factory(:category) recruit = Factory(:recruit, :categories => [category]) - question = Factory(:question, :title => "new question", - :category => category, :user => Factory(:recruit), :approved => true) + question = Factory(:question, :user => Factory(:recruit), :approved => true) + question.categories << category UserMailer.should_not_receive(:deliver_new_question).with(recruit, question) @@ -146,7 +146,6 @@ describe Question do question.should be_editable_by(recruit) question.should be_editable_by(recruit, :title) question.should be_editable_by(recruit, :documentation) - question.should be_editable_by(recruit, :category) question.should_not be_editable_by(recruit, :user) question.should_not be_editable_by(recruit, :approved) @@ -159,7 +158,6 @@ describe Question do question.should be_editable_by(recruit) question.should be_editable_by(recruit, :title) question.should be_editable_by(recruit, :documentation) - question.should be_editable_by(recruit, :category) question.should_not be_editable_by(recruit, :user) question.should_not be_editable_by(recruit, :approved) @@ -172,7 +170,6 @@ describe Question do question.should be_editable_by(admin) question.should be_editable_by(admin, :title) question.should be_editable_by(admin, :documentation) - question.should be_editable_by(admin, :category) question.should be_editable_by(admin, :approved) question.should_not be_editable_by(admin, :user) diff --git a/spec/models/user_category_spec.rb b/spec/models/user_category_spec.rb index 99efdea..130a359 100644 --- a/spec/models/user_category_spec.rb +++ b/spec/models/user_category_spec.rb @@ -70,7 +70,9 @@ describe UserCategory do for n in 1..5 groups_in_cat.push Factory(:question_group) for i in 1..n - Factory(:question, :category => category, :question_group => groups_in_cat.last) + Factory(:question_category, + :category => category, + :question => Factory(:question, :question_group => groups_in_cat.last)) end end diff --git a/spec/models/user_mailer_spec.rb b/spec/models/user_mailer_spec.rb index 39a45e2..d681e9e 100644 --- a/spec/models/user_mailer_spec.rb +++ b/spec/models/user_mailer_spec.rb @@ -10,7 +10,7 @@ describe UserMailer do notification.should deliver_to(recruit.email_address) notification.should deliver_from("no-reply@localhost") notification.should have_text(/There is a new question "#{question.title}"/) - notification.should have_text(/in category "#{question.category.name}" you are assigned to./) + notification.should have_text(/one of the categories you are assigned to./) notification.should have_text(/http:\/\/localhost:3000\/questions\/#{question.id}/) notification.should have_subject('New question') end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ee256c4..b4a3dbf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -310,7 +310,7 @@ describe User do q1 = Factory(:question) Factory(:question_content_multiple_choice, :question => q1) Factory(:user_category, - :category => q1.category, + :category => q1.categories.first, :user => recruit) recruit.answered_all_multi_choice_questions?.should be_false @@ -337,7 +337,7 @@ describe User do q1 = Factory(:question) Factory(:user_category, :user => recruit, - :category => q1.category) + :category => q1.categories.first) recruit.progress.should == "Answered 0 of 1 questions." Factory(:answer, :owner => recruit, :question => q1) diff --git a/spec/support/factory_orders.rb b/spec/support/factory_orders.rb index d02249a..9548330 100644 --- a/spec/support/factory_orders.rb +++ b/spec/support/factory_orders.rb @@ -12,19 +12,27 @@ def recruit_with_answered_and_unanswered_questions(n=5) for i in 1..n # answered and unanswered ungrouped questions category = Factory(:category) - r.answered.push Factory(:question, :category => category) - r.unanswered.push Factory(:question, :category => category) + r.answered.push Factory(:question_category, :category => category).question + r.unanswered.push Factory(:question_category, :category => category).question Factory(:answer, :owner => r.recruit, :question => r.answered.last) # and answered and unanswered question in one group group = Factory(:question_group) - r.answered.push Factory(:question, :category => category, :question_group => group) + r.answered.push Factory(:question_category, + :category => category, + :question => Factory(:question, :question_group => group) + ).question Factory(:user_question_group, :user => r.recruit, :question => r.answered.last) # This question isn't unanswered! This is question user can't answer - Factory(:question, :category => category, :question_group => group) + Factory(:question_category, + :category => category, + :question => Factory(:question, :question_group => group)) # add a unanswered grouped question - r.unanswered.push Factory(:question, :category => category, :question_group => Factory(:question_group)) + r.unanswered.push Factory(:question_category, + :category => category, + :question => Factory(:question, :question_group => Factory(:question_group)) + ).question Factory(:user_question_group, :user => r.recruit, :question => r.unanswered.last) Factory(:answer, :owner => r.recruit, :question => r.answered.last) @@ -51,14 +59,18 @@ def recruit_with_answers_in_categories(mentor = nil, n_categories = 5, n_ans_in_ r.categories.push Factory(:category) r.answers_in_cat.push [] for i in 1..n_ans_in_cat - question = Factory(:question, :category => r.categories.last) + question = Factory(:question_category, :category => r.categories.last).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 => r.categories.last, :question_group => group) - Factory(:question, :category => r.categories.last, :question_group => group) + question = Factory(:question_category, + :category => r.categories.last, + :question => Factory(:question, :question_group => group)).question + Factory(:question_category, + :category => r.categories.last, + :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) r.answers_in_cat.last.push r.all_answers.last |