require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/atomic_spec_helper' #require 'time' describe Atomic::Atom::Entry do include AtomicSpecHelper before :each do @xml = File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'valid_atom_entry.xml')) end describe "Class Methods" do describe "#parse" do before :each do @entry = Atomic::Atom::Entry.parse(@xml) end it "should return a new Atomic::Entry" do @entry.should be_an(Atomic::Atom::Entry) end it "should decode a valid Atom Entry xml document" do @entry.title.should == 'Test Announcement' @entry.id.should == 'tag:example.org,2003:3.2397' @entry.categories.size.should == 2 end it "should handle author element" do @entry.author.should_not be_nil end it "should handle the announcements extension" do @entry.content.should_not be_nil @entry.content[:message].should == 'Test Announcement Message' @entry.content[:starts_at].should == '2009-02-10T08:00:00Z' @entry.content[:ends_at].should == '2009-02-10T17:00:00Z' end end describe "#new" do it "should return a new Atomic::Entry" do entry = Atomic::Atom::Entry.new(valid_entry_attributes) entry.should be_an(Atomic::Atom::Entry) end it "should set created_at and updated_at to current time if not supplied" do now = Time.now Time.stub!(:now).and_return(now) entry = Atomic::Atom::Entry.new(valid_entry_attributes) entry.created_at.should be_a(Time) entry.created_at.should == now entry.updated_at.should be_a(Time) entry.updated_at.should == now end it "should set created_at to supplied time" do now = Time.now Time.stub!(:now).and_return(now) entry = Atomic::Atom::Entry.new(valid_entry_attributes.merge(:created_at => '2009-02-10T08:00:00Z')) entry.created_at.should == Time.parse('2009-02-10T08:00:00Z') entry.created_at.should be_a(Time) end it "should set updated_at to supplied time" do now = Time.now Time.stub!(:now).and_return(now) entry = Atomic::Atom::Entry.new(valid_entry_attributes.merge(:updated_at => '2009-02-10T08:00:00Z')) entry.updated_at.should == Time.parse('2009-02-10T08:00:00Z') entry.updated_at.should be_a(Time) end end end describe "#to_hash" do before :each do @now = Time.now Time.stub!(:now).and_return(@now) @entry = Atomic::Atom::Entry.new(valid_entry_attributes) end it "should return a hash" do @entry.to_hash.should be_a(Hash) end it "should include the id" do @entry.to_hash.should have_key(:id) @entry.to_hash[:id].should == valid_entry_attributes[:id] end it "should include the title" do @entry.to_hash.should have_key(:title) @entry.to_hash[:title].should == valid_entry_attributes[:title] end it "should include the categories" do @entry.to_hash.should have_key(:categories) @entry.to_hash[:categories].should == valid_entry_attributes[:categories] end it "should include the content" do @entry.to_hash.should have_key(:content) @entry.to_hash[:content].should == valid_entry_attributes[:content] end it "should include the created_at time" do @entry.to_hash.should have_key(:created_at) @entry.to_hash[:created_at].should == @now end it "should include the updated_at time" do @entry.to_hash.should have_key(:updated_at) @entry.to_hash[:updated_at].should == @now end end describe "#to_xml" do before :each do @now = Time.now Time.stub!(:now).and_return(@now) @entry = Atomic::Atom::Entry.new(valid_entry_attributes) end it "should work" do puts @entry.to_xml(true) end end end