la_maquina 0.0.2 → 0.0.3

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +2 -3
  4. data/README.md +25 -6
  5. data/Rakefile +1 -1
  6. data/lib/la_maquina/ciguenal.rb +12 -8
  7. data/lib/la_maquina/error_notifier/base.rb +11 -0
  8. data/lib/la_maquina/error_notifier/honeybadger_notifier.rb +12 -0
  9. data/lib/la_maquina/error_notifier/silent_notifier.rb +10 -0
  10. data/lib/la_maquina/error_notifier.rb +6 -0
  11. data/lib/la_maquina/piston/base.rb +11 -0
  12. data/lib/la_maquina/piston/cache_piston.rb +39 -0
  13. data/lib/la_maquina/piston.rb +3 -6
  14. data/lib/la_maquina/version.rb +1 -1
  15. data/lib/la_maquina/volante.rb +13 -9
  16. data/lib/la_maquina.rb +6 -7
  17. data/test/ciguenal_test.rb +30 -0
  18. data/test/dummy/app/models/admin.rb +3 -3
  19. data/test/dummy/app/models/admin_trait.rb +3 -3
  20. data/test/dummy/app/models/admin_trait_modifier.rb +3 -3
  21. data/test/dummy/app/models/guest.rb +2 -2
  22. data/test/dummy/app/models/guest_trait.rb +3 -3
  23. data/test/dummy/app/models/guest_trait_modifier.rb +3 -2
  24. data/test/dummy/app/models/property.rb +3 -2
  25. data/test/dummy/app/models/standalone.rb +3 -2
  26. data/test/dummy/config/application.rb +1 -1
  27. data/test/dummy/config/initializers/la_maquina.rb +3 -0
  28. data/test/dummy/lib/dummy_comm_object.rb +5 -0
  29. data/test/dummy/lib/exploding_comm_object.rb +5 -0
  30. data/test/dummy/lib/test_notifier.rb +6 -0
  31. data/test/dummy/lib/test_piston.rb +5 -0
  32. data/test/la_maquina_test.rb +2 -2
  33. data/test/volante_test.rb +136 -0
  34. metadata +22 -20
  35. data/lib/la_maquina/pistons/cache_piston.rb +0 -37
  36. data/test/dummy/README.rdoc +0 -28
  37. data/test/dummy/app/models/danny_trejo.rb +0 -5
  38. data/test/dummy/app/models/machete.rb +0 -8
  39. data/test/dummy/config/initializers/cache_machine.rb +0 -2
  40. data/test/dummy/lib/dummy_cache_machine_comm_object.rb +0 -5
  41. data/test/dummy/lib/exploding_cache_machine_comm_object.rb +0 -5
  42. data/test/dummy/log/test.log +0 -3980
  43. data/test/master_cache_object_test.rb +0 -23
  44. data/test/subordinate_cache_object_test.rb +0 -136
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d18a4ef4eed5cd9ae9141c6177b17710a1df9242
4
- data.tar.gz: 1be1594aad8a4ca3d445aaf9e73393a6d9a567cf
3
+ metadata.gz: 1ce3d8574213b0db902e504ad4b66e30e0961951
4
+ data.tar.gz: 258fec304013d1b468633d04c4cbc4f3408522a5
5
5
  SHA512:
