gated_release 0.1.0 → 0.2.0

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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/CHANGELOG.md +22 -0
  4. data/Gemfile.lock +54 -6
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +32 -1
  7. data/Rakefile +25 -2
  8. data/app/assets/config/gated_release_manifest.js +2 -0
  9. data/app/assets/images/gated_release/.keep +0 -0
  10. data/app/assets/javascripts/gated_release/application.js +13 -0
  11. data/app/assets/stylesheets/gated_release/application.css +15 -0
  12. data/app/assets/stylesheets/gated_release/gates.css +131 -0
  13. data/app/controllers/gated_release/application_controller.rb +5 -0
  14. data/app/controllers/gated_release/gates_controller.rb +47 -0
  15. data/app/helpers/gated_release/application_helper.rb +12 -0
  16. data/app/jobs/gated_release/application_job.rb +4 -0
  17. data/app/mailers/gated_release/application_mailer.rb +6 -0
  18. data/app/models/gated_release/application_record.rb +5 -0
  19. data/{lib → app/models}/gated_release/gate.rb +9 -2
  20. data/app/views/gated_release/gates/index.html.erb +64 -0
  21. data/app/views/layouts/gated_release/application.html.erb +18 -0
  22. data/config/routes.rb +11 -0
  23. data/gated_release.gemspec +6 -3
  24. data/lib/gated_release.rb +1 -1
  25. data/lib/gated_release/engine.rb +13 -0
  26. data/lib/gated_release/version.rb +1 -1
  27. data/lib/tasks/gated_release_tasks.rake +4 -0
  28. data/spec/dummy/Rakefile +6 -0
  29. data/spec/dummy/app/assets/config/manifest.js +5 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  31. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  32. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  33. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  34. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  35. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  37. data/spec/dummy/app/jobs/application_job.rb +2 -0
  38. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  39. data/spec/dummy/app/models/application_record.rb +3 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  42. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  43. data/spec/dummy/bin/bundle +3 -0
  44. data/spec/dummy/bin/rails +4 -0
  45. data/spec/dummy/bin/rake +4 -0
  46. data/spec/dummy/bin/setup +34 -0
  47. data/spec/dummy/bin/update +29 -0
  48. data/spec/dummy/config.ru +5 -0
  49. data/spec/dummy/config/application.rb +15 -0
  50. data/spec/dummy/config/boot.rb +5 -0
  51. data/spec/dummy/config/cable.yml +9 -0
  52. data/spec/dummy/config/database.yml +25 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +54 -0
  55. data/spec/dummy/config/environments/production.rb +86 -0
  56. data/spec/dummy/config/environments/test.rb +42 -0
  57. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  58. data/spec/dummy/config/initializers/assets.rb +11 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  61. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/spec/dummy/config/initializers/inflections.rb +16 -0
  63. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  64. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  65. data/spec/dummy/config/initializers/session_store.rb +3 -0
  66. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  67. data/spec/dummy/config/locales/en.yml +23 -0
  68. data/spec/dummy/config/puma.rb +47 -0
  69. data/spec/dummy/config/routes.rb +3 -0
  70. data/spec/dummy/config/secrets.yml +22 -0
  71. data/spec/dummy/config/spring.rb +6 -0
  72. data/spec/dummy/db/schema.rb +15 -0
  73. data/spec/dummy/public/404.html +67 -0
  74. data/spec/dummy/public/422.html +67 -0
  75. data/spec/dummy/public/500.html +66 -0
  76. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  77. data/spec/dummy/public/apple-touch-icon.png +0 -0
  78. data/spec/dummy/public/favicon.ico +0 -0
  79. data/spec/gated_release_spec.rb +8 -0
  80. data/spec/generators/install/install_generator_spec.rb +25 -0
  81. data/spec/models/gated_release/gate_spec.rb +293 -0
  82. data/spec/spec_helper.rb +36 -0
  83. metadata +160 -4
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ mount GatedRelease::Engine => "/gated_release"
3
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: d1cc42e4e176d50e8d14b1dea939d7ba7213bc32ba9614283503b45dd31af76c8a815f2652834aa23949ed404bdca9f1fc032a37ae085258bc47e96251097408
15
+
16
+ test:
17
+ secret_key_base: ec2111488e1087a36305ce734e90fccd1735ecd09f45ef0bdd9b9d71fbbba45295e78707c38138c015aedfceb3430fd57a558c495c73294643f78ae2028d0175
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,15 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 0) do
14
+
15
+ end
@@ -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
File without changes
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+ require "gated_release"
3
+
4
+ describe GatedRelease do
5
+ it "has a version number" do
6
+ expect(GatedRelease::VERSION).not_to be nil
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ require "generator_spec"
2
+
3
+ module GatedRelease
4
+ module Generators
5
+ describe InstallGenerator, :type => :generator do
6
+
7
+ root_dir = File.expand_path("../../../../tmp", __FILE__)
8
+ puts root_dir
9
+ destination root_dir
10
+
11
+ before :all do
12
+ prepare_destination
13
+ run_generator
14
+ end
15
+
16
+ it "creates the installation db migration" do
17
+ migration_file =
18
+ Dir.glob("#{root_dir}/db/migrate/*create_gated_release_gates.rb")
19
+
20
+ assert_file migration_file[0],
21
+ /class CreateGatedReleaseGates < ActiveRecord::Migration/
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,293 @@
1
+ require "spec_helper"
2
+
3
+ describe GatedRelease::Gate do
4
+ describe "#get" do
5
+ it "creates a gate if one not found" do
6
+ expect(described_class.get("my_gate").name).to eq("my_gate")
7
+ expect(described_class.find_by_name("my_gate")).not_to be_nil
8
+ end
9
+ end
10
+
11
+ describe "open!" do
12
+ let(:gate) { described_class.get("my_gate") }
13
+
14
+ it "opens the gate" do
15
+ expect(gate.state).to eq("limited")
16
+ gate.open!
17
+ expect(gate.state).to eq("open")
18
+ end
19
+ end
20
+
21
+ let(:name) { 'my_release'}
22
+
23
+ let(:open_stub) { double }
24
+ let(:closed_stub) { double }
25
+
26
+ let(:open_block) { -> { open_stub.a_method } }
27
+ let(:closed_block) { -> { closed_stub.a_method } }
28
+
29
+ let(:run_args) { {open: open_block, closed: closed_block} }
30
+
31
+ subject { described_class.get(name) }
32
+
33
+ describe '#run' do
34
+
35
+ context 'when gate does not exists' do
36
+
37
+ it 'creates a gate that runs old code' do
38
+ expect(closed_stub).to receive(:a_method)
39
+ subject.run(run_args)
40
+ end
41
+ end
42
+
43
+ context 'when gate is open' do
44
+
45
+ before do
46
+ subject.open!
47
+ end
48
+
49
+ let(:run_args) { {open: open_block, closed: closed_block} }
50
+
51
+ it 'runs new code' do
52
+ expect(open_stub).to receive(:a_method)
53
+ subject.run(run_args)
54
+ end
55
+
56
+ context "when close_on_error" do
57
+ let(:open_block) { -> { raise NotImplementedError } }
58
+
59
+ it 'closes the gate' do
60
+ expect(subject.state).to eq(described_class::OPEN)
61
+ expect {
62
+ subject.run(run_args.merge(close_on_error: true))
63
+ }.to raise_error(NotImplementedError)
64
+ expect(subject.state).to eq(described_class::CLOSED)
65
+ end
66
+ end
67
+
68
+ describe 'error handling' do
69
+
70
+ context 'when the argument is missing the :open_block or :open key' do
71
+
72
+ it 'displays a useful error message' do
73
+ run_args.delete(:open)
74
+ expect{ subject.run(run_args) }.to raise_error(KeyError, 'key not found: :open for gated release: my_release')
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ context 'when the gate is closed' do
81
+
82
+ before do
83
+ subject.state = described_class::CLOSED
84
+ subject.attempts = 0
85
+ allow(closed_stub).to receive(:a_method)
86
+ end
87
+
88
+ it 'does not increment the counter' do
89
+ subject.run(run_args)
90
+ expect(subject.attempts).to eq 0
91
+ end
92
+
93
+ it 'runs new code' do
94
+ expect(closed_stub).to receive(:a_method)
95
+ subject.run(run_args)
96
+ end
97
+
98
+ context 'and the max_attempts has not been reached' do
99
+ it 'runs the old code' do
100
+ expect(closed_stub).to receive(:a_method)
101
+ subject.run(run_args)
102
+ end
103
+ end
104
+ end
105
+
106
+ context "when the gate is percentage" do
107
+ before do
108
+ subject.state = described_class::PERCENTAGE
109
+ subject.percent_open = 50
110
+ end
111
+
112
+ context "and luck is in your favour" do
113
+ before do
114
+ expect(Kernel).to receive(:rand).with(100).and_return(49)
115
+ end
116
+ it 'runs new code' do
117
+ expect(open_stub).to receive(:a_method)
118
+ subject.run(run_args)
119
+ end
120
+ end
121
+
122
+ context "and luck is NOT in your favour" do
123
+ before do
124
+ expect(Kernel).to receive(:rand).with(100).and_return(51)
125
+ end
126
+ it 'runs new code' do
127
+ expect(closed_stub).to receive(:a_method)
128
+ subject.run(run_args)
129
+ end
130
+ end
131
+ end
132
+
133
+ context 'when gate is limited' do
134
+
135
+ it 'creates a gate that runs old code' do
136
+ expect(closed_stub).to receive(:a_method)
137
+ subject.run(run_args)
138
+ end
139
+
140
+ context 'and the max_attempts is not reached' do
141
+
142
+ before do
143
+ subject.allow_more!(1)
144
+ end
145
+
146
+ it 'runs the new code' do
147
+ expect(open_stub).to receive(:a_method)
148
+ subject.run(run_args)
149
+ end
150
+ end
151
+ end
152
+
153
+ describe 'error handling' do
154
+
155
+ context 'when the argument is missing the :closed_block or :closed key' do
156
+
157
+ it 'displays a useful error message' do
158
+ run_args.delete(:closed)
159
+ expect{ subject.run(run_args) }.to raise_error(KeyError, 'key not found: :closed for gated release: my_release')
160
+ end
161
+ end
162
+
163
+ end
164
+ end
165
+
166
+ describe '.search' do
167
+
168
+ it "returns result" do
169
+ subject
170
+ expect(described_class.search('y*r')).to eq [subject]
171
+ end
172
+
173
+ it "returns no results for non-matching search term" do
174
+ subject
175
+ expect(described_class.search('zzz')).to eq []
176
+ end
177
+
178
+ end
179
+
180
+ describe '#max_attempts' do
181
+
182
+ context 'when gate does not exists' do
183
+
184
+ it 'is zero' do
185
+ expect(subject.max_attempts).to eq 0
186
+ end
187
+ end
188
+
189
+ context 'when allowing more' do
190
+
191
+ before do
192
+ subject.allow_more!(100)
193
+ end
194
+
195
+ it 'is increased' do
196
+ expect(subject.max_attempts).to eq 100
197
+ end
198
+
199
+ context 'when allowing more on existing gate' do
200
+
201
+ before do
202
+ subject.allow_more!(7)
203
+ end
204
+
205
+ it 'increments by specified count' do
206
+ expect(subject.max_attempts).to eq 107
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ describe '#allow_more!' do
213
+
214
+ context 'when gate does not exists' do
215
+
216
+ let(:count) { 7 }
217
+
218
+ it 'increments the max_attempts by specified count' do
219
+ subject.allow_more!(7)
220
+ expect(subject.max_attempts).to eq 7
221
+ end
222
+ end
223
+ end
224
+
225
+ describe "#open!" do
226
+ it "saves it in state open" do
227
+ subject.state = 'closed'
228
+ subject.save!
229
+
230
+ subject.open!
231
+ subject.reload
232
+ expect(subject.state).to eq 'open'
233
+ end
234
+ end
235
+
236
+ describe "#close!" do
237
+ it "saves it in state closed" do
238
+ subject.state = 'open'
239
+ subject.save!
240
+
241
+ subject.close!
242
+ subject.reload
243
+ expect(subject.state).to eq 'closed'
244
+ end
245
+ end
246
+
247
+ describe "#limit!" do
248
+ it "saves it in state limited" do
249
+ subject.state = 'open'
250
+ subject.save!
251
+
252
+ subject.limit!
253
+ subject.reload
254
+ expect(subject.state).to eq 'limited'
255
+ end
256
+ end
257
+
258
+ describe "#percentage!" do
259
+ it "saves it in state percentage" do
260
+ subject.state = 'open'
261
+ subject.save!
262
+
263
+ subject.percentage!(60)
264
+ subject.reload
265
+ expect(subject.state).to eq 'percentage'
266
+ expect(subject.percent_open).to eq 60
267
+ end
268
+ end
269
+
270
+ describe '#attempts' do
271
+
272
+ context 'when gate does not exists' do
273
+
274
+ it 'is zero' do
275
+ expect(subject.attempts).to eq 0
276
+ end
277
+ end
278
+
279
+ context 'after 1 attempt' do
280
+
281
+ before do
282
+ subject.allow_more!(1)
283
+ expect(open_stub).to receive(:a_method)
284
+ subject.run(run_args)
285
+ end
286
+
287
+ it 'increments the attempt counter' do
288
+ expect(subject.attempts).to eq 1
289
+ end
290
+ end
291
+
292
+ end
293
+ end