mongoid_paranoia 0.4.1 → 0.5.0

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
  SHA256:
3
- metadata.gz: 1a91dadeb276e443e5060c0365961ca55f0a64e52dc6d98ec9d1f8c27323e4c9
4
- data.tar.gz: 71acb61e9ac0c78c37b9e70c9985bcfbbd778364b0e4394ae087dbfc3c260955
3
+ metadata.gz: ec456afdb66a1a23fdb5dc73db06b9dc6344932f8aa3c95b378ca60560aea474
4
+ data.tar.gz: b80b6cfaedfb9523b9dbfe791d586493eb4c9d3e65b7286d3cdc2010d8f9874e
5
5
  SHA512:
6
- metadata.gz: 3c1516b87ec542acbd708b0d5aca3a372b2cdc16123df093223d2159eb8b4a8c2c13720b4bd8492ada399e58308a49e5ba1895273fb18bac2bd784978e4f282c
7
- data.tar.gz: 71eb2a17add46c46f97f6b5fab35907765c6ba1e97ebc24016e0314feee8d0bf9ac0964e3e45910d260ea3b1abb4e9492ac4928181a6307772347f919f16a463
6
+ metadata.gz: 3aff3ad8f7f06f0a1498143baf6cf72d58c24b99b3a4f0bfb19fd314ec836625356291989293ddee2dc230d148dda65f84bc153660bd00566ba8bc727e21ee9f
7
+ data.tar.gz: 5322c2f12d84591a8e0bc3463faf1e82571f09c5877bc3a3f7bcfbf7c10c87e198bb8be2add2ab42c6e71341df77fdbe7dbe368ccc476d7e44c8f41839c283cb
@@ -50,23 +50,6 @@ module Mongoid
50
50
  define_model_callbacks :remove
51
51
  end
52
52
 
53
- # Delete the paranoid +Document+ from the database completely. This will
54
- # run the destroy callbacks.
55
- #
56
- # @example Hard destroy the document.
57
- # document.destroy!
58
- #
59
- # @return [ true, false ] If the operation succeeded.
60
- #
61
- # @since 1.0.0
62
- def destroy!
63
- run_callbacks(:destroy) do
64
- run_callbacks(:remove) do
65
- delete!
66
- end
67
- end
68
- end
69
-
70
53
  # Override the persisted method to allow for the paranoia gem.
71
54
  # If a paranoid record is selected, then we only want to check
72
55
  # if it's a new record, not if it is "destroyed"
@@ -92,34 +75,41 @@ module Mongoid
92
75
  # @return [ true ] True.
93
76
  #
94
77
  # @since 1.0.0
95
- alias orig_remove :remove
78
+ alias :orig_delete :delete
96
79
 
97
80
  def remove(_ = {})
98
- return false unless catch(:abort) do
99
- if respond_to?(:apply_destroy_dependencies!)
100
- apply_destroy_dependencies!
101
- else
102
- apply_delete_dependencies!
103
- end
104
- end
105
81
  time = self.deleted_at = Time.now
106
82
  _paranoia_update('$set' => { paranoid_field => time })
107
83
  @destroyed = true
108
84
  true
109
85
  end
110
86
 
111
- alias delete :remove
87
+ alias :delete :remove
88
+ alias :delete! :orig_delete
112
89
 
113
- # Delete the paranoid +Document+ from the database completely.
90
+ # Delete the paranoid +Document+ from the database completely. This will
91
+ # run the destroy and remove callbacks.
114
92
  #
115
- # @example Hard delete the document.
116
- # document.delete!
93
+ # @example Hard destroy the document.
94
+ # document.destroy!
117
95
  #
118
96
  # @return [ true, false ] If the operation succeeded.
119
97
  #
120
98
  # @since 1.0.0
121
- def delete!
122
- orig_remove
99
+ def destroy!(options = {})
100
+ raise Errors::ReadonlyDocument.new(self.class) if readonly?
101
+ self.flagged_for_destroy = true
102
+ result = run_callbacks(:destroy) do
103
+ run_callbacks(:remove) do
104
+ if catch(:abort) { apply_destroy_dependencies! }
105
+ delete!(options || {})
106
+ else
107
+ false
108
+ end
109
+ end
110
+ end
111
+ self.flagged_for_destroy = false
112
+ result
123
113
  end
124
114
 
125
115
  # Determines if this document is destroyed.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Paranoia
5
- VERSION = '0.4.1'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -531,10 +531,10 @@ describe Mongoid::Paranoia do
531
531
  post.delete!
532
532
  end
533
533
 
534
- it "cascades the dependent option" do
534
+ it "does not cascade the dependent option" do
535
535
  expect {
536
536
  author.reload
537
- }.to raise_error(Mongoid::Errors::DocumentNotFound)
537
+ }.to_not raise_error(Mongoid::Errors::DocumentNotFound)
538
538
  end
539
539
  end
540
540
  end
@@ -613,10 +613,10 @@ describe Mongoid::Paranoia do
613
613
  post.delete
614
614
  end
615
615
 
616
- it "cascades the dependent option" do
616
+ it "does not cascade the dependent option" do
617
617
  expect {
618
618
  author.reload
619
- }.to raise_error(Mongoid::Errors::DocumentNotFound)
619
+ }.to_not raise_error(Mongoid::Errors::DocumentNotFound)
620
620
  end
621
621
  end
622
622
 
@@ -637,8 +637,8 @@ describe Mongoid::Paranoia do
637
637
  end
638
638
  end
639
639
 
640
- it "does not destroy the document" do
641
- expect(post).not_to be_destroyed
640
+ it "ignores restrict and destroys the document" do
641
+ expect(post).to be_destroyed
642
642
  end
643
643
  end
644
644
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -15,20 +15,14 @@ dependencies:
15
15
  name: mongoid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '7.0'
21
- - - "<"
18
+ - - "~>"
22
19
  - !ruby/object:Gem::Version
23
20
  version: '7.3'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: '7.0'
31
- - - "<"
25
+ - - "~>"
32
26
  - !ruby/object:Gem::Version
33
27
  version: '7.3'
34
28
  - !ruby/object:Gem::Dependency