require File.expand_path('../test_helper', File.dirname(__FILE__)) class CmsLayoutTest < ActiveSupport::TestCase def test_fixtures_validity CmsLayout.all.each do |layout| assert layout.valid? end end def test_validations layout = CmsLayout.create assert layout.errors.present? assert_has_errors_on layout, [:label, :slug, :content] end def test_validation_of_tag_presence layout = CmsLayout.create(:content => 'some text') assert_has_errors_on layout, :content layout = CmsLayout.create(:content => '{cms:snippet:blah}') assert_has_errors_on layout, :content layout = cms_sites(:default).cms_layouts.new( :label => 'test', :slug => 'test', :content => '{{cms:page:blah}}' ) assert layout.valid? layout = cms_sites(:default).cms_layouts.new( :label => 'test', :slug => 'test', :content => '{{cms:field:blah}}' ) assert layout.valid? end def test_options_for_select assert_equal ['Default Layout', 'Nested Layout', '. . Child Layout'], CmsLayout.options_for_select(cms_sites(:default)).collect{|t| t.first} assert_equal ['Default Layout', 'Nested Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:child)).collect{|t| t.first} assert_equal ['Default Layout'], CmsLayout.options_for_select(cms_sites(:default), cms_layouts(:nested)).collect{|t| t.first} end def test_app_layouts_for_select assert_equal ['cms_admin.html.erb'], CmsLayout.app_layouts_for_select end def test_merged_content parent_layout = cms_layouts(:nested) layout = cms_layouts(:child) assert_equal "{{cms:page:header}}\n{{cms:page:left_column}}\n{{cms:page:right_column}}", layout.merged_content assert_equal "{{cms:page:left_column}}\n{{cms:page:right_column}}", layout.content parent_layout.update_attribute(:content, '{{cms:page:whatever}}') layout.reload assert_equal "{{cms:page:left_column}}\n{{cms:page:right_column}}", layout.merged_content end def test_merged_css assert_equal "nested_css\nchild_css", cms_layouts(:child).merged_css end def test_merged_js assert_equal "nested_js\nchild_js", cms_layouts(:child).merged_js end def test_load_from_file assert !CmsLayout.load_from_file(cms_sites(:default), 'default') ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__)) assert !CmsLayout.load_from_file(cms_sites(:default), 'bogus') assert layout = CmsLayout.load_from_file(cms_sites(:default), 'default') assert_equal 'Default Layout', layout.label assert_equal '{{cms:page:content}}', layout.content assert layout = CmsLayout.load_from_file(cms_sites(:default), 'nested') assert_equal 'Nested Layout', layout.label assert_equal '