-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23374d6
commit 18ed28c
Showing
8 changed files
with
124 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Grape::Validations::Types::ArrayCoercer do | ||
subject { described_class.new(type) } | ||
|
||
describe '#call' do | ||
context 'an array of primitives' do | ||
let(:type) { Array[String] } | ||
|
||
it 'coerces elements in the array' do | ||
expect(subject.call([10, 20])).to eq(%w[10 20]) | ||
end | ||
end | ||
|
||
context 'an array of arrays' do | ||
let(:type) { Array[Array[Integer]] } | ||
|
||
it 'coerces elements in the nested array' do | ||
expect(subject.call([%w[10 20]])).to eq([[10, 20]]) | ||
expect(subject.call([['10'], ['20']])).to eq([[10], [20]]) | ||
end | ||
end | ||
|
||
context 'an array of sets' do | ||
let(:type) { Array[Set[Integer]] } | ||
|
||
it 'coerces elements in the nested set' do | ||
expect(subject.call([%w[10 20]])).to eq([Set[10, 20]]) | ||
expect(subject.call([['10'], ['20']])).to eq([Set[10], Set[20]]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Grape::Validations::Types::SetCoercer do | ||
subject { described_class.new(type) } | ||
|
||
describe '#call' do | ||
context 'a set of primitives' do | ||
let(:type) { Set[String] } | ||
|
||
it 'coerces elements to the set' do | ||
expect(subject.call([10, 20])).to eq(Set['10', '20']) | ||
end | ||
end | ||
|
||
context 'a set of sets' do | ||
let(:type) { Set[Set[Integer]] } | ||
|
||
it 'coerces elements in the nested set' do | ||
expect(subject.call([%w[10 20]])).to eq(Set[Set[10, 20]]) | ||
expect(subject.call([['10'], ['20']])).to eq(Set[Set[10], Set[20]]) | ||
end | ||
end | ||
|
||
context 'a set of sets of arrays' do | ||
let(:type) { Set[Set[Array[Integer]]] } | ||
|
||
it 'coerces elements in the nested set' do | ||
expect(subject.call([[['10'], ['20']]])).to eq(Set[Set[Array[10], Array[20]]]) | ||
end | ||
end | ||
end | ||
end |