diff options
| author | hukl <contact@smyck.org> | 2009-02-27 16:53:11 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-02-27 16:53:11 +0100 |
| commit | 69a37065f9f523c25bc4edb9c70a9b21578d46f6 (patch) | |
| tree | 550e750f9c48dee36f472fa1c8bae54e5bd95f17 /app/models/node.rb | |
| parent | 463da8c96569f4ef9450f0eb75c7209f6a25b84b (diff) | |
more tests and fixes. always write tests - they are so good!
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 33c82c9..e2cb564 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -65,26 +65,34 @@ class Node < ActiveRecord::Base | |||
| 65 | end | 65 | end |
| 66 | 66 | ||
| 67 | def create_new_draft user | 67 | def create_new_draft user |
| 68 | p = self.pages.create! | 68 | page = self.pages.create! |
| 69 | 69 | ||
| 70 | p.tag_list = self.head.tag_list.join(", ") | 70 | if self.head |
| 71 | clone_attributes_to page | ||
| 72 | end | ||
| 73 | |||
| 74 | page.user = user | ||
| 75 | page.save | ||
| 76 | page.reload | ||
| 77 | page | ||
| 78 | end | ||
| 79 | |||
| 80 | def clone_attributes_to page | ||
| 81 | page.tag_list = self.head.tag_list.join(", ") | ||
| 71 | 82 | ||
| 72 | locale_before = I18n.locale | 83 | locale_before = I18n.locale |
| 73 | 84 | ||
| 74 | I18n.available_locales.each do |l| | 85 | I18n.available_locales.each do |l| |
| 75 | next if l == :root | 86 | next if l == :root |
| 76 | I18n.locale = l | 87 | I18n.locale = l |
| 77 | p.title = self.head.title | 88 | page.title = self.head.title |
| 78 | p.abstract = self.head.abstract | 89 | page.abstract = self.head.abstract |
| 79 | p.body = self.head.body | 90 | page.body = self.head.body |
| 80 | end | 91 | end |
| 81 | 92 | ||
| 82 | I18n.locale = locale_before | 93 | I18n.locale = locale_before |
| 83 | 94 | ||
| 84 | p.user = user | 95 | page |
| 85 | p.save | ||
| 86 | p.reload | ||
| 87 | p | ||
| 88 | end | 96 | end |
| 89 | 97 | ||
| 90 | def publish_draft! | 98 | def publish_draft! |
