Commit f33e035168fb28ebf7a0c3651412dc9c57355a4f
1 parent
bca9640c
Exists in
staging
and in
42 other branches
ActionItem4: integration test of tags management added
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@129 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
70 additions
and
4 deletions
Show diff stats
app/views/manage_tags/_a_tag.rhtml
| 1 | <li> | 1 | <li> |
| 2 | -<%= a_tag.id %> | ||
| 3 | <%= a_tag.name %> | 2 | <%= a_tag.name %> |
| 4 | <%= link_to _('Edit'), {:action => 'edit', :id => a_tag } %> | 3 | <%= link_to _('Edit'), {:action => 'edit', :id => a_tag } %> |
| 5 | <%= link_to _('Destroy'), {:action => 'destroy', :id => a_tag} %> | 4 | <%= link_to _('Destroy'), {:action => 'destroy', :id => a_tag} %> |
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 'tag[parent_id]', ['<option></option>'] + @parent_tags.map {|pt|"<option value=\"#{pt.id}\" #{'selected="selected"' if @tag.parent == pt} >" + pt.name + '</option>'} %> <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
| 1 | <h2> <%= _("Listing tags") %> </h2> | 1 | <h2> <%= _("Listing tags") %> </h2> |
| 2 | 2 | ||
| 3 | -<span><%= flash[:notice] %></span> | ||
| 4 | - | ||
| 5 | <ul> | 3 | <ul> |
| 6 | <%= render :partial => 'a_tag', :collection => @tags %> | 4 | <%= render :partial => 'a_tag', :collection => @tags %> |
| 7 | </ul> | 5 | </ul> |
| 8 | 6 | ||
| 9 | <h3> <%= _('Pending Tags') %> </h3> | 7 | <h3> <%= _('Pending Tags') %> </h3> |
| 8 | + | ||
| 10 | <ul> | 9 | <ul> |
| 11 | <%= render :partial => 'a_tag', :collection => @pending_tags %> | 10 | <%= render :partial => 'a_tag', :collection => @pending_tags %> |
| 12 | </ul> | 11 | </ul> |
| @@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
| 1 | +require "#{File.dirname(__FILE__)}/../test_helper" | ||
| 2 | + | ||
| 3 | +class ManageTagsTest < ActionController::IntegrationTest | ||
| 4 | + fixtures :tags, :profiles, :users, :virtual_communities, :domains, :boxes, :blocks | ||
| 5 | + | ||
| 6 | + def test_tags_create_edit_destroy | ||
| 7 | + get '/admin/manage_tags' | ||
| 8 | + assert_response :redirect | ||
| 9 | + | ||
| 10 | + follow_redirect! | ||
| 11 | + assert_response :success | ||
| 12 | + assert_equal '/admin/manage_tags/list', path | ||
| 13 | + assert_tag :tag => 'a', :attributes => {:href => '/admin/manage_tags/new'} | ||
| 14 | + | ||
| 15 | + get '/admin/manage_tags/new' | ||
| 16 | + assert_response :success | ||
| 17 | + assert_tag :tag => 'input', :attributes => {:name => 'tag[name]'} | ||
| 18 | + assert_tag :tag => 'select', :attributes => {:name => 'tag[parent_id]'} | ||
| 19 | + assert_tag :tag => 'input', :attributes => {:name => 'tag[pending]'} | ||
| 20 | + | ||
| 21 | + post '/admin/manage_tags/create', :tag => { 'name' => 'new_tag', 'pending' => 'false', 'parent_id' => '0'} | ||
| 22 | + assert_response :redirect | ||
| 23 | + | ||
| 24 | + follow_redirect! | ||
| 25 | + assert_response :success | ||
| 26 | + assert_equal '/admin/manage_tags/list', path | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | +end |
| @@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | +require 'extended_tag.rb' | ||
| 3 | + | ||
| 4 | +class UserTest < Test::Unit::TestCase | ||
| 5 | + | ||
| 6 | + def test_find_without_pendings | ||
| 7 | + tag1 = Tag.create(:name => 'pending_tag', :pending => true) | ||
| 8 | + tag2 = Tag.create(:name => 'approved_tag', :pending => false) | ||
| 9 | + assert_nothing_raised {Tag.find(tag2.id)} | ||
| 10 | + assert_raise(ActiveRecord::RecordNotFound) {Tag.find(tag1.id)} | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def test_find_pendings | ||
| 14 | + tag1 = Tag.create(:name => 'pending_tag', :pending => true) | ||
| 15 | + tag2 = Tag.create(:name => 'approved_tag', :pending => false) | ||
| 16 | + assert Tag.find_pendings.include?(tag1) | ||
| 17 | + assert (not Tag.find_pendings.include?(tag2)) | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | + def test_parent_candidates | ||
| 21 | + tag1 = Tag.create(:name => 'parent_tag') | ||
| 22 | + tag2 = Tag.create(:name => 'child_tag', :parent => tag1) | ||
| 23 | + assert ( not tag1.parent_candidates.include?(tag2) ) | ||
| 24 | + assert tag2.parent_candidates.include?(tag1) | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def test_descendents | ||
| 28 | + tag1 = Tag.create(:name => 'parent_tag') | ||
| 29 | + tag2 = Tag.create(:name => 'child_tag', :parent => tag1) | ||
| 30 | + tag3 = Tag.create(:name => 'grand_tag', :parent => tag2) | ||
| 31 | + assert (not tag2.descendents.include?(tag1)) | ||
| 32 | + assert (not tag1.descendents.include?(tag1)) | ||
| 33 | + assert tag1.descendents.include?(tag2) | ||
| 34 | + assert tag1.descendents.include?(tag3) | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | +end |