Skip to content

Commit

Permalink
Always use precision truncate in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Exterm1nate committed Nov 28, 2024
1 parent cca95ee commit fe85d8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
50 changes: 32 additions & 18 deletions spec/support/shared_examples/store_attribute_datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
context "when internal value is a date" do
let(:internal_value) { random_date }

it { is_expected.to eq(internal_value.to_time(:utc).in_time_zone) }
it { is_expected.to eq(apply_datetime_precision(internal_value.to_time(:utc).in_time_zone, max_precision)) }
end

context "when internal value is a date string" do
let(:internal_value) { random_date.iso8601 }

it { is_expected.to eq(Date.parse(internal_value).to_time(:utc).in_time_zone) }
it do
expect(call_method).to eq(
apply_datetime_precision(Date.parse(internal_value).to_time(:utc).in_time_zone, max_precision),
)
end
end

context "when internal value is a datetime" do
Expand All @@ -58,7 +62,7 @@
context "when internal value is a datetime string" do
let(:internal_value) { random_datetime.utc.iso8601 }

it { is_expected.to eq(Time.zone.parse(internal_value).in_time_zone) }
it { is_expected.to eq(apply_datetime_precision(Time.zone.parse(internal_value).in_time_zone, max_precision)) }
end

context "when internal value is a datetime string with fractional seconds digits" do
Expand All @@ -78,13 +82,17 @@
context "when internal value is a date" do
let(:internal_value) { random_date }

it { is_expected.to eq(internal_value.to_time(:utc).in_time_zone) }
it { is_expected.to eq(apply_datetime_precision(internal_value.to_time(:utc).in_time_zone, max_precision)) }
end

context "when internal value is a date string" do
let(:internal_value) { random_date.iso8601 }

it { is_expected.to eq(Date.parse(internal_value).to_time(:utc).in_time_zone) }
it do
expect(call_method).to eq(
apply_datetime_precision(Date.parse(internal_value).to_time(:utc).in_time_zone, max_precision),
)
end
end

context "when internal value is a datetime" do
Expand All @@ -96,7 +104,7 @@
context "when internal value is a datetime string" do
let(:internal_value) { random_datetime.utc.iso8601 }

it { is_expected.to eq(Time.zone.parse(internal_value).in_time_zone) }
it { is_expected.to eq(apply_datetime_precision(Time.zone.parse(internal_value).in_time_zone, max_precision)) }
end

context "when internal value is a datetime string with fractional seconds digits" do
Expand Down Expand Up @@ -169,8 +177,9 @@
it "sets datetime as string" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s])
.to eq(Date.parse(value).to_time(:utc).iso8601(max_precision))
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(
Date.parse(value).to_time(:utc).iso8601(max_precision),
)
end
end

Expand All @@ -190,8 +199,9 @@
it "sets datetime as string" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s])
.to eq(Time.zone.parse(value).utc.iso8601(max_precision))
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(
Time.zone.parse(value).utc.iso8601(max_precision),
)
end
end

Expand All @@ -201,8 +211,9 @@
it "sets datetime as string" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s])
.to eq(Time.zone.parse(value).utc.iso8601(max_precision))
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(
Time.zone.parse(value).utc.iso8601(max_precision),
)
end
end
end
Expand Down Expand Up @@ -230,8 +241,9 @@
it "sets datetime as string" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s])
.to eq(Date.parse(value).to_time(:utc).iso8601(max_precision))
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(
Date.parse(value).to_time(:utc).iso8601(max_precision),
)
end
end

Expand All @@ -251,8 +263,9 @@
it "sets datetime as string" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s])
.to eq(Time.zone.parse(value).utc.iso8601(max_precision))
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(
Time.zone.parse(value).utc.iso8601(max_precision),
)
end
end

Expand All @@ -262,8 +275,9 @@
it "sets datetime as string" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s])
.to eq(Time.zone.parse(value).utc.iso8601(max_precision))
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(
Time.zone.parse(value).utc.iso8601(max_precision),
)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/support/shared_examples/store_attribute_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
context "when internal value is an integer" do
let(:internal_value) { random_integer }

it { is_expected.to eq(internal_value.to_d) }
it { is_expected.to eq(internal_value.to_d.truncate(max_precision)) }
end

context "when internal value is a float" do
let(:internal_value) { random_float }

it { is_expected.to eq(internal_value.to_d) }
it { is_expected.to eq(internal_value.to_d.truncate(max_precision)) }
end

context "when internal value is a big decimal" do
Expand All @@ -39,7 +39,7 @@
context "when internal value is an integer string" do
let(:internal_value) { random_integer.to_s }

it { is_expected.to eq(internal_value.to_d) }
it { is_expected.to eq(internal_value.to_d.truncate(max_precision)) }
end

context "when internal value is a decimal string" do
Expand Down Expand Up @@ -82,7 +82,7 @@
it "sets decimal" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(value.to_d.to_s)
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(value.to_d.truncate(max_precision).to_s)
end
end

Expand All @@ -92,7 +92,7 @@
it "sets decimal" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(value.to_d.to_s)
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(value.to_d.truncate(max_precision).to_s)
end
end

Expand All @@ -112,7 +112,7 @@
it "sets decimal" do
call_method

expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(value.to_d.to_s)
expect(record.public_send(store_attr_name)[attr_name.to_s]).to eq(value.to_d.truncate(max_precision).to_s)
end
end

Expand Down

0 comments on commit fe85d8e

Please sign in to comment.