Skip to content

Commit

Permalink
Code cleanup (#2369)
Browse files Browse the repository at this point in the history
* Lint travis.yml on https://config.travis-ci.com/explore

* Replace deprecated 'thread_safe' with 'concurrent-ruby' alternative

'thread_safe' gem is now deprecated and merged into 'concurrent-ruby'.
Ref: ruby-concurrency/concurrent-ruby@52e5f37#diff-42d5a45da331eaa07d2b315bd3c9e738

* Fix deprecation warning for Ruby 2.7

https://bugs.ruby-lang.org/issues/15539


* Remove a TODO tag that is already resolved
  • Loading branch information
wasifhossain authored and bf4 committed Jan 3, 2020
1 parent 6b093c9 commit 64c7fee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
18 changes: 10 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -41,15 +41,17 @@ 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
after_success:
- codeclimate-test-reporter

env:
matrix:
global:
- BUNDLER_VERSION=1.17.3
jobs:
- *rails_4_1
- *rails_4_2
- *rails_5_0
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion active_model_serializers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/active_model/serializer/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions test/serializers/serializer_for_with_namespace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64c7fee

Please sign in to comment.