diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories.rb | 1 | ||||
-rw-r--r-- | spec/helpers/diff_helper_spec.rb | 98 | ||||
-rw-r--r-- | spec/lib/git_ref_validator_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 21 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/parser_spec.rb | 93 | ||||
-rw-r--r-- | spec/models/assembla_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/flowdock_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/gemnasium_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/gitlab_ci_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/service_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/slack_service_spec.rb | 7 | ||||
-rw-r--r-- | spec/requests/api/branches_spec.rb | 45 | ||||
-rw-r--r-- | spec/requests/api/issues_spec.rb | 65 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/repositories_spec.rb | 63 |
15 files changed, 396 insertions, 54 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index 03c87fcc6c5..f7f65bffb8b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -165,7 +165,6 @@ FactoryGirl.define do factory :service do type "" title "GitLab CI" - token "x56olispAND34ng" project end diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb new file mode 100644 index 00000000000..4ab415b4ef3 --- /dev/null +++ b/spec/helpers/diff_helper_spec.rb @@ -0,0 +1,98 @@ +require 'spec_helper' + +describe DiffHelper do + include RepoHelpers + + let(:project) { create(:project) } + let(:commit) { project.repository.commit(sample_commit.id) } + let(:diff) { commit.diffs.first } + let(:diff_file) { Gitlab::Diff::File.new(diff) } + + describe 'diff_hard_limit_enabled?' do + it 'should return true if param is provided' do + controller.stub(:params).and_return { { :force_show_diff => true } } + diff_hard_limit_enabled?.should be_true + end + + it 'should return false if param is not provided' do + diff_hard_limit_enabled?.should be_false + end + end + + describe 'allowed_diff_size' do + it 'should return hard limit for a diff if force diff is true' do + controller.stub(:params).and_return { { :force_show_diff => true } } + allowed_diff_size.should eq(1000) + end + + it 'should return safe limit for a diff if force diff is false' do + allowed_diff_size.should eq(100) + end + end + + describe 'parallel_diff' do + it 'should return an array of arrays containing the parsed diff' do + parallel_diff(diff_file, 0).should match_array(parallel_diff_result_array) + end + end + + describe 'generate_line_code' do + it 'should generate correct line code' do + generate_line_code(diff_file.file_path, diff_file.diff_lines.first).should == '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6' + end + end + + describe 'unfold_bottom_class' do + it 'should return empty string when bottom line shouldnt be unfolded' do + unfold_bottom_class(false).should == '' + end + + it 'should return js class when bottom lines should be unfolded' do + unfold_bottom_class(true).should == 'js-unfold-bottom' + end + end + + describe 'diff_line_content' do + + it 'should return non breaking space when line is empty' do + diff_line_content(nil).should eq(" ") + end + + it 'should return the line itself' do + diff_line_content(diff_file.diff_lines.first.text).should eq("@@ -6,12 +6,18 @@ module Popen") + diff_line_content(diff_file.diff_lines.first.type).should eq("match") + diff_line_content(diff_file.diff_lines.first.new_pos).should eq(6) + end + end + + def parallel_diff_result_array + [ + ["match", 6, "@@ -6,12 +6,18 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6", "match", 6, "@@ -6,12 +6,18 @@ module Popen"], + [nil, 6, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6", nil, 6, " "], + [nil, 7, " def popen(cmd, path=nil)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7", nil, 7, " def popen(cmd, path=nil)"], + [nil, 8, " unless cmd.is_a?(Array)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8", nil, 8, " unless cmd.is_a?(Array)"], + ["old", 9, "- raise <span class='idiff'></span>"System commands must be given as an array of strings"", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9", "new", 9, "+ raise <span class='idiff'>RuntimeError, </span>"System commands must be given as an array of strings""], + [nil, 10, " end", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10", nil, 10, " end"], [nil, 11, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11", nil, 11, " "], + [nil, 12, " path ||= Dir.pwd", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12", nil, 12, " path ||= Dir.pwd"], + ["old", 13, "- vars = { "PWD" => path }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13", "old", nil, " "], + ["old", 14, "- options = { chdir: path }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_13", "new", 13, "+"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14", "new", 14, "+ vars = {"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15", "new", 15, "+ "PWD" => path"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16", "new", 16, "+ }"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17", "new", 17, "+"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18", "new", 18, "+ options = {"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19", "new", 19, "+ chdir: path"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20", "new", 20, "+ }"], + [nil, 15, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21", nil, 21, " "], + [nil, 16, " unless File.directory?(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22", nil, 22, " unless File.directory?(path)"], + [nil, 17, " FileUtils.mkdir_p(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23", nil, 23, " FileUtils.mkdir_p(path)"], + ["match", 19, "@@ -19,6 +25,7 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25", "match", 25, "@@ -19,6 +25,7 @@ module Popen"], + [nil, 19, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25", nil, 25, " "], [nil, 20, " @cmd_output = """, "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26", nil, 26, " @cmd_output = """], + [nil, 21, " @cmd_status = 0", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27", nil, 27, " @cmd_status = 0"], + [nil, nil, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28", "new", 28, "+"], + [nil, 22, " Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29", nil, 29, " Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|"], + [nil, 23, " @cmd_output << stdout.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30", nil, 30, " @cmd_output << stdout.read"], + [nil, 24, " @cmd_output << stderr.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31", nil, 31, " @cmd_output << stderr.read"] + ] + end +end diff --git a/spec/lib/git_ref_validator_spec.rb b/spec/lib/git_ref_validator_spec.rb new file mode 100644 index 00000000000..b2469c18395 --- /dev/null +++ b/spec/lib/git_ref_validator_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Gitlab::GitRefValidator do + it { Gitlab::GitRefValidator.validate('feature/new').should be_true } + it { Gitlab::GitRefValidator.validate('implement_@all').should be_true } + it { Gitlab::GitRefValidator.validate('my_new_feature').should be_true } + it { Gitlab::GitRefValidator.validate('#1').should be_true } + it { Gitlab::GitRefValidator.validate('feature/~new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/^new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/:new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/?new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/*new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/[new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/new.').should be_false } + it { Gitlab::GitRefValidator.validate('feature\@{').should be_false } + it { Gitlab::GitRefValidator.validate('feature\new').should be_false } + it { Gitlab::GitRefValidator.validate('feature//new').should be_false } + it { Gitlab::GitRefValidator.validate('feature new').should be_false } +end diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb new file mode 100644 index 00000000000..cf0b5c282c1 --- /dev/null +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Gitlab::Diff::File do + include RepoHelpers + + let(:project) { create(:project) } + let(:commit) { project.repository.commit(sample_commit.id) } + let(:diff) { commit.diffs.first } + let(:diff_file) { Gitlab::Diff::File.new(diff) } + + describe :diff_lines do + let(:diff_lines) { diff_file.diff_lines } + + it { diff_lines.size.should == 30 } + it { diff_lines.first.should be_kind_of(Gitlab::Diff::Line) } + end + + describe :mode_changed? do + it { diff_file.mode_changed?.should be_false } + end +end diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb new file mode 100644 index 00000000000..35b78260acd --- /dev/null +++ b/spec/lib/gitlab/diff/parser_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' + +describe Gitlab::Diff::Parser do + include RepoHelpers + + let(:project) { create(:project) } + let(:commit) { project.repository.commit(sample_commit.id) } + let(:diff) { commit.diffs.first } + let(:parser) { Gitlab::Diff::Parser.new } + + describe :parse do + let(:diff) do + <<eos +--- a/files/ruby/popen.rb ++++ b/files/ruby/popen.rb +@@ -6,12 +6,18 @@ module Popen + + def popen(cmd, path=nil) + unless cmd.is_a?(Array) +- raise "System commands must be given as an array of strings" ++ raise RuntimeError, "System commands must be given as an array of strings" + end + + path ||= Dir.pwd +- vars = { "PWD" => path } +- options = { chdir: path } ++ ++ vars = { ++ "PWD" => path ++ } ++ ++ options = { ++ chdir: path ++ } + + unless File.directory?(path) + FileUtils.mkdir_p(path) +@@ -19,6 +25,7 @@ module Popen + + @cmd_output = "" + @cmd_status = 0 ++ + Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| + @cmd_output << stdout.read + @cmd_output << stderr.read +eos + end + + before do + @lines = parser.parse(diff.lines) + end + + it { @lines.size.should == 30 } + + describe 'lines' do + describe 'first line' do + let(:line) { @lines.first } + + it { line.type.should == 'match' } + it { line.old_pos.should == 6 } + it { line.new_pos.should == 6 } + it { line.text.should == '@@ -6,12 +6,18 @@ module Popen' } + end + + describe 'removal line' do + let(:line) { @lines[10] } + + it { line.type.should == 'old' } + it { line.old_pos.should == 14 } + it { line.new_pos.should == 13 } + it { line.text.should == '- options = { chdir: path }' } + end + + describe 'addition line' do + let(:line) { @lines[16] } + + it { line.type.should == 'new' } + it { line.old_pos.should == 15 } + it { line.new_pos.should == 18 } + it { line.text.should == '+ options = {' } + end + + describe 'unchanged line' do + let(:line) { @lines.last } + + it { line.type.should == nil } + it { line.old_pos.should == 24 } + it { line.new_pos.should == 31 } + it { line.text.should == ' @cmd_output << stderr.read' } + end + end + end +end diff --git a/spec/models/assembla_service_spec.rb b/spec/models/assembla_service_spec.rb index acc08fc4d69..0ef475b87c3 100644 --- a/spec/models/assembla_service_spec.rb +++ b/spec/models/assembla_service_spec.rb @@ -5,16 +5,11 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# token :string(255) # project_id :integer not null # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null -# project_url :string(255) -# subdomain :string(255) -# room :string(255) -# recipients :text -# api_key :string(255) +# properties :text # require 'spec_helper' diff --git a/spec/models/flowdock_service_spec.rb b/spec/models/flowdock_service_spec.rb index 25ad133e122..710b8cba502 100644 --- a/spec/models/flowdock_service_spec.rb +++ b/spec/models/flowdock_service_spec.rb @@ -5,16 +5,11 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# token :string(255) # project_id :integer not null # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null -# project_url :string(255) -# subdomain :string(255) -# room :string(255) -# recipients :text -# api_key :string(255) +# properties :text # require 'spec_helper' diff --git a/spec/models/gemnasium_service_spec.rb b/spec/models/gemnasium_service_spec.rb index efdf0dc891b..5de645cdf33 100644 --- a/spec/models/gemnasium_service_spec.rb +++ b/spec/models/gemnasium_service_spec.rb @@ -5,16 +5,11 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# token :string(255) # project_id :integer not null # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null -# project_url :string(255) -# subdomain :string(255) -# room :string(255) -# recipients :text -# api_key :string(255) +# properties :text # require 'spec_helper' diff --git a/spec/models/gitlab_ci_service_spec.rb b/spec/models/gitlab_ci_service_spec.rb index 439a30869bb..e4cd8bb90c3 100644 --- a/spec/models/gitlab_ci_service_spec.rb +++ b/spec/models/gitlab_ci_service_spec.rb @@ -5,16 +5,11 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# token :string(255) # project_id :integer not null # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null -# project_url :string(255) -# subdomain :string(255) -# room :string(255) -# recipients :text -# api_key :string(255) +# properties :text # require 'spec_helper' diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index adeeac115c1..480aeabf67f 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -5,16 +5,11 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# token :string(255) # project_id :integer not null # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null -# project_url :string(255) -# subdomain :string(255) -# room :string(255) -# recipients :text -# api_key :string(255) +# properties :text # require 'spec_helper' diff --git a/spec/models/slack_service_spec.rb b/spec/models/slack_service_spec.rb index b00eb30569b..4576913b473 100644 --- a/spec/models/slack_service_spec.rb +++ b/spec/models/slack_service_spec.rb @@ -5,16 +5,11 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# token :string(255) # project_id :integer not null # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null -# project_url :string(255) -# subdomain :string(255) -# room :string(255) -# recipients :text -# api_key :string(255) +# properties :text # require 'spec_helper' diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index f3d7ca2ed21..e7f91c5e46e 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -94,22 +94,50 @@ describe API::API, api: true do describe "POST /projects/:id/repository/branches" do it "should create a new branch" do post api("/projects/#{project.id}/repository/branches", user), - branch_name: branch_name, - ref: branch_sha + branch_name: 'feature1', + ref: branch_sha response.status.should == 201 - json_response['name'].should == branch_name + json_response['name'].should == 'feature1' json_response['commit']['id'].should == branch_sha end it "should deny for user without push access" do post api("/projects/#{project.id}/repository/branches", user2), - branch_name: branch_name, - ref: branch_sha - + branch_name: branch_name, + ref: branch_sha response.status.should == 403 end + + it 'should return 400 if branch name is invalid' do + post api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new design', + ref: branch_sha + response.status.should == 400 + json_response['message'].should == 'Branch name invalid' + end + + it 'should return 400 if branch already exists' do + post api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new_design1', + ref: branch_sha + response.status.should == 201 + + post api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new_design1', + ref: branch_sha + response.status.should == 400 + json_response['message'].should == 'Branch already exists' + end + + it 'should return 400 if ref name is invalid' do + post api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new_design3', + ref: 'foo' + response.status.should == 400 + json_response['message'].should == 'Invalid reference name' + end end describe "DELETE /projects/:id/repository/branches/:branch" do @@ -120,6 +148,11 @@ describe API::API, api: true do response.status.should == 200 end + it 'should return 404 if branch not exists' do + delete api("/projects/#{project.id}/repository/branches/foobar", user) + response.status.should == 404 + end + it "should remove protected branch" do project.protected_branches.create(name: branch_name) delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user) diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index f70b56b194f..e8eebda95b4 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -9,6 +9,7 @@ describe API::API, api: true do let!(:label) do create(:label, title: 'label', color: '#FFAABB', project: project) end + let!(:label_link) { create(:label_link, label: label, target: issue) } before { project.team << [user, :reporter] } @@ -58,6 +59,45 @@ describe API::API, api: true do json_response.first['id'].should == issue.id json_response.second['id'].should == closed_issue.id end + + it 'should return an array of labeled issues' do + get api("/issues?labels=#{label.title}", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 1 + json_response.first['labels'].should == [label.title] + end + + it 'should return an array of labeled issues when at least one label matches' do + get api("/issues?labels=#{label.title},foo,bar", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 1 + json_response.first['labels'].should == [label.title] + end + + it 'should return an empty array if no issue matches labels' do + get api('/issues?labels=foo,bar', user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 0 + end + + it 'should return an array of labeled issues matching given state' do + get api("/issues?labels=#{label.title}&state=opened", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 1 + json_response.first['labels'].should == [label.title] + json_response.first['state'].should == 'opened' + end + + it 'should return an empty array if no issue matches labels and state filters' do + get api("/issues?labels=#{label.title}&state=closed", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 0 + end end end @@ -68,6 +108,29 @@ describe API::API, api: true do json_response.should be_an Array json_response.first['title'].should == issue.title end + + it 'should return an array of labeled project issues' do + get api("/projects/#{project.id}/issues?labels=#{label.title}", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 1 + json_response.first['labels'].should == [label.title] + end + + it 'should return an array of labeled project issues when at least one label matches' do + get api("/projects/#{project.id}/issues?labels=#{label.title},foo,bar", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 1 + json_response.first['labels'].should == [label.title] + end + + it 'should return an empty array if no project issue matches labels' do + get api("/projects/#{project.id}/issues?labels=foo,bar", user) + response.status.should == 200 + json_response.should be_an Array + json_response.length.should == 0 + end end describe "GET /projects/:id/issues/:issue_id" do @@ -182,7 +245,7 @@ describe API::API, api: true do labels: 'label2', state_event: "close" response.status.should == 200 - json_response['labels'].should == ['label2'] + json_response['labels'].should include 'label2' json_response['state'].should eq "closed" end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 12a3a07ff76..058b831e783 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -114,6 +114,7 @@ describe API::API, api: true do it "should assign attributes to project" do project = attributes_for(:project, { + path: 'camelCasePath', description: Faker::Lorem.sentence, issues_enabled: false, merge_requests_enabled: false, @@ -123,7 +124,6 @@ describe API::API, api: true do post api("/projects", user), project project.each_pair do |k,v| - next if k == :path json_response[k.to_s].should == v end end diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index f8603e11a04..17173aaeeac 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -23,22 +23,67 @@ describe API::API, api: true do end describe 'POST /projects/:id/repository/tags' do - it 'should create a new tag' do - post api("/projects/#{project.id}/repository/tags", user), - tag_name: 'v1.0.0', - ref: 'master' - - response.status.should == 201 - json_response['name'].should == 'v1.0.0' + context 'lightweight tags' do + it 'should create a new tag' do + post api("/projects/#{project.id}/repository/tags", user), + tag_name: 'v7.0.1', + ref: 'master' + + response.status.should == 201 + json_response['name'].should == 'v7.0.1' + end end + # TODO: fix this test for CI + #context 'annotated tag' do + #it 'should create a new annotated tag' do + #post api("/projects/#{project.id}/repository/tags", user), + #tag_name: 'v7.1.0', + #ref: 'master', + #message: 'tag message' + + #response.status.should == 201 + #json_response['name'].should == 'v7.1.0' + # The message is not part of the JSON response. + # Additional changes to the gitlab_git gem may be required. + # json_response['message'].should == 'tag message' + #end + #end + it 'should deny for user without push access' do post api("/projects/#{project.id}/repository/tags", user2), - tag_name: 'v1.0.0', + tag_name: 'v1.9.0', ref: '621491c677087aa243f165eab467bfdfbee00be1' - response.status.should == 403 end + + it 'should return 400 if tag name is invalid' do + post api("/projects/#{project.id}/repository/tags", user), + tag_name: 'v 1.0.0', + ref: 'master' + response.status.should == 400 + json_response['message'].should == 'Tag name invalid' + end + + it 'should return 400 if tag already exists' do + post api("/projects/#{project.id}/repository/tags", user), + tag_name: 'v8.0.0', + ref: 'master' + response.status.should == 201 + post api("/projects/#{project.id}/repository/tags", user), + tag_name: 'v8.0.0', + ref: 'master' + response.status.should == 400 + json_response['message'].should == 'Tag already exists' + end + + it 'should return 400 if ref name is invalid' do + post api("/projects/#{project.id}/repository/tags", user), + tag_name: 'mytag', + ref: 'foo' + response.status.should == 400 + json_response['message'].should == 'Invalid reference name' + end end describe "GET /projects/:id/repository/tree" do |