summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-05 00:49:58 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-05 00:49:58 +0200
commit0a94640e328ab30dcf90e65ba79242bc1aa77a57 (patch)
tree49599acd6e4dbc50de0491ff174588b1fbf0cf8e /spec/models
parente6c0673ef1108a93928c4d88ba273e12616b836b (diff)
parentde6fa5dd520244e9802b5b486ce9d437556baf31 (diff)
downloadgitlab-ce-0a94640e328ab30dcf90e65ba79242bc1aa77a57.tar.gz
Merge branch 'refactoring/backend'
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/commit_spec.rb2
-rw-r--r--spec/models/gitlab_ci_service_spec.rb4
-rw-r--r--spec/models/note_spec.rb5
-rw-r--r--spec/models/project_hooks_spec.rb6
-rw-r--r--spec/models/project_repository_spec.rb159
-rw-r--r--spec/models/project_spec.rb60
-rw-r--r--spec/models/protected_branch_spec.rb2
-rw-r--r--spec/models/repository_spec.rb105
-rw-r--r--spec/models/system_hook_spec.rb4
-rw-r--r--spec/models/team_spec.rb18
-rw-r--r--spec/models/users_project_spec.rb10
11 files changed, 152 insertions, 223 deletions
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index e760c501bd7..91301029e89 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -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) }
diff --git a/spec/models/gitlab_ci_service_spec.rb b/spec/models/gitlab_ci_service_spec.rb
index ec43d46b347..b86588af1ac 100644
--- a/spec/models/gitlab_ci_service_spec.rb
+++ b/spec/models/gitlab_ci_service_spec.rb
@@ -35,10 +35,6 @@ describe GitlabCiService do
)
end
- describe :commit_badge_path do
- it { @service.commit_badge_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/status?sha=2ab7834c"}
- 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
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 61aaf6455eb..8e06e6748da 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -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'
@@ -76,7 +77,7 @@ describe Note do
end
let(:project) { create(:project) }
- let(:commit) { project.commit }
+ let(:commit) { project.repository.commit }
describe "Commit notes" do
before do
diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb
index 77adfe06cff..60457e20c51 100644
--- a/spec/models/project_hooks_spec.rb
+++ b/spec/models/project_hooks_spec.rb
@@ -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"
diff --git a/spec/models/project_repository_spec.rb b/spec/models/project_repository_spec.rb
deleted file mode 100644
index e1d01cbfeaf..00000000000
--- a/spec/models/project_repository_spec.rb
+++ /dev/null
@@ -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
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ea1efbbec78..223b9d48c01 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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
@@ -75,57 +75,16 @@ 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) }
@@ -138,11 +97,6 @@ describe Project do
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"
@@ -269,4 +223,16 @@ describe Project do
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
diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb
index 7340ce50ced..0835666a101 100644
--- a/spec/models/protected_branch_spec.rb
+++ b/spec/models/protected_branch_spec.rb
@@ -44,7 +44,7 @@ describe ProtectedBranch do
let(:branch) { create(:protected_branch) }
it 'commits itself to its project' do
- branch.project.should_receive(:commit).with(branch.name)
+ branch.project.repository.should_receive(:commit).with(branch.name)
branch.commit
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
new file mode 100644
index 00000000000..71f9b964e70
--- /dev/null
+++ b/spec/models/repository_spec.rb
@@ -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
diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb
index 7ae483a4003..cc358a2ed3b 100644
--- a/spec/models/system_hook_spec.rb
+++ b/spec/models/system_hook_spec.rb
@@ -56,7 +56,7 @@ describe SystemHook do
user = create(:user)
project = create(:project)
with_resque do
- project.add_access(user, :admin)
+ project.team << [user, :master]
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
@@ -64,7 +64,7 @@ describe SystemHook do
it "project_destroy hook" do
user = create(:user)
project = create(:project)
- project.add_access(user, :admin)
+ project.team << [user, :master]
with_resque do
project.users_projects.clear
end
diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb
new file mode 100644
index 00000000000..65ffe13b490
--- /dev/null
+++ b/spec/models/team_spec.rb
@@ -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
+
diff --git a/spec/models/users_project_spec.rb b/spec/models/users_project_spec.rb
index f85e21ff3f1..e8f5b647ce0 100644
--- a/spec/models/users_project_spec.rb
+++ b/spec/models/users_project_spec.rb
@@ -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 }
@@ -101,8 +101,8 @@ 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]
UsersProject.truncate_teams([@project_1.id, @project_2.id])
end