Skip to content

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

readd legacy spec helper methods still required

ulfertsbf32df831424
diff --git a/spec_legacy/legacy_spec_helper.rb b/spec_legacy/legacy_spec_helper.rb
index ff0f29bfd6c..b7e628afe5e 100644
--- a/spec_legacy/legacy_spec_helper.rb
+++ b/spec_legacy/legacy_spec_helper.rb
@@ -55,6 +55,8 @@ RSpec.configure do |config|
config.include LegacyAssertionsAndHelpers
config.include ActiveSupport::Testing::Assertions
config.include Shoulda::Context::Assertions
+ # included in order to use #fixture_file_upload
+ config.include ActionDispatch::TestProcess
config.include RSpec::Rails::RequestExampleGroup, file_path: %r(spec_legacy/integration)
config.include Shoulda::Matchers::ActionController, file_path: %r(spec_legacy/integration)
@@ -78,6 +80,8 @@ RSpec.configure do |config|
config.before(:each) do
reset_global_state!
+ initialize_attachments
+
I18n.locale = 'en'
end
diff --git a/spec_legacy/support/legacy_assertions.rb b/spec_legacy/support/legacy_assertions.rb
index 82259cdcc1f..d05a78a3a6d 100644
--- a/spec_legacy/support/legacy_assertions.rb
+++ b/spec_legacy/support/legacy_assertions.rb
@@ -38,6 +38,28 @@ module LegacyAssertionsAndHelpers
RequestStore.clear!
end
+ ##
+ # Attachments generated through fixtures do not files associated with them even
+ # when one provides them within the fixture yml. Dunno why.
+ #
+ # This method fixes that. Tries to lookup existing files. Generates temporary files
+ # where none exist.
+ def initialize_attachments
+ Attachment.all.each do |a|
+ if a.file.filename.nil?
+ begin # existing file under `spec/fixtures/files`
+ a.file = uploaded_test_file a.disk_filename, a.attributes['content_type'],
+ original_filename: a.attributes['filename']
+ rescue # imaginary file: create it on-the-fly
+ a.file = LegacyFileHelpers.mock_uploaded_file name: a.attributes['filename'],
+ content_type: a.attributes['content_type']
+ end
+
+ a.save!
+ end
+ end
+ end
+
def log_user(login, password)
User.anonymous
get '/login'
@@ -48,6 +70,18 @@ module LegacyAssertionsAndHelpers
assert_equal login, User.find(session[:user_id]).login
end
+ ##
+ # Creates a UploadedFile for a file in the fixtures under `spec/fixtures/files`.
+ # Optionally allows to override the original filename.
+ #
+ # Shortcut for Rack::Test::UploadedFile.new(
+ # ActionController::TestCase.fixture_path + path, mime)
+ def uploaded_test_file(name, mime, original_filename: nil)
+ file = fixture_file_upload("/files/#{name}", mime, true)
+ file.define_singleton_method(:original_filename) { original_filename } if original_filename
+ file
+ end
+
def with_settings(options, &_block)
saved_settings = options.keys.inject({}) { |h, k| h[k] = Setting[k].dup; h }
options.each do |k, v| Setting[k] = v end