summaryrefslogtreecommitdiff
path: root/test/functional/identities_controller_test.rb
blob: 5e46f9c2b7cf8b3532c1b48cafe37020cfb239b3 (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
43
44
45
46
47
48
49
50
51
52
require 'test_helper'

class IdentitiesControllerTest < ActionController::TestCase

  setup do
    InviteCodeValidator.any_instance.stubs(:validate)
  end

  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 = 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 = create_user
    identity = 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

  def create_identity(attrs={})
    FactoryBot.create :identity, attrs
  end

  def create_user
    FactoryBot.create :user
  end
end