config_manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/config_manager/application.js +15 -0
- data/app/assets/stylesheets/config_manager/_reset.css.scss +74 -0
- data/app/assets/stylesheets/config_manager/application.css +5 -0
- data/app/assets/stylesheets/config_manager/generic.css.scss +19 -0
- data/app/controllers/config_manager/admins_controller.rb +59 -0
- data/app/controllers/config_manager/application_controller.rb +12 -0
- data/app/controllers/config_manager/sessions_controller.rb +5 -0
- data/app/controllers/config_manager/toggles_controller.rb +57 -0
- data/app/helpers/config_manager/application_helper.rb +11 -0
- data/app/helpers/config_manager/toggles_helper.rb +7 -0
- data/app/models/config_manager/admin.rb +18 -0
- data/app/views/config_manager/admins/_errors.html.slim +7 -0
- data/app/views/config_manager/admins/_form.html.slim +10 -0
- data/app/views/config_manager/admins/edit.html.slim +13 -0
- data/app/views/config_manager/admins/index.html.slim +28 -0
- data/app/views/config_manager/admins/new.html.slim +10 -0
- data/app/views/config_manager/sessions/new.html.slim +23 -0
- data/app/views/config_manager/toggles/_form.html.slim +12 -0
- data/app/views/config_manager/toggles/index.html.slim +45 -0
- data/app/views/layouts/config_manager/application.html.slim +54 -0
- data/config/initializers/devise.rb +258 -0
- data/config/locales/devise.en.yml +59 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20140725161636_create_config_manager_admins.rb +41 -0
- data/lib/config_manager.rb +6 -0
- data/lib/config_manager/engine.rb +20 -0
- data/lib/config_manager/toggle.rb +66 -0
- data/lib/config_manager/toggles/boolean.rb +21 -0
- data/lib/config_manager/toggles/definition.rb +103 -0
- data/lib/config_manager/toggles/null.rb +18 -0
- data/lib/config_manager/toggles/set.rb +21 -0
- data/lib/config_manager/version.rb +3 -0
- data/lib/tasks/config_manager_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/dummy_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/bad_toggles.yml +8 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/config_manager_toggles.yml +7 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/redis.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/redis.yml +8 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/toggles.yml +8 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +31 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +9283 -0
- data/spec/dummy/log/test.log +557 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/786e38d79a0d3df53e8917152c8f9ebd061f1eac/_reset.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/786e38d79a0d3df53e8917152c8f9ebd061f1eac/generic.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1d468d61d8002d0709400b7ab8112441 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/259bf4d13dff689b9dbca70a598c3755 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4c700e6b525103954790256e74000237 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/53db5a69412d8243c467b6af17d2f483 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/550cbb5bc745772776097bec6b7ee6db +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6159fbf8e1fca57907de03eef7ed9cdb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/69d29900d66ffd35bf01cae75f4e0fe6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6d3f4fe92dd890a8bbdaf3f21eae0615 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b248de24a4d5454a0dcf2490dc088b8e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bfdd9543b7b28b65c9d760f854cc387c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c5471c9026b426e70abbb969df7ba671 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c69bf92b5432ae5a1c2044ebc2923c71 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dbbeb33ef5af4bd661989cf666fde840 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e808c4872b8e90c978084811080405ee +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ecd5a5f69d121045c4fc39b914215798 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f0bf3eb5da8250b91d2179600efef783 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f318cd7091c78a646f7e5bed19e774bf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f33a897212fccae3670eab346f4e193e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/dummy/tmp/test.yml +7 -0
- data/spec/integration/navigation_test.rb +10 -0
- data/spec/lib/config_manager/toggle_spec.rb +110 -0
- data/spec/lib/config_manager/toggles/boolean_spec.rb +34 -0
- data/spec/lib/config_manager/toggles/definition_spec.rb +130 -0
- data/spec/lib/config_manager/toggles/set_spec.rb +34 -0
- data/spec/rails_helper.rb +48 -0
- data/spec/spec_helper.rb +78 -0
- data/spec/support/rspec_redis_helper.rb +28 -0
- data/spec/test_helper.rb +15 -0
- metadata +486 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
85868
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module ConfigManager
|
4
|
+
describe Toggle, :redis => true do
|
5
|
+
describe ".toggles" do
|
6
|
+
context "when there are no toggles" do
|
7
|
+
it "returns an empty array" do
|
8
|
+
Toggle.toggles.should == []
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the an array of currently defined toggles" do
|
12
|
+
Toggles::Definition.new('d').type = 'set'
|
13
|
+
Toggles::Definition.new('d1').type = 'boolean'
|
14
|
+
Toggle.toggles.should have(2).toggles
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".active?" do
|
20
|
+
before do
|
21
|
+
definition.type = 'set'
|
22
|
+
definition.acceptable_values = %w(a b)
|
23
|
+
end
|
24
|
+
let(:definition) { Toggles::Definition.new('d1') }
|
25
|
+
|
26
|
+
context "when the challenge is in the acceptable answer test" do
|
27
|
+
it "returns true" do
|
28
|
+
Toggle.active?('d1', 'a').should be_truthy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when the challenge is not in the acceptable answer test" do
|
33
|
+
it "returns false" do
|
34
|
+
Toggle.active?('d1', 'c').should be_falsy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the toggle is undefined" do
|
39
|
+
it "returns false" do
|
40
|
+
Toggle.active?('d2', 'a').should be_falsy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ".create" do
|
46
|
+
let(:definition) { Toggles::Definition.new('ut') }
|
47
|
+
|
48
|
+
it "creates a new boolean toggle" do
|
49
|
+
Toggle.create(:name => 'ut', :type => 'boolean', :formatted_acceptable_values => 'true')
|
50
|
+
definition.name.should == 'ut'
|
51
|
+
definition.type.should == 'boolean'
|
52
|
+
definition.acceptable_values.should == true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "creates a new set toggle" do
|
56
|
+
Toggle.create(:name => 'ut', :type => 'set', :formatted_acceptable_values => 'a, b , d')
|
57
|
+
definition.name.should == 'ut'
|
58
|
+
definition.type.should == 'set'
|
59
|
+
definition.acceptable_values.should == %w{a b d}
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns a toggle definition instance" do
|
63
|
+
Toggle.create(:name => 'ut', :type => 'set', :formatted_acceptable_values => 'a, b , d').
|
64
|
+
should be_instance_of(Toggles::Definition)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe ".delete" do
|
69
|
+
it "deletes the toggle" do
|
70
|
+
Toggle.create(:name => 'ut', :type => 'boolean', :formatted_acceptable_values => 'true')
|
71
|
+
Toggle.delete('ut')
|
72
|
+
d = Toggles::Definition.new('ut')
|
73
|
+
d.name.should == 'ut'
|
74
|
+
d.type.should == nil
|
75
|
+
d.acceptable_values.should == nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ".from_yaml" do
|
80
|
+
context "when file exists" do
|
81
|
+
it "creates toggles (set and boolean) defined in file" do
|
82
|
+
Toggle.from_yaml(Rails.root.join('config/toggles.yml'))
|
83
|
+
Toggle.toggles.should have(3).toggles
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns number of created toggles and 0 failed" do
|
87
|
+
Toggle.from_yaml(Rails.root.join('config/toggles.yml')).should == [3, 0]
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when file has one bad toggle" do
|
91
|
+
it "skips the bad toggle" do
|
92
|
+
Toggle.from_yaml(Rails.root.join('config/bad_toggles.yml'))
|
93
|
+
Toggle.toggles.should have(2).toggles
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns number of created toggles and 1 failed" do
|
97
|
+
Toggle.from_yaml(Rails.root.join('config/bad_toggles.yml')).should == [2, 1]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when files doesn't exist" do
|
103
|
+
it "raises an ENOENT error" do
|
104
|
+
expect { Toggle.from_yaml(Rails.root.join('config/noexist.yml')) }.
|
105
|
+
to raise_error(Errno::ENOENT)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module ConfigManager
|
4
|
+
module Toggles
|
5
|
+
describe Boolean, :redis => true do
|
6
|
+
describe ".active?" do
|
7
|
+
before { definition.type = 'boolean' }
|
8
|
+
let(:definition) { Definition.new('ut') }
|
9
|
+
|
10
|
+
context "when the acceptable answer is true" do
|
11
|
+
before { definition.acceptable_values = true }
|
12
|
+
|
13
|
+
it "returns true" do
|
14
|
+
Boolean.active?(definition).should be_truthy
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the acceptable answer is false" do
|
19
|
+
before { definition.acceptable_values = false }
|
20
|
+
|
21
|
+
it "returns false" do
|
22
|
+
Boolean.active?(definition).should be_falsy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when the acceptable answer is not set" do
|
27
|
+
it "returns false" do
|
28
|
+
Boolean.active?(definition).should be_falsy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module ConfigManager
|
4
|
+
module Toggles
|
5
|
+
describe Definition, :redis => true do
|
6
|
+
let(:definition) { Definition.new('ut') }
|
7
|
+
|
8
|
+
describe "validness" do
|
9
|
+
context "when name is blank" do
|
10
|
+
let(:definition) { Definition.new(nil) }
|
11
|
+
|
12
|
+
it "is false" do
|
13
|
+
definition.should_not be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
context "after setting the type" do
|
17
|
+
before { definition.type == 'set' }
|
18
|
+
|
19
|
+
it "is still false" do
|
20
|
+
definition.should_not be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
it "doesn't really set the type" do
|
24
|
+
definition.type.should be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when type is not set" do
|
30
|
+
it "is false" do
|
31
|
+
definition.should_not be_valid
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when type is set" do
|
36
|
+
before { definition.type = 'set' }
|
37
|
+
|
38
|
+
it "is true" do
|
39
|
+
definition.should be_valid
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#type" do
|
45
|
+
context "when not set" do
|
46
|
+
it "returns nil" do
|
47
|
+
definition.type.should be_nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when set" do
|
52
|
+
before { definition.type = 'set' }
|
53
|
+
|
54
|
+
it "returns the stored value" do
|
55
|
+
definition.type.should == 'set'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "updates the stored value to a new value" do
|
59
|
+
definition.type.should == 'set'
|
60
|
+
definition.type = 'boolean'
|
61
|
+
definition.type.should == 'boolean'
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when the type is not in the supported list" do
|
65
|
+
it "raises an error" do
|
66
|
+
expect { definition.type = 'blah' }.to raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#acceptable_values" do
|
73
|
+
|
74
|
+
context "when not set" do
|
75
|
+
context" when type is not set" do
|
76
|
+
it "returns nil" do
|
77
|
+
definition.acceptable_values.should == nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when type is set" do
|
82
|
+
before { definition.type = 'set' }
|
83
|
+
|
84
|
+
it "returns an empty array" do
|
85
|
+
definition.acceptable_values.should == []
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when set" do
|
91
|
+
context "when type is set to 'set'" do
|
92
|
+
before do
|
93
|
+
definition.type = 'set'
|
94
|
+
definition.acceptable_values = %w(a b)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "returns the stored values in set format" do
|
98
|
+
definition.acceptable_values.should == %w(a b)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "updates the stored values to a new value" do
|
102
|
+
definition.acceptable_values = %w(c d)
|
103
|
+
definition.acceptable_values.should == %w(c d)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when type is boolean" do
|
108
|
+
before { definition.type = 'boolean' }
|
109
|
+
|
110
|
+
it "converts the string to a bool and store it" do
|
111
|
+
definition.acceptable_values = 'true'
|
112
|
+
definition.acceptable_values.should == true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#delete" do
|
119
|
+
it "deletes the stored toggle" do
|
120
|
+
definition.type = 'set'
|
121
|
+
definition.acceptable_values = %w(a b)
|
122
|
+
key = definition.instance_variable_get(:@key)
|
123
|
+
$redis.exists(key).should be_truthy
|
124
|
+
definition.delete
|
125
|
+
$redis.exists(key).should be_falsy
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|