mongoid-paranoia 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -0
- data/README.md +65 -0
- data/Rakefile +7 -0
- data/lib/mongoid/paranoia.rb +133 -0
- data/lib/mongoid/paranoia/version.rb +5 -0
- data/mongoid-paranoia.gemspec +18 -0
- data/spec/app/models/account.rb +32 -0
- data/spec/app/models/acolyte.rb +16 -0
- data/spec/app/models/actor.rb +19 -0
- data/spec/app/models/actor_observer.rb +15 -0
- data/spec/app/models/actress.rb +2 -0
- data/spec/app/models/address.rb +72 -0
- data/spec/app/models/address_component.rb +5 -0
- data/spec/app/models/address_number.rb +6 -0
- data/spec/app/models/agency.rb +5 -0
- data/spec/app/models/agent.rb +12 -0
- data/spec/app/models/album.rb +14 -0
- data/spec/app/models/alert.rb +5 -0
- data/spec/app/models/animal.rb +25 -0
- data/spec/app/models/answer.rb +4 -0
- data/spec/app/models/appointment.rb +7 -0
- data/spec/app/models/article.rb +13 -0
- data/spec/app/models/artist.rb +66 -0
- data/spec/app/models/artwork.rb +4 -0
- data/spec/app/models/augmentation.rb +11 -0
- data/spec/app/models/author.rb +6 -0
- data/spec/app/models/band.rb +25 -0
- data/spec/app/models/bar.rb +9 -0
- data/spec/app/models/basic.rb +6 -0
- data/spec/app/models/bed.rb +1 -0
- data/spec/app/models/big_palette.rb +2 -0
- data/spec/app/models/birthday.rb +13 -0
- data/spec/app/models/book.rb +12 -0
- data/spec/app/models/breed.rb +4 -0
- data/spec/app/models/browser.rb +6 -0
- data/spec/app/models/building.rb +7 -0
- data/spec/app/models/building_address.rb +7 -0
- data/spec/app/models/bus.rb +7 -0
- data/spec/app/models/business.rb +5 -0
- data/spec/app/models/callback_recorder.rb +25 -0
- data/spec/app/models/callback_test.rb +9 -0
- data/spec/app/models/canvas.rb +25 -0
- data/spec/app/models/car.rb +1 -0
- data/spec/app/models/cat.rb +8 -0
- data/spec/app/models/category.rb +8 -0
- data/spec/app/models/child.rb +4 -0
- data/spec/app/models/child_doc.rb +22 -0
- data/spec/app/models/church.rb +4 -0
- data/spec/app/models/circle.rb +3 -0
- data/spec/app/models/circuit.rb +4 -0
- data/spec/app/models/circus.rb +7 -0
- data/spec/app/models/code.rb +5 -0
- data/spec/app/models/comment.rb +16 -0
- data/spec/app/models/contractor.rb +7 -0
- data/spec/app/models/cookie.rb +6 -0
- data/spec/app/models/country_code.rb +8 -0
- data/spec/app/models/definition.rb +7 -0
- data/spec/app/models/description.rb +11 -0
- data/spec/app/models/dictionary.rb +10 -0
- data/spec/app/models/division.rb +10 -0
- data/spec/app/models/doctor.rb +12 -0
- data/spec/app/models/dog.rb +6 -0
- data/spec/app/models/dokument.rb +5 -0
- data/spec/app/models/driver.rb +7 -0
- data/spec/app/models/drug.rb +8 -0
- data/spec/app/models/email.rb +6 -0
- data/spec/app/models/employer.rb +5 -0
- data/spec/app/models/entry.rb +6 -0
- data/spec/app/models/eraser.rb +1 -0
- data/spec/app/models/event.rb +22 -0
- data/spec/app/models/exhibition.rb +4 -0
- data/spec/app/models/exhibitor.rb +5 -0
- data/spec/app/models/eye.rb +9 -0
- data/spec/app/models/eye_bowl.rb +9 -0
- data/spec/app/models/face.rb +8 -0
- data/spec/app/models/favorite.rb +6 -0
- data/spec/app/models/filesystem.rb +4 -0
- data/spec/app/models/firefox.rb +4 -0
- data/spec/app/models/fish.rb +8 -0
- data/spec/app/models/folder.rb +7 -0
- data/spec/app/models/folder_item.rb +9 -0
- data/spec/app/models/fruits.rb +28 -0
- data/spec/app/models/game.rb +21 -0
- data/spec/app/models/ghost.rb +7 -0
- data/spec/app/models/home.rb +4 -0
- data/spec/app/models/house.rb +8 -0
- data/spec/app/models/html_writer.rb +3 -0
- data/spec/app/models/image.rb +22 -0
- data/spec/app/models/implant.rb +16 -0
- data/spec/app/models/item.rb +12 -0
- data/spec/app/models/jar.rb +7 -0
- data/spec/app/models/label.rb +40 -0
- data/spec/app/models/language.rb +5 -0
- data/spec/app/models/lat_lng.rb +15 -0
- data/spec/app/models/league.rb +11 -0
- data/spec/app/models/learner.rb +2 -0
- data/spec/app/models/line_item.rb +6 -0
- data/spec/app/models/location.rb +8 -0
- data/spec/app/models/login.rb +8 -0
- data/spec/app/models/manufacturer.rb +7 -0
- data/spec/app/models/meat.rb +4 -0
- data/spec/app/models/membership.rb +4 -0
- data/spec/app/models/mixed_drink.rb +4 -0
- data/spec/app/models/movie.rb +12 -0
- data/spec/app/models/my_hash.rb +2 -0
- data/spec/app/models/name.rb +23 -0
- data/spec/app/models/node.rb +5 -0
- data/spec/app/models/note.rb +12 -0
- data/spec/app/models/ordered_post.rb +6 -0
- data/spec/app/models/ordered_preference.rb +6 -0
- data/spec/app/models/oscar.rb +15 -0
- data/spec/app/models/override.rb +16 -0
- data/spec/app/models/ownable.rb +6 -0
- data/spec/app/models/owner.rb +6 -0
- data/spec/app/models/page.rb +5 -0
- data/spec/app/models/page_question.rb +4 -0
- data/spec/app/models/palette.rb +7 -0
- data/spec/app/models/paranoid_phone.rb +25 -0
- data/spec/app/models/paranoid_post.rb +36 -0
- data/spec/app/models/parent.rb +5 -0
- data/spec/app/models/parent_doc.rb +6 -0
- data/spec/app/models/passport.rb +5 -0
- data/spec/app/models/patient.rb +9 -0
- data/spec/app/models/pdf_writer.rb +3 -0
- data/spec/app/models/pencil.rb +1 -0
- data/spec/app/models/person.rb +200 -0
- data/spec/app/models/pet.rb +23 -0
- data/spec/app/models/pet_owner.rb +6 -0
- data/spec/app/models/phone.rb +11 -0
- data/spec/app/models/phone_observer.rb +6 -0
- data/spec/app/models/pizza.rb +7 -0
- data/spec/app/models/player.rb +35 -0
- data/spec/app/models/post.rb +42 -0
- data/spec/app/models/powerup.rb +11 -0
- data/spec/app/models/preference.rb +9 -0
- data/spec/app/models/princess.rb +8 -0
- data/spec/app/models/product.rb +15 -0
- data/spec/app/models/profile.rb +5 -0
- data/spec/app/models/pronunciation.rb +5 -0
- data/spec/app/models/purchase.rb +4 -0
- data/spec/app/models/question.rb +8 -0
- data/spec/app/models/quiz.rb +10 -0
- data/spec/app/models/rating.rb +8 -0
- data/spec/app/models/record.rb +46 -0
- data/spec/app/models/registry.rb +4 -0
- data/spec/app/models/role.rb +5 -0
- data/spec/app/models/root_category.rb +4 -0
- data/spec/app/models/sandwich.rb +4 -0
- data/spec/app/models/scheduler.rb +7 -0
- data/spec/app/models/seo.rb +7 -0
- data/spec/app/models/series.rb +4 -0
- data/spec/app/models/server.rb +13 -0
- data/spec/app/models/service.rb +22 -0
- data/spec/app/models/shape.rb +12 -0
- data/spec/app/models/shelf.rb +5 -0
- data/spec/app/models/shipping_container.rb +5 -0
- data/spec/app/models/shop.rb +6 -0
- data/spec/app/models/short_agent.rb +4 -0
- data/spec/app/models/short_quiz.rb +5 -0
- data/spec/app/models/slave.rb +6 -0
- data/spec/app/models/song.rb +8 -0
- data/spec/app/models/square.rb +4 -0
- data/spec/app/models/strategy.rb +3 -0
- data/spec/app/models/sub_item.rb +3 -0
- data/spec/app/models/survey.rb +5 -0
- data/spec/app/models/symptom.rb +6 -0
- data/spec/app/models/tag.rb +8 -0
- data/spec/app/models/target.rb +5 -0
- data/spec/app/models/template.rb +5 -0
- data/spec/app/models/thing.rb +9 -0
- data/spec/app/models/title.rb +4 -0
- data/spec/app/models/tool.rb +8 -0
- data/spec/app/models/topping.rb +5 -0
- data/spec/app/models/track.rb +38 -0
- data/spec/app/models/translation.rb +5 -0
- data/spec/app/models/tree.rb +9 -0
- data/spec/app/models/truck.rb +3 -0
- data/spec/app/models/user.rb +20 -0
- data/spec/app/models/user_account.rb +10 -0
- data/spec/app/models/validation_callback.rb +10 -0
- data/spec/app/models/vehicle.rb +11 -0
- data/spec/app/models/version.rb +5 -0
- data/spec/app/models/vet_visit.rb +5 -0
- data/spec/app/models/video.rb +17 -0
- data/spec/app/models/weapon.rb +11 -0
- data/spec/app/models/wiki_page.rb +17 -0
- data/spec/app/models/word.rb +12 -0
- data/spec/app/models/word_origin.rb +11 -0
- data/spec/app/models/writer.rb +11 -0
- data/spec/config/mongoid.yml +40 -0
- data/spec/mongoid/paranoia_spec.rb +715 -0
- data/spec/spec_helper.rb +80 -0
- metadata +271 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
class Pet
|
2
|
+
include Mongoid::Document
|
3
|
+
field :name
|
4
|
+
field :weight, type: Float, default: 0.0
|
5
|
+
embeds_many :vet_visits
|
6
|
+
embedded_in :pet_owner
|
7
|
+
|
8
|
+
after_destroy :set_destroy_flag
|
9
|
+
attr_writer :destroy_flag
|
10
|
+
|
11
|
+
def set_destroy_flag
|
12
|
+
@destroy_flag = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy_flag
|
16
|
+
@destroy_flag ||= false
|
17
|
+
end
|
18
|
+
|
19
|
+
def visits_count=(count)
|
20
|
+
vet_visits.destroy_all
|
21
|
+
count.times { vet_visits.new }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Player
|
2
|
+
include Mongoid::Document
|
3
|
+
field :active, type: Boolean
|
4
|
+
field :frags, type: Integer
|
5
|
+
field :deaths, type: Integer
|
6
|
+
field :impressions, type: Integer, default: 0
|
7
|
+
field :status
|
8
|
+
|
9
|
+
scope :active, where(active: true) do
|
10
|
+
def extension
|
11
|
+
"extension"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
scope :inactive, where(active: false)
|
16
|
+
scope :frags_over, ->(count) { where(:frags.gt => count) }
|
17
|
+
scope :deaths_under, ->(count) { where(:deaths.lt => count) }
|
18
|
+
scope :deaths_over, ->(count) { where(:deaths.gt => count) }
|
19
|
+
|
20
|
+
has_many :weapons
|
21
|
+
has_one :powerup
|
22
|
+
|
23
|
+
embeds_many :implants
|
24
|
+
embeds_one :augmentation
|
25
|
+
|
26
|
+
after_find do |doc|
|
27
|
+
doc.impressions += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
class << self
|
31
|
+
def alive
|
32
|
+
where(status: "Alive")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Post
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :title, type: String
|
5
|
+
field :content, type: String
|
6
|
+
field :rating, type: Integer
|
7
|
+
field :person_title, type: String, default: ->{ person.try(:title) }
|
8
|
+
|
9
|
+
attr_accessor :before_add_called, :after_add_called, :before_remove_called, :after_remove_called
|
10
|
+
|
11
|
+
belongs_to :person, counter_cache: true
|
12
|
+
belongs_to :author, foreign_key: :author_id, class_name: "User"
|
13
|
+
has_and_belongs_to_many :tags, before_add: :before_add_tag, after_add: :after_add_tag, before_remove: :before_remove_tag, after_remove: :after_remove_tag
|
14
|
+
has_many :videos, validate: false
|
15
|
+
|
16
|
+
scope :recent, where(created_at: { "$lt" => Time.now, "$gt" => 30.days.ago })
|
17
|
+
scope :posting, where(:content.in => [ "Posting" ])
|
18
|
+
|
19
|
+
validates_format_of :title, without: /\$\$\$/
|
20
|
+
|
21
|
+
def before_add_tag(tag)
|
22
|
+
@before_add_called = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def after_add_tag(tag)
|
26
|
+
@after_add_called = true
|
27
|
+
end
|
28
|
+
|
29
|
+
def before_remove_tag(tag)
|
30
|
+
@before_remove_called = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def after_remove_tag(tag)
|
34
|
+
@after_remove_called = true
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
def old
|
39
|
+
where(created_at: { "$lt" => 30.days.ago })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Preference
|
2
|
+
include Mongoid::Document
|
3
|
+
field :name, type: String
|
4
|
+
field :value, type: String
|
5
|
+
field :ranking, type: Integer
|
6
|
+
has_and_belongs_to_many :people, validate: false
|
7
|
+
validates_length_of :name, minimum: 2, allow_nil: true
|
8
|
+
scope :posting, where(:value.in => [ "Posting" ])
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Product
|
2
|
+
include Mongoid::Document
|
3
|
+
field :description, localize: true
|
4
|
+
field :name, localize: true, default: "no translation"
|
5
|
+
field :price, type: Integer
|
6
|
+
field :brand_name
|
7
|
+
field :stores, type: Array
|
8
|
+
field :website, localize: true
|
9
|
+
alias_attribute :cost, :price
|
10
|
+
|
11
|
+
validates :name, presence: true
|
12
|
+
validates :website, format: { with: URI.regexp, allow_blank: true }
|
13
|
+
|
14
|
+
embeds_one :seo, as: :seo_tags, cascade_callbacks: true, autobuild: true
|
15
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Record
|
2
|
+
include Mongoid::Document
|
3
|
+
field :name, type: String
|
4
|
+
|
5
|
+
field :before_create_called, type: Boolean, default: false
|
6
|
+
field :before_save_called, type: Boolean, default: false
|
7
|
+
field :before_update_called, type: Boolean, default: false
|
8
|
+
field :before_validation_called, type: Boolean, default: false
|
9
|
+
field :before_destroy_called, type: Boolean, default: false
|
10
|
+
|
11
|
+
embedded_in :band
|
12
|
+
embeds_many :tracks, cascade_callbacks: true
|
13
|
+
embeds_many :notes, as: :noteable, cascade_callbacks: true, validate: false
|
14
|
+
|
15
|
+
before_create :before_create_stub
|
16
|
+
before_save :before_save_stub
|
17
|
+
before_update :before_update_stub
|
18
|
+
before_validation :before_validation_stub
|
19
|
+
before_destroy :before_destroy_stub
|
20
|
+
|
21
|
+
after_destroy :access_band
|
22
|
+
|
23
|
+
def before_create_stub
|
24
|
+
self.before_create_called = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def before_save_stub
|
28
|
+
self.before_save_called = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def before_update_stub
|
32
|
+
self.before_update_called = true
|
33
|
+
end
|
34
|
+
|
35
|
+
def before_validation_stub
|
36
|
+
self.before_validation_called = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def before_destroy_stub
|
40
|
+
self.before_destroy_called = true
|
41
|
+
end
|
42
|
+
|
43
|
+
def access_band
|
44
|
+
band.name
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Server
|
2
|
+
include Mongoid::Document
|
3
|
+
field :name, type: String
|
4
|
+
field :after, type: Boolean, default: false
|
5
|
+
belongs_to :node
|
6
|
+
embeds_many :filesystems, validate: false
|
7
|
+
accepts_nested_attributes_for :filesystems
|
8
|
+
validates :name, presence: { allow_blank: false }
|
9
|
+
|
10
|
+
after_create do |server|
|
11
|
+
server.update_attribute(:after, !after)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Service
|
2
|
+
include Mongoid::Document
|
3
|
+
field :sid
|
4
|
+
field :before_destroy_called, type: Boolean, default: false
|
5
|
+
field :after_destroy_called, type: Boolean, default: false
|
6
|
+
field :after_initialize_called, type: Boolean, default: false
|
7
|
+
embedded_in :person
|
8
|
+
belongs_to :target, class_name: "User"
|
9
|
+
validates_numericality_of :sid
|
10
|
+
|
11
|
+
before_destroy do |doc|
|
12
|
+
doc.before_destroy_called = true
|
13
|
+
end
|
14
|
+
|
15
|
+
after_destroy do |doc|
|
16
|
+
doc.after_destroy_called = true
|
17
|
+
end
|
18
|
+
|
19
|
+
after_initialize do |doc|
|
20
|
+
doc.after_initialize_called = true
|
21
|
+
end
|
22
|
+
end
|