Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails5 Upgrade #86

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d45f7c4
Perform monkey-patching after establishing connections
inbeom Oct 8, 2016
173e3ac
Add Travis test environments for Rails 5
inbeom Oct 8, 2016
3888d66
Remove deprecation warnings from table_exists?
inbeom Oct 8, 2016
d58de84
Override type_to_sql only of Mysql adapter
inbeom Oct 8, 2016
4b4d15e
Remove deprecation warning of alias_method_chain
inbeom Oct 8, 2016
93cfd6d
Discontinue supporting ruby 1.9.3
inbeom Oct 8, 2016
631c9e7
Remove a duplicate entry
inbeom Oct 8, 2016
9d99859
Perform all monkey-patching on connection establishments
inbeom Oct 9, 2016
c99796a
Refine Travis test environments
inbeom Oct 10, 2016
5db8273
Resolve double serialization issue in rails 4.2-postgresql
inbeom Oct 10, 2016
30a7549
Override postgresql type casting scheme in Rails 5
inbeom Oct 10, 2016
33b94fe
Support rails <= 4.1 where #data_source_exists? does not exist
inbeom Oct 10, 2016
529a0d1
Resolve activerecord-mysql2 version conflict
inbeom Oct 10, 2016
2ba2f83
Skip unnecessary tests against rails-head
inbeom Oct 10, 2016
ac82300
Resolve primary key constraint issue on mysql >= 5.7
inbeom Oct 10, 2016
fcc7e29
removing alias_method_chain in favor of prepend
Jan 11, 2017
10e7155
removing alias_method_chain in favor of prepend
Jan 11, 2017
1c32cb7
Refactored alias_method_chain for deprecation purposes
Jan 13, 2017
19a492e
Temporarily adding in last_comment method
Jan 13, 2017
07a5d5e
Merge pull request #1 from inbeom/rails5
inbeom Jan 14, 2017
72e1702
Update rbx to the latest version
inbeom Jan 14, 2017
bf5a6c2
Remove EOL-ed ruby 2.0.0
inbeom Jan 14, 2017
c58699a
Remove EOL-ed rails 3.1 and 3.2
inbeom Jan 14, 2017
a990651
Bump up runtime activerecord dependency
inbeom Jan 14, 2017
c8f871b
Refine jruby dependencies
inbeom Jan 14, 2017
3a3038d
Set rubies on CI to the latest releases
inbeom Jan 14, 2017
1ff86a7
Remove duplicate exclusion list
inbeom Jan 14, 2017
d0fcd14
Update RSpec
inbeom Jan 14, 2017
4a3a148
Exclude all ruby-2.1.10 tests against the primary Gemfile
inbeom Jan 14, 2017
3ff0a87
Fix specs to run again
inbeom Jan 14, 2017
19b48e6
Update rbx, jruby to travis-supported latest versions
inbeom Jan 14, 2017
abf9650
Add ruby 2.4.0
inbeom Jan 14, 2017
b8377cb
Change pending to skip and remove a commented out line
inbeom Jan 14, 2017
b94e225
Prepare active maintenance
inbeom Jan 14, 2017
8d5455d
Specify supported rails versions correctly
inbeom Jan 14, 2017
6312c41
Avoid testing on ruby-2.4.0 against rails 4.x
inbeom Jan 14, 2017
a7b16d4
Remove rbx and change jruby version
inbeom Jan 14, 2017
0be3404
Specify ruby platforms for legacy mysql gems
inbeom Jan 14, 2017
d5f6845
Ignore the default Gemfile for JRuby
inbeom Jan 14, 2017
07f7a8a
Allow CI failures w/ Rails 4.0 and 4.1 under JRuby
inbeom Jan 14, 2017
4d5609a
Merge pull request #3 from inbeom/drop-legacy-support
inbeom Jan 15, 2017
915c2c0
Update Rakefile
jlsookiki Jan 18, 2017
39f1600
Update .travis.yml
jlsookiki Jan 18, 2017
0c9e5ac
Update Rakefile
jlsookiki Jan 19, 2017
70e7484
Merge branch 'master' into rails5
jlsookiki Jan 19, 2017
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
46 changes: 28 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ before_script:
- psql -c 'create database activeuuid_test;' -U postgres

rvm:
- 1.9.3
- 2.0.0
- 2.1.5
- 2.2.0
- rbx-2
- jruby
- 2.1.10
- 2.2.6
- 2.3.3
- 2.4.0
- jruby-9.1.5.0

gemfile:
- Gemfile
- gemfiles/Gemfile.rails-3-1
- gemfiles/Gemfile.rails-3-2
- gemfiles/Gemfile.rails-4-0
- gemfiles/Gemfile.rails-4-1
- gemfiles/Gemfile.rails-4-2
- gemfiles/Gemfile.rails-5-0
- gemfiles/Gemfile.rails-head

env:
Expand All @@ -27,21 +25,33 @@ env:
matrix:
allow_failures:
- gemfile: gemfiles/Gemfile.rails-head
- rvm: jruby-9.1.5.0
gemfile: gemfiles/Gemfile.rails-4-0
- rvm: jruby-9.1.5.0
gemfile: gemfiles/Gemfile.rails-4-1
exclude:
- rvm: 2.2.0
- rvm: 2.1.10
gemfile: Gemfile
- rvm: 2.2.5
gemfile: gemfiles/Gemfile.rails-3-1
- rvm: 2.3.1
gemfile: gemfiles/Gemfile.rails-3-1
- rvm: 2.2.0
gemfile: gemfiles/Gemfile.rails-3-2
- rvm: jruby
gemfile: gemfiles/Gemfile.rails-3-1
env: DB=postgresql
- rvm: jruby
- rvm: 2.2.5
gemfile: gemfiles/Gemfile.rails-3-2
env: DB=postgresql
- rvm: jruby
- rvm: 2.3.1
gemfile: gemfiles/Gemfile.rails-3-2
- rvm: 2.1.10
gemfile: gemfiles/Gemfile.rails-5-0
- rvm: 2.4.0
gemfile: gemfiles/Gemfile.rails-4-0
env: DB=postgresql
- rvm: jruby
- rvm: 2.4.0
gemfile: gemfiles/Gemfile.rails-4-1
env: DB=postgresql

- rvm: 2.4.0
gemfile: gemfiles/Gemfile.rails-4-2
- rvm: jruby-9.1.5.0
gemfile: Gemfile
- rvm: jruby-9.1.5.0
gemfile: gemfiles/Gemfile.rails-5-0
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ source "http://rubygems.org"

# Specify your gem's dependencies in activeuuid.gemspec
gemspec

