From 7e58753b765e0abf6f44c9d9e4312cef30f43de1 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Wed, 23 Apr 2025 15:23:37 -0700 Subject: [PATCH 1/6] Fix compatibility with Grape 2.3 --- Gemfile | 4 ++-- grape-active_model_serializers.gemspec | 2 +- lib/grape-active_model_serializers/error_formatter.rb | 4 +--- lib/grape-active_model_serializers/formatter.rb | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 9d8509f..c9b3f8a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' gemspec -case version = ENV['GRAPE_VERSION'] || '~> 1.0.0' +case version = ENV['GRAPE_VERSION'] || '~> 2.3.0' when 'HEAD' gem 'grape', github: 'intridea/grape' else @@ -12,7 +12,7 @@ end group :test do gem 'rack-test' gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'sequel', '~> 4.37', require: false + gem 'sequel', '~> 5.91', require: false gem 'sqlite3' end diff --git a/grape-active_model_serializers.gemspec b/grape-active_model_serializers.gemspec index 4c6cf0a..85fcc86 100644 --- a/grape-active_model_serializers.gemspec +++ b/grape-active_model_serializers.gemspec @@ -16,6 +16,6 @@ Gem::Specification.new do |gem| gem.version = Grape::ActiveModelSerializers::VERSION gem.licenses = ['MIT'] - gem.add_dependency 'grape', '>= 0.8.0' + gem.add_dependency 'grape', '>= 2.3.0' gem.add_dependency 'active_model_serializers', '>= 0.10.0' end diff --git a/lib/grape-active_model_serializers/error_formatter.rb b/lib/grape-active_model_serializers/error_formatter.rb index a071f2a..fa34def 100644 --- a/lib/grape-active_model_serializers/error_formatter.rb +++ b/lib/grape-active_model_serializers/error_formatter.rb @@ -1,8 +1,6 @@ module Grape module ErrorFormatter - module ActiveModelSerializers - extend Base - + class ActiveModelSerializers < Base class << self def call(message, backtrace, options = {}, env = nil, original_exception = nil) message = present(message, env) if respond_to?(:present) diff --git a/lib/grape-active_model_serializers/formatter.rb b/lib/grape-active_model_serializers/formatter.rb index 19b0183..c9c3ed8 100644 --- a/lib/grape-active_model_serializers/formatter.rb +++ b/lib/grape-active_model_serializers/formatter.rb @@ -1,6 +1,6 @@ module Grape module Formatter - module ActiveModelSerializers + class ActiveModelSerializers class << self def call(resource, env) options = build_options(resource, env) From 096fd41c111936218cf9c914c67d883d97c0e76a Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Wed, 23 Apr 2025 15:27:00 -0700 Subject: [PATCH 2/6] Bump version to 2.0 and update changelog --- CHANGELOG.md | 4 ++-- lib/grape-active_model_serializers/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1399b27..84b58a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ## Changelog -### 1.5.3 (Next) +### 2.0.0 (Next) -* Your contribution here. +* [#96](https://github.com/ruby-grape/grape-active_model_serializers/pull/96): Add compatibility for Grape 2.3 — [@samsonjs](https://github.com/samsonjs) ### 1.5.2 (March 14, 2018) diff --git a/lib/grape-active_model_serializers/version.rb b/lib/grape-active_model_serializers/version.rb index 313d3ab..e4a0891 100644 --- a/lib/grape-active_model_serializers/version.rb +++ b/lib/grape-active_model_serializers/version.rb @@ -1,5 +1,5 @@ module Grape module ActiveModelSerializers - VERSION = '1.5.3'.freeze + VERSION = '2.0.0'.freeze end end From 0a11b5d1016fa0052a8a1d232733d94f604d8a52 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 24 May 2025 15:01:29 -0700 Subject: [PATCH 3/6] Out with Travis CI, in with GitHub Actions * Update dependencies and appease the robot overlords, rubocop and danger. --- .github/workflows/ci.yml | 36 +++++++++++++++++ .rubocop.yml | 4 ++ .rubocop_todo.yml | 8 +++- .travis.yml | 39 ------------------- CHANGELOG.md | 22 ++++++----- Gemfile | 6 +-- README.md | 24 +++++++++++- Rakefile | 1 + .../endpoint_extension.rb | 3 +- .../options_builder.rb | 1 + .../serializer_resolver.rb | 5 ++- .../endpoint_extension_spec.rb | 4 +- .../versioned_api_formatter_spec.rb | 4 +- spec/grape-active_model_serializers_spec.rb | 4 -- .../options_builder_spec.rb | 2 +- .../serializer_resolver_spec.rb | 4 +- spec/old_grape_ams_spec.rb | 38 +++++++++--------- spec/spec_helper.rb | 2 +- 18 files changed, 118 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml delete mode 100644 spec/grape-active_model_serializers_spec.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..13ddf72 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - ruby-version: 3.4.4 + command: bundle exec danger + + - ruby-version: 3.4.4 + command: bundle exec rake + - ruby-version: 3.3.8 + command: bundle exec rake + - ruby-version: 3.2.8 + command: bundle exec rake + - ruby-version: 3.1.7 + command: bundle exec rake + + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run command + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ${{ matrix.command }} diff --git a/.rubocop.yml b/.rubocop.yml index a3abca1..43a01c4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,10 @@ AllCops: Exclude: - Guardfile - grape-active_model_serializers.gemspec + NewCops: enable Style/BlockDelimiters: Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ad2d8dd..843aa5b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -15,7 +15,7 @@ Bundler/DuplicatedGem: # Offense count: 1 Metrics/AbcSize: - Max: 17 + Max: 18 # Offense count: 23 # Configuration parameters: CountComments, ExcludedMethods. @@ -63,5 +63,9 @@ Style/GuardClause: # Offense count: 2 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https -Metrics/LineLength: +Layout/LineLength: Max: 87 + +Lint/ConstantDefinitionInBlock: + Exclude: + - spec/integration/sequel_spec.rb diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index edea92b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: ruby - -sudo: false - -matrix: - include: - - rvm: 2.5.0 - script: - - bundle exec danger - - rvm: 2.5.0 - env: GRAPE_VERSION=0.8.0 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.9.0 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.10.1 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.12.0 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.13.0 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.14.0 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.15.0 - - rvm: 2.5.0 - env: GRAPE_VERSION=0.16.2 - - rvm: 2.5.0 - env: GRAPE_VERSION=HEAD - - rvm: 2.4.3 - - rvm: 2.3.6 - - rvm: 2.2.9 - - rvm: rbx-2 - - rvm: jruby-19mode - - rvm: ruby-head - - rvm: jruby-head - allow_failures: - - rvm: rbx-2 - - rvm: jruby-19mode - - rvm: ruby-head - - rvm: jruby-head diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b58a1..e8b3c37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,20 +2,22 @@ ### 2.0.0 (Next) -* [#96](https://github.com/ruby-grape/grape-active_model_serializers/pull/96): Add compatibility for Grape 2.3 — [@samsonjs](https://github.com/samsonjs) +* [#96](https://github.com/ruby-grape/grape-active_model_serializers/pull/96): Add compatibility for Grape 2.3 - [@samsonjs](https://github.com/samsonjs). +* [#98](https://github.com/ruby-grape/grape-active_model_serializers/pull/98): Out with Travis CI, in with GitHub Actions - [@samsonjs](https://github.com/samsonjs). +* Your contribution here. -### 1.5.2 (March 14, 2018) +### 1.5.2 (2018/03/14) * [#76](https://github.com/ruby-grape/grape-active_model_serializers/pull/76): Add custom error formatter - [@xn](https://github.com/xn). -### 1.5.1 (April 25, 2017) +### 1.5.1 (2017/04/25) * [#74](https://github.com/ruby-grape/grape-active_model_serializers/pull/74): Add support for Sequel - [@drn](https://github.com/drn). * [#73](https://github.com/ruby-grape/grape-active_model_serializers/pull/73): Ensure all AMS options are passed through - [@drn](https://github.com/drn). * [#65](https://github.com/ruby-grape/grape-active_model_serializers/pull/65): Added Danger, PR linter - [@dblock](https://github.com/dblock). * [#63](https://github.com/ruby-grape/grape-active_model_serializers/pull/63): Pass adapter options through render - [@drn](https://github.com/drn). -### 1.5.0 (August 24, 2016) +### 1.5.0 (2016/08/24) * [#61](https://github.com/ruby-grape/grape-active_model_serializers/pull/61): Adds support for collection serializers - [@drn](https://github.com/drn). * [#60](https://github.com/ruby-grape/grape-active_model_serializers/pull/60): Namespace serializer inference - [@drn](https://github.com/drn). @@ -23,22 +25,22 @@ * [#57](https://github.com/ruby-grape/grape-active_model_serializers/pull/57): Solve line length linter issues - [@drn](https://github.com/drn). * [#54](https://github.com/ruby-grape/grape-active_model_serializers/pull/54): Adding support for ASM v0.10. Drops support for ASM v0.9 - [@drn](https://github.com/drn). -### 1.4.0 (July 14, 2016) +### 1.4.0 (2016/07/14) * [#49](https://github.com/ruby-grape/grape-active_model_serializers/pull/49): Adds support for active model serializer namespace - [@syntaxTerr0r](https://github.com/syntaxTerr0r). * [#36](https://github.com/ruby-grape/grape-active_model_serializers/pull/36), [#50](https://github.com/jrhe/grape-active_model_serializers/pull/50): Added support through Grape 0.16.x - [@dblock](https://github.com/dblock). -### v1.3.2 (February 27, 2015) +### 1.3.2 (2015/02/27) * [#40](https://github.com/ruby-grape/grape-active_model_serializers/pull/40): Use env to pass AMS meta around - [@dblock](https://github.com/dblock). * [#39](https://github.com/ruby-grape/grape-active_model_serializers/pull/39): Look for namespace and other options to configure serializers - [@jwkoelewijn](https://github.com/jwkoelewijn). -### v1.3.1 (November 20, 2014) +### 1.3.1 (2014/11/20) * [#30](https://github.com/ruby-grape/grape-active_model_serializers/pull/30): Read options from default_serializer_options - [@siong1987](https://github.com/siong1987). * [#24](https://github.com/ruby-grape/grape-active_model_serializers/pull/24): Makes it possible to use `current_user` within serializers - [@sonxurxo](https://github.com/sonxurxo). -### v1.2.1 (July 23, 2014) +### 1.2.1 (2014/07/23) * [#21](https://github.com/ruby-grape/grape-active_model_serializers/pull/21): Correctly fetch serialization scope - [@radanskoric](https://github.com/radanskoric). * [#18](https://github.com/ruby-grape/grape-active_model_serializers/pull/18): Added support for active model serializer 0.9.x - [@sbounmy](https://github.com/sbounmy). @@ -48,12 +50,12 @@ * [#12](https://github.com/ruby-grape/grape-active_model_serializers/pull/12): Added support for `current_user` - [@kpassapk](https://github.com/kpassapk). * [#11](https://github.com/ruby-grape/grape-active_model_serializers/pull/11): Fixed require path - [@schickling](https://github.com/schickling). -### v1.0.1 (September 9, 2013) +### 1.0.1 (2013/09/09) * [#6](https://github.com/ruby-grape/grape-active_model_serializers/pull/6): Conform to ActiveModel::Serializers way of determining array-ness - [@tfe](https://github.com/tfe). * [#4](https://github.com/ruby-grape/grape-active_model_serializers/pull/4): Support for namespace options and rely more on active_model_serializers - [@johnallen3d](https://github.com/johnallen3d). * [#1](https://github.com/ruby-grape/grape-active_model_serializers/pull/1): Fix: Grape::ActiveModelSerializers for models with compound names - [@george](https://github.com/george). -### v1.0.0 +### 1.0.0 (2013/09/09) * Initial public release - [@jrhe](https://github.com/jrhe). diff --git a/Gemfile b/Gemfile index c9b3f8a..abf0d65 100644 --- a/Gemfile +++ b/Gemfile @@ -11,15 +11,15 @@ end group :test do gem 'rack-test' - gem 'ruby-grape-danger', '~> 0.1.0', require: false + gem 'ruby-grape-danger', '~> 0.2.0', require: false gem 'sequel', '~> 5.91', require: false gem 'sqlite3' end group :development, :test do gem 'guard-rspec' - gem 'listen', '~> 3.0.7' + gem 'listen', '~> 3.9.0' gem 'rake' gem 'rspec' - gem 'rubocop', '0.53.0' + gem 'rubocop', '1.75.7' end diff --git a/README.md b/README.md index f750e9c..6eaa56c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,23 @@ +# Table of Contents + +- [Grape::ActiveModelSerializers](#grapeactivemodelserializers) + - [Installation](#installation) + - [Dependencies](#dependencies) + - [Usage](#usage) + - [Require grape-active_model_serializers](#require-grape-active_model_serializers) + - [Tell your API to use Grape::Formatter::ActiveModelSerializers](#tell-your-api-to-use-grapeformatteractivemodelserializers) + - [Writing Serializers](#writing-serializers) + - [Serializers are inferred by active_record model names](#serializers-are-inferred-by-active_record-model-names) + - [Array Roots](#array-roots) + - [API Versioning](#api-versioning) + - [Manually specifying serializer / adapter options](#manually-specifying-serializer--adapter-options) + - [Custom Metadata](#custom-metadata) + - [Default Serializer Options](#default-serializer-options) + - [Current User](#current-user) + - [Full Example](#full-example) + - [Contributing](#contributing) + - [History](#history) + # Grape::ActiveModelSerializers Use [active_model_serializers](https://github.com/rails-api/active_model_serializers) with [Grape](https://github.com/intridea/grape)! @@ -17,8 +37,8 @@ See [UPGRADING](UPGRADING.md) if you're upgrading from a previous version. ## Dependencies -* >= Ruby v2.2 -* >= [grape](https://github.com/ruby-grape/grape) v0.8.0 +* >= Ruby v3.1 +* >= [grape](https://github.com/ruby-grape/grape) v2.3.0 * >= [active_model_serializers](https://github.com/rails-api/active_model_serializers) v0.10.0 ## Usage diff --git a/Rakefile b/Rakefile index 1dd0ac7..fd07807 100755 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ #!/usr/bin/env rake + require 'bundler/gem_tasks' require 'rspec/core' diff --git a/lib/grape-active_model_serializers/endpoint_extension.rb b/lib/grape-active_model_serializers/endpoint_extension.rb index f575513..a9abce1 100644 --- a/lib/grape-active_model_serializers/endpoint_extension.rb +++ b/lib/grape-active_model_serializers/endpoint_extension.rb @@ -32,6 +32,7 @@ module Grape def serialization_scope return unless _serialization_scope return unless respond_to?(_serialization_scope, true) + send(_serialization_scope) end end @@ -55,5 +56,5 @@ module Grape def url_options; end end - Endpoint.send(:include, EndpointExtension) + Endpoint.include EndpointExtension end diff --git a/lib/grape-active_model_serializers/options_builder.rb b/lib/grape-active_model_serializers/options_builder.rb index 9b6fb86..e415d40 100644 --- a/lib/grape-active_model_serializers/options_builder.rb +++ b/lib/grape-active_model_serializers/options_builder.rb @@ -73,6 +73,7 @@ module Grape def extra_options options = env['ams_extra'] || {} return options if options.is_a?(Hash) + raise 'Extra options must be a hash' end end diff --git a/lib/grape-active_model_serializers/serializer_resolver.rb b/lib/grape-active_model_serializers/serializer_resolver.rb index 13220a1..5ae2b0b 100644 --- a/lib/grape-active_model_serializers/serializer_resolver.rb +++ b/lib/grape-active_model_serializers/serializer_resolver.rb @@ -7,7 +7,7 @@ module Grape end def serializer - serializer_class.new(resource, serializer_options) if serializer_class + serializer_class&.new(resource, serializer_options) end private @@ -16,6 +16,7 @@ module Grape def serializer_class return @serializer_class if defined?(@serializer_class) + @serializer_class = resource_defined_class @serializer_class ||= collection_class @serializer_class ||= options[:serializer] @@ -55,12 +56,14 @@ module Grape def namespace_inferred_class return nil unless options.key?(:for) + namespace = options[:for].to_s.deconstantize "#{namespace}::#{resource_serializer_klass}".safe_constantize end def version_inferred_class return nil unless options.key?(:version) + "#{version}::#{resource_serializer_klass}".safe_constantize end diff --git a/spec/grape-active_model_serializers/endpoint_extension_spec.rb b/spec/grape-active_model_serializers/endpoint_extension_spec.rb index b2ba568..7b144d2 100644 --- a/spec/grape-active_model_serializers/endpoint_extension_spec.rb +++ b/spec/grape-active_model_serializers/endpoint_extension_spec.rb @@ -5,7 +5,7 @@ describe 'Grape::EndpointExtension' do subject do Grape::Endpoint.new( Grape::Util::InheritableSetting.new, - path: '/', + path: '/', method: 'foo' ) end @@ -27,7 +27,7 @@ describe 'Grape::EndpointExtension' do describe '#render' do let(:env) { {} } - let(:env_key) {} + let(:env_key) { nil } before do allow(subject).to receive(:env).and_return(env) diff --git a/spec/grape-active_model_serializers/versioned_api_formatter_spec.rb b/spec/grape-active_model_serializers/versioned_api_formatter_spec.rb index e0bb0b9..3dae35a 100644 --- a/spec/grape-active_model_serializers/versioned_api_formatter_spec.rb +++ b/spec/grape-active_model_serializers/versioned_api_formatter_spec.rb @@ -18,8 +18,8 @@ describe Grape::Formatter::ActiveModelSerializers do { user: { first_name: 'JR', - last_name: 'HE', - email: 'jrhe@github.com' + last_name: 'HE', + email: 'jrhe@github.com' } } end diff --git a/spec/grape-active_model_serializers_spec.rb b/spec/grape-active_model_serializers_spec.rb deleted file mode 100644 index a642ad1..0000000 --- a/spec/grape-active_model_serializers_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'spec_helper' - -describe 'grape-active_model_serializers' do -end diff --git a/spec/grape/active_model_serializers/options_builder_spec.rb b/spec/grape/active_model_serializers/options_builder_spec.rb index af47c43..71ebe70 100644 --- a/spec/grape/active_model_serializers/options_builder_spec.rb +++ b/spec/grape/active_model_serializers/options_builder_spec.rb @@ -12,7 +12,7 @@ describe Grape::ActiveModelSerializers::OptionsBuilder do let(:env) { super().merge('ams_meta' => meta_options) } let(:meta_options) { { - meta: meta, + meta: meta, meta_key: meta_key } } diff --git a/spec/grape/active_model_serializers/serializer_resolver_spec.rb b/spec/grape/active_model_serializers/serializer_resolver_spec.rb index da10876..e381b23 100644 --- a/spec/grape/active_model_serializers/serializer_resolver_spec.rb +++ b/spec/grape/active_model_serializers/serializer_resolver_spec.rb @@ -15,8 +15,8 @@ describe Grape::ActiveModelSerializers::SerializerResolver do let(:options) { { serializer: options_serializer_class, # options defined - for: V4::UsersApi, # namespace inference - version: 'v5' # version inference + for: V4::UsersApi, # namespace inference + version: 'v5' # version inference } } # resource defined diff --git a/spec/old_grape_ams_spec.rb b/spec/old_grape_ams_spec.rb index ef041d6..c40ffed 100644 --- a/spec/old_grape_ams_spec.rb +++ b/spec/old_grape_ams_spec.rb @@ -42,8 +42,8 @@ describe Grape::ActiveModelSerializers do app.get('/home') do User.new( first_name: 'JR', - last_name: 'HE', - email: 'contact@jrhe.co.uk' + last_name: 'HE', + email: 'contact@jrhe.co.uk' ) end end @@ -60,17 +60,17 @@ describe Grape::ActiveModelSerializers do app.get('/users') do user = User.new( first_name: 'JR', - last_name: 'HE', - email: 'contact@jrhe.co.uk' + last_name: 'HE', + email: 'contact@jrhe.co.uk' ) [user, user] end get '/users' expect(subject).to eq( - '{"users":['\ - '{"first_name":"JR","last_name":"HE"},'\ - '{"first_name":"JR","last_name":"HE"}'\ + '{"users":[' \ + '{"first_name":"JR","last_name":"HE"},' \ + '{"first_name":"JR","last_name":"HE"}' \ ']}' ) end @@ -83,8 +83,8 @@ describe Grape::ActiveModelSerializers do get '/home' expect(subject).to eq( - '{"blog_post":'\ - '{"title":"Grape AM::S Rocks!","body":"Really, it does."}'\ + '{"blog_post":' \ + '{"title":"Grape AM::S Rocks!","body":"Really, it does."}' \ '}' ) end @@ -93,16 +93,16 @@ describe Grape::ActiveModelSerializers do app.get('/blog_posts') do blog_post = BlogPost.new( title: 'Grape AM::S Rocks!', - body: 'Really, it does.' + body: 'Really, it does.' ) [blog_post, blog_post] end get '/blog_posts' expect(subject).to eq( - '{"blog_posts":['\ - '{"title":"Grape AM::S Rocks!","body":"Really, it does."},'\ - '{"title":"Grape AM::S Rocks!","body":"Really, it does."}'\ + '{"blog_posts":[' \ + '{"title":"Grape AM::S Rocks!","body":"Really, it does."},' \ + '{"title":"Grape AM::S Rocks!","body":"Really, it does."}' \ ']}' ) end @@ -132,9 +132,9 @@ describe Grape::ActiveModelSerializers do get '/admin/jeff' expect(subject).to eq( - '{"admin":['\ - '{"first_name":"Jeff","last_name":null},'\ - '{"first_name":"Jeff","last_name":null}'\ + '{"admin":[' \ + '{"first_name":"Jeff","last_name":null},' \ + '{"first_name":"Jeff","last_name":null}' \ ']}' ) end @@ -149,9 +149,9 @@ describe Grape::ActiveModelSerializers do get '/people' expect(subject).to eq( - '{"people":['\ - '{"first_name":"Jeff","last_name":null},'\ - '{"first_name":"Jeff","last_name":null}'\ + '{"people":[' \ + '{"first_name":"Jeff","last_name":null},' \ + '{"first_name":"Jeff","last_name":null}' \ ']}' ) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8b1450f..96c41aa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,4 +15,4 @@ RSpec.configure do |config| config.include Rack::Test::Methods end -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } From 0da8ef5bd3bbd96229d3447a85c9f58049bbc64a Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 24 May 2025 16:11:34 -0700 Subject: [PATCH 4/6] Split up workflow into 2 jobs --- .github/workflows/ci.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13ddf72..1f704e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,23 +6,25 @@ on: branches: [master] jobs: + danger: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.4.4 + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run danger + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: bundle exec danger + test: runs-on: ubuntu-latest strategy: matrix: - include: - - ruby-version: 3.4.4 - command: bundle exec danger - - - ruby-version: 3.4.4 - command: bundle exec rake - - ruby-version: 3.3.8 - command: bundle exec rake - - ruby-version: 3.2.8 - command: bundle exec rake - - ruby-version: 3.1.7 - command: bundle exec rake - + ruby-version: [3.4.4, 3.3.8, 3.2.8, 3.1.7] steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 @@ -30,7 +32,5 @@ jobs: ruby-version: ${{ matrix.ruby-version }} - name: Install dependencies run: bundle install --jobs 4 --retry 3 - - name: Run command - env: - DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ${{ matrix.command }} + - name: Run tests + run: bundle exec rake From dcc17a065dc67d0f9cca229ce136f2be593a0210 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 25 May 2025 14:34:16 -0700 Subject: [PATCH 5/6] PR feedback: fix Danger's GitHub token, run on all branches --- .github/workflows/ci.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f704e8..559f536 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,5 @@ name: CI -on: - push: - branches: [master] - pull_request: - branches: [master] +on: [push, pull_request] jobs: danger: @@ -15,10 +11,11 @@ jobs: ruby-version: 3.4.4 - name: Install dependencies run: bundle install --jobs 4 --retry 3 - - name: Run danger - env: - DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bundle exec danger + - name: Run Danger + run: | + # the token is public, has public_repo scope and belongs to the grape-bot user owned by @dblock, this is ok + TOKEN=$(echo -n Z2hwX2lYb0dPNXNyejYzOFJyaTV3QUxUdkNiS1dtblFwZTFuRXpmMwo= | base64 --decode) + DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose test: runs-on: ubuntu-latest From b609ebc6396ccbc5eb45c8f5e14cf916bd7fd0c6 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 25 May 2025 14:38:50 -0700 Subject: [PATCH 6/6] Use GitHub Actions for build status badge in Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6eaa56c..d59d8ba 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Use [active_model_serializers](https://github.com/rails-api/active_model_serializers) with [Grape](https://github.com/intridea/grape)! [![Gem Version](https://badge.fury.io/rb/grape-active_model_serializers.svg)](https://badge.fury.io/rb/grape-active_model_serializers) -[![Build Status](https://api.travis-ci.org/ruby-grape/grape-active_model_serializers.svg)](http://travis-ci.org/ruby-grape/grape-active_model_serializers) [![Code Climate](https://codeclimate.com/github/ruby-grape/grape-active_model_serializers.svg)](https://codeclimate.com/github/ruby-grape/grape-active_model_serializers) +[![Build Status](https://github.com/ruby-grape/grape-active_model_serializers/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby-grape/grape-active_model_serializers/actions/workflows/ci.yml) [![Code Climate](https://codeclimate.com/github/ruby-grape/grape-active_model_serializers.svg)](https://codeclimate.com/github/ruby-grape/grape-active_model_serializers) ## Installation