thermos 0.5.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,11 +13,11 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static file server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
16
+ config.serve_static_files = true
17
+ config.static_cache_control = "public, max-age=3600"
18
18
 
19
19
  # Show full error reports and disable caching.
20
- config.consider_all_requests_local = true
20
+ config.consider_all_requests_local = true
21
21
  config.action_controller.perform_caching = false
22
22
 
23
23
  # Raise exceptions instead of rendering exception templates.
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '1.0'
4
+ # Rails.application.config.assets.version = '1.0'
5
5
 
6
6
  # Add additional assets to the asset load path
7
7
  # Rails.application.config.assets.paths << Emoji.images_path
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.session_store :cookie_store, key: '_dummy_session'
3
+ Rails.application.config.session_store :cookie_store, key: "_dummy_session"
@@ -1,19 +1,14 @@
1
1
  Rails.application.routes.draw do
2
2
  # The priority is based upon order of creation: first created -> highest priority.
3
3
  # See how all your routes lay out with "rake routes".
4
-
5
4
  # You can have the root of your site routed with "root"
6
5
  # root 'welcome#index'
7
-
8
6
  # Example of regular route:
9
7
  # get 'products/:id' => 'catalog#view'
10
-
11
8
  # Example of named route that can be invoked with purchase_url(id: product.id)
12
9
  # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
-
14
10
  # Example resource route (maps HTTP verbs to controller actions automatically):
15
11
  # resources :products
16
-
17
12
  # Example resource route with options:
18
13
  # resources :products do
19
14
  # member do
@@ -25,13 +20,11 @@ Rails.application.routes.draw do
25
20
  # get 'sold'
26
21
  # end
27
22
  # end
28
-
29
23
  # Example resource route with sub-resources:
30
24
  # resources :products do
31
25
  # resources :comments, :sales
32
26
  # resource :seller
33
27
  # end
34
-
35
28
  # Example resource route with more complex sub-resources:
36
29
  # resources :products do
37
30
  # resources :comments
@@ -39,14 +32,12 @@ Rails.application.routes.draw do
39
32
  # get 'recent', on: :collection
40
33
  # end
41
34
  # end
42
-
43
35
  # Example resource route with concerns:
44
36
  # concern :toggleable do
45
37
  # post 'toggle'
46
38
  # end
47
39
  # resources :posts, concerns: :toggleable
48
40
  # resources :photos, concerns: :toggleable
49
-
50
41
  # Example resource route within a namespace:
51
42
  # namespace :admin do
52
43
  # # Directs /admin/products/* to Admin::ProductsController
@@ -10,33 +10,31 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2016_03_26_174530) do
14
-
13
+ ActiveRecord::Schema[7.0].define(version: 2016_03_26_174530) do
15
14
  create_table "categories", force: :cascade do |t|
16
15
  t.string "name"
17
16
  t.integer "store_id"
18
- t.datetime "created_at", null: false
19
- t.datetime "updated_at", null: false
17
+ t.datetime "created_at", precision: nil, null: false
18
+ t.datetime "updated_at", precision: nil, null: false
20
19
  end
21
20
 
22
21
  create_table "category_items", force: :cascade do |t|
23
22
  t.string "name"
24
23
  t.integer "category_id"
25
24
  t.integer "product_id"
26
- t.datetime "created_at", null: false
27
- t.datetime "updated_at", null: false
25
+ t.datetime "created_at", precision: nil, null: false
26
+ t.datetime "updated_at", precision: nil, null: false
28
27
  end
29
28
 
30
29
  create_table "products", force: :cascade do |t|
31
30
  t.string "name"
32
- t.datetime "created_at", null: false
33
- t.datetime "updated_at", null: false
31
+ t.datetime "created_at", precision: nil, null: false
32
+ t.datetime "updated_at", precision: nil, null: false
34
33
  end
35
34
 
36
35
  create_table "stores", force: :cascade do |t|
37
36
  t.string "name"
38
- t.datetime "created_at", null: false
39
- t.datetime "updated_at", null: false
37
+ t.datetime "created_at", precision: nil, null: false
38
+ t.datetime "updated_at", precision: nil, null: false
40
39
  end
41
-
42
40
  end
