Commit dd1be9921823e5fb8aa1a52b9649d1d888c80670
1 parent
864d6099
Exists in
master
and in
29 other branches
ActionItem70: writing functional tests
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@529 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
52 additions
and
4 deletions
Show diff stats
app/views/categories/_category.rhtml
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <div> |
6 | 6 | <%= link_to _('Add subcategory'), :action => 'new', :parent_id => category %> |
7 | 7 | <%= link_to _('Edit'), :action => 'edit', :id => category %> |
8 | - <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :post => true, :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %> | |
8 | + <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :method => 'post', :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %> | |
9 | 9 | </div> |
10 | 10 | </div> |
11 | 11 | ... | ... |
app/views/categories/index.rhtml
test/functional/categories_controller_test.rb
... | ... | @@ -5,14 +5,61 @@ require 'categories_controller' |
5 | 5 | class CategoriesController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class CategoriesControllerTest < Test::Unit::TestCase |
8 | + | |
8 | 9 | def setup |
9 | 10 | @controller = CategoriesController.new |
10 | 11 | @request = ActionController::TestRequest.new |
11 | 12 | @response = ActionController::TestResponse.new |
13 | + | |
14 | + @env = Environment.create!(:name => "My test environment") | |
15 | + Environment.stubs(:default).returns(env) | |
16 | + assert (@cat1 = env.categories.create(:name => 'a test category')) | |
17 | + assert (@cat1 = env.categories.create(:name => 'another category')) | |
18 | + end | |
19 | + attr_reader :env, :cat1, :cat2 | |
20 | + | |
21 | + def test_index | |
22 | + get :index | |
23 | + assert_kind_of Array, assigns(:categories) | |
24 | + assert_tag :tag => 'a', :attributes => { :href => '/admin/categories/new'} | |
25 | + end | |
26 | + | |
27 | + def test_edit | |
28 | + cat = Category.new | |
29 | + env.categories.expects(:find).with('1').returns(cat) | |
30 | + get :edit, :id => '1' | |
31 | + assert_response :success | |
32 | + assert_template 'edit' | |
33 | + assert_equal cat, assigns(:category) | |
34 | + end | |
35 | + | |
36 | + def test_edit_save | |
37 | + post :edit, :id => cat1.id, :category => { :name => 'new name for category' } | |
38 | + assert_redirected_to :action => 'index' | |
39 | + assert_equal 'new name for category', Category.find(cat1.id).name | |
12 | 40 | end |
13 | 41 | |
14 | - # Replace this with your real tests. | |
15 | - def test_truth | |
16 | - assert true | |
42 | + def test_new | |
43 | + cat = Category.new | |
44 | + Category.expects(:new).returns(cat) | |
45 | + get :new | |
17 | 46 | end |
47 | + | |
48 | + def test_new_save | |
49 | + assert_difference Category, :count do | |
50 | + post :new, :category => { :name => 'a new category' } | |
51 | + assert_redirected_to :action => 'index' | |
52 | + end | |
53 | + end | |
54 | + | |
55 | + def test_remove | |
56 | + cat = Category.create!(:name => 'a category to be removed', :environment_id => env.id) | |
57 | + post :remove, :id => cat.id | |
58 | + assert_redirected_to :action => 'index' | |
59 | + assert_raise ActiveRecord::RecordNotFound do | |
60 | + Category.find(cat.id) | |
61 | + end | |
62 | + end | |
63 | + | |
64 | + | |
18 | 65 | end | ... | ... |