Skip to content

Commit

Permalink
fix: Add thread safety cop (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdehaan authored Oct 6, 2023
1 parent ba02fe1 commit fad96b4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gem 'rspec'
gem 'rspec-core'
gem 'rspec-rails'

#for test coverage
# for test coverage
# gem 'simplecov', '~> 0.9.1', :require => false, :group => :test

# static code checking tools
Expand All @@ -14,3 +14,4 @@ gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'rubocop-thread_safety'
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name 'Redmine Base Rspec plugin'
author 'Jean-Baptiste BARTH (orig)'
description 'RSpec and RuboCop support'
version '3.0.2'
version '3.0.3'
url 'https://github.com/tools-aoeur/redmine_base_rspec'
author_url 'https://github.com/tools-aoeur'
end
2 changes: 1 addition & 1 deletion lib/tasks/redmine.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace :redmine do
namespace :plugins do
desc 'Runs the plugins tests.'
task test: :environment do
if !ENV['NAME'] || File.exist?(Rails.root.join("plugins/#{ENV['NAME']}/spec"))
if !ENV['NAME'] || Rails.root.join("plugins/#{ENV.fetch('NAME', nil)}/spec").exist?
Rake::Task['redmine:plugins:spec'].invoke
end
Rake::Task['redmine:plugins:test:units'].invoke
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Add additional requires below this line. Rails is not loaded until this point!

require File.expand_path("#{::Rails.root}/test/object_helpers", __FILE__)
require Rails.root.join('test/object_helpers').expand_path(__FILE__)
include ObjectHelpers

# Requires supporting ruby files with custom matchers and macros, etc, in
Expand All @@ -29,7 +29,7 @@

RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/test/fixtures"
config.fixture_path = Rails.root.join('test/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
Expand Down
42 changes: 20 additions & 22 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
# load rails/redmine
require_relative '../../../config/environment'

require File.expand_path("#{::Rails.root}/test/object_helpers", __FILE__)
require Rails.root.join('test/object_helpers').expand_path(__FILE__)
include ObjectHelpers

#test gems
# test gems
require 'rspec/rails'
# require 'rspec/autorun'
require 'rspec/mocks'
Expand All @@ -38,32 +38,32 @@ def document_root_element
config.mock_with :rspec
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.fixture_path = "#{::Rails.root}/test/fixtures"
config.fixture_path = Rails.root.join('test/fixtures')
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.include AssertSelectRoot, :type => :request
config.include AssertSelectRoot, type: :request
config.before(:each, type: :system) do
options = {}
options[:capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome(
'goog:chromeOptions' => {
'args' => ["headless", "no-sandbox", "disable-gpu"]
'args' => %w[headless no-sandbox disable-gpu]
}
)
driven_by(
:selenium, using: :chrome, screen_size: [1024, 900],
options: options
options: options
)
end
end

def with_settings(options, &_block)
saved_settings = options.keys.each_with_object({}) do |k, h|
h[k] = case Setting[k]
when Symbol, false, true, nil
Setting[k]
else
Setting[k].dup
end
saved_settings = options.keys.index_with do |k|
case Setting[k]
when Symbol, false, true, nil
Setting[k]
else
Setting[k].dup
end
end
options.each { |k, v| Setting[k] = v }
yield
Expand All @@ -73,31 +73,29 @@ def with_settings(options, &_block)

def log_user(login, password)
visit '/my/page'
expect(current_path).to eq '/login'
expect(page).to have_current_path '/login', ignore_query: true

if Redmine::Plugin.installed?(:redmine_scn)
click_on("ou s'authentifier par login / mot de passe")
end
click_on("ou s'authentifier par login / mot de passe") if Redmine::Plugin.installed?(:redmine_scn)

within('#login-form form') do
fill_in 'username', with: login
fill_in 'password', with: password
find('input[name=login]').click
end
expect(current_path).to eq '/my/page'
expect(page).to have_current_path '/my/page', ignore_query: true
end

def assert_mail_body_match(expected, mail, message=nil)
def assert_mail_body_match(expected, mail, message = nil)
if expected.is_a?(String)
expect(mail_body(mail)).to include(expected)
else
assert_match expected, mail_body(mail), message
end
end

def assert_mail_body_no_match(expected, mail, message=nil)
def assert_mail_body_no_match(expected, mail, message = nil)
if expected.is_a?(String)
expect(mail_body(mail)).to_not include expected
expect(mail_body(mail)).not_to include expected
else
assert_no_match expected, mail_body(mail), message
end
Expand All @@ -108,5 +106,5 @@ def mail_body(mail)
end

def uploaded_test_file(name, mime)
fixture_file_upload("#{::Rails.root}/test/fixtures/files/#{name}", mime, true)
fixture_file_upload(Rails.root.join("test/fixtures/files/#{name}"), mime, true)
end

0 comments on commit fad96b4

Please sign in to comment.