position handling with layouts
Olli Huotari
committed Feb 05, 2012
commit 8047922098c9343c7b0791f0fb61cfdc369cb402
Showing 3
changed files with
12 additions
and 5 deletions
cms_fixtures/example.com/layouts/default/nested/_nested.yml b/db/cms_fixtures/example.com/layouts/default/nested/_nested.yml
+2
-1
| @@ | @@ -1 +1,2 @@ |
| - | label: Default Fixture Nested Layout |
| \ No newline at end of file | |
| + | label: Default Fixture Nested Layout |
| + | position: 42 |
| \ No newline at end of file | |
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb
+4
-2
| @@ | @@ -28,7 +28,8 @@ module ComfortableMexicanSofa::Fixtures |
| if layout.new_record? || File.mtime(file_path) > layout.updated_at | |
| attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { } | |
| layout.label = attributes[:label] || identifier.titleize | |
| - | layout.app_layout = attributes[:app_layout] || parent.try(:app_layout) |
| + | layout.app_layout = attributes[:app_layout] || parent.try(:app_layout) |
| + | layout.position = attributes[:position] if attributes[:position] |
| end | |
| elsif layout.new_record? | |
| layout.label = identifier.titleize | |
| @@ | @@ -206,7 +207,8 @@ module ComfortableMexicanSofa::Fixtures |
| f.write({ | |
| 'label' => layout.label, | |
| 'app_layout' => layout.app_layout, | |
| - | 'parent' => layout.parent.try(:identifier) |
| + | 'parent' => layout.parent.try(:identifier), |
| + | 'position' => layout.position |
| }.to_yaml) | |
| end | |
| open(File.join(layout_path, 'content.html'), 'w') do |f| | |
test/unit/fixtures_test.rb
+6
-2
| @@ | @@ -41,6 +41,7 @@ class FixturesTest < ActiveSupport::TestCase |
| assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content | |
| assert_equal 'body{color: red}', layout.css | |
| assert_equal '// default js', layout.js | |
| + | assert_equal 0, layout.position |
| nested_layout.reload | |
| assert_equal layout, nested_layout.parent | |
| @@ | @@ -48,6 +49,7 @@ class FixturesTest < ActiveSupport::TestCase |
| assert_equal "<div class='left'> {{ cms:page:left }} </div>\n<div class='right'> {{ cms:page:right }} </div>", nested_layout.content | |
| assert_equal 'div{float:left}', nested_layout.css | |
| assert_equal '// nested js', nested_layout.js | |
| + | assert_equal 42, nested_layout.position |
| assert_nil Cms::Layout.find_by_identifier('child') | |
| end | |
| @@ | @@ -250,7 +252,8 @@ class FixturesTest < ActiveSupport::TestCase |
| assert_equal ({ | |
| 'label' => 'Nested Layout', | |
| 'app_layout' => nil, | |
| - | 'parent' => nil |
| + | 'parent' => nil, |
| + | 'position' => 0 |
| }), YAML.load_file(layout_1_attr_path) | |
| assert_equal cms_layouts(:nested).content, IO.read(layout_1_content_path) | |
| assert_equal cms_layouts(:nested).css, IO.read(layout_1_css_path) | |
| @@ | @@ -259,7 +262,8 @@ class FixturesTest < ActiveSupport::TestCase |
| assert_equal ({ | |
| 'label' => 'Child Layout', | |
| 'app_layout' => nil, | |
| - | 'parent' => 'nested' |
| + | 'parent' => 'nested', |
| + | 'position' => 0 |
| }), YAML.load_file(layout_2_attr_path) | |
| assert_equal cms_layouts(:child).content, IO.read(layout_2_content_path) | |
| assert_equal cms_layouts(:child).css, IO.read(layout_2_css_path) | |