2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ProjectSnippet do
|
2014-09-02 18:07:02 +05:30
|
|
|
describe "Associations" do
|
2015-04-26 12:48:37 +05:30
|
|
|
it { is_expected.to belong_to(:project) }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "Validation" do
|
2015-04-26 12:48:37 +05:30
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
2020-01-01 13:55:28 +05:30
|
|
|
it { is_expected.to validate_inclusion_of(:secret).in_array([false]) }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
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-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
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}" }
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:expected_web_url_path) { "#{container.project.full_path}/-/snippets/#{container.id}" }
|
|
|
|
let(:expected_repo_url_path) { "#{container.project.full_path}/snippets/#{container.id}" }
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|