Skip to content

Commit

Permalink
Merge pull request #438 from brainspec/as-json
Browse files Browse the repository at this point in the history
Make Enumerize::Value#as_json return a string. not an instance of Enumerize::Value
  • Loading branch information
nashby authored Nov 11, 2023
2 parents df29b37 + df74504 commit 3be0abd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Fix a bug where the value of a false boolean attribute was not properly serialized because it was
treated as ruby's false in condition and that condition was never met. (by [@nashby](https://github.com/nashby))
* Make `Enumerize::Value#as_json` return a string, not an instance of `Enumerize::Value` (by [@nashby](https://github.com/nashby))

### enchancements

Expand All @@ -17,7 +18,7 @@
* Warn about already defined predicate methods only when we generate predicate methods with `predicate: true` (by [@nashby](https://github.com/nashby))
* Define `Type#cast` instead of deserialize to fix serialization issue. (by [@nashby](https://github.com/nashby))
* Fix `Undefined method 'enumerize' for RSpec::ExampleGroups` (by [@softwaregravy](https://github.com/softwaregravy))

### enchancements

* Add support for procs as `i18n_scope` option value. (by [@nashby](https://github.com/nashby))
Expand Down
4 changes: 4 additions & 0 deletions lib/enumerize/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def encode_with(coder)
coder.represent_object(self.class.superclass, @value)
end

def as_json(*)
to_s
end

private

def predicate_call(value)
Expand Down
7 changes: 7 additions & 0 deletions test/value_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,11 @@ def value?(value)
assert_silent() { Enumerize::Value.new(attr, 'test_value') }
end
end

describe '#as_json' do
it 'returns String object, not Value object' do
expect(val.as_json.class).must_equal String
expect(val.as_json).must_equal 'test_value'
end
end
end

0 comments on commit 3be0abd

Please sign in to comment.