OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/spec_helper.rb

192 lines
6.8 KiB

#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'rubygems'
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start 'rails'
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'rspec/example_disabler'
require 'capybara/rails'
require 'capybara-screenshot/rspec'
require 'factory_girl_rails'
require 'webmock/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/features/support/**/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/lib/api/v3/support/**/*.rb')].each { |f| require f }
Dir[Rails.root.join('spec/requests/api/v3/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
#
# Taken from http://stackoverflow.com/questions/21922046/deadlock-detected-with-capybara-webkit
# which replaces the one we had before taken from http://stackoverflow.com/a/13234966
# Thanks a lot!
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do |example|
DatabaseCleaner.strategy = if example.metadata[:js]
# JS => doesn't share connections => can't use transactions
# as of database_cleaner 1.4 'deletion' causes error:
# 'column "table_rows" does not exist'
# https://github.com/DatabaseCleaner/database_cleaner/issues/345
:truncation
else
# No JS/Devise => run with Rack::Test => transactions are ok
:transaction
end
DatabaseCleaner.start
ActionMailer::Base.deliveries.clear
end
config.after(:each) do
DatabaseCleaner.clean
end
# As we're using WebMock to mock and test remote HTTP requests,
# we require specs to selectively enable mocking of Net::HTTP et al. when the example desires.
# Otherwise, all requests are being mocked by default.
WebMock.disable!
# When we enable webmock, no connections other than stubbed ones are allowed.
# We will exempt local connections from this block, since selenium etc.
# uses localhost to communicate with the browser.
# Leaving this off will randomly fail some specs with WebMock::NetConnectNotAllowedError
WebMock.disable_net_connect!(allow_localhost: true)
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
config.run_all_when_everything_filtered = true
# add helpers to parse json-responses
config.include JsonSpec::Helpers
config.include ::Angular::DSL
10 years ago
Capybara.default_wait_time = 4
config.after(:each) do
OpenProject::RspecCleanup.cleanup
end
config.after(:suite) do
# We don't want this to be reported on CI as it breaks the build
unless ENV['CI']
[User, Project, WorkPackage].each do |cls|
raise "your specs left a #{cls} in the DB\ndid you use before(:all) instead of before or forget to kill the instances in a after(:all)?" if cls.count > 0
end
end
end
config.mock_with :rspec do |c|
c.yield_receiver_to_any_instance_implementation_blocks = true
end
Initial foundations for API v3 User Story # 8769 Squashed commit of the following: commit fac82d68b6afa6a757b2ca1b71e7424c02666471 Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 11 15:53:21 2014 +0200 Removed cascade false call from root api commit fedff52220927830376939021d4a36df26dc854b Merge: 7b2942c e204fa9 Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 11 14:17:27 2014 +0200 Merge commit 7b2942c419864448d9416909f73d5aa23c8bea4a Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 11 14:11:58 2014 +0200 Generated new Gemfile.lock commit 7af2f77bbcd4c4871ccccb4211939d6e975fe607 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 10 15:03:47 2014 +0200 Removed print call commit bb19cddee90b7bd163004f1ed7009af29d8219e7 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 10 14:39:35 2014 +0200 Removed 'spec/factories/priority_factory.rb commit e8bbf476f148775654fb840e6219b40f955387de Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 10 14:38:31 2014 +0200 Replaced lambda calls with '->' commit 9d8a1c2423fd686e51f1a9b5e400444619e40685 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 19:19:40 2014 +0200 Clean up commit 08f80e8c91e6f10100ab7ced4af75edc9971b045 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 19:03:38 2014 +0200 Delete ::ConnectionManagement-call(env)> commit 190c2e2d867020373c1ae4d9ad6715bf81e99da4 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 17:40:34 2014 +0200 Reset Gemfile.lock commit 0a32dcaef08f603fdbfd57b65abfde7fc702ebb9 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 14:43:58 2014 +0200 Small refactoring of the API specs commit 963bb3e84851598e870fb52c7e01097fa554ea8c Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 4 17:10:15 2014 +0200 Basic implementation of APIv3 work package #get commit ffdb5641a7ecc6cbb4d5af7e0f6d04ba3493aee8 Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 4 17:08:48 2014 +0200 Basic implementation of APIv3 work package #get commit 8d64840f02b768338a1aa2721cc93a5d782f2295 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 3 16:33:02 2014 +0200 Clening up commit 2caf393c94f9a82739daaca79625db17e9096934 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 3 16:30:50 2014 +0200 Work package #patch - incomplete tests commit d6b9a4f263fa2843e3f44b6fb9caae2bbb36d093 Author: Marek Takac <m.takac@finn.de> Date: Wed May 28 17:42:26 2014 +0200 Renamed #done_ratio to #percentage_done commit 583ba0b52564da99d241ed07e112efb0ed22acf9 Author: Marek Takac <m.takac@finn.de> Date: Wed May 28 17:30:42 2014 +0200 Cleanup commit 34bfb883771ce41c8de5e641514835b07164a011 Author: Marek Takac <m.takac@finn.de> Date: Wed May 28 17:14:09 2014 +0200 Added basic test & improved patch work package commit 377070acfec5f8efe911dc9c1e898584f4ccfa63 Author: Marek Takac <m.takac@finn.de> Date: Fri May 23 15:38:58 2014 +0200 Implemented basic batch update for work packages commit 9df0ffb916aad624ffe71cc23c3f53136ef29e22 Author: Marek Takac <m.takac@finn.de> Date: Fri May 23 14:41:56 2014 +0200 Set default limit and offset for GET work packages resource commit f1ac16b23f2f6632daf6a5759403dcf5335c014f Author: Marek Takac <m.takac@finn.de> Date: Fri May 23 14:18:00 2014 +0200 Created GET endpoint work work packages resource & N+1 query optimization commit 9a7bb32f4600fe04edb72c81af0b7ba9dd412b7b Author: Marek Takac <m.takac@finn.de> Date: Thu May 22 19:29:04 2014 +0200 Basic authorization for work package GET and PATCH commit da4b778d51798df6eb2e80fbf85029a4b3c06b23 Author: Marek Takac <m.takac@finn.de> Date: Thu May 22 15:51:10 2014 +0200 Completed basic implementation of get, patch, head and options requests for work package resource commit c8e8ab68af07412a999c16331af8f695cbd090af Author: Marek Takac <m.takac@finn.de> Date: Thu May 22 10:47:43 2014 +0200 Added target version attributes to the work package resource commit 2ab0bea6ac174258c301d9ede38d1ec0128459aa Author: Marek Takac <m.takac@finn.de> Date: Wed May 21 18:08:13 2014 +0200 Implemented work package update with some child resources commit 17edd10bb5c46d258d201ed426c6a7f86ea514e9 Author: Marek Takac <m.takac@finn.de> Date: Wed May 21 16:31:18 2014 +0200 Minor refactoring of work packages api commit a63f17622c1258d3b90be39792cd84448c15dafa Author: Marek Takac <m.takac@finn.de> Date: Wed May 21 16:28:48 2014 +0200 Created GET work package endpoint commit abcf2e50b48b64a23cb80fb087af50fa59c23cb7 Author: Marek Takac <m.takac@finn.de> Date: Tue May 20 14:40:47 2014 +0200 Created OP API entry point commit 4564bae6f5613b7032b09086db197f12f79a4e46 Author: Marek Takac <m.takac@finn.de> Date: Tue May 20 13:39:57 2014 +0200 Refactor authorize method (created service object) commit cb464d932917247c74df4b70e957c4011610331b Author: Marek Takac <m.takac@finn.de> Date: Tue May 20 11:15:31 2014 +0200 Created basic structure for Work packages API commit 00f3b7a2919dfd80feb0332e87b82141b4785904 Author: Marek Takac <m.takac@finn.de> Date: Tue May 13 16:29:30 2014 +0200 WorkPackage mapper changes commit 622ebd04eb3892dee12a8b32586276fd4431b9f1 Author: Marek Takac <m.takac@finn.de> Date: Tue May 13 01:30:02 2014 +0200 Added relationships to WorkPackage mapper commit 80ebe54d9083967ef0db582a5ea8c489ce9e6df6 Author: Marek Takac <m.takac@finn.de> Date: Tue May 13 01:14:57 2014 +0200 Created WorkPackage mapper class commit 2da9225aef96c56fa478d6f0a822afb4569aadda Author: Marek Takac <m.takac@finn.de> Date: Mon May 12 19:21:07 2014 +0200 Mappers for Grape API commit 5cd59c4ad66652a58703f6c6bcf4557baf687b3b Author: Marek Takac <m.takac@finn.de> Date: Tue Apr 29 16:54:24 2014 +0200 Created some decorators commit a5cb66e5b63813bd6bb3d776cb970c9649b995ba Author: Marek Takac <m.takac@finn.de> Date: Tue Apr 29 15:31:25 2014 +0200 Added pundit for authorization commit f909e896879cb2c2c51df7393bfc0b2bfb6806fd Author: Marek Takac <m.takac@finn.de> Date: Tue Apr 29 14:49:20 2014 +0200 Created work package representer & current_user helper method for API commit 5aad3c087a29ef5a70d5d58f22d374b90eb604d9 Author: Marek Takac <m.takac@finn.de> Date: Mon Apr 28 14:24:47 2014 +0200 Created basic structure for Work packages API commit b25a348619b5785b7004e8320f9b43cb249f5ca4 Author: Marek Takac <m.takac@finn.de> Date: Mon Apr 28 14:04:37 2014 +0200 Set up Grape API v3 commit be76a6500ed03ff4d2c14923179e70f825c0f413 Author: Marek Takac <m.takac@finn.de> Date: Mon Apr 28 13:58:38 2014 +0200 Added grape commit e204fa9de8f10200ed60205dd5529ec78cbd4bc9 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 10 15:03:47 2014 +0200 Removed print call commit 39b921adc7978b0ce4735eea54e3669f47a5f7fe Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 10 14:39:35 2014 +0200 Removed 'spec/factories/priority_factory.rb commit 94c64ab855b8f12dd50365445709c573f6ab5f28 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 10 14:38:31 2014 +0200 Replaced lambda calls with '->' commit c2101b035219d1336d425bcb5c9e423bc4a928b6 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 19:19:40 2014 +0200 Clean up commit a03bc0d84ce772192076731750c77da03b8400ba Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 19:03:38 2014 +0200 Delete ::ConnectionManagement-call(env)> commit 8b2fe0b01ecd4d447d60c4c22ba91126578c25c7 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 17:40:34 2014 +0200 Reset Gemfile.lock commit 5d6618eea42ba9b09985bb55fa9b0691ecf33065 Merge: f325a36 dab75c3 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 16:10:51 2014 +0200 Merge branch 'dev' into feature/api_v3_base commit f325a36d6fce4e43f4d0911710eaf1753bdd8b00 Author: Marek Takac <m.takac@finn.de> Date: Fri Jun 6 14:43:58 2014 +0200 Small refactoring of the API specs commit 84f78d669d3f748fe37be16a26fe9837e7666c5f Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 4 17:10:15 2014 +0200 Basic implementation of APIv3 work package #get commit 82786a97173b40169f09fe79bd30715b5acee064 Author: Marek Takac <m.takac@finn.de> Date: Wed Jun 4 17:08:48 2014 +0200 Basic implementation of APIv3 work package #get commit b7dd82f85f1b7556a02a313a53fa06c18e8e7c25 Merge: f4ba4e8 5525bc3 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 3 17:15:48 2014 +0200 Merge commit 5525bc3d52001d550b85e95668f5b272ffb97378 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 3 16:33:02 2014 +0200 Clening up commit 9d27e3d412b093778f075870a577c523fe709589 Author: Marek Takac <m.takac@finn.de> Date: Tue Jun 3 16:30:50 2014 +0200 Work package #patch - incomplete tests commit 58ceeee83e59b30f7c755d2b7738f3d14e06bee8 Author: Marek Takac <m.takac@finn.de> Date: Wed May 28 17:42:26 2014 +0200 Renamed #done_ratio to #percentage_done commit 7165e32bc45f56571b570ffa03b9c1c34f06296c Author: Marek Takac <m.takac@finn.de> Date: Wed May 28 17:30:42 2014 +0200 Cleanup commit 235ecdeabede44d8901c6fbc13bbdebb184c3cc8 Author: Marek Takac <m.takac@finn.de> Date: Wed May 28 17:14:09 2014 +0200 Added basic test & improved patch work package commit 625f273dc1e90cb5b2e206790f9700b0ac9248a0 Author: Marek Takac <m.takac@finn.de> Date: Fri May 23 15:38:58 2014 +0200 Implemented basic batch update for work packages commit 20239886d43386a975a449366e09ad8aed83d158 Author: Marek Takac <m.takac@finn.de> Date: Fri May 23 14:41:56 2014 +0200 Set default limit and offset for GET work packages resource commit ad79163fd3d97af62b9aa605cd8a5d211501f2c1 Author: Marek Takac <m.takac@finn.de> Date: Fri May 23 14:18:00 2014 +0200 Created GET endpoint work work packages resource & N+1 query optimization commit c3dcba77f02ed4688faf8baf68d8f1811351ec03 Author: Marek Takac <m.takac@finn.de> Date: Thu May 22 19:29:04 2014 +0200 Basic authorization for work package GET and PATCH commit 73d8a8551da59c634cb3fffb2c7a581302263554 Author: Marek Takac <m.takac@finn.de> Date: Thu May 22 15:51:10 2014 +0200 Completed basic implementation of get, patch, head and options requests for work package resource commit 479fc4b00579bd4c7ff3c64712322f0087f081ed Author: Marek Takac <m.takac@finn.de> Date: Thu May 22 10:47:43 2014 +0200 Added target version attributes to the work package resource commit a72cff36a9e90efb01e5ccf7c394edc4a873cf46 Author: Marek Takac <m.takac@finn.de> Date: Wed May 21 18:08:13 2014 +0200 Implemented work package update with some child resources commit 6689628a7419039a34f07d0edff0eb855eb8fb98 Author: Marek Takac <m.takac@finn.de> Date: Wed May 21 16:31:18 2014 +0200 Minor refactoring of work packages api commit 97d4e9a1e6fcbdcda4ecb70d3f06d89936507019 Author: Marek Takac <m.takac@finn.de> Date: Wed May 21 16:28:48 2014 +0200 Created GET work package endpoint commit 1490621af1cee15de310e052f57fc5a542e2ad1a Author: Marek Takac <m.takac@finn.de> Date: Tue May 20 14:40:47 2014 +0200 Created OP API entry point commit 1e080b7936ae2d14ef324b70f95fafb15e9faa2c Author: Marek Takac <m.takac@finn.de> Date: Tue May 20 13:39:57 2014 +0200 Refactor authorize method (created service object) commit 1b0b894456e1e1a22c7b0d759e277125be50e76b Author: Marek Takac <m.takac@finn.de> Date: Tue May 20 11:15:31 2014 +0200 Created basic structure for Work packages API commit 6c8f83ae548fb1cca6049cfc2943301ac2e7cdb9 Author: Marek Takac <m.takac@finn.de> Date: Tue May 13 16:29:30 2014 +0200 WorkPackage mapper changes commit d2a7f29201f5d9922e7ec5a1e9c75852c55f84f6 Author: Marek Takac <m.takac@finn.de> Date: Tue May 13 01:30:02 2014 +0200 Added relationships to WorkPackage mapper commit 0122cd4392e587feef662e611cbf02f4bdb06a4d Author: Marek Takac <m.takac@finn.de> Date: Tue May 13 01:14:57 2014 +0200 Created WorkPackage mapper class commit 6a40cdd6bfca7dbc17c02c8a59531d1c6f33e919 Author: Marek Takac <m.takac@finn.de> Date: Mon May 12 19:21:07 2014 +0200 Mappers for Grape API commit 0a4f39be58b3851c1dbfb39618e63e16ea4b05ec Author: Marek Takac <m.takac@finn.de> Date: Tue Apr 29 16:54:24 2014 +0200 Created some decorators commit 21e1c42b54eee5704cf19a5a0e8abffa39a8d9a7 Author: Marek Takac <m.takac@finn.de> Date: Tue Apr 29 15:31:25 2014 +0200 Added pundit for authorization commit a76f23ec51d6b04e01ab521a9252c41cb377d6ff Author: Marek Takac <m.takac@finn.de> Date: Tue Apr 29 14:49:20 2014 +0200 Created work package representer & current_user helper method for API commit 4d92b359941367043e66e23373ead15ac92ba5d1 Author: Marek Takac <m.takac@finn.de> Date: Mon Apr 28 14:24:47 2014 +0200 Created basic structure for Work packages API commit d19a5d698a7d92c642011aac731a850106095057 Author: Marek Takac <m.takac@finn.de> Date: Mon Apr 28 14:04:37 2014 +0200 Set up Grape API v3 commit b270fa61643a3eba2d4a2d3828e90f5748dd9757 Author: Marek Takac <m.takac@finn.de> Date: Mon Apr 28 13:58:38 2014 +0200 Added grape Signed-off-by: Alex Coles <alex@alexbcoles.com>
11 years ago
# include spec/api for API request specs
config.include RSpec::Rails::RequestExampleGroup, type: :request
# colorized rspec output
config.color = true
end
# Loads two files automatically from plugins:
#
# 1. `spec/disable_specs.rbs` to disable specs which don't work in conjunction with the
# respective plugin.
# 2. The config spec helper in `spec/config_spec_helper` makes sure that the core specs
# (and other plugins' specs) keep working with this plugin in an OpenProject configuration
# even if it changes things which would otherwise break existing specs.
Rails.application.config.plugins_to_test_paths.each do |dir|
['disable_specs.rb', 'config_spec_helper.rb'].each do |file_name|
file = File.join(dir, 'spec', file_name)
if File.exists?(file)
puts "Loading #{file}"
require file
end
end
end
require 'rack_session_access/capybara'
Rails.application.config do
config.middleware.use RackSessionAccess::Middleware
end
module OpenProject::RspecCleanup
def self.cleanup
# Cleanup after specs changing locale explicitly or
# by calling code in the app setting changing the locale.
I18n.locale = :en
# Set the class instance variable @current_user to nil
# to avoid having users from one spec present in the next
::User.instance_variable_set(:@current_user, nil)
end
end
OpenProject::Configuration['attachments_storage_path'] = 'tmp/files'