require File.dirname(__FILE__) + '/../spec_helper' #require 'time' describe Atomic::Entry do def valid_attributes { :id => "123abc", :title => "Atom Entry Title", :categories => [ {:term => 'treforest', :scheme => 'http://cirrusstage.glam.ac.uk/schemes/locations'}, {:term => 'hesas', :scheme => 'http://cirrusstage.glam.ac.uk/schemes/categories'} ], :content => { :message=>"Test Announcement Message", :starts_at=>"2009-02-10T08:00:00Z", :ends_at=>"2009-02-10T17:00:00Z" } } end 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::Entry.parse(@xml) end it "should return a new Atomic::Entry" do @entry.should be_an(Atomic::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 @entry.content.should_not be_nil end end describe "#new" do it "should return a new Atomic::Entry" do entry = Atomic::Entry.new(valid_attributes) entry.should be_an(Atomic::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::Entry.new(valid_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::Entry.new(valid_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::Entry.new(valid_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::Entry.new(valid_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_attributes[:id] end it "should include the title" do @entry.to_hash.should have_key(:title) @entry.to_hash[:title].should == valid_attributes[:title] end it "should include the categories" do @entry.to_hash.should have_key(:categories) @entry.to_hash[:categories].should == valid_attributes[:categories] end it "should include the content" do @entry.to_hash.should have_key(:content) @entry.to_hash[:content].should == valid_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 end