diff options
author | 2011-05-27 11:05:06 +0200 | |
---|---|---|
committer | 2011-05-31 12:29:37 +0200 | |
commit | e624e5412322e7b1ea9c738408a2baae65d696b7 (patch) | |
tree | 43f1b42b85a6fdabc64e83127ae828d6d1767ff5 | |
parent | Improve ready recruits listing (diff) | |
download | recruiting-webapp-e624e5412322e7b1ea9c738408a2baae65d696b7.tar.gz recruiting-webapp-e624e5412322e7b1ea9c738408a2baae65d696b7.tar.bz2 recruiting-webapp-e624e5412322e7b1ea9c738408a2baae65d696b7.zip |
Add developer role
Fix bug:
https://bugs.gentoo.org/show_bug.cgi?id=368185
-rw-r--r-- | app/models/user.rb | 5 | ||||
-rw-r--r-- | app/rich_types/role.rb | 2 | ||||
-rw-r--r-- | features/developer_role.feature | 13 | ||||
-rw-r--r-- | features/step_definitions/within_steps.rb | 8 | ||||
-rw-r--r-- | spec/factories.rb | 7 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 27 |
6 files changed, 42 insertions, 20 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 87d9024..f49341d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -231,9 +231,8 @@ class User < ActiveRecord::Base # and make sure change to role wasn't changed or was promotion of recruit # to mentor or demotion of mentor to recruit return true unless role_changed? - return true if role.is_mentor? && RichTypes::Role.new(role_was).is_recruit? - return true if role.is_recruit? && RichTypes::Role.new(role_was).is_mentor? - + changable = [RichTypes::Role.new(:recruit), RichTypes::Role.new(:developer), RichTypes::Role.new(:mentor)] + return true if changable.include?(RichTypes::Role.new(role)) and changable.include?(RichTypes::Role.new(role_was)) false end diff --git a/app/rich_types/role.rb b/app/rich_types/role.rb index ae9b129..31faa50 100644 --- a/app/rich_types/role.rb +++ b/app/rich_types/role.rb @@ -13,5 +13,5 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. module RichTypes - Role = HoboFields::EnumString.for(:recruit, :mentor, :recruiter) + Role = HoboFields::EnumString.for(:recruit, :mentor, :developer, :recruiter) end diff --git a/features/developer_role.feature b/features/developer_role.feature new file mode 100644 index 0000000..0529c21 --- /dev/null +++ b/features/developer_role.feature @@ -0,0 +1,13 @@ +Feature: Developer role + In order to manage recruits + I want recruits who became developers + But can't be mentors yet + To have developer role + + Scenario: Make user a developer + Given I am logged in as "recruiter" who is "recruiter" + And user "recruit" who is "recruit" + When I am on edit "recruit" user page + And I select "Developer" from "user[role]" + And I press "Save" + Then I should see "developer" as a role diff --git a/features/step_definitions/within_steps.rb b/features/step_definitions/within_steps.rb new file mode 100644 index 0000000..3a3822d --- /dev/null +++ b/features/step_definitions/within_steps.rb @@ -0,0 +1,8 @@ +{ + 'as a role' => '.role-tag.view.user-role' +}. +each do |within, selector| + Then /^I should( not)? see "([^"]*)" #{within}$/ do |negation, text| + Then %Q{I should#{negation} see "#{text}" within "#{selector}"} + end +end diff --git a/spec/factories.rb b/spec/factories.rb index 5253103..58025bc 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -5,6 +5,13 @@ u.mentor { Factory(:mentor) } end + Factory.define :developer, :class => User do |u| + u.sequence(:name) { |n| "developer-#{n}" } + u.email_address { |u| "#{u.name}@developers.org" } + u.role :developer + u.nick { |u| u.name } + end + Factory.define :mentor, :class => User do |u| u.sequence(:name) { |n| "mentor-#{n}" } u.email_address { |u| "#{u.name}@recruiters.org" } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 76a1a45..89d5beb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -70,25 +70,20 @@ describe User do end end - it "should allow recruiter to promote recruits to mentors" do - recruit = Factory(:recruit) - recruit.role = :mentor - for user in [Factory(:recruiter), Factory(:administrator)] - recruit.should be_updatable_by(user) - recruit.should be_editable_by(user, :role) - 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) + it "should allow recruiter to change roles between recruit, developer and mentor" do + allowed_roles = [:recruit, :developer, :mentor] + for old_role in allowed_roles + for new_role in allowed_roles + user = Factory(old_role) + user.role = new_role + for user in [Factory(:recruiter), Factory(:administrator)] + user.should be_updatable_by(user) + user.should be_editable_by(user, :role) + end + end end end - it "should return proper all_questions" do r = recruit_with_answered_and_unanswered_questions |