summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/commits_controller_spec.rb22
-rw-r--r--spec/controllers/tree_controller_spec.rb43
-rw-r--r--spec/factories.rb4
-rw-r--r--spec/helpers/application_helper_spec.rb38
-rw-r--r--spec/helpers/tab_helper_spec.rb44
-rw-r--r--spec/lib/extracts_path_spec.rb58
-rw-r--r--spec/lib/ref_extractor_spec.rb58
-rw-r--r--spec/models/project_spec.rb2
-rw-r--r--spec/requests/atom/dashboard_spec.rb7
-rw-r--r--spec/requests/gitlab_flavored_markdown_spec.rb14
-rw-r--r--spec/requests/security/project_access_spec.rb180
-rw-r--r--spec/roles/repository_spec.rb12
-rw-r--r--spec/routing/project_routing_spec.rb79
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/stubbed_repository.rb4
15 files changed, 432 insertions, 134 deletions
diff --git a/spec/controllers/commits_controller_spec.rb b/spec/controllers/commits_controller_spec.rb
new file mode 100644
index 00000000000..bf335634da9
--- /dev/null
+++ b/spec/controllers/commits_controller_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe CommitsController do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ before do
+ sign_in(user)
+
+ project.add_access(user, :read, :admin)
+ end
+
+ describe "GET show" do
+ context "as atom feed" do
+ it "should render as atom" do
+ get :show, project_id: project.code, id: "master.atom"
+ response.should be_success
+ response.content_type.should == 'application/atom+xml'
+ end
+ end
+ end
+end
diff --git a/spec/controllers/tree_controller_spec.rb b/spec/controllers/tree_controller_spec.rb
new file mode 100644
index 00000000000..b9295537d01
--- /dev/null
+++ b/spec/controllers/tree_controller_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe TreeController do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ before do
+ sign_in(user)
+
+ project.add_access(user, :read, :admin)
+
+ project.stub(:branches).and_return(['master', 'foo/bar/baz'])
+ project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
+ controller.instance_variable_set(:@project, project)
+ end
+
+ describe "GET show" do
+ # Make sure any errors accessing the tree in our views bubble up to this spec
+ render_views
+
+ before { get :show, project_id: project.code, id: id }
+
+ context "valid branch, no path" do
+ let(:id) { 'master' }
+ it { should respond_with(:success) }
+ end
+
+ context "valid branch, valid path" do
+ let(:id) { 'master/README.md' }
+ it { should respond_with(:success) }
+ end
+
+ context "valid branch, invalid path" do
+ let(:id) { 'master/invalid-path.rb' }
+ it { should respond_with(:not_found) }
+ end
+
+ context "invalid branch, valid path" do
+ let(:id) { 'invalid-branch/README.md' }
+ it { should respond_with(:not_found) }
+ end
+ end
+end
diff --git a/spec/factories.rb b/spec/factories.rb
index 92790a3fdb7..e11e6d07398 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -42,8 +42,8 @@ FactoryGirl.define do
factory :project do
sequence(:name) { |n| "project#{n}" }
- path { name }
- code { name }
+ path { name.downcase.gsub(/\s/, '_') }
+ code { name.downcase.gsub(/\s/, '_') }
owner
end
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 9a2df31479c..a94d5505a91 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -1,6 +1,44 @@
require 'spec_helper'
describe ApplicationHelper do
+ describe 'current_controller?' do
+ before do
+ controller.stub!(:controller_name).and_return('foo')
+ end
+
+ it "returns true when controller matches argument" do
+ current_controller?(:foo).should be_true
+ end
+
+ it "returns false when controller does not match argument" do
+ current_controller?(:bar).should_not be_true
+ end
+
+ it "should take any number of arguments" do
+ current_controller?(:baz, :bar).should_not be_true
+ current_controller?(:baz, :bar, :foo).should be_true
+ end
+ end
+
+ describe 'current_action?' do
+ before do
+ stub!(:action_name).and_return('foo')
+ end
+
+ it "returns true when action matches argument" do
+ current_action?(:foo).should be_true
+ end
+
+ it "returns false when action does not match argument" do
+ current_action?(:bar).should_not be_true
+ end
+
+ it "should take any number of arguments" do
+ current_action?(:baz, :bar).should_not be_true
+ current_action?(:baz, :bar, :foo).should be_true
+ end
+ end
+
describe "gravatar_icon" do
let(:user_email) { 'user@email.com' }
diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb
new file mode 100644
index 00000000000..ef8e4cf6375
--- /dev/null
+++ b/spec/helpers/tab_helper_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe TabHelper do
+ include ApplicationHelper
+
+ describe 'nav_link' do
+ before do
+ controller.stub!(:controller_name).and_return('foo')
+ stub!(:action_name).and_return('foo')
+ end
+
+ it "captures block output" do
+ nav_link { "Testing Blocks" }.should match(/Testing Blocks/)
+ end
+
+ it "performs checks on the current controller" do
+ nav_link(controller: :foo).should match(/<li class="active">/)
+ nav_link(controller: :bar).should_not match(/active/)
+ nav_link(controller: [:foo, :bar]).should match(/active/)
+ end
+
+ it "performs checks on the current action" do
+ nav_link(action: :foo).should match(/<li class="active">/)
+ nav_link(action: :bar).should_not match(/active/)
+ nav_link(action: [:foo, :bar]).should match(/active/)
+ end
+
+ it "performs checks on both controller and action when both are present" do
+ nav_link(controller: :bar, action: :foo).should_not match(/active/)
+ nav_link(controller: :foo, action: :bar).should_not match(/active/)
+ nav_link(controller: :foo, action: :foo).should match(/active/)
+ end
+
+ it "accepts a path shorthand" do
+ nav_link(path: 'foo#bar').should_not match(/active/)
+ nav_link(path: 'foo#foo').should match(/active/)
+ end
+
+ it "passes extra html options to the list element" do
+ nav_link(action: :foo, html_options: {class: 'home'}).should match(/<li class="home active">/)
+ nav_link(html_options: {class: 'active'}).should match(/<li class="active">/)
+ end
+ end
+end
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
new file mode 100644
index 00000000000..8876373dffa
--- /dev/null
+++ b/spec/lib/extracts_path_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe ExtractsPath do
+ include ExtractsPath
+
+ let(:project) { double('project') }
+
+ before do
+ @project = project
+ project.stub(:branches).and_return(['master', 'foo/bar/baz'])
+ project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
+ end
+
+ describe '#extract_ref' do
+ it "returns an empty pair when no @project is set" do
+ @project = nil
+ extract_ref('master/CHANGELOG').should == ['', '']
+ end
+
+ context "without a path" do
+ it "extracts a valid branch" do
+ extract_ref('master').should == ['master', '']
+ end
+
+ it "extracts a valid tag" do
+ extract_ref('v2.0.0').should == ['v2.0.0', '']
+ end
+
+ it "extracts a valid commit ref without a path" do
+ extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062').should ==
+ ['f4b14494ef6abf3d144c28e4af0c20143383e062', '']
+ end
+
+ it "falls back to a primitive split for an invalid ref" do
+ extract_ref('stable').should == ['stable', '']
+ end
+ end
+
+ context "with a path" do
+ it "extracts a valid branch" do
+ extract_ref('foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
+ end
+
+ it "extracts a valid tag" do
+ extract_ref('v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
+ end
+
+ it "extracts a valid commit SHA" do
+ extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
+ ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
+ end
+
+ it "falls back to a primitive split for an invalid ref" do
+ extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
+ end
+ end
+ end
+end
diff --git a/spec/lib/ref_extractor_spec.rb b/spec/lib/ref_extractor_spec.rb
new file mode 100644
index 00000000000..8876373dffa
--- /dev/null
+++ b/spec/lib/ref_extractor_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe ExtractsPath do
+ include ExtractsPath
+
+ let(:project) { double('project') }
+
+ before do
+ @project = project
+ project.stub(:branches).and_return(['master', 'foo/bar/baz'])
+ project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
+ end
+
+ describe '#extract_ref' do
+ it "returns an empty pair when no @project is set" do
+ @project = nil
+ extract_ref('master/CHANGELOG').should == ['', '']
+ end
+
+ context "without a path" do
+ it "extracts a valid branch" do
+ extract_ref('master').should == ['master', '']
+ end
+
+ it "extracts a valid tag" do
+ extract_ref('v2.0.0').should == ['v2.0.0', '']
+ end
+
+ it "extracts a valid commit ref without a path" do
+ extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062').should ==
+ ['f4b14494ef6abf3d144c28e4af0c20143383e062', '']
+ end
+
+ it "falls back to a primitive split for an invalid ref" do
+ extract_ref('stable').should == ['stable', '']
+ end
+ end
+
+ context "with a path" do
+ it "extracts a valid branch" do
+ extract_ref('foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
+ end
+
+ it "extracts a valid tag" do
+ extract_ref('v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
+ end
+
+ it "extracts a valid commit SHA" do
+ extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
+ ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
+ end
+
+ it "falls back to a primitive split for an invalid ref" do
+ extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
+ end
+ end
+ end
+end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index c313b58ecd6..bb975a93dfd 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -125,7 +125,7 @@ describe Project do
it "should return path to repo" do
project = Project.new(path: "somewhere")
- project.path_to_repo.should == File.join(Rails.root, "tmp", "repositories", "somewhere")
+ project.path_to_repo.should == Rails.root.join("tmp", "repositories", "somewhere")
end
it "returns the full web URL for this repo" do
diff --git a/spec/requests/atom/dashboard_spec.rb b/spec/requests/atom/dashboard_spec.rb
index 9459dd01e22..c160d24ac20 100644
--- a/spec/requests/atom/dashboard_spec.rb
+++ b/spec/requests/atom/dashboard_spec.rb
@@ -10,12 +10,5 @@ describe "Dashboard Feed" do
page.body.should have_selector("feed title")
end
end
-
- context "projects page via private token" do
- it "should redirect to login page" do
- visit dashboard_path(private_token: user.private_token)
- current_path.should == new_user_session_path
- end
- end
end
end
diff --git a/spec/requests/gitlab_flavored_markdown_spec.rb b/spec/requests/gitlab_flavored_markdown_spec.rb
index 68d354b7bc7..106f6451485 100644
--- a/spec/requests/gitlab_flavored_markdown_spec.rb
+++ b/spec/requests/gitlab_flavored_markdown_spec.rb
@@ -40,28 +40,27 @@ describe "Gitlab Flavored Markdown" do
project.add_access(@user, :read, :write)
end
-
describe "for commits" do
it "should render title in commits#index" do
- visit project_commits_path(project, ref: @branch_name)
+ visit project_commits_path(project, @branch_name, limit: 1)
page.should have_link("##{issue.id}")
end
it "should render title in commits#show" do
- visit project_commit_path(project, id: commit.id)
+ visit project_commit_path(project, commit)
page.should have_link("##{issue.id}")
end
it "should render description in commits#show" do
- visit project_commit_path(project, id: commit.id)
+ visit project_commit_path(project, commit)
page.should have_link("@#{fred.name}")
end
it "should render title in refs#tree", js: true do
- visit tree_project_ref_path(project, id: @branch_name)
+ visit project_tree_path(project, @branch_name)
within(".tree_commit") do
page.should have_link("##{issue.id}")
@@ -69,7 +68,7 @@ describe "Gitlab Flavored Markdown" do
end
it "should render title in refs#blame" do
- visit blame_file_project_ref_path(project, id: @branch_name, path: @test_file)
+ visit project_blame_path(project, File.join(@branch_name, @test_file))
within(".blame_commit") do
page.should have_link("##{issue.id}")
@@ -89,7 +88,6 @@ describe "Gitlab Flavored Markdown" do
end
end
-
describe "for issues" do
before do
@other_issue = Factory :issue,
@@ -175,7 +173,7 @@ describe "Gitlab Flavored Markdown" do
describe "for notes" do
it "should render in commits#show", js: true do
- visit project_commit_path(project, id: commit.id)
+ visit project_commit_path(project, commit)
fill_in "note_note", with: "see ##{issue.id}"
click_button "Add Comment"
diff --git a/spec/requests/security/project_access_spec.rb b/spec/requests/security/project_access_spec.rb
index af0d5fcd3fe..060a276b740 100644
--- a/spec/requests/security/project_access_spec.rb
+++ b/spec/requests/security/project_access_spec.rb
@@ -14,204 +14,228 @@ describe "Application access" do
end
describe "Project" do
+ let(:project) { create(:project) }
+
+ let(:master) { create(:user) }
+ let(:guest) { create(:user) }
+ let(:reporter) { create(:user) }
+
before do
- @project = Factory :project
- @u1 = Factory :user
- @u2 = Factory :user
- @u3 = Factory :user
# full access
- @project.users_projects.create(user: @u1, project_access: UsersProject::MASTER)
+ project.users_projects.create(user: master, project_access: UsersProject::MASTER)
+
# readonly
- @project.users_projects.create(user: @u3, project_access: UsersProject::REPORTER)
+ project.users_projects.create(user: reporter, project_access: UsersProject::REPORTER)
end
describe "GET /project_code" do
- subject { project_path(@project) }
+ subject { project_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
- describe "GET /project_code/master/tree" do
- subject { tree_project_ref_path(@project, @project.root_ref) }
+ describe "GET /project_code/tree/master" do
+ subject { project_tree_path(project, project.root_ref) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
- describe "GET /project_code/commits" do
- subject { project_commits_path(@project) }
+ describe "GET /project_code/commits/master" do
+ subject { project_commits_path(project, project.root_ref, limit: 1) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
- describe "GET /project_code/commit" do
- subject { project_commit_path(@project, @project.commit.id) }
+ describe "GET /project_code/commit/:sha" do
+ subject { project_commit_path(project, project.commit) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
+ it { should be_denied_for :user }
+ it { should be_denied_for :visitor }
+ end
+
+ describe "GET /project_code/compare" do
+ subject { project_compare_index_path(project) }
+
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
+ it { should be_denied_for :admin }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/team" do
- subject { project_team_index_path(@project) }
+ subject { project_team_index_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/wall" do
- subject { wall_project_path(@project) }
+ subject { wall_project_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/blob" do
before do
- commit = @project.commit
+ commit = project.commit
path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob)}.first.name
- @blob_path = blob_project_ref_path(@project, commit.id, path: path)
+ @blob_path = project_blob_path(project, File.join(commit.id, path))
end
- it { @blob_path.should be_allowed_for @u1 }
- it { @blob_path.should be_allowed_for @u3 }
+ it { @blob_path.should be_allowed_for master }
+ it { @blob_path.should be_allowed_for reporter }
it { @blob_path.should be_denied_for :admin }
- it { @blob_path.should be_denied_for @u2 }
+ it { @blob_path.should be_denied_for guest }
it { @blob_path.should be_denied_for :user }
it { @blob_path.should be_denied_for :visitor }
end
describe "GET /project_code/edit" do
- subject { edit_project_path(@project) }
+ subject { edit_project_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_denied_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_denied_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/deploy_keys" do
- subject { project_deploy_keys_path(@project) }
+ subject { project_deploy_keys_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_denied_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_denied_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/issues" do
- subject { project_issues_path(@project) }
+ subject { project_issues_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/snippets" do
- subject { project_snippets_path(@project) }
+ subject { project_snippets_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/merge_requests" do
- subject { project_merge_requests_path(@project) }
+ subject { project_merge_requests_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/repository" do
- subject { project_repository_path(@project) }
+ subject { project_repository_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/repository/branches" do
- subject { branches_project_repository_path(@project) }
+ subject { branches_project_repository_path(project) }
+
+ before do
+ # Speed increase
+ Project.any_instance.stub(:branches).and_return([])
+ end
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/repository/tags" do
- subject { tags_project_repository_path(@project) }
+ subject { tags_project_repository_path(project) }
+
+ before do
+ # Speed increase
+ Project.any_instance.stub(:tags).and_return([])
+ end
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/hooks" do
- subject { project_hooks_path(@project) }
+ subject { project_hooks_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
describe "GET /project_code/files" do
- subject { files_project_path(@project) }
+ subject { files_project_path(project) }
- it { should be_allowed_for @u1 }
- it { should be_allowed_for @u3 }
+ it { should be_allowed_for master }
+ it { should be_allowed_for reporter }
it { should be_denied_for :admin }
- it { should be_denied_for @u2 }
+ it { should be_denied_for guest }
it { should be_denied_for :user }
it { should be_denied_for :visitor }
end
diff --git a/spec/roles/repository_spec.rb b/spec/roles/repository_spec.rb
index 0fda57a3e27..3507585aa8d 100644
--- a/spec/roles/repository_spec.rb
+++ b/spec/roles/repository_spec.rb
@@ -21,27 +21,27 @@ describe Project, "Repository" do
end
describe "#discover_default_branch" do
- let(:master) { double(name: 'master') }
- let(:stable) { double(name: 'stable') }
+ let(:master) { 'master' }
+ let(:stable) { 'stable' }
it "returns 'master' when master exists" do
- project.should_receive(:heads).and_return([stable, master])
+ 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(:heads).and_return([stable, master])
+ 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(:heads).and_return([stable])
+ 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(:heads).and_return([])
+ project.should_receive(:branch_names).at_least(:once).and_return([])
project.discover_default_branch.should be_nil
end
end
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
index b3f9db01ab3..dc687d2a7ac 100644
--- a/spec/routing/project_routing_spec.rb
+++ b/spec/routing/project_routing_spec.rb
@@ -192,34 +192,17 @@ describe ProtectedBranchesController, "routing" do
end
# switch_project_refs GET /:project_id/switch(.:format) refs#switch
-# tree_project_ref GET /:project_id/:id/tree(.:format) refs#tree
# logs_tree_project_ref GET /:project_id/:id/logs_tree(.:format) refs#logs_tree
-# blob_project_ref GET /:project_id/:id/blob(.:format) refs#blob
-# tree_file_project_ref GET /:project_id/:id/tree/:path(.:format) refs#tree
# logs_file_project_ref GET /:project_id/:id/logs_tree/:path(.:format) refs#logs_tree
-# blame_file_project_ref GET /:project_id/:id/blame/:path(.:format) refs#blame
describe RefsController, "routing" do
it "to #switch" do
get("/gitlabhq/switch").should route_to('refs#switch', project_id: 'gitlabhq')
end
- it "to #tree" do
- get("/gitlabhq/stable/tree").should route_to('refs#tree', project_id: 'gitlabhq', id: 'stable')
- get("/gitlabhq/stable/tree/foo/bar/baz").should route_to('refs#tree', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
- 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')
end
-
- it "to #blob" do
- get("/gitlabhq/stable/blob").should route_to('refs#blob', project_id: 'gitlabhq', id: 'stable')
- end
-
- it "to #blame" do
- get("/gitlabhq/stable/blame/foo/bar/baz").should route_to('refs#blame', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
- end
end
# diffs_project_merge_request GET /:project_id/merge_requests/:id/diffs(.:format) merge_requests#diffs
@@ -298,25 +281,22 @@ describe HooksController, "routing" do
end
end
-# compare_project_commits GET /:project_id/commits/compare(.:format) commits#compare
+# project_commit GET /:project_id/commit/:id(.:format) commit#show {:id=>/[[:alnum:]]{6,40}/, :project_id=>/[^\/]+/}
+describe CommitController, "routing" do
+ it "to #show" do
+ get("/gitlabhq/commit/4246fb").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fb')
+ get("/gitlabhq/commit/4246fb.patch").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fb', format: 'patch')
+ get("/gitlabhq/commit/4246fbd13872934f72a8fd0d6fb1317b47b59cb5").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fbd13872934f72a8fd0d6fb1317b47b59cb5')
+ end
+end
+
# patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch
# project_commits GET /:project_id/commits(.:format) commits#index
# POST /:project_id/commits(.:format) commits#create
-# new_project_commit GET /:project_id/commits/new(.:format) commits#new
-# edit_project_commit GET /:project_id/commits/:id/edit(.:format) commits#edit
# project_commit GET /:project_id/commits/:id(.:format) commits#show
-# PUT /:project_id/commits/:id(.:format) commits#update
-# DELETE /:project_id/commits/:id(.:format) commits#destroy
describe CommitsController, "routing" do
- it "to #compare" do
- get("/gitlabhq/commits/compare").should route_to('commits#compare', project_id: 'gitlabhq')
- end
-
- it "to #patch" do
- get("/gitlabhq/commits/1/patch").should route_to('commits#patch', project_id: 'gitlabhq', id: '1')
- end
-
it_behaves_like "RESTful project resources" do
+ let(:actions) { [:show] }
let(:controller) { 'commits' }
end
end
@@ -396,3 +376,42 @@ describe NotesController, "routing" do
let(:controller) { 'notes' }
end
end
+
+# project_blame GET /:project_id/blame/:id(.:format) blame#show {:id=>/.+/, :project_id=>/[^\/]+/}
+describe BlameController, "routing" do
+ it "to #show" do
+ get("/gitlabhq/blame/master/app/models/project.rb").should route_to('blame#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
+ end
+end
+
+# project_blob GET /:project_id/blob/:id(.:format) blob#show {:id=>/.+/, :project_id=>/[^\/]+/}
+describe BlobController, "routing" do
+ it "to #show" do
+ get("/gitlabhq/blob/master/app/models/project.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
+ end
+end
+
+# project_tree GET /:project_id/tree/:id(.:format) tree#show {:id=>/.+/, :project_id=>/[^\/]+/}
+describe TreeController, "routing" do
+ it "to #show" do
+ get("/gitlabhq/tree/master/app/models/project.rb").should route_to('tree#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
+ end
+end
+
+# project_compare_index GET /:project_id/compare(.:format) compare#index {:id=>/[^\/]+/, :project_id=>/[^\/]+/}
+# POST /:project_id/compare(.:format) compare#create {:id=>/[^\/]+/, :project_id=>/[^\/]+/}
+# project_compare /:project_id/compare/:from...:to(.:format) compare#show {:from=>/.+/, :to=>/.+/, :id=>/[^\/]+/, :project_id=>/[^\/]+/}
+describe CompareController, "routing" do
+ it "to #index" do
+ get("/gitlabhq/compare").should route_to('compare#index', project_id: 'gitlabhq')
+ end
+
+ it "to #compare" do
+ post("/gitlabhq/compare").should route_to('compare#create', project_id: 'gitlabhq')
+ end
+
+ it "to #show" do
+ get("/gitlabhq/compare/master...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'master', to: 'stable')
+ get("/gitlabhq/compare/issue/1234...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable')
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index d381b3f1e2e..4700c3fe9af 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -28,6 +28,7 @@ RSpec.configure do |config|
config.include LoginHelpers, type: :request
config.include GitoliteStub
config.include FactoryGirl::Syntax::Methods
+ config.include Devise::TestHelpers, type: :controller
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb
index 90491e430b4..5bf3ea46099 100644
--- a/spec/support/stubbed_repository.rb
+++ b/spec/support/stubbed_repository.rb
@@ -5,11 +5,11 @@ module StubbedRepository
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.
- File.join(Rails.root, 'tmp', 'repositories', path)
+ Rails.root.join('tmp', 'repositories', path)
else
# For everything else, just give it the path to one of our real seeded
# repos.
- File.join(Rails.root, 'tmp', 'repositories', 'gitlabhq')
+ Rails.root.join('tmp', 'repositories', 'gitlabhq')
end
end