Permalink
Browse files

Rails 5 support

  • Loading branch information...
1 parent c1394c2 commit cbfd9a5cdb0466ed442e98bb9d558f664da8bca0 @mnoack mnoack committed Aug 1, 2016
View
@@ -17,6 +17,10 @@ matrix:
- rvm: jruby
- rvm: rbx
exclude:
+ - rvm: 1.9.3
+ gemfile: gemfiles/activerecord_5.0.gemfile
+ - rvm: 2.1.10
+ gemfile: gemfiles/activerecord_5.0.gemfile
- rvm: 2.1.10
gemfile: gemfiles/activerecord_2.3.gemfile
- rvm: 2.2.5
@@ -32,3 +36,4 @@ gemfile:
- gemfiles/activerecord_4.0.gemfile
- gemfiles/activerecord_4.1.gemfile
- gemfiles/activerecord_4.2.gemfile
+ - gemfiles/activerecord_5.0.gemfile
View
@@ -26,3 +26,7 @@ end
appraise "activerecord-4.2" do
gem "activerecord", "~> 4.2.0"
end
+
+appraise "activerecord-5.0" do
+ gem "activerecord", "~> 5.0.0"
+end
@@ -0,0 +1,17 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "activerecord", "~> 5.0.0"
+
+group :development, :test do
+ gem "spec"
+ gem "rspec", ">= 1.2.9"
+ gem "rake"
+end
+
+group :development do
+ gem "jeweler"
+ gem "appraisal"
+ gem "simplecov", :require => false
+end
@@ -23,8 +23,8 @@ def initialize(config={})
@indexes = Hash.new { |hash, key| hash[key] = [] }
@schema_path = config.fetch(:schema){ "db/schema.rb" }
@config = config.merge(:adapter => :nulldb)
- super(nil, @logger)
- @visitor = Arel::Visitors::ToSql.new self if defined?(Arel::Visitors::ToSql)
+ super *initialize_args
+ @visitor ||= Arel::Visitors::ToSql.new self if defined?(Arel::Visitors::ToSql)
end
# A log of every statement that has been "executed" by this connection adapter
@@ -117,6 +117,10 @@ def tables
@tables.keys.map(&:to_s)
end
+ def views
+ [] # TODO: Implement properly if needed - This is new method in rails
+ end
+
# Retrieve table columns as defined by the schema
def columns(table_name, name = nil)
if @tables.size <= 1
@@ -148,7 +152,7 @@ def execute(statement, name = nil)
NullObject.new
end
- def exec_query(statement, name = 'SQL', binds = [])
+ def exec_query(statement, name = 'SQL', binds = [], options = {})
self.execution_log << Statement.new(entry_point, statement)
EmptyResult.new
end
@@ -180,7 +184,7 @@ def delete(statement, name=nil, binds = [])
end
end
- def select_all(statement, name=nil, binds = [])
+ def select_all(statement, name=nil, binds = [], options = {})
with_entry_point(:select_all) do
super(statement, name)
end
@@ -254,6 +258,8 @@ def with_thread_local_variable(name, value)
def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
case ::ActiveRecord::VERSION::MAJOR
+ when 5
+ TableDefinition.new(table_name, is_temporary, options.except(:id))
when 4
TableDefinition.new(native_database_types, table_name, is_temporary, options)
when 2,3
@@ -269,7 +275,11 @@ def new_column_arguments(col_def)
def args_with_optional_cast_type(col_def)
default_column_arguments(col_def).tap do |args|
- args.insert(2, lookup_cast_type(col_def.type)) if initialize_column_with_cast_type?
+ if respond_to? :fetch_type_metadata
+ args.insert(2, fetch_type_metadata(col_def.type))
+ elsif initialize_column_with_cast_type?
+ args.insert(2, lookup_cast_type(col_def.type))
+ end
end
end
@@ -286,4 +296,9 @@ def initialize_column_with_cast_type?
::ActiveRecord::VERSION::MAJOR == 4 && ::ActiveRecord::VERSION::MINOR >= 2
end
+ def initialize_args
+ return [nil, @logger, @config] if ActiveRecord::VERSION::MAJOR > 3
+ [nil, @logger]
+ end
+
end
@@ -33,7 +33,8 @@ def self.nulldb_connection(config)
module ActiveRecord
# Just make sure you have the latest version of your schema
- class Schema < Migration
+ superclass = ActiveRecord::VERSION::MAJOR == 5 ? Migration[5.0] : Migration
+ class Schema < superclass
def self.define(info={}, &block)
instance_eval(&block)
end

0 comments on commit cbfd9a5

Please sign in to comment.