Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

replace legacy spec

ulfertsd327d589364a
diff --git a/spec/models/wiki_content_spec.rb b/spec/models/wiki_content_spec.rb
index 8d9493f8243..4e00689112c 100644
--- a/spec/models/wiki_content_spec.rb
+++ b/spec/models/wiki_content_spec.rb
@@ -29,29 +29,22 @@
require 'spec_helper'
describe WikiContent, type: :model do
- let(:wiki) { FactoryBot.create(:wiki) }
- let(:page) { FactoryBot.create(:wiki_page, wiki: wiki) }
let(:content) { FactoryBot.create(:wiki_content, page: page, author: author) }
- let(:author) do
+
+ shared_let(:wiki) { FactoryBot.create(:wiki) }
+ shared_let(:page) { FactoryBot.create(:wiki_page, wiki: wiki) }
+ shared_let(:author) do
FactoryBot.create(:user,
member_in_project: wiki.project,
member_with_permissions: [:view_wiki_pages])
end
- let(:project_watcher) do
+ shared_let(:project_watcher) do
FactoryBot.create(:user,
member_in_project: wiki.project,
member_with_permissions: [:view_wiki_pages])
end
- let(:page_watcher) do
- watcher = FactoryBot.create(:user,
- member_in_project: wiki.project,
- member_with_permissions: [:view_wiki_pages])
- page.watcher_users << watcher
-
- watcher
- end
- let(:wiki_watcher) do
+ shared_let(:wiki_watcher) do
watcher = FactoryBot.create(:user,
member_in_project: wiki.project,
member_with_permissions: [:view_wiki_pages])
@@ -60,39 +53,134 @@ describe WikiContent, type: :model do
watcher
end
- describe '#save (create)' do
- let(:content) { FactoryBot.build(:wiki_content, page: page) }
+ describe 'mail sending' do
+ context 'when creating' do
+ let(:content) { FactoryBot.build(:wiki_content, page: page) }
+
+ it 'sends mails to the wiki`s watchers and project all watchers' do
+ expect do
+ perform_enqueued_jobs do
+ User.execute_as(author) do
+ content.save!
+ end
+ end
+ end
+ .to change { ActionMailer::Base.deliveries.size }
+ .by(2)
+ end
+ end
- it 'sends mails to the wiki`s watchers and project all watchers' do
- wiki_watcher
- project_watcher
+ context 'when updating',
+ with_settings: { journal_aggregation_time_minutes: 0 } do
+ let(:page_watcher) do
+ watcher = FactoryBot.create(:user,
+ member_in_project: wiki.project,
+ member_with_permissions: [:view_wiki_pages])
+ page.watcher_users << watcher
- expect do
- perform_enqueued_jobs do
- content.save!
+ watcher
+ end
+
+ before do
+ page_watcher
+
+ content.text = 'My new content'
+ end
+
+ it 'sends mails to the watchers, the wiki`s watchers and project all watchers' do
+ expect do
+ perform_enqueued_jobs do
+ User.execute_as(author) do
+ content.save!
+ end
+ end
end
+ .to change { ActionMailer::Base.deliveries.size }
+ .by(3)
end
- .to change { ActionMailer::Base.deliveries.size }
- .by(2)
end
end
- describe '#save (update)' do
- it 'sends mails to the watchers, the wiki`s watchers and project all watchers',
- with_settings: { journal_aggregation_time_minutes: 0 } do
- page_watcher
- wiki_watcher
- project_watcher
+ describe '#version',
+ with_settings: { journal_aggregation_time_minutes: 0 } do
+ context 'when updating' do
+ it 'updates the version' do
+ content.text = 'My new content'
- content.text = 'My new content'
+ expect { content.save! }
+ .to change(content, :version)
+ .by(1)
+ end
+ end
- expect do
- perform_enqueued_jobs do
- content.save!
- end
+ context 'when creating' do
+ it 'sets the version to 1' do
+ content.save!
+
+ expect(content.version)
+ .to be 1
end
- .to change { ActionMailer::Base.deliveries.size }
- .by(3)
+ end
+
+ context 'when new' do
+ it 'starts with 0' do
+ content = described_class.new(text: 'a', author: author, page: page)
+
+ expect(content.version)
+ .to be 0
+ end
+ end
+ end
+
+ describe '#author' do
+ it 'sets the author' do
+ expect(content.author)
+ .to eql author
+ end
+ end
+
+ describe '#journals',
+ with_settings: { journal_aggregation_time_minutes: 0 } do
+ context 'when creating' do
+ it 'adds a journal' do
+ expect(content.journals.count)
+ .to be 1
+ end
+
+ it 'journalizes the text' do
+ expect(content.journals.last.data.text)
+ .to eql content.text
+ end
+ end
+
+ context 'when updating' do
+ let(:text) { 'My new content' }
+
+ before do
+ content.text = text
+ end
+
+ it 'adds a journal' do
+ expect { content.save! }
+ .to change(content.journals, :count)
+ .by(1)
+ end
+
+ it 'journalizes the text' do
+ content.save!
+
+ expect(content.journals.last.data.text)
+ .to eql content.text
+ end
+ end
+ end
+
+ describe '#text' do
+ it 'doe not truncate to 64k' do
+ content = described_class.create(text: 'a' * 500.kilobyte, author: author, page: page)
+ content.reload
+ expect(content.text.size)
+ .to eql(500.kilobyte)
end
end
end
diff --git a/spec_legacy/unit/wiki_content_spec.rb b/spec_legacy/unit/wiki_content_spec.rb
deleted file mode 100644
index 4850336a1f5..00000000000
--- a/spec_legacy/unit/wiki_content_spec.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-#-- encoding: UTF-8
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../legacy_spec_helper'
-
-describe WikiContent, type: :model do
- fixtures :all
-
- before do
- @wiki = Wiki.find(1)
- @page = @wiki.pages.first
- end
-
- it 'should create' do
- page = WikiPage.new(wiki: @wiki, title: 'Page')
- page.content = WikiContent.new(text: 'Content text', author: User.find(1))
- assert page.save
- page.reload
-
- content = page.content
- assert_kind_of WikiContent, content
- assert_equal 1, content.version
- assert_equal 1, content.journals.length
- assert_equal 'Content text', content.text
- assert_equal User.find(1), content.author
- assert_equal content.text, content.journals.last.data.text
- end
-
- it 'should update' do
- content = @page.content
- version_count = content.version
- content.text = 'My new content'
- assert content.save
- content.reload
- assert_equal version_count + 1, content.version
- assert_equal version_count + 1, content.journals.length
- end
-
- it 'should fetch history' do
- wiki_content_journal = FactoryBot.create(:wiki_content_journal,
- journable: @page.content)
- wiki_content_journal.data.update(page_id: @page.id, text: '')
-
- @page.content.journals.each do |journal|
- assert_kind_of String, journal.data.text
- end
- end
-
- it 'should large text should not be truncated to 64k' do
- page = WikiPage.new(wiki: @wiki, title: 'Big page')
- page.content = WikiContent.new(text: 'a' * 500.kilobyte, author: User.find(1))
- assert page.save
- page.reload
- assert_equal 500.kilobyte, page.content.text.size
- end
-
- specify 'new WikiContent is version 0' do
- page = WikiPage.new(wiki: @wiki, title: 'Page')
- page.content = WikiContent.new(text: 'Content text', author: User.find(1))
-
- assert_equal 0, page.content.version
- end
-end