-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement nested with
support in parameter DSL
#2434
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,17 @@ def validates_reader | |
@validates | ||
end | ||
|
||
def new_scope(args, _, &block) | ||
nested_scope = self.class.new | ||
nested_scope.new_group_scope(args, &block) | ||
nested_scope | ||
end | ||
Comment on lines
+38
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this, but looks legit for me. |
||
|
||
def new_group_scope(args) | ||
prev_group = @group | ||
@group = args.clone.first | ||
yield | ||
@group = prev_group | ||
Comment on lines
+45
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we do not really create scopes, this is my imitation of it. |
||
end | ||
|
||
def extract_message_option(attrs) | ||
|
@@ -169,6 +177,45 @@ def extract_message_option(attrs) | |
] | ||
) | ||
end | ||
|
||
it "supports nested 'with' calls" do | ||
subject.with(type: Integer, documentation: { in: 'body' }) do | ||
subject.optional :pipboy_id | ||
subject.with(documentation: { default: 33 }) do | ||
subject.optional :vault | ||
subject.with(type: String) do | ||
subject.with(documentation: { default: 'resident' }) do | ||
subject.optional :role | ||
end | ||
end | ||
subject.optional :age, documentation: { default: 42 } | ||
end | ||
end | ||
|
||
expect(subject.validate_attributes_reader).to eq( | ||
[ | ||
[:pipboy_id], { type: Integer, documentation: { in: 'body' } }, | ||
[:vault], { type: Integer, documentation: { in: 'body', default: 33 } }, | ||
[:role], { type: String, documentation: { in: 'body', default: 'resident' } }, | ||
[:age], { type: Integer, documentation: { in: 'body', default: 42 } } | ||
] | ||
) | ||
end | ||
|
||
it "supports Hash parameter inside the 'with' calls" do | ||
subject.with(documentation: { in: 'body' }) do | ||
subject.optional :info, type: Hash, documentation: { x: { nullable: true }, desc: 'The info' } do | ||
subject.optional :vault, type: Integer, documentation: { default: 33, desc: 'The vault number' } | ||
end | ||
end | ||
|
||
expect(subject.validate_attributes_reader).to eq( | ||
[ | ||
[:info], { type: Hash, documentation: { in: 'body', desc: 'The info', x: { nullable: true } } }, | ||
[:vault], { type: Integer, documentation: { in: 'body', default: 33, desc: 'The vault number' } } | ||
] | ||
) | ||
end | ||
end | ||
|
||
describe '#mutually_exclusive' do | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock I've added more specs and found that in case of mix of nested scopes and groups,
with
doesn't work as expected (if there is anything expected). The reason is that when a new parameter with a block is defined , a new scope is created without any link to the current group.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open an issue with a failed spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether it is an issue or an undocumented feature is always hard to tell in such mature projects :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I follow the rule of thumb of 1) is there a spec (undocumented feature), 2) is it in README (documented feature).