Skip to content

Commit 22ba79b

Browse files
lgebhardtDavidMikeSimon
authored andcommitted
Add test to demonstrate issue with SqlLiterals
1 parent 827f5db commit 22ba79b

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

test/controllers/controller_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,3 +3575,15 @@ def test_whitelisted_error_in_controller
35753575
$PostProcessorRaisesErrors = false
35763576
end
35773577
end
3578+
3579+
class Api::V6::PostsControllerTest < ActionController::TestCase
3580+
def test_with_sql_fragment
3581+
get :index, params: {include: 'section'}
3582+
assert_response :success
3583+
end
3584+
3585+
def test_caching_with_sql_fragment
3586+
assert_cacheable_get :index, params: {include: 'section'}
3587+
assert_response :success
3588+
end
3589+
end

test/fixtures/active_record.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,9 @@ class IsoCurrenciesController < JSONAPI::ResourceController
755755
end
756756

757757
module V6
758+
class PostsController < JSONAPI::ResourceController
759+
end
760+
758761
class CustomersController < JSONAPI::ResourceController
759762
end
760763

@@ -1459,6 +1462,18 @@ class EmployeeResource < EmployeeResource; end
14591462

14601463
module Api
14611464
module V6
1465+
class PersonResource < PersonResource; end
1466+
class TagResource < TagResource; end
1467+
class SectionResource < SectionResource; end
1468+
class CommentResource < CommentResource; end
1469+
1470+
class PostResource < PostResource
1471+
# Test caching with SQL fragments
1472+
def self.records(options = {})
1473+
super.joins('INNER JOIN people on people.id = author_id')
1474+
end
1475+
end
1476+
14621477
class CustomerResource < JSONAPI::Resource
14631478
attribute :name
14641479

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class CatResource < JSONAPI::Resource
321321

322322
JSONAPI.configuration.route_format = :dasherized_route
323323
namespace :v6 do
324+
jsonapi_resources :posts
324325
jsonapi_resources :customers
325326
jsonapi_resources :purchase_orders
326327
jsonapi_resources :line_items

0 commit comments

Comments
 (0)