Skip to content

Instantly share code, notes, and snippets.

@adam
Created August 14, 2008 15:36
Show Gist options
  • Save adam/5444 to your computer and use it in GitHub Desktop.
Save adam/5444 to your computer and use it in GitHub Desktop.
# this demonstrates using dm-fauxtures to fill an ticketing systems database with fixtures.
# invoke by using `rake app:setup`
namespace :app do
desc 'setup'
task :setup => ['dm:db:automigrate', 'app:create_base_users', 'app:create_base_projects']
task :create_base_users => :merb_env do
User.create(
:login => 'admin',
:email => 'adam@demo.com',
:password => 'sekrit',
:password_confirmation => 'sekrit',
:active => true
)
end
task :create_base_projects => [:merb_env] do
User.fixture {{
:login => /[:word:]/.gen,
:email => /\w+@\w+\.(com|org|edu|co\.uk|com\.au)/.gen,
:password => pwd = /\w+/.gen,
:password_confirmation => pwd,
:active => true
}}
Project.fixture {{
:name => /\w+ Inc/.gen.capitalize,
:description => /[:sentence:]{1,5}/.gen
}}
Ticket.fixture {{
:title => /[:sentence:]/.gen,
:description => /[:sentence:]{1,5}/.gen
}}
Comment.fixture {{
:body => /[:sentence:]{1,5}/.gen,
:user => User.all.entries.pick,
:ticket => Ticket.all.entries.pick
}}
users = 20.of { User.gen }
projects = 20.of { Project.gen }
50.of {
Ticket.gen(
:project => projects.pick,
:users => (1..10).of { users.pick }.uniq,
:comments => (1..10).of { Comment.gen }
)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment