Archived
Add methods to work with manager role,add task to build user test data
This commit is contained in:
1 parent
18a82d7f47
commit
4df8ab6cc3
2 files changed
+78
-24
No files matched your search
@@ -0,0 +1,29 @@
|
||||
# encoding: utf-8
|
||||
namespace :user do
|
||||
|
||||
task :build => :environment do
|
||||
User.all(conditions: {email: /nor/}).destroy_all
|
||||
|
||||
username_list = %w{nor1 nor2 nor3 nor4 nor5 nor6 nor7}
|
||||
userfirstname_list_en = %w{ One Two Thre For Fiv Six Sen }
|
||||
userlastname_list_en = %w{ Aa Bb Cc Dd Ee Ff Gg }
|
||||
|
||||
userfirstname_list_ct = %w{ 一一 二二 三三 四四 五五 六六 七七 }
|
||||
userlastname_list_ct = %w{ 陳 林 吳 李 鄭 方 王 }
|
||||
|
||||
first_name_field = AttributeField.first(conditions: {key: "first_name"})
|
||||
last_name_field = AttributeField.first(conditions: {key: "last_name"})
|
||||
major_field = AttributeField.first(conditions: {key: "major"})
|
||||
department_field = AttributeField.first(conditions: {key: "department"})
|
||||
|
||||
stud_role = Role.first(conditions: {key: 'student'})
|
||||
|
||||
username_list.each_with_index do |username,index|
|
||||
user = User.create( :email => "#{username}@rulingcom.com", :password => 'password', :password_confirmation => 'password', :admin => false ,:role_id => stud_role.id,:sub_role_ids => [stud_role.sub_roles[Random.rand(stud_role.sub_roles.count-1)].id])
|
||||
AttributeValue.create( :user_id => user.id, :attribute_field_id => first_name_field.id, :key => 'first_name', :en => userfirstname_list_en[index], :zh_tw => userfirstname_list_ct[index] )
|
||||
AttributeValue.create( :user_id => user.id, :attribute_field_id => last_name_field.id, :key => 'last_name', :en => userlastname_list_en[index], :zh_tw => userlastname_list_ct[index] )
|
||||
AttributeValue.create( :user_id => user.id, :attribute_field_id => major_field.id, :key => 'major', :en => 'Information management', :zh_tw => '信息化管理' )
|
||||
AttributeValue.create( :user_id => user.id, :attribute_field_id => department_field.id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' )
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user