Skip to content

Commit

Permalink
fix: Merge upstream (#16)
Browse files Browse the repository at this point in the history
* Add specific gem to provide legacy methods like assigns and assert_template

* Include ObjectHelpers in specs

* Fix path to object_helper

* Specify system specs web browser and options

* Add log_user system helper

* Add helper methods

* Add DB support files for CI configuration

* Add missing test helper to spec_helper

* Update arguments for latest selenium-webdriver gem: v4.0

* Update Rspec for Redmine 5

* Replace deprecated option

* Improve compatibility with Redmine 5 - Use fullpath to fixtures/files

Co-authored-by: Vincent Robert <vincent.robert@nanego.com>
  • Loading branch information
jdehaan and nanego authored Sep 14, 2022
1 parent 74b5739 commit 4e976e4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
source 'https://rubygems.org'
gem 'erb_lint', require: false
gem 'rails-controller-testing'
gem 'rspec'
gem 'rspec-core'
gem 'rspec-rails'

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

# static code checking tools
gem 'rubocop'
gem 'rubocop-performance'
Expand Down
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.0'
version '3.0.1'
url 'https://github.com/tools-aoeur/redmine_base_rspec'
author_url 'https://github.com/tools-aoeur'
end
5 changes: 4 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

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

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

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
Expand All @@ -26,7 +29,7 @@

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

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

#test gems
require 'rspec/rails'
# require 'rspec/autorun'
require 'rspec/mocks'
Expand All @@ -38,7 +41,19 @@ def document_root_element
config.fixture_path = "#{::Rails.root}/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"]
}
)
driven_by(
:selenium, using: :chrome, screen_size: [1024, 900],
options: options
)
end
end

def with_settings(options, &_block)
Expand All @@ -55,3 +70,43 @@ def with_settings(options, &_block)
ensure
saved_settings&.each { |k, v| Setting[k] = v }
end

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

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

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'
end

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)
if expected.is_a?(String)
expect(mail_body(mail)).to_not include expected
else
assert_no_match expected, mail_body(mail), message
end
end

def mail_body(mail)
mail.parts.first.body.encoded
end

def uploaded_test_file(name, mime)
fixture_file_upload("#{::Rails.root}/test/fixtures/files/#{name}", mime, true)
end
8 changes: 8 additions & 0 deletions spec/support/database-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
adapter: postgresql
host: localhost
encoding: unicode
pool: 5
database: pg_test
username: postgres
password: postgres

0 comments on commit 4e976e4

Please sign in to comment.