Skip to content

Commit

Permalink
Merge 62f1237 into b74c821
Browse files Browse the repository at this point in the history
  • Loading branch information
blanquer committed Aug 11, 2016
2 parents b74c821 + 62f1237 commit cb1f84a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: ruby
cache: bundler
sudo: false
rvm:
- 2.2.3
- 2.2.5
- 2.3.1
script:
- bundle exec rspec spec
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Include Attributor::Dumpable in Blueprint, so it renders (semi) correctly if
rendered with just `true` specified for fields.
* Fix bug rendering subobjects with nil values (manifested when `include_nil: true` there’s an explicit subsection of fields)

## 3.2

Expand Down
4 changes: 2 additions & 2 deletions lib/praxis-blueprints/blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ def validate(context = Attributor::DEFAULT_ROOT_CONTEXT)
if value.respond_to?(:validating) # really, it's a thing with sub-attributes
next if value.validating
end
errors.push(*sub_attribute.validate(value, sub_context))
errors.concat(sub_attribute.validate(value, sub_context))
end
self.class.attribute.type.requirements.each do |req|
validation_errors = req.validate(keys_with_values, context)
errors.push(*validation_errors) unless validation_errors.empty?
errors.concat(validation_errors) unless validation_errors.empty?
end
errors
ensure
Expand Down
4 changes: 4 additions & 0 deletions lib/praxis-blueprints/config_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def to_hash
@hash
end

def respond_to_missing?(method_name, _include_private = false)
true || super # silly, but it'll appease rubocop
end

def method_missing(name, value, *rest, &block)
if (existing = @hash[name])
if block
Expand Down
2 changes: 1 addition & 1 deletion lib/praxis-blueprints/field_expander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def expand_with_member_attribute(object, fields = true)
new_fields = fields.is_a?(Array) ? fields[0] : fields

result = [expand(object.member_attribute.type, new_fields)]
history[object][fields].push(*result)
history[object][fields].concat(result)

result
end
Expand Down
5 changes: 4 additions & 1 deletion lib/praxis-blueprints/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def _render(object, fields, view = nil, context: Attributor::DEFAULT_ROOT_CONTEX
raise Attributor::DumpError, context: context, name: key, type: object.class, original_exception: e
end

next if value.nil? && !include_nil
if value.nil?
hash[key] = nil if self.include_nil
next
end

if subfields == true
hash[key] = case value
Expand Down
6 changes: 6 additions & 0 deletions spec/praxis-blueprints/renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

context 'with include_nil: true' do
let(:renderer) { Praxis::Renderer.new(include_nil: true) }
let(:address) { nil }

it 'renders attributes with nil values' do
output.should have_key :email
Expand All @@ -108,6 +109,11 @@
output.should have_key :work_address
output[:work_address].should be nil
end

it 'renders nil directly for nil subobjects' do
output.should have_key :address
output[:address].should be nil
end
end

context '#render_collection' do
Expand Down

0 comments on commit cb1f84a

Please sign in to comment.