Merge commit 'master' into discussions
Conflicts: app/assets/stylesheets/sections/notes.scss app/contexts/notes/load_context.rb app/models/project.rb app/observers/note_observer.rb app/roles/votes.rb app/views/commit/show.html.haml app/views/merge_requests/_show.html.haml app/views/merge_requests/diffs.js.haml app/views/merge_requests/show.js.haml app/views/notes/_note.html.haml features/steps/project/project_merge_requests.rb spec/models/note_spec.rb
This commit is contained in:
commit
3022786948
930 changed files with 80374 additions and 103682 deletions
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Commit do
|
||||
let(:commit) { create(:project).commit }
|
||||
let(:commit) { create(:project).repository.commit }
|
||||
|
||||
describe CommitDecorator do
|
||||
let(:decorator) { CommitDecorator.new(commit) }
|
||||
|
@ -34,4 +34,65 @@ describe Commit do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Commit info" do
|
||||
before do
|
||||
@committer = double(
|
||||
email: 'mike@smith.com',
|
||||
name: 'Mike Smith'
|
||||
)
|
||||
|
||||
@author = double(
|
||||
email: 'john@smith.com',
|
||||
name: 'John Smith'
|
||||
)
|
||||
|
||||
@raw_commit = double(
|
||||
id: "bcf03b5de6abcf03b5de6c",
|
||||
author: @author,
|
||||
committer: @committer,
|
||||
committed_date: Date.yesterday,
|
||||
message: 'Refactoring specs'
|
||||
)
|
||||
|
||||
@commit = Commit.new(@raw_commit)
|
||||
end
|
||||
|
||||
it { @commit.short_id.should == "bcf03b5de6a" }
|
||||
it { @commit.safe_message.should == @raw_commit.message }
|
||||
it { @commit.created_at.should == @raw_commit.committed_date }
|
||||
it { @commit.author_email.should == @author.email }
|
||||
it { @commit.author_name.should == @author.name }
|
||||
it { @commit.committer_name.should == @committer.name }
|
||||
it { @commit.committer_email.should == @committer.email }
|
||||
it { @commit.different_committer?.should be_true }
|
||||
end
|
||||
|
||||
describe "Class methods" do
|
||||
subject { Commit }
|
||||
|
||||
it { should respond_to(:find_or_first) }
|
||||
it { should respond_to(:fresh_commits) }
|
||||
it { should respond_to(:commits_with_refs) }
|
||||
it { should respond_to(:commits_since) }
|
||||
it { should respond_to(:commits_between) }
|
||||
it { should respond_to(:commits) }
|
||||
it { should respond_to(:compare) }
|
||||
end
|
||||
|
||||
describe "delegation" do
|
||||
subject { commit }
|
||||
|
||||
it { should respond_to(:message) }
|
||||
it { should respond_to(:authored_date) }
|
||||
it { should respond_to(:committed_date) }
|
||||
it { should respond_to(:parents) }
|
||||
it { should respond_to(:date) }
|
||||
it { should respond_to(:committer) }
|
||||
it { should respond_to(:author) }
|
||||
it { should respond_to(:diffs) }
|
||||
it { should respond_to(:tree) }
|
||||
it { should respond_to(:id) }
|
||||
it { should respond_to(:to_patch) }
|
||||
end
|
||||
end
|
||||
|
|
70
spec/models/concerns/issuable_spec.rb
Normal file
70
spec/models/concerns/issuable_spec.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Issue, "Issuable" do
|
||||
let(:issue) { create(:issue) }
|
||||
|
||||
describe "Associations" do
|
||||
it { should belong_to(:project) }
|
||||
it { should belong_to(:author) }
|
||||
it { should belong_to(:assignee) }
|
||||
it { should have_many(:notes).dependent(:destroy) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
it { should validate_presence_of(:project) }
|
||||
it { should validate_presence_of(:author) }
|
||||
it { should validate_presence_of(:title) }
|
||||
it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
|
||||
it { should ensure_inclusion_of(:closed).in_array([true, false]) }
|
||||
end
|
||||
|
||||
describe "Scope" do
|
||||
it { described_class.should respond_to(:opened) }
|
||||
it { described_class.should respond_to(:closed) }
|
||||
it { described_class.should respond_to(:assigned) }
|
||||
end
|
||||
|
||||
it "has an :author_id_of_changes accessor" do
|
||||
issue.should respond_to(:author_id_of_changes)
|
||||
issue.should respond_to(:author_id_of_changes=)
|
||||
end
|
||||
|
||||
describe ".search" do
|
||||
let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
|
||||
|
||||
it "matches by title" do
|
||||
described_class.search('able').all.should == [searchable_issue]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#today?" do
|
||||
it "returns true when created today" do
|
||||
# Avoid timezone differences and just return exactly what we want
|
||||
Date.stub(:today).and_return(issue.created_at.to_date)
|
||||
issue.today?.should be_true
|
||||
end
|
||||
|
||||
it "returns false when not created today" do
|
||||
Date.stub(:today).and_return(Date.yesterday)
|
||||
issue.today?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#new?" do
|
||||
it "returns true when created today and record hasn't been updated" do
|
||||
issue.stub(:today?).and_return(true)
|
||||
issue.new?.should be_true
|
||||
end
|
||||
|
||||
it "returns false when not created today" do
|
||||
issue.stub(:today?).and_return(false)
|
||||
issue.new?.should be_false
|
||||
end
|
||||
|
||||
it "returns false when record has been updated" do
|
||||
issue.stub(:today?).and_return(true)
|
||||
issue.touch
|
||||
issue.new?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
46
spec/models/gitlab_ci_service_spec.rb
Normal file
46
spec/models/gitlab_ci_service_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: services
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# token :string(255)
|
||||
# project_id :integer not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# active :boolean default(FALSE), not null
|
||||
# project_url :string(255)
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe GitlabCiService do
|
||||
describe "Associations" do
|
||||
it { should belong_to :project }
|
||||
it { should have_one :service_hook }
|
||||
end
|
||||
|
||||
describe "Mass assignment" do
|
||||
it { should_not allow_mass_assignment_of(:project_id) }
|
||||
end
|
||||
|
||||
describe 'commits methods' do
|
||||
before do
|
||||
@service = GitlabCiService.new
|
||||
@service.stub(
|
||||
service_hook: true,
|
||||
project_url: 'http://ci.gitlab.org/projects/2',
|
||||
token: 'verySecret'
|
||||
)
|
||||
end
|
||||
|
||||
describe :commit_status_path do
|
||||
it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c/status.json?token=verySecret"}
|
||||
end
|
||||
|
||||
describe :build_page do
|
||||
it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c"}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -33,8 +33,7 @@ describe Issue do
|
|||
end
|
||||
|
||||
describe 'modules' do
|
||||
it { should include_module(IssueCommonality) }
|
||||
it { should include_module(Votes) }
|
||||
it { should include_module(Issuable) }
|
||||
end
|
||||
|
||||
subject { create(:issue) }
|
||||
|
|
|
@ -33,15 +33,14 @@ describe MergeRequest do
|
|||
end
|
||||
|
||||
describe 'modules' do
|
||||
it { should include_module(IssueCommonality) }
|
||||
it { should include_module(Votes) }
|
||||
it { should include_module(Issuable) }
|
||||
end
|
||||
|
||||
describe "#mr_and_commit_notes" do
|
||||
let!(:merge_request) { create(:merge_request) }
|
||||
|
||||
before do
|
||||
merge_request.stub(:commits) { [merge_request.project.commit] }
|
||||
merge_request.stub(:commits) { [merge_request.project.repository.commit] }
|
||||
create(:note, commit_id: merge_request.commits.first.id, noteable_type: 'Commit')
|
||||
create(:note, noteable: merge_request)
|
||||
end
|
||||
|
|
|
@ -40,6 +40,7 @@ describe Milestone do
|
|||
end
|
||||
|
||||
it "should count closed issues" do
|
||||
IssueObserver.current_user = issue.author
|
||||
issue.update_attributes(closed: true)
|
||||
milestone.issues << issue
|
||||
milestone.percent_complete.should == 100
|
||||
|
@ -62,4 +63,54 @@ describe Milestone do
|
|||
milestone.expires_at.should be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe :expired? do
|
||||
context "expired" do
|
||||
before do
|
||||
milestone.stub(due_date: Date.today.prev_year)
|
||||
end
|
||||
|
||||
it { milestone.expired?.should be_true }
|
||||
end
|
||||
|
||||
context "not expired" do
|
||||
before do
|
||||
milestone.stub(due_date: Date.today.next_year)
|
||||
end
|
||||
|
||||
it { milestone.expired?.should be_false }
|
||||
end
|
||||
end
|
||||
|
||||
describe :percent_complete do
|
||||
before do
|
||||
milestone.stub(
|
||||
closed_items_count: 3,
|
||||
total_items_count: 4
|
||||
)
|
||||
end
|
||||
|
||||
it { milestone.percent_complete.should == 75 }
|
||||
end
|
||||
|
||||
describe :items_count do
|
||||
before do
|
||||
milestone.issues << create(:issue)
|
||||
milestone.issues << create(:issue, closed: true)
|
||||
milestone.merge_requests << create(:merge_request)
|
||||
end
|
||||
|
||||
it { milestone.closed_items_count.should == 1 }
|
||||
it { milestone.open_items_count.should == 2 }
|
||||
it { milestone.total_items_count.should == 3 }
|
||||
it { milestone.is_empty?.should be_false }
|
||||
end
|
||||
|
||||
describe :can_be_closed? do
|
||||
it { milestone.can_be_closed?.should be_true }
|
||||
end
|
||||
|
||||
describe :open? do
|
||||
it { milestone.open?.should be_true }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#
|
||||
# id :integer not null, primary key
|
||||
# note :text
|
||||
# noteable_id :string(255)
|
||||
# noteable_type :string(255)
|
||||
# author_id :integer
|
||||
# created_at :datetime not null
|
||||
|
@ -12,6 +11,8 @@
|
|||
# project_id :integer
|
||||
# attachment :string(255)
|
||||
# line_code :string(255)
|
||||
# commit_id :string(255)
|
||||
# noteable_id :integer
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
@ -33,12 +34,6 @@ describe Note do
|
|||
it { should validate_presence_of(:project) }
|
||||
end
|
||||
|
||||
describe "Scopes" do
|
||||
it "should have a today named scope that returns ..." do
|
||||
Note.today.where_values.should == ["created_at >= '#{Date.today}'"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "Voting score" do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
|
@ -75,6 +70,9 @@ describe Note do
|
|||
end
|
||||
end
|
||||
|
||||
let(:project) { create(:project) }
|
||||
let(:commit) { project.repository.commit }
|
||||
|
||||
describe "Commit notes" do
|
||||
let!(:note) { create(:note_on_commit, note: "+1 from me") }
|
||||
let!(:commit) { note.noteable }
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Project, "Hooks" do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
before do
|
||||
@key = create(:key, user: project.owner)
|
||||
@user = @key.user
|
||||
|
@ -70,8 +71,9 @@ describe Project, "Hooks" do
|
|||
|
||||
context "when gathering commit data" do
|
||||
before do
|
||||
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
|
||||
@commit = project.fresh_commits(2).first
|
||||
@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"
|
||||
|
@ -91,7 +93,7 @@ describe Project, "Hooks" do
|
|||
subject { @data[:repository] }
|
||||
|
||||
it { should include(name: project.name) }
|
||||
it { should include(url: project.web_url) }
|
||||
it { should include(url: project.url_to_repo) }
|
||||
it { should include(description: project.description) }
|
||||
it { should include(homepage: project.web_url) }
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ describe Project do
|
|||
@u1 = create(:user)
|
||||
@u2 = create(:user)
|
||||
@u3 = create(:user)
|
||||
@u4 = @p1.chief
|
||||
@u4 = @p1.owner
|
||||
|
||||
@abilities = Six.new
|
||||
@abilities << Ability
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# private_flag :boolean default(TRUE), not null
|
||||
# owner_id :integer
|
||||
# creator_id :integer
|
||||
# default_branch :string(255)
|
||||
# issues_enabled :boolean default(TRUE), not null
|
||||
# wall_enabled :boolean default(TRUE), not null
|
||||
|
@ -24,7 +24,7 @@ describe Project do
|
|||
describe "Associations" do
|
||||
it { should belong_to(:group) }
|
||||
it { should belong_to(:namespace) }
|
||||
it { should belong_to(:owner).class_name('User') }
|
||||
it { should belong_to(:creator).class_name('User') }
|
||||
it { should have_many(:users) }
|
||||
it { should have_many(:events).dependent(:destroy) }
|
||||
it { should have_many(:merge_requests).dependent(:destroy) }
|
||||
|
@ -41,7 +41,7 @@ describe Project do
|
|||
|
||||
describe "Mass assignment" do
|
||||
it { should_not allow_mass_assignment_of(:namespace_id) }
|
||||
it { should_not allow_mass_assignment_of(:owner_id) }
|
||||
it { should_not allow_mass_assignment_of(:creator_id) }
|
||||
it { should_not allow_mass_assignment_of(:private_flag) }
|
||||
end
|
||||
|
||||
|
@ -55,20 +55,15 @@ describe Project do
|
|||
it { should validate_presence_of(:path) }
|
||||
it { should validate_uniqueness_of(:path) }
|
||||
it { should ensure_length_of(:path).is_within(0..255) }
|
||||
# TODO: Formats
|
||||
|
||||
it { should ensure_length_of(:description).is_within(0..2000) }
|
||||
|
||||
# TODO: Formats
|
||||
|
||||
it { should validate_presence_of(:owner) }
|
||||
it { should validate_presence_of(:creator) }
|
||||
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))
|
||||
project.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 1))
|
||||
project.should_not be_valid
|
||||
project.errors[:base].first.should match(/Your own projects limit is 1/)
|
||||
end
|
||||
|
@ -80,82 +75,28 @@ describe Project do
|
|||
end
|
||||
|
||||
describe "Respond to" do
|
||||
it { should respond_to(:public?) }
|
||||
it { should respond_to(:private?) }
|
||||
it { should respond_to(:url_to_repo) }
|
||||
it { should respond_to(:path_to_repo) }
|
||||
it { should respond_to(:valid_repo?) }
|
||||
it { should respond_to(:repo_exists?) }
|
||||
|
||||
# Repository Role
|
||||
it { should respond_to(:tree) }
|
||||
it { should respond_to(:root_ref) }
|
||||
it { should respond_to(:repo) }
|
||||
it { should respond_to(:tags) }
|
||||
it { should respond_to(:commit) }
|
||||
it { should respond_to(:commits) }
|
||||
it { should respond_to(:commits_between) }
|
||||
it { should respond_to(:commits_with_refs) }
|
||||
it { should respond_to(:commits_since) }
|
||||
it { should respond_to(:commits_between) }
|
||||
it { should respond_to(:satellite) }
|
||||
it { should respond_to(:update_repository) }
|
||||
it { should respond_to(:destroy_repository) }
|
||||
it { should respond_to(:archive_repo) }
|
||||
|
||||
# Authority Role
|
||||
it { should respond_to(:add_access) }
|
||||
it { should respond_to(:reset_access) }
|
||||
it { should respond_to(:repository_writers) }
|
||||
it { should respond_to(:repository_masters) }
|
||||
it { should respond_to(:repository_readers) }
|
||||
it { should respond_to(:allow_read_for?) }
|
||||
it { should respond_to(:guest_access_for?) }
|
||||
it { should respond_to(:report_access_for?) }
|
||||
it { should respond_to(:dev_access_for?) }
|
||||
it { should respond_to(:master_access_for?) }
|
||||
|
||||
# Team Role
|
||||
it { should respond_to(:team_member_by_name_or_email) }
|
||||
it { should respond_to(:team_member_by_id) }
|
||||
it { should respond_to(:add_user_to_team) }
|
||||
it { should respond_to(:add_users_to_team) }
|
||||
it { should respond_to(:add_user_id_to_team) }
|
||||
it { should respond_to(:add_users_ids_to_team) }
|
||||
|
||||
# Project Push Role
|
||||
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) }
|
||||
|
||||
# Namespaced Project Role
|
||||
it { should respond_to(:transfer) }
|
||||
it { should respond_to(:name_with_namespace) }
|
||||
it { should respond_to(:namespace_owner) }
|
||||
it { should respond_to(:chief) }
|
||||
it { should respond_to(:owner) }
|
||||
it { should respond_to(:path_with_namespace) }
|
||||
end
|
||||
|
||||
describe 'modules' do
|
||||
it { should include_module(Repository) }
|
||||
it { should include_module(PushObserver) }
|
||||
it { should include_module(Authority) }
|
||||
it { should include_module(Team) }
|
||||
it { should include_module(NamespacedProject) }
|
||||
end
|
||||
|
||||
it "should return valid url to repo" do
|
||||
project = Project.new(path: "somewhere")
|
||||
project.url_to_repo.should == Gitlab.config.gitolite.ssh_path_prefix + "somewhere.git"
|
||||
end
|
||||
|
||||
it "should return path to repo" do
|
||||
project = Project.new(path: "somewhere")
|
||||
project.path_to_repo.should == Rails.root.join("tmp", "repositories", "somewhere")
|
||||
end
|
||||
|
||||
it "returns the full web URL for this repo" do
|
||||
project = Project.new(path: "somewhere")
|
||||
project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
|
||||
|
@ -211,4 +152,87 @@ describe Project do
|
|||
@merge_request.last_commit.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
|
||||
end
|
||||
end
|
||||
|
||||
describe :create_by_user do
|
||||
before do
|
||||
@user = create :user
|
||||
@opts = {
|
||||
name: "GitLab"
|
||||
}
|
||||
end
|
||||
|
||||
context 'user namespace' do
|
||||
before do
|
||||
@project = Project.create_by_user(@opts, @user)
|
||||
end
|
||||
|
||||
it { @project.should be_valid }
|
||||
it { @project.owner.should == @user }
|
||||
it { @project.namespace.should == @user.namespace }
|
||||
end
|
||||
|
||||
context 'user namespace' do
|
||||
before do
|
||||
@group = create :group, owner: @user
|
||||
@opts.merge!(namespace_id: @group.id)
|
||||
@project = Project.create_by_user(@opts, @user)
|
||||
end
|
||||
|
||||
it { @project.should be_valid }
|
||||
it { @project.owner.should == @user }
|
||||
it { @project.namespace.should == @group }
|
||||
end
|
||||
end
|
||||
|
||||
describe :find_with_namespace do
|
||||
context 'with namespace' do
|
||||
before do
|
||||
@group = create :group, name: 'gitlab'
|
||||
@project = create(:project, name: 'gitlab-ci', namespace: @group)
|
||||
end
|
||||
|
||||
it { Project.find_with_namespace('gitlab/gitlab-ci').should == @project }
|
||||
it { Project.find_with_namespace('gitlab-ci').should be_nil }
|
||||
end
|
||||
|
||||
context 'w/o namespace' do
|
||||
before do
|
||||
@project = create(:project, name: 'gitlab-ci')
|
||||
end
|
||||
|
||||
it { Project.find_with_namespace('gitlab-ci').should == @project }
|
||||
it { Project.find_with_namespace('gitlab/gitlab-ci').should be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe :to_param do
|
||||
context 'with namespace' do
|
||||
before do
|
||||
@group = create :group, name: 'gitlab'
|
||||
@project = create(:project, name: 'gitlab-ci', namespace: @group)
|
||||
end
|
||||
|
||||
it { @project.to_param.should == "gitlab/gitlab-ci" }
|
||||
end
|
||||
|
||||
context 'w/o namespace' do
|
||||
before do
|
||||
@project = create(:project, name: 'gitlab-ci')
|
||||
end
|
||||
|
||||
it { @project.to_param.should == "gitlab-ci" }
|
||||
end
|
||||
end
|
||||
|
||||
describe :repository do
|
||||
let(:project) { create(:project) }
|
||||
|
||||
it "should return valid repo" do
|
||||
project.repository.should be_kind_of(Repository)
|
||||
end
|
||||
|
||||
it "should return nil" do
|
||||
Project.new(path: "empty").repository.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,13 +39,4 @@ describe ProtectedBranch do
|
|||
branch.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe '#commit' do
|
||||
let(:branch) { create(:protected_branch) }
|
||||
|
||||
it 'commits itself to its project' do
|
||||
branch.project.should_receive(:commit).with(branch.name)
|
||||
branch.commit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
105
spec/models/repository_spec.rb
Normal file
105
spec/models/repository_spec.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Repository do
|
||||
let(:project) { create(:project) }
|
||||
let(:repository) { project.repository }
|
||||
|
||||
describe "Respond to" do
|
||||
subject { repository }
|
||||
|
||||
it { should respond_to(:repo) }
|
||||
it { should respond_to(:tree) }
|
||||
it { should respond_to(:root_ref) }
|
||||
it { should respond_to(:tags) }
|
||||
it { should respond_to(:commit) }
|
||||
it { should respond_to(:commits) }
|
||||
it { should respond_to(:commits_between) }
|
||||
it { should respond_to(:commits_with_refs) }
|
||||
it { should respond_to(:commits_since) }
|
||||
it { should respond_to(:commits_between) }
|
||||
end
|
||||
|
||||
|
||||
describe "#discover_default_branch" do
|
||||
let(:master) { 'master' }
|
||||
let(:stable) { 'stable' }
|
||||
|
||||
it "returns 'master' when master exists" do
|
||||
repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
|
||||
repository.discover_default_branch.should == 'master'
|
||||
end
|
||||
|
||||
it "returns non-master when master exists but default branch is set to something else" do
|
||||
repository.root_ref = 'stable'
|
||||
repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
|
||||
repository.discover_default_branch.should == 'stable'
|
||||
end
|
||||
|
||||
it "returns a non-master branch when only one exists" do
|
||||
repository.should_receive(:branch_names).at_least(:once).and_return([stable])
|
||||
repository.discover_default_branch.should == 'stable'
|
||||
end
|
||||
|
||||
it "returns nil when no branch exists" do
|
||||
repository.should_receive(:branch_names).at_least(:once).and_return([])
|
||||
repository.discover_default_branch.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe :commit do
|
||||
it "should return first head commit if without params" do
|
||||
repository.commit.id.should == repository.repo.commits.first.id
|
||||
end
|
||||
|
||||
it "should return valid commit" do
|
||||
repository.commit(ValidCommit::ID).should be_valid_commit
|
||||
end
|
||||
|
||||
it "should return nil" do
|
||||
repository.commit("+123_4532530XYZ").should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe :tree do
|
||||
before do
|
||||
@commit = repository.commit(ValidCommit::ID)
|
||||
end
|
||||
|
||||
it "should raise error w/o arguments" do
|
||||
lambda { repository.tree }.should raise_error
|
||||
end
|
||||
|
||||
it "should return root tree for commit" do
|
||||
tree = repository.tree(@commit)
|
||||
tree.contents.size.should == ValidCommit::FILES_COUNT
|
||||
tree.contents.map(&:name).should == ValidCommit::FILES
|
||||
end
|
||||
|
||||
it "should return root tree for commit with correct path" do
|
||||
tree = repository.tree(@commit, ValidCommit::C_FILE_PATH)
|
||||
tree.contents.map(&:name).should == ValidCommit::C_FILES
|
||||
end
|
||||
|
||||
it "should return root tree for commit with incorrect path" do
|
||||
repository.tree(@commit, "invalid_path").should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "fresh commits" do
|
||||
it { repository.fresh_commits(3).count.should == 3 }
|
||||
it { repository.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
|
||||
it { repository.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
|
||||
end
|
||||
|
||||
describe "commits_between" do
|
||||
subject do
|
||||
commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
|
||||
"8470d70da67355c9c009e4401746b1d5410af2e3")
|
||||
commits.map { |c| c.id }
|
||||
end
|
||||
|
||||
it { should have(3).elements }
|
||||
it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
|
||||
it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
|
||||
end
|
||||
end
|
|
@ -23,53 +23,40 @@ describe SystemHook do
|
|||
end
|
||||
|
||||
it "project_create hook" do
|
||||
with_resque do
|
||||
project = create(:project)
|
||||
end
|
||||
project = create(:project)
|
||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
|
||||
end
|
||||
|
||||
it "project_destroy hook" do
|
||||
project = create(:project)
|
||||
with_resque do
|
||||
project.destroy
|
||||
end
|
||||
project.destroy
|
||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
|
||||
end
|
||||
|
||||
it "user_create hook" do
|
||||
with_resque do
|
||||
create(:user)
|
||||
end
|
||||
create(:user)
|
||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
|
||||
end
|
||||
|
||||
it "user_destroy hook" do
|
||||
user = create(:user)
|
||||
with_resque do
|
||||
user.destroy
|
||||
end
|
||||
user.destroy
|
||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
|
||||
end
|
||||
|
||||
it "project_create hook" do
|
||||
user = create(:user)
|
||||
project = create(:project)
|
||||
with_resque do
|
||||
project.add_access(user, :admin)
|
||||
end
|
||||
project.team << [user, :master]
|
||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
|
||||
end
|
||||
|
||||
it "project_destroy hook" do
|
||||
user = create(:user)
|
||||
project = create(:project)
|
||||
project.add_access(user, :admin)
|
||||
with_resque do
|
||||
project.users_projects.clear
|
||||
end
|
||||
project.team << [user, :master]
|
||||
project.users_projects.clear
|
||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
18
spec/models/team_spec.rb
Normal file
18
spec/models/team_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Team do
|
||||
let(:team) { create(:project).team }
|
||||
|
||||
describe "Respond to" do
|
||||
subject { team }
|
||||
|
||||
it { should respond_to(:developers) }
|
||||
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
|
||||
|
|
@ -39,7 +39,6 @@ describe User do
|
|||
describe "Associations" do
|
||||
it { should have_one(:namespace) }
|
||||
it { should have_many(:users_projects).dependent(:destroy) }
|
||||
it { should have_many(:projects) }
|
||||
it { should have_many(:groups) }
|
||||
it { should have_many(:keys).dependent(:destroy) }
|
||||
it { should have_many(:events).class_name('Event').dependent(:destroy) }
|
||||
|
@ -66,10 +65,6 @@ describe User do
|
|||
it { should ensure_length_of(:bio).is_within(0..255) }
|
||||
end
|
||||
|
||||
describe 'modules' do
|
||||
it { should include_module(Account) }
|
||||
end
|
||||
|
||||
describe "Respond to" do
|
||||
it { should respond_to(:is_admin?) }
|
||||
it { should respond_to(:identifier) }
|
||||
|
@ -119,4 +114,83 @@ describe User do
|
|||
user.authentication_token.should_not be_blank
|
||||
end
|
||||
end
|
||||
|
||||
describe 'projects' do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable(:user_observer)
|
||||
@user = create :user
|
||||
@project = create :project, namespace: @user.namespace
|
||||
end
|
||||
|
||||
it { @user.authorized_projects.should include(@project) }
|
||||
it { @user.owned_projects.should include(@project) }
|
||||
it { @user.personal_projects.should include(@project) }
|
||||
end
|
||||
|
||||
describe 'groups' do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable(:user_observer)
|
||||
@user = create :user
|
||||
@group = create :group, owner: @user
|
||||
end
|
||||
|
||||
it { @user.several_namespaces?.should be_true }
|
||||
it { @user.namespaces.should == [@user.namespace, @group] }
|
||||
it { @user.authorized_groups.should == [@group] }
|
||||
it { @user.owned_groups.should == [@group] }
|
||||
end
|
||||
|
||||
describe 'namespaced' do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable(:user_observer)
|
||||
@user = create :user
|
||||
@project = create :project, namespace: @user.namespace
|
||||
end
|
||||
|
||||
it { @user.several_namespaces?.should be_false }
|
||||
it { @user.namespaces.should == [@user.namespace] }
|
||||
end
|
||||
|
||||
describe 'blocking user' do
|
||||
let(:user) { create(:user, name: 'John Smith') }
|
||||
|
||||
it "should block user" do
|
||||
user.block
|
||||
user.blocked.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'filter' do
|
||||
before do
|
||||
User.delete_all
|
||||
@user = create :user
|
||||
@admin = create :user, admin: true
|
||||
@blocked = create :user, blocked: true
|
||||
end
|
||||
|
||||
it { User.filter("admins").should == [@admin] }
|
||||
it { User.filter("blocked").should == [@blocked] }
|
||||
it { User.filter("wop").should == [@user, @admin, @blocked] }
|
||||
it { User.filter(nil).should == [@user, @admin] }
|
||||
end
|
||||
|
||||
describe :not_in_project do
|
||||
before do
|
||||
User.delete_all
|
||||
@user = create :user
|
||||
@project = create :project
|
||||
end
|
||||
|
||||
it { User.not_in_project(@project).should == [@user, @project.owner] }
|
||||
end
|
||||
|
||||
describe 'normal user' do
|
||||
let(:user) { create(:user, name: 'John Smith') }
|
||||
|
||||
it { user.is_admin?.should be_false }
|
||||
it { user.require_ssh_key?.should be_true }
|
||||
it { user.can_create_group?.should be_false }
|
||||
it { user.can_create_project?.should be_true }
|
||||
it { user.first_name.should == 'John' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,10 +48,10 @@ describe UsersProject do
|
|||
@user_1 = create :user
|
||||
@user_2 = create :user
|
||||
|
||||
@project_1.add_access @user_1, :write
|
||||
@project_2.add_access @user_2, :read
|
||||
@project_1.team << [ @user_1, :developer ]
|
||||
@project_2.team << [ @user_2, :reporter ]
|
||||
|
||||
@status = UsersProject.import_team(@project_1, @project_2)
|
||||
@status = @project_2.team.import(@project_1)
|
||||
end
|
||||
|
||||
it { @status.should be_true }
|
||||
|
@ -69,4 +69,45 @@ describe UsersProject do
|
|||
it { @project_1.users.should_not include(@user_2) }
|
||||
end
|
||||
end
|
||||
|
||||
describe :add_users_into_projects do
|
||||
before do
|
||||
@project_1 = create :project
|
||||
@project_2 = create :project
|
||||
|
||||
@user_1 = create :user
|
||||
@user_2 = create :user
|
||||
|
||||
UsersProject.add_users_into_projects(
|
||||
[@project_1.id, @project_2.id],
|
||||
[@user_1.id, @user_2.id],
|
||||
UsersProject::MASTER
|
||||
)
|
||||
end
|
||||
|
||||
it { @project_1.users.should include(@user_1) }
|
||||
it { @project_1.users.should include(@user_2) }
|
||||
|
||||
|
||||
it { @project_2.users.should include(@user_1) }
|
||||
it { @project_2.users.should include(@user_2) }
|
||||
end
|
||||
|
||||
describe :truncate_teams do
|
||||
before do
|
||||
@project_1 = create :project
|
||||
@project_2 = create :project
|
||||
|
||||
@user_1 = create :user
|
||||
@user_2 = create :user
|
||||
|
||||
@project_1.team << [ @user_1, :developer]
|
||||
@project_2.team << [ @user_2, :reporter]
|
||||
|
||||
UsersProject.truncate_teams([@project_1.id, @project_2.id])
|
||||
end
|
||||
|
||||
it { @project_1.users.should be_empty }
|
||||
it { @project_2.users.should be_empty }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue