debian-mirror-gitlab/spec/services/update_snippet_service_spec.rb

49 lines
1.6 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe UpdateSnippetService, services: true do
2015-04-26 12:48:37 +05:30
before do
@user = create :user
@admin = create :user, admin: true
@opts = {
title: 'Test snippet',
file_name: 'snippet.rb',
content: 'puts "hello world"',
visibility_level: Gitlab::VisibilityLevel::PRIVATE
}
end
context 'When public visibility is restricted' do
before do
2015-09-11 14:41:01 +05:30
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
2015-04-26 12:48:37 +05:30
@snippet = create_snippet(@project, @user, @opts)
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end
it 'non-admins should not be able to update to public visibility' do
old_visibility = @snippet.visibility_level
update_snippet(@project, @user, @snippet, @opts)
expect(@snippet.errors.messages).to have_key(:visibility_level)
expect(@snippet.errors.messages[:visibility_level].first).to(
2016-06-02 11:05:42 +05:30
match('has been restricted')
2015-04-26 12:48:37 +05:30
)
expect(@snippet.visibility_level).to eq(old_visibility)
end
it 'admins should be able to update to pubic visibility' do
old_visibility = @snippet.visibility_level
update_snippet(@project, @admin, @snippet, @opts)
expect(@snippet.visibility_level).not_to eq(old_visibility)
expect(@snippet.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
end
def create_snippet(project, user, opts)
CreateSnippetService.new(project, user, opts).execute
end
2015-12-23 02:04:40 +05:30
def update_snippet(project, user, snippet, opts)
2015-04-26 12:48:37 +05:30
UpdateSnippetService.new(project, user, snippet, opts).execute
end
end