Skip to content

Commit e362c71

Browse files
committed
Merge pull request #217 from plugintheworld/fix_215_dont_delegate_to_kernel_methods
Do not delegate to Kernel methods.
2 parents 50ccc90 + bda6d66 commit e362c71

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sudo: false
33
language: ruby
44

55
cache: bundler
6+
bundler_args: --without development
67

78
rvm:
89
- ruby-head

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
0.5.2 (Next)
22
============
33

4+
* [#215](https://github.com/ruby-grape/grape-entity/pull/217): `#delegate_attribute` should not delegate to methods included with `Kernel`. - [@maltoe](https://github.com/maltoe)
45
* Your contribution here.
56

67
0.5.1 (2016-4-4)

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ source 'http://rubygems.org'
22

33
gemspec
44

5-
group :development, :test do
5+
group :development do
66
gem 'pry'
77
gem 'guard'
88
gem 'guard-rspec'
99
gem 'guard-bundler'
1010
gem 'rb-fsevent'
1111
gem 'growl'
12+
end
13+
14+
group :development, :test do
15+
gem 'rake'
1216
gem 'json'
1317
gem 'rspec'
1418
gem 'rack-test', '~> 0.6.2', require: 'rack/test'

lib/grape_entity/entity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def value_for(key, options = Options.new)
478478
end
479479

480480
def delegate_attribute(attribute)
481-
if respond_to?(attribute, true)
481+
if respond_to?(attribute, true) && method(attribute).owner == self.class
482482
send(attribute)
483483
else
484484
delegator.delegate(attribute)

spec/grape_entity/entity_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,18 @@ def name
15481548
expect(rep.value_for(:name)).to eq 'cooler name'
15491549
end
15501550

1551+
it 'does not delegate to Kernel methods' do
1552+
module EntitySpec
1553+
class DelegatingEntity < Grape::Entity
1554+
expose :system
1555+
end
1556+
end
1557+
1558+
foo = double 'Foo', system: 'System'
1559+
rep = EntitySpec::DelegatingEntity.new foo
1560+
expect(rep.value_for(:system)).to eq 'System'
1561+
end
1562+
15511563
context 'using' do
15521564
before do
15531565
module EntitySpec

spec/spec_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77

88
Bundler.require :default, :test
99

10-
require 'pry'
11-
1210
RSpec.configure(&:raise_errors_for_deprecations!)

0 commit comments

Comments
 (0)