mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +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:
commit
8aaaa44ba3
13
.travis.yml
13
.travis.yml
@ -5,7 +5,8 @@ sudo: false
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
- 2.2
|
||||
- 2.1
|
||||
- 2.2.2
|
||||
- ruby-head
|
||||
- rbx-2
|
||||
|
||||
@ -24,12 +25,18 @@ env:
|
||||
- "RAILS_VERSION=master"
|
||||
|
||||
matrix:
|
||||
include:
|
||||
exclude:
|
||||
- rvm: 1.9.3
|
||||
env: RAILS_VERSION=master
|
||||
- rvm: 2.0.0
|
||||
env: RAILS_VERSION=master
|
||||
- rvm: 2.1
|
||||
env: RAILS_VERSION=master
|
||||
include:
|
||||
- rvm: 2.2
|
||||
env: CAPTURE_STDERR=true
|
||||
- rvm: jruby-19mode
|
||||
env: JRUBY_OPTS='--server -Xcompile.invokedynamic=false -Xcli.debug=true --debug'
|
||||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
- env: "RAILS_VERSION=master"
|
||||
fast_finish: true
|
||||
|
||||
7
Gemfile
7
Gemfile
@ -11,22 +11,23 @@ version = ENV['RAILS_VERSION'] || '4.2'
|
||||
|
||||
if version == 'master'
|
||||
gem 'rack', github: 'rack/rack'
|
||||
gem 'arel', github: 'rails/arel'
|
||||
git 'https://github.com/rails/rails.git' do
|
||||
gem 'railties'
|
||||
gem 'activesupport'
|
||||
gem 'activemodel'
|
||||
gem 'actionpack'
|
||||
gem 'activerecord', group: :test
|
||||
# Rails 5
|
||||
gem 'actionview'
|
||||
end
|
||||
# Rails 5
|
||||
gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
|
||||
else
|
||||
gem_version = "~> #{version}.0"
|
||||
gem 'railties', gem_version
|
||||
gem 'activesupport', gem_version
|
||||
gem 'activemodel', gem_version
|
||||
gem 'actionpack', gem_version
|
||||
gem 'activerecord', gem_version, group: :test
|
||||
end
|
||||
|
||||
# https://github.com/bundler/bundler/blob/89a8778c19269561926cea172acdcda241d26d23/lib/bundler/dependency.rb#L30-L54
|
||||
@ -36,11 +37,9 @@ end
|
||||
gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
|
||||
|
||||
group :test do
|
||||
gem 'activerecord'
|
||||
gem 'sqlite3', platform: (@windows_platforms + [:ruby])
|
||||
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
|
||||
|
||||
gem 'minitest-reporters', require: false, group: :development
|
||||
gem 'codeclimate-test-reporter', require: false
|
||||
gem 'simplecov', '~> 0.10', require: false, group: :development
|
||||
end
|
||||
|
||||
@ -41,10 +41,16 @@ Gem::Specification.new do |spec|
|
||||
# 'minitest'
|
||||
# 'thread_safe'
|
||||
|
||||
spec.add_development_dependency 'activerecord', rails_versions
|
||||
# arel
|
||||
# activesuport
|
||||
# activemodel
|
||||
|
||||
# Soft dependency for pagination
|
||||
spec.add_development_dependency 'kaminari', ' ~> 0.16.3'
|
||||
spec.add_development_dependency 'will_paginate', '~> 3.0', '>= 3.0.7'
|
||||
|
||||
spec.add_development_dependency 'bundler', '~> 1.6'
|
||||
spec.add_development_dependency 'timecop', '~> 0.7'
|
||||
spec.add_development_dependency 'minitest-reporters'
|
||||
end
|
||||
|
||||
@ -152,7 +152,7 @@ module ActiveModel
|
||||
# @todo require less code comments. See
|
||||
# https://github.com/rails-api/active_model_serializers/pull/1249#issuecomment-146567837
|
||||
def self.cache(options = {})
|
||||
self._cache = ActionController::Base.cache_store if Rails.configuration.action_controller.perform_caching
|
||||
self._cache = ActiveModelSerializers.config.cache_store if ActiveModelSerializers.config.perform_caching
|
||||
self._cache_key = options.delete(:key)
|
||||
self._cache_only = options.delete(:only)
|
||||
self._cache_except = options.delete(:except)
|
||||
|
||||
@ -8,6 +8,13 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
initializer 'active_model_serializers.caching' do
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
ActiveModelSerializers.config.cache_store = ActionController::Base.cache_store
|
||||
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
|
||||
end
|
||||
end
|
||||
|
||||
initializer 'generators' do |app|
|
||||
app.load_generators
|
||||
require 'generators/serializer/resource_override'
|
||||
|
||||
@ -5,6 +5,10 @@ require 'action_controller/railtie'
|
||||
module ActiveModelSerializers
|
||||
mattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
||||
|
||||
def self.config
|
||||
ActiveModel::Serializer.config
|
||||
end
|
||||
|
||||
extend ActiveSupport::Autoload
|
||||
autoload :Model
|
||||
autoload :Callbacks
|
||||
|
||||
@ -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'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user