Skip to content

Commit

Permalink
Merge pull request #132 from procore/bugfix/serialize-false
Browse files Browse the repository at this point in the history
[Bugfix] Serialize boolean false values
  • Loading branch information
mcclayton authored Jan 25, 2019
2 parents 64546aa + ed5f21a commit ca31dc5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.1 - 2019/1/24

* 🐛 [BUGFIX] Fix boolean `false` values getting serialized as `null`. Please see PR [#132](https://github.com/procore/blueprinter/pull/132).

## 0.12.0 - 2019/1/16

* 🚀 [FEATURE] Enables the setting of global `:field_default` and `:association_default` option value in the Blueprinter Configuration that will be used as default values for fields and associations that evaluate to nil. [#128](https://github.com/procore/blueprinter/pull/128). Thanks to [@mcclayton](https://github.com/mcclayton).
Expand Down
4 changes: 2 additions & 2 deletions lib/blueprinter/extractors/hash_extractor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Blueprinter
class HashExtractor < Extractor
def extract(field_name, object, local_options, options = {})
object[field_name] || object[field_name.to_s]
def extract(field_name, object, _local_options, _options = {})
object[field_name]
end
end
end
2 changes: 1 addition & 1 deletion lib/blueprinter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Blueprinter
VERSION = '0.12.0'
VERSION = '0.12.1'
end
3 changes: 2 additions & 1 deletion spec/activerecord_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Vehicle < ActiveRecord::Base
end

class User < ActiveRecord::Base
attr_accessor :company, :description, :position
attr_accessor :company, :description, :position, :active
has_many :vehicles
end

Expand All @@ -25,6 +25,7 @@ class User < ActiveRecord::Base
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "deleted_at"
t.boolean "active"
end

create_table "vehicles", force: :cascade do |t|
Expand Down
1 change: 1 addition & 0 deletions spec/factories/model_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
company { 'Procore' }
birthday { Date.new(1994, 3, 4) }
deleted_at { nil }
active { false }
end

factory :vehicle do
Expand Down
3 changes: 2 additions & 1 deletion spec/integrations/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
description: 'A person',
company: 'Procore',
birthday: Date.new(1994, 3, 4),
deleted_at: nil
deleted_at: nil,
active: false
}
end
let(:object_with_attributes) { OpenStruct.new(obj_hash) }
Expand Down
14 changes: 14 additions & 0 deletions spec/integrations/shared/base_render_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
it('returns json with specified fields') { should eq(result) }
end

context 'Given blueprint has ::field with all data types' do
let(:result) { '{"active":false,"birthday":"1994-03-04","deleted_at":null,"first_name":"Meg","id":' + obj_id + '}' }
let(:blueprint) do
Class.new(Blueprinter::Base) do
field :id # number
field :first_name # string
field :active # boolean
field :birthday # date
field :deleted_at # null
end
end
it('returns json with the correct values for each data type') { should eq(result) }
end

context 'Given blueprint has ::fields' do
let(:result) do
'{"id":' + obj_id + ',"description":"A person","first_name":"Meg"}'
Expand Down

0 comments on commit ca31dc5

Please sign in to comment.