6
- metadata.gz: 126281d86542110b43fe57c135f483cafb5fdbd0ce34e236570447e5597dd8302e20071946f47a766a4c0ea671b370f4c796486d96daf986c7d953d264e46eb1
7
- data.tar.gz: db6e7be277c7d39881edf1f3b64582ff081e27f83e7392e5af00160863c0fb36f8e2ad82c3f903fc25100a874736931ff973cb61f4f33e463b2c985f2c32b8fe
6
+ metadata.gz: 18fbd41257b6fa9a3e423887fa2a0c345b1e51e5d0bd4de656abdd69430215f508060a54696fdebc2318e06ab9845e12f68a5b0749e814456c4b4323aa208864
7
+ data.tar.gz: 37f9ca36e459a12e4bdf199381af7eb8b007f38a9a5e2a5a62a52ffa35d54256c42addd9bcfedbcb6998b4a27d459d94d56a0ebc00a79c52818ff0de0fdb83b7
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage/
2
+ test/dummy/log/*
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cache_machine (0.0.8)
5
- redis
4
+ la_maquina (0.0.2)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
@@ -120,7 +119,7 @@ PLATFORMS
120
119
 
121
120
  DEPENDENCIES
122
121
  bundler (~> 1.6)
123
- cache_machine!
122
+ la_maquina!
124
123
  rails (>= 4.2.0)
125
124
  rake
126
125
  redis
data/README.md CHANGED
@@ -42,7 +42,7 @@ class Machete < ActiveRecord::Base
42
42
  belongs_to :danny_trejo
43
43
 
44
44
  include LaMaquina::Volante
45
- updates :danny_trejo
45
+ notifies :danny_trejo
46
46
  end
47
47
  ```
48
48
  and we want to let `DannyTrejo` know when his `Machete` has been updated so that we can reindex him.
@@ -50,7 +50,7 @@ and we want to let `DannyTrejo` know when his `Machete` has been updated so that
50
50
  `Machete` is set up to fire on update, so we'll set up a listener Piston that looks like this:
51
51
 
52
52
  ```ruby
53
- class SunspotPiston < LaMaquina::Piston
53
+ class SunspotPiston < LaMaquina::Piston::Base
54
54
  class << self
55
55
  def fire!(klass = "", id = nil)
56
56
  indexed_class.find(id).index!
@@ -69,13 +69,32 @@ Which finds the klass, does a find on it and fires off [Sunspot](https://github.
69
69
 
70
70
  ### Setup
71
71
 
72
- The setup is pretty straightforward: you do all the setting up in `config/la_maquina.rb'.
72
+ The setup is pretty straightforward: you do all the setting up in `config/initializers/la_maquina.rb`.
73
73
 
74
- The 2 things you have to do are: set up the pistons(if they need configuring) and install them.
74
+ The 3 things you have to do are: set up the pistons(if they need configuring), install them, and configure the error_handler.
75
75
  For example, if you're using the CachePiston and need to set up Redis, here's how your `la_maquina.rb` will look
76
76
 
77
- LaMaquina::Pistons::CachePiston.redis = Redis::Namespace.new(:cache_piston, redis: MyRedisInstance)
78
- LaMaquina::Ciguenal.install MyPiston, LaMaquina::Pistons::CachePiston
77
+ ```ruby
78
+ LaMaquina::Piston::CachePiston.redis = Redis::Namespace.new(:cache_piston, redis: Redis.new)
79
+ LaMaquina::Ciguenal.install LaMaquina::Piston::CachePiston, TestPiston
80
+ LaMaquina.error_notifier = LaMaquina::ErrorNotifier::HoneybadgerNotifier
81
+ ```
82
+ #### ErrorNotifier
83
+ LaMaquina by default comes with an `ErrorNotifier::Base` that will explode in a very unhelpful manner. To override it, you need to change it in the config above and roll a new `ErrorNotifier` that responds to `notify(error, details)`. For example, if you're using Honeybadger, you can use the included `LaMaquina::ErrorNotifiers::HoneybadgerNotifier, which looks like:
84
+ ```ruby
85
+ class HoneybadgerNotifier < LaMaquina::ErrorNotifier::Base
86
+ self.notify(error = nil, details = {})
87
+ Honeybadger.notify( :error_class => "CacheMachineError: #{error.class.name}",
88
+ :error_message => error.message,
89
+ :parameters => details
90
+ )
91
+ end
92
+ end
93
+ ```
94
+ If you *don't* care about your exceptions and want to ignore them, there's a notifier you can use, `SilentNotifier`, making that last line in your `config/initializers/la_maquina.rb` be
95
+ ```ruby
96
+ LaMaquina::Cinegual.error_notifier = LaMaquina::ErrorNotifier::SilentNotifier
97
+ ```
79
98
 
80
99
  ## Contributing
81
100
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rdoc/task'
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
10
  rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'CacheMachine'
11
+ rdoc.title = 'LaMaquina'
12
12
  rdoc.options << '--line-numbers'
13
13
  rdoc.rdoc_files.include('README.rdoc')
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
@@ -1,23 +1,27 @@
1
- module LaMacquina
1
+ module LaMaquina
2
2
  class Ciguenal
3
3
 
4
4
  class << self
5
- def self.notify!(klass = "", id = nil)
5
+ protected
6
+
7
+ attr_accessor :pistons
8
+ end
9
+ self.pistons = []
10
+
11
+ class << self
12
+
13
+ def notify!(klass = "", id = nil)
6
14
  pistons.each do |piston|
7
15
  piston.fire! klass, id
8
16
  end
9
17
  end
10
18
 
11
- def self.install(*pistons)
12
- pistons.each do |piston|
19
+ def install(*attrs)
20
+ attrs.each do |piston|
13
21
  self.pistons << piston
14
22
  end
15
23
  end
16
24
 
17
- protected
18
-
19
- attr_accessor :pistons
20
- self.pistons = []
21
25
  end
22
26
  end
23
27
  end
@@ -0,0 +1,11 @@
1
+ module LaMaquina
2
+ module ErrorNotifier
3
+ class Base
4
+
5
+ def self.notify(error, details = {})
6
+ throw "There's no ErrorNotifier set or id doesn't implement `notify` as it should."
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module LaMaquina
2
+ module ErrorNotifier
3
+ class HoneybadgerNotifier < LaMaquina::ErrorNotifier::Base
4
+ def notify(error, details = {})
5
+ Honeybadger.notify( :error_class => "CacheMachineError: #{error.class.name}",
6
+ :error_message => error.message,
7
+ :parameters => details
8
+ )
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module LaMaquina
2
+ module ErrorNotifier
3
+ class SilentNotifier < LaMaquina::ErrorNotifier::Base
4
+
5
+ def self.notify(error, details = {})
6
+ # don't blame me! you're the one who didn't set the notifier!
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module LaMaquina
2
+ module ErrorNotifier
3
+ autoload :Base, 'la_maquina/error_notifier/base'
4
+ autoload :HoneybadgerNotifier, 'la_maquina/error_notifier/honeybadger_notifier'
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module LaMaquina
2
+ module Piston
3
+ class Base
4
+
5
+ def self.fire!(klass = "", id = nil)
6
+ throw "A piston has to implement 'fire!'"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ module LaMaquina
2
+ module Piston
3
+ class CachePiston < LaMaquina::Piston::Base
4
+ class << self
5
+ attr_accessor :redis
6
+
7
+ def fire!(klass = "", id = nil)
8
+
9
+ updated_at = SecureRandom.uuid()
10
+ redis_key_string = redis_key klass, id
11
+ # make a class var with a default
12
+
13
+ cache_key = "#{redis_key_string}/#{updated_at}"
14
+ redis.set redis_key_string, cache_key
15
+
16
+ cache_key
17
+ end
18
+
19
+ def cache_key(klass, id)
20
+
21
+ redis_key_string = redis_key klass, id
22
+
23
+ key = redis.get redis_key_string
24
+ # key found
25
+ return key if key
26
+
27
+ # there's no key; we can't very well rerun nil for cache_key. Let's make a new entry
28
+ touch_cache klass, id
29
+ end
30
+
31
+ protected
32
+
33
+ def redis_key(klass, id)
34
+ "#{klass}/#{id}"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,9 +1,6 @@
1
1
  module LaMaquina
2
- class Piston
3
-
4
- def self.fire!(klass = "", id = nil)
5
- throw "A piston has to implement 'fire!'"
6
- end
7
-
2
+ module Piston
3
+ autoload :Base, 'la_maquina/piston/base'
4
+ autoload :CachePiston, 'la_maquina/piston/cache_piston'
8
5
  end
9
6
  end
@@ -1,3 +1,3 @@
1
1
  module LaMaquina
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,11 +4,15 @@ module LaMaquina
4
4
  include ActiveRecord::Callbacks
5
5
 
6
6
  included do
7
-
7
+
8
8
  class << self
9
- attr_reader :notified_objects
10
- notified_objects = []
9
+ attr_accessor :notified_objects
10
+ end
11
11
 
12
+ self.notified_objects = []
13
+
14
+
15
+ class << self
12
16
  def notifies(object, opts = {})
13
17
  notified_objects << {:object => object, :options => opts}
14
18
  end
@@ -18,7 +22,7 @@ module LaMaquina
18
22
  end
19
23
 
20
24
  def notify!
21
- notified_objects.each do |notified|
25
+ self.class.notified_objects.each do |notified|
22
26
 
23
27
  object = notified[:object]
24
28
  options = notified[:options]
@@ -35,11 +39,11 @@ module LaMaquina
35
39
  LaMaquina::Ciguenal.notify!(klass, id)
36
40
  end
37
41
  rescue => e
38
- LaMaquina.update_error_handler.call( e,
39
- :notified_class => klass,
40
- :notified_id => id,
41
- :subordinate_class => LaMaquina.format_object_name(self),
42
- :subordinate_id => self.id)
42
+ LaMaquina.error_notifier.notify( e,
43
+ :notified_class => klass,
44
+ :notified_id => id,
45
+ :notifier_class => LaMaquina.format_object_name(self),
46
+ :notifier_id => self.id)
43
47
  end
44
48
  end
45
49
  end
data/lib/la_maquina.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  require "la_maquina/version"
2
2
 
3
3
  module LaMaquina
4
- autoload :Ciguenal, 'la_maquina/ciguenal'
5
- autoload :Piston, 'la_maquina/piston'
6
- autoload :Volante, 'la_maquina/volante'
4
+ autoload :Ciguenal, 'la_maquina/ciguenal'
5
+ autoload :ErrorNotifier, 'la_maquina/error_notifier'
6
+ autoload :Piston, 'la_maquina/piston'
7
+ autoload :Volante, 'la_maquina/volante'
7
8
 
8
- autoload :CachePiston, 'la_maquina/pistons/cache_piston'
9
-
10
-
11
- mattr_accessor :update_error_handler
9
+ mattr_accessor :error_notifier
10
+ error_notifier ||= LaMaquina::ErrorNotifier::Base
12
11
 
13
12
  def self.format_object_name(object)
14
13
  object.class.to_s.demodulize.underscore
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class CiguenalTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @admin = admins(:wheel)
7
+ end
8
+
9
+ def test_can_fire_pistons
10
+ @admin.name = "lol"
11
+ @admin.save!
12
+
13
+ assert_equal "admin/#{@admin.id}", $fire_message
14
+ end
15
+
16
+ # def test_touch_cache_updates_cache_key
17
+ # key = LaMaquina::Ciguenal.cache_key :admin, @admin.id
18
+
19
+ # sleep(1)
20
+ # LaMaquina::Ciguenal.touch_cache :admin, @admin.id
21
+
22
+ # assert_not_equal key, LaMaquina::Ciguenal.cache_key(:admin, @admin.id)
23
+ # end
24
+
25
+ # def test_cache_key_generates_new_key
26
+ # Redis.current.del LaMaquina::Ciguenal.redis_key(:admin, @admin.id)
27
+
28
+ # assert_not_nil LaMaquina::Ciguenal.cache_key(:admin, @admin.id)
29
+ # end
30
+ end
@@ -4,8 +4,8 @@ class Admin < ActiveRecord::Base
4
4
 
5
5
  has_many :properties, :as => :user
6
6
 
7
- include CacheMachine::SubordinateCacheObject
8
- updates_cache_master :self
7
+ include LaMaquina::Volante
8
+ notifies :self
9
9
 
10
- updates_cache_master :self, :comm_object => ::DummyCacheMachineCommObject
10
+ notifies :self, :using => ::DummyCommObject
11
11
  end
@@ -2,8 +2,8 @@ class AdminTrait < ActiveRecord::Base
2
2
  belongs_to :user, :class_name => "Admin"
3
3
  belongs_to :thing, :class_name => "Trait"
4
4
 
5
- include CacheMachine::SubordinateCacheObject
5
+ include LaMaquina::Volante
6
6
 
7
- updates_cache_master :user, :class => Admin
8
- updates_cache_master :thing, :class_name => "Trait"
7
+ notifies :user, :class => Admin
8
+ notifies :thing, :class_name => "Trait"
9
9
  end
@@ -1,8 +1,8 @@
1
1
  class AdminTraitModifier < ActiveRecord::Base
2
2
  belongs_to :admin_trait
3
3
 
4
- include CacheMachine::SubordinateCacheObject
4
+ include LaMaquina::Volante
5
5
 
6
- updates_cache_master :user, :through => :admin_trait, :class_name => "Admin"
7
- updates_cache_master :thing, :through => :admin_trait, :class => Trait
6
+ notifies :user, :through => :admin_trait, :class_name => "Admin"
7
+ notifies :thing, :through => :admin_trait, :class => Trait
8
8
  end
@@ -4,7 +4,7 @@ class Guest < ActiveRecord::Base
4
4
 
5
5
  has_many :properties, :as => :user
6
6
 
7
- include CacheMachine::SubordinateCacheObject
7
+ include LaMaquina::Volante
8
8
 
9
- updates_cache_master :self
9
+ notifies :self
10
10
  end
@@ -2,8 +2,8 @@ class GuestTrait < ActiveRecord::Base
2
2
  belongs_to :guest
3
3
  belongs_to :trait
4
4
 
5
- include CacheMachine::SubordinateCacheObject
5
+ include LaMaquina::Volante
6
6
 
7
- updates_cache_master :guest
8
- updates_cache_master :trait
7
+ notifies :guest
8
+ notifies :trait
9
9
  end
@@ -1,7 +1,8 @@
1
1
  class GuestTraitModifier < ActiveRecord::Base
2
2
  belongs_to :guest_trait
3
3
 
4
- include CacheMachine::SubordinateCacheObject
4
+ include LaMaquina::Volante
5
5
 
6
- updates_cache_master :guest, :through => :guest_trait
6
+
7
+ notifies :guest, :through => :guest_trait
7
8
  end
@@ -1,7 +1,8 @@
1
1
  class Property < ActiveRecord::Base
2
2
  belongs_to :user, :polymorphic => true
3
3
 
4
- include CacheMachine::SubordinateCacheObject
4
+ include LaMaquina::Volante
5
5
 
6
- updates_cache_master :user, :polymorphic => true
6
+
7
+ notifies :user, :polymorphic => true
7
8
  end
@@ -1,4 +1,5 @@
1
1
  class Standalone < ActiveRecord::Base
2
- include CacheMachine::SubordinateCacheObject
3
- updates_cache_master :self, :comm_object => ::ExplodingCacheMachineCommObject
2
+ include LaMaquina::Volante
3
+
4
+ notifies :self, :comm_object => ::ExplodingCommObject
4
5
  end
@@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require "cache_machine"
6
+ require "la_maquina"
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
@@ -0,0 +1,3 @@
1
+ LaMaquina::Piston::CachePiston.redis = Redis::Namespace.new(:cache_piston, redis: Redis.new)
2
+ LaMaquina::Ciguenal.install LaMaquina::Piston::CachePiston, TestPiston
3
+ LaMaquina.error_notifier = LaMaquina::ErrorNotifier::TestNotifier
@@ -0,0 +1,5 @@
1
+ class DummyCommObject
2
+ def self.notify! params
3
+ $dummy_params = params
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ExplodingCommObject
2
+ def self.notify! params
3
+ raise "oh noes!"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class TestNotifier < LaMaquina::ErrorNotifier::Base
2
+ def self.notify(error, details = {})
3
+ $error = error
4
+ $details = details
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class TestPiston < LaMaquina::Piston::Base
2
+ def self.fire!(klass = "", id = nil)
3
+ $fire_message = "#{klass}/#{id}"
4
+ end
5
+ end
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class LaMaquinaTest < ActiveSupport::TestCase
4
4
 
5
5
  def test_object_name_formatting
6
- assert_equal "admin", LaMaquina.format_object_name(admins(:su))
6
+ assert_equal "admin", LaMaquina.format_object_name(admins(:su))
7
7
  assert_equal "admin_trait", LaMaquina.format_object_name(admin_traits(:wheels_something_else))
8
8
  end
9
9
 
10
10
 
11
11
  def test_class_name_formatting
12
- assert_equal "admin", LaMaquina.format_class_name(Admin)
12
+ assert_equal "admin", LaMaquina.format_class_name(Admin)
13
13
  assert_equal "admin_trait", LaMaquina.format_class_name(AdminTrait)
14
14
  end
15
15
  end
@@ -0,0 +1,136 @@
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