mongoid 0.7.1 → 0.7.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -47,13 +47,17 @@ module Mongoid #:nodoc:
47
47
 
48
48
  # Save the +Document+. Delegates to the Save command.
49
49
  def save
50
- Save.execute(self)
50
+ new_record? ? Create.execute(self) : Save.execute(self)
51
51
  end
52
52
 
53
53
  # Save the +Document+. Delegates to the Save command. If the command
54
54
  # returns false then a +ValidationError+ will be raised.
55
55
  def save!
56
- Save.execute(self) || (raise ValidationsError.new(self.errors.full_messages))
56
+ if new_record?
57
+ return Create.execute(self) || (raise ValidationsError.new(self.errors.full_messages))
58
+ else
59
+ return Save.execute(self) || (raise ValidationsError.new(self.errors.full_messages))
60
+ end
57
61
  end
58
62
 
59
63
  # Update the attributes of the +Document+. Will call save after the
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.7.1"
8
+ s.version = "0.7.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
@@ -5,7 +5,7 @@ describe Mongoid::Commands do
5
5
  context "instance methods" do
6
6
 
7
7
  before do
8
- @person = Person.new(:_id => Mongo::ObjectID.new)
8
+ @person = Person.new(:_id => Mongo::ObjectID.new.to_s)
9
9
  end
10
10
 
11
11
  describe "#delete" do
@@ -33,6 +33,19 @@ describe Mongoid::Commands do
33
33
  @person.save
34
34
  end
35
35
 
36
+ context "when document is new" do
37
+
38
+ before do
39
+ @person = Person.new
40
+ end
41
+
42
+ it "delegates to the Create command" do
43
+ Mongoid::Commands::Create.expects(:execute).with(@person).returns(@person)
44
+ @person.save
45
+ end
46
+
47
+ end
48
+
36
49
  end
37
50
 
38
51
  describe "#save!" do
@@ -55,6 +68,28 @@ describe Mongoid::Commands do
55
68
 
56
69
  end
57
70
 
71
+ context "when document is new" do
72
+
73
+ before do
74
+ @person = Person.new
75
+ end
76
+
77
+ it "delegates to the Create command" do
78
+ Mongoid::Commands::Create.expects(:execute).with(@person).returns(@person)
79
+ @person.save!
80
+ end
81
+
82
+ context "when validation fails" do
83
+
84
+ it "it raises a ValidationsError" do
85
+ Mongoid::Commands::Create.expects(:execute).with(@person).returns(false)
86
+ lambda { @person.save! }.should raise_error
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
58
93
  end
59
94
 
60
95
  describe "#update_attributes" do
@@ -123,7 +158,7 @@ describe Mongoid::Commands do
123
158
  it "raises an exception" do
124
159
  person = stub(:errors => stub(:empty? => false))
125
160
  Mongoid::Commands::Create.expects(:execute).returns(person)
126
- lambda { Person.create! }.should raise_error
161
+ lambda { Person.create! }.should raise_error
127
162
  end
128
163
 
129
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan