Skip to content
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

Fixed duplicating endpoints #988

Merged
merged 1 commit into from
Apr 17, 2015
Merged

Fixed duplicating endpoints #988

merged 1 commit into from
Apr 17, 2015

Conversation

u2
Copy link
Contributor

@u2 u2 commented Apr 16, 2015

.to change{ subject.endpoints.count }.from(0).to(1)
end

it 'uniq the duplicating endpoint' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to put these two tests together, just add a new test at the same level that says 'does not duplicate identical endpoints'.

@dblock
Copy link
Member

dblock commented Apr 16, 2015

I understand the case of a reloader, but is this generally correct? What happens when you re-define an endpoint with all the same arguments, you probably would want the second one, not the first one, to be defined or to see a warning/error?

Maybe a better approach could be to freeze endpoints or something like that? Not sure if it can be accomplished.

Definitely needs a CHANGELOG, thanks.

@@ -120,7 +120,8 @@ def route(methods, paths = ['/'], route_options = {}, &block)
}).deep_merge(route_setting(:description) || {}).deep_merge(route_options || {})
}

endpoints << Grape::Endpoint.new(inheritable_setting, endpoint_options, &block)
new_endpoint = Grape::Endpoint.new(inheritable_setting, endpoint_options, &block)
endpoints << new_endpoint unless endpoints.any?{ |o| o.options == new_endpoint.options && o.inheritable_setting.to_hash == new_endpoint.inheritable_setting.to_hash }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would want the comparison logic to live in Endpoint, so a comparison operator on Grape::Endpoint so we could maybe write endpoints.include?(...) or endpoints.any? { |e| endpoint.equals?(e) } # or ==.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, The the comparison of Endpoint is meaningful.

@u2
Copy link
Contributor Author

u2 commented Apr 17, 2015

Yes.I can't agree more.Before, I did not think so much about that.

@dblock
Copy link
Member

dblock commented Apr 17, 2015

Merging.

dblock added a commit that referenced this pull request Apr 17, 2015
@dblock dblock merged commit 8ee8be7 into ruby-grape:master Apr 17, 2015
@u2 u2 deleted the duplicating_endpoints branch April 17, 2015 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants