From e7494f740b61a0f68d943a344201617dce7e0c44 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 12:16:31 +0100 Subject: [PATCH 1/8] Specify RuboCop supported Ruby version (2.4.10) --- .rubocop.yml | 12 ++++++------ .ruby-version | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index fd3a02e..f35103e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ AllCops: Include: - Rakefile -Lint/SpaceBeforeFirstArg: +Layout/SpaceBeforeFirstArg: Enabled: false Lint/UnusedBlockArgument: Enabled: false @@ -13,13 +13,13 @@ Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false -Metrics/LineLength: +Layout/LineLength: Enabled: false Metrics/MethodLength: Enabled: false Metrics/PerceivedComplexity: Enabled: false -Style/AlignParameters: +Layout/ParameterAlignment: Enabled: false Style/ClassAndModuleChildren: Enabled: false @@ -27,17 +27,17 @@ Style/ClassVars: Enabled: false Style/Documentation: Enabled: false -Style/FileName: +Naming/FileName: Enabled: false Style/GuardClause: Enabled: false -Style/IndentHash: +Layout/FirstHashElementIndentation: Enabled: false Style/RescueModifier: Enabled: false Style/SignalException: Enabled: false -Style/SpaceAroundEqualsInParameterDefault: +Layout/SpaceAroundEqualsInParameterDefault: Enabled: false Style/StringLiterals: EnforcedStyle: double_quotes diff --git a/.ruby-version b/.ruby-version index 0bee604..b0f6bf0 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.3 +2.4.10 From d2c1095d2866ba425471daddf516c49b4a5fe6a6 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 12:36:47 +0100 Subject: [PATCH 2/8] Add ActiveRecord 5.2 to Appraisals NOTE: Also drops ActiveRecord older than 4.2. --- Appraisals | 16 ++++++++-------- Gemfile | 4 ---- gemfiles/activerecord_4.1.gemfile | 11 ----------- gemfiles/activerecord_4.2.gemfile | 5 +---- gemfiles/activerecord_5.0.gemfile | 5 +---- gemfiles/activerecord_5.1.gemfile | 5 +---- ...cord_4.0.gemfile => activerecord_5.2.gemfile} | 7 ++----- 7 files changed, 13 insertions(+), 40 deletions(-) delete mode 100644 gemfiles/activerecord_4.1.gemfile rename gemfiles/{activerecord_4.0.gemfile => activerecord_5.2.gemfile} (55%) diff --git a/Appraisals b/Appraisals index 2417252..63b0daa 100644 --- a/Appraisals +++ b/Appraisals @@ -1,19 +1,19 @@ +appraise "activerecord-5.2" do + gem "activerecord", "~> 5.2.0" + gem "pg", ">= 0.21.0" +end + appraise "activerecord-5.1" do gem "activerecord", "~> 5.1.0" + gem "pg", ">= 0.21.0" end appraise "activerecord-5.0" do gem "activerecord", "~> 5.0.0" + gem "pg", ">= 0.21.0" end appraise "activerecord-4.2" do gem "activerecord", "~> 4.2.0" -end - -appraise "activerecord-4.1" do - gem "activerecord", "~> 4.1.0" -end - -appraise "activerecord-4.0" do - gem "activerecord", "~> 4.0.0" + gem "pg", "< 1" end diff --git a/Gemfile b/Gemfile index 59d35df..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,3 @@ source "https://rubygems.org" gemspec - -group :test do - gem "pg", ">= 0.14.1" -end diff --git a/gemfiles/activerecord_4.1.gemfile b/gemfiles/activerecord_4.1.gemfile deleted file mode 100644 index dab20ae..0000000 --- a/gemfiles/activerecord_4.1.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "activerecord", "~> 4.1.0" - -group :test do - gem "pg", ">= 0.14.1" -end - -gemspec path: "../" diff --git a/gemfiles/activerecord_4.2.gemfile b/gemfiles/activerecord_4.2.gemfile index a2624e0..3fa1707 100644 --- a/gemfiles/activerecord_4.2.gemfile +++ b/gemfiles/activerecord_4.2.gemfile @@ -3,9 +3,6 @@ source "https://rubygems.org" gem "activerecord", "~> 4.2.0" - -group :test do - gem "pg", ">= 0.14.1" -end +gem "pg", "< 1" gemspec path: "../" diff --git a/gemfiles/activerecord_5.0.gemfile b/gemfiles/activerecord_5.0.gemfile index e826846..b2fe51e 100644 --- a/gemfiles/activerecord_5.0.gemfile +++ b/gemfiles/activerecord_5.0.gemfile @@ -3,9 +3,6 @@ source "https://rubygems.org" gem "activerecord", "~> 5.0.0" - -group :test do - gem "pg", ">= 0.14.1" -end +gem "pg", ">= 0.21.0" gemspec path: "../" diff --git a/gemfiles/activerecord_5.1.gemfile b/gemfiles/activerecord_5.1.gemfile index e04ad04..8ed3256 100644 --- a/gemfiles/activerecord_5.1.gemfile +++ b/gemfiles/activerecord_5.1.gemfile @@ -3,9 +3,6 @@ source "https://rubygems.org" gem "activerecord", "~> 5.1.0" - -group :test do - gem "pg", ">= 0.14.1" -end +gem "pg", ">= 0.21.0" gemspec path: "../" diff --git a/gemfiles/activerecord_4.0.gemfile b/gemfiles/activerecord_5.2.gemfile similarity index 55% rename from gemfiles/activerecord_4.0.gemfile rename to gemfiles/activerecord_5.2.gemfile index 60032e3..37eb6e5 100644 --- a/gemfiles/activerecord_4.0.gemfile +++ b/gemfiles/activerecord_5.2.gemfile @@ -2,10 +2,7 @@ source "https://rubygems.org" -gem "activerecord", "~> 4.0.0" - -group :test do - gem "pg", ">= 0.14.1" -end +gem "activerecord", "~> 5.2.0" +gem "pg", ">= 0.21.0" gemspec path: "../" From e08d263fb7b49f963d6a822457da56575ac11e2f Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 15:14:44 +0100 Subject: [PATCH 3/8] Specify Ruby 2.6.6 --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index b0f6bf0..338a5b5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.10 +2.6.6 From fbf55549b6a2a3a39f2a9f65ca975ab9706157ea Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 15:18:26 +0100 Subject: [PATCH 4/8] Remove `BigDecimal.new` calls Fixes deprecation warning: > BigDecimal.new is deprecated; use BigDecimal() method instead. --- lib/hstore_accessor/serialization.rb | 2 +- spec/hstore_accessor_spec.rb | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/hstore_accessor/serialization.rb b/lib/hstore_accessor/serialization.rb index 1432f32..49e42be 100644 --- a/lib/hstore_accessor/serialization.rb +++ b/lib/hstore_accessor/serialization.rb @@ -25,7 +25,7 @@ module Serialization DESERIALIZERS = { boolean: -> value { TypeHelpers.cast(:boolean, value) }, date: -> value { value && Date.parse(value) }, - decimal: -> value { value && (value == '' ? BigDecimal.new(0) : BigDecimal.new(value)) }, + decimal: -> value { value && (value == '' ? BigDecimal(0) : BigDecimal(value)) }, float: -> value { value && value.to_f }, integer: -> value { value && value.to_i }, datetime: -> value { value && Time.at(value.to_i).in_time_zone } diff --git a/spec/hstore_accessor_spec.rb b/spec/hstore_accessor_spec.rb index d2d0103..376c618 100644 --- a/spec/hstore_accessor_spec.rb +++ b/spec/hstore_accessor_spec.rb @@ -83,7 +83,7 @@ class FakeModel let!(:timestamp) { Time.now } let!(:datestamp) { Date.today } let(:product) { Product.new } - let(:persisted_product) { Product.create!(color: "green", price: 10, weight: 10.1, popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal.new("9.133790001")) } + let(:persisted_product) { Product.create!(color: "green", price: 10, weight: 10.1, popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal("9.133790001")) } FIELDS.keys.each do |field| it "responds with nil when #{field} is not set" do @@ -153,9 +153,9 @@ class FakeModel describe "scopes" do let!(:timestamp) { Time.now } let!(:datestamp) { Date.today } - let!(:product_a) { Product.create(likes: 3, name: "widget", color: "green", price: 10, weight: 10.1, popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal.new("10.113379001")) } - let!(:product_b) { Product.create(color: "orange", price: 20, weight: 20.2, popular: false, build_timestamp: (timestamp - 5.days), released_at: (datestamp - 4.days), miles: BigDecimal.new("20.213379001")) } - let!(:product_c) { Product.create(color: "blue", price: 30, weight: 30.3, popular: true, build_timestamp: timestamp, released_at: datestamp, miles: BigDecimal.new("30.313379001")) } + let!(:product_a) { Product.create(likes: 3, name: "widget", color: "green", price: 10, weight: 10.1, popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal("10.113379001")) } + let!(:product_b) { Product.create(color: "orange", price: 20, weight: 20.2, popular: false, build_timestamp: (timestamp - 5.days), released_at: (datestamp - 4.days), miles: BigDecimal("20.213379001")) } + let!(:product_c) { Product.create(color: "blue", price: 30, weight: 30.3, popular: true, build_timestamp: timestamp, released_at: datestamp, miles: BigDecimal("30.313379001")) } context "ambiguous column names" do let!(:product_category) { ProductCategory.create!(name: "widget", likes: 2) } @@ -235,23 +235,23 @@ class FakeModel context "for decimal fields support" do it "less than" do - expect(Product.miles_lt(BigDecimal.new("10.55555")).to_a).to eq [product_a] + expect(Product.miles_lt(BigDecimal("10.55555")).to_a).to eq [product_a] end it "less than or equal" do - expect(Product.miles_lte(BigDecimal.new("20.213379001")).to_a).to eq [product_a, product_b] + expect(Product.miles_lte(BigDecimal("20.213379001")).to_a).to eq [product_a, product_b] end it "equality" do - expect(Product.miles_eq(BigDecimal.new("10.113379001")).to_a).to eq [product_a] + expect(Product.miles_eq(BigDecimal("10.113379001")).to_a).to eq [product_a] end it "greater than or equal" do - expect(Product.miles_gte(BigDecimal.new("20.213379001")).to_a).to eq [product_b, product_c] + expect(Product.miles_gte(BigDecimal("20.213379001")).to_a).to eq [product_b, product_c] end it "greater than" do - expect(Product.miles_gt(BigDecimal.new("20.555555")).to_a).to eq [product_c] + expect(Product.miles_gt(BigDecimal("20.555555")).to_a).to eq [product_c] end end @@ -477,7 +477,7 @@ def self.it_returns_the_properly_typed_column(hstore_type, attribute_name, activ end it "correctly stores decimal values" do - decimal = BigDecimal.new("9.13370009001") + decimal = BigDecimal("9.13370009001") product.miles = decimal product.save product.reload @@ -531,7 +531,7 @@ def self.it_returns_the_properly_typed_column(hstore_type, attribute_name, activ it "type casts decimal values" do product.miles = "1.337900129339202" - expect(product.miles).to eq BigDecimal.new("1.337900129339202") + expect(product.miles).to eq BigDecimal("1.337900129339202") end it "type casts boolean values" do From b297dbc6461869531543c53771a4ef7bd326ae0f Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 16:25:13 +0100 Subject: [PATCH 5/8] Add ActiveRecord 6.0 to Appraisals --- Appraisals | 5 +++++ gemfiles/activerecord_6.0.gemfile | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 gemfiles/activerecord_6.0.gemfile diff --git a/Appraisals b/Appraisals index 63b0daa..dbbf153 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,8 @@ +appraise "activerecord-6.0" do + gem "activerecord", "~> 6.0.0" + gem "pg", ">= 0.21.0", "< 2" +end + appraise "activerecord-5.2" do gem "activerecord", "~> 5.2.0" gem "pg", ">= 0.21.0" diff --git a/gemfiles/activerecord_6.0.gemfile b/gemfiles/activerecord_6.0.gemfile new file mode 100644 index 0000000..43e7dce --- /dev/null +++ b/gemfiles/activerecord_6.0.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 6.0.0" +gem "pg", ">= 0.21.0", "< 2" + +gemspec path: "../" From 028fb60eb2934e2222fd31f8974fa3920e915de4 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 16:25:33 +0100 Subject: [PATCH 6/8] Replace `update_attributes!` with `update!` Fixes deprecation warning: > DEPRECATION WARNING: update_attributes! is deprecated and will be > removed from Rails 6.1 (please, use update! instead) --- spec/hstore_accessor_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/hstore_accessor_spec.rb b/spec/hstore_accessor_spec.rb index 376c618..bdacf5b 100644 --- a/spec/hstore_accessor_spec.rb +++ b/spec/hstore_accessor_spec.rb @@ -426,7 +426,7 @@ def self.it_returns_the_properly_typed_column(hstore_type, attribute_name, activ context "multipart values" do it "stores multipart dates correctly" do - product.update_attributes!( + product.update!( "released_at(1i)" => "2014", "released_at(2i)" => "04", "released_at(3i)" => "14" From bc28f9c6b473f7855712102991ac75fa89a5cee9 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 16:34:02 +0100 Subject: [PATCH 7/8] Fix spec helper `create_database` --- spec/spec_helper.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 29ab257..f4b7975 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,11 +25,20 @@ end def create_database - ActiveRecord::Base.establish_connection( - adapter: "postgresql", - database: "hstore_accessor", - username: "postgres" - ) + begin + ActiveRecord::Base.establish_connection( + adapter: "postgresql", + database: "hstore_accessor", + username: "postgres" + ) + ActiveRecord::Base.connection + rescue ActiveRecord::NoDatabaseError => e + ActiveRecord::Base.establish_connection( + adapter: "postgresql", + username: "postgres" + ) + ActiveRecord::Base.connection.create_database("hstore_accessor") + end ActiveRecord::Base.connection.execute("CREATE EXTENSION hstore;") rescue ActiveRecord::StatementInvalid ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS products;") From 940fbc6242984333207aa8b7999fd49b3fa722cf Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Fri, 5 Jun 2020 17:43:55 +0100 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f7b4a6..1d4c724 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Starting a new project? Use [Jsonb Accessor](https://github.com/devmynd/jsonb_accessor) instead! It has more features and is better maintained. ## Description -Hstore Accessor allows you to treat fields on an hstore column as though they were actual columns being picked up by ActiveRecord. This is especially handy when trying to avoid sparse columns while making use of [single table inheritence](#single-table-inheritance). Hstore Accessor currently supports ActiveRecord versions 4.0, 4.1, 4.2, 5.0, and 5.1. +Hstore Accessor allows you to treat fields on an hstore column as though they were actual columns being picked up by ActiveRecord. This is especially handy when trying to avoid sparse columns while making use of [single table inheritence](#single-table-inheritance). Hstore Accessor currently supports ActiveRecord versions 4.2, 5.0, 5.1, 5.2 and 6.0. ## Table of Contents