validation_errors 0.2.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fed7190ae44232b3441ccaa634450ceefa80ac74dd5615c6b0b58147fc3990d
4
- data.tar.gz: 3fc056004f5e810c75489c009df26d2bd42f3804d163b3c2bcd2ab85665a50e4
3
+ metadata.gz: 83e3819827bf1a4c43f5cc7f460ebaf26c51e0661c438d896e0d434cf705d038
4
+ data.tar.gz: 83fda6815b49bd7bb28b70b717379ce6e421d26b558a05df1ddfcf1efd06b260
5
5
  SHA512:
6
- metadata.gz: f2fd1b962e6f1dca4fa2cdb6dc672bc45823d1e79e20a1ccbe44f5dc562207e7871c1f5637acfb8698af7c54caad3be70de5b80f44d5bdab501d76825522d11c
7
- data.tar.gz: 15191622d27d105d9872cd266b9610e6c8e6db98c650aefb0efcd0ef9d833ec1f6ebe00fc7ef101443abac6c959bd099dcc6cc426a0434505bb3653ce6f53d02
6
+ metadata.gz: ef287bf9b54ad6d38725df355b54cfa8671f6d4416064eaaca13837f31b95aef9066ebb1b0aa21496f9f6c5eec28ef7a7a742d2d4bf1022db1e89798ff3620c9
7
+ data.tar.gz: '08680fc49f5d4c2b56b7d37a4ee188022208e5032f8d785517dfdd8711b0debb35d1b7be6277da31c9d52b0508ecf89ef5a52087648407cc99055a7ae86e0f93'
data/CHANGELOG.md CHANGED
@@ -1,11 +1,16 @@
1
- ## Unreleased
1
+ ## [0.3.1] - 2025-08-12
2
2
 
3
- - ...
3
+ - Documentation changes and some more tests to specify how to track errors on nested associations.
4
+
5
+ ## [0.3.0] - 2024-11-05
6
+
7
+ - Fix persistance in case of rolled back transactions.
8
+ - Filter `Rails.application.config.filter_parameters` by default. Does not support procs.
4
9
 
5
10
  ## [0.2.0] - 2022-12-29
6
11
 
7
- - Allow to use a custom action name when tracking errors
12
+ - Allow to use a custom action name when tracking errors.
8
13
 
9
14
  ## [0.1.0] - 2022-09-19
10
15
 
11
- - Initial release
16
+ - Initial release.
data/Gemfile.lock CHANGED
@@ -1,68 +1,106 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validation_errors (0.2.0)
4
+ validation_errors (0.3.1)
5
5
  activerecord (>= 4.1.0)
