From 2672c1e2b701c4054ae2930bd0e304781d19869a Mon Sep 17 00:00:00 2001 From: Simon Rozet Date: Mon, 23 Jun 2008 21:34:57 +0200 Subject: [PATCH] crreate some basic scenarios --- spec/scenarios/contexts_scenario.rb | 17 +++++++++++++++++ spec/scenarios/projects_scenario.rb | 16 ++++++++++++++++ spec/scenarios/todos_scenario.rb | 16 ++++++++++++++++ spec/scenarios/users_scenario.rb | 23 +++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 spec/scenarios/contexts_scenario.rb create mode 100644 spec/scenarios/projects_scenario.rb create mode 100644 spec/scenarios/todos_scenario.rb create mode 100644 spec/scenarios/users_scenario.rb diff --git a/spec/scenarios/contexts_scenario.rb b/spec/scenarios/contexts_scenario.rb new file mode 100644 index 00000000..9b4b3bce --- /dev/null +++ b/spec/scenarios/contexts_scenario.rb @@ -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 diff --git a/spec/scenarios/projects_scenario.rb b/spec/scenarios/projects_scenario.rb new file mode 100644 index 00000000..a0f94347 --- /dev/null +++ b/spec/scenarios/projects_scenario.rb @@ -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 diff --git a/spec/scenarios/todos_scenario.rb b/spec/scenarios/todos_scenario.rb new file mode 100644 index 00000000..e073ec2e --- /dev/null +++ b/spec/scenarios/todos_scenario.rb @@ -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 diff --git a/spec/scenarios/users_scenario.rb b/spec/scenarios/users_scenario.rb new file mode 100644 index 00000000..a8c7b05c --- /dev/null +++ b/spec/scenarios/users_scenario.rb @@ -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