Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test Redmine ONE Webhook Plugin

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]

jobs:
test:
runs-on: ubuntu-24.04

strategy:
matrix:
database: ['mysql:8.0']
ruby-version: ['3.2']
redmine-version: ['5.1-stable']

steps:
- name: Setup Redmine
uses: hidakatsuya/action-setup-redmine@v3.0.1
with:
repository: 'redmine/redmine'
version: ${{ matrix.redmine-version }}
database: ${{ matrix.database }}
ruby-version: ${{ matrix.ruby-version }}

- name: Checkout plugin
uses: actions/checkout@v4
with:
path: plugins/redmine_one_webhook

- name: Run plugin tests
run: |
bundle install
bin/rails redmine:plugins:test NAME=redmine_one_webhook RAILS_ENV=test
2 changes: 1 addition & 1 deletion app/views/settings/_redmine_one_webhook_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<table class="list">
<tr>
<td>
<%= check_box_tag 'settings[enabled]', '1', @settings['enabled'] == '1' %>When enabled, overtime logs will be sent to ONE system
<%= check_box_tag 'settings[enabled]', '1', @settings['enabled'] == '1', style: 'height: 100%; margin-right: 5px;' %>When enabled, overtime logs will be sent to ONE system
</td>
</tr>

Expand Down
7 changes: 2 additions & 5 deletions lib/redmine_webhook/author_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ def to_hash
end

def icon_url
if @author.mail.blank?
icon_url = nil
else
icon_url = gravatar_url(@author.mail)
end
return nil if @author.mail.blank?
gravatar_url(@author.mail)
end
end
end
2 changes: 1 addition & 1 deletion lib/redmine_webhook/time_entry_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def issue_hash

def custom_field_values_hash
return [] unless @time_entry.custom_field_values
@time_entry.custom_field_values.collect do |value|
@time_entry.custom_field_values.select { |cfv| cfv.value.present? && cfv.value.to_s != '0' }.collect do |value|
RedmineWebhook::CustomFieldValueWrapper.new(value).to_hash
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/redmine_webhook/webhook_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

module RedmineWebhook
class WebhookListener < Redmine::Hook::Listener
# Make new public for testing (Redmine::Hook::Listener makes new private by default)
def self.new(*args)
super
end

# Configurable overtime activity names (case-insensitive)
OVERTIME_ACTIVITIES = ['overtime', 'ot'].freeze

Expand Down Expand Up @@ -198,7 +203,7 @@ def get_custom_field_value(time_entry, field_names)

time_entry.custom_field_values.each do |cfv|
field_name = cfv.custom_field.name.to_s.downcase.strip
if field_names.any? { |fn| field_name.include?(fn) }
if field_names.any? { |fn| field_name.include?(fn.to_s.downcase) }
return cfv.value
end
end
Expand Down
81 changes: 81 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
# Test runner script for Redmine ONE Webhook Plugin
# Usage: ./run_tests.sh [test_file]

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color

PLUGIN_NAME="redmine_one_webhook"

echo -e "${GREEN}Running Redmine ONE Webhook Plugin Tests${NC}"
echo "=========================================="

# Check if running in Docker or locally
if [ -f "/.dockerenv" ] || [ -n "$DOCKER_CONTAINER" ]; then
# Running inside Docker container
REDMINE_ROOT="/usr/src/redmine"
cd "$REDMINE_ROOT"

if [ -n "$1" ]; then
# Run specific test file
TEST_FILE="$1"
echo -e "${YELLOW}Running test: $TEST_FILE${NC}"
RAILS_ENV=test ruby -Itest "plugins/$PLUGIN_NAME/test/$TEST_FILE"
else
# Run all plugin tests
echo -e "${YELLOW}Running all tests...${NC}"
RAILS_ENV=test rake redmine:plugins:test NAME=$PLUGIN_NAME
fi
else
# Running locally - use Docker Compose
if [ ! -d "../pms" ]; then
echo -e "${RED}Error: Cannot find pms directory${NC}"
echo "Please ensure docker-compose setup exists"
exit 1
fi

echo -e "${YELLOW}Running tests via Docker Compose...${NC}"
cd ../pms

# Check if test database is configured
TEST_DB_CONFIGURED=$(docker-compose exec -T redmine bash -c "grep -q 'test:' /usr/src/redmine/config/database.yml && echo 'yes' || echo 'no'" 2>/dev/null || echo "no")

if [ "$TEST_DB_CONFIGURED" = "no" ]; then
echo -e "${RED}Error: Test database not configured${NC}"
echo -e "${YELLOW}Please run './setup_test.sh' first${NC}"
exit 1
fi

if [ -n "$1" ]; then
# Run specific test file
echo -e "${BLUE}Running test file: $1${NC}"
# Add mocha to load path (it's not in Gemfile.lock due to --without test)
docker-compose exec -T redmine bash -c "cd /usr/src/redmine && RUBYLIB='/usr/local/bundle/gems/mocha-3.0.1/lib' RAILS_ENV=test ruby -Itest plugins/$PLUGIN_NAME/test/$1"
else
# Run all tests
echo -e "${BLUE}Running all tests...${NC}"
# Add mocha to load path (it's not in Gemfile.lock due to --without test)
docker-compose exec -T redmine bash -c "cd /usr/src/redmine && RUBYLIB='/usr/local/bundle/gems/mocha-3.0.1/lib' RAILS_ENV=test rake redmine:plugins:test NAME=$PLUGIN_NAME"
fi

TEST_EXIT_CODE=$?

if [ $TEST_EXIT_CODE -eq 0 ]; then
echo ""
echo -e "${GREEN}✓ All tests passed!${NC}"
else
echo ""
echo -e "${RED}✗ Some tests failed${NC}"
fi

exit $TEST_EXIT_CODE
fi

echo -e "${GREEN}Tests completed!${NC}"
89 changes: 89 additions & 0 deletions setup_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# Setup test environment for Redmine plugin testing
# Run this ONCE after docker-compose up for the first time

set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${GREEN}=== Setting up Redmine Test Environment ===${NC}"
echo ""

# Check if we're in the right directory
if [ ! -f "init.rb" ]; then
echo -e "${RED}Error: Must run from plugin directory${NC}"
exit 1
fi

cd ../pms

# Check if containers are running
if ! docker-compose ps redmine | grep -q "Up"; then
echo -e "${YELLOW}Starting containers...${NC}"
docker-compose up -d
echo "Waiting for containers to be ready..."
sleep 15
fi

echo -e "${BLUE}Step 1: Configuring test database...${NC}"
docker-compose exec -T redmine bash -c "
cd /usr/src/redmine
if ! grep -q 'test:' config/database.yml; then
cat >> config/database.yml << 'EOF'

test:
adapter: mysql2
host: \"db\"
port: \"3306\"
username: \"redmine\"
password: \"redmine_password\"
database: \"redmine_test\"
encoding: utf8mb4
EOF
echo '✓ Test database configuration added'
else
echo '✓ Test database already configured'
fi
"

echo -e "${BLUE}Step 2: Creating test database...${NC}"
docker-compose exec -T redmine bash -c "
cd /usr/src/redmine
echo 'Creating test database...'
RAILS_ENV=test bin/rails db:create 2>&1 | grep -v 'already exists' | head -1 || echo '✓ Database exists'
echo 'Running migrations...'
RAILS_ENV=test bin/rails db:migrate 2>&1 | tail -5
"

echo -e "${BLUE}Step 3: Installing test dependencies and patching Gemfile.lock...${NC}"
docker-compose exec -T redmine bash -c "
cd /usr/src/redmine
echo 'Installing compatible minitest 5.27.0...'
gem install minitest -v 5.27.0 --no-document 2>&1 | tail -1
echo 'Installing mocha gem...'
gem install mocha --no-document 2>&1 | tail -1
echo 'Patching Gemfile.lock to use minitest 5.27.0...'
# Replace minitest 6.0.1 with 5.27.0 in Gemfile.lock
sed -i 's/minitest (6\\.0\\.1)/minitest (5.27.0)/g' Gemfile.lock
sed -i 's/minitest (~> 6\\.0)/minitest (~> 5.27)/g' Gemfile.lock
echo '✓ Test dependencies installed and Gemfile.lock patched'
"

echo -e "${BLUE}Step 4: Loading default test data...${NC}"
docker-compose exec -T redmine bash -c "
cd /usr/src/redmine
RAILS_ENV=test bin/rails redmine:load_default_data REDMINE_LANG=en 2>&1 | grep -E '(Default|Select)' || echo '✓ Data loaded'
"

echo ""
echo -e "${GREEN}✓ Setup complete!${NC}"
echo ""
echo -e "${YELLOW}You can now run tests with:${NC}"
echo -e " ${BLUE}cd $(dirname $0) && ./run_tests.sh${NC}"
echo ""
echo -e "${YELLOW}Note: This setup persists across 'docker-compose restart'${NC}"
echo -e "${YELLOW}Only need to run this again after 'docker-compose down'${NC}"
Loading