Commit 71b98ac5f53730ae103b7cd86438d6a8473d06a5
1 parent
e6aebf76
Exists in
master
and in
22 other branches
ActionItem6: Integration tests added
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@354 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
97 additions
and
1 deletions
Show diff stats
app/controllers/enterprise_controller.rb
| @@ -69,7 +69,7 @@ class EnterpriseController < ApplicationController | @@ -69,7 +69,7 @@ class EnterpriseController < ApplicationController | ||
| 69 | end | 69 | end |
| 70 | 70 | ||
| 71 | def search | 71 | def search |
| 72 | - @tagged_enterprises = Enterprise.find_tagged_with(params[:query]) | 72 | + @tagged_enterprises = Enterprise.search(params[:query]) |
| 73 | end | 73 | end |
| 74 | 74 | ||
| 75 | def activate | 75 | def activate |
app/models/profile.rb
| @@ -56,4 +56,8 @@ class Profile < ActiveRecord::Base | @@ -56,4 +56,8 @@ class Profile < ActiveRecord::Base | ||
| 56 | self.virtual_community ||= VirtualCommunity.default | 56 | self.virtual_community ||= VirtualCommunity.default |
| 57 | end | 57 | end |
| 58 | 58 | ||
| 59 | + def self.search(term) | ||
| 60 | + find_tagged_with(term) + find_all_by_name(term) | ||
| 61 | + end | ||
| 62 | + | ||
| 59 | end | 63 | end |
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | +require "#{File.dirname(__FILE__)}/../test_helper" | ||
| 2 | + | ||
| 3 | +class EditEnterpriseTest < ActionController::IntegrationTest | ||
| 4 | + all_fixtures | ||
| 5 | + def test_edit_an_enterprise | ||
| 6 | + get '/admin/enterprise' | ||
| 7 | + assert_response :redirect | ||
| 8 | + | ||
| 9 | + login('ze', 'test') | ||
| 10 | + | ||
| 11 | + get '/admin/enterprise' | ||
| 12 | + assert_response :redirect | ||
| 13 | + | ||
| 14 | + follow_redirect! | ||
| 15 | + assert_response :success | ||
| 16 | + assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/edit/5'} | ||
| 17 | + | ||
| 18 | + get '/admin/enterprise/edit/5' | ||
| 19 | + assert_response :success | ||
| 20 | + assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} | ||
| 21 | + | ||
| 22 | + post '/admin/enterprise/update/5', :enterprise => {'name' => 'new_name' } | ||
| 23 | + assert_response :redirect | ||
| 24 | + | ||
| 25 | + follow_redirect! | ||
| 26 | + assert_response :redirect | ||
| 27 | + | ||
| 28 | + follow_redirect! | ||
| 29 | + assert_equal '/admin/enterprise/show/5', path | ||
| 30 | + | ||
| 31 | + end | ||
| 32 | +end |
| @@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
| 1 | +require "#{File.dirname(__FILE__)}/../test_helper" | ||
| 2 | + | ||
| 3 | +class RegisterEnterpriseTest < ActionController::IntegrationTest | ||
| 4 | + all_fixtures | ||
| 5 | + | ||
| 6 | + def test_register_new_enterprise | ||
| 7 | + get '/admin/enterprise' | ||
| 8 | + assert_response :redirect | ||
| 9 | + | ||
| 10 | + login('ze','test') | ||
| 11 | + | ||
| 12 | + get '/admin/enterprise' | ||
| 13 | + assert_response :redirect | ||
| 14 | + | ||
| 15 | + follow_redirect! | ||
| 16 | + assert_response :success | ||
| 17 | + assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/register_form'} | ||
| 18 | + | ||
| 19 | + get '/admin/enterprise/register_form' | ||
| 20 | + assert_response :success | ||
| 21 | + assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} | ||
| 22 | + assert_tag :tag => 'input', :attributes => {:name => 'enterprise[identifier]'} | ||
| 23 | + | ||
| 24 | + post '/admin/enterprise/register', :enterprise => {'name' => 'new_enterprise', 'identifier' => 'enterprise_new'} | ||
| 25 | + assert_response :redirect | ||
| 26 | + | ||
| 27 | + follow_redirect! | ||
| 28 | + assert_response :redirect | ||
| 29 | + | ||
| 30 | + follow_redirect! | ||
| 31 | + assert_response :success | ||
| 32 | + end | ||
| 33 | +end |
| @@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
| 1 | +require "#{File.dirname(__FILE__)}/../test_helper" | ||
| 2 | + | ||
| 3 | +class SearchEnterpriseTest < ActionController::IntegrationTest | ||
| 4 | + all_fixtures | ||
| 5 | + | ||
| 6 | + def test_search_by_name_or_tag | ||
| 7 | + login('ze', 'test') | ||
| 8 | + get '/admin/enterprise' | ||
| 9 | + assert_response :redirect | ||
| 10 | + | ||
| 11 | + follow_redirect! | ||
| 12 | + assert_response :success | ||
| 13 | + assert_tag :tag => 'input', :attributes => {'name', 'query'} | ||
| 14 | + | ||
| 15 | + get '/admin/enterprise/search', :query => 'bla' | ||
| 16 | + assert_response :success | ||
| 17 | + end | ||
| 18 | +end |
test/unit/profile_test.rb
| @@ -76,4 +76,13 @@ class ProfileTest < Test::Unit::TestCase | @@ -76,4 +76,13 @@ class ProfileTest < Test::Unit::TestCase | ||
| 76 | 76 | ||
| 77 | assert pe.profiles.include?(pr) | 77 | assert pe.profiles.include?(pr) |
| 78 | end | 78 | end |
| 79 | + | ||
| 80 | + def test_search | ||
| 81 | + p = Profile.create(:name => 'wanted', :identifier => 'wanted') | ||
| 82 | + p.update_attribute(:tag_list, 'bla') | ||
| 83 | + | ||
| 84 | + assert Profile.search('wanted').include?(p) | ||
| 85 | + assert Profile.search('bla').include?(p) | ||
| 86 | + assert ! Profile.search('not_wanted').include?(p) | ||
| 87 | + end | ||
| 79 | end | 88 | end |