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:
Riyad Preukschas 2013-01-15 00:52:25 +01:00
commit 3022786948
930 changed files with 80374 additions and 103682 deletions

View file

@ -3,12 +3,12 @@ require 'spec_helper'
describe CommitController do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:commit) { project.last_commit_for("master") }
let(:commit) { project.repository.last_commit_for("master") }
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
end
describe "#show" do

View file

@ -7,7 +7,7 @@ describe CommitsController do
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
end
describe "GET show" do

View file

@ -7,7 +7,7 @@ describe MergeRequestsController do
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
MergeRequestsController.any_instance.stub(validates_merge_request: true)
end

View file

@ -7,7 +7,7 @@ describe TreeController do
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])

View file

@ -9,7 +9,7 @@ FactoryGirl.define do
sequence(:url) { Faker::Internet.uri('http') }
factory :user, aliases: [:author, :assignee, :owner] do
factory :user, aliases: [:author, :assignee, :owner, :creator] do
email { Faker::Internet.email }
name
username { Faker::Internet.user_name }
@ -26,7 +26,7 @@ FactoryGirl.define do
factory :project do
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
owner
creator
end
factory :group do
@ -37,7 +37,7 @@ FactoryGirl.define do
end
factory :namespace do
sequence(:name) { |n| "group#{n}" }
sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') }
owner
end

View file

@ -4,7 +4,7 @@ describe GitlabMarkdownHelper do
let!(:project) { create(:project) }
let(:user) { create(:user, username: 'gfm') }
let(:commit) { CommitDecorator.decorate(project.commit) }
let(:commit) { CommitDecorator.decorate(project.repository.commit) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, project: project) }
let(:snippet) { create(:snippet, project: project) }
@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do
let(:expected) { project_team_member_path(project, member) }
before do
project.add_access(user, :admin)
project.team << [user, :master]
end
it "should link using a simple name" do
@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do
end
it "should handle references in lists" do
project.add_access(user, :admin)
project.team << [user, :master]
actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}"

View file

@ -7,7 +7,8 @@ describe ExtractsPath do
before do
@project = project
project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])
project.stub(repository: stub(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']))
project.stub(path_with_namespace: 'gitlab/gitlab-ci')
end
describe '#extract_ref' do
@ -53,5 +54,24 @@ describe ExtractsPath do
extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
end
end
context "with a fullpath" do
it "extracts a valid branch" do
extract_ref('/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
end
it "extracts a valid tag" do
extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
end
it "extracts a valid commit SHA" do
extract_ref('/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
end
it "extracts a timestamp" do
extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']
end
end
end
end

View file

@ -5,6 +5,7 @@ describe Gitlab::ProjectMover do
before do
FileUtils.rm_rf base_path if File.exists? base_path
FileUtils.mkdir_p base_path
Gitlab.config.gitolite.stub(repos_path: base_path)

View file

@ -60,7 +60,7 @@ describe Notify do
it_behaves_like 'an assignee email'
it 'has the correct subject' do
should have_subject /new issue ##{issue.id} \| #{issue.title} \| #{project.name}/
should have_subject /#{project.name} \| new issue ##{issue.id} \| #{issue.title}/
end
it 'contains a link to the new issue' do

View file

@ -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

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe Issue, "IssueCommonality" do
describe Issue, "Issuable" do
let(:issue) { create(:issue) }
describe "Associations" do

View 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

View file

@ -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) }

View file

@ -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

View file

@ -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

View file

@ -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 }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View 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

View file

@ -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
View 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

View file

@ -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

View file

@ -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

View file

@ -21,8 +21,7 @@ describe IssueObserver do
end
it 'sends an email to the assignee' do
Notify.should_receive(:new_issue_email).with(issue.id).
and_return(double(deliver: true))
Notify.should_receive(:new_issue_email).with(issue.id)
subject.after_create(issue)
end
@ -71,6 +70,7 @@ describe IssueObserver do
context 'a status "closed"' do
it 'note is created if the issue is being closed' do
issue.should_receive(:is_being_closed?).and_return(true)
Notify.should_receive(:issue_status_changed_email).twice
Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
subject.after_update(issue)
@ -85,7 +85,7 @@ describe IssueObserver do
it 'notification is delivered if the issue being closed' do
issue.stub(:is_being_closed?).and_return(true)
Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).twice
Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
subject.after_update(issue)
@ -104,7 +104,7 @@ describe IssueObserver do
issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
issue_without_assignee.stub(:is_being_closed?).and_return(true)
issue_without_assignee.stub(:is_being_reopened?).and_return(false)
Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).once
Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed')
subject.after_update(issue_without_assignee)
@ -113,6 +113,7 @@ describe IssueObserver do
context 'a status "reopened"' do
it 'note is created if the issue is being reopened' do
Notify.should_receive(:issue_status_changed_email).twice
issue.should_receive(:is_being_reopened?).and_return(true)
Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
@ -128,7 +129,7 @@ describe IssueObserver do
it 'notification is delivered if the issue being reopened' do
issue.stub(:is_being_reopened?).and_return(true)
Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).twice
Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
subject.after_update(issue)
@ -147,7 +148,7 @@ describe IssueObserver do
issue_without_assignee.stub(:is_being_reassigned?).and_return(false)
issue_without_assignee.stub(:is_being_closed?).and_return(false)
issue_without_assignee.stub(:is_being_reopened?).and_return(true)
Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true))
Notify.should_receive(:issue_status_changed_email).once
Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened')
subject.after_update(issue_without_assignee)
@ -164,8 +165,7 @@ describe IssueObserver do
end
def it_sends_a_reassigned_email_to(recipient)
Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id).
and_return(double(deliver: true))
Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id)
end
def it_does_not_send_a_reassigned_email_to(recipient)

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe KeyObserver do
before do
before do
@key = double('Key',
identifier: 'admin_654654',
key: '== a vaild ssh key',
@ -15,7 +15,7 @@ describe KeyObserver do
)
@observer = KeyObserver.instance
@observer.stub(:git_host => @gitolite)
@observer.stub(gitolite: @gitolite)
end
context :after_save do
@ -25,7 +25,7 @@ describe KeyObserver do
end
end
context :after_destroy do
context :after_destroy do
it do
@gitolite.should_receive(:remove_key).with(@key.identifier, @key.projects)
@observer.after_destroy(@key)

View file

@ -21,9 +21,7 @@ describe MergeRequestObserver do
end
it 'sends an email to the assignee' do
Notify.should_receive(:new_merge_request_email).with(mr.id).
and_return(double(deliver: true))
Notify.should_receive(:new_merge_request_email).with(mr.id)
subject.after_create(mr)
end
@ -158,8 +156,7 @@ describe MergeRequestObserver do
end
def it_sends_a_reassigned_email_to(recipient)
Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id).
and_return(double(deliver: true))
Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id)
end
def it_does_not_send_a_reassigned_email_to(recipient)

View file

@ -4,7 +4,6 @@ describe NoteObserver do
subject { NoteObserver.instance }
let(:team_without_author) { (1..2).map { |n| double :user, id: n } }
let(:delivery_success) { double deliver: true }
describe '#after_create' do
let(:note) { double :note }
@ -45,13 +44,13 @@ describe NoteObserver do
note.stub(:id).and_return(42)
author = double :user, id: 1
note.stub(:commit_author).and_return(author)
Notify.should_receive(:note_commit_email).and_return(delivery_success)
Notify.should_receive(:note_commit_email)
subject.after_create(note)
end
it 'does not notify the author of a commit when not flagged to notify the author' do
Notify.should_not_receive(:note_commit_email)
notify.should_not_receive(:note_commit_email)
subject.after_create(note)
end
@ -71,28 +70,28 @@ describe NoteObserver do
context 'notifies team of a new note on' do
it 'a commit' do
note.stub(:noteable_type).and_return('Commit')
Notify.should_receive(:note_commit_email).twice.and_return(delivery_success)
notify.should_receive(:note_commit_email).twice
subject.send(:notify_team, note)
end
it 'an issue' do
note.stub(:noteable_type).and_return('Issue')
Notify.should_receive(:note_issue_email).twice.and_return(delivery_success)
notify.should_receive(:note_issue_email).twice
subject.send(:notify_team, note)
end
it 'a wiki page' do
note.stub(:noteable_type).and_return('Wiki')
Notify.should_receive(:note_wiki_email).twice.and_return(delivery_success)
notify.should_receive(:note_wiki_email).twice
subject.send(:notify_team, note)
end
it 'a merge request' do
note.stub(:noteable_type).and_return('MergeRequest')
Notify.should_receive(:note_merge_request_email).twice.and_return(delivery_success)
notify.should_receive(:note_merge_request_email).twice
subject.send(:notify_team, note)
end
@ -100,16 +99,16 @@ describe NoteObserver do
it 'a wall' do
# Note: wall posts have #noteable_type of nil
note.stub(:noteable_type).and_return(nil)
Notify.should_receive(:note_wall_email).twice.and_return(delivery_success)
notify.should_receive(:note_wall_email).twice
subject.send(:notify_team, note)
end
end
it 'does nothing for a new note on a snippet' do
note.stub(:noteable_type).and_return('Snippet')
note.stub(:noteable_type).and_return('Snippet')
subject.send(:notify_team, note).should be_nil
subject.send(:notify_team, note).should be_nil
end
end
@ -125,4 +124,8 @@ describe NoteObserver do
subject.send(:team_without_note_author, note).should == team_without_author
end
end
def notify
Notify
end
end

