Skip to content

Instantly share code, notes, and snippets.

class KeyExtractor
def self.extract(key_spec, source)
new(key_spec.split("."), source).extract
end
def self.extract_array(key_spec, source)
extract(key_spec, source) || []
end
def initialize(key_parts, source)
@senny
senny / bug_report.rb
Last active December 31, 2015 17:19
require 'rails'
require 'action_controller/railtie'
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
config.secret_token = 'secret_token'
config.secret_key_base = 'secret_key_base'
config.logger = Logger.new($stdout)
@senny
senny / travis.sh
Last active December 31, 2015 14:49 — forked from rejeep/travis.sh
#!/bin/sh
# This script will setup Evm (Emacs Version Manager) and Cask on
# Travis to use for Emacs Lisp testing.
#
# In .travis.yml, add this:
#
# - curl -fsSkL https://gist.github.com/rejeep/7736123/raw > travis.sh && source ./travis.sh
#
# Emacs 24.3 is installed in the above script because Cask requires
@senny
senny / travis.sh
Created December 17, 2013 11:07
Setup Evm and Cask on Travis.
#!/bin/sh
# This script will setup Evm and Cask on Travis to use for Emacs Lisp testing.
#
# In .travis.yml, add Evm and Cask to PATH.
#
# - export PATH="/home/travis/.cask/bin:$PATH"
# - export PATH="/home/travis/.evm/bin:$PATH"
sudo mkdir /usr/local/evm
0463698 (HEAD, 4-0-stable) Merge pull request #12646 from severin/polymorphic_belongs_to_touch [Yves Senn] [27 seconds ago]
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 852be57..adc7003 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,17 @@
+* Polymorphic belongs_to associations with the `touch: true` option set update the timestamps of
+ the old and new owner correctly when moved between owners of different types.
+
@senny
senny / weird.rb
Last active December 28, 2015 03:19
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :event_kinds do |t|
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
index 927fbab..3100638 100644
--- a/activerecord/lib/active_record/log_subscriber.rb
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -22,6 +22,7 @@ module ActiveRecord
def render_bind(column, value)
if column
+ value = value[:value] if value.is_a?(Hash)
if column.binary?
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 41a4718..88c9494 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -559,7 +559,7 @@ module ActiveRecord
def set_field_encoding field_name
field_name.force_encoding(client_encoding)
if internal_enc = Encoding.default_internal
- field_name = field_name.encoding(internal_enc)
+ field_name = field_name.encode!(internal_enc)
@senny
senny / results.txt
Created October 25, 2013 15:06
time_zone_aware_attributes = true
1) Failure:
BasicsTest#test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_local [/Users/senny/Projects/rails/activerecord/test/cases/base_test.rb:279]:
--- expected
+++ actual
@@ -1 +1 @@
-[0, 0, 1, 1, 1, 2000, 6, 1, false, "EST"]
+[0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"]
def test_timestamp_with_zone_values_without_rails_time_zone_support
p @connection.execute('SHOW TIME ZONE', 'SCHEMA').first["TimeZone"]
with_timezone_config default: :local, aware_attributes: false do
@connection.reconnect!
@connection.execute("SET time zone 'America/Jamaica'", 'SCHEMA')
@first_timestamp_with_zone = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), @first_timestamp_with_zone.time
assert_instance_of Time, @first_timestamp_with_zone.time
p @connection.execute('SHOW TIME ZONE', 'SCHEMA').first["TimeZone"]