diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/querying.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/date_time.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/callbacks_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/date_time_test.rb | 8 |
4 files changed, 18 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb index e8de4db3a7..91c9a0db99 100644 --- a/activerecord/lib/active_record/querying.rb +++ b/activerecord/lib/active_record/querying.rb @@ -55,11 +55,12 @@ module ActiveRecord # The use of this method should be restricted to complicated SQL queries that can't be executed # using the ActiveRecord::Calculations class methods. Look into those before using this. # - # ==== Parameters + # Product.count_by_sql "SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id" + # # => 12 # - # * +sql+ - An SQL statement which should return a count query from the database, see the example below. + # ==== Parameters # - # Product.count_by_sql "SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id" + # * +sql+ - An SQL statement which should return a count query from the database, see the example above. def count_by_sql(sql) sql = sanitize_conditions(sql) connection.select_value(sql, "#{name} Count").to_i diff --git a/activerecord/lib/active_record/type/date_time.rb b/activerecord/lib/active_record/type/date_time.rb index 5f19608a33..0a737815bc 100644 --- a/activerecord/lib/active_record/type/date_time.rb +++ b/activerecord/lib/active_record/type/date_time.rb @@ -11,7 +11,11 @@ module ActiveRecord zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal if value.acts_like?(:time) - value.send(zone_conversion_method) + if value.respond_to?(zone_conversion_method) + value.send(zone_conversion_method) + else + value + end else super end diff --git a/activerecord/test/cases/callbacks_test.rb b/activerecord/test/cases/callbacks_test.rb index 7fa8eeaa77..670d94dc06 100644 --- a/activerecord/test/cases/callbacks_test.rb +++ b/activerecord/test/cases/callbacks_test.rb @@ -81,7 +81,7 @@ end class DeveloperWithCanceledCallbacks < ActiveRecord::Base self.table_name = 'developers' - validates_inclusion_of :salary, :in => 50000..200000 + validates_inclusion_of :salary, in: 50000..200000 before_save :cancel before_destroy :cancel diff --git a/activerecord/test/cases/date_time_test.rb b/activerecord/test/cases/date_time_test.rb index c2ec92c40d..330232cee2 100644 --- a/activerecord/test/cases/date_time_test.rb +++ b/activerecord/test/cases/date_time_test.rb @@ -50,4 +50,12 @@ class DateTimeTest < ActiveRecord::TestCase topic.bonus_time = '' assert_nil topic.bonus_time end + + def test_assign_in_local_timezone + now = DateTime.now + with_timezone_config default: :local do + task = Task.new starting: now + assert now, task.starting + end + end end |