Merge pull request #2467 from TracksApp/test_on_all_supported

Run tests on all supported platforms
This commit is contained in:
Jyri-Petteri Paloposki 2020-09-05 04:12:05 +03:00 committed by GitHub
commit d99361bb3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 262 additions and 22 deletions

View file

@ -1,11 +1,38 @@
---
name: Continuous Integration
name: Automated tests
on: pull_request
jobs:
test:
test25mysql:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: bash -x script/cibuild
- run: bash -x script/cibuild 2.5 mysql
test26mysql:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: bash -x script/cibuild 2.6 mysql
test27mysql:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: bash -x script/cibuild 2.7 mysql
test26postgres:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: bash -x script/cibuild 2.6 postgres
test26sqlite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: bash -x script/cibuild 2.6 sqlite
# - run: bash -x script/cibuild 2.5 postgres
# - run: bash -x script/cibuild 2.7 postgres

30
Dockerfile-2.5 Normal file
View file

@ -0,0 +1,30 @@
FROM ruby:2.5
# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
WORKDIR /app
RUN touch /etc/app-env
COPY Gemfile* /app/
RUN gem install bundler
RUN bundle install --jobs 4
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn
RUN mkdir /app/log
COPY . /app/
COPY config/database.docker.yml /app/config/database.yml
COPY config/site.docker.yml /app/config/site.yml
RUN RAILS_ENV=production bundle exec rake assets:precompile
ENTRYPOINT ["/app/docker-entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

30
Dockerfile-2.7 Normal file
View file

@ -0,0 +1,30 @@
FROM ruby:2.7
# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
WORKDIR /app
RUN touch /etc/app-env
COPY Gemfile* /app/
RUN gem install bundler
RUN bundle install --jobs 4
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn
RUN mkdir /app/log
COPY . /app/
COPY config/database.docker.yml /app/config/database.yml
COPY config/site.docker.yml /app/config/site.yml
RUN RAILS_ENV=production bundle exec rake assets:precompile
ENTRYPOINT ["/app/docker-entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

View file

@ -24,6 +24,7 @@ gem 'jquery-ui-rails' , '~>6.0.1'
# Alternatively use --without <group> arguments to bundler to not install that group
gem "sqlite3", group: :sqlite
gem "mysql2", "~> 0.5.3", group: :mysql
gem "pg", "~> 1.2.3", group: :postgresql
gem "RedCloth"
gem "sanitize", "~> 5.2"
@ -70,7 +71,6 @@ group :test do
gem 'rails-controller-testing'
gem 'rails-dom-testing', '~> 2.0.0'
gem "factory_bot_rails"
gem "rspec-expectations"
gem "database_cleaner"

View file

@ -165,6 +165,7 @@ GEM
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
pg (1.2.3)
puma (4.3.5)
nio4r (~> 2.0)
rack (2.2.3)
@ -326,6 +327,7 @@ DEPENDENCIES
mocha
mysql2 (~> 0.5.3)
paperclip
pg (~> 1.2.3)
puma (~> 4.3)
rack-mini-profiler
rails (~> 6.0.3)

View file

@ -766,7 +766,7 @@ class TodosController < ApplicationController
def get_not_completed_for_predecessor(relation, todo_id=nil)
items = relation.todos.not_completed.
where('(LOWER(todos.description) LIKE ?)', "%#{params[:term].downcase}%")
where('(LOWER(todos.description) ' + Common.like_operator + '?)', "%#{params[:term].downcase}%")
items = items.where("AND NOT(todos.id=?)", todo_id) unless todo_id.nil?
items.

View file

@ -7,7 +7,7 @@ class Context < ApplicationRecord
scope :active, -> { where state: :active }
scope :hidden, -> { where state: :hidden }
scope :closed, -> { where state: :closed }
scope :with_name, lambda { |name| where("name LIKE ?", name) }
scope :with_name, lambda { |name| where("name " + Common.like_operator + " ?", name) }
acts_as_list :scope => :user, :top_of_list => 0

View file

@ -2,5 +2,5 @@ class Note < ApplicationRecord
belongs_to :user
belongs_to :project
scope :with_body, lambda { |terms| where("body LIKE ?", terms) }
scope :with_body, lambda { |terms| where("body " + Common.like_operator + " ?", terms) }
end

View file

@ -11,8 +11,8 @@ class Project < ApplicationRecord
scope :completed, -> { where state: 'completed' }
scope :uncompleted, -> { where("NOT(state = ?)", 'completed') }
scope :with_name_or_description, lambda { |body| where("name LIKE ? OR description LIKE ?", body, body) }
scope :with_namepart, lambda { |body| where("name LIKE ?", body + '%') }
scope :with_name_or_description, lambda { |body| where("name " + Common.like_operator + " ? OR description " + Common.like_operator + " ?", body, body) }
scope :with_namepart, lambda { |body| where("name " + Common.like_operator + " ?", body + '%') }
before_create :set_last_reviewed_now

View file

@ -27,14 +27,14 @@ module Search
def incomplete_todos(terms)
@user.todos.
where("(todos.description LIKE ? OR todos.notes LIKE ?) AND todos.completed_at IS NULL", terms, terms).
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND todos.completed_at IS NULL", terms, terms).
includes(Todo::DEFAULT_INCLUDES).
reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
end
def complete_todos(terms)
@user.todos.
where("(todos.description LIKE ? OR todos.notes LIKE ?) AND NOT (todos.completed_at IS NULL)", terms, terms).
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND NOT (todos.completed_at IS NULL)", terms, terms).
includes(Todo::DEFAULT_INCLUDES).
reorder("todos.completed_at DESC")
end
@ -46,7 +46,7 @@ module Search
"LEFT JOIN taggings ON tags.id = taggings.tag_id "+
"LEFT JOIN todos ON taggings.taggable_id = todos.id "+
"WHERE todos.user_id=? "+
"AND tags.name LIKE ? ", @user.id, terms])
"AND tags.name " + Common.like_operator + " ? ", @user.id, terms])
end
end

