Sha256: 2abae43f92bbc29e7c8d8742420b81fff5887c88ba7571d3731144544800257a

Contents?: true

Size: 854 Bytes

Versions: 5

Compression:

Stored size: 854 Bytes

Contents

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

describe Pupa::Concerns::Timestamps do
  let :klass do
    Class.new do
      include Pupa::Model
      include Pupa::Concerns::Timestamps

      def save
        run_callbacks(:save) do
          unless created_at
            run_callbacks(:create) do
            end
          end
        end
      end
    end
  end

  it 'should set created_at and updated_at on create' do
    object = klass.new
    object.save
    expect(object.created_at).to be_within(1).of(Time.now.utc)
    expect(object.updated_at).to be_within(1).of(Time.now.utc)
  end

  it 'should set updated_at on save' do
    object = klass.new(created_at: Time.new(2000))
    object.save
    expect(object.created_at).to eq(Time.new(2000))
    expect(object.updated_at).to be_within(1).of(Time.now.utc)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pupa-0.2.4 spec/models/concerns/timestamps_spec.rb
pupa-0.2.3 spec/models/concerns/timestamps_spec.rb
pupa-0.2.2 spec/models/concerns/timestamps_spec.rb
pupa-0.2.1 spec/models/concerns/timestamps_spec.rb
pupa-0.2.0 spec/models/concerns/timestamps_spec.rb