Merge branch 'master' into fixes/api

This commit is contained in:
Sebastian Ziebell 2013-02-27 10:16:48 +01:00
commit ac4a09e9cc
94 changed files with 935 additions and 731 deletions

View file

@ -82,7 +82,6 @@ describe "Admin::Users" do
it "should have user info" do
page.should have_content(@user.email)
page.should have_content(@user.name)
page.should have_content(@user.projects_limit)
end
end

View file

@ -169,32 +169,40 @@ describe "Gitlab Flavored Markdown" do
describe "for notes" do
it "should render in commits#show", js: true do
visit project_commit_path(project, commit)
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
within ".new_note.js-main-target-form" do
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
end
page.should have_link("##{issue.id}")
end
it "should render in issue#show", js: true do
visit project_issue_path(project, issue)
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
within ".new_note.js-main-target-form" do
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
end
page.should have_link("##{issue.id}")
end
it "should render in merge_request#show", js: true do
visit project_merge_request_path(project, merge_request)
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
within ".new_note.js-main-target-form" do
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
end
page.should have_link("##{issue.id}")
end
it "should render in projects#wall", js: true do
visit wall_project_path(project)
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
within ".new_note.js-main-target-form" do
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
end
page.should have_link("##{issue.id}")
end

View file

@ -18,7 +18,7 @@ describe "On a merge request", js: true do
it { should have_css(".js-main-target-form", visible: true, count: 1) }
# button initalization
it { within(".js-main-target-form") { should have_button("Add Comment") } }
it { find(".js-main-target-form input[type=submit]").value.should == "Add Comment" }
it { within(".js-main-target-form") { should_not have_link("Cancel") } }
# notifiactions
@ -67,7 +67,7 @@ describe "On a merge request", js: true do
end
# note added
it { within(".js-main-target-form") { should have_content("This is awsome!") } }
it { should have_content("This is awsome!") }
# reset form
it { within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") } }
@ -97,7 +97,9 @@ describe "On a merge request diff", js: true, focus: true do
visit diffs_project_merge_request_path(project, merge_request)
click_link("Diff")
within '.diffs-tab' do
click_link("Diff")
end
end
subject { page }
@ -134,7 +136,9 @@ describe "On a merge request diff", js: true, focus: true do
end
it "should be removed when canceled" do
find(".js-close-discussion-note-form").trigger("click")
within(".file form[rel$='4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185']") do
find(".js-close-discussion-note-form").trigger("click")
end
should have_no_css(".js-temp-notes-holder")
end

View file

@ -17,7 +17,7 @@ describe "On the project wall", js: true do
it { should have_css(".js-main-target-form", visible: true, count: 1) }
# button initalization
it { within(".js-main-target-form") { should have_button("Add Comment") } }
it { find(".js-main-target-form input[type=submit]").value.should == "Add Comment" }
it { within(".js-main-target-form") { should_not have_link("Cancel") } }
# notifiactions
@ -66,7 +66,7 @@ describe "On the project wall", js: true do
end
# note added
it { within(".js-main-target-form") { should have_content("This is awsome!") } }
it { should have_content("This is awsome!") }
# reset form
it { within(".js-main-target-form") { should have_no_field("note[note]", with: "This is awesome!") } }

View file

@ -6,8 +6,11 @@ describe "Search" do
@project = create(:project)
@project.team << [@user, :reporter]
visit search_path
fill_in "search", with: @project.name[0..3]
click_button "Search"
within '.search-holder' do
fill_in "search", with: @project.name[0..3]
click_button "Search"
end
end
it "should show project in search results" do

View file

@ -72,7 +72,7 @@ describe "Snippets" do
author: @user,
project: project)
visit project_snippet_path(project, @snippet)
click_link "Edit"
click_link "Edit Snippet"
end
it "should open edit page" do

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe 'Users' do
describe "GET /users/sign_up" do
before do
Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
end
it "should create a new user account" do
visit new_user_registration_path
fill_in "user_name", with: "Name Surname"
fill_in "user_username", with: "Great"
fill_in "user_email", with: "name@mail.com"
fill_in "user_password", with: "password1234"
fill_in "user_password_confirmation", with: "password1234"
expect { click_button "Sign up" }.to change {User.count}.by(1)
end
end
end

29
spec/lib/popen_spec.rb Normal file
View file

@ -0,0 +1,29 @@
require 'spec_helper'
describe 'Gitlab::Popen', no_db: true do
let (:path) { Rails.root.join('tmp').to_s }
before do
@klass = Class.new(Object)
@klass.send(:include, Gitlab::Popen)
end
context 'zero status' do
before do
@output, @status = @klass.new.popen('ls', path)
end
it { @status.should be_zero }
it { @output.should include('cache') }
end
context 'non-zero status' do
before do
@output, @status = @klass.new.popen('cat NOTHING', path)
end
it { @status.should == 1 }
it { @output.should include('No such file or directory') }
end
end

