diff options
author | 2010-08-13 09:38:06 +0200 | |
---|---|---|
committer | 2010-08-14 13:15:31 +0200 | |
commit | 666d2e43979e251eb088d7f12b662faa47537cc4 (patch) | |
tree | 5dbb85263c57c7788155b42fe16945056b8ca1e7 /spec | |
parent | Factory for guests to simplify tests (diff) | |
download | recruiting-webapp-666d2e43979e251eb088d7f12b662faa47537cc4.tar.gz recruiting-webapp-666d2e43979e251eb088d7f12b662faa47537cc4.tar.bz2 recruiting-webapp-666d2e43979e251eb088d7f12b662faa47537cc4.zip |
Improve coverage of ProjectAcceptance model and fix found bug
I defined view_permitted not view_permitted? so the function was
ignored.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_acceptance_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 36 |
2 files changed, 63 insertions, 5 deletions
diff --git a/spec/models/project_acceptance_spec.rb b/spec/models/project_acceptance_spec.rb index e702de4..992aad1 100644 --- a/spec/models/project_acceptance_spec.rb +++ b/spec/models/project_acceptance_spec.rb @@ -57,7 +57,7 @@ describe ProjectAcceptance do end it 'should allow creation only to recruiters and project leads that create for themselfs' do - acceptance = ProjectAcceptance.new :accepting_nick => 'a' + acceptance = Factory(:project_acceptance, :accepting_nick => 'a') lead = Factory(:mentor, :nick => "a", :project_lead => true) acceptance.should be_creatable_by(Factory(:recruiter)) @@ -71,4 +71,34 @@ describe ProjectAcceptance do acceptance.should_not be_creatable_by(Factory(:mentor, :project_lead => true)) acceptance.should_not be_creatable_by(Guest.new) end + + it "should be vieable only to user, mentor of user, accepting lead an drecruiters to view" do + acceptance = Factory(:project_acceptance) + acceptance.should be_viewable_by(acceptance.user) + acceptance.should be_viewable_by(acceptance.user.mentor) + acceptance.should be_viewable_by(User.find_by_nick(acceptance.accepting_nick)) + acceptance.should be_viewable_by(Factory(:recruiter)) + acceptance.should be_viewable_by(Factory(:administrator)) + + for u in fabricate_users(:recruit, :mentor, :guest) + acceptance.should_not be_viewable_by(u) + end + end + + it "should return properly return new acceptance for users" do + ProjectAcceptance.new_for_users(Factory(:recruit), Factory(:mentor)).should be_nil + ProjectAcceptance.new_for_users(Factory(:guest), Factory(:mentor)).should be_nil + ProjectAcceptance.new_for_users(Factory(:guest), Factory(:mentor, :project_lead => true)).should be_nil + + acceptance = ProjectAcceptance.new_for_users(Factory(:recruit), Factory(:mentor, :project_lead => true)) + acceptance.save! + ProjectAcceptance.new_for_users(acceptance.user, User.find_by_nick(acceptance.accepting_nick)).should be_nil + + recruit = Factory(:recruit) + lead = Factory(:mentor, :project_lead => true) + acceptance = ProjectAcceptance.new_for_users(recruit, lead) + acceptance.is_a?(ProjectAcceptance).should be_true + acceptance.user_is?(recruit).should be_true + acceptance.accepting_nick.should == lead.nick + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3b2859b..529c3b9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -70,7 +70,7 @@ describe User do end end - it "should allow recruiter to change user role" do + it "should allow recruiter to promote recruits to mentors" do recruit = Factory(:recruit) recruit.role = :mentor for user in [Factory(:recruiter), Factory(:administrator)] @@ -79,6 +79,15 @@ describe User do end end + it "should allow recruiter to demote mentors to recruits" do + recruit = Factory(:mentor) + recruit.role = :recruit + for user in [Factory(:recruiter), Factory(:administrator)] + recruit.should be_updatable_by(user) + recruit.should be_editable_by(user, :role) + end + end + it "should return proper all_questions" do r = recruit_with_answered_and_unanswered_questions @@ -203,7 +212,7 @@ describe User do user.nick = "short" user.should_not be_valid - user.nick = "short" + user.nick = "invalid" user.should_not be_valid silence_warnings { APP_CONFIG = JSON.load(old_config) } # restore config @@ -310,8 +319,7 @@ describe User do recruit.answered_all_multi_choice_questions?.should be_true q2 = Factory(:question, :question_group => Factory(:question_group)) - Factory(:question_content_multiple_choice, - :question => q2) + Factory(:question_content_multiple_choice, :question => q2) recruit.answered_all_multi_choice_questions?.should be_true Factory(:user_question_group, @@ -322,4 +330,24 @@ describe User do Factory(:multiple_choice_answer, :question => q2, :owner => recruit) recruit.answered_all_multi_choice_questions?.should be_true end + + it "shold return proper progress" do + recruit = Factory(:recruit) + recruit.progress.should == "Answered 0 of 0 questions." + + q1 = Factory(:question) + Factory(:user_category, :user => recruit, + :question_category => q1.question_category) + recruit.progress.should == "Answered 0 of 1 questions." + + Factory(:answer, :owner => recruit, :question => q1) + recruit.progress.should == "Answered 1 of 1 questions." + + q2 = Factory(:question, :question_group => Factory(:question_group)) + Factory(:user_question_group, :question => q2, :user => recruit) + recruit.progress.should == "Answered 1 of 2 questions." + + Factory(:answer, :owner => recruit, :question => q2) + recruit.progress.should == "Answered 2 of 2 questions." + end end |