infopark_component_cache 3.1.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +25 -0
  4. data/.rubocop_todo.yml +115 -0
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +24 -0
  7. data/Gemfile +3 -1
  8. data/Gemfile.lock +214 -0
  9. data/Gemfile.rails50 +6 -0
  10. data/Gemfile.rails50.lock +206 -0
  11. data/Gemfile.rails51 +6 -0
  12. data/Gemfile.rails51.lock +206 -0
  13. data/README.md +1 -1
  14. data/Rakefile +7 -7
  15. data/app/helpers/infopark_component_cache_helper.rb +2 -2
  16. data/infopark_component_cache.gemspec +16 -13
  17. data/lib/engine.rb +6 -7
  18. data/lib/infopark_component_cache.rb +1 -2
  19. data/lib/infopark_component_cache/abstract_cache_storage.rb +4 -3
  20. data/lib/infopark_component_cache/cache_storage.rb +1 -0
  21. data/lib/infopark_component_cache/component.rb +9 -5
  22. data/lib/infopark_component_cache/component_cache.rb +31 -30
  23. data/lib/infopark_component_cache/consistency_guard.rb +1 -1
  24. data/lib/infopark_component_cache/delayed_guard.rb +7 -7
  25. data/lib/infopark_component_cache/guards/cms_state_guard.rb +6 -5
  26. data/lib/infopark_component_cache/guards/last_changed.rb +5 -2
  27. data/lib/infopark_component_cache/guards/obj_count.rb +3 -3
  28. data/lib/infopark_component_cache/guards/valid_from.rb +7 -10
  29. data/lib/infopark_component_cache/guards/valid_until.rb +7 -9
  30. data/lib/infopark_component_cache/key_generator.rb +3 -3
  31. data/lib/infopark_component_cache/version.rb +1 -1
  32. data/lib/infopark_component_cache/volatile_cache.rb +1 -1
  33. data/lib/infopark_component_cache/volatile_cache_storage.rb +1 -0
  34. data/spec/dummy/Rakefile +1 -1
  35. data/spec/dummy/config.ru +1 -1
  36. data/spec/dummy/config/application.rb +4 -2
  37. data/spec/dummy/config/boot.rb +5 -5
  38. data/spec/dummy/config/environment.rb +1 -1
  39. data/spec/dummy/config/environments/development.rb +1 -0
  40. data/spec/dummy/config/environments/test.rb +1 -0
  41. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  42. data/spec/dummy/config/initializers/session_store.rb +1 -1
  43. data/spec/dummy/db/schema.rb +1 -2
  44. data/spec/lib/infopark_component_cache/component_cache_spec.rb +118 -0
  45. data/spec/lib/{delayed_guard_spec.rb → infopark_component_cache/delayed_guard_spec.rb} +3 -3
  46. data/spec/lib/{guards → infopark_component_cache/guards}/always_consistent_spec.rb +7 -6
  47. data/spec/lib/{guards → infopark_component_cache/guards}/last_changed_spec.rb +20 -12
  48. data/spec/lib/{guards → infopark_component_cache/guards}/never_consistent_spec.rb +7 -6
  49. data/spec/lib/{guards → infopark_component_cache/guards}/obj_count_spec.rb +20 -12
  50. data/spec/lib/{guards → infopark_component_cache/guards}/valid_from_spec.rb +20 -12
  51. data/spec/lib/{guards → infopark_component_cache/guards}/valid_until_spec.rb +23 -14
  52. data/spec/spec_helper.rb +8 -8
  53. data/spec/support/cache_switching_macros.rb +4 -4
  54. metadata +96 -40
  55. data/spec/lib/compontent_cache_spec.rb +0 -116
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe InfoparkComponentCache::ComponentCache do
4
- let(:obj) { double(name: 'spec_obj', id: 2001) }
5
- let(:name) { 'spec_cached_component' }
6
- let(:params) { {some: 'additional', params: 'supplied'} }
7
- let(:guard) { Class.new(Struct.new(:component)) }
8
-
9
- subject { described_class.new(obj, name, params, [guard]) }
10
-
11
- context 'with caching disabled' do
12
- before { allow(Rails.application.config.action_controller).to receive(:perform_caching).and_return(false) }
13
-
14
- describe '#fetch' do
15
- let(:value) { 'very_hard_computation_required_for_this_string' }
16
- let(:specific_guard) { subject.guards.first }
17
-
18
- it 'returns the passed the block value' do
19
- expect(subject.fetch { value }).to eq(value)
20
- end
21
-
22
- it 'never calls any methods on the guard' do
23
- expect(specific_guard).not_to receive(:consistent?)
24
- expect(specific_guard).not_to receive(:guard!)
25
-
26
- subject.fetch { value }
27
- end
28
- end
29
- end
30
-
31
- context 'with caching enabled' do
32
- before { allow(Rails.application.config.action_controller).to receive(:perform_caching).and_return(true) }
33
-
34
- let(:guard) { Class.new(InfoparkComponentCache::ConsistencyGuard) {
35
- def consistent?
36
- cache.exist?(:guard_called)
37
- end
38
-
39
- def guard!
40
- cache.write(:guard_called, 1)
41
- end
42
- } }
43
-
44
- describe '#fetch' do
45
- let(:value) { 'very_hard_computation_required_for_this_string' }
46
- let(:specific_guard) { subject.guards.first }
47
- let(:computer) { double }
48
-
49
- it 'returns the passed the block value' do
50
- expect(subject.fetch { value }).to eq(value)
51
- end
52
-
53
- it 'calls the required methods on the guard' do
54
- expect(specific_guard).to receive(:consistent?).exactly(3).times
55
- expect(specific_guard).to receive(:guard!).exactly(3).times
56
-
57
- 3.times { subject.fetch { value } }
58
- end
59
-
60
- it 'only evalues the block once' do
61
- expect(computer).to receive(:compute).and_return(value).once
62
-
63
- 3.times { expect(subject.fetch { computer.compute }).to eq(value) }
64
- end
65
- end
66
- end
67
-
68
- describe '#compontent' do
69
- subject { described_class.new(obj, name, params).component }
70
-
71
- it 'stores the passed obj' do
72
- expect(subject.obj).to eq(obj)
73
- end
74
-
75
- it 'stores the passed name' do
76
- expect(subject.name).to eq(name)
77
- end
78
-
79
- it 'stores the passed params' do
80
- expect(subject.params).to eq(params)
81
- end
82
- end
83
-
84
- describe '#guards' do
85
- let(:guard_class1) { Struct.new(:component) }
86
- let(:guard_class2) { Struct.new(:compontent, :extra) }
87
- let(:guard_params) { {guard: guard_class2, something: 'more'} }
88
-
89
- subject { described_class.new(obj, name, params, [guard_class1, guard_params]).guards }
90
-
91
- it 'contains an array of passed guards' do
92
- expect(subject).to match_array([
93
- an_instance_of(guard_class1),
94
- an_instance_of(guard_class2)
95
- ])
96
- end
97
-
98
- it 'preserves the extra params' do
99
- expect(subject.last.extra).to eq(guard_params)
100
- end
101
-
102
- context 'with no guards specified in the constructors' do
103
- subject { described_class.new(obj, name, params).guards }
104
-
105
- it 'contains standard guards' do
106
- expect(subject).to match_array([
107
- an_instance_of(InfoparkComponentCache::Guards::ValuePresent),
108
- an_instance_of(InfoparkComponentCache::Guards::LastChanged),
109
- an_instance_of(InfoparkComponentCache::Guards::ObjCount),
110
- an_instance_of(InfoparkComponentCache::Guards::ValidFrom),
111
- an_instance_of(InfoparkComponentCache::Guards::ValidUntil)
112
- ])
113
- end
114
- end
115
- end
116
- end