From 144b18c5db61c53028177680295f3fc9d4e8711d Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 18 Jul 2009 18:17:06 +0200 Subject: 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 --- app/models/node.rb | 2 +- app/models/page.rb | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'app/models') 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 end def create_new_draft user - empty_page = self.pages.create + empty_page = self.pages.create! empty_page.user = user empty_page.save 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 belongs_to :user # Filter - before_save :rewrite_links_in_body + before_create :set_page_title + before_save :rewrite_links_in_body # Security attr_accessible :title, :abstract, :body, :template_name, :published_at @@ -168,16 +169,21 @@ class Page < ActiveRecord::Base private + def set_page_title + if title.nil? + title = "Untitled" + end + end + def rewrite_links_in_body begin if self.body - tmp_body = "
#{self.body}
" - xml_string = XML::Parser.string( tmp_body ) - xml_doc = xml_string.parse - links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") - - locales = I18n.available_locales.reject {|l| l == :root} - + tmp_body = "
#{self.body}
" + xml_string = XML::Parser.string( tmp_body ) + xml_doc = xml_string.parse + links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") + locales = I18n.available_locales.reject {|l| l == :root} + links.each do |link| unless locales.include? link[:href].slice(1,2).to_sym link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") -- cgit v1.3