diff --git a/.dockerdev/Aptfile b/.dockerdev/Aptfile
new file mode 100644
index 000000000..f027e0d4b
--- /dev/null
+++ b/.dockerdev/Aptfile
@@ -0,0 +1 @@
+vim
diff --git a/.dockerdev/Dockerfile b/.dockerdev/Dockerfile
new file mode 100644
index 000000000..8306c3925
--- /dev/null
+++ b/.dockerdev/Dockerfile
@@ -0,0 +1,60 @@
+ARG RUBY_VERSION
+FROM ruby:$RUBY_VERSION
+
+ARG BUNDLER_VERSION
+ARG PG_MAJOR
+ARG NODE_MAJOR
+
+# Common dependencies
+RUN apt-get update -qq \
+ && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
+ build-essential \
+ gnupg2 \
+ curl \
+ less \
+ git \
+ && apt-get clean \
+ && rm -rf /var/cache/apt/archives/* \
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
+ && truncate -s 0 /var/log/*log
+
+# Add PostgreSQL to sources list
+RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
+ && echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
+
+
+# Add NodeJS to sources list
+RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
+
+
+# Application dependencies
+# We use an external Aptfile for that, stay tuned
+COPY ./Aptfile /tmp/Aptfile
+RUN apt-get update -qq
+RUN DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade
+RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
+ nodejs \
+ $(cat /tmp/Aptfile | xargs) && \
+ apt-get clean && \
+ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
+ truncate -s 0 /var/log/*log
+
+# Configure bundler
+ENV LANG=C.UTF-8 \
+ BUNDLE_JOBS=4 \
+ BUNDLE_RETRY=3
+
+# Uncomment this line if you store Bundler settings in the project's root
+# ENV BUNDLE_APP_CONFIG=.bundle
+
+# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec`
+# ENV PATH /app/bin:$PATH
+
+# Upgrade RubyGems and install required Bundler version
+RUN gem update --system && \
+ gem install bundler:$BUNDLER_VERSION
+
+# Create a directory for the app code
+RUN mkdir -p /app
+
+WORKDIR /app
diff --git a/.dockerdev/env/database b/.dockerdev/env/database
new file mode 100644
index 000000000..3dc8cad74
--- /dev/null
+++ b/.dockerdev/env/database
@@ -0,0 +1,2 @@
+POSTGRES_USER=postgres
+POSTGRES_PASSWORD=supersecure
diff --git a/.dockerdev/env/web b/.dockerdev/env/web
new file mode 100644
index 000000000..359c0371a
--- /dev/null
+++ b/.dockerdev/env/web
@@ -0,0 +1 @@
+DATABASE_HOST=database
diff --git a/.gitignore b/.gitignore
index 54cb8bbbc..86a3e2108 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,6 @@
*.sassc
.sass-cache
capybara-*.html
-.rspec
/.bundle
/vendor/bundle
/log/*
@@ -13,4 +12,23 @@ capybara-*.html
/spec/tmp/*
**.orig
rerun.txt
-pickle-email-*.html
\ No newline at end of file
+pickle-email-*.html
+
+# Rails stuff
+/source/.bundle
+/source/vendor/bundle/
+/source/doc
+/source/log/*
+/source/tmp
+
+# various artifacts
+**.war
+/source/public/cache
+/source/public/stylesheets/compiled
+/source/public/uploads
+/source/public/system
+/source/spec/tmp/*
+/source/cache
+
+# Mac finder artifacts
+.DS_Store
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 000000000..168b60143
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,42 @@
+version: '3.7'
+
+volumes:
+ db_data:
+ gem_cache:
+
+services:
+ web:
+ build:
+ context: .dockerdev
+ dockerfile: Dockerfile
+ args:
+ RUBY_VERSION: '2.3.8'
+ PG_MAJOR: '11'
+ NODE_MAJOR: '10'
+ BUNDLER_VERSION: '1.17.3'
+ command: bundle exec rails server -b 0.0.0.0
+ ports:
+ - "3000:3000"
+ volumes:
+ - ./source:/app
+ - gem_cache:/usr/local/bundle
+ env_file:
+ - .dockerdev/env/web
+ - .dockerdev/env/database
+ depends_on:
+ - database
+ # - redis
+ tty: true
+ stdin_open: true
+ tmpfs:
+ - /tmp
+
+ database:
+ image: postgres:11
+ env_file:
+ - .dockerdev/env/database
+ volumes:
+ - db_data:/var/lib/postgresql/data
+
+ # redis:
+ # image: redis:5.0
diff --git a/source/.rspec b/source/.rspec
new file mode 100644
index 000000000..49d5710b3
--- /dev/null
+++ b/source/.rspec
@@ -0,0 +1 @@
+--format documentation
diff --git a/source/Gemfile b/source/Gemfile
new file mode 100644
index 000000000..097ef59d6
--- /dev/null
+++ b/source/Gemfile
@@ -0,0 +1,50 @@
+source 'https://rubygems.org'
+
+ruby '2.3.8'
+
+# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
+gem 'rails', '4.2.11.3'
+# Use postgresql as the database for Active Record
+gem 'pg', '~> 0.15'
+# Use SCSS for stylesheets
+gem 'sass-rails', '~> 5.0'
+# Use Uglifier as compressor for JavaScript assets
+gem 'uglifier', '>= 1.3.0'
+# Use CoffeeScript for .coffee assets and views
+gem 'coffee-rails', '~> 4.1.0'
+# See https://github.com/rails/execjs#readme for more supported runtimes
+# gem 'therubyracer', platforms: :ruby
+
+# Use jquery as the JavaScript library
+gem 'jquery-rails'
+# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
+gem 'turbolinks'
+# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
+gem 'jbuilder', '~> 2.0'
+# bundle exec rake doc:rails generates the API under doc/api.
+gem 'sdoc', '~> 0.4.0', group: :doc
+
+# Use ActiveModel has_secure_password
+# gem 'bcrypt', '~> 3.1.7'
+
+# Use Unicorn as the app server
+# gem 'unicorn'
+
+# Use Capistrano for deployment
+# gem 'capistrano-rails', group: :development
+
+group :development, :test do
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
+ gem 'byebug'
+ gem 'rspec-rails', '~> 4.1.0'
+ gem 'pry-byebug'
+end
+
+group :development do
+ gem 'web-console', '~> 2.0'
+ gem 'spring'
+end
+
+group :test do
+ gem 'capybara'
+end
diff --git a/source/Gemfile.lock b/source/Gemfile.lock
new file mode 100644
index 000000000..57d0bb517
--- /dev/null
+++ b/source/Gemfile.lock
@@ -0,0 +1,213 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (4.2.11.3)
+ actionpack (= 4.2.11.3)
+ actionview (= 4.2.11.3)
+ activejob (= 4.2.11.3)
+ mail (~> 2.5, >= 2.5.4)
+ rails-dom-testing (~> 1.0, >= 1.0.5)
+ actionpack (4.2.11.3)
+ actionview (= 4.2.11.3)
+ activesupport (= 4.2.11.3)
+ rack (~> 1.6)
+ rack-test (~> 0.6.2)
+ rails-dom-testing (~> 1.0, >= 1.0.5)
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
+ actionview (4.2.11.3)
+ activesupport (= 4.2.11.3)
+ builder (~> 3.1)
+ erubis (~> 2.7.0)
+ rails-dom-testing (~> 1.0, >= 1.0.5)
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
+ activejob (4.2.11.3)
+ activesupport (= 4.2.11.3)
+ globalid (>= 0.3.0)
+ activemodel (4.2.11.3)
+ activesupport (= 4.2.11.3)
+ builder (~> 3.1)
+ activerecord (4.2.11.3)
+ activemodel (= 4.2.11.3)
+ activesupport (= 4.2.11.3)
+ arel (~> 6.0)
+ activesupport (4.2.11.3)
+ i18n (~> 0.7)
+ minitest (~> 5.1)
+ thread_safe (~> 0.3, >= 0.3.4)
+ tzinfo (~> 1.1)
+ addressable (2.7.0)
+ public_suffix (>= 2.0.2, < 5.0)
+ arel (6.0.4)
+ binding_of_caller (1.0.0)
+ debug_inspector (>= 0.0.1)
+ builder (3.2.4)
+ byebug (11.0.1)
+ capybara (3.15.1)
+ addressable
+ mini_mime (>= 0.1.3)
+ nokogiri (~> 1.8)
+ rack (>= 1.6.0)
+ rack-test (>= 0.6.3)
+ regexp_parser (~> 1.2)
+ xpath (~> 3.2)
+ coderay (1.1.3)
+ coffee-rails (4.1.1)
+ coffee-script (>= 2.2.0)
+ railties (>= 4.0.0, < 5.1.x)
+ coffee-script (2.4.1)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.12.2)
+ concurrent-ruby (1.1.8)
+ crass (1.0.6)
+ debug_inspector (1.1.0)
+ diff-lcs (1.4.4)
+ erubis (2.7.0)
+ execjs (2.7.0)
+ ffi (1.15.0)
+ globalid (0.4.2)
+ activesupport (>= 4.2.0)
+ i18n (0.9.5)
+ concurrent-ruby (~> 1.0)
+ jbuilder (2.9.1)
+ activesupport (>= 4.2.0)
+ jquery-rails (4.4.0)
+ rails-dom-testing (>= 1, < 3)
+ railties (>= 4.2.0)
+ thor (>= 0.14, < 2.0)
+ json (1.8.6)
+ loofah (2.9.1)
+ crass (~> 1.0.2)
+ nokogiri (>= 1.5.9)
+ mail (2.7.1)
+ mini_mime (>= 0.1.1)
+ method_source (1.0.0)
+ mini_mime (1.1.0)
+ mini_portile2 (2.4.0)
+ minitest (5.14.4)
+ nokogiri (1.10.10)
+ mini_portile2 (~> 2.4.0)
+ pg (0.21.0)
+ pry (0.14.1)
+ coderay (~> 1.1)
+ method_source (~> 1.0)
+ pry-byebug (3.7.0)
+ byebug (~> 11.0)
+ pry (~> 0.10)
+ public_suffix (4.0.6)
+ rack (1.6.13)
+ rack-test (0.6.3)
+ rack (>= 1.0)
+ rails (4.2.11.3)
+ actionmailer (= 4.2.11.3)
+ actionpack (= 4.2.11.3)
+ actionview (= 4.2.11.3)
+ activejob (= 4.2.11.3)
+ activemodel (= 4.2.11.3)
+ activerecord (= 4.2.11.3)
+ activesupport (= 4.2.11.3)
+ bundler (>= 1.3.0, < 2.0)
+ railties (= 4.2.11.3)
+ sprockets-rails
+ rails-deprecated_sanitizer (1.0.4)
+ activesupport (>= 4.2.0.alpha)
+ rails-dom-testing (1.0.9)
+ activesupport (>= 4.2.0, < 5.0)
+ nokogiri (~> 1.6)
+ rails-deprecated_sanitizer (>= 1.0.1)
+ rails-html-sanitizer (1.3.0)
+ loofah (~> 2.3)
+ railties (4.2.11.3)
+ actionpack (= 4.2.11.3)
+ activesupport (= 4.2.11.3)
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+ rake (13.0.3)
+ rb-fsevent (0.10.4)
+ rb-inotify (0.10.1)
+ ffi (~> 1.0)
+ rdoc (4.3.0)
+ regexp_parser (1.8.2)
+ rspec-core (3.10.1)
+ rspec-support (~> 3.10.0)
+ rspec-expectations (3.10.1)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.10.0)
+ rspec-mocks (3.10.2)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.10.0)
+ rspec-rails (4.1.2)
+ actionpack (>= 4.2)
+ activesupport (>= 4.2)
+ railties (>= 4.2)
+ rspec-core (~> 3.10)
+ rspec-expectations (~> 3.10)
+ rspec-mocks (~> 3.10)
+ rspec-support (~> 3.10)
+ rspec-support (3.10.2)
+ sass (3.7.4)
+ sass-listen (~> 4.0.0)
+ sass-listen (4.0.0)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ sass-rails (5.0.7)
+ railties (>= 4.0.0, < 6)
+ sass (~> 3.1)
+ sprockets (>= 2.8, < 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ tilt (>= 1.1, < 3)
+ sdoc (0.4.2)
+ json (~> 1.7, >= 1.7.7)
+ rdoc (~> 4.0)
+ spring (2.0.2)
+ activesupport (>= 4.2)
+ sprockets (3.7.2)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-rails (3.2.2)
+ actionpack (>= 4.0)
+ activesupport (>= 4.0)
+ sprockets (>= 3.0.0)
+ thor (1.1.0)
+ thread_safe (0.3.6)
+ tilt (2.0.10)
+ turbolinks (5.2.1)
+ turbolinks-source (~> 5.2)
+ turbolinks-source (5.2.0)
+ tzinfo (1.2.9)
+ thread_safe (~> 0.1)
+ uglifier (4.2.0)
+ execjs (>= 0.3.0, < 3)
+ web-console (2.3.0)
+ activemodel (>= 4.0)
+ binding_of_caller (>= 0.7.2)
+ railties (>= 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ xpath (3.2.0)
+ nokogiri (~> 1.8)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ byebug
+ capybara
+ coffee-rails (~> 4.1.0)
+ jbuilder (~> 2.0)
+ jquery-rails
+ pg (~> 0.15)
+ pry-byebug
+ rails (= 4.2.11.3)
+ rspec-rails (~> 4.1.0)
+ sass-rails (~> 5.0)
+ sdoc (~> 0.4.0)
+ spring
+ turbolinks
+ uglifier (>= 1.3.0)
+ web-console (~> 2.0)
+
+RUBY VERSION
+ ruby 2.3.8p459
+
+BUNDLED WITH
+ 1.17.3
diff --git a/source/README.rdoc b/source/README.rdoc
new file mode 100644
index 000000000..dd4e97e22
--- /dev/null
+++ b/source/README.rdoc
@@ -0,0 +1,28 @@
+== README
+
+This README would normally document whatever steps are necessary to get the
+application up and running.
+
+Things you may want to cover:
+
+* Ruby version
+
+* System dependencies
+
+* Configuration
+
+* Database creation
+
+* Database initialization
+
+* How to run the test suite
+
+* Services (job queues, cache servers, search engines, etc.)
+
+* Deployment instructions
+
+* ...
+
+
+Please feel free to use a different markup language if you do not plan to run
+rake doc:app.
diff --git a/source/Rakefile b/source/Rakefile
new file mode 100644
index 000000000..ba6b733dd
--- /dev/null
+++ b/source/Rakefile
@@ -0,0 +1,6 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Rails.application.load_tasks
diff --git a/source/app/assets/images/.keep b/source/app/assets/images/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/app/assets/javascripts/application.js b/source/app/assets/javascripts/application.js
new file mode 100644
index 000000000..e07c5a830
--- /dev/null
+++ b/source/app/assets/javascripts/application.js
@@ -0,0 +1,16 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file.
+//
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+//= require jquery
+//= require jquery_ujs
+//= require turbolinks
+//= require_tree .
diff --git a/source/app/assets/stylesheets/application.css b/source/app/assets/stylesheets/application.css
new file mode 100644
index 000000000..f9cd5b348
--- /dev/null
+++ b/source/app/assets/stylesheets/application.css
@@ -0,0 +1,15 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
+ * compiled file so the styles you add here take precedence over styles defined in any styles
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
+ * file per style scope.
+ *
+ *= require_tree .
+ *= require_self
+ */
diff --git a/source/app/assets/stylesheets/charges.scss b/source/app/assets/stylesheets/charges.scss
new file mode 100644
index 000000000..1f489ce16
--- /dev/null
+++ b/source/app/assets/stylesheets/charges.scss
@@ -0,0 +1,11 @@
+li.failed-charge {
+ background-color: #ff0000;
+}
+
+li.disputed-charge {
+ background-color: #ff5400;
+}
+
+li.successful-charge {
+
+}
diff --git a/source/app/controllers/application_controller.rb b/source/app/controllers/application_controller.rb
new file mode 100644
index 000000000..d83690e1b
--- /dev/null
+++ b/source/app/controllers/application_controller.rb
@@ -0,0 +1,5 @@
+class ApplicationController < ActionController::Base
+ # Prevent CSRF attacks by raising an exception.
+ # For APIs, you may want to use :null_session instead.
+ protect_from_forgery with: :exception
+end
diff --git a/source/app/controllers/charges_controller.rb b/source/app/controllers/charges_controller.rb
new file mode 100644
index 000000000..fa7c546bf
--- /dev/null
+++ b/source/app/controllers/charges_controller.rb
@@ -0,0 +1,5 @@
+class ChargesController < ApplicationController
+ def index
+ @charges = Charge.includes(:customer).all
+ end
+end
diff --git a/source/app/controllers/concerns/.keep b/source/app/controllers/concerns/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/app/helpers/application_helper.rb b/source/app/helpers/application_helper.rb
new file mode 100644
index 000000000..de6be7945
--- /dev/null
+++ b/source/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff --git a/source/app/mailers/.keep b/source/app/mailers/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/app/models/.keep b/source/app/models/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/app/models/charge.rb b/source/app/models/charge.rb
new file mode 100644
index 000000000..a2b9722d8
--- /dev/null
+++ b/source/app/models/charge.rb
@@ -0,0 +1,27 @@
+class Charge < ActiveRecord::Base
+ belongs_to :customer
+
+ def self.new_random_payment(attributes)
+ new(attributes.merge(amount: rand(1000_00) + 1, currency: %w(usd eur rub chf gbp).sample))
+ end
+
+ def refund!
+ update!(refunded: true)
+ end
+
+ def successful?
+ paid and not refunded
+ end
+
+ def disputed?
+ paid and refunded
+ end
+
+ def failed?
+ not paid
+ end
+
+ def to_s
+ "#{'%.2f' % (amount / 100.0)} #{currency.upcase} --- #{updated_at.strftime("%Y, %B %d")}"
+ end
+end
diff --git a/source/app/models/concerns/.keep b/source/app/models/concerns/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/app/models/customer.rb b/source/app/models/customer.rb
new file mode 100644
index 000000000..64d6dbe86
--- /dev/null
+++ b/source/app/models/customer.rb
@@ -0,0 +1,7 @@
+class Customer < ActiveRecord::Base
+ has_many :charges
+
+ def name
+ [first_name, last_name].compact.join(" ")
+ end
+end
diff --git a/source/app/views/charges/index.html.erb b/source/app/views/charges/index.html.erb
new file mode 100644
index 000000000..67a1c0289
--- /dev/null
+++ b/source/app/views/charges/index.html.erb
@@ -0,0 +1,32 @@
+
+
Failed Charges
+
+ <% @charges.select(&:failed?).each do |charge| %>
+ -
+ <%= "#{charge.customer.name} --- #{charge}" %>
+
+ <% end %>
+
+
+
+
+
Disputed Charges
+
+ <% @charges.select(&:disputed?).each do |charge| %>
+ -
+ <%= "#{charge.customer.name} --- #{charge}" %>
+
+ <% end %>
+
+
+
+
+
Successful Charges
+
+ <% @charges.select(&:successful?).each do |charge| %>
+ -
+ <%= "#{charge.customer.name} --- #{charge}" %>
+
+ <% end %>
+
+
diff --git a/source/app/views/layouts/application.html.erb b/source/app/views/layouts/application.html.erb
new file mode 100644
index 000000000..caec00bfc
--- /dev/null
+++ b/source/app/views/layouts/application.html.erb
@@ -0,0 +1,14 @@
+
+
+
+ Charging
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
+ <%= csrf_meta_tags %>
+
+
+
+<%= yield %>
+
+
+
diff --git a/source/bin/bundle b/source/bin/bundle
new file mode 100755
index 000000000..66e9889e8
--- /dev/null
+++ b/source/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/source/bin/rails b/source/bin/rails
new file mode 100755
index 000000000..5191e6927
--- /dev/null
+++ b/source/bin/rails
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/source/bin/rake b/source/bin/rake
new file mode 100755
index 000000000..17240489f
--- /dev/null
+++ b/source/bin/rake
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/source/bin/setup b/source/bin/setup
new file mode 100755
index 000000000..acdb2c138
--- /dev/null
+++ b/source/bin/setup
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+Dir.chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file:
+
+ puts "== Installing dependencies =="
+ system "gem install bundler --conservative"
+ system "bundle check || bundle install"
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?("config/database.yml")
+ # system "cp config/database.yml.sample config/database.yml"
+ # end
+
+ puts "\n== Preparing database =="
+ system "bin/rake db:setup"
+
+ puts "\n== Removing old logs and tempfiles =="
+ system "rm -f log/*"
+ system "rm -rf tmp/cache"
+
+ puts "\n== Restarting application server =="
+ system "touch tmp/restart.txt"
+end
diff --git a/source/config.ru b/source/config.ru
new file mode 100644
index 000000000..bd83b2541
--- /dev/null
+++ b/source/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Rails.application
diff --git a/source/config/application.rb b/source/config/application.rb
new file mode 100644
index 000000000..d56296bc4
--- /dev/null
+++ b/source/config/application.rb
@@ -0,0 +1,35 @@
+require File.expand_path('../boot', __FILE__)
+
+require "rails"
+# Pick the frameworks you want:
+require "active_model/railtie"
+require "active_job/railtie"
+require "active_record/railtie"
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "action_view/railtie"
+require "sprockets/railtie"
+# require "rails/test_unit/railtie"
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module Charging
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Do not swallow errors in after_commit/after_rollback callbacks.
+ config.active_record.raise_in_transactional_callbacks = true
+ end
+end
diff --git a/source/config/boot.rb b/source/config/boot.rb
new file mode 100644
index 000000000..6b750f00b
--- /dev/null
+++ b/source/config/boot.rb
@@ -0,0 +1,3 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/source/config/database.yml b/source/config/database.yml
new file mode 100644
index 000000000..7491d2fed
--- /dev/null
+++ b/source/config/database.yml
@@ -0,0 +1,86 @@
+# PostgreSQL. Versions 8.2 and up are supported.
+#
+# Install the pg driver:
+# gem install pg
+# On OS X with Homebrew:
+# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
+# On OS X with MacPorts:
+# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
+# On Windows:
+# gem install pg
+# Choose the win32 build.
+# Install PostgreSQL and put its /bin directory on your path.
+#
+# Configure Using Gemfile
+# gem 'pg'
+#
+default: &default
+ adapter: postgresql
+ encoding: unicode
+ host: <%= ENV.fetch("DATABASE_HOST") %>
+ port: 5432
+ username: <%= ENV.fetch("POSTGRES_USER") %>
+ password: <%= ENV.fetch("POSTGRES_PASSWORD") %>
+
+development:
+ <<: *default
+ database: charging_development
+
+ # The specified database role being used to connect to postgres.
+ # To create additional roles in postgres see `$ createuser --help`.
+ # When left blank, postgres will use the default role. This is
+ # the same name as the operating system user that initialized the database.
+ #username: charging
+
+ # The password associated with the postgres role (username).
+ #password:
+
+ # Connect on a TCP socket. Omitted by default since the client uses a
+ # domain socket that doesn't need configuration. Windows does not have
+ # domain sockets, so uncomment these lines.
+ #host: localhost
+
+ # The TCP port the server listens on. Defaults to 5432.
+ # If your server runs on a different port number, change accordingly.
+ #port: 5432
+
+ # Schema search path. The server defaults to $user,public
+ #schema_search_path: myapp,sharedapp,public
+
+ # Minimum log levels, in increasing order:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, notice, warning, error, fatal, and panic
+ # Defaults to warning.
+ #min_messages: notice
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: charging_test
+
+# As with config/secrets.yml, you never want to store sensitive information,
+# like your database password, in your source code. If your source code is
+# ever seen by anyone, they now have access to your database.
+#
+# Instead, provide the password as a unix environment variable when you boot
+# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
+# for a full rundown on how to provide these environment variables in a
+# production deployment.
+#
+# On Heroku and other platform providers, you may have a full connection URL
+# available as an environment variable. For example:
+#
+# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
+#
+# You can use this database configuration with:
+#
+# production:
+# url: <%= ENV['DATABASE_URL'] %>
+#
+production:
+ <<: *default
+ database: charging_production
+ username: charging
+ password: <%= ENV['CHARGING_DATABASE_PASSWORD'] %>
diff --git a/source/config/environment.rb b/source/config/environment.rb
new file mode 100644
index 000000000..ee8d90dc6
--- /dev/null
+++ b/source/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require File.expand_path('../application', __FILE__)
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/source/config/environments/development.rb b/source/config/environments/development.rb
new file mode 100644
index 000000000..b55e2144b
--- /dev/null
+++ b/source/config/environments/development.rb
@@ -0,0 +1,41 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
+ # yet still be able to expire them through the digest params.
+ config.assets.digest = true
+
+ # Adds additional error checking when serving assets at runtime.
+ # Checks for improperly declared sprockets dependencies.
+ # Raises helpful error messages.
+ config.assets.raise_runtime_errors = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/source/config/environments/production.rb b/source/config/environments/production.rb
new file mode 100644
index 000000000..5c1b32e48
--- /dev/null
+++ b/source/config/environments/production.rb
@@ -0,0 +1,79 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
+ # Add `rack-cache` to your Gemfile before enabling this.
+ # For large-scale production use, consider using a caching reverse proxy like
+ # NGINX, varnish or squid.
+ # config.action_dispatch.rack_cache = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
+ # yet still be able to expire them through the digest params.
+ config.assets.digest = true
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ # config.log_tags = [ :subdomain, :uuid ]
+
+ # Use a different logger for distributed setups.
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/source/config/environments/test.rb b/source/config/environments/test.rb
new file mode 100644
index 000000000..1c19f08b2
--- /dev/null
+++ b/source/config/environments/test.rb
@@ -0,0 +1,42 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure static file server for tests with Cache-Control for performance.
+ config.serve_static_files = true
+ config.static_cache_control = 'public, max-age=3600'
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Randomize the order test cases are executed.
+ config.active_support.test_order = :random
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/source/config/initializers/assets.rb b/source/config/initializers/assets.rb
new file mode 100644
index 000000000..01ef3e663
--- /dev/null
+++ b/source/config/initializers/assets.rb
@@ -0,0 +1,11 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path
+# Rails.application.config.assets.paths << Emoji.images_path
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
+# Rails.application.config.assets.precompile += %w( search.js )
diff --git a/source/config/initializers/backtrace_silencers.rb b/source/config/initializers/backtrace_silencers.rb
new file mode 100644
index 000000000..59385cdf3
--- /dev/null
+++ b/source/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/source/config/initializers/cookies_serializer.rb b/source/config/initializers/cookies_serializer.rb
new file mode 100644
index 000000000..7f70458de
--- /dev/null
+++ b/source/config/initializers/cookies_serializer.rb
@@ -0,0 +1,3 @@
+# Be sure to restart your server when you modify this file.
+
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/source/config/initializers/filter_parameter_logging.rb b/source/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 000000000..4a994e1e7
--- /dev/null
+++ b/source/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/source/config/initializers/inflections.rb b/source/config/initializers/inflections.rb
new file mode 100644
index 000000000..ac033bf9d
--- /dev/null
+++ b/source/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/source/config/initializers/mime_types.rb b/source/config/initializers/mime_types.rb
new file mode 100644
index 000000000..dc1899682
--- /dev/null
+++ b/source/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/source/config/initializers/session_store.rb b/source/config/initializers/session_store.rb
new file mode 100644
index 000000000..05ea030b6
--- /dev/null
+++ b/source/config/initializers/session_store.rb
@@ -0,0 +1,3 @@
+# Be sure to restart your server when you modify this file.
+
+Rails.application.config.session_store :cookie_store, key: '_charging_session'
diff --git a/source/config/initializers/to_time_preserves_timezone.rb b/source/config/initializers/to_time_preserves_timezone.rb
new file mode 100644
index 000000000..8674be322
--- /dev/null
+++ b/source/config/initializers/to_time_preserves_timezone.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Preserve the timezone of the receiver when calling to `to_time`.
+# Ruby 2.4 will change the behavior of `to_time` to preserve the timezone
+# when converting to an instance of `Time` instead of the previous behavior
+# of converting to the local system timezone.
+#
+# Rails 5.0 introduced this config option so that apps made with earlier
+# versions of Rails are not affected when upgrading.
+ActiveSupport.to_time_preserves_timezone = true
diff --git a/source/config/initializers/wrap_parameters.rb b/source/config/initializers/wrap_parameters.rb
new file mode 100644
index 000000000..33725e95f
--- /dev/null
+++ b/source/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/source/config/locales/en.yml b/source/config/locales/en.yml
new file mode 100644
index 000000000..065395716
--- /dev/null
+++ b/source/config/locales/en.yml
@@ -0,0 +1,23 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/source/config/routes.rb b/source/config/routes.rb
new file mode 100644
index 000000000..705c39eaf
--- /dev/null
+++ b/source/config/routes.rb
@@ -0,0 +1,5 @@
+Rails.application.routes.draw do
+ resources :charges, only: :index
+
+ root to: 'charges#index'
+end
diff --git a/source/config/secrets.yml b/source/config/secrets.yml
new file mode 100644
index 000000000..1e66d08da
--- /dev/null
+++ b/source/config/secrets.yml
@@ -0,0 +1,22 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key is used for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+# You can use `rake secret` to generate a secure secret key.
+
+# Make sure the secrets in this file are kept private
+# if you're sharing your code publicly.
+
+development:
+ secret_key_base: 75b497000917d46e46ed0cb413e99ece4b7f8774552cffa1e49180e0d65a34c1d02cf5747cec7a3fbdedb96d6d724e6b222f1551bfc9680bd1860fa8740593ed
+
+test:
+ secret_key_base: 7afefe3ed4e66fa99504ab40454e4a01ba2aec7f8f5a5a8d2588e8b22a9d4575bc963440da9b4a6217683d341256c1b177758e6ffe1421743681ea2ce8953a45
+
+# Do not keep production secrets in the repository,
+# instead read values from the environment.
+production:
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
diff --git a/source/db/migrate/20210420185100_create_customers.rb b/source/db/migrate/20210420185100_create_customers.rb
new file mode 100644
index 000000000..4a0ac76c1
--- /dev/null
+++ b/source/db/migrate/20210420185100_create_customers.rb
@@ -0,0 +1,10 @@
+class CreateCustomers < ActiveRecord::Migration
+ def change
+ create_table :customers do |t|
+ t.string :first_name
+ t.string :last_name
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/source/db/migrate/20210420185501_create_charges.rb b/source/db/migrate/20210420185501_create_charges.rb
new file mode 100644
index 000000000..34b327082
--- /dev/null
+++ b/source/db/migrate/20210420185501_create_charges.rb
@@ -0,0 +1,14 @@
+class CreateCharges < ActiveRecord::Migration
+ def change
+ create_table :charges do |t|
+ t.integer :created, null: false
+ t.boolean :paid, default: false
+ t.integer :amount, null: false
+ t.string :currency, null: false, default: "usd"
+ t.boolean :refunded, default: false
+ t.references :customer, index: true, foreign_key: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/source/db/migrate/20210420194906_remove_created_from_charge.rb b/source/db/migrate/20210420194906_remove_created_from_charge.rb
new file mode 100644
index 000000000..911847ae6
--- /dev/null
+++ b/source/db/migrate/20210420194906_remove_created_from_charge.rb
@@ -0,0 +1,5 @@
+class RemoveCreatedFromCharge < ActiveRecord::Migration
+ def change
+ remove_column :charges, :created, :integer
+ end
+end
diff --git a/source/db/schema.rb b/source/db/schema.rb
new file mode 100644
index 000000000..f1f7f20c1
--- /dev/null
+++ b/source/db/schema.rb
@@ -0,0 +1,39 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20210420194906) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "charges", force: :cascade do |t|
+ t.boolean "paid", default: false
+ t.integer "amount", null: false
+ t.string "currency", default: "usd", null: false
+ t.boolean "refunded", default: false
+ t.integer "customer_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "charges", ["customer_id"], name: "index_charges_on_customer_id", using: :btree
+
+ create_table "customers", force: :cascade do |t|
+ t.string "first_name"
+ t.string "last_name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_foreign_key "charges", "customers"
+end
diff --git a/source/db/seeds.rb b/source/db/seeds.rb
new file mode 100644
index 000000000..65173c643
--- /dev/null
+++ b/source/db/seeds.rb
@@ -0,0 +1,30 @@
+# Seed the customers
+customers =
+ [%w(Johny Flow), %w(Raj Jamnis), %w(Andrew Chung), %w(Mike Smith)].map do |name, sirname|
+ Customer.find_or_create_by(first_name: name, last_name: sirname)
+ end
+
+# Successful transactions
+[5, 3, 1, 1].each_with_index do |transactions_number, customer_id|
+ transactions_number.times do
+ charge = Charge.new_random_payment(paid: true, customer: customers[customer_id])
+ charge.save!
+ end
+end
+
+# Failed transactions
+[0, 0, 3, 2].each_with_index do |transactions_number, customer_id|
+ transactions_number.times do
+ charge = Charge.new_random_payment(paid: false, customer: customers[customer_id])
+ charge.save!
+ end
+end
+
+# Disputed transactions - as i understood it's paid, but refunded charges
+[3, 2].each_with_index do |transactions_number, customer_id|
+ transactions_number.times do
+ charge = Charge.new_random_payment(paid: true, customer: customers[customer_id])
+ charge.save!
+ charge.refund!
+ end
+end
diff --git a/source/lib/assets/.keep b/source/lib/assets/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/lib/tasks/.keep b/source/lib/tasks/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/log/.keep b/source/log/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/public/404.html b/source/public/404.html
new file mode 100644
index 000000000..b612547fc
--- /dev/null
+++ b/source/public/404.html
@@ -0,0 +1,67 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/source/public/422.html b/source/public/422.html
new file mode 100644
index 000000000..a21f82b3b
--- /dev/null
+++ b/source/public/422.html
@@ -0,0 +1,67 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/source/public/500.html b/source/public/500.html
new file mode 100644
index 000000000..061abc587
--- /dev/null
+++ b/source/public/500.html
@@ -0,0 +1,66 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/source/public/favicon.ico b/source/public/favicon.ico
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/public/robots.txt b/source/public/robots.txt
new file mode 100644
index 000000000..3c9c7c01f
--- /dev/null
+++ b/source/public/robots.txt
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-agent: *
+# Disallow: /
diff --git a/source/spec/features/charges_lists_spec.rb b/source/spec/features/charges_lists_spec.rb
new file mode 100644
index 000000000..a87554a62
--- /dev/null
+++ b/source/spec/features/charges_lists_spec.rb
@@ -0,0 +1,29 @@
+require 'rails_helper'
+
+RSpec.feature "Charges Lists page" do
+ before do
+ Rails.application.load_seed
+ visit "/charges"
+ end
+
+ it "contains 3 lists on the screen", :aggregate_failures do
+ expect(page).to have_xpath("//h1[text()='Successful Charges']/following-sibling::ul")
+ expect(page).to have_xpath("//h1[text()='Failed Charges']/following-sibling::ul")
+ expect(page).to have_xpath("//h1[text()='Disputed Charges']/following-sibling::ul")
+ end
+
+ it 'contains 10 lines of successful charges' do
+ line_items = page.all(:xpath, "//h1[text()='Successful Charges']/following-sibling::ul/li")
+ expect(line_items.size).to eq(10)
+ end
+
+ it 'contains 5 lines of failed charges' do
+ line_items = page.all(:xpath, "//h1[text()='Failed Charges']/following-sibling::ul/li")
+ expect(line_items.size).to eq(5)
+ end
+
+ it 'contains 5 lines of disputed charges' do
+ line_items = page.all(:xpath, "//h1[text()='Disputed Charges']/following-sibling::ul/li")
+ expect(line_items.size).to eq(5)
+ end
+end
diff --git a/source/spec/rails_helper.rb b/source/spec/rails_helper.rb
new file mode 100644
index 000000000..00345af7c
--- /dev/null
+++ b/source/spec/rails_helper.rb
@@ -0,0 +1,64 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+require 'spec_helper'
+ENV['RAILS_ENV'] ||= 'test'
+require File.expand_path('../config/environment', __dir__)
+# Prevent database truncation if the environment is production
+abort("The Rails environment is running in production mode!") if Rails.env.production?
+require 'rspec/rails'
+# Add additional requires below this line. Rails is not loaded until this point!
+
+# Requires supporting ruby files with custom matchers and macros, etc, in
+# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
+# run as spec files by default. This means that files in spec/support that end
+# in _spec.rb will both be required and run as specs, causing the specs to be
+# run twice. It is recommended that you do not name files matching this glob to
+# end with _spec.rb. You can configure this pattern with the --pattern
+# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
+#
+# The following line is provided for convenience purposes. It has the downside
+# of increasing the boot-up time by auto-requiring all files in the support
+# directory. Alternatively, in the individual `*_spec.rb` files, manually
+# require only the support files necessary.
+#
+# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
+
+# Checks for pending migrations and applies them before tests are run.
+# If you are not using ActiveRecord, you can remove these lines.
+begin
+ ActiveRecord::Migration.maintain_test_schema!
+rescue ActiveRecord::PendingMigrationError => e
+ puts e.to_s.strip
+ exit 1
+end
+RSpec.configure do |config|
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # You can uncomment this line to turn off ActiveRecord support entirely.
+ # config.use_active_record = false
+
+ # RSpec Rails can automatically mix in different behaviours to your tests
+ # based on their file location, for example enabling you to call `get` and
+ # `post` in specs under `spec/controllers`.
+ #
+ # You can disable this behaviour by removing the line below, and instead
+ # explicitly tag your specs with their type, e.g.:
+ #
+ # RSpec.describe UsersController, type: :controller do
+ # # ...
+ # end
+ #
+ # The different available types are documented in the features, such as in
+ # https://relishapp.com/rspec/rspec-rails/docs
+ config.infer_spec_type_from_file_location!
+
+ # Filter lines from Rails gems in backtraces.
+ config.filter_rails_from_backtrace!
+ # arbitrary gems may also be filtered via:
+ # config.filter_gems_from_backtrace("gem name")
+end
diff --git a/source/spec/spec_helper.rb b/source/spec/spec_helper.rb
new file mode 100644
index 000000000..ce33d66df
--- /dev/null
+++ b/source/spec/spec_helper.rb
@@ -0,0 +1,96 @@
+# This file was generated by the `rails generate rspec:install` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# The generated `.rspec` file contains `--require spec_helper` which will cause
+# this file to always be loaded, without a need to explicitly require it in any
+# files.
+#
+# Given that it is always loaded, you are encouraged to keep this file as
+# light-weight as possible. Requiring heavyweight dependencies from this file
+# will add to the boot time of your test suite on EVERY test run, even for an
+# individual file that may not need all of that loaded. Instead, consider making
+# a separate helper file that requires the additional dependencies and performs
+# the additional setup, and require it from the spec files that actually need
+# it.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ # rspec-expectations config goes here. You can use an alternate
+ # assertion/expectation library such as wrong or the stdlib/minitest
+ # assertions if you prefer.
+ config.expect_with :rspec do |expectations|
+ # This option will default to `true` in RSpec 4. It makes the `description`
+ # and `failure_message` of custom matchers include text for helper methods
+ # defined using `chain`, e.g.:
+ # be_bigger_than(2).and_smaller_than(4).description
+ # # => "be bigger than 2 and smaller than 4"
+ # ...rather than:
+ # # => "be bigger than 2"
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ # rspec-mocks config goes here. You can use an alternate test double
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
+ config.mock_with :rspec do |mocks|
+ # Prevents you from mocking or stubbing a method that does not exist on
+ # a real object. This is generally recommended, and will default to
+ # `true` in RSpec 4.
+ mocks.verify_partial_doubles = true
+ end
+
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
+ # have no way to turn it off -- the option exists only for backwards
+ # compatibility in RSpec 3). It causes shared context metadata to be
+ # inherited by the metadata hash of host groups and examples, rather than
+ # triggering implicit auto-inclusion in groups with matching metadata.
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+
+# The settings below are suggested to provide a good initial experience
+# with RSpec, but feel free to customize to your heart's content.
+=begin
+ # This allows you to limit a spec run to individual examples or groups
+ # you care about by tagging them with `:focus` metadata. When nothing
+ # is tagged with `:focus`, all examples get run. RSpec also provides
+ # aliases for `it`, `describe`, and `context` that include `:focus`
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
+ config.filter_run_when_matching :focus
+
+ # Allows RSpec to persist some state between runs in order to support
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
+ # you configure your source control system to ignore this file.
+ config.example_status_persistence_file_path = "spec/examples.txt"
+
+ # Limits the available syntax to the non-monkey patched syntax that is
+ # recommended. For more details, see:
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
+ config.disable_monkey_patching!
+
+ # Many RSpec users commonly either run the entire suite or an individual
+ # file, and it's useful to allow more verbose output when running an
+ # individual spec file.
+ if config.files_to_run.one?
+ # Use the documentation formatter for detailed output,
+ # unless a formatter has already been configured
+ # (e.g. via a command-line flag).
+ config.default_formatter = "doc"
+ end
+
+ # Print the 10 slowest examples and example groups at the
+ # end of the spec run, to help surface which specs are running
+ # particularly slow.
+ config.profile_examples = 10
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = :random
+
+ # Seed global randomization in this process using the `--seed` CLI option.
+ # Setting this allows you to use `--seed` to deterministically reproduce
+ # test failures related to randomization by passing the same `--seed` value
+ # as the one that triggered the failure.
+ Kernel.srand config.seed
+=end
+end
diff --git a/source/vendor/assets/javascripts/.keep b/source/vendor/assets/javascripts/.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/source/vendor/assets/stylesheets/.keep b/source/vendor/assets/stylesheets/.keep
new file mode 100644
index 000000000..e69de29bb