# -*- ruby -*- # vim: set nosta noet ts=4 sw=4: # encoding: utf-8 require_relative '../../helpers' require 'strelka/cms/pagecatalog' ##################################################################### ### C O N T E X T S ##################################################################### describe Strelka::CMS::PageCatalog do include FakeFS::SpecHelpers before( :all ) do setup_logging() end before( :each ) do FileUtils.mkdir_p( '/var/www/local/test' ) FileUtils.mkdir_p( '/var/www/local/lib' ) Dir.chdir( '/var/www/local' ) end after( :all ) do reset_logging() end context "created with defaults" do subject { described_class.new } it "has a glob pattern that matches .page files under the current directory" do expect( subject.glob ).to eq( "/var/www/local/**/*.page" ) end it "can load page files by name" do FileUtils.touch( '/var/www/local/test/index.page' ) page = subject['test/index'] expect( page ).to be_a( Strelka::CMS::Page ) expect( page.path.to_s ).to eq( '/var/www/local/test/index.page' ) expect( page.catalog ).to be( subject ) end it "doesn't require the .page extension when loading page files by name" do FileUtils.touch( '/var/www/local/test/index.page' ) page = subject['test/index'] expect( page ).to be_a( Strelka::CMS::Page ) expect( page.path.to_s ).to eq( '/var/www/local/test/index.page' ) expect( page.catalog ).to be( subject ) end end context "created with a base directory" do subject { described_class.new('/var/www') } it "has a glob pattern that matches .page files under the directory it was created with" do expect( subject.glob ).to eq( "/var/www/**/*.page" ) end end context "created with a base directory and a glob pattern" do subject { described_class.new('/var/www/local', '**/*.rb') } it "has a glob pattern that matches files that match the pattern under the directory it was " + "created with" do expect( subject.glob ).to eq( "/var/www/local/**/*.rb" ) end it "has a mutator that clones it for a subdirectory" do expect( subject.relative_to('lib').glob ).to eq( "/var/www/local/lib/**/*.rb" ) end it "has a mutator that clones it for a different glob pattern" do expect( subject.matching_pattern('*.txt').glob ).to eq( "/var/www/local/*.txt" ) end it "has an iterator that yields files that match its glob pattern" do pending "Database rewrite" FileUtils.touch( '/var/www/local/lib/payment.rb' ) expect( subject.relative_to('lib').map(&:path) ). to include( Pathname('/var/www/local/lib/payment.rb') ) end it "strips leading directory separators from relative paths" do expect( subject.relative_to( '/lib' ).glob ).to eq( "/var/www/local/lib/**/*.rb" ) end end end