flipper-ui 1.4.2 → 1.5.0.rc2

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/flipper/ui/action.rb +46 -35
  3. data/lib/flipper/ui/actions/actors_gate.rb +17 -3
  4. data/lib/flipper/ui/actions/cloud_migrate.rb +1 -0
  5. data/lib/flipper/ui/actions/features.rb +5 -1
  6. data/lib/flipper/ui/actions/groups_gate.rb +6 -1
  7. data/lib/flipper/ui/actions/import.rb +20 -2
  8. data/lib/flipper/ui/actions/percentage_of_actors_gate.rb +2 -0
  9. data/lib/flipper/ui/actions/percentage_of_time_gate.rb +2 -0
  10. data/lib/flipper/ui/configuration.rb +6 -1
  11. data/lib/flipper/ui/decorators/feature.rb +6 -12
  12. data/lib/flipper/ui/error.rb +2 -2
  13. data/lib/flipper/ui/middleware.rb +10 -0
  14. data/lib/flipper/ui/public/images/logo.png +0 -0
  15. data/lib/flipper/ui/util.rb +5 -4
  16. data/lib/flipper/ui/views/feature.erb +8 -0
  17. data/lib/flipper/ui/views/layout.erb +8 -4
  18. data/lib/flipper/ui/views/settings.erb +21 -18
  19. data/lib/flipper/ui.rb +4 -1
  20. data/lib/flipper/version.rb +1 -1
  21. metadata +5 -32
  22. data/examples/ui/authorization.ru +0 -48
  23. data/examples/ui/basic.ru +0 -71
  24. data/examples/ui/prefixed.ru +0 -21
  25. data/examples/ui/read_only.ru +0 -43
  26. data/flipper-ui.gemspec +0 -29
  27. data/lib/flipper/ui/decorators/gate.rb +0 -37
  28. data/lib/flipper/ui/public/js/jquery-3.6.0.slim.js +0 -8782
  29. data/spec/flipper/ui/action_spec.rb +0 -76
  30. data/spec/flipper/ui/actions/actors_gate_spec.rb +0 -201
  31. data/spec/flipper/ui/actions/add_feature_spec.rb +0 -57
  32. data/spec/flipper/ui/actions/boolean_gate_spec.rb +0 -139
  33. data/spec/flipper/ui/actions/cloud_migrate_spec.rb +0 -54
  34. data/spec/flipper/ui/actions/export_spec.rb +0 -51
  35. data/spec/flipper/ui/actions/feature_spec.rb +0 -254
  36. data/spec/flipper/ui/actions/features_spec.rb +0 -233
  37. data/spec/flipper/ui/actions/file_spec.rb +0 -21
  38. data/spec/flipper/ui/actions/groups_gate_spec.rb +0 -144
  39. data/spec/flipper/ui/actions/home_spec.rb +0 -14
  40. data/spec/flipper/ui/actions/import_spec.rb +0 -63
  41. data/spec/flipper/ui/actions/percentage_of_actors_gate_spec.rb +0 -65
  42. data/spec/flipper/ui/actions/percentage_of_time_gate_spec.rb +0 -65
  43. data/spec/flipper/ui/actions/settings_spec.rb +0 -35
  44. data/spec/flipper/ui/configuration_spec.rb +0 -229
  45. data/spec/flipper/ui/decorators/feature_spec.rb +0 -59
  46. data/spec/flipper/ui/decorators/gate_spec.rb +0 -45
  47. data/spec/flipper/ui/util_spec.rb +0 -17
  48. data/spec/flipper/ui_spec.rb +0 -197
