require File.expand_path("../../spec_helper", __FILE__) describe StylesheetPage do dataset :stylesheets let(:css){ pages(:css) } let(:site_css){ pages(:site_css) } subject{ css } its(:cache?) { should be_true } its(:sheet?) { should be_true } its(:virtual?) { should be_true } its(:layout) { should be_nil } describe '.root' do subject{ StylesheetPage.root } it { should == css } end describe '.new_with_defaults' do describe '#parts' do let(:parts){ StylesheetPage.new_with_defaults.parts } subject{ parts } its(:length) { should == 1 } it "should have a body part" do parts[0].name.should == 'body' end end end describe '#headers' do it "should have a 'Content-Type' of 'text/css'" do css.headers['Content-Type'].should == 'text/css' end end describe '#find_by_path' do context 'with a valid url' do it 'should return the child found by the given slug' do css.find_by_path('/css/site.css').should == site_css end end end describe '#digest' do it 'should return an md5 hash of the rendered contents' do site_css.digest.should == Digest::MD5.hexdigest(site_css.render) end end describe '#path' do before do Radiant::Config['sheets.use_cache_param?'] = true end it 'should include an md5 hash of the rendered contents' do site_css.path.should == "/css/site.css?#{site_css.digest}" end it 'should not include an md5 hash of the rendered contents for the root' do css.path.should == "/css/" end end context 'when validating a new page' do it "should automatically set the title to the given slug" do j = StylesheetPage.new(:slug => 'site.css') j.valid? j.title.should == 'site.css' end it "should automatically set the breadcrumb to the given slug" do j = StylesheetPage.new(:slug => 'site.css') j.valid? j.breadcrumb.should == 'site.css' end end context 'when saving a new page' do subject { s = StylesheetPage.new_with_defaults s.slug = 'test.css' s.save! s } its(:status){ should == Status[:published] } its(:status_id){ should == Status[:published].id } its(:published_at){ should_not be_nil } it "should have a published_at greater than or equal to the current time" do subject.published_at.to_i.should <= Time.zone.now.to_i end context 'with the default page status set to draft' do it 'should save a new page with a published status' do Radiant::Config['defaults.page.status'] = 'draft' new_sheet = StylesheetPage.new_with_defaults new_sheet.slug = 'published.css' new_sheet.save! new_sheet.status.should == Status[:published] end end end end