summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Braha Stoll <alexbrahastoll@gmail.com>2016-12-26 13:07:40 -0200
committerAlex Braha Stoll <alexbrahastoll@gmail.com>2016-12-31 16:55:50 -0200
commitb361a67fb019e5c7f5361bbd3c43545da3ab0288 (patch)
treed18bc1aa00d3f54fc77941dc65a6292d3c9af460
parent8d8c5d9f61491c63e89d73a3f77244d3cd6406da (diff)
downloadgitlab-ce-b361a67fb019e5c7f5361bbd3c43545da3ab0288.tar.gz
Add model WikiDirectory
-rw-r--r--app/models/wiki_directory.rb13
-rw-r--r--spec/factories/wiki_directories.rb6
-rw-r--r--spec/models/wiki_directory_spec.rb45
3 files changed, 64 insertions, 0 deletions
diff --git a/app/models/wiki_directory.rb b/app/models/wiki_directory.rb
new file mode 100644
index 00000000000..c126a4d0421
--- /dev/null
+++ b/app/models/wiki_directory.rb
@@ -0,0 +1,13 @@
+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
diff --git a/spec/factories/wiki_directories.rb b/spec/factories/wiki_directories.rb
new file mode 100644
index 00000000000..3f3c864ac2b
--- /dev/null
+++ b/spec/factories/wiki_directories.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :wiki_directory do
+ slug '/path_up_to/dir'
+ initialize_with { new(slug) }
+ end
+end
diff --git a/spec/models/wiki_directory_spec.rb b/spec/models/wiki_directory_spec.rb
new file mode 100644
index 00000000000..8362a285c54
--- /dev/null
+++ b/spec/models/wiki_directory_spec.rb
@@ -0,0 +1,45 @@
+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