mongoid-pre 2.0.0.beta1 → 2.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. data/.watchr +15 -10
  2. data/HISTORY +342 -0
  3. data/README.rdoc +8 -1
  4. data/Rakefile +2 -3
  5. data/VERSION +1 -1
  6. data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
  7. data/lib/mongoid/associations/belongs_to_related.rb +9 -6
  8. data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
  9. data/lib/mongoid/associations/has_many_related.rb +4 -28
  10. data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
  11. data/lib/mongoid/associations/options.rb +6 -1
  12. data/lib/mongoid/associations.rb +32 -41
  13. data/lib/mongoid/attributes.rb +6 -13
  14. data/lib/mongoid/collection.rb +1 -2
  15. data/lib/mongoid/commands/delete.rb +1 -1
  16. data/lib/mongoid/commands/delete_all.rb +1 -4
  17. data/lib/mongoid/commands/destroy.rb +1 -1
  18. data/lib/mongoid/commands/destroy_all.rb +1 -3
  19. data/lib/mongoid/commands/save.rb +0 -1
  20. data/lib/mongoid/commands.rb +13 -2
  21. data/lib/mongoid/components.rb +1 -6
  22. data/lib/mongoid/config.rb +1 -5
  23. data/lib/mongoid/contexts/enumerable.rb +17 -54
  24. data/lib/mongoid/contexts/mongo.rb +38 -101
  25. data/lib/mongoid/contexts/paging.rb +2 -2
  26. data/lib/mongoid/contexts.rb +0 -21
  27. data/lib/mongoid/criteria.rb +73 -15
  28. data/lib/mongoid/criterion/inclusion.rb +0 -2
  29. data/lib/mongoid/criterion/optional.rb +2 -10
  30. data/lib/mongoid/document.rb +30 -41
  31. data/lib/mongoid/extensions.rb +0 -15
  32. data/lib/mongoid/field.rb +7 -20
  33. data/lib/mongoid/fields.rb +10 -15
  34. data/lib/mongoid/finders.rb +98 -10
  35. data/lib/mongoid/identity.rb +2 -8
  36. data/lib/mongoid/named_scope.rb +0 -2
  37. data/lib/mongoid/validations/associated.rb +8 -3
  38. data/lib/mongoid/validations/uniqueness.rb +7 -2
  39. data/lib/mongoid/validations.rb +2 -2
  40. data/lib/mongoid/versioning.rb +1 -1
  41. data/lib/mongoid.rb +5 -21
  42. data/mongoid.gemspec +19 -59
  43. data/spec/integration/mongoid/associations_spec.rb +3 -42
  44. data/spec/integration/mongoid/attributes_spec.rb +2 -2
  45. data/spec/integration/mongoid/commands_spec.rb +13 -27
  46. data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
  47. data/spec/integration/mongoid/criteria_spec.rb +3 -50
  48. data/spec/integration/mongoid/document_spec.rb +5 -72
  49. data/spec/integration/mongoid/finders_spec.rb +28 -85
  50. data/spec/models/address.rb +3 -3
  51. data/spec/models/animal.rb +2 -2
  52. data/spec/models/country_code.rb +2 -2
  53. data/spec/models/game.rb +1 -2
  54. data/spec/models/inheritance.rb +5 -5
  55. data/spec/models/location.rb +2 -2
  56. data/spec/models/name.rb +3 -3
  57. data/spec/models/namespacing.rb +2 -2
  58. data/spec/models/patient.rb +0 -2
  59. data/spec/models/person.rb +4 -6
  60. data/spec/models/pet.rb +3 -3
  61. data/spec/models/pet_owner.rb +3 -3
  62. data/spec/models/phone.rb +3 -3
  63. data/spec/models/post.rb +1 -1
  64. data/spec/models/translation.rb +2 -2
  65. data/spec/models/vet_visit.rb +2 -2
  66. data/spec/spec_helper.rb +2 -2
  67. data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
  68. data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
  69. data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
  70. data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
  71. data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
  72. data/spec/unit/mongoid/associations/options_spec.rb +19 -20
  73. data/spec/unit/mongoid/associations_spec.rb +12 -74
  74. data/spec/unit/mongoid/attributes_spec.rb +51 -83
  75. data/spec/unit/mongoid/collection_spec.rb +0 -46
  76. data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
  77. data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
  78. data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
  79. data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
  80. data/spec/unit/mongoid/commands_spec.rb +11 -20
  81. data/spec/unit/mongoid/config_spec.rb +0 -18
  82. data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
  83. data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
  84. data/spec/unit/mongoid/criteria_spec.rb +78 -107
  85. data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
  86. data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
  87. data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
  88. data/spec/unit/mongoid/document_spec.rb +34 -71
  89. data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
  90. data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
  91. data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
  92. data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
  93. data/spec/unit/mongoid/field_spec.rb +0 -62
  94. data/spec/unit/mongoid/fields_spec.rb +0 -33
  95. data/spec/unit/mongoid/finders_spec.rb +1 -37
  96. data/spec/unit/mongoid/identity_spec.rb +6 -47
  97. data/spec/unit/mongoid/named_scope_spec.rb +2 -15
  98. data/spec/unit/mongoid/scope_spec.rb +1 -1
  99. data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
  100. data/spec/unit/mongoid_spec.rb +2 -11
  101. metadata +14 -64
  102. data/lib/mongoid/associations/meta_data.rb +0 -28
  103. data/lib/mongoid/contexts/ids.rb +0 -25
  104. data/lib/mongoid/deprecation.rb +0 -22
  105. data/lib/mongoid/dirty.rb +0 -203
  106. data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
  107. data/lib/mongoid/extensions/binary/conversions.rb +0 -17
  108. data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
  109. data/lib/mongoid/extras.rb +0 -61
  110. data/lib/mongoid/javascript/functions.yml +0 -37
  111. data/lib/mongoid/javascript.rb +0 -21
  112. data/lib/mongoid/observable.rb +0 -30
  113. data/lib/mongoid/paths.rb +0 -54
  114. data/lib/mongoid/persistence/command.rb +0 -20
  115. data/lib/mongoid/persistence/insert.rb +0 -71
  116. data/lib/mongoid/persistence/update.rb +0 -78
  117. data/lib/mongoid/persistence.rb +0 -27
  118. data/lib/mongoid/state.rb +0 -32
  119. data/spec/integration/mongoid/dirty_spec.rb +0 -70
  120. data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
  121. data/spec/models/callbacks.rb +0 -18
  122. data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
  123. data/spec/unit/mongoid/contexts_spec.rb +0 -25
  124. data/spec/unit/mongoid/deprecation_spec.rb +0 -24
  125. data/spec/unit/mongoid/dirty_spec.rb +0 -286
  126. data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
  127. data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
  128. data/spec/unit/mongoid/extras_spec.rb +0 -102
  129. data/spec/unit/mongoid/javascript_spec.rb +0 -48
  130. data/spec/unit/mongoid/observable_spec.rb +0 -46
  131. data/spec/unit/mongoid/paths_spec.rb +0 -124
  132. data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
  133. data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
  134. data/spec/unit/mongoid/persistence_spec.rb +0 -40
  135. data/spec/unit/mongoid/state_spec.rb +0 -83
