1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'group_controller'
4 # Re-raise errors caught by the controller.
5 class GroupController; def rescue_action(e) raise e end; end
7 class GroupControllerTest < Test::Unit::TestCase
8 fixtures :settings, :groups, :users, :forums, :categories
10 @controller = GroupController.new
11 @request = ActionController::TestRequest.new
12 @response = ActionController::TestResponse.new
13 User.current_user = users(:admin)
20 assert_response :success
21 assert flash.key?(:errors) == false
23 post :update, :id => id, :group => {:g_title => 'test title', :g_user_title => 'test user title'}
24 assert_redirected_to :controller => 'group', :action => 'index'
26 assert_equal g.g_title, 'test title'
27 assert_equal g.g_user_title, 'test user title'
29 for set in [{:group => groups(:member), :keys => [:g_read_board, :g_post_replies, :g_post_topics, :g_post_polls, :g_edit_posts, :g_delete_posts, :g_delete_topics, :g_set_title, :g_search, :g_search_users]}, {:group => groups(:guest), :keys => [:g_read_board, :g_post_replies, :g_post_topics, :g_post_polls, :g_search, :g_search_users]}]
33 for result in [{:value => '0', :bool => false},{:value => '1', :bool => true}]
34 post :update, :id => id, :group => keys.inject(Hash.new) {|h,k| h[k] = result[:value]; h}
35 assert_redirected_to :controller => 'group', :action => 'index'
37 keys.each { |k| assert g.send(k) == result[:bool] }
43 post :update, :id => id, :group => {:g_edit_subjects_interval => '10', :g_post_flood => '12', :g_search_flood => '14'}
44 assert_redirected_to :controller => 'group', :action => 'index'
46 assert_equal 10, g.g_edit_subjects_interval
47 assert_equal 12, g.g_post_flood
48 assert_equal 14, g.g_search_flood
53 assert_response :success
55 get :update_index, :add_group => true, :base_group => groups(:g100).id
56 assert_redirected_to :controller => 'group', :action => 'index'
57 assert_nil flash[:error]
58 g = Group.find_by_g_title('group one (new)')
60 assert g.id != groups(:g100).id
62 get :update_index, :set_default_group => true, :default_group => g.id
63 assert_redirected_to :controller => 'group', :action => 'index'
64 assert_nil flash[:error]
65 assert_equal Settings.default_user_group, g.id
67 assert_raise(PermissionException,'You can not delete default group') {get :delete, :id => g.id}
69 get :update_index, :set_default_group => true, :default_group => groups(:member).id
70 assert_redirected_to :controller => 'group', :action => 'index'
71 assert_nil flash[:error]
72 assert_equal Settings.default_user_group, groups(:member).id
76 u.email = 'meme@meme.com'
77 u.email_confirmation = u.email
81 assert_equal u.group_id,g.id
82 get :delete, :id => g.id
83 assert_response :success
84 assert_form :action => 'destroy', :id => g.id
86 get :destroy, :id => g.id, :move_to_group => groups(:g100).id
87 assert_redirected_to :controller => 'group', :action => 'index'
88 assert_nil flash[:error]
89 assert_nil Group.find_by_id(g.id)
91 assert_equal u.group_id,groups(:g100).id