aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-06-24 15:07:46 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-06-25 19:39:42 +0200
commitc2634a954af3c5e0cc99eb53f33eb73b03c70bd5 (patch)
treed2817245d97eb1bcf321d57dd3cdea1d8c11a3d2
parentRewrite seed to make it cleaner (diff)
downloadrecruiting-webapp-c2634a954af3c5e0cc99eb53f33eb73b03c70bd5.tar.gz
recruiting-webapp-c2634a954af3c5e0cc99eb53f33eb73b03c70bd5.tar.bz2
recruiting-webapp-c2634a954af3c5e0cc99eb53f33eb73b03c70bd5.zip
Users can list their contributions, mentors can find for recruits with no mentor
-rw-r--r--app/controllers/users_controller.rb5
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/taglibs/pages.dryml3
-rw-r--r--app/views/users/mentorless_recruits.dryml1
-rw-r--r--db/schema.rb13
-rw-r--r--features/request_mentor.feature23
-rw-r--r--spec/models/user_category_spec.rb29
7 files changed, 71 insertions, 7 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 90dc3c9..d1a8ac6 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -4,8 +4,13 @@ class UsersController < ApplicationController
auto_actions :all, :except => [ :index, :new, :create ]
index_action :ready_recruits
+ index_action :mentorless_recruits
def ready_recruits
hobo_index
end
+
+ def mentorless_recruits
+ hobo_index User.mentorless_recruits
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index f4eda70..ccb050f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -8,6 +8,7 @@ class User < ActiveRecord::Base
administrator :boolean, :default => false
role Role, :default => 'recruit'
nick :string
+ contributions :text
timestamps
end
@@ -20,6 +21,7 @@ class User < ActiveRecord::Base
belongs_to :mentor, :class_name => "User"
has_many :recruits, :class_name => "User", :foreign_key => :mentor_id
+ named_scope :mentorless_recruits, :conditions => { :role => 'recruit', :mentor_id => nil}
# This gives admin rights and recruiter role to the first sign-up.
before_create { |user|
if !Rails.env.test? && count == 0
@@ -140,7 +142,7 @@ class User < ActiveRecord::Base
def changes_allowed_to_self?
only_changed?(:email_address, :crypted_password, :current_password,
- :password, :password_confirmation, :nick)
+ :password, :password_confirmation, :nick, :contributions)
# Note: crypted_password has attr_protected so although it is permitted to change, it cannot be changed
# directly from a form submission.
end
diff --git a/app/views/taglibs/pages.dryml b/app/views/taglibs/pages.dryml
index e3e554e..47766b3 100644
--- a/app/views/taglibs/pages.dryml
+++ b/app/views/taglibs/pages.dryml
@@ -39,5 +39,8 @@
<if test="&current_user.try.any_pending_project_acceptances?">
<a with="&ProjectAcceptance" action="pending_acceptances">Recruits waiting for your acceptance</a>.
</if>
+ <if test="&current_user.try.role.try.is_mentor? && User.mentorless_recruits.count > 0">
+ <a with="&User" action="mentorless_recruits">See mentorless recruits</a><br/>
+ </if>
</section>
</def>
diff --git a/app/views/users/mentorless_recruits.dryml b/app/views/users/mentorless_recruits.dryml
new file mode 100644
index 0000000..2acb381
--- /dev/null
+++ b/app/views/users/mentorless_recruits.dryml
@@ -0,0 +1 @@
+<index-page/>
diff --git a/db/schema.rb b/db/schema.rb
index d63bb9d..1149c5e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,16 +9,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100623172612) do
+ActiveRecord::Schema.define(:version => 20100625160008) do
create_table "answers", :force => true do |t|
t.text "content"
+ t.boolean "approved", :default => false
+ t.boolean "reference", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "question_id"
t.integer "owner_id"
- t.boolean "reference", :default => false
- t.boolean "approved", :default => false
end
add_index "answers", ["owner_id"], :name => "index_answers_on_owner_id"
@@ -76,17 +76,18 @@ ActiveRecord::Schema.define(:version => 20100623172612) do
t.string "remember_token"
t.datetime "remember_token_expires_at"
t.string "name"
+ t.string "email_address"
t.boolean "administrator", :default => false
t.string "role", :default => "recruit"
+ t.string "nick"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "mentor_id"
t.string "state", :default => "active"
t.datetime "key_timestamp"
- t.integer "mentor_id"
- t.string "email_address"
t.string "crypted_password", :limit => 40
t.string "salt", :limit => 40
- t.string "nick"
+ t.text "contributions"
end
add_index "users", ["mentor_id"], :name => "index_users_on_mentor_id"
diff --git a/features/request_mentor.feature b/features/request_mentor.feature
new file mode 100644
index 0000000..b192d16
--- /dev/null
+++ b/features/request_mentor.feature
@@ -0,0 +1,23 @@
+Feature: Request Mentor
+ As a recruit
+ I want to use the webapp to apply for a mentor
+ so that I will get assigned one
+
+ Scenario: Listing contributions
+ Given I am logged in as "recruit"
+ And I am on edit "recruit" user page
+ When I fill in "user[contributions]" with "some contributions"
+ And I press "Save"
+ Then I should see "Changes to your account were saved" within ".flash.notice"
+ And I should see "some contributions" within ".contributions-tag.view.user-contributions"
+
+ Scenario: Unassigned Recruit listing for Mentors
+ Given I am logged in as "mentor" who is "mentor"
+ And user "recruit1" who is "recruit"
+ And user "recruit2" who is "recruit"
+ And user "mentor" is mentor of "recruit3"
+ When I am on the home page
+ And I follow "See mentorless recruits"
+ Then I should see "recruit1" within ".collection.users"
+ And I should see "recruit1" within ".collection.users"
+ But I should not see "recruit3" within ".collection.users"
diff --git a/spec/models/user_category_spec.rb b/spec/models/user_category_spec.rb
index 0ed258c..b61f3eb 100644
--- a/spec/models/user_category_spec.rb
+++ b/spec/models/user_category_spec.rb
@@ -34,4 +34,33 @@ describe UserCategory do
it "should deny other users to CUD, edit and view user categories" do
deny_all(fabricate_users(:recruit, :mentor) + [Guest.new], Factory(:user_category))
end
+
+ it "should allow everybody to view contributons" do
+ for u in fabricate_all_roles + [Guest.new]
+ Factory(:recruit).should be_viewable_by(u, :contributions)
+ end
+ end
+
+ it "should allow to edit and update users own contributons" do
+ recruit = Factory(:recruit)
+ recruit.should be_editable_by(recruit, :contributions)
+ recruit.contributions = "changed"
+ recruit.should be_updatable_by(recruit)
+ end
+
+ it "should allow admins to edit and update users contributons" do
+ recruit = Factory(:recruit)
+ recruit.should be_editable_by(Factory(:administrator), :contributions)
+ recruit.contributions = "changed"
+ recruit.should be_updatable_by(Factory(:administrator))
+ end
+
+ it "should prohibit non-admins to edit and update someone else contributons" do
+ recruit = Factory(:recruit)
+ for u in fabricate_users(:recruit, :mentor, :recruiter) + [Guest.new]
+ recruit.should_not be_editable_by(u, :contributions)
+ recruit.contributions = "changed"
+ recruit.should_not be_updatable_by(u)
+ end
+ end
end