From 5d30efe8f5ee27a04b706b48918e4942922b202c Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Wed, 6 Feb 2019 17:58:36 +0900 Subject: [PATCH] Add support for Travis CI again --- .travis.yml | 71 +++---- config/Gemfile.travis | 6 - config/database.yml.travis | 5 - .../redmine_notifier_patch.rb | 2 +- lib/tasks/testing.rake | 77 -------- script/ci.sh | 176 ------------------ .../redmine_exception_handler_test.rb | 19 ++ test/test_helper.rb | 24 +-- 8 files changed, 50 insertions(+), 330 deletions(-) delete mode 100644 config/Gemfile.travis delete mode 100644 config/database.yml.travis delete mode 100644 lib/tasks/testing.rake delete mode 100755 script/ci.sh create mode 100644 test/integration/redmine_exception_handler_test.rb diff --git a/.travis.yml b/.travis.yml index 8d6c834..20d6d00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,44 +1,31 @@ ---- -language: ruby -sudo: false -cache: - directories: - - workspace/redmine/vendor/bundle -timeouts: - bundle: 600 -rvm: - - 1.9.3 - - 2.0.0 - - 2.2.0 -env: - global: - - REDMINE_DIR=./workspace/redmine - - PLUGIN_NAME=redmine_exception_handler - matrix: - - REDMINE=3.0-stable - - REDMINE=v3.8.0 - - REDMINE=master +dist: xenial + +services: + - mysql + matrix: - exclude: - - rvm: 2.0.0 - env: REDMINE=v3.8.0 - gemfile: workspace/redmine/Gemfile - - rvm: 2.2.0 - env: REDMINE=v3.8.0 - gemfile: workspace/redmine/Gemfile - allow_failures: - - env: REDMINE=v3.8.0 -gemfile: workspace/redmine/Gemfile + include: + - name: "Redmine 3.4" + env: + - REDMINE_VERSION=3.4-stable + install: + - gem install bundler -v "1.17.3" + - bundle _1.17.3_ install + - bin/rake db:create + - bin/rake generate_secret_token + - bin/rake db:migrate + - bin/rake redmine:plugins:migrate + script: + - RAILS_ENV=test bin/rake redmine:plugins:test:integration + before_install: - - ./script/ci.sh clone_redmine --target $REDMINE_DIR - - cp ./config/database.yml.travis $REDMINE_DIR/config/database.yml - - ./script/ci.sh install_plugin_gemfile -install: ./script/ci.sh bundle_install -before_script: - - mysql -e 'CREATE DATABASE redmine CHARACTER SET utf8;' - - ./script/ci.sh prepare_redmine - - ./script/ci.sh prepare_plugin - - 'phantomjs --webdriver 4444 2>&- 1>&- &' -script: - - ./script/ci.sh run_tests - - ./script/ci.sh test_uninstall + - cd .. + - git clone + --depth 1 + --branch ${REDMINE_VERSION} + https://github.com/redmine/redmine.git + - cd redmine/plugins + - ln -s ../../redmine_exception_handler ./ + - cd ../ + - cp config/database.yml{.example,} + - unset BUNDLE_GEMFILE diff --git a/config/Gemfile.travis b/config/Gemfile.travis deleted file mode 100644 index 6befc7f..0000000 --- a/config/Gemfile.travis +++ /dev/null @@ -1,6 +0,0 @@ -gem 'tinder', '~> 1.9.1' -gem 'exception_notification', '~> 4.0' - -group :test do - gem 'coveralls', :require => false -end diff --git a/config/database.yml.travis b/config/database.yml.travis deleted file mode 100644 index a911650..0000000 --- a/config/database.yml.travis +++ /dev/null @@ -1,5 +0,0 @@ -test: - adapter: <%= RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql' %> - database: redmine - username: travis - encoding: utf8 \ No newline at end of file diff --git a/lib/exception_handler/redmine_notifier_patch.rb b/lib/exception_handler/redmine_notifier_patch.rb index 3e991fb..2f4cf7d 100644 --- a/lib/exception_handler/redmine_notifier_patch.rb +++ b/lib/exception_handler/redmine_notifier_patch.rb @@ -23,4 +23,4 @@ def notify_exception_with_database(exception, options = {}) end end -end \ No newline at end of file +end diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake deleted file mode 100644 index cdf859a..0000000 --- a/lib/tasks/testing.rake +++ /dev/null @@ -1,77 +0,0 @@ -# encoding: utf-8 -# Copyright (C) 2011-2013 The Redmine LDAP Sync Authors -# -# This file is part of Redmine LDAP Sync. -# -# Redmine LDAP Sync 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 3 of the License, or -# (at your option) any later version. -# -# Redmine LDAP Sync 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 Redmine LDAP Sync. If not, see . -namespace :redmine do - namespace :plugins do - namespace :exception_handler do - PLUGIN_NAME='redmine_exception_handler' - - desc 'Runs the exception_handler tests.' - task :test do - require 'redmine/version' - Rake::Task["redmine:plugins:exception_handler:test:units"].invoke - Rake::Task["redmine:plugins:exception_handler:test:functionals"].invoke - Rake::Task["redmine:plugins:exception_handler:test:integration"].invoke - - if RUBY_VERSION >= '1.9.3' && Redmine::VERSION.to_s >= '2.3.0' - Rake::Task["redmine:plugins:exception_handler:test:ui"].invoke - end - end - - namespace :test do - desc 'Runs the plugins unit tests.' - Rake::TestTask.new :ui => "db:test:prepare" do |t| - t.libs << "test" - t.verbose = true - t.pattern = "plugins/#{PLUGIN_NAME}/test/ui/**/*_test.rb" - end - - desc 'Runs the plugins unit tests.' - Rake::TestTask.new :units => "db:test:prepare" do |t| - t.libs << "test" - t.verbose = true - t.pattern = "plugins/#{PLUGIN_NAME}/test/unit/**/*_test.rb" - end - - desc 'Runs the plugins functional tests.' - Rake::TestTask.new :functionals => "db:test:prepare" do |t| - t.libs << "test" - t.verbose = true - t.pattern = "plugins/#{PLUGIN_NAME}/test/functional/**/*_test.rb" - end - - desc 'Runs the plugins integration tests.' - Rake::TestTask.new :integration => "db:test:prepare" do |t| - t.libs << "test" - t.verbose = true - t.pattern = "plugins/#{PLUGIN_NAME}/test/integration/**/*_test.rb" - end - end - - namespace :coveralls do - desc "Push latest coverage results to Coveralls.io" - task :test => 'redmine:plugins:exception_handler:test' do - require 'simplecov' - ::SimpleCov.root Rails.root.join('plugins', "#{PLUGIN_NAME}") - - require 'coveralls' - Coveralls.push! - end - end - end - end -end diff --git a/script/ci.sh b/script/ci.sh deleted file mode 100755 index fc22674..0000000 --- a/script/ci.sh +++ /dev/null @@ -1,176 +0,0 @@ -#/bin/bash -set -e # exit if any command fails - -setenv() { - export RAILS_ENV=test - export PATH_TO_PLUGIN=$(pwd) - export RUBY_VERSION=$(ruby -e 'print RUBY_VERSION') - if [[ -z "$REDMINE" ]]; then - echo "You have not set REDMINE" - exit 1 - fi - if [ "$VERBOSE" = "yes" ]; then export TRACE=--trace; fi - if [ ! "$VERBOSE" = "yes" ]; then export QUIET=--quiet; fi - - case $REDMINE in - 2.*.*) export PATH_TO_PLUGINS=./plugins # for redmine 2.x.x - export GENERATE_SECRET=generate_secret_token - export MIGRATE_PLUGINS=redmine:plugins - export REDMINE_TARBALL=https://github.com/edavis10/redmine/archive/$REDMINE.tar.gz - ;; - 3.*-stable) export PATH_TO_PLUGINS=./plugins # for redmine 3.x-stable - export GENERATE_SECRET=generate_secret_token - export MIGRATE_PLUGINS=redmine:plugins - export REDMINE_SVN_REPO=http://svn.redmine.org/redmine/branches/$REDMINE - ;; - master) export PATH_TO_PLUGINS=./plugins - export GENERATE_SECRET=generate_secret_token - export MIGRATE_PLUGINS=redmine:plugins - export REDMINE_SVN_REPO=http://svn.redmine.org/redmine/trunk/ - ;; - v3.8.0) export PATH_TO_PLUGINS=./vendor/chiliproject_plugins - export GENERATE_SECRET=generate_session_store - export MIGRATE_PLUGINS=db:migrate:plugins - export REDMINE_TARBALL=https://github.com/chiliproject/chiliproject/archive/$REDMINE.tar.gz - export RUBYGEMS=1.8.29 - ;; - *) echo "Unsupported platform $REDMINE" - exit 1 - ;; - esac -} - -extract_args() { - while :; do - case "$1" in - --target) export TARGET="$2"; shift; shift;; - -*) echo "Invalid argument $1"; exit 2;; - *) break;; - esac - done -} - -trace() { - if [ "$VERBOSE" = "yes" ]; then echo $@; fi -} - -clone_redmine() -{ - setenv; extract_args $@ - - if [[ -z "$TARGET" ]]; then - echo "You have not set a target directory"; exit 1 - fi - - rm -rf $TARGET - if [ -n "${REDMINE_GIT_REPO}" ]; then - git clone -b $REDMINE_GIT_TAG --depth=100 $QUIET $REDMINE_GIT_REPO $TARGET - pushd $TARGET 1> /dev/null - git checkout $REDMINE_GIT_TAG - popd 1> /dev/null - elif [ -n "${REDMINE_HG_REPO}" ]; then - hg clone -r $REDMINE_HG_TAG $QUIET $REDMINE_HG_REPO $TARGET - elif [ -n "${REDMINE_SVN_REPO}" ]; then - svn co $QUIET $REDMINE_SVN_REPO $TARGET - else - mkdir -p $TARGET - wget $REDMINE_TARBALL -O- | tar -C $TARGET -xz --strip=1 --show-transformed -f - - fi - - # Temporarily pin down database_cleaner for bug with sqlite, see https://github.com/bmabey/database_cleaner/issues/224 - sed -ri 's/gem "database_cleaner"/gem "database_cleaner", "< 1.1.0"/' $TARGET/Gemfile -} - -install_plugin_gemfile() -{ - setenv - - mkdir $REDMINE_DIR/$PATH_TO_PLUGINS/$PLUGIN_NAME - rm -f "$REDMINE_DIR/$PATH_TO_PLUGINS/$PLUGIN_NAME/Gemfile" - ln -s "$PATH_TO_PLUGIN/config/Gemfile.travis" "$REDMINE_DIR/$PATH_TO_PLUGINS/$PLUGIN_NAME/Gemfile" -} - -bundle_install() -{ - setenv - - if [ -n "${RUBYGEMS}" ]; then - rvm rubygems ${RUBYGEMS} - fi - pushd $REDMINE_DIR 1> /dev/null - for i in {1..3}; do - gem install bundler $QUIET --no-rdoc --no-ri && \ - bundle install $QUIET --gemfile=./Gemfile --path vendor/bundle --without development rmagick ldap && break - done && popd 1> /dev/null -} - -prepare_redmine() -{ - setenv - - pushd $REDMINE_DIR 1> /dev/null - - trace 'Database migrations' - bundle exec rake db:migrate $TRACE - - trace 'Load defaults' - bundle exec rake redmine:load_default_data REDMINE_LANG=en $TRACE - - trace 'Session token' - bundle exec rake $GENERATE_SECRET $TRACE - - popd 1> /dev/null -} - -prepare_plugin() -{ - setenv - - pushd $REDMINE_DIR 1> /dev/null - - rm -f "$PATH_TO_PLUGIN/Gemfile" - ln -s $PATH_TO_PLUGIN/* $PATH_TO_PLUGINS/$PLUGIN_NAME - - trace 'Prepare plugins' - bundle exec rake $MIGRATE_PLUGINS NAME=$PLUGIN_NAME $TRACE - - popd 1> /dev/null -} - -run_tests() -{ - setenv - - pushd $REDMINE_DIR 1> /dev/null - - if [ "$REDMINE" == "master" ] && [ "$RUBY_VERSION" == "1.9.3" ]; then - bundle exec rake redmine:plugins:exception_handler:coveralls:test $TRACE - else - bundle exec rake redmine:plugins:exception_handler:test $TRACE - fi - - popd 1> /dev/null -} - -test_uninstall() -{ - setenv - - pushd $REDMINE_DIR 1> /dev/null - - bundle exec rake $TRACE $MIGRATE_PLUGINS NAME=$PLUGIN_NAME VERSION=0 - - popd 1> /dev/null -} - -case "$1" in - "clone_redmine") shift; clone_redmine $@;; - "install_plugin_gemfile") shift; install_plugin_gemfile $@;; - "bundle_install") shift; bundle_install $@;; - "prepare_redmine") shift; prepare_redmine $@;; - "prepare_plugin") shift; prepare_plugin $@;; - "start_ldap") shift; start_ldap $@;; - "run_tests") shift; run_tests $@;; - "test_uninstall") shift; test_uninstall $@;; - *) echo "clone_redmine; install_plugin_gemfile; prepare_redmine; prepare_plugin; start_ldap; run_tests; test_uninstall";; -esac diff --git a/test/integration/redmine_exception_handler_test.rb b/test/integration/redmine_exception_handler_test.rb new file mode 100644 index 0000000..d6f9bf5 --- /dev/null +++ b/test/integration/redmine_exception_handler_test.rb @@ -0,0 +1,19 @@ +require File.expand_path("../../test_helper", __FILE__) + +class RedmineExceptionHandlerTest < Redmine::IntegrationTest + def test_exception + assert_difference 'ActionMailer::Base.deliveries.size', 1 do + get "/example_exception" + end + mail = ActionMailer::Base.deliveries.last + settings = Setting.plugin_redmine_exception_handler + assert_equal([ + settings["exception_handler_recipients"], + settings["exception_handler_sender_address"], + ], + [ + mail.to.join(", "), + mail.header["From"].value, + ]) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0833689..14770c8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,23 +1 @@ -require 'simplecov' - -SimpleCov.start do - add_group 'Controllers', 'app/controllers' - add_group 'Models', 'app/models' - add_group 'Helpers', 'app/helpers' - add_group 'Libraries', 'lib' - add_filter '/test/' - add_filter 'init.rb' - root File.expand_path(File.dirname(__FILE__) + '/../') -end if RUBY_VERSION >= '1.9.0' - -require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') - -Rails.backtrace_cleaner.remove_silencers! - -class ActiveSupport::TestCase - self.fixture_path = File.expand_path(File.dirname(__FILE__) + '/fixtures') -end - -class ActionDispatch::IntegrationTest - self.fixture_path = File.expand_path(File.dirname(__FILE__) + '/fixtures') -end +require File.expand_path("../../../../test/test_helper", __FILE__)