diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-04 18:50:31 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-04 18:50:31 +0200 |
commit | afbdbb0c959affbdb8725eafb8169025a8aede1e (patch) | |
tree | 87fec66647ef63d1abc5cae17192f1f10c1559bb /spec | |
parent | dccd8b6eaa8b2e98b0245262a8e39df8fb8ae634 (diff) | |
download | gitlab-ce-afbdbb0c959affbdb8725eafb8169025a8aede1e.tar.gz |
Rspec fixes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/commit_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/controllers/commits_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/merge_requests_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/tree_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/gitlab_markdown_helper_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/project_repository_spec.rb | 159 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 38 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 89 | ||||
-rw-r--r-- | spec/requests/api/issues_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/milestones_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/notes_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/atom/issues_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/gitlab_flavored_markdown_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/projects_deploy_keys_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/search_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/snippets_spec.rb | 4 |
18 files changed, 141 insertions, 191 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/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 8016c67ced0..54e7bc32c8f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -84,7 +84,6 @@ describe Project do 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(:reset_access) } @@ -94,14 +93,6 @@ describe Project do 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) } @@ -253,4 +244,33 @@ describe Project do it { @project.to_param.should == "gitlab-ci" } end end + + describe "#empty_repo?" do + let(:project) { create(:project) } + + 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 :repository do + it "should return valid repo" do + project.repository.should be_kind_of(Repository) + end + + it "should return nil" do + Project.new(path: "invalid").repository.should be_nil + end + end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 160fed17ecc..b7a17ccf489 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1,5 +1,10 @@ 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) } @@ -11,4 +16,88 @@ describe Repository do 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.default_branch = '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/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/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/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/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 |