Merge pull request #41401 from schmijos/addendum-40351
Add missing CHANGELOG entry for #40351
This commit is contained in:
commit
08ef83b7cf
@ -1,3 +1,30 @@
|
||||
* Switch to database adapter return type for `ActiveRecord::Calculations.calculate`
|
||||
when called with `:average` (aliased as `ActiveRecord::Calculations.average`)
|
||||
|
||||
Previously average aggregation returned `BigDecimal` for everything which
|
||||
supported `to_d`. This was especially weird for floating point numbers.
|
||||
|
||||
Database adapters today map database column types to Ruby types more
|
||||
accurately than 10 years ago. So now we simply pass them on
|
||||
(except for special cases which are not `Numeric`).
|
||||
|
||||
```ruby
|
||||
# With the following schema:
|
||||
create_table "measurements" do |t|
|
||||
t.float "temperature"
|
||||
end
|
||||
|
||||
# Before:
|
||||
Measurement.average(:temperature).class
|
||||
# => BigDecimal
|
||||
|
||||
# After:
|
||||
Measurement.average(:temperature).class
|
||||
# => Float
|
||||
```
|
||||
|
||||
*Josua Schmid*
|
||||
|
||||
* PostgreSQL: handle `timestamp with time zone` columns correctly in `schema.rb`.
|
||||
|
||||
Previously they dumped as `t.datetime :column_name`, now they dump as `t.timestamptz :column_name`,
|
||||
|
@ -67,6 +67,14 @@ def test_should_return_float_average_if_db_returns_such
|
||||
assert_equal 37.5, value
|
||||
end
|
||||
|
||||
def test_should_return_decimal_average_if_db_returns_such
|
||||
NumericData.create!(decimal_number: 37.5)
|
||||
|
||||
value = NumericData.average(:decimal_number)
|
||||
assert_instance_of BigDecimal, value
|
||||
assert_equal 37.5, value
|
||||
end
|
||||
|
||||
def test_should_return_nil_as_average
|
||||
assert_nil NumericData.average(:bank_balance)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user