la_maquina 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +2 -3
- data/README.md +25 -6
- data/Rakefile +1 -1
- data/lib/la_maquina/ciguenal.rb +12 -8
- data/lib/la_maquina/error_notifier/base.rb +11 -0
- data/lib/la_maquina/error_notifier/honeybadger_notifier.rb +12 -0
- data/lib/la_maquina/error_notifier/silent_notifier.rb +10 -0
- data/lib/la_maquina/error_notifier.rb +6 -0
- data/lib/la_maquina/piston/base.rb +11 -0
- data/lib/la_maquina/piston/cache_piston.rb +39 -0
- data/lib/la_maquina/piston.rb +3 -6
- data/lib/la_maquina/version.rb +1 -1
- data/lib/la_maquina/volante.rb +13 -9
- data/lib/la_maquina.rb +6 -7
- data/test/ciguenal_test.rb +30 -0
- data/test/dummy/app/models/admin.rb +3 -3
- data/test/dummy/app/models/admin_trait.rb +3 -3
- data/test/dummy/app/models/admin_trait_modifier.rb +3 -3
- data/test/dummy/app/models/guest.rb +2 -2
- data/test/dummy/app/models/guest_trait.rb +3 -3
- data/test/dummy/app/models/guest_trait_modifier.rb +3 -2
- data/test/dummy/app/models/property.rb +3 -2
- data/test/dummy/app/models/standalone.rb +3 -2
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/config/initializers/la_maquina.rb +3 -0
- data/test/dummy/lib/dummy_comm_object.rb +5 -0
- data/test/dummy/lib/exploding_comm_object.rb +5 -0
- data/test/dummy/lib/test_notifier.rb +6 -0
- data/test/dummy/lib/test_piston.rb +5 -0
- data/test/la_maquina_test.rb +2 -2
- data/test/volante_test.rb +136 -0
- metadata +22 -20
- data/lib/la_maquina/pistons/cache_piston.rb +0 -37
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/models/danny_trejo.rb +0 -5
- data/test/dummy/app/models/machete.rb +0 -8
- data/test/dummy/config/initializers/cache_machine.rb +0 -2
- data/test/dummy/lib/dummy_cache_machine_comm_object.rb +0 -5
- data/test/dummy/lib/exploding_cache_machine_comm_object.rb +0 -5
- data/test/dummy/log/test.log +0 -3980
- data/test/master_cache_object_test.rb +0 -23
- data/test/subordinate_cache_object_test.rb +0 -136
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MasterCacheObjectTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@admin = admins(:wheel)
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_touch_cache_updates_cache_key
|
10
|
-
key = CacheMachine::MasterCacheObject.cache_key :admin, @admin.id
|
11
|
-
|
12
|
-
sleep(1)
|
13
|
-
CacheMachine::MasterCacheObject.touch_cache :admin, @admin.id
|
14
|
-
|
15
|
-
assert_not_equal key, CacheMachine::MasterCacheObject.cache_key(:admin, @admin.id)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_cache_key_generates_new_key
|
19
|
-
Redis.current.del CacheMachine::MasterCacheObject.redis_key(:admin, @admin.id)
|
20
|
-
|
21
|
-
assert_not_nil CacheMachine::MasterCacheObject.cache_key(:admin, @admin.id)
|
22
|
-
end
|
23
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
|
4
|
-
class MasterCacheObjectTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
def test_update_subordinate_objects_suports_explicit_class_and_class_name
|
8
|
-
admin_attr = admin_traits(:wheels_something_else)
|
9
|
-
admin_key = CacheMachine::MasterCacheObject.cache_key :admin, admin_attr.user.id
|
10
|
-
trait_key = CacheMachine::MasterCacheObject.cache_key :trait, admin_attr.thing.id
|
11
|
-
|
12
|
-
# sleep to prevent key clash
|
13
|
-
sleep(1)
|
14
|
-
|
15
|
-
admin_attr.value = "lol"
|
16
|
-
admin_attr.save!
|
17
|
-
|
18
|
-
assert_not_equal admin_key, CacheMachine::MasterCacheObject.cache_key(:admin, admin_attr.user.id)
|
19
|
-
assert_not_equal trait_key, CacheMachine::MasterCacheObject.cache_key(:trait, admin_attr.thing.id)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_update_subordinate_object_can_update_self
|
23
|
-
wheel = admins(:wheel)
|
24
|
-
key = CacheMachine::MasterCacheObject.cache_key :admin, wheel.id
|
25
|
-
|
26
|
-
sleep(1)
|
27
|
-
|
28
|
-
wheel.name = "WHEEL!"
|
29
|
-
wheel.save!
|
30
|
-
|
31
|
-
assert_not_equal key, CacheMachine::MasterCacheObject.cache_key(:admin, wheel.id)
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def test_update_subordinate_object_supports_implict_class
|
36
|
-
|
37
|
-
guest_attr = guest_traits(:gregs_something)
|
38
|
-
guest_key = CacheMachine::MasterCacheObject.cache_key :guest, guest_attr.guest.id
|
39
|
-
trait_key = CacheMachine::MasterCacheObject.cache_key :trait, guest_attr.trait.id
|
40
|
-
|
41
|
-
# sleep to prevent key clash
|
42
|
-
sleep(1)
|
43
|
-
|
44
|
-
guest_attr.value = "who cares"
|
45
|
-
guest_attr.save!
|
46
|
-
|
47
|
-
assert_not_equal guest_key, CacheMachine::MasterCacheObject.cache_key(:guest, guest_attr.guest.id)
|
48
|
-
assert_not_equal trait_key, CacheMachine::MasterCacheObject.cache_key(:trait, guest_attr.trait.id)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_update_subordinate_object_supports_polymorphism
|
52
|
-
su_whatever = properties(:su_whatever)
|
53
|
-
gregs_thing = properties(:gregs_thing)
|
54
|
-
|
55
|
-
su_key = CacheMachine::MasterCacheObject.cache_key :admin, su_whatever.user.id
|
56
|
-
gt_key = CacheMachine::MasterCacheObject.cache_key :guest, gregs_thing.user.id
|
57
|
-
|
58
|
-
sleep(1)
|
59
|
-
|
60
|
-
su_whatever.value = "blah"
|
61
|
-
gregs_thing.value = "blah blah"
|
62
|
-
|
63
|
-
su_whatever.save!
|
64
|
-
gregs_thing.save!
|
65
|
-
|
66
|
-
assert_not_equal su_key, CacheMachine::MasterCacheObject.cache_key(:admin, su_whatever.user.id)
|
67
|
-
assert_not_equal gt_key, CacheMachine::MasterCacheObject.cache_key(:guest, gregs_thing.user.id)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_subordingate_object_creation_updates_master
|
71
|
-
greg = guests(:greg)
|
72
|
-
key = CacheMachine::MasterCacheObject.cache_key :guest, greg.id
|
73
|
-
|
74
|
-
sleep(1)
|
75
|
-
|
76
|
-
greg.guest_traits.create!(:value => "some bullshit")
|
77
|
-
|
78
|
-
assert_not_equal key, CacheMachine::MasterCacheObject.cache_key(:guest, greg.id)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_subordingate_object_destruction_updates_master
|
82
|
-
wheel = admins(:wheel)
|
83
|
-
wheel_attr = admin_traits(:wheels_something_else)
|
84
|
-
|
85
|
-
key = CacheMachine::MasterCacheObject.cache_key :admin, wheel.id
|
86
|
-
|
87
|
-
sleep(1)
|
88
|
-
|
89
|
-
wheel_attr.destroy
|
90
|
-
|
91
|
-
assert_not_equal key, CacheMachine::MasterCacheObject.cache_key(:admin, wheel.id)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_subordinate_object_can_update_through
|
95
|
-
modifier = guest_trait_modifiers(:gregs_something_modifier)
|
96
|
-
key = CacheMachine::MasterCacheObject.cache_key(:guest, modifier.guest_trait.guest.id)
|
97
|
-
|
98
|
-
sleep(1)
|
99
|
-
|
100
|
-
modifier.modifier = "something something darkside"
|
101
|
-
modifier.save!
|
102
|
-
|
103
|
-
assert_not_equal key, CacheMachine::MasterCacheObject.cache_key(:guest, modifier.guest_trait.guest.id)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_subordinate_object_can_update_through_with_explicit_target_class
|
107
|
-
modifier = admin_trait_modifiers(:wheels_something_else_modifier)
|
108
|
-
admin_key = CacheMachine::MasterCacheObject.cache_key :admin, modifier.admin_trait.user.id
|
109
|
-
trait_key = CacheMachine::MasterCacheObject.cache_key :trait, modifier.admin_trait.thing.id
|
110
|
-
|
111
|
-
sleep(1)
|
112
|
-
|
113
|
-
modifier.modifier = "something something darkside"
|
114
|
-
modifier.save!
|
115
|
-
|
116
|
-
assert_not_equal admin_key, CacheMachine::MasterCacheObject.cache_key(:admin, modifier.admin_trait.user.id)
|
117
|
-
assert_not_equal trait_key, CacheMachine::MasterCacheObject.cache_key(:trait, modifier.admin_trait.thing.id)
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_touch_cache_through_gem
|
121
|
-
admin = admins(:su)
|
122
|
-
admin.update_attribute(:name, "lol")
|
123
|
-
|
124
|
-
assert_equal $dummy_cache_params[:subordinate_class], "admin"
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_touch_cache_can_handle_comm_object_failures
|
128
|
-
thing = standalones(:thing)
|
129
|
-
thing.value = "something new"
|
130
|
-
thing.save
|
131
|
-
|
132
|
-
assert_equal $error.class, RuntimeError
|
133
|
-
assert_equal $error.to_s, "oh noes!"
|
134
|
-
assert_equal $deets[:master_class], "standalone"
|
135
|
-
end
|
136
|
-
end
|