mongoid_paranoia 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +117 -117
- data/lib/mongoid/paranoia/configuration.rb +13 -11
- data/lib/mongoid/paranoia/monkey_patches.rb +114 -113
- data/lib/mongoid/paranoia/version.rb +7 -5
- data/lib/mongoid/paranoia.rb +196 -203
- data/lib/mongoid-paranoia.rb +3 -1
- data/lib/mongoid_paranoia.rb +3 -1
- data/perf/scope.rb +65 -64
- data/spec/app/models/address.rb +71 -71
- data/spec/app/models/appointment.rb +7 -7
- data/spec/app/models/author.rb +6 -6
- data/spec/app/models/fish.rb +8 -8
- data/spec/app/models/paranoid_phone.rb +25 -25
- data/spec/app/models/paranoid_post.rb +65 -65
- data/spec/app/models/person.rb +21 -21
- data/spec/app/models/phone.rb +11 -11
- data/spec/app/models/relations.rb +247 -247
- data/spec/app/models/tag.rb +6 -6
- data/spec/app/models/title.rb +4 -4
- data/spec/mongoid/configuration_spec.rb +19 -19
- data/spec/mongoid/document_spec.rb +21 -21
- data/spec/mongoid/nested_attributes_spec.rb +164 -164
- data/spec/mongoid/paranoia_spec.rb +887 -887
- data/spec/mongoid/scoping_spec.rb +55 -55
- data/spec/mongoid/validatable/uniqueness_spec.rb +74 -74
- data/spec/spec_helper.rb +43 -75
- metadata +36 -25
data/spec/app/models/address.rb
CHANGED
@@ -1,71 +1,71 @@
|
|
1
|
-
class Address
|
2
|
-
include Mongoid::Document
|
3
|
-
|
4
|
-
field :_id, type: String, default: ->{ street.try(:parameterize) }
|
5
|
-
|
6
|
-
attr_accessor :mode
|
7
|
-
|
8
|
-
field :address_type
|
9
|
-
field :number, type: Integer
|
10
|
-
field :street
|
11
|
-
field :city
|
12
|
-
field :state
|
13
|
-
field :post_code
|
14
|
-
field :parent_title
|
15
|
-
field :services, type: Array
|
16
|
-
field :latlng, type: Array
|
17
|
-
field :map, type: Hash
|
18
|
-
field :move_in, type: DateTime
|
19
|
-
field :s, type: String, as: :suite
|
20
|
-
field :name, localize: true
|
21
|
-
|
22
|
-
embeds_one :code, validate: false
|
23
|
-
embeds_one :target, as: :targetable, validate: false
|
24
|
-
|
25
|
-
embedded_in :addressable, polymorphic: true do
|
26
|
-
def extension
|
27
|
-
"Testing"
|
28
|
-
end
|
29
|
-
def doctor?
|
30
|
-
title == "Dr"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
accepts_nested_attributes_for :code, :target
|
35
|
-
|
36
|
-
belongs_to :account
|
37
|
-
|
38
|
-
scope :without_postcode, -> {where(postcode: nil)}
|
39
|
-
scope :rodeo, -> {
|
40
|
-
where(street: "Rodeo Dr") do
|
41
|
-
def mansion?
|
42
|
-
all? { |address| address.street == "Rodeo Dr" }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
}
|
46
|
-
|
47
|
-
validates_presence_of :street, on: :update
|
48
|
-
validates_format_of :street, with: /\D/, allow_nil: true
|
49
|
-
|
50
|
-
def set_parent=(set = false)
|
51
|
-
self.parent_title = addressable.title if set
|
52
|
-
end
|
53
|
-
|
54
|
-
def <=>(other)
|
55
|
-
street <=> other.street
|
56
|
-
end
|
57
|
-
|
58
|
-
class << self
|
59
|
-
def california
|
60
|
-
where(state: "CA")
|
61
|
-
end
|
62
|
-
|
63
|
-
def homes
|
64
|
-
where(address_type: "Home")
|
65
|
-
end
|
66
|
-
|
67
|
-
def streets
|
68
|
-
all.map(&:street)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
1
|
+
class Address
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :_id, type: String, default: ->{ street.try(:parameterize) }
|
5
|
+
|
6
|
+
attr_accessor :mode
|
7
|
+
|
8
|
+
field :address_type
|
9
|
+
field :number, type: Integer
|
10
|
+
field :street
|
11
|
+
field :city
|
12
|
+
field :state
|
13
|
+
field :post_code
|
14
|
+
field :parent_title
|
15
|
+
field :services, type: Array
|
16
|
+
field :latlng, type: Array
|
17
|
+
field :map, type: Hash
|
18
|
+
field :move_in, type: DateTime
|
19
|
+
field :s, type: String, as: :suite
|
20
|
+
field :name, localize: true
|
21
|
+
|
22
|
+
embeds_one :code, validate: false
|
23
|
+
embeds_one :target, as: :targetable, validate: false
|
24
|
+
|
25
|
+
embedded_in :addressable, polymorphic: true do
|
26
|
+
def extension
|
27
|
+
"Testing"
|
28
|
+
end
|
29
|
+
def doctor?
|
30
|
+
title == "Dr"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
accepts_nested_attributes_for :code, :target
|
35
|
+
|
36
|
+
belongs_to :account
|
37
|
+
|
38
|
+
scope :without_postcode, -> {where(postcode: nil)}
|
39
|
+
scope :rodeo, -> {
|
40
|
+
where(street: "Rodeo Dr") do
|
41
|
+
def mansion?
|
42
|
+
all? { |address| address.street == "Rodeo Dr" }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
validates_presence_of :street, on: :update
|
48
|
+
validates_format_of :street, with: /\D/, allow_nil: true
|
49
|
+
|
50
|
+
def set_parent=(set = false)
|
51
|
+
self.parent_title = addressable.title if set
|
52
|
+
end
|
53
|
+
|
54
|
+
def <=>(other)
|
55
|
+
street <=> other.street
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def california
|
60
|
+
where(state: "CA")
|
61
|
+
end
|
62
|
+
|
63
|
+
def homes
|
64
|
+
where(address_type: "Home")
|
65
|
+
end
|
66
|
+
|
67
|
+
def streets
|
68
|
+
all.map(&:street)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class Appointment
|
2
|
-
include Mongoid::Document
|
3
|
-
field :active, type: Boolean, default: true
|
4
|
-
field :timed, type: Boolean, default: true
|
5
|
-
embedded_in :person
|
6
|
-
default_scope ->{where(active: true)}
|
7
|
-
end
|
1
|
+
class Appointment
|
2
|
+
include Mongoid::Document
|
3
|
+
field :active, type: Boolean, default: true
|
4
|
+
field :timed, type: Boolean, default: true
|
5
|
+
embedded_in :person
|
6
|
+
default_scope ->{where(active: true)}
|
7
|
+
end
|
data/spec/app/models/author.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class Author
|
2
|
-
include Mongoid::Document
|
3
|
-
field :name, type: String
|
4
|
-
|
5
|
-
belongs_to :post, class_name: "ParanoidPost"
|
6
|
-
end
|
1
|
+
class Author
|
2
|
+
include Mongoid::Document
|
3
|
+
field :name, type: String
|
4
|
+
|
5
|
+
belongs_to :post, class_name: "ParanoidPost"
|
6
|
+
end
|
data/spec/app/models/fish.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
class Fish
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Paranoia
|
4
|
-
|
5
|
-
def self.fresh
|
6
|
-
where(fresh: true)
|
7
|
-
end
|
8
|
-
end
|
1
|
+
class Fish
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Paranoia
|
4
|
+
|
5
|
+
def self.fresh
|
6
|
+
where(fresh: true)
|
7
|
+
end
|
8
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
class ParanoidPhone
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Paranoia
|
4
|
-
|
5
|
-
attr_accessor :after_destroy_called, :before_destroy_called
|
6
|
-
|
7
|
-
field :number, type: String
|
8
|
-
|
9
|
-
embedded_in :person
|
10
|
-
|
11
|
-
before_destroy :before_destroy_stub, :halt_me
|
12
|
-
after_destroy :after_destroy_stub
|
13
|
-
|
14
|
-
def before_destroy_stub
|
15
|
-
self.before_destroy_called = true
|
16
|
-
end
|
17
|
-
|
18
|
-
def after_destroy_stub
|
19
|
-
self.after_destroy_called = true
|
20
|
-
end
|
21
|
-
|
22
|
-
def halt_me
|
23
|
-
throw :abort if person.age == 42
|
24
|
-
end
|
25
|
-
end
|
1
|
+
class ParanoidPhone
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Paranoia
|
4
|
+
|
5
|
+
attr_accessor :after_destroy_called, :before_destroy_called
|
6
|
+
|
7
|
+
field :number, type: String
|
8
|
+
|
9
|
+
embedded_in :person
|
10
|
+
|
11
|
+
before_destroy :before_destroy_stub, :halt_me
|
12
|
+
after_destroy :after_destroy_stub
|
13
|
+
|
14
|
+
def before_destroy_stub
|
15
|
+
self.before_destroy_called = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def after_destroy_stub
|
19
|
+
self.after_destroy_called = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def halt_me
|
23
|
+
throw :abort if person.age == 42
|
24
|
+
end
|
25
|
+
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
class ParanoidPost
|
2
|
-
include Mongoid::Document
|
3
|
-
include Mongoid::Paranoia
|
4
|
-
|
5
|
-
field :title, type: String
|
6
|
-
|
7
|
-
attr_accessor :after_destroy_called, :before_destroy_called,
|
8
|
-
:after_restore_called, :before_restore_called,
|
9
|
-
:after_remove_called, :before_remove_called,
|
10
|
-
:around_before_restore_called, :around_after_restore_called
|
11
|
-
|
12
|
-
belongs_to :person
|
13
|
-
|
14
|
-
has_and_belongs_to_many :tags
|
15
|
-
has_many :authors, dependent: :delete_all, inverse_of: :post
|
16
|
-
has_many :titles, dependent: :restrict_with_error
|
17
|
-
|
18
|
-
scope :recent, -> {where(created_at: { "$lt" => Time.now, "$gt" => 30.days.ago })}
|
19
|
-
|
20
|
-
before_destroy :before_destroy_stub
|
21
|
-
after_destroy :after_destroy_stub
|
22
|
-
|
23
|
-
before_remove :before_remove_stub
|
24
|
-
after_remove :after_remove_stub
|
25
|
-
|
26
|
-
before_restore :before_restore_stub
|
27
|
-
after_restore :after_restore_stub
|
28
|
-
around_restore :around_restore_stub
|
29
|
-
|
30
|
-
def before_destroy_stub
|
31
|
-
self.before_destroy_called = true
|
32
|
-
end
|
33
|
-
|
34
|
-
def after_destroy_stub
|
35
|
-
self.after_destroy_called = true
|
36
|
-
end
|
37
|
-
|
38
|
-
def before_remove_stub
|
39
|
-
self.before_remove_called = true
|
40
|
-
end
|
41
|
-
|
42
|
-
def after_remove_stub
|
43
|
-
self.after_remove_called = true
|
44
|
-
end
|
45
|
-
|
46
|
-
def before_restore_stub
|
47
|
-
self.before_restore_called = true
|
48
|
-
end
|
49
|
-
|
50
|
-
def after_restore_stub
|
51
|
-
self.after_restore_called = true
|
52
|
-
end
|
53
|
-
|
54
|
-
def around_restore_stub
|
55
|
-
self.around_before_restore_called = true
|
56
|
-
yield
|
57
|
-
self.around_after_restore_called = true
|
58
|
-
end
|
59
|
-
|
60
|
-
class << self
|
61
|
-
def old
|
62
|
-
where(created_at: { "$lt" => 30.days.ago })
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
class ParanoidPost
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Paranoia
|
4
|
+
|
5
|
+
field :title, type: String
|
6
|
+
|
7
|
+
attr_accessor :after_destroy_called, :before_destroy_called,
|
8
|
+
:after_restore_called, :before_restore_called,
|
9
|
+
:after_remove_called, :before_remove_called,
|
10
|
+
:around_before_restore_called, :around_after_restore_called
|
11
|
+
|
12
|
+
belongs_to :person
|
13
|
+
|
14
|
+
has_and_belongs_to_many :tags
|
15
|
+
has_many :authors, dependent: :delete_all, inverse_of: :post
|
16
|
+
has_many :titles, dependent: :restrict_with_error
|
17
|
+
|
18
|
+
scope :recent, -> {where(created_at: { "$lt" => Time.now, "$gt" => 30.days.ago })}
|
19
|
+
|
20
|
+
before_destroy :before_destroy_stub
|
21
|
+
after_destroy :after_destroy_stub
|
22
|
+
|
23
|
+
before_remove :before_remove_stub
|
24
|
+
after_remove :after_remove_stub
|
25
|
+
|
26
|
+
before_restore :before_restore_stub
|
27
|
+
after_restore :after_restore_stub
|
28
|
+
around_restore :around_restore_stub
|
29
|
+
|
30
|
+
def before_destroy_stub
|
31
|
+
self.before_destroy_called = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_destroy_stub
|
35
|
+
self.after_destroy_called = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def before_remove_stub
|
39
|
+
self.before_remove_called = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_remove_stub
|
43
|
+
self.after_remove_called = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def before_restore_stub
|
47
|
+
self.before_restore_called = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def after_restore_stub
|
51
|
+
self.after_restore_called = true
|
52
|
+
end
|
53
|
+
|
54
|
+
def around_restore_stub
|
55
|
+
self.around_before_restore_called = true
|
56
|
+
yield
|
57
|
+
self.around_after_restore_called = true
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
def old
|
62
|
+
where(created_at: { "$lt" => 30.days.ago })
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/app/models/person.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
class Person
|
2
|
-
include Mongoid::Document
|
3
|
-
|
4
|
-
field :age, type: Integer, default: "100"
|
5
|
-
field :score, type: Integer
|
6
|
-
|
7
|
-
attr_reader :rescored
|
8
|
-
|
9
|
-
embeds_many :phone_numbers, class_name: "Phone", validate: false
|
10
|
-
embeds_many :phones, store_as: :mobile_phones, validate: false
|
11
|
-
embeds_many :addresses, as: :addressable, validate: false
|
12
|
-
|
13
|
-
embeds_many :appointments, validate: false
|
14
|
-
embeds_many :paranoid_phones, validate: false
|
15
|
-
|
16
|
-
has_many :paranoid_posts, validate: false
|
17
|
-
belongs_to :paranoid_post
|
18
|
-
|
19
|
-
accepts_nested_attributes_for :addresses
|
20
|
-
accepts_nested_attributes_for :paranoid_phones
|
21
|
-
end
|
1
|
+
class Person
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :age, type: Integer, default: "100"
|
5
|
+
field :score, type: Integer
|
6
|
+
|
7
|
+
attr_reader :rescored
|
8
|
+
|
9
|
+
embeds_many :phone_numbers, class_name: "Phone", validate: false
|
10
|
+
embeds_many :phones, store_as: :mobile_phones, validate: false
|
11
|
+
embeds_many :addresses, as: :addressable, validate: false
|
12
|
+
|
13
|
+
embeds_many :appointments, validate: false
|
14
|
+
embeds_many :paranoid_phones, validate: false
|
15
|
+
|
16
|
+
has_many :paranoid_posts, validate: false
|
17
|
+
belongs_to :paranoid_post
|
18
|
+
|
19
|
+
accepts_nested_attributes_for :addresses
|
20
|
+
accepts_nested_attributes_for :paranoid_phones
|
21
|
+
end
|
data/spec/app/models/phone.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class Phone
|
2
|
-
include Mongoid::Document
|
3
|
-
|
4
|
-
attr_accessor :number_in_observer
|
5
|
-
|
6
|
-
field :_id, type: String, default: ->{ number }
|
7
|
-
|
8
|
-
field :number
|
9
|
-
embeds_one :country_code
|
10
|
-
embedded_in :person
|
11
|
-
end
|
1
|
+
class Phone
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
attr_accessor :number_in_observer
|
5
|
+
|
6
|
+
field :_id, type: String, default: ->{ number }
|
7
|
+
|
8
|
+
field :number
|
9
|
+
embeds_one :country_code
|
10
|
+
embedded_in :person
|
11
|
+
end
|