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