<commit_before>require File.dirname(__FILE__) + '/../test_helper'
require 'pages_controller'

# Re-raise errors caught by the controller.
class PagesController; def rescue_action(e) raise e end; end

class PagesControllerTest < Test::Unit::TestCase
  fixtures :pages, :users

  def setup
    @controller = PagesController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_create
    login_as :quentin
    get :create
    assert :success
    assert_template 'create'
  end
  
  def test_login_required
    [:tag, :notify, :access, :move, :destroy].each do |action|
      assert_requires_login do |c|
        c.get action, :id => pages(:hello).id
      end
    end
  end
  
  def test_add_access
    login_as :orange
# i don't think this test is working correctly --af    
#    post :access, :id => 1, :add_name => "public_group"
#    assert :success
#    assert_nil flash[:error], 'adding access to public group'
    
#    post :access, :id => 1, :add_name => "private_group12"
#    assert :success
#    assert_equal 'you do not have permission to do that', flash[:error],
#                  'adding access to private group'
  end
end
<commit_msg>Made a test to check that users can give a public group (which they don't belong to) access to a page, but  that they cannot give a private group which they don't belong to access to a page. <commit_after>require File.dirname(__FILE__) + '/../test_helper'
require 'pages_controller'

# Re-raise errors caught by the controller.
class PagesController; def rescue_action(e) raise e end; end

class PagesControllerTest < Test::Unit::TestCase
  fixtures :pages, :users, :user_participations, :groups, :group_participations, :memberships, :profiles

  def setup
    @controller = PagesController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_create
    login_as :quentin
    get :create
    assert :success
    assert_template 'create'
  end
  
  def test_login_required
    [:tag, :notify, :access, :move, :destroy].each do |action|
      assert_requires_login do |c|
        c.get action, :id => pages(:hello).id
      end
    end
  end
  
  def test_add_access
    pg = Page.find(1)
    assert pg, 'page should exist'

    user = User.find_by_login('orange')
    assert user, 'user should exist'
    assert user.may?(:admin, pg), 'user should be able to admin page'
    login = login_as(:orange)
    assert_equal login, 5, 'should login as user 5'
 
    group = Group.find_by_name('public_group_everyone_can_see')
    assert group, 'group should exist'
    assert !group.may?(:admin, pg), 'public group should not have access to page'

    post 'access', :id => pg.id, :add_name => group.name
    assert user.may_pester?(group), 'user should be able to pester pub group'
    pg.reload
    assert group.may?(:admin, pg), 'public group should have access to page'
    
    group_private = Group.find_by_name('private_group_not_everyone_can_see')   
    assert group, 'private group should exist'
    assert !group_private.may?(:admin, pg), 'private group should not have access to page originally'
 
    post 'access', :id => pg.id, :add_name => group_private.name
    pg.reload
    assert !group_private.may?(:admin, pg), 'private group should still not have access to page'
  end
end

{'fraction_non_alphanumeric': 0.09923213230950975, 'fraction_numerical': 0.002067336089781453, 'mean_word_length': 3.52807486631016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3941041', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1011, 'n_words': 347}