summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-07-18 18:17:06 +0200
committerhukl <contact@smyck.org>2009-07-18 18:17:06 +0200
commit144b18c5db61c53028177680295f3fc9d4e8711d (patch)
treedfed99c6a59487af6279ce15c02dbc366328602d /app
parentaab86f2d2a0258a1347f39c1ee4081cd06bac56b (diff)
Test::Unit Fixtures can't handle globalize2's translated attributes which is why its impossible to set translated attributes via fixtures. Therefor I removed the page fixtures entirely and and made sure that a title is set to "Untitled" when it is not specified otherwise.
If a new node is created, its initial draft has "Untitled" set as title automatically. Modified tests accordingly
Diffstat (limited to 'app')
-rw-r--r--app/models/node.rb2
-rw-r--r--app/models/page.rb22
2 files changed, 15 insertions, 9 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 647a86a..2a82ba8 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -67,7 +67,7 @@ class Node < ActiveRecord::Base
67 end 67 end
68 68
69 def create_new_draft user 69 def create_new_draft user
70 empty_page = self.pages.create 70 empty_page = self.pages.create!
71 empty_page.user = user 71 empty_page.user = user
72 empty_page.save 72 empty_page.save
73 73
diff --git a/app/models/page.rb b/app/models/page.rb
index 49ac586..0a978ab 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -30,7 +30,8 @@ class Page < ActiveRecord::Base
30 belongs_to :user 30 belongs_to :user
31 31
32 # Filter 32 # Filter
33 before_save :rewrite_links_in_body 33 before_create :set_page_title
34 before_save :rewrite_links_in_body
34 35
35 # Security 36 # Security
36 attr_accessible :title, :abstract, :body, :template_name, :published_at 37 attr_accessible :title, :abstract, :body, :template_name, :published_at
@@ -168,16 +169,21 @@ class Page < ActiveRecord::Base
168 169
169 private 170 private
170 171
172 def set_page_title
173 if title.nil?
174 title = "Untitled"
175 end
176 end
177
171 def rewrite_links_in_body 178 def rewrite_links_in_body
172 begin 179 begin
173 if self.body 180 if self.body
174 tmp_body = "<div>#{self.body}</div>" 181 tmp_body = "<div>#{self.body}</div>"
175 xml_string = XML::Parser.string( tmp_body ) 182 xml_string = XML::Parser.string( tmp_body )
176 xml_doc = xml_string.parse 183 xml_doc = xml_string.parse
177 links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") 184 links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]")
178 185 locales = I18n.available_locales.reject {|l| l == :root}
179 locales = I18n.available_locales.reject {|l| l == :root} 186
180
181 links.each do |link| 187 links.each do |link|
182 unless locales.include? link[:href].slice(1,2).to_sym 188 unless locales.include? link[:href].slice(1,2).to_sym
183 link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") 189 link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/")