From c7e9675565645815a38e18785fed2439619037a8 Mon Sep 17 00:00:00 2001 From: dB Date: Sat, 15 Aug 2015 16:22:17 -0400 Subject: [PATCH] Tests for current behavior, related to #84. --- .rubocop_todo.yml | 6 +++--- test/hyperclient/link_test.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dd9a10a..a928c0e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-08-15 16:01:39 -0400 using RuboCop version 0.33.0. +# on 2015-08-15 17:01:12 -0400 using RuboCop version 0.33.0. # 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 @@ -11,7 +11,7 @@ Metrics/ClassLength: Max: 103 -# Offense count: 80 +# Offense count: 85 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 142 @@ -24,7 +24,7 @@ Metrics/MethodLength: # Offense count: 3 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 238 + Max: 258 # Offense count: 1 Style/AsciiComments: diff --git a/test/hyperclient/link_test.rb b/test/hyperclient/link_test.rb index e8c3a17..77e7d92 100644 --- a/test/hyperclient/link_test.rb +++ b/test/hyperclient/link_test.rb @@ -75,6 +75,21 @@ module Hyperclient 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 end @@ -91,6 +106,18 @@ module Hyperclient link._url.must_equal '/orders?id=1' end + it 'does not expand an uri template with unknown variables' do + link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1) + + link._url.must_equal '/orders' + end + + it 'only expands known variables in a uri template' do + link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1, id: 2) + + link._url.must_equal '/orders?id=2' + end + it 'returns the link when no uri template' do link = Link.new('key', { 'href' => '/orders' }, entry_point) link._url.must_equal '/orders'