@@ -1,63 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::Import do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
-
10
- let(:session) do
11
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
12
- end
13
-
14
- let(:path) { FlipperRoot.join("spec", "fixtures", "flipper_pstore_1679087600.json") }
15
-
16
- describe "POST /settings/import" do
17
- before do
18
- flipper.enable :plausible
19
- flipper.disable :google_analytics
20
-
21
- post '/settings/import',
22
- {
23
- 'authenticity_token' => token,
24
- 'file' => Rack::Test::UploadedFile.new(path, "application/json"),
25
- },
26
- 'rack.session' => session
27
- end
28
-
29
- it 'imports the file export' do
30
- expect(flipper[:search].actors_value).to eq(Set.new(['john', 'another', 'testing']))
31
- expect(flipper[:search].groups_value).to eq(Set.new(['admins']))
32
- expect(flipper[:google_analytics_tag].percentage_of_actors_value).to eq(100)
33
- expect(flipper[:new_pricing].boolean_value).to eq(true)
34
- expect(flipper[:nope].boolean_value).to eq(false)
35
- end
36
-
37
- it 'responds with redirect to settings' do
38
- expect(last_response.status).to be(302)
39
- expect(last_response.headers['location']).to eq('/features')
40
- end
41
-
42
- context "when in read only mode" do
43
- before do
44
- allow(flipper).to receive(:read_only?) { true }
45
-
46
- post '/settings/import',
47
- {
48
- 'authenticity_token' => token,
49
- 'file' => Rack::Test::UploadedFile.new(path, "application/json"),
50
- },
51
- 'rack.session' => session
52
- end
53
-
54
- it 'returns 403' do
55
- expect(last_response.status).to be(403)
56
- end
57
-
58
- it 'renders read only template' do
59
- expect(last_response.body).to include('read only')
60
- end
61
- end
62
- end
63
- end
@@ -1,65 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::PercentageOfActorsGate do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
- let(:session) do
10
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
11
- end
12
-
13
- describe 'POST /features/:feature/percentage_of_actors' do
14
- context 'with valid value' do
15
- before do
16
- post 'features/search/percentage_of_actors',
17
- { 'value' => '24', 'authenticity_token' => token },
18
- 'rack.session' => session
19
- end
20
-
21
- it 'enables the feature' do
22
- expect(flipper[:search].percentage_of_actors_value).to be(24)
23
- end
24
-
25
- it 'redirects back to feature' do
26
- expect(last_response.status).to be(302)
27
- expect(last_response.headers['location']).to eq('/features/search')
28
- end
29
- end
30
-
31
- context 'with space in feature name' do
32
- before do
33
- post 'features/sp+ace/percentage_of_actors',
34
- { 'value' => '24', 'authenticity_token' => token },
35
- 'rack.session' => session
36
- end
37
-
38
- it 'enables the feature' do
39
- expect(flipper["sp ace"].percentage_of_actors_value).to be(24)
40
- end
41
-
42
- it 'redirects back to feature' do
43
- expect(last_response.status).to be(302)
44
- expect(last_response.headers['location']).to eq('/features/sp+ace')
45
- end
46
- end
47
-
48
- context 'with invalid value' do
49
- before do
50
- post 'features/search/percentage_of_actors',
51
- { 'value' => '555', 'authenticity_token' => token },
52
- 'rack.session' => session
53
- end
54
-
55
- it 'does not change value' do
56
- expect(flipper[:search].percentage_of_actors_value).to be(0)
57
- end
58
-
59
- it 'redirects back to feature' do
60
- expect(last_response.status).to be(302)
61
- expect(last_response.headers['location']).to eq('/features/search?error=Invalid+percentage+of+actors+value%3A+value+must+be+a+positive+number+less+than+or+equal+to+100%2C+but+was+555')
62
- end
63
- end
64
- end
65
- end
@@ -1,65 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::PercentageOfTimeGate do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
- let(:session) do
10
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
11
- end
12
-
13
- describe 'POST /features/:feature/percentage_of_time' do
14
- context 'with valid value' do
15
- before do
16
- post 'features/search/percentage_of_time',
17
- { 'value' => '24', 'authenticity_token' => token },
18
- 'rack.session' => session
19
- end
20
-
21
- it 'enables the feature' do
22
- expect(flipper[:search].percentage_of_time_value).to be(24)
23
- end
24
-
25
- it 'redirects back to feature' do
26
- expect(last_response.status).to be(302)
27
- expect(last_response.headers['location']).to eq('/features/search')
28
- end
29
- end
30
-
31
- context 'with space in feature name' do
32
- before do
33
- post 'features/sp+ace/percentage_of_time',
34
- { 'value' => '24', 'authenticity_token' => token },
35
- 'rack.session' => session
36
- end
37
-
38
- it 'enables the feature' do
39
- expect(flipper["sp ace"].percentage_of_time_value).to be(24)
40
- end
41
-
42
- it 'redirects back to feature' do
43
- expect(last_response.status).to be(302)
44
- expect(last_response.headers['location']).to eq('/features/sp+ace')
45
- end
46
- end
47
-
48
- context 'with invalid value' do
49
- before do
50
- post 'features/search/percentage_of_time',
51
- { 'value' => '555', 'authenticity_token' => token },
52
- 'rack.session' => session
53
- end
54
-
55
- it 'does not change value' do
56
- expect(flipper[:search].percentage_of_time_value).to be(0)
57
- end
58
-
59
- it 'redirects back to feature' do
60
- expect(last_response.status).to be(302)
61
- expect(last_response.headers['location']).to eq('/features/search?error=Invalid+percentage+of+time+value%3A+value+must+be+a+positive+number+less+than+or+equal+to+100%2C+but+was+555')
62
- end
63
- end
64
- end
65
- end
@@ -1,35 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::Settings do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
-
10
- let(:session) do
11
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
12
- end
13
-
14
- describe 'GET /settings' do
15
- before do
16
- get '/settings'
17
- end
18
-
19
- it 'responds with success' do
20
- expect(last_response.status).to be(200)
21
- end
22
-
23
- it 'renders template' do
24
- expect(last_response.body).to include('Download')
25
- end
26
-
27
- it 'includes migrate to Flipper Cloud card' do
28
- expect(last_response.body).to include('Migrate to Flipper Cloud')
29
- end
30
-
31
- it 'shows feature count' do
32
- expect(last_response.body).to include('features ready to migrate')
33
- end
34
- end
35
- end
@@ -1,229 +0,0 @@
1
- RSpec.describe Flipper::UI::Configuration do
2
- let(:configuration) { described_class.new }
3
-
4
- describe "#delete" do
5
- it "has default text" do
6
- expect(configuration.delete.title).to eq("Danger Zone")
7
- expect(configuration.delete.description).to eq("Deleting a feature removes it from the list of features and disables it for everyone.")
8
- end
9
- end
10
-
11
- describe "#banner_text" do
12
- it "has no default" do
13
- expect(configuration.banner_text).to eq(nil)
14
- end
15
-
16
- it "can be updated" do
17
- configuration.banner_text = 'Production Environment'
18
- expect(configuration.banner_text).to eq('Production Environment')
19
- end
20
- end
21
-
22
- describe "#banner_class" do
23
- it "has default color" do
24
- expect(configuration.banner_class).to eq('danger')
25
- end
26
-
27
- it "can be updated" do
28
- configuration.banner_class = 'info'
29
- expect(configuration.banner_class).to eq('info')
30
- end
31
-
32
- it "raises if set to invalid value" do
33
- expect { configuration.banner_class = :invalid_class }
34
- .to raise_error(Flipper::InvalidConfigurationValue)
35
- end
36
- end
37
-
38
- describe "#application_href" do
39
- it "has default value" do
40
- expect(configuration.application_href).to eq(nil)
41
- end
42
-
43
- it "can be updated" do
44
- configuration.application_href = 'http://www.myapp.com'
45
- expect(configuration.application_href).to eq('http://www.myapp.com')
46
- end
47
-
48
- it 'aliases application_breadcrumb_href to application_href' do
49
- configuration.application_breadcrumb_href = "/myapp"
50
- expect(configuration.application_href).to eq("/myapp")
51
- end
52
- end
53
-
54
- describe "#feature_creation_enabled" do
55
- it "has default value" do
56
- expect(configuration.feature_creation_enabled).to eq(true)
57
- end
58
-
59
- it "can be updated" do
60
- configuration.feature_creation_enabled = false
61
- expect(configuration.feature_creation_enabled).to eq(false)
62
- end
63
- end
64
-
65
- describe "#cloud_recommendation" do
66
- it "has default value" do
67
- expect(configuration.cloud_recommendation).to eq(true)
68
- end
69
-
70
- it "can be updated" do
71
- configuration.cloud_recommendation = false
72
- expect(configuration.cloud_recommendation).to eq(false)
73
- end
74
- end
75
-
76
- describe "#version_check_enabled" do
77
- it "has default value" do
78
- expect(configuration.version_check_enabled).to eq(true)
79
- end
80
-
81
- it "can be updated" do
82
- configuration.version_check_enabled = false
83
- expect(configuration.version_check_enabled).to eq(false)
84
- end
85
- end
86
-
87
- describe "#feature_removal_enabled" do
88
- it "has default value" do
89
- expect(configuration.feature_removal_enabled).to eq(true)
90
- end
91
-
92
- it "can be updated" do
93
- configuration.feature_removal_enabled = false
94
- expect(configuration.feature_removal_enabled).to eq(false)
95
- end
96
- end
97
-
98
- describe "#fun" do
99
- it "has default value" do
100
- expect(configuration.fun).to eq(true)
101
- end
102
-
103
- it "can be updated" do
104
- configuration.fun = false
105
- expect(configuration.fun).to eq(false)
106
- end
107
- end
108
-
109
- describe "#descriptions_source" do
110
- it "has default value" do
111
- expect(configuration.descriptions_source.call(%w[foo bar])).to eq({})
112
- end
113
-
114
- context "descriptions source is provided" do
115
- it "can be updated" do
116
- configuration.descriptions_source = lambda do |_keys|
117
- YAML.load_file(FlipperRoot.join('spec/support/descriptions.yml'))
118
- end
119
- keys = %w[some_awesome_feature foo]
120
- result = configuration.descriptions_source.call(keys)
121
- expected = {
122
- "some_awesome_feature" => "Awesome feature description",
123
- }
124
- expect(result).to eq(expected)
125
- end
126
- end
127
- end
128
-
129
- describe "#actor_names_source" do
130
- it "has default value" do
131
- expect(configuration.actor_names_source.call(%w[foo bar])).to eq({})
132
- end
133
-
134
- context "actor names source is provided" do
135
- it "can be updated" do
136
- configuration.actor_names_source = lambda do |_keys|
137
- YAML.load_file(FlipperRoot.join('spec/support/actor_names.yml'))
138
- end
139
- keys = %w[actor_1 foo]
140
- result = configuration.actor_names_source.call(keys)
141
- expected = {
142
- "actor_name_1" => "Actor #1",
143
- }
144
- expect(result).to eq(expected)
145
- end
146
- end
147
- end
148
-
149
- describe "#confirm_fully_enable" do
150
- it "has default value" do
151
- expect(configuration.confirm_fully_enable).to eq(false)
152
- end
153
-
154
- it "can be updated" do
155
- configuration.confirm_fully_enable = true
156
- expect(configuration.confirm_fully_enable).to eq(true)
157
- end
158
- end
159
-
160
- describe "#disable_fully_enable" do
161
- it "defaults to nil" do
162
- expect(configuration.disable_fully_enable).to be_nil
163
- end
164
-
165
- it "can be set to true" do
166
- configuration.disable_fully_enable = true
167
- expect(configuration.disable_fully_enable).to eq(true)
168
- end
169
-
170
- it "can be set to false" do
171
- configuration.disable_fully_enable = false
172
- expect(configuration.disable_fully_enable).to eq(false)
173
- end
174
-
175
- it "can be set to a custom message" do
176
- configuration.disable_fully_enable = "Use deploy pipeline instead."
177
- expect(configuration.disable_fully_enable).to eq("Use deploy pipeline instead.")
178
- end
179
- end
180
-
181
- describe "#disable_fully_enable_message" do
182
- it "returns default message when set to true" do
183
- configuration.disable_fully_enable = true
184
- expect(configuration.disable_fully_enable_message).to eq("Fully enabling features via the UI is disabled.")
185
- end
186
-
187
- it "returns custom message when set to a string" do
188
- configuration.disable_fully_enable = "Use deploy pipeline instead."
189
- expect(configuration.disable_fully_enable_message).to eq("Use deploy pipeline instead.")
190
- end
191
- end
192
-
193
- describe "#show_feature_description_in_list" do
194
- it "has default value" do
195
- expect(configuration.show_feature_description_in_list).to eq(false)
196
- end
197
-
198
- it "can be updated" do
199
- configuration.show_feature_description_in_list = true
200
- expect(configuration.show_feature_description_in_list).to eq(true)
201
- end
202
- end
203
-
204
- describe "#show_feature_description_in_list?" do
205
- subject { configuration.show_feature_description_in_list? }
206
-
207
- context 'when using_descriptions? is false and show_feature_description_in_list is false' do
208
- it { is_expected.to eq(false) }
209
- end
210
-
211
- context 'when using_descriptions? is false and show_feature_description_in_list is true' do
212
- before { configuration.show_feature_description_in_list = true }
213
- it { is_expected.to eq(false) }
214
- end
215
-
216
- context 'when using_descriptions? is true and show_feature_description_in_list is false' do
217
- before { allow(configuration).to receive(:using_descriptions?).and_return(true) }
218
- it { is_expected.to eq(false) }
219
- end
220
-
221
- context 'when using_descriptions? is true and show_feature_description_in_list is true' do
222
- before do
223
- allow(configuration).to receive(:using_descriptions?).and_return(true)
224
- configuration.show_feature_description_in_list = true
225
- end
226
- it { is_expected.to eq(true) }
227
- end
228
- end
229
- end
@@ -1,59 +0,0 @@
1
- RSpec.describe Flipper::UI::Decorators::Feature do
2
- let(:source) { {} }
3
- let(:adapter) { Flipper::Adapters::Memory.new(source) }
4
- let(:flipper) { build_flipper }
5
- let(:feature) { flipper[:some_awesome_feature] }
6
-
7
- subject do
8
- described_class.new(feature)
9
- end
10
-
11
- describe '#initialize' do
12
- it 'sets the feature' do
13
- expect(subject.feature).to be(feature)
14
- end
15
- end
16
-
17
- describe '#pretty_name' do
18
- it 'capitalizes each word separated by underscores' do
19
- expect(subject.pretty_name).to eq('Some Awesome Feature')
20
- end
21
- end
22
-
23
- describe '#<=>' do
24
- let(:on) do
25
- flipper.enable(:on_a)
26
- described_class.new(flipper[:on_a])
27
- end
28
-
29
- let(:on_b) do
30
- flipper.enable(:on_b)
31
- described_class.new(flipper[:on_b])
32
- end
33
-
34
- let(:conditional) do
35
- flipper.enable_percentage_of_time :conditional_a, 5
36
- described_class.new(flipper[:conditional_a])
37
- end
38
-
39
- let(:off) do
40
- described_class.new(flipper[:off_a])
41
- end
42
-
43
- it 'sorts :on before :conditional' do
44
- expect((on <=> conditional)).to be(-1)
45
- end
46
-
47
- it 'sorts :on before :off' do
48
- expect((on <=> off)).to be(-1)
49
- end
50
-
51
- it 'sorts :conditional before :off' do
52
- expect((conditional <=> off)).to be(-1)
53
- end
54
-
55
- it 'sorts on key for identical states' do
56
- expect((on <=> on_b)).to be(-1)
57
- end
58
- end
59
- end
@@ -1,45 +0,0 @@
1
- require 'flipper/ui/decorators/gate'
2
-
3
- RSpec.describe Flipper::UI::Decorators::Gate do
4
- let(:source) { {} }
5
- let(:adapter) { Flipper::Adapters::Memory.new(source) }
6
- let(:flipper) { build_flipper }
7
- let(:feature) { flipper[:some_awesome_feature] }
8
- let(:gate) { feature.gate(:boolean) }
9
-
10
- subject do
11
- described_class.new(gate, false)
12
- end
13
-
14
- describe '#initialize' do
15
- it 'sets gate' do
16
- expect(subject.gate).to be(gate)
17
- end
18
-
19
- it 'sets value' do
20
- expect(subject.value).to eq(false)
21
- end
22
- end
23
-
24
- describe '#as_json' do
25
- before do
26
- @result = subject.as_json
27
- end
28
-
29
- it 'returns Hash' do
30
- expect(@result).to be_instance_of(Hash)
31
- end
32
-
33
- it 'includes key' do
34
- expect(@result['key']).to eq('boolean')
35
- end
36
-
37
- it 'includes pretty name' do
38
- expect(@result['name']).to eq('boolean')
39
- end
40
-
41
- it 'includes value' do
42
- expect(@result['value']).to be(false)
43
- end
44
- end
45
- end
@@ -1,17 +0,0 @@
1
- require 'flipper/ui/util'
2
-
3
- RSpec.describe Flipper::UI::Util do
4
- describe '#blank?' do
5
- context 'with a string' do
6
- it 'returns true if blank' do
7
- expect(described_class.blank?(nil)).to be(true)
8
- expect(described_class.blank?('')).to be(true)
9
- expect(described_class.blank?(' ')).to be(true)
10
- end
11
-
12
- it 'returns false if not blank' do
13
- expect(described_class.blank?('nope')).to be(false)
14
- end
15
- end
16
- end
17
- end