View file

@ -6,31 +6,18 @@ describe UserObserver do
it 'calls #after_create when new users are created' do
new_user = build(:user)
subject.should_receive(:after_create).with(new_user)
User.observers.enable :user_observer do
new_user.save
end
new_user.save
end
context 'when a new user is created' do
let(:user) { double(:user, id: 42,
password: 'P@ssword!',
name: 'John',
email: 'u@mail.local',
username: 'root',
create_namespace: true) }
let(:notification) { double :notification }
it 'sends an email' do
notification.should_receive(:deliver)
Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification)
subject.after_create(user)
Notify.should_receive(:new_user_email)
create(:user)
end
it 'trigger logger' do
Gitlab::AppLogger.should_receive(:info)
subject.after_create(user)
create(:user)
end
end
end

View file

@ -3,72 +3,62 @@ require 'spec_helper'
describe UsersProjectObserver do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:users_project) { create(:users_project,
project: project,
user: user )}
subject { UsersProjectObserver.instance }
describe "#after_commit" do
it "should called when UsersProject created" do
subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
create(:users_project)
end
subject.should_receive(:after_commit)
create(:users_project)
end
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
subject.after_commit(users_project)
Notify.should_receive(:project_access_granted_email).and_return(double(deliver: true))
Event.stub(:create => true)
create(:users_project)
end
it "should create new event" do
Event.should_receive(:create).with(
project_id: users_project.project.id,
action: Event::Joined,
author_id: users_project.user.id
)
Event.should_receive(:create)
subject.after_create(users_project)
create(:users_project)
end
end
describe "#after_update" do
before do
@users_project = create :users_project
end
it "should called when UsersProject updated" do
subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
create(:users_project).update_attribute(:project_access, UsersProject::MASTER)
end
subject.should_receive(:after_commit)
@users_project.update_attribute(:project_access, UsersProject::MASTER)
end
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
subject.after_commit(users_project)
Notify.should_receive(:project_access_granted_email)
@users_project.update_attribute(:project_access, UsersProject::MASTER)
end
it "should not called after UsersProject destroyed" do
subject.should_not_receive(:after_commit)
UsersProject.observers.enable :users_project_observer do
users_project.destroy
end
@users_project.destroy
end
end
describe "#after_destroy" do
before do
@users_project = create :users_project
end
it "should called when UsersProject destroyed" do
subject.should_receive(:after_destroy)
UsersProject.observers.enable :users_project_observer do
create(:users_project).destroy
end
@users_project.destroy
end
it "should create new event" do
Event.should_receive(:create).with(
project_id: users_project.project.id,
action: Event::Left,
author_id: users_project.user.id
)
subject.after_destroy(users_project)
Event.should_receive(:create)
@users_project.destroy
end
end
end

View file

@ -41,7 +41,7 @@ describe "Admin::Users" do
end
it "should call send mail" do
Notify.should_receive(:new_user_email).and_return(stub(deliver: true))
Notify.should_receive(:new_user_email)
User.observers.enable :user_observer do
click_button "Save"
@ -50,9 +50,7 @@ describe "Admin::Users" do
it "should send valid email to user with email & password" do
User.observers.enable :user_observer do
with_resque do
click_button "Save"
end
click_button "Save"
user = User.last
email = ActionMailer::Base.deliveries.last
email.subject.should have_content("Account was created")

View file

@ -4,9 +4,9 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
before { project.add_access(user, :read) }
before { project.team << [user, :reporter] }
describe "GET /issues" do
context "when unauthenticated" do
@ -28,7 +28,7 @@ describe Gitlab::API do
describe "GET /projects/:id/issues" do
it "should return project issues" do
get api("/projects/#{project.path}/issues", user)
get api("/projects/#{project.id}/issues", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == issue.title
@ -37,7 +37,7 @@ describe Gitlab::API do
describe "GET /projects/:id/issues/:issue_id" do
it "should return a project issue by id" do
get api("/projects/#{project.path}/issues/#{issue.id}", user)
get api("/projects/#{project.id}/issues/#{issue.id}", user)
response.status.should == 200
json_response['title'].should == issue.title
end
@ -45,7 +45,7 @@ describe Gitlab::API do
describe "POST /projects/:id/issues" do
it "should create a new project issue" do
post api("/projects/#{project.path}/issues", user),
post api("/projects/#{project.id}/issues", user),
title: 'new issue', labels: 'label, label2'
response.status.should == 201
json_response['title'].should == 'new issue'
@ -56,7 +56,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/issues/:issue_id" do
it "should update a project issue" do
put api("/projects/#{project.path}/issues/#{issue.id}", user),
put api("/projects/#{project.id}/issues/#{issue.id}", user),
title: 'updated title', labels: 'label2', closed: 1
response.status.should == 200
json_response['title'].should == 'updated title'
@ -67,7 +67,7 @@ describe Gitlab::API do
describe "DELETE /projects/:id/issues/:issue_id" do
it "should delete a project issue" do
delete api("/projects/#{project.path}/issues/#{issue.id}", user)
delete api("/projects/#{project.id}/issues/#{issue.id}", user)
response.status.should == 405
end
end

View file

@ -4,21 +4,21 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user ) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
before { project.add_access(user, :read) }
before { project.team << [user, :reporters] }
describe "GET /projects/:id/merge_requests" do
context "when unauthenticated" do
it "should return authentication error" do
get api("/projects/#{project.path}/merge_requests")
get api("/projects/#{project.id}/merge_requests")
response.status.should == 401
end
end
context "when authenticated" do
it "should return an array of merge_requests" do
get api("/projects/#{project.path}/merge_requests", user)
get api("/projects/#{project.id}/merge_requests", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == merge_request.title
@ -28,7 +28,7 @@ describe Gitlab::API do
describe "GET /projects/:id/merge_request/:merge_request_id" do
it "should return merge_request" do
get api("/projects/#{project.path}/merge_request/#{merge_request.id}", user)
get api("/projects/#{project.id}/merge_request/#{merge_request.id}", user)
response.status.should == 200
json_response['title'].should == merge_request.title
end
@ -36,7 +36,7 @@ describe Gitlab::API do
describe "POST /projects/:id/merge_requests" do
it "should return merge_request" do
post api("/projects/#{project.path}/merge_requests", user),
post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user
response.status.should == 201
json_response['title'].should == 'Test merge_request'
@ -45,7 +45,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/merge_request/:merge_request_id" do
it "should return merge_request" do
put api("/projects/#{project.path}/merge_request/#{merge_request.id}", user), title: "New title"
put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), title: "New title"
response.status.should == 200
json_response['title'].should == 'New title'
end
@ -53,7 +53,7 @@ describe Gitlab::API do
describe "POST /projects/:id/merge_request/:merge_request_id/comments" do
it "should return comment" do
post api("/projects/#{project.path}/merge_request/#{merge_request.id}/comments", user), note: "My comment"
post api("/projects/#{project.id}/merge_request/#{merge_request.id}/comments", user), note: "My comment"
response.status.should == 201
json_response['note'].should == 'My comment'
end

View file