@@ -0,0 +1,52 @@
1
+ require "test_helper"
2
+
3
+ class FilterTest < ActiveSupport::TestCase
4
+ self.use_transactional_tests = true
5
+ teardown :clear_cache
6
+
7
+ test "allows filtering for which records should be rebuilt" do
8
+ mock = Minitest::Mock.new
9
+ category = categories(:baseball)
10
+ filter = ->(model) { model.name.match("ball") }
11
+ Thermos.fill(
12
+ key: "key",
13
+ model: Category,
14
+ lookup_key: "name",
15
+ filter: filter,
16
+ ) { |name| mock.call(name) }
17
+
18
+ mock.expect(:call, 1, ["basketball"])
19
+ category.update!(name: "basketball")
20
+ mock.verify
21
+
22
+ mock.expect(:call, 1, ["hockey"])
23
+ category.update!(name: "hockey")
24
+ assert_raises(MockExpectationError) { mock.verify }
25
+ end
26
+
27
+ test "allows filtering based on the beverage when multiple beverages are configured and only one of them has a filter" do
28
+ mock = Minitest::Mock.new
29
+ store = stores(:supermarket)
30
+ category = categories(:baseball)
31
+
32
+ # filter method specific to one model
33
+ # store.ball? doesn't exist
34
+ filter = ->(model) { model.ball? }
35
+
36
+ Thermos.fill(
37
+ key: "key",
38
+ model: Category,
39
+ lookup_key: "name",
40
+ filter: filter,
41
+ ) { |name| mock.call(name) }
42
+
43
+ Thermos.fill(key: "key_2", model: Store, lookup_key: "name") do |name|
44
+ mock.call(name)
45
+ end
46
+
47
+ mock.expect(:call, 1, ["groceries"])
48
+ store.update!(name: "groceries")
49
+ assert_equal 1, Thermos.drink(key: "key_2", id: "groceries")
50
+ mock.verify
51
+ end
52
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class QueueTest < ActiveSupport::TestCase
4
+ include ActiveJob::TestHelper
5
+ self.use_transactional_tests = true
6
+ teardown :clear_cache
7
+
8
+ test "uses the default background queue by default" do
9
+ mock = Minitest::Mock.new
10
+ category = categories(:baseball)
11
+
12
+ Thermos.fill(key: "key", model: Category) { |id| mock.call(id) }
13
+
14
+ mock.expect(:call, 1, [category.id])
15
+ assert_performed_with(job: Thermos::RebuildCacheJob, queue: "default") do
16
+ category.update!(name: "foo")
17
+ end
18
+ mock.verify
19
+ end
20
+
21
+ test "can specify a preferred queue name for the cache filling" do
22
+ mock = Minitest::Mock.new
23
+ category = categories(:baseball)
24
+
25
+ Thermos.fill(key: "key", model: Category, queue: "low_priority") do |id|
26
+ mock.call(id)
27
+ end
28
+
29
+ mock.expect(:call, 1, [category.id])
30
+ assert_performed_with(
31
+ job: Thermos::RebuildCacheJob,
32
+ queue: "low_priority",
33
+ ) { category.update!(name: "foo") }
34
+ mock.verify
35
+ end
36
+ end
data/test/test_helper.rb CHANGED
@@ -1,23 +1,33 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [
6
+ File.expand_path("../../test/dummy/db/migrate", __FILE__),
7
+ ]
6
8
  require "rails/test_help"
7
9
 
8
10
  # Filter out Minitest backtrace while allowing backtrace from other libraries
9
11
  # to be shown.
10
12
  Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
- require 'minitest/mock'
13
+ require "minitest/mock"
12
14
 
13
15
  # Load support files
14
16
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
17
 
16
18
  # Load fixtures from the engine
17
19
  if ActiveSupport::TestCase.respond_to?(:fixture_path=)
18
- ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
19
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
20
+ ActiveSupport::TestCase.fixture_path =
21
+ File.expand_path("../fixtures", __FILE__)
22
+ ActionDispatch::IntegrationTest.fixture_path =
23
+ ActiveSupport::TestCase.fixture_path
20
24
  ActiveSupport::TestCase.fixtures :all
21
25
  end
22
26
 
23
27
  ActiveJob::Base.queue_adapter = :inline
28
+ ActiveSupport.test_order = :random
29
+
30
+ def clear_cache
31
+ Thermos::BeverageStorage.instance.empty
32
+ Rails.cache.clear
33
+ end