rails_readonly_injector 0.1.1 → 0.2.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: 0c17f3a71ff8c4089bfc183fd0b661a50f0b3d60
4
- data.tar.gz: eda68bb545c0cfe97dfc2c15227cd271a15f41ae
3
+ metadata.gz: 9509703bc12b066f6af792e478484e61bb0a0249
4
+ data.tar.gz: 21225186b776c134d52ec75b95ce3483fd70c21f
5
5
  SHA512:
6
- metadata.gz: 55e15401c1aef32c37f4e7ad5b921a2ef7fc81554e421f948b598b778cc647f588cf76d901854bde6bdcde209cca70f76b0d8b8baed9c9c109d551193d14f58a
7
- data.tar.gz: fd618f6e50007598655d667e9dcda0412ae5e9582c9b0e0a94437171f0d98c5106381f36c19811c97c34ae4bc0ca224cc420fc21fd0399f121bd23394550e01d
6
+ metadata.gz: e5aa0948322922fd1940fb817fe4ac52bdcbf3fdc2ff3f1630835e7cd80f4fd4f0bb990812f974b447c2364379f008c5bb951fbf643fd8feb82b5a8fb949c25b
7
+ data.tar.gz: 2d7734d7370b5eda65ceababacd75302013dddfd4c26ba2e95fcc4126e75db3c00310198d92a9e9d5d2b9790846f544422a8f67c4f03a4489431886108ec5bb6
data/.gitignore CHANGED
@@ -7,4 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  gemfiles/*.gemfile.lock
10
- .byebug_history
10
+ .byebug_history
11
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -28,6 +28,7 @@ gemfile:
28
28
  - gemfiles/rails_4_1.gemfile
29
29
  - gemfiles/rails_4_2.gemfile
30
30
  - gemfiles/rails_5_0.gemfile
31
+ - gemfiles/rails_5_1.gemfile
31
32
 
32
33
  matrix:
33
34
  fast_finish: true
@@ -38,6 +39,8 @@ matrix:
38
39
  gemfile: gemfiles/rails_4_2.gemfile
39
40
  - rvm: 2.1.3
40
41
  gemfile: gemfiles/rails_5_0.gemfile
42
+ - rvm: 2.1.3
43
+ gemfile: gemfiles/rails_5_1.gemfile
41
44
  - rvm: 2.2.7
42
45
  gemfile: gemfiles/rails_3.gemfile
43
46
  - rvm: 2.3.6
data/Appraisals CHANGED
@@ -12,6 +12,7 @@ appraise 'rails_4_0' do
12
12
  gem 'rspec-rails', '~> 3.7.2', group: :test
13
13
  gem 'database_cleaner', '~> 1.0.1'
14
14
  gem 'sqlite3', '~> 1.3.13'
15
+ gem 'xpath', '~> 2.1.0'
15
16
  end
16
17
 
17
18
  appraise 'rails_4_1' do
@@ -35,4 +36,11 @@ appraise 'rails_5_0' do
35
36
  gem 'cucumber-rails', '~> 1.5.0', group: :test, require: false
36
37
  gem 'rspec-rails', '~> 3.7.2', group: :test
37
38
  gem 'database_cleaner', '~> 1.0.1'
39
+ end
40
+
41
+ appraise 'rails_5_1' do
42
+ gem 'rails', '~> 5.1.0'
43
+ gem 'cucumber-rails', '~> 1.5.0', group: :test, require: false
44
+ gem 'rspec-rails', '~> 3.7.2', group: :test
45
+ gem 'database_cleaner', '~> 1.0.1'
38
46
  end
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.2.0
2
+ - Added ability to exclude specific classes from read-only mode.
3
+ - Improved support for Rails 5 (Automatic inclusion of descendants of `ApplicationRecord` rather than `ActiveRecord::Base`).
4
+ ## 0.1.1
5
+ - Initial release
data/Gemfile.lock CHANGED
@@ -1,23 +1,114 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_readonly_injector (0.1.0)
4
+ rails_readonly_injector (0.1.2)
5
+ rails (>= 3.0, < 5.2)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ actionmailer (4.2.10)
11
+ actionpack (= 4.2.10)
12
+ actionview (= 4.2.10)
13
+ activejob (= 4.2.10)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.10)
17
+ actionview (= 4.2.10)
18
+ activesupport (= 4.2.10)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.10)
24
+ activesupport (= 4.2.10)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
29
+ activejob (4.2.10)
30
+ activesupport (= 4.2.10)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.10)
33
+ activesupport (= 4.2.10)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.10)
36
+ activemodel (= 4.2.10)
37
+ activesupport (= 4.2.10)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.10)
40
+ i18n (~> 0.7)
41
+ minitest (~> 5.1)
42
+ thread_safe (~> 0.3, >= 0.3.4)
43
+ tzinfo (~> 1.1)
9
44
  appraisal (2.2.0)
10
45
  bundler
11
46
  rake
12
47
  thor (>= 0.14.0)
48
+ arel (6.0.4)
49
+ builder (3.2.3)
50
+ concurrent-ruby (1.0.5)
51
+ crass (1.0.3)
52
+ erubis (2.7.0)
53
+ globalid (0.4.1)
54
+ activesupport (>= 4.2.0)
55
+ i18n (0.9.5)
56
+ concurrent-ruby (~> 1.0)
57
+ loofah (2.1.1)
58
+ crass (~> 1.0.2)
59
+ nokogiri (>= 1.5.9)
60
+ mail (2.7.0)
61
+ mini_mime (>= 0.1.1)
62
+ mini_mime (1.0.0)
63
+ mini_portile2 (2.3.0)
64
+ minitest (5.11.3)
65
+ nokogiri (1.8.2)
66
+ mini_portile2 (~> 2.3.0)
67
+ rack (1.6.8)
68
+ rack-test (0.6.3)
69
+ rack (>= 1.0)
70
+ rails (4.2.10)
71
+ actionmailer (= 4.2.10)
72
+ actionpack (= 4.2.10)
73
+ actionview (= 4.2.10)
74
+ activejob (= 4.2.10)
75
+ activemodel (= 4.2.10)
76
+ activerecord (= 4.2.10)
77
+ activesupport (= 4.2.10)
78
+ bundler (>= 1.3.0, < 2.0)
79
+ railties (= 4.2.10)
80
+ sprockets-rails
81
+ rails-deprecated_sanitizer (1.0.3)
82
+ activesupport (>= 4.2.0.alpha)
83
+ rails-dom-testing (1.0.9)
84
+ activesupport (>= 4.2.0, < 5.0)
85
+ nokogiri (~> 1.6)
86
+ rails-deprecated_sanitizer (>= 1.0.1)
87
+ rails-html-sanitizer (1.0.3)
88
+ loofah (~> 2.0)
89
+ railties (4.2.10)
90
+ actionpack (= 4.2.10)
91
+ activesupport (= 4.2.10)
92
+ rake (>= 0.8.7)
93
+ thor (>= 0.18.1, < 2.0)
13
94
  rake (10.5.0)
95
+ sprockets (3.7.1)
96
+ concurrent-ruby (~> 1.0)
97
+ rack (> 1, < 3)
98
+ sprockets-rails (3.2.1)
99
+ actionpack (>= 4.0)
100
+ activesupport (>= 4.0)
101
+ sprockets (>= 3.0.0)
14
102
  thor (0.20.0)
103
+ thread_safe (0.3.6)
104
+ tzinfo (1.2.5)
105
+ thread_safe (~> 0.1)
15
106
 
16
107
  PLATFORMS
17
108
  ruby
18
109
 
19
110
  DEPENDENCIES
20
- appraisal (~> 2.2.0)
111
+ appraisal (~> 2.2)
21
112
  bundler (~> 1.16)
22
113
  rails_readonly_injector!
23
114
  rake (~> 10.0)
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Build Status](https://travis-ci.org/xtrasimplicity/rails_readonly_injector.svg?branch=master)](https://travis-ci.org/xtrasimplicity/rails_readonly_injector)
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/427c153efd48ae03f688/maintainability)](https://codeclimate.com/github/xtrasimplicity/rails_readonly_injector/maintainability)
4
4
  [![Test Coverage](https://api.codeclimate.com/v1/badges/427c153efd48ae03f688/test_coverage)](https://codeclimate.com/github/xtrasimplicity/rails_readonly_injector/test_coverage)
5
+ [![Gem Version](https://badge.fury.io/rb/rails_readonly_injector.svg)](https://badge.fury.io/rb/rails_readonly_injector)
5
6
 
6
7
  Easily switch a Rails site into 'read-only' mode, and back again, without restarting the server.
7
8
 
@@ -44,6 +45,10 @@ When you want to switch a site into read-only mode, you can then simply set `Rai
44
45
 
45
46
  If you want to reset the configuration to the defaults, you can simply call `RailsReadonlyInjector.reset_configuration!` from anywhere in your application.
46
47
 
48
+ ## Configuration Options
49
+ - `read_only` => Whether the site should be in read-only mode. (Default: false)
50
+ - `exclude_classes` => An array of classes that should be exempt from read-only mode.
51
+ - `controller_rescue_action` => A lambda expression/Proc to execute when an `ActiveRecord::ReadOnlyRecord` error is raised, from within a controller.
47
52
  ## Development
48
53
 
49
54
  After checking out the repo, run `bundle install` to install the dependencies.
@@ -16,14 +16,4 @@ Feature: Configuration
16
16
 
17
17
  RailsReadonlyInjector.reload!
18
18
  """
19
- Then I should be able to create a user without any errors
20
-
21
-
22
- #Feature: Configuration
23
- # Scenario: When `allowed_models` is set
24
- # Given I configure RailsReadonlyInjector with:
25
- # """
26
- # RailsReadonlyInjector.config do |config|
27
- # config.allowed_models = ['User']
28
- # """
29
- # When
19
+ Then I should be able to create a user without any errors
@@ -40,8 +40,6 @@ 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
-
45
43
  expect(@user.persisted?).to eq(true)
46
44
  end
47
45
 
@@ -6,7 +6,11 @@ Feature: User Controller - When in read only mode
6
6
  RailsReadonlyInjector.config do |config|
7
7
  config.read_only = true
8
8
  config.controller_rescue_action = lambda do |context|
9
- render :text => 'The site is currently in read-only mode'
9
+ if Rails::VERSION::STRING < '4.1.0'
10
+ render :text => 'The site is currently in read-only mode'
11
+ else
12
+ render :plain => 'The site is currently in read-only mode'
13
+ end
10
14
  end
11
15
  end
12
16
 
@@ -23,7 +27,11 @@ Feature: User Controller - When in read only mode
23
27
  RailsReadonlyInjector.config do |config|
24
28
  config.read_only = true
25
29
  config.controller_rescue_action = lambda do |context|
26
- render :text => 'The site is currently in read-only mode'
30
+ if Rails::VERSION::STRING < '4.1.0'
31
+ render :text => 'The site is currently in read-only mode'
32
+ else
33
+ render :plain => 'The site is currently in read-only mode'
34
+ end
27
35
  end
28
36
  end
29
37
 
@@ -23,4 +23,18 @@ Feature: User model - When in read-only mode
23
23
  RailsReadonlyInjector.reload!
24
24
  """
25
25
  When I save the user
26
- Then the user should not be saved
26
+ Then the user should not be saved
27
+
28
+ Scenario: An attempt to create an instance of a model exempt from read-only mode has been made
29
+ Given There is a user that has not been persisted to the database
30
+ Given I execute:
31
+ """
32
+ RailsReadonlyInjector.config do |config|
33
+ config.read_only = true
34
+ config.classes_to_exclude = [User]
35
+ end
36
+
37
+ RailsReadonlyInjector.reload!
38
+ """
39
+ When I save the user
40
+ Then the user should be saved
@@ -36,9 +36,12 @@ namespace :dev do
36
36
  ENV.delete('RUBYOPT')
37
37
 
38
38
  # Install gems
39
- system("bundle install")
39
+ system("bundle install --binstubs")
40
40
 
41
+ puts "Installing Cucumber..."
41
42
  system("bundle exec rails generate cucumber:install")
43
+
44
+ puts "Installing RSpec..."
42
45
  system("bundle exec rails generate rspec:install")
43
46
 
44
47
  # RSpec: Include all files in support/
@@ -71,8 +74,8 @@ namespace :dev do
71
74
  FileUtils.cp_r File.join(GEM_ROOT_PATH, 'cucumber_features', '.'), 'features'
72
75
  FileUtils.cp_r File.join(GEM_ROOT_PATH, 'rspec_specs', '.'), 'spec'
73
76
 
74
- system('bundle exec cucumber')
75
- system('bundle exec rspec')
77
+ exit_code = system('bundle exec cucumber && bundle exec rspec')
78
+ exit exit_code
76
79
  end
77
80
 
78
81
  def parse_gemfile(file_path)
@@ -7,5 +7,6 @@ gem "cucumber-rails", "~> 1.5.0", group: :test, require: false
7
7
  gem "rspec-rails", "~> 3.7.2", group: :test
8
8
  gem "database_cleaner", "~> 1.0.1"
9
9
  gem "sqlite3", "~> 1.3.13"
10
+ gem "xpath", "~> 2.1.0"
10
11
 
11
12
  gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.0"
6
+ gem "cucumber-rails", "~> 1.5.0", group: :test, require: false
7
+ gem "rspec-rails", "~> 3.7.2", group: :test
8
+ gem "database_cleaner", "~> 1.0.1"
9
+
10
+ gemspec path: "../"
@@ -3,14 +3,23 @@ require "rails_readonly_injector/configuration"
3
3
 
4
4
  module RailsReadonlyInjector
5
5
  def self.reload!
6
- descendants = ActiveRecord::Base.descendants
7
6
 
8
- if descendants.empty?
9
- Rails.application.eager_load!
7
+ Rails.application.eager_load!
8
+
9
+ if Rails::VERSION::STRING < '5.0.0'
10
10
  descendants = ActiveRecord::Base.descendants
11
+ else
12
+ descendants = ApplicationRecord.descendants
11
13
  end
12
14
 
13
15
  descendants.each do |descendant_class|
16
+
17
+ # Ensure excluded classes aren't set to read-only
18
+ if config.classes_to_exclude.include? descendant_class
19
+ restore_readonly_method(descendant_class)
20
+ next
21
+ end
22
+
14
23
  if self.config.read_only
15
24
  override_readonly_method(descendant_class)
16
25
  else
@@ -1,6 +1,6 @@
1
1
  module RailsReadonlyInjector
2
2
  class Configuration
3
- attr_writer :read_only
3
+ attr_writer :read_only, :classes_to_exclude
4
4
 
5
5
  def read_only
6
6
  @read_only || false
@@ -15,6 +15,10 @@ module RailsReadonlyInjector
15
15
  def controller_rescue_action
16
16
  @controller_rescue_action || Proc.new {}
17
17
  end
18
+
19
+ def classes_to_exclude
20
+ @classes_to_exclude || []
21
+ end
18
22
  end
19
23
  private_constant :Configuration
20
24
 
@@ -1,3 +1,3 @@
1
1
  module RailsReadonlyInjector
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["andrew.walter@burnet.edu.au"]
11
11
 
12
12
  spec.summary = "Globally toggle 'read-only' mode in a Rails application, on-demand, without having to restart the server."
13
- spec.homepage = "https://www.github.com"
13
+ spec.homepage = "https://www.github.com/xtrasimplicity/rails_readonly_injector"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.required_ruby_version = ">= 2.1.3"
24
24
 
25
- spec.add_runtime_dependency "rails", ">= 3.0"
25
+ spec.add_runtime_dependency "rails", [">= 3.0", "< 5.2"]
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.16"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency 'appraisal', '~> 2.2.0'
29
+ spec.add_development_dependency 'appraisal', '~> 2.2'
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_readonly_injector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Walter
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +64,14 @@ dependencies:
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: 2.2.0
67
+ version: '2.2'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: 2.2.0
74
+ version: '2.2'
69
75
  description:
70
76
  email:
71
77
  - andrew.walter@burnet.edu.au
@@ -76,6 +82,7 @@ files:
76
82
  - ".gitignore"
77
83
  - ".travis.yml"
78
84
  - Appraisals
85
+ - CHANGELOG.md
79
86
  - CODE_OF_CONDUCT.md
80
87
  - Gemfile
81
88
  - Gemfile.lock
@@ -100,6 +107,7 @@ files:
100
107
  - gemfiles/rails_4_1.gemfile
101
108
  - gemfiles/rails_4_2.gemfile
102
109
  - gemfiles/rails_5_0.gemfile
110
+ - gemfiles/rails_5_1.gemfile
103
111
  - lib/rails_readonly_injector.rb
104
112
  - lib/rails_readonly_injector/configuration.rb
105
113
  - lib/rails_readonly_injector/version.rb
@@ -108,7 +116,7 @@ files:
108
116
  - rspec_specs/readonly_site_toggle/configuration_spec.rb
109
117
  - rspec_specs/readonly_site_toggle_spec.rb
110
118
  - rspec_specs/support/.gitkeep
111
- homepage: https://www.github.com
119
+ homepage: https://www.github.com/xtrasimplicity/rails_readonly_injector
112
120
  licenses:
113
121
  - MIT
114
122
  metadata: {}