From f4aa37844caf926fa644ab3109aac54386aa2353 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 5 Apr 2010 14:50:27 -0300 Subject: [PATCH] Running the tests does not depend on compiling translations anymore. --- app/models/doc_section.rb | 8 ++++++-- lib/tasks/doc.rake | 4 ++++ lib/tasks/test.rake | 2 -- test/unit/doc_section_test.rb | 42 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/models/doc_section.rb b/app/models/doc_section.rb index 03269d9..2482e13 100644 --- a/app/models/doc_section.rb +++ b/app/models/doc_section.rb @@ -1,5 +1,9 @@ class DocSection < DocItem + def self.root_dir + @root_dir ||= File.join(RAILS_ROOT, 'doc', 'noosfero') + end + def items @items ||= load_items end @@ -36,7 +40,7 @@ class DocSection < DocItem def self.root(language = 'en') @root ||= {} - @root[language] ||= load(File.join(RAILS_ROOT, 'doc', 'noosfero'), language) + @root[language] ||= load(root_dir, language) end private @@ -44,7 +48,7 @@ class DocSection < DocItem attr_accessor :directory def self.load_dirs(language) - Dir.glob(File.join(RAILS_ROOT, 'doc', 'noosfero', '*')).select {|item| File.directory?(item) }.map do |dir| + Dir.glob(File.join(root_dir, '*')).select {|item| File.directory?(item) }.map do |dir| load(dir, language) end end diff --git a/lib/tasks/doc.rake b/lib/tasks/doc.rake index 53a3a9e..4f60ea5 100644 --- a/lib/tasks/doc.rake +++ b/lib/tasks/doc.rake @@ -86,18 +86,22 @@ namespace :noosfero do end end + desc "Build Noosfero online documentation" task :build => po4a_conf do sh "po4a #{po4a_conf}" end + desc "Cleans Noosfero online documentation" task :clean do sh 'rm -f doc/noosfero/*.xhtml' sh 'rm -f doc/noosfero/*/*.xhtml' rm_f po4a_conf end + desc "Rebuild Noosfero online documentation" task :rebuild => [:clean, :build] + desc "Translates Noosfero online documentation (does not touch PO files)" task :translate => english_xhtml do languages = Noosfero.locales.keys - ['en'] languages.each do |lang| diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake index 8389007..ed6dffd 100644 --- a/lib/tasks/test.rake +++ b/lib/tasks/test.rake @@ -1,6 +1,4 @@ task :default => [:test, :cucumber, :selenium] -task 'test:units' => 'noosfero:doc:translate' -task 'test:functionals' => 'noosfero:doc:translate' task :selenium do sh 'xvfb-run cucumber -p selenium' diff --git a/test/unit/doc_section_test.rb b/test/unit/doc_section_test.rb index d9074b4..d326ee6 100644 --- a/test/unit/doc_section_test.rb +++ b/test/unit/doc_section_test.rb @@ -1,6 +1,46 @@ require 'test_helper' class DocSectionTest < ActiveSupport::TestCase + + ROOT = File.join(Rails.root, "test", "tmp", "doc") + + def create_doc(section, topic, language, title) + dir = File.join(ROOT, section) + FileUtils.mkdir_p(dir) + File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| + f.puts "

#{title}

" + end + end + + def setup + FileUtils.mkdir_p(ROOT) + + # root + create_doc('', 'index', 'en', 'Root') + create_doc('', 'toc', 'en', 'Root') + # cms + create_doc('cms', 'index', 'en', 'Content Management') + create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') + create_doc('cms', 'toc', 'en', '') + create_doc('cms', 'toc', 'pt', '') + create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') + create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') + create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') + create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') + # user + create_doc('user', 'index', 'en', 'User features') + create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') + create_doc('user', 'toc', 'en', '') + create_doc('user', 'toc', 'pt', '') + create_doc('user', 'accepting-friends', 'en', 'Accepting friends') + + DocSection.stubs(:root_dir).returns(ROOT) + end + + def tear_down + FileUtils.rm_rf(ROOT) + end + should 'be a DocItem' do assert_kind_of DocItem, DocSection.new end @@ -87,7 +127,7 @@ class DocSectionTest < ActiveSupport::TestCase should 'load null section (the root)' do [nil, ''].each do |key| section = DocSection.find(nil) - assert_equal "#{RAILS_ROOT}/doc/noosfero", section.send(:directory) + assert_equal DocSection.root_dir, section.send(:directory) end end -- libgit2 0.21.2