paranoia 2.2.1 → 2.6.0

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
- SHA1:
3
- metadata.gz: a081d1169b0d0b18a5815aafe4bafdeab81e62fd
4
- data.tar.gz: 4b38ec1db06051b0c5ada74f9405f935ba39624b
2
+ SHA256:
3
+ metadata.gz: ad52996a9a12b6605d8179ad1ae5ef39cb7655d19d037884518800a02f6ff160
4
+ data.tar.gz: 3c9d2c4203e203b64bf0e24db1995ddfc431c8ed742ad96319f19eea2a62bc8a
5
5
  SHA512:
6
- metadata.gz: e80496f3e472a7ecef7abee20f49d394fb884bb8e81313c92e6f1915b2f805d9f14ef1ef930f47ccdf97300df51f25458881d465df4355f85d2a6066c0b92671
7
- data.tar.gz: 205530a0638b6d1d1f455cfae490e2c9e77f080ef4fdfd63d6fdafba849ebc7615ff34f091479b011a02cd9bd7919f27061a0f608be33be22b9801041d8277b7
6
+ metadata.gz: ed7a78d7135fce0a513e0f5fb4c6c685c99ad788efa57e15dd9ae011d1dfce0d98bc41fd49b7688f3d706e6101b78824ada19ce3617359a085186e76acc0a2db
7
+ data.tar.gz: 2a24bfb1f5d1f9b8c5e588c86bf745ed80125167dfefc6ad5a10cc3b7a66da3ee50f85b7727cda74a5f92a9a1d1b3fac0defc4296b71b1dd7f8c9e9d8496831f
@@ -0,0 +1,61 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-20.04
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby:
19
+ - 3.1
20
+ - '3.0'
21
+ - 2.7
22
+ - 2.6
23
+ - 2.5
24
+ # - jruby-9.2.19.0
25
+ # - jruby-9.3.1.0
26
+ rails:
27
+ - '~> 5.1.0'
28
+ - '~> 5.2.0'
29
+ - '~> 6.0.0'
30
+ - '~> 6.1.0'
31
+ - '~> 7.0.0'
32
+ - 'edge'
33
+ exclude:
34
+ # Rails edge is now 7.x and requires ruby 2.7
35
+ - rails: 'edge'
36
+ ruby: 2.6
37
+ - rails: 'edge'
38
+ ruby: 2.5
39
+ - rails: '~> 7.0.0'
40
+ ruby: 2.6
41
+ - rails: '~> 7.0.0'
42
+ ruby: 2.5
43
+ # Legacy Rails with newer rubies
44
+ - rails: '~> 5.1.0'
45
+ ruby: '3.0'
46
+ - rails: '~> 5.2.0'
47
+ ruby: '3.0'
48
+ - rails: '~> 5.1.0'
49
+ ruby: 3.1
50
+ - rails: '~> 5.2.0'
51
+ ruby: 3.1
52
+
53
+ env:
54
+ RAILS: ${{ matrix.rails }}
55
+ steps:
56
+ - uses: actions/checkout@v2
57
+ - uses: ruby/setup-ruby@v1
58
+ with:
59
+ ruby-version: ${{ matrix.ruby }}
60
+ bundler-cache: true
61
+ - run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,6 +1,117 @@
1
1
  # paranoia Changelog
2
2
 
