diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index da9dfdd22bd..f2a2c6e35f8 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -62,7 +62,7 @@ class MessagesController < ApplicationController
# new topic
def new
- Messages::SetAttributesService
+ @message = Messages::SetAttributesService
.new(user: current_user,
model: Message.new,
contract_class: NoopContract)
diff --git a/app/models/announcement.rb b/app/models/announcement.rb
index e436f43c025..bcb4033fb37 100644
--- a/app/models/announcement.rb
+++ b/app/models/announcement.rb
@@ -1,4 +1,4 @@
-class Announcement < ActiveRecord::Base
+class Announcement < ApplicationRecord
scope :active, -> { where(active: true) }
scope :current, -> { where('show_until >= ?', Date.today) }
diff --git a/app/models/application_record.rb b/app/models/application_record.rb
index e75358a7dce..bdd23013245 100644
--- a/app/models/application_record.rb
+++ b/app/models/application_record.rb
@@ -1,6 +1,12 @@
-class ApplicationRecord < ActiveRecord::Base
+class ApplicationRecord < ::ActiveRecord::Base
self.abstract_class = true
+ ##
+ # Refind this instance fresh from the database
+ def refind!
+ self.class.find(self.class.primary_key)
+ end
+
##
# Get the newest recently changed resource for the given record classes
#
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 5b36c930b7c..cec5d4673ae 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -30,7 +30,7 @@
require 'digest/md5'
-class Attachment < ActiveRecord::Base
+class Attachment < ApplicationRecord
ALLOWED_TEXT_TYPES = %w[text/plain].freeze
ALLOWED_IMAGE_TYPES = %w[image/gif image/jpeg image/png image/tiff image/bmp].freeze
diff --git a/app/models/attribute_help_text.rb b/app/models/attribute_help_text.rb
index 2169b1a6598..93af7a315b2 100644
--- a/app/models/attribute_help_text.rb
+++ b/app/models/attribute_help_text.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class AttributeHelpText < ActiveRecord::Base
+class AttributeHelpText < ApplicationRecord
def self.available_types
subclasses.map { |child| child.name.demodulize }
end
diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb
index b49c1b13beb..c5ef62a190e 100644
--- a/app/models/auth_source.rb
+++ b/app/models/auth_source.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class AuthSource < ActiveRecord::Base
+class AuthSource < ApplicationRecord
include Redmine::Ciphering
has_many :users
diff --git a/app/models/category.rb b/app/models/category.rb
index 1db15e12455..fb631b3f26c 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Category < ActiveRecord::Base
+class Category < ApplicationRecord
belongs_to :project
belongs_to :assigned_to, class_name: 'Principal', foreign_key: 'assigned_to_id'
has_many :work_packages, foreign_key: 'category_id', dependent: :nullify
diff --git a/app/models/change.rb b/app/models/change.rb
index 005f7be3717..632842d783e 100644
--- a/app/models/change.rb
+++ b/app/models/change.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Change < ActiveRecord::Base
+class Change < ApplicationRecord
belongs_to :changeset
validates_presence_of :changeset_id, :action, :path
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index e8ee7a675bf..324701732d4 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Changeset < ActiveRecord::Base
+class Changeset < ApplicationRecord
belongs_to :repository
belongs_to :user
has_many :file_changes, class_name: 'Change', dependent: :delete_all
diff --git a/app/models/color.rb b/app/models/color.rb
index ecb6e46783e..04139767781 100644
--- a/app/models/color.rb
+++ b/app/models/color.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Color < ActiveRecord::Base
+class Color < ApplicationRecord
self.table_name = 'colors'
has_many :planning_element_types, class_name: 'Type',
diff --git a/app/models/comment.rb b/app/models/comment.rb
index ebf5785d3f3..af3eb2579da 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Comment < ActiveRecord::Base
+class Comment < ApplicationRecord
belongs_to :commented, polymorphic: true, counter_cache: true
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
diff --git a/app/models/custom_action.rb b/app/models/custom_action.rb
index 492c42466c9..57bfc7f2be7 100644
--- a/app/models/custom_action.rb
+++ b/app/models/custom_action.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class CustomAction < ActiveRecord::Base
+class CustomAction < ApplicationRecord
validates :name, length: { maximum: 255, minimum: 1 }
serialize :actions, CustomActions::Actions::Serializer
has_and_belongs_to_many :status_conditions, class_name: 'Status'
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index deaf6232b90..d8f1ba92d69 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class CustomField < ActiveRecord::Base
+class CustomField < ApplicationRecord
include CustomField::OrderStatements
has_many :custom_values, dependent: :delete_all
diff --git a/app/models/custom_option.rb b/app/models/custom_option.rb
index b01dab1cfbb..06004df58aa 100644
--- a/app/models/custom_option.rb
+++ b/app/models/custom_option.rb
@@ -31,7 +31,7 @@
##
# A custom option is a possible value for a given custom field
# which is restricted to a set of specific values.
-class CustomOption < ActiveRecord::Base
+class CustomOption < ApplicationRecord
acts_as_list
belongs_to :custom_field, touch: true
diff --git a/app/models/custom_style.rb b/app/models/custom_style.rb
index 34632b24448..e9b480c6154 100644
--- a/app/models/custom_style.rb
+++ b/app/models/custom_style.rb
@@ -1,4 +1,4 @@
-class CustomStyle < ActiveRecord::Base
+class CustomStyle < ApplicationRecord
mount_uploader :logo, OpenProject::Configuration.file_uploader
mount_uploader :favicon, OpenProject::Configuration.file_uploader
mount_uploader :touch_icon, OpenProject::Configuration.file_uploader
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 8fb60a596f1..28e2857445f 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class CustomValue < ActiveRecord::Base
+class CustomValue < ApplicationRecord
belongs_to :custom_field
belongs_to :customized, polymorphic: true
diff --git a/app/models/design_color.rb b/app/models/design_color.rb
index 6d417de7594..f4df52bd113 100644
--- a/app/models/design_color.rb
+++ b/app/models/design_color.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class DesignColor < ActiveRecord::Base
+class DesignColor < ApplicationRecord
after_commit -> do
# CustomStyle.current.updated_at determins the cache key for inline_css
# in which the CSS color variables will be overwritten. That is why we need
diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb
index f0707acf711..d71e62cec9c 100644
--- a/app/models/enabled_module.rb
+++ b/app/models/enabled_module.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class EnabledModule < ActiveRecord::Base
+class EnabledModule < ApplicationRecord
belongs_to :project
validates :name,
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb
index fe568dda74f..2739b39cde7 100644
--- a/app/models/enterprise_token.rb
+++ b/app/models/enterprise_token.rb
@@ -25,7 +25,7 @@
#
# See docs/COPYRIGHT.rdoc for more details.
#++
-class EnterpriseToken < ActiveRecord::Base
+class EnterpriseToken < ApplicationRecord
class << self
def current
RequestStore.fetch(:current_ee_token) do
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index 7c9c4cdd436..2cb06e3ad85 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Enumeration < ActiveRecord::Base
+class Enumeration < ApplicationRecord
default_scope { order("#{Enumeration.table_name}.position ASC") }
belongs_to :project
diff --git a/app/models/forum.rb b/app/models/forum.rb
index 07488f3b72b..b7bd1a98d0e 100644
--- a/app/models/forum.rb
+++ b/app/models/forum.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Forum < ActiveRecord::Base
+class Forum < ApplicationRecord
belongs_to :project
has_many :topics, -> {
where("#{Message.table_name}.parent_id IS NULL")
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 18417060ed1..19d0a49a0b7 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Journal < ActiveRecord::Base
+class Journal < ApplicationRecord
self.table_name = 'journals'
include ::JournalChanges
diff --git a/app/models/journal/base_journal.rb b/app/models/journal/base_journal.rb
index a1e131debca..391c818c89d 100644
--- a/app/models/journal/base_journal.rb
+++ b/app/models/journal/base_journal.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Journal::BaseJournal < ActiveRecord::Base
+class Journal::BaseJournal < ApplicationRecord
self.abstract_class = true
belongs_to :journal
diff --git a/app/models/legacy_journal.rb b/app/models/legacy_journal.rb
index 8313765f889..9c07b00720c 100644
--- a/app/models/legacy_journal.rb
+++ b/app/models/legacy_journal.rb
@@ -35,7 +35,7 @@ require 'open_project/journal_formatter/custom_field'
require 'journal_deprecated'
# The ActiveRecord model representing journals.
-class LegacyJournal < ActiveRecord::Base
+class LegacyJournal < ApplicationRecord
include Comparable
include ::JournalFormatter
include ::JournalDeprecated
diff --git a/app/models/member.rb b/app/models/member.rb
index 05aad366edc..0280e71fec3 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -27,9 +27,8 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Member < ActiveRecord::Base
+class Member < ApplicationRecord
extend DeprecatedAlias
-
belongs_to :principal, foreign_key: 'user_id'
has_many :member_roles, dependent: :destroy, autosave: true
has_many :roles, through: :member_roles
diff --git a/app/models/member_role.rb b/app/models/member_role.rb
index 81db53f266f..e1778de77eb 100644
--- a/app/models/member_role.rb
+++ b/app/models/member_role.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class MemberRole < ActiveRecord::Base
+class MemberRole < ApplicationRecord
belongs_to :member
belongs_to :role
diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb
index 4abb8f53472..ca5db280342 100644
--- a/app/models/menu_item.rb
+++ b/app/models/menu_item.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class MenuItem < ActiveRecord::Base
+class MenuItem < ApplicationRecord
belongs_to :parent, class_name: 'MenuItem'
has_many :children, -> {
order('id ASC')
diff --git a/app/models/message.rb b/app/models/message.rb
index 132786a483d..c45f1ed5b99 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Message < ActiveRecord::Base
+class Message < ApplicationRecord
include OpenProject::Journal::AttachmentHelper
belongs_to :forum
diff --git a/app/models/news.rb b/app/models/news.rb
index f4678476a56..aa704a5d3f6 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class News < ActiveRecord::Base
+class News < ApplicationRecord
belongs_to :project
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
has_many :comments, -> {
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 55c50b9ed51..439090892c4 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Principal < ActiveRecord::Base
+class Principal < ApplicationRecord
# Account statuses
# Code accessing the keys assumes they are ordered, which they are since Ruby 1.9
STATUSES = {
diff --git a/app/models/project.rb b/app/models/project.rb
index 69929b12508..b73cfe147c7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Project < ActiveRecord::Base
+class Project < ApplicationRecord
extend Pagination::Model
extend FriendlyId
diff --git a/app/models/query.rb b/app/models/query.rb
index acaa2c4ef83..3b5307e1790 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Query < ActiveRecord::Base
+class Query < ApplicationRecord
include Timelines
include Highlighting
include ManualSorting
diff --git a/app/models/relation.rb b/app/models/relation.rb
index 31ec527179d..b24ce482fb1 100644
--- a/app/models/relation.rb
+++ b/app/models/relation.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Relation < ActiveRecord::Base
+class Relation < ApplicationRecord
include VirtualAttribute
scope :of_work_package,
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c2e487060d9..c2b9609065b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Repository < ActiveRecord::Base
+class Repository < ApplicationRecord
include Redmine::Ciphering
include OpenProject::SCM::ManageableRepository
diff --git a/app/models/role.rb b/app/models/role.rb
index a6add02adf2..aa3bd5b944c 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Role < ActiveRecord::Base
+class Role < ApplicationRecord
extend Pagination::Model
# Built-in roles
diff --git a/app/models/role_permission.rb b/app/models/role_permission.rb
index 93d98cbc99e..cab1b1c8467 100644
--- a/app/models/role_permission.rb
+++ b/app/models/role_permission.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class RolePermission < ActiveRecord::Base
+class RolePermission < ApplicationRecord
belongs_to :role
validates_presence_of :permission
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 756270d35c5..c8f9e648f2c 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Setting < ActiveRecord::Base
+class Setting < ApplicationRecord
DATE_FORMATS = [
'%Y-%m-%d',
'%d/%m/%Y',
diff --git a/app/models/status.rb b/app/models/status.rb
index b043d606c7a..91921bf92c0 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Status < ActiveRecord::Base
+class Status < ApplicationRecord
extend Pagination::Model
default_scope { order_by_position }
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index 3cd41a18275..c3096f36e41 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class TimeEntry < ActiveRecord::Base
+class TimeEntry < ApplicationRecord
# could have used polymorphic association
# project association here allows easy loading of time entries at project level with one database trip
belongs_to :project
diff --git a/app/models/token/base.rb b/app/models/token/base.rb
index e5c3a0eb10b..56bc6c340c3 100644
--- a/app/models/token/base.rb
+++ b/app/models/token/base.rb
@@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Token
- class Base < ActiveRecord::Base
+ class Base < ApplicationRecord
self.table_name = 'tokens'
# Hashed tokens belong to a user and are unique per type
diff --git a/app/models/type.rb b/app/models/type.rb
index 1a86a8d99af..794220109e3 100644
--- a/app/models/type.rb
+++ b/app/models/type.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class ::Type < ActiveRecord::Base
+class ::Type < ApplicationRecord
extend Pagination::Model
# Work Package attributes for this type
diff --git a/app/models/user_password.rb b/app/models/user_password.rb
index 62630d018db..5a6483eb168 100644
--- a/app/models/user_password.rb
+++ b/app/models/user_password.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class UserPassword < ActiveRecord::Base
+class UserPassword < ApplicationRecord
belongs_to :user, inverse_of: :passwords
# passwords must never be modified, so doing this on create should be enough
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index faa37256c0e..12050975ebc 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class UserPreference < ActiveRecord::Base
+class UserPreference < ApplicationRecord
belongs_to :user
serialize :others
diff --git a/app/models/version.rb b/app/models/version.rb
index 09d8bf86065..30091938fcd 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Version < ActiveRecord::Base
+class Version < ApplicationRecord
include ::Versions::ProjectSharing
include ::Scopes::Scoped
diff --git a/app/models/watcher.rb b/app/models/watcher.rb
index 9e3ed9efcf1..4263ba9a262 100644
--- a/app/models/watcher.rb
+++ b/app/models/watcher.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Watcher < ActiveRecord::Base
+class Watcher < ApplicationRecord
belongs_to :watchable, polymorphic: true
belongs_to :user
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index 8be765febf5..19dc1cf51f6 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Wiki < ActiveRecord::Base
+class Wiki < ApplicationRecord
belongs_to :project
has_many :pages, -> {
order('title')
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index e28f4368939..ebeec3498e6 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -29,7 +29,7 @@
require 'zlib'
-class WikiContent < ActiveRecord::Base
+class WikiContent < ApplicationRecord
belongs_to :page, class_name: 'WikiPage', foreign_key: 'page_id'
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
validates_length_of :comments, maximum: 255, allow_nil: true
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index 961dbadabd1..c4b4157085a 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class WikiPage < ActiveRecord::Base
+class WikiPage < ApplicationRecord
belongs_to :wiki, touch: true
has_one :project, through: :wiki
has_one :content, class_name: 'WikiContent', foreign_key: 'page_id', dependent: :destroy
diff --git a/app/models/wiki_redirect.rb b/app/models/wiki_redirect.rb
index 31035496bc8..1b8bf8cc07d 100644
--- a/app/models/wiki_redirect.rb
+++ b/app/models/wiki_redirect.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class WikiRedirect < ActiveRecord::Base
+class WikiRedirect < ApplicationRecord
belongs_to :wiki
validates_presence_of :title, :redirects_to
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index 8139e53d54e..5bd34a5d71d 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class WorkPackage < ActiveRecord::Base
+class WorkPackage < ApplicationRecord
include WorkPackage::Validations
include WorkPackage::SchedulingRules
include WorkPackage::StatusTransitions
diff --git a/app/models/workflow.rb b/app/models/workflow.rb
index 68678182cdc..10e8ad169b3 100644
--- a/app/models/workflow.rb
+++ b/app/models/workflow.rb
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Workflow < ActiveRecord::Base
+class Workflow < ApplicationRecord
belongs_to :role
belongs_to :old_status, class_name: 'Status', foreign_key: 'old_status_id'
belongs_to :new_status, class_name: 'Status', foreign_key: 'new_status_id'
diff --git a/lib/tasks/attachment_migrations.rake b/lib/tasks/attachment_migrations.rake
index 9e687745b94..fbf5d5dceb2 100644
--- a/lib/tasks/attachment_migrations.rake
+++ b/lib/tasks/attachment_migrations.rake
@@ -38,13 +38,13 @@ module Migrations
# the migration of an ChiliProject (2.x or 3.x) which lacks a couple
# of columns models have in OpenProject >6.
module Attachments
- class CurrentWikiPage < ActiveRecord::Base
+ class CurrentWikiPage < ::ActiveRecord::Base
self.table_name = "wiki_pages"
has_one :content, class_name: 'WikiContent', foreign_key: 'page_id', dependent: :destroy
end
- class CurrentWikiContent < ActiveRecord::Base
+ class CurrentWikiContent < ::ActiveRecord::Base
self.table_name = "wiki_contents"
end
end
diff --git a/lib/tasks/delete_documents.rake b/lib/tasks/delete_documents.rake
index 40a47bc79ab..1c861e06dc6 100644
--- a/lib/tasks/delete_documents.rake
+++ b/lib/tasks/delete_documents.rake
@@ -33,7 +33,7 @@ namespace :migrations do
namespace :documents do
include Tasks::Shared::UserFeedback
- class Document < ActiveRecord::Base
+ class TemporaryDocument < ActiveRecord::Base
belongs_to :project
belongs_to :category, class_name: 'DocumentCategory', foreign_key: 'category_id'
end
@@ -47,7 +47,7 @@ namespace :migrations do
if !$stdout.isatty || user_agrees_to_delete_all_documents
puts 'Delete all attachments attached to projects or versions...'
- Document.destroy_all
+ TemporaryDocument.destroy_all
Attachment.where(container_type: ['Document']).destroy_all
end
rescue
diff --git a/modules/backlogs/app/models/version_setting.rb b/modules/backlogs/app/models/version_setting.rb
index 0cad558e00d..9faef049915 100644
--- a/modules/backlogs/app/models/version_setting.rb
+++ b/modules/backlogs/app/models/version_setting.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class VersionSetting < ActiveRecord::Base
+class VersionSetting < ApplicationRecord
belongs_to :project
belongs_to :version
diff --git a/modules/backlogs/spec/models/issue_position_spec.rb b/modules/backlogs/spec/models/issue_position_spec.rb
index e79381374bb..ea2e2ca203e 100644
--- a/modules/backlogs/spec/models/issue_position_spec.rb
+++ b/modules/backlogs/spec/models/issue_position_spec.rb
@@ -254,7 +254,7 @@ describe WorkPackage, type: :model do
project_id: project_wo_backlogs.id,
name: 'Go-Live')
}
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
def move_to_project(work_package, project)
service = WorkPackages::MoveService.new(work_package, admin)
diff --git a/modules/backlogs/spec/models/version_spec.rb b/modules/backlogs/spec/models/version_spec.rb
index ab687c7df46..1a562af81ee 100644
--- a/modules/backlogs/spec/models/version_spec.rb
+++ b/modules/backlogs/spec/models/version_spec.rb
@@ -54,7 +54,7 @@ describe Version, type: :model do
let(:version) { FactoryBot.create(:version, project_id: project.id, name: 'Version') }
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
def move_to_project(work_package, project)
service = WorkPackages::MoveService.new(work_package, admin)
diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rb
index 3819ac1359e..11f80f2da27 100644
--- a/modules/costs/app/models/cost_entry.rb
+++ b/modules/costs/app/models/cost_entry.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class CostEntry < ActiveRecord::Base
+class CostEntry < ApplicationRecord
belongs_to :project
belongs_to :work_package
belongs_to :user
diff --git a/modules/costs/app/models/cost_object.rb b/modules/costs/app/models/cost_object.rb
index 4c9127b46ab..f7f2e076872 100644
--- a/modules/costs/app/models/cost_object.rb
+++ b/modules/costs/app/models/cost_object.rb
@@ -28,7 +28,7 @@
# A CostObject is an item that is created as part of the project. These items
# contain a collection of work packages.
-class CostObject < ActiveRecord::Base
+class CostObject < ApplicationRecord
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
belongs_to :project
has_many :work_packages, dependent: :nullify
diff --git a/modules/costs/app/models/cost_type.rb b/modules/costs/app/models/cost_type.rb
index f4074ea1c56..b2a305d98d5 100644
--- a/modules/costs/app/models/cost_type.rb
+++ b/modules/costs/app/models/cost_type.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class CostType < ActiveRecord::Base
+class CostType < ApplicationRecord
has_many :material_budget_items
has_many :cost_entries, dependent: :destroy
has_many :rates, class_name: 'CostRate', foreign_key: 'cost_type_id', dependent: :destroy
diff --git a/modules/costs/app/models/entry.rb b/modules/costs/app/models/entry.rb
index 73212a5c15e..99ea7ba072f 100644
--- a/modules/costs/app/models/entry.rb
+++ b/modules/costs/app/models/entry.rb
@@ -29,7 +29,7 @@
module Entry
[TimeEntry, CostEntry].each do |e| e.send :include, self end
- class Delegator < ActiveRecord::Base
+ class Delegator < ApplicationRecord
self.abstract_class = true
class << self
def ===(obj)
diff --git a/modules/costs/app/models/labor_budget_item.rb b/modules/costs/app/models/labor_budget_item.rb
index 72e3a8e0a69..f6c6faec4b9 100644
--- a/modules/costs/app/models/labor_budget_item.rb
+++ b/modules/costs/app/models/labor_budget_item.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class LaborBudgetItem < ActiveRecord::Base
+class LaborBudgetItem < ApplicationRecord
belongs_to :cost_object
belongs_to :user
belongs_to :principal, foreign_key: 'user_id'
diff --git a/modules/costs/app/models/material_budget_item.rb b/modules/costs/app/models/material_budget_item.rb
index b8f54498c15..068a4c64588 100644
--- a/modules/costs/app/models/material_budget_item.rb
+++ b/modules/costs/app/models/material_budget_item.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class MaterialBudgetItem < ActiveRecord::Base
+class MaterialBudgetItem < ApplicationRecord
belongs_to :cost_object
belongs_to :cost_type
diff --git a/modules/costs/app/models/rate.rb b/modules/costs/app/models/rate.rb
index 6f618d17985..9cda3b1b34f 100644
--- a/modules/costs/app/models/rate.rb
+++ b/modules/costs/app/models/rate.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Rate < ActiveRecord::Base
+class Rate < ApplicationRecord
validates_numericality_of :rate, allow_nil: false
validate :validate_date_is_a_date
diff --git a/modules/costs/spec/controllers/hourly_rates_controller_spec.rb b/modules/costs/spec/controllers/hourly_rates_controller_spec.rb
index 536ef6bdbdc..aad811b7d5f 100644
--- a/modules/costs/spec/controllers/hourly_rates_controller_spec.rb
+++ b/modules/costs/spec/controllers/hourly_rates_controller_spec.rb
@@ -29,8 +29,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe HourlyRatesController do
+ using_shared_fixtures :admin
+
let(:user) { FactoryBot.create(:user) }
- let(:admin) { FactoryBot.create(:admin) }
let(:default_rate) { FactoryBot.create(:default_hourly_rate, user: user) }
describe 'PUT update' do
diff --git a/modules/documents/app/models/document.rb b/modules/documents/app/models/document.rb
index 9d018697c72..0eecd451376 100644
--- a/modules/documents/app/models/document.rb
+++ b/modules/documents/app/models/document.rb
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Document < ActiveRecord::Base
+class Document < ApplicationRecord
belongs_to :project
belongs_to :category, class_name: "DocumentCategory", foreign_key: "category_id"
acts_as_attachable delete_permission: :manage_documents,
diff --git a/modules/global_roles/app/models/principal_role.rb b/modules/global_roles/app/models/principal_role.rb
index 38896fe1358..b92acde1e77 100644
--- a/modules/global_roles/app/models/principal_role.rb
+++ b/modules/global_roles/app/models/principal_role.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class PrincipalRole < ActiveRecord::Base
+class PrincipalRole < ApplicationRecord
belongs_to :principal
belongs_to :role
validate :validate_assignable
diff --git a/modules/ldap_groups/app/models/ldap_groups/membership.rb b/modules/ldap_groups/app/models/ldap_groups/membership.rb
index 2a89bc45eb4..6a9f6c78af4 100644
--- a/modules/ldap_groups/app/models/ldap_groups/membership.rb
+++ b/modules/ldap_groups/app/models/ldap_groups/membership.rb
@@ -1,5 +1,5 @@
module LdapGroups
- class Membership < ActiveRecord::Base
+ class Membership < ApplicationRecord
belongs_to :user
belongs_to :group,
class_name: '::LdapGroups::SynchronizedGroup',
diff --git a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb
index 556b588fca9..b77d1352cb0 100644
--- a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb
+++ b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb
@@ -2,7 +2,7 @@ require 'net/ldap'
require 'net/ldap/dn'
module LdapGroups
- class SynchronizedGroup < ActiveRecord::Base
+ class SynchronizedGroup < ApplicationRecord
belongs_to :group
belongs_to :auth_source
has_many :users,
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index 0ef855bd9ff..bbfba95db1e 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Meeting < ActiveRecord::Base
+class Meeting < ApplicationRecord
include VirtualAttribute
self.table_name = 'meetings'
diff --git a/modules/meeting/app/models/meeting_content.rb b/modules/meeting/app/models/meeting_content.rb
index cb8964799ef..fc8cee19f7c 100644
--- a/modules/meeting/app/models/meeting_content.rb
+++ b/modules/meeting/app/models/meeting_content.rb
@@ -27,7 +27,7 @@
#++
#
-class MeetingContent < ActiveRecord::Base
+class MeetingContent < ApplicationRecord
include OpenProject::Journal::AttachmentHelper
belongs_to :meeting
diff --git a/modules/meeting/app/models/meeting_participant.rb b/modules/meeting/app/models/meeting_participant.rb
index 747b331f4a7..4bbec24a0da 100644
--- a/modules/meeting/app/models/meeting_participant.rb
+++ b/modules/meeting/app/models/meeting_participant.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class MeetingParticipant < ActiveRecord::Base
+class MeetingParticipant < ApplicationRecord
belongs_to :meeting
belongs_to :user
diff --git a/modules/openid_connect/spec/requests/openid_connect_spec.rb b/modules/openid_connect/spec/requests/openid_connect_spec.rb
index 786c84bd447..c25290710a8 100644
--- a/modules/openid_connect/spec/requests/openid_connect_spec.rb
+++ b/modules/openid_connect/spec/requests/openid_connect_spec.rb
@@ -77,14 +77,6 @@ describe 'OpenID Connect', type: :rails_request do
)
end
- after(:all) do
- User.delete_all
- end
-
- after do
- User.current = nil
- end
-
it 'works' do
##
# it should redirect to the provider's openid connect authentication endpoint
diff --git a/modules/pdf_export/app/models/export_card_configuration.rb b/modules/pdf_export/app/models/export_card_configuration.rb
index df97086a652..0730419bf3a 100644
--- a/modules/pdf_export/app/models/export_card_configuration.rb
+++ b/modules/pdf_export/app/models/export_card_configuration.rb
@@ -27,7 +27,7 @@
#++
-class ExportCardConfiguration < ActiveRecord::Base
+class ExportCardConfiguration < ApplicationRecord
class RowsYamlValidator < ActiveModel::Validator
REQUIRED_GROUP_KEYS = ["rows"]
diff --git a/modules/reporting/app/models/entry.rb b/modules/reporting/app/models/entry.rb
index cb4bb9c1238..6eed3ecb33a 100644
--- a/modules/reporting/app/models/entry.rb
+++ b/modules/reporting/app/models/entry.rb
@@ -29,7 +29,7 @@
module Entry
[TimeEntry, CostEntry].each { |e| e.send :include, self }
- class Delegator < ActiveRecord::Base
+ class Delegator < ApplicationRecord
# Rails 3.2.13 delegates most of the methods defined here to an
# ActiveRecord::Relation (see active_record/querying.rb).
# Thus only implementing the four find_x methods isn't enough
diff --git a/modules/reporting_engine/lib/report.rb b/modules/reporting_engine/lib/report.rb
index ab1c80f75f5..97e836f7056 100644
--- a/modules/reporting_engine/lib/report.rb
+++ b/modules/reporting_engine/lib/report.rb
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Report < ActiveRecord::Base
+class Report < ApplicationRecord
extend Forwardable
include Enumerable
include Engine
diff --git a/modules/reporting_engine/lib/report/chainable.rb b/modules/reporting_engine/lib/report/chainable.rb
index 8ccf96ec6d6..034647095c5 100644
--- a/modules/reporting_engine/lib/report/chainable.rb
+++ b/modules/reporting_engine/lib/report/chainable.rb
@@ -28,7 +28,7 @@
# Provides convinience layer and logic shared between GroupBy::Base and Filter::Base.
# Implements a double linked list (FIXME: is that the correct term?).
-class Report < ActiveRecord::Base
+class Report < ApplicationRecord
class Chainable
include Enumerable
include Report::QueryUtils
diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb
index ba7ed23e4d3..794c0263818 100644
--- a/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb
+++ b/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb
@@ -1,5 +1,5 @@
module TwoFactorAuthentication
- class Device < ActiveRecord::Base
+ class Device < ApplicationRecord
default_scope { order('id ASC') }
belongs_to :user
diff --git a/modules/webhooks/app/models/webhooks/event.rb b/modules/webhooks/app/models/webhooks/event.rb
index 5484285d8ba..269f09ce05f 100644
--- a/modules/webhooks/app/models/webhooks/event.rb
+++ b/modules/webhooks/app/models/webhooks/event.rb
@@ -1,7 +1,7 @@
module Webhooks
- class Event < ActiveRecord::Base
+ class Event < ApplicationRecord
belongs_to :webhook
validates_associated :webhook
validates_presence_of :name
end
-end
\ No newline at end of file
+end
diff --git a/modules/webhooks/app/models/webhooks/log.rb b/modules/webhooks/app/models/webhooks/log.rb
index 242cc6759fa..d1cb62ab34a 100644
--- a/modules/webhooks/app/models/webhooks/log.rb
+++ b/modules/webhooks/app/models/webhooks/log.rb
@@ -1,5 +1,5 @@
module Webhooks
- class Log < ActiveRecord::Base
+ class Log < ApplicationRecord
belongs_to :webhook, foreign_key: :webhooks_webhook_id, class_name: '::Webhooks::Webhook', dependent: :destroy
validates :url, presence: true
@@ -16,4 +16,4 @@ module Webhooks
order(updated_at: :desc).limit(limit)
end
end
-end
\ No newline at end of file
+end
diff --git a/modules/webhooks/app/models/webhooks/project.rb b/modules/webhooks/app/models/webhooks/project.rb
index 7740b515cba..539b6f94cdc 100644
--- a/modules/webhooks/app/models/webhooks/project.rb
+++ b/modules/webhooks/app/models/webhooks/project.rb
@@ -1,8 +1,8 @@
module Webhooks
- class Project < ActiveRecord::Base
+ class Project < ApplicationRecord
belongs_to :webhook
belongs_to :project, class_name: '::Project'
validates_presence_of :project
end
-end
\ No newline at end of file
+end
diff --git a/modules/webhooks/app/models/webhooks/webhook.rb b/modules/webhooks/app/models/webhooks/webhook.rb
index 9ae31db57a0..923b8674a0d 100644
--- a/modules/webhooks/app/models/webhooks/webhook.rb
+++ b/modules/webhooks/app/models/webhooks/webhook.rb
@@ -1,5 +1,5 @@
module Webhooks
- class Webhook < ActiveRecord::Base
+ class Webhook < ApplicationRecord
default_scope { order(id: :asc) }
validates_presence_of :name
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index 08305e199d3..bef8e84ef71 100644
--- a/spec/controllers/account_controller_spec.rb
+++ b/spec/controllers/account_controller_spec.rb
@@ -29,7 +29,6 @@
require 'spec_helper'
describe AccountController, type: :controller do
- # class AccountHook < Redmine::Hook::ViewListener; end
class UserHook < Redmine::Hook::ViewListener
attr_reader :registered_user
@@ -55,10 +54,6 @@ describe AccountController, type: :controller do
hook.reset!
end
- after do
- User.delete_all
- User.current = nil
- end
let(:user) { FactoryBot.build_stubbed(:user) }
context 'GET #login' do
@@ -106,7 +101,7 @@ describe AccountController, type: :controller do
end
context 'POST #login' do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
describe 'wrong password' do
it 'redirects back to login' do
@@ -285,7 +280,7 @@ describe AccountController, type: :controller do
end
context 'GET #logout' do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
it 'calls reset_session' do
expect(@controller).to receive(:reset_session).once
@@ -618,10 +613,9 @@ describe AccountController, type: :controller do
it "notifies the admins about the issue" do
perform_enqueued_jobs
- mail = ActionMailer::Base.deliveries.last
-
+ mail = ActionMailer::Base.deliveries.detect { |mail| mail.to.first == admin.mail }
+ expect(mail).to be_present
expect(mail.subject).to match /limit reached/
- expect(mail.to.first).to eq admin.mail
expect(mail.body.parts.first.to_s).to match /new user \(#{params[:user][:mail]}\)/
end
@@ -873,10 +867,9 @@ describe AccountController, type: :controller do
it "notifies the admins about the issue" do
perform_enqueued_jobs
- mail = ActionMailer::Base.deliveries.last
-
+ mail = ActionMailer::Base.deliveries.detect { |mail| mail.to.first == admin.mail }
+ expect(mail).to be_present
expect(mail.subject).to match /limit reached/
- expect(mail.to.first).to eq admin.mail
end
end
diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb
index 0e30917d8b4..b8e7d0610fd 100644
--- a/spec/controllers/members_controller_spec.rb
+++ b/spec/controllers/members_controller_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe MembersController, type: :controller do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:user) { FactoryBot.create(:user) }
let(:project) { FactoryBot.create(:project, identifier: 'pet_project') }
let(:role) { FactoryBot.create(:role) }
@@ -44,7 +44,7 @@ describe MembersController, type: :controller do
end
describe 'create' do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:project_2) { FactoryBot.create(:project) }
before do
@@ -75,7 +75,7 @@ describe MembersController, type: :controller do
end
describe 'update' do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:project_2) { FactoryBot.create(:project) }
let(:role_1) { FactoryBot.create(:role) }
let(:role_2) { FactoryBot.create(:role) }
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index ae99fd65d99..66717919cef 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -29,16 +29,13 @@
require 'spec_helper'
describe ProjectsController, type: :controller do
- before do
- Role.delete_all
- User.delete_all
- end
+ using_shared_fixtures :admin
before do
allow(@controller).to receive(:set_localization)
- @user = FactoryBot.create(:admin)
- allow(User).to receive(:current).and_return @user
+ @role = FactoryBot.create(:non_member)
+ allow(User).to receive(:current).and_return admin
@params = {}
end
diff --git a/spec/controllers/users/memberships_controller_spec.rb b/spec/controllers/users/memberships_controller_spec.rb
index aef1e2dde61..b9f6b525c6b 100644
--- a/spec/controllers/users/memberships_controller_spec.rb
+++ b/spec/controllers/users/memberships_controller_spec.rb
@@ -30,8 +30,9 @@ require 'spec_helper'
require 'work_package'
describe Users::MembershipsController, type: :controller do
+ using_shared_fixtures :admin
+
let(:user) { FactoryBot.create(:user) }
- let(:admin) { FactoryBot.create(:admin) }
let(:anonymous) { FactoryBot.create(:anonymous) }
describe 'update memberships' do
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 1645a24340a..6c3e262fe05 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -30,13 +30,7 @@ require 'spec_helper'
require 'work_package'
describe UsersController, type: :controller do
- before do
- User.delete_all
- end
-
- after do
- User.current = nil
- end
+ using_shared_fixtures :admin, :anonymous
let(:user_password) {'bob!' * 4}
let(:user) do
@@ -46,8 +40,6 @@ describe UsersController, type: :controller do
password_confirmation: user_password,
)
end
- let(:admin) { FactoryBot.create(:admin) }
- let(:anonymous) { FactoryBot.create(:anonymous) }
describe 'GET new' do
context "with user limit reached" do
@@ -192,12 +184,10 @@ describe UsersController, type: :controller do
end
context 'with admin rights' do
- let(:admin_user) { FactoryBot.create :admin }
-
before do
expect(ActionMailer::Base.deliveries).to be_empty
- as_logged_in_user admin_user do
+ as_logged_in_user admin do
post :resend_invitation, params: { id: invited_user.id }
end
end
@@ -287,7 +277,7 @@ describe UsersController, type: :controller do
describe "WHEN the current user is the admin
WHEN the given password does not match
WHEN the setting users_deletable_by_admins is set to true" do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
disable_flash_sweep
@@ -309,19 +299,12 @@ describe UsersController, type: :controller do
WHEN the given password does match
WHEN the setting users_deletable_by_admins is set to true" do
- let(:admin_password) { 'admin!' * 4 }
- let(:admin) do
- FactoryBot.create(:admin,
- password: admin_password,
- password_confirmation: admin_password)
- end
-
before do
disable_flash_sweep
allow(Setting).to receive(:users_deletable_by_admins?).and_return(true)
as_logged_in_user admin do
- post :destroy, params: base_params.merge(:'_password_confirmation' => admin_password)
+ post :destroy, params: base_params.merge(:'_password_confirmation' => 'adminADMIN!')
end
end
@@ -331,7 +314,7 @@ describe UsersController, type: :controller do
describe "WHEN the current user is the admin
WHEN the setting users_deletable_by_admins is set to false" do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
disable_flash_sweep
diff --git a/spec/controllers/wiki_controller_spec.rb b/spec/controllers/wiki_controller_spec.rb
index feda455780c..0301bf59f7c 100644
--- a/spec/controllers/wiki_controller_spec.rb
+++ b/spec/controllers/wiki_controller_spec.rb
@@ -29,20 +29,14 @@
require 'spec_helper'
describe WikiController, type: :controller do
- before do
- Role.delete_all # removing me makes us faster
- User.delete_all # removing me makes us faster
- I18n.locale = :en
- end
+ using_shared_fixtures :admin
describe 'actions' do
before do
allow(@controller).to receive(:set_localization)
@role = FactoryBot.create(:non_member)
- @user = FactoryBot.create(:admin)
-
- allow(User).to receive(:current).and_return @user
+ login_as admin
@project = FactoryBot.create(:project)
@project.reload # to get the wiki into the proxy
@@ -53,7 +47,7 @@ describe WikiController, type: :controller do
# creating page contents
FactoryBot.create(:wiki_content, page_id: @existing_page.id,
- author_id: @user.id)
+ author_id: admin.id)
end
shared_examples_for "a 'new' action" do
@@ -237,14 +231,13 @@ describe WikiController, type: :controller do
allow(Setting).to receive(:login_required?).and_return(false)
@role = FactoryBot.create(:non_member)
- @user = FactoryBot.create(:admin)
@anon = User.anonymous.nil? ? FactoryBot.create(:anonymous) : User.anonymous
Role.anonymous.update name: I18n.t(:default_role_anonymous),
permissions: [:view_wiki_pages]
- allow(User).to receive(:current).and_return @user
+ allow(User).to receive(:current).and_return admin
@project = FactoryBot.create(:public_project)
@project.reload # to get the wiki into the proxy
@@ -261,11 +254,11 @@ describe WikiController, type: :controller do
# creating page contents
FactoryBot.create(:wiki_content, page_id: @page_default.id,
- author_id: @user.id)
+ author_id: admin.id)
FactoryBot.create(:wiki_content, page_id: @page_with_content.id,
- author_id: @user.id)
+ author_id: admin.id)
FactoryBot.create(:wiki_content, page_id: @unrelated_page.id,
- author_id: @user.id)
+ author_id: admin.id)
# creating some child pages
@children = {}
@@ -274,7 +267,7 @@ describe WikiController, type: :controller do
parent_id: page.id,
title: page.title + ' child')
FactoryBot.create(:wiki_content, page_id: child_page.id,
- author_id: @user.id)
+ author_id: admin.id)
@children[page] = child_page
end
diff --git a/spec/features/activities/disabled_activity_spec.rb b/spec/features/activities/disabled_activity_spec.rb
index 92ba1a801b8..ed7fa15540d 100644
--- a/spec/features/activities/disabled_activity_spec.rb
+++ b/spec/features/activities/disabled_activity_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Disabled activity', type: :feature do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:project1) do
FactoryBot.create(:project, enabled_module_names: %i[work_package_tracking wiki])
diff --git a/spec/features/admin/attribute_help_texts_spec.rb b/spec/features/admin/attribute_help_texts_spec.rb
index 4f9b57586a0..3d012aad064 100644
--- a/spec/features/admin/attribute_help_texts_spec.rb
+++ b/spec/features/admin/attribute_help_texts_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Attribute help texts' do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:instance) { AttributeHelpText.last }
let(:modal) { Components::AttributeHelpTextModal.new(instance) }
diff --git a/spec/features/admin/custom_fields/multi_value_custom_fields_spec.rb b/spec/features/admin/custom_fields/multi_value_custom_fields_spec.rb
index 584bb0011a5..11d0907f7ad 100644
--- a/spec/features/admin/custom_fields/multi_value_custom_fields_spec.rb
+++ b/spec/features/admin/custom_fields/multi_value_custom_fields_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Multi-value custom fields creation', type: :feature, js: true do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
def drag_and_drop(handle, to)
scroll_to_element(handle)
diff --git a/spec/features/admin/enterprise_spec.rb b/spec/features/admin/enterprise_spec.rb
index 7fcda53c6f3..6acd03b9f90 100644
--- a/spec/features/admin/enterprise_spec.rb
+++ b/spec/features/admin/enterprise_spec.rb
@@ -31,7 +31,7 @@ require 'spec_helper'
describe 'Enterprise token', type: :feature, js: true do
include Redmine::I18n
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:token_object) do
token = OpenProject::Token.new
token.subscriber = 'Foobar'
diff --git a/spec/features/admin/enumerations_spec.rb b/spec/features/admin/enumerations_spec.rb
index 3ed1dae3685..588cb92de3b 100644
--- a/spec/features/admin/enumerations_spec.rb
+++ b/spec/features/admin/enumerations_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Enumerations', type: :feature do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
login_as(admin)
diff --git a/spec/features/admin/test_mail_notification_spec.rb b/spec/features/admin/test_mail_notification_spec.rb
index 4c8eec11158..8e05b6405ff 100644
--- a/spec/features/admin/test_mail_notification_spec.rb
+++ b/spec/features/admin/test_mail_notification_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Test mail notification', type: :feature do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
login_as(admin)
diff --git a/spec/features/auth/auth_stages_spec.rb b/spec/features/auth/auth_stages_spec.rb
index d0ac02081d1..aa57fa7de9c 100644
--- a/spec/features/auth/auth_stages_spec.rb
+++ b/spec/features/auth/auth_stages_spec.rb
@@ -42,9 +42,6 @@ describe 'Authentication Stages', type: :feature do
after do
Capybara.ignore_hidden_elements = @capybara_ignore_elements
- User.delete_all
- User.current = nil
-
OpenProject::Authentication::Stage.deregister :dummy_step
end
diff --git a/spec/features/auth/login_spec.rb b/spec/features/auth/login_spec.rb
index 18d1c87417a..8fa48d3d288 100644
--- a/spec/features/auth/login_spec.rb
+++ b/spec/features/auth/login_spec.rb
@@ -36,8 +36,6 @@ describe 'Login', type: :feature do
after do
Capybara.ignore_hidden_elements = @capybara_ignore_elements
- User.delete_all
- User.current = nil
end
def expect_being_logged_in(user)
diff --git a/spec/features/auth/omniauth_spec.rb b/spec/features/auth/omniauth_spec.rb
index 6198a675dcf..e23f2b764fb 100644
--- a/spec/features/auth/omniauth_spec.rb
+++ b/spec/features/auth/omniauth_spec.rb
@@ -49,8 +49,6 @@ describe 'Omniauth authentication', type: :feature do
end
after do
- User.delete_all
- User.current = nil
OmniAuth.config.test_mode = @omniauth_test_mode
Capybara.ignore_hidden_elements = @capybara_ignore_elements
OmniAuth.config.logger = @omniauth_logger
diff --git a/spec/features/colors/color_administration_spec.rb b/spec/features/colors/color_administration_spec.rb
index 057c0ca7bf4..ae0fed36693 100644
--- a/spec/features/colors/color_administration_spec.rb
+++ b/spec/features/colors/color_administration_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
feature 'color administration', type: :feature do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
login_as(admin)
diff --git a/spec/features/groups/group_memberships_spec.rb b/spec/features/groups/group_memberships_spec.rb
index 8f8a12a998e..3970b6c7911 100644
--- a/spec/features/groups/group_memberships_spec.rb
+++ b/spec/features/groups/group_memberships_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'group memberships through groups page', type: :feature, js: true do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:peter) { FactoryBot.create :user, firstname: 'Peter', lastname: 'Pan' }
let!(:hannibal) { FactoryBot.create :user, firstname: 'Hannibal', lastname: 'Smith' }
let(:group) { FactoryBot.create :group, lastname: 'A-Team' }
diff --git a/spec/features/groups/groups_spec.rb b/spec/features/groups/groups_spec.rb
index e02f900c0b7..45c90694e83 100644
--- a/spec/features/groups/groups_spec.rb
+++ b/spec/features/groups/groups_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
feature 'group memberships through groups page', type: :feature do
- let(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
let!(:group) { FactoryBot.create :group, lastname: "Bob's Team" }
let(:groups_page) { Pages::Groups.new }
diff --git a/spec/features/groups/membership_spec.rb b/spec/features/groups/membership_spec.rb
index a84f1d7887a..3e1c9155bfd 100644
--- a/spec/features/groups/membership_spec.rb
+++ b/spec/features/groups/membership_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'group memberships through project members page', type: :feature do
+ using_shared_fixtures :admin
let(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let(:alice) { FactoryBot.create :user, firstname: 'Alice', lastname: 'Wonderland' }
let(:bob) { FactoryBot.create :user, firstname: 'Bob', lastname: 'Bobbit' }
let(:group) { FactoryBot.create :group, lastname: 'group1' }
diff --git a/spec/features/members/error_messages_spec.rb b/spec/features/members/error_messages_spec.rb
index fe0bb8284a2..edaca138efc 100644
--- a/spec/features/members/error_messages_spec.rb
+++ b/spec/features/members/error_messages_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'Group memberships through groups page', type: :feature do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:peter) { FactoryBot.create :user, firstname: 'Peter', lastname: 'Pan' }
let!(:manager) { FactoryBot.create :role, name: 'Manager' }
diff --git a/spec/features/members/invitation_spec.rb b/spec/features/members/invitation_spec.rb
index d84ca736013..3281468bd35 100644
--- a/spec/features/members/invitation_spec.rb
+++ b/spec/features/members/invitation_spec.rb
@@ -29,8 +29,8 @@
require 'spec_helper'
feature 'invite user via email', type: :feature, js: true do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:developer) { FactoryBot.create :role, name: 'Developer' }
let(:members_page) { Pages::Members.new project.identifier }
diff --git a/spec/features/members/membership_filter_spec.rb b/spec/features/members/membership_filter_spec.rb
index 0e1ca125cf8..5036875a441 100644
--- a/spec/features/members/membership_filter_spec.rb
+++ b/spec/features/members/membership_filter_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'group memberships through groups page', type: :feature, js: true do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:peter) do
FactoryBot.create :user,
firstname: 'Peter',
diff --git a/spec/features/members/membership_spec.rb b/spec/features/members/membership_spec.rb
index 07e147501e2..12641ee0537 100644
--- a/spec/features/members/membership_spec.rb
+++ b/spec/features/members/membership_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'group memberships through groups page', type: :feature, js: true do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:peter) { FactoryBot.create :user, firstname: 'Peter', lastname: 'Pan', mail: 'foo@example.org' }
let!(:hannibal) { FactoryBot.create :user, firstname: 'Hannibal', lastname: 'Smith', mail: 'boo@bar.org' }
let!(:crash) { FactoryBot.create :user, firstname: "",
diff --git a/spec/features/members/pagination_spec.rb b/spec/features/members/pagination_spec.rb
index a51a8fd34b9..5dd2a2e77c1 100644
--- a/spec/features/members/pagination_spec.rb
+++ b/spec/features/members/pagination_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'members pagination', type: :feature, js: true do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:peter) { FactoryBot.create :user, firstname: 'Peter', lastname: 'Pan' }
let!(:bob) { FactoryBot.create :user, firstname: 'Bob', lastname: 'Bobbit' }
let!(:alice) { FactoryBot.create :user, firstname: 'Alice', lastname: 'Alison' }
diff --git a/spec/features/members/roles_spec.rb b/spec/features/members/roles_spec.rb
index 6d22cec7699..053ba49ee16 100644
--- a/spec/features/members/roles_spec.rb
+++ b/spec/features/members/roles_spec.rb
@@ -29,9 +29,9 @@
require 'spec_helper'
feature 'members pagination', type: :feature, js: true do
+ using_shared_fixtures :admin
let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
- let(:admin) { FactoryBot.create :admin }
let!(:bob) { FactoryBot.create :user, firstname: 'Bob', lastname: 'Bobbit' }
let!(:alice) { FactoryBot.create :user, firstname: 'Alice', lastname: 'Alison' }
diff --git a/spec/features/menu_items/wiki_menu_item_spec.rb b/spec/features/menu_items/wiki_menu_item_spec.rb
index 0117933fb9b..4d9b07eb67a 100644
--- a/spec/features/menu_items/wiki_menu_item_spec.rb
+++ b/spec/features/menu_items/wiki_menu_item_spec.rb
@@ -158,7 +158,7 @@ feature 'Wiki menu items' do
# removing the menu item which is also the last wiki menu item
# removing the default wiki menu item programatically first
- MenuItems::WikiMenuItem.where(name: "wiki").delete_all
+ MenuItems::WikiMenuItem.where(navigatable_id: project.wiki.id, name: "wiki").delete_all
visit project_wiki_path(project, other_wiki_page)
click_link 'More'
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index 9f656ece8e3..c3d3f6eb4b2 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -32,7 +32,7 @@ describe 'Projects index page',
type: :feature,
js: true,
with_settings: { login_required?: false } do
- let!(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
let!(:manager) { FactoryBot.create :role, name: 'Manager' }
let!(:developer) { FactoryBot.create :role, name: 'Developer' }
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index 261733f46e1..cab52d4e265 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -30,8 +30,10 @@ require 'spec_helper'
describe 'Search', type: :feature, js: true, with_settings: { per_page_options: '5' }, with_mail: false do
include ::Components::NgSelectAutocompleteHelpers
+
+ using_shared_fixtures :admin
+ let(:user) { admin }
let(:project) { FactoryBot.create :project }
- let(:user) { FactoryBot.create :admin }
let(:searchable) { true }
let(:is_filter) { true }
diff --git a/spec/features/security/expire_sessions_spec.rb b/spec/features/security/expire_sessions_spec.rb
index 17111470548..695d9208c34 100644
--- a/spec/features/security/expire_sessions_spec.rb
+++ b/spec/features/security/expire_sessions_spec.rb
@@ -31,10 +31,11 @@ require 'spec_helper'
describe 'Expire old user sessions',
with_config: { session_store: :active_record_store },
type: :feature do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:admin_password) { 'adminADMIN!'}
before do
- login_with(user.login, user.password)
+ login_with(admin.login, admin_password)
# Create a dangling session
Capybara.current_session.driver.browser.clear_cookies
@@ -46,15 +47,15 @@ describe 'Expire old user sessions',
expect(UserSession.count).to eq(1)
first_session = UserSession.first
- expect(first_session.user_id).to eq(user.id)
+ expect(first_session.user_id).to eq(admin.id)
# Actually login now
- login_with(user.login, user.password)
+ login_with(admin.login, admin_password)
expect(UserSession.count).to eq(1)
second_session = UserSession.first
- expect(second_session.user_id).to eq(user.id)
+ expect(second_session.user_id).to eq(admin.id)
expect(second_session.session_id).not_to eq(first_session.session_id)
end
end
@@ -62,9 +63,9 @@ describe 'Expire old user sessions',
context 'with drop_old_sessions disabled', with_config: { drop_old_sessions_on_login: false } do
it 'keeps the old session' do
# Actually login now
- login_with(user.login, user.password)
+ login_with(admin.login, admin_password)
- expect(UserSession.where(user_id: user.id).count).to eq(2)
+ expect(UserSession.where(user_id: admin.id).count).to eq(2)
end
end
end
@@ -72,15 +73,15 @@ describe 'Expire old user sessions',
describe 'logging out on another session', with_config: { drop_old_sessions_on_login: false } do
before do
# Actually login now
- login_with(user.login, user.password)
- expect(UserSession.where(user_id: user.id).count).to eq(2)
+ login_with(admin.login, admin_password)
+ expect(UserSession.where(user_id: admin.id).count).to eq(2)
visit '/logout'
end
context 'with drop_old_sessions enabled', with_config: { drop_old_sessions_on_logout: true } do
it 'destroys the old session' do
# A fresh session is opened due to reset_session
- expect(UserSession.where(user_id: user.id).count).to eq(0)
+ expect(UserSession.where(user_id: admin.id).count).to eq(0)
expect(UserSession.where(user_id: nil).count).to eq(1)
end
end
@@ -89,7 +90,7 @@ describe 'Expire old user sessions',
with_config: { drop_old_sessions_on_logout: false } do
it 'keeps the old session' do
expect(UserSession.count).to eq(2)
- expect(UserSession.where(user_id: user.id).count).to eq(1)
+ expect(UserSession.where(user_id: admin.id).count).to eq(1)
end
end
end
diff --git a/spec/features/security/session_ttl_spec.rb b/spec/features/security/session_ttl_spec.rb
index 4ac0c919aef..f714ae660d5 100644
--- a/spec/features/security/session_ttl_spec.rb
+++ b/spec/features/security/session_ttl_spec.rb
@@ -31,11 +31,13 @@ require 'spec_helper'
describe 'Session TTL',
with_settings: { session_ttl_enabled?: true, session_ttl: '10' },
type: :feature do
- let!(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:admin_password) { 'adminADMIN!'}
+
let!(:work_package) { FactoryBot.create :work_package }
before do
- login_with(user.login, user.password)
+ login_with(admin.login, admin_password)
end
def expire!
@@ -45,7 +47,7 @@ describe 'Session TTL',
describe 'outdated TTL on Rails request' do
it 'expires on the next Rails request' do
visit '/my/account'
- expect(page).to have_selector('.form--field-container', text: user.login)
+ expect(page).to have_selector('.form--field-container', text: admin.login)
# Expire the session
expire!
diff --git a/spec/features/time_entry/activity_spec.rb b/spec/features/time_entry/activity_spec.rb
index 39118bb1be9..aaf8171c75f 100644
--- a/spec/features/time_entry/activity_spec.rb
+++ b/spec/features/time_entry/activity_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Time entry activity', type: :feature do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
login_as(admin)
diff --git a/spec/features/types/crud_spec.rb b/spec/features/types/crud_spec.rb
index 25a34c00ace..de8cc5f7b05 100644
--- a/spec/features/types/crud_spec.rb
+++ b/spec/features/types/crud_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
feature 'Types', type: :feature do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
+
let!(:existing_role) { FactoryBot.create(:role) }
let!(:existing_workflow) { FactoryBot.create(:workflow_with_default_status, role: existing_role, type: existing_type) }
let!(:existing_type) { FactoryBot.create(:type) }
diff --git a/spec/features/types/form_configuration_query_spec.rb b/spec/features/types/form_configuration_query_spec.rb
index c858dc2e8ed..ce99d4e2e46 100644
--- a/spec/features/types/form_configuration_query_spec.rb
+++ b/spec/features/types/form_configuration_query_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'form query configuration', type: :feature, js: true do
- let(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
let(:type_bug) { FactoryBot.create :type_bug }
let(:type_task) { FactoryBot.create :type_task }
diff --git a/spec/features/types/form_configuration_spec.rb b/spec/features/types/form_configuration_spec.rb
index 6bdb4b89f03..d8c56ce9e00 100644
--- a/spec/features/types/form_configuration_spec.rb
+++ b/spec/features/types/form_configuration_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'form configuration', type: :feature, js: true do
- let(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
let(:type) { FactoryBot.create :type }
let(:project) { FactoryBot.create :project, types: [type] }
diff --git a/spec/features/types/reset_form_configuration_spec.rb b/spec/features/types/reset_form_configuration_spec.rb
index 7bc8bb0478d..c85ec7183c5 100644
--- a/spec/features/types/reset_form_configuration_spec.rb
+++ b/spec/features/types/reset_form_configuration_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'Reset form configuration', type: :feature, js: true do
- let(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
let(:type) { FactoryBot.create :type }
let(:project) { FactoryBot.create :project, types: [type] }
diff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rb
index 9ce8ed87082..08817c6d595 100644
--- a/spec/features/users/create_spec.rb
+++ b/spec/features/users/create_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
describe 'create users', type: :feature, selenium: true do
- let(:current_user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:current_user) { admin }
let(:auth_source) { FactoryBot.build :dummy_auth_source }
let(:new_user_page) { Pages::NewUser.new }
diff --git a/spec/features/users/edit_users_spec.rb b/spec/features/users/edit_users_spec.rb
index db9bd604beb..dbc8187efbb 100644
--- a/spec/features/users/edit_users_spec.rb
+++ b/spec/features/users/edit_users_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
describe 'edit users', type: :feature, js: true do
- let(:current_user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:current_user) { admin }
let(:user) { FactoryBot.create :user }
let!(:auth_source) { FactoryBot.create :auth_source }
diff --git a/spec/features/users/index_spec.rb b/spec/features/users/index_spec.rb
index dbc825c20e2..6048281a389 100644
--- a/spec/features/users/index_spec.rb
+++ b/spec/features/users/index_spec.rb
@@ -62,17 +62,17 @@ describe 'index users', type: :feature do
expect(active_user.reload)
.to be_locked
- index_page.filter_by_status('locked permanently (1)')
+ index_page.filter_by_status('locked permanently')
index_page.expect_listed(active_user)
- index_page.filter_by_status('active (1)')
+ index_page.filter_by_status('active')
index_page.expect_listed(admin)
- index_page.filter_by_status('locked permanently (1)')
+ index_page.filter_by_status('locked permanently')
index_page.unlock_user(active_user)
index_page.expect_non_listed
- index_page.filter_by_status('active (2)')
+ index_page.filter_by_status('active')
index_page.expect_listed(admin, active_user)
index_page.filter_by_name(active_user.lastname[0..-3])
@@ -84,7 +84,7 @@ describe 'index users', type: :feature do
index_page.clear_filters
index_page.expect_listed(admin, active_user, registered_user, invited_user)
- index_page.filter_by_status('locked temporarily (1)')
+ index_page.filter_by_status('locked temporarily')
index_page.expect_listed(active_user)
index_page.reset_failed_logins(active_user)
@@ -96,27 +96,27 @@ describe 'index users', type: :feature do
last_failed_login_on: 9.minutes.ago)
index_page.clear_filters
- index_page.filter_by_status('locked temporarily (1)')
+ index_page.filter_by_status('locked temporarily')
index_page.expect_listed(active_user)
index_page.lock_user(active_user)
index_page.expect_listed(active_user)
- index_page.filter_by_status('locked permanently (1)')
+ index_page.filter_by_status('locked permanently')
index_page.expect_listed(active_user)
index_page.unlock_and_reset_user(active_user)
index_page.expect_non_listed
- index_page.filter_by_status('active (2)')
+ index_page.filter_by_status('active')
index_page.expect_listed(admin, active_user)
# activate registered user
- index_page.filter_by_status('registered (1)')
+ index_page.filter_by_status('registered')
index_page.expect_listed(registered_user)
index_page.activate_user(registered_user)
- index_page.filter_by_status('active (3)')
+ index_page.filter_by_status('active')
index_page.expect_listed(admin, active_user, registered_user)
end
diff --git a/spec/features/users/invitation_spec.rb b/spec/features/users/invitation_spec.rb
index 9a23e9fd8ff..802504301aa 100644
--- a/spec/features/users/invitation_spec.rb
+++ b/spec/features/users/invitation_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
feature 'invitation spec', type: :feature, js: true do
- let(:current_user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:current_user) { admin }
let(:user) { FactoryBot.create :invited_user, mail: 'holly@openproject.com' }
before do
diff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rb
index 2ed1e924df7..5d1cb058277 100644
--- a/spec/features/users/my_spec.rb
+++ b/spec/features/users/my_spec.rb
@@ -98,14 +98,11 @@ describe 'my',
end
context 'as admin' do
- let(:user) do
- FactoryBot.create :admin,
- password: user_password,
- password_confirmation: user_password
- end
+ using_shared_fixtures :admin
+ let(:user) { admin }
it 'requires the password' do
- dialog.confirm_flow_with(user_password)
+ dialog.confirm_flow_with('adminADMIN!')
expect_changed!
end
end
diff --git a/spec/features/users/password_change_spec.rb b/spec/features/users/password_change_spec.rb
index a4ec2165283..6706613d1f7 100644
--- a/spec/features/users/password_change_spec.rb
+++ b/spec/features/users/password_change_spec.rb
@@ -32,7 +32,8 @@ describe 'random password generation',
with_config: { session_store: :active_record_store },
type: :feature,
js: true do
- let(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+
let(:auth_source) { FactoryBot.build :dummy_auth_source }
let(:old_password) { 'old_Password!123' }
let(:new_password) { 'new_Password!123' }
diff --git a/spec/features/wiki/wiki_unicode_spec.rb b/spec/features/wiki/wiki_unicode_spec.rb
index b79b59c704a..4b88bf1e813 100644
--- a/spec/features/wiki/wiki_unicode_spec.rb
+++ b/spec/features/wiki/wiki_unicode_spec.rb
@@ -29,7 +29,9 @@
require 'spec_helper'
describe 'Wiki unicode title spec', type: :feature, js: true do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
+
let(:project) { FactoryBot.create :project }
let(:wiki_page_1) do
FactoryBot.build :wiki_page_with_content,
diff --git a/spec/features/work_packages/custom_actions_spec.rb b/spec/features/work_packages/custom_actions_spec.rb
index 173edcc268c..4326d01793b 100644
--- a/spec/features/work_packages/custom_actions_spec.rb
+++ b/spec/features/work_packages/custom_actions_spec.rb
@@ -29,10 +29,11 @@
require 'spec_helper'
describe 'Custom actions', type: :feature, js: true do
+ using_shared_fixtures :admin
+
let(:permissions) { %i(view_work_packages edit_work_packages move_work_packages) }
let(:role) { FactoryBot.create(:role, permissions: permissions) }
let!(:other_role) { FactoryBot.create(:role, permissions: permissions) }
- let(:admin) { FactoryBot.create(:admin) }
let(:user) do
user = FactoryBot.create(:user,
firstname: 'A',
diff --git a/spec/features/work_packages/index_sums_spec.rb b/spec/features/work_packages/index_sums_spec.rb
index efce811d761..cfb248a1d9d 100644
--- a/spec/features/work_packages/index_sums_spec.rb
+++ b/spec/features/work_packages/index_sums_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
RSpec.feature 'Work package index sums', js: true do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
+
let(:project) do
FactoryBot.create(:project, name: 'project1', identifier: 'project1')
end
diff --git a/spec/features/work_packages/pagination_spec.rb b/spec/features/work_packages/pagination_spec.rb
index 04c4ddaec5f..6e3c62334e4 100644
--- a/spec/features/work_packages/pagination_spec.rb
+++ b/spec/features/work_packages/pagination_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
RSpec.feature 'Work package pagination', js: true do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
+
let(:project) do
FactoryBot.create(:project, name: 'project1', identifier: 'project1')
end
diff --git a/spec/features/wysiwyg/macros/code_block_macro_spec.rb b/spec/features/wysiwyg/macros/code_block_macro_spec.rb
index ada8f3d9039..2c0eece5355 100644
--- a/spec/features/wysiwyg/macros/code_block_macro_spec.rb
+++ b/spec/features/wysiwyg/macros/code_block_macro_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
describe 'Wysiwyg code block macro', type: :feature, js: true do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) }
let(:editor) { ::Components::WysiwygEditor.new }
diff --git a/spec/features/wysiwyg/macros/embedded_tables_spec.rb b/spec/features/wysiwyg/macros/embedded_tables_spec.rb
index 96afc2b76a3..7fcc5207534 100644
--- a/spec/features/wysiwyg/macros/embedded_tables_spec.rb
+++ b/spec/features/wysiwyg/macros/embedded_tables_spec.rb
@@ -30,7 +30,8 @@ require 'spec_helper'
describe 'Wysiwyg embedded work package tables',
type: :feature, js: true do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki work_package_tracking]) }
let(:editor) { ::Components::WysiwygEditor.new }
let!(:work_package) { FactoryBot.create(:work_package, project: project) }
diff --git a/spec/features/wysiwyg/macros/work_package_button_spec.rb b/spec/features/wysiwyg/macros/work_package_button_spec.rb
index b7f40357f6c..84380fce62e 100644
--- a/spec/features/wysiwyg/macros/work_package_button_spec.rb
+++ b/spec/features/wysiwyg/macros/work_package_button_spec.rb
@@ -30,7 +30,9 @@ require 'spec_helper'
describe 'Wysiwyg work package button spec',
type: :feature, js: true do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
+
let!(:type) { FactoryBot.create :type, name: 'MyTaskName' }
let(:project) do
FactoryBot.create :valid_project,
diff --git a/spec/features/wysiwyg/non_breaking_spaces_spec.rb b/spec/features/wysiwyg/non_breaking_spaces_spec.rb
index ceb4723aa31..4c8c90ef8be 100644
--- a/spec/features/wysiwyg/non_breaking_spaces_spec.rb
+++ b/spec/features/wysiwyg/non_breaking_spaces_spec.rb
@@ -30,7 +30,9 @@ require 'spec_helper'
describe 'Wysiwyg behavior',
type: :feature, js: true do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin}
+
let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) }
let(:editor) { ::Components::WysiwygEditor.new }
diff --git a/spec/features/wysiwyg/tables_spec.rb b/spec/features/wysiwyg/tables_spec.rb
index 50d33c39474..8575f067641 100644
--- a/spec/features/wysiwyg/tables_spec.rb
+++ b/spec/features/wysiwyg/tables_spec.rb
@@ -30,7 +30,9 @@ require 'spec_helper'
describe 'Wysiwyg tables',
type: :feature, js: true do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
+
let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) }
let(:editor) { ::Components::WysiwygEditor.new }
diff --git a/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb b/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb
index 8058809bb5b..6e8b10da601 100644
--- a/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb
+++ b/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb
@@ -142,7 +142,8 @@ describe ::API::V3::Queries::Filters::QueryFilterInstanceRepresenter do
end
context 'with a subproject filter value_objects' do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+
let(:project) { FactoryBot.create :project }
let(:subproject) { FactoryBot.create :project, parent: project }
let(:filter) do
@@ -158,7 +159,7 @@ describe ::API::V3::Queries::Filters::QueryFilterInstanceRepresenter do
end
before do
- login_as user
+ login_as admin
allow(filter)
.to receive(:value_objects)
diff --git a/spec/lib/api/v3/relations/relation_representer_spec.rb b/spec/lib/api/v3/relations/relation_representer_spec.rb
index 8499deefd1c..a4efdea530d 100644
--- a/spec/lib/api/v3/relations/relation_representer_spec.rb
+++ b/spec/lib/api/v3/relations/relation_representer_spec.rb
@@ -29,7 +29,8 @@
require 'spec_helper'
describe ::API::V3::Relations::RelationRepresenter do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
let(:from) { FactoryBot.create :work_package }
let(:to) { FactoryBot.create :work_package }
diff --git a/spec/lib/open_project/enterprise_spec.rb b/spec/lib/open_project/enterprise_spec.rb
index ff34900ad76..a17fc1e8a0a 100644
--- a/spec/lib/open_project/enterprise_spec.rb
+++ b/spec/lib/open_project/enterprise_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
require 'open_project/passwords'
-describe OpenProject::Enterprise do
+describe OpenProject::Enterprise, :with_clean_fixture do
describe "#user_limit_reached?" do
let(:user_limit) { 2 }
let(:builtin_user_count) { 2 }
diff --git a/spec/lib/open_project/macros/work_package_buttons_macro_spec.rb b/spec/lib/open_project/macros/work_package_buttons_macro_spec.rb
index dcf8f785c09..8358ebbd38e 100644
--- a/spec/lib/open_project/macros/work_package_buttons_macro_spec.rb
+++ b/spec/lib/open_project/macros/work_package_buttons_macro_spec.rb
@@ -29,6 +29,8 @@
require 'spec_helper'
describe 'OpenProject work package button macros' do
+ using_shared_fixtures :admin
+
include ActionView::Helpers::UrlHelper
include OpenProject::StaticRouting::UrlHelpers
include OpenProject::TextFormatting
@@ -39,13 +41,12 @@ describe 'OpenProject work package button macros' do
let(:type) { FactoryBot.create :type, name: 'MyTaskName' }
let(:project) { FactoryBot.create :valid_project, identifier: 'my-project', name: 'My project name', types: [type] }
- let(:user) { FactoryBot.create :admin }
let(:input) { }
subject { format_text(input, project: project) }
before do
- login_as user
+ login_as admin
end
def error_html(exception_msg)
diff --git a/spec/models/deleted_user_spec.rb b/spec/models/deleted_user_spec.rb
index c1bfd96e9a1..1820f143ae9 100644
--- a/spec/models/deleted_user_spec.rb
+++ b/spec/models/deleted_user_spec.rb
@@ -29,10 +29,6 @@
require 'spec_helper'
describe DeletedUser, type: :model do
- before do
- User.delete_all
- end
-
let(:user) { DeletedUser.new }
describe '#admin' do
diff --git a/spec/models/news_spec.rb b/spec/models/news_spec.rb
index 2bb361c328f..9a282b75583 100644
--- a/spec/models/news_spec.rb
+++ b/spec/models/news_spec.rb
@@ -51,6 +51,8 @@ describe News, type: :model do
end
describe '.latest' do
+ let(:project_news) { News.where(project: project) }
+
before do
Role.anonymous
end
@@ -74,34 +76,35 @@ describe News, type: :model do
end
it 'limits the number of returned news elements' do
- News.delete_all
+ project_news.delete_all
10.times do
FactoryBot.create(:news, project: project)
end
- expect(News.latest(user: User.current, count: 2).size).to eq(2)
- expect(News.latest(user: User.current, count: 6).size).to eq(6)
- expect(News.latest(user: User.current, count: 15).size).to eq(10)
+ expect(project_news.latest(user: User.current, count: 2).size).to eq(2)
+ expect(project_news.latest(user: User.current, count: 6).size).to eq(6)
+ expect(project_news.latest(user: User.current, count: 15).size).to eq(10)
end
it 'returns five news elements by default' do
- News.delete_all
+ project_news.delete_all
2.times do
FactoryBot.create(:news, project: project)
end
- expect(News.latest.size).to eq(2)
+
+ expect(project_news.latest.size).to eq(2)
3.times do
FactoryBot.create(:news, project: project)
end
- expect(News.latest.size).to eq(5)
+ expect(project_news.latest.size).to eq(5)
2.times do
FactoryBot.create(:news, project: project)
end
- expect(News.latest.size).to eq(5)
+ expect(project_news.latest.size).to eq(5)
end
end
diff --git a/spec/models/principal_spec.rb b/spec/models/principal_spec.rb
index 01dacf9df07..6281f9a5644 100644
--- a/spec/models/principal_spec.rb
+++ b/spec/models/principal_spec.rb
@@ -36,19 +36,19 @@ describe Principal, type: :model do
it 'should return a user' do
user.save!
- expect(Principal.send(method, *params)).to eq([user])
+ expect(Principal.send(method, *params).where(id: user.id)).to eq([user])
end
it 'should return a group' do
group.save!
- expect(Principal.send(method, *params)).to eq([group])
+ expect(Principal.send(method, *params).where(id: group.id)).to eq([group])
end
it 'should not return the anonymous user' do
User.anonymous
- expect(Principal.send(method, *params)).to eq([])
+ expect(Principal.send(method, *params).where(id: user.id)).to eq([])
end
it 'should not return an inactive user' do
@@ -56,7 +56,7 @@ describe Principal, type: :model do
user.save!
- expect(Principal.send(method, *params)).to eq([])
+ expect(Principal.send(method, *params).where(id: user.id).to_a).to eq([])
end
end
@@ -68,7 +68,7 @@ describe Principal, type: :model do
user.save!
- expect(Principal.active).to eq([])
+ expect(Principal.active.where(id: user.id)).to eq([])
end
end
@@ -80,7 +80,7 @@ describe Principal, type: :model do
user.save!
- expect(Principal.active_or_registered).to eq([user])
+ expect(Principal.active_or_registered.where(id: user.id)).to eq([user])
end
end
@@ -103,19 +103,19 @@ describe Principal, type: :model do
user.save!
- expect(Principal.active_or_registered_like(search)).to eq([user])
+ expect(Principal.active_or_registered_like(search).where(id: user.id)).to eq([user])
end
it 'should not return a user if the name does not match' do
user.save!
- expect(Principal.active_or_registered_like(user.lastname + '123')).to eq([])
+ expect(Principal.active_or_registered_like(user.lastname + '123').to_a).not_to include(user)
end
it 'should return a group if the name does match partially' do
user.save!
- expect(Principal.active_or_registered_like(user.lastname[0, -1])).to eq([user])
+ expect(Principal.active_or_registered_like(user.lastname[0, -1]).to_a).to include(user)
end
end
@@ -126,9 +126,14 @@ describe Principal, type: :model do
let!(:group) { FactoryBot.create(:group) }
let!(:user) { FactoryBot.create(:user) }
- it 'returns only actual users and groups' do
- expect(described_class.not_builtin)
- .to match_array [user, group]
+ subject { described_class.not_builtin }
+
+ it 'returns only actual users and groups', :aggregate_failures do
+ expect(subject).to include(user)
+ expect(subject).to include(group)
+ expect(subject).not_to include(anonymous_user)
+ expect(subject).not_to include(system_user)
+ expect(subject).not_to include(deleted_user)
end
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 27a56502880..688dcc3347c 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -31,11 +31,11 @@ require File.expand_path('../../support/shared/become_member', __FILE__)
describe Project, type: :model do
include BecomeMember
+ using_shared_fixtures :admin
let(:active) { true }
let(:project) { FactoryBot.create(:project, active: active) }
let(:build_project) { FactoryBot.build_stubbed(:project, active: active) }
- let(:admin) { FactoryBot.create(:admin) }
let(:user) { FactoryBot.create(:user) }
describe '#active?' do
diff --git a/spec/models/type/attribute_groups_spec.rb b/spec/models/type/attribute_groups_spec.rb
index 0d2a298daff..111405bfbca 100644
--- a/spec/models/type/attribute_groups_spec.rb
+++ b/spec/models/type/attribute_groups_spec.rb
@@ -32,7 +32,7 @@ require 'spec_helper'
describe ::Type, type: :model do
let(:type) { FactoryBot.build(:type) }
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
before do
# Clear up the request store cache for all_work_package_attributes
diff --git a/spec/models/user_deletion_spec.rb b/spec/models/user_deletion_spec.rb
index 1d14f61641e..59b17106e8b 100644
--- a/spec/models/user_deletion_spec.rb
+++ b/spec/models/user_deletion_spec.rb
@@ -30,8 +30,8 @@ require 'spec_helper'
describe User, 'deletion', type: :model do
let(:project) { FactoryBot.create(:project_with_types) }
- let(:user) { FactoryBot.build(:user, member_in_project: project) }
- let(:user2) { FactoryBot.build(:user) }
+ let(:user) { FactoryBot.create(:user, member_in_project: project) }
+ let(:user2) { FactoryBot.create(:user) }
let(:member) { project.members.first }
let(:role) { member.roles.first }
let(:status) { FactoryBot.create(:status) }
@@ -52,13 +52,6 @@ describe User, 'deletion', type: :model do
let(:substitute_user) { DeletedUser.first }
- before do
- # for some reason there seem to be users in the db
- User.delete_all
- user.save!
- user2.save!
- end
-
describe 'WHEN there is the user' do
before do
user.destroy
@@ -334,13 +327,17 @@ describe User, 'deletion', type: :model do
describe 'WHEN the user is a member of a project' do
before do
- member # saving
- user.destroy
+ user
+ member
end
- it { expect(Member.find_by(id: member.id)).to be_nil }
- it { expect(Role.find_by(id: role.id)).to eq(role) }
- it { expect(Project.find_by(id: project.id)).to eq(project) }
+ it 'removes that member' do
+ user.destroy
+
+ expect(Member.find_by(id: member.id)).to be_nil
+ expect(Role.find_by(id: role.id)).to eq(role)
+ expect(Project.find_by(id: project.id)).to eq(project)
+ end
end
describe 'WHEN the user is watching something' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 9626ed2aeec..3cd06765554 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -51,9 +51,13 @@ describe User, type: :model do
let!(:deleted_user) { FactoryBot.create(:deleted_user) }
let!(:user) { FactoryBot.create(:user) }
- it 'returns only actual users' do
- expect(described_class.not_builtin)
- .to match_array [user]
+ subject { described_class.not_builtin }
+
+ it 'returns only actual users', :aggregate_failures do
+ expect(subject).to include(user)
+ expect(subject).not_to include(anonymous_user)
+ expect(subject).not_to include(system_user)
+ expect(subject).not_to include(deleted_user)
end
end
@@ -629,12 +633,16 @@ describe User, type: :model do
end
describe 'scope.newest' do
- let!(:anonymous) { FactoryBot.create(:anonymous) }
+ let!(:anonymous) { User.anonymous }
let!(:user1) { FactoryBot.create(:user) }
let!(:user2) { FactoryBot.create(:user) }
- it 'without anonymous user' do
- expect(User.newest).to match_array([user1, user2])
+ let(:newest) { User.newest.to_a }
+
+ it 'without anonymous user', :aggregate_failures do
+ expect(newest).to include(user1)
+ expect(newest).to include(user2)
+ expect(newest).not_to include(anonymous)
end
end
diff --git a/spec/models/users/allowed_scope_spec.rb b/spec/models/users/allowed_scope_spec.rb
index 9bb14a4a703..1dfec3c9fde 100644
--- a/spec/models/users/allowed_scope_spec.rb
+++ b/spec/models/users/allowed_scope_spec.rb
@@ -63,7 +63,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed(action, project)).to match_array [user]
+ expect(User.allowed(action, project).where(id: user.id)).to match_array [user]
end
end
@@ -76,7 +76,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed(action, project)).to match_array [user]
+ expect(User.allowed(action, project).where(id: user.id)).to match_array [user]
end
end
@@ -90,7 +90,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -103,7 +103,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -120,7 +120,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -139,7 +139,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -157,7 +157,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed(action, project)).to match_array [user]
+ expect(User.allowed(action, project).where(id: user.id)).to match_array [user]
end
end
@@ -175,7 +175,7 @@ describe User, 'allowed scope' do
end
it 'should return the anonymous user' do
- expect(User.allowed(action, project)).to match_array([anonymous])
+ expect(User.allowed(action, project).where(id: [user.id, anonymous.id])).to match_array([anonymous])
end
end
@@ -193,7 +193,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -209,7 +209,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -230,7 +230,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(action, project)).to be_empty
+ expect(User.allowed(action, project).where(id: user.id)).to be_empty
end
end
@@ -244,7 +244,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed(public_action, project)).to match_array [user]
+ expect(User.allowed(public_action, project).where(id: user.id)).to match_array [user]
end
end
@@ -259,7 +259,7 @@ describe User, 'allowed scope' do
end
it 'should return the user and anonymous' do
- expect(User.allowed(public_action, project)).to match_array [user, anonymous]
+ expect(User.allowed(public_action, project).where(id: [user.id, anonymous.id])).to match_array [user, anonymous]
end
end
@@ -280,7 +280,7 @@ describe User, 'allowed scope' do
end
it 'should be empty' do
- expect(User.allowed(permission.name, project)).to eq []
+ expect(User.allowed(permission.name, project).where(id: user.id)).to eq []
end
end
@@ -301,7 +301,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed(permission.name, project)).to eq [user]
+ expect(User.allowed(permission.name, project).where(id: user.id)).to eq [user]
end
end
@@ -331,7 +331,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed_members(action, project)).to be_empty
+ expect(User.allowed_members(action, project).where(id: user.id)).to be_empty
end
end
@@ -346,7 +346,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed_members(action, project)).to match_array [user]
+ expect(User.allowed_members(action, project).where(id: user.id)).to match_array [user]
end
end
@@ -359,7 +359,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed_members(action, project)).to be_empty
+ expect(User.allowed_members(action, project).where(id: user.id)).to be_empty
end
end
@@ -376,7 +376,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed_members(action, project)).to match_array [user]
+ expect(User.allowed_members(action, project).where(id: user.id)).to match_array [user]
end
end
@@ -391,7 +391,7 @@ describe User, 'allowed scope' do
end
it 'should return the user' do
- expect(User.allowed_members(action, project)).to be_empty
+ expect(User.allowed_members(action, project).where(id: user.id)).to be_empty
end
end
end
diff --git a/spec/models/work_package/openproject_notifications_spec.rb b/spec/models/work_package/openproject_notifications_spec.rb
index 41db8d068a0..a2794dd5c4a 100644
--- a/spec/models/work_package/openproject_notifications_spec.rb
+++ b/spec/models/work_package/openproject_notifications_spec.rb
@@ -33,12 +33,12 @@ require 'spec_helper'
# Tests that email notifications will be sent upon creating or changing a work package.
describe WorkPackage, type: :model do
describe 'OpenProject notifications' do
- let(:user) { FactoryBot.create :admin }
- let(:current_user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+
let(:project) { FactoryBot.create :project }
let(:work_package) do
FactoryBot.create :work_package,
- author: user,
+ author: admin,
subject: 'I can see you',
project: project
end
diff --git a/spec/models/work_package/work_package_acts_as_journalized_spec.rb b/spec/models/work_package/work_package_acts_as_journalized_spec.rb
index 83e18228456..e983d34b79a 100644
--- a/spec/models/work_package/work_package_acts_as_journalized_spec.rb
+++ b/spec/models/work_package/work_package_acts_as_journalized_spec.rb
@@ -404,14 +404,11 @@ describe WorkPackage, type: :model do
describe 'Acts as journalized' do
before(:each) do
- Status.delete_all
- IssuePriority.delete_all
-
@type ||= FactoryBot.create(:type_feature)
- @status_resolved ||= FactoryBot.create(:status, name: 'Resolved', is_default: false)
- @status_open ||= FactoryBot.create(:status, name: 'Open', is_default: true)
- @status_rejected ||= FactoryBot.create(:status, name: 'Rejected', is_default: false)
+ @status_resolved ||= FactoryBot.create(:status, name: 'Resolved')
+ @status_open ||= FactoryBot.create(:status, name: 'Open')
+ @status_rejected ||= FactoryBot.create(:status, name: 'Rejected')
role = FactoryBot.create(:role)
FactoryBot.create(:workflow,
@@ -425,7 +422,7 @@ describe WorkPackage, type: :model do
role: role,
type_id: @type.id)
- @priority_low ||= FactoryBot.create(:priority_low, is_default: true)
+ @priority_low ||= FactoryBot.create(:priority_low)
@priority_high ||= FactoryBot.create(:priority_high)
@project ||= FactoryBot.create(:project, no_types: true, types: [@type])
diff --git a/spec/models/work_package/work_package_notifications_spec.rb b/spec/models/work_package/work_package_notifications_spec.rb
index 44366995bcf..919955393fb 100644
--- a/spec/models/work_package/work_package_notifications_spec.rb
+++ b/spec/models/work_package/work_package_notifications_spec.rb
@@ -33,7 +33,8 @@ require 'spec_helper'
# Tests that email notifications will be sent upon creating or changing a work package.
describe WorkPackage, type: :model do
describe 'email notifications' do
- let(:user) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
+ let(:user) { admin }
let(:current_user) { FactoryBot.create :admin }
let(:project) { FactoryBot.create :project }
let!(:work_package) do
diff --git a/spec/models/work_package/work_package_visibility_spec.rb b/spec/models/work_package/work_package_visibility_spec.rb
index 7fa513af446..a8f822db70e 100644
--- a/spec/models/work_package/work_package_visibility_spec.rb
+++ b/spec/models/work_package/work_package_visibility_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'WorkPackage-Visibility', type: :model do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
let(:anonymous) { FactoryBot.create(:anonymous) }
let(:user) { FactoryBot.create(:user) }
let(:public_project) { FactoryBot.create(:project, public: true) }
diff --git a/spec/requests/api/v3/activities_api_spec.rb b/spec/requests/api/v3/activities_api_spec.rb
index 9c3a92c8296..2f31c1a3658 100644
--- a/spec/requests/api/v3/activities_api_spec.rb
+++ b/spec/requests/api/v3/activities_api_spec.rb
@@ -33,7 +33,8 @@ describe API::V3::Activities::ActivitiesAPI, type: :request do
include Rack::Test::Methods
include API::V3::Utilities::PathHelper
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
+
let(:comment) { 'This is a test comment!' }
shared_examples_for 'safeguarded API' do
diff --git a/spec/requests/api/v3/support/api_helper.rb b/spec/requests/api/v3/support/api_helper.rb
index 02d9bfedf80..a5d17da722c 100644
--- a/spec/requests/api/v3/support/api_helper.rb
+++ b/spec/requests/api/v3/support/api_helper.rb
@@ -31,8 +31,8 @@ shared_examples_for 'safeguarded API' do
end
shared_examples_for 'valid activity request' do
+ using_shared_fixtures :admin
let(:status_code) { 200 }
- let(:admin) { FactoryBot.create(:admin) }
before do
allow(User).to receive(:current).and_return(admin)
@@ -50,7 +50,8 @@ shared_examples_for 'valid activity request' do
end
shared_examples_for 'invalid activity request' do
- let(:admin) { FactoryBot.create(:admin) }
+ using_shared_fixtures :admin
+
before do
allow(User).to receive(:current).and_return(admin)
end
diff --git a/spec/requests/api/v3/support/api_v3_collection_response.rb b/spec/requests/api/v3/support/api_v3_collection_response.rb
index b5a87b3cd4f..851fdd0da0c 100644
--- a/spec/requests/api/v3/support/api_v3_collection_response.rb
+++ b/spec/requests/api/v3/support/api_v3_collection_response.rb
@@ -31,19 +31,36 @@ require 'spec_helper'
shared_examples_for 'API V3 collection response' do |total, count, type|
subject { last_response.body }
- it { expect(last_response.status).to eql(200) }
+ # Allow input to pass a proc to avoid counting before the example
+ # context
+ let(:total_number) do
+ if total.is_a? Proc
+ total.call
+ else
+ total
+ end
+ end
- it { is_expected.to be_json_eql('Collection'.to_json).at_path('_type') }
+ let(:count_number) do
+ if count.is_a? Proc
+ count.call
+ else
+ count
+ end
+ end
- it { is_expected.to be_json_eql(count.to_json).at_path('count') }
+ it 'returns a collection successfully' do
+ aggregate_failures do
- it { is_expected.to be_json_eql(total.to_json).at_path('total') }
+ expect(last_response.status).to eql(200)
+ expect(subject).to be_json_eql('Collection'.to_json).at_path('_type')
+ expect(subject).to be_json_eql(count_number.to_json).at_path('count')
+ expect(subject).to be_json_eql(total_number.to_json).at_path('total')
+ expect(subject).to have_json_size(count_number).at_path('_embedded/elements')
- it { is_expected.to have_json_size(count) .at_path('_embedded/elements') }
-
- it 'has element of specified type if elements exist' do
- if count > 0
- is_expected.to be_json_eql(type.to_json).at_path('_embedded/elements/0/_type')
+ if count_number > 0
+ expect(subject).to be_json_eql(type.to_json).at_path('_embedded/elements/0/_type')
+ end
end
end
end
diff --git a/spec/requests/api/v3/user/filters_spec.rb b/spec/requests/api/v3/user/filters_spec.rb
index 683a39fcbe1..777fab2fb8c 100644
--- a/spec/requests/api/v3/user/filters_spec.rb
+++ b/spec/requests/api/v3/user/filters_spec.rb
@@ -29,7 +29,9 @@
require 'spec_helper'
-describe 'GET /api/v3/users', type: :request do
+describe 'GET /api/v3/users',
+ :with_clean_fixture,
+ type: :request do
let!(:users) do
[
FactoryBot.create(:admin, login: 'admin', status: Principal::STATUSES[:active]),
diff --git a/spec/requests/api/v3/user/user_resource_spec.rb b/spec/requests/api/v3/user/user_resource_spec.rb
index 6618770d7f4..f627dfda6f6 100644
--- a/spec/requests/api/v3/user/user_resource_spec.rb
+++ b/spec/requests/api/v3/user/user_resource_spec.rb
@@ -29,7 +29,10 @@
require 'spec_helper'
require 'rack/test'
-describe 'API v3 User resource', type: :request, content_type: :json do
+describe 'API v3 User resource',
+ type: :request,
+ content_type: :json,
+ with_clean_fixture: true do
include Rack::Test::Methods
include API::V3::Utilities::PathHelper
diff --git a/spec/services/authorization/user_allowed_query_spec.rb b/spec/services/authorization/user_allowed_query_spec.rb
index b51f9e0834c..7f619f46930 100644
--- a/spec/services/authorization/user_allowed_query_spec.rb
+++ b/spec/services/authorization/user_allowed_query_spec.rb
@@ -28,7 +28,7 @@
require 'spec_helper'
-describe Authorization::UserAllowedQuery do
+describe Authorization::UserAllowedQuery, :with_clean_fixture do
describe '.query' do
let(:user) { member.principal }
let(:anonymous) { FactoryBot.build(:anonymous) }
diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rb
index 1b95937e45b..97f67566db2 100644
--- a/spec/services/work_packages/update_service_integration_spec.rb
+++ b/spec/services/work_packages/update_service_integration_spec.rb
@@ -1197,12 +1197,14 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma
#
# Trying to set parent of C to B failed because parent relation is requested before change is saved.
describe 'Changing parent to a new one that has the same parent as the current element (Regression #27746)' do
+ using_shared_fixtures :admin
+ let(:user) { admin }
+
let(:project) { FactoryBot.create :project }
let!(:wp_a) { FactoryBot.create :work_package }
let!(:wp_b) { FactoryBot.create :work_package, parent: wp_a }
let!(:wp_c) { FactoryBot.create :work_package, parent: wp_a }
- let(:user) { FactoryBot.create :admin }
let(:work_package) { wp_c }
let(:attributes) { { parent: wp_b } }
diff --git a/spec/support/pages/admin/users/index.rb b/spec/support/pages/admin/users/index.rb
index 8f648196b18..41cbc130206 100644
--- a/spec/support/pages/admin/users/index.rb
+++ b/spec/support/pages/admin/users/index.rb
@@ -38,7 +38,7 @@ module Pages
def expect_listed(*users)
rows = page.all 'td.username'
- expect(rows.map(&:text)).to match_array(users.map(&:login))
+ expect(rows.map(&:text)).to include(*users.map(&:login))
end
def expect_non_listed
diff --git a/spec/support/rspec_cleanup.rb b/spec/support/rspec_cleanup.rb
index 919d01a42d8..f50793f8792 100644
--- a/spec/support/rspec_cleanup.rb
+++ b/spec/support/rspec_cleanup.rb
@@ -16,7 +16,7 @@ RSpec.configure do |config|
# We don't want this to be reported on CI as it breaks the build
unless ENV['CI']
- config.after(:suite) do
+ config.append_after(:suite) do
[User, Project, WorkPackage].each do |cls|
next if cls.count == 0
raise <<-EOS
diff --git a/spec/support/shared_fixtures/shared_fixture.rb b/spec/support/shared_fixtures/shared_fixture.rb
new file mode 100644
index 00000000000..b4b63ad40c8
--- /dev/null
+++ b/spec/support/shared_fixtures/shared_fixture.rb
@@ -0,0 +1,60 @@
+require 'test_prof/recipes/rspec/any_fixture'
+require 'test_prof/ext/active_record_refind'
+
+##
+# Shared fixture class, tiny wrapper around TestProf::AnyFixture.
+# This will allow to lazily define fixtures through FactoryBot calls
+# that are created once and reloaded (instead of recreated) for each example.
+class SharedFixture
+
+ # Keep a registry of fixture to instantiate
+ # them lazily.
+ cattr_accessor :fixtures
+ self.fixtures = {}
+
+ # A unique fixture key that we identify dynamic fixtures by
+ attr_reader :key, :builder
+
+ def initialize(key, builder)
+ @key = key
+ @builder = builder
+ end
+
+ def self.context_name(key)
+ "shared fixture: #{key}"
+ end
+
+ ##
+ # Create the fixture.
+ # This will call the fixture builder.
+ def self.create!(key)
+ fixture = self.fixtures.fetch key
+ ::TestProf::AnyFixture.register(key, &fixture)
+ end
+
+ # Reload items that will be a bit slower,
+ # but ensure we have a fresh object
+ using TestProf::Ext::ActiveRecordRefind
+
+ ##
+ # Register a factory as a shared_context
+ # with the context_name "shared fixture: "
+ # that will bootstrap the Factory once whenever its included.
+ def self.register!(key, &block)
+ self.fixtures[key] = block
+
+ RSpec.shared_context(self.context_name(key)) do
+ before(:all) { ::SharedFixture.create!(key) }
+ let(key) { ::TestProf::AnyFixture.register(key).refind }
+ end
+ end
+end
+
+##
+# Helper method injected into rspec to load fixtures into self
+# Include one or mulitple shared fixture(s)
+def using_shared_fixtures(*keys)
+ keys.each do |key|
+ include_context ::SharedFixture.context_name(key)
+ end
+end
diff --git a/spec/support/shared_fixtures/users/admin_user.rb b/spec/support/shared_fixtures/users/admin_user.rb
new file mode 100644
index 00000000000..c49132a0b01
--- /dev/null
+++ b/spec/support/shared_fixtures/users/admin_user.rb
@@ -0,0 +1,7 @@
+require_relative '../shared_fixture'
+
+::SharedFixture.register! :admin do
+ FactoryBot.create :admin,
+ password: 'adminADMIN!',
+ password_confirmation: 'adminADMIN!'
+end
diff --git a/spec/support/shared_fixtures/users/generated.rb b/spec/support/shared_fixtures/users/generated.rb
new file mode 100644
index 00000000000..e9ef61a6bd5
--- /dev/null
+++ b/spec/support/shared_fixtures/users/generated.rb
@@ -0,0 +1,13 @@
+require_relative '../shared_fixture'
+
+# For many factories, we often need one instance
+# without any customized attributes.
+# Thus we expose them dynamically as AnyFixture,
+# so they will be loaded only once.
+%i[
+ anonymous
+].each do |factory_key|
+ ::SharedFixture.register! factory_key do
+ FactoryBot.create factory_key
+ end
+end
diff --git a/spec/support/shared_let.rb b/spec/support/shared_let.rb
index 4bddfa47aed..f4bf9dc3627 100644
--- a/spec/support/shared_let.rb
+++ b/spec/support/shared_let.rb
@@ -37,6 +37,8 @@
# than creating new records (especially, work packages).
#
# Since test-prof added `let_it_be` this is only a wrapper for it
+# before_all / let_it_be fixture
+require 'test_prof/recipes/rspec/before_all'
require 'test_prof/recipes/rspec/let_it_be'
def shared_let(key, reload: true, refind: false, &block)
diff --git a/spec/views/layouts/admin.html.erb_spec.rb b/spec/views/layouts/admin.html.erb_spec.rb
index 4fef9b436d2..9c0f0781a23 100644
--- a/spec/views/layouts/admin.html.erb_spec.rb
+++ b/spec/views/layouts/admin.html.erb_spec.rb
@@ -29,11 +29,11 @@
require 'spec_helper'
describe 'layouts/admin', type: :view do
+ using_shared_fixtures :admin
+
include Redmine::MenuManager::MenuHelper
helper Redmine::MenuManager::MenuHelper
- let(:admin) { FactoryBot.create :admin }
-
before do
allow(view).to receive(:current_menu_item).and_return('overview')
allow(view).to receive(:default_breadcrumb)
diff --git a/spec/views/users/index.html.erb_spec.rb b/spec/views/users/index.html.erb_spec.rb
index 96f1ac0bda2..7585667acf7 100644
--- a/spec/views/users/index.html.erb_spec.rb
+++ b/spec/views/users/index.html.erb_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe 'users/index', type: :view do
- let!(:admin) { FactoryBot.create :admin }
+ using_shared_fixtures :admin
let!(:user) { FactoryBot.create :user, firstname: "Scarlet", lastname: "Scallywag" }
before do
diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb
index 8d5da681c92..7aa711c4aa3 100644
--- a/spec_legacy/unit/user_spec.rb
+++ b/spec_legacy/unit/user_spec.rb
@@ -260,8 +260,7 @@ describe User, type: :model do
puts 'Skipping LDAP tests.'
end
- it 'should create anonymous' do
- AnonymousUser.delete_all
+ it 'should return existing or new anonymous' do
anon = User.anonymous
assert !anon.new_record?
assert_kind_of AnonymousUser, anon