diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4f127d9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,13 @@ +--- +name: test +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.4 + bundler-cache: true + - run: bundle exec rake \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index bdd4025..ed844a8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,11 @@ AllCops: + NewCops: enable Exclude: - vendor/**/* - bin/**/* +plugins: + - rubocop-rake + - rubocop-rspec + inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f1f00df..680c398 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,28 +1,84 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-08-06 12:31:48 -0400 using RuboCop version 0.33.0. +# on 2025-09-10 16:24:35 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: 1 -Metrics/AbcSize: - Max: 19 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/NonDeterministicRequireOrder: + Exclude: + - 'config/application.rb' -# Offense count: 18 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 152 +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 18 # Offense count: 1 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 45 + +# Offense count: 2 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 15 +# Offense count: 3 +RSpec/AnyInstance: + Exclude: + - 'spec/api/splines_endpoint_spec.rb' + +# Offense count: 5 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/api/cors_spec.rb' + - 'spec/api/splines_endpoint_spec.rb' + - 'spec/api/splines_endpoint_with_hyperclient_spec.rb' + +# Offense count: 5 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 10 + +# Offense count: 19 +RSpec/MultipleExpectations: + Max: 5 + +# Offense count: 4 +# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata. +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/api/cors_spec.rb' + - 'spec/api/root_endpoint_spec.rb' + - 'spec/api/splines_endpoint_spec.rb' + - 'spec/api/splines_endpoint_with_hyperclient_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Rake/Desc: + Exclude: + - 'Rakefile' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/CommentedKeyword: + Exclude: + - 'api/splines_endpoint.rb' + # Offense count: 9 +# Configuration parameters: AllowedConstants. Style/Documentation: Exclude: + - 'spec/**/*' + - 'test/**/*' - 'api/extensions/crud_extension.rb' - 'api/presenters/paginated_presenter.rb' - 'api/presenters/root_presenter.rb' @@ -33,7 +89,16 @@ Style/Documentation: - 'app/models/spline.rb' - 'app/root_endpoint.rb' +# Offense count: 20 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + # Offense count: 1 -Style/DoubleNegation: - Exclude: - - 'app/models/spline.rb' +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings. +# URISchemes: http, https +Layout/LineLength: + Max: 129 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c9a6e8a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -sudo: false - -rvm: - - 2.3.0 - -language: ruby - -cache: bundler diff --git a/Gemfile b/Gemfile index 391393e..30c02b3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,21 +1,24 @@ source 'http://rubygems.org' +gem 'activemodel' +gem 'faraday-rack' gem 'grape' gem 'grape-roar' -gem 'rack-cors' gem 'grape-swagger' -gem 'activemodel' -gem 'kaminari', require: 'kaminari/grape' -gem 'rack-rewrite' +gem 'kaminari-grape' gem 'puma' +gem 'rack-cors' +gem 'rack-rewrite' group :development do gem 'rake' gem 'rubocop' + gem 'rubocop-rake' + gem 'rubocop-rspec' end group :test do - gem 'rspec' - gem 'rack-test' gem 'hyperclient' + gem 'rack-test' + gem 'rspec' end diff --git a/Gemfile.lock b/Gemfile.lock index 5f1214a..de2d1b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,164 +1,181 @@ GEM remote: http://rubygems.org/ specs: - actionpack (4.2.6) - actionview (= 4.2.6) - activesupport (= 4.2.6) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.6) - activesupport (= 4.2.6) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activemodel (4.2.6) - activesupport (= 4.2.6) - builder (~> 3.1) - activesupport (4.2.6) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - ast (2.2.0) - axiom-types (0.1.1) - descendants_tracker (~> 0.0.4) - ice_nine (~> 0.11.0) - thread_safe (~> 0.3, >= 0.3.1) - builder (3.2.2) - coercible (1.0.0) - descendants_tracker (~> 0.0.1) - descendants_tracker (0.0.4) - thread_safe (~> 0.3, >= 0.3.1) - diff-lcs (1.2.5) - equalizer (0.0.11) - erubis (2.7.0) - faraday (0.9.2) - multipart-post (>= 1.2, < 3) - faraday-digestauth (0.2.1) - faraday (~> 0.7) - net-http-digest_auth (~> 1.4) - faraday_hal_middleware (0.0.1) - faraday_middleware (>= 0.9, < 0.10) - faraday_middleware (0.9.2) - faraday (>= 0.7.4, < 0.10) - futuroscope (0.1.11) - grape (0.15.0) - activesupport - builder - hashie (>= 2.1.0) - multi_json (>= 1.3.2) - multi_xml (>= 0.5.2) - rack (>= 1.3.0) - rack-accept - rack-mount - virtus (>= 1.0.0) - grape-entity (0.4.8) - activesupport - multi_json (>= 1.3.2) - grape-roar (0.3.0) + activemodel (8.0.2.1) + activesupport (= 8.0.2.1) + activesupport (8.0.2.1) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ast (2.4.3) + base64 (0.3.0) + benchmark (0.4.1) + bigdecimal (3.2.3) + concurrent-ruby (1.3.5) + connection_pool (2.5.4) + declarative (0.0.20) + diff-lcs (1.6.2) + drb (2.2.3) + dry-core (1.1.0) + concurrent-ruby (~> 1.0) + logger + zeitwerk (~> 2.6) + dry-inflector (1.2.0) + dry-logic (1.6.0) + bigdecimal + concurrent-ruby (~> 1.0) + dry-core (~> 1.1) + zeitwerk (~> 2.6) + dry-types (1.8.3) + bigdecimal (~> 3.0) + concurrent-ruby (~> 1.0) + dry-core (~> 1.0) + dry-inflector (~> 1.0) + dry-logic (~> 1.4) + zeitwerk (~> 2.6) + faraday (2.13.4) + faraday-net_http (>= 2.0, < 3.5) + json + logger + faraday-follow_redirects (0.3.0) + faraday (>= 1, < 3) + faraday-net_http (3.4.1) + net-http (>= 0.5.0) + faraday-rack (2.1.3) + faraday (~> 2.0) + faraday_hal_middleware (0.2.0) + faraday (~> 2.0) + grape (2.4.0) + activesupport (>= 6.1) + dry-types (>= 1.1) + mustermann-grape (~> 1.1.0) + rack (>= 2) + zeitwerk + grape-roar (0.4.1) grape - roar (>= 1.0) - grape-swagger (0.10.4) - grape (>= 0.8.0) - grape-entity (< 0.5.0) - hashie (3.4.3) - hyperclient (0.8.1) - faraday - faraday-digestauth - faraday_hal_middleware - faraday_middleware - futuroscope - net-http-digest_auth - uri_template - i18n (0.7.0) - ice_nine (0.11.2) - json (1.8.3) - kaminari (0.16.3) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) - loofah (2.0.3) - nokogiri (>= 1.5.9) - mini_portile2 (2.0.0) - minitest (5.8.4) - multi_json (1.11.2) - multi_xml (0.5.5) - multipart-post (2.0.0) - net-http-digest_auth (1.4) - nokogiri (1.6.7.2) - mini_portile2 (~> 2.0.0.rc2) - parser (2.3.0.6) - ast (~> 2.2) - powerpack (0.1.1) - puma (3.1.0) - rack (1.6.4) - rack-accept (0.4.5) - rack (>= 0.4) - rack-cors (0.4.0) - rack-mount (0.8.3) - rack (>= 1.0.0) + multi_json + roar (~> 1.1.0) + grape-swagger (2.1.2) + grape (>= 1.7, < 3.0) + rack-test (~> 2) + hyperclient (2.0.0) + addressable + faraday (>= 2) + faraday-follow_redirects + faraday_hal_middleware (>= 0.2) + i18n (1.14.7) + concurrent-ruby (~> 1.0) + json (2.13.2) + kaminari-core (1.2.2) + kaminari-grape (1.0.1) + grape + kaminari-core (~> 1.0) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + logger (1.7.0) + minitest (5.25.5) + multi_json (1.17.0) + mustermann (3.0.4) + ruby2_keywords (~> 0.0.1) + mustermann-grape (1.1.0) + mustermann (>= 1.0.0) + net-http (0.6.0) + uri + nio4r (2.7.4) + parallel (1.27.0) + parser (3.3.9.0) + ast (~> 2.4.1) + racc + prism (1.4.0) + public_suffix (6.0.2) + puma (7.0.2) + nio4r (~> 2.0) + racc (1.8.1) + rack (3.2.1) + rack-cors (3.0.0) + logger + rack (>= 3.0.14) rack-rewrite (1.5.1) - rack-test (0.6.3) - rack (>= 1.0) - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - rainbow (2.1.0) - rake (11.1.1) - representable (2.3.0) - uber (~> 0.0.7) - roar (1.0.4) - representable (>= 2.0.1, < 2.4.0) - rspec (3.4.0) - rspec-core (~> 3.4.0) - rspec-expectations (~> 3.4.0) - rspec-mocks (~> 3.4.0) - rspec-core (3.4.4) - rspec-support (~> 3.4.0) - rspec-expectations (3.4.0) + rack-test (2.2.0) + rack (>= 1.3) + rainbow (3.1.1) + rake (13.3.0) + regexp_parser (2.11.2) + representable (3.2.0) + declarative (< 0.1.0) + trailblazer-option (>= 0.1.1, < 0.2.0) + uber (< 0.2.0) + roar (1.1.1) + representable (~> 3.0) + rspec (3.13.1) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.5) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.4.0) - rspec-mocks (3.4.1) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.5) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.4.0) - rspec-support (3.4.1) - rubocop (0.38.0) - parser (>= 2.3.0.6, < 3.0) - powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.5) + rubocop (1.80.2) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.7.5) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - uber (0.0.15) - unicode-display_width (1.0.2) - uri_template (0.7.0) - virtus (1.0.5) - axiom-types (~> 0.1) - coercible (~> 1.0) - descendants_tracker (~> 0.0, >= 0.0.3) - equalizer (~> 0.0, >= 0.0.9) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.46.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-rake (0.7.1) + lint_roller (~> 1.1) + rubocop (>= 1.72.1) + rubocop-rspec (3.7.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + securerandom (0.4.1) + trailblazer-option (0.1.2) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uber (0.1.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.1.0) + uri (1.0.3) + zeitwerk (2.7.3) PLATFORMS + arm64-darwin-24 ruby DEPENDENCIES activemodel + faraday-rack grape grape-roar grape-swagger hyperclient - kaminari + kaminari-grape puma rack-cors rack-rewrite @@ -166,6 +183,8 @@ DEPENDENCIES rake rspec rubocop + rubocop-rake + rubocop-rspec BUNDLED WITH - 1.10.6 + 2.6.9 diff --git a/README.md b/README.md index 28e91cd..8671da7 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,10 @@ Grape API with Roar =================== -[![Build Status](https://travis-ci.org/ruby-grape/grape-with-roar.svg?branch=master)](https://travis-ci.org/ruby-grape/grape-with-roar) -[![Dependency Status](https://gemnasium.com/ruby-grape/grape-with-roar.svg)](https://gemnasium.com/ruby-grape/grape-with-roar) -[![Code Climate](https://codeclimate.com/github/ruby-grape/grape-with-roar.svg)](https://codeclimate.com/github/ruby-grape/grape-with-roar) +[![test](https://github.com/ruby-grape/grape-with-roar/actions/workflows/test.yml/badge.svg)](https://github.com/ruby-grape/grape-with-roar/actions/workflows/test.yml) A [Grape](http://github.com/ruby-grape/grape) API that uses [Roar](https://github.com/apotonick/roar). -See ---- - -Try me [here](http://grape-with-roar.herokuapp.com/). In Chrome, best viewed with the [JSONView Plugin](https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc?hl=en). - Run --- @@ -24,10 +17,10 @@ $ rackup [2013-06-20 08:57:58] INFO WEBrick::HTTPServer#start: pid=247 port=9292 ``` -### Hello World - Navigate to [localhost:9292/api](http://localhost:9292/api) with a browser. This is a hypermedia API, so all links are clickable. +In Chrome, best viewed with the [JSONView Plugin](https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc?hl=en). + Hyperclient ----------- @@ -51,6 +44,6 @@ Check out the [with-mongoid branch](https://github.com/ruby-grape/grape-with-roa Copyright and License --------------------- -Copyright (c) 2014-2016 Daniel Doubrovkine +Copyright (c) 2014-2025 Daniel Doubrovkine MIT License, see [LICENSE](LICENSE) for details. diff --git a/Rakefile b/Rakefile index 8beb9eb..fcea863 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ require 'rake' task :environment do ENV['RACK_ENV'] ||= 'development' - require File.expand_path('../config/environment', __FILE__) + require File.expand_path('config/environment', __dir__) end unless ENV['RACK_ENV'] == 'production' @@ -21,5 +21,5 @@ unless ENV['RACK_ENV'] == 'production' require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) - task default: [:rubocop, :spec] + task default: %i[rubocop spec] end diff --git a/app/acme_app.rb b/app/acme_app.rb index 53a4bc5..9e30e71 100644 --- a/app/acme_app.rb +++ b/app/acme_app.rb @@ -4,7 +4,7 @@ def initialize @filenames = ['', '.html', 'index.html', '/index.html'] @rack_static = ::Rack::Static.new( -> { [404, {}, []] }, - root: File.expand_path('../../public', __FILE__), + root: File.expand_path('../public', __dir__), urls: ['/'] ) end @@ -20,7 +20,7 @@ def self.instance # rewrite HAL links to make them clickable in a browser use Rack::Rewrite do - r302 %r{^([\/\w]*)(%7B|\{)?(.*)(%7D|\})$}, '$1' + r302 %r{^([/\w]*)(%7B|\{)?(.*)(%7D|\})$}, '$1' end run Acme::App.new diff --git a/app/models/spline.rb b/app/models/spline.rb index b2caaeb..367a09e 100644 --- a/app/models/spline.rb +++ b/app/models/spline.rb @@ -3,11 +3,10 @@ module Models class Spline include ActiveModel::Model - attr_accessor :uuid - attr_accessor :reticulated + attr_accessor :uuid, :reticulated def initialize(attrs = { reticulated: [true, false].sample }) - super(attrs) + super @uuid ||= SecureRandom.uuid @reticulated = !!attrs[:reticulated] end @@ -20,11 +19,9 @@ def self.find(uuid) Acme::Models::Spline.new(uuid: uuid) end - def save! - end + def save!; end - def destroy - end + def destroy; end end end end diff --git a/config.ru b/config.ru index c8af3f1..7a0d5d7 100644 --- a/config.ru +++ b/config.ru @@ -1,2 +1,2 @@ -require File.expand_path('../config/environment', __FILE__) +require File.expand_path('config/environment', __dir__) run Acme::App.instance diff --git a/config/application.rb b/config/application.rb index dc56863..f6f2fac 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,7 +4,7 @@ require 'boot' -Bundler.require :default, ENV['RACK_ENV'] +Bundler.require :default, ENV.fetch('RACK_ENV', nil) require 'roar/representer' require 'roar/json' diff --git a/config/environment.rb b/config/environment.rb index e1b44f6..c26ecf1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,3 @@ ENV['RACK_ENV'] ||= 'test' -require File.expand_path('../application', __FILE__) +require File.expand_path('application', __dir__) diff --git a/spec/api/cors_spec.rb b/spec/api/cors_spec.rb index 925830c..f5ec2fe 100644 --- a/spec/api/cors_spec.rb +++ b/spec/api/cors_spec.rb @@ -8,25 +8,34 @@ def app end context 'CORS' do + it 'without options' do + options '/' + expect(last_response.status).to eq 200 + expect(last_response.headers['Access-Control-Allow-Origin']).to be_nil + expect(last_response.headers['Access-Control-Expose-Headers']).to be_nil + end + it 'supports options' do options '/', {}, - 'HTTP_ORIGIN' => 'http://cors.example.com', + 'HTTP_ORIGIN' => 'https://cors.example.com', 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'Origin, Accept, Content-Type', 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'GET' expect(last_response.status).to eq 200 - expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://cors.example.com' + expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*' expect(last_response.headers['Access-Control-Expose-Headers']).to eq '' end + it 'includes Access-Control-Allow-Origin in the response' do - get '/api', {}, 'HTTP_ORIGIN' => 'http://cors.example.com' + get '/api', {}, 'HTTP_ORIGIN' => 'https://cors.example.com' expect(last_response.status).to eq 200 - expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://cors.example.com' + expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*' end + it 'includes Access-Control-Allow-Origin in errors' do - get '/invalid', {}, 'HTTP_ORIGIN' => 'http://cors.example.com' + get '/invalid', {}, 'HTTP_ORIGIN' => 'https://cors.example.com' expect(last_response.status).to eq 404 - expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://cors.example.com' + expect(last_response.headers['Access-Control-Allow-Origin']).to eq '*' end end end diff --git a/spec/api/root_endpoint_spec.rb b/spec/api/root_endpoint_spec.rb index 4c2e8fc..3b98cfd 100644 --- a/spec/api/root_endpoint_spec.rb +++ b/spec/api/root_endpoint_spec.rb @@ -11,8 +11,9 @@ def app get '/api' expect(last_response.status).to eq 200 links = JSON.parse(last_response.body)['_links'] - expect(links.keys.sort).to eq(%w(self spline splines swagger_doc)) + expect(links.keys.sort).to eq(%w[self spline splines swagger_doc]) end + it 'follows all links' do get '/api' expect(last_response.status).to eq 200 @@ -20,16 +21,19 @@ def app links.each_pair do |_key, h| href = h['href'] next if href.include?('{') # templated link + get href.gsub('http://example.org', '') expect(last_response.status).to eq 200 - expect(JSON.parse(last_response.body)).to_not eq({}) + expect(JSON.parse(last_response.body)).not_to eq({}) end end + it 'rewrites encoded HAL links to make them clickable' do get '/api/splines/%7B?cursor,size%7D' expect(last_response.status).to eq 302 expect(last_response.headers['Location']).to eq '/api/splines/' end + it 'rewrites encoded HAL links without a trailing slash to make them clickable' do get '/api/splines%7B?cursor,size%7D' expect(last_response.status).to eq 302 diff --git a/spec/api/splines_endpoint_spec.rb b/spec/api/splines_endpoint_spec.rb index 9daacf6..db58fbe 100644 --- a/spec/api/splines_endpoint_spec.rb +++ b/spec/api/splines_endpoint_spec.rb @@ -45,7 +45,7 @@ def app post '/api/splines', spline: { reticulated: false } expect(last_response.status).to eq 201 json = JSON.parse(last_response.body) - expect(json['uuid']).to_not be_blank + expect(json['uuid']).not_to be_blank end it 'updates a spline' do @@ -71,7 +71,8 @@ def app json = JSON.parse(last_response.body) expect(json['uuid']).to eq '123' expect(json['_links']['self']['href']).to eq 'http://example.org/api/splines/123' - expect(json['_links']['curies']).to eq([{ 'name' => 'images', 'href' => 'http://example.org/docs/splines/images/{rel}', 'templated' => true }]) + expect(json['_links']['curies']).to eq([{ 'name' => 'images', + 'href' => 'http://example.org/docs/splines/images/{rel}', 'templated' => true }]) expect(json['_links']['images:thumbnail']['href']).to eq 'http://example.org/api/splines/123/images/thumbnail.jpg' end end diff --git a/spec/api/splines_endpoint_with_hyperclient_spec.rb b/spec/api/splines_endpoint_with_hyperclient_spec.rb index 4479c9a..19433be 100644 --- a/spec/api/splines_endpoint_with_hyperclient_spec.rb +++ b/spec/api/splines_endpoint_with_hyperclient_spec.rb @@ -11,18 +11,14 @@ def app client.connection(default: false) do |conn| conn.request :json conn.response :json - conn.use Faraday::Adapter::Rack, app + conn.adapter Faraday::Adapter::Rack, app end end end context 'splines' do - it 'returns 3 splines by default' do - expect(client.splines({}).count).to eq 3 - end - - it 'returns 2 splines' do - expect(client.splines(size: 2).count).to eq 2 + it 'returns all splines' do + expect(client.splines({}).count).to eq 42 end it 'returns pagination' do @@ -34,14 +30,14 @@ def app it 'returns all unique uuids' do splines = client.splines({}) - expect(splines.map(&:uuid).uniq.count).to eq 3 + expect(splines.map(&:uuid).uniq.count).to eq 42 end end context 'spline' do it 'creates a spline' do spline = client.splines._post(spline: { reticulated: true }) - expect(spline.uuid).to_not be_blank + expect(spline.uuid).not_to be_blank expect(spline.reticulated).to be true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ea8e087..2449102 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ require 'rack/test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) RSpec.configure do |config| config.mock_with :rspec