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.rb10
-rw-r--r--spec/helpers/application_helper_spec.rb38
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb13
-rw-r--r--spec/helpers/tab_helper_spec.rb44
-rw-r--r--spec/helpers/tree_helper_spec.rb2
-rw-r--r--spec/lib/extracts_path_spec.rb58
-rw-r--r--spec/lib/ref_extractor_spec.rb58
-rw-r--r--spec/models/commit_spec.rb37
-rw-r--r--spec/models/event_spec.rb41
-rw-r--r--spec/models/issue_spec.rb5
-rw-r--r--spec/models/key_spec.rb5
-rw-r--r--spec/models/merge_request_spec.rb5
-rw-r--r--spec/models/milestone_spec.rb4
-rw-r--r--spec/models/note_spec.rb5
-rw-r--r--spec/models/project_spec.rb7
-rw-r--r--spec/models/protected_branch_spec.rb4
-rw-r--r--spec/models/snippet_spec.rb5
-rw-r--r--spec/models/user_spec.rb5
-rw-r--r--spec/models/users_project_spec.rb4
-rw-r--r--spec/models/web_hook_spec.rb4
-rw-r--r--spec/models/wiki_spec.rb5
-rw-r--r--spec/observers/users_project_observer_spec.rb43
-rw-r--r--spec/requests/api/projects_spec.rb75
-rw-r--r--spec/requests/api/session_spec.rb39
-rw-r--r--spec/requests/api/users_spec.rb88
-rw-r--r--spec/requests/atom/dashboard_spec.rb7
-rw-r--r--spec/requests/gitlab_flavored_markdown_spec.rb15
-rw-r--r--spec/requests/hooks_spec.rb43
-rw-r--r--spec/requests/security/profile_access_spec.rb4
-rw-r--r--spec/requests/security/project_access_spec.rb180
-rw-r--r--spec/roles/repository_spec.rb12
-rw-r--r--spec/routing/admin_routing_spec.rb166
-rw-r--r--spec/routing/project_routing_spec.rb417
-rw-r--r--spec/routing/routing_spec.rb186
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/gitolite_stub.rb34
-rw-r--r--spec/support/matchers.rb6
-rw-r--r--spec/support/stubbed_repository.rb4
40 files changed, 1495 insertions, 249 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 848fc01ff1d..5bdb3c28f67 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
@@ -78,6 +78,12 @@ FactoryGirl.define do
end
factory :event do
+ factory :closed_issue_event do
+ project
+ action Event::Closed
+ target factory: :closed_issue
+ author factory: :user
+ end
end
factory :key do
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/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index 0af331424f5..ec830e40ecd 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -292,11 +292,18 @@ describe GitlabMarkdownHelper do
actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo')
actual.should have_selector 'a.gfm.gfm-commit.foo'
end
+
+ it "escapes HTML passed in as the body" do
+ actual = "This is a <h1>test</h1> - see ##{issues[0].id}"
+ link_to_gfm(actual, commit_path).should match('&lt;h1&gt;test&lt;/h1&gt;')
+ end
end
describe "#markdown" do
it "should handle references in paragraphs" do
- markdown("\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. #{commit.id} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.\n").should == "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. #{link_to commit.id, project_commit_path(project, commit), title: commit.link_title, class: "gfm gfm-commit "} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.</p>\n"
+ actual = "\n\nLorem ipsum dolor sit amet. #{commit.id} Nam pulvinar sapien eget.\n"
+ expected = project_commit_path(project, commit)
+ markdown(actual).should match(expected)
end
it "should handle references in headers" do
@@ -322,9 +329,9 @@ describe GitlabMarkdownHelper do
end
it "should leave code blocks untouched" do
- markdown("\n some code from $#{snippet.id}\n here too\n").should == "<div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre>\n</div>\n"
+ markdown("\n some code from $#{snippet.id}\n here too\n").should == "<div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre></div>"
- markdown("\n```\nsome code from $#{snippet.id}\nhere too\n```\n").should == "<div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre>\n</div>\n"
+ markdown("\n```\nsome code from $#{snippet.id}\nhere too\n```\n").should == "<div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre></div>"
end
it "should leave inline code untouched" do
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/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
index bb124d8b303..d450b687caf 100644
--- a/spec/helpers/tree_helper_spec.rb
+++ b/spec/helpers/tree_helper_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe TreeHelper do
describe '#markup?' do
- %w(mdown md markdown textile rdoc org creole mediawiki rst asciidoc pod).each do |type|
+ %w(textile rdoc org creole mediawiki rst asciidoc pod).each do |type|
it "returns true for #{type} files" do
markup?("README.#{type}").should be_true
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/commit_spec.rb b/spec/models/commit_spec.rb
new file mode 100644
index 00000000000..e4bc1936839
--- /dev/null
+++ b/spec/models/commit_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe Commit do
+ let(:commit) { create(:project).commit }
+
+ describe CommitDecorator do
+ let(:decorator) { CommitDecorator.new(commit) }
+
+ describe '#title' do
+ it "returns no_commit_message when safe_message is blank" do
+ decorator.stub(:safe_message).and_return('')
+ decorator.title.should == "--no commit message"
+ end
+
+ it "truncates a message without a newline at 70 characters" do
+ message = commit.safe_message * 10
+
+ decorator.stub(:safe_message).and_return(message)
+ decorator.title.should == "#{message[0..69]}&hellip;"
+ end
+
+ it "truncates a message with a newline before 80 characters at the newline" do
+ message = commit.safe_message.split(" ").first
+
+ decorator.stub(:safe_message).and_return(message + "\n" + message)
+ decorator.title.should == message
+ end
+
+ it "truncates a message with a newline after 80 characters at 70 characters" do
+ message = (commit.safe_message * 10) + "\n"
+
+ decorator.stub(:safe_message).and_return(message)
+ decorator.title.should == "#{message[0..69]}&hellip;"
+ end
+ end
+ end
+end
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index ee022e959e7..5cb68761b29 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -14,12 +14,12 @@ describe Event do
it { should respond_to(:commits) }
end
- describe "Push event" do
- before do
+ describe "Push event" do
+ before do
project = Factory :project
@user = project.owner
- data = {
+ data = {
before: "0000000000000000000000000000000000000000",
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
ref: "refs/heads/master",
@@ -50,25 +50,24 @@ describe Event do
it { @event.author.should == @user }
end
- describe "Joined project team" do
- let(:project) {Factory.create :project}
- let(:new_user) {Factory.create :user}
- it "should create event" do
- UsersProject.observers.enable :users_project_observer
- expect{
- UsersProject.bulk_import(project, [new_user.id], UsersProject::DEVELOPER)
- }.to change{Event.count}.by(1)
+ describe 'Team events' do
+ let(:user_project) { stub.as_null_object }
+ let(:observer) { UsersProjectObserver.instance }
+
+ before {
+ Event.should_receive :create
+ }
+
+ describe "Joined project team" do
+ it "should create event" do
+ observer.after_create user_project
+ end
end
- end
- describe "Left project team" do
- let(:project) {Factory.create :project}
- let(:new_user) {Factory.create :user}
- it "should create event" do
- UsersProject.bulk_import(project, [new_user.id], UsersProject::DEVELOPER)
- UsersProject.observers.enable :users_project_observer
- expect{
- UsersProject.bulk_delete(project, [new_user.id])
- }.to change{Event.count}.by(1)
+
+ describe "Left project team" do
+ it "should create event" do
+ observer.after_destroy user_project
+ end
end
end
end
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 34192da94ad..099c41985cb 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -5,6 +5,11 @@ describe Issue do
it { should belong_to(:milestone) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:author_id) }
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe "Validation" do
it { should ensure_length_of(:description).is_within(0..2000) }
it { should ensure_inclusion_of(:closed).in_array([true, false]) }
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index 9bb31a16483..169bd890c3d 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -6,6 +6,11 @@ describe Key do
it { should belong_to(:project) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ it { should_not allow_mass_assignment_of(:user_id) }
+ end
+
describe "Validation" do
it { should validate_presence_of(:title) }
it { should validate_presence_of(:key) }
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 523e823de34..a54849240ae 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -6,6 +6,11 @@ describe MergeRequest do
it { should validate_presence_of(:source_branch) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:author_id) }
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe 'modules' do
it { should include_module(IssueCommonality) }
it { should include_module(Votes) }
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index f0f0f88303f..9c11a7b1043 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -6,6 +6,10 @@ describe Milestone do
it { should have_many(:issues) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe "Validation" do
it { should validate_presence_of(:title) }
it { should validate_presence_of(:project_id) }
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 7809953f5b3..34493a1117d 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -7,6 +7,11 @@ describe Note do
it { should belong_to(:author).class_name('User') }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:author) }
+ it { should_not allow_mass_assignment_of(:author_id) }
+ end
+
describe "Validation" do
it { should validate_presence_of(:note) }
it { should validate_presence_of(:project) }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 756f69ded56..bb975a93dfd 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -17,6 +17,11 @@ describe Project do
it { should have_many(:protected_branches).dependent(:destroy) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:owner_id) }
+ it { should_not allow_mass_assignment_of(:private_flag) }
+ end
+
describe "Validation" do
let!(:project) { create(:project) }
@@ -120,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/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb
index 9180bc3bca6..4b2923624dd 100644
--- a/spec/models/protected_branch_spec.rb
+++ b/spec/models/protected_branch_spec.rb
@@ -5,6 +5,10 @@ describe ProtectedBranch do
it { should belong_to(:project) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe 'Validation' do
it { should validate_presence_of(:project_id) }
it { should validate_presence_of(:name) }
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index ffb861c4910..66c36e51ec7 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -7,6 +7,11 @@ describe Snippet do
it { should have_many(:notes).dependent(:destroy) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:author_id) }
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe "Validation" do
it { should validate_presence_of(:author_id) }
it { should validate_presence_of(:project_id) }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 081767543e2..b77d88783f4 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -15,6 +15,11 @@ describe User do
it { should have_many(:assigned_merge_requests).dependent(:destroy) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:projects_limit) }
+ it { should allow_mass_assignment_of(:projects_limit).as(:admin) }
+ end
+
describe 'validations' do
it { should validate_presence_of(:projects_limit) }
it { should validate_numericality_of(:projects_limit) }
diff --git a/spec/models/users_project_spec.rb b/spec/models/users_project_spec.rb
index 33cb358e7bd..a13a08db17a 100644
--- a/spec/models/users_project_spec.rb
+++ b/spec/models/users_project_spec.rb
@@ -6,6 +6,10 @@ describe UsersProject do
it { should belong_to(:user) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe "Validation" do
let!(:users_project) { create(:users_project) }
diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb
index 3cba5b64ff0..422d67cf016 100644
--- a/spec/models/web_hook_spec.rb
+++ b/spec/models/web_hook_spec.rb
@@ -5,6 +5,10 @@ describe ProjectHook do
it { should belong_to :project }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+
describe "Validations" do
it { should validate_presence_of(:url) }
diff --git a/spec/models/wiki_spec.rb b/spec/models/wiki_spec.rb
index de6ce426331..1e27954cb84 100644
--- a/spec/models/wiki_spec.rb
+++ b/spec/models/wiki_spec.rb
@@ -7,6 +7,11 @@ describe Wiki do
it { should have_many(:notes).dependent(:destroy) }
end
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ it { should_not allow_mass_assignment_of(:user_id) }
+ end
+
describe "Validation" do
it { should validate_presence_of(:title) }
it { should ensure_length_of(:title).is_within(1..250) }
diff --git a/spec/observers/users_project_observer_spec.rb b/spec/observers/users_project_observer_spec.rb
index f38d98620a3..a8e0834bc99 100644
--- a/spec/observers/users_project_observer_spec.rb
+++ b/spec/observers/users_project_observer_spec.rb
@@ -10,55 +10,64 @@ describe UsersProjectObserver do
user: user )}
subject { UsersProjectObserver.instance }
- describe "#after_create" do
+ describe "#after_commit" do
it "should called when UsersProject created" do
- subject.should_receive(:after_create)
+ subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
- Factory.create(:users_project,
- project: project,
- user: user)
+ create(:users_project)
end
end
+
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
- subject.after_create(users_project)
+ subject.after_commit(users_project)
+ Event.stub(:create => true)
end
+
it "should create new event" do
Event.should_receive(:create).with(
- project_id: users_project.project.id,
- action: Event::Joined,
+ project_id: users_project.project.id,
+ action: Event::Joined,
author_id: users_project.user.id
)
+
subject.after_create(users_project)
end
end
describe "#after_update" do
it "should called when UsersProject updated" do
- subject.should_receive(:after_update)
+ subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
- users_project.update_attribute(:project_access, 40)
+ create(:users_project).update_attribute(:project_access, UsersProject::MASTER)
end
end
+
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
- subject.after_update(users_project)
+ subject.after_commit(users_project)
+ end
+ it "should not called after UsersProject destroyed" do
+ subject.should_not_receive(:after_commit)
+ UsersProject.observers.enable :users_project_observer do
+ users_project.destroy
+ end
end
end
+
describe "#after_destroy" do
it "should called when UsersProject destroyed" do
subject.should_receive(:after_destroy)
+
UsersProject.observers.enable :users_project_observer do
- UsersProject.bulk_delete(
- users_project.project,
- [users_project.user.id]
- )
+ create(:users_project).destroy
end
end
+
it "should create new event" do
Event.should_receive(:create).with(
- project_id: users_project.project.id,
- action: Event::Left,
+ project_id: users_project.project.id,
+ action: Event::Left,
author_id: users_project.user.id
)
subject.after_destroy(users_project)
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index b46380b21d9..498bbad6179 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -111,42 +111,52 @@ describe Gitlab::API do
end
end
- describe "GET /projects/:id/users" do
- it "should return project users" do
- get api("/projects/#{project.code}/users", user)
-
+ describe "GET /projects/:id/members" do
+ it "should return project team members" do
+ get api("/projects/#{project.code}/members", user)
response.status.should == 200
-
json_response.should be_an Array
json_response.count.should == 2
- json_response.first['user']['id'].should == user.id
+ json_response.first['email'].should == user.email
end
end
- describe "POST /projects/:id/users" do
- it "should add users to project" do
- expect {
- post api("/projects/#{project.code}/users", user),
- user_ids: {"0" => user2.id}, project_access: UsersProject::DEVELOPER
- }.to change {project.users_projects.where(:project_access => UsersProject::DEVELOPER).count}.by(1)
+ describe "GET /projects/:id/members/:user_id" do
+ it "should return project team member" do
+ get api("/projects/#{project.code}/members/#{user.id}", user)
+ response.status.should == 200
+ json_response['email'].should == user.email
+ json_response['access_level'].should == UsersProject::MASTER
end
end
- describe "PUT /projects/:id/users" do
- it "should update users to new access role" do
+ describe "POST /projects/:id/members" do
+ it "should add user to project team" do
expect {
- put api("/projects/#{project.code}/users", user),
- user_ids: {"0" => user3.id}, project_access: UsersProject::MASTER
- }.to change {project.users_projects.where(:project_access => UsersProject::MASTER).count}.by(1)
+ post api("/projects/#{project.code}/members", user), user_id: user2.id,
+ access_level: UsersProject::DEVELOPER
+ }.to change { UsersProject.count }.by(1)
+
+ response.status.should == 201
+ json_response['email'].should == user2.email
+ json_response['access_level'].should == UsersProject::DEVELOPER
+ end
+ end
+
+ describe "PUT /projects/:id/members/:user_id" do
+ it "should update project team member" do
+ put api("/projects/#{project.code}/members/#{user3.id}", user), access_level: UsersProject::MASTER
+ response.status.should == 200
+ json_response['email'].should == user3.email
+ json_response['access_level'].should == UsersProject::MASTER
end
end
- describe "DELETE /projects/:id/users" do
- it "should delete users from project" do
+ describe "DELETE /projects/:id/members/:user_id" do
+ it "should remove user from project team" do
expect {
- delete api("/projects/#{project.code}/users", user),
- user_ids: {"0" => user3.id}
- }.to change {project.users_projects.count}.by(-1)
+ delete api("/projects/#{project.code}/members/#{user3.id}", user)
+ }.to change { UsersProject.count }.by(-1)
end
end
@@ -189,6 +199,27 @@ describe Gitlab::API do
end
end
+ describe "GET /projects/:id/repository/commits" do
+ context "authorized user" do
+ before { project.add_access(user2, :read) }
+
+ it "should return project commits" do
+ get api("/projects/#{project.code}/repository/commits", user)
+ response.status.should == 200
+
+ json_response.should be_an Array
+ json_response.first['id'].should == project.commit.id
+ end
+ end
+
+ context "unauthorized user" do
+ it "should not return project commits" do
+ get api("/projects/#{project.code}/repository/commits")
+ response.status.should == 401
+ end
+ end
+ end
+
describe "GET /projects/:id/snippets/:snippet_id" do
it "should return a project snippet" do
get api("/projects/#{project.code}/snippets/#{snippet.id}", user)
diff --git a/spec/requests/api/session_spec.rb b/spec/requests/api/session_spec.rb
new file mode 100644
index 00000000000..f251f3921ac
--- /dev/null
+++ b/spec/requests/api/session_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe Gitlab::API do
+ include ApiHelpers
+
+ let(:user) { Factory :user }
+
+ describe "POST /session" do
+ context "when valid password" do
+ it "should return private token" do
+ post api("/session"), email: user.email, password: '123456'
+ response.status.should == 201
+
+ json_response['email'].should == user.email
+ json_response['private_token'].should == user.private_token
+ end
+ end
+
+ context "when invalid password" do
+ it "should return authentication error" do
+ post api("/session"), email: user.email, password: '123'
+ response.status.should == 401
+
+ json_response['email'].should be_nil
+ json_response['private_token'].should be_nil
+ end
+ end
+
+ context "when empty password" do
+ it "should return authentication error" do
+ post api("/session"), email: user.email
+ response.status.should == 401
+
+ json_response['email'].should be_nil
+ json_response['private_token'].should be_nil
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index e25fe1341d5..e3049e09016 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Gitlab::API do
include ApiHelpers
- let(:user) { Factory :user }
+ let(:user) { Factory :user }
+ let(:admin) {Factory :admin}
+ let(:key) { Factory :key, user: user }
describe "GET /users" do
context "when unauthenticated" do
@@ -31,6 +33,26 @@ describe Gitlab::API do
end
end
+ describe "POST /users" do
+ before{ admin }
+
+ it "should not create invalid user" do
+ post api("/users", admin), { email: "invalid email" }
+ response.status.should == 404
+ end
+
+ it "should create user" do
+ expect{
+ post api("/users", admin), Factory.attributes(:user)
+ }.to change{User.count}.by(1)
+ end
+
+ it "shouldn't available for non admin users" do
+ post api("/users", user), Factory.attributes(:user)
+ response.status.should == 403
+ end
+ end
+
describe "GET /user" do
it "should return current user" do
get api("/user", user)
@@ -38,4 +60,68 @@ describe Gitlab::API do
json_response['email'].should == user.email
end
end
+
+ describe "GET /user/keys" do
+ context "when unauthenticated" do
+ it "should return authentication error" do
+ get api("/user/keys")
+ response.status.should == 401
+ end
+ end
+
+ context "when authenticated" do
+ it "should return array of ssh keys" do
+ user.keys << key
+ user.save
+ get api("/user/keys", user)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.first["title"].should == key.title
+ end
+ end
+ end
+
+ describe "GET /user/keys/:id" do
+ it "should returm single key" do
+ user.keys << key
+ user.save
+ get api("/user/keys/#{key.id}", user)
+ response.status.should == 200
+ json_response["title"].should == key.title
+ end
+
+ it "should return 404 Not Found within invalid ID" do
+ get api("/user/keys/42", user)
+ response.status.should == 404
+ end
+ end
+
+ describe "POST /user/keys" do
+ it "should not create invalid ssh key" do
+ post api("/user/keys", user), { title: "invalid key" }
+ response.status.should == 404
+ end
+
+ it "should create ssh key" do
+ key_attrs = Factory.attributes :key
+ expect {
+ post api("/user/keys", user), key_attrs
+ }.to change{ user.keys.count }.by(1)
+ end
+ end
+
+ describe "DELETE /user/keys/:id" do
+ it "should delete existed key" do
+ user.keys << key
+ user.save
+ expect {
+ delete api("/user/keys/#{key.id}", user)
+ }.to change{user.keys.count}.by(-1)
+ end
+
+ it "should return 404 Not Found within invalid ID" do
+ delete api("/user/keys/42", user)
+ response.status.should == 404
+ end
+ end
end
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 1076e90c42b..106f6451485 100644
--- a/spec/requests/gitlab_flavored_markdown_spec.rb
+++ b/spec/requests/gitlab_flavored_markdown_spec.rb
@@ -25,6 +25,7 @@ describe "Gitlab Flavored Markdown" do
@tag_name = "gfm-test-tag"
r.git.native(:tag, {}, @tag_name, commit.id)
end
+
after do
# delete test branch and tag
project.repo.git.native(:branch, {D: true}, @branch_name)
@@ -39,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}")
@@ -68,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}")
@@ -88,7 +88,6 @@ describe "Gitlab Flavored Markdown" do
end
end
-
describe "for issues" do
before do
@other_issue = Factory :issue,
@@ -174,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/hooks_spec.rb b/spec/requests/hooks_spec.rb
deleted file mode 100644
index 7cfe7cfe849..00000000000
--- a/spec/requests/hooks_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require 'spec_helper'
-
-describe "Hooks" do
- before do
- login_as :user
- @project = Factory :project
- @project.add_access(@user, :read, :admin)
- end
-
- describe "GET index" do
- it "should be available" do
- @hook = Factory :project_hook, project: @project
- visit project_hooks_path(@project)
- page.should have_content "Hooks"
- page.should have_content @hook.url
- end
- end
-
- describe "New Hook" do
- before do
- @url = Faker::Internet.uri("http")
- visit project_hooks_path(@project)
- fill_in "hook_url", with: @url
- expect { click_button "Add Web Hook" }.to change(ProjectHook, :count).by(1)
- end
-
- it "should open new team member popup" do
- page.current_path.should == project_hooks_path(@project)
- page.should have_content(@url)
- end
- end
-
- describe "Test" do
- before do
- @hook = Factory :project_hook, project: @project
- stub_request(:post, @hook.url)
- visit project_hooks_path(@project)
- click_link "Test Hook"
- end
-
- it { page.current_path.should == project_hooks_path(@project) }
- end
-end
diff --git a/spec/requests/security/profile_access_spec.rb b/spec/requests/security/profile_access_spec.rb
index 9f6fe6a2b50..69c1c29cf12 100644
--- a/spec/requests/security/profile_access_spec.rb
+++ b/spec/requests/security/profile_access_spec.rb
@@ -28,8 +28,8 @@ describe "Users Security" do
it { should be_denied_for :visitor }
end
- describe "GET /profile/password" do
- subject { profile_password_path }
+ describe "GET /profile/account" do
+ subject { profile_account_path }
it { should be_allowed_for @u1 }
it { should be_allowed_for :admin }
diff --git a/spec/requests/security/project_access_spec.rb b/spec/requests/security/project_access_spec.rb
index 0cdf43bf84e..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 { team_project_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/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb
new file mode 100644
index 00000000000..60261c7ae71
--- /dev/null
+++ b/spec/routing/admin_routing_spec.rb
@@ -0,0 +1,166 @@
+require 'spec_helper'
+
+# team_update_admin_user PUT /admin/users/:id/team_update(.:format) admin/users#team_update
+# block_admin_user PUT /admin/users/:id/block(.:format) admin/users#block
+# unblock_admin_user PUT /admin/users/:id/unblock(.:format) admin/users#unblock
+# admin_users GET /admin/users(.:format) admin/users#index
+# POST /admin/users(.:format) admin/users#create
+# new_admin_user GET /admin/users/new(.:format) admin/users#new
+# edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
+# admin_user GET /admin/users/:id(.:format) admin/users#show
+# PUT /admin/users/:id(.:format) admin/users#update
+# DELETE /admin/users/:id(.:format) admin/users#destroy
+describe Admin::UsersController, "routing" do
+ it "to #team_update" do
+ put("/admin/users/1/team_update").should route_to('admin/users#team_update', id: '1')
+ end
+
+ it "to #block" do
+ put("/admin/users/1/block").should route_to('admin/users#block', id: '1')
+ end
+
+ it "to #unblock" do
+ put("/admin/users/1/unblock").should route_to('admin/users#unblock', id: '1')
+ end
+
+ it "to #index" do
+ get("/admin/users").should route_to('admin/users#index')
+ end
+
+ it "to #show" do
+ get("/admin/users/1").should route_to('admin/users#show', id: '1')
+ end
+
+ it "to #create" do
+ post("/admin/users").should route_to('admin/users#create')
+ end
+
+ it "to #new" do
+ get("/admin/users/new").should route_to('admin/users#new')
+ end
+
+ it "to #edit" do
+ get("/admin/users/1/edit").should route_to('admin/users#edit', id: '1')
+ end
+
+ it "to #show" do
+ get("/admin/users/1").should route_to('admin/users#show', id: '1')
+ end
+
+ it "to #update" do
+ put("/admin/users/1").should route_to('admin/users#update', id: '1')
+ end
+
+ it "to #destroy" do
+ delete("/admin/users/1").should route_to('admin/users#destroy', id: '1')
+ end
+end
+
+# team_admin_project GET /admin/projects/:id/team(.:format) admin/projects#team {:id=>/[^\/]+/}
+# team_update_admin_project PUT /admin/projects/:id/team_update(.:format) admin/projects#team_update {:id=>/[^\/]+/}
+# admin_projects GET /admin/projects(.:format) admin/projects#index {:id=>/[^\/]+/}
+# POST /admin/projects(.:format) admin/projects#create {:id=>/[^\/]+/}
+# new_admin_project GET /admin/projects/new(.:format) admin/projects#new {:id=>/[^\/]+/}
+# edit_admin_project GET /admin/projects/:id/edit(.:format) admin/projects#edit {:id=>/[^\/]+/}
+# admin_project GET /admin/projects/:id(.:format) admin/projects#show {:id=>/[^\/]+/}
+# PUT /admin/projects/:id(.:format) admin/projects#update {:id=>/[^\/]+/}
+# DELETE /admin/projects/:id(.:format) admin/projects#destroy {:id=>/[^\/]+/}
+describe Admin::ProjectsController, "routing" do
+ it "to #team" do
+ get("/admin/projects/gitlab/team").should route_to('admin/projects#team', id: 'gitlab')
+ end
+
+ it "to #team_update" do
+ put("/admin/projects/gitlab/team_update").should route_to('admin/projects#team_update', id: 'gitlab')
+ end
+
+ it "to #index" do
+ get("/admin/projects").should route_to('admin/projects#index')
+ end
+
+ it "to #create" do
+ post("/admin/projects").should route_to('admin/projects#create')
+ end
+
+ it "to #new" do
+ get("/admin/projects/new").should route_to('admin/projects#new')
+ end
+
+ it "to #edit" do
+ get("/admin/projects/gitlab/edit").should route_to('admin/projects#edit', id: 'gitlab')
+ end
+
+ it "to #show" do
+ get("/admin/projects/gitlab").should route_to('admin/projects#show', id: 'gitlab')
+ end
+
+ it "to #update" do
+ put("/admin/projects/gitlab").should route_to('admin/projects#update', id: 'gitlab')
+ end
+
+ it "to #destroy" do
+ delete("/admin/projects/gitlab").should route_to('admin/projects#destroy', id: 'gitlab')
+ end
+end
+
+# edit_admin_team_member GET /admin/team_members/:id/edit(.:format) admin/team_members#edit
+# admin_team_member PUT /admin/team_members/:id(.:format) admin/team_members#update
+# DELETE /admin/team_members/:id(.:format) admin/team_members#destroy
+describe Admin::TeamMembersController, "routing" do
+ it "to #edit" do
+ get("/admin/team_members/1/edit").should route_to('admin/team_members#edit', id: '1')
+ end
+
+ it "to #update" do
+ put("/admin/team_members/1").should route_to('admin/team_members#update', id: '1')
+ end
+
+ it "to #destroy" do
+ delete("/admin/team_members/1").should route_to('admin/team_members#destroy', id: '1')
+ end
+end
+
+# admin_hook_test GET /admin/hooks/:hook_id/test(.:format) admin/hooks#test
+# admin_hooks GET /admin/hooks(.:format) admin/hooks#index
+# POST /admin/hooks(.:format) admin/hooks#create
+# admin_hook DELETE /admin/hooks/:id(.:format) admin/hooks#destroy
+describe Admin::HooksController, "routing" do
+ it "to #test" do
+ get("/admin/hooks/1/test").should route_to('admin/hooks#test', hook_id: '1')
+ end
+
+ it "to #index" do
+ get("/admin/hooks").should route_to('admin/hooks#index')
+ end
+
+ it "to #create" do
+ post("/admin/hooks").should route_to('admin/hooks#create')
+ end
+
+ it "to #destroy" do
+ delete("/admin/hooks/1").should route_to('admin/hooks#destroy', id: '1')
+ end
+
+end
+
+# admin_logs GET /admin/logs(.:format) admin/logs#show
+describe Admin::LogsController, "routing" do
+ it "to #show" do
+ get("/admin/logs").should route_to('admin/logs#show')
+ end
+end
+
+# admin_resque GET /admin/resque(.:format) admin/resque#show
+describe Admin::ResqueController, "routing" do
+ it "to #show" do
+ get("/admin/resque").should route_to('admin/resque#show')
+ end
+end
+
+# admin_root /admin(.:format) admin/dashboard#index
+describe Admin::DashboardController, "routing" do
+ it "to #index" do
+ get("/admin").should route_to('admin/dashboard#index')
+ end
+end
+
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
new file mode 100644
index 00000000000..dc687d2a7ac
--- /dev/null
+++ b/spec/routing/project_routing_spec.rb
@@ -0,0 +1,417 @@
+require 'spec_helper'
+
+# Shared examples for a resource inside a Project
+#
+# By default it tests all the default REST actions: index, create, new, edit,
+# show, update, and destroy. You can remove actions by customizing the
+# `actions` variable.
+#
+# It also expects a `controller` variable to be available which defines both
+# the path to the resource as well as the controller name.
+#
+# Examples
+#
+# # Default behavior
+# it_behaves_like "RESTful project resources" do
+# let(:controller) { 'issues' }
+# end
+#
+# # Customizing actions
+# it_behaves_like "RESTful project resources" do
+# let(:actions) { [:index] }
+# let(:controller) { 'issues' }
+# end
+shared_examples "RESTful project resources" do
+ let(:actions) { [:index, :create, :new, :edit, :show, :update, :destroy] }
+
+ it "to #index" do
+ get("/gitlabhq/#{controller}").should route_to("#{controller}#index", project_id: 'gitlabhq') if actions.include?(:index)
+ end
+
+ it "to #create" do
+ post("/gitlabhq/#{controller}").should route_to("#{controller}#create", project_id: 'gitlabhq') if actions.include?(:create)
+ end
+
+ it "to #new" do
+ get("/gitlabhq/#{controller}/new").should route_to("#{controller}#new", project_id: 'gitlabhq') if actions.include?(:new)
+ end
+
+ it "to #edit" do
+ get("/gitlabhq/#{controller}/1/edit").should route_to("#{controller}#edit", project_id: 'gitlabhq', id: '1') if actions.include?(:edit)
+ end
+
+ it "to #show" do
+ get("/gitlabhq/#{controller}/1").should route_to("#{controller}#show", project_id: 'gitlabhq', id: '1') if actions.include?(:show)
+ end
+
+ it "to #update" do
+ put("/gitlabhq/#{controller}/1").should route_to("#{controller}#update", project_id: 'gitlabhq', id: '1') if actions.include?(:update)
+ end
+
+ it "to #destroy" do
+ delete("/gitlabhq/#{controller}/1").should route_to("#{controller}#destroy", project_id: 'gitlabhq', id: '1') if actions.include?(:destroy)
+ end
+end
+
+# projects POST /projects(.:format) projects#create
+# new_project GET /projects/new(.:format) projects#new
+# wall_project GET /:id/wall(.:format) projects#wall
+# graph_project GET /:id/graph(.:format) projects#graph
+# files_project GET /:id/files(.:format) projects#files
+# edit_project GET /:id/edit(.:format) projects#edit
+# project GET /:id(.:format) projects#show
+# PUT /:id(.:format) projects#update
+# DELETE /:id(.:format) projects#destroy
+describe ProjectsController, "routing" do
+ it "to #create" do
+ post("/projects").should route_to('projects#create')
+ end
+
+ it "to #new" do
+ get("/projects/new").should route_to('projects#new')
+ end
+
+ it "to #wall" do
+ get("/gitlabhq/wall").should route_to('projects#wall', id: 'gitlabhq')
+ end
+
+ it "to #graph" do
+ get("/gitlabhq/graph").should route_to('projects#graph', id: 'gitlabhq')
+ end
+
+ it "to #files" do
+ get("/gitlabhq/files").should route_to('projects#files', id: 'gitlabhq')
+ end
+
+ it "to #edit" do
+ get("/gitlabhq/edit").should route_to('projects#edit', id: 'gitlabhq')
+ end
+
+ it "to #show" do
+ get("/gitlabhq").should route_to('projects#show', id: 'gitlabhq')
+ end
+
+ it "to #update" do
+ put("/gitlabhq").should route_to('projects#update', id: 'gitlabhq')
+ end
+
+ it "to #destroy" do
+ delete("/gitlabhq").should route_to('projects#destroy', id: 'gitlabhq')
+ end
+end
+
+# pages_project_wikis GET /:project_id/wikis/pages(.:format) wikis#pages
+# history_project_wiki GET /:project_id/wikis/:id/history(.:format) wikis#history
+# project_wikis POST /:project_id/wikis(.:format) wikis#create
+# edit_project_wiki GET /:project_id/wikis/:id/edit(.:format) wikis#edit
+# project_wiki GET /:project_id/wikis/:id(.:format) wikis#show
+# DELETE /:project_id/wikis/:id(.:format) wikis#destroy
+describe WikisController, "routing" do
+ it "to #pages" do
+ get("/gitlabhq/wikis/pages").should route_to('wikis#pages', project_id: 'gitlabhq')
+ end
+
+ it "to #history" do
+ get("/gitlabhq/wikis/1/history").should route_to('wikis#history', project_id: 'gitlabhq', id: '1')
+ end
+
+ it_behaves_like "RESTful project resources" do
+ let(:actions) { [:create, :edit, :show, :destroy] }
+ let(:controller) { 'wikis' }
+ end
+end
+
+# branches_project_repository GET /:project_id/repository/branches(.:format) repositories#branches
+# tags_project_repository GET /:project_id/repository/tags(.:format) repositories#tags
+# archive_project_repository GET /:project_id/repository/archive(.:format) repositories#archive
+# project_repository POST /:project_id/repository(.:format) repositories#create
+# new_project_repository GET /:project_id/repository/new(.:format) repositories#new
+# edit_project_repository GET /:project_id/repository/edit(.:format) repositories#edit
+# GET /:project_id/repository(.:format) repositories#show
+# PUT /:project_id/repository(.:format) repositories#update
+# DELETE /:project_id/repository(.:format) repositories#destroy
+describe RepositoriesController, "routing" do
+ it "to #branches" do
+ get("/gitlabhq/repository/branches").should route_to('repositories#branches', project_id: 'gitlabhq')
+ end
+
+ it "to #tags" do
+ get("/gitlabhq/repository/tags").should route_to('repositories#tags', project_id: 'gitlabhq')
+ end
+
+ it "to #archive" do
+ get("/gitlabhq/repository/archive").should route_to('repositories#archive', project_id: 'gitlabhq')
+ end
+
+ it "to #create" do
+ post("/gitlabhq/repository").should route_to('repositories#create', project_id: 'gitlabhq')
+ end
+
+ it "to #new" do
+ get("/gitlabhq/repository/new").should route_to('repositories#new', project_id: 'gitlabhq')
+ end
+
+ it "to #edit" do
+ get("/gitlabhq/repository/edit").should route_to('repositories#edit', project_id: 'gitlabhq')
+ end
+
+ it "to #show" do
+ get("/gitlabhq/repository").should route_to('repositories#show', project_id: 'gitlabhq')
+ end
+
+ it "to #update" do
+ put("/gitlabhq/repository").should route_to('repositories#update', project_id: 'gitlabhq')
+ end
+
+ it "to #destroy" do
+ delete("/gitlabhq/repository").should route_to('repositories#destroy', project_id: 'gitlabhq')
+ end
+end
+
+# project_deploy_keys GET /:project_id/deploy_keys(.:format) deploy_keys#index
+# POST /:project_id/deploy_keys(.:format) deploy_keys#create
+# new_project_deploy_key GET /:project_id/deploy_keys/new(.:format) deploy_keys#new
+# edit_project_deploy_key GET /:project_id/deploy_keys/:id/edit(.:format) deploy_keys#edit
+# project_deploy_key GET /:project_id/deploy_keys/:id(.:format) deploy_keys#show
+# PUT /:project_id/deploy_keys/:id(.:format) deploy_keys#update
+# DELETE /:project_id/deploy_keys/:id(.:format) deploy_keys#destroy
+describe DeployKeysController, "routing" do
+ it_behaves_like "RESTful project resources" do
+ let(:controller) { 'deploy_keys' }
+ end
+end
+
+# project_protected_branches GET /:project_id/protected_branches(.:format) protected_branches#index
+# POST /:project_id/protected_branches(.:format) protected_branches#create
+# project_protected_branch DELETE /:project_id/protected_branches/:id(.:format) protected_branches#destroy
+describe ProtectedBranchesController, "routing" do
+ it_behaves_like "RESTful project resources" do
+ let(:actions) { [:index, :create, :destroy] }
+ let(:controller) { 'protected_branches' }
+ end
+end
+
+# switch_project_refs GET /:project_id/switch(.:format) refs#switch
+# logs_tree_project_ref GET /:project_id/:id/logs_tree(.:format) refs#logs_tree
+# logs_file_project_ref GET /:project_id/:id/logs_tree/:path(.:format) refs#logs_tree
+describe RefsController, "routing" do
+ it "to #switch" do
+ get("/gitlabhq/switch").should route_to('refs#switch', project_id: 'gitlabhq')
+ 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
+end
+
+# diffs_project_merge_request GET /:project_id/merge_requests/:id/diffs(.:format) merge_requests#diffs
+# automerge_project_merge_request GET /:project_id/merge_requests/:id/automerge(.:format) merge_requests#automerge
+# automerge_check_project_merge_request GET /:project_id/merge_requests/:id/automerge_check(.:format) merge_requests#automerge_check
+# raw_project_merge_request GET /:project_id/merge_requests/:id/raw(.:format) merge_requests#raw
+# branch_from_project_merge_requests GET /:project_id/merge_requests/branch_from(.:format) merge_requests#branch_from
+# branch_to_project_merge_requests GET /:project_id/merge_requests/branch_to(.:format) merge_requests#branch_to
+# project_merge_requests GET /:project_id/merge_requests(.:format) merge_requests#index
+# POST /:project_id/merge_requests(.:format) merge_requests#create
+# new_project_merge_request GET /:project_id/merge_requests/new(.:format) merge_requests#new
+# edit_project_merge_request GET /:project_id/merge_requests/:id/edit(.:format) merge_requests#edit
+# project_merge_request GET /:project_id/merge_requests/:id(.:format) merge_requests#show
+# PUT /:project_id/merge_requests/:id(.:format) merge_requests#update
+# DELETE /:project_id/merge_requests/:id(.:format) merge_requests#destroy
+describe MergeRequestsController, "routing" do
+ it "to #diffs" do
+ get("/gitlabhq/merge_requests/1/diffs").should route_to('merge_requests#diffs', project_id: 'gitlabhq', id: '1')
+ end
+
+ it "to #automerge" do
+ get("/gitlabhq/merge_requests/1/automerge").should route_to('merge_requests#automerge', project_id: 'gitlabhq', id: '1')
+ end
+
+ it "to #automerge_check" do
+ get("/gitlabhq/merge_requests/1/automerge_check").should route_to('merge_requests#automerge_check', project_id: 'gitlabhq', id: '1')
+ end
+
+ it "to #raw" do
+ get("/gitlabhq/merge_requests/1/raw").should route_to('merge_requests#raw', project_id: 'gitlabhq', id: '1')
+ end
+
+ it "to #branch_from" do
+ get("/gitlabhq/merge_requests/branch_from").should route_to('merge_requests#branch_from', project_id: 'gitlabhq')
+ end
+
+ it "to #branch_to" do
+ get("/gitlabhq/merge_requests/branch_to").should route_to('merge_requests#branch_to', project_id: 'gitlabhq')
+ end
+
+ it_behaves_like "RESTful project resources" do
+ let(:controller) { 'merge_requests' }
+ end
+end
+
+# raw_project_snippet GET /:project_id/snippets/:id/raw(.:format) snippets#raw
+# project_snippets GET /:project_id/snippets(.:format) snippets#index
+# POST /:project_id/snippets(.:format) snippets#create
+# new_project_snippet GET /:project_id/snippets/new(.:format) snippets#new
+# edit_project_snippet GET /:project_id/snippets/:id/edit(.:format) snippets#edit
+# project_snippet GET /:project_id/snippets/:id(.:format) snippets#show
+# PUT /:project_id/snippets/:id(.:format) snippets#update
+# DELETE /:project_id/snippets/:id(.:format) snippets#destroy
+describe SnippetsController, "routing" do
+ it "to #raw" do
+ get("/gitlabhq/snippets/1/raw").should route_to('snippets#raw', project_id: 'gitlabhq', id: '1')
+ end
+
+ it_behaves_like "RESTful project resources" do
+ let(:controller) { 'snippets' }
+ end
+end
+
+# test_project_hook GET /:project_id/hooks/:id/test(.:format) hooks#test
+# project_hooks GET /:project_id/hooks(.:format) hooks#index
+# POST /:project_id/hooks(.:format) hooks#create
+# project_hook DELETE /:project_id/hooks/:id(.:format) hooks#destroy
+describe HooksController, "routing" do
+ it "to #test" do
+ get("/gitlabhq/hooks/1/test").should route_to('hooks#test', project_id: 'gitlabhq', id: '1')
+ end
+
+ it_behaves_like "RESTful project resources" do
+ let(:actions) { [:index, :create, :destroy] }
+ let(:controller) { 'hooks' }
+ end
+end
+
+# 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
+# project_commit GET /:project_id/commits/:id(.:format) commits#show
+describe CommitsController, "routing" do
+ it_behaves_like "RESTful project resources" do
+ let(:actions) { [:show] }
+ let(:controller) { 'commits' }
+ end
+end
+
+# project_team_members GET /:project_id/team_members(.:format) team_members#index
+# POST /:project_id/team_members(.:format) team_members#create
+# new_project_team_member GET /:project_id/team_members/new(.:format) team_members#new
+# edit_project_team_member GET /:project_id/team_members/:id/edit(.:format) team_members#edit
+# project_team_member GET /:project_id/team_members/:id(.:format) team_members#show
+# PUT /:project_id/team_members/:id(.:format) team_members#update
+# DELETE /:project_id/team_members/:id(.:format) team_members#destroy
+describe TeamMembersController, "routing" do
+ it_behaves_like "RESTful project resources" do
+ let(:controller) { 'team_members' }
+ end
+end
+
+# project_milestones GET /:project_id/milestones(.:format) milestones#index
+# POST /:project_id/milestones(.:format) milestones#create
+# new_project_milestone GET /:project_id/milestones/new(.:format) milestones#new
+# edit_project_milestone GET /:project_id/milestones/:id/edit(.:format) milestones#edit
+# project_milestone GET /:project_id/milestones/:id(.:format) milestones#show
+# PUT /:project_id/milestones/:id(.:format) milestones#update
+# DELETE /:project_id/milestones/:id(.:format) milestones#destroy
+describe MilestonesController, "routing" do
+ it_behaves_like "RESTful project resources" do
+ let(:controller) { 'milestones' }
+ end
+end
+
+# project_labels GET /:project_id/labels(.:format) labels#index
+describe LabelsController, "routing" do
+ it "to #index" do
+ get("/gitlabhq/labels").should route_to('labels#index', project_id: 'gitlabhq')
+ end
+end
+
+# sort_project_issues POST /:project_id/issues/sort(.:format) issues#sort
+# bulk_update_project_issues POST /:project_id/issues/bulk_update(.:format) issues#bulk_update
+# search_project_issues GET /:project_id/issues/search(.:format) issues#search
+# project_issues GET /:project_id/issues(.:format) issues#index
+# POST /:project_id/issues(.:format) issues#create
+# new_project_issue GET /:project_id/issues/new(.:format) issues#new
+# edit_project_issue GET /:project_id/issues/:id/edit(.:format) issues#edit
+# project_issue GET /:project_id/issues/:id(.:format) issues#show
+# PUT /:project_id/issues/:id(.:format) issues#update
+# DELETE /:project_id/issues/:id(.:format) issues#destroy
+describe IssuesController, "routing" do
+ it "to #sort" do
+ post("/gitlabhq/issues/sort").should route_to('issues#sort', project_id: 'gitlabhq')
+ end
+
+ it "to #bulk_update" do
+ post("/gitlabhq/issues/bulk_update").should route_to('issues#bulk_update', project_id: 'gitlabhq')
+ end
+
+ it "to #search" do
+ get("/gitlabhq/issues/search").should route_to('issues#search', project_id: 'gitlabhq')
+ end
+
+ it_behaves_like "RESTful project resources" do
+ let(:controller) { 'issues' }
+ end
+end
+
+# preview_project_notes POST /:project_id/notes/preview(.:format) notes#preview
+# project_notes GET /:project_id/notes(.:format) notes#index
+# POST /:project_id/notes(.:format) notes#create
+# project_note DELETE /:project_id/notes/:id(.:format) notes#destroy
+describe NotesController, "routing" do
+ it "to #preview" do
+ post("/gitlabhq/notes/preview").should route_to('notes#preview', project_id: 'gitlabhq')
+ end
+
+ it_behaves_like "RESTful project resources" do
+ let(:actions) { [:index, :create, :destroy] }
+ 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/routing/routing_spec.rb b/spec/routing/routing_spec.rb
new file mode 100644
index 00000000000..cb8dbf373ba
--- /dev/null
+++ b/spec/routing/routing_spec.rb
@@ -0,0 +1,186 @@
+require 'spec_helper'
+
+# search GET /search(.:format) search#show
+describe SearchController, "routing" do
+ it "to #show" do
+ get("/search").should route_to('search#show')
+ end
+end
+
+# gitlab_api /api Gitlab::API
+# resque /info/resque Resque::Server
+# /:path Grack
+describe "Mounted Apps", "routing" do
+ it "to API" do
+ get("/api").should be_routable
+ end
+
+ it "to Resque" do
+ pending
+ get("/info/resque").should be_routable
+ end
+
+ it "to Grack" do
+ get("/gitlabhq.git").should be_routable
+ end
+end
+
+# help GET /help(.:format) help#index
+# help_permissions GET /help/permissions(.:format) help#permissions
+# help_workflow GET /help/workflow(.:format) help#workflow
+# help_api GET /help/api(.:format) help#api
+# help_web_hooks GET /help/web_hooks(.:format) help#web_hooks
+# help_system_hooks GET /help/system_hooks(.:format) help#system_hooks
+# help_markdown GET /help/markdown(.:format) help#markdown
+# help_ssh GET /help/ssh(.:format) help#ssh
+describe HelpController, "routing" do
+ it "to #index" do
+ get("/help").should route_to('help#index')
+ end
+
+ it "to #permissions" do
+ get("/help/permissions").should route_to('help#permissions')
+ end
+
+ it "to #workflow" do
+ get("/help/workflow").should route_to('help#workflow')
+ end
+
+ it "to #api" do
+ get("/help/api").should route_to('help#api')
+ end
+
+ it "to #web_hooks" do
+ get("/help/web_hooks").should route_to('help#web_hooks')
+ end
+
+ it "to #system_hooks" do
+ get("/help/system_hooks").should route_to('help#system_hooks')
+ end
+
+ it "to #markdown" do
+ get("/help/markdown").should route_to('help#markdown')
+ end
+
+ it "to #ssh" do
+ get("/help/ssh").should route_to('help#ssh')
+ end
+end
+
+# errors_githost GET /errors/githost(.:format) errors#githost
+describe ErrorsController, "routing" do
+ it "to #githost" do
+ get("/errors/githost").should route_to('errors#githost')
+ end
+end
+
+# profile_account GET /profile/account(.:format) profile#account
+# profile_history GET /profile/history(.:format) profile#history
+# profile_password PUT /profile/password(.:format) profile#password_update
+# profile_token GET /profile/token(.:format) profile#token
+# profile_reset_private_token PUT /profile/reset_private_token(.:format) profile#reset_private_token
+# profile GET /profile(.:format) profile#show
+# profile_design GET /profile/design(.:format) profile#design
+# profile_update PUT /profile/update(.:format) profile#update
+describe ProfileController, "routing" do
+ it "to #account" do
+ get("/profile/account").should route_to('profile#account')
+ end
+
+ it "to #history" do
+ get("/profile/history").should route_to('profile#history')
+ end
+
+ it "to #password_update" do
+ put("/profile/password").should route_to('profile#password_update')
+ end
+
+ it "to #token" do
+ get("/profile/token").should route_to('profile#token')
+ end
+
+ it "to #reset_private_token" do
+ put("/profile/reset_private_token").should route_to('profile#reset_private_token')
+ end
+
+ it "to #show" do
+ get("/profile").should route_to('profile#show')
+ end
+
+ it "to #design" do
+ get("/profile/design").should route_to('profile#design')
+ end
+
+ it "to #update" do
+ put("/profile/update").should route_to('profile#update')
+ end
+end
+
+# keys GET /keys(.:format) keys#index
+# POST /keys(.:format) keys#create
+# new_key GET /keys/new(.:format) keys#new
+# edit_key GET /keys/:id/edit(.:format) keys#edit
+# key GET /keys/:id(.:format) keys#show
+# PUT /keys/:id(.:format) keys#update
+# DELETE /keys/:id(.:format) keys#destroy
+describe KeysController, "routing" do
+ it "to #index" do
+ get("/keys").should route_to('keys#index')
+ end
+
+ it "to #create" do
+ post("/keys").should route_to('keys#create')
+ end
+
+ it "to #new" do
+ get("/keys/new").should route_to('keys#new')
+ end
+
+ it "to #edit" do
+ get("/keys/1/edit").should route_to('keys#edit', id: '1')
+ end
+
+ it "to #show" do
+ get("/keys/1").should route_to('keys#show', id: '1')
+ end
+
+ it "to #update" do
+ put("/keys/1").should route_to('keys#update', id: '1')
+ end
+
+ it "to #destroy" do
+ delete("/keys/1").should route_to('keys#destroy', id: '1')
+ end
+end
+
+# dashboard GET /dashboard(.:format) dashboard#index
+# dashboard_issues GET /dashboard/issues(.:format) dashboard#issues
+# dashboard_merge_requests GET /dashboard/merge_requests(.:format) dashboard#merge_requests
+# root / dashboard#index
+describe DashboardController, "routing" do
+ it "to #index" do
+ get("/dashboard").should route_to('dashboard#index')
+ get("/").should route_to('dashboard#index')
+ end
+
+ it "to #issues" do
+ get("/dashboard/issues").should route_to('dashboard#issues')
+ end
+
+ it "to #merge_requests" do
+ get("/dashboard/merge_requests").should route_to('dashboard#merge_requests')
+ end
+end
+
+# new_user_session GET /users/sign_in(.:format) devise/sessions#new
+# user_session POST /users/sign_in(.:format) devise/sessions#create
+# destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
+# user_omniauth_authorize /users/auth/:provider(.:format) omniauth_callbacks#passthru
+# user_omniauth_callback /users/auth/:action/callback(.:format) omniauth_callbacks#(?-mix:(?!))
+# user_password POST /users/password(.:format) devise/passwords#create
+# new_user_password GET /users/password/new(.:format) devise/passwords#new
+# edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
+# PUT /users/password(.:format) devise/passwords#update
+describe "Authentication", "routing" do
+ # pending
+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/gitolite_stub.rb b/spec/support/gitolite_stub.rb
index 037b09cd555..574bb5a12a3 100644
--- a/spec/support/gitolite_stub.rb
+++ b/spec/support/gitolite_stub.rb
@@ -5,42 +5,16 @@ module GitoliteStub
end
def stub_gitolite_admin
- gitolite_repo = mock(
- clean_permissions: true,
- add_permission: true
- )
-
- gitolite_config = mock(
- add_repo: true,
- get_repo: gitolite_repo,
- has_repo?: true
- )
-
- gitolite_admin = double(
- 'Gitolite::GitoliteAdmin',
- config: gitolite_config,
- save: true,
- )
+ gitolite_admin = double('Gitolite::GitoliteAdmin')
+ gitolite_admin.as_null_object
Gitolite::GitoliteAdmin.stub(new: gitolite_admin)
-
end
def stub_gitlab_gitolite
gitolite_config = double('Gitlab::GitoliteConfig')
- gitolite_config.stub(
- apply: ->() { yield(self) },
- write_key: true,
- rm_key: true,
- update_projects: true,
- update_project: true,
- update_project!: true,
- destroy_project: true,
- destroy_project!: true,
- admin_all_repo: true,
- admin_all_repo!: true,
-
- )
+ gitolite_config.stub(apply: ->() { yield(self) })
+ gitolite_config.as_null_object
Gitlab::GitoliteConfig.stub(new: gitolite_config)
end
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
index cb1dcba3dd8..809453c4a3b 100644
--- a/spec/support/matchers.rb
+++ b/spec/support/matchers.rb
@@ -73,11 +73,7 @@ module Shoulda::Matchers::ActiveModel
class EnsureLengthOfMatcher
# Shortcut for is_at_least and is_at_most
def is_within(range)
- if range.exclude_end?
- is_at_least(range.first) && is_at_most(range.last - 1)
- else
- is_at_least(range.first) && is_at_most(range.last)
- end
+ is_at_least(range.min) && is_at_most(range.max)
end
end
end
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