rails_readonly_injector 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25d251e5a12704817f3a4568882e00d68c6d80de
4
- data.tar.gz: 1b5b6fdbe4cb1772286002fb24ecc22b63e4f5f7
3
+ metadata.gz: c048af88f0b2c66068ceac474300b94da63bf30a
4
+ data.tar.gz: 9c2dd969f857a47fa866887c6e1e9bbe467b5dfd
5
5
  SHA512:
6
- metadata.gz: 9182f0b556f492a5180677208f42833840bc091b6047ce6fbad5fa19ecb491a153575ea68b80f6971526bae58d1a5217be0f03e39b32737aa8fa33f512a5801c
7
- data.tar.gz: 358b647a57d38f3b0f3235f0b6ad3dc0ee00055384403158a7556446b3b4acaf2b168d93cbfbcb18f2ac9ffaffa4bc197ef365a1c550363fd529ad0409174b8e
6
+ metadata.gz: 751bf2c91e9798e777811577792ae4c92d6bea387ea265b13c00e15a4ed9c5598fd5b27da99cc89f6c112a0d3e35398912e6e03f963ef002962cc0b37bc4314d
7
+ data.tar.gz: 3b90a488f476ccb57ab84bf6a4b255687e0e0688c4dae617222c4d8d35e0ebb867df9ccf7cddffd7a5f8531a5941b3d7a615c9b43980476aa0efc675df7d771a
@@ -0,0 +1,18 @@
1
+ ## Expected Behavior
2
+
3
+
4
+ ## Actual Behavior
5
+
6
+
7
+ ## Steps to Reproduce the Problem
8
+
9
+ 1.
10
+ 2.
11
+ 3.
12
+ 4.
13
+
14
+ ## Specifications
15
+
16
+ - Version:
17
+ - Platform:
18
+ - Subsystem:
@@ -0,0 +1,24 @@
1
+ ## Problem
2
+
3
+ <!-- Describe the problem that this PR resolves -->
4
+
5
+ #### Related issues:
6
+ <!-- Link to issues that are related to this problem. If there aren't any, you can remove the heading. -->
7
+
8
+ ## How this PR resolves the problem
9
+
10
+ <!--- Describe how your PR resolves this problem -->
11
+
12
+ ## Types of changes
13
+
14
+ <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
15
+ - [ ] Bug fix (non-breaking change which fixes an issue).
16
+ - [ ] New feature (non-breaking change which adds functionality).
17
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected).
18
+
19
+ ## Checklist:
20
+
21
+ <!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
22
+ - [ ] I've added tests for my code.
23
+ - [ ] My change requires a change to the documentation.
24
+ - [ ] I have updated the documentation accordingly.
data/.gitignore CHANGED
@@ -7,5 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  gemfiles/*.gemfile.lock
10
- .byebug_history
11
- Gemfile.lock
10
+ .byebug_history
@@ -1,3 +1,5 @@
1
+ ## 1.0.0
2
+ - Removed the ability to read the current read-only status using `RailsReadonlyInjector.config.read_only`, and replaced it with `RailsReadonlyInjector.in_read_only_mode?`.
1
3
  ## 0.3.0
2
4
  - Added ability to explicitly include specific classes.
3
5
  ## 0.2.0
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_readonly_injector (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ appraisal (2.2.0)
10
+ bundler
11
+ rake
12
+ thor (>= 0.14.0)
13
+ rake (10.5.0)
14
+ thor (0.20.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ appraisal (~> 2.2.0)
21
+ bundler (~> 1.16)
22
+ rails_readonly_injector!
23
+ rake (~> 10.0)
24
+
25
+ BUNDLED WITH
26
+ 1.16.1
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Rails ReadOnly Injector
2
2
  [![Build Status](https://travis-ci.org/xtrasimplicity/rails_readonly_injector.svg?branch=master)](https://travis-ci.org/xtrasimplicity/rails_readonly_injector)
3
+ [![Read the Docs](https://img.shields.io/readthedocs/pip.svg)](http://www.rubydoc.info/github/xtrasimplicity/rails_readonly_injector/master)
3
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/427c153efd48ae03f688/maintainability)](https://codeclimate.com/github/xtrasimplicity/rails_readonly_injector/maintainability)
4
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/427c153efd48ae03f688/test_coverage)](https://codeclimate.com/github/xtrasimplicity/rails_readonly_injector/test_coverage)
5
6
  [![Gem Version](https://badge.fury.io/rb/rails_readonly_injector.svg)](https://badge.fury.io/rb/rails_readonly_injector)
@@ -45,11 +46,14 @@ When you want to switch a site into read-only mode, you can then simply set `Rai
45
46
 
46
47
  If you want to reset the configuration to the defaults, you can simply call `RailsReadonlyInjector.reset_configuration!` from anywhere in your application.
47
48
 
49
+ If you want to check whether read-only mode is currently enabled, you can use `RailsReadonlyInjector.in_read_only_mode?`.
50
+
48
51
  ## Configuration Options
49
52
  - `read_only` => Whether the site should be in read-only mode. (Default: false)
50
53
  - `classes_to_exclude` => An array of classes that should be _exempt_ from read-only mode. (Default: `[]`)
51
54
  - `classes_to_include` => An array of classes that should be set to read-only mode. (Defaults to `ActiveRecord::Base.descendants` on Rails 3-4, and `ApplicationRecord.descendants` on Rails 5.0+)
52
55
  - `controller_rescue_action` => A lambda expression/Proc to execute when an `ActiveRecord::ReadOnlyRecord` error is raised, from within a controller.
56
+
53
57
  ## Development
54
58
 
55
59
  After checking out the repo, run `bundle install` to install the dependencies.
@@ -58,6 +62,13 @@ RSpec specs and Cucumber features are stored in `rspec_specs` and `cucumber_feat
58
62
 
59
63
  To run tests for a specific version of Rails, simply run `bundle exec appraisal {APPRAISAL} bundle exec rake`, where `{APPRAISAL}` is one of the appraisals found under `Appraisals`.
60
64
 
65
+ If you don't want to re-build the application each time you run tests, you can execute one of the following rake tasks against an appraisal:
66
+
67
+ * `dev:run_features` => Synchronises features from `cucumber_features` into the temporary rails application, and runs them against the application.
68
+ * `dev:run_specs` => Synchronises specs from `rspec_specs` into the temporary rails application, and runs them against the application.
69
+ * `dev:run_tests` => Runs both `dev:run_features` and `dev:run_specs`.
70
+
71
+
61
72
  ## Contributing
62
73
 
63
74
  Bug reports and pull requests are welcome on GitHub at https://github.com/xtrasimplicity/rails_readonly_injector. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -40,6 +40,8 @@ Then("the user should be updated") do
40
40
  end
41
41
 
42
42
  Then("the user should be saved") do
43
+ @user.reload
44
+
43
45
  expect(@user.persisted?).to eq(true)
44
46
  end
45
47
 
@@ -31,17 +31,12 @@ namespace :dev do
31
31
  append_to_file 'Gemfile', %{gem "rails_readonly_injector", path: "#{GEM_ROOT_PATH}"\n}
32
32
 
33
33
  # Make sure we don't use the gemfile from Appraisal
34
- ENV.delete('BUNDLE_GEMFILE')
35
- ENV.delete('BUNDLE_BIN_PATH')
36
- ENV.delete('RUBYOPT')
34
+ unset_appraisal_environment_variables
37
35
 
38
36
  # Install gems
39
- system("bundle install --binstubs")
37
+ system("bundle install")
40
38
 
41
- puts "Installing Cucumber..."
42
39
  system("bundle exec rails generate cucumber:install")
43
-
44
- puts "Installing RSpec..."
45
40
  system("bundle exec rails generate rspec:install")
46
41
 
47
42
  # RSpec: Include all files in support/
@@ -67,15 +62,35 @@ namespace :dev do
67
62
  end
68
63
 
69
64
  desc "Synchronises tests from `cucumber_features` and `rspec_specs` into the rails application in #{RAILS_APP_PATH}, and runs the tests against the application."
70
- task :run_tests do
65
+ task :run_tests => [:run_features, :run_specs]
66
+
67
+ desc "Synchronises features from `cucumber_features` into the rails application in #{RAILS_APP_PATH}, and runs them against the application."
68
+ task :run_features do
71
69
  switch_to_rails_app_path
72
70
 
73
- # Set up the Cucumber and RSpec tests
71
+ # Synchronise the cucumber features
74
72
  FileUtils.cp_r File.join(GEM_ROOT_PATH, 'cucumber_features', '.'), 'features'
73
+
74
+ unset_appraisal_environment_variables
75
+
76
+ command_executed_successfully = system('bundle exec cucumber')
77
+
78
+ exit 1 unless command_executed_successfully
79
+ end
80
+
81
+ desc "Synchronises specs from `rspec_specs` into the rails application in #{RAILS_APP_PATH}, and runs them against the application."
82
+ task :run_specs do
83
+ switch_to_rails_app_path
84
+
85
+ # Synchronise the cucumber features
75
86
  FileUtils.cp_r File.join(GEM_ROOT_PATH, 'rspec_specs', '.'), 'spec'
76
87
 
77
- exit_code = system('bundle exec cucumber && bundle exec rspec')
78
- exit exit_code
88
+ unset_appraisal_environment_variables
89
+
90
+
91
+ command_executed_successfully = system('bundle exec rspec')
92
+
93
+ exit 1 unless command_executed_successfully
79
94
  end
80
95
 
81
96
  def parse_gemfile(file_path)
@@ -127,4 +142,10 @@ namespace :dev do
127
142
  f.write content
128
143
  end
129
144
  end
145
+
146
+ def unset_appraisal_environment_variables
147
+ ENV.delete('BUNDLE_GEMFILE')
148
+ ENV.delete('BUNDLE_BIN_PATH')
149
+ ENV.delete('RUBYOPT')
150
+ end
130
151
  end
@@ -2,16 +2,20 @@ require "rails_readonly_injector/version"
2
2
  require "rails_readonly_injector/configuration"
3
3
 
4
4
  module RailsReadonlyInjector
5
+
6
+ # Applies changes defined in the `config` object
7
+ # and resets `config.dirty?` to false
5
8
  def self.reload!
6
9
  config.classes_to_include.each do |klass|
7
10
 
8
- # Ensure we don't impact classes that we want to exclude
11
+ # Ensure we restore classes that we want to exclude, to their defaults
12
+ # in case they were previously marked as read-only.
9
13
  if config.classes_to_exclude.include? klass
10
14
  restore_readonly_method(klass)
11
15
  next
12
16
  end
13
17
 
14
- if self.config.read_only
18
+ if self.config.send(:read_only)
15
19
  override_readonly_method(klass)
16
20
  else
17
21
  restore_readonly_method(klass)
@@ -19,6 +23,28 @@ module RailsReadonlyInjector
19
23
  end
20
24
 
21
25
  inject_error_handler_into_actioncontroller_base
26
+
27
+ self.config.send(:reset_dirty_status!)
28
+ end
29
+
30
+ # Returns the currently loaded `config.read_only` value.
31
+ # @return [Boolean] Whether the currently loaded config is set to read-only.
32
+ def self.in_read_only_mode?
33
+ if self.config.dirty? && self.config.changed_attributes.has_key?(:read_only)
34
+ # Return the previously stored value
35
+ self.config.changed_attributes[:read_only]
36
+ else
37
+ self.config.send(:read_only)
38
+ end
39
+ end
40
+
41
+ # Sets the desired configuration object, if a block is provided,
42
+ # and then returns the current configuration object.
43
+ # @return [Configuration] The current configuration object.
44
+ def self.config
45
+ yield self.configuration if block_given?
46
+
47
+ self.configuration
22
48
  end
23
49
 
24
50
  private
@@ -1,25 +1,20 @@
1
1
  module RailsReadonlyInjector
2
- class Configuration
3
- attr_writer :read_only, :classes_to_exclude, :classes_to_include
4
-
5
- def read_only
6
- @read_only || false
7
- end
8
-
9
- def controller_rescue_action=(action)
10
- raise 'A lambda or proc must be specified' unless action.respond_to? :call
11
2
 
12
- @controller_rescue_action = action
13
- end
3
+ class Configuration
4
+ attr_reader :controller_rescue_action, :classes_to_include, :classes_to_exclude
14
5
 
15
- def controller_rescue_action
16
- @controller_rescue_action || Proc.new {}
17
- end
6
+ def initialize
7
+ @read_only = false
8
+ @controller_rescue_action = Proc.new {}
9
+ @classes_to_exclude = []
18
10
 
19
- def classes_to_exclude
20
- @classes_to_exclude || []
11
+ @changed_attributes = Hash.new
21
12
  end
22
13
 
14
+ # @return [Array<Class>] An array of classes to include
15
+ # If not specified upon initialisation, it defaults to:
16
+ # ActiveRecord::Base.descendants on Rails < 5.0.0, or
17
+ # ApplicationRecord.descendants on Rails >= 5.0.0
23
18
  def classes_to_include
24
19
  return @classes_to_include if defined? @classes_to_include
25
20
 
@@ -31,26 +26,88 @@ module RailsReadonlyInjector
31
26
  ApplicationRecord.descendants
32
27
  end
33
28
  end
34
- end
35
- private_constant :Configuration
36
29
 
37
- # Sets the specified configuration options, if a block is provided
38
- # @return [Configuration] the current configuration object.
39
- def self.config
40
- yield self.configuration if block_given?
30
+ #######################
31
+ # Setter Methods #
32
+ #######################
41
33
 
42
- self.configuration
43
- end
34
+ # @param new_value [Boolean] Whether the site should be in read-only mode
35
+ def read_only=(new_value)
36
+ update_instance_variable('@read_only', new_value)
37
+ end
44
38
 
45
- def self.reset_configuration!
46
- @config = Configuration.new
39
+ # @param action [Lambda, Proc] The action to execute when rescuing from
40
+ # `ActiveRecord::RecordReadOnly` errors, within a controller
41
+ def controller_rescue_action=(action)
42
+ raise 'A lambda or proc must be specified' unless action.respond_to? :call
47
43
 
48
- self.reload!
44
+ update_instance_variable('@controller_rescue_action', action)
45
+ end
46
+
47
+ # @param klasses [Array<Class>] The classes to exclude from being marked as read-only
48
+ def classes_to_exclude=(klasses)
49
+ update_instance_variable('@classes_to_exclude', klasses)
50
+ end
51
+
52
+ # @param klasses [Array<Class>] The classes to mark as read-only
53
+ def classes_to_include=(klasses)
54
+ update_instance_variable('@classes_to_include', klasses)
55
+ end
56
+
57
+ #####################
58
+ # Instance methods #
59
+ #####################
60
+
61
+ # @return [Boolean] Whether the configuration
62
+ # has changed since the config was last reloaded
63
+ def dirty?
64
+ !changed_attributes.empty?
65
+ end
66
+
67
+ # @return [Hash] A hash of changed attributes
68
+ # and their previous values
69
+ def changed_attributes
70
+ @changed_attributes
71
+ end
72
+
73
+ private
74
+
75
+ # Updates the value of the specified instance variable
76
+ # and tracks the attribute's previous value (for `#dirty?`)
77
+ def update_instance_variable(variable_name, new_value)
78
+ old_value = instance_variable_get(variable_name).freeze
79
+
80
+ instance_variable_set(variable_name.to_sym, new_value)
81
+
82
+ unless old_value == new_value
83
+ changed_attributes[variable_name.to_s.gsub('@', '').to_sym] = old_value
84
+ end
85
+ end
86
+
87
+ # Resets the changed attributes hash,
88
+ # so that `#dirty?` returns false
89
+ def reset_dirty_status!
90
+ @changed_attributes = Hash.new
91
+ end
92
+
93
+ def read_only
94
+ @read_only
95
+ end
49
96
  end
97
+ private_constant :Configuration
50
98
 
51
99
  private
52
100
 
101
+ # @return [Configuration] The current configuration object
53
102
  def self.configuration
54
103
  @config ||= Configuration.new
55
104
  end
105
+
106
+ # Resets the current configuration to the defaults
107
+ # and reloads RailsReadonlyInjector
108
+ def self.reset_configuration!
109
+ @config = Configuration.new
110
+
111
+ self.reload!
112
+ end
56
113
  end
@@ -1,3 +1,3 @@
1
1
  module RailsReadonlyInjector
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "bundler", "~> 1.16"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  spec.add_development_dependency 'appraisal', '~> 2.2'
30
+ spec.add_development_dependency 'yard', '~> 0.9.12'
30
31
  end
@@ -0,0 +1,163 @@
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
+
32
+ describe '#classes_to_include' do
33
+ context 'when not defined' do
34
+ context 'when using Rails < 5.0' do
35
+ before do
36
+ stub_const('Rails::VERSION::STRING', '4.1.0')
37
+ end
38
+
39
+ it 'returns the descendants of ActiveRecord::Base' do
40
+ expect(ActiveRecord::Base).to receive(:descendants)
41
+
42
+ RailsReadonlyInjector.config.classes_to_include
43
+ end
44
+
45
+ end
46
+
47
+ context 'when using Rails >= 5.0' do
48
+ before do
49
+ stub_const('Rails::VERSION::STRING', '5.0.0')
50
+
51
+ unless defined? ApplicationRecord
52
+ class ApplicationRecord
53
+ def descendants
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ it 'returns the descendants of ActiveRecord::Base' do
60
+ expect(ApplicationRecord).to receive(:descendants)
61
+
62
+ RailsReadonlyInjector.config.classes_to_include
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#changed_attributes' do
70
+ setup do
71
+ RailsReadonlyInjector.reset_configuration!
72
+
73
+ RailsReadonlyInjector.config.read_only = false
74
+ end
75
+
76
+ context 'when one attribute is changed' do
77
+ before(:each) do
78
+ RailsReadonlyInjector.config.read_only = true
79
+ end
80
+
81
+ context 'and `reload!` is not called' do
82
+ subject { RailsReadonlyInjector.config.changed_attributes }
83
+
84
+ it 'returns a hash with the attribute and its old value' do
85
+ expect(subject).to eq({ read_only: false })
86
+ end
87
+ end
88
+
89
+ context 'and `reload!` is called' do
90
+ before { RailsReadonlyInjector.reload! }
91
+ subject { RailsReadonlyInjector.config.changed_attributes }
92
+
93
+ it 'returns an empty hash' do
94
+ expect(subject).to eq({})
95
+ end
96
+ end
97
+ end
98
+
99
+ context 'when more than one attribute is changed' do
100
+ setup { class TestClassA < ActiveRecord::Base; end; }
101
+
102
+ before(:each) do
103
+ RailsReadonlyInjector.config do |c|
104
+ c.read_only = true
105
+ c.classes_to_include = [TestClassA]
106
+ c.classes_to_exclude = [User]
107
+ end
108
+ end
109
+
110
+ context 'and `reload!` is not called' do
111
+ subject { RailsReadonlyInjector.config.changed_attributes }
112
+
113
+ it 'returns a hash with the attribute and its old value' do
114
+ expect(subject).to eq({
115
+ read_only: false,
116
+ classes_to_include: nil, # We expect this to be nil, as the `getter` method _returns_ (but does not assign) dynamic descendants of ActiveRecord::Base/ApplicationRecord, if undefined
117
+ classes_to_exclude: []
118
+ })
119
+ end
120
+ end
121
+
122
+ context 'and `reload!` is called' do
123
+ before { RailsReadonlyInjector.reload! }
124
+ subject { RailsReadonlyInjector.config.changed_attributes }
125
+
126
+ it 'returns an empty hash' do
127
+ expect(subject).to eq({})
128
+ end
129
+ end
130
+ end
131
+
132
+ context 'when an attribute is not changed' do
133
+ subject { RailsReadonlyInjector.config.changed_attributes }
134
+
135
+ it { is_expected.to eq({}) }
136
+ end
137
+ end
138
+
139
+
140
+ describe '#dirty?' do
141
+ setup do
142
+ RailsReadonlyInjector.config { |config| config.read_only = false }
143
+ RailsReadonlyInjector.reload!
144
+ end
145
+
146
+ context 'when `read_only` is changed' do
147
+ before(:each) { RailsReadonlyInjector.config.read_only = true }
148
+
149
+ context 'and `reload!` is not called' do
150
+ subject { RailsReadonlyInjector.config.dirty? }
151
+
152
+ it { is_expected.to eq(true) }
153
+ end
154
+
155
+ context 'and `reload!` is called' do
156
+ before { RailsReadonlyInjector.reload! }
157
+ subject { RailsReadonlyInjector.config.dirty? }
158
+
159
+ it { is_expected.to eq(false) }
160
+ end
161
+ end
162
+ end
163
+ end
@@ -13,7 +13,7 @@ RSpec.describe RailsReadonlyInjector do
13
13
  subject { RailsReadonlyInjector.config }
14
14
 
15
15
  it 'sets `read_only` to false' do
16
- expect(RailsReadonlyInjector.config.read_only).to eq(false)
16
+ expect(RailsReadonlyInjector.config.send(:read_only)).to eq(false)
17
17
  end
18
18
  end
19
19
 
@@ -56,4 +56,42 @@ RSpec.describe RailsReadonlyInjector do
56
56
  it { is_expected.to eq(false) }
57
57
  end
58
58
  end
59
+
60
+ describe '#in_read_only_mode?' do
61
+ setup do
62
+ RailsReadonlyInjector.config.read_only = false
63
+ RailsReadonlyInjector.reload!
64
+ end
65
+
66
+ context 'when `reload!` is called' do
67
+ before do
68
+ RailsReadonlyInjector.config.read_only = true
69
+ RailsReadonlyInjector.reload!
70
+ end
71
+
72
+ it 'returns the correct value' do
73
+ expect(RailsReadonlyInjector.in_read_only_mode?).to eq(true)
74
+ end
75
+ end
76
+
77
+ context 'when `reload!` is not called' do
78
+ context 'when `config.read_only` is changed' do
79
+ before do
80
+ RailsReadonlyInjector.config.read_only = true
81
+ end
82
+
83
+ it 'returns the previous value' do
84
+ expect(RailsReadonlyInjector.in_read_only_mode?).to eq(false)
85
+ end
86
+ end
87
+
88
+ context 'when `config.read_only` is not changed' do
89
+ before { RailsReadonlyInjector.config.classes_to_exclude = [User] }
90
+
91
+ it 'returns the current value' do
92
+ expect(RailsReadonlyInjector.in_read_only_mode?).to eq(RailsReadonlyInjector.config.send(:read_only))
93
+ end
94
+ end
95
+ end
96
+ end
59
97
  end
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: 0.3.0
4
+ version: 1.0.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: 2018-03-18 00:00:00.000000000 Z
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: yard
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.9.12
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.9.12
75
89
  description:
76
90
  email:
77
91
  - andrew.walter@burnet.edu.au
@@ -79,6 +93,8 @@ 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"
83
99
  - ".travis.yml"
84
100
  - Appraisals
@@ -113,8 +129,8 @@ files:
113
129
  - lib/rails_readonly_injector/version.rb
114
130
  - rails_readonly_injector.gemspec
115
131
  - rspec_specs/.gitkeep
116
- - rspec_specs/readonly_site_toggle/configuration_spec.rb
117
- - rspec_specs/readonly_site_toggle_spec.rb
132
+ - rspec_specs/rails_readonly_injector/configuration_spec.rb
133
+ - rspec_specs/rails_readonly_injector_spec.rb
118
134
  - rspec_specs/support/.gitkeep
119
135
  homepage: https://www.github.com/xtrasimplicity/rails_readonly_injector
120
136
  licenses:
@@ -1,66 +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
-
32
- describe '#classes_to_include' do
33
- context 'when not defined' do
34
- context 'when using Rails < 5.0' do
35
- before { stub_const('Rails::VERSION::STRING', '4.1.0') }
36
-
37
- it 'returns the descendants of ActiveRecord::Base' do
38
- expect(ActiveRecord::Base).to receive(:descendants)
39
-
40
- RailsReadonlyInjector.config.classes_to_include
41
- end
42
-
43
- end
44
-
45
- context 'when using Rails >= 5.0' do
46
- before do
47
- stub_const('Rails::VERSION::STRING', '5.0.0')
48
-
49
- unless defined? ApplicationRecord
50
- class ApplicationRecord
51
- def descendants
52
- end
53
- end
54
- end
55
- end
56
-
57
- it 'returns the descendants of ActiveRecord::Base' do
58
- expect(ApplicationRecord).to receive(:descendants)
59
-
60
- RailsReadonlyInjector.config.classes_to_include
61
- end
62
-
63
- end
64
- end
65
- end
66
- end