diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95124d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM ruby:3.2.2 + +WORKDIR /app + +ADD . /app + +# Install nodejs +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client \ + && apt-get clean + +# Update bundler to correct version +RUN gem install bundler:2.4.3 + +# Install any needed packages +RUN bundle install diff --git a/Gemfile b/Gemfile index bbc2b18..a050bd3 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,9 @@ source "https://rubygems.org" # gem 'sdoc', :git => 'https://github.com/pond/sdoc.git', :branch => 'master' +group :test do + gem 'pry' + gem 'pry-nav' +end + gemspec diff --git a/Gemfile.lock b/Gemfile.lock index f50ac0a..49073f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,6 +82,7 @@ GEM tzinfo (~> 2.0) builder (3.2.4) byebug (11.1.3) + coderay (1.1.3) concurrent-ruby (1.2.2) crass (1.0.6) date (3.3.3) @@ -121,6 +122,11 @@ GEM mini_portile2 (~> 2.8.0) racc (~> 1.4) pg (1.4.6) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-nav (1.0.0) + pry (>= 0.9.10, < 0.15) psych (5.1.0) stringio racc (1.6.2) @@ -198,6 +204,8 @@ DEPENDENCIES byebug (~> 11.1) doggo (~> 1.3) pg (~> 1.4) + pry + pry-nav rake (~> 13.0) rdoc (~> 6.5) rspec-rails (~> 6.0) diff --git a/README.md b/README.md index cec2c04..7aa2b84 100644 --- a/README.md +++ b/README.md @@ -625,6 +625,11 @@ bundle install ### Tests +For testing, two main options are available. +The first option is running the project locally. This is also the recommended way, as running the tests on a variety of setups and platforms increases the chance of finding platform- or setup-specific bugs. +The second option is utilising the existing Docker Compose setup provided in the project. You can use this if getting the project to work locally is hard or not feasible. + +#### Testing on your machine You will need to have PostgreSQL running. This database is chosen for tests to prove case-insensitive behaviour via detection of ILIKE in generated queries. Using SQLite would have resulted in a more conceptually self-contained test suite, but SQLite is case-insensitive by default and uses "LIKE" either way, making it hard to "see" if the query system is doing the right thing. After `bundle install` and with PostgreSQL up, set up the test database with: @@ -643,6 +648,16 @@ bundle exec rspec You can get an idea of arising test coverage by opening `coverage/index.html` in your preferred web browser. +#### Testing with Docker (Compose) + +In order to be able to utilise the Docker Compose, you will need to have Docker installed, with the Compose plugin. For an easy install of Docker, with a GUI and the Compose plugin preinstalled, please refer to [Docker Desktop](https://www.docker.com/products/docker-desktop/). + +In order to set up the image, simply run `docker compose build` in a terminal of your choice, in the root of this project. This will download the required image and install the required libraries. After this is complete, running the tests is as easy as running the command `docker compose up test`. + +As said in the previous section, test coverage may be analysed using `coverage/index.html` after running the project. + +You can also open a raw terminal in this test container by running `docker run --rm test sh`. For more Compose commands, please refer to [the docker compose reference manual](https://docs.docker.com/compose/reference/). + ### Internal documentation Locally generated RDoc HTML seems to contain a more comprehensive and inter-linked set of pages than those available from `rubydoc.info`. You can (re)generate the internal [`rdoc` documentation](https://ruby-doc.org/stdlib-2.4.1/libdoc/rdoc/rdoc/RDoc/Markup.html#label-Supported+Formats) with: diff --git a/bin/test b/bin/test new file mode 100644 index 0000000..ebe8b44 --- /dev/null +++ b/bin/test @@ -0,0 +1,11 @@ +#!/usr/bin/env sh +set -e + +# go to dummy app (where the bundle and rake files are) +cd ./spec/apps/dummy +echo "== Creating fresh database... ==" +bundle exec rake db:reset +cd ../../.. # nagivate back to root of project + +echo "== Running tests... ==" +bundle exec rspec \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8b75b03 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '2.3' +services: + postgresql: + image: postgres:15 + ports: + - 5432 + environment: + - POSTGRES_PASSWORD=Sup3rSecr1tPasw8rd + - POSTGRES_USER=postgres + - PGDATA=/var/lib/postgresql/data/pgdata + volumes: + - postgresql:/var/lib/postgresql/data + + test: + build: ./ + volumes: + - .:/app + depends_on: + - postgresql + command: 'bin/test' + environment: + - RAILS_ENV=test + - DATABASE_URL=postgresql://postgres:Sup3rSecr1tPasw8rd@postgresql:5432/scimitar-test + +volumes: + postgresql: diff --git a/spec/apps/dummy/bin/bundle b/spec/apps/dummy/bin/bundle old mode 100755 new mode 100644 diff --git a/spec/apps/dummy/bin/rails b/spec/apps/dummy/bin/rails old mode 100755 new mode 100644 diff --git a/spec/apps/dummy/bin/rake b/spec/apps/dummy/bin/rake old mode 100755 new mode 100644 diff --git a/spec/apps/dummy/bin/setup b/spec/apps/dummy/bin/setup old mode 100755 new mode 100644