diff options
| author | hukl <hukl@eight.local> | 2009-01-31 13:05:48 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-01-31 13:05:48 +0100 |
| commit | 5b06d137fc6143ff679d1ce6048c4149ca23f4e2 (patch) | |
| tree | c2945a13eb3376aabb0d610804bf7a8f972793e7 | |
| parent | be83d467b5b6f92b0a6a175ee365d043f250d631 (diff) | |
connected page and node model + some minor tweaks
| -rw-r--r-- | app/models/node.rb | 2 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | test/fixtures/nodes.yml | 12 | ||||
| -rw-r--r-- | test/unit/node_test.rb | 47 | ||||
| m--------- | vendor/rails | 0 |
5 files changed, 59 insertions, 4 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index e2ff973..cac4495 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | class Node < ActiveRecord::Base | 1 | class Node < ActiveRecord::Base |
| 2 | acts_as_nested_set | 2 | acts_as_nested_set |
| 3 | 3 | ||
| 4 | has_many :pages | ||
| 5 | |||
| 4 | # returns array with pages up to root excluding root | 6 | # returns array with pages up to root excluding root |
| 5 | def path_to_root | 7 | def path_to_root |
| 6 | parent.nil? && [slug] || parent.path_to_root.push(slug) | 8 | parent.nil? && [slug] || parent.path_to_root.push(slug) |
diff --git a/config/routes.rb b/config/routes.rb index cbad5cc..96d56de 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | ActionController::Routing::Routes.draw do |map| | 1 | ActionController::Routing::Routes.draw do |map| |
| 2 | map.resources :pages | ||
| 3 | |||
| 2 | 4 | ||
| 3 | map.connect ':language/*pagepath', | 5 | map.connect ':language/*pagepath', |
| 4 | :controller => 'content', :action => 'render_page', | 6 | :controller => 'content', :action => 'render_page', |
diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index 9879d9f..3f89f6d 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml | |||
| @@ -3,6 +3,16 @@ | |||
| 3 | one: | 3 | one: |
| 4 | id: 1 | 4 | id: 1 |
| 5 | lft: 1 | 5 | lft: 1 |
| 6 | rgt: 2 | 6 | rgt: 4 |
| 7 | parent_id: | ||
| 8 | slug: | ||
| 9 | unique_name: | ||
| 10 | |||
| 11 | |||
| 12 | two: | ||
| 13 | id: 2 | ||
| 14 | lft: 2 | ||
| 15 | rgt: 3 | ||
| 16 | parent_id: 1 | ||
| 7 | slug: my_first_page | 17 | slug: my_first_page |
| 8 | unique_name: root/my_first_page | 18 | unique_name: root/my_first_page |
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index a311b84..14fdad0 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb | |||
| @@ -1,8 +1,49 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class NodeTest < ActiveSupport::TestCase | 3 | class NodeTest < ActiveSupport::TestCase |
| 4 | # Replace this with your real tests. | 4 | |
| 5 | test "the truth" do | 5 | def setup |
| 6 | assert true | 6 | @root = Node.find(1) |
| 7 | @first_child = Node.find(2) | ||
| 8 | end | ||
| 9 | |||
| 10 | def test_creation_of_unique_name | ||
| 11 | node = Node.create :slug => 'child' | ||
| 12 | node.move_to_child_of @root | ||
| 13 | node.reload | ||
| 14 | assert_equal 'child', node.unique_name | ||
| 15 | |||
| 16 | node = Node.create :slug => 'deep_child' | ||
| 17 | node.move_to_child_of @first_child | ||
| 18 | node.reload | ||
| 19 | assert_equal 'my_first_page/deep_child', node.unique_name | ||
| 20 | end | ||
| 21 | |||
| 22 | def test_retrieving_page_current | ||
| 23 | |||
| 24 | end | ||
| 25 | |||
| 26 | def test_retrieving_page_by_revision | ||
| 27 | |||
| 28 | end | ||
| 29 | |||
| 30 | def test_behavior_of_acts_as_list | ||
| 31 | one = @first_child.pages.create :title => "one" | ||
| 32 | two = @first_child.pages.create :title => "two" | ||
| 33 | three = @first_child.pages.create :title => "three" | ||
| 34 | |||
| 35 | assert_equal 1, one.revision | ||
| 36 | assert_equal 2, two.revision | ||
| 37 | assert_equal 3, three.revision | ||
| 38 | |||
| 39 | assert_equal three, @first_child.pages.last | ||
| 40 | |||
| 41 | assert one.move_to_bottom | ||
| 42 | |||
| 43 | one.reload; two.reload; three.reload; | ||
| 44 | |||
| 45 | assert_equal 3, one.revision | ||
| 46 | assert_equal 1, two.revision | ||
| 47 | assert_equal 2, three.revision | ||
| 7 | end | 48 | end |
| 8 | end | 49 | end |
diff --git a/vendor/rails b/vendor/rails | |||
| Subproject 8761663a68bd7ddd918f78fb3def4697784024f | Subproject 2dedb5b03ab88a1c31068f71c8d4cad7c5a5d9a | ||
