-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds #path class method on :composable contracts [#593]
- Loading branch information
Showing
2 changed files
with
97 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ class Test::ComposedContract < Dry::Validation::Contract | |
describe '#call(input)' do | ||
subject(:result) { contract.call(input) } | ||
|
||
let(:input) { { email: 'moss@reynholm.com', | ||
let(:input) { { email: 'moss#reynholm.com', | ||
name: 'Moss', | ||
phone: '01189998819991197253' } } | ||
|
||
|
@@ -91,13 +91,14 @@ class Test::ComposedContract < Dry::Validation::Contract | |
end | ||
|
||
it 'has appropriate values' do | ||
expect(result.to_h).to eq(email: 'moss@reynholm.com', | ||
expect(result.to_h).to eq(email: 'moss#reynholm.com', | ||
name: 'Moss', | ||
phone: '01189998819991197253') | ||
end | ||
|
||
it 'has appropriate errors' do | ||
expect(result.errors.to_h).to eq(phone: ['is emergency services']) | ||
expect(result.errors.to_h).to eq(email: ['is in invalid format'], | ||
phone: ['is emergency services']) | ||
end | ||
end | ||
end | ||
|
@@ -113,8 +114,14 @@ class Test::PersonContract < Dry::Validation::Contract | |
let(:contract_class) do | ||
class Test::ComposedContract < Dry::Validation::Contract | ||
contract Test::PersonContract | ||
contract Test::PersonContract, path: 'emergency' | ||
contract Test::PersonContract, path: 'emergency.backup' | ||
|
||
path :emergency do | ||
contract Test::PersonContract | ||
|
||
path :backup do | ||
contract Test::PersonContract | ||
end | ||
end | ||
end | ||
|
||
Test::ComposedContract | ||
|
@@ -131,19 +138,17 @@ class Test::ComposedContract < Dry::Validation::Contract | |
|
||
let(:input) { { email: 'foo', | ||
name: '', | ||
other: 'bad', | ||
shmemergency: { more_noise: 'XXXXXX' }, | ||
shmemergency: { noise: 'XXXXXX' }, | ||
emergency: { name: 'smudger', | ||
whoops: 'why is this here?', | ||
backup: { email: '[email protected]', | ||
name: '', | ||
noise: 'ZZZZ' } } } } | ||
name: '' } } } } | ||
|
||
it 'returns a result' do | ||
expect(subject).to be_failure | ||
end | ||
|
||
it 'has the schemafied values at the specified paths' do | ||
it 'has appropriate values at the specified paths' do | ||
expect(result.to_h).to eq(email: 'foo', | ||
name: '', | ||
emergency: { name: 'smudger', | ||
|