Skip to content
Snippets Groups Projects
Commit d4543eb5 authored by Andrew8xx8's avatar Andrew8xx8
Browse files

Tests fixed

parent 611ac727
No related branches found
No related tags found
No related merge requests found
Loading
@@ -23,11 +23,11 @@ class Projects::SnippetsController < Projects::ApplicationController
Loading
@@ -23,11 +23,11 @@ class Projects::SnippetsController < Projects::ApplicationController
end end
   
def new def new
@snippet = @project.snippets.new @snippet = @project.snippets.build
end end
   
def create def create
@snippet = @project.snippets.new(params[:project_snippet]) @snippet = @project.snippets.build(params[:project_snippet])
@snippet.author = current_user @snippet.author = current_user
@snippet.save @snippet.save
   
Loading
Loading
Loading
@@ -55,7 +55,7 @@ class Ability
Loading
@@ -55,7 +55,7 @@ class Ability
:read_wiki, :read_wiki,
:read_issue, :read_issue,
:read_milestone, :read_milestone,
:read_snippet, :read_project_snippet,
:read_team_member, :read_team_member,
:read_merge_request, :read_merge_request,
:read_note, :read_note,
Loading
@@ -68,7 +68,7 @@ class Ability
Loading
@@ -68,7 +68,7 @@ class Ability
def project_report_rules def project_report_rules
project_guest_rules + [ project_guest_rules + [
:download_code, :download_code,
:write_snippet :write_project_snippet
] ]
end end
   
Loading
@@ -84,11 +84,11 @@ class Ability
Loading
@@ -84,11 +84,11 @@ class Ability
project_dev_rules + [ project_dev_rules + [
:push_code_to_protected_branches, :push_code_to_protected_branches,
:modify_issue, :modify_issue,
:modify_snippet, :modify_project_snippet,
:modify_merge_request, :modify_merge_request,
:admin_issue, :admin_issue,
:admin_milestone, :admin_milestone,
:admin_snippet, :admin_project_snippet,
:admin_team_member, :admin_team_member,
:admin_merge_request, :admin_merge_request,
:admin_note, :admin_note,
Loading
Loading
Loading
@@ -408,7 +408,7 @@ module Gitlab
Loading
@@ -408,7 +408,7 @@ module Gitlab
# Example Request: # Example Request:
# POST /projects/:id/snippets # POST /projects/:id/snippets
post ":id/snippets" do post ":id/snippets" do
authorize! :write_snippet, user_project authorize! :write_project_snippet, user_project
required_attributes! [:title, :file_name, :code] required_attributes! [:title, :file_name, :code]
   
attrs = attributes_for_keys [:title, :file_name] attrs = attributes_for_keys [:title, :file_name]
Loading
@@ -437,7 +437,7 @@ module Gitlab
Loading
@@ -437,7 +437,7 @@ module Gitlab
# PUT /projects/:id/snippets/:snippet_id # PUT /projects/:id/snippets/:snippet_id
put ":id/snippets/:snippet_id" do put ":id/snippets/:snippet_id" do
@snippet = user_project.snippets.find(params[:snippet_id]) @snippet = user_project.snippets.find(params[:snippet_id])
authorize! :modify_snippet, @snippet authorize! :modify_project_snippet, @snippet
   
attrs = attributes_for_keys [:title, :file_name] attrs = attributes_for_keys [:title, :file_name]
attrs[:expires_at] = params[:lifetime] if params[:lifetime].present? attrs[:expires_at] = params[:lifetime] if params[:lifetime].present?
Loading
@@ -460,7 +460,7 @@ module Gitlab
Loading
@@ -460,7 +460,7 @@ module Gitlab
delete ":id/snippets/:snippet_id" do delete ":id/snippets/:snippet_id" do
begin begin
@snippet = user_project.snippets.find(params[:snippet_id]) @snippet = user_project.snippets.find(params[:snippet_id])
authorize! :modify_snippet, user_project authorize! :modify_project_snippet, @snippet
@snippet.destroy @snippet.destroy
rescue rescue
end end
Loading
Loading
Loading
@@ -10,7 +10,7 @@ describe GitlabMarkdownHelper do
Loading
@@ -10,7 +10,7 @@ describe GitlabMarkdownHelper do
let(:commit) { CommitDecorator.decorate(project.repository.commit) } let(:commit) { CommitDecorator.decorate(project.repository.commit) }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, project: project) } let(:merge_request) { create(:merge_request, project: project) }
let(:snippet) { create(:snippet, project: project) } let(:snippet) { create(:project_snippet, project: project) }
let(:member) { project.users_projects.where(user_id: user).first } let(:member) { project.users_projects.where(user_id: user).first }
   
before do before do
Loading
@@ -190,8 +190,43 @@ describe GitlabMarkdownHelper do
Loading
@@ -190,8 +190,43 @@ describe GitlabMarkdownHelper do
describe "referencing a snippet" do describe "referencing a snippet" do
let(:object) { snippet } let(:object) { snippet }
let(:reference) { "$#{snippet.id}" } let(:reference) { "$#{snippet.id}" }
let(:actual) { "Reference to #{reference}" }
let(:expected) { project_snippet_path(project, object) }
it "should link using a valid id" do
gfm(actual).should match(expected)
end
it "should link with adjacent text" do
# Wrap the reference in parenthesis
gfm(actual.gsub(reference, "(#{reference})")).should match(expected)
# Append some text to the end of the reference
gfm(actual.gsub(reference, "#{reference}, right?")).should match(expected)
end
it "should keep whitespace intact" do
actual = "Referenced #{reference} already."
expected = /Referenced <a.+>[^\s]+<\/a> already/
gfm(actual).should match(expected)
end
it "should not link with an invalid id" do
# Modify the reference string so it's still parsed, but is invalid
reference.gsub!(/^(.)(\d+)$/, '\1' + ('\2' * 2))
gfm(actual).should == actual
end
it "should include a title attribute" do
title = "Snippet: #{object.title}"
gfm(actual).should match(/title="#{title}"/)
end
it "should include standard gfm classes" do
css = object.class.to_s.underscore
gfm(actual).should match(/class="\s?gfm gfm-snippet\s?"/)
end
   
include_examples 'referenced object'
end end
   
describe "referencing multiple objects" do describe "referencing multiple objects" do
Loading
Loading
Loading
@@ -34,7 +34,7 @@ describe Project do
Loading
@@ -34,7 +34,7 @@ describe Project do
it { should have_many(:milestones).dependent(:destroy) } it { should have_many(:milestones).dependent(:destroy) }
it { should have_many(:users_projects).dependent(:destroy) } it { should have_many(:users_projects).dependent(:destroy) }
it { should have_many(:notes).dependent(:destroy) } it { should have_many(:notes).dependent(:destroy) }
it { should have_many(:snippets).dependent(:destroy) } it { should have_many(:project_snippets).class_name('ProjectSnippet').dependent(:destroy) }
it { should have_many(:deploy_keys).dependent(:destroy) } it { should have_many(:deploy_keys).dependent(:destroy) }
it { should have_many(:hooks).dependent(:destroy) } it { should have_many(:hooks).dependent(:destroy) }
it { should have_many(:wikis).dependent(:destroy) } it { should have_many(:wikis).dependent(:destroy) }
Loading
Loading
Loading
@@ -7,7 +7,7 @@ describe Gitlab::API do
Loading
@@ -7,7 +7,7 @@ describe Gitlab::API do
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, project: project, author: user) } let!(:issue) { create(:issue, project: project, author: user) }
let!(:merge_request) { create(:merge_request, project: project, author: user) } let!(:merge_request) { create(:merge_request, project: project, author: user) }
let!(:snippet) { create(:snippet, project: project, author: user) } let!(:snippet) { create(:project_snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) } let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) } let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
Loading
Loading
Loading
@@ -9,7 +9,7 @@ describe Gitlab::API do
Loading
@@ -9,7 +9,7 @@ describe Gitlab::API do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
let!(:hook) { create(:project_hook, project: project, url: "http://example.com") } let!(:hook) { create(:project_hook, project: project, url: "http://example.com") }
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } let!(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') }
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
let(:key) { create(:key, project: project) } let(:key) { create(:key, project: project) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment