diff --git a/Makefile b/Makefile new file mode 100755 index 000000000..a38a46b0b --- /dev/null +++ b/Makefile @@ -0,0 +1,84 @@ +SHELL:=/bin/bash + +wipe-all: down wipe-volumes wipe-images wipe-containers + +wipe-volumes: + @$$(cd gt-app/tmp && ls -A | grep -v '\.keep' | xargs sudo rm -rf) + @if [[ -n "$$(docker volume ls -qf dangling=true)" ]]; then\ + docker volume rm -f $$(docker volume ls -qf dangling=true);\ + fi + @docker volume ls -qf dangling=true | xargs -r docker volume rm + +wipe-images: + @if [[ -n "$$(docker images --filter "dangling=true" -q --no-trunc)" ]]; then\ + docker rmi -f $$(docker images --filter "dangling=true" -q --no-trunc);\ + fi + @if [[ -n "$$(docker images | grep "none" | awk '/ / { print $3 }')" ]]; then\ + docker rmi -f $$(docker images | grep "none" | awk '/ / { print $3 }');\ + fi + +wipe-containers: + @if [[ -n "$$(docker ps -qa --no-trunc --filter "status=exited")" ]]; then\ + docker rm -f $$(docker ps -qa --no-trunc --filter "status=exited");\ + fi + +wipe-postgres-redis-data: + @sudo rm -rf tmp + +down: + @docker-compose down + @docker-compose kill + +install-docker: + @echo "Installing Docker" + + @sudo apt-get update + + @sudo apt-get install \ + apt-transport-https \ + ca-certificates \ + curl \ + software-properties-common -y + + @curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + + @sudo add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ + $$(lsb_release -cs) \ + stable" + + @sudo apt-get update + + @sudo apt-get install docker-ce + + @sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) \ + -o /usr/local/bin/docker-compose + + @sudo chmod +x /usr/local/bin/docker-compose + @sleep 5 + @echo "Docker Installed successfully" + +install-docker-if-not-already-installed: + @if [ -z "$$(which docker)" ]; then\ + make install-docker;\ + fi + +build-all-docker-images: + @echo "Building docker images." + @echo "Grab a coffe and wait." + @docker-compose build + @echo "Docker images built" + +pull: + @git pull origin $$(git branch | grep \* | cut -d ' ' -f2) --rebase + +push: + @git push origin $$(git branch | grep \* | cut -d ' ' -f2) --force-with-lease + +up: + @docker-compose up -d + +set-up: install-docker-if-not-already-installed down build-all-docker-images + +reset: wipe-all set-up + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 000000000..7534d5500 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.7' + +services: + web: + stdin_open: true + tty: true + build: + context: ./source + target: rails_app + volumes: + - ./source:/home/rails/myapp + ports: + - "3000:3000" + diff --git a/source/.gitignore b/source/.gitignore new file mode 100644 index 000000000..050c9d95c --- /dev/null +++ b/source/.gitignore @@ -0,0 +1,17 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +!/log/.keep +/tmp diff --git a/source/.rubocop-excludes.yml b/source/.rubocop-excludes.yml new file mode 100644 index 000000000..cbb10298a --- /dev/null +++ b/source/.rubocop-excludes.yml @@ -0,0 +1,26 @@ +AllCops: + Exclude: + # Rubocop defaults + - Gemfile + - vendor/**/* + - tmp/**/* + # Framework generated configuration files + - config/boot.rb + - config/application.rb + - config/environment.rb + - config/environments/* + - config/initializers/* + - bin/**/* + - script/**/* + - db/schema.rb + - Rakefile + # rspec generated files + - spec/spec_helper.rb + - spec/rails_helper.rb +# auto genrate scafold files + - spec/controllers/* + - spec/routing/* + - spec/requests/* + - spec/views/**/* + - app/controllers/* + - app/views/**/* \ No newline at end of file diff --git a/source/.rubocop.yml b/source/.rubocop.yml new file mode 100644 index 000000000..e77891306 --- /dev/null +++ b/source/.rubocop.yml @@ -0,0 +1,61 @@ +AllCops: + TargetRubyVersion: 2.5.1 + +Bundler/OrderedGems: + Enabled: false + +Layout/ParameterAlignment: + EnforcedStyle: with_fixed_indentation + +Metrics/AbcSize: + Max: 20 + +Metrics/BlockLength: + Exclude: + - config/routes.rb + - spec/**/*.rb + - config/routes/*.rb + +Layout/LineLength: + Max: 120 + Exclude: + - config/routes.rb + IgnoreCopDirectives: true + +Metrics/MethodLength: + Max: 50 + Exclude: + - db/migrate/*.rb + + +Style/ClassAndModuleChildren: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: false + +Layout/SpaceAroundMethodCallOperator: + Enabled: true + +Lint/RaiseException: + Enabled: true + +Lint/StructNewOverride: + Enabled: true + +Style/ExponentialNotation: + Enabled: true + +Style/HashEachMethods: + Enabled: true + +Style/HashTransformKeys: + Enabled: true + +Style/HashTransformValues: + Enabled: true + +inherit_from: .rubocop-excludes.yml diff --git a/source/Dockerfile b/source/Dockerfile new file mode 100644 index 000000000..a70506a2d --- /dev/null +++ b/source/Dockerfile @@ -0,0 +1,29 @@ +FROM ruby:2.5.1 AS base + +RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs + +RUN useradd -ms /bin/bash rails + +USER rails + +RUN mkdir /home/rails/myapp + +WORKDIR /home/rails/myapp + +COPY Gemfile* ./ + +RUN bundle install + +COPY . . + +FROM base AS rails_app + +COPY ./docker-entrypoint.sh /usr/local/bin/ + +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "bundle", "exec", "rails s -p 3000 -b '0.0.0.0'"] + +FROM base AS sidekiq_app + +CMD ["bundle", "exec", "sidekiq"] diff --git a/source/Gemfile b/source/Gemfile new file mode 100644 index 000000000..26435c5b6 --- /dev/null +++ b/source/Gemfile @@ -0,0 +1,59 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.2.11' +# Use sqlite3 as the database for Active Record +gem 'sqlite3', '1.3.13' +# 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', '~> 3.7' + gem 'pry-byebug' + gem 'shoulda-matchers' + gem 'database_cleaner' + gem 'factory_bot_rails' + gem 'faker' + gem 'rubocop' + gem 'capybara' +end +gem 'simplecov', require: false, group: :test + +group :development do + # Access an IRB console on exception pages or by using <%= console %> in views + gem 'web-console', '~> 2.0' + + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' +end +gem "therubyracer" +gem "less-rails" +gem "twitter-bootstrap-rails" +gem 'bootstrap-generators', '~> 3.3.4' diff --git a/source/Gemfile.lock b/source/Gemfile.lock new file mode 100644 index 000000000..c3fc89512 --- /dev/null +++ b/source/Gemfile.lock @@ -0,0 +1,270 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.11) + actionpack (= 4.2.11) + actionview (= 4.2.11) + activejob (= 4.2.11) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.11) + actionview (= 4.2.11) + activesupport (= 4.2.11) + 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) + activesupport (= 4.2.11) + 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) + activesupport (= 4.2.11) + globalid (>= 0.3.0) + activemodel (4.2.11) + activesupport (= 4.2.11) + builder (~> 3.1) + activerecord (4.2.11) + activemodel (= 4.2.11) + activesupport (= 4.2.11) + arel (~> 6.0) + activesupport (4.2.11) + 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) + ast (2.4.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + bootstrap-generators (3.3.4) + railties (>= 3.1.0) + builder (3.2.4) + byebug (11.1.3) + capybara (3.32.1) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + coderay (1.1.2) + 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) + commonjs (0.2.7) + concurrent-ruby (1.1.6) + crass (1.0.6) + database_cleaner (1.8.5) + debug_inspector (0.0.3) + diff-lcs (1.3) + docile (1.3.2) + erubis (2.7.0) + execjs (2.7.0) + factory_bot (5.2.0) + activesupport (>= 4.2.0) + factory_bot_rails (5.2.0) + factory_bot (~> 5.2.0) + railties (>= 4.2.0) + faker (2.2.1) + i18n (>= 0.8) + ffi (1.12.2) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jaro_winkler (1.5.4) + jbuilder (2.9.1) + activesupport (>= 4.2.0) + jquery-rails (4.3.5) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (1.8.6) + less (2.6.0) + commonjs (~> 0.2.7) + less-rails (4.0.0) + actionpack (>= 4) + less (~> 2.6.0) + sprockets (>= 2) + libv8 (3.16.14.19) + loofah (2.5.0) + 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.0.2) + mini_portile2 (2.4.0) + minitest (5.14.0) + nokogiri (1.10.9) + mini_portile2 (~> 2.4.0) + parallel (1.19.1) + parser (2.7.1.2) + ast (~> 2.4.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) + public_suffix (4.0.4) + rack (1.6.13) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.11) + actionmailer (= 4.2.11) + actionpack (= 4.2.11) + actionview (= 4.2.11) + activejob (= 4.2.11) + activemodel (= 4.2.11) + activerecord (= 4.2.11) + activesupport (= 4.2.11) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.11) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + 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) + actionpack (= 4.2.11) + activesupport (= 4.2.11) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) + rake (13.0.1) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + rdoc (4.3.0) + ref (2.0.0) + regexp_parser (1.7.0) + rexml (3.2.4) + rspec-core (3.9.2) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-rails (3.9.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.3) + rubocop (0.82.0) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.7.0.1) + rainbow (>= 2.2.2, < 4.0) + rexml + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + ruby-progressbar (1.10.1) + 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) + shoulda-matchers (4.3.0) + activesupport (>= 4.2.0) + simplecov (0.18.5) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov-html (0.12.2) + spring (2.1.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) + ref + thor (1.0.1) + thread_safe (0.3.6) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + twitter-bootstrap-rails (3.2.2) + actionpack (>= 3.1) + execjs (>= 2.2.2, >= 2.2) + less-rails (>= 2.5.0) + railties (>= 3.1) + tzinfo (1.2.7) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + unicode-display_width (1.7.0) + 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 + bootstrap-generators (~> 3.3.4) + byebug + capybara + coffee-rails (~> 4.1.0) + database_cleaner + factory_bot_rails + faker + jbuilder (~> 2.0) + jquery-rails + less-rails + pry-byebug + rails (= 4.2.11) + rspec-rails (~> 3.7) + rubocop + sass-rails (~> 5.0) + sdoc (~> 0.4.0) + shoulda-matchers + simplecov + spring + sqlite3 (= 1.3.13) + therubyracer + turbolinks + twitter-bootstrap-rails + uglifier (>= 1.3.0) + web-console (~> 2.0) + +BUNDLED WITH + 1.17.3 diff --git a/source/README.rdoc b/source/README.rdoc new file mode 100644 index 000000000..7cbcba0dc --- /dev/null +++ b/source/README.rdoc @@ -0,0 +1,22 @@ +# README + +* Ruby version 2.5.1 + +* Rails version 4.2.11 + +#### Instriction to run app +###### To setup DB Run: +* `rake db:create` +* `rake db:migrate` + +###### To seed customers and charges: +* `rake db:seed` + +###### Run rails app using +* `rails s` + +###### Run Test case using +* `rspec` + +##### run app using docker +* `make up` \ No newline at end of file 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..bcb49bf38 --- /dev/null +++ b/source/app/assets/javascripts/application.js @@ -0,0 +1,17 @@ +// 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 twitter/bootstrap +//= require turbolinks +//= require_tree . diff --git a/source/app/assets/javascripts/bootstrap.js.coffee b/source/app/assets/javascripts/bootstrap.js.coffee new file mode 100644 index 000000000..944067987 --- /dev/null +++ b/source/app/assets/javascripts/bootstrap.js.coffee @@ -0,0 +1,3 @@ +jQuery -> + $("a[rel~=popover], .has-popover").popover() + $("a[rel~=tooltip], .has-tooltip").tooltip() diff --git a/source/app/assets/javascripts/charges.coffee b/source/app/assets/javascripts/charges.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/app/assets/javascripts/charges.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/source/app/assets/javascripts/customers.coffee b/source/app/assets/javascripts/customers.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/app/assets/javascripts/customers.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/source/app/assets/stylesheets/application.css b/source/app/assets/stylesheets/application.css new file mode 100644 index 000000000..11392b975 --- /dev/null +++ b/source/app/assets/stylesheets/application.css @@ -0,0 +1,27 @@ +/* + * 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 + */ + +table, th, td { + padding: 2px; +} + +tr.failed { + background-color: #FF0000; +} + +tr.disputed { + background-color: #FF5400; +} diff --git a/source/app/assets/stylesheets/bootstrap_and_overrides.css.less b/source/app/assets/stylesheets/bootstrap_and_overrides.css.less new file mode 100644 index 000000000..d7b6f58b5 --- /dev/null +++ b/source/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -0,0 +1,32 @@ +@import "twitter/bootstrap/bootstrap"; + +// Set correct font paths +@glyphiconsEotPath: font-url("glyphicons-halflings-regular.eot"); +@glyphiconsEotPath_iefix: font-url("glyphicons-halflings-regular.eot?#iefix"); +@glyphiconsWoffPath: font-url("glyphicons-halflings-regular.woff"); +@glyphiconsTtfPath: font-url("glyphicons-halflings-regular.ttf"); +@glyphiconsSvgPath: font-url("glyphicons-halflings-regular.svg#glyphicons_halflingsregular"); + +// Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines) +@fontAwesomeEotPath: font-url("fontawesome-webfont.eot"); +@fontAwesomeEotPath_iefix: font-url("fontawesome-webfont.eot?#iefix"); +@fontAwesomeWoffPath: font-url("fontawesome-webfont.woff"); +@fontAwesomeTtfPath: font-url("fontawesome-webfont.ttf"); +@fontAwesomeSvgPath: font-url("fontawesome-webfont.svg#fontawesomeregular"); + +// Font Awesome +@import "fontawesome/font-awesome"; + +// Glyphicons +//@import "twitter/bootstrap/glyphicons.less"; + +// Your custom LESS stylesheets goes here +// +// Since bootstrap was imported above you have access to its mixins which +// you may use and inherit here +// +// If you'd like to override bootstrap's own variables, you can do so here as well +// See http://twitter.github.com/bootstrap/customize.html#variables for their names and documentation +// +// Example: +// @link-color: #ff0000; 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..c3d1eb3e2 --- /dev/null +++ b/source/app/controllers/charges_controller.rb @@ -0,0 +1,74 @@ +class ChargesController < ApplicationController + before_action :set_charge, only: [:show, :edit, :update, :destroy] + + # GET /charges + # GET /charges.json + def index + @charges = Charge.all.includes(:customer) + end + + # GET /charges/1 + # GET /charges/1.json + def show + end + + # GET /charges/new + def new + @charge = Charge.new + end + + # GET /charges/1/edit + def edit + end + + # POST /charges + # POST /charges.json + def create + @charge = Charge.new(charge_params) + + respond_to do |format| + if @charge.save + format.html { redirect_to @charge, notice: 'Charge was successfully created.' } + format.json { render :show, status: :created, location: @charge } + else + format.html { render :new } + format.json { render json: @charge.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /charges/1 + # PATCH/PUT /charges/1.json + def update + respond_to do |format| + if @charge.update(charge_params) + format.html { redirect_to @charge, notice: 'Charge was successfully updated.' } + format.json { render :show, status: :ok, location: @charge } + else + format.html { render :edit } + format.json { render json: @charge.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /charges/1 + # DELETE /charges/1.json + def destroy + @charge.destroy + respond_to do |format| + format.html { redirect_to charges_url, notice: 'Charge was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_charge + @charge = Charge.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def charge_params + params.require(:charge).permit(:created, :paid, :amount, :refunded, :currency, :customer_id) + 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/controllers/customers_controller.rb b/source/app/controllers/customers_controller.rb new file mode 100644 index 000000000..c5cf7e989 --- /dev/null +++ b/source/app/controllers/customers_controller.rb @@ -0,0 +1,74 @@ +class CustomersController < ApplicationController + before_action :set_customer, only: [:show, :edit, :update, :destroy] + + # GET /customers + # GET /customers.json + def index + @customers = Customer.all + end + + # GET /customers/1 + # GET /customers/1.json + def show + end + + # GET /customers/new + def new + @customer = Customer.new + end + + # GET /customers/1/edit + def edit + end + + # POST /customers + # POST /customers.json + def create + @customer = Customer.new(customer_params) + + respond_to do |format| + if @customer.save + format.html { redirect_to @customer, notice: 'Customer was successfully created.' } + format.json { render :show, status: :created, location: @customer } + else + format.html { render :new } + format.json { render json: @customer.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /customers/1 + # PATCH/PUT /customers/1.json + def update + respond_to do |format| + if @customer.update(customer_params) + format.html { redirect_to @customer, notice: 'Customer was successfully updated.' } + format.json { render :show, status: :ok, location: @customer } + else + format.html { render :edit } + format.json { render json: @customer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /customers/1 + # DELETE /customers/1.json + def destroy + @customer.destroy + respond_to do |format| + format.html { redirect_to customers_url, notice: 'Customer was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_customer + @customer = Customer.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def customer_params + params.require(:customer).permit(:first_name, :last_name) + end +end 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/helpers/charges_helper.rb b/source/app/helpers/charges_helper.rb new file mode 100644 index 000000000..414ee900f --- /dev/null +++ b/source/app/helpers/charges_helper.rb @@ -0,0 +1,2 @@ +module ChargesHelper +end diff --git a/source/app/helpers/customers_helper.rb b/source/app/helpers/customers_helper.rb new file mode 100644 index 000000000..a07ce2943 --- /dev/null +++ b/source/app/helpers/customers_helper.rb @@ -0,0 +1,2 @@ +module CustomersHelper +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..033ea6f2c --- /dev/null +++ b/source/app/models/charge.rb @@ -0,0 +1,15 @@ +class Charge < ActiveRecord::Base + belongs_to :customer, required: true + + scope :successful, -> { where(paid: true, refunded: false) } + scope :failed, -> { where(paid: false) } + scope :disputed, -> { where(paid: true, refunded: true) } + + def formated_amount + "$ #{amount / 1000.0}" + end + + def formated_date + Time.at(created).to_datetime.strftime('%c') + 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..107b58c99 --- /dev/null +++ b/source/app/models/customer.rb @@ -0,0 +1,8 @@ +class Customer < ActiveRecord::Base + validates :first_name, presence: true + validates :last_name, presence: true + has_many :charges + def name + "#{first_name} #{last_name}" + end +end diff --git a/source/app/views/charges/_charge.json.jbuilder b/source/app/views/charges/_charge.json.jbuilder new file mode 100644 index 000000000..18eb8e4e9 --- /dev/null +++ b/source/app/views/charges/_charge.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! charge, :id, :created, :paid, :amount, :refunded, :currency, :customer_id, :created_at, :updated_at +json.url charge_url(charge, format: :json) diff --git a/source/app/views/charges/_charges.html.erb b/source/app/views/charges/_charges.html.erb new file mode 100644 index 000000000..c14e32f36 --- /dev/null +++ b/source/app/views/charges/_charges.html.erb @@ -0,0 +1,24 @@ +
| Customer Name | +Amount | +Date | +
|---|---|---|
| <%= charge.customer.name %> | +<%= charge.formated_amount %> | +<%= charge.formated_date %> | +
<%= notice %>
+<%= notice %>
+ ++ Created: + <%= @charge.created %> +
+ ++ Paid: + <%= @charge.paid %> +
+ ++ Amount: + <%= @charge.amount %> +
+ ++ Refunded: + <%= @charge.refunded %> +
+ ++ Currency: + <%= @charge.currency %> +
+ ++ Customer: + <%= @charge.customer %> +
+ +<%= link_to 'Edit', edit_charge_path(@charge) %> | +<%= link_to 'Back', charges_path %> diff --git a/source/app/views/charges/show.json.jbuilder b/source/app/views/charges/show.json.jbuilder new file mode 100644 index 000000000..54f867331 --- /dev/null +++ b/source/app/views/charges/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "charges/charge", charge: @charge diff --git a/source/app/views/customers/_customer.json.jbuilder b/source/app/views/customers/_customer.json.jbuilder new file mode 100644 index 000000000..9f2b36660 --- /dev/null +++ b/source/app/views/customers/_customer.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! customer, :id, :first_name, :last_name, :created_at, :updated_at +json.url customer_url(customer, format: :json) diff --git a/source/app/views/customers/_form.html.erb b/source/app/views/customers/_form.html.erb new file mode 100644 index 000000000..a6a28ec49 --- /dev/null +++ b/source/app/views/customers/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@customer) do |f| %> + <% if @customer.errors.any? %> +<%= notice %>
+| First name | +Last name | ++ | ||
|---|---|---|---|---|
| <%= customer.first_name %> | +<%= customer.last_name %> | +<%= link_to 'Show', customer %> | +<%= link_to 'Edit', edit_customer_path(customer) %> | +<%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ First name: + <%= @customer.first_name %> +
+ ++ Last name: + <%= @customer.last_name %> +
+ +<%= link_to 'Edit', edit_customer_path(@customer) %> | +<%= link_to 'Back', customers_path %> diff --git a/source/app/views/customers/show.json.jbuilder b/source/app/views/customers/show.json.jbuilder new file mode 100644 index 000000000..14cfc837e --- /dev/null +++ b/source/app/views/customers/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "customers/customer", customer: @customer diff --git a/source/app/views/layouts/application.html.erb b/source/app/views/layouts/application.html.erb new file mode 100644 index 000000000..914fe49a0 --- /dev/null +++ b/source/app/views/layouts/application.html.erb @@ -0,0 +1,26 @@ + + + +<%= notice %>
+<%= alert %>
+ +You may have mistyped the address or the page may have moved.
+If you are the application owner check the logs for more information.
+Maybe you tried to change something you didn't have access to.
+If you are the application owner check the logs for more information.
+If you are the application owner check the logs for more information.
+" do + render + expect(rendered).to match(/First Name/) + expect(rendered).to match(/Last Name/) + 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