6
6
  zeitwerk (>= 2.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (7.0.4)
12
- activesupport (= 7.0.4)
13
- activerecord (7.0.4)
14
- activemodel (= 7.0.4)
15
- activesupport (= 7.0.4)
16
- activesupport (7.0.4)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ activemodel (7.2.2.1)
12
+ activesupport (= 7.2.2.1)
13
+ activerecord (7.2.2.1)
14
+ activemodel (= 7.2.2.1)
15
+ activesupport (= 7.2.2.1)
16
+ timeout (>= 0.4.0)
17
+ activesupport (7.2.2.1)
18
+ base64
19
+ benchmark (>= 0.3)
20
+ bigdecimal
21
+ concurrent-ruby (~> 1.0, >= 1.3.1)
22
+ connection_pool (>= 2.2.5)
23
+ drb
18
24
  i18n (>= 1.6, < 2)
25
+ logger (>= 1.4.2)
19
26
  minitest (>= 5.1)
20
- tzinfo (~> 2.0)
21
- ast (2.4.2)
22
- concurrent-ruby (1.1.10)
23
- i18n (1.12.0)
27
+ securerandom (>= 0.3)
28
+ tzinfo (~> 2.0, >= 2.0.5)
29
+ ast (2.4.3)
30
+ base64 (0.1.2)
31
+ benchmark (0.4.1)
32
+ bigdecimal (3.2.2)
33
+ concurrent-ruby (1.3.5)
34
+ connection_pool (2.5.3)
35
+ drb (2.2.3)
36
+ i18n (1.14.7)
24
37
  concurrent-ruby (~> 1.0)
25
- minitest (5.16.3)
26
- parallel (1.22.1)
27
- parser (3.1.2.1)
38
+ json (2.13.2)
39
+ language_server-protocol (3.17.0.5)
40
+ lint_roller (1.1.0)
41
+ logger (1.7.0)
42
+ minitest (5.25.5)
43
+ parallel (1.27.0)
44
+ parser (3.3.9.0)
28
45
  ast (~> 2.4.1)
46
+ racc
47
+ prism (1.4.0)
48
+ racc (1.8.1)
29
49
  rainbow (3.1.1)
30
- rake (13.0.6)
31
- regexp_parser (2.5.0)
32
- rexml (3.2.5)
33
- rubocop (1.10.0)
50
+ rake (13.3.0)
51
+ regexp_parser (2.11.1)
52
+ rexml (3.4.1)
53
+ rubocop (1.56.4)
54
+ base64 (~> 0.1.1)
55
+ json (~> 2.3)
56
+ language_server-protocol (>= 3.17.0)
34
57
  parallel (~> 1.10)
35
- parser (>= 3.0.0.0)
58
+ parser (>= 3.2.2.3)
36
59
  rainbow (>= 2.2.2, < 4.0)
37
60
  regexp_parser (>= 1.8, < 3.0)
38
- rexml
39
- rubocop-ast (>= 1.2.0, < 2.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.28.1, < 2.0)
40
63
  ruby-progressbar (~> 1.7)
41
- unicode-display_width (>= 1.4.0, < 3.0)
42
- rubocop-ast (1.21.0)
43
- parser (>= 3.1.1.0)
44
- rubocop-performance (1.9.2)
45
- rubocop (>= 0.90.0, < 2.0)
46
- rubocop-ast (>= 0.4.0)
47
- ruby-progressbar (1.11.0)
48
- sqlite3 (1.5.0-arm64-darwin)
49
- standard (0.13.0)
50
- rubocop (= 1.10.0)
51
- rubocop-performance (= 1.9.2)
52
- tzinfo (2.0.5)
64
+ unicode-display_width (>= 2.4.0, < 3.0)
65
+ rubocop-ast (1.46.0)
66
+ parser (>= 3.3.7.2)
67
+ prism (~> 1.4)
68
+ rubocop-performance (1.23.1)
69
+ rubocop (>= 1.48.1, < 2.0)
70
+ rubocop-ast (>= 1.31.1, < 2.0)
71
+ ruby-progressbar (1.13.0)
72
+ securerandom (0.4.1)
73
+ sqlite3 (1.5.4-arm64-darwin)
74
+ sqlite3 (1.5.4-x86_64-linux)
75
+ standard (1.31.2)
76
+ language_server-protocol (~> 3.17.0.2)
77
+ lint_roller (~> 1.0)
78
+ rubocop (~> 1.56.4)
79
+ standard-custom (~> 1.0.0)
80
+ standard-performance (~> 1.2)
81
+ standard-custom (1.0.2)
82
+ lint_roller (~> 1.0)
83
+ rubocop (~> 1.50)
84
+ standard-performance (1.6.0)
85
+ lint_roller (~> 1.1)
86
+ rubocop-performance (~> 1.23.0)
87
+ timeout (0.4.3)
88
+ tzinfo (2.0.6)
53
89
  concurrent-ruby (~> 1.0)
54
- unicode-display_width (2.3.0)
55
- zeitwerk (2.6.6)
90
+ unicode-display_width (2.6.0)
91
+ zeitwerk (2.6.18)
56
92
 
57
93
  PLATFORMS
58
94
  arm64-darwin-21
95
+ arm64-darwin-24
96
+ x86_64-linux
59
97
 
60
98
  DEPENDENCIES
61
99
  minitest (~> 5.0)
62
100
  rake (~> 13.0)
63
101
  sqlite3 (~> 1.5.0)
64
- standard (~> 0.13.0)
102
+ standard (~> 1.31.0)
65
103
  validation_errors!
66
104
 
67
105
  BUNDLED WITH
68
- 2.3.21
106
+ 2.5.18
data/README.md CHANGED
@@ -4,7 +4,8 @@ _Because shit happens_
4
4
 
5
5
  This gem helps you keep track of the ActiveRecord validation errors that have been triggered on a model.
6
6
 
7
- It persists them on a `validation_errors` database table the following information:
7
+ It persists them on a `validation_errors` database table with:
8
+
8
9
  * time of the error
9
10
  * model name
10
11
  * model id (if available)
@@ -18,17 +19,17 @@ This gem has been extracted from various Ruby On Rails apps where I had this nee
18
19
 
19
20
  If you have a validation error, you want to keep track of it...but how?
20
21
  * You can use a logger, but then you have to parse the logs to get the information you need. i.e. is not structured.
21
- * You can use an error tracker, like Sentry, but this isn't really an error, is it? If you have many, it might pollute your errors tracker.
22
- * You can use a database table, and that's what this gem does.
22
+ * You can use an error tracker, like Sentry, but this isn't really an error, is it? If you have many, it might pollute your error tracker.
23
+ * You can use a database table! And that's exactly what this gem does.
23
24
 
24
25
  This gem will keep track of the errors, and give you all the freedom to query it and extract statistics and make analysis.
25
- By analysing from time to time these data, you might found out the following:
26
+ By analysing these data from time to time, you might found out the following:
26
27
  * Your UI sucks
27
28
  * Your validations are too strict
28
29
  * Your validations are too loose
29
30
  * Your client-side validations are not working
30
31
  * Your client-side validations are too loose
31
- * This bullet point list has been generated by copilot
32
+ * This bullet point list has been generated by AI
32
33
 
33
34
  ## Installation
34
35
 
@@ -100,6 +101,10 @@ class ApplicationRecord < ActiveRecord::Base
100
101
  end
101
102
  ```
102
103
 
104
+ ### Validate nested attributes
105
+
106
+ If you don't specify `accepts_nested_attributes_for` for nested attributes, only a generic `invalid` error will be tracked for associations.
107
+
103
108
  We currently don't support (PR welcome):
104
109
  * enable globally and disable on a specific model `skip_track_validation_errors`
105
110
  * enable only for specific actions `track_validation_errors only: [:create]`
@@ -184,6 +189,34 @@ group by 1, 2
184
189
  FlatValidationError.group(:invalid_model_name, :error_column).count
185
190
  ```
186
191
 
192
+ ## RailsAdmin integration
193
+
194
+ We provide here some code samples to integrate the models in [RailsAdmin](https://github.com/sferik/rails_admin).
195
+
196
+ This configuration will give you a basic configuration to work with the validation errors efficiently.
197
+ ```ruby
198
+ config.model "ValidationError" do
199
+ list do
200
+ include_fields :invalid_model_name, :invalid_model_id, :action, :created_at
201
+
202
+ field :details, :string do
203
+ visible false
204
+ searchable true
205
+ filterable true
206
+ end
207
+ end
208
+
209
+ show do
210
+ include_fields :invalid_model_name, :invalid_model_id, :action
211
+
212
+ field(:created_at)
213
+ field(:details) do
214
+ formatted_value { "<pre>#{JSON.pretty_generate(bindings[:object].details)}</pre>".html_safe }
215
+ end
216
+ end
217
+ end
218
+ ```
219
+
187
220
  ## Development
188
221
 
189
222
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
@@ -199,10 +232,8 @@ which will create a git tag for the version, push git commits and the created ta
199
232
  Bug reports and pull requests are welcome on GitHub at https://github.com/coorasse/validation_errors.
200
233
  This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/coorasse/validation_errors/blob/master/CODE_OF_CONDUCT.md).
201
234
 
235
+ Try to be a decent human being while interacting with other people.
236
+
202
237
  ## License
203
238
 
204
239
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
205
-
206
- ## Code of Conduct
207
-
208
- Everyone interacting in the ValidationErrors project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/coorasse/validation_errors/blob/master/CODE_OF_CONDUCT.md).
@@ -2,9 +2,37 @@
2
2
 
