]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/composite_primary_keys-2.2.2/lib/adapter_helper/base.rb
Present "too many pending traces" message as a warning box
[rails.git] / vendor / gems / composite_primary_keys-2.2.2 / lib / adapter_helper / base.rb
1 module AdapterHelper
2   class Base
3     class << self
4       attr_accessor :adapter
5
6       def load_connection_from_env(adapter)
7         self.adapter = adapter
8         unless ENV['cpk_adapters']
9           puts error_msg_setup_helper
10           exit
11         end
12
13         ActiveRecord::Base.configurations = YAML.load(ENV['cpk_adapters'])
14         unless spec = ActiveRecord::Base.configurations[adapter]
15           puts error_msg_adapter_helper
16           exit
17         end
18         spec[:adapter] = adapter
19         spec
20       end
21     
22       def error_msg_setup_helper
23         <<-EOS
24 Setup Helper:
25   CPK now has a place for your individual testing configuration.
26   That is, instead of hardcoding it in the Rakefile and test/connections files,
27   there is now a local/database_connections.rb file that is NOT in the
28   repository. Your personal DB information (username, password etc) can
29   be stored here without making it difficult to submit patches etc.
30
31 Installation:
32   i)   cp locals/database_connections.rb.sample locals/database_connections.rb
33   ii)  For #{adapter} connection details see "Adapter Setup Helper" below.
34   iii) Rerun this task
35   
36 #{error_msg_adapter_helper}
37   
38 Current ENV:
39   #{ENV.inspect}
40         EOS
41       end
42         
43       def error_msg_adapter_helper
44         <<-EOS
45 Adapter Setup Helper:
46   To run #{adapter} tests, you need to setup your #{adapter} connections.
47   In your local/database_connections.rb file, within the ENV['cpk_adapter'] hash, add:
48       "#{adapter}" => { adapter settings }
49
50   That is, it will look like:
51     ENV['cpk_adapters'] = {
52       "#{adapter}" => {
53         :adapter  => "#{adapter}",
54         :username => "root",
55         :password => "root",
56         # ...
57       }
58     }.to_yaml
59         EOS
60       end
61     end
62   end
63 end