BigW Consortium Gitlab

Commit e09ef2fc by Dmitriy Zaporozhets

Merge branch 'improve-test-env' into 'master'

Improve test env * Replace big gitlabhq repo with small one (https://gitlab.com/gitlab-org/gitlab-test) * dont stub gitlab-shell calls Advantages: * test gitlab-shell install during tests * test integration with gitlab-shell features (fork, change default branch etc) * don't store archive with test repo inside gitlab * less stubs - easier to write/read tests During this refactoring __next issues are be fixed__: * satellite error if gitlab_shell path is relative * project rename repo -> 500 error * fixed wrong diff for MR `download plain diff` * fixed bug when gfm ignores `@ref` variable during link parsing Fixes #1451 See merge request !1005
parents c0e13125 a0755d2f
......@@ -179,7 +179,11 @@ module GitlabMarkdownHelper
if @commit
@commit.id
elsif @repository && !@repository.empty?
@repository.head_commit.sha
if @ref
@repository.commit(@ref).try(:sha)
else
@repository.head_commit.sha
end
end
end
......
......@@ -494,6 +494,7 @@ class Project < ActiveRecord::Base
end
def rename_repo
path_was = previous_changes['path'].first
old_path_with_namespace = File.join(namespace_dir, path_was)
new_path_with_namespace = File.join(namespace_dir, path)
......
......@@ -10,8 +10,11 @@ class Repository
nil
end
# Return absolute path to repository
def path_to_repo
@path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, path_with_namespace + ".git")
@path_to_repo ||= File.expand_path(
File.join(Gitlab.config.gitlab_shell.repos_path, path_with_namespace + ".git")
)
end
def exists?
......
......@@ -259,6 +259,12 @@ test:
gitlab:
host: localhost
port: 80
satellites:
path: tmp/tests/gitlab-satellites/
gitlab_shell:
path: tmp/tests/gitlab-shell/
repos_path: tmp/tests/repositories/
hooks_path: tmp/tests/gitlab-shell/hooks/
issues_tracker:
redmine:
title: "Redmine"
......
require 'fileutils'
print "Unpacking seed repository..."
SEED_REPO = 'seed_project.tar.gz'
REPO_PATH = Rails.root.join('tmp', 'repositories')
# Make whatever directories we need to make
FileUtils.mkdir_p(REPO_PATH)
# Copy the archive to the repo path
FileUtils.cp(Rails.root.join('spec', SEED_REPO), REPO_PATH)
# chdir to the repo path
FileUtils.cd(REPO_PATH) do
# Extract the archive
`tar -xf #{SEED_REPO}`
# Remove the copy
FileUtils.rm(SEED_REPO)
end
puts ' done.'
print "Creating seed satellite..."
SATELLITE_PATH = Rails.root.join('tmp', 'satellite')
# Make directory
FileUtils.mkdir_p(SATELLITE_PATH)
# Clear any potential directory
FileUtils.rm_rf("#{SATELLITE_PATH}/gitlabhq")
# Chdir, clone from the seed
FileUtils.cd(SATELLITE_PATH) do
# Clone the satellite
`git clone --quiet #{REPO_PATH}/gitlabhq #{SATELLITE_PATH}/gitlabhq`
end
puts ' done.'
......@@ -38,10 +38,6 @@ Feature: Project Browse commits
Given I visit big commit page
Then I see big commit warning
Scenario: I browse huge commit
Given I visit huge commit page
Then I see huge commit message
Scenario: I browse a commit with an image
Given I visit a commit with an image that changed
Then The diff links to both the previous and current image
......@@ -2,13 +2,14 @@ Feature: Project Browse Commits User Lookup
Background:
Given I sign in as a user
And I own a project
And I have the user that authored the commits
And I visit my project's commits page
Scenario: I browse commit from list
Given I click on commit link
Then I see commit info
Given I have user with primary email
When I click on commit link
Then I see author based on primary email
Scenario: I browse another commit from list
Given I click on another commit link
Then I see other commit info
Given I have user with secondary email
When I click on another commit link
Then I see author based on secondary email
......@@ -4,7 +4,6 @@ Feature: Project Forked Merge Requests
And I am a member of project "Shop"
And I have a project forked off of "Shop" called "Forked Shop"
@javascript
Scenario: I submit new unassigned merge request to a forked project
Given I visit project "Forked Shop" merge requests page
And I click link "New Merge Request"
......
......@@ -52,27 +52,27 @@ Feature: Project Merge Requests
Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05"
And I switch to the diff tab
And I leave a comment like "Line is wrong" on line 185 of the first file
And I leave a comment like "Line is wrong" on diff
And I switch to the merge request's comments tab
Then I should see a discussion has started on line 185
Then I should see a discussion has started on diff
@javascript
Scenario: I comment on a line of a commit in merge request
Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05"
And I click on the first commit in the merge request
And I leave a comment like "Line is wrong" on line 185 of the first file in commit
And I click on the commit in the merge request
And I leave a comment like "Line is wrong" on diff in commit
And I switch to the merge request's comments tab
Then I should see a discussion has started on commit b1e6a9dbf1:L185
Then I should see a discussion has started on commit diff
@javascript
Scenario: I comment on a commit in merge request
Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05"
And I click on the first commit in the merge request
And I click on the commit in the merge request
And I leave a comment on the diff page in commit
And I switch to the merge request's comments tab
Then I should see a discussion has started on commit b1e6a9dbf1
Then I should see a discussion has started on commit
@javascript
Scenario: I accept merge request with custom commit message
......
......@@ -12,28 +12,28 @@ Feature: Project Network Graph
@javascript
Scenario: I should switch "branch" and "tag"
When I switch ref to "stable"
Then page should select "stable" in select box
And page should have "stable" on graph
When I switch ref to "v2.1.0"
Then page should select "v2.1.0" in select box
And page should have "v2.1.0" on graph
When I switch ref to "feature"
Then page should select "feature" in select box
And page should have "feature" on graph
When I switch ref to "v1.0.0"
Then page should select "v1.0.0" in select box
And page should have "v1.0.0" on graph
@javascript
Scenario: I should looking for a commit by SHA
When I looking for a commit by SHA of "v2.1.0"
When I looking for a commit by SHA of "v1.0.0"
Then page should have network graph
And page should select "master" in select box
And page should have "v2.1.0" on graph
And page should have "v1.0.0" on graph
@javascript
Scenario: I should filter selected tag
When I switch ref to "v2.1.0"
Then page should have content not containing "v2.1.0"
When I switch ref to "v1.0.0"
Then page should have content not containing "v1.0.0"
When click "Show only selected branch" checkbox
Then page should not have content not containing "v2.1.0"
Then page should not have content not containing "v1.0.0"
When click "Show only selected branch" checkbox
Then page should have content not containing "v2.1.0"
Then page should have content not containing "v1.0.0"
Scenario: I should fail to look for a commit
When I look for a commit by ";"
......
......@@ -8,11 +8,11 @@ Feature: Project Browse files
Then I should see files from repository
Scenario: I browse files for specific ref
Given I visit project source page for "8470d70"
Then I should see files from repository for "8470d70"
Given I visit project source page for "6d39438"
Then I should see files from repository for "6d39438"
Scenario: I browse file content
Given I click on "Gemfile.lock" file in repo
Given I click on ".gitignore" file in repo
Then I should see it content
Scenario: I browse raw file
......@@ -26,20 +26,20 @@ Feature: Project Browse files
@javascript
Scenario: I can edit file
Given I click on "Gemfile.lock" file in repo
Given I click on ".gitignore" file in repo
And I click button "edit"
Then I can edit code
@javascript
Scenario: I can see editing preview
Given I click on "Gemfile.lock" file in repo
Given I click on ".gitignore" file in repo
And I click button "edit"
And I edit code
And I click link "Diff"
Then I see diff
Scenario: I can browse directory with Browse Dir
Given I click on app directory
Given I click on files directory
And I click on history link
Then I see Browse dir link
......
......@@ -5,6 +5,6 @@ Feature: Project Browse git repo
Given I visit project source page
Scenario: I blame file
Given I click on "Gemfile.lock" file in repo
Given I click on ".gitignore" file in repo
And I click blame button
Then I should see git file blame
......@@ -2,7 +2,7 @@ Feature: Project markdown render
Background:
Given I sign in as a user
And I own project "Delta"
Given I visit project source page
And I visit markdown branch
# Tree README
......@@ -11,26 +11,26 @@ Feature: Project markdown render
And I click on a relative link in README
Then I should see the correct markdown
Scenario: I browse files from master branch
Then I should see files from repository in master
Scenario: I browse files from markdown branch
Then I should see files from repository in markdown
And I should see rendered README which contains correct links
And I click on Gitlab API in README
Then I should see correct document rendered
Scenario: I view README in master branch
Then I should see files from repository in master
Scenario: I view README in markdown branch
Then I should see files from repository in markdown
And I should see rendered README which contains correct links
And I click on Rake tasks in README
Then I should see correct directory rendered
Scenario: I view README in master branch to see reference links to directory
Then I should see files from repository in master
Scenario: I view README in markdown branch to see reference links to directory
Then I should see files from repository in markdown
And I should see rendered README which contains correct links
And I click on GitLab API doc directory in README
Then I should see correct doc/api directory rendered
Scenario: I view README in master branch to see reference links to file
Then I should see files from repository in master
Scenario: I view README in markdown branch to see reference links to file
Then I should see files from repository in markdown
And I should see rendered README which contains correct links
And I click on Maintenance in README
Then I should see correct maintenance file rendered
......@@ -41,19 +41,19 @@ Feature: Project markdown render
# Blob
Scenario: I navigate to doc directory to view documentation in master
Scenario: I navigate to doc directory to view documentation in markdown
And I navigate to the doc/api/README
And I see correct file rendered
And I click on users in doc/api/README
Then I should see the correct document file
Scenario: I navigate to doc directory to view user doc in master
Scenario: I navigate to doc directory to view user doc in markdown
And I navigate to the doc/api/README
And I see correct file rendered
And I click on raketasks in doc/api/README
Then I should see correct directory rendered
Scenario: I navigate to doc directory to view user doc in master
Scenario: I navigate to doc directory to view user doc in markdown
And I navigate to the doc/api/README
And Header "GitLab API" should have correct id and link
......
......@@ -2,7 +2,7 @@ Feature: Project Multiselect Blob
Background:
Given I sign in as a user
And I own project "Shop"
And I visit "Gemfile.lock" file in repo
And I visit ".gitignore" file in repo
@javascript
Scenario: I click line 1 in file
......
......@@ -4,6 +4,6 @@ Feature: Project Search code
And I own project "Shop"
Given I visit project source page
Scenario: Search for term "Welcome to GitLab"
When I search for term "Welcome to GitLab"
Then I should see files from repository containing "Welcome to GitLab"
Scenario: Search for term "coffee"
When I search for term "coffee"
Then I should see files from repository containing "coffee"
......@@ -12,7 +12,7 @@ class Dashboard < Spinach::FeatureSteps
end
Then 'I should see last push widget' do
page.should have_content "You pushed to new_design"
page.should have_content "You pushed to fix"
page.should have_link "Create Merge Request"
end
......@@ -23,7 +23,7 @@ class Dashboard < Spinach::FeatureSteps
Then 'I see prefilled new Merge Request page' do
current_path.should == new_project_merge_request_path(@project)
find("#merge_request_target_project_id").value.should == @project.id.to_s
find("#merge_request_source_branch").value.should == "new_design"
find("#merge_request_source_branch").value.should == "fix"
find("#merge_request_target_branch").value.should == "master"
end
......
......@@ -90,4 +90,3 @@ class Spinach::Features::ExploreGroupsFeature < Spinach::FeatureSteps
)
end
end
......@@ -2,11 +2,12 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include RepoHelpers
Then 'I see project commits' do
commit = @project.repository.commit
page.should have_content(@project.name)
page.should have_content(commit.message)
page.should have_content(commit.message[0..20])
page.should have_content(commit.id.to_s[0..5])
end
......@@ -19,21 +20,21 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
page.response_headers['Content-Type'].should have_content("application/atom+xml")
page.body.should have_selector("title", text: "Recent commits to #{@project.name}")
page.body.should have_selector("author email", text: commit.author_email)
page.body.should have_selector("entry summary", text: commit.description)
page.body.should have_selector("entry summary", text: commit.description[0..10])
end
Given 'I click on commit link' do
visit project_commit_path(@project, ValidCommit::ID)
visit project_commit_path(@project, sample_commit.id)
end
Then 'I see commit info' do
page.should have_content ValidCommit::MESSAGE
page.should have_content "Showing 1 changed file"
page.should have_content sample_commit.message
page.should have_content "Showing #{sample_commit.files_changed_count} changed files"
end
And 'I fill compare fields with refs' do
fill_in "from", with: "8716fc78f3c65bbf7bcf7b574febd583bc5d2812"
fill_in "to", with: "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
fill_in "from", with: sample_commit.parent_id
fill_in "to", with: sample_commit.id
click_button "Compare"
end
......@@ -56,30 +57,24 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
end
Given 'I visit big commit page' do
visit project_commit_path(@project, BigCommits::BIG_COMMIT_ID)
Commit::DIFF_SAFE_FILES = 20
visit project_commit_path(@project, sample_big_commit.id)
end
Then 'I see big commit warning' do
page.should have_content BigCommits::BIG_COMMIT_MESSAGE
page.should have_content sample_big_commit.message
page.should have_content "Too many changes"
end
Given 'I visit huge commit page' do
visit project_commit_path(@project, BigCommits::HUGE_COMMIT_ID)
end
Then 'I see huge commit message' do
page.should have_content BigCommits::HUGE_COMMIT_MESSAGE
Commit::DIFF_SAFE_FILES = 100
end
Given 'I visit a commit with an image that changed' do
visit project_commit_path(@project, 'cc1ba255d6c5ffdce87a357ba7ccc397a4f4026b')
visit project_commit_path(@project, sample_image_commit.id)
end
Then 'The diff links to both the previous and current image' do
links = page.all('.two-up span div a')
links[0]['href'].should =~ %r{blob/bc3735004cb45cec5e0e4fa92710897a910a5957}
links[1]['href'].should =~ %r{blob/cc1ba255d6c5ffdce87a357ba7ccc397a4f4026b}
links[0]['href'].should =~ %r{blob/#{sample_image_commit.old_blob_id}}
links[1]['href'].should =~ %r{blob/#{sample_image_commit.new_blob_id}}
end
Given 'I click side-by-side diff button' do
......@@ -93,5 +88,4 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
Then 'I see inline diff button' do
page.should have_content "Inline Diff"
end
end
......@@ -2,34 +2,47 @@ class ProjectBrowseCommitsUserLookup < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
Given 'I have the user that authored the commits' do
@user = create(:user, email: 'dmitriy.zaporozhets@gmail.com')
create(:email, { user: @user, email: 'dzaporozhets@sphereconsultinginc.com' })
end
Given 'I click on commit link' do
visit project_commit_path(@project, ValidCommit::ID)
visit project_commit_path(@project, sample_commit.id)
end
Given 'I click on another commit link' do
visit project_commit_path(@project, ValidCommitWithAltEmail::ID)
visit project_commit_path(@project, sample_commit.parent_id)
end
step 'I have user with primary email' do
user_primary
end
step 'I have user with secondary email' do
user_secondary
end
Then 'I see commit info' do
page.should have_content ValidCommit::MESSAGE
check_author_link(ValidCommit::AUTHOR_EMAIL)
step 'I see author based on primary email' do
check_author_link(sample_commit.author_email, user_primary)
end
Then 'I see other commit info' do
page.should have_content ValidCommitWithAltEmail::MESSAGE
check_author_link(ValidCommitWithAltEmail::AUTHOR_EMAIL)
step 'I see author based on secondary email' do
check_author_link(sample_commit.author_email, user_secondary)
end
def check_author_link(email)
def check_author_link(email, user)
author_link = find('.commit-author-link')
author_link['href'].should == user_path(@user)
author_link['href'].should == user_path(user)
author_link['data-original-title'].should == email
find('.commit-author-name').text.should == @user.name
find('.commit-author-name').text.should == user.name
end
def user_primary
@user_primary ||= create(:user, email: 'dmitriy.zaporozhets@gmail.com')
end
def user_secondary
@user_secondary ||= begin
user = create(:user, email: 'dzaporozhets@example.com')
create(:email, { user: user, email: 'dmitriy.zaporozhets@gmail.com' })
user
end
end
end
......@@ -2,26 +2,26 @@ class ProjectBrowseFiles < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include RepoHelpers
step 'I should see files from repository' do
page.should have_content "app"
page.should have_content "history"
page.should have_content "Gemfile"
page.should have_content "VERSION"
page.should have_content ".gitignore"
page.should have_content "LICENSE"
end
step 'I should see files from repository for "8470d70"' do
current_path.should == project_tree_path(@project, "8470d70")
page.should have_content "app"
page.should have_content "history"
page.should have_content "Gemfile"
step 'I should see files from repository for "6d39438"' do
current_path.should == project_tree_path(@project, "6d39438")
page.should have_content ".gitignore"
page.should have_content "LICENSE"
end
step 'I click on "Gemfile.lock" file in repo' do
click_link "Gemfile.lock"
step 'I click on ".gitignore" file in repo' do
click_link ".gitignore"
end
step 'I should see it content' do
page.should have_content "DEPENDENCIES"
page.should have_content "*.rbc"
end
step 'I click link "raw"' do
......@@ -29,7 +29,7 @@ class ProjectBrowseFiles < Spinach::FeatureSteps
end
step 'I should see raw file content' do
page.source.should == ValidCommit::BLOB_FILE
page.source.should == sample_blob.data
end
step 'I click button "edit"' do
......@@ -63,8 +63,8 @@ class ProjectBrowseFiles < Spinach::FeatureSteps
page.should have_content "Commit message"
end
step 'I click on app directory' do
click_link 'app'
step 'I click on files directory' do
click_link 'files'
end
step 'I click on history link' do
......
......@@ -3,8 +3,8 @@ class ProjectBrowseGitRepo < Spinach::FeatureSteps
include SharedProject
include SharedPaths
Given 'I click on "Gemfile.lock" file in repo' do
click_link "Gemfile.lock"
Given 'I click on ".gitignore" file in repo' do
click_link ".gitignore"
end
And 'I click blame button' do
......@@ -12,8 +12,8 @@ class ProjectBrowseGitRepo < Spinach::FeatureSteps
end
Then 'I should see git file blame' do
page.should have_content "DEPENDENCIES"
page.should have_content "*.rb"
page.should have_content "Dmitriy Zaporozhets"
page.should have_content "Moving to rails 3.2"
page.should have_content "Initial commit"
end
end
......@@ -5,6 +5,6 @@ class ProjectBrowseTags < Spinach::FeatureSteps
Then 'I should see "Shop" all tags list' do
page.should have_content "Tags"
page.should have_content "v1.2.1"
page.should have_content "v1.0.0"
end
end
......@@ -6,31 +6,23 @@ class ForkProject < Spinach::FeatureSteps
step 'I click link "Fork"' do
page.should have_content "Shop"
page.should have_content "Fork"
Gitlab::Shell.any_instance.stub(:fork_repository).and_return(true)
click_link "Fork"
end
step 'I am a member of project "Shop"' do
@project = Project.find_by(name: "Shop")
@project ||= create(:project, name: "Shop", group: create(:group))
@project = create(:project, name: "Shop")
@project.team << [@user, :reporter]
end
step 'I should see the forked project page' do
page.should have_content "Project was successfully forked."
current_path.should include current_user.namespace.path
@forked_project = Project.find_by(namespace_id: current_user.namespace.path)
end
step 'I already have a project named "Shop" in my namespace' do
current_user.namespace ||= create(:namespace)
current_user.namespace.should_not be_nil
current_user.namespace.path.should_not be_nil
@my_project = create(:project, name: "Shop", namespace: current_user.namespace)
end
step 'I should see a "Name has already been taken" warning' do
page.should have_content "Name has already been taken"
end
end
......@@ -9,18 +9,11 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
@project = Project.find_by(name: "Shop")
@project ||= create(:project, name: "Shop")
@project.team << [@user, :reporter]
@project.ensure_satellite_exists
end
step 'I have a project forked off of "Shop" called "Forked Shop"' do
@forking_user = @user
forked_project_link = build(:forked_project_link)
@forked_project = Project.find_by(name: "Forked Shop")
@forked_project ||= create(:project, name: "Forked Shop", forked_project_link: forked_project_link, creator_id: @forking_user.id , namespace: @forking_user.namespace)
forked_project_link.forked_from_project = @project
forked_project_link.forked_to_project = @forked_project
@forked_project.team << [@forking_user , :master]
forked_project_link.save!
@forked_project = Projects::ForkService.new(@project, @user).execute
end
step 'I click link "New Merge Request"' do
......@@ -33,8 +26,8 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
current_path.should == project_merge_request_path(@project, @merge_request)
@merge_request.title.should == "Merge Request On Forked Project"
@merge_request.source_project.should == @forked_project
@merge_request.source_branch.should == "master"
@merge_request.target_branch.should == "stable"
@merge_request.source_branch.should == "fix"
@merge_request.target_branch.should == "master"
page.should have_content @forked_project.path_with_namespace
page.should have_content @project.path_with_namespace
page.should have_content @merge_request.source_branch
......@@ -42,17 +35,11 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
end
step 'I fill out a "Merge Request On Forked Project" merge request' do
select2 @forked_project.id, from: "#merge_request_source_project_id"
select2 @project.id, from: "#merge_request_target_project_id"
find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s
find(:select, "merge_request_target_project_id", {}).value.should == @project.id.to_s
select2 "master", from: "#merge_request_source_branch"
select2 "stable", from: "#merge_request_target_branch"
select @forked_project.path_with_namespace, from: "merge_request_source_project_id"
select @project.path_with_namespace, from: "merge_request_target_project_id"
select "fix", from: "merge_request_source_branch"
select "master", from: "merge_request_target_branch"
find(:select, "merge_request_source_branch", {}).value.should == 'master'
find(:select, "merge_request_target_branch", {}).value.should == 'stable'
click_button "Compare branches"
fill_in "merge_request_title", with: "Merge Request On Forked Project"
......@@ -101,8 +88,8 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
@merge_request = @project.merge_requests.last
current_path.should == project_merge_request_path(@project, @merge_request)
@merge_request.source_project.should == @forked_project
@merge_request.source_branch.should == "master"
@merge_request.target_branch.should == "stable"
@merge_request.source_branch.should == "fix"
@merge_request.target_branch.should == "master"
page.should have_content @forked_project.path_with_namespace
page.should have_content @project.path_with_namespace
page.should have_content @merge_request.source_branch
......@@ -114,33 +101,6 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
page.should have_link "Create Merge Request"
end
step 'project "Forked Shop" has push event' do
@forked_project = Project.find_by(name: "Forked Shop")
data = {
before: "0000000000000000000000000000000000000000",
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
ref: "refs/heads/new_design",
user_id: @user.id,
user_name: @user.name,
repository: {
name: @forked_project.name,
url: "localhost/rubinius",
description: "",
homepage: "localhost/rubinius",
private: true
}
}
@event = Event.create(
project: @forked_project,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
end
step 'I click link edit "Merge Request On Forked Project"' do
find("#edit_merge_request").click
end
......
......@@ -12,11 +12,10 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
@project.team << [@user, :master]
end
Then 'I should see files from repository in master' do
current_path.should == project_tree_path(@project, "master")
page.should have_content "Gemfile"
page.should have_content "app"
page.should have_content "README"
Then 'I should see files from repository in markdown' do
current_path.should == project_tree_path(@project, "markdown")
page.should have_content "README.md"
page.should have_content "CHANGELOG"
end
And 'I should see rendered README which contains correct links' do
......@@ -34,7 +33,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I should see correct document rendered' do
current_path.should == project_blob_path(@project, "master/doc/api/README.md")
current_path.should == project_blob_path(@project, "markdown/doc/api/README.md")
page.should have_content "All API requests require authentication"
end
......@@ -43,7 +42,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I should see correct directory rendered' do
current_path.should == project_tree_path(@project, "master/doc/raketasks")
current_path.should == project_tree_path(@project, "markdown/doc/raketasks")
page.should have_content "backup_restore.md"
page.should have_content "maintenance.md"
end
......@@ -53,7 +52,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I should see correct doc/api directory rendered' do
current_path.should == project_tree_path(@project, "master/doc/api")
current_path.should == project_tree_path(@project, "markdown/doc/api")
page.should have_content "README.md"
page.should have_content "users.md"
end
......@@ -63,7 +62,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I should see correct maintenance file rendered' do
current_path.should == project_blob_path(@project, "master/doc/raketasks/maintenance.md")
current_path.should == project_blob_path(@project, "markdown/doc/raketasks/maintenance.md")
page.should have_content "bundle exec rake gitlab:env:info RAILS_ENV=production"
end
......@@ -86,7 +85,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
And 'I see correct file rendered' do
current_path.should == project_blob_path(@project, "master/doc/api/README.md")
current_path.should == project_blob_path(@project, "markdown/doc/api/README.md")
page.should have_content "Contents"
page.should have_link "Users"
page.should have_link "Rake tasks"
......@@ -97,7 +96,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I should see the correct document file' do
current_path.should == project_blob_path(@project, "master/doc/api/users.md")
current_path.should == project_blob_path(@project, "markdown/doc/api/users.md")
page.should have_content "Get a list of users."
end
......@@ -125,9 +124,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
Then 'I should see files from repository in markdown branch' do
current_path.should == project_tree_path(@project, "markdown")
page.should have_content "Gemfile"
page.should have_content "app"
page.should have_content "README"
page.should have_content "README.md"
page.should have_content "CHANGELOG"
end
And 'I see correct file rendered in markdown branch' do
......@@ -256,8 +254,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Given 'I go directory which contains README file' do
visit project_tree_path(@project, "master/doc/api")
current_path.should == project_tree_path(@project, "master/doc/api")
visit project_tree_path(@project, "markdown/doc/api")
current_path.should == project_tree_path(@project, "markdown/doc/api")
end
And 'I click on a relative link in README' do
......@@ -265,7 +263,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I should see the correct markdown' do
current_path.should == project_blob_path(@project, "master/doc/api/users.md")
current_path.should == project_blob_path(@project, "markdown/doc/api/users.md")
page.should have_content "List users"
end
......
......@@ -61,8 +61,8 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
step 'I submit new merge request "Wiki Feature"' do
select "master", from: "merge_request_source_branch"
select "notes_refactoring", from: "merge_request_target_branch"
select "fix", from: "merge_request_source_branch"
select "feature", from: "merge_request_target_branch"
click_button "Compare branches"
fill_in "merge_request_title", with: "Wiki Feature"
click_button "Submit merge request"
......@@ -73,7 +73,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps
title: "Bug NS-04",
source_project: project,
target_project: project,
source_branch: 'stable',
source_branch: 'fix',
target_branch: 'master',
author: project.users.first,
description: "# Description header"
......@@ -104,9 +104,9 @@ class ProjectMergeRequests < Spinach::FeatureSteps
visit project_merge_request_path(project, merge_request)
end
step 'I click on the first commit in the merge request' do
within '.first-commits' do
click_link merge_request.commits.first.short_id(8)
step 'I click on the commit in the merge request' do
within '.mr-commits' do
click_link sample_commit.id[0..8]
end
end
......@@ -116,36 +116,35 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
step 'I leave a comment on the diff page in commit' do
find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
click_diff_line(sample_commit.line_code)
leave_comment "One comment to rule them all"
end
step 'I leave a comment like "Line is wrong" on line 185 of the first file' do
step 'I leave a comment like "Line is wrong" on diff' do
init_diff_note
leave_comment "Line is wrong"
end
step 'I leave a comment like "Line is wrong" on line 185 of the first file in commit' do
find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
step 'I leave a comment like "Line is wrong" on diff in commit' do
click_diff_line(sample_commit.line_code)
leave_comment "Line is wrong"
end
step 'I should see a discussion has started on line 185' do
step 'I should see a discussion has started on diff' do
page.should have_content "#{current_user.name} started a discussion"
page.should have_content "app/assets/stylesheets/tree.scss"
page.should have_content sample_commit.line_code_path
page.should have_content "Line is wrong"
end
step 'I should see a discussion has started on commit b1e6a9dbf1:L185' do
step 'I should see a discussion has started on commit diff' do
page.should have_content "#{current_user.name} started a discussion on commit"
page.should have_content "app/assets/stylesheets/tree.scss"
page.should have_content sample_commit.line_code_path
page.should have_content "Line is wrong"
end
step 'I should see a discussion has started on commit b1e6a9dbf1' do
step 'I should see a discussion has started on commit' do
page.should have_content "#{current_user.name} started a discussion on commit"
page.should have_content "One comment to rule them all"
page.should have_content "app/assets/stylesheets/tree.scss"
end
step 'merge request is mergeable' do
......@@ -162,6 +161,10 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
step 'I accept this merge request' do
Gitlab::Satellite::MergeAction.any_instance.stub(
merge!: true,
)
click_button "Accept Merge Request"
end
......@@ -248,7 +251,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
def init_diff_note
find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_172_185"]').click
click_diff_line(sample_commit.line_code)
end
def leave_comment(message)
......@@ -261,14 +264,18 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
def init_diff_note_first_file
find('a[data-line-code="a5cc2925ca8258af241be7e5b0381edf30266302_12_12"]').click
click_diff_line(sample_compare.changes[0][:line_code])
end
def init_diff_note_second_file
find('a[data-line-code="8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_28_39"]').click
click_diff_line(sample_compare.changes[1][:line_code])
end
def have_visible_content (text)
have_css("*", text: text, visible: true)
end
def click_diff_line(code)
find("a[data-line-code='#{code}']").click
end
end
......@@ -52,7 +52,7 @@ class ProjectMultiselectBlob < Spinach::FeatureSteps
page.evaluate_script("window.history.forward()")
end
step 'I click on "Gemfile.lock" file in repo' do
click_link "Gemfile.lock"
step 'I click on ".gitignore" file in repo' do
click_link ".gitignore"
end
end
......@@ -19,8 +19,8 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
page.should have_selector '.select2-chosen', text: "master"
end
And 'page should select "v2.1.0" in select box' do
page.should have_selector '.select2-chosen', text: "v2.1.0"
And 'page should select "v1.0.0" in select box' do
page.should have_selector '.select2-chosen', text: "v1.0.0"
end
And 'page should have "master" on graph' do
......@@ -29,13 +29,13 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
end
end
When 'I switch ref to "stable"' do
page.select 'stable', from: 'ref'
When 'I switch ref to "feature"' do
page.select 'feature', from: 'ref'
sleep 2
end
When 'I switch ref to "v2.1.0"' do
page.select 'v2.1.0', from: 'ref'
When 'I switch ref to "v1.0.0"' do
page.select 'v1.0.0', from: 'ref'
sleep 2
end
......@@ -44,43 +44,43 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
sleep 2
end
Then 'page should have content not containing "v2.1.0"' do
Then 'page should have content not containing "v1.0.0"' do
within '.network-graph' do
page.should have_content 'cleaning'
page.should have_content 'Change some files'
end
end
Then 'page should not have content not containing "v2.1.0"' do
Then 'page should not have content not containing "v1.0.0"' do
within '.network-graph' do
page.should_not have_content 'cleaning'
page.should_not have_content 'Change some files'
end
end
And 'page should select "stable" in select box' do
page.should have_selector '.select2-chosen', text: "stable"
And 'page should select "feature" in select box' do
page.should have_selector '.select2-chosen', text: "feature"
end
And 'page should select "v2.1.0" in select box' do
page.should have_selector '.select2-chosen', text: "v2.1.0"
And 'page should select "v1.0.0" in select box' do
page.should have_selector '.select2-chosen', text: "v1.0.0"
end
And 'page should have "stable" on graph' do
And 'page should have "feature" on graph' do
within '.network-graph' do
page.should have_content 'stable'
page.should have_content 'feature'
end
end
When 'I looking for a commit by SHA of "v2.1.0"' do
When 'I looking for a commit by SHA of "v1.0.0"' do
within ".network-form" do
fill_in 'extended_sha1', with: '98d6492'
fill_in 'extended_sha1', with: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9'
find('button').click
end
sleep 2
end
And 'page should have "v2.1.0" on graph' do
And 'page should have "v1.0.0" on graph' do
within '.network-graph' do
page.should have_content 'v2.1.0'
page.should have_content 'v1.0.0'
end
end
......
......@@ -33,18 +33,16 @@ class ProjectFeature < Spinach::FeatureSteps
step 'I should see project "Shop" version' do
within '.project-side' do
page.should have_content "Version: 2.2.0"
page.should have_content "Version: 6.7.0.pre"
end
end
step 'change project default branch' do
select 'stable', from: 'project_default_branch'
select 'fix', from: 'project_default_branch'
click_button 'Save changes'
end
step 'I should see project default branch changed' do
# TODO: Uncomment this when we can do real gitlab-shell calls
# from spinach tests. Right now gitlab-shell calls are stubbed so this test
# will not pass
# find(:css, 'select#project_default_branch').value.should == 'stable'
find(:css, 'select#project_default_branch').value.should == 'fix'
end
end
......@@ -3,15 +3,14 @@ class ProjectSearchCode < Spinach::FeatureSteps
include SharedProject
include SharedPaths
When 'I search for term "Welcome to GitLab"' do
fill_in "search", with: "Welcome to GitLab"
When 'I search for term "coffee"' do
fill_in "search", with: "coffee"
click_button "Go"
click_link 'Repository Code'
end
Then 'I should see files from repository containing "Welcome to GitLab"' do
page.should have_content "Welcome to GitLab"
page.should have_content "GitLab is a free project and repository management application"
Then 'I should see files from repository containing "coffee"' do
page.should have_content "coffee"
page.should have_content " CONTRIBUTING.md"
end
end
module SharedDiffNote
include Spinach::DSL
include RepoHelpers
Given 'I cancel the diff comment' do
within(diff_file_selector) do
......@@ -19,8 +20,8 @@ module SharedDiffNote
end
Given 'I leave a diff comment like "Typo, please fix"' do
find('a[data-line-code="586fb7c4e1add2d4d24e27566ed7064680098646_29_14"]').click
within("#{diff_file_selector} form[rel$='586fb7c4e1add2d4d24e27566ed7064680098646_29_14']") do
click_diff_line(sample_commit.line_code)
within("#{diff_file_selector} form[rel$='#{sample_commit.line_code}']") do
fill_in "note[note]", with: "Typo, please fix"
find(".js-comment-button").trigger("click")
sleep 0.05
......@@ -28,28 +29,28 @@ module SharedDiffNote
end
Given 'I preview a diff comment text like "Should fix it :smile:"' do
find('a[data-line-code="586fb7c4e1add2d4d24e27566ed7064680098646_29_14"]').click
within("#{diff_file_selector} form[rel$='586fb7c4e1add2d4d24e27566ed7064680098646_29_14']") do
click_diff_line(sample_commit.line_code)
within("#{diff_file_selector} form[rel$='#{sample_commit.line_code}']") do
fill_in "note[note]", with: "Should fix it :smile:"
find(".js-note-preview-button").trigger("click")
end
end
Given 'I preview another diff comment text like "DRY this up"' do
find('a[data-line-code="586fb7c4e1add2d4d24e27566ed7064680098646_57_41"]').click
click_diff_line(sample_commit.del_line_code)
within("#{diff_file_selector} form[rel$='586fb7c4e1add2d4d24e27566ed7064680098646_57_41']") do
within("#{diff_file_selector} form[rel$='#{sample_commit.del_line_code}']") do
fill_in "note[note]", with: "DRY this up"
find(".js-note-preview-button").trigger("click")
end
end
Given 'I open a diff comment form' do
find('a[data-line-code="586fb7c4e1add2d4d24e27566ed7064680098646_29_14"]').click
click_diff_line(sample_commit.line_code)
end
Given 'I open another diff comment form' do
find('a[data-line-code="586fb7c4e1add2d4d24e27566ed7064680098646_57_41"]').click
click_diff_line(sample_commit.del_line_code)
end
Given 'I write a diff comment like ":-1: I don\'t like this"' do
......@@ -155,6 +156,10 @@ module SharedDiffNote
end
def diff_file_selector
".diff-file"
".diff-file:nth-of-type(1)"
end
def click_diff_line(code)
find("a[data-line-code='#{code}']").click
end
end
module SharedPaths
include Spinach::DSL
include RepoHelpers
step 'I visit new project page' do
visit new_project_path
......@@ -257,15 +258,15 @@ module SharedPaths
end
step 'I visit blob file from repo' do
visit project_blob_path(@project, File.join(ValidCommit::ID, ValidCommit::BLOB_FILE_PATH))
visit project_blob_path(@project, File.join(sample_commit.id, sample_blob.path))
end
step 'I visit "Gemfile.lock" file in repo' do
visit project_blob_path(@project, File.join(root_ref, 'Gemfile.lock'))
step 'I visit ".gitignore" file in repo' do
visit project_blob_path(@project, File.join(root_ref, '.gitignore'))
end
step 'I visit project source page for "8470d70"' do
visit project_tree_path(@project, "8470d70")
step 'I visit project source page for "6d39438"' do
visit project_tree_path(@project, "6d39438")
end
step 'I visit project tags page' do
......@@ -273,7 +274,7 @@ module SharedPaths
end
step 'I visit project commit page' do
visit project_commit_path(@project, ValidCommit::ID)
visit project_commit_path(@project, sample_commit.id)
end
step 'I visit project "Shop" issues page' do
......
......@@ -26,8 +26,8 @@ module SharedProject
data = {
before: "0000000000000000000000000000000000000000",
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
ref: "refs/heads/new_design",
after: "6d394385cf567f80a8fd85055db1ab4c5295806f",
ref: "refs/heads/fix",
user_id: @user.id,
user_name: @user.name,
repository: {
......@@ -49,7 +49,7 @@ module SharedProject
Then 'I should see project "Shop" activity feed' do
project = Project.find_by(name: "Shop")
page.should have_content "#{@user.name} pushed new branch new_design at #{project.name_with_namespace}"
page.should have_content "#{@user.name} pushed new branch fix at #{project.name_with_namespace}"
end
Then 'I should see project settings' do
......
......@@ -15,7 +15,7 @@ require 'spinach/capybara'
require 'sidekiq/testing/inline'
%w(valid_commit valid_commit_with_alt_email big_commits select2_helper test_env).each do |f|
%w(select2_helper test_env repo_helpers).each do |f|
require Rails.root.join('spec', 'support', f)
end
......@@ -39,7 +39,6 @@ Capybara.ignore_hidden_elements = false
DatabaseCleaner.strategy = :truncation
Spinach.hooks.before_scenario do
TestEnv.setup_stubs
DatabaseCleaner.start
end
......@@ -48,7 +47,7 @@ Spinach.hooks.after_scenario do
end
Spinach.hooks.before_run do
TestEnv.init(mailer: false, init_repos: true, repos: false)
TestEnv.init(mailer: false)
RSpec::Mocks::setup self
include FactoryGirl::Syntax::Methods
......
......@@ -45,27 +45,30 @@ module Gitlab
handle_exception(ex)
end
# Get a raw diff of the source to the target
def diff_in_satellite
in_locked_and_timed_satellite do |merge_repo|
prepare_satellite!(merge_repo)
update_satellite_source_and_target!(merge_repo)
diff = merge_repo.git.native(:diff, default_options, "origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}")
# Only show what is new in the source branch compared to the target branch, not the other way around.
# The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit = merge_repo.git.native(:merge_base, default_options, ["origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}"]).strip
merge_repo.git.native(:diff, default_options, common_commit, "source/#{merge_request.source_branch}")
end
rescue Grit::Git::CommandFailed => ex
handle_exception(ex)
end
# Only show what is new in the source branch compared to the target branch, not the other way around.
# The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
def diffs_between_satellite
in_locked_and_timed_satellite do |merge_repo|
prepare_satellite!(merge_repo)
update_satellite_source_and_target!(merge_repo)
if merge_request.for_fork?
# Only show what is new in the source branch compared to the target branch, not the other way around.
# The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit = merge_repo.git.native(:merge_base, default_options, ["origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}"]).strip
#this method doesn't take default options
diffs = merge_repo.diff(common_commit, "source/#{merge_request.source_branch}")
else
raise "Attempt to determine diffs between for a non forked merge request in satellite MergeRequest.id:[#{merge_request.id}]"
......
......@@ -4,7 +4,8 @@ namespace :gitlab do
task :install, [:tag, :repo] => :environment do |t, args|
warn_user_is_not_gitlab
args.with_defaults(tag: "v1.9.3", repo: "https://gitlab.com/gitlab-org/gitlab-shell.git")
default_version = File.read(File.join(Rails.root, "GITLAB_SHELL_VERSION")).strip
args.with_defaults(tag: 'v' + default_version, repo: "https://gitlab.com/gitlab-org/gitlab-shell.git")
user = Settings.gitlab.user
home_dir = Settings.gitlab.user_home
......
......@@ -44,8 +44,8 @@ describe Projects::BlobController do
end
context 'redirect to tree' do
let(:id) { 'master/doc' }
it { should redirect_to("/#{project.path_with_namespace}/tree/master/doc") }
let(:id) { 'markdown/doc' }
it { should redirect_to("/#{project.path_with_namespace}/tree/markdown/doc") }
end
end
end
......@@ -3,12 +3,11 @@ require 'spec_helper'
describe Projects::MergeRequestsController do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project, target_branch: "stable", source_branch: "master") }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
before do
sign_in(user)
project.team << [user, :master]
Projects::MergeRequestsController.any_instance.stub(validates_merge_request: true, )
end
describe "#show" do
......@@ -61,7 +60,7 @@ describe Projects::MergeRequestsController do
it "should really be a git email patch with commit" do
get :show, project_id: project.to_param, id: merge_request.iid, format: format
expect(response.body[0..100]).to start_with("From 6ea87c47f0f8a24ae031c3fff17bc913889ecd00")
expect(response.body[0..100]).to start_with("From #{merge_request.commits.last.id}")
end
it "should contain git diffs" do
......
......@@ -26,7 +26,7 @@ describe Projects::TreeController do
end
context "valid branch, valid path" do
let(:id) { 'master/app/' }
let(:id) { 'master/encoding/' }
it { should respond_with(:success) }
end
......@@ -36,7 +36,7 @@ describe Projects::TreeController do
end
context "invalid branch, valid path" do
let(:id) { 'invalid-branch/app/' }
let(:id) { 'invalid-branch/encoding/' }
it { should respond_with(:not_found) }
end
end
......
......@@ -27,51 +27,6 @@ FactoryGirl.define do
factory :admin, traits: [:admin]
end
factory :empty_project, class: 'Project' do
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
namespace
creator
snippets_enabled true
trait :public do
visibility_level Gitlab::VisibilityLevel::PUBLIC
end
trait :internal do
visibility_level Gitlab::VisibilityLevel::INTERNAL
end
trait :private do
visibility_level Gitlab::VisibilityLevel::PRIVATE
end
end
# Generates a test repository from the repository stored under `spec/seed_project.tar.gz`.
# Once you run `rake gitlab:setup`, you can see what the repository looks like under `tmp/repositories/gitlabhq`.
# In order to modify files in the repository, you must untar the seed, modify and remake the tar.
# Before recompressing, do not forget to `git checkout master`.
# After recompressing, you need to run `RAILS_ENV=test bundle exec rake gitlab:setup` to regenerate the seeds under tmp.
#
# If you want to modify the repository only for an specific type of tests, e.g., markdown tests,
# consider using a feature branch to reduce the chances of collision with other tests.
# Create a new commit, and use the same commit message that you will use for the change in the main repo.
# Changing the commig message and SHA of branch `master` may break tests.
factory :project, parent: :empty_project do
path { 'gitlabhq' }
after :create do |project|
TestEnv.clear_repo_dir(project.namespace, project.path)
TestEnv.reset_satellite_dir
TestEnv.create_repo(project.namespace, project.path)
end
end
factory :redmine_project, parent: :project do
issues_tracker { "redmine" }
issues_tracker_id { "project_name_in_redmine" }
end
factory :group do
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
......@@ -107,105 +62,6 @@ FactoryGirl.define do
factory :reopened_issue, traits: [:reopened]
end
factory :merge_request do
title
author
source_project factory: :project
target_project { source_project }
# → git log stable..master --pretty=oneline
# b1e6a9dbf1c85e6616497a5e7bad9143a4bd0828 tree css fixes
# 8716fc78f3c65bbf7bcf7b574febd583bc5d2812 Added loading animation for notes
# cd5c4bac5042c5469dcdf7e7b2f768d3c6fd7088 notes count for wall
# 8470d70da67355c9c009e4401746b1d5410af2e3 notes controller refactored
# 1e689bfba39525ead225eaf611948cfbe8ac34cf fixed notes logic
# f0f14c8eaba69ebddd766498a9d0b0e79becd633 finished scss refactoring
# 3a4b4fb4cde7809f033822a171b9feae19d41fff Moving ui styles to one scss file, Added ui class to body
# 065c200c33f68c2bb781e35a43f9dc8138a893b5 removed unnecessary hr tags & titles
# 1e8b111be85df0db6c8000ef9a710bc0221eae83 Merge branch 'master' of github.com:gitlabhq/gitlabhq
# f403da73f5e62794a0447aca879360494b08f678 Fixed ajax loading image. Fixed wrong wording
# e6ea73c77600d413d370249b8e392734f7d1dbee Merge pull request #468 from bencevans/patch-1
# 4a3c05b69355deee25767a74d0512ec4b510d4ef Merge pull request #470 from bgondy/patch-1
# 0347fe2412eb51d3efeccc35210e9268bc765ac5 Update app/views/projects/team.html.haml
# 2b5c61bdece1f7eb2b901ceea7d364065cdf76ac Title for a link fixed
# 460eeb13b7560b40104044973ff933b1a6dbbcaa Increased count of notes loaded when visit wall page
# 21c141afb1c53a9180a99d2cca29ffa613eb7e3a Merge branch 'notes_refactoring'
# 292a41cbe295f16f7148913b31eb0fb91f3251c3 Fixed comments for snippets. Tests fixed
# d41d8ffb02fa74fd4571603548bd7e401ec99e0c Reply button, Comments for Merge Request diff
# b1a36b552be2a7a6bc57fbed6c52dc6ed82111f8 Merge pull request #466 from skroutz/no-rbenv
# db75dae913e8365453ca231f101b067314a7ea71 Merge pull request #465 from skroutz/branches_commit_link
# 75f040fbfe4b5af23ff004ad3207c3976df097a8 Don't enforce rbenv version
# e42fb4fda475370dcb0d8f8f1268bfdc7a0cc437 Fix broken commit link in branches page
# 215a01f63ccdc085f75a48f6f7ab6f2b15b5852c move notes login to one controller
# 81092c01984a481e312de10a28e3f1a6dda182a3 Status codes for errors, New error pages
# 7d279f9302151e3c8f4c5df9c5200a72799409b9 better error handling for not found resource, gitolite error
# 9e6d0710e927aa8ea834b8a9ae9f277be617ac7d Merge pull request #443 from CedricGatay/fix/incorrectLineNumberingInDiff
# 6ea87c47f0f8a24ae031c3fff17bc913889ecd00 Incorrect line numbering in diff
#
# → git log master..stable --pretty=oneline
# empty
source_branch "master"
target_branch "stable"
trait :with_diffs do
end
trait :closed do
state :closed
end
trait :reopened do
state :reopened
end
trait :simple do
source_branch "simple_merge_request"
target_branch "master"
end
factory :closed_merge_request, traits: [:closed]
factory :reopened_merge_request, traits: [:reopened]
factory :merge_request_with_diffs, traits: [:with_diffs]
end
factory :note do
project
note "Note"
author
factory :note_on_commit, traits: [:on_commit]
factory :note_on_commit_diff, traits: [:on_commit, :on_diff]
factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
factory :note_on_merge_request, traits: [:on_merge_request]
factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
trait :on_commit do
project factory: :project
commit_id "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
noteable_type "Commit"
end
trait :on_diff do
line_code "0_184_184"
end
trait :on_merge_request do
project factory: :project
noteable_id 1
noteable_type "MergeRequest"
end
trait :on_issue do
noteable_id 1
noteable_type "Issue"
end
trait :with_attachment do
attachment { fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "`/png") }
end
end
factory :event do
factory :closed_issue_event do
project
......
FactoryGirl.define do
factory :merge_request do
title
author
source_project factory: :project
target_project { source_project }
# → git log --pretty=oneline feature..master
# 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com
# 570e7b2abdd848b95f2f578043fc23bd6f6fd24d Change some files
# 6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 More submodules
# d14d6c0abdd253381df51a723d58691b2ee1ab08 Remove ds_store files
# c1acaa58bbcbc3eafe538cb8274ba387047b69f8 Ignore DS files
#
# See also RepoHelpers.sample_compare
#
source_branch "master"
target_branch "feature"
merge_status :can_be_merged
trait :with_diffs do
end
trait :conflict do
source_branch "feature_conflict"
target_branch "feature"
end
trait :closed do
state :closed
end
trait :reopened do
state :reopened
end
trait :simple do
source_branch "feature"
target_branch "master"
end
factory :closed_merge_request, traits: [:closed]
factory :reopened_merge_request, traits: [:reopened]
factory :merge_request_with_diffs, traits: [:with_diffs]
end
end
require_relative '../support/repo_helpers'
FactoryGirl.define do
factory :note do
project
note "Note"
author
factory :note_on_commit, traits: [:on_commit]
factory :note_on_commit_diff, traits: [:on_commit, :on_diff]
factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
factory :note_on_merge_request, traits: [:on_merge_request]
factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
trait :on_commit do
project factory: :project
commit_id RepoHelpers.sample_commit.id
noteable_type "Commit"
end
trait :on_diff do
line_code "0_184_184"
end
trait :on_merge_request do
project factory: :project
noteable_id 1
noteable_type "MergeRequest"
end
trait :on_issue do
noteable_id 1
noteable_type "Issue"
end
trait :with_attachment do
attachment { fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "`/png") }
end
end
end
FactoryGirl.define do
factory :empty_project, class: 'Project' do
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
namespace
creator
snippets_enabled true
trait :public do
visibility_level Gitlab::VisibilityLevel::PUBLIC
end
trait :internal do
visibility_level Gitlab::VisibilityLevel::INTERNAL
end
trait :private do
visibility_level Gitlab::VisibilityLevel::PRIVATE
end
end
# Generates a test repository from the repository stored under `spec/seed_project.tar.gz`.
# Once you run `rake gitlab:setup`, you can see what the repository looks like under `tmp/repositories/gitlabhq`.
# In order to modify files in the repository, you must untar the seed, modify and remake the tar.
# Before recompressing, do not forget to `git checkout master`.
# After recompressing, you need to run `RAILS_ENV=test bundle exec rake gitlab:setup` to regenerate the seeds under tmp.
#
# If you want to modify the repository only for an specific type of tests, e.g., markdown tests,
# consider using a feature branch to reduce the chances of collision with other tests.
# Create a new commit, and use the same commit message that you will use for the change in the main repo.
# Changing the commig message and SHA of branch `master` may break tests.
factory :project, parent: :empty_project do
path { 'gitlabhq' }
after :create do |project|
TestEnv.copy_repo(project)
end
end
factory :redmine_project, parent: :project do
issues_tracker { "redmine" }
issues_tracker_id { "project_name_in_redmine" }
end
end
......@@ -132,12 +132,12 @@ describe ApplicationHelper do
it "includes a list of branch names" do
options[0][0].should == 'Branches'
options[0][1].should include('master', 'stable')
options[0][1].should include('master', 'feature')
end
it "includes a list of tag names" do
options[1][0].should == 'Tags'
options[1][1].should include('v0.9.4','v1.2.0')
options[1][1].should include('v1.0.0','v1.1.0')
end
it "includes a specific commit ref if defined" do
......
......@@ -17,6 +17,7 @@ describe GitlabMarkdownHelper do
before do
# Helper expects a @project instance variable
@project = project
@ref = 'markdown'
@repository = project.repository
end
......@@ -472,13 +473,13 @@ describe GitlabMarkdownHelper do
it "should handle relative urls for a file in master" do
actual = "[GitLab API doc](doc/api/README.md)\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md\">GitLab API doc</a></p>\n"
markdown(actual).should match(expected)
end
it "should handle relative urls for a directory in master" do
actual = "[GitLab API doc](doc/api)\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/tree/master/doc/api\">GitLab API doc</a></p>\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/tree/#{@ref}/doc/api\">GitLab API doc</a></p>\n"
markdown(actual).should match(expected)
end
......@@ -490,13 +491,13 @@ describe GitlabMarkdownHelper do
it "should handle relative urls in reference links for a file in master" do
actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md\">GitLab API doc</a></p>\n"
markdown(actual).should match(expected)
end
it "should handle relative urls in reference links for a directory in master" do
actual = "[GitLab API doc directory][GitLab readmes]\n [GitLab readmes]: doc/api/\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/tree/master/doc/api\">GitLab API doc directory</a></p>\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/tree/#{@ref}/doc/api\">GitLab API doc directory</a></p>\n"
markdown(actual).should match(expected)
end
......
require 'spec_helper'
describe 'Gitlab::Satellite::MergeAction' do
before(:each) do
@master = ['master', '69b34b7e9ad9f496f0ad10250be37d6265a03bba']
@one_after_stable = ['stable', '6ea87c47f0f8a24ae031c3fff17bc913889ecd00'] #this commit sha is one after stable
@wiki_branch = ['wiki', '635d3e09b72232b6e92a38de6cc184147e5bcb41'] #this is the commit sha where the wiki branch goes off from master
@conflicting_metior = ['metior', '313d96e42b313a0af5ab50fa233bf43e27118b3f'] #this branch conflicts with the wiki branch
# these commits are quite close together, itended to make string diffs/format patches small
@close_commit1 = ['2_3_notes_fix', '8470d70da67355c9c009e4401746b1d5410af2e3']
@close_commit2 = ['scss_refactoring', 'f0f14c8eaba69ebddd766498a9d0b0e79becd633']
end
include RepoHelpers
let(:project) { create(:project, namespace: create(:group)) }
let(:fork_project) { create(:project, namespace: create(:group), forked_from_project: project) }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:merge_request_fork) { create(:merge_request, source_project: fork_project, target_project: project) }
let(:merge_request_with_conflict) { create(:merge_request, :conflict, source_project: project, target_project: project) }
let(:merge_request_fork_with_conflict) { create(:merge_request, :conflict, source_project: project, target_project: project) }
describe '#commits_between' do
def verify_commits(commits, first_commit_sha, last_commit_sha)
commits.each { |commit| commit.class.should == Gitlab::Git::Commit }
......@@ -26,51 +20,27 @@ describe 'Gitlab::Satellite::MergeAction' do
context 'on fork' do
it 'should get proper commits between' do
merge_request_fork.target_branch = @one_after_stable[0]
merge_request_fork.source_branch = @master[0]
commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between
verify_commits(commits, @one_after_stable[1], @master[1])
merge_request_fork.target_branch = @wiki_branch[0]
merge_request_fork.source_branch = @master[0]
commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between
verify_commits(commits, @wiki_branch[1], @master[1])
verify_commits(commits, sample_compare.commits.first, sample_compare.commits.last)
end
end
context 'between branches' do
it 'should raise exception -- not expected to be used by non forks' do
merge_request.target_branch = @one_after_stable[0]
merge_request.source_branch = @master[0]
expect {Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between}.to raise_error
merge_request.target_branch = @wiki_branch[0]
merge_request.source_branch = @master[0]
expect {Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between}.to raise_error
expect { Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between }.to raise_error
end
end
end
describe '#format_patch' do
let(:target_commit) {['artiom-config-examples','9edbac5ac88ffa1ec9dad0097226b51e29ebc9ac']}
let(:source_commit) {['metior', '313d96e42b313a0af5ab50fa233bf43e27118b3f']}
def verify_content(patch)
(patch.include? source_commit[1]).should be_true
(patch.include? '635d3e09b72232b6e92a38de6cc184147e5bcb41').should be_true
(patch.include? '2bb2dee057327c81978ed0aa99904bd7ff5e6105').should be_true
(patch.include? '2e83de1924ad3429b812d17498b009a8b924795d').should be_true
(patch.include? 'ee45a49c57a362305431cbf004e4590b713c910e').should be_true
(patch.include? 'a6870dd08f8f274d9a6b899f638c0c26fefaa690').should be_true
(patch.include? 'e74fae147abc7d2ffbf93d363dbbe45b87751f6f').should be_false
(patch.include? '86f76b11c670425bbab465087f25172378d76147').should be_false
sample_compare.commits.each do |commit|
patch.include?(commit).should be_true
end
end
context 'on fork' do
it 'should build a format patch' do
merge_request_fork.target_branch = target_commit[0]
merge_request_fork.source_branch = source_commit[0]
patch = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).format_patch
verify_content(patch)
end
......@@ -78,8 +48,6 @@ describe 'Gitlab::Satellite::MergeAction' do
context 'between branches' do
it 'should build a format patch' do
merge_request.target_branch = target_commit[0]
merge_request.source_branch = source_commit[0]
patch = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request).format_patch
verify_content(patch)
end
......@@ -87,7 +55,6 @@ describe 'Gitlab::Satellite::MergeAction' do
end
describe '#diffs_between_satellite tested against diff_in_satellite' do
def is_a_matching_diff(diff, diffs)
diff_count = diff.scan('diff --git').size
diff_count.should >= 1
......@@ -100,50 +67,38 @@ describe 'Gitlab::Satellite::MergeAction' do
context 'on fork' do
it 'should get proper diffs' do
merge_request_fork.target_branch = @close_commit1[0]
merge_request_fork.source_branch = @master[0]
diffs = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).diffs_between_satellite
merge_request_fork.target_branch = @close_commit1[0]
merge_request_fork.source_branch = @master[0]
diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request_fork).diff_in_satellite
is_a_matching_diff(diff, diffs)
end
end
context 'between branches' do
it 'should get proper diffs' do
merge_request.target_branch = @close_commit1[0]
merge_request.source_branch = @master[0]
expect{Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diffs_between_satellite}.to raise_error
expect{ Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diffs_between_satellite }.to raise_error
end
end
end
describe '#can_be_merged?' do
context 'on fork' do
it 'return true or false depending on if something is mergable' do
merge_request_fork.target_branch = @one_after_stable[0]
merge_request_fork.source_branch = @master[0]
Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).can_be_merged?.should be_true
merge_request_fork.target_branch = @conflicting_metior[0]
merge_request_fork.source_branch = @wiki_branch[0]
Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).can_be_merged?.should be_false
end
it { Gitlab::Satellite::MergeAction.new(
merge_request_fork.author,
merge_request_fork).can_be_merged?.should be_true }
it { Gitlab::Satellite::MergeAction.new(
merge_request_fork_with_conflict.author,
merge_request_fork_with_conflict).can_be_merged?.should be_false }
end
context 'between branches' do
it 'return true or false depending on if something is mergable' do
merge_request.target_branch = @one_after_stable[0]
merge_request.source_branch = @master[0]
Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).can_be_merged?.should be_true
merge_request.target_branch = @conflicting_metior[0]
merge_request.source_branch = @wiki_branch[0]
Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).can_be_merged?.should be_false
end
it { Gitlab::Satellite::MergeAction.new(
merge_request.author,
merge_request).can_be_merged?.should be_true }
it { Gitlab::Satellite::MergeAction.new(
merge_request_with_conflict.author,
merge_request_with_conflict).can_be_merged?.should be_false }
end
end
end
......@@ -3,6 +3,7 @@ require 'spec_helper'
describe Notify do
include EmailSpec::Helpers
include EmailSpec::Matchers
include RepoHelpers
let(:gitlab_sender) { Gitlab.config.gitlab.email_from }
let(:recipient) { create(:user, email: 'recipient@example.com') }
......@@ -524,7 +525,7 @@ describe Notify do
describe 'email on push with multiple commits' do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, 'cd5c4bac', 'b1e6a9db') }
let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, sample_image_commit.id, sample_commit.id) }
let(:commits) { Commit.decorate(compare.commits) }
let(:diff_path) { project_compare_path(project, from: commits.first, to: commits.last) }
......@@ -545,11 +546,11 @@ describe Notify do
end
it 'includes commits list' do
should have_body_text /tree css fixes/
should have_body_text /Change some files/
end
it 'includes diffs' do
should have_body_text /Checkout wiki pages for installation information/
should have_body_text /def archive_formats_regex/
end
it 'contains a link to the diff' do
......@@ -560,7 +561,7 @@ describe Notify do
describe 'email on push with a single commit' do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, '8716fc78', 'b1e6a9db') }
let(:compare) { Gitlab::Git::Compare.new(project.repository.raw_repository, sample_commit.parent_id, sample_commit.id) }
let(:commits) { Commit.decorate(compare.commits) }
let(:diff_path) { project_commit_path(project, commits.first) }
......@@ -581,11 +582,11 @@ describe Notify do
end
it 'includes commits list' do
should have_body_text /tree css fixes/
should have_body_text /Change some files/
end
it 'includes diffs' do
should have_body_text /Checkout wiki pages for installation information/
should have_body_text /def archive_formats_regex/
end
it 'contains a link to the diff' do
......
......@@ -11,7 +11,7 @@ describe Commit do
end
it "truncates a message without a newline at 80 characters" do
message = commit.safe_message * 10
message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.'
commit.stub(:safe_message).and_return(message)
commit.title.should == "#{message[0..79]}&hellip;"
......@@ -24,11 +24,14 @@ describe Commit do
commit.title.should == message
end
it "truncates a message with a newline after 80 characters at 70 characters" do
message = (commit.safe_message * 10) + "\n"
it "does not truncates a message with a newline after 80 but less 100 characters" do
message =<<eos
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
Vivamus egestas lacinia lacus, sed rutrum mauris.
eos
commit.stub(:safe_message).and_return(message)
commit.title.should == "#{message[0..79]}&hellip;"
commit.title.should == message.split("\n").first
end
end
......
......@@ -124,24 +124,21 @@ describe Project do
describe :update_merge_requests do
let(:project) { create(:project) }
before do
@merge_request = create(:merge_request, source_project: project, target_project: project)
@key = create(:key, user_id: project.owner.id)
end
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:key) { create(:key, user_id: project.owner.id) }
let(:prev_commit_id) { merge_request.commits.last.id }
let(:commit_id) { merge_request.commits.first.id }
it "should close merge request if last commit from source branch was pushed to target branch" do
@merge_request.reload_code
@merge_request.last_commit.id.should == "69b34b7e9ad9f496f0ad10250be37d6265a03bba"
project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "69b34b7e9ad9f496f0ad10250be37d6265a03bba", "refs/heads/stable", @key.user)
@merge_request.reload
@merge_request.merged?.should be_true
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.target_branch}", key.user)
merge_request.reload
merge_request.merged?.should be_true
end
it "should update merge request commits with new one if pushed to source branch" do
project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "69b34b7e9ad9f496f0ad10250be37d6265a03bba", "refs/heads/master", @key.user)
@merge_request.reload
@merge_request.last_commit.id.should == "69b34b7e9ad9f496f0ad10250be37d6265a03bba"
project.update_merge_requests(prev_commit_id, commit_id, "refs/heads/#{merge_request.source_branch}", key.user)
merge_request.reload
merge_request.last_commit.id.should == commit_id
end
end
......@@ -237,7 +234,7 @@ describe Project do
project.protected_branches.create(name: 'master')
end
it { project.open_branches.map(&:name).should include('bootstrap') }
it { project.open_branches.map(&:name).should include('feature') }
it { project.open_branches.map(&:name).should_not include('master') }
end
......
require "spec_helper"
describe ProjectWiki do
def remove_temp_repo(path)
FileUtils.rm_rf path
end
def commit_details
commit = {name: user.name, email: user.email, message: "test commit"}
end
def create_page(name, content)
subject.wiki.write_page(name, :markdown, content, commit_details)
end
def destroy_page(page)
subject.wiki.delete_page(page, commit_details)
end
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
let(:repository) { project.repository }
let(:user) { project.owner }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_wiki) { ProjectWiki.new(project, user) }
subject { ProjectWiki.new(project, user) }
before do
create_temp_repo(subject.send(:path_to_repo))
end
subject { project_wiki }
before { project_wiki.wiki }
describe "#path_with_namespace" do
it "returns the project path with namespace with the .wiki extension" do
......@@ -60,23 +41,13 @@ describe ProjectWiki do
subject.wiki.should be_a Gollum::Wiki
end
before do
Gitlab::Shell.any_instance.stub(:add_repository) do
create_temp_repo("#{Rails.root}/tmp/test-git-base-path/non-existant.wiki.git")
end
project.stub(:path_with_namespace).and_return("non-existant")
end
it "creates a new wiki repo if one does not yet exist" do
wiki = ProjectWiki.new(project, user)
wiki.create_page("index", "test content").should_not == false
FileUtils.rm_rf wiki.send(:path_to_repo)
project_wiki.create_page("index", "test content").should be_true
end
it "raises CouldNotCreateWikiError if it can't create the wiki repository" do
ProjectWiki.any_instance.stub(:init_repo).and_return(false)
expect { ProjectWiki.new(project, user).wiki }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)
project_wiki.stub(:init_repo).and_return(false)
expect { project_wiki.send(:create_repo!) }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)
end
end
......@@ -242,4 +213,26 @@ describe ProjectWiki do
end
end
private
def create_temp_repo(path)
FileUtils.mkdir_p path
system(*%W(git init --quiet --bare -- #{path}))
end
def remove_temp_repo(path)
FileUtils.rm_rf path
end
def commit_details
commit = {name: user.name, email: user.email, message: "test commit"}
end
def create_page(name, content)
subject.wiki.write_page(name, :markdown, content, commit_details)
end
def destroy_page(page)
subject.wiki.delete_page(page, commit_details)
end
end
require "spec_helper"
describe WikiPage do
def remove_temp_repo(path)
FileUtils.rm_rf path
end
def commit_details
commit = {name: user.name, email: user.email, message: "test commit"}
end
def create_page(name, content)
wiki.wiki.write_page(name, :markdown, content, commit_details)
end
def destroy_page(title)
page = wiki.wiki.paged(title)
wiki.wiki.delete_page(page, commit_details)
end
let(:project) { create(:project) }
let(:repository) { project.repository }
let(:project) { create(:empty_project) }
let(:user) { project.owner }
let(:wiki) { ProjectWiki.new(project, user) }
subject { WikiPage.new(wiki) }
before do
create_temp_repo(wiki.send(:path_to_repo))
end
describe "#initialize" do
context "when initialized with an existing gollum page" do
before do
......@@ -171,4 +148,22 @@ describe WikiPage do
end
end
private
def remove_temp_repo(path)
FileUtils.rm_rf path
end
def commit_details
commit = {name: user.name, email: user.email, message: "test commit"}
end
def create_page(name, content)
wiki.wiki.write_page(name, :markdown, content, commit_details)
end
def destroy_page(title)
page = wiki.wiki.paged(title)
wiki.wiki.delete_page(page, commit_details)
end
end
......@@ -9,6 +9,8 @@ describe API::API, api: true do
let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: UsersProject::GUEST) }
let!(:branch_name) { 'feature' }
let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
describe "GET /projects/:id/repository/branches" do
it "should return an array of project branches" do
......@@ -21,11 +23,11 @@ describe API::API, api: true do
describe "GET /projects/:id/repository/branches/:branch" do
it "should return the branch information for a single branch" do
get api("/projects/#{project.id}/repository/branches/new_design", user)
get api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
response.status.should == 200
json_response['name'].should == 'new_design'
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['name'].should == branch_name
json_response['commit']['id'].should == branch_sha
json_response['protected'].should == false
end
......@@ -42,11 +44,11 @@ describe API::API, api: true do
describe "PUT /projects/:id/repository/branches/:branch/protect" do
it "should protect a single branch" do
put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
response.status.should == 200
json_response['name'].should == 'new_design'
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['name'].should == branch_name
json_response['commit']['id'].should == branch_sha
json_response['protected'].should == true
end
......@@ -56,24 +58,24 @@ describe API::API, api: true do
end
it "should return a 403 error if guest" do
put api("/projects/#{project.id}/repository/branches/new_design/protect", user2)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user2)
response.status.should == 403
end
it "should return success when protect branch again" do
put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/protect", user)
response.status.should == 200
end
end
describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
it "should unprotect a single branch" do
put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
response.status.should == 200
json_response['name'].should == 'new_design'
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['name'].should == branch_name
json_response['commit']['id'].should == branch_sha
json_response['protected'].should == false
end
......@@ -83,8 +85,8 @@ describe API::API, api: true do
end
it "should return success when unprotect branch again" do
put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
put api("/projects/#{project.id}/repository/branches/#{branch_name}/unprotect", user)
response.status.should == 200
end
end
......@@ -92,19 +94,19 @@ describe API::API, api: true do
describe "POST /projects/:id/repository/branches" do
it "should create a new branch" do
post api("/projects/#{project.id}/repository/branches", user),
branch_name: 'new_design',
ref: '621491c677087aa243f165eab467bfdfbee00be1'
branch_name: branch_name,
ref: branch_sha
response.status.should == 201
json_response['name'].should == 'new_design'
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['name'].should == branch_name
json_response['commit']['id'].should == branch_sha
end
it "should deny for user without push access" do
post api("/projects/#{project.id}/repository/branches", user2),
branch_name: 'new_design',
ref: '621491c677087aa243f165eab467bfdfbee00be1'
branch_name: branch_name,
ref: branch_sha
response.status.should == 403
end
......@@ -114,13 +116,13 @@ describe API::API, api: true do
before { Repository.any_instance.stub(rm_branch: true) }
it "should remove branch" do
delete api("/projects/#{project.id}/repository/branches/new_design", user)
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
response.status.should == 200
end
it "should remove protected branch" do
project.protected_branches.create(name: 'new_design')
delete api("/projects/#{project.id}/repository/branches/new_design", user)
project.protected_branches.create(name: branch_name)
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)
response.status.should == 405
json_response['message'].should == 'Protected branch cant be removed'
end
......
......@@ -4,20 +4,22 @@ describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let(:file_path) { 'files/ruby/popen.rb' }
before { project.team << [user, :developer] }
describe "GET /projects/:id/repository/files" do
it "should return file info" do
params = {
file_path: 'app/models/key.rb',
file_path: file_path,
ref: 'master',
}
get api("/projects/#{project.id}/repository/files", user), params
response.status.should == 200
json_response['file_path'].should == 'app/models/key.rb'
json_response['file_name'].should == 'key.rb'
Base64.decode64(json_response['content']).lines.first.should == "class Key < ActiveRecord::Base\n"
json_response['file_path'].should == file_path
json_response['file_name'].should == 'popen.rb'
Base64.decode64(json_response['content']).lines.first.should == "require 'fileutils'\n"
end
it "should return a 400 bad request if no params given" do
......@@ -74,7 +76,7 @@ describe API::API, api: true do
describe "PUT /projects/:id/repository/files" do
let(:valid_params) {
{
file_path: 'spec/spec_helper.rb',
file_path: file_path,
branch_name: 'master',
content: 'puts 8',
commit_message: 'Changed file'
......@@ -88,7 +90,7 @@ describe API::API, api: true do
put api("/projects/#{project.id}/repository/files", user), valid_params
response.status.should == 200
json_response['file_path'].should == 'spec/spec_helper.rb'
json_response['file_path'].should == file_path
end
it "should return a 400 bad request if no params given" do
......@@ -109,7 +111,7 @@ describe API::API, api: true do
describe "DELETE /projects/:id/repository/files" do
let(:valid_params) {
{
file_path: 'spec/spec_helper.rb',
file_path: file_path,
branch_name: 'master',
commit_message: 'Changed file'
}
......@@ -122,7 +124,7 @@ describe API::API, api: true do
delete api("/projects/#{project.id}/repository/files", user), valid_params
response.status.should == 200
json_response['file_path'].should == 'spec/spec_helper.rb'
json_response['file_path'].should == file_path
end
it "should return a 400 bad request if no params given" do
......
......@@ -3,6 +3,8 @@ require 'mime/types'
describe API::API, api: true do
include ApiHelpers
include RepoHelpers
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) }
......@@ -29,6 +31,7 @@ describe API::API, api: true do
response.status.should == 201
json_response['name'].should == 'v1.0.0'
end
it 'should deny for user without push access' do
post api("/projects/#{project.id}/repository/tags", user2),
tag_name: 'v1.0.0',
......@@ -47,7 +50,7 @@ describe API::API, api: true do
response.status.should == 200
json_response.should be_an Array
json_response.first['name'].should == 'app'
json_response.first['name'].should == 'encoding'
json_response.first['type'].should == 'tree'
json_response.first['mode'].should == '040000'
end
......@@ -92,7 +95,7 @@ describe API::API, api: true do
describe "GET /projects/:id/repository/raw_blobs/:sha" do
it "should get the raw file contents" do
get api("/projects/#{project.id}/repository/raw_blobs/d1aff2896d99d7acc4d9780fbb716b113c45ecf7", user)
get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user)
response.status.should == 200
end
end
......@@ -130,21 +133,21 @@ describe API::API, api: true do
describe 'GET /projects/:id/repository/compare' do
it "should compare branches" do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request'
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature'
response.status.should == 200
json_response['commits'].should be_present
json_response['diffs'].should be_present
end
it "should compare tags" do
get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.1', to: 'v1.0.2'
get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0'
response.status.should == 200
json_response['commits'].should be_present
json_response['diffs'].should be_present
end
it "should compare commits" do
get api("/projects/#{project.id}/repository/compare", user), from: 'b1e6a9dbf1c85', to: '1e689bfba395'
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id
response.status.should == 200
json_response['commits'].should be_empty
json_response['diffs'].should be_empty
......@@ -152,7 +155,7 @@ describe API::API, api: true do
end
it "should compare commits in reverse order" do
get api("/projects/#{project.id}/repository/compare", user), from: '1e689bfba395', to: 'b1e6a9dbf1c85'
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id
response.status.should == 200
json_response['commits'].should be_present
json_response['diffs'].should be_present
......@@ -175,9 +178,9 @@ describe API::API, api: true do
contributor = json_response.first
contributor['email'].should == 'dmitriy.zaporozhets@gmail.com'
contributor['name'].should == 'Dmitriy Zaporozhets'
contributor['commits'].should == 185
contributor['additions'].should == 66072
contributor['deletions'].should == 63013
contributor['commits'].should == 13
contributor['additions'].should == 4081
contributor['deletions'].should == 29
end
end
end
require 'spec_helper'
describe GitPushService do
include RepoHelpers
let (:user) { create :user }
let (:project) { create :project }
let (:service) { GitPushService.new }
before do
@blankrev = '0000000000000000000000000000000000000000'
@oldrev = 'b98a310def241a6fd9c9a9a3e7934c48e498fe81'
@newrev = 'b19a04f53caeebf4fe5ec2327cb83e9253dc91bb'
@oldrev = sample_commit.parent_id
@newrev = sample_commit.id
@ref = 'refs/heads/master'
end
......
......@@ -38,14 +38,7 @@ RSpec.configure do |config|
config.include TestEnv
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.before(:suite) do
TestEnv.init(init_repos: true, repos: false)
end
config.before(:each) do
TestEnv.setup_stubs
TestEnv.init
end
end
module BigCommits
HUGE_COMMIT_ID = "7f92534f767fa20357a11c63f973ae3b79cc5b85"
HUGE_COMMIT_MESSAGE = "pybments.rb version up. gitignore improved"
BIG_COMMIT_ID = "d62200cad430565bd9f80befaf329297120330b5"
BIG_COMMIT_MESSAGE = "clean-up code"
end
module RepoHelpers
extend self
# Text file in repo
#
# Ex.
#
# # Get object
# blob = RepoHelpers.text_blob
#
# blob.path # => 'files/js/commit.js.coffee'
# blob.data # => 'class Commit...'
#
def sample_blob
OpenStruct.new(
oid: '5f53439ca4b009096571d3c8bc3d09d30e7431b3',
path: "files/js/commit.js.coffee",
data: <<eos
class Commit
constructor: ->
$('.files .diff-file').each ->
new CommitFile(this)
@Commit = Commit
eos
)
end
def sample_commit
OpenStruct.new(
id: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
parent_id: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9',
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
files_changed_count: 2,
line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14',
line_code_path: 'files/ruby/popen.rb',
del_line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13',
message: <<eos
Change some files
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
end
def sample_big_commit
OpenStruct.new(
id: "913c66a37b4a45b9769037c55c2d238bd0942d2e",
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
message: <<eos
Files, encoding and much more
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
end
def sample_image_commit
OpenStruct.new(
id: "2f63565e7aac07bcdadb654e253078b727143ec4",
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
old_blob_id: '33f3729a45c02fc67d00adb1b8bca394b0e761d9',
new_blob_id: '2f63565e7aac07bcdadb654e253078b727143ec4',
message: <<eos
Modified image
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
end
def sample_compare
changes = [
{
line_code: 'a5cc2925ca8258af241be7e5b0381edf30266302_20_20',
file_path: '.gitignore',
},
{
line_code: '7445606fbf8f3683cd42bdc54b05d7a0bc2dfc44_4_6',
file_path: '.gitmodules',
}
]
commits = [
'5937ac0a7beb003549fc5fd26fc247adbce4a52e',
'570e7b2abdd848b95f2f578043fc23bd6f6fd24d',
'6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9',
'd14d6c0abdd253381df51a723d58691b2ee1ab08',
'c1acaa58bbcbc3eafe538cb8274ba387047b69f8',
].reverse # last commit is recent one
OpenStruct.new(
source_branch: 'master',
target_branch: 'feature',
changes: changes,
commits: commits
)
end
end
......@@ -5,167 +5,63 @@ module TestEnv
# Test environment
#
# all repositories and namespaces stored at
# RAILS_APP/tmp/test-git-base-path
#
# Next shell methods are stubbed and return true
# - mv_repository
# - remove_repository
# - add_key
# - remove_key
# See gitlab.yml.example test section for paths
#
def init(opts = {})
RSpec::Mocks::setup(self)
# Disable mailer for spinach tests
disable_mailer if opts[:mailer] == false
setup_stubs
clear_test_repo_dir if opts[:init_repos] == true
setup_test_repos(opts) if opts[:repos] == true
end
def disable_mailer
NotificationService.any_instance.stub(mailer: double.as_null_object)
end
def enable_mailer
NotificationService.any_instance.unstub(:mailer)
end
# Clean /tmp/tests
tmp_test_path = Rails.root.join('tmp', 'tests')
def setup_stubs()
# Use tmp dir for FS manipulations
repos_path = testing_path()
ProjectWiki.any_instance.stub(:init_repo) do |path|
create_temp_repo(File.join(repos_path, "#{path}.git"))
if File.directory?(tmp_test_path)
FileUtils.rm_r(tmp_test_path)
end
Gitlab.config.gitlab_shell.stub(repos_path: repos_path)
FileUtils.mkdir_p(tmp_test_path)
Gitlab.config.satellites.stub(path: satellite_path)
# Setup GitLab shell for test instance
setup_gitlab_shell
Gitlab::Git::Repository.stub(repos_path: repos_path)
Gitlab::Shell.any_instance.stub(
add_repository: true,
mv_repository: true,
remove_repository: true,
update_repository_head: true,
add_key: true,
remove_key: true,
version: '6.3.0'
)
Gitlab::Satellite::MergeAction.any_instance.stub(
merge!: true,
)
Gitlab::Satellite::Satellite.any_instance.stub(
exists?: true,
destroy: true,
create: true,
lock_files_dir: repos_path
)
MergeRequest.any_instance.stub(
check_if_can_be_merged: true
)
Repository.any_instance.stub(
size: 12.45
)
end
def clear_repo_dir(namespace, name)
setup_stubs
# Clean any .wiki.git that may have been created
FileUtils.rm_rf File.join(testing_path(), "#{name}.wiki.git")
# Create repository for FactoryGirl.create(:project)
setup_factory_repo
end
def reset_satellite_dir
setup_stubs
[
%W(git reset --hard --quiet),
%W(git clean -fx --quiet),
%W(git checkout --quiet origin/master)
].each do |git_cmd|
system(*git_cmd, chdir: seed_satellite_path)
end
end
# Create a repo and it's satellite
def create_repo(namespace, name)
setup_stubs
repo = repo(namespace, name)
# Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq
FileUtils.ln_sf(seed_repo_path, repo)
create_satellite(repo, namespace, name)
end
private
def testing_path
Rails.root.join('tmp', 'test-git-base-path')
end
def seed_repo_path
Rails.root.join('tmp', 'repositories', 'gitlabhq')
end
def seed_satellite_path
Rails.root.join('tmp', 'satellite', 'gitlabhq')
end
def satellite_path
"#{testing_path()}/satellite"
def disable_mailer
NotificationService.any_instance.stub(mailer: double.as_null_object)
end
def repo(namespace, name)
unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?)
repo = File.join(testing_path(), "#{namespace.path}/#{name}.git")
else
repo = File.join(testing_path(), "#{name}.git")
end
def enable_mailer
NotificationService.any_instance.unstub(:mailer)
end
def satellite(namespace, name)
unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?)
satellite_repo = File.join(satellite_path, namespace.path, name)
else
satellite_repo = File.join(satellite_path, name)
def setup_gitlab_shell
unless File.directory?(Gitlab.config.gitlab_shell.path)
%x[rake gitlab:shell:install]
end
end
def setup_test_repos(opts ={})
create_repo(nil, 'gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('')
create_repo(nil, 'source_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('source_')
create_repo(nil, 'target_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('target_')
end
def setup_factory_repo
repo_path = repos_path + "/root/testme.git"
clone_url = 'https://gitlab.com/gitlab-org/gitlab-test.git'
def clear_test_repo_dir
setup_stubs
# Remove tmp/test-git-base-path
FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path
# Recreate tmp/test-git-base-path
FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path
# Since much more is happening in satellites
FileUtils.mkdir_p Gitlab.config.satellites.path
unless File.directory?(repo_path)
git_cmd = %W(git clone --bare #{clone_url} #{repo_path})
system(*git_cmd)
end
end
# Create a testing satellite, and clone the source repo into it
def create_satellite(source_repo, namespace, satellite_name)
satellite_repo = satellite(namespace, satellite_name)
# Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already
satellite_dir = File.dirname(satellite_repo)
FileUtils.mkdir_p(satellite_dir) unless File.exists?(satellite_dir)
FileUtils.ln_sf(seed_satellite_path, satellite_repo)
def copy_repo(project)
base_repo_path = File.expand_path(repos_path + "/root/testme.git")
target_repo_path = File.expand_path(repos_path + "/#{project.namespace.path}/#{project.path}.git")
FileUtils.mkdir_p(target_repo_path)
FileUtils.cp_r("#{base_repo_path}/.", target_repo_path)
FileUtils.chmod_R 0755, target_repo_path
end
def create_temp_repo(path)
FileUtils.mkdir_p path
system(*%W(git init --quiet --bare -- #{path}))
def repos_path
Gitlab.config.gitlab_shell.repos_path
end
end
module ValidCommit
ID = "8470d70da67355c9c009e4401746b1d5410af2e3"
MESSAGE = "notes controller refactored"
AUTHOR_FULL_NAME = "Dmitriy Zaporozhets"
AUTHOR_EMAIL = "dmitriy.zaporozhets@gmail.com"
FILES = [".foreman", ".gitignore", ".rails_footnotes", ".rspec", ".travis.yml", "CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "Procfile", "Procfile.production", "README.md", "Rakefile", "VERSION", "app", "config.ru", "config", "db", "doc", "lib", "log", "public", "resque.sh", "script", "spec", "vendor"]
FILES_COUNT = 26
C_FILE_PATH = "app/models"
C_FILES = [".gitkeep", "ability.rb", "commit.rb", "issue.rb", "key.rb", "mailer_observer.rb", "merge_request.rb", "note.rb", "project.rb", "protected_branch.rb", "repository.rb", "snippet.rb", "tree.rb", "user.rb", "users_project.rb", "web_hook.rb", "wiki.rb"]
BLOB_FILE = %{%h3= @key.title\n%hr\n%pre= @key.key\n.actions\n = link_to 'Remove', @key, :confirm => 'Are you sure?', :method => :delete, :class => \"btn danger delete-key\"\n\n\n}
BLOB_FILE_PATH = "app/views/keys/show.html.haml"
end
module ValidCommitWithAltEmail
ID = "1e689bfba39525ead225eaf611948cfbe8ac34cf"
MESSAGE = "fixed notes logic"
AUTHOR_FULL_NAME = "Dmitriy Zaporozhets"
AUTHOR_EMAIL = "dzaporozhets@sphereconsultinginc.com"
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