gem "activerecord"
gem 'rake', '< 11.0'
gem "activerecord", "~>5.0"
6 changes: 3 additions & 3 deletions README.mkd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/jashmenn/activeuuid.png)](http://travis-ci.org/jashmenn/activeuuid)
[![Build Status](https://travis-ci.org/inbeom/activeuuid.png)](http://travis-ci.org/inbeom/activeuuid)

# activeuuid

Expand Down Expand Up @@ -131,7 +131,7 @@ Add this to your `Gemfile`

gem "activeuuid"

Or get the code here: https://github.com/jashmenn/activeuuid
Or get the code here: https://github.com/inbeom/activeuuid


## References
Expand All @@ -144,7 +144,7 @@ Or get the code here: https://github.com/jashmenn/activeuuid
* [7] http://tools.ietf.org/html/rfc4122.html#appendix-C

## Dependencies
Rails ~> 3.1.0
Rails >= 4.0.0

## Authors

Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ require "bundler/gem_tasks"
require 'rspec/core'
require 'rspec/core/rake_task'

module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
4 changes: 2 additions & 2 deletions activeuuid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 2.99.0"
s.add_development_dependency "rspec", "~> 3.5.0"
s.add_development_dependency "rspec-its"
s.add_development_dependency "activesupport"
s.add_development_dependency "database_cleaner"
Expand All @@ -35,5 +35,5 @@ Gem::Specification.new do |s|
end

s.add_runtime_dependency "uuidtools"
s.add_runtime_dependency "activerecord", '>= 3.1'
s.add_runtime_dependency "activerecord", '>= 4.0'
end
5 changes: 0 additions & 5 deletions gemfiles/Gemfile.rails-3-2

This file was deleted.

1 change: 1 addition & 0 deletions gemfiles/Gemfile.rails-4-0
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ source "http://rubygems.org"

gemspec path: '../'

gem 'mysql2', '~> 0.3.21', '~> 0.3.21', platforms: [:mri, :rbx]
gem 'activerecord', '~> 4.0.0'
1 change: 1 addition & 0 deletions gemfiles/Gemfile.rails-4-1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ source "http://rubygems.org"

gemspec path: '../'

gem 'mysql2', '~> 0.3.21', platforms: [:mri, :rbx]
gem 'activerecord', '~> 4.1.0'
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.rails-3-1 → gemfiles/Gemfile.rails-5-0
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source "http://rubygems.org"

gemspec path: '../'

gem 'activerecord', '~> 3.1.0'
gem 'activerecord', '~> 5.0.0'
119 changes: 67 additions & 52 deletions lib/activeuuid/patches.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
require 'active_record'
require 'active_support/concern'

if ActiveRecord::VERSION::MAJOR == 4 and ActiveRecord::VERSION::MINOR == 2
if (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2) ||
(ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0)
module ActiveRecord
module Type
class UUID < Binary # :nodoc:
def type
:uuid
end

def serialize(value)
return if value.nil?
UUIDTools::UUID.serialize(value)
end

def cast_value(value)
UUIDTools::UUID.serialize(value)
end
Expand All @@ -24,7 +30,6 @@ class Uuid < Type::Value # :nodoc:
def type_cast_from_user(value)
UUIDTools::UUID.serialize(value) if value
end
alias_method :type_cast_from_database, :type_cast_from_user
end
end
end
Expand All @@ -47,25 +52,21 @@ def uuid(*column_names)
module Column
extend ActiveSupport::Concern

included do
def self.prepended(klass)
def type_cast_with_uuid(value)
return UUIDTools::UUID.serialize(value) if type == :uuid
type_cast_without_uuid(value)
super
end

def type_cast_code_with_uuid(var_name)
return "UUIDTools::UUID.serialize(#{var_name})" if type == :uuid
type_cast_code_without_uuid(var_name)
super
end

def simplified_type_with_uuid(field_type)
return :uuid if field_type == 'binary(16)' || field_type == 'binary(16,0)'
simplified_type_without_uuid(field_type)
super
end

alias_method_chain :type_cast, :uuid
alias_method_chain :type_cast_code, :uuid if ActiveRecord::VERSION::MAJOR < 4
alias_method_chain :simplified_type, :uuid
end
end

Expand Down Expand Up @@ -98,102 +99,116 @@ def simplified_type(field_type)
module PostgreSQLColumn
extend ActiveSupport::Concern

included do
def self.prepended(klass)
def type_cast_with_uuid(value)
return UUIDTools::UUID.serialize(value) if type == :uuid
type_cast_without_uuid(value)
super
end
alias_method_chain :type_cast, :uuid if ActiveRecord::VERSION::MAJOR >= 4

def simplified_type_with_pguuid(field_type)
return :uuid if field_type == 'uuid'
simplified_type_without_pguuid(field_type)
super
end

alias_method_chain :simplified_type, :pguuid
end
end

module Quoting
extend ActiveSupport::Concern

included do
def self.prepended(klass)
def quote_with_visiting(value, column = nil)
value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid
quote_without_visiting(value, column)
super
end

def type_cast_with_visiting(value, column = nil)
value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid
type_cast_without_visiting(value, column)
super
end

def native_database_types_with_uuid
@native_database_types ||= native_database_types_without_uuid.merge(uuid: { name: 'binary', limit: 16 })
end

alias_method_chain :quote, :visiting
alias_method_chain :type_cast, :visiting
alias_method_chain :native_database_types, :uuid
end
end

module PostgreSQLQuoting
extend ActiveSupport::Concern

included do
def self.prepended(klass)
def quote_with_visiting(value, column = nil)
value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid
value = value.to_s if value.is_a? UUIDTools::UUID
quote_without_visiting(value, column)
super
end

def type_cast_with_visiting(value, column = nil, *args)
value = UUIDTools::UUID.serialize(value) if column && column.type == :uuid
value = value.to_s if value.is_a? UUIDTools::UUID
type_cast_without_visiting(value, column, *args)
super
end

def native_database_types_with_pguuid
@native_database_types ||= native_database_types_without_pguuid.merge(uuid: { name: 'uuid' })
end
end
end

alias_method_chain :quote, :visiting
alias_method_chain :type_cast, :visiting
alias_method_chain :native_database_types, :pguuid
module PostgresqlTypeOverride
def deserialize(value)
UUIDTools::UUID.serialize(value) if value
end

alias_method :cast, :deserialize
end

module AbstractAdapter
extend ActiveSupport::Concern
module TypeMapOverride
def initialize_type_map(m)
super

included do
def initialize_type_map_with_uuid(m)
initialize_type_map_without_uuid(m)
register_class_with_limit m, /binary\(16(,0)?\)/i, ::ActiveRecord::Type::UUID
end
register_class_with_limit m, /binary\(16(,0)?\)/i, ::ActiveRecord::Type::UUID
end
end

alias_method_chain :initialize_type_map, :uuid
module MysqlTypeToSqlOverride
def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = nil)
type.to_s == 'uuid' ? 'binary(16)' : super
end
end

def self.apply!
ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition

if ActiveRecord::VERSION::MAJOR == 4 and ActiveRecord::VERSION::MINOR == 2
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, AbstractAdapter if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, AbstractAdapter if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
else
ActiveRecord::ConnectionAdapters::Column.send :include, Column
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.send :include, PostgreSQLColumn if defined? ActiveRecord::ConnectionAdapters::PostgreSQLColumn
module ConnectionHandling
def establish_connection(_ = nil)
super

ActiveRecord::ConnectionAdapters::Table.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::Table
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Migrations if defined? ActiveRecord::ConnectionAdapters::TableDefinition

if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 0
if defined? ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend TypeMapOverride
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend MysqlTypeToSqlOverride
end

ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend TypeMapOverride if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid.prepend PostgresqlTypeOverride if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
elsif ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
ActiveRecord::ConnectionAdapters::Mysql2Adapter.prepend TypeMapOverride if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend TypeMapOverride if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
else
ActiveRecord::ConnectionAdapters::Column.send :include, Column
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.send :include, PostgreSQLColumn if defined? ActiveRecord::ConnectionAdapters::PostgreSQLColumn
end

ActiveRecord::ConnectionAdapters::MysqlAdapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, PostgreSQLQuoting if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
end
ArJdbc::MySQL::Column.send :include, MysqlJdbcColumn if defined? ArJdbc::MySQL::Column
end

ActiveRecord::ConnectionAdapters::MysqlAdapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :include, Quoting if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, PostgreSQLQuoting if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
def self.apply!
ActiveRecord::Base.singleton_class.prepend ConnectionHandling
end
end
end
end
Loading