workarea-core 3.5.0.beta.1 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/workarea/current_tracking.rb +4 -0
  3. data/app/models/workarea/checkout/collect_payment.rb +5 -5
  4. data/app/models/workarea/data_file/operation.rb +4 -0
  5. data/app/models/workarea/fulfillment/policies/base.rb +0 -4
  6. data/app/models/workarea/fulfillment/policies/{ignore.rb → shipping.rb} +2 -2
  7. data/app/models/workarea/fulfillment/sku.rb +0 -2
  8. data/app/models/workarea/insights/trending_searches.rb +8 -1
  9. data/app/models/workarea/metrics/search_by_day.rb +2 -0
  10. data/app/models/workarea/order.rb +12 -2
  11. data/app/models/workarea/order/item.rb +28 -2
  12. data/app/models/workarea/pricing/calculators/tax_calculator.rb +2 -2
  13. data/app/models/workarea/pricing/discount.rb +3 -2
  14. data/app/models/workarea/releasable.rb +3 -5
  15. data/app/models/workarea/reports/custom_event.rb +22 -0
  16. data/app/models/workarea/search/admin/releasable.rb +18 -6
  17. data/app/models/workarea/segment/life_cycle.rb +5 -5
  18. data/app/models/workarea/segment/rules/last_order.rb +9 -2
  19. data/app/models/workarea/segment/rules/traffic_referrer.rb +16 -5
  20. data/app/models/workarea/segmentable.rb +13 -0
  21. data/app/models/workarea/traffic_referrer.rb +3 -0
  22. data/app/queries/workarea/alerts.rb +21 -0
  23. data/app/queries/workarea/order_item_details.rb +16 -16
  24. data/app/queries/workarea/search/admin_index_search.rb +2 -1
  25. data/app/queries/workarea/search/product_display_rules.rb +0 -2
  26. data/app/services/workarea/direct_upload.rb +5 -0
  27. data/app/services/workarea/packaging.rb +1 -1
  28. data/app/workers/workarea/deactivate_stale_discounts.rb +1 -1
  29. data/app/workers/workarea/synchronize_user_metrics.rb +9 -0
  30. data/config/locales/en.yml +22 -0
  31. data/lib/tasks/migrate.rake +9 -12
  32. data/lib/workarea/configuration.rb +6 -6
  33. data/lib/workarea/configuration/redis.rb +21 -3
  34. data/lib/workarea/core.rb +3 -0
  35. data/lib/workarea/ext/freedom_patches/referer_parser.rb +7 -0
  36. data/lib/workarea/ext/mongoid/embedded_children.rb +20 -0
  37. data/lib/workarea/latest_version.rb +24 -0
  38. data/lib/workarea/ping_home_base.rb +0 -1
  39. data/lib/workarea/version.rb +1 -1
  40. data/lib/workarea/visit.rb +5 -2
  41. data/lib/workarea/warnings.rb +6 -6
  42. data/test/lib/workarea/ext/mongoid/embedded_children_test.rb +32 -0
  43. data/test/lib/workarea/latest_version_test.rb +11 -0
  44. data/test/models/workarea/checkout/collect_payment_test.rb +6 -6
  45. data/test/models/workarea/data_file/csv_test.rb +15 -0
  46. data/test/models/workarea/fulfillment/sku_test.rb +5 -5
  47. data/test/models/workarea/insights/cold_searches_test.rb +13 -11
  48. data/test/models/workarea/insights/hot_searches_test.rb +13 -11
  49. data/test/models/workarea/insights/searches_to_improve_test.rb +9 -6
  50. data/test/models/workarea/insights/star_searches_test.rb +5 -4
  51. data/test/models/workarea/insights/trending_searches_test.rb +12 -9
  52. data/test/models/workarea/pricing/calculators/tax_calculator_test.rb +1 -1
  53. data/test/models/workarea/search/admin/releasable_test.rb +5 -7
  54. data/test/models/workarea/segment/life_cycle_test.rb +5 -0
  55. data/test/models/workarea/segment/rules/last_order_test.rb +15 -3
  56. data/test/models/workarea/segment/rules/traffic_referrer_test.rb +10 -8
  57. data/test/models/workarea/segmentable_test.rb +18 -0
  58. data/test/queries/workarea/alerts_test.rb +11 -0
  59. data/test/queries/workarea/order_item_details_test.rb +4 -12
  60. data/test/services/workarea/direct_upload_test.rb +3 -0
  61. data/test/vcr_cassettes/get_latest_version.yml +90 -0
  62. data/test/workers/workarea/deactivate_stale_discounts_test.rb +2 -2
  63. data/workarea-core.gemspec +2 -3
  64. metadata +16 -25
  65. data/app/controllers/workarea/current_referrer.rb +0 -14
  66. data/app/models/workarea/fulfillment/policies/ship.rb +0 -15
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class LatestVersionTest < TestCase
5
+ def test_get
6
+ VCR.use_cassette 'get_latest_version' do
7
+ assert_equal('3.4.21', Workarea::LatestVersion.get)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -39,19 +39,19 @@ module Workarea
39
39
 
40
40
  def test_action
41
41
  Workarea.config.checkout_payment_action = {
42
- not_shipped: 'foo!',
43
- shipped: 'bar!',
44
- mixed: 'baz!'
42
+ shipping: 'bar!',
43
+ partial_shipping: 'baz!',
44
+ no_shipping: 'foo!'
45
45
  }
46
46
 
47
- order.items.build(requires_shipping: false)
47
+ order.items.build(fulfillment: 'download')
48
48
  assert_equal('foo!', collect_payment.action)
49
49
 
50
- order.items.build(requires_shipping: true)
50
+ order.items.build(fulfillment: 'shipping')
51
51
  assert_equal('baz!', collect_payment.action)
52
52
 
53
53
  order.items.clear
54
- order.items.build(requires_shipping: true)
54
+ order.items.build(fulfillment: 'shipping')
55
55
  assert_equal('bar!', collect_payment.action)
56
56
  end
57
57
  end
@@ -401,6 +401,21 @@ module Workarea
401
401
  assert_equal("Bowl Light\u0099", product.name)
402
402
  end
403
403
  end
404
+
405
+ def test_bom_characters_in_unicode
406
+ csv = %(\xEF\xBB\xBF_id,name,slug,details_keywords\n653911,Bowl Light,Bowl_Light,"testing")
407
+ import = create_import(
408
+ model_type: Catalog::Product.name,
409
+ file: create_tempfile(csv, extension: 'csv'),
410
+ file_type: 'csv'
411
+ )
412
+
413
+ Csv.new(import).import!
414
+
415
+ product = Catalog::Product.find_by(slug: 'bowl_light')
416
+
417
+ assert_equal('653911', product.id)
418
+ end
404
419
  end
405
420
  end
406
421
  end
@@ -4,7 +4,7 @@ module Workarea
4
4
  class Fulfillment
5
5
  class SkuTest < TestCase
6
6
  def test_validation
7
- sku = Sku.new(id: 'SKU1', policy: 'ignore')
7
+ sku = Sku.new(id: 'SKU1', policy: 'shipping')
8
8
  assert(sku.valid?)
9
9
 
10
10
  sku.policy = 'download'
@@ -16,10 +16,10 @@ module Workarea
16
16
  end
17
17
 
18
18
  def test_find_or_initialize_all
19
- create_fulfillment_sku(id: 'sku1', policy: 'ignore')
19
+ create_fulfillment_sku(id: 'sku1')
20
20
  skus = Sku.find_or_initialize_all(%w(sku1 sku2))
21
21
 
22
- assert(2, skus.size)
22
+ assert_equal(2, skus.size)
23
23
  assert(skus.first.persisted?)
24
24
  refute(skus.second.persisted?)
25
25
  end
@@ -28,7 +28,7 @@ module Workarea
28
28
  order = Order.new
29
29
  item = order.items.build(sku: 'SKU1')
30
30
 
31
- sku = Sku.new(id: 'SKU1', policy: 'ignore')
31
+ sku = Sku.new(id: 'SKU1', policy: 'shipping')
32
32
  assert_nil(sku.process!(order_item: item))
33
33
 
34
34
  sku = Sku.new(id: 'SKU1', policy: 'foobar')
@@ -40,7 +40,7 @@ module Workarea
40
40
  end
41
41
 
42
42
  def test_downloadable?
43
- sku = Sku.new(id: 'SKU1', policy: 'ignore')
43
+ sku = Sku.new(id: 'SKU1', policy: 'shipping')
44
44
  refute(sku.downloadable?)
45
45
 
46
46
  sku.policy = 'download'
@@ -5,32 +5,32 @@ module Workarea
5
5
  class ColdSearchesTest < TestCase
6
6
  def test_results
7
7
  create_search_by_week(
8
- query_id: 'foo',
8
+ query_string: 'foo',
9
9
  revenue_change: -1,
10
10
  reporting_on: Time.current.last_week
11
11
  )
12
12
  create_search_by_week(
13
- query_id: 'bar',
13
+ query_string: 'bar',
14
14
  revenue_change: -4,
15
15
  reporting_on: Time.current.last_week
16
16
  )
17
17
  create_search_by_week(
18
- query_id: 'baz',
18
+ query_string: 'baz',
19
19
  revenue_change: -2,
20
20
  reporting_on: Time.current.last_week
21
21
  )
22
22
  create_search_by_week(
23
- query_id: 'qoo',
23
+ query_string: 'qoo',
24
24
  revenue_change: -5,
25
25
  reporting_on: Time.current.last_week
26
26
  )
27
27
  create_search_by_week(
28
- query_id: 'quz',
28
+ query_string: 'quz',
29
29
  revenue_change: -15,
30
30
  reporting_on: Time.current.last_week
31
31
  )
32
32
  create_search_by_week(
33
- query_id: 'qux',
33
+ query_string: 'qux',
34
34
  revenue_change: 0,
35
35
  reporting_on: Time.current.last_week
36
36
  )
@@ -41,32 +41,33 @@ module Workarea
41
41
  cold_searches = ColdSearches.first
42
42
  assert_equal(1, cold_searches.results.size)
43
43
  assert_equal('quz', cold_searches.results.first['query_id'])
44
+ assert_equal('quz', cold_searches.results.first['query_string'])
44
45
  assert_equal(-15, cold_searches.results.first['revenue_change'])
45
46
  end
46
47
 
47
48
  def test_falling_back_to_fewer_deviations
48
49
  create_search_by_week(
49
- query_id: 'foo',
50
+ query_string: 'foo',
50
51
  revenue_change: -1,
51
52
  reporting_on: Time.current.last_week
52
53
  )
53
54
  create_search_by_week(
54
- query_id: 'bar',
55
+ query_string: 'bar',
55
56
  revenue_change: -4,
56
57
  reporting_on: Time.current.last_week
57
58
  )
58
59
  create_search_by_week(
59
- query_id: 'baz',
60
+ query_string: 'baz',
60
61
  revenue_change: -2,
61
62
  reporting_on: Time.current.last_week
62
63
  )
63
64
  create_search_by_week(
64
- query_id: 'qoo',
65
+ query_string: 'qoo',
65
66
  revenue_change: -5,
66
67
  reporting_on: Time.current.last_week
67
68
  )
68
69
  create_search_by_week(
69
- query_id: 'qux',
70
+ query_string: 'qux',
70
71
  revenue_change: 0,
71
72
  reporting_on: Time.current.last_week
72
73
  )
@@ -77,6 +78,7 @@ module Workarea
77
78
  cold_searches = ColdSearches.first
78
79
  assert_equal(1, cold_searches.results.size)
79
80
  assert_equal('qoo', cold_searches.results.first['query_id'])
81
+ assert_equal('qoo', cold_searches.results.first['query_string'])
80
82
  assert_equal(-5, cold_searches.results.first['revenue_change'])
81
83
  end
82
84
 
@@ -5,32 +5,32 @@ module Workarea
5
5
  class HotSearchesTest < TestCase
6
6
  def test_results
7
7
  create_search_by_week(
8
- query_id: 'foo',
8
+ query_string: 'foo',
9
9
  revenue_change: 1,
10
10
  reporting_on: Time.current.last_week
11
11
  )
12
12
  create_search_by_week(
13
- query_id: 'bar',
13
+ query_string: 'bar',
14
14
  revenue_change: 4,
15
15
  reporting_on: Time.current.last_week
16
16
  )
17
17
  create_search_by_week(
18
- query_id: 'baz',
18
+ query_string: 'baz',
19
19
  revenue_change: 2,
20
20
  reporting_on: Time.current.last_week
21
21
  )
22
22
  create_search_by_week(
23
- query_id: 'qoo',
23
+ query_string: 'qoo',
24
24
  revenue_change: 5,
25
25
  reporting_on: Time.current.last_week
26
26
  )
27
27
  create_search_by_week(
28
- query_id: 'quz',
28
+ query_string: 'quz',
29
29
  revenue_change: 15,
30
30
  reporting_on: Time.current.last_week
31
31
  )
32
32
  create_search_by_week(
33
- query_id: 'qux',
33
+ query_string: 'qux',
34
34
  revenue_change: 0,
35
35
  reporting_on: Time.current.last_week
36
36
  )
@@ -41,32 +41,33 @@ module Workarea
41
41
  hot_searches = HotSearches.first
42
42
  assert_equal(1, hot_searches.results.size)
43
43
  assert_equal('quz', hot_searches.results.first['query_id'])
44
+ assert_equal('quz', hot_searches.results.first['query_string'])
44
45
  assert_equal(15, hot_searches.results.first['revenue_change'])
45
46
  end
46
47
 
47
48
  def test_falling_back_to_fewer_deviations
48
49
  create_search_by_week(
49
- query_id: 'foo',
50
+ query_string: 'foo',
50
51
  revenue_change: 1,
51
52
  reporting_on: Time.current.last_week
52
53
  )
53
54
  create_search_by_week(
54
- query_id: 'bar',
55
+ query_string: 'bar',
55
56
  revenue_change: 4,
56
57
  reporting_on: Time.current.last_week
57
58
  )
58
59
  create_search_by_week(
59
- query_id: 'baz',
60
+ query_string: 'baz',
60
61
  revenue_change: 2,
61
62
  reporting_on: Time.current.last_week
62
63
  )
63
64
  create_search_by_week(
64
- query_id: 'qoo',
65
+ query_string: 'qoo',
65
66
  revenue_change: 5,
66
67
  reporting_on: Time.current.last_week
67
68
  )
68
69
  create_search_by_week(
69
- query_id: 'qux',
70
+ query_string: 'qux',
70
71
  revenue_change: 0,
71
72
  reporting_on: Time.current.last_week
72
73
  )
@@ -77,6 +78,7 @@ module Workarea
77
78
  hot_searches = HotSearches.first
78
79
  assert_equal(1, hot_searches.results.size)
79
80
  assert_equal('qoo', hot_searches.results.first['query_id'])
81
+ assert_equal('qoo', hot_searches.results.first['query_string'])
80
82
  assert_equal(5, hot_searches.results.first['revenue_change'])
81
83
  end
82
84
 
@@ -5,25 +5,25 @@ module Workarea
5
5
  class SearchesToImproveTest < TestCase
6
6
  def test_results
7
7
  create_search_by_week(
8
- query_id: 'foo',
8
+ query_string: 'foo',
9
9
  searches_percentile: 100,
10
10
  reporting_on: Time.current.last_week,
11
11
  conversion_rate: 0.1
12
12
  )
13
13
  create_search_by_week(
14
- query_id: 'bar',
14
+ query_string: 'bar',
15
15
  searches_percentile: 90,
16
16
  reporting_on: Time.current.last_week,
17
17
  conversion_rate: 0.2
18
18
  )
19
19
  create_search_by_week(
20
- query_id: 'baz',
20
+ query_string: 'baz',
21
21
  searches_percentile: 100,
22
22
  reporting_on: Time.current.last_week,
23
23
  conversion_rate: 0.01
24
24
  )
25
25
  create_search_by_week(
26
- query_id: 'qoo',
26
+ query_string: 'qoo',
27
27
  searches_percentile: 100,
28
28
  reporting_on: Time.current.last_week,
29
29
  conversion_rate: 0.02
@@ -35,20 +35,22 @@ module Workarea
35
35
  searches_to_improve = SearchesToImprove.first
36
36
  assert_equal(2, searches_to_improve.results.size)
37
37
  assert_equal('baz', searches_to_improve.results.first['query_id'])
38
+ assert_equal('baz', searches_to_improve.results.first['query_string'])
38
39
  assert_equal(0.01, searches_to_improve.results.first['conversion_rate'])
39
40
  assert_equal('qoo', searches_to_improve.results.second['query_id'])
41
+ assert_equal('qoo', searches_to_improve.results.second['query_string'])
40
42
  assert_equal(0.02, searches_to_improve.results.second['conversion_rate'])
41
43
  end
42
44
 
43
45
  def test_falling_back_to_second_pass
44
46
  create_search_by_week(
45
- query_id: 'foo',
47
+ query_string: 'foo',
46
48
  searches_percentile: 90,
47
49
  reporting_on: Time.current.last_week,
48
50
  conversion_rate: 0.1
49
51
  )
50
52
  create_search_by_week(
51
- query_id: 'bar',
53
+ query_string: 'bar',
52
54
  searches_percentile: 80,
53
55
  reporting_on: Time.current.last_week,
54
56
  conversion_rate: 0.2
@@ -62,6 +64,7 @@ module Workarea
62
64
  searches_to_improve = SearchesToImprove.first
63
65
  assert_equal(1, searches_to_improve.results.size)
64
66
  assert_equal('foo', searches_to_improve.results.first['query_id'])
67
+ assert_equal('foo', searches_to_improve.results.first['query_string'])
65
68
  assert_equal(0.1, searches_to_improve.results.first['conversion_rate'])
66
69
  end
67
70
 
@@ -5,25 +5,25 @@ module Workarea
5
5
  class StarSearchesTest < TestCase
6
6
  def test_generate_weekly!
7
7
  create_search_by_week(
8
- query_id: 'foo',
8
+ query_string: 'foo',
9
9
  searches_percentile: 100,
10
10
  reporting_on: Time.current.last_week,
11
11
  conversion_rate: 0.1
12
12
  )
13
13
  create_search_by_week(
14
- query_id: 'bar',
14
+ query_string: 'bar',
15
15
  searches_percentile: 90,
16
16
  reporting_on: Time.current.last_week,
17
17
  conversion_rate: 0.2
18
18
  )
19
19
  create_search_by_week(
20
- query_id: 'baz',
20
+ query_string: 'baz',
21
21
  searches_percentile: 100,
22
22
  reporting_on: Time.current.last_week,
23
23
  conversion_rate: 0.01
24
24
  )
25
25
  create_search_by_week(
26
- query_id: 'qoo',
26
+ query_string: 'qoo',
27
27
  searches_percentile: 100,
28
28
  reporting_on: Time.current.last_week,
29
29
  conversion_rate: 0.02
@@ -35,6 +35,7 @@ module Workarea
35
35
  star_searches = StarSearches.first
36
36
  assert_equal(1, star_searches.results.size)
37
37
  assert_equal('foo', star_searches.results.first['query_id'])
38
+ assert_equal('foo', star_searches.results.first['query_string'])
38
39
  assert_equal(0.1, star_searches.results.first['conversion_rate'])
39
40
  end
40
41
 
@@ -5,55 +5,55 @@ module Workarea
5
5
  class TrendingSearchesTest < TestCase
6
6
  def test_generate_monthly!
7
7
  create_search_by_week(
8
- query_id: 'foo',
8
+ query_string: 'foo',
9
9
  revenue_change: 10,
10
10
  orders: 5,
11
11
  reporting_on: Time.zone.local(2018, 12, 3)
12
12
  )
13
13
  create_search_by_week(
14
- query_id: 'foo',
14
+ query_string: 'foo',
15
15
  revenue_change: -10,
16
16
  orders: 0,
17
17
  reporting_on: Time.zone.local(2018, 12, 10)
18
18
  )
19
19
  create_search_by_week(
20
- query_id: 'foo',
20
+ query_string: 'foo',
21
21
  revenue_change: 20,
22
22
  orders: 10,
23
23
  reporting_on: Time.zone.local(2018, 12, 17)
24
24
  )
25
25
  create_search_by_week(
26
- query_id: 'bar',
26
+ query_string: 'bar',
27
27
  revenue_change: 10,
28
28
  orders: 5,
29
29
  reporting_on: Time.zone.local(2018, 12, 3)
30
30
  )
31
31
  create_search_by_week(
32
- query_id: 'bar',
32
+ query_string: 'bar',
33
33
  revenue_change: -10,
34
34
  orders: 0,
35
35
  reporting_on: Time.zone.local(2018, 12, 10)
36
36
  )
37
37
  create_search_by_week(
38
- query_id: 'bar',
38
+ query_string: 'bar',
39
39
  revenue_change: 0,
40
40
  orders: 0,
41
41
  reporting_on: Time.zone.local(2018, 12, 17)
42
42
  )
43
43
  create_search_by_week(
44
- query_id: 'baz',
44
+ query_string: 'baz',
45
45
  revenue_change: 10,
46
46
  orders: 5,
47
47
  reporting_on: Time.zone.local(2018, 12, 3)
48
48
  )
49
49
  create_search_by_week(
50
- query_id: 'baz',
50
+ query_string: 'baz',
51
51
  revenue_change: -10,
52
52
  orders: 1,
53
53
  reporting_on: Time.zone.local(2018, 12, 10)
54
54
  )
55
55
  create_search_by_week(
56
- query_id: 'baz',
56
+ query_string: 'baz',
57
57
  revenue_change: 0,
58
58
  orders: 0,
59
59
  reporting_on: Time.zone.local(2018, 12, 17)
@@ -67,14 +67,17 @@ module Workarea
67
67
  assert_equal(3, trending_searches.results.size)
68
68
 
69
69
  assert_equal('foo', trending_searches.results.first['query_id'])
70
+ assert_equal('foo', trending_searches.results.first['query_string'])
70
71
  assert_equal(2, trending_searches.results.first['improving_weeks'])
71
72
  assert_equal(15, trending_searches.results.first['orders'])
72
73
 
73
74
  assert_equal('baz', trending_searches.results.second['query_id'])
75
+ assert_equal('baz', trending_searches.results.second['query_string'])
74
76
  assert_equal(1, trending_searches.results.second['improving_weeks'])
75
77
  assert_equal(6, trending_searches.results.second['orders'])
76
78
 
77
79
  assert_equal('bar', trending_searches.results.third['query_id'])
80
+ assert_equal('bar', trending_searches.results.third['query_string'])
78
81
  assert_equal(1, trending_searches.results.third['improving_weeks'])
79
82
  assert_equal(5, trending_searches.results.third['orders'])
80
83
  end