Skip to content

Instantly share code, notes, and snippets.

View rasmar's full-sized avatar

Marcin Raszkiewicz rasmar

View GitHub Profile
@rasmar
rasmar / docker-compose.ci.yml
Last active December 22, 2017 18:10
E2E - volumes
frontend:
build:
context: .
dockerfile: Dockerfile.e2e
command: nginx
networks:
main:
aliases:
- frontend
ports:
@rasmar
rasmar / database.e2e.yml
Last active December 22, 2017 18:01
E2E - database.e2e
e2e:
adapter: postgresql
host: postgres
encoding: unicode
database: your_project_test
pool: 5
username: postgres
password: your_password
@rasmar
rasmar / Dockerfile.e2e
Last active February 20, 2018 18:55
E2E - Backend Dockerfile
FROM quay.io/netguru/baseimage:0.10.1 # Image containing all dependecies like imagemagick etc
ENV RUBY_VERSION 2.4.2 # To get proper ruby
## Install Ruby & Dependencies
RUN \ # Install ruby
apt-get update -q && \
apt-get install -q libcurl3 && \
apt-get install -q -y cron && \
ruby-install --system --cleanup ruby $RUBY_VERSION -- --disable-install-rdoc && \
@rasmar
rasmar / rails_helper.rb
Last active February 20, 2018 18:59
E2E - final rails_helper
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: { "chromeOptions" => { "args" => %w[window-size=1024,768] } },
)
end
if Rails.env.test?
Capybara.register_driver :selenium do |app|
@rasmar
rasmar / docker-compose.ci.yml
Last active March 9, 2018 12:14
E2E - docker-compose
version: '2' # Version of composer
services:
backend: # Backend container
build:
context: ~/backend # Backend should be pulled by git to this location
dockerfile: docker/Dockerfile.e2e # The location of Dockerfile, relative to context above
depends_on: # The containers below will be resolved and loaded before backed
- redis
- postgres
- frontend
@rasmar
rasmar / circle.yml
Last active February 20, 2018 19:34
E2E - final circle setup
machine:
node:
version: 8.2.1
pre:
- mkdir ~/.cache/yarn
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0 # Download Docker 1.10.0 (linked to docker-compose v2) for CircleCI
- >-
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_jaacoo-backend-e2e-tests-deploy-key-for-jaacoo-repo'
git clone git@github.com:netguru/jaacoo.git ~/backend && cd ~/backend # Download backend to ~/backend. The SSH for backend had to be placed in CircleCI build setup page
- set -o allexport; source "${HOME}/${CIRCLE_PROJECT_REPONAME}/.env"; set +o allexport
@rasmar
rasmar / about.md
Last active January 1, 2018 19:55
Rails Jobs

Important notes

  1. Use ActiveJob
  2. Use different adapters: Sidekiq, Resque
  3. Backend adapters depend on workers to execute jobs
  4. Use queues for different kind of jobs / tasks: mailing, maintenance, etc.
  5. Job perform callbacks are available as well
  6. ActionMailer can work as an ActiveJob
  7. Watch out for Thread safety - pay attention to instance variables and how they are accessed and changed in concurrent processes. One option is to use Mutex
  8. Sidekiq > Resque > DelayedJob (But it depends on the needs and available resources)
@rasmar
rasmar / query_objects.md
Created January 3, 2018 10:50
Query Objects

WHY USE

  1. Slim-down models / controllers
  2. Dissect big queries
  3. Make testing queries easier

WHAT IS IT

  1. It's a PORO
  2. Overrides ActiveRecord standard query methods like all
  3. Query objects can be composed (as long as they return relation)
  4. QUery objects can be extended by inheritance
@rasmar
rasmar / null_objects.md
Created January 3, 2018 13:25
Null Objects

Why not use Object#try

  1. It may hide a problem from a plain sight
  2. Sometimes it resolves problem which should be there at the first place
  3. Implementation of try says nothing about the purpose of what is written

To remember

  1. Original article
  2. Law of Demeter

When use NullObject

@rasmar
rasmar / form_controller.rb
Created January 3, 2018 13:48
FormObject
def create
@form_object = UserRegistration::RegistrationForm.new(user_params, params[:notify])
if @form_object.register
... #typically we flash and redirect here
else
render :new
end
end