mongoid-paranoia 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/.gitignore +25 -0
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +7 -0
  4. data/README.md +65 -0
  5. data/Rakefile +7 -0
  6. data/lib/mongoid/paranoia.rb +133 -0
  7. data/lib/mongoid/paranoia/version.rb +5 -0
  8. data/mongoid-paranoia.gemspec +18 -0
  9. data/spec/app/models/account.rb +32 -0
  10. data/spec/app/models/acolyte.rb +16 -0
  11. data/spec/app/models/actor.rb +19 -0
  12. data/spec/app/models/actor_observer.rb +15 -0
  13. data/spec/app/models/actress.rb +2 -0
  14. data/spec/app/models/address.rb +72 -0
  15. data/spec/app/models/address_component.rb +5 -0
  16. data/spec/app/models/address_number.rb +6 -0
  17. data/spec/app/models/agency.rb +5 -0
  18. data/spec/app/models/agent.rb +12 -0
  19. data/spec/app/models/album.rb +14 -0
  20. data/spec/app/models/alert.rb +5 -0
  21. data/spec/app/models/animal.rb +25 -0
  22. data/spec/app/models/answer.rb +4 -0
  23. data/spec/app/models/appointment.rb +7 -0
  24. data/spec/app/models/article.rb +13 -0
  25. data/spec/app/models/artist.rb +66 -0
  26. data/spec/app/models/artwork.rb +4 -0
  27. data/spec/app/models/augmentation.rb +11 -0
  28. data/spec/app/models/author.rb +6 -0
  29. data/spec/app/models/band.rb +25 -0
  30. data/spec/app/models/bar.rb +9 -0
  31. data/spec/app/models/basic.rb +6 -0
  32. data/spec/app/models/bed.rb +1 -0
  33. data/spec/app/models/big_palette.rb +2 -0
  34. data/spec/app/models/birthday.rb +13 -0
  35. data/spec/app/models/book.rb +12 -0
  36. data/spec/app/models/breed.rb +4 -0
  37. data/spec/app/models/browser.rb +6 -0
  38. data/spec/app/models/building.rb +7 -0
  39. data/spec/app/models/building_address.rb +7 -0
  40. data/spec/app/models/bus.rb +7 -0
  41. data/spec/app/models/business.rb +5 -0
  42. data/spec/app/models/callback_recorder.rb +25 -0
  43. data/spec/app/models/callback_test.rb +9 -0
  44. data/spec/app/models/canvas.rb +25 -0
  45. data/spec/app/models/car.rb +1 -0
  46. data/spec/app/models/cat.rb +8 -0
  47. data/spec/app/models/category.rb +8 -0
  48. data/spec/app/models/child.rb +4 -0
  49. data/spec/app/models/child_doc.rb +22 -0
  50. data/spec/app/models/church.rb +4 -0
  51. data/spec/app/models/circle.rb +3 -0
  52. data/spec/app/models/circuit.rb +4 -0
  53. data/spec/app/models/circus.rb +7 -0
  54. data/spec/app/models/code.rb +5 -0
  55. data/spec/app/models/comment.rb +16 -0
  56. data/spec/app/models/contractor.rb +7 -0
  57. data/spec/app/models/cookie.rb +6 -0
  58. data/spec/app/models/country_code.rb +8 -0
  59. data/spec/app/models/definition.rb +7 -0
  60. data/spec/app/models/description.rb +11 -0
  61. data/spec/app/models/dictionary.rb +10 -0
  62. data/spec/app/models/division.rb +10 -0
  63. data/spec/app/models/doctor.rb +12 -0
  64. data/spec/app/models/dog.rb +6 -0
  65. data/spec/app/models/dokument.rb +5 -0
  66. data/spec/app/models/driver.rb +7 -0
  67. data/spec/app/models/drug.rb +8 -0
  68. data/spec/app/models/email.rb +6 -0
  69. data/spec/app/models/employer.rb +5 -0
  70. data/spec/app/models/entry.rb +6 -0
  71. data/spec/app/models/eraser.rb +1 -0
  72. data/spec/app/models/event.rb +22 -0
  73. data/spec/app/models/exhibition.rb +4 -0
  74. data/spec/app/models/exhibitor.rb +5 -0
  75. data/spec/app/models/eye.rb +9 -0
  76. data/spec/app/models/eye_bowl.rb +9 -0
  77. data/spec/app/models/face.rb +8 -0
  78. data/spec/app/models/favorite.rb +6 -0
  79. data/spec/app/models/filesystem.rb +4 -0
  80. data/spec/app/models/firefox.rb +4 -0
  81. data/spec/app/models/fish.rb +8 -0
  82. data/spec/app/models/folder.rb +7 -0
  83. data/spec/app/models/folder_item.rb +9 -0
  84. data/spec/app/models/fruits.rb +28 -0
  85. data/spec/app/models/game.rb +21 -0
  86. data/spec/app/models/ghost.rb +7 -0
  87. data/spec/app/models/home.rb +4 -0
  88. data/spec/app/models/house.rb +8 -0
  89. data/spec/app/models/html_writer.rb +3 -0
  90. data/spec/app/models/image.rb +22 -0
  91. data/spec/app/models/implant.rb +16 -0
  92. data/spec/app/models/item.rb +12 -0
  93. data/spec/app/models/jar.rb +7 -0
  94. data/spec/app/models/label.rb +40 -0
  95. data/spec/app/models/language.rb +5 -0
  96. data/spec/app/models/lat_lng.rb +15 -0
  97. data/spec/app/models/league.rb +11 -0
  98. data/spec/app/models/learner.rb +2 -0
  99. data/spec/app/models/line_item.rb +6 -0
  100. data/spec/app/models/location.rb +8 -0
  101. data/spec/app/models/login.rb +8 -0
  102. data/spec/app/models/manufacturer.rb +7 -0
  103. data/spec/app/models/meat.rb +4 -0
  104. data/spec/app/models/membership.rb +4 -0
  105. data/spec/app/models/mixed_drink.rb +4 -0
  106. data/spec/app/models/movie.rb +12 -0
  107. data/spec/app/models/my_hash.rb +2 -0
  108. data/spec/app/models/name.rb +23 -0
  109. data/spec/app/models/node.rb +5 -0
  110. data/spec/app/models/note.rb +12 -0
  111. data/spec/app/models/ordered_post.rb +6 -0
  112. data/spec/app/models/ordered_preference.rb +6 -0
  113. data/spec/app/models/oscar.rb +15 -0
  114. data/spec/app/models/override.rb +16 -0
  115. data/spec/app/models/ownable.rb +6 -0
  116. data/spec/app/models/owner.rb +6 -0
  117. data/spec/app/models/page.rb +5 -0
  118. data/spec/app/models/page_question.rb +4 -0
  119. data/spec/app/models/palette.rb +7 -0
  120. data/spec/app/models/paranoid_phone.rb +25 -0
  121. data/spec/app/models/paranoid_post.rb +36 -0
  122. data/spec/app/models/parent.rb +5 -0
  123. data/spec/app/models/parent_doc.rb +6 -0
  124. data/spec/app/models/passport.rb +5 -0
  125. data/spec/app/models/patient.rb +9 -0
  126. data/spec/app/models/pdf_writer.rb +3 -0
  127. data/spec/app/models/pencil.rb +1 -0
  128. data/spec/app/models/person.rb +200 -0
  129. data/spec/app/models/pet.rb +23 -0
  130. data/spec/app/models/pet_owner.rb +6 -0
  131. data/spec/app/models/phone.rb +11 -0
  132. data/spec/app/models/phone_observer.rb +6 -0
  133. data/spec/app/models/pizza.rb +7 -0
  134. data/spec/app/models/player.rb +35 -0
  135. data/spec/app/models/post.rb +42 -0
  136. data/spec/app/models/powerup.rb +11 -0
  137. data/spec/app/models/preference.rb +9 -0
  138. data/spec/app/models/princess.rb +8 -0
  139. data/spec/app/models/product.rb +15 -0
  140. data/spec/app/models/profile.rb +5 -0
  141. data/spec/app/models/pronunciation.rb +5 -0
  142. data/spec/app/models/purchase.rb +4 -0
  143. data/spec/app/models/question.rb +8 -0
  144. data/spec/app/models/quiz.rb +10 -0
  145. data/spec/app/models/rating.rb +8 -0
  146. data/spec/app/models/record.rb +46 -0
  147. data/spec/app/models/registry.rb +4 -0
  148. data/spec/app/models/role.rb +5 -0
  149. data/spec/app/models/root_category.rb +4 -0
  150. data/spec/app/models/sandwich.rb +4 -0
  151. data/spec/app/models/scheduler.rb +7 -0
  152. data/spec/app/models/seo.rb +7 -0
  153. data/spec/app/models/series.rb +4 -0
  154. data/spec/app/models/server.rb +13 -0
  155. data/spec/app/models/service.rb +22 -0
  156. data/spec/app/models/shape.rb +12 -0
  157. data/spec/app/models/shelf.rb +5 -0
  158. data/spec/app/models/shipping_container.rb +5 -0
  159. data/spec/app/models/shop.rb +6 -0
  160. data/spec/app/models/short_agent.rb +4 -0
  161. data/spec/app/models/short_quiz.rb +5 -0
  162. data/spec/app/models/slave.rb +6 -0
  163. data/spec/app/models/song.rb +8 -0
  164. data/spec/app/models/square.rb +4 -0
  165. data/spec/app/models/strategy.rb +3 -0
  166. data/spec/app/models/sub_item.rb +3 -0
  167. data/spec/app/models/survey.rb +5 -0
  168. data/spec/app/models/symptom.rb +6 -0
  169. data/spec/app/models/tag.rb +8 -0
  170. data/spec/app/models/target.rb +5 -0
  171. data/spec/app/models/template.rb +5 -0
  172. data/spec/app/models/thing.rb +9 -0
  173. data/spec/app/models/title.rb +4 -0
  174. data/spec/app/models/tool.rb +8 -0
  175. data/spec/app/models/topping.rb +5 -0
  176. data/spec/app/models/track.rb +38 -0
  177. data/spec/app/models/translation.rb +5 -0
  178. data/spec/app/models/tree.rb +9 -0
  179. data/spec/app/models/truck.rb +3 -0
  180. data/spec/app/models/user.rb +20 -0
  181. data/spec/app/models/user_account.rb +10 -0
  182. data/spec/app/models/validation_callback.rb +10 -0
  183. data/spec/app/models/vehicle.rb +11 -0
  184. data/spec/app/models/version.rb +5 -0
  185. data/spec/app/models/vet_visit.rb +5 -0
  186. data/spec/app/models/video.rb +17 -0
  187. data/spec/app/models/weapon.rb +11 -0
  188. data/spec/app/models/wiki_page.rb +17 -0
  189. data/spec/app/models/word.rb +12 -0
  190. data/spec/app/models/word_origin.rb +11 -0
  191. data/spec/app/models/writer.rb +11 -0
  192. data/spec/config/mongoid.yml +40 -0
  193. data/spec/mongoid/paranoia_spec.rb +715 -0
  194. data/spec/spec_helper.rb +80 -0
  195. metadata +271 -0
