add unit tests for shared database synchronisation
This commit is contained in:
parent
a5a29aff5c
commit
ac6b00d4f5
2 changed files with 83 additions and 0 deletions
29
spec/support/shared_database.rb
Normal file
29
spec/support/shared_database.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# http://stackoverflow.com/questions/8774227
|
||||
# http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite
|
||||
class ActiveRecord::Base
|
||||
mattr_accessor :shared_connection
|
||||
@@shared_connection = nil
|
||||
|
||||
def self.connection
|
||||
@@shared_connection || retrieve_connection
|
||||
end
|
||||
end
|
||||
# Forces all threads to share the same connection. This works on
|
||||
# Capybara because it starts the web server in a thread.
|
||||
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
||||
|
||||
ActiveSupport.on_load(:after_initialize) do
|
||||
# We simulate the shared database by pointing to our own database.
|
||||
# This allows running tests without additional database setup.
|
||||
# But take care when designing tests using the shared database.
|
||||
SharedSupplier.establish_connection Rails.env
|
||||
SharedArticle.establish_connection Rails.env
|
||||
# hack for different structure of shared database
|
||||
SharedArticle.class_eval do
|
||||
alias_attribute :number, :order_number
|
||||
alias_attribute :updated_on, :updated_at
|
||||
def self.find_by_number(n)
|
||||
find_by_order_number(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue