Sha256: 9e6cdc04e254a3e3dcfeae9ee56512db24856a131703599dde9c372d8400286a

Contents?: true

Size: 823 Bytes

Versions: 8

Compression:

Stored size: 823 Bytes

Contents

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

describe Pupa::Concerns::Timestamps do
  let :klass do
    Class.new(Pupa::Base) do
      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
    object.created_at.should be_within(1).of(Time.now.utc)
    object.updated_at.should 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
    object.created_at.should == Time.new(2000)
    object.updated_at.should be_within(1).of(Time.now.utc)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pupa-0.0.8 spec/models/concerns/timestamps_spec.rb
pupa-0.0.7 spec/models/concerns/timestamps_spec.rb
pupa-0.0.6 spec/models/concerns/timestamps_spec.rb
pupa-0.0.5 spec/models/concerns/timestamps_spec.rb
pupa-0.0.4 spec/models/concerns/timestamps_spec.rb
pupa-0.0.3 spec/models/concerns/timestamps_spec.rb
pupa-0.0.2 spec/models/concerns/timestamps_spec.rb
pupa-0.0.1 spec/models/concerns/timestamps_spec.rb