Skip to content

Fix: return self instead of nil if no attribute was deleted #203

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

Merged
merged 1 commit into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

* Your contribution here.
* [#202](https://github.com/ruby-grape/grape-entity/pull/202): Fix: Reset `@using_class` memoization on `.setup` - [@rngtng](https://github.com/rngtng).
* [#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).

0.5.0 (2015-12-07)
==================
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Upgrading Grape Entity
===============

### Upgrading to >= 0.5.1

* `Grape::Entity::Exposure::NestingExposure::NestedExposures.delete_if` always
returns exposures, regardless of delete result (used to be
`nil` in negative case), see [#203](https://github.com/ruby-grape/grape-entity/pull/203).
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def <<(exposure)
def delete_by(*attributes)
reset_memoization!
@exposures.reject! { |e| attributes.include? e.attribute }
@exposures
end

def clear
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Grape::Entity::Exposure::NestingExposure::NestedExposures do
subject { described_class.new([]) }
subject(:nested_exposures) { described_class.new([]) }

describe '#deep_complex_nesting?' do
it 'is reset when additional exposure is added' do
Expand Down Expand Up @@ -31,4 +31,26 @@
expect(subject.instance_variable_get(:@deep_complex_nesting)).to be_nil
end
end

describe '.delete_by' do
subject { nested_exposures.delete_by(*attributes) }

let(:attributes) { [:id] }

before do
nested_exposures << Grape::Entity::Exposure.new(:id, {})
end

it 'deletes matching exposure' do
is_expected.to eq []
end

context "when given attribute doesn't exists" do
let(:attributes) { [:foo] }

it 'deletes matching exposure' do
is_expected.to eq(nested_exposures)
end
end
end
end