2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-24 15:26:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe ProjectSnippet do
|
2013-03-24 15:26:49 +00:00
|
|
|
describe "Associations" do
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to belong_to(:project) }
|
2013-03-24 15:26:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Validation" do
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
2019-11-19 06:06:07 +00:00
|
|
|
it { is_expected.to validate_inclusion_of(:secret).in_array([false]) }
|
2013-03-24 15:26:49 +00:00
|
|
|
end
|
2019-11-08 09:06:07 +00:00
|
|
|
|
|
|
|
describe '#embeddable?' do
|
|
|
|
[
|
|
|
|
{ project: :public, snippet: :public, embeddable: true },
|
|
|
|
{ project: :internal, snippet: :public, embeddable: false },
|
|
|
|
{ project: :private, snippet: :public, embeddable: false },
|
|
|
|
{ project: :public, snippet: :internal, embeddable: false },
|
|
|
|
{ project: :internal, snippet: :internal, embeddable: false },
|
|
|
|
{ project: :private, snippet: :internal, embeddable: false },
|
|
|
|
{ project: :public, snippet: :private, embeddable: false },
|
|
|
|
{ project: :internal, snippet: :private, embeddable: false },
|
|
|
|
{ project: :private, snippet: :private, embeddable: false }
|
|
|
|
].each do |combination|
|
|
|
|
it 'only returns true when both project and snippet are public' do
|
|
|
|
project = create(:project, combination[:project])
|
|
|
|
snippet = build(:project_snippet, combination[:snippet], project: project)
|
|
|
|
|
|
|
|
expect(snippet.embeddable?).to eq(combination[:embeddable])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-13 15:08:52 +00:00
|
|
|
|
|
|
|
it_behaves_like 'model with repository' do
|
|
|
|
let_it_be(:container) { create(:project_snippet, :repository) }
|
|
|
|
let(:stubbed_container) { build_stubbed(:project_snippet) }
|
2020-10-27 18:08:59 +00:00
|
|
|
let(:expected_full_path) { "#{container.project.full_path}/snippets/#{container.id}" }
|
2020-07-23 15:09:28 +00:00
|
|
|
let(:expected_web_url_path) { "#{container.project.full_path}/-/snippets/#{container.id}" }
|
2020-02-13 15:08:52 +00:00
|
|
|
end
|
2013-03-24 15:26:49 +00:00
|
|
|
end
|