Commit f33e035168fb28ebf7a0c3651412dc9c57355a4f

Authored by MoisesMachado
1 parent bca9640c

ActionItem4: integration test of tags management added

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@129 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/manage_tags_helper.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +module ManageTagsHelper
  2 +end
... ...
app/views/manage_tags/_a_tag.rhtml
1 1 <li>
2   -<%= a_tag.id %>
3 2 <%= a_tag.name %>
4 3 <%= link_to _('Edit'), {:action => 'edit', :id => a_tag } %>
5 4 <%= link_to _('Destroy'), {:action => 'destroy', :id => a_tag} %>
... ...
app/views/manage_tags/_form.rhtml
1 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 3 Pending: <%= check_box 'tag', 'pending' %> <br>
... ...
app/views/manage_tags/list.rhtml
1 1 <h2> <%= _("Listing tags") %> </h2>
2 2  
3   -<span><%= flash[:notice] %></span>
4   -
5 3 <ul>
6 4 <%= render :partial => 'a_tag', :collection => @tags %>
7 5 </ul>
8 6  
9 7 <h3> <%= _('Pending Tags') %> </h3>
  8 +
10 9 <ul>
11 10 <%= render :partial => 'a_tag', :collection => @pending_tags %>
12 11 </ul>
... ...
test/integration/manage_tags_test.rb 0 → 100644
... ... @@ -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
... ...
test/unit/extended_tag_test.rb 0 → 100644
... ... @@ -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
... ...