3
- ## 2.2.2 (Unreleased)
3
+ ## 2.6.0
4
+
5
+ * [#512](https://github.com/rubysherpas/paranoia/pull/512) Quote table names; Mysql 8 has keywords that might match table names which cause an exception.
6
+ * [#476](https://github.com/rubysherpas/paranoia/pull/476) Fix syntax error in documentation.
7
+ * [#485](https://github.com/rubysherpas/paranoia/pull/485) Rollback transaction if destroy aborted.
8
+ * [#522](https://github.com/rubysherpas/paranoia/pull/522) Add failing tests for association with abort on destroy.
9
+ * [#513](https://github.com/rubysherpas/paranoia/pull/513) Fix create callback called on destroy.
10
+
11
+ ## 2.5.3
12
+
13
+ * [#532](https://github.com/rubysherpas/paranoia/pull/532) Fix: correct bug when sentinel_value is not a timestamp
14
+ [Hassanin Ahmed](https://github.com/sas1ni69)
15
+ * [#531](https://github.com/rubysherpas/paranoia/pull/531) Added test case to reproduce bug introduce in v2.5.1
16
+ [Sherif Elkassaby](https://github.com/sherif-nedap)
17
+ * [#529](https://github.com/rubysherpas/paranoia/pull/529) Fix: Do not define a RSpec matcher when RSpec isn't present
18
+ [Sebastian Welther](https://github.com/swelther)
19
+
20
+ ## 2.5.2
21
+
22
+ * [#526](https://github.com/rubysherpas/paranoia/pull/526) Do not include tests files in packaged gem
23
+
24
+ [Jason Fleetwood-Boldt](https://github.com/jasonfb)
25
+ * [#492](https://github.com/rubysherpas/paranoia/pull/492) Warn if acts_as_paranoid is called more than once on the same model
26
+
27
+ [Ignatius Reza](https://github.com/ignatiusreza)
28
+
29
+ ## 2.5.1
30
+
31
+ * [#481](https://github.com/rubysherpas/paranoia/pull/481) Replaces hard coded `deleted_at` with `paranoia_column`.
32
+
33
+ [Hassanin Ahmed](https://github.com/sas1ni69)
34
+
35
+ ## 2.5.0
36
+
37
+ * [#516](https://github.com/rubysherpas/paranoia/pull/516) Add support for ActiveRecord 7.0, drop support for EOL Ruby < 2.5 and Rails < 5.1
38
+ adding support for Rails 7
39
+
40
+ [Mathieu Jobin](https://github.com/mathieujobin)
41
+ * [#515](https://github.com/rubysherpas/paranoia/pull/515) Switch from Travis CI to GitHub Actions
42
+
43
+ [Shinichi Maeshima](https://github.com/willnet)
44
+
45
+ ## 2.4.3
46
+
47
+ * [#503](https://github.com/rubysherpas/paranoia/pull/503) Bump activerecord dependency for Rails 6.1
48
+
49
+ [Jörg Schiller](https://github.com/joergschiller)
50
+
51
+ * [#483](https://github.com/rubysherpas/paranoia/pull/483) Update JRuby version to 9.2.8.0 + remove EOL Ruby 2.2
52
+
53
+ [Uwe Kubosch](https://github.com/donv)
54
+
55
+ * [#482](https://github.com/rubysherpas/paranoia/pull/482) Fix after_commit for Rails 6
56
+
57
+ [Ashwin Hegde](https://github.com/hashwin)
58
+
59
+ ## 2.4.2
60
+
61
+ * [#470](https://github.com/rubysherpas/paranoia/pull/470) Add support for ActiveRecord 6.0
62
+
63
+ [Anton Kolodii](https://github.com/iggant), [Jared Norman](https://github.com/jarednorman)
64
+
65
+ ## 2.4.1
66
+
67
+ * [#435](https://github.com/rubysherpas/paranoia/pull/435) Monkeypatch activerecord relations to work with rails 5.2.0
68
+
69
+ [Bartosz Bonisławski (@bbonislawski)](https://github.com/bbonislawski)
70
+
71
+ ## 2.4.0
72
+
73
+ * [#423](https://github.com/rubysherpas/paranoia/pull/423) Add `paranoia_destroy` and `paranoia_delete` aliases
74
+
75
+ [John Hawthorn (@jhawthorn)](https://github.com/jhawthorn)
76
+
77
+ * [#408](https://github.com/rubysherpas/paranoia/pull/408) Fix instance variable `@_disable_counter_cache` not initialized warning.
78
+
79
+ [Akira Matsuda (@amatsuda)](https://github.com/amatsuda)
80
+
81
+ * [#412](https://github.com/rubysherpas/paranoia/pull/412) Fix `really_destroy!` behavior with `sentinel_value`
82
+
83
+ [Steve Rice (@steverice)](https://github.com/steverice)
84
+
85
+ ## 2.3.1
86
+
87
+ * [#397](https://github.com/rubysherpas/paranoia/pull/397) Bump active record max version to support 5.1 final
88
+
89
+ ## 2.3.0 (2017-04-14)
90
+
91
+ * [#393](https://github.com/rubysherpas/paranoia/pull/393) Drop support for Rails 4.1 and begin supporting Rails 5.1.
92
+
93
+ [Miklós Fazekas (@mfazekas)](https://github.com/mfazekas)
94
+
95
+ * [#391](https://github.com/rubysherpas/paranoia/pull/391) Use Contributor Covenant Version 1.4
96
+
97
+ [Ben A. Morgan (@BenMorganIO)](https://github.com/BenMorganIO)
98
+
99
+ * [#390](https://github.com/rubysherpas/paranoia/pull/390) Fix counter cache with double destroy, really_destroy, and restore
100
+
101
+ [Chris Oliver (@excid3)](https://github.com/excid3)
102
+
103
+ * [#389](https://github.com/rubysherpas/paranoia/pull/389) Added association not soft destroyed validator
104
+
105
+ _Fixes [#380](https://github.com/rubysherpas/paranoia/issues/380)_
106
+
107
+ [Edward Poot (@edwardmp)](https://github.com/edwardmp)
108
+
109
+ * [#383](https://github.com/rubysherpas/paranoia/pull/383) Add recovery window feature
110
+
111
+ _Fixes [#359](https://github.com/rubysherpas/paranoia/issues/359)_
112
+
113
+ [Andrzej Piątyszek (@konto-andrzeja)](https://github.com/konto-andrzeja)
114
+
4
115
 
5
116
  ## 2.2.1 (2017-02-15)
6
117
 
@@ -46,7 +157,7 @@
46
157
 
47
158
  * `#destroyed?` is no longer overridden. Use `#paranoia_destroyed?` for the existing behaviour. [Washington Luiz](https://github.com/huoxito)
48
159
  * `#persisted?` is no longer overridden.
49
- * ActiveRecord 4.0 no longer has `#destroy!` as an alias for `#really_destroy`.
160
+ * ActiveRecord 4.0 no longer has `#destroy!` as an alias for `#really_destroy!`.
50
161
  * `#destroy` will now raise an exception if called on a readonly record.
51
162
  * `#destroy` on a hard deleted record is now a successful noop.
52
163
  * `#destroy` on a new record will set deleted_at (previously this raised an error)
@@ -54,7 +165,7 @@
54
165
 
55
166
  ### Bug Fixes
56
167
 
57
- * Calling `#destroy` twice will not hard-delete records. Use `#really_destroy` if this is desired.
168
+ * Calling `#destroy` twice will not hard-delete records. Use `#really_destroy!` if this is desired.
58
169
  * Fix errors on non-paranoid has_one dependent associations
59
170
 
60
171
  ## 2.0.5 (2015-01-22)
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ben@benmorgan.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,20 +1,32 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', platforms: [:ruby]
3
+ sqlite = ENV['SQLITE_VERSION']
4
+
5
+ if sqlite
6
+ gem 'sqlite3', sqlite, platforms: [:ruby]
7
+ else
8
+ gem 'sqlite3', platforms: [:ruby]
9
+ end
4
10
 
5
11
  platforms :jruby do
6
- gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
12
+ gem 'activerecord-jdbcsqlite3-adapter'
7
13
  end
8
14
 
9
- platforms :rbx do
10
- gem 'rubysl', '~> 2.0'
11
- gem 'rubysl-test-unit'
12
- gem 'rubinius-developer_tools'
15
+ if RUBY_ENGINE == 'rbx'
16
+ platforms :rbx do
17
+ gem 'rubinius-developer_tools'
18
+ gem 'rubysl', '~> 2.0'
19
+ gem 'rubysl-test-unit'
20
+ end
13
21
  end
14
22
 
15
- rails = ENV['RAILS'] || '~> 4.2.0'
23
+ rails = ENV['RAILS'] || '~> 6.0.4'
16
24
 
17
- gem 'rails', rails
25
+ if rails == 'edge'
26
+ gem 'rails', github: 'rails/rails'
27
+ else
28
+ gem 'rails', rails
29
+ end
18
30
 
19
31
  # Specify your gem's dependencies in paranoia.gemspec
20
32
  gemspec
data/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ [![Gem Version](https://badge.fury.io/rb/paranoia.svg)](https://badge.fury.io/rb/paranoia)
2
+ [![build](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml/badge.svg)](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml)
3
+
4
+ **Notice:**
5
+
6
+ `paranoia` has some surprising behaviour (like overriding ActiveRecord's `delete` and `destroy`) and is not recommended for new projects. See [`discard`'s README](https://github.com/jhawthorn/discard#why-not-paranoia-or-acts_as_paranoid) for more details.
7
+
8
+ Paranoia will continue to accept bug fixes and support new versions of Rails but isn't accepting new features.
9
+
1
10
  # Paranoia
2
11
 
3
12
  Paranoia is a re-implementation of [acts\_as\_paranoid](http://github.com/ActsAsParanoid/acts_as_paranoid) for Rails 3/4/5, using much, much, much less code.
@@ -181,6 +190,21 @@ Client.restore(id, :recursive => true)
181
190
  client.restore(:recursive => true)
182
191
  ```
183
192
 
193
+ If you want to restore a record and only those dependently destroyed associated records that were deleted within 2 minutes of the object upon which they depend:
194
+
195
+ ``` ruby
196
+ Client.restore(id, :recursive => true, :recovery_window => 2.minutes)
197
+ # or
198
+ client.restore(:recursive => true, :recovery_window => 2.minutes)
199
+ ```
200
+
201
+ Note that by default paranoia will not prevent that a soft destroyed object can't be associated with another object of a different model.
202
+ A Rails validator is provided should you require this functionality:
203
+ ``` ruby
204
+ validates :some_assocation, association_not_soft_destroyed: true
205
+ ```
206
+ This validator makes sure that `some_assocation` is not soft destroyed. If the object is soft destroyed the main object is rendered invalid and an validation error is added.
207
+
184
208
  For more information, please look at the tests.
185
209
 
186
210
  #### About indexes:
@@ -0,0 +1,41 @@
1
+ module HandleParanoiaDestroyedInBelongsToAssociation
2
+ def handle_dependency
3
+ return unless load_target
4
+
5
+ case options[:dependent]
6
+ when :destroy
7
+ target.destroy
8
+ if target.respond_to?(:paranoia_destroyed?)
9
+ raise ActiveRecord::Rollback unless target.paranoia_destroyed?
10
+ else
11
+ raise ActiveRecord::Rollback unless target.destroyed?
12
+ end
13
+ else
14
+ target.send(options[:dependent])
15
+ end
16
+ end
17
+ end
18
+
19
+ module HandleParanoiaDestroyedInHasOneAssociation
20
+ def delete(method = options[:dependent])
21
+ if load_target
22
+ case method
23
+ when :delete
24
+ target.delete
25
+ when :destroy
26
+ target.destroyed_by_association = reflection
27
+ target.destroy
28
+ if target.respond_to?(:paranoia_destroyed?)
29
+ throw(:abort) unless target.paranoia_destroyed?
30
+ else
31
+ throw(:abort) unless target.destroyed?
32
+ end
33
+ when :nullify
34
+ target.update_columns(reflection.foreign_key => nil) if target.persisted?
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ ActiveRecord::Associations::BelongsToAssociation.prepend HandleParanoiaDestroyedInBelongsToAssociation
41
+ ActiveRecord::Associations::HasOneAssociation.prepend HandleParanoiaDestroyedInHasOneAssociation
@@ -1,23 +1,26 @@
1
- require 'rspec/expectations'
1
+ if defined?(RSpec)
2
+ require 'rspec/expectations'
2
3
 
3
- # Validate the subject's class did call "acts_as_paranoid"
4
- RSpec::Matchers.define :act_as_paranoid do
5
- match { |subject| subject.class.ancestors.include?(Paranoia) }
4
+ # Validate the subject's class did call "acts_as_paranoid"
5
+ RSpec::Matchers.define :act_as_paranoid do
6
+ match { |subject| subject.class.ancestors.include?(Paranoia) }
6
7
 
7
- failure_message_proc = lambda do
8
- "expected #{subject.class} to use `acts_as_paranoid`"
9
- end
8
+ failure_message_proc = lambda do
9
+ "expected #{subject.class} to use `acts_as_paranoid`"
10
+ end
10
11
 
11
- failure_message_when_negated_proc = lambda do
12
- "expected #{subject.class} not to use `acts_as_paranoid`"
13
- end
12
+ failure_message_when_negated_proc = lambda do
13
+ "expected #{subject.class} not to use `acts_as_paranoid`"
14
+ end
14
15
 
15
- if respond_to?(:failure_message_when_negated)
16
- failure_message(&failure_message_proc)
17
- failure_message_when_negated(&failure_message_when_negated_proc)
18
- else
19
- # RSpec 2 compatibility:
20
- failure_message_for_should(&failure_message_proc)
21
- failure_message_for_should_not(&failure_message_when_negated_proc)
16
+ if respond_to?(:failure_message_when_negated)
17
+ failure_message(&failure_message_proc)
18
+ failure_message_when_negated(&failure_message_when_negated_proc)
19
+ else
20
+ # RSpec 2 compatibility:
21
+ failure_message_for_should(&failure_message_proc)
22
+ failure_message_for_should_not(&failure_message_when_negated_proc)
23
+ end
22
24
  end
25
+
23
26
  end
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  end