Commit 107dbf62 by Hoang Phuc Do

Generate default products data by Faker

parent 8870603e
...@@ -36,8 +36,9 @@ gem 'carrierwave', '~> 1.0' ...@@ -36,8 +36,9 @@ gem 'carrierwave', '~> 1.0'
gem 'mini_magick' gem 'mini_magick'
# bootstrap-sass is a Sass-powered version of Bootstrap 3 # bootstrap-sass is a Sass-powered version of Bootstrap 3
gem 'bootstrap-sass', '~> 3.3.6' gem 'bootstrap-sass', '~> 3.3.6'
# Vacuum is a fast, light-weight Ruby wrapper to the Amazon Product Advertising API # Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.
gem 'vacuum', '~> 1.4' gem 'faker', '~> 1.6', '>= 1.6.3'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
......
...@@ -71,8 +71,9 @@ GEM ...@@ -71,8 +71,9 @@ GEM
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
erubi (1.6.0) erubi (1.6.0)
excon (0.56.0)
execjs (2.7.0) execjs (2.7.0)
faker (1.6.6)
i18n (~> 0.5)
ffi (1.9.18) ffi (1.9.18)
globalid (0.4.0) globalid (0.4.0)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
...@@ -80,8 +81,6 @@ GEM ...@@ -80,8 +81,6 @@ GEM
jbuilder (2.7.0) jbuilder (2.7.0)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
multi_json (>= 1.2) multi_json (>= 1.2)
jeff (1.5.2)
excon (>= 0.22.1)
listen (3.1.5) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
...@@ -98,7 +97,6 @@ GEM ...@@ -98,7 +97,6 @@ GEM
mini_portile2 (2.2.0) mini_portile2 (2.2.0)
minitest (5.10.2) minitest (5.10.2)
multi_json (1.12.1) multi_json (1.12.1)
multi_xml (0.6.0)
mysql2 (0.4.6) mysql2 (0.4.6)
nio4r (2.1.0) nio4r (2.1.0)
nokogiri (1.8.0) nokogiri (1.8.0)
...@@ -170,9 +168,6 @@ GEM ...@@ -170,9 +168,6 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.2.0) uglifier (3.2.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
vacuum (1.4.1)
jeff (~> 1.0)
multi_xml (~> 0.6.0)
web-console (3.5.1) web-console (3.5.1)
actionview (>= 5.0) actionview (>= 5.0)
activemodel (>= 5.0) activemodel (>= 5.0)
...@@ -194,6 +189,7 @@ DEPENDENCIES ...@@ -194,6 +189,7 @@ DEPENDENCIES
capybara (~> 2.13) capybara (~> 2.13)
carrierwave (~> 1.0) carrierwave (~> 1.0)
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
faker (~> 1.6, >= 1.6.3)
jbuilder (~> 2.5) jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
mini_magick mini_magick
...@@ -207,7 +203,6 @@ DEPENDENCIES ...@@ -207,7 +203,6 @@ DEPENDENCIES
turbolinks (~> 5) turbolinks (~> 5)
tzinfo-data tzinfo-data
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
vacuum (~> 1.4)
web-console (>= 3.3.0) web-console (>= 3.3.0)
BUNDLED WITH BUNDLED WITH
......
...@@ -25,10 +25,7 @@ ActiveRecord::Schema.define(version: 20170606064132) do ...@@ -25,10 +25,7 @@ ActiveRecord::Schema.define(version: 20170606064132) do
t.bigint "category_id" t.bigint "category_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "image_file_name" t.string "image_url"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.index ["category_id"], name: "index_products_on_category_id" t.index ["category_id"], name: "index_products_on_category_id"
end end
......
...@@ -7,22 +7,20 @@ ...@@ -7,22 +7,20 @@
# Character.create(name: 'Luke', movie: movies.first) # Character.create(name: 'Luke', movie: movies.first)
# Create Product Categories # Create Product Categories
5.times do |n| 4.times do |n|
freq = n + 1 title = "Category #{n}"
title = "Category #{freq}" desc = Faker::Lorem.paragraphs
desc = "Description for category #{freq}"
Category.create!(title: title, description: desc) Category.create!(title: title, description: desc)
end end
# Create Products # Create Products
categories = Category.take(5) categories = Category.all
40.times do |n| 80.times do
freq = n + 1
title = "Product #{freq}"
desc = "Description for product #{freq}"
categories.each do |cat| categories.each do |cat|
title = Faker::Commerce.product_name
desc = Faker::Lorem.paragraphs
sku = "u-#{rand(1..999)}" sku = "u-#{rand(1..999)}"
price = (200.0 - 5.0) * rand + 5 price = Faker::Commerce.price
cat.products.create!(title: title, cat.products.create!(title: title,
description: desc, description: desc,
sku: sku, sku: sku,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment