Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#935](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/935) Fix schema cache generation
(**breaking change**)
- [#936](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/936) Fix deteministic fetch when table has a composite primary key
- [#938](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/938) Fix date columns serialization for range values

#### Changed

Expand Down
3 changes: 2 additions & 1 deletion lib/active_record/connection_adapters/sqlserver/type/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def sqlserver_type
end

def serialize(value)
return unless value.present?
value = super
return value unless value.acts_like?(:date)

date = super(value).to_s(:_sqlserver_dateformat)
Data.new date, self
Expand Down
4 changes: 4 additions & 0 deletions test/cases/column_test_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def assert_obj_set_and_save(attribute, value)
_(obj.date).must_equal Date.civil(0001, 4, 1)
obj.reload
_(obj.date).must_equal Date.civil(0001, 4, 1)
# Can filter by date range
_(obj).must_equal obj.class.where(date: obj.date..Date::Infinity.new).first
# Can keep and return assigned date.
assert_obj_set_and_save :date, Date.civil(1972, 04, 14)
# Can accept and cast time objects.
Expand Down Expand Up @@ -333,6 +335,8 @@ def assert_obj_set_and_save(attribute, value)
obj.reload
_(obj.datetime).must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
_(obj).must_equal obj.class.where(datetime: time).first
# Can filter by datetime range
_(obj).must_equal obj.class.where(datetime: time..DateTime::Infinity.new).first
# Will cast to true DB value on attribute write, save and return again.
time = Time.utc 2010, 04, 01, 12, 34, 56, 234567
time2 = Time.utc 2010, 04, 01, 12, 34, 56, 233000
Expand Down