@ -31,7 +31,9 @@ require 'spec_helper'
describe WikiPage , type : :model do
describe WikiPage , type : :model do
let ( :project ) { FactoryBot . create ( :project ) . reload } # a wiki is created for project, but the object doesn't know of it (FIXME?)
let ( :project ) { FactoryBot . create ( :project ) . reload } # a wiki is created for project, but the object doesn't know of it (FIXME?)
let ( :wiki ) { project . wiki }
let ( :wiki ) { project . wiki }
let ( :wiki_page ) { FactoryBot . create ( :wiki_page , wiki : wiki , title : wiki . wiki_menu_items . first . title ) }
let ( :title ) { wiki . wiki_menu_items . first . title }
let ( :wiki_page ) { FactoryBot . create ( :wiki_page , wiki : wiki , title : title ) }
let ( :new_wiki_page ) { FactoryBot . build ( :wiki_page , wiki : wiki , title : title ) }
it_behaves_like 'acts_as_watchable included' do
it_behaves_like 'acts_as_watchable included' do
let ( :model_instance ) { FactoryBot . create ( :wiki_page ) }
let ( :model_instance ) { FactoryBot . create ( :wiki_page ) }
@ -66,6 +68,23 @@ describe WikiPage, type: :model do
expect ( wiki_page . slug ) . to eq ( 'dot' )
expect ( wiki_page . slug ) . to eq ( 'dot' )
end
end
end
end
context 'when only having a ! for the title' do
let ( :wiki_page ) { FactoryBot . create ( :wiki_page , wiki : wiki , title : '!' ) }
it 'creates a non empty slug' do
expect ( wiki_page . slug ) . to eq ( 'bang' )
end
end
context 'when only having a { for the title' do
let ( :wiki_page ) { FactoryBot . create ( :wiki_page , wiki : wiki , title : '{' ) }
it 'fails to create' do
expect { wiki_page }
. to raise_error ( ActiveRecord :: RecordInvalid )
end
end
end
end
describe '#nearest_main_item' do
describe '#nearest_main_item' do
@ -83,7 +102,7 @@ describe WikiPage, type: :model do
describe '#destroy' do
describe '#destroy' do
context 'when the only wiki page is destroyed' do
context 'when the only wiki page is destroyed' do
before :each do
before do
wiki_page . destroy
wiki_page . destroy
end
end
@ -94,7 +113,7 @@ describe WikiPage, type: :model do
end
end
context 'when one of two wiki pages is destroyed' do
context 'when one of two wiki pages is destroyed' do
before :each do
before do
FactoryBot . create ( :wiki_page , wiki : wiki )
FactoryBot . create ( :wiki_page , wiki : wiki )
wiki_page . destroy
wiki_page . destroy
end
end
@ -106,6 +125,26 @@ describe WikiPage, type: :model do
end
end
end
end
describe '#title' do
context 'when it is blank' do
let ( :title ) { nil }
it 'is invalid' do
new_wiki_page . valid?
expect ( new_wiki_page . errors . symbols_for ( :title ) )
. to match_array [ :blank ]
end
end
end
describe '#protected?' do
it 'is false by default' do
expect ( wiki_page . reload )
. not_to be_protected
end
end
describe '#project' do
describe '#project' do
it 'is the same as the project on wiki' do
it 'is the same as the project on wiki' do
expect ( wiki_page . project ) . to eql ( wiki . project )
expect ( wiki_page . project ) . to eql ( wiki . project )