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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixes

- Restore literal false in parameter expansion (#68)

### Breaks

## 2.0.1 - (2025-02-16)
Expand Down
8 changes: 6 additions & 2 deletions lib/restify/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ def convert_param(value, nesting: true)

def extract!(params)
@template.variables.each_with_object({}) do |var, hash|
if (value = params.delete(var) { params.delete(var.to_sym) { nil } })
hash[var] = value
sym = var.to_sym
if params.key?(var)
hash[var] = params.delete(var)
end
if params.key?(sym)
hash[sym] = params.delete(sym)
end
end
end
Expand Down
55 changes: 54 additions & 1 deletion spec/restify/relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def to_param
context 'with false' do
let(:params) { {id: false} }

it { expect(expanded.to_s).to eq 'http://test.host/resource/' }
it { expect(expanded.to_s).to eq 'http://test.host/resource/false' }
end

context 'with true' do
Expand All @@ -59,6 +59,27 @@ def to_param
it { expect(expanded.to_s).to eq 'http://test.host/resource/1,2' }
end

context 'with nil query parameter' do
let(:pattern) { '/resource{?abc}' }
let(:params) { {abc: nil} }

it { expect(expanded.to_s).to eq 'http://test.host/resource' }
end

context 'with false query parameter' do
let(:pattern) { '/resource{?abc}' }
let(:params) { {abc: false} }

it { expect(expanded.to_s).to eq 'http://test.host/resource?abc=false' }
end

context 'with true query parameter' do
let(:pattern) { '/resource{?abc}' }
let(:params) { {abc: true} }

it { expect(expanded.to_s).to eq 'http://test.host/resource?abc=true' }
end

context 'with unknown additional query parameter' do
let(:pattern) { '/resource{?a,b}' }
let(:params) { {a: 1, b: 2, c: 3} }
Expand Down Expand Up @@ -119,6 +140,38 @@ def to_param

it { expect { expanded }.to raise_exception TypeError, /Can't convert Hash into String./ }
end

context 'with string-keyed params' do
context 'with value' do
let(:params) { {'id' => 1} }

it { expect(expanded.to_s).to eq 'http://test.host/resource/1' }
end
end

context 'with mixed-keyed params' do
context 'non-overlapping' do
let(:params) { {'id' => 1, q: 2} }

it { expect(expanded.to_s).to eq 'http://test.host/resource/1?q=2' }
end

context 'overlapping (1)' do
let(:params) { {'id' => 1, id: 2} }

it 'prefers symbol value' do
expect(expanded.to_s).to eq 'http://test.host/resource/2'
end
end

context 'overlapping (2)' do
let(:params) { {id: 2, 'id' => 1} }

it 'prefers symbol value' do
expect(expanded.to_s).to eq 'http://test.host/resource/2'
end
end
end
end

shared_examples 'non-data-request' do |method|
Expand Down