@@ -0,0 +1,6 @@
1
+ class AddressNumber
2
+ include Mongoid::Document
3
+ field :country_code, type: Integer, default: 1
4
+ field :number
5
+ embedded_in :slave
6
+ end
@@ -0,0 +1,5 @@
1
+ class Agency
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps::Updated
4
+ has_many :agents, validate: false
5
+ end
@@ -0,0 +1,12 @@
1
+ class Agent
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps::Updated
4
+ field :title, type: String
5
+ field :number, type: String
6
+ field :dob, type: Time
7
+ embeds_many :names, as: :namable
8
+ belongs_to :game
9
+ belongs_to :agency, touch: true, autobuild: true
10
+
11
+ has_and_belongs_to_many :accounts
12
+ end
@@ -0,0 +1,14 @@
1
+ class Album
2
+ include Mongoid::Document
3
+
4
+ belongs_to :artist
5
+ before_destroy :set_parent_name
6
+
7
+ attr_accessor :before_add_called
8
+
9
+ private
10
+
11
+ def set_parent_name
12
+ artist.name = "destroyed"
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class Alert
2
+ include Mongoid::Document
3
+ field :message, type: String
4
+ belongs_to :account
5
+ end
@@ -0,0 +1,25 @@
1
+ class Animal
2
+ include Mongoid::Document
3
+
4
+ field :_id, type: String, default: ->{ name.try(:parameterize) }
5
+
6
+ field :name
7
+ field :height, type: Integer
8
+ field :weight, type: Integer
9
+ field :tags, type: Array
10
+
11
+ embedded_in :person
12
+ embedded_in :circus
13
+
14
+ validates_format_of :name, without: /\$\$\$/
15
+
16
+ accepts_nested_attributes_for :person
17
+
18
+ def tag_list
19
+ tags.join(", ")
20
+ end
21
+
22
+ def tag_list=(_tag_list)
23
+ self.tags = _tag_list.split(",").map(&:strip)
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ class Answer
2
+ include Mongoid::Document
3
+ embedded_in :question
4
+ end
@@ -0,0 +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
@@ -0,0 +1,13 @@
1
+ class Article
2
+ include Mongoid::Document
3
+
4
+ field :title, type: String
5
+ field :is_rss, type: Boolean, default: false
6
+ field :user_login, type: String
7
+
8
+ attr_accessible :title, as: [:default, :parser]
9
+ attr_accessible :is_rss, as: :parser
10
+ attr_accessible :user_login
11
+ has_and_belongs_to_many :tags, validate: false
12
+ has_and_belongs_to_many :preferences, inverse_of: nil, validate: false
13
+ end
@@ -0,0 +1,66 @@
1
+ class Artist
2
+ include Mongoid::Document
3
+
4
+ attr_accessor :before_add_called, :after_add_called, :before_add_referenced_called, :after_add_referenced_called, :before_remove_embedded_called, :after_remove_embedded_called, :before_remove_referenced_called, :after_remove_referenced_called
5
+
6
+ field :name, type: String
7
+
8
+ embeds_many :songs, before_add: [ :before_add_song, Proc.new { |artist, song| song.before_add_called = true } ], before_remove: :before_remove_song
9
+ embeds_many :labels, after_add: :after_add_label, after_remove: :after_remove_label
10
+ has_many :albums, dependent: :destroy, before_add: [:before_add_album, Proc.new { |artist, album| album.before_add_called = true} ], after_add: :after_add_album, before_remove: :before_remove_album, after_remove: :after_remove_album
11
+
12
+ before_create :before_create_stub
13
+ after_create :create_songs
14
+ before_save :before_save_stub
15
+ before_destroy :before_destroy_stub
16
+
17
+ protected
18
+ def before_create_stub
19
+ true
20
+ end
21
+
22
+ def before_save_stub
23
+ true
24
+ end
25
+
26
+ def before_destroy_stub
27
+ true
28
+ end
29
+
30
+ def create_songs
31
+ 2.times { |n| songs.create!(title: "#{n}") }
32
+ end
33
+
34
+ def before_add_song(song)
35
+ @before_add_called = true
36
+ end
37
+
38
+ def after_add_label(label)
39
+ @after_add_called = true
40
+ end
41
+
42
+ def before_add_album(album)
43
+ @before_add_referenced_called = true
44
+ end
45
+
46
+ def after_add_album(album)
47
+ @after_add_referenced_called = true
48
+ end
49
+
50
+ def before_remove_song(song)
51
+ @before_remove_embedded_called = true
52
+ end
53
+
54
+ def after_remove_label(label)
55
+ @after_remove_embedded_called = true
56
+ end
57
+
58
+ def before_remove_album(album)
59
+ @before_remove_referenced_called = true
60
+ end
61
+
62
+ def after_remove_album(album)
63
+ @after_remove_referenced_called = true
64
+ end
65
+
66
+ end
@@ -0,0 +1,4 @@
1
+ class Artwork
2
+ include Mongoid::Document
3
+ has_and_belongs_to_many :exhibitors
4
+ end
@@ -0,0 +1,11 @@
1
+ class Augmentation
2
+ include Mongoid::Document
3
+
4
+ field :name
5
+
6
+ embedded_in :player, inverse_of: :augmentation
7
+
8
+ after_build do
9
+ self.name = "Infolink (#{player.frags})"
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class Author
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+
5
+ belongs_to :paranoid_post
6
+ end
@@ -0,0 +1,25 @@
1
+ class Band
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+ field :active, type: Boolean, default: true
5
+ field :origin, type: String
6
+ field :genres, type: Array
7
+ field :member_count, type: Integer
8
+ field :mems, as: :members, type: Array
9
+ field :likes, type: Integer
10
+ field :views, type: Integer
11
+ field :rating, type: Float
12
+ field :upserted, type: Boolean, default: false
13
+ field :created, type: DateTime
14
+ field :sales, type: BigDecimal
15
+ field :y, as: :years, type: Integer
16
+ field :founded, type: Date
17
+
18
+ embeds_many :records, cascade_callbacks: true
19
+ embeds_many :notes, as: :noteable, cascade_callbacks: true, validate: false
20
+ embeds_one :label, cascade_callbacks: true
21
+
22
+ after_upsert do |doc|
23
+ doc.upserted = true
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ class Bar
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+ field :location, type: Array
5
+ field :lat_lng, type: LatLng
6
+
7
+ has_one :rating, as: :ratable
8
+ index location: "2d"
9
+ end
@@ -0,0 +1,6 @@
1
+ class Basic
2
+ include Mongoid::Document
3
+ end
4
+
5
+ class SubBasic < Basic
6
+ end
@@ -0,0 +1 @@
1
+ class Bed; end
@@ -0,0 +1,2 @@
1
+ class BigPalette < Palette
2
+ end
@@ -0,0 +1,13 @@
1
+ class Birthday
2
+ include Mongoid::Document
3
+ field :title
4
+ field :date, type: Date
5
+ embedded_in :owner, inverse_of: :birthdays
6
+
7
+ def self.each_day(start_date, end_date)
8
+ groups = only(:date).asc(:date).where(:date.gte => start_date, :date.lte => end_date).group
9
+ groups.each do |date, group|
10
+ yield(date, group)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class Book
2
+ include Mongoid::Document
3
+ field :title, type: String
4
+ field :chapters, type: Integer
5
+ belongs_to :series
6
+ belongs_to :person, autobuild: true
7
+ has_one :rating, as: :ratable, dependent: :nullify
8
+
9
+ after_initialize do |doc|
10
+ doc.chapters = 5
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ class Breed
2
+ include Mongoid::Document
3
+ has_and_belongs_to_many :dogs
4
+ end
@@ -0,0 +1,6 @@
1
+ class Browser < Canvas
2
+ field :version, type: Integer
3
+ def render; end
4
+ end
5
+
6
+ require "app/models/firefox"
@@ -0,0 +1,7 @@
1
+ class Building
2
+ include Mongoid::Document
3
+ attr_accessible
4
+ attr_accessible :building_address, :contractors, as: :admin
5
+ embeds_one :building_address
6
+ embeds_many :contractors
7
+ end
@@ -0,0 +1,7 @@
1
+ class BuildingAddress
2
+ include Mongoid::Document
3
+ attr_accessible
4
+ attr_accessible :city, as: :admin
5
+ embedded_in :building
6
+ field :city, type: String
7
+ end
@@ -0,0 +1,7 @@
1
+ class Bus
2
+ include Mongoid::Document
3
+ field :saturday, type: Boolean, default: false
4
+ field :departure_time, type: Time
5
+ field :number, type: Integer
6
+ embedded_in :circuit
7
+ end
@@ -0,0 +1,5 @@
1
+ class Business
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+ has_and_belongs_to_many :owners, class_name: "User", validate: false
5
+ end
@@ -0,0 +1,25 @@
1
+ class CallbackRecorder < Mongoid::Observer
2
+ observe :actor
3
+
4
+ attr_reader :last_callback, :call_count, :last_record
5
+
6
+ def initialize
7
+ reset
8
+ super
9
+ end
10
+
11
+ def reset
12
+ @last_callback = nil
13
+ @call_count = Hash.new(0)
14
+ @last_record = {}
15
+ end
16
+
17
+ Mongoid::Callbacks.observables.each do |callback|
18
+ define_method(callback) do |record, &block|
19
+ @last_callback = callback
20
+ @call_count[callback] += 1
21
+ @last_record[callback] = record
22
+ block ? block.call : true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ class CallbackTest
2
+ include Mongoid::Document
3
+ around_save :execute
4
+
5
+ def execute
6
+ yield(self)
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ class Canvas
2
+ include Mongoid::Document
3
+ field :name
4
+ embeds_many :shapes
5
+ embeds_one :writer
6
+ embeds_one :palette
7
+
8
+ field :foo, type: String, default: ->{ "original" }
9
+
10
+ has_many :comments, as: :commentable
11
+
12
+ accepts_nested_attributes_for :shapes
13
+ accepts_nested_attributes_for :writer
14
+
15
+ def render
16
+ shapes.each { |shape| render }
17
+ end
18
+
19
+ class Test < Canvas
20
+
21
+ field :foo, type: String, default: ->{ "overridden" }
22
+ end
23
+ end
24
+
25
+ require "app/models/browser"
@@ -0,0 +1 @@
1
+ class Car < Vehicle; end
@@ -0,0 +1,8 @@
1
+ class Cat
2
+ include Mongoid::Document
3
+
4
+ field :name
5
+
6
+ belongs_to :person, primary_key: :username
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ class Category
2
+ include Mongoid::Document
3
+ embedded_in :root_category
4
+ embedded_in :category
5
+ embeds_many :categories
6
+
7
+ field :name
8
+ end
@@ -0,0 +1,4 @@
1
+ class Child
2
+ include Mongoid::Document
3
+ embedded_in :parent, inverse_of: :childable, polymorphic: true
4
+ end
@@ -0,0 +1,22 @@
1
+ class ChildDoc
2
+ include Mongoid::Document
3
+
4
+ embedded_in :parent_doc
5
+
6
+ attr_writer :position
7
+
8
+ after_save :update_position
9
+
10
+ def position
11
+ exsited_position = parent_doc.children_order.index(id)
12
+ exsited_position ? exsited_position + 1 : parent_doc.aspects.size
13
+ end
14
+
15
+ def update_position
16
+ if @position && (@position.to_i > 0)
17
+ parent_doc.children_order.delete(id)
18
+ parent_doc.children_order.insert(@position.to_i - 1, id)
19
+ parent_doc.save
20
+ end
21
+ end
22
+ end