summaryrefslogtreecommitdiff
path: root/test/functional/identities_controller_test.rb
blob: fcdeaa2588dcf95d16b04ef95b161d7054d530ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'test_helper'

class IdentitiesControllerTest < ActionController::TestCase

  test "admin can list active and blocked ids" do
    login :is_admin? => true
    get :index
    assert_response :success
    assert ids = assigns(:identities)
  end

  test "non-admin can't list usernames" do
    login
    get :index
    assert_access_denied
  end

  test "requires login" do
    get :index
    assert_login_required
  end

  test "admin can unblock username" do
    # an identity without user_id and destination is a blocked handle
    identity = FactoryGirl.create :identity
    login :is_admin? => true
    delete :destroy, id: identity.id
    assert_response :redirect
    assert_nil Identity.find(identity.id)
  end

  test "admin cannot remove main identity" do
    user = FactoryGirl.create :user
    identity = FactoryGirl.create :identity,
      Identity.attributes_from_user(user)
    login :is_admin? => true
    delete :destroy, id: identity.id
    assert_response :redirect
    assert_equal identity, Identity.find(identity.id)
  end

end