Commit f4aa37844caf926fa644ab3109aac54386aa2353
1 parent
53a345b6
Exists in
master
and in
29 other branches
Running the tests does not depend on compiling translations anymore.
Showing
4 changed files
with
51 additions
and
5 deletions
Show diff stats
app/models/doc_section.rb
1 | class DocSection < DocItem | 1 | class DocSection < DocItem |
2 | 2 | ||
3 | + def self.root_dir | ||
4 | + @root_dir ||= File.join(RAILS_ROOT, 'doc', 'noosfero') | ||
5 | + end | ||
6 | + | ||
3 | def items | 7 | def items |
4 | @items ||= load_items | 8 | @items ||= load_items |
5 | end | 9 | end |
@@ -36,7 +40,7 @@ class DocSection < DocItem | @@ -36,7 +40,7 @@ class DocSection < DocItem | ||
36 | 40 | ||
37 | def self.root(language = 'en') | 41 | def self.root(language = 'en') |
38 | @root ||= {} | 42 | @root ||= {} |
39 | - @root[language] ||= load(File.join(RAILS_ROOT, 'doc', 'noosfero'), language) | 43 | + @root[language] ||= load(root_dir, language) |
40 | end | 44 | end |
41 | 45 | ||
42 | private | 46 | private |
@@ -44,7 +48,7 @@ class DocSection < DocItem | @@ -44,7 +48,7 @@ class DocSection < DocItem | ||
44 | attr_accessor :directory | 48 | attr_accessor :directory |
45 | 49 | ||
46 | def self.load_dirs(language) | 50 | def self.load_dirs(language) |
47 | - Dir.glob(File.join(RAILS_ROOT, 'doc', 'noosfero', '*')).select {|item| File.directory?(item) }.map do |dir| | 51 | + Dir.glob(File.join(root_dir, '*')).select {|item| File.directory?(item) }.map do |dir| |
48 | load(dir, language) | 52 | load(dir, language) |
49 | end | 53 | end |
50 | end | 54 | end |
lib/tasks/doc.rake
@@ -86,18 +86,22 @@ namespace :noosfero do | @@ -86,18 +86,22 @@ namespace :noosfero do | ||
86 | end | 86 | end |
87 | end | 87 | end |
88 | 88 | ||
89 | + desc "Build Noosfero online documentation" | ||
89 | task :build => po4a_conf do | 90 | task :build => po4a_conf do |
90 | sh "po4a #{po4a_conf}" | 91 | sh "po4a #{po4a_conf}" |
91 | end | 92 | end |
92 | 93 | ||
94 | + desc "Cleans Noosfero online documentation" | ||
93 | task :clean do | 95 | task :clean do |
94 | sh 'rm -f doc/noosfero/*.xhtml' | 96 | sh 'rm -f doc/noosfero/*.xhtml' |
95 | sh 'rm -f doc/noosfero/*/*.xhtml' | 97 | sh 'rm -f doc/noosfero/*/*.xhtml' |
96 | rm_f po4a_conf | 98 | rm_f po4a_conf |
97 | end | 99 | end |
98 | 100 | ||
101 | + desc "Rebuild Noosfero online documentation" | ||
99 | task :rebuild => [:clean, :build] | 102 | task :rebuild => [:clean, :build] |
100 | 103 | ||
104 | + desc "Translates Noosfero online documentation (does not touch PO files)" | ||
101 | task :translate => english_xhtml do | 105 | task :translate => english_xhtml do |
102 | languages = Noosfero.locales.keys - ['en'] | 106 | languages = Noosfero.locales.keys - ['en'] |
103 | languages.each do |lang| | 107 | languages.each do |lang| |
lib/tasks/test.rake
1 | task :default => [:test, :cucumber, :selenium] | 1 | task :default => [:test, :cucumber, :selenium] |
2 | -task 'test:units' => 'noosfero:doc:translate' | ||
3 | -task 'test:functionals' => 'noosfero:doc:translate' | ||
4 | 2 | ||
5 | task :selenium do | 3 | task :selenium do |
6 | sh 'xvfb-run cucumber -p selenium' | 4 | sh 'xvfb-run cucumber -p selenium' |
test/unit/doc_section_test.rb
1 | require 'test_helper' | 1 | require 'test_helper' |
2 | 2 | ||
3 | class DocSectionTest < ActiveSupport::TestCase | 3 | class DocSectionTest < ActiveSupport::TestCase |
4 | + | ||
5 | + ROOT = File.join(Rails.root, "test", "tmp", "doc") | ||
6 | + | ||
7 | + def create_doc(section, topic, language, title) | ||
8 | + dir = File.join(ROOT, section) | ||
9 | + FileUtils.mkdir_p(dir) | ||
10 | + File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| | ||
11 | + f.puts "<h1>#{title}</h1>" | ||
12 | + end | ||
13 | + end | ||
14 | + | ||
15 | + def setup | ||
16 | + FileUtils.mkdir_p(ROOT) | ||
17 | + | ||
18 | + # root | ||
19 | + create_doc('', 'index', 'en', 'Root') | ||
20 | + create_doc('', 'toc', 'en', 'Root') | ||
21 | + # cms | ||
22 | + create_doc('cms', 'index', 'en', 'Content Management') | ||
23 | + create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') | ||
24 | + create_doc('cms', 'toc', 'en', '') | ||
25 | + create_doc('cms', 'toc', 'pt', '') | ||
26 | + create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') | ||
27 | + create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') | ||
28 | + create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') | ||
29 | + create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') | ||
30 | + # user | ||
31 | + create_doc('user', 'index', 'en', 'User features') | ||
32 | + create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') | ||
33 | + create_doc('user', 'toc', 'en', '') | ||
34 | + create_doc('user', 'toc', 'pt', '') | ||
35 | + create_doc('user', 'accepting-friends', 'en', 'Accepting friends') | ||
36 | + | ||
37 | + DocSection.stubs(:root_dir).returns(ROOT) | ||
38 | + end | ||
39 | + | ||
40 | + def tear_down | ||
41 | + FileUtils.rm_rf(ROOT) | ||
42 | + end | ||
43 | + | ||
4 | should 'be a DocItem' do | 44 | should 'be a DocItem' do |
5 | assert_kind_of DocItem, DocSection.new | 45 | assert_kind_of DocItem, DocSection.new |
6 | end | 46 | end |
@@ -87,7 +127,7 @@ class DocSectionTest < ActiveSupport::TestCase | @@ -87,7 +127,7 @@ class DocSectionTest < ActiveSupport::TestCase | ||
87 | should 'load null section (the root)' do | 127 | should 'load null section (the root)' do |
88 | [nil, ''].each do |key| | 128 | [nil, ''].each do |key| |
89 | section = DocSection.find(nil) | 129 | section = DocSection.find(nil) |
90 | - assert_equal "#{RAILS_ROOT}/doc/noosfero", section.send(:directory) | 130 | + assert_equal DocSection.root_dir, section.send(:directory) |
91 | end | 131 | end |
92 | end | 132 | end |
93 | 133 |