3
3
  class ValidationError < ActiveRecord::Base
4
4
  def self.track(invalid_model, action: invalid_model.persisted? ? "update" : "create")
5
+ details = filter_sensible_information(invalid_model.errors.details)
5
6
  create!(invalid_model_name: invalid_model.class.name,
6
- invalid_model_id: invalid_model.id,
7
- details: invalid_model.errors.details,
8
- action: action)
7
+ invalid_model_id: invalid_model.id,
8
+ details: details,
9
+ action: action)
10
+ end
11
+
12
+ def self.filter_sensible_information(details)
13
+ filter_parameters = if defined?(Rails) && Rails.respond_to?(:application)
14
+ Rails.application.config.filter_parameters
15
+ else
16
+ []
17
+ end
18
+ filtered_details = details.dup
19
+ filtered_details.each do |column_name, errors|
20
+ filter_parameters.each do |filter|
21
+ must_filter = case filter
22
+ when Regexp
23
+ filter.match?(column_name)
24
+ when String, Symbol
25
+ filter.to_s == column_name.to_s
26
+ end
27
+ if must_filter
28
+ errors.each do |error|
29
+ if error[:value].present?
30
+ error[:value] = "***"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ filtered_details
9
37
  end
10
38
  end
@@ -22,18 +22,31 @@ module ValidationErrors
22
22
  end
