-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Postgresql and use sqlite3 for testing ActiveRecord
- Loading branch information
Showing
12 changed files
with
55 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "activemodel-serializers-xml" | ||
gem 'sqlite3', platforms: :ruby | ||
gem "activerecord-jdbcsqlite3-adapter", platform: [:jruby, :truffleruby] | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "rails", "~> 5.0.0" | ||
gem 'pg', '~> 0.21.0', platforms: :ruby | ||
gem "activemodel-serializers-xml" | ||
gem "activerecord-jdbcpostgresql-adapter", "~> 50.0", platforms: :jruby | ||
if RUBY_VERSION < '2.3' | ||
gem "ruby-vips", "2.0.13" | ||
end | ||
gem 'sqlite3', '~> 1.3.6', platforms: :ruby | ||
gem "activerecord-jdbcsqlite3-adapter", platform: [:jruby, :truffleruby] | ||
|
||
gemspec :path => "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
if RUBY_ENGINE == 'jruby' | ||
require 'activerecord-jdbcpostgresql-adapter' | ||
else | ||
require 'pg' | ||
end | ||
require 'active_record' | ||
require 'carrierwave/orm/activerecord' | ||
Bundler.require | ||
|
||
# Change this if PG is unavailable | ||
dbconfig = { | ||
:host => '127.0.0.1', | ||
:adapter => 'postgresql', | ||
:database => 'carrierwave_test', | ||
:encoding => 'utf8', | ||
:username => 'postgres', | ||
:password => 'postgres' | ||
} | ||
|
||
database = dbconfig.delete(:database) | ||
|
||
ActiveRecord::Base.establish_connection(dbconfig.merge(database: "template1")) | ||
begin | ||
ActiveRecord::Base.connection.create_database database | ||
rescue ActiveRecord::StatementInvalid => e # database already exists | ||
end | ||
ActiveRecord::Base.establish_connection(dbconfig.merge(:database => database)) | ||
ActiveRecord::Base.establish_connection({ adapter: 'sqlite3', database: ':memory:' }) | ||
|
||
ActiveRecord::Migration.verbose = false | ||
|
||
if ActiveRecord::VERSION::STRING >= '4.2' && ActiveRecord::VERSION::STRING < '5.0' | ||
ActiveRecord::Base.raise_in_transactional_callbacks = true | ||
if ActiveRecord.version < Gem::Version.new("5.2") | ||
module ActiveRecord | ||
module Type | ||
class Json < ActiveModel::Type::Value | ||
include ActiveModel::Type::Helpers::Mutable | ||
|
||
def type | ||
:json | ||
end | ||
|
||
def deserialize(value) | ||
return value unless value.is_a?(::String) | ||
ActiveSupport::JSON.decode(value) rescue nil | ||
end | ||
|
||
def serialize(value) | ||
ActiveSupport::JSON.encode(value) unless value.nil? | ||
end | ||
|
||
def changed_in_place?(raw_old_value, new_value) | ||
deserialize(raw_old_value) != new_value | ||
end | ||
|
||
def accessor | ||
ActiveRecord::Store::StringKeyedHashAccessor | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Type.register(:json, ActiveRecord::Type::Json, override: false) | ||
end |