Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Rake's Anatomy
- # dependency = task to run first
- #
- # desc "description"
- # task :name => :dependency (or array of dependencies) do
- # Ruby code
- # end
- #
- # Rake useful stuff in the console:
- # rake -T db
- # rake app:reset
- namespace :app do
- task :ensure_development_environment => :environment do
- if Rails.env.production?
- raise "\nSorry Buster, I can't do that.\n(R u outta ure mind? Drop production database?.)"
- end
- end
- desc "Reset database data."
- task :reset => [:ensure_development_environment, "db:drop", "db:create", "db:migrate", "db:seed", "app:populate"]
- desc "Populate the database with development data."
- task :populate => :environment do
- [
- {:nickname => "alessio", :email => "alessio.ijoomla@gmail.com",
- :password => "ronaldo", :user_type => "admin"}
- ].each do |attributes|
- User.find_or_create_by_nickname_and_email(attributes)
- end
- puts "Populated the user table"
- [
- {:title => "First article", :body => "Hey there!",
- :user_id => 1, :published_at => 7.months.ago,
- },
- {:title => "Second article", :body => "Hey there 2nd!",
- :user_id => 1, :published_at => 7.months.ago,
- },
- {:title => "First Ana Are MERE", :body => "Hey there!",
- :user_id => 1, :published_at => 6.months.ago,
- },
- {:title => "Man sigur are ana mere?", :body => "Hey there 2nd!",
- :user_id => 1, :published_at => 5.months.ago,
- },
- {:title => "jQuery", :body => "Hey there!",
- :user_id => 1, :published_at => 4.months.ago,
- },
- {:title => "VIM is the best test editor", :body => "Hey there 2nd!",
- :user_id => 1, :published_at => 1.year.ago,
- },
- {:title => "jQuery and Dojo are cool2", :body => "Hey there!",
- :user_id => 1, :published_at => 2.years.ago,
- },
- {:title => "jQuery and Dojo are cool3", :body => "Hey there!",
- :user_id => 1, :published_at => 1.month.ago,
- },
- {:title => "jQuery and Dojo are cool4", :body => "Hey there!",
- :user_id => 1, :published_at => 1.month.ago,
- },
- {:title => "jQuery and Dojo are cool", :body => "Hey there!",
- :user_id => 1, :published_at => Date.today,
- },
- {:title => "Bum bum bum", :body => "Hey there 2nd!",
- :user_id => 1, :published_at => Date.today,
- }
- ].each do |attributes|
- Article.find_or_create_by_title(attributes)
- end
- puts "Populated the article table"
- # user = User.find(1)
- # user.articles.create :title => 'Advanced Active Record',
- # :body => "It's about the power of Models in Rails!",
- # :published_at => Date.today
- # user.articles.create :title => "One-to-many associations",
- # :body => "Bum bum bum bum",
- # :published_at => Date.today
- [
- {:name => "Ruby"},
- {:name => "Rails"},
- {:name => "PHP"},
- {:name => "Joomla"},
- {:name => "Node"},
- {:name => "JavaScript"},
- {:name => "jQuery"}
- ].each do |attributes|
- Category.find_or_create_by_name(attributes)
- end
- puts "Populated the category table"
- first = Article.first
- first.categories << Category.first
- first.tag_list = "plugins, development, article"
- first.save
- puts "Add a category & tags to the first article"
- end
- end
Add Comment
Please, Sign In to add comment