From aca6d36722df8139bb26e06fd39970b797aa6a1f Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Fri, 19 Jun 2015 12:23:05 +0200
Subject: [PATCH] Add tests for admin managing user identities

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 features/admin/users.feature  | 19 +++++++++++++++++-
 features/steps/admin/users.rb | 36 +++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/features/admin/users.feature b/features/admin/users.feature
index 1a8720dd77e..f17254911b7 100644
--- a/features/admin/users.feature
+++ b/features/admin/users.feature
@@ -28,7 +28,7 @@ Feature: Admin Users
     When I submit modified user
     Then I see user attributes changed
 
-@javascript
+  @javascript
   Scenario: Remove users secondary email
     Given I visit admin users page
     And I view the user with secondary email
@@ -45,3 +45,20 @@ Feature: Admin Users
     Then I should see key details
     And I click on remove key
     Then I should see the key removed
+
+  Scenario: Show user identities
+    Given user "Pete" with twitter account
+    And I visit "Pete" identities page in admin
+    Then I should see twitter details
+
+  Scenario: Update user identities
+    Given user "Pete" with twitter account
+    And I visit "Pete" identities page in admin
+    And I modify twitter identity
+    Then I should see twitter details updated
+
+  Scenario: Remove user identities
+    Given user "Pete" with twitter account
+    And I visit "Pete" identities page in admin
+    And I remove twitter identity
+    Then I should not see twitter details
diff --git a/features/steps/admin/users.rb b/features/steps/admin/users.rb
index 34a3ed9f615..a9bb314b24f 100644
--- a/features/steps/admin/users.rb
+++ b/features/steps/admin/users.rb
@@ -114,4 +114,40 @@ class Spinach::Features::AdminUsers < Spinach::FeatureSteps
   step 'I should see the key removed' do
     expect(page).not_to have_content 'ssh-rsa Key2'
   end
+
+  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
+    expect(page).to have_content 'Identities for Pete'
+    expect(page).to have_content 'twitter'
+  end
+
+  step 'I modify twitter identity' do
+    click_link 'Edit'
+    fill_in 'identity_extern_uid', with: '654321'
+    fill_in 'identity_provider', with: 'twitter_updated'
+    click_button 'Save changes'
+  end
+
+  step 'I should see twitter details updated' do
+    expect(page).to have_content 'Identities for Pete'
+    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
+    expect(page).to have_content 'Identities for Pete'
+    expect(page).to_not have_content 'twitter'
+  end
 end
-- 
GitLab