Commit 9e9bd5c87b398ddb43f782d540f1875b76a9d9b7
1 parent
83e70c2f
Exists in
master
and in
23 other branches
ActionItem4: integration tests and user documentation added
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@140 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
71 additions
and
19 deletions
Show diff stats
app/views/manage_tags/_a_tag.rhtml
| 1 | <li> | 1 | <li> |
| 2 | <%= a_tag.name %> | 2 | <%= a_tag.name %> |
| 3 | <%= link_to _('Edit'), {:action => 'edit', :id => a_tag } %> | 3 | <%= link_to _('Edit'), {:action => 'edit', :id => a_tag } %> |
| 4 | +<%= help _('Edit the attributes of this tag (name, parent and pending status)') %> | ||
| 4 | <%= link_to _('Destroy'), {:action => 'destroy', :id => a_tag} %> | 5 | <%= link_to _('Destroy'), {:action => 'destroy', :id => a_tag} %> |
| 6 | +<%= help _('Erase the tag and all its subtags but not the tagged content') %> | ||
| 5 | <%= link_to _('Filter by this tag'), {:action => 'list', :parent => a_tag} %> | 7 | <%= link_to _('Filter by this tag'), {:action => 'list', :parent => a_tag} %> |
| 6 | -<%= link_to _('Approve tag'), {:action => 'approve', :id => a_tag} if a_tag.pending? %> <ul> | 8 | +<%= help _('List only the tags that are subtags of this tag') %> |
| 9 | +<% if a_tag.pending? %> | ||
| 10 | + <%= link_to _('Approve tag'), {:action => 'approve', :id => a_tag} %> | ||
| 11 | + <%= help _('Approve this tag so content can be tagged with it and subtags of it can br created') %> | ||
| 12 | +<% end %> | ||
| 13 | +<ul> | ||
| 7 | <%= render :partial => 'a_tag', :collection => a_tag.children.select{|t|!t.pending?} %> | 14 | <%= render :partial => 'a_tag', :collection => a_tag.children.select{|t|!t.pending?} %> |
| 8 | </ul> | 15 | </ul> |
| 9 | </li> | 16 | </li> |
app/views/manage_tags/_form.rhtml
| 1 | Name: <%= text_field 'tag', 'name' %> <br> | 1 | Name: <%= text_field 'tag', 'name' %> <br> |
| 2 | -Parent tag: <%= select("tag", "parent_id", @parent_tags.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) %> <br> | 2 | +Parent tag: <%= select('tag', 'parent_id', @parent_tags.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) %> <br> |
| 3 | Pending: <%= check_box 'tag', 'pending' %> <br> | 3 | Pending: <%= check_box 'tag', 'pending' %> <br> |
app/views/manage_tags/list.rhtml
| @@ -10,5 +10,9 @@ | @@ -10,5 +10,9 @@ | ||
| 10 | <%= render :partial => 'a_tag', :collection => @pending_tags %> | 10 | <%= render :partial => 'a_tag', :collection => @pending_tags %> |
| 11 | </ul> | 11 | </ul> |
| 12 | 12 | ||
| 13 | +<%= link_to _('Top'), {:action => 'list'} if @parent %> | ||
| 14 | +<%= help _('Go to the top view of the tags') %> | ||
| 13 | <%= link_to _('Up'), {:action => 'list', :parent => @parent.parent} if @parent %> | 15 | <%= link_to _('Up'), {:action => 'list', :parent => @parent.parent} if @parent %> |
| 16 | +<% help _('Filter by the parent of the actual tag') %> | ||
| 14 | <%= link_to _('New tag'), {:action => 'new'} %> | 17 | <%= link_to _('New tag'), {:action => 'new'} %> |
| 18 | +<%= help _('Create a new tag') %> |
test/functional/manage_tags_controller_test.rb
| @@ -6,7 +6,7 @@ class ManageTagsController; def rescue_action(e) raise e end; end | @@ -6,7 +6,7 @@ class ManageTagsController; def rescue_action(e) raise e end; end | ||
| 6 | 6 | ||
| 7 | class ManageTagsControllerTest < Test::Unit::TestCase | 7 | class ManageTagsControllerTest < Test::Unit::TestCase |
| 8 | 8 | ||
| 9 | - fixtures :tags | 9 | + fixtures :profiles, :boxes, :blocks, :domains |
| 10 | 10 | ||
| 11 | def setup | 11 | def setup |
| 12 | @controller = ManageTagsController.new | 12 | @controller = ManageTagsController.new |
| @@ -30,13 +30,18 @@ class ManageTagsControllerTest < Test::Unit::TestCase | @@ -30,13 +30,18 @@ class ManageTagsControllerTest < Test::Unit::TestCase | ||
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | def test_scoped_list | 32 | def test_scoped_list |
| 33 | - assert_nothing_raised { Tag.find(1) } | ||
| 34 | - get :list, :parent => Tag.find(1) | 33 | + parent_tag = Tag.create(:name => 'parent_tag') |
| 34 | + child_tag = Tag.create(:name => 'child_tag', :parent => parent_tag) | ||
| 35 | + orphan_tag = Tag.create(:name => 'orphan_tag') | ||
| 36 | + get :list, :parent => parent_tag | ||
| 35 | assert_response :success | 37 | assert_response :success |
| 36 | assert_template 'list' | 38 | assert_template 'list' |
| 37 | assert_not_nil assigns(:parent), 'the list should be scoped' | 39 | assert_not_nil assigns(:parent), 'the list should be scoped' |
| 38 | assert_not_nil assigns(:tags) | 40 | assert_not_nil assigns(:tags) |
| 39 | assert_not_nil assigns(:pending_tags) | 41 | assert_not_nil assigns(:pending_tags) |
| 42 | + assert assigns(:tags).include?(child_tag) | ||
| 43 | + assert (not assigns(:tags).include?(orphan_tag)) | ||
| 44 | + | ||
| 40 | end | 45 | end |
| 41 | 46 | ||
| 42 | def test_new | 47 | def test_new |
| @@ -61,43 +66,44 @@ class ManageTagsControllerTest < Test::Unit::TestCase | @@ -61,43 +66,44 @@ class ManageTagsControllerTest < Test::Unit::TestCase | ||
| 61 | end | 66 | end |
| 62 | 67 | ||
| 63 | def test_edit | 68 | def test_edit |
| 64 | - assert_nothing_raised { Tag.find(1) } | ||
| 65 | - get :edit, :id => 1 | 69 | + tag_to_edit = Tag.create(:name => 'tag_to_edit') |
| 70 | + get :edit, :id => tag_to_edit.id | ||
| 66 | assert assigns(:tag) | 71 | assert assigns(:tag) |
| 67 | assert assigns(:parent_tags) | 72 | assert assigns(:parent_tags) |
| 68 | end | 73 | end |
| 69 | 74 | ||
| 70 | def test_update | 75 | def test_update |
| 71 | - assert_nothing_raised { Tag.find(1) } | ||
| 72 | - post :update, :id => 1, :tag => {:name => 'altered_tag'} | 76 | + tag_to_update = Tag.create(:name => 'tag_to_update') |
| 77 | + post :update, :id => tag_to_update.id, :tag => {:name => 'altered_tag'} | ||
| 73 | assert_response :redirect | 78 | assert_response :redirect |
| 74 | assert_redirected_to :action => 'list' | 79 | assert_redirected_to :action => 'list' |
| 75 | assert assigns(:tag) | 80 | assert assigns(:tag) |
| 81 | + assert_equal 'altered_tag', assigns(:tag).name | ||
| 76 | end | 82 | end |
| 77 | 83 | ||
| 78 | def test_update_wrong | 84 | def test_update_wrong |
| 79 | - assert_nothing_raised { Tag.find(1) } | ||
| 80 | - post :update, :id => 1, :tag => {:name => ''} | 85 | + wrong_tag = Tag.create(:name => 'wrong_tag') |
| 86 | + post :update, :id => wrong_tag, :tag => {:name => ''} | ||
| 81 | assert_response :success | 87 | assert_response :success |
| 82 | assert_template 'edit' | 88 | assert_template 'edit' |
| 83 | assert assigns(:parent_tags) | 89 | assert assigns(:parent_tags) |
| 84 | end | 90 | end |
| 85 | 91 | ||
| 86 | def test_destroy | 92 | def test_destroy |
| 87 | - assert_nothing_raised { Tag.find(1) } | ||
| 88 | - post :destroy, :id => 1 | 93 | + destroyed_tag = Tag.create(:name => 'tag_to_destroy') |
| 94 | + post :destroy, :id => destroyed_tag.id | ||
| 89 | assert_response :redirect | 95 | assert_response :redirect |
| 90 | assert_redirected_to :action => 'list' | 96 | assert_redirected_to :action => 'list' |
| 91 | assert_not_nil flash[:notice] | 97 | assert_not_nil flash[:notice] |
| 92 | - assert_raise(ActiveRecord::RecordNotFound) { Tag.find(1) } | 98 | + assert_raise(ActiveRecord::RecordNotFound) { Tag.find(destroyed_tag.id) } |
| 93 | end | 99 | end |
| 94 | 100 | ||
| 95 | def test_approve | 101 | def test_approve |
| 96 | - assert_nothing_raised { Tag.find_with_pendings(4) } | ||
| 97 | - assert Tag.find_with_pendings(4).pending? | ||
| 98 | - post :approve, :id => 4 | 102 | + pending_tag = Tag.create(:name => 'pending_tag', :pending => true) |
| 103 | + assert pending_tag.pending? | ||
| 104 | + post :approve, :id => pending_tag.id | ||
| 99 | assert_response :redirect | 105 | assert_response :redirect |
| 100 | assert_redirected_to :action => 'list' | 106 | assert_redirected_to :action => 'list' |
| 101 | - assert ( not Tag.find_with_pendings(4).pending? ) | 107 | + assert ( not Tag.find_with_pendings(pending_tag.id).pending? ) |
| 102 | end | 108 | end |
| 103 | end | 109 | end |
test/integration/manage_tags_test.rb
| 1 | require "#{File.dirname(__FILE__)}/../test_helper" | 1 | require "#{File.dirname(__FILE__)}/../test_helper" |
| 2 | 2 | ||
| 3 | class ManageTagsTest < ActionController::IntegrationTest | 3 | class ManageTagsTest < ActionController::IntegrationTest |
| 4 | - fixtures :tags, :profiles, :users, :virtual_communities, :domains, :boxes, :blocks | 4 | + fixtures :tags, :profiles, :boxes, :blocks |
| 5 | 5 | ||
| 6 | def test_tags_create_edit_destroy | 6 | def test_tags_create_edit_destroy |
| 7 | get '/admin/manage_tags' | 7 | get '/admin/manage_tags' |
| @@ -24,6 +24,41 @@ class ManageTagsTest < ActionController::IntegrationTest | @@ -24,6 +24,41 @@ class ManageTagsTest < ActionController::IntegrationTest | ||
| 24 | follow_redirect! | 24 | follow_redirect! |
| 25 | assert_response :success | 25 | assert_response :success |
| 26 | assert_equal '/admin/manage_tags/list', path | 26 | assert_equal '/admin/manage_tags/list', path |
| 27 | + assert_tag :tag => 'a', :attributes => {:href => %r[/admin/manage_tags/edit]} | ||
| 28 | + | ||
| 29 | + get '/admin/manage_tags/edit', :id => 1 | ||
| 30 | + assert_response :success | ||
| 31 | + assert_tag :tag => 'input', :attributes => {:name => 'tag[name]'} | ||
| 32 | + assert_tag :tag => 'select', :attributes => {:name => 'tag[parent_id]'} | ||
| 33 | + assert_tag :tag => 'input', :attributes => {:name => 'tag[pending]'} | ||
| 34 | + | ||
| 35 | + post '/admin/manage_tags/update', :id => 1, :tag => {:name => 'bla_tag'} | ||
| 36 | + assert_response :redirect | ||
| 37 | + | ||
| 38 | + follow_redirect! | ||
| 39 | + assert_response :success | ||
| 40 | + assert_equal '/admin/manage_tags/list', path | ||
| 41 | + assert_tag :tag => 'a', :attributes => {:href => %r[/admin/manage_tags/destroy]} | ||
| 42 | + | ||
| 43 | + post '/admin/manage_tags/destroy', :id => 1 | ||
| 44 | + assert_response :redirect | ||
| 45 | + | ||
| 46 | + follow_redirect! | ||
| 47 | + assert_response :success | ||
| 48 | + assert_equal '/admin/manage_tags/list', path | ||
| 49 | + end | ||
| 50 | + | ||
| 51 | + def test_approve_tag | ||
| 52 | + get '/admin/manage_tags/list' | ||
| 53 | + assert_response :success | ||
| 54 | + assert_tag :tag => 'a', :attributes => {:href => %r[/admin/manage_tags/approve]} | ||
| 55 | + | ||
| 56 | + post '/admin/manage_tags/approve', :id => 5 | ||
| 57 | + assert_response :redirect | ||
| 58 | + | ||
| 59 | + follow_redirect! | ||
| 60 | + assert_response :success | ||
| 61 | + assert_equal '/admin/manage_tags/list', path | ||
| 27 | end | 62 | end |
| 28 | 63 | ||
| 29 | end | 64 | end |