diff options
| author | hukl <contact@smyck.org> | 2009-02-21 14:27:08 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-02-21 14:27:08 +0100 |
| commit | edf4a4783c454ec6e5e63d70bac716b3821768eb (patch) | |
| tree | 4a694f5f36cd68dc8b33647c27cb798e32127322 | |
| parent | 3f0b690d8f0011dfdcc32af2626eef473f9111b5 (diff) | |
cloning now with all the translations. test added
| -rw-r--r-- | app/models/node.rb | 16 | ||||
| -rw-r--r-- | config/locales/de.yml | 2 | ||||
| -rw-r--r-- | test/unit/node_test.rb | 28 |
3 files changed, 41 insertions, 5 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 30e9e59..170ca1c 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -58,11 +58,17 @@ class Node < ActiveRecord::Base | |||
| 58 | raise "Page is locked" | 58 | raise "Page is locked" |
| 59 | else | 59 | else |
| 60 | # TODO clone tags later on | 60 | # TODO clone tags later on |
| 61 | p = self.pages.create!( | 61 | p = self.pages.create! |
| 62 | :title => self.head.title, | 62 | |
| 63 | :abstract => self.head.abstract, | 63 | I18n.available_locales.each do |l| |
| 64 | :body => self.head.body | 64 | next if l == :root |
| 65 | ) | 65 | I18n.locale = l |
| 66 | |||
| 67 | p.title = self.head.title | ||
| 68 | p.abstract = self.head.abstract | ||
| 69 | p.body = self.head.body | ||
| 70 | end | ||
| 71 | |||
| 66 | p.user = user | 72 | p.user = user |
| 67 | p.save | 73 | p.save |
| 68 | p | 74 | p |
diff --git a/config/locales/de.yml b/config/locales/de.yml new file mode 100644 index 0000000..3ddfada --- /dev/null +++ b/config/locales/de.yml | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | de: | ||
| 2 | hello: "Hello World" \ No newline at end of file | ||
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 937c3e0..d0c088e 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb | |||
| @@ -11,6 +11,34 @@ class NodeTest < ActiveSupport::TestCase | |||
| 11 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' | 11 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' |
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | def test_cloning_a_head_page_to_a_new_draft_with_translations | ||
| 15 | assert_not_nil draft = @first_child.draft | ||
| 16 | I18n.locale = :de | ||
| 17 | draft.title = "Hallo" | ||
| 18 | draft.abstract = "Bitte" | ||
| 19 | draft.body = "Danke" | ||
| 20 | draft.save | ||
| 21 | I18n.locale = :en | ||
| 22 | draft.title = "Hello" | ||
| 23 | draft.abstract = "Please" | ||
| 24 | draft.body = "Thanks" | ||
| 25 | draft.save | ||
| 26 | |||
| 27 | @first_child.publish_draft! | ||
| 28 | |||
| 29 | draft1 = @first_child.find_or_create_draft(@user1) | ||
| 30 | |||
| 31 | I18n.locale = :de | ||
| 32 | assert_equal "Hallo", draft1.title | ||
| 33 | assert_equal "Bitte", draft1.abstract | ||
| 34 | assert_equal "Danke", draft1.body | ||
| 35 | |||
| 36 | I18n.locale = :en | ||
| 37 | assert_equal "Hello", draft1.title | ||
| 38 | assert_equal "Please", draft1.abstract | ||
| 39 | assert_equal "Thanks", draft1.body | ||
| 40 | end | ||
| 41 | |||
| 14 | def test_created_nodes_have_an_empty_draft_and_no_head | 42 | def test_created_nodes_have_an_empty_draft_and_no_head |
| 15 | node = Node.create :slug => "third_child" | 43 | node = Node.create :slug => "third_child" |
| 16 | node.move_to_child_of @root | 44 | node.move_to_child_of @root |
