mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #1324 from rails-api/get_tests_running_on_rails_master
Get tests passing on Rails 5
This commit is contained in:
@@ -53,7 +53,7 @@ module ActionController
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||
|
||||
get :render_pagination_using_will_paginate, page: { number: 2, size: 1 }
|
||||
get :render_pagination_using_will_paginate, params: { page: { number: 2, size: 1 } }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
@@ -62,7 +62,7 @@ module ActionController
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2" }
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }
|
||||
get :render_pagination_using_will_paginate, params: { page: { number: 1, size: 2 } }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
@@ -73,7 +73,7 @@ module ActionController
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'next' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'last' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||
get :render_pagination_using_kaminari, page: { number: 2, size: 1 }
|
||||
get :render_pagination_using_kaminari, params: { page: { number: 2, size: 1 } }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
@@ -82,7 +82,7 @@ module ActionController
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1" }
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }
|
||||
get :render_pagination_using_kaminari, params: { page: { number: 3, size: 1 } }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
@@ -91,7 +91,7 @@ module ActionController
|
||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional" }
|
||||
get :render_pagination_using_will_paginate, page: { number: 1, size: 2 }, teste: 'additional'
|
||||
get :render_pagination_using_will_paginate, params: { page: { number: 1, size: 2 }, teste: 'additional' }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
@@ -100,13 +100,13 @@ module ActionController
|
||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional" }
|
||||
get :render_pagination_using_kaminari, page: { number: 3, size: 1 }, teste: 'additional'
|
||||
get :render_pagination_using_kaminari, params: { page: { number: 3, size: 1 }, teste: 'additional' }
|
||||
response = JSON.parse(@response.body)
|
||||
assert_equal expected_links, response['links']
|
||||
end
|
||||
|
||||
def test_array_without_pagination_links
|
||||
get :render_array_without_pagination_links, page: { number: 2, size: 1 }
|
||||
get :render_array_without_pagination_links, params: { page: { number: 2, size: 1 } }
|
||||
response = JSON.parse(@response.body)
|
||||
refute response.key? 'links'
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ class DefaultScopeNameTest < ActionController::TestCase
|
||||
class UserTestController < ActionController::Base
|
||||
protect_from_forgery
|
||||
|
||||
before_filter { request.format = :json }
|
||||
before_action { request.format = :json }
|
||||
|
||||
def current_user
|
||||
User.new(id: 1, name: 'Pete', admin: false)
|
||||
@@ -43,7 +43,7 @@ class SerializationScopeNameTest < ActionController::TestCase
|
||||
protect_from_forgery
|
||||
|
||||
serialization_scope :current_admin
|
||||
before_filter { request.format = :json }
|
||||
before_action { request.format = :json }
|
||||
|
||||
def current_admin
|
||||
User.new(id: 2, name: 'Bob', admin: true)
|
||||
|
||||
@@ -4,6 +4,7 @@ module ActiveModel
|
||||
module Adapter
|
||||
class FragmentCacheTest < Minitest::Test
|
||||
def setup
|
||||
super
|
||||
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
||||
@author = Author.new(name: 'Joao M. D. Moura')
|
||||
@role = Role.new(name: 'Great Author', description: nil)
|
||||
|
||||
6
test/fixtures/poro.rb
vendored
6
test/fixtures/poro.rb
vendored
@@ -16,6 +16,12 @@ class Model < ActiveModelSerializers::Model
|
||||
end
|
||||
end
|
||||
|
||||
# required for ActiveModel::AttributeAssignment#_assign_attribute
|
||||
# in Rails 5
|
||||
def respond_to_missing?(method_name, _include_private = false)
|
||||
attributes.key?(method_name.to_s.tr('=', '').to_sym) || super
|
||||
end
|
||||
|
||||
def cache_key_with_digest
|
||||
"#{cache_key}/#{FILE_DIGEST}"
|
||||
end
|
||||
|
||||
29
test/support/rails5_shims.rb
Normal file
29
test/support/rails5_shims.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
module Rails5Shims
|
||||
module ControllerTests
|
||||
# https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb
|
||||
REQUEST_KWARGS = [:params, :session, :flash, :method, :body, :xhr]
|
||||
|
||||
# Fold kwargs from test request into args
|
||||
# Band-aid for DEPRECATION WARNING
|
||||
def get(path, *args)
|
||||
hash = args && args[0]
|
||||
if hash.respond_to?(:key)
|
||||
Rails5Shims::ControllerTests::REQUEST_KWARGS.each do |kwarg|
|
||||
next unless hash.key?(kwarg)
|
||||
hash.merge! hash.delete(kwarg)
|
||||
end
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
# Uncomment for debugging where the kwargs warnings come from
|
||||
# def non_kwarg_request_warning
|
||||
# super.tap do
|
||||
# STDOUT.puts caller[2..3]
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
if Rails::VERSION::MAJOR < 5
|
||||
ActionController::TestCase.send :include, Rails5Shims::ControllerTests
|
||||
end
|
||||
@@ -1,14 +1,18 @@
|
||||
class Foo < Rails::Application
|
||||
class ActiveModelSerializers::RailsApplication < Rails::Application
|
||||
if Rails::VERSION::MAJOR >= 4
|
||||
config.eager_load = false
|
||||
|
||||
config.secret_key_base = 'abc123'
|
||||
config.action_controller.perform_caching = true
|
||||
|
||||
config.active_support.test_order = :random
|
||||
|
||||
config.logger = Logger.new(nil)
|
||||
|
||||
config.action_controller.perform_caching = true
|
||||
ActionController::Base.cache_store = :memory_store
|
||||
end
|
||||
end
|
||||
Foo.initialize!
|
||||
ActiveModelSerializers::RailsApplication.initialize!
|
||||
|
||||
module TestHelper
|
||||
Routes = ActionDispatch::Routing::RouteSet.new
|
||||
|
||||
@@ -2,4 +2,18 @@ ActionController::TestCase.class_eval do
|
||||
def setup
|
||||
@routes = TestHelper::Routes
|
||||
end
|
||||
|
||||
# For Rails5
|
||||
# https://github.com/rails/rails/commit/ca83436d1b3b6cedd1eca2259f65661e69b01909#diff-b9bbf56e85d3fe1999f16317f2751e76L17
|
||||
def assigns(key = nil)
|
||||
assigns = {}.with_indifferent_access
|
||||
@controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) }
|
||||
key.nil? ? assigns : assigns[key]
|
||||
end
|
||||
|
||||
# Rails5: Uncomment for debugging where the warnings come from
|
||||
# def non_kwarg_request_warning
|
||||
# super
|
||||
# STDOUT.puts caller[2..3]
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -64,6 +64,8 @@ require 'support/test_case'
|
||||
|
||||
require 'support/serialization_testing'
|
||||
|
||||
require 'support/rails5_shims'
|
||||
|
||||
require 'fixtures/active_record'
|
||||
|
||||
require 'fixtures/poro'
|
||||
|
||||
Reference in New Issue
Block a user