mongoid 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ 0.2.7:
2
+ - Added has_timestamps macro
3
+
1
4
  0.2.6:
2
5
  - Adding destroy_all to document
3
6
  - Adding before and after create callbacks
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -40,7 +40,7 @@ module Mongoid #:nodoc:
40
40
  # For each field that is defined, a getter and setter will be
41
41
  # added as an instance method to the Document.
42
42
  def fields(*names)
43
- @fields = []
43
+ @fields ||= []
44
44
  names.flatten.each do |name|
45
45
  @fields << name
46
46
  define_method(name) { read_attribute(name) }
@@ -58,6 +58,15 @@ module Mongoid #:nodoc:
58
58
  add_association(:has_one, association_name.to_s.titleize, association_name)
59
59
  end
60
60
 
61
+ # Adds timestamps on the Document in the form of the fields 'created_on'
62
+ # and 'last_modified'
63
+ def has_timestamps
64
+ fields :created_on, :last_modified
65
+ class_eval do
66
+ before_save :update_timestamps
67
+ end
68
+ end
69
+
61
70
  # Adds an index on the field specified. Options can be :unique => true or
62
71
  # :unique => false. It will default to the latter.
63
72
  def index(name, options = { :unique => false })
@@ -126,6 +135,11 @@ module Mongoid #:nodoc:
126
135
  @attributes = attributes.symbolize_keys!; save; true
127
136
  end
128
137
 
138
+ def update_timestamps
139
+ self.created_on = Time.now
140
+ self.last_modified = Time.now
141
+ end
142
+
129
143
  private
130
144
 
131
145
  class << self
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
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"]
@@ -39,3 +39,7 @@ class Name < Mongoid::Document
39
39
  :last_name
40
40
  belongs_to :person
41
41
  end
42
+
43
+ class Tester < Mongoid::Document
44
+ has_timestamps
45
+ end
@@ -179,6 +179,21 @@ describe Mongoid::Document do
179
179
 
180
180
  end
181
181
 
182
+ describe "#has_timestamps" do
183
+
184
+ before do
185
+ @tester = Tester.new
186
+ end
187
+
188
+ it "adds created_on and last_modified to the document" do
189
+ @collection.expects(:save).with(@tester.attributes)
190
+ @tester.save
191
+ @tester.created_on.should_not be_nil
192
+ @tester.last_modified.should_not be_nil
193
+ end
194
+
195
+ end
196
+
182
197
  describe "#index" do
183
198
 
184
199
  context "when unique options are not provided" do
@@ -152,6 +152,14 @@ describe Mongoid::Finders do
152
152
 
153
153
  end
154
154
 
155
+ context "when param keys are strings" do
156
+
157
+ it "converts the keys to symbols" do
158
+
159
+ end
160
+
161
+ end
162
+
155
163
  end
156
164
 
157
165
  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.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan