2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-24 11:26:49 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe ProjectSnippet do
|
2013-03-24 11:26:49 -04:00
|
|
|
describe "Associations" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to belong_to(:project) }
|
2013-03-24 11:26:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Validation" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
2019-11-19 01:06:07 -05:00
|
|
|
it { is_expected.to validate_inclusion_of(:secret).in_array([false]) }
|
2013-03-24 11:26:49 -04:00
|
|
|
end
|
2019-11-08 04:06:07 -05: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 10:08:52 -05:00
|
|
|
|
|
|
|
it_behaves_like 'model with repository' do
|
|
|
|
let_it_be(:container) { create(:project_snippet, :repository) }
|
|
|
|
let(:stubbed_container) { build_stubbed(:project_snippet) }
|
|
|
|
let(:expected_full_path) { "#{container.project.full_path}/@snippets/#{container.id}" }
|
|
|
|
let(:expected_repository_klass) { Repository }
|
|
|
|
let(:expected_storage_klass) { Storage::Hashed }
|
|
|
|
let(:expected_web_url_path) { "#{container.project.full_path}/snippets/#{container.id}" }
|
|
|
|
end
|
2013-03-24 11:26:49 -04:00
|
|
|
end
|