Commit 947cf3770c68cf9457b73fae7268c6d23c98dd43
1 parent
cf1897a9
Exists in
master
and in
29 other branches
ActionItem18: writing integration tests for cms controller
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@443 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
75 additions
and
0 deletions
Show diff stats
app/controllers/account_controller.rb
@@ -72,4 +72,13 @@ class AccountController < ApplicationController | @@ -72,4 +72,13 @@ class AccountController < ApplicationController | ||
72 | end | 72 | end |
73 | end | 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 | end | 84 | end |
test/fixtures/comatose_pages.yml
@@ -2,20 +2,24 @@ root: | @@ -2,20 +2,24 @@ root: | ||
2 | id: 1 | 2 | id: 1 |
3 | title: Root page | 3 | title: Root page |
4 | slug: | 4 | slug: |
5 | + type: Article | ||
5 | ze: | 6 | ze: |
6 | id: 2 | 7 | id: 2 |
7 | title: Ze homepage | 8 | title: Ze homepage |
8 | slug: ze | 9 | slug: ze |
9 | full_path: 'ze' | 10 | full_path: 'ze' |
11 | + type: Article | ||
10 | ze_curriculum: | 12 | ze_curriculum: |
11 | id: 3 | 13 | id: 3 |
12 | title: Ze curriculum | 14 | title: Ze curriculum |
13 | parent_id: 2 | 15 | parent_id: 2 |
14 | slug: curriculum | 16 | slug: curriculum |
15 | full_path: 'ze/curriculum' | 17 | full_path: 'ze/curriculum' |
18 | + type: Article | ||
16 | ze_contact: | 19 | ze_contact: |
17 | id: 4 | 20 | id: 4 |
18 | title: Ze contact info | 21 | title: Ze contact info |
19 | parent_id: 2 | 22 | parent_id: 2 |
20 | slug: contact | 23 | slug: contact |
21 | full_path: 'ze/contact' | 24 | full_path: 'ze/contact' |
25 | + type: Article |
@@ -0,0 +1,62 @@ | @@ -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 |