Commit c910bca7 authored by Douwe Maan's avatar Douwe Maan

Add tests for new functionality

parent c6524342
...@@ -10,7 +10,11 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -10,7 +10,11 @@ class Projects::ForksController < Projects::ApplicationController
def create def create
namespace = Namespace.find(params[:namespace_key]) namespace = Namespace.find(params[:namespace_key])
@forked_project = ::Projects::ForkService.new(project, current_user, namespace: namespace).execute
@forked_project = namespace.projects.find_by(path: project.path)
@forked_project = nil unless @forked_project && @forked_project.forked_from_project == project
@forked_project ||= ::Projects::ForkService.new(project, current_user, namespace: namespace).execute
if @forked_project.saved? && @forked_project.forked? if @forked_project.saved? && @forked_project.forked?
if @forked_project.import_in_progress? if @forked_project.import_in_progress?
......
...@@ -24,6 +24,12 @@ Feature: Project Source Browse Files ...@@ -24,6 +24,12 @@ Feature: Project Source Browse Files
Given I click on "New file" link in repo Given I click on "New file" link in repo
Then I can see new file page Then I can see new file page
Scenario: I can create file when I don't have write access
Given I don't have write access
And I click on "New file" link in repo
Then I should see a notice about a new fork having been created
Then I can see new file page
@javascript @javascript
Scenario: I can create and commit file Scenario: I can create and commit file
Given I click on "New file" link in repo Given I click on "New file" link in repo
...@@ -34,6 +40,17 @@ Feature: Project Source Browse Files ...@@ -34,6 +40,17 @@ Feature: Project Source Browse Files
Then I am redirected to the new file Then I am redirected to the new file
And I should see its new content And I should see its new content
@javascript
Scenario: I can create and commit file when I don't have write access
Given I don't have write access
And I click on "New file" link in repo
And I edit code
And I fill the new file name
And I fill the commit message
And I click on "Commit Changes"
Then I am redirected to the fork's new merge request page
And I can see the new commit message
@javascript @javascript
Scenario: I can create and commit file with new lines at the end of file Scenario: I can create and commit file with new lines at the end of file
Given I click on "New file" link in repo Given I click on "New file" link in repo
...@@ -45,6 +62,17 @@ Feature: Project Source Browse Files ...@@ -45,6 +62,17 @@ Feature: Project Source Browse Files
And I click button "Edit" And I click button "Edit"
And I should see its content with new lines preserved at end of file And I should see its content with new lines preserved at end of file
@javascript
Scenario: I can create and commit file and specify new branch
Given I click on "New file" link in repo
And I edit code
And I fill the new file name
And I fill the commit message
And I fill the new branch name
And I click on "Commit Changes"
Then I am redirected to the fork's new merge request page
And I should see its new content
@javascript @javascript
Scenario: I can upload file and commit Scenario: I can upload file and commit
Given I click on "Upload file" link in repo Given I click on "Upload file" link in repo
...@@ -56,6 +84,19 @@ Feature: Project Source Browse Files ...@@ -56,6 +84,19 @@ Feature: Project Source Browse Files
And I am redirected to the new merge request page And I am redirected to the new merge request page
And I can see the new commit message And I can see the new commit message
@javascript
Scenario: I can upload file and commit when I don't have write access
Given I don't have write access
And I click on "Upload file" link in repo
Then I should see a notice about a new fork having been created
When I click on "Upload file" link in repo
And I upload a new text file
And I fill the upload file commit message
And I click on "Upload file"
Then I can see the new text file
And I am redirected to the fork's new merge request page
And I can see the new commit message
@javascript @javascript
Scenario: I can replace file and commit Scenario: I can replace file and commit
Given I click on ".gitignore" file in repo Given I click on ".gitignore" file in repo
...@@ -68,15 +109,19 @@ Feature: Project Source Browse Files ...@@ -68,15 +109,19 @@ Feature: Project Source Browse Files
And I can see the replacement commit message And I can see the replacement commit message
@javascript @javascript
Scenario: I can create and commit file and specify new branch Scenario: I can replace file and commit when I don't have write access
Given I click on "New file" link in repo Given I don't have write access
And I edit code And I click on ".gitignore" file in repo
And I fill the new file name And I see the ".gitignore"
And I fill the commit message And I click on "Replace"
And I fill the new branch name Then I should see a notice about a new fork having been created
And I click on "Commit Changes" When I click on "Replace"
Then I am redirected to the new merge request page And I replace it with a text file
And I should see its new content And I fill the replace file commit message
And I click on "Replace file"
Then I can see the new text file
And I am redirected to the new merge request page
And I can see the replacement commit message
@javascript @javascript
Scenario: I can create file in empty repo Scenario: I can create file in empty repo
...@@ -117,6 +162,14 @@ Feature: Project Source Browse Files ...@@ -117,6 +162,14 @@ Feature: Project Source Browse Files
And I click button "Edit" And I click button "Edit"
Then I can edit code Then I can edit code
@javascript
Scenario: I can edit file when I don't have write access
Given I don't have write access
And I click on ".gitignore" file in repo
And I click button "Edit"
Then I should see a notice about a new fork having been created
And I can edit code
Scenario: If the file is binary the edit link is hidden Scenario: If the file is binary the edit link is hidden
Given I visit a binary file in the repo Given I visit a binary file in the repo
Then I cannot see the edit button Then I cannot see the edit button
...@@ -131,6 +184,17 @@ Feature: Project Source Browse Files ...@@ -131,6 +184,17 @@ Feature: Project Source Browse Files
Then I am redirected to the ".gitignore" Then I am redirected to the ".gitignore"
And I should see its new content And I should see its new content
@javascript
Scenario: I can edit and commit file when I don't have write access
Given I don't have write access
And I click on ".gitignore" file in repo
And I click button "Edit"
And I edit code
And I fill the commit message
And I click on "Commit Changes"
Then I am redirected to the fork's new merge request page
And I can see the new commit message
@javascript @javascript
Scenario: I can edit and commit file to new branch Scenario: I can edit and commit file to new branch
Given I click on ".gitignore" file in repo Given I click on ".gitignore" file in repo
...@@ -161,6 +225,17 @@ Feature: Project Source Browse Files ...@@ -161,6 +225,17 @@ Feature: Project Source Browse Files
And I click on "Create directory" And I click on "Create directory"
Then I am redirected to the new merge request page Then I am redirected to the new merge request page
@javascript
Scenario: I can create directory in repo when I don't have write access
Given I don't have write access
When I click on "New directory" link in repo
Then I should see a notice about a new fork having been created
When I click on "New directory" link in repo
And I fill the new directory name
And I fill the commit message
And I click on "Create directory"
Then I am redirected to the fork's new merge request page
@javascript @javascript
Scenario: I attempt to create an existing directory Scenario: I attempt to create an existing directory
When I click on "New directory" link in repo When I click on "New directory" link in repo
...@@ -188,6 +263,19 @@ Feature: Project Source Browse Files ...@@ -188,6 +263,19 @@ Feature: Project Source Browse Files
Then I am redirected to the files URL Then I am redirected to the files URL
And I don't see the ".gitignore" And I don't see the ".gitignore"
@javascript
Scenario: I can delete file and commit when I don't have write access
Given I don't have write access
And I click on ".gitignore" file in repo
And I see the ".gitignore"
And I click on "Delete"
Then I should see a notice about a new fork having been created
When I click on "Delete"
And I fill the commit message
And I click on "Delete file"
Then I am redirected to the fork's new merge request page
And I can see the new commit message
Scenario: I can browse directory with Browse Dir Scenario: I can browse directory with Browse Dir
Given I click on files directory Given I click on files directory
And I click on History link And I click on History link
......
...@@ -5,6 +5,12 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -5,6 +5,12 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
include SharedPaths include SharedPaths
include RepoHelpers include RepoHelpers
step "I don't have write access" do
@project = create(:project, name: "Other Project", path: "other-project")
@project.team << [@user, :reporter]
visit namespace_project_tree_path(@project.namespace, @project, root_ref)
end
step 'I should see files from repository' do step 'I should see files from repository' do
expect(page).to have_content "VERSION" expect(page).to have_content "VERSION"
expect(page).to have_content ".gitignore" expect(page).to have_content ".gitignore"
...@@ -87,7 +93,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -87,7 +93,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end end
step 'I fill the commit message' do step 'I fill the commit message' do
fill_in :commit_message, with: 'Not yet a commit message.', visible: true fill_in :commit_message, with: 'New commit message', visible: true
end end
step 'I click link "Diff"' do step 'I click link "Diff"' do
...@@ -103,7 +109,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -103,7 +109,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end end
step 'I click on "Delete"' do step 'I click on "Delete"' do
click_button 'Delete' click_on 'Delete'
end end
step 'I click on "Delete file"' do step 'I click on "Delete file"' do
...@@ -111,7 +117,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -111,7 +117,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end end
step 'I click on "Replace"' do step 'I click on "Replace"' do
click_button "Replace" click_on "Replace"
end end
step 'I click on "Replace file"' do step 'I click on "Replace file"' do
...@@ -155,7 +161,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -155,7 +161,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end end
step 'I can see the new commit message' do step 'I can see the new commit message' do
expect(page).to have_content "New upload commit message" expect(page).to have_content "New commit message"
end end
step 'I upload a new text file' do step 'I upload a new text file' do
...@@ -164,7 +170,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -164,7 +170,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
step 'I fill the upload file commit message' do step 'I fill the upload file commit message' do
page.within('#modal-upload-blob') do page.within('#modal-upload-blob') do
fill_in :commit_message, with: 'New upload commit message' fill_in :commit_message, with: 'New commit message'
end end
end end
...@@ -251,6 +257,11 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -251,6 +257,11 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
expect(current_path).to eq(new_namespace_project_merge_request_path(@project.namespace, @project)) expect(current_path).to eq(new_namespace_project_merge_request_path(@project.namespace, @project))
end end
step "I am redirected to the fork's new merge request page" do
fork = @user.fork_of(@project)
expect(current_path).to eq(new_namespace_project_merge_request_path(fork.namespace, fork))
end
step 'I am redirected to the root directory' do step 'I am redirected to the root directory' do
expect(current_path).to eq( expect(current_path).to eq(
namespace_project_tree_path(@project.namespace, @project, 'master')) namespace_project_tree_path(@project.namespace, @project, 'master'))
...@@ -336,6 +347,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -336,6 +347,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
expect(page).to have_content 'Replace' expect(page).to have_content 'Replace'
end end
step 'I should see a notice about a new fork having been created' do
expect(page).to have_content "You're not allowed to make changes to this project directly. A fork of this project has been created that you can make changes in, so you can submit a merge request."
end
private private
def set_new_content def set_new_content
......
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