workarea-core 3.5.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/workarea/content/block_draft.rb +4 -1
  3. data/app/models/workarea/data_file/csv.rb +8 -6
  4. data/app/models/workarea/data_file/json.rb +20 -1
  5. data/app/models/workarea/insights/customer_acquisition.rb +9 -5
  6. data/app/models/workarea/insights/trending_products.rb +2 -2
  7. data/app/models/workarea/insights/trending_searches.rb +2 -2
  8. data/app/models/workarea/metrics/product_for_last_week.rb +11 -5
  9. data/app/models/workarea/metrics/search_for_last_week.rb +11 -5
  10. data/app/models/workarea/metrics/update_user_aggregations.rb +1 -1
  11. data/app/models/workarea/pricing/discount/redemption.rb +1 -0
  12. data/app/queries/workarea/reports/average_order_value.rb +1 -1
  13. data/app/queries/workarea/reports/first_time_vs_returning_sales.rb +1 -1
  14. data/app/queries/workarea/reports/group_by_time.rb +17 -13
  15. data/app/queries/workarea/reports/sales_by_category.rb +1 -1
  16. data/app/queries/workarea/reports/sales_by_country.rb +1 -1
  17. data/app/queries/workarea/reports/sales_by_discount.rb +1 -1
  18. data/app/queries/workarea/reports/sales_by_menu.rb +1 -1
  19. data/app/queries/workarea/reports/sales_by_product.rb +1 -1
  20. data/app/queries/workarea/reports/sales_by_sku.rb +1 -1
  21. data/app/queries/workarea/reports/sales_by_traffic_referrer.rb +1 -1
  22. data/app/queries/workarea/reports/sales_over_time.rb +1 -1
  23. data/app/queries/workarea/reports/searches.rb +1 -1
  24. data/app/queries/workarea/reports/searches_over_time.rb +1 -1
  25. data/app/queries/workarea/reports/searches_without_results_over_time.rb +1 -1
  26. data/app/queries/workarea/search/product_search.rb +1 -1
  27. data/config/initializers/00_configuration.rb +0 -5
  28. data/lib/workarea/configuration.rb +3 -0
  29. data/lib/workarea/configuration/redis.rb +29 -22
  30. data/lib/workarea/core.rb +4 -3
  31. data/lib/workarea/core/engine.rb +0 -1
  32. data/lib/workarea/version.rb +1 -1
  33. data/test/lib/workarea/configuration/redis_test.rb +47 -0
  34. data/test/models/workarea/data_file/csv_test.rb +48 -0
  35. data/test/models/workarea/data_file/json_test.rb +40 -0
  36. data/test/queries/workarea/search/product_search_test.rb +7 -5
  37. data/workarea-core.gemspec +1 -2
  38. metadata +11 -25
  39. data/lib/workarea/configuration/logstasher.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 350a33b73048c0e24062f5bbd378518bfae1133b2e8d49b58907d4327191ffe9
4
- data.tar.gz: 74ddf766b88286672ca1ac81924a09b753aa6e20efae0d9fa6eeb1ecbcf8bfa8
3
+ metadata.gz: 8235a2cc74baebc1277b7654671af10c36f634f31e1cf42f66b13acc71bc2422
4
+ data.tar.gz: 98bad1e8beb51469a28a823f935361517201b9306e7c1191357bd0ab03b8fa9d
5
5
  SHA512:
6
- metadata.gz: 349c362c45e578680ef743051bc3554c5995013be7a1e348bcac2780fa6a9425b137fbfec9f6d7be3af354996a5fcc895be5af91241e1bf7b7ad1a878cf428d1
7
- data.tar.gz: 260730f0b9e935712e47230aa9b3a103b971ec190afbadb7b0a15a2b78efd562928f48f990ed0db0a4ecf515084bd65f385145683b33ac2a66fab971cdbeda47
6
+ metadata.gz: ae272f2e725c5ea055fee8d5650896f39ecafffb429cb08287a8b698425fdd91252ad9efcf3cb11b2ba8ff9ef2c46d49bf2aa6bebea5672685ffacca2d4baecd
7
+ data.tar.gz: a1ce00f795b52f99024aac425f38f0ecf81b0945559a272bd31a974c797b9d3ac2312d9bd2226bdf5e07e3da6b09574d30c6d67fafe11776bb463abedbaeb131
@@ -2,13 +2,16 @@ module Workarea
2
2
  class Content
3
3
  class BlockDraft
4
4
  include ApplicationDocument
5
- include Releasable
6
5
 
7
6
  field :content_id, type: String
8
7
  Block.fields.except('_id').each do |name, field_instance|
9
8
  field name, field_instance.options.except(:klass)
10
9
  end
11
10
 
11
+ # Added as a field to ensure copying this value to any blocks created
12
+ # from a draft.
13
+ field :activate_with, type: String
14
+
12
15
  index(
13
16
  { created_at: 1 },
14
17
  { expire_after_seconds: 1.hour.seconds.to_i }
@@ -48,6 +48,8 @@ module Workarea
48
48
 
49
49
  def assign_attributes(model, attrs)
50
50
  model.fields.each do |name, metadata|
51
+ next if name == 'updated_at'
52
+
51
53
  value = CsvFields.deserialize_from(attrs, field: metadata, model: model)
52
54
  model.send("#{name}=", value) if value.present?
53
55
  end
@@ -86,17 +88,17 @@ module Workarea
86
88
  ]
87
89
 
88
90
  if unnamespaced_attrs.values.any?(&:present?)
91
+ klass = attrs["#{name}_type"].constantize if attrs["#{name}_type"].present?
92
+ klass ||= root.relations[name].class_name.constantize
93
+
89
94
  if metadata.many?
90
95
  id = attrs["#{name}_id"]
91
- instance = if id.present?
92
- root.send(name).find_or_initialize_by(id: id)
93
- else
94
- root.send(name).build
95
- end
96
+ instance = root.send(name).find_by(id: id) rescue nil
97
+ instance ||= root.send(name).build({}, klass)
96
98
 
97
99
  assign_attributes(instance, unnamespaced_attrs)
98
100
  else
99
- instance = root.send(name) || root.send("build_#{name}")
101
+ instance = root.send(name) || root.send("build_#{name}", {}, klass)
100
102
  assign_attributes(instance, unnamespaced_attrs)
101
103
  end
102
104
  end
@@ -45,12 +45,31 @@ module Workarea
45
45
 
46
46
  if id.present?
47
47
  result = model_class.find_or_initialize_by(id: id)
48
- result.attributes = attributes
48
+ result.attributes = attributes_without_updated_at(attributes)
49
49
  result
50
50
  else
51
51
  model_class.new(attributes)
52
52
  end
53
53
  end
54
+
55
+ def attributes_without_updated_at(attrs)
56
+ return attrs unless attrs.respond_to?(:each_with_object)
57
+
58
+ attrs.each_with_object({}) do |(key, value), attributes|
59
+ next if key.to_s == 'updated_at'
60
+
61
+ attributes[key] = case value
62
+ when Hash
63
+ attributes_without_updated_at(value)
64
+ when Array
65
+ value.map do |item|
66
+ attributes_without_updated_at(item)
67
+ end
68
+ else
69
+ value
70
+ end
71
+ end
72
+ end
54
73
  end
55
74
  end
56
75
  end
@@ -37,8 +37,8 @@ module Workarea
37
37
  {
38
38
  '$match' => {
39
39
  'first_order_at' => {
40
- '$gte' => beginning_of_last_month,
41
- '$lte' => end_of_last_month
40
+ '$gte' => beginning_of_last_month.utc,
41
+ '$lte' => end_of_last_month.utc
42
42
  }
43
43
  }
44
44
  }
@@ -48,14 +48,18 @@ module Workarea
48
48
  {
49
49
  '$group' => {
50
50
  '_id' => {
51
- 'year' => { '$year' => '$first_order_at' },
52
- 'month' => { '$month' => '$first_order_at' },
53
- 'day' => { '$dayOfMonth' => '$first_order_at' }
51
+ 'year' => { '$year' => first_order_at_in_time_zone },
52
+ 'month' => { '$month' => first_order_at_in_time_zone },
53
+ 'day' => { '$dayOfMonth' => first_order_at_in_time_zone }
54
54
  },
55
55
  'new_customers' => { '$sum' => 1 }
56
56
  }
57
57
  }
58
58
  end
59
+
60
+ def first_order_at_in_time_zone
61
+ { 'date' => '$first_order_at', 'timezone' => Time.zone.tzinfo.name }
62
+ end
59
63
  end
60
64
  end
61
65
  end
@@ -22,8 +22,8 @@ module Workarea
22
22
  {
23
23
  '$match' => {
24
24
  'reporting_on' => {
25
- '$gte' => beginning_of_last_month,
26
- '$lte' => end_of_last_month
25
+ '$gte' => beginning_of_last_month.utc,
26
+ '$lte' => end_of_last_month.utc
27
27
  }
28
28
  }
29
29
  }
@@ -28,8 +28,8 @@ module Workarea
28
28
  {
29
29
  '$match' => {
30
30
  'reporting_on' => {
31
- '$gte' => beginning_of_last_month,
32
- '$lte' => end_of_last_month
31
+ '$gte' => beginning_of_last_month.utc,
32
+ '$lte' => end_of_last_month.utc
33
33
  }
34
34
  }
35
35
  }
@@ -35,8 +35,8 @@ module Workarea
35
35
  {
36
36
  '$match' => {
37
37
  'reporting_on' => {
38
- '$gte' => Time.current.last_week,
39
- '$lte' => Time.current.last_week.end_of_week
38
+ '$gte' => Time.current.last_week.utc,
39
+ '$lte' => Time.current.last_week.end_of_week.utc
40
40
  }
41
41
  }
42
42
  }
@@ -72,8 +72,8 @@ module Workarea
72
72
  '$expr' => {
73
73
  '$and' => [
74
74
  { '$eq' => ['$product_id', '$$product_id'] },
75
- { '$gte' => ['$reporting_on', Time.current.last_week - 1.week] },
76
- { '$lte' => ['$reporting_on', Time.current.last_week.end_of_week - 1.week] }
75
+ { '$gte' => ['$reporting_on', (Time.current.last_week - 1.week).utc] },
76
+ { '$lte' => ['$reporting_on', (Time.current.last_week.end_of_week - 1.week).utc] }
77
77
  ]
78
78
  }
79
79
  }
@@ -146,7 +146,13 @@ module Workarea
146
146
  '$addFields' => {
147
147
  '_id' => {
148
148
  '$concat' => [
149
- { '$dateToString' => { 'format' => '%Y%m%d', 'date' => '$reporting_on' } },
149
+ {
150
+ '$dateToString' => {
151
+ 'format' => '%Y%m%d',
152
+ 'date' => '$reporting_on',
153
+ 'timezone' => Time.zone.tzinfo.name
154
+ }
155
+ },
150
156
  '-',
151
157
  '$product_id'
152
158
  ]
@@ -36,8 +36,8 @@ module Workarea
36
36
  {
37
37
  '$match' => {
38
38
  'reporting_on' => {
39
- '$gte' => Time.current.last_week,
40
- '$lte' => Time.current.last_week.end_of_week
39
+ '$gte' => Time.current.last_week.utc,
40
+ '$lte' => Time.current.last_week.end_of_week.utc
41
41
  }
42
42
  }
43
43
  }
@@ -77,8 +77,8 @@ module Workarea
77
77
  '$expr' => {
78
78
  '$and' => [
79
79
  { '$eq' => ['$query_id', '$$query_id'] },
80
- { '$gte' => ['$reporting_on', Time.current.last_week - 1.week] },
81
- { '$lte' => ['$reporting_on', Time.current.last_week.end_of_week - 1.week] }
80
+ { '$gte' => ['$reporting_on', (Time.current.last_week - 1.week).utc] },
81
+ { '$lte' => ['$reporting_on', (Time.current.last_week.end_of_week - 1.week).utc] }
82
82
  ]
83
83
  }
84
84
  }
@@ -151,7 +151,13 @@ module Workarea
151
151
  '$addFields' => {
152
152
  '_id' => {
153
153
  '$concat' => [
154
- { '$dateToString' => { 'format' => '%Y%m%d', 'date' => '$reporting_on' } },
154
+ {
155
+ '$dateToString' => {
156
+ 'format' => '%Y%m%d',
157
+ 'date' => '$reporting_on',
158
+ 'timezone' => Time.zone.tzinfo.name
159
+ }
160
+ },
155
161
  '-',
156
162
  '$query_id'
157
163
  ]
@@ -19,7 +19,7 @@ module Workarea
19
19
  {
20
20
  '$divide' => [
21
21
  '$orders',
22
- { '$subtract' => [Time.current, '$first_order_at'] }
22
+ { '$subtract' => [Time.current.utc, '$first_order_at'] }
23
23
  ]
24
24
  }
25
25
  ]
@@ -20,6 +20,7 @@ module Workarea
20
20
 
21
21
  scope :recent, -> { desc(:created_at) }
22
22
  index({ discount_id: 1, email: 1 })
23
+ index({ discount_id: 1, created_at: -1 }, { background: true })
23
24
 
24
25
  before_validation :downcase_email
25
26
 
@@ -14,7 +14,7 @@ module Workarea
14
14
  def filter_date_range_and_zeroes
15
15
  {
16
16
  '$match' => {
17
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
17
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
18
18
  'orders' => { '$gt' => 0 },
19
19
  'revenue' => { '$gt' => 0 }
20
20
  }
@@ -14,7 +14,7 @@ module Workarea
14
14
  def filter
15
15
  {
16
16
  '$match' => {
17
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
17
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
18
18
  'orders' => { '$gt' => 0 }
19
19
  }
20
20
  }
@@ -25,46 +25,50 @@ module Workarea
25
25
 
26
26
  private
27
27
 
28
+ def reporting_on_in_time_zone
29
+ { 'date' => '$reporting_on', 'timezone' => Time.zone.tzinfo.name }
30
+ end
31
+
28
32
  def day_id
29
33
  {
30
- 'year' => { '$year' => '$reporting_on' },
31
- 'month' => { '$month' => '$reporting_on' },
32
- 'day' => { '$dayOfMonth' => '$reporting_on' }
34
+ 'year' => { '$year' => reporting_on_in_time_zone },
35
+ 'month' => { '$month' => reporting_on_in_time_zone },
36
+ 'day' => { '$dayOfMonth' => reporting_on_in_time_zone }
33
37
  }
34
38
  end
35
39
 
36
40
  def week_id
37
41
  {
38
- 'year' => { '$year' => '$reporting_on' },
39
- 'week' => { '$isoWeek' => '$reporting_on' }
42
+ 'year' => { '$year' => reporting_on_in_time_zone },
43
+ 'week' => { '$isoWeek' => reporting_on_in_time_zone }
40
44
  }
41
45
  end
42
46
 
43
47
  def day_of_week_id
44
- { 'day_of_week' => { '$dayOfWeek' => '$reporting_on' } }
48
+ { 'day_of_week' => { '$dayOfWeek' => reporting_on_in_time_zone } }
45
49
  end
46
50
 
47
51
  def month_id
48
52
  {
49
- 'year' => { '$year' => '$reporting_on' },
50
- 'month' => { '$month' => '$reporting_on' }
53
+ 'year' => { '$year' => reporting_on_in_time_zone },
54
+ 'month' => { '$month' => reporting_on_in_time_zone }
51
55
  }
52
56
  end
53
57
 
54
58
  def quarter_id
55
59
  {
56
- 'year' => { '$year' => '$reporting_on' },
60
+ 'year' => { '$year' => reporting_on_in_time_zone },
57
61
  'quarter' => {
58
62
  '$cond' => [
59
- { '$lte' => [{ '$month' => '$reporting_on' }, 3] },
63
+ { '$lte' => [{ '$month' => reporting_on_in_time_zone }, 3] },
60
64
  1,
61
65
  {
62
66
  '$cond' => [
63
- { '$lte' => [{ '$month' => '$reporting_on' }, 6] },
67
+ { '$lte' => [{ '$month' => reporting_on_in_time_zone }, 6] },
64
68
  2,
65
69
  {
66
70
  '$cond' => [
67
- { '$lte' => [{ '$month' => '$reporting_on' }, 9] },
71
+ { '$lte' => [{ '$month' => reporting_on_in_time_zone }, 9] },
68
72
  3,
69
73
  4
70
74
  ]
@@ -77,7 +81,7 @@ module Workarea
77
81
  end
78
82
 
79
83
  def year_id
80
- { 'year' => { '$year' => '$reporting_on' } }
84
+ { 'year' => { '$year' => reporting_on_in_time_zone } }
81
85
  end
82
86
  end
83
87
  end
@@ -13,7 +13,7 @@ module Workarea
13
13
  def filter
14
14
  {
15
15
  '$match' => {
16
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
16
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
17
17
  'orders' => { '$gt' => 0 }
18
18
  }
19
19
  }
@@ -13,7 +13,7 @@ module Workarea
13
13
  def filter
14
14
  {
15
15
  '$match' => {
16
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
16
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
17
17
  '$or' => [
18
18
  { 'orders' => { '$gt' => 0 } },
19
19
  { 'units_sold' => { '$gt' => 0 } },
@@ -13,7 +13,7 @@ module Workarea
13
13
  def filter
14
14
  {
15
15
  '$match' => {
16
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
16
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
17
17
  'orders' => { '$gt' => 0 }
18
18
  }
19
19
  }
@@ -13,7 +13,7 @@ module Workarea
13
13
  def filter
14
14
  {
15
15
  '$match' => {
16
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
16
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
17
17
  'orders' => { '$gt' => 0 }
18
18
  }
19
19
  }
@@ -13,7 +13,7 @@ module Workarea
13
13
  def filter
14
14
  {
15
15
  '$match' => {
16
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
16
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
17
17
  '$or' => [
18
18
  { 'orders' => { '$gt' => 0 } },
19
19
  { 'units_sold' => { '$gt' => 0 } },
@@ -17,7 +17,7 @@ module Workarea
17
17
  def filter
18
18
  result = {
19
19
  '$match' => {
20
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
20
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
21
21
  '$or' => [
22
22
  { 'orders' => { '$gt' => 0 } },
23
23
  { 'units_sold' => { '$gt' => 0 } },
@@ -23,7 +23,7 @@ module Workarea
23
23
  def filter
24
24
  {
25
25
  '$match' => {
26
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
26
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
27
27
  'orders' => { '$gt' => 0 }
28
28
  }
29
29
  }
@@ -14,7 +14,7 @@ module Workarea
14
14
  def filter
15
15
  {
16
16
  '$match' => {
17
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
17
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
18
18
  '$or' => [
19
19
  { 'orders' => { '$gt' => 0 } },
20
20
  { 'cancellations' => { '$gt' => 0 } }
@@ -13,7 +13,7 @@ module Workarea
13
13
  def filter_date_range
14
14
  {
15
15
  '$match' => {
16
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
16
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
17
17
  'total_results' => total_results_query
18
18
  }
19
19
  }
@@ -14,7 +14,7 @@ module Workarea
14
14
  def filter_date_range
15
15
  {
16
16
  '$match' => {
17
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at }
17
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc }
18
18
  }
19
19
  }
20
20
  end
@@ -14,7 +14,7 @@ module Workarea
14
14
  def filter
15
15
  {
16
16
  '$match' => {
17
- 'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at },
17
+ 'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
18
18
  'total_results' => 0
19
19
  }
20
20
  }
@@ -58,7 +58,7 @@ module Workarea
58
58
  return @customization if defined?(@customization)
59
59
 
60
60
  result = Customization.find_by_query(params[:q])
61
- @customization = result.active? ? result : nil
61
+ @customization = result.active? ? result : Customization.new
62
62
  end
63
63
 
64
64
  def boosts
@@ -5,11 +5,6 @@ Workarea::Configuration.define_fields do
5
5
  default: 6,
6
6
  description: 'How many failed login attempts before marking the user locked out'
7
7
 
8
- field 'Password Reset Timeout',
9
- type: :duration,
10
- default: 2.hours,
11
- description: 'How long a password reset URL stays valid'
12
-
13
8
  field 'Password Strength',
14
9
  type: :symbol,
15
10
  default: :weak,
@@ -1273,6 +1273,9 @@ module Workarea
1273
1273
  # Max number of non-unique affinity items that will be stored, older items
1274
1274
  # will be evicted first.
1275
1275
  config.max_affinity_items = 50
1276
+
1277
+ # How long a password reset URL stays valid
1278
+ config.password_reset_timeout = 2.hours
1276
1279
  end
1277
1280
  end
1278
1281
  end
@@ -34,41 +34,37 @@ module Workarea
34
34
  def find_config(name)
35
35
  config_slug = name.to_s.underscore.downcase
36
36
  from_config = Workarea.config[config_slug].presence ||
37
- Rails.application.secrets[config_slug]
38
-
39
- return from_config if from_config.present?
37
+ Rails.application.secrets[config_slug] ||
38
+ {}
40
39
 
41
40
  env_slug = name.to_s.underscore.upcase
42
- scheme = ENV["WORKAREA_#{env_slug}_SCHEME"].presence || DEFAULT[:scheme]
43
-
44
- {
45
- scheme: scheme,
46
- host: ENV["WORKAREA_#{env_slug}_HOST"].presence || DEFAULT[:host],
47
- port: ENV["WORKAREA_#{env_slug}_PORT"].presence || DEFAULT[:port],
48
- db: ENV["WORKAREA_#{env_slug}_DB"].presence || DEFAULT[:db],
49
- password: ENV["WORKAREA_#{env_slug}_PASSWORD"].presence,
50
- ssl: scheme == 'rediss' ? true : false
51
- }
41
+ from_config.symbolize_keys.reverse_merge(
42
+ scheme: ENV["WORKAREA_#{env_slug}_SCHEME"],
43
+ host: ENV["WORKAREA_#{env_slug}_HOST"],
44
+ port: ENV["WORKAREA_#{env_slug}_PORT"],
45
+ db: ENV["WORKAREA_#{env_slug}_DB"],
46
+ password: ENV["WORKAREA_#{env_slug}_PASSWORD"]
47
+ )
52
48
  end
53
49
  end
54
50
 
55
51
  attr_reader :config
56
- alias_method :to_h, :config
57
52
 
58
53
  def initialize(config)
59
54
  @config = config.to_h.deep_symbolize_keys
60
55
  end
61
56
 
62
57
  def scheme
63
- @config[:scheme]
58
+ @config[:scheme].presence || DEFAULT[:scheme]
64
59
  end
65
60
 
66
- def ssl
67
- @config[:ssl]
61
+ def ssl?
62
+ scheme == 'rediss'
68
63
  end
64
+ alias_method :ssl, :ssl?
69
65
 
70
66
  def host
71
- @config[:host]
67
+ @config[:host].presence || DEFAULT[:host]
72
68
  end
73
69
 
74
70
  def password
@@ -76,19 +72,30 @@ module Workarea
76
72
  end
77
73
 
78
74
  def port
79
- @config[:port]
75
+ @config[:port].presence || DEFAULT[:port]
80
76
  end
81
77
 
82
78
  def db
83
- @config[:db]
79
+ @config[:db].presence || DEFAULT[:db]
80
+ end
81
+
82
+ def to_h
83
+ {
84
+ scheme: scheme,
85
+ host: host,
86
+ port: port,
87
+ db: db,
88
+ password: password,
89
+ ssl: ssl?
90
+ }
84
91
  end
85
92
 
86
93
  def to_url
87
94
  base = "#{scheme}://"
88
95
  base << "admin:#{password}@" if password.present?
89
96
  base << "#{host}"
90
- base << ":#{port}" if port.present?
91
- base << "/#{db}" if db.present?
97
+ base << ":#{port}"
98
+ base << "/#{db}"
92
99
  base
93
100
  end
94
101
  end
@@ -106,7 +106,6 @@ require 'referer-parser'
106
106
  require 'dragonfly/s3_data_store'
107
107
  require 'serviceworker-rails'
108
108
  require 'chartkick'
109
- require 'logstasher' if ENV['WORKAREA_LOGSTASH'] =~ /true/i
110
109
  require 'mongoid/encrypted'
111
110
  require 'browser'
112
111
 
@@ -176,7 +175,6 @@ require 'workarea/configuration/asset_host'
176
175
  require 'workarea/configuration/s3'
177
176
  require 'workarea/configuration/cache_store'
178
177
  require 'workarea/configuration/action_mailer'
179
- require 'workarea/configuration/logstasher'
180
178
  require 'workarea/configuration/error_handling'
181
179
  require 'workarea/configuration/i18n'
182
180
  require 'workarea/configuration/session'
@@ -223,11 +221,14 @@ require 'workarea/warnings'
223
221
  require 'workarea/latest_version'
224
222
 
225
223
  #
226
- # Core
224
+ # Engines
227
225
  #
228
226
  #
229
227
  require 'workarea/version'
230
228
  require 'workarea/core/engine'
229
+ require 'workarea/admin/engine'
230
+ require 'workarea/storefront/engine'
231
+ require 'workarea/testing/engine' if Rails.env.test?
231
232
 
232
233
  #
233
234
  # Testing
@@ -29,7 +29,6 @@ module Workarea
29
29
  Configuration::CacheStore.load
30
30
  Configuration::AssetHost.load
31
31
  Configuration::ActionMailer.load
32
- Configuration::Logstasher.load
33
32
  Configuration::ErrorHandling.load
34
33
  Configuration::I18n.load
35
34
  end
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 0
5
+ PATCH = 1
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Configuration
5
+ class RedisTest < TestCase
6
+ def test_find_config
7
+ ENV['WORKAREA_FOO_REDIS_PORT'] = '1234'
8
+ Workarea.config.foo_redis = { scheme: 'rediss' }
9
+
10
+ result = Redis.find_config(:foo_redis)
11
+ assert_equal('rediss', result[:scheme])
12
+ assert_equal('1234', result[:port])
13
+
14
+ ensure
15
+ ENV.delete('WORKAREA_FOO_REDIS_PORT')
16
+ end
17
+
18
+ def test_defaults
19
+ instance = Redis.new(host: 'foo')
20
+ assert_equal('redis', instance.scheme)
21
+ assert_equal('foo', instance.host)
22
+ assert_equal(6379, instance.port)
23
+ assert_equal(0, instance.db)
24
+ refute(instance.ssl?)
25
+ assert_match(URI::regexp, instance.to_url)
26
+
27
+ instance = Redis.new(scheme: 'rediss')
28
+ assert_equal('rediss', instance.scheme)
29
+ assert_equal('localhost', instance.host)
30
+ assert_equal(6379, instance.port)
31
+ assert_equal(0, instance.db)
32
+ assert(instance.ssl?)
33
+ assert_match(URI::regexp, instance.to_url)
34
+ end
35
+
36
+ def test_to_h
37
+ result = Redis.new(scheme: 'rediss', port: 1234).to_h
38
+ assert_equal('rediss', result[:scheme])
39
+ assert_equal('localhost', result[:host])
40
+ assert_equal(1234, result[:port])
41
+ assert_equal(0, result[:db])
42
+ assert_nil(result[:password])
43
+ assert(result[:ssl])
44
+ end
45
+ end
46
+ end
47
+ end
@@ -47,6 +47,10 @@ module Workarea
47
47
  embedded_in :foo
48
48
  end
49
49
 
50
+ class Qoo < Bar
51
+ field :qoo, type: String
52
+ end
53
+
50
54
  def test_merging_rows_for_embedded
51
55
  model = Foo.create!(
52
56
  bars: [{ name: '1' }, { name: '2' }],
@@ -416,6 +420,50 @@ module Workarea
416
420
 
417
421
  assert_equal('653911', product.id)
418
422
  end
423
+
424
+ def test_embedded_subclasses
425
+ model = Foo.create!(bars: [{ name: '1' }, { _type: Qoo.name, qoo: '2' }])
426
+ csv = Csv.new.serialize(model)
427
+ results = CSV.parse(csv, headers: :first_row).map(&:to_h)
428
+
429
+ assert_equal(2, results.size)
430
+ results.each { |r| assert_equal(model.id.to_s, r['_id']) }
431
+ assert_equal('1', results.first['bars_name'])
432
+ assert_equal(Qoo.name, results.second['bars_type'])
433
+ assert_equal('2', results.second['bars_qoo'])
434
+
435
+ import = create_import(
436
+ model_type: Foo.name,
437
+ file: create_tempfile(csv, extension: 'csv'),
438
+ file_type: 'csv'
439
+ )
440
+
441
+ model.destroy
442
+ Csv.new(import).import!
443
+
444
+ model = Foo.first
445
+ assert_equal(2, model.bars.size)
446
+ assert_equal(Bar, model.bars.first.class)
447
+ assert_equal('1', model.bars.first.name)
448
+ assert_equal(Qoo, model.bars.second.class)
449
+ assert_equal('2', model.bars.second.qoo)
450
+ end
451
+
452
+ def test_exclude_updated_at
453
+ original_date = 2.days.ago
454
+ model = Foo.create!(name: '1', updated_at: original_date)
455
+ model.name = '2'
456
+ csv = Csv.new.serialize(model)
457
+ import = create_import(
458
+ model_type: Foo.name,
459
+ file: create_tempfile(csv, extension: 'csv'),
460
+ file_type: 'csv'
461
+ )
462
+
463
+ assert_changes -> { model.reload.updated_at.to_date } do
464
+ Csv.new(import).import!
465
+ end
466
+ end
419
467
  end
420
468
  end
421
469
  end
@@ -7,6 +7,16 @@ module Workarea
7
7
  include ApplicationDocument
8
8
  field :name, type: String
9
9
  field :ignore, type: Integer
10
+
11
+ embeds_many :bars, class_name: Foo.name
12
+ end
13
+
14
+ class Bar
15
+ include ApplicationDocument
16
+
17
+ field :name, type: String
18
+
19
+ embedded_in :foo, class_name: Foo.name
10
20
  end
11
21
 
12
22
  def test_ignored_fields
@@ -73,6 +83,36 @@ module Workarea
73
83
 
74
84
  assert_equal 'Bar', user.reload.first_name
75
85
  end
86
+
87
+ def test_exclude_updated_at
88
+ model = Foo.create!(name: '1', updated_at: 2.days.ago)
89
+ json = [model.as_json.merge(name: '2')].to_json
90
+ import = create_import(
91
+ model_type: Foo.name,
92
+ file: create_tempfile(json, extension: 'json'),
93
+ file_type: 'json'
94
+ )
95
+
96
+ assert_changes -> { model.reload.updated_at.to_date } do
97
+ Json.new(import).import!
98
+ end
99
+ end
100
+
101
+ def test_exclude_updated_at_when_embedded
102
+ original_date = 2.days.ago
103
+ parent = Foo.create!(updated_at: original_date)
104
+ model = parent.bars.create!(name: '1', updated_at: original_date)
105
+ json = [model.as_json.merge(name: '2')].to_json
106
+ import = create_import(
107
+ model_type: Foo.name,
108
+ file: create_tempfile(json, extension: 'json'),
109
+ file_type: 'json'
110
+ )
111
+
112
+ assert_changes -> { model.reload.updated_at.to_date } do
113
+ Json.new(import).import!
114
+ end
115
+ end
76
116
  end
77
117
  end
78
118
  end
@@ -277,11 +277,13 @@ module Workarea
277
277
  end
278
278
 
279
279
  def test_only_finds_active_customizations
280
- Search::Customization.find_by_query('*').tap do |c|
281
- c.active = false
282
- c.save
283
- end
284
- search = ProductSearch.new(q: '*')
280
+ customization = Search::Customization.find_by_query('foo')
281
+ search = ProductSearch.new(q: 'foo')
282
+ assert_equal(customization, search.customization)
283
+
284
+ customization.update!(active: false)
285
+ search = ProductSearch.new(q: 'foo')
286
+ refute_equal(customization, search.customization)
285
287
  refute(search.customization.persisted?)
286
288
  end
287
289
 
@@ -90,10 +90,9 @@ Gem::Specification.new do |s|
90
90
  s.add_dependency 'loofah', '~> 2.3.1'
91
91
  s.add_dependency 'referer-parser', '~> 0.3.0'
92
92
  s.add_dependency 'serviceworker-rails', '~> 0.5.5'
93
- s.add_dependency 'logstasher', '~> 1.2.2'
94
93
  s.add_dependency 'chartkick', '~> 3.3.0'
95
- s.add_dependency 'puma', '~> 4.0'
96
94
  s.add_dependency 'browser', '~> 2.6.1'
95
+ s.add_dependency 'puma', '>= 4.3.1'
97
96
 
98
97
  # HACK for vendoring active_shipping
99
98
  s.add_dependency 'active_utils', '~> 3.3.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Crouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1080,20 +1080,6 @@ dependencies:
1080
1080
  - - "~>"
1081
1081
  - !ruby/object:Gem::Version
1082
1082
  version: 0.5.5
1083
- - !ruby/object:Gem::Dependency
1084
- name: logstasher
1085
- requirement: !ruby/object:Gem::Requirement
1086
- requirements:
1087
- - - "~>"
1088
- - !ruby/object:Gem::Version
1089
- version: 1.2.2
1090
- type: :runtime
1091
- prerelease: false
1092
- version_requirements: !ruby/object:Gem::Requirement
1093
- requirements:
1094
- - - "~>"
1095
- - !ruby/object:Gem::Version
1096
- version: 1.2.2
1097
1083
  - !ruby/object:Gem::Dependency
1098
1084
  name: chartkick
1099
1085
  requirement: !ruby/object:Gem::Requirement
@@ -1109,33 +1095,33 @@ dependencies:
1109
1095
  - !ruby/object:Gem::Version
1110
1096
  version: 3.3.0
1111
1097
  - !ruby/object:Gem::Dependency
1112
- name: puma
1098
+ name: browser
1113
1099
  requirement: !ruby/object:Gem::Requirement
1114
1100
  requirements:
1115
1101
  - - "~>"
1116
1102
  - !ruby/object:Gem::Version
1117
- version: '4.0'
1103
+ version: 2.6.1
1118
1104
  type: :runtime
1119
1105
  prerelease: false
1120
1106
  version_requirements: !ruby/object:Gem::Requirement
1121
1107
  requirements:
1122
1108
  - - "~>"
1123
1109
  - !ruby/object:Gem::Version
1124
- version: '4.0'
1110
+ version: 2.6.1
1125
1111
  - !ruby/object:Gem::Dependency
1126
- name: browser
1112
+ name: puma
1127
1113
  requirement: !ruby/object:Gem::Requirement
1128
1114
  requirements:
1129
- - - "~>"
1115
+ - - ">="
1130
1116
  - !ruby/object:Gem::Version
1131
- version: 2.6.1
1117
+ version: 4.3.1
1132
1118
  type: :runtime
1133
1119
  prerelease: false
1134
1120
  version_requirements: !ruby/object:Gem::Requirement
1135
1121
  requirements:
1136
- - - "~>"
1122
+ - - ">="
1137
1123
  - !ruby/object:Gem::Version
1138
- version: 2.6.1
1124
+ version: 4.3.1
1139
1125
  - !ruby/object:Gem::Dependency
1140
1126
  name: active_utils
1141
1127
  requirement: !ruby/object:Gem::Requirement
@@ -1893,7 +1879,6 @@ files:
1893
1879
  - lib/workarea/configuration/error_handling.rb
1894
1880
  - lib/workarea/configuration/i18n.rb
1895
1881
  - lib/workarea/configuration/localized_active_fields.rb
1896
- - lib/workarea/configuration/logstasher.rb
1897
1882
  - lib/workarea/configuration/mongoid.rb
1898
1883
  - lib/workarea/configuration/mongoid_client.rb
1899
1884
  - lib/workarea/configuration/redis.rb
@@ -2073,6 +2058,7 @@ files:
2073
2058
  - test/lib/workarea/configuration/administrable/field_test.rb
2074
2059
  - test/lib/workarea/configuration/administrable/fieldset_test.rb
2075
2060
  - test/lib/workarea/configuration/configuration_test.rb
2061
+ - test/lib/workarea/configuration/redis_test.rb
2076
2062
  - test/lib/workarea/constants_test.rb
2077
2063
  - test/lib/workarea/elasticsearch/document_test.rb
2078
2064
  - test/lib/workarea/elasticsearch/query_cache_test.rb
@@ -1,16 +0,0 @@
1
- module Workarea
2
- module Configuration
3
- module Logstasher
4
- extend self
5
-
6
- def load
7
- if ENV['WORKAREA_LOGSTASH'] =~ /true/i
8
- Rails.application.config.logstasher.enabled = true
9
- Rails.application.config.logstasher.controller_enabled = true
10
- Rails.application.config.logstasher.suppress_app_log = true
11
- Rails.application.config.logstasher.source = `hostname`.strip!.to_s
12
- end
13
- end
14
- end
15
- end
16
- end