rails_readonly_injector 0.2.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE.md +18 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +24 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +7 -0
- data/.travis.yml +3 -1
- data/Appraisals +10 -1
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +4 -2
- data/LICENSE.txt +0 -0
- data/README.md +25 -6
- data/Rakefile +4 -2
- data/bin/console +4 -3
- data/cucumber_features/configuration.feature +0 -0
- data/cucumber_features/step_definitions/.gitkeep +0 -0
- data/cucumber_features/step_definitions/generic_steps.rb +5 -3
- data/cucumber_features/step_definitions/user_steps.rb +18 -14
- data/cucumber_features/support/.gitkeep +0 -0
- data/cucumber_features/user_controller.feature +0 -0
- data/cucumber_features/user_controller_readonly.feature +0 -0
- data/cucumber_features/user_model.feature +0 -0
- data/cucumber_features/user_model_readonly.feature +0 -0
- data/development_tasks/support/file_helpers.rb +57 -0
- data/development_tasks/support/gem_helpers.rb +63 -0
- data/development_tasks/tests.rake +40 -93
- data/gemfiles/.bundle/config +0 -0
- data/gemfiles/rails_3.gemfile +0 -0
- data/gemfiles/rails_4_0.gemfile +0 -0
- data/gemfiles/rails_4_1.gemfile +0 -0
- data/gemfiles/rails_4_2.gemfile +0 -0
- data/gemfiles/rails_5_0.gemfile +0 -0
- data/gemfiles/rails_5_1.gemfile +0 -0
- data/gemfiles/rails_5_2.gemfile +10 -0
- data/lib/rails_readonly_injector.rb +37 -20
- data/lib/rails_readonly_injector/configuration.rb +86 -20
- data/lib/rails_readonly_injector/version.rb +3 -1
- data/rails_readonly_injector.gemspec +16 -14
- data/rspec_specs/.gitkeep +0 -0
- data/rspec_specs/rails_readonly_injector/configuration_spec.rb +167 -0
- data/rspec_specs/{readonly_site_toggle_spec.rb → rails_readonly_injector_spec.rb} +42 -1
- data/rspec_specs/support/.gitkeep +0 -0
- metadata +36 -18
- data/rspec_specs/readonly_site_toggle/configuration_spec.rb +0 -31
data/rspec_specs/.gitkeep
CHANGED
File without changes
|
@@ -0,0 +1,167 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe RailsReadonlyInjector.config do
|
6
|
+
describe '#controller_rescue_action=' do
|
7
|
+
context 'when given a lambda expression' do
|
8
|
+
let(:exp) { -> { 'This is a test lambda!' } }
|
9
|
+
before do
|
10
|
+
RailsReadonlyInjector.config.controller_rescue_action = exp
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { RailsReadonlyInjector.config.controller_rescue_action }
|
14
|
+
|
15
|
+
it { is_expected.to eq(exp) }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when given a Proc' do
|
19
|
+
let(:passed_proc) { proc { 'This is a test Proc!' } }
|
20
|
+
|
21
|
+
before do
|
22
|
+
RailsReadonlyInjector.config.controller_rescue_action = passed_proc
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { RailsReadonlyInjector.config.controller_rescue_action }
|
26
|
+
|
27
|
+
it { is_expected.to eq(passed_proc) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when an invalid value is assigned' do
|
31
|
+
it 'raises an error message' do
|
32
|
+
expect do
|
33
|
+
RailsReadonlyInjector.config.controller_rescue_action = nil
|
34
|
+
end.to raise_error 'A lambda or proc must be specified'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#classes_to_include' do
|
40
|
+
context 'when not defined' do
|
41
|
+
context 'when using Rails < 5.0' do
|
42
|
+
before do
|
43
|
+
stub_const('Rails::VERSION::STRING', '4.1.0')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the descendants of ActiveRecord::Base' do
|
47
|
+
expect(ActiveRecord::Base).to receive(:descendants)
|
48
|
+
|
49
|
+
RailsReadonlyInjector.config.classes_to_include
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when using Rails >= 5.0' do
|
54
|
+
before do
|
55
|
+
stub_const('Rails::VERSION::STRING', '5.0.0')
|
56
|
+
|
57
|
+
unless defined? ApplicationRecord
|
58
|
+
# :nodoc:
|
59
|
+
class ApplicationRecord
|
60
|
+
def descendants; end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns the descendants of ActiveRecord::Base' do
|
66
|
+
expect(ApplicationRecord).to receive(:descendants)
|
67
|
+
|
68
|
+
RailsReadonlyInjector.config.classes_to_include
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#changed_attributes' do
|
75
|
+
setup do
|
76
|
+
RailsReadonlyInjector.reset_configuration!
|
77
|
+
|
78
|
+
RailsReadonlyInjector.config.read_only = false
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when one attribute is changed' do
|
82
|
+
before(:each) do
|
83
|
+
RailsReadonlyInjector.config.read_only = true
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'and `reload!` is not called' do
|
87
|
+
subject { RailsReadonlyInjector.config.changed_attributes }
|
88
|
+
|
89
|
+
it 'returns a hash with the attribute and its old value' do
|
90
|
+
expect(subject).to eq(read_only: false)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'and `reload!` is called' do
|
95
|
+
before { RailsReadonlyInjector.reload! }
|
96
|
+
subject { RailsReadonlyInjector.config.changed_attributes }
|
97
|
+
|
98
|
+
it 'returns an empty hash' do
|
99
|
+
expect(subject).to eq({})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when more than one attribute is changed' do
|
105
|
+
setup { class TestClassA < ActiveRecord::Base; end; }
|
106
|
+
|
107
|
+
before(:each) do
|
108
|
+
RailsReadonlyInjector.config do |c|
|
109
|
+
c.read_only = true
|
110
|
+
c.classes_to_include = [TestClassA]
|
111
|
+
c.classes_to_exclude = [User]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'and `reload!` is not called' do
|
116
|
+
subject { RailsReadonlyInjector.config.changed_attributes }
|
117
|
+
|
118
|
+
it 'returns a hash with the attribute and its old value' do
|
119
|
+
expect(subject).to eq(
|
120
|
+
read_only: false,
|
121
|
+
classes_to_include: nil,
|
122
|
+
classes_to_exclude: []
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'and `reload!` is called' do
|
128
|
+
before { RailsReadonlyInjector.reload! }
|
129
|
+
subject { RailsReadonlyInjector.config.changed_attributes }
|
130
|
+
|
131
|
+
it 'returns an empty hash' do
|
132
|
+
expect(subject).to eq({})
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when an attribute is not changed' do
|
138
|
+
subject { RailsReadonlyInjector.config.changed_attributes }
|
139
|
+
|
140
|
+
it { is_expected.to eq({}) }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#dirty?' do
|
145
|
+
setup do
|
146
|
+
RailsReadonlyInjector.config { |config| config.read_only = false }
|
147
|
+
RailsReadonlyInjector.reload!
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when `read_only` is changed' do
|
151
|
+
before(:each) { RailsReadonlyInjector.config.read_only = true }
|
152
|
+
|
153
|
+
context 'and `reload!` is not called' do
|
154
|
+
subject { RailsReadonlyInjector.config.dirty? }
|
155
|
+
|
156
|
+
it { is_expected.to eq(true) }
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'and `reload!` is called' do
|
160
|
+
before { RailsReadonlyInjector.reload! }
|
161
|
+
subject { RailsReadonlyInjector.config.dirty? }
|
162
|
+
|
163
|
+
it { is_expected.to eq(false) }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails_helper'
|
2
4
|
|
3
5
|
RSpec.describe RailsReadonlyInjector do
|
@@ -13,7 +15,7 @@ RSpec.describe RailsReadonlyInjector do
|
|
13
15
|
subject { RailsReadonlyInjector.config }
|
14
16
|
|
15
17
|
it 'sets `read_only` to false' do
|
16
|
-
expect(RailsReadonlyInjector.config.read_only).to eq(false)
|
18
|
+
expect(RailsReadonlyInjector.config.send(:read_only)).to eq(false)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -56,4 +58,43 @@ RSpec.describe RailsReadonlyInjector do
|
|
56
58
|
it { is_expected.to eq(false) }
|
57
59
|
end
|
58
60
|
end
|
61
|
+
|
62
|
+
describe '#in_read_only_mode?' do
|
63
|
+
setup do
|
64
|
+
RailsReadonlyInjector.config.read_only = false
|
65
|
+
RailsReadonlyInjector.reload!
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when `reload!` is called' do
|
69
|
+
before do
|
70
|
+
RailsReadonlyInjector.config.read_only = true
|
71
|
+
RailsReadonlyInjector.reload!
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns the correct value' do
|
75
|
+
expect(RailsReadonlyInjector.in_read_only_mode?).to eq(true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when `reload!` is not called' do
|
80
|
+
context 'when `config.read_only` is changed' do
|
81
|
+
before do
|
82
|
+
RailsReadonlyInjector.config.read_only = true
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns the previous value' do
|
86
|
+
expect(RailsReadonlyInjector.in_read_only_mode?).to eq(false)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when `config.read_only` is not changed' do
|
91
|
+
before { RailsReadonlyInjector.config.classes_to_exclude = [User] }
|
92
|
+
subject { RailsReadonlyInjector.in_read_only_mode? }
|
93
|
+
|
94
|
+
it 'returns the current value' do
|
95
|
+
expect(subject).to eq(RailsReadonlyInjector.config.send(:read_only))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
59
100
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_readonly_injector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Walter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '3.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5.
|
22
|
+
version: '5.3'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,49 +29,63 @@ dependencies:
|
|
29
29
|
version: '3.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5.
|
32
|
+
version: '5.3'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: appraisal
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '2.2'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.16'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
46
60
|
version: '1.16'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: rake
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
|
-
- - "
|
65
|
+
- - ">="
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
67
|
+
version: 12.3.3
|
54
68
|
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
|
-
- - "
|
72
|
+
- - ">="
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
74
|
+
version: 12.3.3
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
76
|
+
name: yard
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
66
80
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
81
|
+
version: 0.9.12
|
68
82
|
type: :development
|
69
83
|
prerelease: false
|
70
84
|
version_requirements: !ruby/object:Gem::Requirement
|
71
85
|
requirements:
|
72
86
|
- - "~>"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
88
|
+
version: 0.9.12
|
75
89
|
description:
|
76
90
|
email:
|
77
91
|
- andrew.walter@burnet.edu.au
|
@@ -79,13 +93,15 @@ executables: []
|
|
79
93
|
extensions: []
|
80
94
|
extra_rdoc_files: []
|
81
95
|
files:
|
96
|
+
- ".github/ISSUE_TEMPLATE.md"
|
97
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
82
98
|
- ".gitignore"
|
99
|
+
- ".rubocop.yml"
|
83
100
|
- ".travis.yml"
|
84
101
|
- Appraisals
|
85
102
|
- CHANGELOG.md
|
86
103
|
- CODE_OF_CONDUCT.md
|
87
104
|
- Gemfile
|
88
|
-
- Gemfile.lock
|
89
105
|
- LICENSE.txt
|
90
106
|
- README.md
|
91
107
|
- Rakefile
|
@@ -100,6 +116,8 @@ files:
|
|
100
116
|
- cucumber_features/user_controller_readonly.feature
|
101
117
|
- cucumber_features/user_model.feature
|
102
118
|
- cucumber_features/user_model_readonly.feature
|
119
|
+
- development_tasks/support/file_helpers.rb
|
120
|
+
- development_tasks/support/gem_helpers.rb
|
103
121
|
- development_tasks/tests.rake
|
104
122
|
- gemfiles/.bundle/config
|
105
123
|
- gemfiles/rails_3.gemfile
|
@@ -108,13 +126,14 @@ files:
|
|
108
126
|
- gemfiles/rails_4_2.gemfile
|
109
127
|
- gemfiles/rails_5_0.gemfile
|
110
128
|
- gemfiles/rails_5_1.gemfile
|
129
|
+
- gemfiles/rails_5_2.gemfile
|
111
130
|
- lib/rails_readonly_injector.rb
|
112
131
|
- lib/rails_readonly_injector/configuration.rb
|
113
132
|
- lib/rails_readonly_injector/version.rb
|
114
133
|
- rails_readonly_injector.gemspec
|
115
134
|
- rspec_specs/.gitkeep
|
116
|
-
- rspec_specs/
|
117
|
-
- rspec_specs/
|
135
|
+
- rspec_specs/rails_readonly_injector/configuration_spec.rb
|
136
|
+
- rspec_specs/rails_readonly_injector_spec.rb
|
118
137
|
- rspec_specs/support/.gitkeep
|
119
138
|
homepage: https://www.github.com/xtrasimplicity/rails_readonly_injector
|
120
139
|
licenses:
|
@@ -135,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
154
|
- !ruby/object:Gem::Version
|
136
155
|
version: '0'
|
137
156
|
requirements: []
|
138
|
-
|
139
|
-
rubygems_version: 2.6.13
|
157
|
+
rubygems_version: 3.0.3
|
140
158
|
signing_key:
|
141
159
|
specification_version: 4
|
142
160
|
summary: Globally toggle 'read-only' mode in a Rails application, on-demand, without
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe RailsReadonlyInjector.config do
|
4
|
-
describe '#controller_rescue_action=' do
|
5
|
-
context 'when given a lambda expression' do
|
6
|
-
let(:lambda_expression) { lambda { "This is a test lambda!" } }
|
7
|
-
|
8
|
-
before { RailsReadonlyInjector.config.controller_rescue_action = lambda_expression }
|
9
|
-
|
10
|
-
subject { RailsReadonlyInjector.config.controller_rescue_action }
|
11
|
-
|
12
|
-
it { is_expected.to eq(lambda_expression) }
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when given a Proc' do
|
16
|
-
let(:proc) { Proc.new { "This is a test Proc!" } }
|
17
|
-
|
18
|
-
before { RailsReadonlyInjector.config.controller_rescue_action = proc }
|
19
|
-
|
20
|
-
subject { RailsReadonlyInjector.config.controller_rescue_action }
|
21
|
-
|
22
|
-
it { is_expected.to eq(proc) }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when an invalid value is assigned' do
|
26
|
-
it 'raises an error message' do
|
27
|
-
expect { RailsReadonlyInjector.config.controller_rescue_action = nil }.to raise_error 'A lambda or proc must be specified'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|