crreate some basic scenarios

This commit is contained in:
Simon Rozet 2008-06-23 21:34:57 +02:00
parent b13df20630
commit 2672c1e2b7
4 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,17 @@
class ContextsScenario < Scenario::Base
def load
%w(Call Email Errand Someday).each_with_index do |context, index|
create_context context, index+1
end
end
def create_context(name, position)
create_model :context, name.downcase.to_sym,
:name => name,
:position => position,
:hide => name == 'Someday' ? true : false,
:created_at => Time.now,
:updated_at => Time.now,
:user_id => user_id(:sean)
end
end

View file

@ -0,0 +1,16 @@
class ProjectsScenario < Scenario::Base
def load
['Build a working time machin',
'Make more money than Billy Gates',
'Evict dinosaurs from the garden',
'Attend RailsConf'].each_with_index do |project, index|
create_record :project, project.split.first.downcase.to_sym,
:name => project,
:description => '',
:position => index + 1,
:state => 'active',
:created_at => Time.now,
:updated_at => Time.now
end
end
end

View file

@ -0,0 +1,16 @@
class TodosScenario < Scenario::Base
uses :contexts, :projects, :users
def load
create_record :todo, :billy,
:description => "Call Bill Gates to find out how much he makes per day",
:notes => "~",
:state => 'active',
:created_at => 1.week.ago,
:due => 2.weeks.from_now,
:completed_at => nil,
:context => context(:call),
:project_id => project_id(:make),
:user_id => user_id(:sean)
end
end

View file

@ -0,0 +1,23 @@
class UsersScenario < Scenario::Base
def load
create_preference
create_user :login => 'johnny', :first_name => 'Johnny', :last_name => 'Smith'
create_user :login => 'jane', :first_name => 'Jane', :last_name => 'Pilbeam'
create_user :login => 'sean', :first_name => 'Sean', :last_name => 'Pallmer'
end
def create_user(attributes={})
password = attributes[:login] + Time.now.to_s
attributes = {
:password => password,
:password_confirmation => password,
:is_admin => attributes[:is_admin] || false,
:preference => preferences(:default)
}.merge(attributes)
create_model :user, attributes[:login].downcase.to_sym, attributes
end
def create_preference
create_record :preference, :default, :show_number_completed => 5
end
end