Skip to content

Instantly share code, notes, and snippets.

@StefanH
StefanH / change_enum_migration.rb
Created January 11, 2016 10:08
Better migration of enum types
class ChangeEnumMigration < ActiveRecord::Migration
include MigrationTools
def change
migrate_enum :some_enum, [:some_table, :some_column, null: false, default: 'other'],
keep_values: %w(foo bar),
new_values: %w(baz qux),
mappings: {'quux' => 'mux'},
removed_values: %w(baaaz baaz)
end
@StefanH
StefanH / install_ruby.sh
Last active December 23, 2015 00:09
install ruby on precise64 vagrant box
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p429.tar.gz
tar -xvzf ruby-1.9.3-p429.tar.gz
cd ruby-1.9.3-p429/
./configure --prefix=/usr/local
make
make install
# issue 8048
gem 'rails', '3.2.8'
require 'action_mailer'
ActionMailer::Base.delivery_method = :test
class TestMailer < ActionMailer::Base
def anything
mail(to: "someone")
@StefanH
StefanH / gist:1875597
Created February 21, 2012 10:08
test and possible solution for #3965
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 433d508..10ae5dc 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -86,7 +86,15 @@ module ActiveRecord
# be typecast back to 0 (''.to_i => 0)
value = nil
else
- value = column.type_cast(value)
+ # if time zone aware attributes, attribute is
@StefanH
StefanH / gist:1868608
Created February 20, 2012 09:49
reproduces issue 3965 config.time_zone and datetime update
gem 'rails', '3.2.1'
require 'active_record'
# Print out what version we're running
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
Time.zone = 'Amsterdam'