Skip to content

Commit

Permalink
fix: Accept nil serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateus Nava committed Aug 30, 2019
1 parent eb20081 commit 39ed733
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 1.5.3 (Next)

* Your contribution here.
* [#92](https://github.com/ruby-grape/grape-active_model_serializers/pull/92): Fix: accept nil serializer - [@mateusnava](https://github.com/mateusnava).

### 1.5.2 (March 14, 2018)

Expand Down
3 changes: 3 additions & 0 deletions lib/grape-active_model_serializers/serializer_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def serializer

def serializer_class
return @serializer_class if defined?(@serializer_class)

return nil if options.has_key?(:serializer) && options[:serializer].nil?

@serializer_class = resource_defined_class
@serializer_class ||= collection_class
@serializer_class ||= options[:serializer]
Expand Down
12 changes: 12 additions & 0 deletions spec/grape/active_model_serializers/serializer_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
expect(serializer).to be_kind_of(serializer_class)
end

context 'specified nil by options' do
let(:options) {
super().merge(
serializer: nil
)
}

it 'returns nil' do
expect(serializer).to be_nil
end
end

context 'each serializer' do
let(:options) {
super().except(:serializer).merge(
Expand Down

0 comments on commit 39ed733

Please sign in to comment.