2012-10-09 04:14:17 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: snippets
|
|
|
|
#
|
2014-10-09 11:22:20 -04:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# title :string(255)
|
|
|
|
# content :text
|
|
|
|
# author_id :integer not null
|
|
|
|
# project_id :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# file_name :string(255)
|
|
|
|
# expires_at :datetime
|
|
|
|
# type :string(255)
|
|
|
|
# visibility_level :integer default(0), not null
|
2012-10-09 04:14:17 -04:00
|
|
|
#
|
|
|
|
|
2011-10-16 17:07:10 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Snippet do
|
2015-05-02 23:11:21 -04:00
|
|
|
describe 'modules' do
|
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
it { is_expected.to include_module(Gitlab::VisibilityLevel) }
|
|
|
|
it { is_expected.to include_module(Linguist::BlobHelper) }
|
|
|
|
it { is_expected.to include_module(Participable) }
|
|
|
|
it { is_expected.to include_module(Referable) }
|
|
|
|
it { is_expected.to include_module(Sortable) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'associations' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to belong_to(:author).class_name('User') }
|
2015-05-02 23:14:31 -04:00
|
|
|
it { is_expected.to belong_to(:project) }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to have_many(:notes).dependent(:destroy) }
|
2011-10-16 17:07:10 -04:00
|
|
|
end
|
|
|
|
|
2015-05-02 23:14:31 -04:00
|
|
|
describe 'validation' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to validate_presence_of(:author) }
|
2012-08-29 11:36:02 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to validate_presence_of(:title) }
|
2015-05-18 16:40:10 -04:00
|
|
|
it { is_expected.to validate_length_of(:title).is_within(0..255) }
|
2012-08-29 11:36:02 -04:00
|
|
|
|
2015-05-18 16:40:10 -04:00
|
|
|
it { is_expected.to validate_length_of(:file_name).is_within(0..255) }
|
2012-08-29 11:36:02 -04:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to validate_presence_of(:content) }
|
2015-05-02 23:14:31 -04:00
|
|
|
|
|
|
|
it { is_expected.to validate_inclusion_of(:visibility_level).in_array(Gitlab::VisibilityLevel.values) }
|
2011-10-16 17:07:10 -04:00
|
|
|
end
|
2015-05-02 23:11:21 -04:00
|
|
|
|
|
|
|
describe '#to_reference' do
|
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:snippet) { create(:snippet, project: project) }
|
|
|
|
|
|
|
|
it 'returns a String reference to the object' do
|
|
|
|
expect(snippet.to_reference).to eq "$#{snippet.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports a cross-project reference' do
|
|
|
|
cross = double('project')
|
|
|
|
expect(snippet.to_reference(cross)).to eq "#{project.to_reference}$#{snippet.id}"
|
|
|
|
end
|
|
|
|
end
|
2011-10-16 17:07:10 -04:00
|
|
|
end
|