Guest User

Untitled

a guest
Dec 14th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. # Rake's Anatomy
  2. # dependency = task to run first
  3. #
  4. # desc "description"
  5. # task :name => :dependency (or array of dependencies) do
  6. # Ruby code
  7. # end
  8. #
  9. # Rake useful stuff in the console:
  10. # rake -T db
  11. # rake app:reset
  12.  
  13. namespace :app do
  14.  
  15. task :ensure_development_environment => :environment do
  16. if Rails.env.production?
  17. raise "\nSorry Buster, I can't do that.\n(R u outta ure mind? Drop production database?.)"
  18. end
  19. end
  20.  
  21. desc "Reset database data."
  22. task :reset => [:ensure_development_environment, "db:drop", "db:create", "db:migrate", "db:seed", "app:populate"]
  23.  
  24. desc "Populate the database with development data."
  25. task :populate => :environment do
  26. [
  27. {:nickname => "alessio", :email => "alessio.ijoomla@gmail.com",
  28. :password => "ronaldo", :user_type => "admin"}
  29. ].each do |attributes|
  30. User.find_or_create_by_nickname_and_email(attributes)
  31. end
  32. puts "Populated the user table"
  33.  
  34. [
  35. {:title => "First article", :body => "Hey there!",
  36. :user_id => 1, :published_at => 7.months.ago,
  37. },
  38. {:title => "Second article", :body => "Hey there 2nd!",
  39. :user_id => 1, :published_at => 7.months.ago,
  40. },
  41. {:title => "First Ana Are MERE", :body => "Hey there!",
  42. :user_id => 1, :published_at => 6.months.ago,
  43. },
  44. {:title => "Man sigur are ana mere?", :body => "Hey there 2nd!",
  45. :user_id => 1, :published_at => 5.months.ago,
  46. },
  47. {:title => "jQuery", :body => "Hey there!",
  48. :user_id => 1, :published_at => 4.months.ago,
  49. },
  50. {:title => "VIM is the best test editor", :body => "Hey there 2nd!",
  51. :user_id => 1, :published_at => 1.year.ago,
  52. },
  53. {:title => "jQuery and Dojo are cool2", :body => "Hey there!",
  54. :user_id => 1, :published_at => 2.years.ago,
  55. },
  56. {:title => "jQuery and Dojo are cool3", :body => "Hey there!",
  57. :user_id => 1, :published_at => 1.month.ago,
  58. },
  59. {:title => "jQuery and Dojo are cool4", :body => "Hey there!",
  60. :user_id => 1, :published_at => 1.month.ago,
  61. },
  62. {:title => "jQuery and Dojo are cool", :body => "Hey there!",
  63. :user_id => 1, :published_at => Date.today,
  64. },
  65. {:title => "Bum bum bum", :body => "Hey there 2nd!",
  66. :user_id => 1, :published_at => Date.today,
  67. }
  68. ].each do |attributes|
  69. Article.find_or_create_by_title(attributes)
  70. end
  71. puts "Populated the article table"
  72.  
  73. # user = User.find(1)
  74. # user.articles.create :title => 'Advanced Active Record',
  75. # :body => "It's about the power of Models in Rails!",
  76. # :published_at => Date.today
  77. # user.articles.create :title => "One-to-many associations",
  78. # :body => "Bum bum bum bum",
  79. # :published_at => Date.today
  80.  
  81. [
  82. {:name => "Ruby"},
  83. {:name => "Rails"},
  84. {:name => "PHP"},
  85. {:name => "Joomla"},
  86. {:name => "Node"},
  87. {:name => "JavaScript"},
  88. {:name => "jQuery"}
  89. ].each do |attributes|
  90. Category.find_or_create_by_name(attributes)
  91. end
  92. puts "Populated the category table"
  93.  
  94. first = Article.first
  95. first.categories << Category.first
  96. first.tag_list = "plugins, development, article"
  97. first.save
  98. puts "Add a category & tags to the first article"
  99.  
  100. end
  101.  
  102. end
Add Comment
Please, Sign In to add comment