Commit d4543eb5 authored by Andrew8xx8's avatar Andrew8xx8

Tests fixed

parent 611ac727
......@@ -23,11 +23,11 @@ class Projects::SnippetsController < Projects::ApplicationController
end
def new
@snippet = @project.snippets.new
@snippet = @project.snippets.build
end
def create
@snippet = @project.snippets.new(params[:project_snippet])
@snippet = @project.snippets.build(params[:project_snippet])
@snippet.author = current_user
@snippet.save
......
......@@ -55,7 +55,7 @@ class Ability
:read_wiki,
:read_issue,
:read_milestone,
:read_snippet,
:read_project_snippet,
:read_team_member,
:read_merge_request,
:read_note,
......@@ -68,7 +68,7 @@ class Ability
def project_report_rules
project_guest_rules + [
:download_code,
:write_snippet
:write_project_snippet
]
end
......@@ -84,11 +84,11 @@ class Ability
project_dev_rules + [
:push_code_to_protected_branches,
:modify_issue,
:modify_snippet,
:modify_project_snippet,
:modify_merge_request,
:admin_issue,
:admin_milestone,
:admin_snippet,
:admin_project_snippet,
:admin_team_member,
:admin_merge_request,
:admin_note,
......
......@@ -408,7 +408,7 @@ module Gitlab
# Example Request:
# POST /projects/:id/snippets
post ":id/snippets" do
authorize! :write_snippet, user_project
authorize! :write_project_snippet, user_project
required_attributes! [:title, :file_name, :code]
attrs = attributes_for_keys [:title, :file_name]
......@@ -437,7 +437,7 @@ module Gitlab
# PUT /projects/:id/snippets/:snippet_id
put ":id/snippets/:snippet_id" do
@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[:expires_at] = params[:lifetime] if params[:lifetime].present?
......@@ -460,7 +460,7 @@ module Gitlab
delete ":id/snippets/:snippet_id" do
begin
@snippet = user_project.snippets.find(params[:snippet_id])
authorize! :modify_snippet, user_project
authorize! :modify_project_snippet, @snippet
@snippet.destroy
rescue
end
......
......@@ -10,7 +10,7 @@ describe GitlabMarkdownHelper do
let(:commit) { CommitDecorator.decorate(project.repository.commit) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, project: project) }
let(:snippet) { create(:snippet, project: project) }
let(:snippet) { create(:project_snippet, project: project) }
let(:member) { project.users_projects.where(user_id: user).first }
before do
......@@ -190,8 +190,43 @@ describe GitlabMarkdownHelper do
describe "referencing a snippet" do
let(:object) { snippet }
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
describe "referencing multiple objects" do
......
......@@ -34,7 +34,7 @@ describe Project do
it { should have_many(:milestones).dependent(:destroy) }
it { should have_many(:users_projects).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(:hooks).dependent(:destroy) }
it { should have_many(:wikis).dependent(:destroy) }
......
......@@ -7,7 +7,7 @@ describe Gitlab::API do
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, 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!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
......
......@@ -9,7 +9,7 @@ describe Gitlab::API do
let(:admin) { create(:admin) }
let!(:project) { create(:project, namespace: user.namespace ) }
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_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
let(:key) { create(:key, project: project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment