Commit 947cf3770c68cf9457b73fae7268c6d23c98dd43

Authored by AntonioTerceiro
1 parent cf1897a9

ActionItem18: writing integration tests for cms controller



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@443 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/account_controller.rb
... ... @@ -72,4 +72,13 @@ class AccountController < ApplicationController
72 72 end
73 73 end
74 74  
  75 + protected
  76 +
  77 + before_filter :load_profile_for_user
  78 + def load_profile_for_user
  79 + return unless logged_in?
  80 + @profile = current_user.person
  81 + end
  82 +
  83 +
75 84 end
... ...
test/fixtures/comatose_pages.yml
... ... @@ -2,20 +2,24 @@ root:
2 2 id: 1
3 3 title: Root page
4 4 slug:
  5 + type: Article
5 6 ze:
6 7 id: 2
7 8 title: Ze homepage
8 9 slug: ze
9 10 full_path: 'ze'
  11 + type: Article
10 12 ze_curriculum:
11 13 id: 3
12 14 title: Ze curriculum
13 15 parent_id: 2
14 16 slug: curriculum
15 17 full_path: 'ze/curriculum'
  18 + type: Article
16 19 ze_contact:
17 20 id: 4
18 21 title: Ze contact info
19 22 parent_id: 2
20 23 slug: contact
21 24 full_path: 'ze/contact'
  25 + type: Article
... ...
test/integration/manage_documents_test.rb 0 → 100644
... ... @@ -0,0 +1,62 @@
  1 +require "#{File.dirname(__FILE__)}/../test_helper"
  2 +
  3 +class ManageDocumentsTest < ActionController::IntegrationTest
  4 +
  5 + fixtures :users, :profiles, :comatose_pages, :domains, :virtual_communities
  6 +
  7 + def test_creation_of_a_new_article
  8 + count = Article.count
  9 +
  10 + login('ze', 'test')
  11 +
  12 + get '/cms/ze'
  13 + assert_response :success
  14 +
  15 + get '/cms/ze/new'
  16 + assert_response :success
  17 + assert_tag :tag => 'form', :attributes => { :action => '/cms/ze/new' }
  18 +
  19 + post '/cms/ze/new', :page => { :title => 'my new article', :body => 'this is the text of my new article' , :parent_id => Article.find_by_path('ze').id }
  20 + assert_response :redirect
  21 +
  22 + follow_redirect!
  23 + assert_response :success
  24 +
  25 + assert_equal count + 1, Article.count
  26 +
  27 + end
  28 +
  29 + def test_update_of_an_existing_article
  30 + login('ze', 'test')
  31 +
  32 + get '/cms/ze'
  33 + assert_response :success
  34 +
  35 + id = Comatose::Page.find_by_path('ze').id
  36 + get "cms/ze/edit/#{id}"
  37 + assert_response :success
  38 + assert_tag :tag => 'form', :attributes => { :action => "/cms/ze/edit/#{id}" }
  39 +
  40 + post "cms/ze/edit/#{id}", :page => { :body => 'changed_body' }
  41 + assert_response :redirect
  42 +
  43 + end
  44 +
  45 + def test_removing_an_article
  46 + article = Article.create!(:title => 'to be removed', :body => 'go to hell', :parent_id => Article.find_by_path('ze').id)
  47 + count = Article.count
  48 +
  49 + get '/cms/ze'
  50 + assert_response :success
  51 +
  52 + post "/cms/ze/delete/#{article.id}"
  53 + assert_response :redirect
  54 +
  55 + assert_raise ActiveRecord::RecordNotFound do
  56 + Article.find(article.id)
  57 + end
  58 + end
  59 +
  60 + # FIXME: add tests for page reordering
  61 +
  62 +end
... ...