diff --git a/spec/support/shared_examples/store_attribute_datetime.rb b/spec/support/shared_examples/store_attribute_datetime.rb index fa724c2..4a742fa 100644 --- a/spec/support/shared_examples/store_attribute_datetime.rb +++ b/spec/support/shared_examples/store_attribute_datetime.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/support/shared_examples/store_attribute_decimal.rb b/spec/support/shared_examples/store_attribute_decimal.rb index 38ccaec..d2630b4 100644 --- a/spec/support/shared_examples/store_attribute_decimal.rb +++ b/spec/support/shared_examples/store_attribute_decimal.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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