spec/happymapper_spec.rb in happymapper-0.1.6 vs spec/happymapper_spec.rb in happymapper-0.1.7

- old
+ new

@@ -87,10 +87,24 @@ element :total_pages, Integer, :tag => 'TotalPages' has_many :items, Item end end +module GitHub + class Commit + include HappyMapper + + tag "commit" + + element :url, String + element :tree, String + element :message, String + element :id, String + element :'committed-date', Date + end +end + describe HappyMapper do describe "being included into another class" do before do Foo.instance_variable_set("@attributes", {}) @@ -110,20 +124,33 @@ lambda { Foo.attribute :name, String }.should change(Foo, :attributes) end + it "should allow adding an attribute containing a dash" do + lambda { + Foo.attribute :'bar-baz', String + }.should change(Foo, :attributes) + end + it "should be able to get all attributes in array" do Foo.attribute :name, String Foo.attributes.size.should == 1 end it "should allow adding an element" do lambda { Foo.element :name, String }.should change(Foo, :elements) end + + it "should allow adding an element containing a dash" do + lambda { + Foo.element :'bar-baz', String + }.should change(Foo, :elements) + + end it "should be able to get all elements in array" do Foo.element(:name, String) Foo.elements.size.should == 1 end @@ -289,6 +316,22 @@ @third.places.size.should == 2 @third.places[0].name.should == 'Work' @third.places[1].name.should == 'Home' end end -end \ No newline at end of file + + describe "#parse (with xml that has elements with dashes in them)" do + before do + file_contents = File.read(File.dirname(__FILE__) + '/fixtures/commit.xml') + @commit = GitHub::Commit.parse(file_contents).first + end + + it "should properly create objects" do + @commit.message.should == "move commands.rb and helpers.rb into commands/ dir" + @commit.url.should == "http://github.com/defunkt/github-gem/commit/c26d4ce9807ecf57d3f9eefe19ae64e75bcaaa8b" + @commit.id.should == "c26d4ce9807ecf57d3f9eefe19ae64e75bcaaa8b" + @commit.committed_date.should == Date.parse("2008-03-02T16:45:41-08:00") + @commit.tree.should == "28a1a1ca3e663d35ba8bf07d3f1781af71359b76" + end + + end +end