Merge branch 'master' into fix_project_access_notification
This commit is contained in:
commit
ed4fbcf6b0
953 changed files with 943 additions and 1041 deletions
|
@ -11,6 +11,9 @@ module Factory
|
|||
def self.new(type, *args)
|
||||
FactoryGirl.build(type, *args)
|
||||
end
|
||||
def self.attributes(type, *args)
|
||||
FactoryGirl.attributes_for(type, *args)
|
||||
end
|
||||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
|
@ -28,7 +31,7 @@ FactoryGirl.define do
|
|||
email { Faker::Internet.email }
|
||||
name
|
||||
password "123456"
|
||||
password_confirmation "123456"
|
||||
password_confirmation { password }
|
||||
|
||||
trait :admin do
|
||||
admin true
|
||||
|
|
|
@ -1,91 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Factories" do
|
||||
describe 'User' do
|
||||
it "builds a valid instance" do
|
||||
build(:user).should be_valid
|
||||
end
|
||||
|
||||
it "builds a valid admin instance" do
|
||||
build(:admin).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Project' do
|
||||
it "builds a valid instance" do
|
||||
build(:project).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Issue' do
|
||||
it "builds a valid instance" do
|
||||
build(:issue).should be_valid
|
||||
end
|
||||
|
||||
it "builds a valid closed instance" do
|
||||
build(:closed_issue).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'MergeRequest' do
|
||||
it "builds a valid instance" do
|
||||
build(:merge_request).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Note' do
|
||||
it "builds a valid instance" do
|
||||
build(:note).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Event' do
|
||||
it "builds a valid instance" do
|
||||
build(:event).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Key' do
|
||||
it "builds a valid instance" do
|
||||
build(:key).should be_valid
|
||||
end
|
||||
|
||||
it "builds a valid deploy key instance" do
|
||||
build(:deploy_key).should be_valid
|
||||
end
|
||||
|
||||
it "builds a valid personal key instance" do
|
||||
build(:personal_key).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Milestone' do
|
||||
it "builds a valid instance" do
|
||||
build(:milestone).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'SystemHook' do
|
||||
it "builds a valid instance" do
|
||||
build(:system_hook).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ProjectHook' do
|
||||
it "builds a valid instance" do
|
||||
build(:project_hook).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Wiki' do
|
||||
it "builds a valid instance" do
|
||||
build(:wiki).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Snippet' do
|
||||
it "builds a valid instance" do
|
||||
build(:snippet).should be_valid
|
||||
FactoryGirl.factories.map(&:name).each do |factory_name|
|
||||
describe "#{factory_name} factory" do
|
||||
it 'should be valid' do
|
||||
build(factory_name).should be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -208,6 +208,46 @@ describe GitlabMarkdownHelper do
|
|||
gfm(actual).should match(expected)
|
||||
end
|
||||
end
|
||||
|
||||
describe "emoji" do
|
||||
it "matches at the start of a string" do
|
||||
gfm(":+1:").should match(/<img/)
|
||||
end
|
||||
|
||||
it "matches at the end of a string" do
|
||||
gfm("This gets a :-1:").should match(/<img/)
|
||||
end
|
||||
|
||||
it "matches with adjacent text" do
|
||||
gfm("+1 (:+1:)").should match(/<img/)
|
||||
end
|
||||
|
||||
it "has a title attribute" do
|
||||
gfm(":-1:").should match(/title=":-1:"/)
|
||||
end
|
||||
|
||||
it "has an alt attribute" do
|
||||
gfm(":-1:").should match(/alt=":-1:"/)
|
||||
end
|
||||
|
||||
it "has an emoji class" do
|
||||
gfm(":+1:").should match('class="emoji"')
|
||||
end
|
||||
|
||||
it "sets height and width" do
|
||||
actual = gfm(":+1:")
|
||||
actual.should match(/width="20"/)
|
||||
actual.should match(/height="20"/)
|
||||
end
|
||||
|
||||
it "keeps whitespace intact" do
|
||||
gfm("This deserves a :+1: big time.").should match(/deserves a <img.+\/> big time/)
|
||||
end
|
||||
|
||||
it "ignores invalid emoji" do
|
||||
gfm(":invalid-emoji:").should_not match(/<img/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#link_to_gfm" do
|
||||
|
|
|
@ -24,7 +24,7 @@ describe Notify do
|
|||
end
|
||||
|
||||
it 'has the correct subject' do
|
||||
should have_subject /^gitlab \| Account was created for you$/
|
||||
should have_subject /^gitlab \| Account was created for you$/i
|
||||
end
|
||||
|
||||
it 'contains the new user\'s login name' do
|
||||
|
|
|
@ -7,6 +7,7 @@ describe Issue do
|
|||
|
||||
describe "Validation" do
|
||||
it { should ensure_length_of(:description).is_within(0..2000) }
|
||||
it { should ensure_inclusion_of(:closed).in_array([true, false]) }
|
||||
end
|
||||
|
||||
describe 'modules' do
|
||||
|
|
|
@ -9,6 +9,7 @@ describe Milestone do
|
|||
describe "Validation" do
|
||||
it { should validate_presence_of(:title) }
|
||||
it { should validate_presence_of(:project_id) }
|
||||
it { should ensure_inclusion_of(:closed).in_array([true, false]) }
|
||||
end
|
||||
|
||||
let(:milestone) { Factory :milestone }
|
||||
|
|
|
@ -35,6 +35,16 @@ describe Note do
|
|||
note = Factory(:note, note: "-1 for this")
|
||||
note.should_not be_upvote
|
||||
end
|
||||
|
||||
it "recognizes a +1 emoji as a vote" do
|
||||
note = build(:note, note: ":+1: for this")
|
||||
note.should be_upvote
|
||||
end
|
||||
|
||||
it "recognizes a neutral emoji note" do
|
||||
note = build(:note, note: "I would :+1: this, but I don't want to")
|
||||
note.should_not be_upvote
|
||||
end
|
||||
end
|
||||
|
||||
let(:project) { create(:project) }
|
||||
|
|
|
@ -37,6 +37,10 @@ describe Project do
|
|||
# TODO: Formats
|
||||
|
||||
it { should validate_presence_of(:owner) }
|
||||
it { should ensure_inclusion_of(:issues_enabled).in_array([true, false]) }
|
||||
it { should ensure_inclusion_of(:wall_enabled).in_array([true, false]) }
|
||||
it { should ensure_inclusion_of(:merge_requests_enabled).in_array([true, false]) }
|
||||
it { should ensure_inclusion_of(:wiki_enabled).in_array([true, false]) }
|
||||
|
||||
it "should not allow new projects beyond user limits" do
|
||||
project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1))
|
||||
|
@ -239,7 +243,7 @@ describe Project do
|
|||
end
|
||||
end
|
||||
|
||||
describe :update_merge_requests do
|
||||
describe :update_merge_requests do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
before do
|
||||
|
@ -259,7 +263,7 @@ describe Project do
|
|||
@merge_request.closed.should be_true
|
||||
end
|
||||
|
||||
it "should update merge request commits with new one if pushed to source branch" do
|
||||
it "should update merge request commits with new one if pushed to source branch" do
|
||||
@merge_request.last_commit.should == nil
|
||||
project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/master", @key.user)
|
||||
@merge_request.reload
|
||||
|
|
|
@ -31,36 +31,46 @@ describe User do
|
|||
it { should respond_to(:private_token) }
|
||||
end
|
||||
|
||||
it "should return valid identifier" do
|
||||
user = User.new(email: "test@mail.com")
|
||||
user.identifier.should == "test_mail_com"
|
||||
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
|
||||
|
||||
it "should return identifier without + sign" do
|
||||
user = User.new(email: "test+foo@mail.com")
|
||||
user.identifier.should == "test_foo_mail_com"
|
||||
describe '#generate_password' do
|
||||
it "should execute callback when force_random_password specified" do
|
||||
user = build(:user, force_random_password: true)
|
||||
user.should_receive(:generate_password)
|
||||
user.save
|
||||
end
|
||||
|
||||
it "should not generate password by default" do
|
||||
user = create(:user, password: 'abcdefg')
|
||||
user.password.should == 'abcdefg'
|
||||
end
|
||||
|
||||
it "should generate password when forcing random password" do
|
||||
Devise.stub(:friendly_token).and_return('123456789')
|
||||
user = create(:user, password: 'abcdefg', force_random_password: true)
|
||||
user.password.should == '12345678'
|
||||
end
|
||||
end
|
||||
|
||||
it "should execute callback when force_random_password specified" do
|
||||
user = User.new(email: "test@mail.com", force_random_password: true)
|
||||
user.should_receive(:generate_password)
|
||||
user.save
|
||||
end
|
||||
|
||||
it "should not generate password by default" do
|
||||
user = Factory(:user, password: 'abcdefg', password_confirmation: 'abcdefg')
|
||||
user.password.should == 'abcdefg'
|
||||
end
|
||||
|
||||
it "should generate password when forcing random password" do
|
||||
Devise.stub(:friendly_token).and_return('123456789')
|
||||
user = User.create(email: "test1@mail.com", force_random_password: true)
|
||||
user.password.should == user.password_confirmation
|
||||
user.password.should == '12345678'
|
||||
end
|
||||
|
||||
it "should have authentication token" do
|
||||
user = Factory(:user)
|
||||
user.authentication_token.should_not == ""
|
||||
describe 'authentication token' do
|
||||
it "should have authentication token" do
|
||||
user = Factory(:user)
|
||||
user.authentication_token.should_not be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe UsersProject do
|
|||
let!(:users_project) { create(:users_project) }
|
||||
|
||||
it { should validate_presence_of(:user_id) }
|
||||
it { should validate_uniqueness_of(:user_id).scoped_to(:project_id) }
|
||||
it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) }
|
||||
|
||||
it { should validate_presence_of(:project_id) }
|
||||
end
|
||||
|
|
|
@ -27,38 +27,40 @@ describe Gitlab::API do
|
|||
|
||||
describe "POST /projects" do
|
||||
it "should create new project without code and path" do
|
||||
lambda {
|
||||
name = "foo"
|
||||
post api("/projects", user), {
|
||||
name: name
|
||||
}
|
||||
response.status.should == 201
|
||||
json_response["name"].should == name
|
||||
json_response["code"].should == name
|
||||
json_response["path"].should == name
|
||||
}.should change{Project.count}.by(1)
|
||||
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
|
||||
end
|
||||
it "should create new project" do
|
||||
lambda {
|
||||
name = "foo"
|
||||
path = "bar"
|
||||
code = "bazz"
|
||||
post api("/projects", user), {
|
||||
code: code,
|
||||
path: path,
|
||||
name: name
|
||||
}
|
||||
response.status.should == 201
|
||||
json_response["name"].should == name
|
||||
json_response["path"].should == path
|
||||
json_response["code"].should == code
|
||||
}.should change{Project.count}.by(1)
|
||||
|
||||
it "should not create new project without name" do
|
||||
expect { post api("/projects", user) }.to_not change {Project.count}
|
||||
end
|
||||
it "should not create project without name" do
|
||||
lambda {
|
||||
post api("/projects", user)
|
||||
response.status.should == 404
|
||||
}.should_not change{Project.count}
|
||||
|
||||
it "should respond with 201 on success" do
|
||||
post api("/projects", user), name: 'foo'
|
||||
response.status.should == 201
|
||||
end
|
||||
|
||||
it "should repsond with 404 on failure" do
|
||||
post api("/projects", user)
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "should assign attributes to project" do
|
||||
project = Factory.attributes(:project, {
|
||||
path: 'path',
|
||||
code: 'code',
|
||||
description: Faker::Lorem.sentence,
|
||||
default_branch: 'stable',
|
||||
issues_enabled: false,
|
||||
wall_enabled: false,
|
||||
merge_requests_enabled: false,
|
||||
wiki_enabled: false
|
||||
})
|
||||
|
||||
post api("/projects", user), project
|
||||
|
||||
project.each_pair do |k,v|
|
||||
json_response[k.to_s].should == v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
72
spec/roles/repository_spec.rb
Normal file
72
spec/roles/repository_spec.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Project, "Repository" do
|
||||
let(:project) { build(:project) }
|
||||
|
||||
describe "#empty_repo?" do
|
||||
it "should return true if the repo doesn't exist" do
|
||||
project.stub(repo_exists?: false, has_commits?: true)
|
||||
project.should be_empty_repo
|
||||
end
|
||||
|
||||
it "should return true if the repo has commits" do
|
||||
project.stub(repo_exists?: true, has_commits?: false)
|
||||
project.should be_empty_repo
|
||||
end
|
||||
|
||||
it "should return false if the repo exists and has commits" do
|
||||
project.stub(repo_exists?: true, has_commits?: true)
|
||||
project.should_not be_empty_repo
|
||||
end
|
||||
end
|
||||
|
||||
describe "#discover_default_branch" do
|
||||
let(:master) { double(name: 'master') }
|
||||
let(:stable) { double(name: 'stable') }
|
||||
|
||||
it "returns 'master' when master exists" do
|
||||
project.should_receive(:heads).and_return([stable, master])
|
||||
project.discover_default_branch.should == 'master'
|
||||
end
|
||||
|
||||
it "returns non-master when master exists but default branch is set to something else" do
|
||||
project.default_branch = 'stable'
|
||||
project.should_receive(:heads).and_return([stable, master])
|
||||
project.discover_default_branch.should == 'stable'
|
||||
end
|
||||
|
||||
it "returns a non-master branch when only one exists" do
|
||||
project.should_receive(:heads).and_return([stable])
|
||||
project.discover_default_branch.should == 'stable'
|
||||
end
|
||||
|
||||
it "returns nil when no branch exists" do
|
||||
project.should_receive(:heads).and_return([])
|
||||
project.discover_default_branch.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#root_ref" do
|
||||
it "returns default_branch when set" do
|
||||
project.default_branch = 'stable'
|
||||
project.root_ref.should == 'stable'
|
||||
end
|
||||
|
||||
it "returns 'master' when default_branch is nil" do
|
||||
project.default_branch = nil
|
||||
project.root_ref.should == 'master'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#root_ref?" do
|
||||
it "returns true when branch is root_ref" do
|
||||
project.default_branch = 'stable'
|
||||
project.root_ref?('stable').should be_true
|
||||
end
|
||||
|
||||
it "returns false when branch is not root_ref" do
|
||||
project.default_branch = nil
|
||||
project.root_ref?('stable').should be_false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue