diff --git a/foreman_notification_send.gemspec b/foreman_notification_send.gemspec index c845696a32c239f00f1ae3dacf3f8823ea5aa03a..b9cd73d6aedc81e17c1582b677ee890fd63b4736 100644 --- a/foreman_notification_send.gemspec +++ b/foreman_notification_send.gemspec @@ -2,23 +2,23 @@ require File.join File.expand_path('lib', __dir__), 'foreman_notification_send/version' -Gem::Specification.new do |s| - s.name = 'foreman_notification_send' - s.version = ForemanNotificationSend::VERSION - s.authors = ['Alexander Olofsson'] - s.email = ['alexander.olofsson@liu.se'] +Gem::Specification.new do |spec| + spec.name = 'foreman_notification_send' + spec.version = ForemanNotificationSend::VERSION + spec.authors = ['Alexander Olofsson'] + spec.email = ['alexander.olofsson@liu.se'] - s.homepage = 'https://github.com/ananace/foreman_notification_send' - s.summary = 'Send Foreman notifications to external systems' - s.description = s.summary - s.license = 'GPL-3.0' + spec.homepage = 'https://github.com/ananace/foreman_notification_send' + spec.summary = 'Send Foreman notifications to external systems' + spec.description = spec.summary + spec.license = 'GPL-3.0' - s.files = Dir['{app,config,db,lib}/**/*.{rake,rb}'] + %w[LICENSE.txt README.md] - s.require_paths = ['lib'] + spec.files = Dir['{app,config,db,lib}/**/*.{rake,rb}'] + %w[LICENSE.txt README.md] - s.add_dependency 'matrix_sdk', '~> 2.6' + spec.add_dependency 'matrix_sdk', '~> 2.6' - s.add_development_dependency 'bundler' - s.add_development_dependency 'minitest' - s.add_development_dependency 'rake' + spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'rubocop-minitest' + spec.add_development_dependency 'rubocop-performance' + spec.add_development_dependency 'rubocop-rails' end diff --git a/lib/tasks/foreman_notification_send_tasks.rake b/lib/tasks/foreman_notification_send_tasks.rake index 7bf7736408de8bc956d656e69c9df297e7e69894..93f3625e56ffcf8a76d874cd51745fa170ac83cb 100644 --- a/lib/tasks/foreman_notification_send_tasks.rake +++ b/lib/tasks/foreman_notification_send_tasks.rake @@ -1,4 +1,14 @@ -# desc "Explaining what the task does" -# task :foreman_notification_send do -# # Task goes here -# end +# frozen_string_literal: true + +namespace :test do + desc 'Test ForemanNotificationSend' + Rake::TestTask.new(:foreman_notification_send) do |t| + test_dir = File.join(__dir__, '../..', 'test') + t.libs << ['test', test_dir] + t.pattern = "#{test_dir}/**/*_test.rb" + t.verbose = true + t.warning = false + end +end + +Rake::Task[:test].enhance %w[test:foreman_notification_send] diff --git a/test/foreman_notification_send_test.rb b/test/foreman_notification_send_test.rb deleted file mode 100644 index 7e3041dc4fae33276f5e32317c753b4dc01944c4..0000000000000000000000000000000000000000 --- a/test/foreman_notification_send_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ForemanNotificationSend::Test < ActiveSupport::TestCase - test "truth" do - assert_kind_of Module, ForemanNotificationSend - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 94fec6b8be7144e9ab199a7533e09ee5ed0e0a4f..0000000000000000000000000000000000000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Configure Rails Environment -ENV["RAILS_ENV"] = "test" - -require_relative "../test/dummy/config/environment" -ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] -require "rails/test_help" - -# Filter out Minitest backtrace while allowing backtrace from other libraries -# to be shown. -Minitest.backtrace_filter = Minitest::BacktraceFilter.new - -require "rails/test_unit/reporter" -Rails::TestUnitReporter.executable = 'bin/test' - -# Load fixtures from the engine -if ActiveSupport::TestCase.respond_to?(:fixture_path=) - ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) - ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path - ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" - ActiveSupport::TestCase.fixtures :all -end diff --git a/test/test_plugin_helper.rb b/test/test_plugin_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..8e54ab14d5d58604b1b3e60432a7f3bd719e7509 --- /dev/null +++ b/test/test_plugin_helper.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# This calls the main test_helper in Foreman-core +require 'test_helper' +require 'database_cleaner' + +# Add plugin to FactoryBot's paths +FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories') +FactoryBot.reload + +# Foreman's setup doesn't handle cleaning up for Minitest::Spec +DatabaseCleaner.strategy = :transaction + +class Minitest::Spec + before :each do + DatabaseCleaner.start + end + + after :each do + DatabaseCleaner.clean + end +end diff --git a/test/unit/notification_test.rb b/test/unit/notification_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..cd416996386818ab754e1234c07489de715b96b3 --- /dev/null +++ b/test/unit/notification_test.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'test_plugin_helper' + +class NotificationTest < ActiveSupport::TestCase + let(:blueprint) { NotificationBlueprint.new group: 'test', level: 'info' } + let(:notification) { Notification.new notification_blueprint: blueprint, message: 'example' } + + context 'Handling data manipulation' do + test 'it should serialize to valid text' do + assert_equal <<~MD.strip, notification.to_markdown + **test**: + â„¹ï¸ example + MD + assert_equal <<~HTML.strip, notification.to_html + <b>test</b>:<br/>â„¹ï¸ example + HTML + end + end +end