paranoia 2.0.3 → 2.0.4
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/paranoia.rb +5 -3
- data/lib/paranoia/version.rb +1 -1
- data/test/paranoia_test.rb +36 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 699077f31f4cc413787d2132a6a36fc18051392d
|
4
|
+
data.tar.gz: 3ad7c463ced3e000c097c76c3b77d3378f4100e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9b72b34e364d624fc9b0152f6be5d57903f87b0aed34ac6a010cb7bc0b117df0954db926595f67873cb43e3e6b5542ac4a07a6626e0d59de4af9d4c2874e132
|
7
|
+
data.tar.gz: 423bdba7a858510b877973e0746d0fbe896f96d43b6eae06793da88e9566755e53b9740bcaa1a82b883a12ac1876927f47a60cb58626200f02ec2678a89af6af
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# paranoia Changelog
|
2
|
+
|
3
|
+
## 2.0.4 (2014-12-02)
|
4
|
+
|
5
|
+
### Features
|
6
|
+
* Add paranoia_scope as named version of default_scope [#184](https://github.com/radar/paranoia/pull/184) [Jozsef Nyitrai](https://github.com/nyjt)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
* Fix initialization problems when missing table or no database connection [#186](https://github.com/radar/paranoia/issues/186)
|
11
|
+
* Fix broken restore of has_one associations [#185](https://github.com/radar/paranoia/issues/185) [#171](https://github.com/radar/paranoia/pull/171) [Martin Sereinig](https://github.com/srecnig)
|
data/lib/paranoia.rb
CHANGED
@@ -144,7 +144,7 @@ module Paranoia
|
|
144
144
|
if association_data.nil? && association.macro.to_s == "has_one"
|
145
145
|
association_class_name = association.options[:class_name].present? ? association.options[:class_name] : association.name.to_s.camelize
|
146
146
|
association_foreign_key = association.options[:foreign_key].present? ? association.options[:foreign_key] : "#{self.class.name.to_s.underscore}_id"
|
147
|
-
Object.const_get(association_class_name).only_deleted.where(association_foreign_key
|
147
|
+
Object.const_get(association_class_name).only_deleted.where(association_foreign_key => self.id).first.try(:restore, recursive: true)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
@@ -154,7 +154,6 @@ end
|
|
154
154
|
|
155
155
|
class ActiveRecord::Base
|
156
156
|
def self.acts_as_paranoid(options={})
|
157
|
-
raise "primary key required for "+self.name unless self.primary_key
|
158
157
|
alias :destroy! :destroy
|
159
158
|
alias :delete! :delete
|
160
159
|
def really_destroy!
|
@@ -183,7 +182,10 @@ class ActiveRecord::Base
|
|
183
182
|
|
184
183
|
self.paranoia_column = (options[:column] || :deleted_at).to_s
|
185
184
|
self.paranoia_sentinel_value = options.fetch(:sentinel_value) { Paranoia.default_sentinel_value }
|
186
|
-
|
185
|
+
def self.paranoia_scope
|
186
|
+
where(table_name => { paranoia_column => paranoia_sentinel_value })
|
187
|
+
end
|
188
|
+
default_scope { paranoia_scope }
|
187
189
|
|
188
190
|
before_restore {
|
189
191
|
self.class.notify_observers(:before_restore, self) if self.class.respond_to?(:notify_observers)
|
data/lib/paranoia/version.rb
CHANGED
data/test/paranoia_test.rb
CHANGED
@@ -11,6 +11,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../lib/paranoia")
|
|
11
11
|
|
12
12
|
def connect!
|
13
13
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', database: ':memory:'
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup!
|
17
|
+
connect!
|
14
18
|
ActiveRecord::Base.connection.execute 'CREATE TABLE parent_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
|
15
19
|
ActiveRecord::Base.connection.execute 'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME)'
|
16
20
|
ActiveRecord::Base.connection.execute 'CREATE TABLE paranoid_model_with_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER)'
|
@@ -28,7 +32,6 @@ def connect!
|
|
28
32
|
ActiveRecord::Base.connection.execute 'CREATE TABLE custom_column_models (id INTEGER NOT NULL PRIMARY KEY, destroyed_at DATETIME)'
|
29
33
|
ActiveRecord::Base.connection.execute 'CREATE TABLE custom_sentinel_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME NOT NULL)'
|
30
34
|
ActiveRecord::Base.connection.execute 'CREATE TABLE non_paranoid_models (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER)'
|
31
|
-
ActiveRecord::Base.connection.execute 'CREATE TABLE idless_models (deleted_at DATETIME)'
|
32
35
|
end
|
33
36
|
|
34
37
|
class WithDifferentConnection < ActiveRecord::Base
|
@@ -37,7 +40,7 @@ class WithDifferentConnection < ActiveRecord::Base
|
|
37
40
|
acts_as_paranoid
|
38
41
|
end
|
39
42
|
|
40
|
-
|
43
|
+
setup!
|
41
44
|
|
42
45
|
class ParanoiaTest < test_framework
|
43
46
|
def setup
|
@@ -535,7 +538,28 @@ class ParanoiaTest < test_framework
|
|
535
538
|
|
536
539
|
assert hasOne.reload.deleted_at.nil?
|
537
540
|
end
|
538
|
-
|
541
|
+
|
542
|
+
# covers #185
|
543
|
+
def test_restoring_recursive_has_one_restores_correct_object
|
544
|
+
hasOnes = 2.times.map { ParanoidModelWithHasOne.create }
|
545
|
+
belongsTos = 2.times.map { ParanoidModelWithBelong.create }
|
546
|
+
|
547
|
+
hasOnes[0].update paranoid_model_with_belong: belongsTos[0]
|
548
|
+
hasOnes[1].update paranoid_model_with_belong: belongsTos[1]
|
549
|
+
|
550
|
+
hasOnes.each(&:destroy)
|
551
|
+
|
552
|
+
ParanoidModelWithHasOne.restore(hasOnes[1], :recursive => true)
|
553
|
+
hasOnes.each(&:reload)
|
554
|
+
belongsTos.each(&:reload)
|
555
|
+
|
556
|
+
# without #185, belongsTos[0] will be restored instead of belongsTos[1]
|
557
|
+
refute_nil hasOnes[0].deleted_at
|
558
|
+
refute_nil belongsTos[0].deleted_at
|
559
|
+
assert_nil hasOnes[1].deleted_at
|
560
|
+
assert_nil belongsTos[1].deleted_at
|
561
|
+
end
|
562
|
+
|
539
563
|
# covers #131
|
540
564
|
def test_has_one_really_destroy_with_nil
|
541
565
|
model = ParanoidModelWithHasOne.create
|
@@ -603,7 +627,8 @@ class ParanoiaTest < test_framework
|
|
603
627
|
a.destroy!
|
604
628
|
a.restore!
|
605
629
|
# This test passes if no exception is raised
|
606
|
-
|
630
|
+
ensure
|
631
|
+
setup! # Reconnect the main connection
|
607
632
|
end
|
608
633
|
|
609
634
|
def test_restore_clear_association_cache_if_associations_present
|
@@ -621,10 +646,12 @@ class ParanoiaTest < test_framework
|
|
621
646
|
assert_equal 3, parent.very_related_models.size
|
622
647
|
end
|
623
648
|
|
624
|
-
def
|
625
|
-
|
626
|
-
|
627
|
-
|
649
|
+
def test_model_without_db_connection
|
650
|
+
ActiveRecord::Base.remove_connection
|
651
|
+
|
652
|
+
NoConnectionModel.class_eval{ acts_as_paranoid }
|
653
|
+
ensure
|
654
|
+
setup!
|
628
655
|
end
|
629
656
|
|
630
657
|
private
|
@@ -766,5 +793,5 @@ class AsplodeModel < ActiveRecord::Base
|
|
766
793
|
end
|
767
794
|
end
|
768
795
|
|
769
|
-
class
|
796
|
+
class NoConnectionModel < ActiveRecord::Base
|
770
797
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paranoia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
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: 2014-
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -65,6 +65,7 @@ extra_rdoc_files: []
|
|
65
65
|
files:
|
66
66
|
- ".gitignore"
|
67
67
|
- ".travis.yml"
|
68
|
+
- CHANGELOG.md
|
68
69
|
- Gemfile
|
69
70
|
- LICENSE
|
70
71
|
- README.md
|