Commit 3b21da84 authored by blackst0ne's avatar blackst0ne Committed by Robert Speicher

Replace the `project/deploy_keys.feature` spinach test with an rspec analog

parent 1a9f90f8
---
title: 'Replace the `project/deploy_keys.feature` spinach test with an rspec analog'
merge_request: 18796
author: '@blackst0ne'
type: other
Feature: Project Deploy Keys
Background:
Given I sign in as a user
And I own project "Shop"
@javascript
Scenario: I should see deploy keys list
Given project has deploy key
When I visit project deploy keys page
Then I should see project deploy key
@javascript
Scenario: I should see project deploy keys
Given other projects have deploy keys
When I visit project deploy keys page
Then I should see other project deploy key
And I should only see the same deploy key once
@javascript
Scenario: I should see public deploy keys
Given public deploy key exists
When I visit project deploy keys page
Then I should see public deploy key
@javascript
Scenario: I add new deploy key
Given I visit project deploy keys page
And I submit new deploy key
Then I should be on deploy keys page
And I should see newly created deploy key
@javascript
Scenario: I attach other project deploy key to project
Given other projects have deploy keys
And I visit project deploy keys page
When I click attach deploy key
Then I should be on deploy keys page
And I should see newly created deploy key
@javascript
Scenario: I attach public deploy key to project
Given public deploy key exists
And I visit project deploy keys page
When I click attach deploy key
Then I should be on deploy keys page
And I should see newly created deploy key
class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
step 'project has deploy key' do
create(:deploy_keys_project, project: @project)
end
step 'I should see project deploy key' do
page.within(find('.deploy-keys')) do
find('.js-deployKeys-tab-enabled_keys').click()
expect(page).to have_content deploy_key.title
end
end
step 'I should see other project deploy key' do
page.within(find('.deploy-keys')) do
find('.js-deployKeys-tab-available_project_keys').click()
expect(page).to have_content other_deploy_key.title
end
end
step 'I should see public deploy key' do
page.within(find('.deploy-keys')) do
find('.js-deployKeys-tab-public_keys').click()
expect(page).to have_content public_deploy_key.title
end
end
step 'I click \'New Deploy Key\'' do
click_link 'New deploy key'
end
step 'I submit new deploy key' do
fill_in "deploy_key_title", with: "laptop"
fill_in "deploy_key_key", with: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzrEJUIR6Y03TCE9rIJ+GqTBvgb8t1jI9h5UBzCLuK4VawOmkLornPqLDrGbm6tcwM/wBrrLvVOqi2HwmkKEIecVO0a64A4rIYScVsXIniHRS6w5twyn1MD3sIbN+socBDcaldECQa2u1dI3tnNVcs8wi77fiRe7RSxePsJceGoheRQgC8AZ510UdIlO+9rjIHUdVN7LLyz512auAfYsgx1OfablkQ/XJcdEwDNgi9imI6nAXhmoKUm1IPLT2yKajTIC64AjLOnE0YyCh6+7RFMpiMyu1qiOCpdjYwTgBRiciNRZCH8xIedyCoAmiUgkUT40XYHwLuwiPJICpkAzp7Q== user@laptop"
click_button "Add key"
end
step 'I should be on deploy keys page' do
expect(current_path).to eq project_settings_repository_path(@project)
end
step 'I should see newly created deploy key' do
@project.reload
page.within(find('.deploy-keys')) do
find('.js-deployKeys-tab-enabled_keys').click()
expect(page).to have_content(deploy_key.title)
end
end
step 'other projects have deploy keys' do
@second_project = create(:project, namespace: create(:group))
@second_project.add_master(current_user)
create(:deploy_keys_project, project: @second_project)
@third_project = create(:project, namespace: create(:group))
@third_project.add_master(current_user)
create(:deploy_keys_project, project: @third_project, deploy_key: @second_project.deploy_keys.first)
end
step 'I should only see the same deploy key once' do
page.within(find('.deploy-keys')) do
expect(find('.js-deployKeys-tab-available_project_keys .badge')).to have_content('1')
end
end
step 'public deploy key exists' do
create(:deploy_key, public: true)
end
step 'I click attach deploy key' do
page.within(find('.deploy-keys')) do
find('.badge', text: '1').click()
click_button 'Enable'
expect(page).not_to have_selector('.fa-spinner')
end
end
protected
def deploy_key
@project.deploy_keys.last
end
def other_deploy_key
@second_project.deploy_keys.last
end
def public_deploy_key
DeployKey.are_public.last
end
end
...@@ -240,10 +240,6 @@ module SharedPaths ...@@ -240,10 +240,6 @@ module SharedPaths
visit project_settings_integrations_path(@project) visit project_settings_integrations_path(@project)
end end
step 'I visit project deploy keys page' do
visit project_deploy_keys_path(@project)
end
step 'I visit project find file page' do step 'I visit project find file page' do
visit project_find_file_path(@project, root_ref) visit project_find_file_path(@project, root_ref)
end end
......
require "spec_helper"
describe "User interacts with deploy keys", :js do
let(:project) { create(:project, :repository) }
let(:user) { project.owner }
before do
sign_in(user)
end
shared_examples "attaches a key" do
it "attaches key" do
visit(project_deploy_keys_path(project))
page.within(".deploy-keys") do
find(".badge", text: "1").click
click_button("Enable")
expect(page).not_to have_selector(".fa-spinner")
expect(current_path).to eq(project_settings_repository_path(project))
find(".js-deployKeys-tab-enabled_keys").click
expect(page).to have_content(deploy_key.title)
end
end
end
context "viewing deploy keys" do
let(:deploy_key) { create(:deploy_key) }
context "when project has keys" do
before do
create(:deploy_keys_project, project: project, deploy_key: deploy_key)
end
it "shows deploy keys" do
visit(project_deploy_keys_path(project))
page.within(".deploy-keys") do
expect(page).to have_content(deploy_key.title)
end
end
end
context "when another project has keys" do
let(:another_project) { create(:project) }
before do
create(:deploy_keys_project, project: another_project, deploy_key: deploy_key)
another_project.add_master(user)
end
it "shows deploy keys" do
visit(project_deploy_keys_path(project))
page.within(".deploy-keys") do
find('.js-deployKeys-tab-available_project_keys').click
expect(page).to have_content(deploy_key.title)
expect(find(".js-deployKeys-tab-available_project_keys .badge")).to have_content("1")
end
end
end
context "when there are public deploy keys" do
let!(:deploy_key) { create(:deploy_key, public: true) }
it "shows public deploy keys" do
visit(project_deploy_keys_path(project))
page.within(".deploy-keys") do
find(".js-deployKeys-tab-public_keys").click
expect(page).to have_content(deploy_key.title)
end
end
end
end
context "adding deploy keys" do
before do
visit(project_deploy_keys_path(project))
end
it "adds new key" do
DEPLOY_KEY_TITLE = attributes_for(:key)[:title]
DEPLOY_KEY_BODY = attributes_for(:key)[:key]
fill_in("deploy_key_title", with: DEPLOY_KEY_TITLE)
fill_in("deploy_key_key", with: DEPLOY_KEY_BODY)
click_button("Add key")
expect(current_path).to eq(project_settings_repository_path(project))
page.within(".deploy-keys") do
expect(page).to have_content(DEPLOY_KEY_TITLE)
end
end
end
context "attaching existing keys" do
context "from another project" do
let(:another_project) { create(:project) }
let(:deploy_key) { create(:deploy_key) }
before do
create(:deploy_keys_project, project: another_project, deploy_key: deploy_key)
another_project.add_master(user)
end
it_behaves_like "attaches a key"
end
context "when keys are public" do
let!(:deploy_key) { create(:deploy_key, public: true) }
it_behaves_like "attaches a key"
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment