solidus_searchkick 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 544ccb542d567a10665a33d0c7ae0536fe63ade5
4
- data.tar.gz: 26f09eaffa8fdcf2d4436c510140ac4b4b54d6cf
3
+ metadata.gz: 8d41ff74254c659a4764941593f5d0844550e09f
4
+ data.tar.gz: 054de8b8a244bf3c711a84245c951753c76a8e49
5
5
  SHA512:
6
- metadata.gz: 2d375e3c5641838bcebdc3756d2faef1a8fe2080593508122a540cc4cd319f6df5ef28ea0aa40affb467772e7160f0f4b59a0ce73481bb2f1aa2beeb95babf16
7
- data.tar.gz: efaad9b7dbca148e8b903de900e616689625f46e2e982cd04b3bc5c24811687c7b09d54959a4d3a8e5cd322fa90a6b260c4756ecb1fdbdb60b9f9a4540b3d10a
6
+ metadata.gz: 941aff221b9b8c4eda972a9568db0da12731b75920a9301280a4021163427f97ab79af35becd387ce1889472425ad05409296e026a08ca788792e1ac51a0b4c8
7
+ data.tar.gz: 6a95a64426eb9e354cb99f43a95cc6a506686de3f37ea261b7aca28dd809b5fb5b5a043572bf1acce2ce6e8eff213cd9eb5463ba39d174120cdf136597b846b4
@@ -2,7 +2,7 @@ Spree::ProductsHelper.module_eval do
2
2
  def cache_key_for_products
3
3
  count = @products.count
4
4
  hash = Digest::SHA1.hexdigest(params.to_json)
5
- max_updated_at = (@products.maximum(:updated_at) || Date.today).to_s(:number)
5
+ max_updated_at = (@products.records.maximum(:updated_at) || Date.today).to_s(:number)
6
6
  "#{I18n.locale}/#{current_pricing_options.cache_key}/spree/products/all-#{params[:page]}-#{hash}-#{max_updated_at}-#{count}"
7
7
  end
8
8
  end
@@ -1,3 +1,6 @@
1
+ # 0.3.4
2
+ Updated cache_key_for_products (thanks @Sinetheta)
3
+
1
4
  # 0.3.3
2
5
  Updates default indexed currency to `Spree::Config.currency` instead of the products `cost_currency`.
3
6
 
@@ -1,3 +1,3 @@
1
1
  module SolidusSearchkick
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Spree::ProductsHelper do
4
+ include ActiveSupport::Testing::TimeHelpers
5
+
6
+ describe 'cache_key_for_products' do
7
+ helper do
8
+ # Normally provided by Spree::Core::ControllerHelpers::Pricing
9
+ def current_pricing_options
10
+ Spree::Config.pricing_options_class.new(currency: 'USD')
11
+ end
12
+
13
+ # Normally provided by Spree::Core::ControllerHelpers::Search
14
+ def build_searcher(params)
15
+ Spree::Config.searcher_class.new(params).tap do |searcher|
16
+ searcher.current_user = FactoryGirl.create(:user)
17
+ searcher.pricing_options = current_pricing_options
18
+ end
19
+ end
20
+ end
21
+
22
+ # Performed in controller before cache key is used
23
+ def load_products
24
+ products
25
+ Spree::Product.reindex
26
+ searcher = helper.build_searcher(params)
27
+ @products = searcher.retrieve_products
28
+ end
29
+
30
+ let(:products) do
31
+ travel_to(Time.local(1990)) do
32
+ create_list(:product, 2)
33
+ end
34
+ end
35
+ let(:params) { {} }
36
+
37
+ subject { helper.cache_key_for_products }
38
+
39
+ after do
40
+ # Since we're using timecop we need to avoid index collisions
41
+ Spree::Product.searchkick_index.delete
42
+ end
43
+
44
+ it 'returns a long string' do
45
+ load_products
46
+ is_expected.to eq('en/USD/spree/products/all--bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f-19900101000000-2')
47
+ end
48
+
49
+ context 'when products are updated' do
50
+ before do
51
+ load_products
52
+ products.first.update(updated_at: Time.local(1992))
53
+ end
54
+
55
+ it { is_expected.to eq('en/USD/spree/products/all--bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f-19920101000000-2') }
56
+ end
57
+
58
+ context 'when no products are found' do
59
+ let(:products) { nil }
60
+
61
+ it 'uses the current time ' do
62
+ travel_to(Time.local(1991)) do
63
+ load_products
64
+ expect(subject).to eq('en/USD/spree/products/all--bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f-19910101-0')
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus
@@ -258,6 +258,7 @@ files:
258
258
  - lib/spree/search/searchkick.rb
259
259
  - solidus_searchkick.gemspec
260
260
  - spec/controllers/spree/products_controller_spec.rb
261
+ - spec/helpers/products_helper_spec.rb
261
262
  - spec/lib/spree/search/searchkick_spec.rb
262
263
  - spec/models/spree/order_spec.rb
263
264
  - spec/models/spree/product_spec.rb
@@ -290,6 +291,7 @@ specification_version: 4
290
291
  summary: Add searchkick to Solidus
291
292
  test_files:
292
293
  - spec/controllers/spree/products_controller_spec.rb
294
+ - spec/helpers/products_helper_spec.rb
293
295
  - spec/lib/spree/search/searchkick_spec.rb
294
296
  - spec/models/spree/order_spec.rb
295
297
  - spec/models/spree/product_spec.rb