2016-12-26 10:07:40 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
RSpec.describe WikiDirectory do
|
2016-12-26 10:07:40 -05:00
|
|
|
describe 'validations' do
|
|
|
|
subject { build(:wiki_directory) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:slug) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#initialize' do
|
2016-12-31 14:27:03 -05:00
|
|
|
context 'when there are pages' do
|
2016-12-26 10:07:40 -05:00
|
|
|
let(:pages) { [build(:wiki_page)] }
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:directory) { described_class.new('/path_up_to/dir', pages) }
|
2016-12-26 10:07:40 -05:00
|
|
|
|
|
|
|
it 'sets the slug attribute' do
|
|
|
|
expect(directory.slug).to eq('/path_up_to/dir')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the pages attribute' do
|
|
|
|
expect(directory.pages).to eq(pages)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-31 14:27:03 -05:00
|
|
|
context 'when there are no pages' do
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:directory) { described_class.new('/path_up_to/dir') }
|
2016-12-26 10:07:40 -05:00
|
|
|
|
|
|
|
it 'sets the slug attribute' do
|
|
|
|
expect(directory.slug).to eq('/path_up_to/dir')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the pages attribute to an empty array' do
|
|
|
|
expect(directory.pages).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-26 20:52:26 -05:00
|
|
|
|
|
|
|
describe '#to_partial_path' do
|
|
|
|
it 'returns the relative path to the partial to be used' do
|
|
|
|
directory = build(:wiki_directory)
|
|
|
|
|
|
|
|
expect(directory.to_partial_path).to eq('projects/wikis/wiki_directory')
|
|
|
|
end
|
|
|
|
end
|
2016-12-26 10:07:40 -05:00
|
|
|
end
|