aboutsummaryrefslogblamecommitdiffstats
path: root/lib/tasks/dev_load_sample_data.rake
blob: da43843445b1fccf54c9a17b902240bec6819cce (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                            










                                                           



                                                                              



                                                                                            

                               



                                                         
                                                                        
                                                                                                    

                                                         
                                     
                           









                                                                                              
# This file is part of hmnoweb, a RefineryCMS based Webapp for heavymetal.no
# Copyright (C) 2018  Harald Eilertsen <haraldei@anduin.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

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|
      pos = 0
      pos = 1 if cat == "Nyheter"
      pos = 2 if cat == "Anmeldelser"
      Refinery::Blog::Category.create(:title => cat, :sidebar_position => pos)
    end
  end

  task :create_blog_posts => [:environment, :create_blog_categories, :create_sample_user] do
    include ActionView::Helpers

    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.new(:title => "#{cat.title} post #{n}",
                                     :body => simple_format(Lorem::Base.new(:paragraphs, 5).output),
                                     :user_id => user.id,
                                     :draft => false)
        p.published_at = DateTime.now
        p.categories << cat
        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