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,12 @@
1
+ class Item
2
+ include Mongoid::Document
3
+ field :title, type: String
4
+ field :is_rss, type: Boolean, default: false
5
+ field :user_login, type: String
6
+
7
+ attr_protected :title, as: [:default, :parser]
8
+ attr_protected :is_rss, as: :parser
9
+ attr_protected :user_login
10
+ end
11
+
12
+ require "app/models/sub_item"
@@ -0,0 +1,7 @@
1
+ class Jar
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps::Updated
4
+
5
+ field :_id, type: Integer
6
+ has_many :cookies, class_name: "Cookie"
7
+ end
@@ -0,0 +1,40 @@
1
+ class Label
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps::Updated::Short
4
+
5
+ field :name, type: String
6
+ field :after_create_called, type: Boolean, default: false
7
+ field :after_save_called, type: Boolean, default: false
8
+ field :after_update_called, type: Boolean, default: false
9
+ field :after_validation_called, type: Boolean, default: false
10
+
11
+ embedded_in :artist
12
+ embedded_in :band
13
+
14
+ after_create :after_create_stub
15
+ after_save :after_save_stub
16
+ after_update :after_update_stub
17
+ after_validation :after_validation_stub
18
+ before_validation :cleanup
19
+
20
+ def after_create_stub
21
+ self.after_create_called = true
22
+ end
23
+
24
+ def after_save_stub
25
+ self.after_save_called = true
26
+ end
27
+
28
+ def after_update_stub
29
+ self.after_update_called = true
30
+ end
31
+
32
+ def after_validation_stub
33
+ self.after_validation_called = true
34
+ end
35
+
36
+ private
37
+ def cleanup
38
+ self.name = self.name.downcase.capitalize
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ class Language
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+ embedded_in :translatable, polymorphic: true
5
+ end
@@ -0,0 +1,15 @@
1
+ class LatLng
2
+ attr_accessor :lat, :lng
3
+
4
+ def self.demongoize(object)
5
+ LatLng.new(object[1], object[0])
6
+ end
7
+
8
+ def initialize(lat, lng)
9
+ @lat, @lng = lat, lng
10
+ end
11
+
12
+ def mongoize
13
+ [ lng, lat ]
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class League
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+ embeds_many :divisions
5
+ accepts_nested_attributes_for :divisions, allow_destroy: true
6
+ before_destroy :destroy_children
7
+
8
+ def destroy_children
9
+ divisions.destroy_all
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ class Learner < Driver
2
+ end
@@ -0,0 +1,6 @@
1
+ class LineItem
2
+ include Mongoid::Document
3
+ embedded_in :purchase
4
+ belongs_to :product, polymorphic: true
5
+ validates :product, presence: true
6
+ end
@@ -0,0 +1,8 @@
1
+ class Location
2
+ include Mongoid::Document
3
+ field :name
4
+ field :info, type: Hash
5
+ field :occupants, type: Array
6
+ field :number, type: Integer
7
+ embedded_in :address
8
+ end
@@ -0,0 +1,8 @@
1
+ class Login
2
+ include Mongoid::Document
3
+
4
+ field :_id, type: String, default: ->{ username }
5
+
6
+ field :username, type: String
7
+ field :application_id, type: Integer
8
+ end
@@ -0,0 +1,7 @@
1
+ class Manufacturer
2
+ include Mongoid::Document
3
+
4
+ field :products, type: Array, default: []
5
+
6
+ validates_presence_of :products
7
+ end
@@ -0,0 +1,4 @@
1
+ class Meat
2
+ include Mongoid::Document
3
+ has_and_belongs_to_many :sandwiches
4
+ end
@@ -0,0 +1,4 @@
1
+ class Membership
2
+ include Mongoid::Document
3
+ embedded_in :account
4
+ end
@@ -0,0 +1,4 @@
1
+ class MixedDrink
2
+ include Mongoid::Document
3
+ field :name
4
+ end
@@ -0,0 +1,12 @@
1
+ class Movie
2
+ include Mongoid::Document
3
+ field :title, type: String
4
+ field :poster, type: Image
5
+ field :poster_thumb, type: Thumbnail
6
+ has_many :ratings, as: :ratable, dependent: :nullify
7
+ has_many :comments
8
+
9
+ def global_set
10
+ Set.new
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ class MyHash < ::Hash
2
+ end
@@ -0,0 +1,23 @@
1
+ class Name
2
+ include Mongoid::Document
3
+
4
+ field :_id, type: String, default: ->{
5
+ "#{first_name}-#{last_name}"
6
+ }
7
+
8
+ field :first_name, type: String
9
+ field :last_name, type: String
10
+ field :parent_title, type: String
11
+
12
+ embeds_many :translations, validate: false
13
+ embeds_one :language, as: :translatable, validate: false
14
+ embedded_in :namable, polymorphic: true
15
+
16
+ accepts_nested_attributes_for :language
17
+
18
+ attr_protected :_id, :id
19
+
20
+ def set_parent=(set = false)
21
+ self.parent_title = namable.title if set
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ class Node
2
+ include Mongoid::Document
3
+ has_many :servers
4
+ accepts_nested_attributes_for :servers
5
+ end
@@ -0,0 +1,12 @@
1
+ class Note
2
+ include Mongoid::Document
3
+ field :text, type: String
4
+ field :saved, type: Boolean, default: false
5
+ embedded_in :noteable, polymorphic: true
6
+
7
+ after_save :update_saved
8
+
9
+ def update_saved
10
+ self.saved = true
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ class OrderedPost
2
+ include Mongoid::Document
3
+ field :title, type: String
4
+ field :rating, type: Integer
5
+ belongs_to :person
6
+ end
@@ -0,0 +1,6 @@
1
+ class OrderedPreference
2
+ include Mongoid::Document
3
+ field :name, type: String
4
+ field :value, type: String
5
+ has_and_belongs_to_many :people, validate: false
6
+ end
@@ -0,0 +1,15 @@
1
+ class Oscar
2
+ include Mongoid::Document
3
+ field :title, type: String
4
+ field :destroy_after_save, type: Boolean, default: false
5
+ before_save :complain
6
+
7
+ def complain
8
+ if destroy_after_save?
9
+ destroy
10
+ true
11
+ else
12
+ false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ class Override
2
+ include Mongoid::Document
3
+
4
+ def self.public_method
5
+ end
6
+
7
+ protected
8
+
9
+ def self.protected_method
10
+ end
11
+
12
+ private
13
+
14
+ def self.private_method
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ module Ownable
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ belongs_to :user
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class Owner
2
+ include Mongoid::Document
3
+ field :name
4
+ has_many :events
5
+ embeds_many :birthdays
6
+ end
@@ -0,0 +1,5 @@
1
+ class Page
2
+ include Mongoid::Document
3
+ embedded_in :quiz
4
+ embeds_many :page_questions
5
+ end
@@ -0,0 +1,4 @@
1
+ class PageQuestion
2
+ include Mongoid::Document
3
+ embedded_in :page
4
+ end
@@ -0,0 +1,7 @@
1
+ class Palette
2
+ include Mongoid::Document
3
+ embedded_in :canvas
4
+ embeds_many :tools
5
+ end
6
+
7
+ require "app/models/big_palette"
@@ -0,0 +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
+ person.age == 42 ? false : true
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ class ParanoidPost
2
+ include Mongoid::Document
3
+ include Mongoid::Versioning
4
+ include Mongoid::Paranoia
5
+
6
+ max_versions 2
7
+
8
+ field :title, type: String
9
+
10
+ attr_accessor :after_destroy_called, :before_destroy_called
11
+
12
+ belongs_to :person
13
+
14
+ has_and_belongs_to_many :tags
15
+ has_many :authors, dependent: :delete
16
+ has_many :titles, dependent: :restrict
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
+ def before_destroy_stub
24
+ self.before_destroy_called = true
25
+ end
26
+
27
+ def after_destroy_stub
28
+ self.after_destroy_called = true
29
+ end
30
+
31
+ class << self
32
+ def old
33
+ where(created_at: { "$lt" => 30.days.ago })
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ class Parent
2
+ include Mongoid::Document
3
+ embeds_many :sub_items
4
+ embeds_one :first_child, class_name: "Child", as: :childable
5
+ end
@@ -0,0 +1,6 @@
1
+ class ParentDoc
2
+ include Mongoid::Document
3
+ field :statistic
4
+ field :children_order, type: Array, default: [] # hold all the children's id
5
+ embeds_many :child_docs
6
+ end
@@ -0,0 +1,5 @@
1
+ class Passport
2
+ include Mongoid::Document
3
+ field :number, type: String
4
+ embedded_in :person, autobuild: true
5
+ end
@@ -0,0 +1,9 @@
1
+ class Patient
2
+ include Mongoid::Document
3
+ field :title, type: String
4
+ store_in collection: "inpatient"
5
+ embeds_many :addresses, as: :addressable
6
+ embeds_one :email
7
+ embeds_one :name, as: :namable
8
+ validates_presence_of :title, on: :create
9
+ end
@@ -0,0 +1,3 @@
1
+ class PdfWriter < Writer
2
+ def write; end
3
+ end
@@ -0,0 +1 @@
1
+ class Pencil < Tool; end
@@ -0,0 +1,200 @@
1
+ class Person
2
+ include Mongoid::Document
3
+ attr_accessor :mode
4
+
5
+ class_attribute :somebody_elses_important_class_options
6
+ self.somebody_elses_important_class_options = { keep_me_around: true }
7
+
8
+ field :username, default: -> { "arthurnn#{rand(0..10)}" }
9
+ field :title
10
+ field :terms, type: Boolean
11
+ field :pets, type: Boolean, default: false
12
+ field :age, type: Integer, default: "100"
13
+ field :dob, type: Date
14
+ field :employer_id
15
+ field :lunch_time, type: Time
16
+ field :aliases, type: Array
17
+ field :map, type: Hash
18
+ field :map_with_default, type: Hash, default: {}
19
+ field :score, type: Integer
20
+ field :blood_alcohol_content, type: Float, default: ->{ 0.0 }
21
+ field :last_drink_taken_at, type: Date, default: ->{ 1.day.ago.in_time_zone("Alaska") }
22
+ field :ssn
23
+ field :owner_id, type: Integer
24
+ field :security_code
25
+ field :reading, type: Object
26
+ field :bson_id, type: Moped::BSON::ObjectId
27
+ field :pattern, type: Regexp
28
+ field :override_me, type: Integer
29
+ field :t, as: :test, type: String
30
+ field :i, as: :inte, type: Integer
31
+ field :a, as: :array, type: Array
32
+ field :desc, localize: true
33
+
34
+ index age: 1
35
+ index addresses: 1
36
+ index dob: 1
37
+ index name: 1
38
+ index title: 1
39
+
40
+ index({ ssn: 1 }, { unique: true })
41
+
42
+ attr_reader :rescored
43
+
44
+ attr_protected :security_code, :owner_id, :appointments
45
+
46
+ embeds_many :favorites, order: :title.desc, inverse_of: :perp, validate: false
47
+ embeds_many :videos, order: [[ :title, :asc ]], validate: false
48
+ embeds_many :phone_numbers, class_name: "Phone", validate: false
49
+ embeds_many :phones, store_as: :mobile_phones, validate: false
50
+ embeds_many :addresses, as: :addressable, validate: false do
51
+ def extension
52
+ "Testing"
53
+ end
54
+ def find_by_street(street)
55
+ where(street: street).first
56
+ end
57
+ end
58
+
59
+ embeds_many :address_components, validate: false
60
+ embeds_many :paranoid_phones, validate: false
61
+ embeds_many :services, cascade_callbacks: true, validate: false
62
+ embeds_many :symptoms, validate: false
63
+ embeds_many :appointments, validate: false
64
+
65
+ embeds_one :passport, autobuild: true, store_as: :pass, validate: false
66
+ embeds_one :pet, class_name: "Animal", validate: false
67
+ embeds_one :name, as: :namable, validate: false do
68
+ def extension
69
+ "Testing"
70
+ end
71
+ def dawkins?
72
+ first_name == "Richard" && last_name == "Dawkins"
73
+ end
74
+ end
75
+ embeds_one :quiz, validate: false
76
+
77
+ has_one :game, dependent: :destroy, validate: false do
78
+ def extension
79
+ "Testing"
80
+ end
81
+ end
82
+
83
+ has_many \
84
+ :posts,
85
+ dependent: :delete,
86
+ validate: false do
87
+ def extension
88
+ "Testing"
89
+ end
90
+ end
91
+ has_many :ordered_posts, order: :rating.desc, validate: false
92
+ has_many :paranoid_posts, validate: false
93
+ has_and_belongs_to_many \
94
+ :preferences,
95
+ index: true,
96
+ dependent: :nullify,
97
+ validate: false
98
+ has_and_belongs_to_many :user_accounts, validate: false
99
+ has_and_belongs_to_many :houses, validate: false
100
+ has_and_belongs_to_many :ordered_preferences, order: :value.desc, validate: false
101
+
102
+ has_many :drugs, validate: false
103
+ has_one :account, validate: false
104
+ has_one :cat, dependent: :nullify, validate: false, primary_key: :username
105
+ has_one :book, autobuild: true, validate: false
106
+ has_one :home, dependent: :delete, validate: false
107
+
108
+ has_and_belongs_to_many \
109
+ :administrated_events,
110
+ class_name: 'Event',
111
+ inverse_of: :administrators,
112
+ dependent: :nullify,
113
+ validate: false
114
+
115
+ accepts_nested_attributes_for :addresses
116
+ accepts_nested_attributes_for :paranoid_phones
117
+ accepts_nested_attributes_for :name, update_only: true
118
+ accepts_nested_attributes_for :pet, allow_destroy: true
119
+ accepts_nested_attributes_for :game, allow_destroy: true
120
+ accepts_nested_attributes_for :favorites, allow_destroy: true, limit: 5
121
+ accepts_nested_attributes_for :posts
122
+ accepts_nested_attributes_for :preferences
123
+ accepts_nested_attributes_for :quiz
124
+ accepts_nested_attributes_for :services, allow_destroy: true
125
+
126
+ scope :minor, where(:age.lt => 18)
127
+ scope :without_ssn, without(:ssn)
128
+ scope :search, ->(query){ any_of({ title: query }) }
129
+
130
+ def score_with_rescoring=(score)
131
+ @rescored = score.to_i + 20
132
+ self.score_without_rescoring = score
133
+ end
134
+
135
+ alias_method_chain :score=, :rescoring
136
+
137
+ def update_addresses
138
+ addresses.each do |address|
139
+ address.street = "Updated Address"
140
+ end
141
+ end
142
+
143
+ def employer=(emp)
144
+ self.employer_id = emp.id
145
+ end
146
+
147
+ def set_addresses=(addresses)
148
+ self.addresses = addresses
149
+ end
150
+
151
+ def override_me
152
+ read_attribute(:override_me).to_s
153
+ end
154
+
155
+ class << self
156
+ def accepted
157
+ scoped.where(terms: true)
158
+ end
159
+ def knight
160
+ scoped.where(title: "Sir")
161
+ end
162
+ def old
163
+ scoped.where(age: { "$gt" => 50 })
164
+ end
165
+ end
166
+
167
+ def reject_if_city_is_empty(attrs)
168
+ attrs[:city].blank?
169
+ end
170
+
171
+ def reject_if_name_is_blank(attrs)
172
+ attrs[:first_name].blank?
173
+ end
174
+
175
+ def foo
176
+ 'i_am_foo'
177
+ end
178
+
179
+ def preference_names=(names)
180
+ names.split(",").each do |name|
181
+ preference = Preference.where(name: name).first
182
+ if preference
183
+ self.preferences << preference
184
+ else
185
+ preferences.build(name: name)
186
+ end
187
+ end
188
+ end
189
+
190
+ def set_on_map_with_default=(value)
191
+ self.map_with_default["key"] = value
192
+ end
193
+
194
+ reset_callbacks(:validate)
195
+ reset_callbacks(:create)
196
+ reset_callbacks(:save)
197
+ reset_callbacks(:destroy)
198
+ end
199
+
200
+ require "app/models/doctor"