Use AnyFixtures to generate fixtures from factories (#7230)

Uses FactoryBot to keep and maintain specific records in a special transaction that does not get removed after each spec.
They automatically are created whenever first hitting them.
This makes an excellent time saver for items that are commonly used, such as an admin user account
This commit is contained in:
Oliver Günther
2020-04-09 11:54:26 +02:00
committed by GitHub
parent 961ed8d593
commit 53f2d694ff
163 changed files with 430 additions and 335 deletions
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -1,4 +1,4 @@
class Announcement < ActiveRecord::Base
class Announcement < ApplicationRecord
scope :active, -> { where(active: true) }
scope :current, -> { where('show_until >= ?', Date.today) }
+7 -1
View File
@@ -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
#
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class AuthSource < ActiveRecord::Base
class AuthSource < ApplicationRecord
include Redmine::Ciphering
has_many :users
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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',
+1 -1
View File
@@ -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'
+1 -1
View File
@@ -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'
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class EnabledModule < ActiveRecord::Base
class EnabledModule < ApplicationRecord
belongs_to :project
validates :name,
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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")
+1 -1
View File
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Journal < ActiveRecord::Base
class Journal < ApplicationRecord
self.table_name = 'journals'
include ::JournalChanges
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -2
View File
@@ -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
+1 -1
View File
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class MemberRole < ActiveRecord::Base
class MemberRole < ApplicationRecord
belongs_to :member
belongs_to :role
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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, -> {
+1 -1
View File
@@ -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 = {
+1 -1
View File
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Project < ActiveRecord::Base
class Project < ApplicationRecord
extend Pagination::Model
extend FriendlyId
+1 -1
View File
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Query < ActiveRecord::Base
class Query < ApplicationRecord
include Timelines
include Highlighting
include ManualSorting
+1 -1
View File
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Relation < ActiveRecord::Base
class Relation < ApplicationRecord
include VirtualAttribute
scope :of_work_package,
+1 -1
View File
@@ -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
+1 -1
View File
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Role < ActiveRecord::Base
class Role < ApplicationRecord
extend Pagination::Model
# Built-in roles
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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',
+1 -1
View File
@@ -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 }
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class UserPreference < ActiveRecord::Base
class UserPreference < ApplicationRecord
belongs_to :user
serialize :others
+1 -1
View File
@@ -28,7 +28,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Version < ActiveRecord::Base
class Version < ApplicationRecord
include ::Versions::ProjectSharing
include ::Scopes::Scoped
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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'
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class VersionSetting < ActiveRecord::Base
class VersionSetting < ApplicationRecord
belongs_to :project
belongs_to :version
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
@@ -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'
@@ -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
+1 -1
View File
@@ -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
@@ -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
+1 -1
View File
@@ -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,
@@ -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
@@ -1,5 +1,5 @@
module LdapGroups
class Membership < ActiveRecord::Base
class Membership < ApplicationRecord
belongs_to :user
belongs_to :group,
class_name: '::LdapGroups::SynchronizedGroup',
@@ -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,
+1 -1
View File
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Meeting < ActiveRecord::Base
class Meeting < ApplicationRecord
include VirtualAttribute
self.table_name = 'meetings'
@@ -27,7 +27,7 @@
#++
#
class MeetingContent < ActiveRecord::Base
class MeetingContent < ApplicationRecord
include OpenProject::Journal::AttachmentHelper
belongs_to :meeting
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class MeetingParticipant < ActiveRecord::Base
class MeetingParticipant < ApplicationRecord
belongs_to :meeting
belongs_to :user
@@ -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
@@ -27,7 +27,7 @@
#++
class ExportCardConfiguration < ActiveRecord::Base
class ExportCardConfiguration < ApplicationRecord
class RowsYamlValidator < ActiveModel::Validator
REQUIRED_GROUP_KEYS = ["rows"]
+1 -1
View File
@@ -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
+1 -1
View File
@@ -26,7 +26,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class Report < ActiveRecord::Base
class Report < ApplicationRecord
extend Forwardable
include Enumerable
include Engine
@@ -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
@@ -1,5 +1,5 @@
module TwoFactorAuthentication
class Device < ActiveRecord::Base
class Device < ApplicationRecord
default_scope { order('id ASC') }
belongs_to :user
@@ -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
end
+2 -2
View File
@@ -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
end
@@ -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
end
@@ -1,5 +1,5 @@
module Webhooks
class Webhook < ActiveRecord::Base
class Webhook < ApplicationRecord
default_scope { order(id: :asc) }
validates_presence_of :name
+6 -13
View File
@@ -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
+3 -3
View File
@@ -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) }
+3 -6
View File
@@ -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
@@ -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
+5 -22
View File
@@ -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
+8 -15
View File
@@ -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
@@ -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])
@@ -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) }
@@ -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)
+1 -1
View File
@@ -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'
+1 -1
View File
@@ -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)
@@ -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)
-3
View File
@@ -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
-2
View File
@@ -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)
-2
View File
@@ -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
@@ -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)
@@ -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' }
+1 -1
View File
@@ -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 }
+1 -1
View File
@@ -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' }

Some files were not shown because too many files have changed in this diff Show More