Commit 8896f40cc723c60ee5d1ec1b4fc1355b06b90452

Authored by AntonioTerceiro
1 parent 0569d067

ActionItem65: better tests push some changes in the code



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@503 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/application_helper.rb
@@ -77,11 +77,9 @@ module ApplicationHelper @@ -77,11 +77,9 @@ module ApplicationHelper
77 content_tag('div', @virtual_community.name, :id => 'virtual_community_identification') 77 content_tag('div', @virtual_community.name, :id => 'virtual_community_identification')
78 end 78 end
79 79
80 - # TODO: test this helper  
81 - # TODO: remove the absolute path  
82 def link_to_cms(text, profile = nil, options = {}) 80 def link_to_cms(text, profile = nil, options = {})
83 profile ||= current_user.login 81 profile ||= current_user.login
84 - link_to text, profile_path(:controller => 'cms', :profile => profile), options 82 + link_to text, myprofile_path(:controller => 'cms', :profile => profile), options
85 end 83 end
86 84
87 def link_to_profile(text, profile = nil, options = {}) 85 def link_to_profile(text, profile = nil, options = {})
app/views/cms/index.rhtml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 </div> 3 </div>
4 4
5 <h1> 5 <h1>
6 - <%= _('Document List') %> 6 + <%= _('Articles') %>
7 <%= image_tag 'comatose/spinner.gif', :id=>'spinner', :align=>'absmiddle', :style=>'display:none;' %> 7 <%= image_tag 'comatose/spinner.gif', :id=>'spinner', :align=>'absmiddle', :style=>'display:none;' %>
8 </h1> 8 </h1>
9 9
@@ -13,6 +13,10 @@ @@ -13,6 +13,10 @@
13 <% end %> 13 <% end %>
14 </ul> 14 </ul>
15 15
  16 +<div>
  17 + <%= link_to _('New article'), :action => 'new' %>
  18 +</div>
  19 +
16 <div id="status"></div> 20 <div id="status"></div>
17 21
18 <%= javascript_tag "ComatoseList.init()" %> 22 <%= javascript_tag "ComatoseList.init()" %>
app/views/layouts/application.rhtml
1 <html> 1 <html>
2 <head> 2 <head>
  3 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
3 <%= javascript_include_tag :defaults %> 4 <%= javascript_include_tag :defaults %>
4 <%= design_all_header_tags %> 5 <%= design_all_header_tags %>
5 <%= javascript_include_tag 'cms' %> 6 <%= javascript_include_tag 'cms' %>
  7 + <%= javascript_include_tag 'menu' %>
6 <% if params[:controller] == 'cms' %> 8 <% if params[:controller] == 'cms' %>
7 <%= stylesheet_link_tag 'cms' %> 9 <%= stylesheet_link_tag 'cms' %>
8 <% end %> 10 <% end %>
9 <%= stylesheet_link_tag 'common' %> 11 <%= stylesheet_link_tag 'common' %>
  12 + <%= stylesheet_link_tag 'menu' %>
10 </head> 13 </head>
11 14
12 <body onload='javascript: if (document.forms[0] != null && document.forms[0].elements[0] != null) { document.forms[0].elements[0].focus(); }'> 15 <body onload='javascript: if (document.forms[0] != null && document.forms[0].elements[0] != null) { document.forms[0].elements[0].focus(); }'>
13 <%= image_tag 'loading.gif', :id => 'spinner', :style => "display:none; float:right;" %> 16 <%= image_tag 'loading.gif', :id => 'spinner', :style => "display:none; float:right;" %>
14 - <div id="wrap"> 17 + <div id="wrap" class='category_blue'>
15 <% unless flash[:notice].nil? %> 18 <% unless flash[:notice].nil? %>
16 <div id='notice'> 19 <div id='notice'>
17 <%= flash[:notice] %> 20 <%= flash[:notice] %>
config/routes.rb
@@ -54,7 +54,6 @@ ActionController::Routing::Routes.draw do |map| @@ -54,7 +54,6 @@ ActionController::Routing::Routes.draw do |map|
54 ## Public controllers 54 ## Public controllers
55 ###################################################### 55 ######################################################
56 56
57 - map.profile 'profile/:profile/:controller', :controller => 'profile'  
58 # *content viewing* 57 # *content viewing*
59 # XXX this route must come last so other routes have priority over it. 58 # XXX this route must come last so other routes have priority over it.
60 map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page' 59 map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page'
test/integration/manage_documents_test.rb
@@ -9,9 +9,12 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest @@ -9,9 +9,12 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest
9 9
10 login('ze', 'test') 10 login('ze', 'test')
11 11
  12 + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/cms' }
  13 +
12 get '/myprofile/ze/cms' 14 get '/myprofile/ze/cms'
13 assert_response :success 15 assert_response :success
14 16
  17 + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/cms/new' }
15 get '/myprofile/ze/cms/new' 18 get '/myprofile/ze/cms/new'
16 assert_response :success 19 assert_response :success
17 assert_tag :tag => 'form', :attributes => { :action => '/myprofile/ze/cms/new' } 20 assert_tag :tag => 'form', :attributes => { :action => '/myprofile/ze/cms/new' }
@@ -21,6 +24,7 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest @@ -21,6 +24,7 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest
21 24
22 follow_redirect! 25 follow_redirect!
23 assert_response :success 26 assert_response :success
  27 + assert_equal '/myprofile/ze/cms', path
24 28
25 assert_equal count + 1, Article.count 29 assert_equal count + 1, Article.count
26 30
@@ -39,18 +43,24 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest @@ -39,18 +43,24 @@ class ManageDocumentsTest &lt; ActionController::IntegrationTest
39 43
40 post "myprofile/ze/cms/edit/#{id}", :page => { :body => 'changed_body' } 44 post "myprofile/ze/cms/edit/#{id}", :page => { :body => 'changed_body' }
41 assert_response :redirect 45 assert_response :redirect
  46 + follow_redirect!
  47 + assert_equal '/myprofile/ze/cms', path
42 48
43 end 49 end
44 50
45 def test_removing_an_article 51 def test_removing_an_article
  52 +
46 article = Article.create!(:title => 'to be removed', :body => 'go to hell', :parent_id => Article.find_by_path('ze').id) 53 article = Article.create!(:title => 'to be removed', :body => 'go to hell', :parent_id => Article.find_by_path('ze').id)
47 count = Article.count 54 count = Article.count
48 55
49 get '/myprofile/ze/cms' 56 get '/myprofile/ze/cms'
50 assert_response :success 57 assert_response :success
  58 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/ze/cms/delete/#{article.id}" }
51 59
52 post "/myprofile/ze/cms/delete/#{article.id}" 60 post "/myprofile/ze/cms/delete/#{article.id}"
53 assert_response :redirect 61 assert_response :redirect
  62 + follow_redirect!
  63 + assert_equal '/myprofile/ze/cms', path
54 64
55 assert_raise ActiveRecord::RecordNotFound do 65 assert_raise ActiveRecord::RecordNotFound do
56 Article.find(article.id) 66 Article.find(article.id)
test/unit/profile_helper_test.rb
@@ -3,14 +3,14 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -3,14 +3,14 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 class ProfileHelperTest < Test::Unit::TestCase 3 class ProfileHelperTest < Test::Unit::TestCase
4 4
5 def setup 5 def setup
6 - @profile = Profile.new 6 + @profile = mock
7 @helper = mock 7 @helper = mock
8 helper.extend(ProfileHelper) 8 helper.extend(ProfileHelper)
9 end 9 end
10 attr_reader :profile, :helper 10 attr_reader :profile, :helper
11 11
12 def test_should_ignore_nil 12 def test_should_ignore_nil
13 - profile.stubs(:info).returns(nil) 13 + profile.expects(:info).returns(nil)
14 14
15 helper.expects(:content_tag) 15 helper.expects(:content_tag)
16 helper.expects(:_) 16 helper.expects(:_)