Sha256: 9ea7c98288d4aabaf95804572233064e81caae5add6923ba70cbbfbeee97e45f

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

describe Ampere::Timestamps do
  before :all do
    Ampere.connect
    
    Ampere.connection.flushall
    
    class Comment
      include Ampere::Model
      include Ampere::Timestamps
      
      field :body
    end
  end
  
  context 'when included in models' do
    it 'sets created_at for newly-created record' do
      Timecop.freeze(Time.now) do
        time = Time.now
        
        c = Comment.create body: "I am intrigued by your ideas, and would like to subscribe to your newsletter."
        c.created_at.should eq(time)
        c.updated_at.should eq(time)
      end
    end
    
    it 'sets updated_at when changing records' do
      c = Comment.create body: "I am intrigued by your ideas, and would like to subscribe to your newsletter."
      created_at = c.created_at
      
      time = 0
      
      Timecop.freeze(Time.now + 30) do
        time = Time.now
        
        c.body = "Theodore Roosevelt riding a moose, therefore your argument is invalid."
        c.save
      end
      
      c.updated_at.should eq(time)
      c.created_at.should eq(created_at)
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ampere-1.2.2 spec/models/timestamps_spec.rb
ampere-1.2.1 spec/models/timestamps_spec.rb
ampere-1.2.0 spec/models/timestamps_spec.rb