From 10ed0b8217856474e343e7e470cc84fd6cd357c1 Mon Sep 17 00:00:00 2001 From: peter scholz Date: Thu, 13 Oct 2016 00:07:45 +0200 Subject: [PATCH] additions to #515 (#518) --- CHANGELOG.md | 2 +- lib/grape-swagger/endpoint.rb | 3 +- spec/issues/430_entity_definitions_spec.rb | 32 ++++++++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e6fb99f..37da3029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ #### Fixes -* [#515](https://github.com/ruby-grape/grape-swagger/pull/515): Removes limit on model names, updates README - [@LeFnord](https://github.com/LeFnord). +* [#515](https://github.com/ruby-grape/grape-swagger/pull/515): Removes limit on model names - [@LeFnord](https://github.com/LeFnord). * Your contribution here. ### 0.24.0 (September 23, 2016) diff --git a/lib/grape-swagger/endpoint.rb b/lib/grape-swagger/endpoint.rb index a3f5199a..b1b86068 100644 --- a/lib/grape-swagger/endpoint.rb +++ b/lib/grape-swagger/endpoint.rb @@ -288,13 +288,12 @@ def expose_params_from_model(model) end def model_name(entity) - if entity.respond_to?(:entity_name) + if entity.methods(false).include?(:entity_name) entity.entity_name elsif entity.to_s.end_with?('::Entity', '::Entities') entity.to_s.split('::')[-2] else entity.name.demodulize.camelize - # entity.respond_to?(:name) ? entity.name.demodulize.camelize : entity.split('::').last end end diff --git a/spec/issues/430_entity_definitions_spec.rb b/spec/issues/430_entity_definitions_spec.rb index 5eda5bc8..1d5ddc8a 100644 --- a/spec/issues/430_entity_definitions_spec.rb +++ b/spec/issues/430_entity_definitions_spec.rb @@ -10,19 +10,19 @@ module WithVeryLongName module AnotherGroupingModule class Class1 class Entity < Grape::Entity - expose :one_thing + expose :first_thing end end class Class2 class Entities < Grape::Entity - expose :one_thing + expose :second_thing end end class Class3 class Entity < Grape::Entity - expose :another_thing + expose :third_thing def self.entity_name 'FooKlass' @@ -32,13 +32,29 @@ def self.entity_name class Class4 class FourthEntity < Grape::Entity - expose :another_thing + expose :fourth_thing end end class Class5 class FithEntity < Class4::FourthEntity - expose :another_thing + expose :fith_thing + end + end + + class Class6 + class SixthEntity < Grape::Entity + expose :sixth_thing + + def self.entity_name + 'BarKlass' + end + end + end + + class Class7 + class SeventhEntity < Class6::SixthEntity + expose :seventh_thing end end end @@ -51,7 +67,9 @@ class NameApi < Grape::API DummyEntities::WithVeryLongName::AnotherGroupingModule::Class2::Entities, DummyEntities::WithVeryLongName::AnotherGroupingModule::Class3::Entity, DummyEntities::WithVeryLongName::AnotherGroupingModule::Class4::FourthEntity, - DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity + DummyEntities::WithVeryLongName::AnotherGroupingModule::Class5::FithEntity, + DummyEntities::WithVeryLongName::AnotherGroupingModule::Class6::SixthEntity, + DummyEntities::WithVeryLongName::AnotherGroupingModule::Class7::SeventhEntity ] end end @@ -69,4 +87,6 @@ class NameApi < Grape::API specify { expect(subject).to include 'FooKlass' } specify { expect(subject).to include 'FourthEntity' } specify { expect(subject).to include 'FithEntity' } + specify { expect(subject).to include 'BarKlass' } + specify { expect(subject).to include 'SeventhEntity' } end