gitlab-org--gitlab-foss/spec/models/project_spec.rb

244 lines
8.7 KiB
Ruby
Raw Normal View History

2012-10-02 15:17:12 +00:00
# == Schema Information
#
# Table name: projects
#
2012-11-19 18:24:05 +00:00
# id :integer not null, primary key
2012-10-02 15:17:12 +00:00
# name :string(255)
# path :string(255)
# description :text
# created_at :datetime
# updated_at :datetime
2013-01-03 19:09:18 +00:00
# creator_id :integer
2012-11-19 18:24:05 +00:00
# issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null
# merge_requests_enabled :boolean default(TRUE), not null
# wiki_enabled :boolean default(TRUE), not null
2012-11-24 20:16:51 +00:00
# namespace_id :integer
2013-03-15 13:16:02 +00:00
# issues_tracker :string(255) default("gitlab"), not null
# issues_tracker_id :string(255)
2013-03-27 16:26:37 +00:00
# snippets_enabled :boolean default(TRUE), not null
# last_activity_at :datetime
2013-08-21 09:34:02 +00:00
# import_url :string(255)
# visibility_level :integer default(0), not null
# archived :boolean default(FALSE), not null
# import_status :string(255)
2012-10-02 15:17:12 +00:00
#
2011-10-08 21:36:38 +00:00
require 'spec_helper'
describe Project do
describe "Associations" do
2012-10-02 15:17:12 +00:00
it { should belong_to(:group) }
it { should belong_to(:namespace) }
it { should belong_to(:creator).class_name('User') }
2011-10-08 21:36:38 +00:00
it { should have_many(:users) }
it { should have_many(:events).dependent(:destroy) }
it { should have_many(:merge_requests).dependent(:destroy) }
it { should have_many(:issues).dependent(:destroy) }
it { should have_many(:milestones).dependent(:destroy) }
it { should have_many(:users_projects).dependent(:destroy) }
it { should have_many(:notes).dependent(:destroy) }
2013-03-25 12:35:57 +00:00
it { should have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) }
it { should have_many(:deploy_keys_projects).dependent(:destroy) }
it { should have_many(:deploy_keys) }
it { should have_many(:hooks).dependent(:destroy) }
it { should have_many(:protected_branches).dependent(:destroy) }
it { should have_one(:forked_project_link).dependent(:destroy) }
2014-03-18 17:27:03 +00:00
it { should have_one(:slack_service).dependent(:destroy) }
2011-10-08 21:36:38 +00:00
end
describe "Mass assignment" do
end
2011-10-08 21:36:38 +00:00
describe "Validation" do
let!(:project) { create(:project) }
2011-10-08 21:36:38 +00:00
it { should validate_presence_of(:name) }
it { should validate_uniqueness_of(:name).scoped_to(:namespace_id) }
it { should ensure_length_of(:name).is_within(0..255) }
2011-10-08 21:36:38 +00:00
it { should validate_presence_of(:path) }
it { should validate_uniqueness_of(:path).scoped_to(:namespace_id) }
it { should ensure_length_of(:path).is_within(0..255) }
it { should ensure_length_of(:description).is_within(0..2000) }
it { should validate_presence_of(:creator) }
2013-02-11 14:17:43 +00:00
it { should ensure_length_of(:issues_tracker_id).is_within(0..255) }
it { should validate_presence_of(:namespace) }
it "should not allow new projects beyond user limits" do
project2 = build(:project)
project2.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 0).as_null_object)
project2.should_not be_valid
project2.errors[:limit_reached].first.should match(/Your project limit is 0/)
end
2011-10-08 21:36:38 +00:00
end
describe "Respond to" do
it { should respond_to(:url_to_repo) }
it { should respond_to(:repo_exists?) }
2012-07-31 05:32:49 +00:00
it { should respond_to(:satellite) }
it { should respond_to(:update_merge_requests) }
it { should respond_to(:execute_hooks) }
it { should respond_to(:name_with_namespace) }
it { should respond_to(:owner) }
it { should respond_to(:path_with_namespace) }
2011-10-08 21:36:38 +00:00
end
it "should return valid url to repo" do
project = Project.new(path: "somewhere")
2013-02-11 18:28:27 +00:00
project.url_to_repo.should == Gitlab.config.gitlab_shell.ssh_path_prefix + "somewhere.git"
2011-10-08 21:36:38 +00:00
end
it "returns the full web URL for this repo" do
2012-11-23 18:53:24 +00:00
project = Project.new(path: "somewhere")
project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
end
it "returns the web URL without the protocol for this repo" do
project = Project.new(path: "somewhere")
project.web_url_without_protocol.should == "#{Gitlab.config.gitlab.url.split("://")[1]}/somewhere"
end
describe "last_activity methods" do
Merge Request on forked projects The good: - You can do a merge request for a forked commit and it will merge properly (i.e. it does work). - Push events take into account merge requests on forked projects - Tests around merge_actions now present, spinach, and other rspec tests - Satellites now clean themselves up rather then recreate The questionable: - Events only know about target projects - Project's merge requests only hold on to MR's where they are the target - All operations performed in the satellite The bad: - Duplication between project's repositories and satellites (e.g. commits_between) (for reference: http://feedback.gitlab.com/forums/176466-general/suggestions/3456722-merge-requests-between-projects-repos) Fixes: Make test repos/satellites only create when needed -Spinach/Rspec now only initialize test directory, and setup stubs (things that are relatively cheap) -project_with_code, source_project_with_code, and target_project_with_code now create/destroy their repos individually -fixed remote removal -How to merge renders properly -Update emails to show project/branches -Edit MR doesn't set target branch -Fix some failures on editing/creating merge requests, added a test -Added back a test around merge request observer -Clean up project_transfer_spec, Remove duplicate enable/disable observers -Ensure satellite lock files are cleaned up, Attempted to add some testing around these as well -Signifant speed ups for tests -Update formatting ordering in notes_on_merge_requests -Remove wiki schema update Fixes for search/search results -Search results was using by_project for a list of projects, updated this to use in_projects -updated search results to reference the correct (target) project -udpated search results to print both sides of the merge request Change-Id: I19407990a0950945cc95d62089cbcc6262dab1a8
2013-04-25 14:15:33 +00:00
let(:project) { create(:project) }
let(:last_event) { double(created_at: Time.now) }
2011-11-02 20:14:03 +00:00
describe "last_activity" do
Merge Request on forked projects The good: - You can do a merge request for a forked commit and it will merge properly (i.e. it does work). - Push events take into account merge requests on forked projects - Tests around merge_actions now present, spinach, and other rspec tests - Satellites now clean themselves up rather then recreate The questionable: - Events only know about target projects - Project's merge requests only hold on to MR's where they are the target - All operations performed in the satellite The bad: - Duplication between project's repositories and satellites (e.g. commits_between) (for reference: http://feedback.gitlab.com/forums/176466-general/suggestions/3456722-merge-requests-between-projects-repos) Fixes: Make test repos/satellites only create when needed -Spinach/Rspec now only initialize test directory, and setup stubs (things that are relatively cheap) -project_with_code, source_project_with_code, and target_project_with_code now create/destroy their repos individually -fixed remote removal -How to merge renders properly -Update emails to show project/branches -Edit MR doesn't set target branch -Fix some failures on editing/creating merge requests, added a test -Added back a test around merge request observer -Clean up project_transfer_spec, Remove duplicate enable/disable observers -Ensure satellite lock files are cleaned up, Attempted to add some testing around these as well -Signifant speed ups for tests -Update formatting ordering in notes_on_merge_requests -Remove wiki schema update Fixes for search/search results -Search results was using by_project for a list of projects, updated this to use in_projects -updated search results to reference the correct (target) project -udpated search results to print both sides of the merge request Change-Id: I19407990a0950945cc95d62089cbcc6262dab1a8
2013-04-25 14:15:33 +00:00
it "should alias last_activity to last_event" do
project.stub(last_event: last_event)
project.last_activity.should == last_event
end
2011-11-02 20:14:03 +00:00
end
describe 'last_activity_date' do
it 'returns the creation date of the project\'s last event if present' do
2013-04-03 03:06:18 +00:00
last_activity_event = create(:event, project: project)
2013-04-10 15:26:25 +00:00
project.last_activity_at.to_i.should == last_event.created_at.to_i
end
it 'returns the project\'s last update date if it has no events' do
project.last_activity_date.should == project.updated_at
end
end
end
2012-09-05 10:14:24 +00:00
describe :update_merge_requests do
let(:project) { create(:project) }
before do
Merge Request on forked projects The good: - You can do a merge request for a forked commit and it will merge properly (i.e. it does work). - Push events take into account merge requests on forked projects - Tests around merge_actions now present, spinach, and other rspec tests - Satellites now clean themselves up rather then recreate The questionable: - Events only know about target projects - Project's merge requests only hold on to MR's where they are the target - All operations performed in the satellite The bad: - Duplication between project's repositories and satellites (e.g. commits_between) (for reference: http://feedback.gitlab.com/forums/176466-general/suggestions/3456722-merge-requests-between-projects-repos) Fixes: Make test repos/satellites only create when needed -Spinach/Rspec now only initialize test directory, and setup stubs (things that are relatively cheap) -project_with_code, source_project_with_code, and target_project_with_code now create/destroy their repos individually -fixed remote removal -How to merge renders properly -Update emails to show project/branches -Edit MR doesn't set target branch -Fix some failures on editing/creating merge requests, added a test -Added back a test around merge request observer -Clean up project_transfer_spec, Remove duplicate enable/disable observers -Ensure satellite lock files are cleaned up, Attempted to add some testing around these as well -Signifant speed ups for tests -Update formatting ordering in notes_on_merge_requests -Remove wiki schema update Fixes for search/search results -Search results was using by_project for a list of projects, updated this to use in_projects -updated search results to reference the correct (target) project -udpated search results to print both sides of the merge request Change-Id: I19407990a0950945cc95d62089cbcc6262dab1a8
2013-04-25 14:15:33 +00:00
@merge_request = create(:merge_request, source_project: project, target_project: project)
@key = create(:key, user_id: project.owner.id)
end
it "should close merge request if last commit from source branch was pushed to target branch" do
@merge_request.reload_code
@merge_request.last_commit.id.should == "69b34b7e9ad9f496f0ad10250be37d6265a03bba"
project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "69b34b7e9ad9f496f0ad10250be37d6265a03bba", "refs/heads/stable", @key.user)
@merge_request.reload
2013-02-18 08:40:56 +00:00
@merge_request.merged?.should be_true
end
2012-09-05 10:14:24 +00:00
it "should update merge request commits with new one if pushed to source branch" do
project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "69b34b7e9ad9f496f0ad10250be37d6265a03bba", "refs/heads/master", @key.user)
@merge_request.reload
@merge_request.last_commit.id.should == "69b34b7e9ad9f496f0ad10250be37d6265a03bba"
end
end
describe :find_with_namespace do
context 'with namespace' do
before do
@group = create :group, name: 'gitlab'
@project = create(:project, name: 'gitlabhq', namespace: @group)
end
it { Project.find_with_namespace('gitlab/gitlabhq').should == @project }
it { Project.find_with_namespace('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: 'gitlabhq', namespace: @group)
end
it { @project.to_param.should == "gitlab/gitlabhq" }
end
end
2013-01-04 16:50:31 +00:00
2013-01-04 22:43:32 +00:00
describe :repository do
2013-01-04 16:50:31 +00:00
let(:project) { create(:project) }
it "should return valid repo" do
project.repository.should be_kind_of(Repository)
2013-01-04 16:50:31 +00:00
end
end
describe :issue_exists? do
let(:project) { create(:project) }
let(:existed_issue) { create(:issue, project: project) }
let(:not_existed_issue) { create(:issue) }
let(:ext_project) { create(:redmine_project) }
it "should be true or if used internal tracker and issue exists" do
2013-08-20 18:41:14 +00:00
project.issue_exists?(existed_issue.iid).should be_true
end
it "should be false or if used internal tracker and issue not exists" do
2013-08-20 18:41:14 +00:00
project.issue_exists?(not_existed_issue.iid).should be_false
end
it "should always be true if used other tracker" do
ext_project.issue_exists?(rand(100)).should be_true
end
end
describe :used_default_issues_tracker? do
let(:project) { create(:project) }
let(:ext_project) { create(:redmine_project) }
it "should be true if used internal tracker" do
project.used_default_issues_tracker?.should be_true
end
it "should be false if used other tracker" do
ext_project.used_default_issues_tracker?.should be_false
end
end
2013-02-11 14:17:43 +00:00
describe :can_have_issues_tracker_id? do
let(:project) { create(:project) }
let(:ext_project) { create(:redmine_project) }
it "should be true for projects with external issues tracker if issues enabled" do
ext_project.can_have_issues_tracker_id?.should be_true
end
2013-02-11 14:17:43 +00:00
it "should be false for projects with internal issue tracker if issues enabled" do
project.can_have_issues_tracker_id?.should be_false
end
2013-07-29 10:46:00 +00:00
it "should be always false if issues disabled" do
2013-02-11 14:17:43 +00:00
project.issues_enabled = false
ext_project.issues_enabled = false
project.can_have_issues_tracker_id?.should be_false
ext_project.can_have_issues_tracker_id?.should be_false
end
end
describe :open_branches do
let(:project) { create(:project) }
before do
project.protected_branches.create(name: 'master')
end
it { project.open_branches.map(&:name).should include('bootstrap') }
it { project.open_branches.map(&:name).should_not include('master') }
end
2011-10-08 21:36:38 +00:00
end