23
23
 
24
24
  module InstanceMethods
25
- def save(**options)
25
+ def update(attributes)
26
26
  super.tap do |result|
27
27
  ValidationError.track(self) unless result
28
28
  end
29
29
  end
30
30
 
31
+ def update!(attributes)
32
+ super
33
+ rescue ActiveRecord::RecordInvalid
34
+ ValidationError.track(self)
35
+ raise
36
+ end
37
+
38
+ def save(**options)
39
+ super.tap do |result|
40
+ ValidationError.track(self) unless result || persisted?
41
+ end
42
+ end
43
+
31
44
  # Attempts to save the record just like {ActiveRecord::Base#save}[rdoc-ref:Base#save] but
32
45
  # will raise an ActiveRecord::RecordInvalid exception instead of returning +false+ if the record is not valid.
33
46
  def save!(**options)
34
47
  super
35
48
  rescue ActiveRecord::RecordInvalid
36
- ValidationError.track(self)
49
+ ValidationError.track(self) unless persisted?
37
50
  raise
38
51
  end
39
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2025-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.13.0
61
+ version: 1.31.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.13.0
68
+ version: 1.31.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -106,10 +106,8 @@ files:
106
106
  - ".semaphore/semaphore.yml"
107
107
  - ".standard.yml"
108
108
  - CHANGELOG.md
109
- - CODE_OF_CONDUCT.md
110
109
  - Gemfile
111
110
  - Gemfile.lock
112
- - LICENSE.txt
113
111
  - README.md
114
112
  - Rakefile
115
113
  - lib/flat_validation_error.rb
@@ -144,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
142
  - !ruby/object:Gem::Version
145
143
  version: '0'
146
144
  requirements: []
147
- rubygems_version: 3.3.10
145
+ rubygems_version: 3.3.27
148
146
  signing_key:
149
147
  specification_version: 4
150
148
  summary: Track ActiveRecord validation errors on database
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at coorasse@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2022 Alessandro Rodi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.