Browse files

Refactored db:seed

  • Loading branch information...
1 parent 6de1788 commit 0c08ffb4dcf56b6c53de66ce1a1f4bf6a250c549 @spob committed Nov 27, 2010
Showing with 44 additions and 31 deletions.
  1. +8 −0 config/sphinx.yml
  2. +36 −31 lib/tasks/seed.rake
View
8 config/sphinx.yml
@@ -4,3 +4,11 @@ development:
min_infix_len: 1
# bin_path: 'c:/sphinx/bin'
bin_path: '/usr/local/bin'
+production:
+ enable_star: 1
+ min_infix_len: 1
+ max_matches: 5000
+ morphology: stem_en
+ html_strip: 1
+# bin_path: 'c:/sphinx/bin'
+ bin_path: '/usr/local/bin'
View
67 lib/tasks/seed.rake
@@ -12,58 +12,63 @@ namespace :db do
task :seed_users => :environment do
enterprise = Enterprise.find(:first)
User.with_options :password => 'changeme', :password_confirmation => 'changeme',
- :salt => 'sodiumchrolide', :enterprise_id => enterprise.id,
- :activated_at => Time.now do |u|
+ :salt => 'sodiumchrolide', :enterprise_id => enterprise.id,
+ :activated_at => Time.now do |u|
- u.create!({ :email => 'admin@openmindsw.com',
- :last_name => "Admin" })
+ u.create!({:email => 'admin@openmindsw.com',
+ :last_name => "Admin"})
- u.create!({ :email => 'prodmgr@openmindsw.com',
- :last_name => "ProdMgr" })
+ u.create!({:email => 'prodmgr@openmindsw.com',
+ :last_name => "ProdMgr"})
- u.create!({ :email => 'voter@openmindsw.com',
- :last_name => "Voter" })
+ u.create!({:email => 'voter@openmindsw.com',
+ :last_name => "Voter"})
- u.create!({ :email => 'readonly@openmindsw.com',
- :last_name => "ReadOnly" })
+ u.create!({:email => 'readonly@openmindsw.com',
+ :last_name => "ReadOnly"})
- u.create!({ :email => 'allocmgr@openmindsw.com',
- :last_name => "AllocMgr" })
+ u.create!({:email => 'allocmgr@openmindsw.com',
+ :last_name => "AllocMgr"})
- u.create!({ :email => 'all@openmindsw.com',
- :last_name => "All" })
- end
+ u.create!({:email => 'all@openmindsw.com',
+ :last_name => "All"})
+ end
# Now set all users as activated
User.update_all ['activated_at = ?', Time.now]
end
desc "Seed the database with user roles"
task :seed_roles => :environment do
- Role.create(:title => "sysadmin",
- :description => "System Admininistrator",
- :default_role => false)
- Role.create(:title => "prodmgr",
- :description => "Product Manager",
- :default_role => false)
- Role.create(:title => "voter",
- :description => "Voter",
- :default_role => true)
- Role.create(:title => "allocmgr",
- :description => "Allocations Manager",
- :default_role => false)
+ create_role("sysadmin", "System Administrator", false)
+ create_role("prodmgr", "Product Manager", false)
+ create_role("voter", "Voter", true)
+ create_role("mediator", "Forum Moderator", false)
+ create_role("allocmgr", "Allocations Manager", false)
assign_user 'admin@openmindsw.com', "sysadmin"
assign_user 'prodmgr@openmindsw.com', "prodmgr"
assign_user 'voter@openmindsw.com', "voter"
assign_user 'allocmgr@openmindsw.com', "allocmgr"
- assign_user 'all@openmindsw.com', [ "voter", "sysadmin", "prodmgr", "allocmgr" ]
+ assign_user 'all@openmindsw.com', ["voter", "sysadmin", "prodmgr", "allocmgr"]
end
+ private
+
def assign_user(user_name, role_names)
user = User.find_by_email(user_name)
- throw "User not found: '#{user_name}'" if user.nil?
- roles = Role.find :all, :conditions => { :title => role_names }
- user.roles << roles
+# throw "User not found: '#{user_name}'" if user.nil?
+ if user.nil?
+ puts "User not found: '#{user_name}'"
+ else
+ roles = Role.find :all, :conditions => {:title => role_names}
+ user.roles << roles
+ end
+ end
+
+ def create_role(title, description, default)
+ Role.create(:title => title,
+ :description => description,
+ :default_role => default) unless Role.find_by_title(title)
end
end

0 comments on commit 0c08ffb

Please sign in to comment.