Skip to content
Draft
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
15 changes: 1 addition & 14 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ jobs:
- 7.0.4
- 6.1.7
- 6.0.6
- 5.2.8.1
- 5.1.7
database_url:
- postgresql://postgres:password@localhost:5432/test
- sqlite3:test_db
Expand All @@ -45,24 +43,13 @@ jobs:
rails: 6.0.6
- ruby: 3.2
rails: 5.2.8.1
- ruby: 3.2
rails: 5.1.7
- ruby: 3.1
rails: 6.0.6
- ruby: 3.1
rails: 5.2.8.1
- ruby: 3.1
rails: 5.1.7
- ruby: '3.0'
rails: 6.0.6
- ruby: '3.0'
rails: 5.2.8.1
- ruby: '3.0'
rails: 5.1.7
- ruby: 2.6
rails: 7.0.4
- database_url: postgresql://postgres:password@localhost:5432/test
rails: 5.1.7

env:
RAILS_VERSION: ${{ matrix.rails }}
DATABASE_URL: ${{ matrix.database_url }}
Expand Down
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ version = ENV['RAILS_VERSION'] || 'default'
platforms :ruby do
gem 'pg'

if version.start_with?('4.2', '5.0')
gem 'sqlite3', '~> 1.3.13'
else
gem 'sqlite3', '~> 1.4'
end
gem 'sqlite3', '~> 1.4'
end

case version
Expand Down
2 changes: 1 addition & 1 deletion jsonapi-resources.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry'
spec.add_development_dependency 'concurrent-ruby-ext'
spec.add_development_dependency 'database_cleaner'
spec.add_dependency 'activerecord', '>= 5.1'
spec.add_dependency 'activerecord', '>= 6.0'
spec.add_dependency 'railties', '>= 5.1'
spec.add_dependency 'concurrent-ruby'
end
6 changes: 1 addition & 5 deletions lib/jsonapi-resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
require 'jsonapi/cached_response_fragment'
require 'jsonapi/response_document'
require 'jsonapi/acts_as_resource_controller'
if Rails::VERSION::MAJOR >= 6
ActiveSupport.on_load(:action_controller_base) do
require 'jsonapi/resource_controller'
end
else
ActiveSupport.on_load(:action_controller_base) do
require 'jsonapi/resource_controller'
end
require 'jsonapi/resource_controller_metal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ module JSONAPI
module ActiveRelation
module Adapters
module JoinLeftActiveRecordAdapter
# Extends left_joins functionality to rails 4, and uses the same logic for rails 5.0.x and 5.1.x
# The default left_joins logic of rails 5.2.x is used. This results in and extra join in some cases. For
# example Post.joins(:comments).joins_left(comments: :author) will join the comments table twice,
# once inner and once left in 5.2, but only as inner in earlier versions.
def joins_left(*columns)
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
left_joins(columns)
else
join_dependency = ActiveRecord::Associations::JoinDependency.new(self, columns, [])
joins(join_dependency)
end
end
ActiveSupport::Deprecation.warn "Prefer `left_joins`, JSONAPI::ActiveRelation::Adapters::JoinLeftActiveRecordAdapter will be removed in a future release"
left_joins(columns)
end

alias_method :join_left, :joins_left
end
Expand Down
10 changes: 3 additions & 7 deletions lib/jsonapi/active_relation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ def apply_join(records:, relationship:, resource_type:, join_type:, options:)
when :inner
records = records.joins(resource_type.to_s.singularize.to_sym)
when :left
records = records.joins_left(resource_type.to_s.singularize.to_sym)
records = records.left_joins(resource_type.to_s.singularize.to_sym)
end
else
relation_name = relationship.relation_name(options)
case join_type
when :inner
records = records.joins(relation_name)
when :left
records = records.joins_left(relation_name)
records = records.left_joins(relation_name)
end
end
records
Expand Down Expand Up @@ -772,11 +772,7 @@ def apply_single_sort(records, field, direction, options)

# Assumes ActiveRecord's counting. Override if you need a different counting method
def count_records(records)
if (Rails::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR >= 6
records.count(:all)
else
records.count
end
records.count(:all)
end

def filter_records(records, filters, options)
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ class PostResource < PostResource
when :inner
records = records.joins(relationship.relation_name(options))
when :left
records = records.joins_left(relationship.relation_name(options))
records = records.left_joins(relationship.relation_name(options))
end
records.where(comments: {approved: true})
}
Expand Down Expand Up @@ -2369,7 +2369,7 @@ class PostResource < PostResource
when :inner
records = records.joins(relationship.relation_name(options))
when :left
records = records.joins_left(relationship.relation_name(options))
records = records.left_joins(relationship.relation_name(options))
end
records.where(comments: {approved: true})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ class JoinTreeTest < ActiveSupport::TestCase
def db_true
case ActiveRecord::Base.connection.adapter_name
when 'SQLite'
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
"1"
else
"'t'"
end
"1"
when 'PostgreSQL'
'TRUE'
end
Expand Down
Loading