2019-11-18 22:21:57 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe RepositoryDateTimeValue, type: :model do
|
2019-12-08 23:53:59 +08:00
|
|
|
let(:date_time_value) do
|
|
|
|
create :repository_date_time_value, data: Time.utc(2000, 10, 11, 1, 4)
|
2019-11-18 22:21:57 +08:00
|
|
|
end
|
|
|
|
|
2019-12-08 23:53:59 +08:00
|
|
|
describe '.formatted' do
|
|
|
|
it 'prints date format with date' do
|
|
|
|
str = '10/11/2000, 01:04'
|
|
|
|
expect(date_time_value.formatted).to eq(str)
|
2019-11-18 22:21:57 +08:00
|
|
|
end
|
2019-12-08 23:53:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.data_changed?' do
|
|
|
|
context 'when has different datetime value' do
|
|
|
|
let(:new_values) { Time.utc(2000, 12, 11, 4, 14).to_s }
|
2019-11-18 22:21:57 +08:00
|
|
|
|
2019-12-08 23:53:59 +08:00
|
|
|
it do
|
|
|
|
expect(date_time_value.data_changed?(new_values)).to be_truthy
|
|
|
|
end
|
2019-11-18 22:21:57 +08:00
|
|
|
end
|
|
|
|
|
2019-12-08 23:53:59 +08:00
|
|
|
context 'when has same datetime value' do
|
|
|
|
let(:new_values) { Time.utc(2000, 10, 11, 1, 4).to_s }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(date_time_value.data_changed?(new_values)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2019-11-18 22:21:57 +08:00
|
|
|
end
|
2019-12-09 20:48:24 +08:00
|
|
|
|
|
|
|
describe 'self.new_with_payload' do
|
|
|
|
let(:user) { create :user }
|
|
|
|
let(:column) { create :repository_column }
|
|
|
|
let(:cell) { build :repository_cell, repository_column: column }
|
|
|
|
let(:attributes) do
|
|
|
|
{
|
|
|
|
repository_cell: cell,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(RepositoryDateTimeValue.new_with_payload(Time.now.utc.to_s, attributes))
|
|
|
|
.to be_an_instance_of RepositoryDateTimeValue
|
|
|
|
end
|
|
|
|
end
|
2019-11-18 22:21:57 +08:00
|
|
|
end
|