BigW Consortium Gitlab

Commit b361a67f by Alex Braha Stoll

Add model WikiDirectory

parent 8d8c5d9f
class WikiDirectory
include ActiveModel::Validations
attr_accessor :slug, :pages, :directories
validates :slug, presence: true
def initialize(slug, pages = [], directories = [])
@slug = slug
@pages = pages
@directories = directories
end
end
FactoryGirl.define do
factory :wiki_directory do
slug '/path_up_to/dir'
initialize_with { new(slug) }
end
end
require 'spec_helper'
RSpec.describe WikiDirectory, models: true do
describe 'validations' do
subject { build(:wiki_directory) }
it { is_expected.to validate_presence_of(:slug) }
end
describe '#initialize' do
context 'when there are pages and directories' do
let(:pages) { [build(:wiki_page)] }
let(:other_directories) { [build(:wiki_directory)] }
let(:directory) { WikiDirectory.new('/path_up_to/dir', pages, other_directories) }
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
it 'sets the directories attribute' do
expect(directory.directories).to eq(other_directories)
end
end
context 'when there are no pages or directories' do
let(:directory) { WikiDirectory.new('/path_up_to/dir') }
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
it 'sets the directories attribute to an empty array' do
expect(directory.directories).to eq([])
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment