Skip to content

Commit

Permalink
Support Redmine 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hidakatsuya committed Aug 14, 2024
1 parent f8b9940 commit 11e8646
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 25 deletions.
31 changes: 27 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ on:
pull_request:

jobs:
build:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
Expand All @@ -22,8 +21,32 @@ jobs:
- name: Lint
run: bundle exec rake standard

integration_test:
runs-on: ubuntu-latest

needs: test

strategy:
matrix:
include:
- ruby_version: "3.3"
redmine_branch_name: "master"

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- name: Set up test
run: bundle exec rake rexer:test:build_integration_test_image
env:
RUBY_VERSION: ${{ matrix.ruby_version }}
REDMINE_BRANCH_NAME: ${{ matrix.redmine_branch_name }}

- name: Run tests
run: bundle exec rake test
- name: Run integration tests
run: bundle exec rake test:integration
env:
RUBY_VERSION: ${{ matrix.ruby_version }}
REDMINE_BRANCH_NAME: ${{ matrix.redmine_branch_name }}
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ It is mainly aimed at helping with the development of Redmine and its plugins, a
gem install rexer
```

## Supported Redmine

Rexer is tested with Redmine v5.1 and trunk.

## Usage

### Quick Start
Expand Down Expand Up @@ -120,20 +124,26 @@ end

## Developing

### Running integration tests
### Running tests

First, you need to build the docker image for the integration tests.

```
rake rexer:test:build_integration_test_image
rake test:prepare_integration
```

Then, you can run the integration tests.
Then, you can run all tests.

```
rake test
```

Or, you can only the integration tests as follows.

```
rake test:integration
```

### Formatting and Linting code

This project uses [Standard](https://github.com/standardrb/standard) for code formatting and linting. You can format and check the code by running the following commands.
Expand Down
27 changes: 19 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@ require "bundler/gem_tasks"
require "rake/testtask"
require "standard/rake"

Rake::TestTask.new(:test) do |t|
Rake::TestTask.new("test:integration") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.test_files = FileList["test/integration/**/*_test.rb"]
t.warning = false
end

task default: %i[test standard]

namespace :rexer do
namespace :test do
desc "Build the integration test image"
task :build_integration_test_image do
system "docker build -f test/integration/Dockerfile -t rexer-test .", exception: true
end
desc "Run all tests"
task test: %i[test:integration]

namespace :test do
desc "Prepare to run integration tests"
task :prepare_integration do
ruby_version = ENV["RUBY_VERSION"] || "3.3"
redmine_branch_name = ENV["REDMINE_BRANCH_NAME"] || "master"

image_tag = "rexer-test:#{ruby_version}-#{redmine_branch_name}"

system(<<~CMD, exception: true)
docker build -f test/integration/Dockerfile \
--build-arg RUBY_VERSION=#{ruby_version} \
--build-arg REDMINE_BRANCH_NAME=#{redmine_branch_name} \
-t #{image_tag} .
CMD
end
end
9 changes: 8 additions & 1 deletion lib/rexer/extension/theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ module Rexer
module Extension
module Theme
def self.dir
Pathname.new("themes")
public_themes = Pathname.pwd.join("public", "themes")

if public_themes.exist?
# When Redmine version is v5.1 or older, public/themes is used.
public_themes
else
Pathname.new("themes")
end
end

class Base
Expand Down
4 changes: 3 additions & 1 deletion test/integration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ ARG RUBY_VERSION=3.3

FROM ruby:$RUBY_VERSION

ARG REDMINE_BRANCH_NAME=master

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -52,7 +54,7 @@ RUN git init && \
# Redmine
#
WORKDIR /redmine
RUN git clone --depth 1 https://github.com/redmine/redmine.git .
RUN git clone -b $REDMINE_BRANCH_NAME --depth 1 https://github.com/redmine/redmine.git .
COPY test/integration/docker/database.yml config/database.yml

# Directory for the bundle cache
Expand Down
2 changes: 1 addition & 1 deletion test/integration/docker/plugin_a/app/models/hello.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Hello < ApplicationRecord
class Hello < (defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base)
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateHellos < ActiveRecord::Migration[7.1]
class CreateHellos < ActiveRecord::Migration[6.1]
def change
create_table :hellos do |t|
t.string :world
Expand Down
15 changes: 14 additions & 1 deletion test/integration/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "rake"

ENV["VERBOSE"] = "1"
ENV["RUBY_VERSION"] ||= "3.3"
ENV["REDMINE_BRANCH_NAME"] ||= "master"

module IntegrationHelper
Result = Data.define(:output_raw, :error_raw, :status_raw) do
Expand All @@ -15,7 +17,9 @@ def error = error_raw.strip
def success? = status_raw.success?
end

def image_name = "rexer-test"
def image_name
@image_name ||= "rexer-test:#{ENV["RUBY_VERSION"]}-#{ENV["REDMINE_BRANCH_NAME"]}"
end

def container_name = "rexer-test-container"

Expand Down Expand Up @@ -62,4 +66,13 @@ def docker_exec(*command, raise: false)
def docker_stop
run_with_capture("docker container stop -t 0 #{container_name} && docker container rm #{container_name}", raise: true)
end

def legacy_theme_dir?
return @legacy_theme_dir if defined?(@legacy_theme_dir)
@legacy_theme_dir = docker_exec("test -d /redmine/public/themes").success?
end

def theme_dir
legacy_theme_dir? ? "/redmine/public/themes" : "/redmine/themes"
end
end
11 changes: 6 additions & 5 deletions test/integration/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class IntegrationTest < Test::Unit::TestCase
assert_equal "plugin_a", result.output.last
end

docker_exec("ls themes").then do |result|
assert_equal "theme_a", result.output.last
docker_exec("ls #{theme_dir}").then do |result|
assert_includes result.output.last, "theme_a"
end

docker_exec("bin/rails r 'puts Hello.table_name'").then do |result|
Expand All @@ -60,8 +60,9 @@ class IntegrationTest < Test::Unit::TestCase
assert_equal ["README"], result.output
end

docker_exec("ls themes").then do |result|
assert_equal ["README"], result.output
docker_exec("ls #{theme_dir}").then do |result|
expected_files = legacy_theme_dir? ? %w[README alternate classic] : %w[README]
assert_equal expected_files, result.output
end

docker_exec("rex state").then do |result|
Expand Down Expand Up @@ -120,7 +121,7 @@ class IntegrationTest < Test::Unit::TestCase
assert_equal "update", result.output_str
end

docker_exec("cat /redmine/themes/theme_a/README").then do |result|
docker_exec("cat #{theme_dir}/theme_a/README").then do |result|
assert_equal "update", result.output_str
end

Expand Down

0 comments on commit 11e8646

Please sign in to comment.