rails_ops 1.0.0.beta6 → 1.0.0.beta7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +4 -0
- data/Rakefile +5 -6
- data/VERSION +1 -1
- data/lib/rails_ops/hookup.rb +9 -1
- data/lib/rails_ops/log_subscriber.rb +3 -6
- data/lib/rails_ops/model_mixins/virtual_has_one.rb +1 -5
- data/lib/rails_ops/model_mixins.rb +0 -1
- data/lib/rails_ops/operation/model.rb +1 -1
- data/lib/rails_ops/operation.rb +2 -2
- data/lib/rails_ops.rb +0 -3
- data/rails_ops.gemspec +11 -20
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/cable.js +13 -0
- data/test/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/group.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +37 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config/application.rb +17 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/database.yml +14 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +91 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/rails_ops.rb +4 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/db/schema.rb +9 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/package.json +5 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/.keep +0 -0
- data/test/test_helper.rb +44 -10
- data/test/unit/rails_ops/operation/model/create_test.rb +52 -0
- data/test/unit/rails_ops/operation/model/load_test.rb +54 -0
- data/test/unit/rails_ops/operation/model/update_test.rb +22 -0
- data/test/unit/rails_ops/operation/model_test.rb +67 -0
- data/test/unit/rails_ops/operation_test.rb +145 -0
- metadata +134 -49
- data/lib/rails_ops/model_mixins/protected_attributes.rb +0 -78
- data/test/rails_ops/operation/example_test.rb +0 -14
@@ -1,78 +0,0 @@
|
|
1
|
-
# This mixin can be used with any Activemodel Model to allow mass assignment
|
2
|
-
# security. This is a simpler implementation of Rails' former mass assignment
|
3
|
-
# security functionality.
|
4
|
-
#
|
5
|
-
# Attribute protection is disabled per default. It can be enabled by either
|
6
|
-
# calling `attr_protection true` or one of `attr_accessible` and
|
7
|
-
# `attr_protected`.
|
8
|
-
module RailsOps::ModelMixins::ProtectedAttributes
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
included do
|
12
|
-
class_attribute :accessible_attributes
|
13
|
-
self.accessible_attributes = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
# TODO: Document.
|
17
|
-
def assign_attributes_with_protection(attributes)
|
18
|
-
self.class._verify_protected_attributes!(attributes.dup)
|
19
|
-
assign_attributes(attributes)
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
# Returns whether attribute protection is enabled for this model.
|
24
|
-
def attr_protection?
|
25
|
-
!accessible_attributes.nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
# Performs attribute protection verification (if enabled, see
|
29
|
-
# {attr_protection?}). If forbidden attributes are found, an
|
30
|
-
# {ActiveModel::ForbiddenAttributesError} exception is thrown.
|
31
|
-
def _verify_protected_attributes!(attributes) # :nodoc:
|
32
|
-
return unless attr_protection?
|
33
|
-
|
34
|
-
received_keys = attributes.keys.map(&:to_sym).to_set
|
35
|
-
|
36
|
-
disallowed_attributes = received_keys - accessible_attributes
|
37
|
-
|
38
|
-
if disallowed_attributes.any?
|
39
|
-
fail ActiveModel::ForbiddenAttributesError,
|
40
|
-
"The following attributes are forbidden to be assigned to #{model_name}: " \
|
41
|
-
"#{disallowed_attributes.to_a}, allowed are: #{accessible_attributes.to_a}."
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Specifically turn on or off attribute protection for this model (and
|
46
|
-
# models inheriting from it without overriding this setting).
|
47
|
-
#
|
48
|
-
# Note that attribute protection is turned on automatically when calling
|
49
|
-
# {attr_accessible} or {attr_protected}.
|
50
|
-
#
|
51
|
-
# If you're using this method to turn protection off, the list of accessible
|
52
|
-
# attributes is wiped. So if you re-enable it, no attributes will be
|
53
|
-
# accessible.
|
54
|
-
def attr_protection(enable)
|
55
|
-
if !enable
|
56
|
-
self.accessible_attributes = nil
|
57
|
-
elsif accessible_attributes.nil?
|
58
|
-
self.accessible_attributes = Set.new
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Specifies the given attribute(s) as accessible. This automatically turns
|
63
|
-
# on attribute protection for this model. This configuration is inherited to
|
64
|
-
# model inheriting from it.
|
65
|
-
def attr_accessible(*attributes)
|
66
|
-
attr_protection true
|
67
|
-
self.accessible_attributes += attributes.map(&:to_sym)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Specifies the given attribute(s) as protected. This automatically turns on
|
71
|
-
# attribute protection for this model. This configuration is inherited
|
72
|
-
# to models inheriting from it.
|
73
|
-
def attr_protected(*attributes)
|
74
|
-
attr_protection true
|
75
|
-
self.accessible_attributes -= attributes.map(&:to_sym)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RailsOps::Operation::ExampleTest < Minitest::Test
|
4
|
-
include TestHelper
|
5
|
-
|
6
|
-
def setup
|
7
|
-
self.class.setup_db
|
8
|
-
self.class.setup_base_data
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_group_create
|
12
|
-
Group.create name: 'Test', color: 'blue'
|
13
|
-
end
|
14
|
-
end
|