View file

@ -32,6 +32,12 @@ describe MergeRequest do
it { should_not allow_mass_assignment_of(:project_id) }
end
describe "Respond to" do
it { should respond_to(:unchecked?) }
it { should respond_to(:can_be_merged?) }
it { should respond_to(:cannot_be_merged?) }
end
describe 'modules' do
it { should include_module(Issuable) }
end

View file

@ -1,128 +0,0 @@
require 'spec_helper'
describe Project, "Hooks" do
let(:project) { create(:project) }
before do
@key = create(:key, user: project.owner)
@user = @key.user
@key_id = @key.identifier
end
describe "Post Receive Event" do
it "should create push event" do
oldrev, newrev, ref = '00000000000000000000000000000000', 'newrev', 'refs/heads/master'
data = project.post_receive_data(oldrev, newrev, ref, @user)
project.observe_push(data)
event = Event.last
event.should_not be_nil
event.project.should == project
event.action.should == Event::PUSHED
event.data.should == data
end
end
describe "Project hooks" do
context "with no web hooks" do
it "raises no errors" do
lambda {
project.execute_hooks({})
}.should_not raise_error
end
end
context "with web hooks" do
before do
@project_hook = create(:project_hook)
@project_hook_2 = create(:project_hook)
project.hooks << [@project_hook, @project_hook_2]
stub_request(:post, @project_hook.url)
stub_request(:post, @project_hook_2.url)
end
it "executes multiple web hook" do
@project_hook.should_receive(:async_execute).once
@project_hook_2.should_receive(:async_execute).once
project.trigger_post_receive('oldrev', 'newrev', 'refs/heads/master', @user)
end
end
context "does not execute web hooks" do
before do
@project_hook = create(:project_hook)
project.hooks << [@project_hook]
end
it "when pushing a branch for the first time" do
@project_hook.should_not_receive(:execute)
project.trigger_post_receive('00000000000000000000000000000000', 'newrev', 'refs/heads/master', @user)
end
it "when pushing tags" do
@project_hook.should_not_receive(:execute)
project.trigger_post_receive('oldrev', 'newrev', 'refs/tags/v1.0.0', @user)
end
end
context "when pushing new branches" do
end
context "when gathering commit data" do
before do
@oldrev, @newrev, @ref = project.repository.fresh_commits(2).last.sha,
project.repository.fresh_commits(2).first.sha, 'refs/heads/master'
@commit = project.repository.fresh_commits(2).first
# Fill nil/empty attributes
project.description = "This is a description"
@data = project.post_receive_data(@oldrev, @newrev, @ref, @user)
end
subject { @data }
it { should include(before: @oldrev) }
it { should include(after: @newrev) }
it { should include(ref: @ref) }
it { should include(user_id: project.owner.id) }
it { should include(user_name: project.owner.name) }
context "with repository data" do
subject { @data[:repository] }
it { should include(name: project.name) }
it { should include(url: project.url_to_repo) }
it { should include(description: project.description) }
it { should include(homepage: project.web_url) }
end
context "with commits" do
subject { @data[:commits] }
it { should be_an(Array) }
it { should have(1).element }
context "the commit" do
subject { @data[:commits].first }
it { should include(id: @commit.id) }
it { should include(message: @commit.safe_message) }
it { should include(timestamp: @commit.date.xmlschema) }
it { should include(url: "#{Gitlab.config.gitlab.url}/#{project.code}/commit/#{@commit.id}") }
context "with a author" do
subject { @data[:commits].first[:author] }
it { should include(name: @commit.author_name) }
it { should include(email: @commit.author_email) }
end
end
end
end
end
end

View file

@ -72,11 +72,8 @@ describe Project do
it { should respond_to(:url_to_repo) }
it { should respond_to(:repo_exists?) }
it { should respond_to(:satellite) }
it { should respond_to(:observe_push) }
it { should respond_to(:update_merge_requests) }
it { should respond_to(:execute_hooks) }
it { should respond_to(:post_receive_data) }
it { should respond_to(:trigger_post_receive) }
it { should respond_to(:transfer) }
it { should respond_to(:name_with_namespace) }
it { should respond_to(:namespace_owner) }

View file

@ -10,9 +10,6 @@ describe ProjectTeam do
it { should respond_to(:masters) }
it { should respond_to(:reporters) }
it { should respond_to(:guests) }
it { should respond_to(:repository_writers) }
it { should respond_to(:repository_masters) }
it { should respond_to(:repository_readers) }
end
end

View file

@ -69,28 +69,10 @@ describe User do
describe "Respond to" do
it { should respond_to(:is_admin?) }
it { should respond_to(:identifier) }
it { should respond_to(:name) }
it { should respond_to(:private_token) }
end
describe '#identifier' do
it "should return valid identifier" do
user = build(:user, email: "test@mail.com")
user.identifier.should == "test_mail_com"
end
it "should return identifier without + sign" do
user = build(:user, email: "test+foo@mail.com")
user.identifier.should == "test_foo_mail_com"
end
it "should conform to Gitolite's required identifier pattern" do
user = build(:user, email: "_test@example.com")
user.identifier.should == 'test_example_com'
end
end
describe '#generate_password' do
it "should execute callback when force_random_password specified" do
user = build(:user, force_random_password: true)

View file

@ -0,0 +1,103 @@
require 'spec_helper'
describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let(:key) { create(:key, user: user) }
let(:project) { create(:project) }
describe "GET /internal/check", no_db: true do
it do
get api("/internal/check")
response.status.should == 200
json_response['api_version'].should == Gitlab::API.version
end
end
describe "GET /internal/discover" do
it do
get(api("/internal/discover"), key_id: key.id)
response.status.should == 200
json_response['email'].should == user.email
end
end
describe "GET /internal/allowed" do
context "access granted" do
before do
project.team << [user, :developer]
end
context "git pull" do
it do
get(
api("/internal/allowed"),
ref: 'master',
key_id: key.id,
project: project.path_with_namespace,
action: 'git-upload-pack'
)
response.status.should == 200
response.body.should == 'true'
end
end
context "git push" do
it do
get(
api("/internal/allowed"),
ref: 'master',
key_id: key.id,
project: project.path_with_namespace,
action: 'git-receive-pack'
)
response.status.should == 200
response.body.should == 'true'
end
end
end
context "access denied" do
before do
project.team << [user, :guest]
end
context "git pull" do
it do
get(
api("/internal/allowed"),
ref: 'master',
key_id: key.id,
project: project.path_with_namespace,
action: 'git-upload-pack'
)
response.status.should == 200
response.body.should == 'false'
end
end
context "git push" do
it do
get(
api("/internal/allowed"),
ref: 'master',
key_id: key.id,
project: project.path_with_namespace,
action: 'git-receive-pack'
)
response.status.should == 200
response.body.should == 'false'
end
end
end
end
end

View file

@ -97,32 +97,27 @@ describe Gitlab::API do
end
describe "GET /users/sign_up" do
before do
Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
end
it "should redirect to sign in page if signup is disabled" do
get "/users/sign_up"
response.status.should == 302
response.should redirect_to(new_user_session_path)
end
end
context 'enabled' do
before do
Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
end
describe "GET /users/sign_up" do
before do
Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
it "should return sign up page if signup is enabled" do
get "/users/sign_up"
response.status.should == 200
end
end
it "should return sign up page if signup is enabled" do
get "/users/sign_up"
response.status.should == 200
end
it "should create a new user account" do
visit new_user_registration_path
fill_in "user_name", with: "Name Surname"
fill_in "user_username", with: "Great"
fill_in "user_email", with: "name@mail.com"
fill_in "user_password", with: "password1234"
fill_in "user_password_confirmation", with: "password1234"
expect { click_button "Sign up" }.to change {User.count}.by(1)
context 'disabled' do
before do
Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
end
it "should redirect to sign in page if signup is disabled" do
get "/users/sign_up"
response.status.should == 302
response.should redirect_to(new_user_session_path)
end
end
end

View file

@ -0,0 +1,111 @@
require 'spec_helper'
describe GitPushService do
let (:user) { create :user }
let (:project) { create :project }
let (:service) { GitPushService.new }
before do
@oldrev = 'b98a310def241a6fd9c9a9a3e7934c48e498fe81'
@newrev = 'b19a04f53caeebf4fe5ec2327cb83e9253dc91bb'
@ref = 'refs/heads/master'
end
describe "Git Push Data" do
before do
service.execute(project, user, @oldrev, @newrev, @ref)
@push_data = service.push_data
@commit = project.repository.commit(@newrev)
end
subject { @push_data }
it { should include(before: @oldrev) }
it { should include(after: @newrev) }
it { should include(ref: @ref) }
it { should include(user_id: user.id) }
it { should include(user_name: user.name) }
context "with repository data" do
subject { @push_data[:repository] }
it { should include(name: project.name) }
it { should include(url: project.url_to_repo) }
it { should include(description: project.description) }
it { should include(homepage: project.web_url) }
end
context "with commits" do
subject { @push_data[:commits] }
it { should be_an(Array) }
it { should have(1).element }
context "the commit" do
subject { @push_data[:commits].first }
it { should include(id: @commit.id) }
it { should include(message: @commit.safe_message) }
it { should include(timestamp: @commit.date.xmlschema) }
it { should include(url: "#{Gitlab.config.gitlab.url}/#{project.code}/commit/#{@commit.id}") }
context "with a author" do
subject { @push_data[:commits].first[:author] }
it { should include(name: @commit.author_name) }
it { should include(email: @commit.author_email) }
end
end
end
end
describe "Push Event" do
before do
service.execute(project, user, @oldrev, @newrev, @ref)
@event = Event.last
end
it { @event.should_not be_nil }
it { @event.project.should == project }
it { @event.action.should == Event::PUSHED }
it { @event.data.should == service.push_data }
end
describe "Web Hooks" do
context "with web hooks" do
before do
@project_hook = create(:project_hook)
@project_hook_2 = create(:project_hook)
project.hooks << [@project_hook, @project_hook_2]
stub_request(:post, @project_hook.url)
stub_request(:post, @project_hook_2.url)
end
it "executes multiple web hook" do
@project_hook.should_receive(:async_execute).once
@project_hook_2.should_receive(:async_execute).once
service.execute(project, user, @oldrev, @newrev, @ref)
end
end
context "does not execute web hooks" do
before do
@project_hook = create(:project_hook)
project.hooks << [@project_hook]
end
it "when pushing a branch for the first time" do
@project_hook.should_not_receive(:execute)
service.execute(project, user, '00000000000000000000000000000000', 'newrev', 'refs/heads/master')
end
it "when pushing tags" do
@project_hook.should_not_receive(:execute)
service.execute(project, user, 'newrev', 'newrev', 'refs/tags/v1.0.0')
end
end
end
end

View file

@ -0,0 +1,41 @@
require 'spec_helper'
describe SystemHooksService do
let (:user) { create :user }
let (:project) { create :project }
let (:users_project) { create :users_project }
context 'it should build event data' do
it 'should build event data for user' do
SystemHooksService.build_event_data(user, :create).should include(:event_name, :name, :created_at, :email)
end
it 'should build event data for project' do
SystemHooksService.build_event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email)
end
it 'should build event data for users project' do
SystemHooksService.build_event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access)
end
end
context 'it should build event names' do
it 'should build event names for user' do
SystemHooksService.build_event_name(user, :create).should eq "user_create"
SystemHooksService.build_event_name(user, :destroy).should eq "user_destroy"
end
it 'should build event names for project' do
SystemHooksService.build_event_name(project, :create).should eq "project_create"
SystemHooksService.build_event_name(project, :destroy).should eq "project_destroy"
end
it 'should build event names for users project' do
SystemHooksService.build_event_name(users_project, :create).should eq "user_add_to_team"
SystemHooksService.build_event_name(users_project, :destroy).should eq "user_remove_from_team"
end
end
end

View file

@ -10,19 +10,19 @@ require 'capybara/rspec'
require 'webmock/rspec'
require 'email_spec'
require 'sidekiq/testing/inline'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.mock_with :rspec
config.include LoginHelpers, type: :feature
config.include LoginHelpers, type: :request
config.include FactoryGirl::Syntax::Methods
config.include Devise::TestHelpers, type: :controller

View file

@ -9,10 +9,14 @@ RSpec.configure do |config|
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
unless example.metadata[:no_db]
DatabaseCleaner.start
end
end
config.after do
DatabaseCleaner.clean
unless example.metadata[:no_db]
DatabaseCleaner.clean
end
end
end

View file

@ -1,5 +1,6 @@
require "repository"
require "project"
require "merge_request"
require "shell"
# Stubs out all Git repository access done by models so that specs can run
@ -32,6 +33,12 @@ class Project
end
end
class MergeRequest
def check_if_can_be_merged
true
end
end
class GitLabTestRepo < Repository
def repo
@repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq'))

View file

@ -21,7 +21,6 @@ describe PostReceive do
it "does not run if the author is not in the project" do
Key.stub(find_by_id: nil)
project.should_not_receive(:observe_push)
project.should_not_receive(:execute_hooks)
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false
@ -32,7 +31,6 @@ describe PostReceive do
project.should_receive(:execute_hooks)
project.should_receive(:execute_services)
project.should_receive(:update_merge_requests)
project.should_receive(:observe_push)
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
end