diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..9c0a710 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [dblock] +tidelift: rubygems/grape \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5ace460 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 0000000..87901fd --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,22 @@ +name: danger +on: pull_request +jobs: + danger: + name: Dangerfile + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/Gemfile.danger + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - 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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..d281f52 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,15 @@ +name: lint +on: [push, pull_request] +jobs: + rubocop: + name: RuboCop + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - run: bundle exec rubocop diff --git a/.github/workflows/test-activerecord.yml b/.github/workflows/test-activerecord.yml new file mode 100644 index 0000000..6bf3fce --- /dev/null +++ b/.github/workflows/test-activerecord.yml @@ -0,0 +1,32 @@ +--- +name: test-activerecord +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + entry: + - { ruby: '3.4', postgresql: '17', activerecord: '~> 8.0.2', grape: '2.4.0' } + name: test (ruby=${{ matrix.entry.ruby }}, postgresql=${{ matrix.entry.postgresql }}, activerecord=${{ matrix.entry.activerecord }}, grape=${{ matrix.entry.grape }}) + env: + ACTIVERECORD_VERSION: ${{ matrix.entry.activerecord }} + GRAPE_VERSION: ${{ matrix.entry.grape }} + steps: + - uses: harmon758/postgresql-action@v1 + with: + postgresql version: ${{ matrix.entry.postgresql }} + postgresql db: slack_ruby_bot_server_test + postgresql user: test + postgresql password: password + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.entry.ruby }} + bundler-cache: true + - name: Run ActiveRecord Tests + env: + SPEC_OPTS: --tag activerecord + run: bundle exec rake + - name: Run Tests + run: bundle exec rake diff --git a/.github/workflows/test-mongodb.yml b/.github/workflows/test-mongodb.yml new file mode 100644 index 0000000..41fd19c --- /dev/null +++ b/.github/workflows/test-mongodb.yml @@ -0,0 +1,29 @@ +--- +name: test-mongodb +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + entry: + - { ruby: '3.4', mongoid: '6.4.8', mongodb: '6.0', grape: '1.7.0' } + name: test (ruby=${{ matrix.entry.ruby }}, mongoid=${{ matrix.entry.mongoid }}, mongodb=${{ matrix.entry.mongodb }}, grape=${{ matrix.entry.grape }}) + env: + MONGOID_VERSION: ${{ matrix.entry.mongoid }} + GRAPE_VERSION: ${{ matrix.entry.grape }} + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.entry.ruby }} + bundler-cache: true + - uses: supercharge/mongodb-github-action@1.7.0 + with: + mongodb-version: ${{ matrix.entry.mongodb }} + - name: Run Tests + run: bundle exec rake + - name: Run Mongoid Tagged Tests + env: + SPEC_OPTS: --tag mongoid + run: bundle exec rake diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4bc89d7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +--- +name: test +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + entry: + - { ruby: 3.4 } + name: test (ruby=${{ matrix.entry.ruby }}) + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.entry.ruby }} + bundler-cache: true + - name: Run Tests + run: bundle exec rake diff --git a/.rubocop.yml b/.rubocop.yml index e372e16..340e4ed 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,14 @@ AllCops: - TargetRubyVersion: 2.3 - DisplayCopNames: true + TargetRubyVersion: 3.0 + NewCops: enable Exclude: - bin/**/* - gemfiles/**/* - spec/**/* - vendor/**/* -inherit_from: .rubocop_todo.yml \ No newline at end of file +inherit_from: .rubocop_todo.yml + +plugins: + - rubocop-rake + - rubocop-rspec \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c9c035c..5e7e134 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,18 +1,45 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-07-02 09:34:39 -0400 using RuboCop version 0.49.1. +# on 2025-09-24 16:57:49 UTC using RuboCop version 1.80.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 7 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 108 +# Offense count: 1 +# Configuration parameters: Severity. +Gemspec/RequiredRubyVersion: + Exclude: + - 'grape-roar.gemspec' + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 11 + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'Rakefile.rb' + - 'lib/grape-roar.rb' + +# Offense count: 6 +# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs. +# NamePrefix: is_, has_, have_, does_ +# ForbiddenPrefixes: is_, has_, have_, does_ +# AllowedMethods: is_a? +# MethodDefinitionMacros: define_method, define_singleton_method +Naming/PredicatePrefix: + Exclude: + - 'spec/**/*' + - 'lib/grape/roar/extensions/relations/validations/active_record.rb' + - 'lib/grape/roar/extensions/relations/validations/mongoid.rb' # Offense count: 14 +# Configuration parameters: AllowedConstants. Style/Documentation: Exclude: - 'spec/**/*' @@ -32,18 +59,8 @@ Style/Documentation: - 'lib/grape/roar/representer.rb' # Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. -# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS -Style/FileName: - Exclude: - - 'lib/grape-roar.rb' - -# Offense count: 3 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -Style/PredicateName: +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: Exclude: - - 'spec/**/*' - - 'lib/grape/roar/extensions/relations/validations/active_record.rb' + - 'lib/grape/roar/extensions/relations/dsl_methods.rb' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 22b2b1c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -sudo: false - -language: ruby - -cache: bundler - -rvm: - - 2.4.1 - - 2.3.4 - -gemfile: - - Gemfile - - gemfiles/with_activerecord.gemfile - - gemfiles/with_mongoid.gemfile - -services: - - mongodb - - pg - -matrix: - include: - - env: SPEC_OPTS="--tag active_record" - gemfile: gemfiles/with_activerecord.gemfile - rvm: 2.4.1 - - env: SPEC_OPTS="--tag mongoid" - gemfile: gemfiles/with_mongoid.gemfile - rvm: 2.4.1 - - env: SPEC_OPTS="--tag active_record" - gemfile: gemfiles/with_activerecord.gemfile - rvm: 2.3.4 - - env: SPEC_OPTS="--tag mongoid" - gemfile: gemfiles/with_mongoid.gemfile - rvm: 2.3.4 - - -script: bundle exec rake \ No newline at end of file diff --git a/Appraisals b/Appraisals deleted file mode 100644 index 80c4db0..0000000 --- a/Appraisals +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -appraise 'with-activerecord' do - gem 'activerecord', '>= 4.0.0', require: 'active_record' -end - -appraise 'with-mongoid' do - gem 'mongoid', '>= 5.0.0', require: 'mongoid' -end diff --git a/CHANGELOG.md b/CHANGELOG.md index a0bd6c9..4d2b12f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,35 +1,30 @@ -Next ----- +### 0.5.0 (Next) +* [#23](https://github.com/ruby-grape/grape-roar/pull/23): Resolves pollution issue with invoking representers on singletons - [@mach-kernel](https://github.com/mach-kernel). +* [#28](https://github.com/ruby-grape/grape-roar/pull/28): Replaced Travis-CI with GHA - [@dblock](https://github.com/dblock). * Your contribution here. -* [#23](https://github.com/ruby-grape/grape-roar/pull/23): Resolves pollution issue with invoking representers on singletons ([#16](https://github.com/ruby-grape/grape-roar/issues/16)) - [@mach-kernel](https://github.com/mach-kernel). -0.4.1 (07/14/2017) ----- +### 0.4.1 (2017/07/14) -* [#22](https://github.com/ruby-grape/grape-roar/pull/22): Adds Grape::Roar::Extensions::Relations. +* [#22](https://github.com/ruby-grape/grape-roar/pull/22): Adds Grape::Roar::Extensions::Relations - [@mach-kernel](https://github.com/mach-kernel). -0.4.0 (02/18/2017) ------------------- +### 0.4.0 (2017/02/18) * [#21](https://github.com/ruby-grape/grape-roar/pull/21): Fixes serialization issue due to [representable](https://github.com/trailblazer/representable) API change, drop support for Ruby < `2.1.0` - [@mach-kernel](https://github.com/mach-kernel). -0.3.0 (12/31/2014) ------------------- +### 0.3.0 (2014/12/31) * Added support for Roar 1.0 - [@dblock](https://github.com/dblock). -0.2.0 (12/18/2014) ------------------- +### 0.2.0 (2014/12/18) * [#10](https://github.com/ruby-grape/grape-roar/pull/10): Support for Roar decorator - [@sdbondi](https://github.com/sdbondi). -0.1.0 (7/17/2014) ------------------ +### 0.1.0 (2014/7/17) * Initial public release, with support for Grape `present` - [@dblock](https://github.com/dblock). diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..527dbb8 --- /dev/null +++ b/Dangerfile @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +danger.import_dangerfile(gem: 'ruby-grape-danger') +toc.check! diff --git a/Gemfile b/Gemfile index 78b460a..5a5363f 100644 --- a/Gemfile +++ b/Gemfile @@ -4,17 +4,25 @@ source 'https://rubygems.org' gemspec -group :development do - gem 'appraisal', '~> 2.2.0' -end +gem 'activerecord', ENV['ACTIVERECORD_VERSION'], require: 'active_record' if ENV.key?('ACTIVERECORD_VERSION') +gem 'grape', ENV['GRAPE_VERSION'] if ENV.key?('GRAPE_VERSION') +gem 'mongoid', ENV['MONGOID_VERSION'], require: 'mongoid' if ENV.key?('MONGOID_VERSION') group :test do gem 'rack-test' - gem 'rspec', '~> 3.1' + gem 'rspec' end group :development, :test do + gem 'base64' + gem 'bigdecimal' + gem 'mutex_m' gem 'nokogiri' + gem 'ostruct' + gem 'rack', '~> 2.2.17' gem 'rake' - gem 'rubocop', '0.49.1' + gem 'rubocop', '1.80.2' + gem 'rubocop-rake' + gem 'rubocop-rspec' + gem 'sorted_set' end diff --git a/Gemfile.danger b/Gemfile.danger new file mode 100644 index 0000000..d22a65b --- /dev/null +++ b/Gemfile.danger @@ -0,0 +1,6 @@ +source 'https://rubygems.org' + +group :test do + gem 'danger-toc', '~> 0.2.0', require: false + gem 'ruby-grape-danger', '~> 0.2.1', require: false +end diff --git a/README.md b/README.md index 0f9f470..1a8e56a 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,43 @@ Grape::Roar ------------- +----------- [![Gem Version](http://img.shields.io/gem/v/grape-roar.svg)](http://badge.fury.io/rb/grape-roar) -[![Build Status](http://img.shields.io/travis/ruby-grape/grape-roar.svg)](https://travis-ci.org/ruby-grape/grape-roar) -[![Dependency Status](https://gemnasium.com/ruby-grape/grape-roar.svg)](https://gemnasium.com/ruby-grape/grape-roar) -[![Code Climate](https://codeclimate.com/github/ruby-grape/grape-roar.svg)](https://codeclimate.com/github/ruby-grape/grape-roar) +[![test](https://github.com/ruby-grape/grape-roar/actions/workflows/test.yml/badge.svg)](https://github.com/ruby-grape/grape-roar/actions/workflows/test.yml) +[![test-activerecord](https://github.com/ruby-grape/grape-roar/actions/workflows/test-activerecord.yml/badge.svg)](https://github.com/ruby-grape/grape-roar/actions/workflows/test-activerecord.yml) +[![test-mongodb](https://github.com/ruby-grape/grape-roar/actions/workflows/test-mongodb.yml/badge.svg)](https://github.com/ruby-grape/grape-roar/actions/workflows/test-mongodb.yml) Use [Roar](https://github.com/apotonick/roar) with [Grape](https://github.com/intridea/grape). -Demo ----- - -The [grape-with-roar](https://github.com/ruby-grape/grape-with-roar) project deployed [here on heroku](http://grape-with-roar.herokuapp.com). - -Installation ------------- +## Table of Contents + +- [Demo](#demo) +- [Installation](#installation) +- [Usage](#usage) + - [Tell your API to use Grape::Formatter::Roar](#tell-your-api-to-use-grapeformatterroar) + - [Use Grape’s Present](#use-grapes-present) + - [Accessing the Request Inside a Representer](#accessing-the-request-inside-a-representer) + - [Decorators](#decorators) + - [Relation Extensions](#relation-extensions) + - [Designing Representers](#designing-representers) + - [Example Models](#example-models) + - [Example Representers](#example-representers) + - [Example Item](#example-item) + - [Example Cart](#example-cart) + - [Errors](#errors) + - [Change how URLs are presented](#change-how-urls-are-presented) + - [Override base URI mappings](#override-base-uri-mappings) + - [Override resource URI mappings](#override-resource-uri-mappings) + - [Designing Adapters](#designing-adapters) + - [Example: ActiveRecord Adapter](#example-activerecord-adapter) + - [Validations](#validations) +- [Contributing](#contributing) +- [Copyright and License](#copyright-and-license) + +## Demo + +See [grape-with-roar](https://github.com/ruby-grape/grape-with-roar). + +## Installation Add the `grape`, `roar` and `grape-roar` gems to Gemfile. @@ -26,8 +49,7 @@ gem 'grape-roar' If you're upgrading from an older version of this gem, please see [UPGRADING](UPGRADING.md). -Usage ------ +## Usage ### Tell your API to use Grape::Formatter::Roar @@ -338,15 +360,12 @@ end After writing your validation methods, just mix them into your adapter. You can choose to not write validation methods; they are only invoked if your adapter responds to them. - -Contributing ------------- +## Contributing See [CONTRIBUTING](CONTRIBUTING.md). -Copyright and License ---------------------- +## Copyright and License MIT License, see [LICENSE](LICENSE) for details. -(c) 2012-2014 [Daniel Doubrovkine](https://github.com/dblock) & Contributors, [Artsy](https://artsy.net) +(c) 2012-2025 [Daniel Doubrovkine](https://github.com/dblock) & Contributors, [Artsy](https://artsy.net) diff --git a/gemfiles/with_activerecord.gemfile b/gemfiles/with_activerecord.gemfile deleted file mode 100644 index fa982cd..0000000 --- a/gemfiles/with_activerecord.gemfile +++ /dev/null @@ -1,22 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "activerecord", ">= 4.0.0", require: "active_record" - -group :development do - gem "appraisal", "~> 2.2.0" -end - -group :test do - gem "rack-test" - gem "rspec", "~> 3.1" -end - -group :development, :test do - gem "nokogiri" - gem "rake" - gem "rubocop", "0.49.1" -end - -gemspec path: "../" diff --git a/gemfiles/with_mongoid.gemfile b/gemfiles/with_mongoid.gemfile deleted file mode 100644 index 2e87e6b..0000000 --- a/gemfiles/with_mongoid.gemfile +++ /dev/null @@ -1,22 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "mongoid", ">= 5.0.0", require: "mongoid" - -group :development do - gem "appraisal", "~> 2.2.0" -end - -group :test do - gem "rack-test" - gem "rspec", "~> 3.1" -end - -group :development, :test do - gem "nokogiri" - gem "rake" - gem "rubocop", "0.49.1" -end - -gemspec path: "../" diff --git a/grape-roar.gemspec b/grape-roar.gemspec index ce8b357..1b05558 100644 --- a/grape-roar.gemspec +++ b/grape-roar.gemspec @@ -1,7 +1,6 @@ -# -*- encoding: utf-8 -*- # frozen_string_literal: true -require File.expand_path('../lib/grape/roar/version', __FILE__) +require File.expand_path('lib/grape/roar/version', __dir__) Gem::Specification.new do |gem| gem.authors = ['Daniel Doubrovkine'] @@ -13,7 +12,6 @@ Gem::Specification.new do |gem| gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.files = `git ls-files`.split("\n") - gem.test_files = `git ls-files -- {spec}/*`.split("\n") gem.name = 'grape-roar' gem.require_paths = ['lib'] gem.version = Grape::Roar::VERSION @@ -22,4 +20,5 @@ Gem::Specification.new do |gem| gem.add_dependency 'multi_json' gem.add_dependency 'roar', '~> 1.1.0' gem.required_ruby_version = '>= 2.1.0' + gem.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/grape/roar/extensions/relations/adapters/base.rb b/lib/grape/roar/extensions/relations/adapters/base.rb index e746175..99e2867 100644 --- a/lib/grape/roar/extensions/relations/adapters/base.rb +++ b/lib/grape/roar/extensions/relations/adapters/base.rb @@ -9,7 +9,7 @@ class Base class << self def valid_for?(klass) valid_proc.call(klass) - rescue + rescue StandardError false end diff --git a/lib/grape/roar/extensions/relations/mapper.rb b/lib/grape/roar/extensions/relations/mapper.rb index 7bad7ea..1af0c5a 100644 --- a/lib/grape/roar/extensions/relations/mapper.rb +++ b/lib/grape/roar/extensions/relations/mapper.rb @@ -34,6 +34,7 @@ def decorate(klass) def find_representer(base, target_name, const) const = base.const_get(const) return false if const.nil? || !const.is_a?(Module) + (const < ::Roar::JSON::HAL) && const.name .downcase .include?(target_name.singularize) @@ -41,6 +42,7 @@ def find_representer(base, target_name, const) def map_collection(relation, opts) return entity.link_relation(relation, true) unless opts.fetch(:embedded, false) + entity.collection(relation, opts) end @@ -50,8 +52,9 @@ def map_relation(relation, opts) elsif adapter.single_entity_methods .include?(opts[:relation_kind]) || opts[:relation_kind] == :self :map_single_entity - else raise Exceptions::UnsupportedRelationError, - 'No such relation supported' + else + raise Exceptions::UnsupportedRelationError, + 'No such relation supported' end send(map, relation, opts) @@ -61,6 +64,7 @@ def map_relation(relation, opts) def map_single_entity(relation, opts) return entity.map_self_url if opts[:relation_kind] == :self return entity.link_relation(relation) unless opts.fetch(:embedded, false) + entity.property(relation, opts) end @@ -80,6 +84,7 @@ def representer_for(relation, opts) def validate_relation(relation, kind) validator_method = "#{kind}_valid?" return true unless adapter.respond_to?(validator_method) + adapter.send(validator_method, relation.to_s) end end diff --git a/lib/grape/roar/extensions/relations/validations/mongoid.rb b/lib/grape/roar/extensions/relations/validations/mongoid.rb index b725edc..fa71bf4 100644 --- a/lib/grape/roar/extensions/relations/validations/mongoid.rb +++ b/lib/grape/roar/extensions/relations/validations/mongoid.rb @@ -41,7 +41,6 @@ def embeds_one_valid?(relation) ) end - # rubocop:disable Style/PredicateName def has_many_valid?(relation) relation = klass.reflect_on_association(relation) @@ -52,9 +51,7 @@ def has_many_valid?(relation) ::Mongoid::Relations::Referenced::Many, relation[:relation] ) end - # rubocop:enable Style/PredicateName - # rubocop:disable Style/PredicateName def has_and_belongs_to_many_valid?(relation) relation = klass.reflect_on_association(relation) @@ -66,9 +63,7 @@ def has_and_belongs_to_many_valid?(relation) relation[:relation] ) end - # rubocop:enable Style/PredicateName - # rubocop:disable Style/PredicateName def has_one_valid?(relation) relation = klass.reflect_on_association(relation) @@ -79,7 +74,6 @@ def has_one_valid?(relation) ::Mongoid::Relations::Referenced::One, relation[:relation] ) end - # rubocop:enable Style/PredicateName end end end diff --git a/lib/grape/roar/representer.rb b/lib/grape/roar/representer.rb index a250e07..067a7d6 100644 --- a/lib/grape/roar/representer.rb +++ b/lib/grape/roar/representer.rb @@ -11,6 +11,7 @@ module ClassMethods def represent(object, _options = {}) # See https://github.com/ruby-grape/grape-roar/issues/16 raise TypeError if object.singleton_class == object.class + object.extend(self) object end diff --git a/lib/grape/roar/version.rb b/lib/grape/roar/version.rb index fe6b5c6..76b5acd 100644 --- a/lib/grape/roar/version.rb +++ b/lib/grape/roar/version.rb @@ -2,6 +2,6 @@ module Grape module Roar - VERSION = '0.4.1' + VERSION = '0.5.0' end end diff --git a/spec/extensions/relations/adapters/active_record_spec.rb b/spec/extensions/relations/adapters/active_record_spec.rb index ec266c2..ad2271b 100644 --- a/spec/extensions/relations/adapters/active_record_spec.rb +++ b/spec/extensions/relations/adapters/active_record_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -describe Grape::Roar::Extensions::Relations::Adapters::ActiveRecord, active_record: true do +describe Grape::Roar::Extensions::Relations::Adapters::ActiveRecord, activerecord: true do let(:model) { Class.new(ActiveRecord::Base) } subject { described_class.new(model) } diff --git a/spec/extensions/relations/adapters/adapters_module_spec.rb b/spec/extensions/relations/adapters/adapters_module_spec.rb index 8c710df..e9ab854 100644 --- a/spec/extensions/relations/adapters/adapters_module_spec.rb +++ b/spec/extensions/relations/adapters/adapters_module_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -describe Grape::Roar::Extensions::Relations::Adapters, active_record: true do +describe Grape::Roar::Extensions::Relations::Adapters, activerecord: true do context '.for' do let(:model) { Class.new(ActiveRecord::Base) } diff --git a/spec/extensions/relations/dsl_methods_spec.rb b/spec/extensions/relations/dsl_methods_spec.rb index c555811..e5530a6 100644 --- a/spec/extensions/relations/dsl_methods_spec.rb +++ b/spec/extensions/relations/dsl_methods_spec.rb @@ -68,7 +68,7 @@ it 'calls the method correctly' do expect(relational_mapper).to receive(:[]=).with( - :self, relation_kind: :self + :self, { relation_kind: :self } ) end end diff --git a/spec/extensions/relations/validations/active_record_spec.rb b/spec/extensions/relations/validations/active_record_spec.rb index c0c12ab..89d390a 100644 --- a/spec/extensions/relations/validations/active_record_spec.rb +++ b/spec/extensions/relations/validations/active_record_spec.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -describe Grape::Roar::Extensions::Relations::Validations::ActiveRecord, active_record: true do +describe Grape::Roar::Extensions::Relations::Validations::ActiveRecord, activerecord: true do let(:model_klass) { double } subject do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 047c047..787a387 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,10 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) +require 'ostruct' +require 'bigdecimal' +require 'base64' + require 'bundler' Bundler.setup :default, :test Bundler.require @@ -15,13 +19,12 @@ require 'grape/roar' require 'rack/test' - require 'rspec' RSpec.configure do |config| config.include Rack::Test::Methods config.filter_run_excluding( - active_record: true, mongoid: true + activerecord: true, mongoid: true ) end