Mikey
So, I have a site that synchronizes data with another server. It does this via after_create, after_update and after_delete triggers on some models. All of those triggers use the same method that returns a connection object which has various methods such as:
# SyncServer::connection method
module SyncServer
def self.connection
new_client.connection{|conn| yield conn }
end
end
SyncServer::connection do |conn|
conn.add_person(person_data)
# or
conn.update_person(person_data)
# or
conn.delete_person(person_id)
end
# The following is to demonstrate I could have
# multiple types of data I'm syncing
# and therefore multiple methods on the
# conn object.
SyncServer::connection do |conn|
conn.add_other_data(other_data)
conn.modify_other_data(other_data)
conn.delete_data(other_id)
end
While the RSpec tests were running, these triggers were being called which was junking up the SyncServer. This is not cool. In order to avoid this, I needed to be able to disable the synchronization. I definitely didn't want to do this in all my triggers.
Enter Mikey, he's going to replace the conn object I return:
#
# Because Mikey will eat anything
#
class Mikey
def method_missing(method, *args)
true
end
end
Now the new conn method:
module SyncServer
def self.connection
if sync?
new_client.connection{|conn| yield conn }
else
yield Mikey.new
end
end
end
The sync? method just checks if the class variable do_synchronization is true. I set this class variable to false if the RAILS_ENV == test. The result is my triggers don't break, the sync server isn't junked up and my tests pass. All good.
4 comments
Comments
-
It seems like Mikey could grown into a fully grown acts_as_chuck_norris plugin!
-
That would be cool and the name alone would make it popular. :)
-
Hello! celebrex online, 345 , [url=http://www.amazon.com/gp/pdp/profile/A1ORZ1B70HZW0N]celebrex online[/url],7333, http://www.amazon.com/gp/pdp/profile/A1ORZ1B70HZW0N celebrex online buy generic cialis online, 6058 , [url=http://www.amazon.com/gp/pdp/profile/A1DZLXH6XXQS6E]buy generic cialis online[/url],3079, http://www.amazon.com/gp/pdp/profile/A1DZLXH6XXQS6E buy generic cialis online order plavix usa, 732 , [url=http://www.amazon.com/gp/pdp/profile/AR0W9CHTP1L1H]order plavix usa[/url],7995, http://www.amazon.com/gp/pdp/profile/AR0W9CHTP1L1H order plavix usa generic acomplia, 3767 , [url=http://www.amazon.com/gp/pdp/profile/A32JKP6WF2BGCF]generic acomplia[/url],6779, http://www.amazon.com/gp/pdp/profile/A32JKP6WF2BGCF generic acomplia buy cheap paxil, 9097 , [url=http://www.amazon.com/gp/pdp/profile/A3OI9BGGRLMN19]buy cheap paxil[/url],3523, http://www.amazon.com/gp/pdp/profile/A3OI9BGGRLMN19 buy cheap paxil
-
Hello! lexapro usa, 7486 , [url=http://www.amazon.com/gp/pdp/profile/AN3HLK3T5WIKL]lexapro usa[/url],1040, http://www.amazon.com/gp/pdp/profile/AN3HLK3T5WIKL lexapro usa online hoodia, 4044 , [url=http://www.amazon.com/gp/pdp/profile/ALV58RBZFXK04]online hoodia[/url],7020, http://www.amazon.com/gp/pdp/profile/ALV58RBZFXK04 online hoodia purchase cheap viagra online, 2421 , [url=http://www.amazon.com/gp/pdp/profile/A108WTGDI2E9SB]purchase cheap viagra online[/url],5826, http://www.amazon.com/gp/pdp/profile/A108WTGDI2E9SB purchase cheap viagra online cheap nexium uk, 7044 , [url=http://www.amazon.com/gp/pdp/profile/A1NM2U6FAE3LR4]cheap nexium uk[/url],6525, http://www.amazon.com/gp/pdp/profile/A1NM2U6FAE3LR4 cheap nexium uk purchase cheap wellbutrin online, 4137 , [url=http://www.amazon.com/gp/pdp/profile/A3VTW5T3GXQHM3]purchase cheap wellbutrin online[/url],6071, http://www.amazon.com/gp/pdp/profile/A3VTW5T3GXQHM3 purchase cheap wellbutrin online
