diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-05 00:49:58 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-05 00:49:58 +0200 |
| commit | 0a94640e328ab30dcf90e65ba79242bc1aa77a57 (patch) | |
| tree | 49599acd6e4dbc50de0491ff174588b1fbf0cf8e /spec | |
| parent | e6c0673ef1108a93928c4d88ba273e12616b836b (diff) | |
| parent | de6fa5dd520244e9802b5b486ce9d437556baf31 (diff) | |
| download | gitlab-ce-0a94640e328ab30dcf90e65ba79242bc1aa77a57.tar.gz | |
Merge branch 'refactoring/backend'
Diffstat (limited to 'spec')
31 files changed, 200 insertions, 267 deletions
diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb index 5aef4c676ee..7bf13822829 100644 --- a/spec/controllers/commit_controller_spec.rb +++ b/spec/controllers/commit_controller_spec.rb @@ -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 diff --git a/spec/controllers/commits_controller_spec.rb b/spec/controllers/commits_controller_spec.rb index da33fd8a2b5..1d5d99df802 100644 --- a/spec/controllers/commits_controller_spec.rb +++ b/spec/controllers/commits_controller_spec.rb @@ -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 diff --git a/spec/controllers/merge_requests_controller_spec.rb b/spec/controllers/merge_requests_controller_spec.rb index 7aebe06cf0c..8478bb3adff 100644 --- a/spec/controllers/merge_requests_controller_spec.rb +++ b/spec/controllers/merge_requests_controller_spec.rb @@ -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 diff --git a/spec/controllers/tree_controller_spec.rb b/spec/controllers/tree_controller_spec.rb index b9295537d01..81c7656d07a 100644 --- a/spec/controllers/tree_controller_spec.rb +++ b/spec/controllers/tree_controller_spec.rb @@ -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']) diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index b792e0c86f6..497a5f17846 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -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}" diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index 8773d77f5a5..deb6499e008 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -7,7 +7,7 @@ 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 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 diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 8f4e51f5a44..781ebab026b 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::API do let(:user) { create(: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 diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index f7b067070e0..5da54154a81 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::API do let(:user) { create(: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 diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index f7df90d0fdd..80696671462 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -7,7 +7,7 @@ describe Gitlab::API do 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 diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index e783ccf73a5..ae4fc111f63 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::API do 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 diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index e829c95e967..c2244210bcf 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -11,7 +11,7 @@ describe Gitlab::API do 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 @@ -226,14 +226,14 @@ 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.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 diff --git a/spec/requests/atom/issues_spec.rb b/spec/requests/atom/issues_spec.rb index eeb355377c4..0488c1f2266 100644 --- a/spec/requests/atom/issues_spec.rb +++ b/spec/requests/atom/issues_spec.rb @@ -6,7 +6,7 @@ describe "Issues Feed" do 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 diff --git a/spec/requests/gitlab_flavored_markdown_spec.rb b/spec/requests/gitlab_flavored_markdown_spec.rb index 7f61c6aaa73..78b8c0c513f 100644 --- a/spec/requests/gitlab_flavored_markdown_spec.rb +++ b/spec/requests/gitlab_flavored_markdown_spec.rb @@ -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 diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb index 0814108523b..2e94ffd0020 100644 --- a/spec/requests/issues_spec.rb +++ b/spec/requests/issues_spec.rb @@ -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 diff --git a/spec/requests/projects_deploy_keys_spec.rb b/spec/requests/projects_deploy_keys_spec.rb index 35323f556f9..25b1da9ebd8 100644 --- a/spec/requests/projects_deploy_keys_spec.rb +++ b/spec/requests/projects_deploy_keys_spec.rb @@ -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 diff --git a/spec/requests/projects_spec.rb b/spec/requests/projects_spec.rb index ea87e35ed94..8f613b458c0 100644 --- a/spec/requests/projects_spec.rb +++ b/spec/requests/projects_spec.rb @@ -6,7 +6,7 @@ describe "Projects" do describe "GET /projects/show" do before do @project = create(:project, namespace: @user.namespace) - @project.add_access(@user, :read) + @project.team << [@user, :reporter] visit project_path(@project) end @@ -19,7 +19,7 @@ describe "Projects" do describe "GET /projects/:id/edit" do before do @project = create(:project) - @project.add_access(@user, :admin, :read) + @project.team << [@user, :master] visit edit_project_path(@project) end @@ -38,7 +38,7 @@ describe "Projects" do describe "PUT /projects/:id" do before do @project = create(:project, namespace: @user.namespace) - @project.add_access(@user, :admin, :read) + @project.team << [@user, :master] visit edit_project_path(@project) @@ -59,7 +59,7 @@ describe "Projects" do describe "DELETE /projects/:id" do before do @project = create(:project, namespace: @user.namespace) - @project.add_access(@user, :read, :admin) + @project.team << [@user, :master] visit edit_project_path(@project) end diff --git a/spec/requests/search_spec.rb b/spec/requests/search_spec.rb index 17cc0d39946..e338f359f88 100644 --- a/spec/requests/search_spec.rb +++ b/spec/requests/search_spec.rb @@ -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" diff --git a/spec/requests/security/project_access_spec.rb b/spec/requests/security/project_access_spec.rb index 060a276b740..a35175102ec 100644 --- a/spec/requests/security/project_access_spec.rb +++ b/spec/requests/security/project_access_spec.rb @@ -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 diff --git a/spec/requests/snippets_spec.rb b/spec/requests/snippets_spec.rb index b231b940a84..770e34dc07c 100644 --- a/spec/requests/snippets_spec.rb +++ b/spec/requests/snippets_spec.rb @@ -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 diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb index ad88dd77a4f..e6e194d70f5 100644 --- a/spec/support/stubbed_repository.rb +++ b/spec/support/stubbed_repository.rb @@ -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. class Project - 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) + 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 @@ -27,3 +26,9 @@ class Project end end end + +class GitLabTestRepo < Repository + def repo + @repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq')) + end +end |
