Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Ruby (2.7)
uses: ruby/setup-ruby@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.4
bundler-cache: true
- name: Build and test with RSpec
run: |
bundle exec rake test
- name: Coveralls
uses: coverallsapp/github-action@master
- run: |
bundle exec rake test spinach
- uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on:
types: [opened, reopened, edited, synchronize]
jobs:
danger:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.4
bundler-cache: true
- name: Run Danger
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
fail-fast: false
matrix:
entry:
- { ruby: '3.4' }
- { ruby: '3.2' }
- { ruby: '2.7' }
- { ruby: 'ruby-head', allowed-failure: true }
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inherit_from: .rubocop_todo.yml

require:
plugins:
- rubocop-rake
- rubocop-minitest

Expand Down
12 changes: 7 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-05-12 16:41:11 UTC using RuboCop version 1.63.5.
# on 2025-09-10 13:55:47 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
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
# Configuration parameters: Severity.
Gemspec/RequiredRubyVersion:
Exclude:
- 'hyperclient.gemspec'
Expand All @@ -30,16 +29,19 @@ Lint/MissingSuper:

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
# Configuration parameters: AllowedMethods, InferNonNilReceiver, AdditionalNilMethods.
# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
# AdditionalNilMethods: present?, blank?, try, try!
Lint/RedundantSafeNavigation:
Exclude:
- 'lib/hyperclient/link.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules.
# SupportedStyles: nested, compact
# SupportedStylesForClasses: ~, nested, compact
# SupportedStylesForModules: ~, nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'features/steps/api_navigation.rb'
Expand Down
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

### 2.0.1 (Next)