View file

@ -6,4 +6,14 @@ module Common
@user_theme = SITE_CONFIG['default_theme'] || 'light_blue'
end
end
def self.like_operator
# This is something of a hack to use the correct operator for Pg
if ActiveRecord::Base.connection.adapter_name.downcase.to_sym == :postgresql
like = 'ILIKE'
else
like = 'LIKE'
end
return like
end
end

View file

@ -2,7 +2,7 @@
set -e
docker_compose="docker-compose --file docker-compose.yml"
docker_compose="docker-compose --file test-envs/docker-compose-$1-$2.yml"
function cleanup() {
$docker_compose down
@ -25,6 +25,12 @@ script/poll-for-db
# Leaving this in since it will be needed for Rails 5
$docker_compose run web bin/rails db:environment:set RAILS_ENV=test || true
$docker_compose run web bin/rake db:reset
if [ "$2" == "mysql" ];
then
$docker_compose run web bin/rake db:reset
else
$docker_compose run web bin/rake db:migrate
$docker_compose run web bin/rake db:seed
fi
$docker_compose run web bin/rake test

View file

@ -0,0 +1,29 @@
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: ${TRACKS_DB:-tracks}
volumes:
- db-data:/var/lib/mysql
web:
build:
context: ..
dockerfile: Dockerfile-2.5
environment:
# These are set in script/ci-build, so we need to pass-thru them.
RAILS_ENV: $RAILS_ENV
DATABASE_NAME: $DATABASE_NAME
DATABASE_USERNAME: root
DATABASE_PASSWORD_EMPTY: 1
volumes:
- ${VOLUME:-..}:/app:Z
- ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z
- ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z
ports:
- 3000:3000
depends_on:
- db
volumes:
db-data:

View file

@ -0,0 +1,29 @@
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: ${TRACKS_DB:-tracks}
volumes:
- db-data:/var/lib/mysql
web:
build:
context: ..
dockerfile: Dockerfile
environment:
# These are set in script/ci-build, so we need to pass-thru them.
RAILS_ENV: $RAILS_ENV
DATABASE_NAME: $DATABASE_NAME
DATABASE_USERNAME: root
DATABASE_PASSWORD_EMPTY: 1
volumes:
- ${VOLUME:-..}:/app:Z
- ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z
- ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z
ports:
- 3000:3000
depends_on:
- db
volumes:
db-data:

View file

@ -0,0 +1,32 @@
version: '3'
services:
db:
image: postgres:13
environment:
POSTGRES_DB: ${DATABASE_NAME:-tracks}
POSTGRES_PASSWORD: password
volumes:
- db-data:/var/lib/postgresql/data
web:
build:
context: ..
dockerfile: Dockerfile
environment:
# These are set in script/ci-build, so we need to pass-thru them.
RAILS_ENV: $RAILS_ENV
DATABASE_NAME: $DATABASE_NAME
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: password
DATABASE_TYPE: postgresql
DATABASE_ENCODING: unicode
DATABASE_PORT: 5432
volumes:
- ${VOLUME:-..}:/app:Z
- ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z
- ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z
ports:
- 3000:3000
depends_on:
- db
volumes:
db-data:

View file

@ -0,0 +1,17 @@
version: '3'
services:
web:
build:
context: ..
dockerfile: Dockerfile
environment:
# These are set in script/ci-build, so we need to pass-thru them.
RAILS_ENV: $RAILS_ENV
DATABASE_NAME: "/app/db.sqlite"
DATABASE_TYPE: sqlite3
volumes:
- ${VOLUME:-..}:/app:Z
- ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z
- ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z
ports:
- 3000:3000

View file

@ -0,0 +1,29 @@
version: '3'
services:
db:
image: mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: ${TRACKS_DB:-tracks}
volumes:
- db-data:/var/lib/mysql
web:
build:
context: ..
dockerfile: Dockerfile-2.7
environment:
# These are set in script/ci-build, so we need to pass-thru them.
RAILS_ENV: $RAILS_ENV
DATABASE_NAME: $DATABASE_NAME
DATABASE_USERNAME: root
DATABASE_PASSWORD_EMPTY: 1
volumes:
- ${VOLUME:-..}:/app:Z
- ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z
- ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z
ports:
- 3000:3000
depends_on:
- db
volumes:
db-data:

View file

@ -1,7 +1,7 @@
require 'test_helper'
class SearchControllerTest < ActionController::TestCase
def setup
end
@ -10,12 +10,12 @@ class SearchControllerTest < ActionController::TestCase
get :index
assert_response 200
end
def test_search_for_todo_with_tag
login_as :admin_user
post :results, params: { :search => "gates" }
assert_response 200
assert_equal 3, assigns['count'], "should have found 3 todos"
end
end

View file

@ -480,7 +480,6 @@ class TodosControllerTest < ActionController::TestCase
login_as(:admin_user)
get :index, params: { :format => "rss" }
assert_equal 'application/rss+xml', @response.media_type
# puts @response.body
assert_select 'rss[version="2.0"]' do
assert_select 'channel' do
@ -996,7 +995,7 @@ class TodosControllerTest < ActionController::TestCase
def test_format_note
login_as(:admin_user)
todo = users(:admin_user).todos.first
todo = users(:admin_user).todos.where("state='active'").first
todo.notes = "Normal *bold* http://foo.bar/baz"
todo.save!
get :index

View file

@ -364,16 +364,16 @@ class UserTest < ActiveSupport::TestCase
# test group counts for projects and contexts
project_counts = u.todos.count_by_group(:project_id)
assert_equal [6,3,4,4], project_counts.values
assert_equal [6,3,4,4].sort, project_counts.values.sort
context_counts = u.todos.count_by_group(:context_id)
assert_equal [7,3,1,3,1,2], context_counts.values
assert_equal [7,3,1,3,1,2].sort, context_counts.values.sort
# add a todo to the first context and check that the count is increased
u.todos.create!(:description => "yet another todo", :context => u.contexts.first)
context_counts = u.todos.reload.count_by_group(:context_id)
assert_equal [8,3,1,3,1,2], context_counts.values
assert_equal [8,3,1,3,1,2].sort, context_counts.values.sort
end
def test_deleting_user_deletes_all_related_data