workarea-google_product_feed 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/CHANGELOG.md +99 -0
  4. data/Gemfile +10 -0
  5. data/README.md +61 -0
  6. data/Rakefile +53 -0
  7. data/app/models/workarea/catalog/category.decorator +7 -0
  8. data/app/models/workarea/catalog/product.decorator +7 -0
  9. data/app/models/workarea/feed/google.rb +16 -0
  10. data/app/view_models/workarea/storefront/google_product_feed_sku_view_model.rb +26 -0
  11. data/app/view_models/workarea/storefront/google_product_feed_view_model.rb +125 -0
  12. data/app/workers/workarea/exporting/google_feed.rb +90 -0
  13. data/bin/rails +18 -0
  14. data/config/initializers/00_scheduled_jobs.rb +6 -0
  15. data/config/initializers/01_configuration.rb +7 -0
  16. data/config/routes.rb +6 -0
  17. data/lib/workarea/google_product_feed.rb +32 -0
  18. data/lib/workarea/google_product_feed/engine.rb +8 -0
  19. data/lib/workarea/google_product_feed/version.rb +5 -0
  20. data/script/admin_ci +9 -0
  21. data/script/ci +11 -0
  22. data/script/core_ci +9 -0
  23. data/script/plugins_ci +9 -0
  24. data/script/storefront_ci +9 -0
  25. data/test/dummy/Rakefile +6 -0
  26. data/test/dummy/app/assets/config/manifest.js +4 -0
  27. data/test/dummy/app/assets/images/.keep +0 -0
  28. data/test/dummy/app/assets/javascripts/application.js +13 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/controllers/concerns/.keep +0 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/jobs/application_job.rb +2 -0
  34. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  35. data/test/dummy/app/models/concerns/.keep +0 -0
  36. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  38. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  39. data/test/dummy/bin/bundle +3 -0
  40. data/test/dummy/bin/rails +4 -0
  41. data/test/dummy/bin/rake +4 -0
  42. data/test/dummy/bin/setup +34 -0
  43. data/test/dummy/bin/update +29 -0
  44. data/test/dummy/config.ru +5 -0
  45. data/test/dummy/config/application.rb +20 -0
  46. data/test/dummy/config/boot.rb +5 -0
  47. data/test/dummy/config/cable.yml +9 -0
  48. data/test/dummy/config/environment.rb +5 -0
  49. data/test/dummy/config/environments/development.rb +54 -0
  50. data/test/dummy/config/environments/production.rb +86 -0
  51. data/test/dummy/config/environments/test.rb +43 -0
  52. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  53. data/test/dummy/config/initializers/assets.rb +11 -0
  54. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  56. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/test/dummy/config/initializers/inflections.rb +16 -0
  58. data/test/dummy/config/initializers/mime_types.rb +4 -0
  59. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  60. data/test/dummy/config/initializers/session_store.rb +3 -0
  61. data/test/dummy/config/initializers/workarea.rb +5 -0
  62. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/test/dummy/config/locales/en.yml +23 -0
  64. data/test/dummy/config/puma.rb +47 -0
  65. data/test/dummy/config/routes.rb +5 -0
  66. data/test/dummy/config/secrets.yml +22 -0
  67. data/test/dummy/config/spring.rb +6 -0
  68. data/test/dummy/lib/assets/.keep +0 -0
  69. data/test/dummy/log/.keep +0 -0
  70. data/test/dummy/public/404.html +67 -0
  71. data/test/dummy/public/422.html +67 -0
  72. data/test/dummy/public/500.html +66 -0
  73. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  74. data/test/dummy/public/apple-touch-icon.png +0 -0
  75. data/test/dummy/public/favicon.ico +0 -0
  76. data/test/test_helper.rb +13 -0
  77. data/test/view_models/workarea/storefront/google_product_feed_view_model_test.rb +46 -0
  78. data/test/workers/workarea/exporting/google_feed_test.rb +181 -0
  79. data/workarea-google_product_feed.gemspec +16 -0
  80. metadata +140 -0
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails' do
3
+ add_filter 'version.rb'
4
+ end
5
+ ENV['RAILS_ENV'] = 'test'
6
+
7
+ require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
8
+ require 'rails/test_help'
9
+ require 'workarea/test_help'
10
+
11
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
12
+ # to be shown.
13
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class GoogleProductFeedViewModelTest < TestCase
6
+ setup :set_asset_host
7
+ teardown :reset_asset_host
8
+
9
+ def test_can_use_categories_from_rules
10
+ create_category(google_name: 'Bar', product_ids: [product.id])
11
+
12
+ assert_equal 'Bar', subject.category_name
13
+ end
14
+
15
+ def test_uses_default_category
16
+ create_category(product_ids: [product.id], google_name: 'Apparel')
17
+
18
+ assert_equal 'Apparel', subject.category_name
19
+ end
20
+
21
+ def test_image_uses_asset_host_if_supplied
22
+ Workarea::Catalog::ProductPlaceholderImage.create
23
+ assert_includes subject.image, 'www.assethost.com'
24
+ end
25
+
26
+ private
27
+
28
+ def product
29
+ @product ||= create_product(name: 'Foo')
30
+ end
31
+
32
+ def subject
33
+ @subject ||= Storefront::GoogleProductFeedViewModel.new(product)
34
+ end
35
+
36
+ def set_asset_host
37
+ @_asset_host = Rails.application.config.action_controller.asset_host
38
+ Rails.application.config.action_controller.asset_host = 'http://www.assethost.com'
39
+ end
40
+
41
+ def reset_asset_host
42
+ Rails.application.config.action_controller.asset_host = @_asset_host
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,181 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Exporting::GoogleFeedTest < TestCase
5
+ setup :set_asset_host
6
+ teardown :reset_asset_host
7
+
8
+ def test_first_row_is_header
9
+ assert_equal(rows.first, [
10
+ 'item_group_id', 'id', 'title', 'description',
11
+ 'link', 'image_link', 'availability', 'condition',
12
+ 'brand', 'color', 'size',
13
+ 'google_product_category', 'product_type', 'price'
14
+ ])
15
+ end
16
+
17
+ def product
18
+ @product ||= create_product(
19
+ id: 'PROD', name: 'Test Product',
20
+ description: '<p>Paragraph test</p>',
21
+ filters: { brand: ['Workarea'], product_type: ['Test'] },
22
+ variants: [
23
+ { sku: 'SKU', regular: 1.to_m, details: { color: 'Red', size: 'Large' } },
24
+ { sku: 'SKU2', regular: 2.to_m, details: { color: 'Blue', size: 'Small' } }
25
+ ]
26
+ )
27
+ @product.images.build
28
+ @product.save!
29
+ @product
30
+ end
31
+
32
+ def test_second_row_is_product
33
+ Workarea.with_config do |config|
34
+ config.domain = 'www.client.com'
35
+ create_category(
36
+ name: 'Test Category',
37
+ google_name: 'Google Category',
38
+ product_ids: [product.id]
39
+ )
40
+
41
+ rows.second.tap do |row|
42
+ assert_equal('PROD', row[0])
43
+ assert_equal('SKU', row[1])
44
+ assert_equal('Test Product', row[2])
45
+ assert_equal('Paragraph test', row[3])
46
+ assert_equal('http://www.example.com/products/test-product?sku=' + product.skus.first.to_s, row[4])
47
+ assert_equal("http://www.assethost.com/product_images/test-product/#{product.images.first.id}/detail.jpg?c=0", row[5])
48
+ assert_equal('in stock', row[6])
49
+ assert_equal('new', row[7])
50
+ assert_equal('Workarea', row[8])
51
+ assert_equal('Red', row[9])
52
+ assert_equal('Large', row[10])
53
+ assert_equal('Google Category', row[11])
54
+ assert_equal('Test', row[12])
55
+ assert_equal(1.to_m.to_s, row[13])
56
+ end
57
+
58
+ rows.third.tap do |row|
59
+ assert_equal('PROD', row[0])
60
+ assert_equal('SKU2', row[1])
61
+ assert_equal('Test Product', row[2])
62
+ assert_equal('Paragraph test', row[3])
63
+ assert_equal('http://www.example.com/products/test-product?sku=' + product.skus.second.to_s, row[4])
64
+ assert_equal("http://www.assethost.com/product_images/test-product/#{product.images.first.id}/detail.jpg?c=0", row[5])
65
+ assert_equal('in stock', row[6])
66
+ assert_equal('new', row[7])
67
+ assert_equal('Workarea', row[8])
68
+ assert_equal('Blue', row[9])
69
+ assert_equal('Small', row[10])
70
+ assert_equal('Google Category', row[11])
71
+ assert_equal('Test', row[12])
72
+ assert_equal(2.to_m.to_s, row[13])
73
+ end
74
+ end
75
+ end
76
+
77
+ def test_google_category_uses_product_google_category_if_present
78
+ product.google_category = 'Product Google Category'
79
+
80
+ create_category(
81
+ name: 'Test Category 1',
82
+ google_name: 'Google Category',
83
+ product_ids: [product.id]
84
+ )
85
+
86
+ assert_equal('Product Google Category', rows.second[11])
87
+ end
88
+
89
+ def test_uses_second_category_if_first_category_does_not_have_a_google_name
90
+ create_category(
91
+ name: 'Test Category 1',
92
+ product_ids: [product.id]
93
+ )
94
+ create_category(
95
+ name: 'Test Category 2',
96
+ google_name: 'Google Category',
97
+ product_ids: [product.id]
98
+ )
99
+
100
+ assert_equal('Google Category', rows.second[11])
101
+ end
102
+
103
+ def test_uses_default_category_name_if_google_name_is_blank
104
+ Workarea.with_config do |config|
105
+ config.google_product_feed.default_category = 'Apparel & Accessories'
106
+
107
+ create_category(
108
+ name: 'Test Category',
109
+ product_ids: [product.id]
110
+ )
111
+
112
+ assert_equal('Apparel & Accessories', rows.second[11])
113
+ end
114
+ end
115
+
116
+ def test_does_not_export_non_displayable_skus
117
+ create_category(
118
+ name: 'Test Category',
119
+ google_name: 'Google Category',
120
+ product_ids: [product.id]
121
+ )
122
+
123
+ create_inventory(id: product.variants.first.sku, available: 0)
124
+
125
+ rows.second.tap do |row|
126
+ refute_equal(product.variants.first.sku, row[1])
127
+ assert_equal(product.variants.second.sku, row[1])
128
+ end
129
+
130
+ assert(rows.third.nil?)
131
+ end
132
+
133
+ def test_does_not_export_inactive_products
134
+ create_category(
135
+ name: 'Test Category',
136
+ google_name: 'Google Category',
137
+ product_ids: [product.id]
138
+ )
139
+
140
+ create_inventory(id: product.variants.first.sku)
141
+
142
+ product.update_attributes!(active: false)
143
+
144
+ assert(rows.second.nil?)
145
+ end
146
+
147
+ def test_static_columns
148
+ Workarea.with_config do |config|
149
+ config.google_product_feed.static_feed_values = { age_group: 'infant' }
150
+ product
151
+
152
+ assert_equal 'age_group', rows.first.last
153
+ assert_equal 'infant', rows.second.last
154
+ end
155
+ end
156
+
157
+ private
158
+
159
+ def set_asset_host
160
+ @_asset_host = Rails.application.config.action_controller.asset_host
161
+ Rails.application.config.action_controller.asset_host = 'http://www.assethost.com'
162
+ end
163
+
164
+ def reset_asset_host
165
+ Rails.application.config.action_controller.asset_host = @_asset_host
166
+ end
167
+
168
+ def google_feed
169
+ @google_feed ||= Exporting::GoogleFeed.new
170
+ end
171
+
172
+ def filename
173
+ @filename ||= Workarea::Exporting::GoogleFeed.temp_file
174
+ end
175
+
176
+ def rows
177
+ google_feed.generate_csv
178
+ File.open(filename).read.split("\n").map { |line| line.split("\t") }
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,16 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'workarea/google_product_feed/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'workarea-google_product_feed'
7
+ s.version = Workarea::GoogleProductFeed::VERSION
8
+ s.authors = ['Jake Beresford']
9
+ s.email = ['jberesford@weblinc.com']
10
+ s.homepage = 'http://www.workarea.com'
11
+ s.summary = 'Google Product Feed for the Workarea commerce platform'
12
+ s.description = 'Google Product Feed Rails Engine of the Workarea commerce platform'
13
+ s.files = `git ls-files`.split("\n")
14
+
15
+ s.add_dependency 'workarea', '~> 3.x', '>= 3.2'
16
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workarea-google_product_feed
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Jake Beresford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: workarea
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.x
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '3.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 3.x
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ description: Google Product Feed Rails Engine of the Workarea commerce platform
34
+ email:
35
+ - jberesford@weblinc.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".gitignore"
41
+ - CHANGELOG.md
42
+ - Gemfile
43
+ - README.md
44
+ - Rakefile
45
+ - app/models/workarea/catalog/category.decorator
46
+ - app/models/workarea/catalog/product.decorator
47
+ - app/models/workarea/feed/google.rb
48
+ - app/view_models/workarea/storefront/google_product_feed_sku_view_model.rb
49
+ - app/view_models/workarea/storefront/google_product_feed_view_model.rb
50
+ - app/workers/workarea/exporting/google_feed.rb
51
+ - bin/rails
52
+ - config/initializers/00_scheduled_jobs.rb
53
+ - config/initializers/01_configuration.rb
54
+ - config/routes.rb
55
+ - lib/workarea/google_product_feed.rb
56
+ - lib/workarea/google_product_feed/engine.rb
57
+ - lib/workarea/google_product_feed/version.rb
58
+ - script/admin_ci
59
+ - script/ci
60
+ - script/core_ci
61
+ - script/plugins_ci
62
+ - script/storefront_ci
63
+ - test/dummy/Rakefile
64
+ - test/dummy/app/assets/config/manifest.js
65
+ - test/dummy/app/assets/images/.keep
66
+ - test/dummy/app/assets/javascripts/application.js
67
+ - test/dummy/app/assets/stylesheets/application.css
68
+ - test/dummy/app/controllers/application_controller.rb
69
+ - test/dummy/app/controllers/concerns/.keep
70
+ - test/dummy/app/helpers/application_helper.rb
71
+ - test/dummy/app/jobs/application_job.rb
72
+ - test/dummy/app/mailers/application_mailer.rb
73
+ - test/dummy/app/models/concerns/.keep
74
+ - test/dummy/app/views/layouts/application.html.erb
75
+ - test/dummy/app/views/layouts/mailer.html.erb
76
+ - test/dummy/app/views/layouts/mailer.text.erb
77
+ - test/dummy/bin/bundle
78
+ - test/dummy/bin/rails
79
+ - test/dummy/bin/rake
80
+ - test/dummy/bin/setup
81
+ - test/dummy/bin/update
82
+ - test/dummy/config.ru
83
+ - test/dummy/config/application.rb
84
+ - test/dummy/config/boot.rb
85
+ - test/dummy/config/cable.yml
86
+ - test/dummy/config/environment.rb
87
+ - test/dummy/config/environments/development.rb
88
+ - test/dummy/config/environments/production.rb
89
+ - test/dummy/config/environments/test.rb
90
+ - test/dummy/config/initializers/application_controller_renderer.rb
91
+ - test/dummy/config/initializers/assets.rb
92
+ - test/dummy/config/initializers/backtrace_silencers.rb
93
+ - test/dummy/config/initializers/cookies_serializer.rb
94
+ - test/dummy/config/initializers/filter_parameter_logging.rb
95
+ - test/dummy/config/initializers/inflections.rb
96
+ - test/dummy/config/initializers/mime_types.rb
97
+ - test/dummy/config/initializers/new_framework_defaults.rb
98
+ - test/dummy/config/initializers/session_store.rb
99
+ - test/dummy/config/initializers/workarea.rb
100
+ - test/dummy/config/initializers/wrap_parameters.rb
101
+ - test/dummy/config/locales/en.yml
102
+ - test/dummy/config/puma.rb
103
+ - test/dummy/config/routes.rb
104
+ - test/dummy/config/secrets.yml
105
+ - test/dummy/config/spring.rb
106
+ - test/dummy/lib/assets/.keep
107
+ - test/dummy/log/.keep
108
+ - test/dummy/public/404.html
109
+ - test/dummy/public/422.html
110
+ - test/dummy/public/500.html
111
+ - test/dummy/public/apple-touch-icon-precomposed.png
112
+ - test/dummy/public/apple-touch-icon.png
113
+ - test/dummy/public/favicon.ico
114
+ - test/test_helper.rb
115
+ - test/view_models/workarea/storefront/google_product_feed_view_model_test.rb
116
+ - test/workers/workarea/exporting/google_feed_test.rb
117
+ - workarea-google_product_feed.gemspec
118
+ homepage: http://www.workarea.com
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.4
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Google Product Feed for the Workarea commerce platform
140
+ test_files: []