* [#298](https://github.com/codegram/hyperclient/pull/298): Upgraded rubocop to 1.63.5 - [@dblock](https://github.com/dblock).
* [#298](https://github.com/codegram/hyperclient/pull/300): Upgraded RuboCop to 1.80.2 - [@dblock](https://github.com/dblock).
* [#298](https://github.com/codegram/hyperclient/pull/298): Upgraded RuboCop to 1.63.5 - [@dblock](https://github.com/dblock).
* Your contribution here.

### 2.0.0 (2024/02/01)

* [#268](https://github.com/codegram/hyperclient/pull/268): Replace Travis-CI with GHA - [@dblock](https://github.com/dblock).
* [#269](https://github.com/codegram/hyperclient/pull/269): Re-add code coverage - [@dblock](https://github.com/dblock).
* [#270](https://github.com/codegram/hyperclient/pull/270): Upgrade Rubocop to 1.45 - [@dblock](https://github.com/dblock).
* [#270](https://github.com/codegram/hyperclient/pull/270): Upgrade RuboCop to 1.45 - [@dblock](https://github.com/dblock).
* [#271](https://github.com/codegram/hyperclient/pull/271): Test against Ruby 3.2 - [@dblock](https://github.com/dblock).
* [#285](https://github.com/codegram/hyperclient/pull/285): Support Faraday 2.x - [@dblock](https://github.com/dblock).

Expand Down Expand Up @@ -44,14 +45,14 @@
### 0.9.0 (2018/01/10)

* [#133](https://github.com/codegram/hyperclient/pull/133): Removed futuroscope - [@dblock](https://github.com/dblock).
* [#131](https://github.com/codegram/hyperclient/pull/131): Upgrade to Rubocop 0.50.0, fix Bundler's insecure git source warning - [@nebolsin](https://github.com/nebolsin).
* [#131](https://github.com/codegram/hyperclient/pull/131): Upgrade to RuboCop 0.50.0, fix Bundler's insecure git source warning - [@nebolsin](https://github.com/nebolsin).
* [#132](https://github.com/codegram/hyperclient/pull/132): Swapped yard dependency for danger-toc - [@dblock](https://github.com/dblock).

### 0.8.6 (2017/08/27)

* [#122](https://github.com/codegram/hyperclient/pull/122): Improve error message when server returns invalid data - [@ivoanjo](https://github.com/ivoanjo).
* [#125](https://github.com/codegram/hyperclient/pull/125): Add table of contents to readme and add note asking users to add their projects to the wiki - [@ivoanjo](https://github.com/ivoanjo).
* [#127](https://github.com/codegram/hyperclient/pull/127): Minor fixes: Fix warnings, and pry-byebug to dev Gemfile and tweak rubocop execution - [@ivoanjo](https://github.com/ivoanjo).
* [#127](https://github.com/codegram/hyperclient/pull/127): Minor fixes: Fix warnings, and pry-byebug to dev Gemfile and tweak RuboCop execution - [@ivoanjo](https://github.com/ivoanjo).
* [#128](https://github.com/codegram/hyperclient/pull/128): Fix link delegation returning nil for field with value false - [@ivoanjo](https://github.com/ivoanjo).

### 0.8.5 (2017/07/05)
Expand Down Expand Up @@ -112,7 +113,7 @@
* [#64](https://github.com/codegram/hyperclient/issues/64): Added support for curies - [@dblock](https://github.com/dblock).
* [#58](https://github.com/codegram/hyperclient/issues/58): Automatically follow redirects - [@dblock](https://github.com/dblock).
* [#63](https://github.com/codegram/hyperclient/pull/63): You can omit the navigational elements, `api.links.products` is now equivalent to `api.products` - [@dblock](https://github.com/dblock).
* [#61](https://github.com/codegram/hyperclient/pull/61): Implemented Rubocop, Ruby-style linter - [@dblock](https://github.com/dblock).
* [#61](https://github.com/codegram/hyperclient/pull/61): Implemented RuboCop, Ruby-style linter - [@dblock](https://github.com/dblock).

### 0.4.0 (2014/05/05)

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

group :development, :test do
gem 'rake'
gem 'rubocop', '~> 1.63.5', require: false
gem 'rubocop', '~> 1.80.2', require: false
gem 'rubocop-minitest', require: false
gem 'rubocop-rake', require: false
gem 'simplecov', require: false
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Gem Version](http://img.shields.io/gem/v/hyperclient.svg)](http://badge.fury.io/rb/hyperclient)
[![Build Status](https://github.com/codegram/hyperclient/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/codegram/hyperclient/actions/workflows/test.yml)
[![Code Climate](https://codeclimate.com/github/codegram/hyperclient.svg)](https://codeclimate.com/github/codegram/hyperclient)
[![Coverage Status](https://img.shields.io/coveralls/codegram/hyperclient.svg)](https://coveralls.io/r/codegram/hyperclient?branch=master)

Hyperclient is a Hypermedia API client written in Ruby. It fully supports [JSON HAL](http://stateless.co/hal_specification.html).
Expand Down
3 changes: 2 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

class Spinach::FeatureSteps
include Minitest::Assertions

attr_accessor :assertions

def initialize(*args)
super(*args)
super
self.assertions = 0
end
end
3 changes: 3 additions & 0 deletions test/hyperclient/entry_point_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ module Hyperclient
it 'can update headers after a connection has been constructed' do
_(entry_point.connection).must_be_kind_of Faraday::Connection
entry_point.headers.update('Content-Type' => 'application/foobar')

_(entry_point.headers['Content-Type']).must_equal 'application/foobar'
end

it 'can insert additional middleware after a connection has been constructed' do
_(entry_point.connection).must_be_kind_of Faraday::Connection
entry_point.connection.use Faraday::Request::Instrumentation
handlers = entry_point.connection.builder.handlers

_(handlers).must_include Faraday::Request::Instrumentation
end

Expand Down Expand Up @@ -136,6 +138,7 @@ module Hyperclient

it 'creates a Faraday connection with the default block' do
handlers = entry_point.connection.builder.handlers

_(handlers).wont_include Faraday::Response::RaiseError
_(handlers).wont_include Faraday::FollowRedirects
_(handlers).must_include Faraday::Request::Json
Expand Down
4 changes: 4 additions & 0 deletions test/hyperclient/link_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ module Hyperclient

describe 'plain link' do
let(:plain_link) { links.self }

it 'must be correct' do
_(plain_link._url).must_equal '/productions/1'
end
end

describe 'templated link' do
let(:templated_link) { links.search }

it 'must expand' do
_(templated_link._expand(search: 'gizmos')._url).must_equal '/productions/1?categories=gizmos'
end
Expand All @@ -47,6 +49,7 @@ module Hyperclient
describe 'curied link collection' do
let(:curied_link) { links['image:thumbnail'] }
let(:curie) { links._curies['image'] }

it 'must expand' do
_(curied_link._expand(version: 'small')._url).must_equal '/images/thumbnails/small.jpg'
end
Expand All @@ -71,6 +74,7 @@ module Hyperclient

describe 'null link value' do
let(:null_link) { links.null_link }

it 'must be nil' do
_(null_link).must_be_nil
end
Expand Down
14 changes: 13 additions & 1 deletion test/hyperclient/link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ module Hyperclient
describe prop do
it 'returns the property value' do
link = Link.new('key', { prop => 'value' }, entry_point)

_(link.send("_#{prop}")).must_equal 'value'
end

it 'returns nil if the property is not present' do
link = Link.new('key', {}, entry_point)

_(link.send("_#{prop}")).must_be_nil
end
end
Expand Down Expand Up @@ -53,11 +55,13 @@ module Hyperclient
describe 'required argument' do
it 'builds a Link with the templated URI representation' do
link = Link.new('key', { 'href' => '/orders/{id}', 'templated' => true }, entry_point)

_(link._expand(id: '1')._url).must_equal '/orders/1'
end

it 'expands an uri template without variables' do
link = Link.new('key', { 'href' => '/orders/{id}', 'templated' => true }, entry_point)

_(link._expand._url).must_equal '/orders/'
_(link._url).must_equal '/orders/'
end
Expand All @@ -66,27 +70,32 @@ module Hyperclient
describe 'query string argument' do
it 'builds a Link with the templated URI representation' do
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)

_(link._expand(id: '1')._url).must_equal '/orders?id=1'
end

it 'expands an uri template without variables' do
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)

_(link._expand._url).must_equal '/orders'
_(link._url).must_equal '/orders'
end

it 'does not expand unknown variables' do
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)

_(link._expand(unknown: '1')._url).must_equal '/orders'
end

it 'only expands known variables' do
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)

_(link._expand(unknown: '1', id: '2')._url).must_equal '/orders?id=2'
end

it 'only expands templated links' do
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => false }, entry_point)

_(link._expand(id: '1')._url).must_equal '/orders{?id}'
end
end
Expand Down Expand Up @@ -119,6 +128,7 @@ module Hyperclient

it 'returns the link when no uri template' do
link = Link.new('key', { 'href' => '/orders' }, entry_point)

_(link._url).must_equal '/orders'
end

Expand Down Expand Up @@ -266,7 +276,7 @@ module Hyperclient
link = Link.new('key', { 'href' => '/productions/1' }, 'foo')

_(link.inspect).must_include 'Link'
_(link.inspect).must_include '"href"=>"/productions/1"'
_(link.inspect).must_include({ 'href' => '/productions/1' }.inspect)
end
end

Expand Down Expand Up @@ -341,11 +351,13 @@ module Hyperclient
it 'responds to missing methods' do
resource.expects(:respond_to?).with('orders').returns(false)
resource.expects(:respond_to?).with('embedded').returns(true)

_(link.respond_to?(:embedded)).must_equal true
end

it 'does not delegate to_ary to resource' do
resource.expects(:to_ary).never

_([[link, link]].flatten).must_equal [link, link]
end
end
Expand Down
10 changes: 9 additions & 1 deletion test/hyperclient/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Hyperclient
end

it 'initializes its attributes' do
Attributes.expects(:new).with(foo: :bar)
Attributes.expects(:new).with({ foo: :bar })

Resource.new({ foo: :bar }, entry_point)
end
Expand Down Expand Up @@ -62,6 +62,7 @@ module Hyperclient
it '_expand' do
resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders/{id}', 'templated' => true } } },
entry_point)

_(resource._links.orders._expand(id: 1)._url).must_equal '/orders/1'
_(resource.orders._expand(id: 1)._url).must_equal '/orders/1'
_(resource.orders(id: 1)._url).must_equal '/orders/1'
Expand Down Expand Up @@ -94,28 +95,33 @@ module Hyperclient
describe 'method_missing' do
it 'delegates to attributes' do
resource._attributes.expects(:foo).returns('bar')

_(resource.foo).must_equal 'bar'
end

it 'delegates to links' do
resource._links.expects(:foo).returns('bar')

_(resource.foo).must_equal 'bar'
end

it 'delegates to embedded' do
resource._embedded.expects(:foo).returns('bar')

_(resource.foo).must_equal 'bar'
end

it 'delegates to attributes, links, embedded' do
resource._attributes.expects('respond_to?').with('foo').returns(false)
resource._links.expects('respond_to?').with('foo').returns(false)
resource._embedded.expects('respond_to?').with('foo').returns(false)

_(-> { resource.foo }).must_raise NoMethodError
end

it 'delegates []' do
resource._attributes.expects(:foo).returns('bar')

_(resource['foo']).must_equal 'bar'
end

Expand All @@ -133,6 +139,7 @@ module Hyperclient
describe 'with a default value' do
it 'returns the value for keys that exist' do
resource._attributes.expects(:foo).returns('bar')

_(resource.fetch('foo', 'default value')).must_equal 'bar'
end

Expand All @@ -144,6 +151,7 @@ module Hyperclient
describe 'with a block' do
it 'returns the value for keys that exist' do
resource._attributes.expects(:foo).returns('bar')

_(resource.fetch('foo') { 'default value' }).must_equal 'bar'
end

Expand Down
1 change: 1 addition & 0 deletions test/hyperclient_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

it 'creates a Faraday connection with the default block plus any additional handlers' do
handlers = client.connection.builder.handlers

_(handlers).must_include Faraday::Request::Instrumentation
_(handlers).must_include Faraday::Response::RaiseError
_(handlers).must_include Faraday::FollowRedirects::Middleware
Expand Down