diff --git a/.travis.yml b/.travis.yml index 02927d3..4732d2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,18 @@ rvm: - 2.3 - 2.4 - 2.5 +matrix: + include: + - rvm: 2.1 + env: "JSON_ON_RAILS_DB_CONFIG=mysql" + - rvm: 2.2 + env: "JSON_ON_RAILS_DB_CONFIG=mysql" + - rvm: 2.3 + env: "JSON_ON_RAILS_DB_CONFIG=mysql" + - rvm: 2.4 + env: "JSON_ON_RAILS_DB_CONFIG=pgsql" + - rvm: 2.5 + env: "JSON_ON_RAILS_DB_CONFIG=mysql" addons: apt: sources: diff --git a/json_on_rails.gemspec b/json_on_rails.gemspec index 4e8255d..39e4bfc 100644 --- a/json_on_rails.gemspec +++ b/json_on_rails.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "activerecord", "~> 4.0" s.add_runtime_dependency "mysql2", "~> 0.3" + s.add_runtime_dependency "pg", "~> 0.21" s.add_development_dependency "rake", "~> 12.3" s.add_development_dependency "rspec", "~> 3.7" diff --git a/spec/helpers/json_attributes_spec_helper.rb b/spec/helpers/json_attributes_spec_helper.rb index 3ee4310..70e4fad 100644 --- a/spec/helpers/json_attributes_spec_helper.rb +++ b/spec/helpers/json_attributes_spec_helper.rb @@ -22,4 +22,8 @@ def self.mysql_version Gem::Version.new(version) end + + def self.postgres? + ActiveRecord::Base.connection.class::ADAPTER_NAME == "PostgreSQL" + end end diff --git a/spec/json_on_rails/json_attributes_spec.rb b/spec/json_on_rails/json_attributes_spec.rb index cc69843..647ddf9 100644 --- a/spec/json_on_rails/json_attributes_spec.rb +++ b/spec/json_on_rails/json_attributes_spec.rb @@ -69,20 +69,20 @@ # README!!! Important. MySQL <= 8.0.4 automatically converts decimals with zero fractional # part to integers, so this must be taken into account (see https://bugs.mysql.com/bug.php?id=88230). # - if JsonAttributesSpecHelper.mysql_version < Gem::Version.new("8.0.4") - it "should return an Integer for Floats with zero fractional part" do + if JsonAttributesSpecHelper.postgres? || JsonAttributesSpecHelper.mysql_version >= Gem::Version.new("8.0.4") + it "should return a Float for Floats with zero fractional part" do extras_on_user_lifecycle([1.0]) do |after_instantiation, after_save, after_reload| expect(after_instantiation).to eql([1.0]) expect(after_save).to eql([1.0]) - expect(after_reload).to eql([1]) + expect(after_reload).to eql([1.0]) end end else - it "should return a Float for Floats with zero fractional part" do + it "should return an Integer for Floats with zero fractional part" do extras_on_user_lifecycle([1.0]) do |after_instantiation, after_save, after_reload| expect(after_instantiation).to eql([1.0]) expect(after_save).to eql([1.0]) - expect(after_reload).to eql([1.0]) + expect(after_reload).to eql([1]) end end end diff --git a/spec/setup/config/database.yml b/spec/setup/config/database.yml index 4c19463..afc6725 100644 --- a/spec/setup/config/database.yml +++ b/spec/setup/config/database.yml @@ -1,4 +1,13 @@ -adapter: mysql2_json -encoding: utf8 -database: json_on_rails_test -socket: <%= ENV.fetch("MYSQL_SOCKET", "/var/run/mysqld/mysqld.sock") %> +common: &common + encoding: utf8 + database: json_on_rails_test + +mysql: &mysql + <<: *common + adapter: mysql2_json + socket: <%= ENV.fetch("MYSQL_SOCKET", "/var/run/mysqld/mysqld.sock") %> + +pgsql: &pgsql + <<: *common + adapter: postgresql + host: localhost diff --git a/spec/setup/spec_environment_helper.rb b/spec/setup/spec_environment_helper.rb index 83161c8..8944262 100644 --- a/spec/setup/spec_environment_helper.rb +++ b/spec/setup/spec_environment_helper.rb @@ -5,6 +5,8 @@ class SpecEnvironmentHelper SCHEMA_FILE = File.expand_path("db/schema.rb", __dir__) TEST_MODELS_PATH = File.expand_path("models", __dir__) + DB_CONFIG_ENV_VAR = "JSON_ON_RAILS_DB_CONFIG" + def setup_spec_environment setup_coverage_tool boot_mini_app @@ -42,8 +44,11 @@ def require_components end def load_connection_configuration + db_config_key = ENV[DB_CONFIG_ENV_VAR] || raise("Set the env variable #{DB_CONFIG_ENV_VAR} to `mysql` or `pgsql`") + erb_db_configuration = ERB.new(File.read(DB_CONFIGFILE)).result - YAML.safe_load(erb_db_configuration) + + YAML.safe_load(erb_db_configuration, [], [], true).fetch(db_config_key) end def prepare_database(configuration)