Skip to content

Commit

Permalink
Merge pull request #66 from trekdemo/default_value_can_be_false
Browse files Browse the repository at this point in the history
Default value can't be `false`
  • Loading branch information
krasnoukhov committed Jan 30, 2015
2 parents b5bb26a + f7b6dc4 commit 66f70f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sax-machine/sax_document.rb
Expand Up @@ -21,7 +21,7 @@ def initialize(attributes = {})

self.class.sax_config.top_level_elements.each do |_, configs|
configs.each do |config|
next unless config.default
next if config.default.nil?
next unless send(config.as).nil?

send(config.setter, config.default)
Expand Down
16 changes: 16 additions & 0 deletions spec/sax-machine/sax_document_spec.rb
Expand Up @@ -207,6 +207,22 @@ def title=(val)
document = @klass.parse("<number></number>")
expect(document.number).to eq(0)
end

it "can be a Boolean" do
@klass = Class.new do
include SAXMachine
element(:bool, default: false) { |v| !!v }
end

document = @klass.parse("<no>bool</no>")
expect(document.bool).to be false

document = @klass.parse("<bool></bool>")
expect(document.bool).to be false

document = @klass.parse("<bool>1</bool>")
expect(document.bool).to be true
end
end

describe "the required attribute" do
Expand Down

0 comments on commit 66f70f6

Please sign in to comment.