Skip to content

Commit fc1f3e6

Browse files
committed
Merge pull request #93 from dblock/tests-for-templated-parameters
Tests for current behavior, related to #84.
2 parents 4298f9f + c7e9675 commit fc1f3e6

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

.rubocop_todo.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2015-08-15 16:01:39 -0400 using RuboCop version 0.33.0.
3+
# on 2015-08-15 17:01:12 -0400 using RuboCop version 0.33.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -11,7 +11,7 @@
1111
Metrics/ClassLength:
1212
Max: 103
1313

14-
# Offense count: 80
14+
# Offense count: 85
1515
# Configuration parameters: AllowURI, URISchemes.
1616
Metrics/LineLength:
1717
Max: 142
@@ -24,7 +24,7 @@ Metrics/MethodLength:
2424
# Offense count: 3
2525
# Configuration parameters: CountComments.
2626
Metrics/ModuleLength:
27-
Max: 238
27+
Max: 258
2828

2929
# Offense count: 1
3030
Style/AsciiComments:

test/hyperclient/link_test.rb

+27
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ module Hyperclient
7575
link._expand._url.must_equal '/orders'
7676
link._url.must_equal '/orders'
7777
end
78+
79+
it 'does not expand unknown variables' do
80+
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
81+
link._expand(unknown: '1')._url.must_equal '/orders'
82+
end
83+
84+
it 'only expands known variables' do
85+
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
86+
link._expand(unknown: '1', id: '2')._url.must_equal '/orders?id=2'
87+
end
88+
89+
it 'only expands templated links' do
90+
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => false }, entry_point)
91+
link._expand(id: '1')._url.must_equal '/orders{?id}'
92+
end
7893
end
7994
end
8095

@@ -91,6 +106,18 @@ module Hyperclient
91106
link._url.must_equal '/orders?id=1'
92107
end
93108

109+
it 'does not expand an uri template with unknown variables' do
110+
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1)
111+
112+
link._url.must_equal '/orders'
113+
end
114+
115+
it 'only expands known variables in a uri template' do
116+
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1, id: 2)
117+
118+
link._url.must_equal '/orders?id=2'
119+
end
120+
94121
it 'returns the link when no uri template' do
95122
link = Link.new('key', { 'href' => '/orders' }, entry_point)
96123
link._url.must_equal '/orders'

0 commit comments

Comments
 (0)