paranoia 2.1.5 → 2.2.0.pre

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: 32a4bc8e17adc564a3c87661d90c1457b44323bd
4
- data.tar.gz: 94527885cf5fb887a88ee2a938472995623639dd
3
+ metadata.gz: 13ad6af701a1a810ddb2f8d320e32cb593dd894e
4
+ data.tar.gz: c6e90f3aa699e29f11ec9aa9021543f109501899
5
5
  SHA512:
6
- metadata.gz: 865a43181fa3699d92554cc800dff88a20070f2a00d839bc583c99b9e6ad2da78217711a0ca52cb5c358322a33865dbe378332c90c9182b7cf47971d2751f8a2
7
- data.tar.gz: d55b46e33174f428e607557b60ba25b8adf6058acdac6dedd3aad00d5f010d7df4c9a5045b9d445c6d640ec1606399f75fbf0f383a6f8297569fd8b90c3d29f8
6
+ metadata.gz: 4d8a2756f70124629e73dc9abc0ff81daf790c56a3f5dc19439f3639dd83ae2be71bc40b76089d0d6875dff67196031f047886563e6e8f18a73186b82ceb337c
7
+ data.tar.gz: b6038a394aec3dd2d9382a434fae9c31122b702b8390a02801194d8e79a7e4472481f68f7a3944171febd409a3174eda1355d348428f23daf11bf007218e2aa9
@@ -1,13 +1,22 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.0
7
- - 2.3.0
8
- - jruby-19mode
5
+ - 2.1.10
6
+ - 2.2.5
7
+ - 2.3.1
8
+ - jruby-9.1.0.0
9
9
 
10
10
  env:
11
- - RAILS='~> 4.0.13'
12
- - RAILS='~> 4.1.10'
13
- - RAILS='~> 4.2.1'
11
+ matrix:
12
+ - RAILS='~> 4.1.15'
13
+ - RAILS='~> 4.2.6'
14
+ - RAILS='~> 5.0.0'
15
+
16
+ matrix:
17
+ exclude:
18
+ - env: RAILS='~> 5.0.0'
19
+ rvm: 2.1.10
20
+ allow_failures:
21
+ - env: RAILS='~> 5.0.0'
22
+ rvm: jruby-9.1.0.0
@@ -1,5 +1,11 @@
1
1
  # paranoia Changelog
2
2
 
3
+ ## 2.2.0 (unreleased)
4
+
5
+ * Ruby 2.0 or greater is required
6
+ * Rails 5.0.0.beta1.1 support [@pigeonworks](https://github.com/pigeonworks) [@halostatue](https://github.com/halostatue) and [@gagalago](https://github.com/gagalago)
7
+ * Previously `#really_destroyed?` may have been defined on non-paranoid models, it is now only available on paranoid models, use regular `#destroyed?` instead.
8
+
3
9
  ## 2.1.5 (2016-01-06)
4
10
 
5
11
  * Ruby 2.3 support
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'sqlite3', :platforms => [:ruby]
4
- gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
3
+ gem 'sqlite3', platforms: [:ruby]
4
+
5
+ platforms :jruby do
6
+ gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
7
+ end
5
8
 
6
9
  platforms :rbx do
7
10
  gem 'rubysl', '~> 2.0'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Paranoia
2
2
 
3
- Paranoia is a re-implementation of [acts\_as\_paranoid](http://github.com/technoweenie/acts_as_paranoid) for Rails 3 and Rails 4, using much, much, much less code.
3
+ 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.
4
4
 
5
5
  When your app is using Paranoia, calling `destroy` on an ActiveRecord object doesn't actually destroy the database record, but just *hides* it. Paranoia does this by setting a `deleted_at` field to the current time when you `destroy` a record, and hides it by scoping all queries on your model to only include records which do not have a `deleted_at` field.
6
6
 
@@ -20,18 +20,18 @@ For Rails 3, please use version 1 of Paranoia:
20
20
  gem "paranoia", "~> 1.0"
21
21
  ```
22
22
 
23
- For Rails 4, please use version 2 of Paranoia:
23
+ For Rails 4 or 5, please use version 2 of Paranoia:
24
24
 
25
25
  ``` ruby
26
26
  gem "paranoia", "~> 2.0"
27
27
  ```
28
28
 
29
- Of course you can install this from GitHub as well:
29
+ Of course you can install this from GitHub as well from one of these examples:
30
30
 
31
31
  ``` ruby
32
- gem "paranoia", :github => "radar/paranoia", :branch => "rails3"
33
- # or
34
- gem "paranoia", :github => "radar/paranoia", :branch => "rails4"
32
+ gem "paranoia", github: "rubysherpas/paranoia", branch: "rails3"
33
+ gem "paranoia", github: "rubysherpas/paranoia", branch: "rails4"
34
+ gem "paranoia", github: "rubysherpas/paranoia", branch: "rails5"
35
35
  ```
36
36
 
37
37
  Then run:
@@ -47,7 +47,7 @@ Updating is as simple as `bundle update paranoia`.
47
47
  Run:
48
48
 
49
49
  ``` shell
50
- rails generate migration AddDeletedAtToClients deleted_at:datetime:index
50
+ bin/rails generate migration AddDeletedAtToClients deleted_at:datetime:index
51
51
  ```
52
52
 
53
53
  and now you have a migration
@@ -104,6 +104,17 @@ class Client < ActiveRecord::Base
104
104
  end
105
105
  ```
106
106
 
107
+
108
+ If you want to skip adding the default scope:
109
+
110
+ ``` ruby
111
+ class Client < ActiveRecord::Base
112
+ acts_as_paranoid without_default_scope: true
113
+
114
+ ...
115
+ end
116
+ ```
117
+
107
118
  If you want to access soft-deleted associations, override the getter method:
108
119
 
109
120
  ``` ruby
@@ -128,6 +139,12 @@ If you want to find all records, even those which are deleted:
128
139
  Client.with_deleted
129
140
  ```
130
141
 
142
+ If you want to exclude deleted records, when not able to use the default_scope (e.g. when using without_default_scope):
143
+
144
+ ``` ruby
145
+ Client.without_deleted
146
+ ```
147
+
131
148
  If you want to find only the deleted records:
132
149
 
133
150
  ``` ruby
@@ -187,7 +204,7 @@ Of course, this is not necessary for the indexes you always use in association w
187
204
 
188
205
  ##### Unique Indexes
189
206
 
190
- Becuse NULL != NULL in standard SQL, we can not simply create a unique index
207
+ Because NULL != NULL in standard SQL, we can not simply create a unique index
191
208
  on the deleted_at column and expect it to enforce that there only be one record
192
209
  with a certain combination of values.
193
210
 
@@ -244,9 +261,9 @@ The `recover` method in `acts_as_paranoid` runs `update` callbacks. Paranoia's
244
261
 
245
262
  ## Callbacks
246
263
 
247
- Paranoia provides few callbacks. It triggers `destroy` callback when the record is marked as deleted and `real_destroy` when the record is completely removed from database. It also calls `restore` callback when record is restored via paranoia
264
+ Paranoia provides several callbacks. It triggers `destroy` callback when the record is marked as deleted and `real_destroy` when the record is completely removed from database. It also calls `restore` callback when the record is restored via paranoia
248
265
 
249
- For example if you want to index you records in some search engine you can do like this:
266
+ For example if you want to index your records in some search engine you can go like this:
250
267
 
251
268
  ```ruby
252
269
  class Product < ActiveRecord::Base
@@ -3,7 +3,7 @@ require 'active_record' unless defined? ActiveRecord
3
3
  module Paranoia
4
4
  @@default_sentinel_value = nil
5
5
 
6
- # Change default_sentinel_value in a rails initilizer
6
+ # Change default_sentinel_value in a rails initializer
7
7
  def self.default_sentinel_value=(val)
8
8
  @@default_sentinel_value = val
9
9
  end
@@ -38,7 +38,7 @@ module Paranoia
38
38
  quoted_paranoia_column = connection.quote_column_name(paranoia_column)
39
39
  with_deleted.where("#{quoted_paranoia_column} IS NULL OR #{quoted_paranoia_column} != ?", paranoia_sentinel_value)
40
40
  end
41
- alias :deleted :only_deleted
41
+ alias_method :deleted, :only_deleted
42
42
 
43
43
  def restore(id_or_ids, opts = {})
44
44
  ids = Array(id_or_ids).flatten
@@ -207,9 +207,9 @@ end
207
207
 
208
208
  class ActiveRecord::Base
209
209
  def self.acts_as_paranoid(options={})
210
- alias :really_destroyed? :destroyed?
211
- alias :really_delete :delete
212
- alias :destroy_without_paranoia :destroy
210
+ alias_method :really_destroyed?, :destroyed?
211
+ alias_method :really_delete, :delete
212
+ alias_method :destroy_without_paranoia, :destroy
213
213
 
214
214
  include Paranoia
215
215
  class_attribute :paranoia_column, :paranoia_sentinel_value
@@ -219,7 +219,11 @@ class ActiveRecord::Base
219
219
  def self.paranoia_scope
220
220
  where(paranoia_column => paranoia_sentinel_value)
221
221
  end
222
- default_scope { paranoia_scope }
222
+ class << self; alias_method :without_deleted, :paranoia_scope end
223
+
224
+ unless options[:without_default_scope]
225
+ default_scope { paranoia_scope }
226
+ end
223
227
 
224
228
  before_restore {
225
229
  self.class.notify_observers(:before_restore, self) if self.class.respond_to?(:notify_observers)
@@ -258,14 +262,21 @@ require 'paranoia/rspec' if defined? RSpec
258
262
 
259
263
  module ActiveRecord
260
264
  module Validations
261
- class UniquenessValidator < ActiveModel::EachValidator
262
- protected
263
- def build_relation_with_paranoia(klass, table, attribute, value)
264
- relation = build_relation_without_paranoia(klass, table, attribute, value)
265
+ module UniquenessParanoiaValidator
266
+ def build_relation(klass, table, attribute, value)
267
+ relation = super(klass, table, attribute, value)
265
268
  return relation unless klass.respond_to?(:paranoia_column)
266
- relation.and(klass.arel_table[klass.paranoia_column].eq(klass.paranoia_sentinel_value))
269
+ arel_paranoia_scope = klass.arel_table[klass.paranoia_column].eq(klass.paranoia_sentinel_value)
270
+ if ActiveRecord::VERSION::STRING >= "5.0"
271
+ relation.where(arel_paranoia_scope)
272
+ else
273
+ relation.and(arel_paranoia_scope)
274
+ end
267
275
  end
268
- alias_method_chain :build_relation, :paranoia
276
+ end
277
+
278
+ class UniquenessValidator < ActiveModel::EachValidator
279
+ prepend UniquenessParanoiaValidator
269
280
  end
270
281
  end
271
282
  end
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = "2.1.5"
2
+ VERSION = "2.2.0.pre"
3
3
  end
@@ -5,16 +5,26 @@ Gem::Specification.new do |s|
5
5
  s.name = "paranoia"
6
6
  s.version = Paranoia::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.authors = ["radarlistener@gmail.com"]
9
- s.email = []
8
+ s.authors = %w(radarlistener@gmail.com)
9
+ s.email = %w(ben@benmorgan.io)
10
10
  s.homepage = "http://rubygems.org/gems/paranoia"
11
- s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using much, much, much less code."
12
- s.description = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using much, much, much less code. You would use either plugin / gem if you wished that when you called destroy on an Active Record object that it didn't actually destroy it, but just \"hid\" the record. Paranoia does this by setting a deleted_at field to the current time when you destroy a record, and hides it by scoping all queries on your model to only include records which do not have a deleted_at field."
11
+ s.license = 'MIT'
12
+ s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, using much, much, much less code."
13
+ s.description = <<-DSC
14
+ Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
15
+ using much, much, much less code. You would use either plugin / gem if you
16
+ wished that when you called destroy on an Active Record object that it
17
+ didn't actually destroy it, but just "hid" the record. Paranoia does this
18
+ by setting a deleted_at field to the current time when you destroy a record,
19
+ and hides it by scoping all queries on your model to only include records
20
+ which do not have a deleted_at field.
21
+ DSC
22
+
13
23
 
14
24
  s.required_rubygems_version = ">= 1.3.6"
15
- s.rubyforge_project = "paranoia"
25
+ s.required_ruby_version = '>= 2.0'
16
26
 
17
- s.add_dependency "activerecord", "~> 4.0"
27
+ s.add_dependency 'activerecord', '>= 4.0', '< 5.1'
18
28
 
19
29
  s.add_development_dependency "bundler", ">= 1.0.0"
20
30
  s.add_development_dependency "rake"
@@ -4,7 +4,6 @@ require 'minitest/autorun'
4
4
  require 'paranoia'
5
5
 
6
6
  test_framework = defined?(MiniTest::Test) ? MiniTest::Test : MiniTest::Unit::TestCase
7
- ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::VERSION::STRING >= '4.2'
8
7
 
9
8
  def connect!
10
9
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', database: ':memory:'
@@ -40,7 +39,8 @@ def setup!
40
39
  'namespaced_paranoid_belongs_tos' => 'deleted_at DATETIME, paranoid_has_one_id INTEGER',
41
40
  'unparanoid_unique_models' => 'name VARCHAR(32), paranoid_with_unparanoids_id INTEGER',
42
41
  'active_column_models' => 'deleted_at DATETIME, active BOOLEAN',
43
- 'active_column_model_with_uniqueness_validations' => 'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN'
42
+ 'active_column_model_with_uniqueness_validations' => 'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN',
43
+ 'without_default_scope_models' => 'deleted_at DATETIME'
44
44
  }.each do |table_name, columns_as_sql_string|
45
45
  ActiveRecord::Base.connection.execute "CREATE TABLE #{table_name} (id INTEGER NOT NULL PRIMARY KEY, #{columns_as_sql_string})"
46
46
  end
@@ -56,8 +56,15 @@ setup!
56
56
 
57
57
  class ParanoiaTest < test_framework
58
58
  def setup
59
- ActiveRecord::Base.connection.tables.each do |table|
60
- ActiveRecord::Base.connection.execute "DELETE FROM #{table}"
59
+ connection = ActiveRecord::Base.connection
60
+ cleaner = ->(source) {
61
+ ActiveRecord::Base.connection.execute "DELETE FROM #{source}"
62
+ }
63
+
64
+ if ActiveRecord::VERSION::MAJOR < 5
65
+ connection.tables.each(&cleaner)
66
+ else
67
+ connection.data_sources.each(&cleaner)
61
68
  end
62
69
  end
63
70
 
@@ -178,8 +185,10 @@ class ParanoiaTest < test_framework
178
185
  assert_equal 0, parent1.paranoid_models.count
179
186
  assert_equal 1, parent1.paranoid_models.only_deleted.count
180
187
  assert_equal 1, parent1.paranoid_models.deleted.count
188
+ assert_equal 0, parent1.paranoid_models.without_deleted.count
181
189
  p3 = ParanoidModel.create(:parent_model => parent1)
182
190
  assert_equal 2, parent1.paranoid_models.with_deleted.count
191
+ assert_equal 1, parent1.paranoid_models.without_deleted.count
183
192
  assert_equal [p1,p3], parent1.paranoid_models.with_deleted
184
193
  end
185
194
 
@@ -204,6 +213,14 @@ class ParanoiaTest < test_framework
204
213
  assert_equal nil, ParanoidModel.paranoia_sentinel_value
205
214
  end
206
215
 
216
+ def test_without_default_scope_option
217
+ model = WithoutDefaultScopeModel.create
218
+ model.destroy
219
+ assert_equal 1, model.class.count
220
+ assert_equal 1, model.class.only_deleted.count
221
+ assert_equal 0, model.class.where(deleted_at: nil).count
222
+ end
223
+
207
224
  def test_active_column_model
208
225
  model = ActiveColumnModel.new
209
226
  assert_equal 0, model.class.count
@@ -283,8 +300,7 @@ class ParanoiaTest < test_framework
283
300
  # Regression test for #24
284
301
  def test_chaining_for_paranoid_models
285
302
  scope = FeaturefulModel.where(:name => "foo").only_deleted
286
- assert_equal "foo", scope.where_values_hash['name']
287
- assert_equal 2, scope.where_values.count
303
+ assert_equal({'name' => "foo"}, scope.where_values_hash)
288
304
  end
289
305
 
290
306
  def test_only_destroyed_scope_for_paranoid_models
@@ -383,9 +399,9 @@ class ParanoiaTest < test_framework
383
399
  # Just to demonstrate the AR behaviour
384
400
  model = NonParanoidModel.new
385
401
  model.destroy!
386
- assert model.really_destroyed?
402
+ assert model.destroyed?
387
403
  model.destroy!
388
- assert model.really_destroyed?
404
+ assert model.destroyed?
389
405
 
390
406
  # Mirrors behaviour above
391
407
  model = ParanoidModel.new
@@ -762,7 +778,7 @@ class ParanoiaTest < test_framework
762
778
  parent1 = ParentModel.create
763
779
  pt1 = ParanoidModelWithTimestamp.create(:parent_model => parent1)
764
780
  ParanoidModelWithTimestamp.record_timestamps = false
765
- pt1.update_columns(created_at: 20.years.ago, updated_at: 10.years.ago, deleted_at: 10.years.ago)
781
+ pt1.update_columns(created_at: 20.years.ago, updated_at: 10.years.ago, deleted_at: 10.years.ago)
766
782
  ParanoidModelWithTimestamp.record_timestamps = true
767
783
  assert pt1.updated_at < 10.minutes.ago
768
784
  refute pt1.deleted_at.nil?
@@ -948,7 +964,13 @@ class FailCallbackModel < ActiveRecord::Base
948
964
  belongs_to :parent_model
949
965
  acts_as_paranoid
950
966
 
951
- before_destroy { |_| false }
967
+ before_destroy { |_|
968
+ if ActiveRecord::VERSION::MAJOR < 5
969
+ false
970
+ else
971
+ throw :abort
972
+ end
973
+ }
952
974
  end
953
975
 
954
976
  class FeaturefulModel < ActiveRecord::Base
@@ -1042,6 +1064,10 @@ class CustomSentinelModel < ActiveRecord::Base
1042
1064
  acts_as_paranoid sentinel_value: DateTime.new(0)
1043
1065
  end
1044
1066
 
1067
+ class WithoutDefaultScopeModel < ActiveRecord::Base
1068
+ acts_as_paranoid without_default_scope: true
1069
+ end
1070
+
1045
1071
  class ActiveColumnModel < ActiveRecord::Base
1046
1072
  acts_as_paranoid column: :active, sentinel_value: true
1047
1073
 
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.2.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - radarlistener@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -52,13 +58,16 @@ dependencies:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
- description: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using
56
- much, much, much less code. You would use either plugin / gem if you wished that
57
- when you called destroy on an Active Record object that it didn't actually destroy
58
- it, but just "hid" the record. Paranoia does this by setting a deleted_at field
59
- to the current time when you destroy a record, and hides it by scoping all queries
60
- on your model to only include records which do not have a deleted_at field.
61
- email: []
61
+ description: |2
62
+ Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
63
+ using much, much, much less code. You would use either plugin / gem if you
64
+ wished that when you called destroy on an Active Record object that it
65
+ didn't actually destroy it, but just "hid" the record. Paranoia does this
66
+ by setting a deleted_at field to the current time when you destroy a record,
67
+ and hides it by scoping all queries on your model to only include records
68
+ which do not have a deleted_at field.
69
+ email:
70
+ - ben@benmorgan.io
62
71
  executables: []
63
72
  extensions: []
64
73
  extra_rdoc_files: []
@@ -77,7 +86,8 @@ files:
77
86
  - paranoia.gemspec
78
87
  - test/paranoia_test.rb
79
88
  homepage: http://rubygems.org/gems/paranoia
80
- licenses: []
89
+ licenses:
90
+ - MIT
81
91
  metadata: {}
82
92
  post_install_message:
83
93
  rdoc_options: []
@@ -87,17 +97,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
97
  requirements:
88
98
  - - ">="
89
99
  - !ruby/object:Gem::Version
90
- version: '0'
100
+ version: '2.0'
91
101
  required_rubygems_version: !ruby/object:Gem::Requirement
92
102
  requirements:
93
103
  - - ">="
94
104
  - !ruby/object:Gem::Version
95
105
  version: 1.3.6
96
106
  requirements: []
97
- rubyforge_project: paranoia
98
- rubygems_version: 2.4.5
107
+ rubyforge_project:
108
+ rubygems_version: 2.6.4
99
109
  signing_key:
100
110
  specification_version: 4
101
- summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using much,
102
- much, much less code.
111
+ summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,
112
+ using much, much, much less code.
103
113
  test_files: []
114
+ has_rdoc: