diff --git a/.rubocop.yml b/.rubocop.yml index 5fa131f..f6bb2ef 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ -require: rubocop-performance +require: + - rubocop-performance Rails: Enabled: true diff --git a/.travis.yml b/.travis.yml index 5a826f2..4d2a924 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,33 @@ language: ruby +dist: xenial rvm: - - 2.5.3 - - 2.4.5 - - 2.3.8 + - 2.6.3 + - 2.5.5 + - 2.4.6 + +services: + - mysql + - postgresql env: - REDMINE_VER=4.0-stable DB=postgresql - REDMINE_VER=3.4-stable DB=postgresql + - REDMINE_VER=4.0-stable DB=mysql + - REDMINE_VER=3.4-stable DB=mysql sudo: true -addons: - postgresql: "9.6" +matrix: + exclude: + - rvm: 2.6.3 + env: REDMINE_VER=3.4-stable DB=mysql + - rvm: 2.6.3 + env: REDMINE_VER=3.4-stable DB=postgresql + - rvm: 2.5.5 + env: REDMINE_VER=3.4-stable DB=mysql + - rvm: 2.5.5 + env: REDMINE_VER=3.4-stable DB=postgresql notifications: webhooks: @@ -26,6 +41,7 @@ before_install: - export REDMINE_GIT_REPO=git://github.com/redmine/redmine.git - export REDMINE_PATH=$HOME/redmine - export BUNDLE_GEMFILE=$REDMINE_PATH/Gemfile + - export RAILS_ENV=test - git clone $REDMINE_GIT_REPO $REDMINE_PATH - cd $REDMINE_PATH - if [[ "$REDMINE_VER" != "master" ]]; then git checkout -b $REDMINE_VER origin/$REDMINE_VER; fi @@ -34,12 +50,7 @@ before_install: - cp $TRAVIS_BUILD_DIR/test/support/database-$DB-travis.yml $REDMINE_PATH/config/database.yml before_script: - # - bundle exec rake redmine:load_default_data REDMINE_LANG=en - # - bundle exec rake db:structure:dump - - psql -c 'create database travis_ci_test;' -U postgres - # - bundle exec rake db:create - - bundle exec rake db:migrate - - bundle exec rake redmine:plugins:migrate + - bundle exec rake db:create db:migrate redmine:plugins:migrate script: - export SKIP_COVERAGE=1 diff --git a/CHANGELOG.md b/CHANGELOG.md index aea29fb..e8e2408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changelog 1.0.5 ----- -- ruby 2.3.x or newer is required +- ruby 2.4.x or newer is required 1.0.4 diff --git a/Gemfile b/Gemfile index e7117a8..cd397d6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,8 @@ gem 'slim-rails' gem 'validate_url' + +group :development, :test do + gem 'brakeman', require: false + gem 'rubocop', require: false + gem 'rubocop-performance', require: false +end diff --git a/README.md b/README.md index df38ce9..bf9d036 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Requirements ------------ * Redmine version >= 3.0.0 -* Ruby version >= 2.3.0 +* Ruby version >= 2.4.0 Installation diff --git a/init.rb b/init.rb index 5c215ae..71d20e2 100644 --- a/init.rb +++ b/init.rb @@ -1,7 +1,6 @@ raise "\n\033[31mredmine_messenger requires ruby 2.3 or newer. Please update your ruby version.\033[0m" if RUBY_VERSION < '2.3' -require 'redmine' -require 'redmine_messenger' +require_dependency 'redmine_messenger' Redmine::Plugin.register :redmine_messenger do name 'Redmine Messenger' @@ -41,3 +40,13 @@ Redmine::Plugin.register :redmine_messenger do post_password_updates: '0' }, partial: 'settings/messenger_settings' end + +begin + if ActiveRecord::Base.connection.table_exists?(Setting.table_name) + Rails.configuration.to_prepare do + RedmineMessenger.setup + end + end +rescue ActiveRecord::NoDatabaseError + Rails.logger.error 'database not created yet' +end diff --git a/lib/redmine_messenger.rb b/lib/redmine_messenger.rb index 32e1869..2476a13 100644 --- a/lib/redmine_messenger.rb +++ b/lib/redmine_messenger.rb @@ -1,11 +1,27 @@ -Rails.configuration.to_prepare do - module RedmineMessenger - REDMINE_CONTACTS_SUPPORT = Redmine::Plugin.installed?('redmine_contacts') ? true : false - REDMINE_DB_SUPPORT = Redmine::Plugin.installed?('redmine_db') ? true : false - # this does not work at the moment, because redmine loads passwords after messener plugin - REDMINE_PASSWORDS_SUPPORT = Redmine::Plugin.installed?('redmine_passwords') ? true : false +module RedmineMessenger + REDMINE_CONTACTS_SUPPORT = Redmine::Plugin.installed?('redmine_contacts') ? true : false + REDMINE_DB_SUPPORT = Redmine::Plugin.installed?('redmine_db') ? true : false + # this does not work at the moment, because redmine loads passwords after messener plugin + REDMINE_PASSWORDS_SUPPORT = Redmine::Plugin.installed?('redmine_passwords') ? true : false - def self.settings + class << self + def setup + # Patches + Issue.send(:include, RedmineMessenger::Patches::IssuePatch) + WikiPage.send(:include, RedmineMessenger::Patches::WikiPagePatch) + ProjectsController.send :helper, MessengerProjectsHelper + Contact.send(:include, RedmineMessenger::Patches::ContactPatch) if RedmineMessenger::REDMINE_CONTACTS_SUPPORT + DbEntry.send(:include, RedmineMessenger::Patches::DbEntryPatch) if RedmineMessenger::REDMINE_DB_SUPPORT + Password.send(:include, RedmineMessenger::Patches::PasswordPatch) if Redmine::Plugin.installed?('redmine_passwords') + + # Global helpers + ActionView::Base.send :include, RedmineMessenger::Helpers + + # Hooks + require_dependency 'redmine_messenger/hooks' + end + + def settings if Setting[:plugin_redmine_messenger].class == Hash if Rails.version >= '5.2' # convert Rails 4 data @@ -21,24 +37,10 @@ Rails.configuration.to_prepare do end end - def self.setting?(value) + def setting?(value) return true if settings[value].to_i == 1 false end end - - # Patches - Issue.send(:include, RedmineMessenger::Patches::IssuePatch) - WikiPage.send(:include, RedmineMessenger::Patches::WikiPagePatch) - ProjectsController.send :helper, MessengerProjectsHelper - Contact.send(:include, RedmineMessenger::Patches::ContactPatch) if RedmineMessenger::REDMINE_CONTACTS_SUPPORT - DbEntry.send(:include, RedmineMessenger::Patches::DbEntryPatch) if RedmineMessenger::REDMINE_DB_SUPPORT - Password.send(:include, RedmineMessenger::Patches::PasswordPatch) if Redmine::Plugin.installed?('redmine_passwords') - - # Global helpers - ActionView::Base.send :include, RedmineMessenger::Helpers - - # Hooks - require_dependency 'redmine_messenger/hooks' end diff --git a/test/support/database-mysql-travis.yml b/test/support/database-mysql-travis.yml new file mode 100644 index 0000000..2acc077 --- /dev/null +++ b/test/support/database-mysql-travis.yml @@ -0,0 +1,8 @@ +test: + adapter: mysql2 + database: travis_ci_test + host: localhost + username: root + password: + pool: 5 + encoding: utf8mb4