diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2013-12-23 13:15:45 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2013-12-23 13:16:09 +0100 |
commit | 08da7a61bf78b6d2e1ca51815495e25f1c91ed86 (patch) | |
tree | 0d92173901ad74f7eb7800ae389a1aefd7e6c93f /lib/tasks | |
parent | 190f5b618788efa3baad5f52c393ab50c1c6e9b5 (diff) | |
download | hmnoweb-08da7a61bf78b6d2e1ca51815495e25f1c91ed86.tar.gz hmnoweb-08da7a61bf78b6d2e1ca51815495e25f1c91ed86.tar.bz2 hmnoweb-08da7a61bf78b6d2e1ca51815495e25f1c91ed86.zip |
Add rake task to generate sample data.
Run `rake dev:load_sample_data` to populate the database with
sample data. This creates the following:
- The categories [Nyheter, Intervjuer, Anmeldelser, Artikler]
- A "sample user" we can use as the author of posts.
- 5 blog posts in each category.
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/dev_load_sample_data.rake | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/tasks/dev_load_sample_data.rake b/lib/tasks/dev_load_sample_data.rake new file mode 100644 index 0000000..230ce95 --- /dev/null +++ b/lib/tasks/dev_load_sample_data.rake @@ -0,0 +1,35 @@ +namespace :dev do + task :create_sample_user => [:environment] do + Refinery::User.create(:username => "sample user", + :email => "email@sample.com", + :password => "test", + :password_confirmation => "test") + end + + task :create_blog_categories => [:environment] do + cats = %w{ Nyheter Intervjuer Anmeldelser Artikler } + cats.each do |cat| + Refinery::Blog::Category.create(:title => cat) + end + end + + task :create_blog_posts => [:environment, :create_blog_categories, :create_sample_user] do + cats = Refinery::Blog::Category.all + user = Refinery::User.find_by_username("sample user") + cats.each do |cat| + (1..5).each do |n| + p = Refinery::Blog::Post.create(:title => "#{cat.title} post #{n}", + :body => Lorem::Base.new(:paragraphs, 5).output, + :user_id => user.id, + :draft => false) + p.published_at = DateTime.now + p.save + end + end + end + + + desc "Load sample data into database" + task :load_sample_data => [:create_sample_user, :create_blog_categories, :create_blog_posts] + +end |