comable_sample 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 248bc7d89964286fc486d7638f048f2bb3eea7fc
4
+ data.tar.gz: 3e45ac70710d173e9121d5a547f5553f4715858c
5
+ SHA512:
6
+ metadata.gz: 47cd9239b893fa61b967a147a56a56918579c05a99b6d5240dece6078d9549569fc1bc57b799a0dfb71c7e9ce4f42cd037e519e099dfa41d68fe92c42afa156e
7
+ data.tar.gz: 7066c58099b7e64a1f07b16c181071b5cb26313487e9432c97de3b3af78844eed69b589a55ac3cc195b3d7ff2a30fe80b97a158abc08e252f240c6889e013166
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOSHIDA Hiroki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,97 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Comable'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
17
+ load 'rails/tasks/engine.rake'
18
+
19
+ def command(string)
20
+ puts string
21
+ system string
22
+ end
23
+
24
+ if File.exist?('comable.gemspec')
25
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
26
+ require 'tasks/release'
27
+
28
+ namespace :app do
29
+ namespace :spec do
30
+ desc 'Run the code examples'
31
+ RSpec::Core::RakeTask.new(:all) do |t|
32
+ FRAMEWORKS.each do |framework|
33
+ t.pattern << ",#{framework}/spec/**{,/*/**}/*_spec.rb"
34
+ end
35
+ end
36
+
37
+ FRAMEWORKS.each do |framework|
38
+ desc "Run the code examples in #{framework}/spec"
39
+ RSpec::Core::RakeTask.new(framework) do |t|
40
+ t.pattern = "../#{framework}/spec/**{,/*/**}/*_spec.rb"
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ namespace :db do
47
+ task 'migrate' => 'app:db:migrate'
48
+ task 'app:db:migrate' => 'migrate:all'
49
+
50
+ namespace :migrate do
51
+ task :all do
52
+ FRAMEWORKS.each do |framework|
53
+ command "cd #{framework} && test -d db/migrate && bundle exec rake db:migrate RAILS_ENV=#{Rails.env}"
54
+ end
55
+ end
56
+ end
57
+
58
+ namespace :migrate do
59
+ task 'reset' => 'app:db:migrate:reset'
60
+ task 'app:db:migrate:reset' => 'app:db:migrate'
61
+ task 'app:db:migrate' => 'reset:all'
62
+
63
+ namespace :reset do
64
+ task :all do
65
+ command "bundle exec rake db:drop db:create RAILS_ENV=#{Rails.env}"
66
+ Rake::Task['db:migrate'].invoke
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ task default: ['app:spec:all', 'rubocop', 'brakeman:all']
73
+ else
74
+ task default: ['app:spec', 'rubocop', 'brakeman']
75
+ end
76
+
77
+ Bundler::GemHelper.install_tasks
78
+
79
+ # from https://github.com/rspec/rspec-rails/issues/936
80
+ task 'test:prepare'
81
+
82
+ task :rubocop do
83
+ sh 'rubocop'
84
+ end
85
+
86
+ task :brakeman do
87
+ sh 'brakeman --exit-on-warn --ignore-config .brakeman.ignore'
88
+ end
89
+
90
+ namespace :brakeman do
91
+ task :all do
92
+ FRAMEWORKS.each do |framework|
93
+ next unless File.directory?("#{framework}/app")
94
+ sh "brakeman --exit-on-warn --ignore-config .brakeman.ignore #{framework}"
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,21 @@
1
+ # Billing address
2
+ Comable::Address.create!(
3
+ family_name: Comable::Sample::Name.family_name,
4
+ first_name: Comable::Sample::Name.first_name,
5
+ zip_code: Comable::Sample::Address.zip_code,
6
+ state_name: Comable::Sample::Address.state_name,
7
+ city: Comable::Sample::Address.city,
8
+ detail: Comable::Sample::Address.detail,
9
+ phone_number: Comable::Sample::PhoneNumber.phone_number
10
+ )
11
+
12
+ # Shipping address
13
+ Comable::Address.create!(
14
+ family_name: Comable::Sample::Name.family_name,
15
+ first_name: Comable::Sample::Name.first_name,
16
+ zip_code: Comable::Sample::Address.zip_code,
17
+ state_name: Comable::Sample::Address.state_name,
18
+ city: Comable::Sample::Address.city,
19
+ detail: Comable::Sample::Address.detail,
20
+ phone_number: Comable::Sample::PhoneNumber.phone_number
21
+ )
@@ -0,0 +1 @@
1
+ Comable::Category.create!(name: Comable::Sample.t(:clothing))
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,46 @@
1
+ Comable::Sample.import('products')
2
+
3
+ suede_dress = Comable::Product.where(name: Comable::Sample.t(:suede_dress)).first!
4
+ girly_coat = Comable::Product.where(name: Comable::Sample.t(:girly_coat)).first!
5
+ fur_gloves = Comable::Product.where(name: Comable::Sample.t(:fur_gloves)).first!
6
+ leather_boots = Comable::Product.where(name: Comable::Sample.t(:leather_boots)).first!
7
+
8
+ def image(name, suffix: '.jpg')
9
+ image_path = File.join(File.dirname(__FILE__), 'images', name + suffix)
10
+ File.open(image_path)
11
+ end
12
+
13
+ images_attributes = [
14
+ {
15
+ product: suede_dress,
16
+ file: image('suede_dress')
17
+ },
18
+ {
19
+ product: suede_dress,
20
+ file: image('suede_dress_full')
21
+ },
22
+ {
23
+ product: girly_coat,
24
+ file: image('girly_coat')
25
+ },
26
+ {
27
+ product: fur_gloves,
28
+ file: image('fur_gloves')
29
+ },
30
+ {
31
+ product: leather_boots,
32
+ file: image('leather_boots')
33
+ },
34
+ {
35
+ product: leather_boots,
36
+ file: image('leather_boots_front')
37
+ },
38
+ {
39
+ product: leather_boots,
40
+ file: image('leather_boots_back')
41
+ }
42
+ ]
43
+
44
+ images_attributes.each do |attributes|
45
+ Comable::Image.create!(attributes)
46
+ end
@@ -0,0 +1,51 @@
1
+ Comable::Sample.import('products')
2
+ Comable::Sample.import('stocks')
3
+ Comable::Sample.import('addresses')
4
+
5
+ bill_address = Comable::Address.first
6
+ ship_address = Comable::Address.last
7
+ suede_dress = Comable::Product.where(name: Comable::Sample.t(:suede_dress)).first!
8
+ girly_coat = Comable::Product.where(name: Comable::Sample.t(:girly_coat)).first!
9
+
10
+ orders_attributes = [
11
+ {
12
+ email: 'comable@example.com',
13
+ bill_address: bill_address,
14
+ ship_address: ship_address,
15
+ shipment_fee: 300,
16
+ payment_fee: 200,
17
+ total_price: 500 + suede_dress.price,
18
+ order_items_attributes: [
19
+ {
20
+ stock: suede_dress.stocks.first,
21
+ quantity: 1
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ email: 'comable@example.com',
27
+ bill_address: bill_address,
28
+ ship_address: ship_address,
29
+ shipment_fee: 300,
30
+ payment_fee: 200,
31
+ total_price: 500 + (suede_dress.price * 2) + (girly_coat.price * 3),
32
+ order_items_attributes: [
33
+ {
34
+ stock: suede_dress.stocks.first,
35
+ quantity: 2
36
+ },
37
+ {
38
+ stock: girly_coat.stocks.first,
39
+ quantity: 3
40
+ }
41
+ ]
42
+ }
43
+ ]
44
+
45
+ orders_attributes.each do |attributes|
46
+ order = Comable::Order.create!(attributes)
47
+ order.send(:generate_code)
48
+ order.state = 'completed'
49
+ order.completed_at = Time.now
50
+ order.save!
51
+ end
@@ -0,0 +1,6 @@
1
+ Comable::PaymentMethod.create!(
2
+ name: Comable::Sample.t(:credit_card),
3
+ fee: 200,
4
+ payment_provider_type: Comable::PaymentProvider::General.name,
5
+ payment_provider_kind: 1
6
+ )
@@ -0,0 +1,11 @@
1
+ Comable::Sample.import('orders')
2
+ Comable::Sample.import('payment_methods')
3
+
4
+ payment_method = Comable::PaymentMethod.first
5
+
6
+ Comable::Order.complete.each do |order|
7
+ payment = order.create_payment!(payment_method: payment_method, fee: payment_method.fee)
8
+ payment.state = 'completed'
9
+ payment.completed_at = Time.now
10
+ payment.save!
11
+ end
@@ -0,0 +1,33 @@
1
+ Comable::Sample.import('categories')
2
+
3
+ clothing = Comable::Category.where(name: Comable::Sample.t(:clothing)).first!
4
+
5
+ products_attributes = [
6
+ {
7
+ name: Comable::Sample.t(:suede_dress),
8
+ price: 6_990,
9
+ categories: [clothing]
10
+ },
11
+ {
12
+ name: Comable::Sample.t(:girly_coat),
13
+ price: 9_000,
14
+ categories: [clothing]
15
+ },
16
+ {
17
+ name: Comable::Sample.t(:fur_gloves),
18
+ price: 5_292,
19
+ categories: [clothing]
20
+ },
21
+ {
22
+ name: Comable::Sample.t(:leather_boots),
23
+ price: 28_080,
24
+ categories: [clothing]
25
+ }
26
+ ]
27
+
28
+ next_id = (Comable::Product.maximum(:id) || 0).next
29
+
30
+ products_attributes.each.with_index(next_id) do |attributes, index|
31
+ code = format('%05d', index)
32
+ Comable::Product.create!(attributes.merge(code: code))
33
+ end
@@ -0,0 +1,4 @@
1
+ Comable::ShipmentMethod.create!(
2
+ name: Comable::Sample.t(:black_cat),
3
+ fee: 300
4
+ )
@@ -0,0 +1,10 @@
1
+ Comable::Sample.import('orders')
2
+ Comable::Sample.import('shipment_methods')
3
+
4
+ shipment_method = Comable::ShipmentMethod.first
5
+
6
+ Comable::Order.complete.each do |order|
7
+ shipment = order.create_shipment!(shipment_method: shipment_method, fee: shipment_method.fee)
8
+ shipment.state = 'ready'
9
+ shipment.save!
10
+ end
@@ -0,0 +1,78 @@
1
+ Comable::Sample.import('products')
2
+
3
+ suede_dress = Comable::Product.where(name: Comable::Sample.t(:suede_dress)).first!
4
+ girly_coat = Comable::Product.where(name: Comable::Sample.t(:girly_coat)).first!
5
+ fur_gloves = Comable::Product.where(name: Comable::Sample.t(:fur_gloves)).first!
6
+ leather_boots = Comable::Product.where(name: Comable::Sample.t(:leather_boots)).first!
7
+
8
+ suede_dress.update_attributes!(sku_h_item_name: Comable::Sample.t(:size), sku_v_item_name: Comable::Sample.t(:color))
9
+ girly_coat.update_attributes!(sku_h_item_name: Comable::Sample.t(:size), sku_v_item_name: Comable::Sample.t(:color))
10
+ leather_boots.update_attributes!(sku_h_item_name: Comable::Sample.t(:size))
11
+
12
+ default_stock_attributes = {
13
+ quantity: 10
14
+ }
15
+
16
+ stocks_attributes = [
17
+ {
18
+ product: suede_dress,
19
+ code: "#{suede_dress.code}-SN",
20
+ sku_h_choice_name: 'S',
21
+ sku_v_choice_name: Comable::Sample.t(:navy)
22
+ },
23
+ {
24
+ product: suede_dress,
25
+ code: "#{suede_dress.code}-MN",
26
+ sku_h_choice_name: 'M',
27
+ sku_v_choice_name: Comable::Sample.t(:navy)
28
+ },
29
+ {
30
+ product: girly_coat,
31
+ code: "#{girly_coat.code}-SB",
32
+ sku_h_choice_name: 'S',
33
+ sku_v_choice_name: Comable::Sample.t(:beige)
34
+ },
35
+ {
36
+ product: girly_coat,
37
+ code: "#{girly_coat.code}-MB",
38
+ sku_h_choice_name: 'M',
39
+ sku_v_choice_name: Comable::Sample.t(:beige)
40
+ },
41
+ {
42
+ product: girly_coat,
43
+ code: "#{girly_coat.code}-SN",
44
+ sku_h_choice_name: 'S',
45
+ sku_v_choice_name: Comable::Sample.t(:navy)
46
+ },
47
+ {
48
+ product: girly_coat,
49
+ code: "#{girly_coat.code}-MN",
50
+ sku_h_choice_name: 'M',
51
+ sku_v_choice_name: Comable::Sample.t(:navy)
52
+ },
53
+ {
54
+ product: fur_gloves,
55
+ code: fur_gloves.code
56
+ },
57
+ {
58
+ product: leather_boots,
59
+ code: "#{leather_boots.code}-S",
60
+ sku_h_choice_name: 'S',
61
+ quantity: 0
62
+ },
63
+ {
64
+ product: leather_boots,
65
+ code: "#{leather_boots.code}-M",
66
+ sku_h_choice_name: 'M',
67
+ quantity: 1
68
+ },
69
+ {
70
+ product: leather_boots,
71
+ code: "#{leather_boots.code}-L",
72
+ sku_h_choice_name: 'L'
73
+ }
74
+ ]
75
+
76
+ stocks_attributes.each do |attributes|
77
+ Comable::Stock.create!(default_stock_attributes.merge(attributes))
78
+ end
@@ -0,0 +1,23 @@
1
+ module Comable
2
+ module Sample
3
+ module Address
4
+ class << self
5
+ def zip_code
6
+ FFaker::AddressUS.zip_code
7
+ end
8
+
9
+ def state_name
10
+ FFaker::AddressUS.state
11
+ end
12
+
13
+ def city
14
+ FFaker::AddressUS.city
15
+ end
16
+
17
+ def detail
18
+ FFaker::AddressUS.street_address
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ module Comable
2
+ module Sample
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module Comable
2
+ module Sample
3
+ module Name
4
+ class << self
5
+ def family_name
6
+ FFaker::Name.last_name
7
+ end
8
+
9
+ def first_name
10
+ FFaker::Name.first_name
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Comable
2
+ module Sample
3
+ module PhoneNumber
4
+ class << self
5
+ def phone_number
6
+ FFaker::PhoneNumber.phone_number
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ module Comable
2
+ module Sample
3
+ class << self
4
+ def translate(key, options = {})
5
+ Comable.translate("sample.#{key}", options)
6
+ end
7
+
8
+ alias_method :t, :translate
9
+
10
+ def import_all
11
+ definitions.each do |definition|
12
+ import(definition)
13
+ end
14
+ end
15
+
16
+ def import(filename)
17
+ filepath = Rails.root.join("db/samples/#{filename}.rb")
18
+ filepath = "#{default_dir}/#{filename}.rb" unless File.exist?(filepath)
19
+ require File.expand_path(filepath)
20
+ end
21
+
22
+ private
23
+
24
+ def definitions
25
+ Dir["#{default_dir}/*.rb"].map do |filepath|
26
+ File.basename(filepath, '.rb')
27
+ end
28
+ end
29
+
30
+ def default_dir
31
+ "#{File.dirname(__FILE__)}/../../db/samples"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'ffaker'
2
+
3
+ require 'comable_core'
4
+
5
+ require 'comable/sample'
6
+ require 'comable/sample/engine'
7
+ require 'comable/sample/address'
8
+ require 'comable/sample/name'
9
+ require 'comable/sample/phone_number'
@@ -0,0 +1,6 @@
1
+ namespace :comable do
2
+ desc 'Imports sample data'
3
+ task sample: :environment do
4
+ Comable::Sample.import_all
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comable_sample
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ platform: ruby
6
+ authors:
7
+ - YOSHIDA Hiroki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: comable_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffaker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ description: Provide sample data for Comable.
42
+ email:
43
+ - hyoshida@appirits.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - Rakefile
50
+ - db/samples/addresses.rb
51
+ - db/samples/categories.rb
52
+ - db/samples/images.rb
53
+ - db/samples/images/fur_gloves.jpg
54
+ - db/samples/images/girly_coat.jpg
55
+ - db/samples/images/leather_boots.jpg
56
+ - db/samples/images/leather_boots_back.jpg
57
+ - db/samples/images/leather_boots_front.jpg
58
+ - db/samples/images/suede_dress.jpg
59
+ - db/samples/images/suede_dress_full.jpg
60
+ - db/samples/orders.rb
61
+ - db/samples/payment_methods.rb
62
+ - db/samples/payments.rb
63
+ - db/samples/products.rb
64
+ - db/samples/shipment_methods.rb
65
+ - db/samples/shipments.rb
66
+ - db/samples/stocks.rb
67
+ - lib/comable/sample.rb
68
+ - lib/comable/sample/address.rb
69
+ - lib/comable/sample/engine.rb
70
+ - lib/comable/sample/name.rb
71
+ - lib/comable/sample/phone_number.rb
72
+ - lib/comable_sample.rb
73
+ - lib/tasks/sample.rake
74
+ homepage: https://github.com/appirits/comable#comable
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Provide sample data for Comable.
98
+ test_files: []
99
+ has_rdoc: