diff --git a/.travis.yml b/.travis.yml index b276d4fbd..b67478eae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: ruby -sudo: false +os: linux -ruby_supported_versions: +_ruby_supported_versions: - &ruby_2_1 2.1.10 - &ruby_2_2 2.2.10 - &ruby_2_3 2.3.8 @@ -10,15 +10,15 @@ ruby_supported_versions: - &ruby_2_6 2.6.5 - &ruby_head ruby-head -jruby_supported_versions: +_jruby_supported_versions: - &jruby_9_1 jruby-9.1.17.0 - &jruby_9_2 jruby-9.2.8.0 - &jruby_head jruby-head -jdk_supported_versions: +_jdk_supported_versions: - &jdk_8 openjdk8 -rails_supported_versions: +_rails_supported_versions: - &rails_4_1 RAILS_VERSION=4.1 - &rails_4_1_jruby RAILS_VERSION=4.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug' - &rails_4_2 RAILS_VERSION=4.2 @@ -41,7 +41,7 @@ cache: before_install: - "travis_retry gem update --system 2.7.9" - "travis_retry gem install bundler -v '1.17.3'" -install: BUNDLER_VERSION=1.17.3 bundle install --path=vendor/bundle --retry=3 --jobs=3 +install: bundle install --path=vendor/bundle --retry=3 --jobs=3 script: - bundle exec rake ci @@ -49,7 +49,9 @@ after_success: - codeclimate-test-reporter env: - matrix: + global: + - BUNDLER_VERSION=1.17.3 + jobs: - *rails_4_1 - *rails_4_2 - *rails_5_0 @@ -70,7 +72,7 @@ rvm: branches: only: 0-10-stable -matrix: +jobs: include: - { rvm: *jruby_9_1, jdk: *jdk_8, env: *rails_4_1_jruby } - { rvm: *jruby_9_1, jdk: *jdk_8, env: *rails_4_2_jruby } diff --git a/active_model_serializers.gemspec b/active_model_serializers.gemspec index 8630cd324..a57b8d9a8 100644 --- a/active_model_serializers.gemspec +++ b/active_model_serializers.gemspec @@ -59,5 +59,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'timecop', '~> 0.7' spec.add_development_dependency 'grape', ['>= 0.13', '< 0.19.1'] spec.add_development_dependency 'json_schema' - spec.add_development_dependency 'rake', ['>= 10.0', '< 12.0'] + spec.add_development_dependency 'rake', ['>= 10.0', '< 13.0'] end diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 605d9dc5e..e3f973a34 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -73,7 +73,7 @@ def self.serializer_lookup_chain_for(klass, namespace = nil) # Used to cache serializer name => serializer class # when looked up by Serializer.get_serializer_for. def self.serializers_cache - @serializers_cache ||= ThreadSafe::Cache.new + @serializers_cache ||= Concurrent::Map.new end # @api private diff --git a/lib/active_model/serializer/reflection.rb b/lib/active_model/serializer/reflection.rb index 9c41bad83..170ea7713 100644 --- a/lib/active_model/serializer/reflection.rb +++ b/lib/active_model/serializer/reflection.rb @@ -87,8 +87,8 @@ def initialize(*) # meta ids: ids # end # end - def link(name, value = nil) - options[:links][name] = block_given? ? Proc.new : value + def link(name, value = nil, &block) + options[:links][name] = block_given? ? block : value :nil end @@ -102,8 +102,8 @@ def link(name, value = nil) # href object.blog.id.to_s # meta(id: object.blog.id) # end - def meta(value = nil) - options[:meta] = block_given? ? Proc.new : value + def meta(value = nil, &block) + options[:meta] = block_given? ? block : value :nil end diff --git a/test/serializers/serializer_for_with_namespace_test.rb b/test/serializers/serializer_for_with_namespace_test.rb index 3bba5e4af..f0f84528d 100644 --- a/test/serializers/serializer_for_with_namespace_test.rb +++ b/test/serializers/serializer_for_with_namespace_test.rb @@ -35,12 +35,11 @@ class PublisherSerializer < ActiveModel::Serializer class BookSerializer < ActiveModel::Serializer attributes :title, :author_name end + test 'resource without a namespace' do book = Book.new(title: 'A Post', author_name: 'hello') - # TODO: this should be able to pull up this serializer without explicitly specifying the serializer - # currently, with no options, it still uses the Api::V3 serializer - result = ActiveModelSerializers::SerializableResource.new(book, serializer: BookSerializer).serializable_hash + result = ActiveModelSerializers::SerializableResource.new(book).serializable_hash expected = { title: 'A Post', author_name: 'hello' } assert_equal expected, result