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

ActiveRecord 6.0 support #81

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AllCops:
Include:
- Rakefile
Lint/SpaceBeforeFirstArg:
Layout/SpaceBeforeFirstArg:
Enabled: false
Lint/UnusedBlockArgument:
Enabled: false
Expand All @@ -13,31 +13,31 @@ 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
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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.3
2.6.6
21 changes: 13 additions & 8 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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"
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
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
source "https://rubygems.org"

gemspec

group :test do
gem "pg", ">= 0.14.1"
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions gemfiles/activerecord_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"
5 changes: 1 addition & 4 deletions gemfiles/activerecord_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"
5 changes: 1 addition & 4 deletions gemfiles/activerecord_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -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: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "~> 4.1.0"

group :test do
gem "pg", ">= 0.14.1"
end
gem "activerecord", "~> 6.0.0"
gem "pg", ">= 0.21.0", "< 2"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/hstore_accessor/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
24 changes: 12 additions & 12 deletions spec/hstore_accessor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand Down