BigW Consortium Gitlab

users.rb 5.5 KB
Newer Older
1
class Spinach::Features::AdminUsers < Spinach::FeatureSteps
2 3 4 5
  include SharedAuthentication
  include SharedPaths
  include SharedAdmin

6
  before do
Stan Hu committed
7 8
    allow(Gitlab::OAuth::Provider).to receive(:providers).and_return([:twitter, :twitter_updated])
    allow_any_instance_of(ApplicationHelper).to receive(:user_omniauth_authorize_path).and_return(root_path)
9 10 11
  end

  after do
Stan Hu committed
12 13
    allow(Gitlab::OAuth::Provider).to receive(:providers).and_call_original
    allow_any_instance_of(ApplicationHelper).to receive(:user_omniauth_authorize_path).and_call_original
14 15
  end

16
  step 'I should see all users' do
17
    User.all.each do |user|
18
      expect(page).to have_content user.name
19 20
    end
  end
21

22
  step 'Click edit' do
23 24 25 26
    @user = User.first
    find("#edit_user_#{@user.id}").click
  end

27
  step 'Input non ascii char in username' do
28 29 30
    fill_in 'user_username', with: "\u3042\u3044"
  end

31
  step 'Click save' do
32 33 34
    click_button("Save")
  end

35
  step 'See username error message' do
36
    page.within "#error_explanation" do
37
      expect(page).to have_content "Username"
38 39 40
    end
  end

41
  step 'Not changed form action url' do
42
    expect(page).to have_selector %(form[action="/admin/users/#{@user.username}"])
43
  end
44 45 46 47 48 49 50

  step 'I submit modified user' do
    check :user_can_create_group
    click_button 'Save'
  end

  step 'I see user attributes changed' do
51
    expect(page).to have_content 'Can create groups: Yes'
52 53 54 55 56
  end

  step 'click edit on my user' do
    find("#edit_user_#{current_user.id}").click
  end
57 58 59 60 61 62 63 64 65

  step 'I view the user with secondary email' do
    @user_with_secondary_email = User.last
    @user_with_secondary_email.emails.new(email: "secondary@example.com")
    @user_with_secondary_email.save
    visit "/admin/users/#{@user_with_secondary_email.username}"
  end

  step 'I see the secondary email' do
66
    expect(page).to have_content "Secondary email: #{@user_with_secondary_email.emails.last.email}"
67 68 69 70 71 72 73
  end

  step 'I click remove secondary email' do
    find("#remove_email_#{@user_with_secondary_email.emails.last.id}").click
  end

  step 'I should not see secondary email anymore' do
74
    expect(page).not_to have_content "Secondary email:"
75
  end
76 77 78 79 80 81 82 83

  step 'user "Mike" with groups and projects' do
    user = create(:user, name: 'Mike')

    project = create(:empty_project)
    project.team << [user, :developer]

    group = create(:group)
84
    group.add_developer(user)
85 86 87 88 89 90 91
  end

  step 'click on "Mike" link' do
    click_link "Mike"
  end

  step 'I should see user "Mike" details' do
92 93
    expect(page).to have_content 'Account'
    expect(page).to have_content 'Personal projects limit'
94
  end
95 96 97 98 99 100 101 102 103 104 105 106

  step 'user "Pete" with ssh keys' do
    user = create(:user, name: 'Pete')
    create(:key, user: user, title: "ssh-rsa Key1", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key1")
    create(:key, user: user, title: "ssh-rsa Key2", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQSTWXhJAX/He+nG78MiRRRn7m0Pb0XbcgTxE0etArgoFoh9WtvDf36HG6tOSg/0UUNcp0dICsNAmhBKdncp6cIyPaXJTURPRAGvhI0/VDk4bi27bRnccGbJ/hDaUxZMLhhrzY0r22mjVf8PF6dvv5QUIQVm1/LeaWYsHHvLgiIjwrXirUZPnFrZw6VLREoBKG8uWvfSXw1L5eapmstqfsME8099oi+vWLR8MgEysZQmD28M73fgW4zek6LDQzKQyJx9nB+hJkKUDvcuziZjGmRFlNgSA2mguERwL1OXonD8WYUrBDGKroIvBT39zS5d9tQDnidEJZ9Y8gv5ViYP7x Key2")
  end

  step 'click on user "Pete"' do
    click_link 'Pete'
  end

  step 'I should see key list' do
107 108
    expect(page).to have_content 'ssh-rsa Key2'
    expect(page).to have_content 'ssh-rsa Key1'
109 110 111 112 113 114 115
  end

  step 'I click on the key title' do
    click_link 'ssh-rsa Key2'
  end

  step 'I should see key details' do
116 117
    expect(page).to have_content 'ssh-rsa Key2'
    expect(page).to have_content 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQSTWXhJAX/He+nG78MiRRRn7m0Pb0XbcgTxE0etArgoFoh9WtvDf36HG6tOSg/0UUNcp0dICsNAmhBKdncp6cIyPaXJTURPRAGvhI0/VDk4bi27bRnccGbJ/hDaUxZMLhhrzY0r22mjVf8PF6dvv5QUIQVm1/LeaWYsHHvLgiIjwrXirUZPnFrZw6VLREoBKG8uWvfSXw1L5eapmstqfsME8099oi+vWLR8MgEysZQmD28M73fgW4zek6LDQzKQyJx9nB+hJkKUDvcuziZjGmRFlNgSA2mguERwL1OXonD8WYUrBDGKroIvBT39zS5d9tQDnidEJZ9Y8gv5ViYP7x Key2'
118 119 120 121 122 123 124
  end

  step 'I click on remove key' do
    click_link 'Remove'
  end

  step 'I should see the key removed' do
125
    expect(page).not_to have_content 'ssh-rsa Key2'
126
  end
127 128 129 130 131 132 133 134 135 136 137

  step 'user "Pete" with twitter account' do
    @user = create(:user, name: 'Pete')
    @user.identities.create!(extern_uid: '123456', provider: 'twitter')
  end

  step 'I visit "Pete" identities page in admin' do
    visit admin_user_identities_path(@user)
  end

  step 'I should see twitter details' do
138
    expect(page).to have_content 'Pete'
139 140 141 142
    expect(page).to have_content 'twitter'
  end

  step 'I modify twitter identity' do
143
    find('.table').find(:link, 'Edit').click
144
    fill_in 'identity_extern_uid', with: '654321'
145
    select 'twitter_updated', from: 'identity_provider'
146 147 148 149
    click_button 'Save changes'
  end

  step 'I should see twitter details updated' do
150
    expect(page).to have_content 'Pete'
151 152 153 154 155 156 157 158 159
    expect(page).to have_content 'twitter_updated'
    expect(page).to have_content '654321'
  end

  step 'I remove twitter identity' do
    click_link 'Delete'
  end

  step 'I should not see twitter details' do
160
    expect(page).to have_content 'Pete'
161 162
    expect(page).to_not have_content 'twitter'
  end
163 164 165 166

  step 'click on ssh keys tab' do
    click_link 'SSH keys'
  end
167
end