Skip to content

Commit

Permalink
Merge pull request #65 from swoop-inc/mb_add_rails_7
Browse files Browse the repository at this point in the history
Add Rails 7 Support
  • Loading branch information
GeorgeKaraszi authored Jan 20, 2022
2 parents 33000ed + a2254e3 commit 3d49e52
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 15 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Test
on: [push]

jobs:
test:
name: Test
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
rails: [51, 52, 60, 61, 70]
ruby: [2.4, 2.5, 2.6, 2.7, '3.0', 3.1]
exclude:
- ruby: 2.4
rails: 60
- ruby: 2.4
rails: 61
- ruby: 2.4
rails: 70
- ruby: 2.5
rails: 70
- ruby: 2.6
rails: 70
- ruby: 3.0
rails: 51
- ruby: 3.0
rails: 52
- ruby: 3.1
rails: 51
- ruby: 3.1
rails: 52

services:
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports: ["5432:5432"]

steps:
- uses: actions/checkout@v2

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- uses: actions/cache@v2
with:
path: vendor/bundle
key: bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.rails }}-
- name: Bundle install
run: |
bundle config path vendor/bundle
bundle config set --local gemfile gemfiles/activerecord-${{ matrix.rails }}.gemfile
bundle install --jobs 4 --retry 3
- name: Setup Database
env:
DATABASE_NAME: active_record_extended_test
DATABASE_URL: postgres://postgres:postgres@localhost:5432/active_record_extended_test
run: |
bundle exec rake db:setup
- name: Run tests
env:
DATABASE_NAME: active_record_extended_test
DATABASE_URL: postgres://postgres:postgres@localhost:5432/active_record_extended_test
run: bundle exec rake
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.7
3.0.1
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rvm:
- 2.5
- 2.6
- 2.7
- 3.0
- ruby-head

before_install: gem install bundler
Expand All @@ -18,6 +19,7 @@ gemfile:
- gemfiles/activerecord-52.gemfile
- gemfiles/activerecord-60.gemfile
- gemfiles/activerecord-61.gemfile
- gemfiles/activerecord-70.gemfile

matrix:
allow_failures:
Expand All @@ -27,7 +29,12 @@ matrix:
gemfile: gemfiles/activerecord-60.gemfile
- rvm: 2.4
gemfile: gemfiles/activerecord-61.gemfile

- rvm: 2.4
gemfile: gemfiles/activerecord-70.gemfile
- rvm: 2.5
gemfile: gemfiles/activerecord-70.gemfile
- rvm: 2.6
gemfile: gemfiles/activerecord-70.gemfile

env:
global:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
active_record_extended (2.0.3)
activerecord (>= 5.1, < 6.2)
activerecord (>= 5.1, < 7.1.0)
ar_outer_joins (~> 0.2)
pg (< 3.0)

Expand Down Expand Up @@ -109,4 +109,4 @@ DEPENDENCIES
simplecov (~> 0.16)

BUNDLED WITH
2.1.4
2.2.16
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ This package is designed align and work with any officially supported Ruby and R
- Minimum Ruby Version: 2.4.x **(EOL warning!)**
- Minimum Rails Version: 5.1.x **(EOL warning!)**
- Minimum Postgres Version: 9.6.x **(EOL warning!)**
- Latest Ruby supported: 2.7.x
- Latest Rails supported: 6.1.x
- Latest Ruby supported: 3.0.x
- Latest Rails supported: 7.0.x
- Postgres: 9.6-current(13) (probably works with most older versions to a certain point)

## Installation
Expand Down
17 changes: 15 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,24 @@ namespace :db do
end

task drop: :load_db_settings do
`dropdb #{ENV["DATABASE_NAME"]}`
db_config = if ActiveRecord.version > Gem::Version.new('6.1')
ActiveRecord::Base.configurations.resolve ENV["DATABASE_URL"]
else
ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(ENV["DATABASE_URL"]).to_hash
end


ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(db_config).drop
end

task create: :load_db_settings do
`createdb #{ENV["DATABASE_NAME"]}`
db_config = if ActiveRecord.version > Gem::Version.new('6.1')
ActiveRecord::Base.configurations.resolve ENV["DATABASE_URL"]
else
ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(ENV["DATABASE_URL"]).to_hash
end

ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(db_config).create
end

task migrate: :load_db_settings do
Expand Down
2 changes: 1 addition & 1 deletion active_record_extended.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.4"

spec.add_dependency "activerecord", ">= 5.1", "< 6.2"
spec.add_dependency "activerecord", ">= 5.1", "< 7.1.0"
spec.add_dependency "ar_outer_joins", "~> 0.2"
spec.add_dependency "pg", "< 3.0"

Expand Down
8 changes: 8 additions & 0 deletions gemfiles/activerecord-70.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec path: ".."

gem "activerecord", "~> 7.0.0"
gem "pg", "< 2.0"
4 changes: 3 additions & 1 deletion lib/active_record_extended/query_methods/where_chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ActiveRecordExtended
module WhereChain
AR_VERSION_AT_LEAST_6_1 = ActiveRecord.version >= Gem::Version.new('6.1')

# Finds Records that have an array column that contain any a set of values
# User.where.overlap(tags: [1,2])
# # SELECT * FROM users WHERE tags && {1,2}
Expand Down Expand Up @@ -106,7 +108,7 @@ def substitute_comparisons(opts, rest, arel_node_class, method)
end

def build_where_clause_for(scope, opts, rest)
if ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR == 1
if AR_VERSION_AT_LEAST_6_1
scope.send(:build_where_clause, opts, rest)
else
scope.send(:where_clause_factory).build(opts, rest)
Expand Down
2 changes: 1 addition & 1 deletion spec/query_methods/unionize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
User.select(:id, "profile_ls.likes").joins(:profile_l).where("profile_ls.likes < 150")
)

expect(query.pluck(:id)).to have_attributes(size: 1).and(eq([user_one_pl.id]))
expect(query.pluck(:id)).to have_attributes(size: 1).and(eq([user_one_pl.user.id]))
expect(query.first.likes).to eq(user_one_pl.likes)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/query_methods/with_cte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
context "when using as a standalone query" do
it "should only return a person with less than 300 likes" do
query = User.with(profile: ProfileL.where("likes < 300"))
.joins("JOIN profile ON profile.id = users.id")
.joins("JOIN profile ON profile.user_id = users.id")

expect(query).to match_array([user_one])
end

it "should return anyone with likes greater than or equal to 200" do
query = User.with(profile: ProfileL.where("likes >= 200"))
.joins("JOIN profile ON profile.id = users.id")
.joins("JOIN profile ON profile.user_id = users.id")

expect(query).to match_array([user_one, user_two])
end
Expand All @@ -39,7 +39,7 @@
it "should contain a unique list of ordered CTE keys when merging in multiple children" do
x = User.with(profile: ProfileL.where("likes < 300"))
y = User.with(profile: ProfileL.where("likes > 400"))
z = y.merge(x).joins("JOIN profile ON profile.id = users.id") # Y should reject X's CTE (FIFO)
z = y.merge(x).joins("JOIN profile ON profile.user_id = users.id") # Y should reject X's CTE (FIFO)
query = User.with(my_profile: z).joins("JOIN my_profile ON my_profile.id = users.id")

expect(query.cte.with_keys).to eq([:profile, :my_profile])
Expand Down
2 changes: 1 addition & 1 deletion spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "database_cleaner"

DatabaseCleaner.strategy = :truncation
DatabaseCleaner.strategy = :transaction

RSpec.configure do |config|
config.before do
Expand Down

0 comments on commit 3d49e52

Please sign in to comment.