Sha256: 7c61d79094b6d0221fd26672c22d11e9b7bae5ae2641844a8ee37af475878fea

Contents?: true

Size: 780 Bytes

Versions: 3

Compression:

Stored size: 780 Bytes

Contents

# encoding: utf-8

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

class TestDoc
  include Mongoid::Document
  include Mongoid::Timestamps
  field :name, type: String
end

class TestDocTwo
  include Mongoid::Document
  field :name, type: String
  field :modified_at, type: Time
end

describe "Mongoid::Document#touch" do

  it "should update the updated_at field" do
    doc = TestDoc.create(name: "My test doc")
    origin_at = doc.updated_at
    sleep 1
    doc.touch
    doc.updated_at.should > origin_at
  end
  
  it "should update a custom Time field" do
    doc = TestDocTwo.create(name: "My test doc", modified_at: Time.now.utc)
    origin_at = doc.modified_at
    sleep 1
    doc.touch(:modified_at)
    doc.modified_at.should > origin_at  
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid_touch-0.0.4 spec/mongoid_touch_spec.rb
mongoid_touch-0.0.3 spec/mongoid_touch_spec.rb
mongoid_touch-0.0.2 spec/mongoid_touch_spec.rb