acts_as_paranoid 0.5.0.beta1 → 0.5.0.beta2

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: 6e4085cb11f666dff4eb490e4214f010f46216ab
4
- data.tar.gz: 7c694f1b21233c47299c523696111a7fc4454194
3
+ metadata.gz: e64b4e62e3467e6208b4b06d4f6f6f45b5758888
4
+ data.tar.gz: 1bf27545571d18596daa573546c84811da6fc5dd
5
5
  SHA512:
6
- metadata.gz: 2910ee9bdae09c7e52d7c7157c57192dda2b6b72fb7ef4b5cbf2055c47ba40f7f7505bc26f781a46acd55a2d079ee5ac0dc8c6c0225e5367173e3db0c7b7d70b
7
- data.tar.gz: d0c8fbaffa54e3052f031c1e3bb94d6baefb186277386674da739a9d3e288d670e4c6c7a7afa3c760c492cd03680fa6845c1ca0f13f120564f773c343a477821
6
+ metadata.gz: 8b4cc3ccb8a881344891c1ded817044c805d3dada173b769725504679c7ab377ce2c078a2f950f093339a8ecd1892532d35777fc8f02231a0fdb8c39e33a5feb
7
+ data.tar.gz: 15d82db6a8ec57720936cbba69dad58ceb98369d7b273610a7594e40d2ba77d08565603676670591e6c1e8c46ff01b02e6fc869215c0f68a8d5f84a0c0c0a689
data/README.md CHANGED
@@ -230,5 +230,6 @@ Watch out for these caveats:
230
230
  * To [Charles G.](https://github.com/chuckg) for Rails 3.2 support and for making a desperately needed global code refactoring
231
231
  * To [Gonçalo Silva](https://github.com/goncalossilva) for supporting this gem prior to v0.4.3
232
232
  * To [Jean Boussier](https://github.com/byroot) for initial Rails 4.0.0 support
233
+ * To [Matijs van Zuijlen](https://github.com/mvz) for Rails 4.1 and 4.2 support
233
234
 
234
235
  See `LICENSE`.
@@ -13,7 +13,12 @@ module ActsAsParanoid
13
13
  result = belongs_to_without_deleted(target, scope, options)
14
14
 
15
15
  if with_deleted
16
- result.options[:with_deleted] = with_deleted
16
+ if result.is_a? Hash
17
+ result.values.last.options[:with_deleted] = with_deleted
18
+ else
19
+ result.options[:with_deleted] = with_deleted
20
+ end
21
+
17
22
  unless method_defined? "#{target}_with_unscoped"
18
23
  class_eval <<-RUBY, __FILE__, __LINE__
19
24
  def #{target}_with_unscoped(*args)
@@ -74,8 +74,14 @@ module ActsAsParanoid
74
74
  protected
75
75
 
76
76
  def without_paranoid_default_scope
77
- scope = self.all.with_default_scope
78
- scope.where_values.delete(paranoid_default_scope_sql)
77
+ scope = self.all
78
+ if scope.where_values.include? paranoid_default_scope_sql
79
+ # ActiveRecord 4.1
80
+ scope.where_values.delete(paranoid_default_scope_sql)
81
+ else
82
+ scope = scope.with_default_scope
83
+ scope.where_values.delete(paranoid_default_scope_sql)
84
+ end
79
85
 
80
86
  scope
81
87
  end
@@ -89,7 +95,7 @@ module ActsAsParanoid
89
95
  self.send(self.class.paranoid_column)
90
96
  end
91
97
 
92
- def destroy!
98
+ def destroy_fully!
93
99
  with_transaction_returning_status do
94
100
  run_callbacks :destroy do
95
101
  destroy_dependent_associations!
@@ -101,7 +107,7 @@ module ActsAsParanoid
101
107
  end
102
108
  end
103
109
 
104
- def destroy
110
+ def destroy!
105
111
  if !deleted?
106
112
  with_transaction_returning_status do
107
113
  run_callbacks :destroy do
@@ -112,10 +118,14 @@ module ActsAsParanoid
112
118
  end
113
119
  end
114
120
  else
115
- destroy!
121
+ destroy_fully!
116
122
  end
117
123
  end
118
124
 
125
+ def destroy
126
+ destroy!
127
+ end
128
+
119
129
  def recover(options={})
120
130
  options = {
121
131
  :recursive => self.class.paranoid_configuration[:recover_dependent_associations],
@@ -144,7 +154,7 @@ module ActsAsParanoid
144
154
  # We can only recover by window if both parent and dependant have a
145
155
  # paranoid column type of :time.
146
156
  if self.class.paranoid_column_type == :time && klass.paranoid_column_type == :time
147
- scope = scope.merge(klass.deleted_inside_time_window(paranoid_value, window))
157
+ scope = scope.deleted_inside_time_window(paranoid_value, window)
148
158
  end
149
159
 
150
160
  scope.each do |object|
@@ -11,10 +11,15 @@ module ActsAsParanoid
11
11
  finder_class = find_finder_class_for(record)
12
12
  table = finder_class.arel_table
13
13
 
14
- coder = record.class.serialized_attributes[attribute.to_s]
14
+ # TODO: Use record.class.column_types[attribute.to_s].coder ?
15
+ coder = record.class.column_types[attribute.to_s]
15
16
 
16
17
  if value && coder
17
- value = coder.dump value
18
+ value = if coder.respond_to? :type_cast_for_database
19
+ coder.type_cast_for_database value
20
+ else
21
+ coder.type_cast_for_write value
22
+ end
18
23
  end
19
24
 
20
25
  relation = build_relation(finder_class, table, attribute, value)
@@ -1,3 +1,3 @@
1
1
  module ActsAsParanoid
2
- VERSION = "0.5.0.beta1"
2
+ VERSION = "0.5.0.beta2"
3
3
  end
@@ -2,8 +2,6 @@ require 'test_helper'
2
2
 
3
3
  class AssociationsTest < ParanoidBaseTest
4
4
  def test_removal_with_associations
5
- # This test shows that the current implementation doesn't handle
6
- # assciation deletion correctly (when hard deleting via parent-object)
7
5
  paranoid_company_1 = ParanoidDestroyCompany.create! :name => "ParanoidDestroyCompany #1"
8
6
  paranoid_company_2 = ParanoidDeleteCompany.create! :name => "ParanoidDestroyCompany #1"
9
7
  paranoid_company_1.paranoid_products.create! :name => "ParanoidProduct #1"
@@ -19,13 +17,19 @@ class AssociationsTest < ParanoidBaseTest
19
17
  assert_equal 1, ParanoidDestroyCompany.with_deleted.count
20
18
  assert_equal 2, ParanoidProduct.with_deleted.count
21
19
 
22
- ParanoidDestroyCompany.with_deleted.first.destroy!
20
+ ParanoidDestroyCompany.with_deleted.first.destroy
23
21
  assert_equal 0, ParanoidDestroyCompany.count
24
22
  assert_equal 1, ParanoidProduct.count
25
23
  assert_equal 0, ParanoidDestroyCompany.with_deleted.count
26
24
  assert_equal 1, ParanoidProduct.with_deleted.count
27
25
 
28
- ParanoidDeleteCompany.with_deleted.first.destroy!
26
+ ParanoidDeleteCompany.first.destroy
27
+ assert_equal 0, ParanoidDeleteCompany.count
28
+ assert_equal 0, ParanoidProduct.count
29
+ assert_equal 1, ParanoidDeleteCompany.with_deleted.count
30
+ assert_equal 1, ParanoidProduct.with_deleted.count
31
+
32
+ ParanoidDeleteCompany.with_deleted.first.destroy
29
33
  assert_equal 0, ParanoidDeleteCompany.count
30
34
  assert_equal 0, ParanoidProduct.count
31
35
  assert_equal 0, ParanoidDeleteCompany.with_deleted.count
@@ -79,19 +83,19 @@ class AssociationsTest < ParanoidBaseTest
79
83
  end
80
84
 
81
85
  def test_belongs_to_options
82
- paranoid_time = ParanoidHasManyDependant.reflections[:paranoid_time]
86
+ paranoid_time = ParanoidHasManyDependant.reflections.with_indifferent_access[:paranoid_time]
83
87
  assert_equal :belongs_to, paranoid_time.macro
84
88
  assert_nil paranoid_time.options[:with_deleted]
85
89
  end
86
90
 
87
91
  def test_belongs_to_with_deleted_options
88
- paranoid_time_with_deleted = ParanoidHasManyDependant.reflections[:paranoid_time_with_deleted]
92
+ paranoid_time_with_deleted = ParanoidHasManyDependant.reflections.with_indifferent_access[:paranoid_time_with_deleted]
89
93
  assert_equal :belongs_to, paranoid_time_with_deleted.macro
90
94
  assert paranoid_time_with_deleted.options[:with_deleted]
91
95
  end
92
96
 
93
97
  def test_belongs_to_polymorphic_with_deleted_options
94
- paranoid_time_polymorphic_with_deleted = ParanoidHasManyDependant.reflections[:paranoid_time_polymorphic_with_deleted]
98
+ paranoid_time_polymorphic_with_deleted = ParanoidHasManyDependant.reflections.with_indifferent_access[:paranoid_time_polymorphic_with_deleted]
95
99
  assert_equal :belongs_to, paranoid_time_polymorphic_with_deleted.macro
96
100
  assert paranoid_time_polymorphic_with_deleted.options[:with_deleted]
97
101
  end
@@ -108,6 +112,9 @@ class AssociationsTest < ParanoidBaseTest
108
112
  child.destroy
109
113
  assert_paranoid_deletion(child)
110
114
 
115
+ parent.reload
116
+
117
+ assert_equal [], parent.paranoid_has_many_dependants.to_a
111
118
  assert_equal [child], parent.paranoid_has_many_dependants.with_deleted.to_a
112
119
  end
113
120
 
@@ -40,9 +40,9 @@ class ParanoidTest < ParanoidBaseTest
40
40
  end
41
41
 
42
42
  def test_real_removal
43
- ParanoidTime.first.destroy!
43
+ ParanoidTime.first.destroy_fully!
44
44
  ParanoidBoolean.delete_all!("name = 'extremely paranoid' OR name = 'really paranoid'")
45
- ParanoidString.first.destroy!
45
+ ParanoidString.first.destroy_fully!
46
46
  assert_equal 2, ParanoidTime.count
47
47
  assert_equal 1, ParanoidBoolean.count
48
48
  assert_equal 0, ParanoidString.count
@@ -144,12 +144,18 @@ class ParanoidTest < ParanoidBaseTest
144
144
  assert_equal 0, ParanoidHasOneDependant.count
145
145
  assert_equal 1, NotParanoid.count
146
146
  assert_equal 0, HasOneNotParanoid.count
147
+
148
+ assert_equal 3, ParanoidTime.with_deleted.count
149
+ assert_equal 4, ParanoidHasManyDependant.with_deleted.count
150
+ assert_equal 3, ParanoidBelongsDependant.with_deleted.count
151
+ assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.with_deleted.count
152
+ assert_equal 3, ParanoidHasOneDependant.with_deleted.count
147
153
  end
148
154
 
149
155
  def test_recursive_real_removal
150
156
  setup_recursive_tests
151
157
 
152
- @paranoid_time_object.destroy!
158
+ @paranoid_time_object.destroy_fully!
153
159
 
154
160
  assert_equal 0, ParanoidTime.only_deleted.count
155
161
  assert_equal 1, ParanoidHasManyDependant.only_deleted.count
@@ -37,7 +37,7 @@ class MultipleDefaultScopesTest < ParanoidBaseTest
37
37
  assert_equal 0, ParanoidHuman.only_deleted.count
38
38
  assert_equal 3, ParanoidHuman.unscoped.count
39
39
 
40
- ParanoidHuman.first.destroy!
40
+ ParanoidHuman.first.destroy_fully!
41
41
  assert_equal 1, ParanoidHuman.count
42
42
  assert_equal 1, ParanoidHuman.with_deleted.count
43
43
  assert_equal 0, ParanoidHuman.only_deleted.count
@@ -24,7 +24,7 @@ def setup_db
24
24
  t.integer :paranoid_belongs_dependant_id
25
25
  t.integer :not_paranoid_id
26
26
 
27
- t.timestamps
27
+ timestamps t
28
28
  end
29
29
 
30
30
  create_table :paranoid_booleans do |t|
@@ -32,7 +32,7 @@ def setup_db
32
32
  t.boolean :is_deleted
33
33
  t.integer :paranoid_time_id
34
34
 
35
- t.timestamps
35
+ timestamps t
36
36
  end
37
37
 
38
38
  create_table :paranoid_strings do |t|
@@ -44,14 +44,14 @@ def setup_db
44
44
  t.string :name
45
45
  t.integer :paranoid_time_id
46
46
 
47
- t.timestamps
47
+ timestamps t
48
48
  end
49
49
 
50
50
  create_table :has_one_not_paranoids do |t|
51
51
  t.string :name
52
52
  t.integer :paranoid_time_id
53
53
 
54
- t.timestamps
54
+ timestamps t
55
55
  end
56
56
 
57
57
  create_table :paranoid_has_many_dependants do |t|
@@ -61,14 +61,14 @@ def setup_db
61
61
  t.string :paranoid_time_polymorphic_with_deleted_type
62
62
  t.integer :paranoid_belongs_dependant_id
63
63
 
64
- t.timestamps
64
+ timestamps t
65
65
  end
66
66
 
67
67
  create_table :paranoid_belongs_dependants do |t|
68
68
  t.string :name
69
69
  t.datetime :deleted_at
70
70
 
71
- t.timestamps
71
+ timestamps t
72
72
  end
73
73
 
74
74
  create_table :paranoid_has_one_dependants do |t|
@@ -76,28 +76,28 @@ def setup_db
76
76
  t.datetime :deleted_at
77
77
  t.integer :paranoid_boolean_id
78
78
 
79
- t.timestamps
79
+ timestamps t
80
80
  end
81
81
 
82
82
  create_table :paranoid_with_callbacks do |t|
83
83
  t.string :name
84
84
  t.datetime :deleted_at
85
85
 
86
- t.timestamps
86
+ timestamps t
87
87
  end
88
88
 
89
89
  create_table :paranoid_destroy_companies do |t|
90
90
  t.string :name
91
91
  t.datetime :deleted_at
92
92
 
93
- t.timestamps
93
+ timestamps t
94
94
  end
95
95
 
96
96
  create_table :paranoid_delete_companies do |t|
97
97
  t.string :name
98
98
  t.datetime :deleted_at
99
99
 
100
- t.timestamps
100
+ timestamps t
101
101
  end
102
102
 
103
103
  create_table :paranoid_products do |t|
@@ -106,7 +106,7 @@ def setup_db
106
106
  t.string :name
107
107
  t.datetime :deleted_at
108
108
 
109
- t.timestamps
109
+ timestamps t
110
110
  end
111
111
 
112
112
  create_table :super_paranoids do |t|
@@ -114,38 +114,38 @@ def setup_db
114
114
  t.references :has_many_inherited_super_paranoidz
115
115
  t.datetime :deleted_at
116
116
 
117
- t.timestamps
117
+ timestamps t
118
118
  end
119
119
 
120
120
  create_table :has_many_inherited_super_paranoidzs do |t|
121
121
  t.references :super_paranoidz
122
122
  t.datetime :deleted_at
123
123
 
124
- t.timestamps
124
+ timestamps t
125
125
  end
126
126
 
127
127
  create_table :paranoid_many_many_parent_lefts do |t|
128
128
  t.string :name
129
- t.timestamps
129
+ timestamps t
130
130
  end
131
131
 
132
132
  create_table :paranoid_many_many_parent_rights do |t|
133
133
  t.string :name
134
- t.timestamps
134
+ timestamps t
135
135
  end
136
136
 
137
137
  create_table :paranoid_many_many_children do |t|
138
138
  t.integer :paranoid_many_many_parent_left_id
139
139
  t.integer :paranoid_many_many_parent_right_id
140
140
  t.datetime :deleted_at
141
- t.timestamps
141
+ timestamps t
142
142
  end
143
143
 
144
144
  create_table :paranoid_with_scoped_validations do |t|
145
145
  t.string :name
146
146
  t.string :category
147
147
  t.datetime :deleted_at
148
- t.timestamps
148
+ timestamps t
149
149
  end
150
150
 
151
151
  create_table :paranoid_forests do |t|
@@ -153,7 +153,7 @@ def setup_db
153
153
  t.boolean :rainforest
154
154
  t.datetime :deleted_at
155
155
 
156
- t.timestamps
156
+ timestamps t
157
157
  end
158
158
 
159
159
  create_table :paranoid_trees do |t|
@@ -161,14 +161,14 @@ def setup_db
161
161
  t.string :name
162
162
  t.datetime :deleted_at
163
163
 
164
- t.timestamps
164
+ timestamps t
165
165
  end
166
166
 
167
167
  create_table :paranoid_humen do |t|
168
168
  t.string :gender
169
169
  t.datetime :deleted_at
170
170
 
171
- t.timestamps
171
+ timestamps t
172
172
  end
173
173
 
174
174
  create_table :paranoid_androids do |t|
@@ -184,6 +184,11 @@ def setup_db
184
184
  end
185
185
  end
186
186
 
187
+ def timestamps(table)
188
+ table.column :created_at , :timestamp, :null => false
189
+ table.column :updated_at , :timestamp, :null => false
190
+ end
191
+
187
192
  def teardown_db
188
193
  ActiveRecord::Base.connection.tables.each do |table|
189
194
  ActiveRecord::Base.connection.drop_table(table)
@@ -389,8 +394,6 @@ end
389
394
  class ParanoidForest < ActiveRecord::Base
390
395
  acts_as_paranoid
391
396
 
392
- # HACK: scope throws an error on 1.8.7 because the logger isn't initialized (see https://github.com/Casecommons/pg_search/issues/26)
393
- require "active_support/core_ext/logger.rb"
394
397
  ActiveRecord::Base.logger = Logger.new(StringIO.new)
395
398
 
396
399
  scope :rainforest, lambda{ where(:rainforest => true) }
@@ -75,7 +75,7 @@ class RelationsTest < ParanoidBaseTest
75
75
 
76
76
  def test_fake_removal_through_relation
77
77
  # destroy: through a relation.
78
- ParanoidForest.rainforest.destroy(@paranoid_forest_3)
78
+ ParanoidForest.rainforest.destroy(@paranoid_forest_3.id)
79
79
  assert_equal 1, ParanoidForest.rainforest.count
80
80
  assert_equal 2, ParanoidForest.rainforest.with_deleted.count
81
81
  assert_equal 1, ParanoidForest.rainforest.only_deleted.count
@@ -95,8 +95,8 @@ class RelationsTest < ParanoidBaseTest
95
95
 
96
96
  # destroy: two-step through a relation
97
97
  paranoid_tree = @paranoid_forest_1.paranoid_trees.first
98
- @paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree)
99
- @paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree)
98
+ @paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree.id)
99
+ @paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree.id)
100
100
  assert_equal 1, @paranoid_forest_1.paranoid_trees(true).count
101
101
  assert_equal 1, @paranoid_forest_1.paranoid_trees(true).with_deleted.count
102
102
  assert_equal 0, @paranoid_forest_1.paranoid_trees(true).only_deleted.count
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_paranoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.beta1
4
+ version: 0.5.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Scott
@@ -10,92 +10,98 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-26 00:00:00.000000000 Z
13
+ date: 2015-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '4.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '4.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: activesupport
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '4.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '4.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: bundler
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.5'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.5'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '>='
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rdoc
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: minitest
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ~>
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '4.0'
92
+ - - "<="
93
+ - !ruby/object:Gem::Version
94
+ version: '6.0'
92
95
  type: :development
93
96
  prerelease: false
94
97
  version_requirements: !ruby/object:Gem::Requirement
95
98
  requirements:
96
- - - ~>
99
+ - - ">="
97
100
  - !ruby/object:Gem::Version
98
101
  version: '4.0'
102
+ - - "<="
103
+ - !ruby/object:Gem::Version
104
+ version: '6.0'
99
105
  description: Check the home page for more in-depth information.
100
106
  email:
101
107
  - e@zzak.io
@@ -128,17 +134,17 @@ require_paths:
128
134
  - lib
129
135
  required_ruby_version: !ruby/object:Gem::Requirement
130
136
  requirements:
131
- - - '>='
137
+ - - ">="
132
138
  - !ruby/object:Gem::Version
133
139
  version: '0'
134
140
  required_rubygems_version: !ruby/object:Gem::Requirement
135
141
  requirements:
136
- - - '>='
142
+ - - ">="
137
143
  - !ruby/object:Gem::Version
138
144
  version: 1.3.6
139
145
  requirements: []
140
146
  rubyforge_project:
141
- rubygems_version: 2.4.1
147
+ rubygems_version: 2.4.5.1
142
148
  signing_key:
143
149
  specification_version: 4
144
150
  summary: Active Record plugin which allows you to hide and restore records without