Skip to content

Commit 896563c

Browse files
pabselgebhardt
authored andcommitted
Add support for Rails 6
fixes #1280
1 parent 3040156 commit 896563c

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

Diff for: .travis.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ env:
55
- "RAILS_VERSION=5.0.7.2"
66
- "RAILS_VERSION=5.1.7"
77
- "RAILS_VERSION=5.2.3"
8-
# - "RAILS_VERSION=6.0.0.beta1"
8+
- "RAILS_VERSION=6.0.0"
99
# - "RAILS_VERSION=master"
1010
rvm:
1111
- 2.3.8
@@ -15,9 +15,12 @@ rvm:
1515
matrix:
1616
allow_failures:
1717
- env: "RAILS_VERSION=master"
18-
- env: "RAILS_VERSION=6.0.0.beta1"
1918
exclude:
2019
- rvm: 2.6.4
2120
env: "RAILS_VERSION=4.2.11"
21+
- rvm: 2.3.8
22+
env: "RAILS_VERSION=6.0.0"
23+
- rvm: 2.4.7
24+
env: "RAILS_VERSION=6.0.0"
2225
before_install:
2326
- gem install bundler --version 1.17.3

Diff for: Gemfile

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ source 'https://rubygems.org'
22

33
gemspec
44

5-
platforms :ruby do
6-
gem 'sqlite3', '1.3.13'
7-
end
8-
95
platforms :jruby do
106
gem 'activerecord-jdbcsqlite3-adapter'
117
end
@@ -17,7 +13,17 @@ when 'master'
1713
gem 'railties', { git: 'https://github.com/rails/rails.git' }
1814
gem 'arel', { git: 'https://github.com/rails/arel.git' }
1915
when 'default'
20-
gem 'railties', '>= 5.0'
16+
gem 'railties', '>= 6.0'
17+
when '6.0.0'
18+
platforms :ruby do
19+
gem 'sqlite3', '~> 1.4'
20+
end
21+
22+
gem 'railties', "~> #{version}"
2123
else
24+
platforms :ruby do
25+
gem 'sqlite3', '1.3.13'
26+
end
27+
2228
gem 'railties', "~> #{version}"
23-
end
29+
end

Diff for: lib/jsonapi-resources.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
require 'jsonapi/cached_response_fragment'
88
require 'jsonapi/response_document'
99
require 'jsonapi/acts_as_resource_controller'
10-
require 'jsonapi/resource_controller'
10+
if ActiveSupport.respond_to?(:on_load)
11+
ActiveSupport.on_load(:action_controller_base) do
12+
require 'jsonapi/resource_controller'
13+
end
14+
else
15+
require 'jsonapi/resource_controller'
16+
end
1117
require 'jsonapi/resource_controller_metal'
1218
require 'jsonapi/resources/version'
1319
require 'jsonapi/configuration'

Diff for: lib/jsonapi/active_relation/adapters/join_left_active_record_adapter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module JoinLeftActiveRecordAdapter
88
# example Post.joins(:comments).joins_left(comments: :author) will join the comments table twice,
99
# once inner and once left in 5.2, but only as inner in earlier versions.
1010
def joins_left(*columns)
11-
if Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2
11+
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
1212
left_joins(columns)
1313
else
1414
join_dependency = ActiveRecord::Associations::JoinDependency.new(self, columns, [])

Diff for: test/unit/active_relation_resource_finder/join_manager_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_add_joins_source_relationship_with_custom_apply
7979
records = Api::V10::PostResource.records({})
8080
records = join_manager.join(records, {})
8181

82-
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
82+
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
8383
assert_equal 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE "comments"."approved" = 1', records.to_sql
8484
else
8585
assert_equal 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" WHERE "comments"."approved" = \'t\'', records.to_sql
@@ -99,7 +99,7 @@ def test_add_nested_scoped_joins
9999
records = Api::V10::PostResource.records({})
100100
records = join_manager.join(records, {})
101101

102-
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
102+
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
103103
assert_equal 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" ON "people"."id" = "posts"."author_id" LEFT OUTER JOIN "people" "authors_comments" ON "authors_comments"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" WHERE "comments"."approved" = 1 AND "author"."special" = 1', records.to_sql
104104
else
105105
assert_equal 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" ON "people"."id" = "posts"."author_id" LEFT OUTER JOIN "people" "authors_comments" ON "authors_comments"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" WHERE "comments"."approved" = \'t\' AND "author"."special" = \'t\'', records.to_sql
@@ -123,7 +123,7 @@ def test_add_nested_scoped_joins
123123
records = join_manager.join(records, {})
124124

125125
# Note sql is in different order, but aliases should still be right
126-
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
126+
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
127127
assert_equal 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "people" ON "people"."id" = "posts"."author_id" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" "authors_comments" ON "authors_comments"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" WHERE "comments"."approved" = 1 AND "author"."special" = 1', records.to_sql
128128
else
129129
assert_equal 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "people" ON "people"."id" = "posts"."author_id" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" "authors_comments" ON "authors_comments"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" WHERE "comments"."approved" = \'t\' AND "author"."special" = \'t\'', records.to_sql
@@ -163,7 +163,7 @@ def test_add_nested_joins_with_fields
163163
records = Api::V10::PostResource.records({})
164164
records = join_manager.join(records, {})
165165

166-
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
166+
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
167167
assert_equal 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" ON "people"."id" = "posts"."author_id" LEFT OUTER JOIN "people" "authors_comments" ON "authors_comments"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" WHERE "comments"."approved" = 1 AND "author"."special" = 1', records.to_sql
168168
else
169169
assert_equal 'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" ON "people"."id" = "posts"."author_id" LEFT OUTER JOIN "people" "authors_comments" ON "authors_comments"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" WHERE "comments"."approved" = \'t\' AND "author"."special" = \'t\'', records.to_sql
@@ -184,7 +184,7 @@ def test_add_joins_with_sub_relationship
184184
records = Api::V10::PostResource.records({})
185185
records = join_manager.join(records, {})
186186

187-
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
187+
if Rails::VERSION::MAJOR >= 6 || (Rails::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 2)
188188
assert_equal 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" ON "people"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" LEFT OUTER JOIN "comments" "comments_people" ON "comments_people"."author_id" = "people"."id" WHERE "comments"."approved" = 1 AND "author"."special" = 1', records.to_sql
189189
else
190190
assert_equal 'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" LEFT OUTER JOIN "people" ON "people"."id" = "comments"."author_id" LEFT OUTER JOIN "comments_tags" ON "comments_tags"."comment_id" = "comments"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "comments_tags"."tag_id" LEFT OUTER JOIN "comments" "comments_people" ON "comments_people"."author_id" = "people"."id" WHERE "comments"."approved" = \'t\' AND "author"."special" = \'t\'', records.to_sql

0 commit comments

Comments
 (0)