mongomodel 0.3.0 → 0.3.1

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.
@@ -52,17 +52,17 @@ module MongoModel
52
52
  doc
53
53
  end
54
54
 
55
- def create(*args, &block)
55
+ def create(*args)
56
56
  scoped.create(*args) do |doc|
57
57
  set_inverse_association(doc)
58
- block.call(doc) if block
58
+ yield doc if block_given?
59
59
  end
60
60
  end
61
61
 
62
- def create!(*args, &block)
62
+ def create!(*args)
63
63
  scoped.create!(*args) do |doc|
64
64
  set_inverse_association(doc)
65
- block.call(doc) if block
65
+ yield doc if block_given?
66
66
  end
67
67
  end
68
68
 
@@ -119,22 +119,25 @@ module MongoModel
119
119
 
120
120
  delegate :ensure_class, :to => :association
121
121
 
122
- def build(*args, &block)
123
- doc = association.build(*args, &block)
124
- self << doc
125
- doc
122
+ def build(*args)
123
+ association.build(*args) do |doc|
124
+ self << doc
125
+ yield doc if block_given?
126
+ end
126
127
  end
127
128
 
128
- def create(*args, &block)
129
- doc = association.create(*args, &block)
130
- self << doc
131
- doc
129
+ def create(*args)
130
+ association.create(*args) do |doc|
131
+ self << doc
132
+ yield doc if block_given?
133
+ end
132
134
  end
133
135
 
134
- def create!(*args, &block)
135
- doc = association.create!(*args, &block)
136
- self << doc
137
- doc
136
+ def create!(*args)
137
+ association.create!(*args) do |doc|
138
+ self << doc
139
+ yield doc if block_given?
140
+ end
138
141
  end
139
142
 
140
143
  def []=(index, doc)
@@ -5,6 +5,10 @@ require 'active_support/core_ext/string/inflections'
5
5
 
6
6
  module MongoModel
7
7
  class Document < EmbeddedDocument
8
+ def ==(other)
9
+ self.class == other.class && id == other.id
10
+ end
11
+
8
12
  include DocumentExtensions::Persistence
9
13
  include DocumentExtensions::OptimisticLocking
10
14
  include DocumentExtensions::CollectionModifiers
@@ -1,7 +1,7 @@
1
1
  module MongoModel
2
2
  class EmbeddedDocument
3
3
  def ==(other)
4
- other.is_a?(self.class) && other.attributes == attributes
4
+ self.class == other.class && attributes == other.attributes
5
5
  end
6
6
 
7
7
  include Attributes
@@ -1,3 +1,3 @@
1
1
  module MongoModel
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -13,6 +13,25 @@ module MongoModel
13
13
  property.default(mock('instance', :generate_id => 'abc-123')).should == 'abc-123'
14
14
  end
15
15
 
16
+ describe "equality" do
17
+ define_class(:DocumentA, Document)
18
+ define_class(:DocumentB, Document)
19
+
20
+ subject { DocumentA.new(:id => 'test') }
21
+
22
+ it "should be equal to another document of the same class with the same id" do
23
+ subject.should == DocumentA.new(:id => 'test')
24
+ end
25
+
26
+ it "should not be equal to another document of the same class with a different id" do
27
+ subject.should_not == DocumentA.new(:id => 'not-test')
28
+ end
29
+
30
+ it "should not be equal to another document of a different class with the same id" do
31
+ subject.should_not == DocumentB.new(:id => 'test')
32
+ end
33
+ end
34
+
16
35
  describe "single collection inheritance" do
17
36
  define_class(:Event, Document)
18
37
  define_class(:SpecialEvent, :Event)
@@ -2,31 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module MongoModel
4
4
  specs_for(EmbeddedDocument, Document) do
5
- describe "equality" do
6
- define_class(:DocumentA, described_class) do
7
- property :name, String
8
- end
9
-
10
- define_class(:DocumentB, described_class) do
11
- property :name, String
12
- end
13
-
14
- subject { DocumentA.new(:id => 'test', :name => 'Test') }
15
-
16
- it "should be equal to another document of the same class with identical attributes" do
17
- subject.should == DocumentA.new(:id => 'test', :name => 'Test')
18
- end
19
-
20
- it "should not be equal to another document of the same class with different attributes" do
21
- subject.should_not == DocumentA.new(:id => 'test', :name => 'Different')
22
- subject.should_not == DocumentA.new(:id => 'test', :name => 'Test', :special_attribute => 'Different')
23
- end
24
-
25
- it "should not be equal to another document of a different class with identical attributes" do
26
- subject.should_not == DocumentB.new(:id => 'test', :name => 'Different')
27
- end
28
- end
29
-
30
5
  it "should be an abstract class" do
31
6
  described_class.should be_an_abstract_class
32
7
  end
@@ -58,6 +33,31 @@ module MongoModel
58
33
  let(:parent) { Parent.new(:event => special) }
59
34
  let(:reloaded) { parent.save!; Parent.find(parent.id) }
60
35
 
36
+ describe "equality" do
37
+ define_class(:DocumentA, EmbeddedDocument) do
38
+ property :name, String
39
+ end
40
+
41
+ define_class(:DocumentB, EmbeddedDocument) do
42
+ property :name, String
43
+ end
44
+
45
+ subject { DocumentA.new(:id => 'test', :name => 'Test') }
46
+
47
+ it "should be equal to another document of the same class with identical attributes" do
48
+ subject.should == DocumentA.new(:id => 'test', :name => 'Test')
49
+ end
50
+
51
+ it "should not be equal to another document of the same class with different attributes" do
52
+ subject.should_not == DocumentA.new(:id => 'test', :name => 'Different')
53
+ subject.should_not == DocumentA.new(:id => 'test', :name => 'Test', :special_attribute => 'Different')
54
+ end
55
+
56
+ it "should not be equal to another document of a different class with identical attributes" do
57
+ subject.should_not == DocumentB.new(:id => 'test', :name => 'Different')
58
+ end
59
+ end
60
+
61
61
  describe "single collection inheritance" do
62
62
  it "should not typecast to parent type when assigning to property" do
63
63
  parent.event.should be_an_instance_of(SpecialEvent)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomodel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Pohlenz