Commit 107dbf62 by Hoang Phuc Do

Generate default products data by Faker

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