Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After marshalling/unmarshalling nil is frozen #38

Closed
warnergodfrey opened this issue Dec 22, 2011 · 1 comment
Closed

After marshalling/unmarshalling nil is frozen #38

warnergodfrey opened this issue Dec 22, 2011 · 1 comment

Comments

@warnergodfrey
Copy link

Marshalling or unmarshalling an XML document using ROXML is freezing nil.

I have included a failing spec that demonstrates the issue and a copy of the Gemfile and rvm config that was used to run the spec.

frozen_nil_spec.rb

require 'rubygems'
require 'roxml'

describe 'roxml' do
  let(:xml_file) { File.open(File.expand_path('library.xml', File.dirname(__FILE__))) }

  context 'before unmarshalling an XML document' do
    it { nil.should_not be_frozen }
  end

  context 'after unmarshalling an XML document' do
    before do
      lib = Library.from_xml(xml_file)
    end

    it { nil.should_not be_frozen }
  end
end

class Book
  include ROXML

  xml_accessor :isbn, :from => "@ISBN" # attribute with name 'ISBN'
  xml_accessor :title
  xml_accessor :description, :cdata => true  # text node with cdata protection
  xml_accessor :author
end


class Library
  include ROXML

  xml_accessor :name, :from => "NAME", :cdata => true
  xml_accessor :books, :as => [Book] # by default roxml searches for books for in <book> child nodes, then, if none are present, in ./books/book children
end

rspec output

.F

Failures:

  1) roxml after unmarshalling an XML document 
     Failure/Error: it { nil.should_not be_frozen }
       expected frozen? to return false, got true
     # ./spec/frozen_nil_spec.rb:16:in `block (3 levels) in <top (required)>'

Finished in 0.00151 seconds
2 examples, 1 failure

Failed examples:

rspec ./spec/frozen_nil_spec.rb:16 # roxml after unmarshalling an XML document 

library.xml

<?xml version="1.0"?>
<library>
  <NAME><![CDATA[Favorite Books]]></NAME>
  <book ISBN="0201710897">
    <title>The PickAxe</title>
    <description><![CDATA[Best Ruby book out there!]]></description>
    <author>David Thomas, Andrew Hunt, Dave Thomas</author>
  </book>
</library>

Gemfile

source 'http://rubygems.org'

gem 'roxml', '3.2.0'
gem 'rspec', '2.6.0'
gem 'i18n'

Gemfile.lock

GEM
  remote: http://rubygems.org/
  specs:
    activesupport (3.1.3)
      multi_json (~> 1.0)
    diff-lcs (1.1.3)
    i18n (0.6.0)
    multi_json (1.0.4)
    nokogiri (1.5.0)
    roxml (3.2.0)
      activesupport (>= 2.3.0)
      nokogiri (>= 1.3.3)
    rspec (2.6.0)
      rspec-core (~> 2.6.0)
      rspec-expectations (~> 2.6.0)
      rspec-mocks (~> 2.6.0)
    rspec-core (2.6.4)
    rspec-expectations (2.6.0)
      diff-lcs (~> 1.1.2)
    rspec-mocks (2.6.0)

PLATFORMS
  ruby

DEPENDENCIES
  i18n
  roxml (= 3.2.0)
  rspec (= 2.6.0)

.rvmrc

rvm 1.9.2-p290@roxml --create
@Empact
Copy link
Owner

Empact commented Jan 5, 2012

Thanks Warner for the great bug report. I believe I have this fixed, and have it released as 3.2.1. The problem in this case was related to overzealous freezing of the roxml_naming_convention attribute, which is sometimes nil. In hindsight I don't really see the point in freezing it so I've dropped that altogether.

Now I have some questions about the freezing behavior in roxml (i.e. when one supplies the :frozen option to an attribute) and whether they can lead to similar behavior, so I've tried to diminish those possibilities, but they still are present I believe.

Thanks again for the report!

@Empact Empact closed this as completed Jan 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants