position handling with pages
Olli Huotari
committed Feb 05, 2012
commit db386ea1b36cb57ea37ad10aab041b5cc6ca096e
Showing 4
changed files with
12 additions
and 4 deletions
app/models/cms/page.rb
+1
-0
| @@ | @@ -144,6 +144,7 @@ protected |
| def assign_position | |
| return unless self.parent | |
| + | return if self.position.to_i > 0 |
| max = self.parent.children.maximum(:position) | |
| self.position = max ? max + 1 : 0 | |
| end | |
cms_fixtures/example.com/pages/index/child/_child.yml b/db/cms_fixtures/example.com/pages/index/child/_child.yml
+2
-1
| @@ | @@ -1,2 +1,3 @@ |
| label: Child Fixture Page | |
| - | layout: nested |
| \ No newline at end of file | |
| + | layout: nested |
| + | position: 42 |
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb
+3
-1
| @@ | @@ -101,6 +101,7 @@ module ComfortableMexicanSofa::Fixtures |
| page.layout = site.layouts.find_by_identifier(attributes[:layout]) || parent.try(:layout) | |
| page.target_page = site.pages.find_by_full_path(attributes[:target_page]) | |
| page.is_published = attributes[:is_published].present?? attributes[:is_published] : true | |
| + | page.position = attributes[:position] if attributes[:position] |
| end | |
| elsif page.new_record? | |
| page.label = slug.titleize | |
| @@ | @@ -237,7 +238,8 @@ module ComfortableMexicanSofa::Fixtures |
| 'layout' => page.layout.try(:identifier), | |
| 'parent' => page.parent && (page.parent.slug.present?? page.parent.slug : 'index'), | |
| 'target_page' => page.target_page.try(:slug), | |
| - | 'is_published' => page.is_published |
| + | 'is_published' => page.is_published, |
| + | 'position' => page.position |
| }.to_yaml) | |
| end | |
| page.blocks_attributes.each do |block| | |
test/unit/fixtures_test.rb
+6
-2
| @@ | @@ -91,6 +91,7 @@ class FixturesTest < ActiveSupport::TestCase |
| assert_equal layout, page.layout | |
| assert_equal 'index', page.slug | |
| assert_equal "<html>Home Page Fixture Contént\ndefault_snippet_content</html>", page.content | |
| + | assert_equal 0, page.position |
| assert page.is_published? | |
| assert child_page = Cms::Page.find_by_full_path('/child') | |
| @@ | @@ -98,6 +99,7 @@ class FixturesTest < ActiveSupport::TestCase |
| assert_equal nested, child_page.layout | |
| assert_equal 'child', child_page.slug | |
| assert_equal '<html>Child Page Left Fixture Content<br/>Child Page Right Fixture Content</html>', child_page.content | |
| + | assert_equal 42, child_page.position |
| end | |
| end | |
| @@ | @@ -280,7 +282,8 @@ class FixturesTest < ActiveSupport::TestCase |
| 'layout' => 'default', | |
| 'parent' => nil, | |
| 'target_page' => nil, | |
| - | 'is_published' => true |
| + | 'is_published' => true, |
| + | 'position' => 0 |
| }), YAML.load_file(page_1_attr_path) | |
| assert_equal cms_blocks(:default_field_text).content, IO.read(page_1_block_a_path) | |
| assert_equal cms_blocks(:default_page_text).content, IO.read(page_1_block_b_path) | |
| @@ | @@ -290,7 +293,8 @@ class FixturesTest < ActiveSupport::TestCase |
| 'layout' => 'default', | |
| 'parent' => 'index', | |
| 'target_page' => nil, | |
| - | 'is_published' => true |
| + | 'is_published' => true, |
| + | 'position' => 0 |
| }), YAML.load_file(page_2_attr_path) | |
| FileUtils.rm_rf(host_path) | |