@@ -1,37 +0,0 @@
1
- aggregate:
2
- "function(obj, prev) {
3
- prev.count++;
4
- }"
5
-
6
- group:
7
- "function(obj, prev) {
8
- prev.group.push(obj);
9
- }"
10
-
11
- max:
12
- "function(obj, prev) {
13
- if (prev.max == 'start') {
14
- prev.max = obj.[field];
15
- }
16
- if (prev.max < obj.[field]) {
17
- prev.max = obj.[field];
18
- }
19
- }"
20
-
21
- min:
22
- "function(obj, prev) {
23
- if (prev.min == 'start') {
24
- prev.min = obj.[field];
25
- }
26
- if (prev.min > obj.[field]) {
27
- prev.min = obj.[field];
28
- }
29
- }"
30
-
31
- sum:
32
- "function(obj, prev) {
33
- if (prev.sum == 'start') {
34
- prev.sum = 0;
35
- }
36
- prev.sum += obj.[field];
37
- }"
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- class Javascript
4
- # Constant for the file that defines all the js functions.
5
- FUNCTIONS = File.join(File.dirname(__FILE__), "javascript", "functions.yml")
6
-
7
- # Load the javascript functions and define a class method for each one,
8
- # that memoizes the value.
9
- #
10
- # Example:
11
- #
12
- # <tt>Mongoid::Javascript.aggregate</tt>
13
- YAML.load(File.read(FUNCTIONS)).each_pair do |key, function|
14
- (class << self; self; end).class_eval <<-EOT
15
- def #{key}
16
- @#{key} ||= "#{function}"
17
- end
18
- EOT
19
- end
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Observable #:nodoc:
4
- extend ActiveSupport::Concern
5
- included do
6
- attr_reader :observers
7
- end
8
-
9
- # Add an observer to this object. This mimics the standard Ruby observable
10
- # library.
11
- #
12
- # Example:
13
- #
14
- # <tt>address.add_observer(person)</tt>
15
- def add_observer(object)
16
- @observers ||= []
17
- @observers.push(object)
18
- end
19
-
20
- # Notify all the objects observing this object of an update. All observers
21
- # need to respond to the update method in order to handle this.
22
- #
23
- # Example:
24
- #
25
- # <tt>document.notify_observers(self)</tt>
26
- def notify_observers(*args)
27
- @observers.dup.each { |observer| observer.observe(*args) } if @observers
28
- end
29
- end
30
- end
data/lib/mongoid/paths.rb DELETED
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Paths #:nodoc:
4
- extend ActiveSupport::Concern
5
- included do
6
- cattr_accessor :_path, :_position
7
- delegate :_path, :_position, :to => "self.class"
8
- end
9
- module InstanceMethods
10
- # Return the path to this +Document+ in JSON notation, used for atomic
11
- # updates via $set in MongoDB.
12
- #
13
- # Example:
14
- #
15
- # <tt>address.path # returns "addresses"</tt>
16
- def path
17
- self._path ||= climb("") do |document, value|
18
- value = "#{document.association_name}#{"." + value unless value.blank?}"
19
- end
20
- end
21
-
22
- # Returns the positional operator of this document for modification.
23
- #
24
- # Example:
25
- #
26
- # <tt>address.position</tt>
27
- def position
28
- self._position ||= (path.blank? ? "" : "#{path}.$")
29
- end
30
-
31
- # Return the selector for this document to be matched exactly for use
32
- # with MongoDB's $ operator.
33
- #
34
- # Example:
35
- #
36
- # <tt>address.selector</tt>
37
- def selector
38
- @selector ||= climb({ "_id" => _root.id }) do |document, value|
39
- value["#{document.path}._id"] = document.id; value
40
- end
41
- end
42
-
43
- protected
44
- def climb(value, &block)
45
- document = self;
46
- while (document._parent) do
47
- value = yield document, value
48
- document = document._parent
49
- end
50
- value
51
- end
52
- end
53
- end
54
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Persistence #:nodoc:
4
- # Mixin for common functionality for all persistence commands.
5
- module Command
6
- attr_reader :collection, :document, :options, :validate
7
- # Initialize the persistence +Command+.
8
- #
9
- # Options:
10
- #
11
- # document: The +Document+ to be persisted.
12
- # validate: Is the document to be validated.
13
- def init(document, validate)
14
- @collection = document.embedded ? document._root.collection : document.collection
15
- @document = document
16
- @validate = validate
17
- end
18
- end
19
- end
20
- end
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Persistence #:nodoc:
4
- # Insert is a persistence command responsible for taking a document that
5
- # has not been saved to the database and saving it.
6
- #
7
- # The underlying query resembles the following MongoDB query:
8
- #
9
- # collection.insert(
10
- # { "_id" : 1, "field" : "value" },
11
- # false
12
- # );
13
- class Insert
14
- include Persistence::Command
15
-
16
- # Create the new insert persister.
17
- #
18
- # Options:
19
- #
20
- # document: The +Document+ to persist.
21
- # validate: +Boolean+ to validate or not.
22
- #
23
- # Example:
24
- #
25
- # <tt>Insert.new(document)</tt>
26
- def initialize(document, validate = true)
27
- init(document, validate)
28
- @options = { :safe => Mongoid.persist_in_safe_mode }
29
- end
30
-
31
- # Insert the new document in the database. This delegates to the standard
32
- # MongoDB collection's insert command.
33
- #
34
- # Example:
35
- #
36
- # <tt>Insert.persist</tt>
37
- #
38
- # Returns:
39
- #
40
- # The +Document+, whether the insert succeeded or not.
41
- def persist
42
- return @document if validate && !@document.valid?
43
- @document.run_callbacks(:create, :save) do
44
- @document.new_record = false if insert
45
- @document
46
- end
47
- end
48
-
49
- protected
50
- # Insert the document into the database.
51
- def insert
52
- if @document.embedded
53
- insert_embedded
54
- else
55
- collection.insert(@document.raw_attributes, options)
56
- end
57
- end
58
-
59
- # Logic for determining how to insert the embedded doc.
60
- def insert_embedded
61
- parent = @document._parent
62
- if parent.new_record?
63
- @document.notify_observers(document, true); parent.insert
64
- else
65
- update = { @document.path => { "$push" => @document.raw_attributes } }
66
- collection.update(parent.selector, update, @options)
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,78 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module Persistence #:nodoc:
4
- # Update is a persistence command responsible for taking a document that
5
- # has already been saved to the database and saving it, depending on
6
- # whether or not the document has been modified.
7
- #
8
- # Before persisting the command will check via dirty attributes if the
9
- # document has changed, if not, it will simply return true. If it has it
10
- # will go through the validation steps, run callbacks, and set the changed
11
- # fields atomically on the document. The underlying query resembles the
12
- # following MongoDB query:
13
- #
14
- # collection.update(
15
- # { "_id" : 1,
16
- # { "$set" : { "field" : "value" },
17
- # false,
18
- # false
19
- # );
20
- #
21
- # For embedded documents it will use the positional locator:
22
- #
23
- # collection.update(
24
- # { "_id" : 1, "addresses._id" : 2 },
25
- # { "$set" : { "addresses.$.field" : "value" },
26
- # false,
27
- # false
28
- # );
29
- #
30
- class Update
31
- include Persistence::Command
32
-
33
- # Create the new update persister.
34
- #
35
- # Options:
36
- #
37
- # document: The +Document+ to persist.
38
- # validate: +Boolean+ to validate or not.
39
- #
40
- # Example:
41
- #
42
- # <tt>Update.new(document)</tt>
43
- def initialize(document, validate = true)
44
- init(document, validate)
45
- @options = { :multi => false, :safe => Mongoid.persist_in_safe_mode }
46
- end
47
-
48
- # Persist the document that is to be updated to the database. This will
49
- # only write changed fields via MongoDB's $set modifier operation.
50
- #
51
- # Example:
52
- #
53
- # <tt>Update.persist</tt>
54
- #
55
- # Returns:
56
- #
57
- # +true+ or +false+, depending on validation.
58
- def persist
59
- if @document.changed?
60
- return false if validate && !@document.valid?
61
- @document.run_callbacks(:save, :update) do
62
- if update
63
- @document.move_changes
64
- else
65
- return false
66
- end
67
- end
68
- end; true
69
- end
70
-
71
- protected
72
- # Update the document in the database atomically.
73
- def update
74
- collection.update(@document.selector, { "$set" => @document.setters }, @options)
75
- end
76
- end
77
- end
78
- end
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
- require "mongoid/persistence/command"
3
- require "mongoid/persistence/insert"
4
- require "mongoid/persistence/update"
5
-
6
- module Mongoid #:nodoc:
7
- module Persistence #:nodoc:
8
- # Insert a new +Document+ into the database. Will return the document
9
- # itself whether or not the save was successful.
10
- #
11
- # Example:
12
- #
13
- # <tt>document.insert</tt>
14
- def insert
15
- Insert.new(self).persist
16
- end
17
-
18
- # Update the +Document+ in the datbase.
19
- #
20
- # Example:
21
- #
22
- # <tt>document.update</tt>
23
- def update
24
- Update.new(self).persist
25
- end
26
- end
27
- end
data/lib/mongoid/state.rb DELETED
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid #:nodoc:
3
- module State #:nodoc:
4
- # Returns true if the +Document+ has not been persisted to the database,
5
- # false if it has. This is determined by the variable @new_record
6
- # and NOT if the object has an id.
7
- def new_record?
8
- @new_record == true
9
- end
10
-
11
- # Sets the new_record boolean - used after document is saved.
12
- def new_record=(saved)
13
- @new_record = saved
14
- end
15
-
16
- # Checks if the document has been saved to the database.
17
- def persisted?
18
- !new_record?
19
- end
20
-
21
- # Returns true if the +Document+ has been succesfully destroyed, and false if it hasn't.
22
- # This is determined by the variable @destroyed and NOT by checking the database.
23
- def destroyed?
24
- @destroyed == true
25
- end
26
-
27
- # Sets the destroyed boolean - used after document is destroyed.
28
- def destroyed=(destroyed)
29
- @destroyed = destroyed && true
30
- end
31
- end
32
- end
@@ -1,70 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Dirty do
4
-
5
- before do
6
- Person.delete_all
7
- end
8
-
9
- after do
10
- Person.delete_all
11
- end
12
-
13
- context "when fields are getting changed" do
14
-
15
- before do
16
- @person = Person.create(:title => "MC", :ssn => "234-11-2533")
17
- @person.title = "DJ"
18
- @person.write_attribute(:ssn, "222-22-2222")
19
- end
20
-
21
- it "marks the document as changed" do
22
- @person.changed?.should == true
23
- end
24
-
25
- it "marks field changes" do
26
- @person.changes.should == {
27
- "title" => [ "MC", "DJ" ],
28
- "ssn" => [ "234-11-2533", "222-22-2222" ]
29
- }
30
- end
31
-
32
- it "marks changed fields" do
33
- @person.changed.should == [ "title", "ssn" ]
34
- end
35
-
36
- it "marks the field as changed" do
37
- @person.title_changed?.should == true
38
- end
39
-
40
- it "stores previous field values" do
41
- @person.title_was.should == "MC"
42
- end
43
-
44
- it "marks field changes" do
45
- @person.title_change.should == [ "MC", "DJ" ]
46
- end
47
-
48
- it "allows reset of field changes" do
49
- @person.reset_title!
50
- @person.title.should == "MC"
51
- @person.changed.should == [ "ssn" ]
52
- end
53
-
54
- context "after a save" do
55
-
56
- before do
57
- @person.save!
58
- end
59
-
60
- it "clears changes" do
61
- @person.changed?.should == false
62
- end
63
-
64
- it "stores previous changes" do
65
- @person.previous_changes["title"].should == [ "MC", "DJ" ]
66
- @person.previous_changes["ssn"].should == [ "234-11-2533", "222-22-2222" ]
67
- end
68
- end
69
- end
70
- end
@@ -1,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Persistence::Update do
4
-
5
- before do
6
- Person.delete_all
7
- end
8
-
9
- after do
10
- Person.delete_all
11
- end
12
-
13
- describe "#persist" do
14
-
15
- let(:person) do
16
- Person.create!(:ssn => "111-11-1111", :title => "Sir")
17
- end
18
-
19
- context "when the document has changed" do
20
-
21
- before do
22
- @person = Person.find(person.id)
23
- @person.title = "Grand Poobah"
24
- end
25
-
26
- it "updates the document in the database" do
27
- update = Mongoid::Persistence::Update.new(@person)
28
- update.persist
29
- from_db = Person.find(@person.id)
30
- from_db.title.should == "Grand Poobah"
31
- end
32
- end
33
-
34
- context "when the document has not changed" do
35
-
36
- before do
37
- @person = Person.find(person.id)
38
- end
39
-
40
- it "returns true" do
41
- update = Mongoid::Persistence::Update.new(@person)
42
- update.persist.should == true
43
- end
44
- end
45
- end
46
- end
@@ -1,18 +0,0 @@
1
- class Artist
2
- include Mongoid::Document
3
- field :name
4
- embeds_many :songs
5
-
6
- after_create :create_songs
7
-
8
- protected
9
- def create_songs
10
- 2.times { |n| songs.create!(:title => "#{n}") }
11
- end
12
- end
13
-
14
- class Song
15
- include Mongoid::Document
16
- field :title
17
- embedded_in :artist, :inverse_of => :songs
18
- end
@@ -1,88 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Associations::MetaData do
4
-
5
- before do
6
- @extension = lambda { "Test" }
7
- end
8
-
9
- let(:association) do
10
- Mongoid::Associations::HasManyRelated
11
- end
12
-
13
- let(:options) do
14
- Mongoid::Associations::Options.new(
15
- :name => :games,
16
- :extend => @extension,
17
- :foreign_key => "person_id",
18
- :inverse_of => :people
19
- )
20
- end
21
-
22
- let(:metadata) do
23
- Mongoid::Associations::MetaData.new(association, options)
24
- end
25
-
26
- describe "#extension" do
27
-
28
- it "delegates to the options" do
29
- metadata.extension.should == @extension
30
- end
31
- end
32
-
33
- describe "#foreign_key" do
34
-
35
- it "delegates to the options" do
36
- metadata.foreign_key.should == "person_id"
37
- end
38
- end
39
-
40
- describe "#inverse_of" do
41
-
42
- it "delegates to the options" do
43
- metadata.inverse_of.should == :people
44
- end
45
- end
46
-
47
- describe "#klass" do
48
-
49
- it "returns the associated klass" do
50
- metadata.klass.should == Game
51
- end
52
- end
53
-
54
- describe "#macro" do
55
-
56
- it "returns the association macro" do
57
- metadata.macro.should == :has_many_related
58
- end
59
- end
60
-
61
- describe "#name" do
62
-
63
- it "delegates to the options" do
64
- metadata.name.should == "games"
65
- end
66
- end
67
-
68
- describe "#options" do
69
-
70
- it "returns the association options" do
71
- metadata.options.should == options
72
- end
73
- end
74
-
75
- describe "#polymorphic" do
76
-
77
- it "delegates to the options" do
78
- metadata.polymorphic.should be_false
79
- end
80
- end
81
-
82
- describe "#association" do
83
-
84
- it "returns the association type" do
85
- metadata.association.should == Mongoid::Associations::HasManyRelated
86
- end
87
- end
88
- end
@@ -1,25 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Contexts do
4
-
5
- context ".context_for" do
6
- let(:klass) { stub('klass', :embedded => false) }
7
- let(:criteria) { stub('criteria', :klass => klass) }
8
-
9
- context "when criteria is for a top-level Mongoid::Document" do
10
- it "creates a Mongo context" do
11
- Mongoid::Contexts::Mongo.expects(:new).with(criteria)
12
- Mongoid::Contexts.context_for(criteria)
13
- end
14
- end
15
-
16
- context "when criteria is for an embedded Mongoid::Document" do
17
- it "creates a Mongo context" do
18
- klass.stubs(:embedded).returns(true)
19
- Mongoid::Contexts::Enumerable.expects(:new).with(criteria)
20
- Mongoid::Contexts.context_for(criteria)
21
- end
22
- end
23
- end
24
-
25
- end
@@ -1,24 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Deprecation do
4
-
5
- let(:logger) do
6
- stub.quacks_like(Logger.allocate)
7
- end
8
-
9
- before do
10
- Logger.expects(:new).with($stdout).returns(logger)
11
- end
12
-
13
- describe "#alert" do
14
-
15
- let(:deprecation) do
16
- Mongoid::Deprecation.instance
17
- end
18
-
19
- it "calls warn on the memoized logger" do
20
- logger.expects(:warn).with("Deprecation: testing")
21
- deprecation.alert("testing")
22
- end
23
- end
24
- end