cloudcontrol-rails 0.0.5 → 0.0.6
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.
- data/cloudcontrol-rails.gemspec +1 -1
- data/lib/cloudcontrol/cloudcontrol.rb +8 -0
- data/spec/database_configuration_spec.rb +111 -174
- metadata +3 -3
data/cloudcontrol-rails.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'cloudcontrol-rails'
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.6"
|
6
6
|
s.authors = ["Alexander Rösel", "Ivan Kusalic"]
|
7
7
|
s.email = ["info@netzok.net"]
|
8
8
|
s.summary = "Autoload MySQL and Postgres credentials from ENV vars on cloudControl"
|
@@ -2,9 +2,17 @@ require 'cloudcontrol/mysql'
|
|
2
2
|
require 'cloudcontrol/postgres'
|
3
3
|
|
4
4
|
module Cloudcontrol
|
5
|
+
def self.update_with_defaults(config, rails_env)
|
6
|
+
%W[ host port database username password ].each do |key|
|
7
|
+
config[rails_env][key] = nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def self.reconfigure_database_configuration(config)
|
6
12
|
rails_env = ENV['RAILS_ENV'] || 'development'
|
7
13
|
|
14
|
+
update_with_defaults(config, rails_env) if config[rails_env].size == 1
|
15
|
+
|
8
16
|
# set creds for the different adapters
|
9
17
|
case config[rails_env]['adapter']
|
10
18
|
when 'mysql2'
|
@@ -5,11 +5,22 @@ require 'yaml'
|
|
5
5
|
require 'spec_helper'
|
6
6
|
require 'cloudcontrol/cloudcontrol'
|
7
7
|
|
8
|
-
|
8
|
+
shared_examples "a configuration test" do |env|
|
9
|
+
it "should return proper value" do
|
10
|
+
other_env = (env == 'production') ? 'development' : 'production'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
ENV["RAILS_ENV"] = env
|
13
|
+
|
14
|
+
res = Cloudcontrol::reconfigure_database_configuration config
|
15
|
+
res[env].should include(expected_res)
|
16
|
+
res[other_env].should include(not_modified)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
shared_examples "a database" do |env_vars|
|
21
|
+
let(:db_config_dev) { [ adapter, 'env.env.env', 42, 'env', 'env', 'env' ] }
|
22
|
+
let(:db_config_prod) { [ adapter, 'env.env.env', 42, 'env', 'env', 'env' ] }
|
23
|
+
let(:db_config) { db_config_dev + db_config_prod }
|
13
24
|
|
14
25
|
let(:database_yml) do
|
15
26
|
yml = <<END
|
@@ -36,9 +47,7 @@ production:
|
|
36
47
|
END
|
37
48
|
|
38
49
|
yml % db_config
|
39
|
-
end
|
40
|
-
|
41
|
-
let(:db_config) { db_config_dev + db_config_prod }
|
50
|
+
end
|
42
51
|
|
43
52
|
let(:config) do
|
44
53
|
IO.stub!(:read).and_return database_yml
|
@@ -48,7 +57,7 @@ end
|
|
48
57
|
let(:not_modified) do
|
49
58
|
{
|
50
59
|
"adapter" => adapter,
|
51
|
-
"host" => 'env',
|
60
|
+
"host" => 'env.env.env',
|
52
61
|
"port" => 42,
|
53
62
|
"database" => 'env',
|
54
63
|
"username" => 'env',
|
@@ -57,189 +66,117 @@ end
|
|
57
66
|
end
|
58
67
|
|
59
68
|
before do
|
60
|
-
ENV =
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
ENV = env_vars
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "with only adapter" do
|
73
|
+
let(:expected_res) { not_modified } # HACK
|
74
|
+
let(:db_config_prod) { [ adapter ] + [ nil] * 5 }
|
75
|
+
let(:database_yml) do
|
76
|
+
yml = <<END
|
77
|
+
development:
|
78
|
+
adapter: %s
|
79
|
+
encoding: utf8
|
80
|
+
reconnect: false
|
81
|
+
pool: 5
|
82
|
+
host: %s
|
83
|
+
port: %s
|
84
|
+
database: %s
|
85
|
+
username: %s
|
86
|
+
password: %s
|
87
|
+
production:
|
88
|
+
adapter: %s
|
89
|
+
END
|
69
90
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#'MYSQLD_DATABASE' => "env",
|
75
|
-
#'MYSQLD_USER' => "env",
|
76
|
-
#'MYSQLD_PASSWORD' => "env",
|
77
|
-
#'ELEPHANTSQL_URL' => 'postgres://env:env@env.env.env:42/env',
|
78
|
-
#}
|
91
|
+
yml % (db_config_dev + [ adapter ])
|
92
|
+
end
|
93
|
+
|
94
|
+
it_should_behave_like "a configuration test", 'production'
|
79
95
|
end
|
80
96
|
|
81
|
-
describe "
|
82
|
-
let(:
|
97
|
+
describe "without provided values" do
|
98
|
+
let(:expected_res) { not_modified } # HACK
|
99
|
+
let(:db_config_prod) { [ adapter ] + [ nil] * 5 }
|
83
100
|
|
84
|
-
|
85
|
-
|
86
|
-
let(:expected_res) { not_modified } # HACK
|
101
|
+
it_should_behave_like "a configuration test", 'production'
|
102
|
+
end
|
87
103
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
104
|
+
describe "with partially provided values" do
|
105
|
+
let(:expected_res) do
|
106
|
+
{
|
107
|
+
"adapter"=>adapter,
|
108
|
+
"host"=>"host",
|
109
|
+
"port"=>42,
|
110
|
+
"database"=>"db",
|
111
|
+
"username"=>"env",
|
112
|
+
"password"=>"env"
|
113
|
+
}
|
94
114
|
end
|
95
115
|
|
96
|
-
describe "
|
97
|
-
let(:
|
98
|
-
|
99
|
-
"adapter"=>adapter,
|
100
|
-
"host"=>"host",
|
101
|
-
"port"=>42,
|
102
|
-
"database"=>"db",
|
103
|
-
"username"=>"env",
|
104
|
-
"password"=>"env"
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "for production" do
|
109
|
-
let(:db_config_prod) { [ adapter, 'host', '42', 'db', nil, nil ] }
|
110
|
-
|
111
|
-
it "should return proper value" do
|
112
|
-
env = 'production'
|
113
|
-
other_env = 'development'
|
114
|
-
ENV["RAILS_ENV"] = env
|
115
|
-
|
116
|
-
res = Cloudcontrol::reconfigure_database_configuration config
|
117
|
-
res[env].should include(expected_res)
|
118
|
-
res[other_env].should include(not_modified)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "for development" do
|
123
|
-
let(:db_config_dev) { [ adapter, 'host', '42', 'db', nil, nil ] }
|
124
|
-
|
125
|
-
it "should return proper value" do
|
126
|
-
env = 'development'
|
127
|
-
other_env = 'production'
|
128
|
-
ENV["RAILS_ENV"] = env
|
129
|
-
|
130
|
-
res = Cloudcontrol::reconfigure_database_configuration config
|
131
|
-
res[env].should include(expected_res)
|
132
|
-
res[other_env].should include(not_modified)
|
133
|
-
end
|
134
|
-
end
|
116
|
+
describe "for production" do
|
117
|
+
let(:db_config_prod) { [ adapter, 'host', 42, 'db', nil, nil ] }
|
118
|
+
it_should_behave_like "a configuration test", 'production'
|
135
119
|
end
|
136
120
|
|
137
|
-
describe "
|
138
|
-
let(:
|
139
|
-
|
140
|
-
{
|
141
|
-
"adapter"=>adapter,
|
142
|
-
"host"=>"host",
|
143
|
-
"port"=>42,
|
144
|
-
"database"=>"db",
|
145
|
-
"username"=>"username",
|
146
|
-
"password"=>"pass"
|
147
|
-
}
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should return proper value" do
|
151
|
-
env = 'production'
|
152
|
-
ENV["RAILS_ENV"] = env
|
153
|
-
res = Cloudcontrol::reconfigure_database_configuration config
|
154
|
-
res[env].should include(expected_res)
|
155
|
-
end
|
121
|
+
describe "for development" do
|
122
|
+
let(:db_config_dev) { [ adapter, 'host', 42, 'db', nil, nil ] }
|
123
|
+
it_should_behave_like "a configuration test", 'development'
|
156
124
|
end
|
157
125
|
end
|
158
126
|
|
159
|
-
describe "
|
160
|
-
let(:
|
127
|
+
describe "with fully provided values" do
|
128
|
+
let(:db_config_prod) { [ adapter, 'host', 42, 'db', 'username', 'pass' ] }
|
129
|
+
let(:expected_res) do
|
130
|
+
{
|
131
|
+
"adapter"=>adapter,
|
132
|
+
"host"=>"host",
|
133
|
+
"port"=>42,
|
134
|
+
"database"=>"db",
|
135
|
+
"username"=>"username",
|
136
|
+
"password"=>"pass"
|
137
|
+
}
|
138
|
+
end
|
161
139
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
140
|
+
it_should_behave_like "a configuration test", 'production'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
describe "Cloudcontrol" do
|
146
|
+
describe "MySQL" do
|
147
|
+
let(:adapter) { 'mysql2' }
|
148
|
+
|
149
|
+
describe "with MySQLs addon" do
|
150
|
+
it_should_behave_like "a database", {
|
151
|
+
'RAILS_ENV' => "production",
|
152
|
+
'MYSQLS_HOSTNAME' => "env.env.env",
|
153
|
+
'MYSQLS_PORT' => "42",
|
154
|
+
'MYSQLS_DATABASE' => "env",
|
155
|
+
'MYSQLS_USERNAME' => "env",
|
156
|
+
'MYSQLS_PASSWORD' => "env",
|
157
|
+
}
|
181
158
|
end
|
182
159
|
|
183
|
-
describe "with
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
}
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "for production" do
|
196
|
-
let(:db_config_prod) { [ adapter, 'host', 42, 'db', nil, nil ] }
|
197
|
-
|
198
|
-
it "should return proper value" do
|
199
|
-
env = 'production'
|
200
|
-
other_env = 'development'
|
201
|
-
ENV["RAILS_ENV"] = env
|
202
|
-
|
203
|
-
res = Cloudcontrol::reconfigure_database_configuration config
|
204
|
-
res[env].should include(expected_res)
|
205
|
-
res[other_env].should include(not_modified)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "for development" do
|
210
|
-
let(:db_config_dev) { [ adapter, 'host', 42, 'db', nil, nil ] }
|
211
|
-
|
212
|
-
it "should return proper value" do
|
213
|
-
env = 'development'
|
214
|
-
other_env = 'production'
|
215
|
-
ENV["RAILS_ENV"] = env
|
216
|
-
|
217
|
-
res = Cloudcontrol::reconfigure_database_configuration config
|
218
|
-
res[env].should include(expected_res)
|
219
|
-
res[other_env].should include(not_modified)
|
220
|
-
end
|
221
|
-
end
|
160
|
+
describe "with MySQLd addon" do
|
161
|
+
it_should_behave_like "a database", {
|
162
|
+
'RAILS_ENV' => "production",
|
163
|
+
'MYSQLD_HOST' => "env.env.env",
|
164
|
+
'MYSQLD_PORT' => "42",
|
165
|
+
'MYSQLD_DATABASE' => "env",
|
166
|
+
'MYSQLD_USER' => "env",
|
167
|
+
'MYSQLD_PASSWORD' => "env",
|
168
|
+
}
|
222
169
|
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "PostgreSQL" do
|
173
|
+
let(:adapter) { 'postgresql' }
|
223
174
|
|
224
|
-
describe "with
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
"host"=>"host",
|
230
|
-
"port"=>42,
|
231
|
-
"database"=>"db",
|
232
|
-
"username"=>"username",
|
233
|
-
"password"=>"pass"
|
234
|
-
}
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should return proper value" do
|
238
|
-
env = 'production'
|
239
|
-
ENV["RAILS_ENV"] = env
|
240
|
-
res = Cloudcontrol::reconfigure_database_configuration config
|
241
|
-
res[env].should include(expected_res)
|
242
|
-
end
|
175
|
+
describe "with ElephantSQL addon" do
|
176
|
+
it_should_behave_like "a database", {
|
177
|
+
'RAILS_ENV' => "production",
|
178
|
+
'ELEPHANTSQL_URL' => 'postgres://env:env@env.env.env:42/env',
|
179
|
+
}
|
243
180
|
end
|
244
181
|
end
|
245
182
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudcontrol-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Use credentials set in ENV vars if database.yml credentials are empty.
|
16
16
|
Supports MySQL and ElephantSQL (Postgres) on the cloudControl platform.
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
55
|
rubyforge_project:
|
56
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.24
|
57
57
|
signing_key:
|
58
58
|
specification_version: 3
|
59
59
|
summary: Autoload MySQL and Postgres credentials from ENV vars on cloudControl
|