project_snippet_spec.rb 1.75 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
RSpec.describe ProjectSnippet do
6
  describe "Associations" do
7
    it { is_expected.to belong_to(:project) }
8 9 10
  end

  describe "Validation" do
11
    it { is_expected.to validate_presence_of(:project) }
12
    it { is_expected.to validate_inclusion_of(:secret).in_array([false]) }
13
  end
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

  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
35 36 37 38 39

  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}" }
40 41
    let(:expected_web_url_path) { "#{container.project.full_path}/-/snippets/#{container.id}" }
    let(:expected_repo_url_path) { "#{container.project.full_path}/snippets/#{container.id}" }
42
  end
43
end