@ -4,14 +4,14 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:milestone) { create(:milestone, project: project) }
before { project.add_access(user, :read) }
before { project.team << [user, :developer] }
describe "GET /projects/:id/milestones" do
it "should return project milestones" do
get api("/projects/#{project.path}/milestones", user)
get api("/projects/#{project.id}/milestones", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == milestone.title
@ -20,7 +20,7 @@ describe Gitlab::API do
describe "GET /projects/:id/milestones/:milestone_id" do
it "should return a project milestone by id" do
get api("/projects/#{project.path}/milestones/#{milestone.id}", user)
get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
response.status.should == 200
json_response['title'].should == milestone.title
end
@ -28,7 +28,7 @@ describe Gitlab::API do
describe "POST /projects/:id/milestones" do
it "should create a new project milestone" do
post api("/projects/#{project.path}/milestones", user),
post api("/projects/#{project.id}/milestones", user),
title: 'new milestone'
response.status.should == 201
json_response['title'].should == 'new milestone'
@ -38,7 +38,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/milestones/:milestone_id" do
it "should update a project milestone" do
put api("/projects/#{project.path}/milestones/#{milestone.id}", user),
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
title: 'updated title'
response.status.should == 200
json_response['title'].should == 'updated title'

View file

@ -4,13 +4,13 @@ describe Gitlab::API do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, project: project, author: user) }
let!(:snippet) { create(:snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
let!(:wall_note) { create(:note, project: project, author: user) }
before { project.add_access(user, :read) }
before { project.team << [user, :reporter] }
describe "GET /projects/:id/notes" do
context "when unauthenticated" do

View file

@ -7,11 +7,11 @@ describe Gitlab::API do
let(:user2) { create(:user) }
let(:user3) { create(:user) }
let!(:hook) { create(:project_hook, project: project, url: "http://example.com") }
let!(:project) { create(:project, owner: user ) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') }
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
before { project.add_access(user, :read) }
before { project.team << [user, :reporter] }
describe "GET /projects" do
context "when unauthenticated" do
@ -64,6 +64,7 @@ describe Gitlab::API do
post api("/projects", user), project
project.each_pair do |k,v|
next if k == :path
json_response[k.to_s].should == v
end
end
@ -78,7 +79,7 @@ describe Gitlab::API do
end
it "should return a project by path name" do
get api("/projects/#{project.path}", user)
get api("/projects/#{project.id}", user)
response.status.should == 200
json_response['name'].should == project.name
end
@ -92,7 +93,7 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/branches" do
it "should return an array of project branches" do
get api("/projects/#{project.path}/repository/branches", user)
get api("/projects/#{project.id}/repository/branches", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name
@ -101,7 +102,7 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/branches/:branch" do
it "should return the branch information for a single branch" do
get api("/projects/#{project.path}/repository/branches/new_design", user)
get api("/projects/#{project.id}/repository/branches/new_design", user)
response.status.should == 200
json_response['name'].should == 'new_design'
@ -111,7 +112,7 @@ describe Gitlab::API do
describe "GET /projects/:id/members" do
it "should return project team members" do
get api("/projects/#{project.path}/members", user)
get api("/projects/#{project.id}/members", user)
response.status.should == 200
json_response.should be_an Array
json_response.count.should == 2
@ -119,7 +120,7 @@ describe Gitlab::API do
end
it "finds team members with query string" do
get api("/projects/#{project.path}/members", user), query: user.username
get api("/projects/#{project.id}/members", user), query: user.username
response.status.should == 200
json_response.should be_an Array
json_response.count.should == 1
@ -129,7 +130,7 @@ describe Gitlab::API do
describe "GET /projects/:id/members/:user_id" do
it "should return project team member" do
get api("/projects/#{project.path}/members/#{user.id}", user)
get api("/projects/#{project.id}/members/#{user.id}", user)
response.status.should == 200
json_response['email'].should == user.email
json_response['access_level'].should == UsersProject::MASTER
@ -139,7 +140,7 @@ describe Gitlab::API do
describe "POST /projects/:id/members" do
it "should add user to project team" do
expect {
post api("/projects/#{project.path}/members", user), user_id: user2.id,
post api("/projects/#{project.id}/members", user), user_id: user2.id,
access_level: UsersProject::DEVELOPER
}.to change { UsersProject.count }.by(1)
@ -151,7 +152,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/members/:user_id" do
it "should update project team member" do
put api("/projects/#{project.path}/members/#{user3.id}", user), access_level: UsersProject::MASTER
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: UsersProject::MASTER
response.status.should == 200
json_response['email'].should == user3.email
json_response['access_level'].should == UsersProject::MASTER
@ -161,14 +162,14 @@ describe Gitlab::API do
describe "DELETE /projects/:id/members/:user_id" do
it "should remove user from project team" do
expect {
delete api("/projects/#{project.path}/members/#{user3.id}", user)
delete api("/projects/#{project.id}/members/#{user3.id}", user)
}.to change { UsersProject.count }.by(-1)
end
end
describe "GET /projects/:id/hooks" do
it "should return project hooks" do
get api("/projects/#{project.path}/hooks", user)
get api("/projects/#{project.id}/hooks", user)
response.status.should == 200
@ -180,7 +181,7 @@ describe Gitlab::API do
describe "GET /projects/:id/hooks/:hook_id" do
it "should return a project hook" do
get api("/projects/#{project.path}/hooks/#{hook.id}", user)
get api("/projects/#{project.id}/hooks/#{hook.id}", user)
response.status.should == 200
json_response['url'].should == hook.url
end
@ -189,7 +190,7 @@ describe Gitlab::API do
describe "POST /projects/:id/hooks" do
it "should add hook to project" do
expect {
post api("/projects/#{project.path}/hooks", user),
post api("/projects/#{project.id}/hooks", user),
"url" => "http://example.com"
}.to change {project.hooks.count}.by(1)
end
@ -197,7 +198,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/hooks/:hook_id" do
it "should update an existing project hook" do
put api("/projects/#{project.path}/hooks/#{hook.id}", user),
put api("/projects/#{project.id}/hooks/#{hook.id}", user),
url: 'http://example.org'
response.status.should == 200
json_response['url'].should == 'http://example.org'
@ -208,7 +209,7 @@ describe Gitlab::API do
describe "DELETE /projects/:id/hooks" do
it "should delete hook from project" do
expect {
delete api("/projects/#{project.path}/hooks", user),
delete api("/projects/#{project.id}/hooks", user),
hook_id: hook.id
}.to change {project.hooks.count}.by(-1)
end
@ -216,7 +217,7 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/tags" do
it "should return an array of project tags" do
get api("/projects/#{project.path}/repository/tags", user)
get api("/projects/#{project.id}/repository/tags", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name
@ -225,20 +226,20 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/commits" do
context "authorized user" do
before { project.add_access(user2, :read) }
before { project.team << [user2, :reporter] }
it "should return project commits" do
get api("/projects/#{project.path}/repository/commits", user)
get api("/projects/#{project.id}/repository/commits", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['id'].should == project.commit.id
json_response.first['id'].should == project.repository.commit.id
end
end
context "unauthorized user" do
it "should not return project commits" do
get api("/projects/#{project.path}/repository/commits")
get api("/projects/#{project.id}/repository/commits")
response.status.should == 401
end
end
@ -246,7 +247,7 @@ describe Gitlab::API do
describe "GET /projects/:id/snippets" do
it "should return an array of project snippets" do
get api("/projects/#{project.path}/snippets", user)
get api("/projects/#{project.id}/snippets", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == snippet.title
@ -255,7 +256,7 @@ describe Gitlab::API do
describe "GET /projects/:id/snippets/:snippet_id" do
it "should return a project snippet" do
get api("/projects/#{project.path}/snippets/#{snippet.id}", user)
get api("/projects/#{project.id}/snippets/#{snippet.id}", user)
response.status.should == 200
json_response['title'].should == snippet.title
end
@ -263,7 +264,7 @@ describe Gitlab::API do
describe "POST /projects/:id/snippets" do
it "should create a new project snippet" do
post api("/projects/#{project.path}/snippets", user),
post api("/projects/#{project.id}/snippets", user),
title: 'api test', file_name: 'sample.rb', code: 'test'
response.status.should == 201
json_response['title'].should == 'api test'
@ -272,7 +273,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/snippets/:shippet_id" do
it "should update an existing project snippet" do
put api("/projects/#{project.path}/snippets/#{snippet.id}", user),
put api("/projects/#{project.id}/snippets/#{snippet.id}", user),
code: 'updated code'
response.status.should == 200
json_response['title'].should == 'example'
@ -283,31 +284,31 @@ describe Gitlab::API do
describe "DELETE /projects/:id/snippets/:snippet_id" do
it "should delete existing project snippet" do
expect {
delete api("/projects/#{project.path}/snippets/#{snippet.id}", user)
delete api("/projects/#{project.id}/snippets/#{snippet.id}", user)
}.to change { Snippet.count }.by(-1)
end
end
describe "GET /projects/:id/snippets/:snippet_id/raw" do
it "should get a raw project snippet" do
get api("/projects/#{project.path}/snippets/#{snippet.id}/raw", user)
get api("/projects/#{project.id}/snippets/#{snippet.id}/raw", user)
response.status.should == 200
end
end
describe "GET /projects/:id/:sha/blob" do
it "should get the raw file contents" do
get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.md", user)
get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user)
response.status.should == 200
end
it "should return 404 for invalid branch_name" do
get api("/projects/#{project.path}/repository/commits/invalid_branch_name/blob?filepath=README.md", user)
get api("/projects/#{project.id}/repository/commits/invalid_branch_name/blob?filepath=README.md", user)
response.status.should == 404
end
it "should return 404 for invalid file" do
get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.invalid", user)
get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.invalid", user)
response.status.should == 404
end
end

View file

@ -3,10 +3,10 @@ require 'spec_helper'
describe "Issues Feed" do
describe "GET /issues" do
let!(:user) { create(:user) }
let!(:project) { create(:project, owner: user) }
let!(:project) { create(:project, namespace: user.namespace) }
let!(:issue) { create(:issue, author: user, project: project) }
before { project.add_access(user, :read, :write) }
before { project.team << [user, :developer] }
context "when authenticated" do
it "should render atom feed" do

View file

@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do
let(:merge_request) { create(:merge_request, project: project) }
let(:fred) do
u = create(:user, name: "fred")
project.add_access(u, :admin)
project.team << [u, :master]
u
end
@ -33,11 +33,11 @@ describe "Gitlab Flavored Markdown" do
project.repo.gc_auto
end
let(:commit) { project.commits(@branch_name).first }
let(:commit) { project.repository.commits(@branch_name).first }
before do
login_as :user
project.add_access(@user, :read, :write)
project.team << [@user, :developer]
end
describe "for commits" do

View file

@ -7,8 +7,7 @@ describe "Issues" do
login_as :user
user2 = create(:user)
project.add_access(@user, :read, :write)
project.add_access(user2, :read, :write)
project.team << [[@user, user2], :developer]
end
describe "Edit issue" do

View file

@ -5,7 +5,7 @@ describe "Projects", "DeployKeys" do
before do
login_as :user
project.add_access(@user, :read, :write, :admin)
project.team << [@user, :master]
end
describe "GET /keys" do

View file

@ -3,63 +3,10 @@ require 'spec_helper'
describe "Projects" do
before { login_as :user }
describe "GET /projects/show" do
before do
@project = create(:project, owner: @user)
@project.add_access(@user, :read)
visit project_path(@project)
end
it "should be correct path" do
current_path.should == project_path(@project)
end
end
describe "GET /projects/:id/edit" do
before do
@project = create(:project)
@project.add_access(@user, :admin, :read)
visit edit_project_path(@project)
end
it "should be correct path" do
current_path.should == edit_project_path(@project)
end
it "should have labels for new project" do
page.should have_content("Project name is")
page.should have_content("Advanced settings:")
page.should have_content("Features:")
end
end
describe "PUT /projects/:id" do
before do
@project = create(:project, owner: @user)
@project.add_access(@user, :admin, :read)
visit edit_project_path(@project)
fill_in 'project_name', with: 'Awesome'
click_button "Save"
@project = @project.reload
end
it "should be correct path" do
current_path.should == edit_project_path(@project)
end
it "should show project" do
page.should have_content("Awesome")
end
end
describe "DELETE /projects/:id" do
before do
@project = create(:project, owner: @user)
@project.add_access(@user, :read, :admin)
@project = create(:project, namespace: @user.namespace)
@project.team << [@user, :master]
visit edit_project_path(@project)
end

View file

@ -4,7 +4,7 @@ describe "Search" do
before do
login_as :user
@project = create(:project)
@project.add_access(@user, :read)
@project.team << [@user, :reporter]
visit search_path
fill_in "search", with: @project.name[0..3]
click_button "Search"

View file

@ -22,10 +22,10 @@ describe "Application access" do
before do
# full access
project.users_projects.create(user: master, project_access: UsersProject::MASTER)
project.team << [master, :master]
# readonly
project.users_projects.create(user: reporter, project_access: UsersProject::REPORTER)
project.team << [reporter, :reporter]
end
describe "GET /project_code" do
@ -40,7 +40,7 @@ describe "Application access" do
end
describe "GET /project_code/tree/master" do
subject { project_tree_path(project, project.root_ref) }
subject { project_tree_path(project, project.repository.root_ref) }
it { should be_allowed_for master }
it { should be_allowed_for reporter }
@ -51,7 +51,7 @@ describe "Application access" do
end
describe "GET /project_code/commits/master" do
subject { project_commits_path(project, project.root_ref, limit: 1) }
subject { project_commits_path(project, project.repository.root_ref, limit: 1) }
it { should be_allowed_for master }
it { should be_allowed_for reporter }
@ -62,7 +62,7 @@ describe "Application access" do
end
describe "GET /project_code/commit/:sha" do
subject { project_commit_path(project, project.commit) }
subject { project_commit_path(project, project.repository.commit) }
it { should be_allowed_for master }
it { should be_allowed_for reporter }
@ -107,7 +107,7 @@ describe "Application access" do
describe "GET /project_code/blob" do
before do
commit = project.commit
commit = project.repository.commit
path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob)}.first.name
@blob_path = project_blob_path(project, File.join(commit.id, path))
end

View file

@ -5,7 +5,7 @@ describe "Snippets" do
before do
login_as :user
project.add_access(@user, :read, :write)
project.team << [@user, :developer]
end
describe "GET /snippets" do
@ -26,7 +26,7 @@ describe "Snippets" do
before do
# admin access to remove snippet
@user.users_projects.destroy_all
project.add_access(@user, :read, :write, :admin)
project.team << [@user, :master]
visit edit_project_snippet_path(project, @snippet)
end

View file

@ -1,44 +0,0 @@
require 'spec_helper'
describe User, "Account" do
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
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 '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.my_own_projects.should include(@project) }
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
end

View file

@ -1,159 +0,0 @@
require 'spec_helper'
describe Project, "Repository" do
let(:project) { create(: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) { 'master' }
let(:stable) { 'stable' }
it "returns 'master' when master exists" do
project.should_receive(:branch_names).at_least(:once).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(:branch_names).at_least(:once).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(:branch_names).at_least(:once).and_return([stable])
project.discover_default_branch.should == 'stable'
end
it "returns nil when no branch exists" do
project.should_receive(:branch_names).at_least(:once).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
describe :repo do
it "should return valid repo" do
project.repo.should be_kind_of(Grit::Repo)
end
it "should return nil" do
lambda { Project.new(path: "invalid").repo }.should raise_error(Grit::NoSuchPathError)
end
it "should return nil" do
lambda { Project.new.repo }.should raise_error(TypeError)
end
end
describe :commit do
it "should return first head commit if without params" do
project.commit.id.should == project.repo.commits.first.id
end
it "should return valid commit" do
project.commit(ValidCommit::ID).should be_valid_commit
end
it "should return nil" do
project.commit("+123_4532530XYZ").should be_nil
end
end
describe :tree do
before do
@commit = project.commit(ValidCommit::ID)
end
it "should raise error w/o arguments" do
lambda { project.tree }.should raise_error
end
it "should return root tree for commit" do
tree = project.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 = project.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
project.tree(@commit, "invalid_path").should be_nil
end
end
describe "fresh commits" do
let(:project) { create(:project) }
it { project.fresh_commits(3).count.should == 3 }
it { project.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
it { project.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
end
describe "commits_between" do
let(:project) { create(:project) }
subject do
commits = project.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
describe :valid_repo? do
it "should be valid repo" do
project = create(:project)
project.valid_repo?.should be_true
end
it "should be invalid repo" do
project = Project.new(name: "ok_name", path: "/INVALID_PATH/", path: "NEOK")
project.valid_repo?.should be_false
end
end
end

View file

@ -191,17 +191,17 @@ describe ProtectedBranchesController, "routing" do
end
end
# switch_project_refs GET /:project_id/switch(.:format) refs#switch
# logs_tree_project_ref GET /:project_id/:id/logs_tree(.:format) refs#logs_tree
# logs_file_project_ref GET /:project_id/:id/logs_tree/:path(.:format) refs#logs_tree
# switch_project_refs GET /:project_id/refs/switch(.:format) refs#switch
# logs_tree_project_ref GET /:project_id/refs/:id/logs_tree(.:format) refs#logs_tree
# logs_file_project_ref GET /:project_id/refs/:id/logs_tree/:path(.:format) refs#logs_tree
describe RefsController, "routing" do
it "to #switch" do
get("/gitlabhq/switch").should route_to('refs#switch', project_id: 'gitlabhq')
get("/gitlabhq/refs/switch").should route_to('refs#switch', project_id: 'gitlabhq')
end
it "to #logs_tree" do
get("/gitlabhq/stable/logs_tree").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable')
get("/gitlabhq/stable/logs_tree/foo/bar/baz").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
get("/gitlabhq/refs/stable/logs_tree").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable')
get("/gitlabhq/refs/stable/logs_tree/foo/bar/baz").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
end
end

View file

@ -1,7 +1,5 @@
unless ENV['CI']
require 'simplecov'
SimpleCov.start 'rails'
end
require 'simplecov' unless ENV['CI']
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
@ -11,6 +9,7 @@ require 'capybara/rails'
require 'capybara/rspec'
require 'webmock/rspec'
require 'email_spec'
require 'sidekiq/testing/inline'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
@ -37,13 +36,10 @@ RSpec.configure do |config|
config.before do
stub_gitolite!
# !!! Observers disabled by default in tests
ActiveRecord::Base.observers.disable(:all)
# ActiveRecord::Base.observers.enable(:all)
# Use tmp dir for FS manipulations
Gitlab.config.gitolite.stub(repos_path: Rails.root.join('tmp', 'test-git-base-path'))
FileUtils.rm_rf Gitlab.config.gitolite.repos_path
FileUtils.mkdir_p Gitlab.config.gitolite.repos_path
temp_repos_path = Rails.root.join('tmp', 'test-git-base-path')
Gitlab.config.gitolite.stub(repos_path: temp_repos_path)
FileUtils.rm_rf temp_repos_path
FileUtils.mkdir_p temp_repos_path
end
end

View file

@ -1,15 +1,14 @@
require "repository"
require "project"
# Stubs out all Git repository access done by models so that specs can run
# against fake repositories without Grit complaining that they don't exist.
module StubbedRepository
def path_to_repo
if new_record? || path == 'newproject'
# There are a couple Project specs and features that expect the Project's
# path to be in the returned path, so let's patronize them.
Rails.root.join('tmp', 'repositories', path)
class Project
def repository
if path == "empty" || !path
nil
else
# For everything else, just give it the path to one of our real seeded
# repos.
Rails.root.join('tmp', 'repositories', 'gitlabhq')
GitLabTestRepo.new(path_with_namespace)
end
end
@ -28,4 +27,8 @@ module StubbedRepository
end
end
Project.send(:include, StubbedRepository)
class GitLabTestRepo < Repository
def repo
@repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq'))
end
end

View file

@ -3,6 +3,7 @@ require 'rake'
describe 'gitlab:app namespace rake task' do
before :all do
Rake.application.rake_require "tasks/gitlab/task_helpers"
Rake.application.rake_require "tasks/gitlab/backup"
# empty task as env is already loaded
Rake::Task.define_task :environment

View file

@ -4,7 +4,7 @@ describe PostReceive do
context "as a resque worker" do
it "reponds to #perform" do
PostReceive.should respond_to(:perform)
PostReceive.new.should respond_to(:perform)
end
end
@ -15,7 +15,7 @@ describe PostReceive do
it "fetches the correct project" do
Project.should_receive(:find_with_namespace).with(project.path_with_namespace).and_return(project)
PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
end
it "does not run if the author is not in the project" do
@ -24,7 +24,7 @@ describe PostReceive do
project.should_not_receive(:observe_push)
project.should_not_receive(:execute_hooks)
PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false
end
it "asks the project to trigger all hooks" do
@ -34,7 +34,7 @@ describe PostReceive do
project.should_receive(:update_merge_requests)
project.should_receive(:observe_push)
PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id)
end
end