Skip to content

Commit 2232eff

Browse files
committed
Merge pull request #203 from rngtng/fix-delete_by
Fix: return `self` instead of `nil` if no attribute was deleted
2 parents 69379e1 + 0b20e42 commit 2232eff

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

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

44
* Your contribution here.
55
* [#202](https://github.com/ruby-grape/grape-entity/pull/202): Fix: Reset `@using_class` memoization on `.setup` - [@rngtng](https://github.com/rngtng).
6+
* [#203](https://github.com/ruby-grape/grape-entity/pull/203): Grape::Entity::Exposure::NestingExposure::NestedExposures.delete_if always returns exposures. - [@rngtng](https://github.com/rngtng).
67

78
0.5.0 (2015-12-07)
89
==================

UPGRADING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Upgrading Grape Entity
2+
===============
3+
4+
### Upgrading to >= 0.5.1
5+
6+
* `Grape::Entity::Exposure::NestingExposure::NestedExposures.delete_if` always
7+
returns exposures, regardless of delete result (used to be
8+
`nil` in negative case), see [#203](https://github.com/ruby-grape/grape-entity/pull/203).

lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def <<(exposure)
2121
def delete_by(*attributes)
2222
reset_memoization!
2323
@exposures.reject! { |e| attributes.include? e.attribute }
24+
@exposures
2425
end
2526

2627
def clear

spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe Grape::Entity::Exposure::NestingExposure::NestedExposures do
4-
subject { described_class.new([]) }
4+
subject(:nested_exposures) { described_class.new([]) }
55

66
describe '#deep_complex_nesting?' do
77
it 'is reset when additional exposure is added' do
@@ -31,4 +31,26 @@
3131
expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
3232
end
3333
end
34+
35+
describe '.delete_by' do
36+
subject { nested_exposures.delete_by(*attributes) }
37+
38+
let(:attributes) { [:id] }
39+
40+
before do
41+
nested_exposures << Grape::Entity::Exposure.new(:id, {})
42+
end
43+
44+
it 'deletes matching exposure' do
45+
is_expected.to eq []
46+
end
47+
48+
context "when given attribute doesn't exists" do
49+
let(:attributes) { [:foo] }
50+
51+
it 'deletes matching exposure' do
52+
is_expected.to eq(nested_exposures)
53+
end
54+
end
55+
end
3456
end

0 commit comments

Comments
 (0)