From a786134431fe2abf4c8a09b4145bc509e0d9bdc0 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 22:48:41 -0400 Subject: [PATCH 01/40] Init app --- source/exampleApp/.gitignore | 16 +++ source/exampleApp/Gemfile | 45 +++++++ source/exampleApp/Gemfile.lock | 120 ++++++++++++++++++ source/exampleApp/README.rdoc | 28 ++++ source/exampleApp/Rakefile | 6 + source/exampleApp/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 16 +++ .../app/assets/stylesheets/application.css | 13 ++ .../app/controllers/application_controller.rb | 5 + .../exampleApp/app/controllers/concerns/.keep | 0 .../app/helpers/application_helper.rb | 2 + source/exampleApp/app/mailers/.keep | 0 source/exampleApp/app/models/.keep | 0 source/exampleApp/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 14 ++ source/exampleApp/bin/bundle | 3 + source/exampleApp/bin/rails | 4 + source/exampleApp/bin/rake | 4 + source/exampleApp/config.ru | 4 + source/exampleApp/config/application.rb | 28 ++++ source/exampleApp/config/boot.rb | 4 + source/exampleApp/config/database.yml | 60 +++++++++ source/exampleApp/config/environment.rb | 5 + .../config/environments/development.rb | 29 +++++ .../config/environments/production.rb | 80 ++++++++++++ source/exampleApp/config/environments/test.rb | 36 ++++++ .../initializers/backtrace_silencers.rb | 7 + .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 +++ .../config/initializers/mime_types.rb | 5 + .../config/initializers/secret_token.rb | 12 ++ .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 ++ source/exampleApp/config/locales/en.yml | 23 ++++ source/exampleApp/config/routes.rb | 56 ++++++++ source/exampleApp/db/seeds.rb | 7 + source/exampleApp/lib/assets/.keep | 0 source/exampleApp/lib/tasks/.keep | 0 source/exampleApp/log/.keep | 0 source/exampleApp/public/404.html | 58 +++++++++ source/exampleApp/public/422.html | 58 +++++++++ source/exampleApp/public/500.html | 57 +++++++++ source/exampleApp/public/favicon.ico | 0 source/exampleApp/public/robots.txt | 5 + .../vendor/assets/javascripts/.keep | 0 .../vendor/assets/stylesheets/.keep | 0 46 files changed, 847 insertions(+) create mode 100644 source/exampleApp/.gitignore create mode 100644 source/exampleApp/Gemfile create mode 100644 source/exampleApp/Gemfile.lock create mode 100644 source/exampleApp/README.rdoc create mode 100644 source/exampleApp/Rakefile create mode 100644 source/exampleApp/app/assets/images/.keep create mode 100644 source/exampleApp/app/assets/javascripts/application.js create mode 100644 source/exampleApp/app/assets/stylesheets/application.css create mode 100644 source/exampleApp/app/controllers/application_controller.rb create mode 100644 source/exampleApp/app/controllers/concerns/.keep create mode 100644 source/exampleApp/app/helpers/application_helper.rb create mode 100644 source/exampleApp/app/mailers/.keep create mode 100644 source/exampleApp/app/models/.keep create mode 100644 source/exampleApp/app/models/concerns/.keep create mode 100644 source/exampleApp/app/views/layouts/application.html.erb create mode 100755 source/exampleApp/bin/bundle create mode 100755 source/exampleApp/bin/rails create mode 100755 source/exampleApp/bin/rake create mode 100644 source/exampleApp/config.ru create mode 100644 source/exampleApp/config/application.rb create mode 100644 source/exampleApp/config/boot.rb create mode 100644 source/exampleApp/config/database.yml create mode 100644 source/exampleApp/config/environment.rb create mode 100644 source/exampleApp/config/environments/development.rb create mode 100644 source/exampleApp/config/environments/production.rb create mode 100644 source/exampleApp/config/environments/test.rb create mode 100644 source/exampleApp/config/initializers/backtrace_silencers.rb create mode 100644 source/exampleApp/config/initializers/filter_parameter_logging.rb create mode 100644 source/exampleApp/config/initializers/inflections.rb create mode 100644 source/exampleApp/config/initializers/mime_types.rb create mode 100644 source/exampleApp/config/initializers/secret_token.rb create mode 100644 source/exampleApp/config/initializers/session_store.rb create mode 100644 source/exampleApp/config/initializers/wrap_parameters.rb create mode 100644 source/exampleApp/config/locales/en.yml create mode 100644 source/exampleApp/config/routes.rb create mode 100644 source/exampleApp/db/seeds.rb create mode 100644 source/exampleApp/lib/assets/.keep create mode 100644 source/exampleApp/lib/tasks/.keep create mode 100644 source/exampleApp/log/.keep create mode 100644 source/exampleApp/public/404.html create mode 100644 source/exampleApp/public/422.html create mode 100644 source/exampleApp/public/500.html create mode 100644 source/exampleApp/public/favicon.ico create mode 100644 source/exampleApp/public/robots.txt create mode 100644 source/exampleApp/vendor/assets/javascripts/.keep create mode 100644 source/exampleApp/vendor/assets/stylesheets/.keep diff --git a/source/exampleApp/.gitignore b/source/exampleApp/.gitignore new file mode 100644 index 000000000..25a742dff --- /dev/null +++ b/source/exampleApp/.gitignore @@ -0,0 +1,16 @@ +# See http://help.github.com/ignore-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 +/tmp diff --git a/source/exampleApp/Gemfile b/source/exampleApp/Gemfile new file mode 100644 index 000000000..36c38ba95 --- /dev/null +++ b/source/exampleApp/Gemfile @@ -0,0 +1,45 @@ +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.0.0' + +# Use postgresql as the database for Active Record +gem 'pg' + +# Use SCSS for stylesheets +gem 'sass-rails', '~> 4.0.0' + +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' + +# Use CoffeeScript for .js.coffee assets and views +gem 'coffee-rails', '~> 4.0.0' + +# See https://github.com/sstephenson/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', '~> 1.2' + +group :doc do + # bundle exec rake doc:rails generates the API under doc/api. + gem 'sdoc', require: false +end + +# Use ActiveModel has_secure_password +# gem 'bcrypt-ruby', '~> 3.0.0' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] diff --git a/source/exampleApp/Gemfile.lock b/source/exampleApp/Gemfile.lock new file mode 100644 index 000000000..b13a89c55 --- /dev/null +++ b/source/exampleApp/Gemfile.lock @@ -0,0 +1,120 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.0) + actionpack (= 4.0.0) + mail (~> 2.5.3) + actionpack (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + activerecord (4.0.0) + activemodel (= 4.0.0) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.0) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.0) + i18n (~> 0.6, >= 0.6.4) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + arel (4.0.2) + builder (3.1.4) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.8) + erubis (2.7.0) + execjs (2.7.0) + hike (1.2.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jbuilder (1.5.3) + activesupport (>= 3.0.0) + multi_json (>= 1.2.0) + jquery-rails (3.1.5) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + mail (2.5.5) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (4.7.5) + multi_json (1.15.0) + pg (1.1.4) + polyglot (0.3.5) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.0.0) + actionmailer (= 4.0.0) + actionpack (= 4.0.0) + activerecord (= 4.0.0) + activesupport (= 4.0.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.0) + sprockets-rails (~> 2.0.0) + railties (4.0.0) + actionpack (= 4.0.0) + activesupport (= 4.0.0) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.3) + rdoc (5.1.0) + sass (3.2.19) + sass-rails (4.0.5) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) + sprockets-rails (~> 2.0) + sdoc (2.1.0) + rdoc (>= 5.0) + sprockets (2.12.5) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + thor (1.1.0) + thread_safe (0.3.6) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (0.3.60) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 4.0.0) + jbuilder (~> 1.2) + jquery-rails + pg + rails (= 4.0.0) + sass-rails (~> 4.0.0) + sdoc + turbolinks + uglifier (>= 1.3.0) + +BUNDLED WITH + 1.17.3 diff --git a/source/exampleApp/README.rdoc b/source/exampleApp/README.rdoc new file mode 100644 index 000000000..dd4e97e22 --- /dev/null +++ b/source/exampleApp/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/exampleApp/Rakefile b/source/exampleApp/Rakefile new file mode 100644 index 000000000..e67201a82 --- /dev/null +++ b/source/exampleApp/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__) + +ExampleApp::Application.load_tasks diff --git a/source/exampleApp/app/assets/images/.keep b/source/exampleApp/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/app/assets/javascripts/application.js b/source/exampleApp/app/assets/javascripts/application.js new file mode 100644 index 000000000..d6925fa43 --- /dev/null +++ b/source/exampleApp/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 vendor/assets/javascripts of plugins, if any, 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/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/source/exampleApp/app/assets/stylesheets/application.css b/source/exampleApp/app/assets/stylesheets/application.css new file mode 100644 index 000000000..3192ec897 --- /dev/null +++ b/source/exampleApp/app/assets/stylesheets/application.css @@ -0,0 +1,13 @@ +/* + * 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 vendor/assets/stylesheets of plugins, if any, 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 top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ diff --git a/source/exampleApp/app/controllers/application_controller.rb b/source/exampleApp/app/controllers/application_controller.rb new file mode 100644 index 000000000..d83690e1b --- /dev/null +++ b/source/exampleApp/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/exampleApp/app/controllers/concerns/.keep b/source/exampleApp/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/app/helpers/application_helper.rb b/source/exampleApp/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/source/exampleApp/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/source/exampleApp/app/mailers/.keep b/source/exampleApp/app/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/app/models/.keep b/source/exampleApp/app/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/app/models/concerns/.keep b/source/exampleApp/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/app/views/layouts/application.html.erb b/source/exampleApp/app/views/layouts/application.html.erb new file mode 100644 index 000000000..3a16810af --- /dev/null +++ b/source/exampleApp/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + ExampleApp + <%= 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/exampleApp/bin/bundle b/source/exampleApp/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/source/exampleApp/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/exampleApp/bin/rails b/source/exampleApp/bin/rails new file mode 100755 index 000000000..728cd85aa --- /dev/null +++ b/source/exampleApp/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/exampleApp/bin/rake b/source/exampleApp/bin/rake new file mode 100755 index 000000000..17240489f --- /dev/null +++ b/source/exampleApp/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/source/exampleApp/config.ru b/source/exampleApp/config.ru new file mode 100644 index 000000000..5bc2a619e --- /dev/null +++ b/source/exampleApp/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/exampleApp/config/application.rb b/source/exampleApp/config/application.rb new file mode 100644 index 000000000..42debc6df --- /dev/null +++ b/source/exampleApp/config/application.rb @@ -0,0 +1,28 @@ +require File.expand_path('../boot', __FILE__) + +# Pick the frameworks you want: +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/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(:default, Rails.env) + +module ExampleApp + 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 + end +end diff --git a/source/exampleApp/config/boot.rb b/source/exampleApp/config/boot.rb new file mode 100644 index 000000000..359673666 --- /dev/null +++ b/source/exampleApp/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/source/exampleApp/config/database.yml b/source/exampleApp/config/database.yml new file mode 100644 index 000000000..632b5bdc3 --- /dev/null +++ b/source/exampleApp/config/database.yml @@ -0,0 +1,60 @@ +# 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' +# +development: + adapter: postgresql + encoding: unicode + database: exampleApp_development + pool: 5 + username: exampleApp + 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: + adapter: postgresql + encoding: unicode + database: exampleApp_test + pool: 5 + username: exampleApp + password: + +production: + adapter: postgresql + encoding: unicode + database: exampleApp_production + pool: 5 + username: exampleApp + password: diff --git a/source/exampleApp/config/environment.rb b/source/exampleApp/config/environment.rb new file mode 100644 index 000000000..aebc109cd --- /dev/null +++ b/source/exampleApp/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +ExampleApp::Application.initialize! diff --git a/source/exampleApp/config/environments/development.rb b/source/exampleApp/config/environments/development.rb new file mode 100644 index 000000000..b4c8454f9 --- /dev/null +++ b/source/exampleApp/config/environments/development.rb @@ -0,0 +1,29 @@ +ExampleApp::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 +end diff --git a/source/exampleApp/config/environments/production.rb b/source/exampleApp/config/environments/production.rb new file mode 100644 index 000000000..9b343689c --- /dev/null +++ b/source/exampleApp/config/environments/production.rb @@ -0,0 +1,80 @@ +ExampleApp::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 thread 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 Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # 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 + + # Generate digests for assets URLs. + config.assets.digest = true + + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + + # 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 + + # Set to :debug to see everything in the log. + config.log_level = :info + + # 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" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) + + # 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 can not be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new +end diff --git a/source/exampleApp/config/environments/test.rb b/source/exampleApp/config/environments/test.rb new file mode 100644 index 000000000..4838a862a --- /dev/null +++ b/source/exampleApp/config/environments/test.rb @@ -0,0 +1,36 @@ +ExampleApp::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 asset server for tests with Cache-Control for performance. + config.serve_static_assets = 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 + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr +end diff --git a/source/exampleApp/config/initializers/backtrace_silencers.rb b/source/exampleApp/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/source/exampleApp/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/exampleApp/config/initializers/filter_parameter_logging.rb b/source/exampleApp/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/source/exampleApp/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/exampleApp/config/initializers/inflections.rb b/source/exampleApp/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/source/exampleApp/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/exampleApp/config/initializers/mime_types.rb b/source/exampleApp/config/initializers/mime_types.rb new file mode 100644 index 000000000..72aca7e44 --- /dev/null +++ b/source/exampleApp/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# 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 +# Mime::Type.register_alias "text/html", :iphone diff --git a/source/exampleApp/config/initializers/secret_token.rb b/source/exampleApp/config/initializers/secret_token.rb new file mode 100644 index 000000000..b7d270ce4 --- /dev/null +++ b/source/exampleApp/config/initializers/secret_token.rb @@ -0,0 +1,12 @@ +# 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 your secret_key_base is kept private +# if you're sharing your code publicly. +ExampleApp::Application.config.secret_key_base = 'f38cc678182185b99c74eada0c427325031b624ad4bc0b9441d487adbdb5cf932a92da75cd6ae0896d371e6d61408074452e62db64163dae8146b67bacf393b2' diff --git a/source/exampleApp/config/initializers/session_store.rb b/source/exampleApp/config/initializers/session_store.rb new file mode 100644 index 000000000..e0c5a30ee --- /dev/null +++ b/source/exampleApp/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +ExampleApp::Application.config.session_store :cookie_store, key: '_exampleApp_session' diff --git a/source/exampleApp/config/initializers/wrap_parameters.rb b/source/exampleApp/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..33725e95f --- /dev/null +++ b/source/exampleApp/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/exampleApp/config/locales/en.yml b/source/exampleApp/config/locales/en.yml new file mode 100644 index 000000000..065395716 --- /dev/null +++ b/source/exampleApp/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/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb new file mode 100644 index 000000000..5b0ceec03 --- /dev/null +++ b/source/exampleApp/config/routes.rb @@ -0,0 +1,56 @@ +ExampleApp::Application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/source/exampleApp/db/seeds.rb b/source/exampleApp/db/seeds.rb new file mode 100644 index 000000000..4edb1e857 --- /dev/null +++ b/source/exampleApp/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/source/exampleApp/lib/assets/.keep b/source/exampleApp/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/lib/tasks/.keep b/source/exampleApp/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/log/.keep b/source/exampleApp/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/public/404.html b/source/exampleApp/public/404.html new file mode 100644 index 000000000..a0daa0c15 --- /dev/null +++ b/source/exampleApp/public/404.html @@ -0,0 +1,58 @@ + + + + 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/exampleApp/public/422.html b/source/exampleApp/public/422.html new file mode 100644 index 000000000..fbb4b84d7 --- /dev/null +++ b/source/exampleApp/public/422.html @@ -0,0 +1,58 @@ + + + + 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/exampleApp/public/500.html b/source/exampleApp/public/500.html new file mode 100644 index 000000000..e9052d35b --- /dev/null +++ b/source/exampleApp/public/500.html @@ -0,0 +1,57 @@ + + + + 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/exampleApp/public/favicon.ico b/source/exampleApp/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/public/robots.txt b/source/exampleApp/public/robots.txt new file mode 100644 index 000000000..1a3a5e4dd --- /dev/null +++ b/source/exampleApp/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/wc/norobots.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/exampleApp/vendor/assets/javascripts/.keep b/source/exampleApp/vendor/assets/javascripts/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/exampleApp/vendor/assets/stylesheets/.keep b/source/exampleApp/vendor/assets/stylesheets/.keep new file mode 100644 index 000000000..e69de29bb From 38601c47e663fe2b060cc07c15eabd607d01458c Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:08:58 -0400 Subject: [PATCH 02/40] Downgrade pg gem to avoid errors --- source/exampleApp/Gemfile | 2 +- source/exampleApp/Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/exampleApp/Gemfile b/source/exampleApp/Gemfile index 36c38ba95..23ce4c3ff 100644 --- a/source/exampleApp/Gemfile +++ b/source/exampleApp/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gem 'rails', '4.0.0' # Use postgresql as the database for Active Record -gem 'pg' +gem 'pg', '~> 0.20.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.0' diff --git a/source/exampleApp/Gemfile.lock b/source/exampleApp/Gemfile.lock index b13a89c55..064b6066d 100644 --- a/source/exampleApp/Gemfile.lock +++ b/source/exampleApp/Gemfile.lock @@ -52,7 +52,7 @@ GEM mime-types (1.25.1) minitest (4.7.5) multi_json (1.15.0) - pg (1.1.4) + pg (0.20.0) polyglot (0.3.5) rack (1.5.5) rack-test (0.6.3) @@ -109,7 +109,7 @@ DEPENDENCIES coffee-rails (~> 4.0.0) jbuilder (~> 1.2) jquery-rails - pg + pg (~> 0.20.0) rails (= 4.0.0) sass-rails (~> 4.0.0) sdoc From ae203126abc9ac9b9d0a8ee306f53350f2f02216 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:09:37 -0400 Subject: [PATCH 03/40] Update db credentials (not a good practice for production) --- source/exampleApp/config/database.yml | 12 ++++++------ source/exampleApp/config/routes.rb | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/exampleApp/config/database.yml b/source/exampleApp/config/database.yml index 632b5bdc3..f8fe20d87 100644 --- a/source/exampleApp/config/database.yml +++ b/source/exampleApp/config/database.yml @@ -19,8 +19,8 @@ development: encoding: unicode database: exampleApp_development pool: 5 - username: exampleApp - password: + username: postgres + password: 123456 # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have @@ -48,13 +48,13 @@ test: encoding: unicode database: exampleApp_test pool: 5 - username: exampleApp - password: + username: postgres + password: 123456 production: adapter: postgresql encoding: unicode database: exampleApp_production pool: 5 - username: exampleApp - password: + username: postgres + password: 123456 diff --git a/source/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb index 5b0ceec03..6441a126c 100644 --- a/source/exampleApp/config/routes.rb +++ b/source/exampleApp/config/routes.rb @@ -1,4 +1,6 @@ ExampleApp::Application.routes.draw do + resources :customers + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From e4547a800553feb94a12e1849e59bfb04ab42a37 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:12:56 -0400 Subject: [PATCH 04/40] Add customers scaffold --- .../assets/javascripts/customers.js.coffee | 3 + .../app/assets/stylesheets/customers.css.scss | 3 + .../app/assets/stylesheets/scaffolds.css.scss | 69 +++++++++++++++++ .../app/controllers/customers_controller.rb | 74 +++++++++++++++++++ .../app/helpers/customers_helper.rb | 2 + source/exampleApp/app/models/customer.rb | 2 + .../app/views/customers/_form.html.erb | 25 +++++++ .../app/views/customers/edit.html.erb | 6 ++ .../app/views/customers/index.html.erb | 29 ++++++++ .../app/views/customers/index.json.jbuilder | 4 + .../app/views/customers/new.html.erb | 5 ++ .../app/views/customers/show.html.erb | 14 ++++ .../app/views/customers/show.json.jbuilder | 1 + .../20210420030808_create_customers.rb | 10 +++ 14 files changed, 247 insertions(+) create mode 100644 source/exampleApp/app/assets/javascripts/customers.js.coffee create mode 100644 source/exampleApp/app/assets/stylesheets/customers.css.scss create mode 100644 source/exampleApp/app/assets/stylesheets/scaffolds.css.scss create mode 100644 source/exampleApp/app/controllers/customers_controller.rb create mode 100644 source/exampleApp/app/helpers/customers_helper.rb create mode 100644 source/exampleApp/app/models/customer.rb create mode 100644 source/exampleApp/app/views/customers/_form.html.erb create mode 100644 source/exampleApp/app/views/customers/edit.html.erb create mode 100644 source/exampleApp/app/views/customers/index.html.erb create mode 100644 source/exampleApp/app/views/customers/index.json.jbuilder create mode 100644 source/exampleApp/app/views/customers/new.html.erb create mode 100644 source/exampleApp/app/views/customers/show.html.erb create mode 100644 source/exampleApp/app/views/customers/show.json.jbuilder create mode 100644 source/exampleApp/db/migrate/20210420030808_create_customers.rb diff --git a/source/exampleApp/app/assets/javascripts/customers.js.coffee b/source/exampleApp/app/assets/javascripts/customers.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/exampleApp/app/assets/javascripts/customers.js.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/exampleApp/app/assets/stylesheets/customers.css.scss b/source/exampleApp/app/assets/stylesheets/customers.css.scss new file mode 100644 index 000000000..892b0ad94 --- /dev/null +++ b/source/exampleApp/app/assets/stylesheets/customers.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the customers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/exampleApp/app/assets/stylesheets/scaffolds.css.scss b/source/exampleApp/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 000000000..6ec6a8ff5 --- /dev/null +++ b/source/exampleApp/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/source/exampleApp/app/controllers/customers_controller.rb b/source/exampleApp/app/controllers/customers_controller.rb new file mode 100644 index 000000000..c7cb97e0d --- /dev/null +++ b/source/exampleApp/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 action: 'show', status: :created, location: @customer } + else + format.html { render action: '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 { head :no_content } + else + format.html { render action: '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 } + 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(:firstName, :lastName) + end +end diff --git a/source/exampleApp/app/helpers/customers_helper.rb b/source/exampleApp/app/helpers/customers_helper.rb new file mode 100644 index 000000000..a07ce2943 --- /dev/null +++ b/source/exampleApp/app/helpers/customers_helper.rb @@ -0,0 +1,2 @@ +module CustomersHelper +end diff --git a/source/exampleApp/app/models/customer.rb b/source/exampleApp/app/models/customer.rb new file mode 100644 index 000000000..047dcb0c0 --- /dev/null +++ b/source/exampleApp/app/models/customer.rb @@ -0,0 +1,2 @@ +class Customer < ActiveRecord::Base +end diff --git a/source/exampleApp/app/views/customers/_form.html.erb b/source/exampleApp/app/views/customers/_form.html.erb new file mode 100644 index 000000000..e70f94f06 --- /dev/null +++ b/source/exampleApp/app/views/customers/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@customer) do |f| %> + <% if @customer.errors.any? %> +
+

<%= pluralize(@customer.errors.count, "error") %> prohibited this customer from being saved:

+ +
    + <% @customer.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :firstName %>
+ <%= f.text_field :firstName %> +
+
+ <%= f.label :lastName %>
+ <%= f.text_field :lastName %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/source/exampleApp/app/views/customers/edit.html.erb b/source/exampleApp/app/views/customers/edit.html.erb new file mode 100644 index 000000000..d1ed0a71c --- /dev/null +++ b/source/exampleApp/app/views/customers/edit.html.erb @@ -0,0 +1,6 @@ +

Editing customer

+ +<%= render 'form' %> + +<%= link_to 'Show', @customer %> | +<%= link_to 'Back', customers_path %> diff --git a/source/exampleApp/app/views/customers/index.html.erb b/source/exampleApp/app/views/customers/index.html.erb new file mode 100644 index 000000000..d03841d83 --- /dev/null +++ b/source/exampleApp/app/views/customers/index.html.erb @@ -0,0 +1,29 @@ +

Listing customers

+ + + + + + + + + + + + + + <% @customers.each do |customer| %> + + + + + + + + <% end %> + +
FirstnameLastname
<%= customer.firstName %><%= customer.lastName %><%= link_to 'Show', customer %><%= link_to 'Edit', edit_customer_path(customer) %><%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Customer', new_customer_path %> diff --git a/source/exampleApp/app/views/customers/index.json.jbuilder b/source/exampleApp/app/views/customers/index.json.jbuilder new file mode 100644 index 000000000..a17bbce62 --- /dev/null +++ b/source/exampleApp/app/views/customers/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@customers) do |customer| + json.extract! customer, :id, :firstName, :lastName + json.url customer_url(customer, format: :json) +end diff --git a/source/exampleApp/app/views/customers/new.html.erb b/source/exampleApp/app/views/customers/new.html.erb new file mode 100644 index 000000000..a93c20371 --- /dev/null +++ b/source/exampleApp/app/views/customers/new.html.erb @@ -0,0 +1,5 @@ +

New customer

+ +<%= render 'form' %> + +<%= link_to 'Back', customers_path %> diff --git a/source/exampleApp/app/views/customers/show.html.erb b/source/exampleApp/app/views/customers/show.html.erb new file mode 100644 index 000000000..aaaf88cee --- /dev/null +++ b/source/exampleApp/app/views/customers/show.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

+ Firstname: + <%= @customer.firstName %> +

+ +

+ Lastname: + <%= @customer.lastName %> +

+ +<%= link_to 'Edit', edit_customer_path(@customer) %> | +<%= link_to 'Back', customers_path %> diff --git a/source/exampleApp/app/views/customers/show.json.jbuilder b/source/exampleApp/app/views/customers/show.json.jbuilder new file mode 100644 index 000000000..65e08441c --- /dev/null +++ b/source/exampleApp/app/views/customers/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @customer, :id, :firstName, :lastName, :created_at, :updated_at diff --git a/source/exampleApp/db/migrate/20210420030808_create_customers.rb b/source/exampleApp/db/migrate/20210420030808_create_customers.rb new file mode 100644 index 000000000..3dd2d031a --- /dev/null +++ b/source/exampleApp/db/migrate/20210420030808_create_customers.rb @@ -0,0 +1,10 @@ +class CreateCustomers < ActiveRecord::Migration + def change + create_table :customers do |t| + t.string :firstName, null: false, limit: 50 + t.string :lastName, null: false, limit: 50 + + t.timestamps + end + end +end From faeb99fbcbc6f32454d52afad89f4911f210c070 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:21:04 -0400 Subject: [PATCH 05/40] Add CreditCards scaffold --- .../assets/javascripts/credit_cards.js.coffee | 3 + .../assets/stylesheets/credit_cards.css.scss | 3 + .../controllers/credit_cards_controller.rb | 74 +++++++++++++++++++ .../app/helpers/credit_cards_helper.rb | 2 + source/exampleApp/app/models/credit_card.rb | 3 + .../app/views/credit_cards/_form.html.erb | 41 ++++++++++ .../app/views/credit_cards/edit.html.erb | 6 ++ .../app/views/credit_cards/index.html.erb | 37 ++++++++++ .../views/credit_cards/index.json.jbuilder | 4 + .../app/views/credit_cards/new.html.erb | 5 ++ .../app/views/credit_cards/show.html.erb | 34 +++++++++ .../app/views/credit_cards/show.json.jbuilder | 1 + source/exampleApp/config/routes.rb | 2 + .../20210420031843_create_credit_cards.rb | 14 ++++ source/exampleApp/db/schema.rb | 26 +++++++ 15 files changed, 255 insertions(+) create mode 100644 source/exampleApp/app/assets/javascripts/credit_cards.js.coffee create mode 100644 source/exampleApp/app/assets/stylesheets/credit_cards.css.scss create mode 100644 source/exampleApp/app/controllers/credit_cards_controller.rb create mode 100644 source/exampleApp/app/helpers/credit_cards_helper.rb create mode 100644 source/exampleApp/app/models/credit_card.rb create mode 100644 source/exampleApp/app/views/credit_cards/_form.html.erb create mode 100644 source/exampleApp/app/views/credit_cards/edit.html.erb create mode 100644 source/exampleApp/app/views/credit_cards/index.html.erb create mode 100644 source/exampleApp/app/views/credit_cards/index.json.jbuilder create mode 100644 source/exampleApp/app/views/credit_cards/new.html.erb create mode 100644 source/exampleApp/app/views/credit_cards/show.html.erb create mode 100644 source/exampleApp/app/views/credit_cards/show.json.jbuilder create mode 100644 source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb create mode 100644 source/exampleApp/db/schema.rb diff --git a/source/exampleApp/app/assets/javascripts/credit_cards.js.coffee b/source/exampleApp/app/assets/javascripts/credit_cards.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/exampleApp/app/assets/javascripts/credit_cards.js.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/exampleApp/app/assets/stylesheets/credit_cards.css.scss b/source/exampleApp/app/assets/stylesheets/credit_cards.css.scss new file mode 100644 index 000000000..8c15348f8 --- /dev/null +++ b/source/exampleApp/app/assets/stylesheets/credit_cards.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the CreditCards controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/exampleApp/app/controllers/credit_cards_controller.rb b/source/exampleApp/app/controllers/credit_cards_controller.rb new file mode 100644 index 000000000..258b8d351 --- /dev/null +++ b/source/exampleApp/app/controllers/credit_cards_controller.rb @@ -0,0 +1,74 @@ +class CreditCardsController < ApplicationController + before_action :set_credit_card, only: [:show, :edit, :update, :destroy] + + # GET /credit_cards + # GET /credit_cards.json + def index + @credit_cards = CreditCard.all + end + + # GET /credit_cards/1 + # GET /credit_cards/1.json + def show + end + + # GET /credit_cards/new + def new + @credit_card = CreditCard.new + end + + # GET /credit_cards/1/edit + def edit + end + + # POST /credit_cards + # POST /credit_cards.json + def create + @credit_card = CreditCard.new(credit_card_params) + + respond_to do |format| + if @credit_card.save + format.html { redirect_to @credit_card, notice: 'Credit card was successfully created.' } + format.json { render action: 'show', status: :created, location: @credit_card } + else + format.html { render action: 'new' } + format.json { render json: @credit_card.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /credit_cards/1 + # PATCH/PUT /credit_cards/1.json + def update + respond_to do |format| + if @credit_card.update(credit_card_params) + format.html { redirect_to @credit_card, notice: 'Credit card was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @credit_card.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /credit_cards/1 + # DELETE /credit_cards/1.json + def destroy + @credit_card.destroy + respond_to do |format| + format.html { redirect_to credit_cards_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_credit_card + @credit_card = CreditCard.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def credit_card_params + params.require(:credit_card).permit(:created, :paid, :amount, :currency, :refunded, :customer_id) + end +end diff --git a/source/exampleApp/app/helpers/credit_cards_helper.rb b/source/exampleApp/app/helpers/credit_cards_helper.rb new file mode 100644 index 000000000..81ecfe1b9 --- /dev/null +++ b/source/exampleApp/app/helpers/credit_cards_helper.rb @@ -0,0 +1,2 @@ +module CreditCardsHelper +end diff --git a/source/exampleApp/app/models/credit_card.rb b/source/exampleApp/app/models/credit_card.rb new file mode 100644 index 000000000..dcf5581f9 --- /dev/null +++ b/source/exampleApp/app/models/credit_card.rb @@ -0,0 +1,3 @@ +class CreditCard < ActiveRecord::Base + belongs_to :customer +end diff --git a/source/exampleApp/app/views/credit_cards/_form.html.erb b/source/exampleApp/app/views/credit_cards/_form.html.erb new file mode 100644 index 000000000..6c942724e --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/_form.html.erb @@ -0,0 +1,41 @@ +<%= form_for(@credit_card) do |f| %> + <% if @credit_card.errors.any? %> +
+

<%= pluralize(@credit_card.errors.count, "error") %> prohibited this credit_card from being saved:

+ +
    + <% @credit_card.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :created %>
+ <%= f.number_field :created %> +
+
+ <%= f.label :paid %>
+ <%= f.check_box :paid %> +
+
+ <%= f.label :amount %>
+ <%= f.text_field :amount %> +
+
+ <%= f.label :currency %>
+ <%= f.text_field :currency %> +
+
+ <%= f.label :refunded %>
+ <%= f.check_box :refunded %> +
+
+ <%= f.label :customer %>
+ <%= f.text_field :customer %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/source/exampleApp/app/views/credit_cards/edit.html.erb b/source/exampleApp/app/views/credit_cards/edit.html.erb new file mode 100644 index 000000000..e27f0b85e --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/edit.html.erb @@ -0,0 +1,6 @@ +

Editing credit_card

+ +<%= render 'form' %> + +<%= link_to 'Show', @credit_card %> | +<%= link_to 'Back', credit_cards_path %> diff --git a/source/exampleApp/app/views/credit_cards/index.html.erb b/source/exampleApp/app/views/credit_cards/index.html.erb new file mode 100644 index 000000000..8dcb1a3a3 --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/index.html.erb @@ -0,0 +1,37 @@ +

Listing credit_cards

+ + + + + + + + + + + + + + + + + + <% @credit_cards.each do |credit_card| %> + + + + + + + + + + + + <% end %> + +
CreatedPaidAmountCurrencyRefundedCustomer
<%= credit_card.created %><%= credit_card.paid %><%= credit_card.amount %><%= credit_card.currency %><%= credit_card.refunded %><%= credit_card.customer %><%= link_to 'Show', credit_card %><%= link_to 'Edit', edit_credit_card_path(credit_card) %><%= link_to 'Destroy', credit_card, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Credit card', new_credit_card_path %> diff --git a/source/exampleApp/app/views/credit_cards/index.json.jbuilder b/source/exampleApp/app/views/credit_cards/index.json.jbuilder new file mode 100644 index 000000000..e075a52ff --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@credit_cards) do |credit_card| + json.extract! credit_card, :id, :created, :paid, :amount, :currency, :refunded, :customer_id + json.url credit_card_url(credit_card, format: :json) +end diff --git a/source/exampleApp/app/views/credit_cards/new.html.erb b/source/exampleApp/app/views/credit_cards/new.html.erb new file mode 100644 index 000000000..ec8d8e648 --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/new.html.erb @@ -0,0 +1,5 @@ +

New credit_card

+ +<%= render 'form' %> + +<%= link_to 'Back', credit_cards_path %> diff --git a/source/exampleApp/app/views/credit_cards/show.html.erb b/source/exampleApp/app/views/credit_cards/show.html.erb new file mode 100644 index 000000000..90a6a5c61 --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/show.html.erb @@ -0,0 +1,34 @@ +

<%= notice %>

+ +

+ Created: + <%= @credit_card.created %> +

+ +

+ Paid: + <%= @credit_card.paid %> +

+ +

+ Amount: + <%= @credit_card.amount %> +

+ +

+ Currency: + <%= @credit_card.currency %> +

+ +

+ Refunded: + <%= @credit_card.refunded %> +

+ +

+ Customer: + <%= @credit_card.customer %> +

+ +<%= link_to 'Edit', edit_credit_card_path(@credit_card) %> | +<%= link_to 'Back', credit_cards_path %> diff --git a/source/exampleApp/app/views/credit_cards/show.json.jbuilder b/source/exampleApp/app/views/credit_cards/show.json.jbuilder new file mode 100644 index 000000000..a70a7ecaf --- /dev/null +++ b/source/exampleApp/app/views/credit_cards/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @credit_card, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb index 6441a126c..7ca95f690 100644 --- a/source/exampleApp/config/routes.rb +++ b/source/exampleApp/config/routes.rb @@ -1,4 +1,6 @@ ExampleApp::Application.routes.draw do + resources :credit_cards + resources :customers # The priority is based upon order of creation: first created -> highest priority. diff --git a/source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb b/source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb new file mode 100644 index 000000000..9cd19d92a --- /dev/null +++ b/source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb @@ -0,0 +1,14 @@ +class CreateCreditCards < ActiveRecord::Migration + def change + create_table :credit_cards do |t| + t.integer :created, null: false + t.boolean :paid, null: false, default: false + t.decimal :amount + t.string :currency, null: false + t.boolean :refunded, null: false, default: false + t.references :customer, index: true, null: false + + t.timestamps + end + end +end diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb new file mode 100644 index 000000000..f9407a028 --- /dev/null +++ b/source/exampleApp/db/schema.rb @@ -0,0 +1,26 @@ +# 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: 20210420030808) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "customers", force: true do |t| + t.string "firstName", limit: 50, null: false + t.string "lastName", limit: 50, null: false + t.datetime "created_at" + t.datetime "updated_at" + end + +end From 11d1ffc7046d5fe347a29f55f7f1fb8303534400 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:21:52 -0400 Subject: [PATCH 06/40] Migrate CreditCards --- source/exampleApp/db/schema.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb index f9407a028..31bea5d09 100644 --- a/source/exampleApp/db/schema.rb +++ b/source/exampleApp/db/schema.rb @@ -11,11 +11,24 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20210420030808) do +ActiveRecord::Schema.define(version: 20210420031843) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "credit_cards", force: true do |t| + t.integer "created", null: false + t.boolean "paid", default: false, null: false + t.decimal "amount" + t.string "currency", null: false + t.boolean "refunded", default: false, null: false + t.integer "customer_id", null: false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "credit_cards", ["customer_id"], name: "index_credit_cards_on_customer_id", using: :btree + create_table "customers", force: true do |t| t.string "firstName", limit: 50, null: false t.string "lastName", limit: 50, null: false From 45980d19fb7a57b2f5af7095bb2c71b5195f7898 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:27:27 -0400 Subject: [PATCH 07/40] Add seeds --- source/exampleApp/db/seeds.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/exampleApp/db/seeds.rb b/source/exampleApp/db/seeds.rb index 4edb1e857..31190f2e1 100644 --- a/source/exampleApp/db/seeds.rb +++ b/source/exampleApp/db/seeds.rb @@ -5,3 +5,8 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +Customer.create(firstName: "Johny", lastName: "Flow") +Customer.create(firstName: "Raj", lastName: "Jamnis") +Customer.create(firstName: "Andrew", lastName: "Chung") +Customer.create(firstName: "Mike", lastName: "Smith") \ No newline at end of file From 98b797c1e768957d90e32af09a3f670fb0637d41 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:32:22 -0400 Subject: [PATCH 08/40] Remove CreditCards scaffold to rename it Transactions --- ...cards.js.coffee => transactions.js.coffee} | 0 ...t_cards.css.scss => transactions.css.scss} | 2 +- .../controllers/credit_cards_controller.rb | 74 ------------------- .../controllers/transactions_controller.rb | 74 +++++++++++++++++++ .../app/helpers/credit_cards_helper.rb | 2 - .../app/helpers/transactions_helper.rb | 2 + source/exampleApp/app/models/credit_card.rb | 3 - source/exampleApp/app/models/transaction.rb | 3 + .../app/views/credit_cards/edit.html.erb | 6 -- .../app/views/credit_cards/index.html.erb | 37 ---------- .../views/credit_cards/index.json.jbuilder | 4 - .../app/views/credit_cards/new.html.erb | 5 -- .../app/views/credit_cards/show.html.erb | 34 --------- .../app/views/credit_cards/show.json.jbuilder | 1 - .../_form.html.erb | 8 +- .../app/views/transactions/edit.html.erb | 6 ++ .../app/views/transactions/index.html.erb | 37 ++++++++++ .../views/transactions/index.json.jbuilder | 4 + .../app/views/transactions/new.html.erb | 5 ++ .../app/views/transactions/show.html.erb | 34 +++++++++ .../app/views/transactions/show.json.jbuilder | 1 + source/exampleApp/config/routes.rb | 2 +- ... => 20210420033157_create_transactions.rb} | 4 +- source/exampleApp/db/schema.rb | 22 +----- source/exampleApp/db/seeds.rb | 17 ++++- 25 files changed, 191 insertions(+), 196 deletions(-) rename source/exampleApp/app/assets/javascripts/{credit_cards.js.coffee => transactions.js.coffee} (100%) rename source/exampleApp/app/assets/stylesheets/{credit_cards.css.scss => transactions.css.scss} (62%) delete mode 100644 source/exampleApp/app/controllers/credit_cards_controller.rb create mode 100644 source/exampleApp/app/controllers/transactions_controller.rb delete mode 100644 source/exampleApp/app/helpers/credit_cards_helper.rb create mode 100644 source/exampleApp/app/helpers/transactions_helper.rb delete mode 100644 source/exampleApp/app/models/credit_card.rb create mode 100644 source/exampleApp/app/models/transaction.rb delete mode 100644 source/exampleApp/app/views/credit_cards/edit.html.erb delete mode 100644 source/exampleApp/app/views/credit_cards/index.html.erb delete mode 100644 source/exampleApp/app/views/credit_cards/index.json.jbuilder delete mode 100644 source/exampleApp/app/views/credit_cards/new.html.erb delete mode 100644 source/exampleApp/app/views/credit_cards/show.html.erb delete mode 100644 source/exampleApp/app/views/credit_cards/show.json.jbuilder rename source/exampleApp/app/views/{credit_cards => transactions}/_form.html.erb (75%) create mode 100644 source/exampleApp/app/views/transactions/edit.html.erb create mode 100644 source/exampleApp/app/views/transactions/index.html.erb create mode 100644 source/exampleApp/app/views/transactions/index.json.jbuilder create mode 100644 source/exampleApp/app/views/transactions/new.html.erb create mode 100644 source/exampleApp/app/views/transactions/show.html.erb create mode 100644 source/exampleApp/app/views/transactions/show.json.jbuilder rename source/exampleApp/db/migrate/{20210420031843_create_credit_cards.rb => 20210420033157_create_transactions.rb} (77%) diff --git a/source/exampleApp/app/assets/javascripts/credit_cards.js.coffee b/source/exampleApp/app/assets/javascripts/transactions.js.coffee similarity index 100% rename from source/exampleApp/app/assets/javascripts/credit_cards.js.coffee rename to source/exampleApp/app/assets/javascripts/transactions.js.coffee diff --git a/source/exampleApp/app/assets/stylesheets/credit_cards.css.scss b/source/exampleApp/app/assets/stylesheets/transactions.css.scss similarity index 62% rename from source/exampleApp/app/assets/stylesheets/credit_cards.css.scss rename to source/exampleApp/app/assets/stylesheets/transactions.css.scss index 8c15348f8..f93ff9762 100644 --- a/source/exampleApp/app/assets/stylesheets/credit_cards.css.scss +++ b/source/exampleApp/app/assets/stylesheets/transactions.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the CreditCards controller here. +// Place all the styles related to the Transactions controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/exampleApp/app/controllers/credit_cards_controller.rb b/source/exampleApp/app/controllers/credit_cards_controller.rb deleted file mode 100644 index 258b8d351..000000000 --- a/source/exampleApp/app/controllers/credit_cards_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -class CreditCardsController < ApplicationController - before_action :set_credit_card, only: [:show, :edit, :update, :destroy] - - # GET /credit_cards - # GET /credit_cards.json - def index - @credit_cards = CreditCard.all - end - - # GET /credit_cards/1 - # GET /credit_cards/1.json - def show - end - - # GET /credit_cards/new - def new - @credit_card = CreditCard.new - end - - # GET /credit_cards/1/edit - def edit - end - - # POST /credit_cards - # POST /credit_cards.json - def create - @credit_card = CreditCard.new(credit_card_params) - - respond_to do |format| - if @credit_card.save - format.html { redirect_to @credit_card, notice: 'Credit card was successfully created.' } - format.json { render action: 'show', status: :created, location: @credit_card } - else - format.html { render action: 'new' } - format.json { render json: @credit_card.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /credit_cards/1 - # PATCH/PUT /credit_cards/1.json - def update - respond_to do |format| - if @credit_card.update(credit_card_params) - format.html { redirect_to @credit_card, notice: 'Credit card was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @credit_card.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /credit_cards/1 - # DELETE /credit_cards/1.json - def destroy - @credit_card.destroy - respond_to do |format| - format.html { redirect_to credit_cards_url } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_credit_card - @credit_card = CreditCard.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def credit_card_params - params.require(:credit_card).permit(:created, :paid, :amount, :currency, :refunded, :customer_id) - end -end diff --git a/source/exampleApp/app/controllers/transactions_controller.rb b/source/exampleApp/app/controllers/transactions_controller.rb new file mode 100644 index 000000000..4d8b2dfaf --- /dev/null +++ b/source/exampleApp/app/controllers/transactions_controller.rb @@ -0,0 +1,74 @@ +class TransactionsController < ApplicationController + before_action :set_transaction, only: [:show, :edit, :update, :destroy] + + # GET /transactions + # GET /transactions.json + def index + @transactions = Transaction.all + end + + # GET /transactions/1 + # GET /transactions/1.json + def show + end + + # GET /transactions/new + def new + @transaction = Transaction.new + end + + # GET /transactions/1/edit + def edit + end + + # POST /transactions + # POST /transactions.json + def create + @transaction = Transaction.new(transaction_params) + + respond_to do |format| + if @transaction.save + format.html { redirect_to @transaction, notice: 'Transaction was successfully created.' } + format.json { render action: 'show', status: :created, location: @transaction } + else + format.html { render action: 'new' } + format.json { render json: @transaction.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /transactions/1 + # PATCH/PUT /transactions/1.json + def update + respond_to do |format| + if @transaction.update(transaction_params) + format.html { redirect_to @transaction, notice: 'Transaction was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @transaction.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /transactions/1 + # DELETE /transactions/1.json + def destroy + @transaction.destroy + respond_to do |format| + format.html { redirect_to transactions_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_transaction + @transaction = Transaction.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def transaction_params + params.require(:transaction).permit(:created, :paid, :amount, :currency, :refunded, :customer_id) + end +end diff --git a/source/exampleApp/app/helpers/credit_cards_helper.rb b/source/exampleApp/app/helpers/credit_cards_helper.rb deleted file mode 100644 index 81ecfe1b9..000000000 --- a/source/exampleApp/app/helpers/credit_cards_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CreditCardsHelper -end diff --git a/source/exampleApp/app/helpers/transactions_helper.rb b/source/exampleApp/app/helpers/transactions_helper.rb new file mode 100644 index 000000000..36098d124 --- /dev/null +++ b/source/exampleApp/app/helpers/transactions_helper.rb @@ -0,0 +1,2 @@ +module TransactionsHelper +end diff --git a/source/exampleApp/app/models/credit_card.rb b/source/exampleApp/app/models/credit_card.rb deleted file mode 100644 index dcf5581f9..000000000 --- a/source/exampleApp/app/models/credit_card.rb +++ /dev/null @@ -1,3 +0,0 @@ -class CreditCard < ActiveRecord::Base - belongs_to :customer -end diff --git a/source/exampleApp/app/models/transaction.rb b/source/exampleApp/app/models/transaction.rb new file mode 100644 index 000000000..7ff402642 --- /dev/null +++ b/source/exampleApp/app/models/transaction.rb @@ -0,0 +1,3 @@ +class Transaction < ActiveRecord::Base + belongs_to :customer +end diff --git a/source/exampleApp/app/views/credit_cards/edit.html.erb b/source/exampleApp/app/views/credit_cards/edit.html.erb deleted file mode 100644 index e27f0b85e..000000000 --- a/source/exampleApp/app/views/credit_cards/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing credit_card

- -<%= render 'form' %> - -<%= link_to 'Show', @credit_card %> | -<%= link_to 'Back', credit_cards_path %> diff --git a/source/exampleApp/app/views/credit_cards/index.html.erb b/source/exampleApp/app/views/credit_cards/index.html.erb deleted file mode 100644 index 8dcb1a3a3..000000000 --- a/source/exampleApp/app/views/credit_cards/index.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -

Listing credit_cards

- - - - - - - - - - - - - - - - - - <% @credit_cards.each do |credit_card| %> - - - - - - - - - - - - <% end %> - -
CreatedPaidAmountCurrencyRefundedCustomer
<%= credit_card.created %><%= credit_card.paid %><%= credit_card.amount %><%= credit_card.currency %><%= credit_card.refunded %><%= credit_card.customer %><%= link_to 'Show', credit_card %><%= link_to 'Edit', edit_credit_card_path(credit_card) %><%= link_to 'Destroy', credit_card, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Credit card', new_credit_card_path %> diff --git a/source/exampleApp/app/views/credit_cards/index.json.jbuilder b/source/exampleApp/app/views/credit_cards/index.json.jbuilder deleted file mode 100644 index e075a52ff..000000000 --- a/source/exampleApp/app/views/credit_cards/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@credit_cards) do |credit_card| - json.extract! credit_card, :id, :created, :paid, :amount, :currency, :refunded, :customer_id - json.url credit_card_url(credit_card, format: :json) -end diff --git a/source/exampleApp/app/views/credit_cards/new.html.erb b/source/exampleApp/app/views/credit_cards/new.html.erb deleted file mode 100644 index ec8d8e648..000000000 --- a/source/exampleApp/app/views/credit_cards/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New credit_card

- -<%= render 'form' %> - -<%= link_to 'Back', credit_cards_path %> diff --git a/source/exampleApp/app/views/credit_cards/show.html.erb b/source/exampleApp/app/views/credit_cards/show.html.erb deleted file mode 100644 index 90a6a5c61..000000000 --- a/source/exampleApp/app/views/credit_cards/show.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -

<%= notice %>

- -

- Created: - <%= @credit_card.created %> -

- -

- Paid: - <%= @credit_card.paid %> -

- -

- Amount: - <%= @credit_card.amount %> -

- -

- Currency: - <%= @credit_card.currency %> -

- -

- Refunded: - <%= @credit_card.refunded %> -

- -

- Customer: - <%= @credit_card.customer %> -

- -<%= link_to 'Edit', edit_credit_card_path(@credit_card) %> | -<%= link_to 'Back', credit_cards_path %> diff --git a/source/exampleApp/app/views/credit_cards/show.json.jbuilder b/source/exampleApp/app/views/credit_cards/show.json.jbuilder deleted file mode 100644 index a70a7ecaf..000000000 --- a/source/exampleApp/app/views/credit_cards/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @credit_card, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/exampleApp/app/views/credit_cards/_form.html.erb b/source/exampleApp/app/views/transactions/_form.html.erb similarity index 75% rename from source/exampleApp/app/views/credit_cards/_form.html.erb rename to source/exampleApp/app/views/transactions/_form.html.erb index 6c942724e..3c321b443 100644 --- a/source/exampleApp/app/views/credit_cards/_form.html.erb +++ b/source/exampleApp/app/views/transactions/_form.html.erb @@ -1,10 +1,10 @@ -<%= form_for(@credit_card) do |f| %> - <% if @credit_card.errors.any? %> +<%= form_for(@transaction) do |f| %> + <% if @transaction.errors.any? %>
-

<%= pluralize(@credit_card.errors.count, "error") %> prohibited this credit_card from being saved:

+

<%= pluralize(@transaction.errors.count, "error") %> prohibited this transaction from being saved:

    - <% @credit_card.errors.full_messages.each do |msg| %> + <% @transaction.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
diff --git a/source/exampleApp/app/views/transactions/edit.html.erb b/source/exampleApp/app/views/transactions/edit.html.erb new file mode 100644 index 000000000..215f599ee --- /dev/null +++ b/source/exampleApp/app/views/transactions/edit.html.erb @@ -0,0 +1,6 @@ +

Editing transaction

+ +<%= render 'form' %> + +<%= link_to 'Show', @transaction %> | +<%= link_to 'Back', transactions_path %> diff --git a/source/exampleApp/app/views/transactions/index.html.erb b/source/exampleApp/app/views/transactions/index.html.erb new file mode 100644 index 000000000..cd805d37d --- /dev/null +++ b/source/exampleApp/app/views/transactions/index.html.erb @@ -0,0 +1,37 @@ +

Listing transactions

+ + + + + + + + + + + + + + + + + + <% @transactions.each do |transaction| %> + + + + + + + + + + + + <% end %> + +
CreatedPaidAmountCurrencyRefundedCustomer
<%= transaction.created %><%= transaction.paid %><%= transaction.amount %><%= transaction.currency %><%= transaction.refunded %><%= transaction.customer %><%= link_to 'Show', transaction %><%= link_to 'Edit', edit_transaction_path(transaction) %><%= link_to 'Destroy', transaction, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Transaction', new_transaction_path %> diff --git a/source/exampleApp/app/views/transactions/index.json.jbuilder b/source/exampleApp/app/views/transactions/index.json.jbuilder new file mode 100644 index 000000000..f8928f841 --- /dev/null +++ b/source/exampleApp/app/views/transactions/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@transactions) do |transaction| + json.extract! transaction, :id, :created, :paid, :amount, :currency, :refunded, :customer_id + json.url transaction_url(transaction, format: :json) +end diff --git a/source/exampleApp/app/views/transactions/new.html.erb b/source/exampleApp/app/views/transactions/new.html.erb new file mode 100644 index 000000000..88e30c7aa --- /dev/null +++ b/source/exampleApp/app/views/transactions/new.html.erb @@ -0,0 +1,5 @@ +

New transaction

+ +<%= render 'form' %> + +<%= link_to 'Back', transactions_path %> diff --git a/source/exampleApp/app/views/transactions/show.html.erb b/source/exampleApp/app/views/transactions/show.html.erb new file mode 100644 index 000000000..a256be3d8 --- /dev/null +++ b/source/exampleApp/app/views/transactions/show.html.erb @@ -0,0 +1,34 @@ +

<%= notice %>

+ +

+ Created: + <%= @transaction.created %> +

+ +

+ Paid: + <%= @transaction.paid %> +

+ +

+ Amount: + <%= @transaction.amount %> +

+ +

+ Currency: + <%= @transaction.currency %> +

+ +

+ Refunded: + <%= @transaction.refunded %> +

+ +

+ Customer: + <%= @transaction.customer %> +

+ +<%= link_to 'Edit', edit_transaction_path(@transaction) %> | +<%= link_to 'Back', transactions_path %> diff --git a/source/exampleApp/app/views/transactions/show.json.jbuilder b/source/exampleApp/app/views/transactions/show.json.jbuilder new file mode 100644 index 000000000..18629b15f --- /dev/null +++ b/source/exampleApp/app/views/transactions/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @transaction, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb index 7ca95f690..d9973cb15 100644 --- a/source/exampleApp/config/routes.rb +++ b/source/exampleApp/config/routes.rb @@ -1,5 +1,5 @@ ExampleApp::Application.routes.draw do - resources :credit_cards + resources :transactions resources :customers diff --git a/source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb b/source/exampleApp/db/migrate/20210420033157_create_transactions.rb similarity index 77% rename from source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb rename to source/exampleApp/db/migrate/20210420033157_create_transactions.rb index 9cd19d92a..0d8685432 100644 --- a/source/exampleApp/db/migrate/20210420031843_create_credit_cards.rb +++ b/source/exampleApp/db/migrate/20210420033157_create_transactions.rb @@ -1,6 +1,6 @@ -class CreateCreditCards < ActiveRecord::Migration +class CreateTransactions < ActiveRecord::Migration def change - create_table :credit_cards do |t| + create_table :transactions do |t| t.integer :created, null: false t.boolean :paid, null: false, default: false t.decimal :amount diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb index 31bea5d09..ea89ed538 100644 --- a/source/exampleApp/db/schema.rb +++ b/source/exampleApp/db/schema.rb @@ -11,29 +11,9 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20210420031843) do +ActiveRecord::Schema.define(version: 0) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "credit_cards", force: true do |t| - t.integer "created", null: false - t.boolean "paid", default: false, null: false - t.decimal "amount" - t.string "currency", null: false - t.boolean "refunded", default: false, null: false - t.integer "customer_id", null: false - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "credit_cards", ["customer_id"], name: "index_credit_cards_on_customer_id", using: :btree - - create_table "customers", force: true do |t| - t.string "firstName", limit: 50, null: false - t.string "lastName", limit: 50, null: false - t.datetime "created_at" - t.datetime "updated_at" - end - end diff --git a/source/exampleApp/db/seeds.rb b/source/exampleApp/db/seeds.rb index 31190f2e1..b51db0ba7 100644 --- a/source/exampleApp/db/seeds.rb +++ b/source/exampleApp/db/seeds.rb @@ -9,4 +9,19 @@ Customer.create(firstName: "Johny", lastName: "Flow") Customer.create(firstName: "Raj", lastName: "Jamnis") Customer.create(firstName: "Andrew", lastName: "Chung") -Customer.create(firstName: "Mike", lastName: "Smith") \ No newline at end of file +Customer.create(firstName: "Mike", lastName: "Smith") + +CreditCards.create() +10 Should be successful transactions: + - 5 Should be linked to Customer 1 + - 3 Should be linked to Customer 2 + - 1 Should be linked to Customer 3 + - 1 Should be linked to Customer 4 + +5 Should be transactions that failed: + - 3 Should be linked to Customer 3 + - 2 Should be linked to Customer 4 + +5 should be disputed: + - 3 should be linked to Customer 1 + - 2 should be linked to customer 2 \ No newline at end of file From 5305227c4a8131519a4c5bc47f4f70284b148a11 Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:33:31 -0400 Subject: [PATCH 09/40] Migrate customers and transactions --- source/exampleApp/db/schema.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb index ea89ed538..34a1f8ba6 100644 --- a/source/exampleApp/db/schema.rb +++ b/source/exampleApp/db/schema.rb @@ -11,9 +11,29 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do +ActiveRecord::Schema.define(version: 20210420033157) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "customers", force: true do |t| + t.string "firstName", limit: 50, null: false + t.string "lastName", limit: 50, null: false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "transactions", force: true do |t| + t.integer "created", null: false + t.boolean "paid", default: false, null: false + t.decimal "amount" + t.string "currency", null: false + t.boolean "refunded", default: false, null: false + t.integer "customer_id", null: false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "transactions", ["customer_id"], name: "index_transactions_on_customer_id", using: :btree + end From b2ad5445f0bd9f82736f03cea5589cbe3a4be15d Mon Sep 17 00:00:00 2001 From: abdelp Date: Mon, 19 Apr 2021 23:40:59 -0400 Subject: [PATCH 10/40] Remove and recreate customers scaffold to not use camelCase for its columns --- source/exampleApp/app/controllers/customers_controller.rb | 2 +- source/exampleApp/app/views/customers/_form.html.erb | 8 ++++---- source/exampleApp/app/views/customers/index.html.erb | 8 ++++---- source/exampleApp/app/views/customers/index.json.jbuilder | 2 +- source/exampleApp/app/views/customers/show.html.erb | 8 ++++---- source/exampleApp/app/views/customers/show.json.jbuilder | 2 +- source/exampleApp/config/routes.rb | 4 ++-- .../db/migrate/20210420033157_create_transactions.rb | 2 +- ...te_customers.rb => 20210420034344_create_customers.rb} | 4 ++-- source/exampleApp/db/schema.rb | 8 ++++---- 10 files changed, 24 insertions(+), 24 deletions(-) rename source/exampleApp/db/migrate/{20210420030808_create_customers.rb => 20210420034344_create_customers.rb} (57%) diff --git a/source/exampleApp/app/controllers/customers_controller.rb b/source/exampleApp/app/controllers/customers_controller.rb index c7cb97e0d..0210a69a7 100644 --- a/source/exampleApp/app/controllers/customers_controller.rb +++ b/source/exampleApp/app/controllers/customers_controller.rb @@ -69,6 +69,6 @@ def set_customer # Never trust parameters from the scary internet, only allow the white list through. def customer_params - params.require(:customer).permit(:firstName, :lastName) + params.require(:customer).permit(:first_name, :last_name) end end diff --git a/source/exampleApp/app/views/customers/_form.html.erb b/source/exampleApp/app/views/customers/_form.html.erb index e70f94f06..f2db3db1e 100644 --- a/source/exampleApp/app/views/customers/_form.html.erb +++ b/source/exampleApp/app/views/customers/_form.html.erb @@ -12,12 +12,12 @@ <% end %>
- <%= f.label :firstName %>
- <%= f.text_field :firstName %> + <%= f.label :first_name %>
+ <%= f.text_field :first_name %>
- <%= f.label :lastName %>
- <%= f.text_field :lastName %> + <%= f.label :last_name %>
+ <%= f.text_field :last_name %>
<%= f.submit %> diff --git a/source/exampleApp/app/views/customers/index.html.erb b/source/exampleApp/app/views/customers/index.html.erb index d03841d83..47ea166c8 100644 --- a/source/exampleApp/app/views/customers/index.html.erb +++ b/source/exampleApp/app/views/customers/index.html.erb @@ -3,8 +3,8 @@ - - + + @@ -14,8 +14,8 @@ <% @customers.each do |customer| %> - - + + diff --git a/source/exampleApp/app/views/customers/index.json.jbuilder b/source/exampleApp/app/views/customers/index.json.jbuilder index a17bbce62..6aac73b4c 100644 --- a/source/exampleApp/app/views/customers/index.json.jbuilder +++ b/source/exampleApp/app/views/customers/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@customers) do |customer| - json.extract! customer, :id, :firstName, :lastName + json.extract! customer, :id, :first_name, :last_name json.url customer_url(customer, format: :json) end diff --git a/source/exampleApp/app/views/customers/show.html.erb b/source/exampleApp/app/views/customers/show.html.erb index aaaf88cee..cacd47343 100644 --- a/source/exampleApp/app/views/customers/show.html.erb +++ b/source/exampleApp/app/views/customers/show.html.erb @@ -1,13 +1,13 @@

<%= notice %>

- Firstname: - <%= @customer.firstName %> + First name: + <%= @customer.first_name %>

- Lastname: - <%= @customer.lastName %> + Last name: + <%= @customer.last_name %>

<%= link_to 'Edit', edit_customer_path(@customer) %> | diff --git a/source/exampleApp/app/views/customers/show.json.jbuilder b/source/exampleApp/app/views/customers/show.json.jbuilder index 65e08441c..a7698de6a 100644 --- a/source/exampleApp/app/views/customers/show.json.jbuilder +++ b/source/exampleApp/app/views/customers/show.json.jbuilder @@ -1 +1 @@ -json.extract! @customer, :id, :firstName, :lastName, :created_at, :updated_at +json.extract! @customer, :id, :first_name, :last_name, :created_at, :updated_at diff --git a/source/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb index d9973cb15..b18da3b89 100644 --- a/source/exampleApp/config/routes.rb +++ b/source/exampleApp/config/routes.rb @@ -1,8 +1,8 @@ ExampleApp::Application.routes.draw do - resources :transactions - resources :customers + resources :transactions + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/source/exampleApp/db/migrate/20210420033157_create_transactions.rb b/source/exampleApp/db/migrate/20210420033157_create_transactions.rb index 0d8685432..c7f625ed1 100644 --- a/source/exampleApp/db/migrate/20210420033157_create_transactions.rb +++ b/source/exampleApp/db/migrate/20210420033157_create_transactions.rb @@ -1,7 +1,7 @@ class CreateTransactions < ActiveRecord::Migration def change create_table :transactions do |t| - t.integer :created, null: false + t.integer :created, null: false, default: "extract('epoch' from CURRENT_TIMESTAMP)::bigint" t.boolean :paid, null: false, default: false t.decimal :amount t.string :currency, null: false diff --git a/source/exampleApp/db/migrate/20210420030808_create_customers.rb b/source/exampleApp/db/migrate/20210420034344_create_customers.rb similarity index 57% rename from source/exampleApp/db/migrate/20210420030808_create_customers.rb rename to source/exampleApp/db/migrate/20210420034344_create_customers.rb index 3dd2d031a..f17897892 100644 --- a/source/exampleApp/db/migrate/20210420030808_create_customers.rb +++ b/source/exampleApp/db/migrate/20210420034344_create_customers.rb @@ -1,8 +1,8 @@ class CreateCustomers < ActiveRecord::Migration def change create_table :customers do |t| - t.string :firstName, null: false, limit: 50 - t.string :lastName, null: false, limit: 50 + t.string :first_name, null: false, limit: 50 + t.string :last_name, null: false, limit: 50 t.timestamps end diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb index 34a1f8ba6..c2fe3f50a 100644 --- a/source/exampleApp/db/schema.rb +++ b/source/exampleApp/db/schema.rb @@ -11,20 +11,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20210420033157) do +ActiveRecord::Schema.define(version: 20210420034344) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "customers", force: true do |t| - t.string "firstName", limit: 50, null: false - t.string "lastName", limit: 50, null: false + t.string "first_name", limit: 50, null: false + t.string "last_name", limit: 50, null: false t.datetime "created_at" t.datetime "updated_at" end create_table "transactions", force: true do |t| - t.integer "created", null: false + t.integer "created", default: 0, null: false t.boolean "paid", default: false, null: false t.decimal "amount" t.string "currency", null: false From b360126e5420260f2b9e78c179b614249980249e Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 00:22:48 -0400 Subject: [PATCH 11/40] Add default value for Transactions --- .../db/migrate/20210420033157_create_transactions.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/exampleApp/db/migrate/20210420033157_create_transactions.rb b/source/exampleApp/db/migrate/20210420033157_create_transactions.rb index c7f625ed1..3a26295ed 100644 --- a/source/exampleApp/db/migrate/20210420033157_create_transactions.rb +++ b/source/exampleApp/db/migrate/20210420033157_create_transactions.rb @@ -1,14 +1,23 @@ class CreateTransactions < ActiveRecord::Migration def change create_table :transactions do |t| - t.integer :created, null: false, default: "extract('epoch' from CURRENT_TIMESTAMP)::bigint" + t.integer :created, null: false t.boolean :paid, null: false, default: false t.decimal :amount t.string :currency, null: false t.boolean :refunded, null: false, default: false t.references :customer, index: true, null: false + t.timestamps end + reversible do |dir| + dir.up do + execute <<-SQL + ALTER TABLE transactions + ALTER COLUMN created SET DEFAULT date_part('epoch', current_timestamp); + SQL + end + end end end From fbfd0e4ba61e67f0e0b56e1ea0f273085144654f Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 00:34:32 -0400 Subject: [PATCH 12/40] Remove default value from transaction created in schema --- source/exampleApp/db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb index c2fe3f50a..83f7777c6 100644 --- a/source/exampleApp/db/schema.rb +++ b/source/exampleApp/db/schema.rb @@ -24,7 +24,7 @@ end create_table "transactions", force: true do |t| - t.integer "created", default: 0, null: false + t.integer "created", null: false t.boolean "paid", default: false, null: false t.decimal "amount" t.string "currency", null: false From 7dd243c64de467cb5787340df92937d1f5841ce8 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 00:35:28 -0400 Subject: [PATCH 13/40] Downgrade turbolinks to avoid include NoMethodError --- source/exampleApp/Gemfile | 3 ++- source/exampleApp/Gemfile.lock | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/exampleApp/Gemfile b/source/exampleApp/Gemfile index 23ce4c3ff..95c5d0d87 100644 --- a/source/exampleApp/Gemfile +++ b/source/exampleApp/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' +ruby "2.0.0" # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.0.0' @@ -22,7 +23,7 @@ gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' +gem 'turbolinks', '~> 1.3' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 1.2' diff --git a/source/exampleApp/Gemfile.lock b/source/exampleApp/Gemfile.lock index 064b6066d..850b66728 100644 --- a/source/exampleApp/Gemfile.lock +++ b/source/exampleApp/Gemfile.lock @@ -95,9 +95,8 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - turbolinks (5.2.1) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) + turbolinks (1.3.1) + coffee-rails tzinfo (0.3.60) uglifier (4.2.0) execjs (>= 0.3.0, < 3) @@ -113,8 +112,11 @@ DEPENDENCIES rails (= 4.0.0) sass-rails (~> 4.0.0) sdoc - turbolinks + turbolinks (~> 1.3) uglifier (>= 1.3.0) +RUBY VERSION + ruby 2.0.0p648 + BUNDLED WITH 1.17.3 From 6e8e5a86bd794787cf688b8bf10d12e1f3a4e82c Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 00:59:03 -0400 Subject: [PATCH 14/40] Rename Transactions to Charges --- ...ansactions.js.coffee => charges.js.coffee} | 0 ...transactions.css.scss => charges.css.scss} | 2 +- .../app/controllers/charges_controller.rb | 74 +++++++++++++++++++ .../controllers/transactions_controller.rb | 74 ------------------- .../exampleApp/app/helpers/charges_helper.rb | 2 + .../app/helpers/transactions_helper.rb | 2 - source/exampleApp/app/models/charge.rb | 3 + source/exampleApp/app/models/transaction.rb | 3 - .../{transactions => charges}/_form.html.erb | 8 +- .../app/views/charges/edit.html.erb | 6 ++ .../app/views/charges/index.html.erb | 37 ++++++++++ .../app/views/charges/index.json.jbuilder | 4 + .../exampleApp/app/views/charges/new.html.erb | 5 ++ .../app/views/charges/show.html.erb | 34 +++++++++ .../app/views/charges/show.json.jbuilder | 1 + .../app/views/transactions/edit.html.erb | 6 -- .../app/views/transactions/index.html.erb | 37 ---------- .../views/transactions/index.json.jbuilder | 4 - .../app/views/transactions/new.html.erb | 5 -- .../app/views/transactions/show.html.erb | 34 --------- .../app/views/transactions/show.json.jbuilder | 1 - source/exampleApp/config/routes.rb | 4 +- ...ns.rb => 20210420045643_create_charges.rb} | 7 +- source/exampleApp/db/schema.rb | 20 ++--- 24 files changed, 186 insertions(+), 187 deletions(-) rename source/exampleApp/app/assets/javascripts/{transactions.js.coffee => charges.js.coffee} (100%) rename source/exampleApp/app/assets/stylesheets/{transactions.css.scss => charges.css.scss} (62%) create mode 100644 source/exampleApp/app/controllers/charges_controller.rb delete mode 100644 source/exampleApp/app/controllers/transactions_controller.rb create mode 100644 source/exampleApp/app/helpers/charges_helper.rb delete mode 100644 source/exampleApp/app/helpers/transactions_helper.rb create mode 100644 source/exampleApp/app/models/charge.rb delete mode 100644 source/exampleApp/app/models/transaction.rb rename source/exampleApp/app/views/{transactions => charges}/_form.html.erb (75%) create mode 100644 source/exampleApp/app/views/charges/edit.html.erb create mode 100644 source/exampleApp/app/views/charges/index.html.erb create mode 100644 source/exampleApp/app/views/charges/index.json.jbuilder create mode 100644 source/exampleApp/app/views/charges/new.html.erb create mode 100644 source/exampleApp/app/views/charges/show.html.erb create mode 100644 source/exampleApp/app/views/charges/show.json.jbuilder delete mode 100644 source/exampleApp/app/views/transactions/edit.html.erb delete mode 100644 source/exampleApp/app/views/transactions/index.html.erb delete mode 100644 source/exampleApp/app/views/transactions/index.json.jbuilder delete mode 100644 source/exampleApp/app/views/transactions/new.html.erb delete mode 100644 source/exampleApp/app/views/transactions/show.html.erb delete mode 100644 source/exampleApp/app/views/transactions/show.json.jbuilder rename source/exampleApp/db/migrate/{20210420033157_create_transactions.rb => 20210420045643_create_charges.rb} (78%) diff --git a/source/exampleApp/app/assets/javascripts/transactions.js.coffee b/source/exampleApp/app/assets/javascripts/charges.js.coffee similarity index 100% rename from source/exampleApp/app/assets/javascripts/transactions.js.coffee rename to source/exampleApp/app/assets/javascripts/charges.js.coffee diff --git a/source/exampleApp/app/assets/stylesheets/transactions.css.scss b/source/exampleApp/app/assets/stylesheets/charges.css.scss similarity index 62% rename from source/exampleApp/app/assets/stylesheets/transactions.css.scss rename to source/exampleApp/app/assets/stylesheets/charges.css.scss index f93ff9762..c3a893042 100644 --- a/source/exampleApp/app/assets/stylesheets/transactions.css.scss +++ b/source/exampleApp/app/assets/stylesheets/charges.css.scss @@ -1,3 +1,3 @@ -// Place all the styles related to the Transactions controller here. +// Place all the styles related to the Charges controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/exampleApp/app/controllers/charges_controller.rb b/source/exampleApp/app/controllers/charges_controller.rb new file mode 100644 index 000000000..5c57af40d --- /dev/null +++ b/source/exampleApp/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 + 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 action: 'show', status: :created, location: @charge } + else + format.html { render action: '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 { head :no_content } + else + format.html { render action: '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 } + 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, :currency, :refunded, :customer_id) + end +end diff --git a/source/exampleApp/app/controllers/transactions_controller.rb b/source/exampleApp/app/controllers/transactions_controller.rb deleted file mode 100644 index 4d8b2dfaf..000000000 --- a/source/exampleApp/app/controllers/transactions_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -class TransactionsController < ApplicationController - before_action :set_transaction, only: [:show, :edit, :update, :destroy] - - # GET /transactions - # GET /transactions.json - def index - @transactions = Transaction.all - end - - # GET /transactions/1 - # GET /transactions/1.json - def show - end - - # GET /transactions/new - def new - @transaction = Transaction.new - end - - # GET /transactions/1/edit - def edit - end - - # POST /transactions - # POST /transactions.json - def create - @transaction = Transaction.new(transaction_params) - - respond_to do |format| - if @transaction.save - format.html { redirect_to @transaction, notice: 'Transaction was successfully created.' } - format.json { render action: 'show', status: :created, location: @transaction } - else - format.html { render action: 'new' } - format.json { render json: @transaction.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /transactions/1 - # PATCH/PUT /transactions/1.json - def update - respond_to do |format| - if @transaction.update(transaction_params) - format.html { redirect_to @transaction, notice: 'Transaction was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @transaction.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /transactions/1 - # DELETE /transactions/1.json - def destroy - @transaction.destroy - respond_to do |format| - format.html { redirect_to transactions_url } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_transaction - @transaction = Transaction.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def transaction_params - params.require(:transaction).permit(:created, :paid, :amount, :currency, :refunded, :customer_id) - end -end diff --git a/source/exampleApp/app/helpers/charges_helper.rb b/source/exampleApp/app/helpers/charges_helper.rb new file mode 100644 index 000000000..414ee900f --- /dev/null +++ b/source/exampleApp/app/helpers/charges_helper.rb @@ -0,0 +1,2 @@ +module ChargesHelper +end diff --git a/source/exampleApp/app/helpers/transactions_helper.rb b/source/exampleApp/app/helpers/transactions_helper.rb deleted file mode 100644 index 36098d124..000000000 --- a/source/exampleApp/app/helpers/transactions_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module TransactionsHelper -end diff --git a/source/exampleApp/app/models/charge.rb b/source/exampleApp/app/models/charge.rb new file mode 100644 index 000000000..c17f5e99d --- /dev/null +++ b/source/exampleApp/app/models/charge.rb @@ -0,0 +1,3 @@ +class Charge < ActiveRecord::Base + belongs_to :customer +end diff --git a/source/exampleApp/app/models/transaction.rb b/source/exampleApp/app/models/transaction.rb deleted file mode 100644 index 7ff402642..000000000 --- a/source/exampleApp/app/models/transaction.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Transaction < ActiveRecord::Base - belongs_to :customer -end diff --git a/source/exampleApp/app/views/transactions/_form.html.erb b/source/exampleApp/app/views/charges/_form.html.erb similarity index 75% rename from source/exampleApp/app/views/transactions/_form.html.erb rename to source/exampleApp/app/views/charges/_form.html.erb index 3c321b443..f818a123a 100644 --- a/source/exampleApp/app/views/transactions/_form.html.erb +++ b/source/exampleApp/app/views/charges/_form.html.erb @@ -1,10 +1,10 @@ -<%= form_for(@transaction) do |f| %> - <% if @transaction.errors.any? %> +<%= form_for(@charge) do |f| %> + <% if @charge.errors.any? %>
-

<%= pluralize(@transaction.errors.count, "error") %> prohibited this transaction from being saved:

+

<%= pluralize(@charge.errors.count, "error") %> prohibited this charge from being saved:

    - <% @transaction.errors.full_messages.each do |msg| %> + <% @charge.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
diff --git a/source/exampleApp/app/views/charges/edit.html.erb b/source/exampleApp/app/views/charges/edit.html.erb new file mode 100644 index 000000000..a723d7a86 --- /dev/null +++ b/source/exampleApp/app/views/charges/edit.html.erb @@ -0,0 +1,6 @@ +

Editing charge

+ +<%= render 'form' %> + +<%= link_to 'Show', @charge %> | +<%= link_to 'Back', charges_path %> diff --git a/source/exampleApp/app/views/charges/index.html.erb b/source/exampleApp/app/views/charges/index.html.erb new file mode 100644 index 000000000..38dfa35f4 --- /dev/null +++ b/source/exampleApp/app/views/charges/index.html.erb @@ -0,0 +1,37 @@ +

Listing charges

+ +
FirstnameLastnameFirst nameLast name
<%= customer.firstName %><%= customer.lastName %><%= 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?' } %>
+ + + + + + + + + + + + + + + + <% @charges.each do |charge| %> + + + + + + + + + + + + <% end %> + +
CreatedPaidAmountCurrencyRefundedCustomer
<%= charge.created %><%= charge.paid %><%= charge.amount %><%= charge.currency %><%= charge.refunded %><%= charge.customer %><%= link_to 'Show', charge %><%= link_to 'Edit', edit_charge_path(charge) %><%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Charge', new_charge_path %> diff --git a/source/exampleApp/app/views/charges/index.json.jbuilder b/source/exampleApp/app/views/charges/index.json.jbuilder new file mode 100644 index 000000000..9b184d029 --- /dev/null +++ b/source/exampleApp/app/views/charges/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@charges) do |charge| + json.extract! charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id + json.url charge_url(charge, format: :json) +end diff --git a/source/exampleApp/app/views/charges/new.html.erb b/source/exampleApp/app/views/charges/new.html.erb new file mode 100644 index 000000000..8dc59a97d --- /dev/null +++ b/source/exampleApp/app/views/charges/new.html.erb @@ -0,0 +1,5 @@ +

New charge

+ +<%= render 'form' %> + +<%= link_to 'Back', charges_path %> diff --git a/source/exampleApp/app/views/charges/show.html.erb b/source/exampleApp/app/views/charges/show.html.erb new file mode 100644 index 000000000..551d274bb --- /dev/null +++ b/source/exampleApp/app/views/charges/show.html.erb @@ -0,0 +1,34 @@ +

<%= notice %>

+ +

+ Created: + <%= @charge.created %> +

+ +

+ Paid: + <%= @charge.paid %> +

+ +

+ Amount: + <%= @charge.amount %> +

+ +

+ Currency: + <%= @charge.currency %> +

+ +

+ Refunded: + <%= @charge.refunded %> +

+ +

+ Customer: + <%= @charge.customer %> +

+ +<%= link_to 'Edit', edit_charge_path(@charge) %> | +<%= link_to 'Back', charges_path %> diff --git a/source/exampleApp/app/views/charges/show.json.jbuilder b/source/exampleApp/app/views/charges/show.json.jbuilder new file mode 100644 index 000000000..8e1676c10 --- /dev/null +++ b/source/exampleApp/app/views/charges/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/exampleApp/app/views/transactions/edit.html.erb b/source/exampleApp/app/views/transactions/edit.html.erb deleted file mode 100644 index 215f599ee..000000000 --- a/source/exampleApp/app/views/transactions/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing transaction

- -<%= render 'form' %> - -<%= link_to 'Show', @transaction %> | -<%= link_to 'Back', transactions_path %> diff --git a/source/exampleApp/app/views/transactions/index.html.erb b/source/exampleApp/app/views/transactions/index.html.erb deleted file mode 100644 index cd805d37d..000000000 --- a/source/exampleApp/app/views/transactions/index.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -

Listing transactions

- - - - - - - - - - - - - - - - - - <% @transactions.each do |transaction| %> - - - - - - - - - - - - <% end %> - -
CreatedPaidAmountCurrencyRefundedCustomer
<%= transaction.created %><%= transaction.paid %><%= transaction.amount %><%= transaction.currency %><%= transaction.refunded %><%= transaction.customer %><%= link_to 'Show', transaction %><%= link_to 'Edit', edit_transaction_path(transaction) %><%= link_to 'Destroy', transaction, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Transaction', new_transaction_path %> diff --git a/source/exampleApp/app/views/transactions/index.json.jbuilder b/source/exampleApp/app/views/transactions/index.json.jbuilder deleted file mode 100644 index f8928f841..000000000 --- a/source/exampleApp/app/views/transactions/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@transactions) do |transaction| - json.extract! transaction, :id, :created, :paid, :amount, :currency, :refunded, :customer_id - json.url transaction_url(transaction, format: :json) -end diff --git a/source/exampleApp/app/views/transactions/new.html.erb b/source/exampleApp/app/views/transactions/new.html.erb deleted file mode 100644 index 88e30c7aa..000000000 --- a/source/exampleApp/app/views/transactions/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New transaction

- -<%= render 'form' %> - -<%= link_to 'Back', transactions_path %> diff --git a/source/exampleApp/app/views/transactions/show.html.erb b/source/exampleApp/app/views/transactions/show.html.erb deleted file mode 100644 index a256be3d8..000000000 --- a/source/exampleApp/app/views/transactions/show.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -

<%= notice %>

- -

- Created: - <%= @transaction.created %> -

- -

- Paid: - <%= @transaction.paid %> -

- -

- Amount: - <%= @transaction.amount %> -

- -

- Currency: - <%= @transaction.currency %> -

- -

- Refunded: - <%= @transaction.refunded %> -

- -

- Customer: - <%= @transaction.customer %> -

- -<%= link_to 'Edit', edit_transaction_path(@transaction) %> | -<%= link_to 'Back', transactions_path %> diff --git a/source/exampleApp/app/views/transactions/show.json.jbuilder b/source/exampleApp/app/views/transactions/show.json.jbuilder deleted file mode 100644 index 18629b15f..000000000 --- a/source/exampleApp/app/views/transactions/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @transaction, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb index b18da3b89..bf48e892d 100644 --- a/source/exampleApp/config/routes.rb +++ b/source/exampleApp/config/routes.rb @@ -1,7 +1,7 @@ ExampleApp::Application.routes.draw do - resources :customers + resources :charges - resources :transactions + resources :customers # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/source/exampleApp/db/migrate/20210420033157_create_transactions.rb b/source/exampleApp/db/migrate/20210420045643_create_charges.rb similarity index 78% rename from source/exampleApp/db/migrate/20210420033157_create_transactions.rb rename to source/exampleApp/db/migrate/20210420045643_create_charges.rb index 3a26295ed..9c50d5b5e 100644 --- a/source/exampleApp/db/migrate/20210420033157_create_transactions.rb +++ b/source/exampleApp/db/migrate/20210420045643_create_charges.rb @@ -1,6 +1,6 @@ -class CreateTransactions < ActiveRecord::Migration +class CreateCharges < ActiveRecord::Migration def change - create_table :transactions do |t| + create_table :charges do |t| t.integer :created, null: false t.boolean :paid, null: false, default: false t.decimal :amount @@ -8,13 +8,12 @@ def change t.boolean :refunded, null: false, default: false t.references :customer, index: true, null: false - t.timestamps end reversible do |dir| dir.up do execute <<-SQL - ALTER TABLE transactions + ALTER TABLE charges ALTER COLUMN created SET DEFAULT date_part('epoch', current_timestamp); SQL end diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb index 83f7777c6..5485080e2 100644 --- a/source/exampleApp/db/schema.rb +++ b/source/exampleApp/db/schema.rb @@ -11,19 +11,12 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20210420034344) do +ActiveRecord::Schema.define(version: 20210420045643) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "customers", force: true do |t| - t.string "first_name", limit: 50, null: false - t.string "last_name", limit: 50, null: false - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "transactions", force: true do |t| + create_table "charges", force: true do |t| t.integer "created", null: false t.boolean "paid", default: false, null: false t.decimal "amount" @@ -34,6 +27,13 @@ t.datetime "updated_at" end - add_index "transactions", ["customer_id"], name: "index_transactions_on_customer_id", using: :btree + add_index "charges", ["customer_id"], name: "index_charges_on_customer_id", using: :btree + + create_table "customers", force: true do |t| + t.string "first_name", limit: 50, null: false + t.string "last_name", limit: 50, null: false + t.datetime "created_at" + t.datetime "updated_at" + end end From b06c82705b8e03cd78a1bb881ad86d52a61a1d51 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 01:47:28 -0400 Subject: [PATCH 15/40] Add charge scopes for failed, disputed, successful --- source/exampleApp/app/models/charge.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/exampleApp/app/models/charge.rb b/source/exampleApp/app/models/charge.rb index c17f5e99d..a99021ced 100644 --- a/source/exampleApp/app/models/charge.rb +++ b/source/exampleApp/app/models/charge.rb @@ -1,3 +1,10 @@ class Charge < ActiveRecord::Base belongs_to :customer + + # we can put indexes on columns to make the queries faster + + scope :failed, -> { where("NOT paid") } + scope :disputed, -> { where("refunded") } + scope :successful, -> { where("paid") } + end From 0db129688919ef1138612935e57fc18375f42ca3 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 01:47:54 -0400 Subject: [PATCH 16/40] Add charge partial --- source/exampleApp/app/views/charges/_charge.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 source/exampleApp/app/views/charges/_charge.html.erb diff --git a/source/exampleApp/app/views/charges/_charge.html.erb b/source/exampleApp/app/views/charges/_charge.html.erb new file mode 100644 index 000000000..76d341137 --- /dev/null +++ b/source/exampleApp/app/views/charges/_charge.html.erb @@ -0,0 +1,12 @@ + + <%= charge.created %> + <%= charge.paid %> + <%= charge.amount %> + <%= charge.currency %> + <%= charge.refunded %> + <%# full name can go in a helper %> + <%= charge.customer.first_name %> + <%= link_to 'Show', charge %> + <%= link_to 'Edit', edit_charge_path(charge) %> + <%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %> + \ No newline at end of file From 1e2169ce0d9bc0a4796bb822fc2d3b219934d560 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 01:48:09 -0400 Subject: [PATCH 17/40] Add charges partial --- .../app/views/charges/_charges.html.erb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 source/exampleApp/app/views/charges/_charges.html.erb diff --git a/source/exampleApp/app/views/charges/_charges.html.erb b/source/exampleApp/app/views/charges/_charges.html.erb new file mode 100644 index 000000000..b16178dcd --- /dev/null +++ b/source/exampleApp/app/views/charges/_charges.html.erb @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + <%= render partial: 'charge', collection: charges %> + +
CreatedPaidAmountCurrencyRefundedCustomer
\ No newline at end of file From e258aa2e96e0759a05a6ea5d11811596a23765a2 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 01:48:47 -0400 Subject: [PATCH 18/40] Update table for charges partial instead --- .../app/views/charges/index.html.erb | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/source/exampleApp/app/views/charges/index.html.erb b/source/exampleApp/app/views/charges/index.html.erb index 38dfa35f4..c51a5c3bc 100644 --- a/source/exampleApp/app/views/charges/index.html.erb +++ b/source/exampleApp/app/views/charges/index.html.erb @@ -1,36 +1,17 @@ -

Listing charges

- - - - - - - - - - - - - - - - - - <% @charges.each do |charge| %> - - - - - - - - - - - - <% end %> - -
CreatedPaidAmountCurrencyRefundedCustomer
<%= charge.created %><%= charge.paid %><%= charge.amount %><%= charge.currency %><%= charge.refunded %><%= charge.customer %><%= link_to 'Show', charge %><%= link_to 'Edit', edit_charge_path(charge) %><%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +<%# we can extract the titles from the scope to assign them to the titles in the partial %> + +

Failed Charges

+ +<%= render partial: 'charges', locals: {charges: @charges.failed} %> + +

Disputed Charges

+ +<%= render partial: 'charges', locals: {charges: @charges.disputed} %> + +

Successful Charges

+ +<%= render partial: 'charges', locals: {charges: @charges.successful} %>
From e7823fc37b8211836781d538f037232c51feac20 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 01:59:50 -0400 Subject: [PATCH 19/40] Add and install rspec 3.10 --- source/exampleApp/Gemfile | 4 ++ source/exampleApp/Gemfile.lock | 15 ++++ source/exampleApp/spec/spec_helper.rb | 100 ++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 source/exampleApp/spec/spec_helper.rb diff --git a/source/exampleApp/Gemfile b/source/exampleApp/Gemfile index 95c5d0d87..0ca41ae74 100644 --- a/source/exampleApp/Gemfile +++ b/source/exampleApp/Gemfile @@ -33,6 +33,10 @@ group :doc do gem 'sdoc', require: false end +group :development do + gem 'rspec', '3.10' +end + # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/source/exampleApp/Gemfile.lock b/source/exampleApp/Gemfile.lock index 850b66728..995852f42 100644 --- a/source/exampleApp/Gemfile.lock +++ b/source/exampleApp/Gemfile.lock @@ -35,6 +35,7 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.8) + diff-lcs (1.4.4) erubis (2.7.0) execjs (2.7.0) hike (1.2.3) @@ -72,6 +73,19 @@ GEM thor (>= 0.18.1, < 2.0) rake (12.3.3) rdoc (5.1.0) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + 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-support (3.10.2) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -110,6 +124,7 @@ DEPENDENCIES jquery-rails pg (~> 0.20.0) rails (= 4.0.0) + rspec (= 3.10) sass-rails (~> 4.0.0) sdoc turbolinks (~> 1.3) diff --git a/source/exampleApp/spec/spec_helper.rb b/source/exampleApp/spec/spec_helper.rb new file mode 100644 index 000000000..251aa5106 --- /dev/null +++ b/source/exampleApp/spec/spec_helper.rb @@ -0,0 +1,100 @@ +# This file was generated by the `rspec --init` 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! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # 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 From 10bfd8e5e954ce5b9441c115997135baa7b8a94a Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 02:01:34 -0400 Subject: [PATCH 20/40] Update seeds to containt failed, disputed and successful charges --- source/exampleApp/db/seeds.rb | 62 ++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/source/exampleApp/db/seeds.rb b/source/exampleApp/db/seeds.rb index b51db0ba7..4b8ca8706 100644 --- a/source/exampleApp/db/seeds.rb +++ b/source/exampleApp/db/seeds.rb @@ -6,22 +6,46 @@ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) -Customer.create(firstName: "Johny", lastName: "Flow") -Customer.create(firstName: "Raj", lastName: "Jamnis") -Customer.create(firstName: "Andrew", lastName: "Chung") -Customer.create(firstName: "Mike", lastName: "Smith") - -CreditCards.create() -10 Should be successful transactions: - - 5 Should be linked to Customer 1 - - 3 Should be linked to Customer 2 - - 1 Should be linked to Customer 3 - - 1 Should be linked to Customer 4 - -5 Should be transactions that failed: - - 3 Should be linked to Customer 3 - - 2 Should be linked to Customer 4 - -5 should be disputed: - - 3 should be linked to Customer 1 - - 2 should be linked to customer 2 \ No newline at end of file +Customer.create(first_name: "Johny", last_name: "Flow") +Customer.create(first_name: "Raj", last_name: "Jamnis") +Customer.create(first_name: "Andrew", last_name: "Chung") +Customer.create(first_name: "Mike", last_name: "Smith") + +# 10 Should be successful Charges: +# - 5 Should be linked to Customer 1 +# - 3 Should be linked to Customer 2 +# - 1 Should be linked to Customer 3 +# - 1 Should be linked to Customer 4 + +Charge.create(paid: true, amount: 10.50, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 150, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 20, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 30, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 45, currency: 'usd', customer_id: 1) + +Charge.create(paid: true, amount: 10.50, currency: 'usd', customer_id: 2) +Charge.create(paid: true, amount: 150, currency: 'usd', customer_id: 2) +Charge.create(paid: true, amount: 20, currency: 'usd', customer_id: 2) + +Charge.create(paid: true, amount: 30, currency: 'usd', customer_id: 3) + +Charge.create(paid: true, amount: 45, currency: 'usd', customer_id: 4) + + +# 5 Should be Charges that failed: +# - 3 Should be linked to Customer 3 +# - 2 Should be linked to Customer 4 + +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) + +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 4) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 4) + +# 5 should be disputed: +# - 3 should be linked to Customer 1 +# - 2 should be linked to customer 2 + +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 1) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 2) From 37515f555f685dbebf62bccc2da029c133f33588 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 02:41:01 -0400 Subject: [PATCH 21/40] Update rspec-core 3.10 gem to rspec-core 3.9 --- source/exampleApp/Gemfile | 3 ++- source/exampleApp/Gemfile.lock | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source/exampleApp/Gemfile b/source/exampleApp/Gemfile index 0ca41ae74..095a67d07 100644 --- a/source/exampleApp/Gemfile +++ b/source/exampleApp/Gemfile @@ -34,7 +34,8 @@ group :doc do end group :development do - gem 'rspec', '3.10' + # bundle exec rake doc:rails generates the API under doc/api. + gem 'rspec-rails', '3.9.1' end # Use ActiveModel has_secure_password diff --git a/source/exampleApp/Gemfile.lock b/source/exampleApp/Gemfile.lock index 995852f42..b8ab1fdf2 100644 --- a/source/exampleApp/Gemfile.lock +++ b/source/exampleApp/Gemfile.lock @@ -73,19 +73,23 @@ GEM thor (>= 0.18.1, < 2.0) rake (12.3.3) rdoc (5.1.0) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) + 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.4) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -124,7 +128,7 @@ DEPENDENCIES jquery-rails pg (~> 0.20.0) rails (= 4.0.0) - rspec (= 3.10) + rspec-rails (= 3.9.1) sass-rails (~> 4.0.0) sdoc turbolinks (~> 1.3) From 3895bc16f5454b161b84813dfa38064cac7a0a4a Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 02:41:24 -0400 Subject: [PATCH 22/40] Add id to charges partial --- source/exampleApp/app/views/charges/_charges.html.erb | 2 +- source/exampleApp/app/views/charges/index.html.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/exampleApp/app/views/charges/_charges.html.erb b/source/exampleApp/app/views/charges/_charges.html.erb index b16178dcd..14dbd36fd 100644 --- a/source/exampleApp/app/views/charges/_charges.html.erb +++ b/source/exampleApp/app/views/charges/_charges.html.erb @@ -1,4 +1,4 @@ - +
> diff --git a/source/exampleApp/app/views/charges/index.html.erb b/source/exampleApp/app/views/charges/index.html.erb index c51a5c3bc..97f24a7f9 100644 --- a/source/exampleApp/app/views/charges/index.html.erb +++ b/source/exampleApp/app/views/charges/index.html.erb @@ -3,15 +3,15 @@

Failed Charges

-<%= render partial: 'charges', locals: {charges: @charges.failed} %> +<%= render partial: 'charges', locals: {id: 'failed-charges', charges: @charges.failed} %>

Disputed Charges

-<%= render partial: 'charges', locals: {charges: @charges.disputed} %> +<%= render partial: 'charges', locals: {id: 'disputed-charges', charges: @charges.disputed} %>

Successful Charges

-<%= render partial: 'charges', locals: {charges: @charges.successful} %> +<%= render partial: 'charges', locals: {id: 'successful-charges', charges: @charges.successful} %>
From 034a7885c24c2f7048723515260dce13aca5168c Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 02:41:44 -0400 Subject: [PATCH 23/40] Install rspec-rails --- source/exampleApp/spec/rails_helper.rb | 63 +++++++++++++++++++ source/exampleApp/spec/spec_helper.rb | 6 +- .../spec/views/charges/index.html.erb_spec.rb | 9 +++ 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 source/exampleApp/spec/rails_helper.rb create mode 100644 source/exampleApp/spec/views/charges/index.html.erb_spec.rb diff --git a/source/exampleApp/spec/rails_helper.rb b/source/exampleApp/spec/rails_helper.rb new file mode 100644 index 000000000..f4fd4d440 --- /dev/null +++ b/source/exampleApp/spec/rails_helper.rb @@ -0,0 +1,63 @@ +# 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')].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.check_pending! +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 + + # 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/exampleApp/spec/spec_helper.rb b/source/exampleApp/spec/spec_helper.rb index 251aa5106..ce33d66df 100644 --- a/source/exampleApp/spec/spec_helper.rb +++ b/source/exampleApp/spec/spec_helper.rb @@ -1,4 +1,4 @@ -# This file was generated by the `rspec --init` command. Conventionally, all +# 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 @@ -66,10 +66,6 @@ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode config.disable_monkey_patching! - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - # 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. diff --git a/source/exampleApp/spec/views/charges/index.html.erb_spec.rb b/source/exampleApp/spec/views/charges/index.html.erb_spec.rb new file mode 100644 index 000000000..f6bdc1ef7 --- /dev/null +++ b/source/exampleApp/spec/views/charges/index.html.erb_spec.rb @@ -0,0 +1,9 @@ +require "rails_helper" + +RSpec.describe "charges/index" do + it "contains a table for successful charges" do + render + + expect(rendered).to match /Failed Charges/ + end +end \ No newline at end of file From 49afed879856ddda9d57444239440269a45b4dae Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 09:43:32 -0400 Subject: [PATCH 24/40] Init app --- source/example-app/.gitignore | 16 ++ source/example-app/Gemfile | 49 ++++++ source/example-app/Gemfile.lock | 139 ++++++++++++++++++ source/example-app/README.rdoc | 28 ++++ source/example-app/Rakefile | 6 + source/example-app/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 16 ++ .../app/assets/stylesheets/application.css | 13 ++ .../app/controllers/application_controller.rb | 5 + .../app/controllers/concerns/.keep | 0 .../app/helpers/application_helper.rb | 2 + source/example-app/app/mailers/.keep | 0 source/example-app/app/models/.keep | 0 source/example-app/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 14 ++ source/example-app/bin/bundle | 3 + source/example-app/bin/rails | 4 + source/example-app/bin/rake | 4 + source/example-app/config.ru | 4 + source/example-app/config/application.rb | 28 ++++ source/example-app/config/boot.rb | 4 + source/example-app/config/database.yml | 60 ++++++++ source/example-app/config/environment.rb | 5 + .../config/environments/development.rb | 29 ++++ .../config/environments/production.rb | 80 ++++++++++ .../example-app/config/environments/test.rb | 36 +++++ .../initializers/backtrace_silencers.rb | 7 + .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 ++ .../config/initializers/mime_types.rb | 5 + .../config/initializers/secret_token.rb | 12 ++ .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 ++ source/example-app/config/locales/en.yml | 23 +++ source/example-app/config/routes.rb | 56 +++++++ source/example-app/db/seeds.rb | 7 + source/example-app/lib/assets/.keep | 0 source/example-app/lib/tasks/.keep | 0 source/example-app/log/.keep | 0 source/example-app/public/404.html | 58 ++++++++ source/example-app/public/422.html | 58 ++++++++ source/example-app/public/500.html | 57 +++++++ source/example-app/public/favicon.ico | 0 source/example-app/public/robots.txt | 5 + .../vendor/assets/javascripts/.keep | 0 .../vendor/assets/stylesheets/.keep | 0 46 files changed, 870 insertions(+) create mode 100644 source/example-app/.gitignore create mode 100644 source/example-app/Gemfile create mode 100644 source/example-app/Gemfile.lock create mode 100644 source/example-app/README.rdoc create mode 100644 source/example-app/Rakefile create mode 100644 source/example-app/app/assets/images/.keep create mode 100644 source/example-app/app/assets/javascripts/application.js create mode 100644 source/example-app/app/assets/stylesheets/application.css create mode 100644 source/example-app/app/controllers/application_controller.rb create mode 100644 source/example-app/app/controllers/concerns/.keep create mode 100644 source/example-app/app/helpers/application_helper.rb create mode 100644 source/example-app/app/mailers/.keep create mode 100644 source/example-app/app/models/.keep create mode 100644 source/example-app/app/models/concerns/.keep create mode 100644 source/example-app/app/views/layouts/application.html.erb create mode 100755 source/example-app/bin/bundle create mode 100755 source/example-app/bin/rails create mode 100755 source/example-app/bin/rake create mode 100644 source/example-app/config.ru create mode 100644 source/example-app/config/application.rb create mode 100644 source/example-app/config/boot.rb create mode 100644 source/example-app/config/database.yml create mode 100644 source/example-app/config/environment.rb create mode 100644 source/example-app/config/environments/development.rb create mode 100644 source/example-app/config/environments/production.rb create mode 100644 source/example-app/config/environments/test.rb create mode 100644 source/example-app/config/initializers/backtrace_silencers.rb create mode 100644 source/example-app/config/initializers/filter_parameter_logging.rb create mode 100644 source/example-app/config/initializers/inflections.rb create mode 100644 source/example-app/config/initializers/mime_types.rb create mode 100644 source/example-app/config/initializers/secret_token.rb create mode 100644 source/example-app/config/initializers/session_store.rb create mode 100644 source/example-app/config/initializers/wrap_parameters.rb create mode 100644 source/example-app/config/locales/en.yml create mode 100644 source/example-app/config/routes.rb create mode 100644 source/example-app/db/seeds.rb create mode 100644 source/example-app/lib/assets/.keep create mode 100644 source/example-app/lib/tasks/.keep create mode 100644 source/example-app/log/.keep create mode 100644 source/example-app/public/404.html create mode 100644 source/example-app/public/422.html create mode 100644 source/example-app/public/500.html create mode 100644 source/example-app/public/favicon.ico create mode 100644 source/example-app/public/robots.txt create mode 100644 source/example-app/vendor/assets/javascripts/.keep create mode 100644 source/example-app/vendor/assets/stylesheets/.keep diff --git a/source/example-app/.gitignore b/source/example-app/.gitignore new file mode 100644 index 000000000..25a742dff --- /dev/null +++ b/source/example-app/.gitignore @@ -0,0 +1,16 @@ +# See http://help.github.com/ignore-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 +/tmp diff --git a/source/example-app/Gemfile b/source/example-app/Gemfile new file mode 100644 index 000000000..e4ecedfce --- /dev/null +++ b/source/example-app/Gemfile @@ -0,0 +1,49 @@ +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.0.0' + +# Use postgresql as the database for Active Record +gem 'pg', '~> 0.20.0' + +# Use SCSS for stylesheets +gem 'sass-rails', '~> 4.0.0' + +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' + +# Use CoffeeScript for .js.coffee assets and views +gem 'coffee-rails', '~> 4.0.0' + +# See https://github.com/sstephenson/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', '~> 1.2' + +group :doc do + # bundle exec rake doc:rails generates the API under doc/api. + gem 'sdoc', require: false +end + +group :development, :test do + gem 'rspec-rails', '~> 3.9.1' +end + +# Use ActiveModel has_secure_password +# gem 'bcrypt-ruby', '~> 3.0.0' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] diff --git a/source/example-app/Gemfile.lock b/source/example-app/Gemfile.lock new file mode 100644 index 000000000..4431cf717 --- /dev/null +++ b/source/example-app/Gemfile.lock @@ -0,0 +1,139 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.0) + actionpack (= 4.0.0) + mail (~> 2.5.3) + actionpack (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + activerecord (4.0.0) + activemodel (= 4.0.0) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.0) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.0) + i18n (~> 0.6, >= 0.6.4) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + arel (4.0.2) + builder (3.1.4) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.8) + diff-lcs (1.4.4) + erubis (2.7.0) + execjs (2.7.0) + hike (1.2.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jbuilder (1.5.3) + activesupport (>= 3.0.0) + multi_json (>= 1.2.0) + jquery-rails (3.1.5) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + mail (2.5.5) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (4.7.5) + multi_json (1.15.0) + pg (0.20.0) + polyglot (0.3.5) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.0.0) + actionmailer (= 4.0.0) + actionpack (= 4.0.0) + activerecord (= 4.0.0) + activesupport (= 4.0.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.0) + sprockets-rails (~> 2.0.0) + railties (4.0.0) + actionpack (= 4.0.0) + activesupport (= 4.0.0) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.3) + rdoc (5.1.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) + 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.4) + sass (3.2.19) + sass-rails (4.0.5) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) + sprockets-rails (~> 2.0) + sdoc (2.1.0) + rdoc (>= 5.0) + sprockets (2.12.5) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + thor (1.1.0) + thread_safe (0.3.6) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (0.3.60) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 4.0.0) + jbuilder (~> 1.2) + jquery-rails + pg (~> 0.20.0) + rails (= 4.0.0) + rspec-rails (~> 3.9.1) + sass-rails (~> 4.0.0) + sdoc + turbolinks + uglifier (>= 1.3.0) + +BUNDLED WITH + 1.17.3 diff --git a/source/example-app/README.rdoc b/source/example-app/README.rdoc new file mode 100644 index 000000000..dd4e97e22 --- /dev/null +++ b/source/example-app/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/example-app/Rakefile b/source/example-app/Rakefile new file mode 100644 index 000000000..e67201a82 --- /dev/null +++ b/source/example-app/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__) + +ExampleApp::Application.load_tasks diff --git a/source/example-app/app/assets/images/.keep b/source/example-app/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/assets/javascripts/application.js b/source/example-app/app/assets/javascripts/application.js new file mode 100644 index 000000000..d6925fa43 --- /dev/null +++ b/source/example-app/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 vendor/assets/javascripts of plugins, if any, 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/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/source/example-app/app/assets/stylesheets/application.css b/source/example-app/app/assets/stylesheets/application.css new file mode 100644 index 000000000..3192ec897 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/application.css @@ -0,0 +1,13 @@ +/* + * 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 vendor/assets/stylesheets of plugins, if any, 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 top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ diff --git a/source/example-app/app/controllers/application_controller.rb b/source/example-app/app/controllers/application_controller.rb new file mode 100644 index 000000000..d83690e1b --- /dev/null +++ b/source/example-app/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/example-app/app/controllers/concerns/.keep b/source/example-app/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/helpers/application_helper.rb b/source/example-app/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/source/example-app/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/source/example-app/app/mailers/.keep b/source/example-app/app/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/models/.keep b/source/example-app/app/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/models/concerns/.keep b/source/example-app/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/views/layouts/application.html.erb b/source/example-app/app/views/layouts/application.html.erb new file mode 100644 index 000000000..3a16810af --- /dev/null +++ b/source/example-app/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + ExampleApp + <%= 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/example-app/bin/bundle b/source/example-app/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/source/example-app/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/example-app/bin/rails b/source/example-app/bin/rails new file mode 100755 index 000000000..728cd85aa --- /dev/null +++ b/source/example-app/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/example-app/bin/rake b/source/example-app/bin/rake new file mode 100755 index 000000000..17240489f --- /dev/null +++ b/source/example-app/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/source/example-app/config.ru b/source/example-app/config.ru new file mode 100644 index 000000000..5bc2a619e --- /dev/null +++ b/source/example-app/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/example-app/config/application.rb b/source/example-app/config/application.rb new file mode 100644 index 000000000..42debc6df --- /dev/null +++ b/source/example-app/config/application.rb @@ -0,0 +1,28 @@ +require File.expand_path('../boot', __FILE__) + +# Pick the frameworks you want: +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/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(:default, Rails.env) + +module ExampleApp + 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 + end +end diff --git a/source/example-app/config/boot.rb b/source/example-app/config/boot.rb new file mode 100644 index 000000000..359673666 --- /dev/null +++ b/source/example-app/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/source/example-app/config/database.yml b/source/example-app/config/database.yml new file mode 100644 index 000000000..f2cab2b8a --- /dev/null +++ b/source/example-app/config/database.yml @@ -0,0 +1,60 @@ +# 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' +# +development: + adapter: postgresql + encoding: unicode + database: example-app_development + pool: 5 + username: example-app + 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: + adapter: postgresql + encoding: unicode + database: example-app_test + pool: 5 + username: example-app + password: + +production: + adapter: postgresql + encoding: unicode + database: example-app_production + pool: 5 + username: example-app + password: diff --git a/source/example-app/config/environment.rb b/source/example-app/config/environment.rb new file mode 100644 index 000000000..aebc109cd --- /dev/null +++ b/source/example-app/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +ExampleApp::Application.initialize! diff --git a/source/example-app/config/environments/development.rb b/source/example-app/config/environments/development.rb new file mode 100644 index 000000000..b4c8454f9 --- /dev/null +++ b/source/example-app/config/environments/development.rb @@ -0,0 +1,29 @@ +ExampleApp::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 +end diff --git a/source/example-app/config/environments/production.rb b/source/example-app/config/environments/production.rb new file mode 100644 index 000000000..9b343689c --- /dev/null +++ b/source/example-app/config/environments/production.rb @@ -0,0 +1,80 @@ +ExampleApp::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 thread 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 Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # 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 + + # Generate digests for assets URLs. + config.assets.digest = true + + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + + # 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 + + # Set to :debug to see everything in the log. + config.log_level = :info + + # 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" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) + + # 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 can not be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new +end diff --git a/source/example-app/config/environments/test.rb b/source/example-app/config/environments/test.rb new file mode 100644 index 000000000..4838a862a --- /dev/null +++ b/source/example-app/config/environments/test.rb @@ -0,0 +1,36 @@ +ExampleApp::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 asset server for tests with Cache-Control for performance. + config.serve_static_assets = 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 + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr +end diff --git a/source/example-app/config/initializers/backtrace_silencers.rb b/source/example-app/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/source/example-app/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/example-app/config/initializers/filter_parameter_logging.rb b/source/example-app/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/source/example-app/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/example-app/config/initializers/inflections.rb b/source/example-app/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/source/example-app/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/example-app/config/initializers/mime_types.rb b/source/example-app/config/initializers/mime_types.rb new file mode 100644 index 000000000..72aca7e44 --- /dev/null +++ b/source/example-app/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# 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 +# Mime::Type.register_alias "text/html", :iphone diff --git a/source/example-app/config/initializers/secret_token.rb b/source/example-app/config/initializers/secret_token.rb new file mode 100644 index 000000000..9d6561b4f --- /dev/null +++ b/source/example-app/config/initializers/secret_token.rb @@ -0,0 +1,12 @@ +# 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 your secret_key_base is kept private +# if you're sharing your code publicly. +ExampleApp::Application.config.secret_key_base = '99be1c8a58f1aa9437bf98c0bc5c3c92ea7acb4373605129b25065db1dd66a7380ce89db5cc7487ee2b9b6f6272c7b0a177a76ebf2dd110bc0901adf759c0787' diff --git a/source/example-app/config/initializers/session_store.rb b/source/example-app/config/initializers/session_store.rb new file mode 100644 index 000000000..e9614dabe --- /dev/null +++ b/source/example-app/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +ExampleApp::Application.config.session_store :cookie_store, key: '_example-app_session' diff --git a/source/example-app/config/initializers/wrap_parameters.rb b/source/example-app/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..33725e95f --- /dev/null +++ b/source/example-app/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/example-app/config/locales/en.yml b/source/example-app/config/locales/en.yml new file mode 100644 index 000000000..065395716 --- /dev/null +++ b/source/example-app/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/example-app/config/routes.rb b/source/example-app/config/routes.rb new file mode 100644 index 000000000..5b0ceec03 --- /dev/null +++ b/source/example-app/config/routes.rb @@ -0,0 +1,56 @@ +ExampleApp::Application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/source/example-app/db/seeds.rb b/source/example-app/db/seeds.rb new file mode 100644 index 000000000..4edb1e857 --- /dev/null +++ b/source/example-app/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/source/example-app/lib/assets/.keep b/source/example-app/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/lib/tasks/.keep b/source/example-app/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/log/.keep b/source/example-app/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/public/404.html b/source/example-app/public/404.html new file mode 100644 index 000000000..a0daa0c15 --- /dev/null +++ b/source/example-app/public/404.html @@ -0,0 +1,58 @@ + + + + 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/example-app/public/422.html b/source/example-app/public/422.html new file mode 100644 index 000000000..fbb4b84d7 --- /dev/null +++ b/source/example-app/public/422.html @@ -0,0 +1,58 @@ + + + + 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/example-app/public/500.html b/source/example-app/public/500.html new file mode 100644 index 000000000..e9052d35b --- /dev/null +++ b/source/example-app/public/500.html @@ -0,0 +1,57 @@ + + + + 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/example-app/public/favicon.ico b/source/example-app/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/public/robots.txt b/source/example-app/public/robots.txt new file mode 100644 index 000000000..1a3a5e4dd --- /dev/null +++ b/source/example-app/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/wc/norobots.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/example-app/vendor/assets/javascripts/.keep b/source/example-app/vendor/assets/javascripts/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/vendor/assets/stylesheets/.keep b/source/example-app/vendor/assets/stylesheets/.keep new file mode 100644 index 000000000..e69de29bb From e7d270cfa8275a7d74476d9f6135d6c9166cd455 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 09:43:53 -0400 Subject: [PATCH 25/40] Add RSpec configuration --- source/example-app/spec/rails_helper.rb | 63 ++++++++++++++++ source/example-app/spec/spec_helper.rb | 96 +++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 source/example-app/spec/rails_helper.rb create mode 100644 source/example-app/spec/spec_helper.rb diff --git a/source/example-app/spec/rails_helper.rb b/source/example-app/spec/rails_helper.rb new file mode 100644 index 000000000..f4fd4d440 --- /dev/null +++ b/source/example-app/spec/rails_helper.rb @@ -0,0 +1,63 @@ +# 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')].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.check_pending! +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 + + # 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/example-app/spec/spec_helper.rb b/source/example-app/spec/spec_helper.rb new file mode 100644 index 000000000..ce33d66df --- /dev/null +++ b/source/example-app/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 From 353889160ec26bf2bbbd3f6776c3f4037a971011 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 09:47:41 -0400 Subject: [PATCH 26/40] Update database credentials (not safe) --- source/example-app/config/database.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/example-app/config/database.yml b/source/example-app/config/database.yml index f2cab2b8a..b8e2fea65 100644 --- a/source/example-app/config/database.yml +++ b/source/example-app/config/database.yml @@ -19,8 +19,8 @@ development: encoding: unicode database: example-app_development pool: 5 - username: example-app - password: + username: postgres + password: 123456 # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have @@ -48,13 +48,13 @@ test: encoding: unicode database: example-app_test pool: 5 - username: example-app - password: + username: postgres + password: 123456 production: adapter: postgresql encoding: unicode database: example-app_production pool: 5 - username: example-app - password: + username: postgres + password: 123456 From 0f51d6847603505a954eacf4e8c5d2002615a8cc Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 09:48:05 -0400 Subject: [PATCH 27/40] Add customers scaffold --- .../assets/javascripts/customers.js.coffee | 3 + .../app/assets/stylesheets/customers.css.scss | 3 + .../app/assets/stylesheets/scaffolds.css.scss | 69 +++++++++ .../app/controllers/customers_controller.rb | 74 +++++++++ .../app/helpers/customers_helper.rb | 2 + source/example-app/app/models/customer.rb | 2 + .../app/views/customers/_form.html.erb | 25 ++++ .../app/views/customers/edit.html.erb | 6 + .../app/views/customers/index.html.erb | 29 ++++ .../app/views/customers/index.json.jbuilder | 4 + .../app/views/customers/new.html.erb | 5 + .../app/views/customers/show.html.erb | 14 ++ .../app/views/customers/show.json.jbuilder | 1 + source/example-app/config/routes.rb | 2 + .../20210420134753_create_customers.rb | 10 ++ .../controllers/customers_controller_spec.rb | 141 ++++++++++++++++++ .../spec/helpers/customers_helper_spec.rb | 15 ++ .../example-app/spec/models/customer_spec.rb | 5 + .../spec/requests/customers_spec.rb | 10 ++ .../spec/routing/customers_routing_spec.rb | 38 +++++ .../views/customers/edit.html.erb_spec.rb | 21 +++ .../views/customers/index.html.erb_spec.rb | 22 +++ .../spec/views/customers/new.html.erb_spec.rb | 21 +++ .../views/customers/show.html.erb_spec.rb | 16 ++ 24 files changed, 538 insertions(+) create mode 100644 source/example-app/app/assets/javascripts/customers.js.coffee create mode 100644 source/example-app/app/assets/stylesheets/customers.css.scss create mode 100644 source/example-app/app/assets/stylesheets/scaffolds.css.scss create mode 100644 source/example-app/app/controllers/customers_controller.rb create mode 100644 source/example-app/app/helpers/customers_helper.rb create mode 100644 source/example-app/app/models/customer.rb create mode 100644 source/example-app/app/views/customers/_form.html.erb create mode 100644 source/example-app/app/views/customers/edit.html.erb create mode 100644 source/example-app/app/views/customers/index.html.erb create mode 100644 source/example-app/app/views/customers/index.json.jbuilder create mode 100644 source/example-app/app/views/customers/new.html.erb create mode 100644 source/example-app/app/views/customers/show.html.erb create mode 100644 source/example-app/app/views/customers/show.json.jbuilder create mode 100644 source/example-app/db/migrate/20210420134753_create_customers.rb create mode 100644 source/example-app/spec/controllers/customers_controller_spec.rb create mode 100644 source/example-app/spec/helpers/customers_helper_spec.rb create mode 100644 source/example-app/spec/models/customer_spec.rb create mode 100644 source/example-app/spec/requests/customers_spec.rb create mode 100644 source/example-app/spec/routing/customers_routing_spec.rb create mode 100644 source/example-app/spec/views/customers/edit.html.erb_spec.rb create mode 100644 source/example-app/spec/views/customers/index.html.erb_spec.rb create mode 100644 source/example-app/spec/views/customers/new.html.erb_spec.rb create mode 100644 source/example-app/spec/views/customers/show.html.erb_spec.rb diff --git a/source/example-app/app/assets/javascripts/customers.js.coffee b/source/example-app/app/assets/javascripts/customers.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/example-app/app/assets/javascripts/customers.js.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/example-app/app/assets/stylesheets/customers.css.scss b/source/example-app/app/assets/stylesheets/customers.css.scss new file mode 100644 index 000000000..892b0ad94 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/customers.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the customers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/example-app/app/assets/stylesheets/scaffolds.css.scss b/source/example-app/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 000000000..6ec6a8ff5 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/source/example-app/app/controllers/customers_controller.rb b/source/example-app/app/controllers/customers_controller.rb new file mode 100644 index 000000000..0210a69a7 --- /dev/null +++ b/source/example-app/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 action: 'show', status: :created, location: @customer } + else + format.html { render action: '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 { head :no_content } + else + format.html { render action: '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 } + 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/example-app/app/helpers/customers_helper.rb b/source/example-app/app/helpers/customers_helper.rb new file mode 100644 index 000000000..a07ce2943 --- /dev/null +++ b/source/example-app/app/helpers/customers_helper.rb @@ -0,0 +1,2 @@ +module CustomersHelper +end diff --git a/source/example-app/app/models/customer.rb b/source/example-app/app/models/customer.rb new file mode 100644 index 000000000..047dcb0c0 --- /dev/null +++ b/source/example-app/app/models/customer.rb @@ -0,0 +1,2 @@ +class Customer < ActiveRecord::Base +end diff --git a/source/example-app/app/views/customers/_form.html.erb b/source/example-app/app/views/customers/_form.html.erb new file mode 100644 index 000000000..f2db3db1e --- /dev/null +++ b/source/example-app/app/views/customers/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@customer) do |f| %> + <% if @customer.errors.any? %> +
+

<%= pluralize(@customer.errors.count, "error") %> prohibited this customer from being saved:

+ +
    + <% @customer.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :first_name %>
+ <%= f.text_field :first_name %> +
+
+ <%= f.label :last_name %>
+ <%= f.text_field :last_name %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/source/example-app/app/views/customers/edit.html.erb b/source/example-app/app/views/customers/edit.html.erb new file mode 100644 index 000000000..d1ed0a71c --- /dev/null +++ b/source/example-app/app/views/customers/edit.html.erb @@ -0,0 +1,6 @@ +

Editing customer

+ +<%= render 'form' %> + +<%= link_to 'Show', @customer %> | +<%= link_to 'Back', customers_path %> diff --git a/source/example-app/app/views/customers/index.html.erb b/source/example-app/app/views/customers/index.html.erb new file mode 100644 index 000000000..47ea166c8 --- /dev/null +++ b/source/example-app/app/views/customers/index.html.erb @@ -0,0 +1,29 @@ +

Listing customers

+ +
Created
+ + + + + + + + + + + + <% @customers.each do |customer| %> + + + + + + + + <% end %> + +
First nameLast 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?' } %>
+ +
+ +<%= link_to 'New Customer', new_customer_path %> diff --git a/source/example-app/app/views/customers/index.json.jbuilder b/source/example-app/app/views/customers/index.json.jbuilder new file mode 100644 index 000000000..6aac73b4c --- /dev/null +++ b/source/example-app/app/views/customers/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@customers) do |customer| + json.extract! customer, :id, :first_name, :last_name + json.url customer_url(customer, format: :json) +end diff --git a/source/example-app/app/views/customers/new.html.erb b/source/example-app/app/views/customers/new.html.erb new file mode 100644 index 000000000..a93c20371 --- /dev/null +++ b/source/example-app/app/views/customers/new.html.erb @@ -0,0 +1,5 @@ +

New customer

+ +<%= render 'form' %> + +<%= link_to 'Back', customers_path %> diff --git a/source/example-app/app/views/customers/show.html.erb b/source/example-app/app/views/customers/show.html.erb new file mode 100644 index 000000000..cacd47343 --- /dev/null +++ b/source/example-app/app/views/customers/show.html.erb @@ -0,0 +1,14 @@ +

<%= 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/example-app/app/views/customers/show.json.jbuilder b/source/example-app/app/views/customers/show.json.jbuilder new file mode 100644 index 000000000..a7698de6a --- /dev/null +++ b/source/example-app/app/views/customers/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @customer, :id, :first_name, :last_name, :created_at, :updated_at diff --git a/source/example-app/config/routes.rb b/source/example-app/config/routes.rb index 5b0ceec03..6441a126c 100644 --- a/source/example-app/config/routes.rb +++ b/source/example-app/config/routes.rb @@ -1,4 +1,6 @@ ExampleApp::Application.routes.draw do + resources :customers + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/source/example-app/db/migrate/20210420134753_create_customers.rb b/source/example-app/db/migrate/20210420134753_create_customers.rb new file mode 100644 index 000000000..ab9127003 --- /dev/null +++ b/source/example-app/db/migrate/20210420134753_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 + end + end +end diff --git a/source/example-app/spec/controllers/customers_controller_spec.rb b/source/example-app/spec/controllers/customers_controller_spec.rb new file mode 100644 index 000000000..60980a9d4 --- /dev/null +++ b/source/example-app/spec/controllers/customers_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe CustomersController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Customer. As you add validations to Customer, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # CustomersController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Customer.create! valid_attributes + get :index, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + customer = Customer.create! valid_attributes + get :show, {:id => customer.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + customer = Customer.create! valid_attributes + get :edit, {:id => customer.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Customer" do + expect { + post :create, {:customer => valid_attributes}, valid_session + }.to change(Customer, :count).by(1) + end + + it "redirects to the created customer" do + post :create, {:customer => valid_attributes}, valid_session + expect(response).to redirect_to(Customer.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, {:customer => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested customer" do + customer = Customer.create! valid_attributes + put :update, {:id => customer.to_param, :customer => new_attributes}, valid_session + customer.reload + skip("Add assertions for updated state") + end + + it "redirects to the customer" do + customer = Customer.create! valid_attributes + put :update, {:id => customer.to_param, :customer => valid_attributes}, valid_session + expect(response).to redirect_to(customer) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + customer = Customer.create! valid_attributes + put :update, {:id => customer.to_param, :customer => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested customer" do + customer = Customer.create! valid_attributes + expect { + delete :destroy, {:id => customer.to_param}, valid_session + }.to change(Customer, :count).by(-1) + end + + it "redirects to the customers list" do + customer = Customer.create! valid_attributes + delete :destroy, {:id => customer.to_param}, valid_session + expect(response).to redirect_to(customers_url) + end + end + +end diff --git a/source/example-app/spec/helpers/customers_helper_spec.rb b/source/example-app/spec/helpers/customers_helper_spec.rb new file mode 100644 index 000000000..fa160374f --- /dev/null +++ b/source/example-app/spec/helpers/customers_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the CustomersHelper. For example: +# +# describe CustomersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe CustomersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/models/customer_spec.rb b/source/example-app/spec/models/customer_spec.rb new file mode 100644 index 000000000..3399b1f56 --- /dev/null +++ b/source/example-app/spec/models/customer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Customer, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/requests/customers_spec.rb b/source/example-app/spec/requests/customers_spec.rb new file mode 100644 index 000000000..081166fb1 --- /dev/null +++ b/source/example-app/spec/requests/customers_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Customers", type: :request do + describe "GET /customers" do + it "works! (now write some real specs)" do + get customers_path + expect(response).to have_http_status(200) + end + end +end diff --git a/source/example-app/spec/routing/customers_routing_spec.rb b/source/example-app/spec/routing/customers_routing_spec.rb new file mode 100644 index 000000000..622cd626a --- /dev/null +++ b/source/example-app/spec/routing/customers_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe CustomersController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/customers").to route_to("customers#index") + end + + it "routes to #new" do + expect(:get => "/customers/new").to route_to("customers#new") + end + + it "routes to #show" do + expect(:get => "/customers/1").to route_to("customers#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/customers/1/edit").to route_to("customers#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/customers").to route_to("customers#create") + end + + it "routes to #update via PUT" do + expect(:put => "/customers/1").to route_to("customers#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/customers/1").to route_to("customers#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/customers/1").to route_to("customers#destroy", :id => "1") + end + end +end diff --git a/source/example-app/spec/views/customers/edit.html.erb_spec.rb b/source/example-app/spec/views/customers/edit.html.erb_spec.rb new file mode 100644 index 000000000..35f127c2c --- /dev/null +++ b/source/example-app/spec/views/customers/edit.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "customers/edit", type: :view do + before(:each) do + @customer = assign(:customer, Customer.create!( + :first_name => "MyString", + :last_name => "MyString" + )) + end + + it "renders the edit customer form" do + render + + assert_select "form[action=?][method=?]", customer_path(@customer), "post" do + + assert_select "input#customer_first_name[name=?]", "customer[first_name]" + + assert_select "input#customer_last_name[name=?]", "customer[last_name]" + end + end +end diff --git a/source/example-app/spec/views/customers/index.html.erb_spec.rb b/source/example-app/spec/views/customers/index.html.erb_spec.rb new file mode 100644 index 000000000..76a42155b --- /dev/null +++ b/source/example-app/spec/views/customers/index.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "customers/index", type: :view do + before(:each) do + assign(:customers, [ + Customer.create!( + :first_name => "First Name", + :last_name => "Last Name" + ), + Customer.create!( + :first_name => "First Name", + :last_name => "Last Name" + ) + ]) + end + + it "renders a list of customers" do + render + assert_select "tr>td", :text => "First Name".to_s, :count => 2 + assert_select "tr>td", :text => "Last Name".to_s, :count => 2 + end +end diff --git a/source/example-app/spec/views/customers/new.html.erb_spec.rb b/source/example-app/spec/views/customers/new.html.erb_spec.rb new file mode 100644 index 000000000..bb26fd937 --- /dev/null +++ b/source/example-app/spec/views/customers/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "customers/new", type: :view do + before(:each) do + assign(:customer, Customer.new( + :first_name => "MyString", + :last_name => "MyString" + )) + end + + it "renders new customer form" do + render + + assert_select "form[action=?][method=?]", customers_path, "post" do + + assert_select "input#customer_first_name[name=?]", "customer[first_name]" + + assert_select "input#customer_last_name[name=?]", "customer[last_name]" + end + end +end diff --git a/source/example-app/spec/views/customers/show.html.erb_spec.rb b/source/example-app/spec/views/customers/show.html.erb_spec.rb new file mode 100644 index 000000000..28ce03fd9 --- /dev/null +++ b/source/example-app/spec/views/customers/show.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "customers/show", type: :view do + before(:each) do + @customer = assign(:customer, Customer.create!( + :first_name => "First Name", + :last_name => "Last Name" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/First Name/) + expect(rendered).to match(/Last Name/) + end +end From 6bfcf8bf0dee4763f84e235cfd6bc6fff6282a8d Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 09:48:51 -0400 Subject: [PATCH 28/40] Add charges scaffold --- .../app/assets/javascripts/charges.js.coffee | 3 + .../app/assets/stylesheets/charges.css.scss | 3 + .../app/controllers/charges_controller.rb | 74 +++++++++ .../example-app/app/helpers/charges_helper.rb | 2 + source/example-app/app/models/charge.rb | 3 + .../app/views/charges/_form.html.erb | 41 +++++ .../app/views/charges/edit.html.erb | 6 + .../app/views/charges/index.html.erb | 37 +++++ .../app/views/charges/index.json.jbuilder | 4 + .../app/views/charges/new.html.erb | 5 + .../app/views/charges/show.html.erb | 34 +++++ .../app/views/charges/show.json.jbuilder | 1 + source/example-app/config/routes.rb | 2 + .../migrate/20210420134839_create_charges.rb | 14 ++ .../controllers/charges_controller_spec.rb | 141 ++++++++++++++++++ .../spec/helpers/charges_helper_spec.rb | 15 ++ source/example-app/spec/models/charge_spec.rb | 5 + .../example-app/spec/requests/charges_spec.rb | 10 ++ .../spec/routing/charges_routing_spec.rb | 38 +++++ .../spec/views/charges/edit.html.erb_spec.rb | 33 ++++ .../spec/views/charges/index.html.erb_spec.rb | 34 +++++ .../spec/views/charges/new.html.erb_spec.rb | 33 ++++ .../spec/views/charges/show.html.erb_spec.rb | 24 +++ 23 files changed, 562 insertions(+) create mode 100644 source/example-app/app/assets/javascripts/charges.js.coffee create mode 100644 source/example-app/app/assets/stylesheets/charges.css.scss create mode 100644 source/example-app/app/controllers/charges_controller.rb create mode 100644 source/example-app/app/helpers/charges_helper.rb create mode 100644 source/example-app/app/models/charge.rb create mode 100644 source/example-app/app/views/charges/_form.html.erb create mode 100644 source/example-app/app/views/charges/edit.html.erb create mode 100644 source/example-app/app/views/charges/index.html.erb create mode 100644 source/example-app/app/views/charges/index.json.jbuilder create mode 100644 source/example-app/app/views/charges/new.html.erb create mode 100644 source/example-app/app/views/charges/show.html.erb create mode 100644 source/example-app/app/views/charges/show.json.jbuilder create mode 100644 source/example-app/db/migrate/20210420134839_create_charges.rb create mode 100644 source/example-app/spec/controllers/charges_controller_spec.rb create mode 100644 source/example-app/spec/helpers/charges_helper_spec.rb create mode 100644 source/example-app/spec/models/charge_spec.rb create mode 100644 source/example-app/spec/requests/charges_spec.rb create mode 100644 source/example-app/spec/routing/charges_routing_spec.rb create mode 100644 source/example-app/spec/views/charges/edit.html.erb_spec.rb create mode 100644 source/example-app/spec/views/charges/index.html.erb_spec.rb create mode 100644 source/example-app/spec/views/charges/new.html.erb_spec.rb create mode 100644 source/example-app/spec/views/charges/show.html.erb_spec.rb diff --git a/source/example-app/app/assets/javascripts/charges.js.coffee b/source/example-app/app/assets/javascripts/charges.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/example-app/app/assets/javascripts/charges.js.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/example-app/app/assets/stylesheets/charges.css.scss b/source/example-app/app/assets/stylesheets/charges.css.scss new file mode 100644 index 000000000..c3a893042 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/charges.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Charges controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/example-app/app/controllers/charges_controller.rb b/source/example-app/app/controllers/charges_controller.rb new file mode 100644 index 000000000..5c57af40d --- /dev/null +++ b/source/example-app/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 + 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 action: 'show', status: :created, location: @charge } + else + format.html { render action: '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 { head :no_content } + else + format.html { render action: '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 } + 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, :currency, :refunded, :customer_id) + end +end diff --git a/source/example-app/app/helpers/charges_helper.rb b/source/example-app/app/helpers/charges_helper.rb new file mode 100644 index 000000000..414ee900f --- /dev/null +++ b/source/example-app/app/helpers/charges_helper.rb @@ -0,0 +1,2 @@ +module ChargesHelper +end diff --git a/source/example-app/app/models/charge.rb b/source/example-app/app/models/charge.rb new file mode 100644 index 000000000..c17f5e99d --- /dev/null +++ b/source/example-app/app/models/charge.rb @@ -0,0 +1,3 @@ +class Charge < ActiveRecord::Base + belongs_to :customer +end diff --git a/source/example-app/app/views/charges/_form.html.erb b/source/example-app/app/views/charges/_form.html.erb new file mode 100644 index 000000000..f818a123a --- /dev/null +++ b/source/example-app/app/views/charges/_form.html.erb @@ -0,0 +1,41 @@ +<%= form_for(@charge) do |f| %> + <% if @charge.errors.any? %> +

+

<%= pluralize(@charge.errors.count, "error") %> prohibited this charge from being saved:

+ +
    + <% @charge.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :created %>
+ <%= f.number_field :created %> +
+
+ <%= f.label :paid %>
+ <%= f.check_box :paid %> +
+
+ <%= f.label :amount %>
+ <%= f.text_field :amount %> +
+
+ <%= f.label :currency %>
+ <%= f.text_field :currency %> +
+
+ <%= f.label :refunded %>
+ <%= f.check_box :refunded %> +
+
+ <%= f.label :customer %>
+ <%= f.text_field :customer %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/source/example-app/app/views/charges/edit.html.erb b/source/example-app/app/views/charges/edit.html.erb new file mode 100644 index 000000000..a723d7a86 --- /dev/null +++ b/source/example-app/app/views/charges/edit.html.erb @@ -0,0 +1,6 @@ +

Editing charge

+ +<%= render 'form' %> + +<%= link_to 'Show', @charge %> | +<%= link_to 'Back', charges_path %> diff --git a/source/example-app/app/views/charges/index.html.erb b/source/example-app/app/views/charges/index.html.erb new file mode 100644 index 000000000..38dfa35f4 --- /dev/null +++ b/source/example-app/app/views/charges/index.html.erb @@ -0,0 +1,37 @@ +

Listing charges

+ + + + + + + + + + + + + + + + + + <% @charges.each do |charge| %> + + + + + + + + + + + + <% end %> + +
CreatedPaidAmountCurrencyRefundedCustomer
<%= charge.created %><%= charge.paid %><%= charge.amount %><%= charge.currency %><%= charge.refunded %><%= charge.customer %><%= link_to 'Show', charge %><%= link_to 'Edit', edit_charge_path(charge) %><%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Charge', new_charge_path %> diff --git a/source/example-app/app/views/charges/index.json.jbuilder b/source/example-app/app/views/charges/index.json.jbuilder new file mode 100644 index 000000000..9b184d029 --- /dev/null +++ b/source/example-app/app/views/charges/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@charges) do |charge| + json.extract! charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id + json.url charge_url(charge, format: :json) +end diff --git a/source/example-app/app/views/charges/new.html.erb b/source/example-app/app/views/charges/new.html.erb new file mode 100644 index 000000000..8dc59a97d --- /dev/null +++ b/source/example-app/app/views/charges/new.html.erb @@ -0,0 +1,5 @@ +

New charge

+ +<%= render 'form' %> + +<%= link_to 'Back', charges_path %> diff --git a/source/example-app/app/views/charges/show.html.erb b/source/example-app/app/views/charges/show.html.erb new file mode 100644 index 000000000..551d274bb --- /dev/null +++ b/source/example-app/app/views/charges/show.html.erb @@ -0,0 +1,34 @@ +

<%= notice %>

+ +

+ Created: + <%= @charge.created %> +

+ +

+ Paid: + <%= @charge.paid %> +

+ +

+ Amount: + <%= @charge.amount %> +

+ +

+ Currency: + <%= @charge.currency %> +

+ +

+ Refunded: + <%= @charge.refunded %> +

+ +

+ Customer: + <%= @charge.customer %> +

+ +<%= link_to 'Edit', edit_charge_path(@charge) %> | +<%= link_to 'Back', charges_path %> diff --git a/source/example-app/app/views/charges/show.json.jbuilder b/source/example-app/app/views/charges/show.json.jbuilder new file mode 100644 index 000000000..8e1676c10 --- /dev/null +++ b/source/example-app/app/views/charges/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/example-app/config/routes.rb b/source/example-app/config/routes.rb index 6441a126c..bf48e892d 100644 --- a/source/example-app/config/routes.rb +++ b/source/example-app/config/routes.rb @@ -1,4 +1,6 @@ ExampleApp::Application.routes.draw do + resources :charges + resources :customers # The priority is based upon order of creation: first created -> highest priority. diff --git a/source/example-app/db/migrate/20210420134839_create_charges.rb b/source/example-app/db/migrate/20210420134839_create_charges.rb new file mode 100644 index 000000000..a7a3619f6 --- /dev/null +++ b/source/example-app/db/migrate/20210420134839_create_charges.rb @@ -0,0 +1,14 @@ +class CreateCharges < ActiveRecord::Migration + def change + create_table :charges do |t| + t.integer :created + t.boolean :paid + t.decimal :amount + t.string :currency + t.boolean :refunded + t.references :customer, index: true + + t.timestamps + end + end +end diff --git a/source/example-app/spec/controllers/charges_controller_spec.rb b/source/example-app/spec/controllers/charges_controller_spec.rb new file mode 100644 index 000000000..e2a7f9c4c --- /dev/null +++ b/source/example-app/spec/controllers/charges_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe ChargesController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Charge. As you add validations to Charge, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # ChargesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Charge.create! valid_attributes + get :index, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + charge = Charge.create! valid_attributes + get :show, {:id => charge.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + charge = Charge.create! valid_attributes + get :edit, {:id => charge.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Charge" do + expect { + post :create, {:charge => valid_attributes}, valid_session + }.to change(Charge, :count).by(1) + end + + it "redirects to the created charge" do + post :create, {:charge => valid_attributes}, valid_session + expect(response).to redirect_to(Charge.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, {:charge => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested charge" do + charge = Charge.create! valid_attributes + put :update, {:id => charge.to_param, :charge => new_attributes}, valid_session + charge.reload + skip("Add assertions for updated state") + end + + it "redirects to the charge" do + charge = Charge.create! valid_attributes + put :update, {:id => charge.to_param, :charge => valid_attributes}, valid_session + expect(response).to redirect_to(charge) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + charge = Charge.create! valid_attributes + put :update, {:id => charge.to_param, :charge => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested charge" do + charge = Charge.create! valid_attributes + expect { + delete :destroy, {:id => charge.to_param}, valid_session + }.to change(Charge, :count).by(-1) + end + + it "redirects to the charges list" do + charge = Charge.create! valid_attributes + delete :destroy, {:id => charge.to_param}, valid_session + expect(response).to redirect_to(charges_url) + end + end + +end diff --git a/source/example-app/spec/helpers/charges_helper_spec.rb b/source/example-app/spec/helpers/charges_helper_spec.rb new file mode 100644 index 000000000..0c25eaa8c --- /dev/null +++ b/source/example-app/spec/helpers/charges_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the ChargesHelper. For example: +# +# describe ChargesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe ChargesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/models/charge_spec.rb b/source/example-app/spec/models/charge_spec.rb new file mode 100644 index 000000000..a99f4cce3 --- /dev/null +++ b/source/example-app/spec/models/charge_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Charge, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/requests/charges_spec.rb b/source/example-app/spec/requests/charges_spec.rb new file mode 100644 index 000000000..504ef7846 --- /dev/null +++ b/source/example-app/spec/requests/charges_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Charges", type: :request do + describe "GET /charges" do + it "works! (now write some real specs)" do + get charges_path + expect(response).to have_http_status(200) + end + end +end diff --git a/source/example-app/spec/routing/charges_routing_spec.rb b/source/example-app/spec/routing/charges_routing_spec.rb new file mode 100644 index 000000000..4b2d9c92f --- /dev/null +++ b/source/example-app/spec/routing/charges_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe ChargesController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/charges").to route_to("charges#index") + end + + it "routes to #new" do + expect(:get => "/charges/new").to route_to("charges#new") + end + + it "routes to #show" do + expect(:get => "/charges/1").to route_to("charges#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/charges/1/edit").to route_to("charges#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/charges").to route_to("charges#create") + end + + it "routes to #update via PUT" do + expect(:put => "/charges/1").to route_to("charges#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/charges/1").to route_to("charges#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/charges/1").to route_to("charges#destroy", :id => "1") + end + end +end diff --git a/source/example-app/spec/views/charges/edit.html.erb_spec.rb b/source/example-app/spec/views/charges/edit.html.erb_spec.rb new file mode 100644 index 000000000..5085974db --- /dev/null +++ b/source/example-app/spec/views/charges/edit.html.erb_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe "charges/edit", type: :view do + before(:each) do + @charge = assign(:charge, Charge.create!( + :created => 1, + :paid => false, + :amount => "9.99", + :currency => "MyString", + :refunded => false, + :customer => nil + )) + end + + it "renders the edit charge form" do + render + + assert_select "form[action=?][method=?]", charge_path(@charge), "post" do + + assert_select "input#charge_created[name=?]", "charge[created]" + + assert_select "input#charge_paid[name=?]", "charge[paid]" + + assert_select "input#charge_amount[name=?]", "charge[amount]" + + assert_select "input#charge_currency[name=?]", "charge[currency]" + + assert_select "input#charge_refunded[name=?]", "charge[refunded]" + + assert_select "input#charge_customer_id[name=?]", "charge[customer_id]" + end + end +end diff --git a/source/example-app/spec/views/charges/index.html.erb_spec.rb b/source/example-app/spec/views/charges/index.html.erb_spec.rb new file mode 100644 index 000000000..4e3adf234 --- /dev/null +++ b/source/example-app/spec/views/charges/index.html.erb_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe "charges/index", type: :view do + before(:each) do + assign(:charges, [ + Charge.create!( + :created => 2, + :paid => false, + :amount => "9.99", + :currency => "Currency", + :refunded => false, + :customer => nil + ), + Charge.create!( + :created => 2, + :paid => false, + :amount => "9.99", + :currency => "Currency", + :refunded => false, + :customer => nil + ) + ]) + end + + it "renders a list of charges" do + render + assert_select "tr>td", :text => 2.to_s, :count => 2 + assert_select "tr>td", :text => false.to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "Currency".to_s, :count => 2 + assert_select "tr>td", :text => false.to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + end +end diff --git a/source/example-app/spec/views/charges/new.html.erb_spec.rb b/source/example-app/spec/views/charges/new.html.erb_spec.rb new file mode 100644 index 000000000..acf7bdb14 --- /dev/null +++ b/source/example-app/spec/views/charges/new.html.erb_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe "charges/new", type: :view do + before(:each) do + assign(:charge, Charge.new( + :created => 1, + :paid => false, + :amount => "9.99", + :currency => "MyString", + :refunded => false, + :customer => nil + )) + end + + it "renders new charge form" do + render + + assert_select "form[action=?][method=?]", charges_path, "post" do + + assert_select "input#charge_created[name=?]", "charge[created]" + + assert_select "input#charge_paid[name=?]", "charge[paid]" + + assert_select "input#charge_amount[name=?]", "charge[amount]" + + assert_select "input#charge_currency[name=?]", "charge[currency]" + + assert_select "input#charge_refunded[name=?]", "charge[refunded]" + + assert_select "input#charge_customer_id[name=?]", "charge[customer_id]" + end + end +end diff --git a/source/example-app/spec/views/charges/show.html.erb_spec.rb b/source/example-app/spec/views/charges/show.html.erb_spec.rb new file mode 100644 index 000000000..ba2c49779 --- /dev/null +++ b/source/example-app/spec/views/charges/show.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "charges/show", type: :view do + before(:each) do + @charge = assign(:charge, Charge.create!( + :created => 2, + :paid => false, + :amount => "9.99", + :currency => "Currency", + :refunded => false, + :customer => nil + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/2/) + expect(rendered).to match(/false/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/Currency/) + expect(rendered).to match(/false/) + expect(rendered).to match(//) + end +end From 86560f8d6dbc80b0cc4ba9415eafc3485112fee5 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 10:22:42 -0400 Subject: [PATCH 29/40] Add and Update gems for RSpec testing Downgrade turbolinks to ~> 1.3 Add rspec-rails Add database_cleaner Add capybara --- source/example-app/Gemfile | 4 +++- source/example-app/Gemfile.lock | 26 ++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/source/example-app/Gemfile b/source/example-app/Gemfile index e4ecedfce..9e6552489 100644 --- a/source/example-app/Gemfile +++ b/source/example-app/Gemfile @@ -22,7 +22,7 @@ gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' +gem 'turbolinks', '~> 1.3' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 1.2' @@ -34,6 +34,8 @@ end group :development, :test do gem 'rspec-rails', '~> 3.9.1' + gem 'database_cleaner', '1.8.3' + gem 'capybara' end # Use ActiveModel has_secure_password diff --git a/source/example-app/Gemfile.lock b/source/example-app/Gemfile.lock index 4431cf717..02f032b51 100644 --- a/source/example-app/Gemfile.lock +++ b/source/example-app/Gemfile.lock @@ -25,8 +25,17 @@ GEM multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) arel (4.0.2) builder (3.1.4) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (>= 2.0, < 4.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -35,6 +44,7 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.8) + database_cleaner (1.8.3) diff-lcs (1.4.4) erubis (2.7.0) execjs (2.7.0) @@ -51,10 +61,15 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) + mini_mime (1.1.0) + mini_portile2 (2.1.0) minitest (4.7.5) multi_json (1.15.0) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) pg (0.20.0) polyglot (0.3.5) + public_suffix (2.0.5) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) @@ -113,18 +128,21 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - turbolinks (5.2.1) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) + turbolinks (1.3.1) + coffee-rails tzinfo (0.3.60) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + xpath (2.1.0) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES + capybara coffee-rails (~> 4.0.0) + database_cleaner (= 1.8.3) jbuilder (~> 1.2) jquery-rails pg (~> 0.20.0) @@ -132,7 +150,7 @@ DEPENDENCIES rspec-rails (~> 3.9.1) sass-rails (~> 4.0.0) sdoc - turbolinks + turbolinks (~> 1.3) uglifier (>= 1.3.0) BUNDLED WITH From d60b6484d19949ed4b346213528f5e7cf7bddfe4 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 10:24:33 -0400 Subject: [PATCH 30/40] Update charges scaffold Add failed, disputed, successful scops Add charge and charges partials Add database cleaner configuration for rspec --- source/example-app/app/models/charge.rb | 6 +++ .../app/views/charges/_charge.html.erb | 12 +++++ .../app/views/charges/_charges.html.erb | 18 +++++++ .../app/views/charges/index.html.erb | 47 ++++++------------- source/example-app/db/schema.rb | 39 +++++++++++++++ source/example-app/db/seeds.rb | 44 +++++++++++++++++ .../example-app/spec/features/charges_spec.rb | 12 +++++ source/example-app/spec/rails_helper.rb | 28 ++++++++++- .../spec/views/charges/_charge.html.erb | 12 +++++ .../spec/views/charges/_charges.html.erb | 18 +++++++ .../spec/views/charges/index.html.erb | 18 +++++++ 11 files changed, 220 insertions(+), 34 deletions(-) create mode 100644 source/example-app/app/views/charges/_charge.html.erb create mode 100644 source/example-app/app/views/charges/_charges.html.erb create mode 100644 source/example-app/db/schema.rb create mode 100644 source/example-app/spec/features/charges_spec.rb create mode 100644 source/example-app/spec/views/charges/_charge.html.erb create mode 100644 source/example-app/spec/views/charges/_charges.html.erb create mode 100644 source/example-app/spec/views/charges/index.html.erb diff --git a/source/example-app/app/models/charge.rb b/source/example-app/app/models/charge.rb index c17f5e99d..add811500 100644 --- a/source/example-app/app/models/charge.rb +++ b/source/example-app/app/models/charge.rb @@ -1,3 +1,9 @@ class Charge < ActiveRecord::Base belongs_to :customer + + # we can put indexes on columns to make the queries faster + + scope :failed, -> { where("NOT paid") } + scope :disputed, -> { where("refunded") } + scope :successful, -> { where("paid") } end diff --git a/source/example-app/app/views/charges/_charge.html.erb b/source/example-app/app/views/charges/_charge.html.erb new file mode 100644 index 000000000..76d341137 --- /dev/null +++ b/source/example-app/app/views/charges/_charge.html.erb @@ -0,0 +1,12 @@ + + <%= charge.created %> + <%= charge.paid %> + <%= charge.amount %> + <%= charge.currency %> + <%= charge.refunded %> + <%# full name can go in a helper %> + <%= charge.customer.first_name %> + <%= link_to 'Show', charge %> + <%= link_to 'Edit', edit_charge_path(charge) %> + <%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %> + \ No newline at end of file diff --git a/source/example-app/app/views/charges/_charges.html.erb b/source/example-app/app/views/charges/_charges.html.erb new file mode 100644 index 000000000..14dbd36fd --- /dev/null +++ b/source/example-app/app/views/charges/_charges.html.erb @@ -0,0 +1,18 @@ +> + + + + + + + + + + + + + + + <%= render partial: 'charge', collection: charges %> + +
CreatedPaidAmountCurrencyRefundedCustomer
\ No newline at end of file diff --git a/source/example-app/app/views/charges/index.html.erb b/source/example-app/app/views/charges/index.html.erb index 38dfa35f4..97f24a7f9 100644 --- a/source/example-app/app/views/charges/index.html.erb +++ b/source/example-app/app/views/charges/index.html.erb @@ -1,36 +1,17 @@ -

Listing charges

- - - - - - - - - - - - - - - - - - <% @charges.each do |charge| %> - - - - - - - - - - - - <% end %> - -
CreatedPaidAmountCurrencyRefundedCustomer
<%= charge.created %><%= charge.paid %><%= charge.amount %><%= charge.currency %><%= charge.refunded %><%= charge.customer %><%= link_to 'Show', charge %><%= link_to 'Edit', edit_charge_path(charge) %><%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +<%# we can extract the titles from the scope to assign them to the titles in the partial %> + +

Failed Charges

+ +<%= render partial: 'charges', locals: {id: 'failed-charges', charges: @charges.failed} %> + +

Disputed Charges

+ +<%= render partial: 'charges', locals: {id: 'disputed-charges', charges: @charges.disputed} %> + +

Successful Charges

+ +<%= render partial: 'charges', locals: {id: 'successful-charges', charges: @charges.successful} %>
diff --git a/source/example-app/db/schema.rb b/source/example-app/db/schema.rb new file mode 100644 index 000000000..bb6226cd7 --- /dev/null +++ b/source/example-app/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: 20210420134839) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "charges", force: true do |t| + t.integer "created" + t.boolean "paid" + t.decimal "amount" + t.string "currency" + t.boolean "refunded" + t.integer "customer_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "charges", ["customer_id"], name: "index_charges_on_customer_id", using: :btree + + create_table "customers", force: true do |t| + t.string "first_name" + t.string "last_name" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/source/example-app/db/seeds.rb b/source/example-app/db/seeds.rb index 4edb1e857..4b8ca8706 100644 --- a/source/example-app/db/seeds.rb +++ b/source/example-app/db/seeds.rb @@ -5,3 +5,47 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +Customer.create(first_name: "Johny", last_name: "Flow") +Customer.create(first_name: "Raj", last_name: "Jamnis") +Customer.create(first_name: "Andrew", last_name: "Chung") +Customer.create(first_name: "Mike", last_name: "Smith") + +# 10 Should be successful Charges: +# - 5 Should be linked to Customer 1 +# - 3 Should be linked to Customer 2 +# - 1 Should be linked to Customer 3 +# - 1 Should be linked to Customer 4 + +Charge.create(paid: true, amount: 10.50, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 150, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 20, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 30, currency: 'usd', customer_id: 1) +Charge.create(paid: true, amount: 45, currency: 'usd', customer_id: 1) + +Charge.create(paid: true, amount: 10.50, currency: 'usd', customer_id: 2) +Charge.create(paid: true, amount: 150, currency: 'usd', customer_id: 2) +Charge.create(paid: true, amount: 20, currency: 'usd', customer_id: 2) + +Charge.create(paid: true, amount: 30, currency: 'usd', customer_id: 3) + +Charge.create(paid: true, amount: 45, currency: 'usd', customer_id: 4) + + +# 5 Should be Charges that failed: +# - 3 Should be linked to Customer 3 +# - 2 Should be linked to Customer 4 + +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) + +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 4) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 4) + +# 5 should be disputed: +# - 3 should be linked to Customer 1 +# - 2 should be linked to customer 2 + +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 1) +Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 2) diff --git a/source/example-app/spec/features/charges_spec.rb b/source/example-app/spec/features/charges_spec.rb new file mode 100644 index 000000000..7fe20131a --- /dev/null +++ b/source/example-app/spec/features/charges_spec.rb @@ -0,0 +1,12 @@ +require "rails_helper" + +RSpec.feature "Charges index", :type => :feature do + scenario "User can see different types of charges" do + visit "/charges/" + + expect(page).to have_text("Successful Charges") + expect(page).to have_text("Failed Charges") + expect(page).to have_text("Disputed Charges") + + end +end \ No newline at end of file diff --git a/source/example-app/spec/rails_helper.rb b/source/example-app/spec/rails_helper.rb index f4fd4d440..bf60770ed 100644 --- a/source/example-app/spec/rails_helper.rb +++ b/source/example-app/spec/rails_helper.rb @@ -1,3 +1,5 @@ +require 'database_cleaner' + # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' @@ -39,7 +41,7 @@ # 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 + config.use_transactional_fixtures = 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 @@ -60,4 +62,28 @@ config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + + config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner.strategy = :transaction + end + + config.before(:each, js: true) do + DatabaseCleaner.strategy = :truncation + end + + config.before :suite do + load "#{Rails.root}/db/seeds.rb" + end + + config.after(:all) do + DatabaseCleaner.clean + end + + config.after(:suite) do + DatabaseCleaner.clean_with(:truncation) + end end diff --git a/source/example-app/spec/views/charges/_charge.html.erb b/source/example-app/spec/views/charges/_charge.html.erb new file mode 100644 index 000000000..76d341137 --- /dev/null +++ b/source/example-app/spec/views/charges/_charge.html.erb @@ -0,0 +1,12 @@ + + <%= charge.created %> + <%= charge.paid %> + <%= charge.amount %> + <%= charge.currency %> + <%= charge.refunded %> + <%# full name can go in a helper %> + <%= charge.customer.first_name %> + <%= link_to 'Show', charge %> + <%= link_to 'Edit', edit_charge_path(charge) %> + <%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %> + \ No newline at end of file diff --git a/source/example-app/spec/views/charges/_charges.html.erb b/source/example-app/spec/views/charges/_charges.html.erb new file mode 100644 index 000000000..14dbd36fd --- /dev/null +++ b/source/example-app/spec/views/charges/_charges.html.erb @@ -0,0 +1,18 @@ +> + + + + + + + + + + + + + + + <%= render partial: 'charge', collection: charges %> + +
CreatedPaidAmountCurrencyRefundedCustomer
\ No newline at end of file diff --git a/source/example-app/spec/views/charges/index.html.erb b/source/example-app/spec/views/charges/index.html.erb new file mode 100644 index 000000000..c51a5c3bc --- /dev/null +++ b/source/example-app/spec/views/charges/index.html.erb @@ -0,0 +1,18 @@ + +<%# we can extract the titles from the scope to assign them to the titles in the partial %> + +

Failed Charges

+ +<%= render partial: 'charges', locals: {charges: @charges.failed} %> + +

Disputed Charges

+ +<%= render partial: 'charges', locals: {charges: @charges.disputed} %> + +

Successful Charges

+ +<%= render partial: 'charges', locals: {charges: @charges.successful} %> + +
+ +<%= link_to 'New Charge', new_charge_path %> From 767c34af9b558e2a1417a59183e755e689f7f533 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 11:10:48 -0400 Subject: [PATCH 31/40] Update scopes syntax --- source/example-app/app/models/charge.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/example-app/app/models/charge.rb b/source/example-app/app/models/charge.rb index add811500..717434265 100644 --- a/source/example-app/app/models/charge.rb +++ b/source/example-app/app/models/charge.rb @@ -3,7 +3,7 @@ class Charge < ActiveRecord::Base # we can put indexes on columns to make the queries faster - scope :failed, -> { where("NOT paid") } - scope :disputed, -> { where("refunded") } - scope :successful, -> { where("paid") } + scope :failed, -> { where(paid: false) } + scope :disputed, -> { where(paid: true, refunded: true) } + scope :successful, -> { where(paid: true, refunded: false) } end From d937d5993f7082f8feecbb134fe7429396d172be Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 11:11:20 -0400 Subject: [PATCH 32/40] Add class to charge partial to use it in RSpec tests --- source/example-app/app/views/charges/_charge.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/example-app/app/views/charges/_charge.html.erb b/source/example-app/app/views/charges/_charge.html.erb index 76d341137..26d648c68 100644 --- a/source/example-app/app/views/charges/_charge.html.erb +++ b/source/example-app/app/views/charges/_charge.html.erb @@ -1,4 +1,4 @@ - + <%= charge.created %> <%= charge.paid %> <%= charge.amount %> From 11f279387b00c5a7386ad29794489988d5532c3d Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 11:13:04 -0400 Subject: [PATCH 33/40] Change the seeds to make them fit differente types of transactions as required --- source/example-app/db/seeds.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/example-app/db/seeds.rb b/source/example-app/db/seeds.rb index 4b8ca8706..d5d132d05 100644 --- a/source/example-app/db/seeds.rb +++ b/source/example-app/db/seeds.rb @@ -47,5 +47,5 @@ # - 3 should be linked to Customer 1 # - 2 should be linked to customer 2 -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 1) -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 2) +Charge.create(paid: true, amount: 45, currency: 'usd', refunded: true, customer_id: 1) +Charge.create(paid: true, amount: 45, currency: 'usd', refunded: true, customer_id: 2) From 642ed23896d548a51ae8defcc1a607eda8c03f30 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 11:15:37 -0400 Subject: [PATCH 34/40] Add more default values and constraints to models --- .../migrate/20210420134753_create_customers.rb | 4 ++-- .../migrate/20210420134839_create_charges.rb | 18 +++++++++++++----- source/example-app/db/schema.rb | 14 +++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/source/example-app/db/migrate/20210420134753_create_customers.rb b/source/example-app/db/migrate/20210420134753_create_customers.rb index ab9127003..f17897892 100644 --- a/source/example-app/db/migrate/20210420134753_create_customers.rb +++ b/source/example-app/db/migrate/20210420134753_create_customers.rb @@ -1,8 +1,8 @@ class CreateCustomers < ActiveRecord::Migration def change create_table :customers do |t| - t.string :first_name - t.string :last_name + t.string :first_name, null: false, limit: 50 + t.string :last_name, null: false, limit: 50 t.timestamps end diff --git a/source/example-app/db/migrate/20210420134839_create_charges.rb b/source/example-app/db/migrate/20210420134839_create_charges.rb index a7a3619f6..9c50d5b5e 100644 --- a/source/example-app/db/migrate/20210420134839_create_charges.rb +++ b/source/example-app/db/migrate/20210420134839_create_charges.rb @@ -1,14 +1,22 @@ class CreateCharges < ActiveRecord::Migration def change create_table :charges do |t| - t.integer :created - t.boolean :paid + t.integer :created, null: false + t.boolean :paid, null: false, default: false t.decimal :amount - t.string :currency - t.boolean :refunded - t.references :customer, index: true + t.string :currency, null: false + t.boolean :refunded, null: false, default: false + t.references :customer, index: true, null: false t.timestamps end + reversible do |dir| + dir.up do + execute <<-SQL + ALTER TABLE charges + ALTER COLUMN created SET DEFAULT date_part('epoch', current_timestamp); + SQL + end + end end end diff --git a/source/example-app/db/schema.rb b/source/example-app/db/schema.rb index bb6226cd7..4ea05f28a 100644 --- a/source/example-app/db/schema.rb +++ b/source/example-app/db/schema.rb @@ -17,12 +17,12 @@ enable_extension "plpgsql" create_table "charges", force: true do |t| - t.integer "created" - t.boolean "paid" + t.integer "created", null: false + t.boolean "paid", default: false, null: false t.decimal "amount" - t.string "currency" - t.boolean "refunded" - t.integer "customer_id" + t.string "currency", null: false + t.boolean "refunded", default: false, null: false + t.integer "customer_id", null: false t.datetime "created_at" t.datetime "updated_at" end @@ -30,8 +30,8 @@ add_index "charges", ["customer_id"], name: "index_charges_on_customer_id", using: :btree create_table "customers", force: true do |t| - t.string "first_name" - t.string "last_name" + t.string "first_name", limit: 50, null: false + t.string "last_name", limit: 50, null: false t.datetime "created_at" t.datetime "updated_at" end From f097556bd5d2043baec98a4789204e33e57171fe Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 11:15:57 -0400 Subject: [PATCH 35/40] Add assertion test as required --- .../example-app/spec/features/charges_spec.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/example-app/spec/features/charges_spec.rb b/source/example-app/spec/features/charges_spec.rb index 7fe20131a..4a0535b2a 100644 --- a/source/example-app/spec/features/charges_spec.rb +++ b/source/example-app/spec/features/charges_spec.rb @@ -1,12 +1,21 @@ require "rails_helper" RSpec.feature "Charges index", :type => :feature do - scenario "User can see different types of charges" do + before(:each) do visit "/charges/" + end - expect(page).to have_text("Successful Charges") - expect(page).to have_text("Failed Charges") - expect(page).to have_text("Disputed Charges") + describe "User visits the index page of the transactions" do + it "Can see the lists of types of transactions" do + expect(page).to have_text("Successful Charges") + expect(page).to have_text("Failed Charges") + expect(page).to have_text("Disputed Charges") + end + it "Can see the exact number of transactions in its corresponding list" do + page.assert_selector('#successful-charges .charge-item', count: 10) + page.assert_selector('#failed-charges .charge-item', count: 5) + page.assert_selector('#disputed-charges .charge-item') + end end end \ No newline at end of file From ad6f0008cdd7b70daaf7e4707cfdfd20f69ae78f Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 11:21:05 -0400 Subject: [PATCH 36/40] Add clarifications --- source/example-app/app/models/charge.rb | 3 +++ .../example-app/db/migrate/20210420134753_create_customers.rb | 1 + source/example-app/db/migrate/20210420134839_create_charges.rb | 3 +++ 3 files changed, 7 insertions(+) diff --git a/source/example-app/app/models/charge.rb b/source/example-app/app/models/charge.rb index 717434265..9cd227100 100644 --- a/source/example-app/app/models/charge.rb +++ b/source/example-app/app/models/charge.rb @@ -1,6 +1,9 @@ class Charge < ActiveRecord::Base belongs_to :customer + # I'm not fully knowing the conditions to filter the different types + # I can investigate them, but it's going to take me longer to complete the challenge + # # we can put indexes on columns to make the queries faster scope :failed, -> { where(paid: false) } diff --git a/source/example-app/db/migrate/20210420134753_create_customers.rb b/source/example-app/db/migrate/20210420134753_create_customers.rb index f17897892..9dec5cbe7 100644 --- a/source/example-app/db/migrate/20210420134753_create_customers.rb +++ b/source/example-app/db/migrate/20210420134753_create_customers.rb @@ -4,6 +4,7 @@ def change t.string :first_name, null: false, limit: 50 t.string :last_name, null: false, limit: 50 + # I didn't see in the specifications these columns, but I'm going to keep them t.timestamps end end diff --git a/source/example-app/db/migrate/20210420134839_create_charges.rb b/source/example-app/db/migrate/20210420134839_create_charges.rb index 9c50d5b5e..c7baa789c 100644 --- a/source/example-app/db/migrate/20210420134839_create_charges.rb +++ b/source/example-app/db/migrate/20210420134839_create_charges.rb @@ -1,5 +1,8 @@ class CreateCharges < ActiveRecord::Migration def change + # some of the default values and constraints might not apply for this case + # need more information about them, just guessed + create_table :charges do |t| t.integer :created, null: false t.boolean :paid, null: false, default: false From 1bed94f9c132136e067a806d48b652d9b97495a6 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 12:05:34 -0400 Subject: [PATCH 37/40] Add danger and salmon class styling --- source/example-app/app/assets/stylesheets/application.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/example-app/app/assets/stylesheets/application.css b/source/example-app/app/assets/stylesheets/application.css index 3192ec897..a63edf58d 100644 --- a/source/example-app/app/assets/stylesheets/application.css +++ b/source/example-app/app/assets/stylesheets/application.css @@ -11,3 +11,11 @@ *= require_self *= require_tree . */ + +.danger { + background-color: #FF0000; +} + +.salmon { + background-color: #FF5400; +} \ No newline at end of file From e64abdae07e26bcff65ff2203559b697914734ae Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 12:06:17 -0400 Subject: [PATCH 38/40] Separate unsuccessful charges partials from the successful ones --- .../app/views/charges/_charge.html.erb | 6 ++-- .../app/views/charges/_charges.html.erb | 3 +- .../charges/_not_successful_charge.html.erb | 9 +++++ .../charges/_not_successful_charges.html.erb | 16 +++++++++ .../app/views/charges/index.html.erb | 34 +++++++++++++------ 5 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 source/example-app/app/views/charges/_not_successful_charge.html.erb create mode 100644 source/example-app/app/views/charges/_not_successful_charges.html.erb diff --git a/source/example-app/app/views/charges/_charge.html.erb b/source/example-app/app/views/charges/_charge.html.erb index 26d648c68..7eff1dcb0 100644 --- a/source/example-app/app/views/charges/_charge.html.erb +++ b/source/example-app/app/views/charges/_charge.html.erb @@ -1,11 +1,11 @@ - + <%= charge.created %> <%= charge.paid %> <%= charge.amount %> <%= charge.currency %> <%= charge.refunded %> - <%# full name can go in a helper %> - <%= charge.customer.first_name %> + + <%= "#{charge.customer.first_name} #{charge.customer.last_name}" %> <%= link_to 'Show', charge %> <%= link_to 'Edit', edit_charge_path(charge) %> <%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/source/example-app/app/views/charges/_charges.html.erb b/source/example-app/app/views/charges/_charges.html.erb index 14dbd36fd..1d2ccd9ea 100644 --- a/source/example-app/app/views/charges/_charges.html.erb +++ b/source/example-app/app/views/charges/_charges.html.erb @@ -1,3 +1,4 @@ +

<%= title %>

> @@ -13,6 +14,6 @@ - <%= render partial: 'charge', collection: charges %> + <%= render partial: 'charge', collection: charges, locals: {row_class: row_class} %>
\ No newline at end of file diff --git a/source/example-app/app/views/charges/_not_successful_charge.html.erb b/source/example-app/app/views/charges/_not_successful_charge.html.erb new file mode 100644 index 000000000..fb6f16bef --- /dev/null +++ b/source/example-app/app/views/charges/_not_successful_charge.html.erb @@ -0,0 +1,9 @@ + + <%= "#{charge.customer.first_name} #{charge.customer.last_name}" %> + <%= "#{charge.amount} #{charge.currency}" %> + <%= charge.created %> + + <%= link_to 'Show', charge %> + <%= link_to 'Edit', edit_charge_path(charge) %> + <%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %> + \ No newline at end of file diff --git a/source/example-app/app/views/charges/_not_successful_charges.html.erb b/source/example-app/app/views/charges/_not_successful_charges.html.erb new file mode 100644 index 000000000..450dba880 --- /dev/null +++ b/source/example-app/app/views/charges/_not_successful_charges.html.erb @@ -0,0 +1,16 @@ +

<%= title %>

+> + + + + + + + + + + + + <%= render partial: 'not_successful_charge', collection: charges, as: :charge, locals: {row_class: row_class} %> + +
CustomerAmountDate
\ No newline at end of file diff --git a/source/example-app/app/views/charges/index.html.erb b/source/example-app/app/views/charges/index.html.erb index 97f24a7f9..86de5cd2f 100644 --- a/source/example-app/app/views/charges/index.html.erb +++ b/source/example-app/app/views/charges/index.html.erb @@ -1,17 +1,29 @@ <%# we can extract the titles from the scope to assign them to the titles in the partial %> -

Failed Charges

- -<%= render partial: 'charges', locals: {id: 'failed-charges', charges: @charges.failed} %> - -

Disputed Charges

- -<%= render partial: 'charges', locals: {id: 'disputed-charges', charges: @charges.disputed} %> - -

Successful Charges

- -<%= render partial: 'charges', locals: {id: 'successful-charges', charges: @charges.successful} %> +<%= render partial: 'not_successful_charges', + locals: { + id: 'failed-charges', + title: 'Failed Charges', + charges: @charges.failed, + row_class: 'danger' + } %> + +<%= render partial: 'not_successful_charges', + locals: { + id: 'disputed-charges', + title: 'Disputed Charges', + charges: @charges.disputed, + row_class: 'salmon' + } %> + +<%= render partial: 'charges', + locals: { + id: 'successful-charges', + title: 'Successful Charges', + charges: @charges.successful, + row_class: '' + } %>
From 46edc334bd024eb695a6d90b99d5256572756c66 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 12:08:15 -0400 Subject: [PATCH 39/40] Remove previous version of project --- source/exampleApp/.gitignore | 16 -- source/exampleApp/Gemfile | 51 ------- source/exampleApp/Gemfile.lock | 141 ------------------ source/exampleApp/README.rdoc | 28 ---- source/exampleApp/Rakefile | 6 - source/exampleApp/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 16 -- .../app/assets/javascripts/charges.js.coffee | 3 - .../assets/javascripts/customers.js.coffee | 3 - .../app/assets/stylesheets/application.css | 13 -- .../app/assets/stylesheets/charges.css.scss | 3 - .../app/assets/stylesheets/customers.css.scss | 3 - .../app/assets/stylesheets/scaffolds.css.scss | 69 --------- .../app/controllers/application_controller.rb | 5 - .../app/controllers/charges_controller.rb | 74 --------- .../exampleApp/app/controllers/concerns/.keep | 0 .../app/controllers/customers_controller.rb | 74 --------- .../app/helpers/application_helper.rb | 2 - .../exampleApp/app/helpers/charges_helper.rb | 2 - .../app/helpers/customers_helper.rb | 2 - source/exampleApp/app/mailers/.keep | 0 source/exampleApp/app/models/.keep | 0 source/exampleApp/app/models/charge.rb | 10 -- source/exampleApp/app/models/concerns/.keep | 0 source/exampleApp/app/models/customer.rb | 2 - .../app/views/charges/_charge.html.erb | 12 -- .../app/views/charges/_charges.html.erb | 18 --- .../app/views/charges/_form.html.erb | 41 ----- .../app/views/charges/edit.html.erb | 6 - .../app/views/charges/index.html.erb | 18 --- .../app/views/charges/index.json.jbuilder | 4 - .../exampleApp/app/views/charges/new.html.erb | 5 - .../app/views/charges/show.html.erb | 34 ----- .../app/views/charges/show.json.jbuilder | 1 - .../app/views/customers/_form.html.erb | 25 ---- .../app/views/customers/edit.html.erb | 6 - .../app/views/customers/index.html.erb | 29 ---- .../app/views/customers/index.json.jbuilder | 4 - .../app/views/customers/new.html.erb | 5 - .../app/views/customers/show.html.erb | 14 -- .../app/views/customers/show.json.jbuilder | 1 - .../app/views/layouts/application.html.erb | 14 -- source/exampleApp/bin/bundle | 3 - source/exampleApp/bin/rails | 4 - source/exampleApp/bin/rake | 4 - source/exampleApp/config.ru | 4 - source/exampleApp/config/application.rb | 28 ---- source/exampleApp/config/boot.rb | 4 - source/exampleApp/config/database.yml | 60 -------- source/exampleApp/config/environment.rb | 5 - .../config/environments/development.rb | 29 ---- .../config/environments/production.rb | 80 ---------- source/exampleApp/config/environments/test.rb | 36 ----- .../initializers/backtrace_silencers.rb | 7 - .../initializers/filter_parameter_logging.rb | 4 - .../config/initializers/inflections.rb | 16 -- .../config/initializers/mime_types.rb | 5 - .../config/initializers/secret_token.rb | 12 -- .../config/initializers/session_store.rb | 3 - .../config/initializers/wrap_parameters.rb | 14 -- source/exampleApp/config/locales/en.yml | 23 --- source/exampleApp/config/routes.rb | 60 -------- .../20210420034344_create_customers.rb | 10 -- .../migrate/20210420045643_create_charges.rb | 22 --- source/exampleApp/db/schema.rb | 39 ----- source/exampleApp/db/seeds.rb | 51 ------- source/exampleApp/lib/assets/.keep | 0 source/exampleApp/lib/tasks/.keep | 0 source/exampleApp/log/.keep | 0 source/exampleApp/public/404.html | 58 ------- source/exampleApp/public/422.html | 58 ------- source/exampleApp/public/500.html | 57 ------- source/exampleApp/public/favicon.ico | 0 source/exampleApp/public/robots.txt | 5 - source/exampleApp/spec/rails_helper.rb | 63 -------- source/exampleApp/spec/spec_helper.rb | 96 ------------ .../spec/views/charges/index.html.erb_spec.rb | 9 -- .../vendor/assets/javascripts/.keep | 0 .../vendor/assets/stylesheets/.keep | 0 79 files changed, 1629 deletions(-) delete mode 100644 source/exampleApp/.gitignore delete mode 100644 source/exampleApp/Gemfile delete mode 100644 source/exampleApp/Gemfile.lock delete mode 100644 source/exampleApp/README.rdoc delete mode 100644 source/exampleApp/Rakefile delete mode 100644 source/exampleApp/app/assets/images/.keep delete mode 100644 source/exampleApp/app/assets/javascripts/application.js delete mode 100644 source/exampleApp/app/assets/javascripts/charges.js.coffee delete mode 100644 source/exampleApp/app/assets/javascripts/customers.js.coffee delete mode 100644 source/exampleApp/app/assets/stylesheets/application.css delete mode 100644 source/exampleApp/app/assets/stylesheets/charges.css.scss delete mode 100644 source/exampleApp/app/assets/stylesheets/customers.css.scss delete mode 100644 source/exampleApp/app/assets/stylesheets/scaffolds.css.scss delete mode 100644 source/exampleApp/app/controllers/application_controller.rb delete mode 100644 source/exampleApp/app/controllers/charges_controller.rb delete mode 100644 source/exampleApp/app/controllers/concerns/.keep delete mode 100644 source/exampleApp/app/controllers/customers_controller.rb delete mode 100644 source/exampleApp/app/helpers/application_helper.rb delete mode 100644 source/exampleApp/app/helpers/charges_helper.rb delete mode 100644 source/exampleApp/app/helpers/customers_helper.rb delete mode 100644 source/exampleApp/app/mailers/.keep delete mode 100644 source/exampleApp/app/models/.keep delete mode 100644 source/exampleApp/app/models/charge.rb delete mode 100644 source/exampleApp/app/models/concerns/.keep delete mode 100644 source/exampleApp/app/models/customer.rb delete mode 100644 source/exampleApp/app/views/charges/_charge.html.erb delete mode 100644 source/exampleApp/app/views/charges/_charges.html.erb delete mode 100644 source/exampleApp/app/views/charges/_form.html.erb delete mode 100644 source/exampleApp/app/views/charges/edit.html.erb delete mode 100644 source/exampleApp/app/views/charges/index.html.erb delete mode 100644 source/exampleApp/app/views/charges/index.json.jbuilder delete mode 100644 source/exampleApp/app/views/charges/new.html.erb delete mode 100644 source/exampleApp/app/views/charges/show.html.erb delete mode 100644 source/exampleApp/app/views/charges/show.json.jbuilder delete mode 100644 source/exampleApp/app/views/customers/_form.html.erb delete mode 100644 source/exampleApp/app/views/customers/edit.html.erb delete mode 100644 source/exampleApp/app/views/customers/index.html.erb delete mode 100644 source/exampleApp/app/views/customers/index.json.jbuilder delete mode 100644 source/exampleApp/app/views/customers/new.html.erb delete mode 100644 source/exampleApp/app/views/customers/show.html.erb delete mode 100644 source/exampleApp/app/views/customers/show.json.jbuilder delete mode 100644 source/exampleApp/app/views/layouts/application.html.erb delete mode 100755 source/exampleApp/bin/bundle delete mode 100755 source/exampleApp/bin/rails delete mode 100755 source/exampleApp/bin/rake delete mode 100644 source/exampleApp/config.ru delete mode 100644 source/exampleApp/config/application.rb delete mode 100644 source/exampleApp/config/boot.rb delete mode 100644 source/exampleApp/config/database.yml delete mode 100644 source/exampleApp/config/environment.rb delete mode 100644 source/exampleApp/config/environments/development.rb delete mode 100644 source/exampleApp/config/environments/production.rb delete mode 100644 source/exampleApp/config/environments/test.rb delete mode 100644 source/exampleApp/config/initializers/backtrace_silencers.rb delete mode 100644 source/exampleApp/config/initializers/filter_parameter_logging.rb delete mode 100644 source/exampleApp/config/initializers/inflections.rb delete mode 100644 source/exampleApp/config/initializers/mime_types.rb delete mode 100644 source/exampleApp/config/initializers/secret_token.rb delete mode 100644 source/exampleApp/config/initializers/session_store.rb delete mode 100644 source/exampleApp/config/initializers/wrap_parameters.rb delete mode 100644 source/exampleApp/config/locales/en.yml delete mode 100644 source/exampleApp/config/routes.rb delete mode 100644 source/exampleApp/db/migrate/20210420034344_create_customers.rb delete mode 100644 source/exampleApp/db/migrate/20210420045643_create_charges.rb delete mode 100644 source/exampleApp/db/schema.rb delete mode 100644 source/exampleApp/db/seeds.rb delete mode 100644 source/exampleApp/lib/assets/.keep delete mode 100644 source/exampleApp/lib/tasks/.keep delete mode 100644 source/exampleApp/log/.keep delete mode 100644 source/exampleApp/public/404.html delete mode 100644 source/exampleApp/public/422.html delete mode 100644 source/exampleApp/public/500.html delete mode 100644 source/exampleApp/public/favicon.ico delete mode 100644 source/exampleApp/public/robots.txt delete mode 100644 source/exampleApp/spec/rails_helper.rb delete mode 100644 source/exampleApp/spec/spec_helper.rb delete mode 100644 source/exampleApp/spec/views/charges/index.html.erb_spec.rb delete mode 100644 source/exampleApp/vendor/assets/javascripts/.keep delete mode 100644 source/exampleApp/vendor/assets/stylesheets/.keep diff --git a/source/exampleApp/.gitignore b/source/exampleApp/.gitignore deleted file mode 100644 index 25a742dff..000000000 --- a/source/exampleApp/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# See http://help.github.com/ignore-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 -/tmp diff --git a/source/exampleApp/Gemfile b/source/exampleApp/Gemfile deleted file mode 100644 index 095a67d07..000000000 --- a/source/exampleApp/Gemfile +++ /dev/null @@ -1,51 +0,0 @@ -source 'https://rubygems.org' - -ruby "2.0.0" -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.0.0' - -# Use postgresql as the database for Active Record -gem 'pg', '~> 0.20.0' - -# Use SCSS for stylesheets -gem 'sass-rails', '~> 4.0.0' - -# Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' - -# Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' - -# See https://github.com/sstephenson/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', '~> 1.3' - -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 1.2' - -group :doc do - # bundle exec rake doc:rails generates the API under doc/api. - gem 'sdoc', require: false -end - -group :development do - # bundle exec rake doc:rails generates the API under doc/api. - gem 'rspec-rails', '3.9.1' -end - -# Use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' - -# Use unicorn as the app server -# gem 'unicorn' - -# Use Capistrano for deployment -# gem 'capistrano', group: :development - -# Use debugger -# gem 'debugger', group: [:development, :test] diff --git a/source/exampleApp/Gemfile.lock b/source/exampleApp/Gemfile.lock deleted file mode 100644 index b8ab1fdf2..000000000 --- a/source/exampleApp/Gemfile.lock +++ /dev/null @@ -1,141 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.0.0) - actionpack (= 4.0.0) - mail (~> 2.5.3) - actionpack (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - activerecord (4.0.0) - activemodel (= 4.0.0) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.0) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.0) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) - builder (3.1.4) - coffee-rails (4.0.1) - coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.8) - diff-lcs (1.4.4) - erubis (2.7.0) - execjs (2.7.0) - hike (1.2.3) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - jbuilder (1.5.3) - activesupport (>= 3.0.0) - multi_json (>= 1.2.0) - jquery-rails (3.1.5) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) - mail (2.5.5) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.25.1) - minitest (4.7.5) - multi_json (1.15.0) - pg (0.20.0) - polyglot (0.3.5) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.0.0) - actionmailer (= 4.0.0) - actionpack (= 4.0.0) - activerecord (= 4.0.0) - activesupport (= 4.0.0) - bundler (>= 1.3.0, < 2.0) - railties (= 4.0.0) - sprockets-rails (~> 2.0.0) - railties (4.0.0) - actionpack (= 4.0.0) - activesupport (= 4.0.0) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.3) - rdoc (5.1.0) - rspec-core (3.9.3) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.4) - 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.4) - sass (3.2.19) - sass-rails (4.0.5) - railties (>= 4.0.0, < 5.0) - sass (~> 3.2.2) - sprockets (~> 2.8, < 3.0) - sprockets-rails (~> 2.0) - sdoc (2.1.0) - rdoc (>= 5.0) - sprockets (2.12.5) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (~> 2.8) - thor (1.1.0) - thread_safe (0.3.6) - tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - turbolinks (1.3.1) - coffee-rails - tzinfo (0.3.60) - uglifier (4.2.0) - execjs (>= 0.3.0, < 3) - -PLATFORMS - ruby - -DEPENDENCIES - coffee-rails (~> 4.0.0) - jbuilder (~> 1.2) - jquery-rails - pg (~> 0.20.0) - rails (= 4.0.0) - rspec-rails (= 3.9.1) - sass-rails (~> 4.0.0) - sdoc - turbolinks (~> 1.3) - uglifier (>= 1.3.0) - -RUBY VERSION - ruby 2.0.0p648 - -BUNDLED WITH - 1.17.3 diff --git a/source/exampleApp/README.rdoc b/source/exampleApp/README.rdoc deleted file mode 100644 index dd4e97e22..000000000 --- a/source/exampleApp/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== 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/exampleApp/Rakefile b/source/exampleApp/Rakefile deleted file mode 100644 index e67201a82..000000000 --- a/source/exampleApp/Rakefile +++ /dev/null @@ -1,6 +0,0 @@ -# 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__) - -ExampleApp::Application.load_tasks diff --git a/source/exampleApp/app/assets/images/.keep b/source/exampleApp/app/assets/images/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/app/assets/javascripts/application.js b/source/exampleApp/app/assets/javascripts/application.js deleted file mode 100644 index d6925fa43..000000000 --- a/source/exampleApp/app/assets/javascripts/application.js +++ /dev/null @@ -1,16 +0,0 @@ -// 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 vendor/assets/javascripts of plugins, if any, 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/sstephenson/sprockets#sprockets-directives) for details -// about supported directives. -// -//= require jquery -//= require jquery_ujs -//= require turbolinks -//= require_tree . diff --git a/source/exampleApp/app/assets/javascripts/charges.js.coffee b/source/exampleApp/app/assets/javascripts/charges.js.coffee deleted file mode 100644 index 24f83d18b..000000000 --- a/source/exampleApp/app/assets/javascripts/charges.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# 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/exampleApp/app/assets/javascripts/customers.js.coffee b/source/exampleApp/app/assets/javascripts/customers.js.coffee deleted file mode 100644 index 24f83d18b..000000000 --- a/source/exampleApp/app/assets/javascripts/customers.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# 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/exampleApp/app/assets/stylesheets/application.css b/source/exampleApp/app/assets/stylesheets/application.css deleted file mode 100644 index 3192ec897..000000000 --- a/source/exampleApp/app/assets/stylesheets/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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 vendor/assets/stylesheets of plugins, if any, 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 top of the - * compiled file, but it's generally better to create a new file per style scope. - * - *= require_self - *= require_tree . - */ diff --git a/source/exampleApp/app/assets/stylesheets/charges.css.scss b/source/exampleApp/app/assets/stylesheets/charges.css.scss deleted file mode 100644 index c3a893042..000000000 --- a/source/exampleApp/app/assets/stylesheets/charges.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Charges controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/exampleApp/app/assets/stylesheets/customers.css.scss b/source/exampleApp/app/assets/stylesheets/customers.css.scss deleted file mode 100644 index 892b0ad94..000000000 --- a/source/exampleApp/app/assets/stylesheets/customers.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the customers controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/exampleApp/app/assets/stylesheets/scaffolds.css.scss b/source/exampleApp/app/assets/stylesheets/scaffolds.css.scss deleted file mode 100644 index 6ec6a8ff5..000000000 --- a/source/exampleApp/app/assets/stylesheets/scaffolds.css.scss +++ /dev/null @@ -1,69 +0,0 @@ -body { - background-color: #fff; - color: #333; - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - &:visited { - color: #666; - } - &:hover { - color: #fff; - background-color: #000; - } -} - -div { - &.field, &.actions { - margin-bottom: 10px; - } -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px; - padding-bottom: 0; - margin-bottom: 20px; - background-color: #f0f0f0; - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - margin-bottom: 0px; - background-color: #c00; - color: #fff; - } - ul li { - font-size: 12px; - list-style: square; - } -} diff --git a/source/exampleApp/app/controllers/application_controller.rb b/source/exampleApp/app/controllers/application_controller.rb deleted file mode 100644 index d83690e1b..000000000 --- a/source/exampleApp/app/controllers/application_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -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/exampleApp/app/controllers/charges_controller.rb b/source/exampleApp/app/controllers/charges_controller.rb deleted file mode 100644 index 5c57af40d..000000000 --- a/source/exampleApp/app/controllers/charges_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -class ChargesController < ApplicationController - before_action :set_charge, only: [:show, :edit, :update, :destroy] - - # GET /charges - # GET /charges.json - def index - @charges = Charge.all - 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 action: 'show', status: :created, location: @charge } - else - format.html { render action: '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 { head :no_content } - else - format.html { render action: '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 } - 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, :currency, :refunded, :customer_id) - end -end diff --git a/source/exampleApp/app/controllers/concerns/.keep b/source/exampleApp/app/controllers/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/app/controllers/customers_controller.rb b/source/exampleApp/app/controllers/customers_controller.rb deleted file mode 100644 index 0210a69a7..000000000 --- a/source/exampleApp/app/controllers/customers_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -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 action: 'show', status: :created, location: @customer } - else - format.html { render action: '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 { head :no_content } - else - format.html { render action: '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 } - 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/exampleApp/app/helpers/application_helper.rb b/source/exampleApp/app/helpers/application_helper.rb deleted file mode 100644 index de6be7945..000000000 --- a/source/exampleApp/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/source/exampleApp/app/helpers/charges_helper.rb b/source/exampleApp/app/helpers/charges_helper.rb deleted file mode 100644 index 414ee900f..000000000 --- a/source/exampleApp/app/helpers/charges_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ChargesHelper -end diff --git a/source/exampleApp/app/helpers/customers_helper.rb b/source/exampleApp/app/helpers/customers_helper.rb deleted file mode 100644 index a07ce2943..000000000 --- a/source/exampleApp/app/helpers/customers_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CustomersHelper -end diff --git a/source/exampleApp/app/mailers/.keep b/source/exampleApp/app/mailers/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/app/models/.keep b/source/exampleApp/app/models/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/app/models/charge.rb b/source/exampleApp/app/models/charge.rb deleted file mode 100644 index a99021ced..000000000 --- a/source/exampleApp/app/models/charge.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Charge < ActiveRecord::Base - belongs_to :customer - - # we can put indexes on columns to make the queries faster - - scope :failed, -> { where("NOT paid") } - scope :disputed, -> { where("refunded") } - scope :successful, -> { where("paid") } - -end diff --git a/source/exampleApp/app/models/concerns/.keep b/source/exampleApp/app/models/concerns/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/app/models/customer.rb b/source/exampleApp/app/models/customer.rb deleted file mode 100644 index 047dcb0c0..000000000 --- a/source/exampleApp/app/models/customer.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Customer < ActiveRecord::Base -end diff --git a/source/exampleApp/app/views/charges/_charge.html.erb b/source/exampleApp/app/views/charges/_charge.html.erb deleted file mode 100644 index 76d341137..000000000 --- a/source/exampleApp/app/views/charges/_charge.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - - <%= charge.created %> - <%= charge.paid %> - <%= charge.amount %> - <%= charge.currency %> - <%= charge.refunded %> - <%# full name can go in a helper %> - <%= charge.customer.first_name %> - <%= link_to 'Show', charge %> - <%= link_to 'Edit', edit_charge_path(charge) %> - <%= link_to 'Destroy', charge, method: :delete, data: { confirm: 'Are you sure?' } %> - \ No newline at end of file diff --git a/source/exampleApp/app/views/charges/_charges.html.erb b/source/exampleApp/app/views/charges/_charges.html.erb deleted file mode 100644 index 14dbd36fd..000000000 --- a/source/exampleApp/app/views/charges/_charges.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -> - - - - - - - - - - - - - - - <%= render partial: 'charge', collection: charges %> - -
CreatedPaidAmountCurrencyRefundedCustomer
\ No newline at end of file diff --git a/source/exampleApp/app/views/charges/_form.html.erb b/source/exampleApp/app/views/charges/_form.html.erb deleted file mode 100644 index f818a123a..000000000 --- a/source/exampleApp/app/views/charges/_form.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -<%= form_for(@charge) do |f| %> - <% if @charge.errors.any? %> -
-

<%= pluralize(@charge.errors.count, "error") %> prohibited this charge from being saved:

- -
    - <% @charge.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - -
- <%= f.label :created %>
- <%= f.number_field :created %> -
-
- <%= f.label :paid %>
- <%= f.check_box :paid %> -
-
- <%= f.label :amount %>
- <%= f.text_field :amount %> -
-
- <%= f.label :currency %>
- <%= f.text_field :currency %> -
-
- <%= f.label :refunded %>
- <%= f.check_box :refunded %> -
-
- <%= f.label :customer %>
- <%= f.text_field :customer %> -
-
- <%= f.submit %> -
-<% end %> diff --git a/source/exampleApp/app/views/charges/edit.html.erb b/source/exampleApp/app/views/charges/edit.html.erb deleted file mode 100644 index a723d7a86..000000000 --- a/source/exampleApp/app/views/charges/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing charge

- -<%= render 'form' %> - -<%= link_to 'Show', @charge %> | -<%= link_to 'Back', charges_path %> diff --git a/source/exampleApp/app/views/charges/index.html.erb b/source/exampleApp/app/views/charges/index.html.erb deleted file mode 100644 index 97f24a7f9..000000000 --- a/source/exampleApp/app/views/charges/index.html.erb +++ /dev/null @@ -1,18 +0,0 @@ - -<%# we can extract the titles from the scope to assign them to the titles in the partial %> - -

Failed Charges

- -<%= render partial: 'charges', locals: {id: 'failed-charges', charges: @charges.failed} %> - -

Disputed Charges

- -<%= render partial: 'charges', locals: {id: 'disputed-charges', charges: @charges.disputed} %> - -

Successful Charges

- -<%= render partial: 'charges', locals: {id: 'successful-charges', charges: @charges.successful} %> - -
- -<%= link_to 'New Charge', new_charge_path %> diff --git a/source/exampleApp/app/views/charges/index.json.jbuilder b/source/exampleApp/app/views/charges/index.json.jbuilder deleted file mode 100644 index 9b184d029..000000000 --- a/source/exampleApp/app/views/charges/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@charges) do |charge| - json.extract! charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id - json.url charge_url(charge, format: :json) -end diff --git a/source/exampleApp/app/views/charges/new.html.erb b/source/exampleApp/app/views/charges/new.html.erb deleted file mode 100644 index 8dc59a97d..000000000 --- a/source/exampleApp/app/views/charges/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New charge

- -<%= render 'form' %> - -<%= link_to 'Back', charges_path %> diff --git a/source/exampleApp/app/views/charges/show.html.erb b/source/exampleApp/app/views/charges/show.html.erb deleted file mode 100644 index 551d274bb..000000000 --- a/source/exampleApp/app/views/charges/show.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -

<%= notice %>

- -

- Created: - <%= @charge.created %> -

- -

- Paid: - <%= @charge.paid %> -

- -

- Amount: - <%= @charge.amount %> -

- -

- Currency: - <%= @charge.currency %> -

- -

- Refunded: - <%= @charge.refunded %> -

- -

- Customer: - <%= @charge.customer %> -

- -<%= link_to 'Edit', edit_charge_path(@charge) %> | -<%= link_to 'Back', charges_path %> diff --git a/source/exampleApp/app/views/charges/show.json.jbuilder b/source/exampleApp/app/views/charges/show.json.jbuilder deleted file mode 100644 index 8e1676c10..000000000 --- a/source/exampleApp/app/views/charges/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/exampleApp/app/views/customers/_form.html.erb b/source/exampleApp/app/views/customers/_form.html.erb deleted file mode 100644 index f2db3db1e..000000000 --- a/source/exampleApp/app/views/customers/_form.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%= form_for(@customer) do |f| %> - <% if @customer.errors.any? %> -
-

<%= pluralize(@customer.errors.count, "error") %> prohibited this customer from being saved:

- -
    - <% @customer.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - -
- <%= f.label :first_name %>
- <%= f.text_field :first_name %> -
-
- <%= f.label :last_name %>
- <%= f.text_field :last_name %> -
-
- <%= f.submit %> -
-<% end %> diff --git a/source/exampleApp/app/views/customers/edit.html.erb b/source/exampleApp/app/views/customers/edit.html.erb deleted file mode 100644 index d1ed0a71c..000000000 --- a/source/exampleApp/app/views/customers/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing customer

- -<%= render 'form' %> - -<%= link_to 'Show', @customer %> | -<%= link_to 'Back', customers_path %> diff --git a/source/exampleApp/app/views/customers/index.html.erb b/source/exampleApp/app/views/customers/index.html.erb deleted file mode 100644 index 47ea166c8..000000000 --- a/source/exampleApp/app/views/customers/index.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -

Listing customers

- - - - - - - - - - - - - - <% @customers.each do |customer| %> - - - - - - - - <% end %> - -
First nameLast 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?' } %>
- -
- -<%= link_to 'New Customer', new_customer_path %> diff --git a/source/exampleApp/app/views/customers/index.json.jbuilder b/source/exampleApp/app/views/customers/index.json.jbuilder deleted file mode 100644 index 6aac73b4c..000000000 --- a/source/exampleApp/app/views/customers/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@customers) do |customer| - json.extract! customer, :id, :first_name, :last_name - json.url customer_url(customer, format: :json) -end diff --git a/source/exampleApp/app/views/customers/new.html.erb b/source/exampleApp/app/views/customers/new.html.erb deleted file mode 100644 index a93c20371..000000000 --- a/source/exampleApp/app/views/customers/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New customer

- -<%= render 'form' %> - -<%= link_to 'Back', customers_path %> diff --git a/source/exampleApp/app/views/customers/show.html.erb b/source/exampleApp/app/views/customers/show.html.erb deleted file mode 100644 index cacd47343..000000000 --- a/source/exampleApp/app/views/customers/show.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -

<%= 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/exampleApp/app/views/customers/show.json.jbuilder b/source/exampleApp/app/views/customers/show.json.jbuilder deleted file mode 100644 index a7698de6a..000000000 --- a/source/exampleApp/app/views/customers/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @customer, :id, :first_name, :last_name, :created_at, :updated_at diff --git a/source/exampleApp/app/views/layouts/application.html.erb b/source/exampleApp/app/views/layouts/application.html.erb deleted file mode 100644 index 3a16810af..000000000 --- a/source/exampleApp/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - ExampleApp - <%= 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/exampleApp/bin/bundle b/source/exampleApp/bin/bundle deleted file mode 100755 index 66e9889e8..000000000 --- a/source/exampleApp/bin/bundle +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') diff --git a/source/exampleApp/bin/rails b/source/exampleApp/bin/rails deleted file mode 100755 index 728cd85aa..000000000 --- a/source/exampleApp/bin/rails +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' diff --git a/source/exampleApp/bin/rake b/source/exampleApp/bin/rake deleted file mode 100755 index 17240489f..000000000 --- a/source/exampleApp/bin/rake +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -require_relative '../config/boot' -require 'rake' -Rake.application.run diff --git a/source/exampleApp/config.ru b/source/exampleApp/config.ru deleted file mode 100644 index 5bc2a619e..000000000 --- a/source/exampleApp/config.ru +++ /dev/null @@ -1,4 +0,0 @@ -# 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/exampleApp/config/application.rb b/source/exampleApp/config/application.rb deleted file mode 100644 index 42debc6df..000000000 --- a/source/exampleApp/config/application.rb +++ /dev/null @@ -1,28 +0,0 @@ -require File.expand_path('../boot', __FILE__) - -# Pick the frameworks you want: -require "active_record/railtie" -require "action_controller/railtie" -require "action_mailer/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(:default, Rails.env) - -module ExampleApp - 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 - end -end diff --git a/source/exampleApp/config/boot.rb b/source/exampleApp/config/boot.rb deleted file mode 100644 index 359673666..000000000 --- a/source/exampleApp/config/boot.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) - -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/source/exampleApp/config/database.yml b/source/exampleApp/config/database.yml deleted file mode 100644 index f8fe20d87..000000000 --- a/source/exampleApp/config/database.yml +++ /dev/null @@ -1,60 +0,0 @@ -# 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' -# -development: - adapter: postgresql - encoding: unicode - database: exampleApp_development - pool: 5 - username: postgres - password: 123456 - - # 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: - adapter: postgresql - encoding: unicode - database: exampleApp_test - pool: 5 - username: postgres - password: 123456 - -production: - adapter: postgresql - encoding: unicode - database: exampleApp_production - pool: 5 - username: postgres - password: 123456 diff --git a/source/exampleApp/config/environment.rb b/source/exampleApp/config/environment.rb deleted file mode 100644 index aebc109cd..000000000 --- a/source/exampleApp/config/environment.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Load the Rails application. -require File.expand_path('../application', __FILE__) - -# Initialize the Rails application. -ExampleApp::Application.initialize! diff --git a/source/exampleApp/config/environments/development.rb b/source/exampleApp/config/environments/development.rb deleted file mode 100644 index b4c8454f9..000000000 --- a/source/exampleApp/config/environments/development.rb +++ /dev/null @@ -1,29 +0,0 @@ -ExampleApp::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 -end diff --git a/source/exampleApp/config/environments/production.rb b/source/exampleApp/config/environments/production.rb deleted file mode 100644 index 9b343689c..000000000 --- a/source/exampleApp/config/environments/production.rb +++ /dev/null @@ -1,80 +0,0 @@ -ExampleApp::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 thread 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 Rails's static asset server (Apache or nginx will already do this). - config.serve_static_assets = false - - # 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 - - # Generate digests for assets URLs. - config.assets.digest = true - - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - - # 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 - - # Set to :debug to see everything in the log. - config.log_level = :info - - # 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" - - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) - - # 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 can not be found). - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new -end diff --git a/source/exampleApp/config/environments/test.rb b/source/exampleApp/config/environments/test.rb deleted file mode 100644 index 4838a862a..000000000 --- a/source/exampleApp/config/environments/test.rb +++ /dev/null @@ -1,36 +0,0 @@ -ExampleApp::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 asset server for tests with Cache-Control for performance. - config.serve_static_assets = 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 - - # Print deprecation notices to the stderr. - config.active_support.deprecation = :stderr -end diff --git a/source/exampleApp/config/initializers/backtrace_silencers.rb b/source/exampleApp/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 59385cdf3..000000000 --- a/source/exampleApp/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,7 +0,0 @@ -# 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/exampleApp/config/initializers/filter_parameter_logging.rb b/source/exampleApp/config/initializers/filter_parameter_logging.rb deleted file mode 100644 index 4a994e1e7..000000000 --- a/source/exampleApp/config/initializers/filter_parameter_logging.rb +++ /dev/null @@ -1,4 +0,0 @@ -# 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/exampleApp/config/initializers/inflections.rb b/source/exampleApp/config/initializers/inflections.rb deleted file mode 100644 index ac033bf9d..000000000 --- a/source/exampleApp/config/initializers/inflections.rb +++ /dev/null @@ -1,16 +0,0 @@ -# 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/exampleApp/config/initializers/mime_types.rb b/source/exampleApp/config/initializers/mime_types.rb deleted file mode 100644 index 72aca7e44..000000000 --- a/source/exampleApp/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# 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 -# Mime::Type.register_alias "text/html", :iphone diff --git a/source/exampleApp/config/initializers/secret_token.rb b/source/exampleApp/config/initializers/secret_token.rb deleted file mode 100644 index b7d270ce4..000000000 --- a/source/exampleApp/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# 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 your secret_key_base is kept private -# if you're sharing your code publicly. -ExampleApp::Application.config.secret_key_base = 'f38cc678182185b99c74eada0c427325031b624ad4bc0b9441d487adbdb5cf932a92da75cd6ae0896d371e6d61408074452e62db64163dae8146b67bacf393b2' diff --git a/source/exampleApp/config/initializers/session_store.rb b/source/exampleApp/config/initializers/session_store.rb deleted file mode 100644 index e0c5a30ee..000000000 --- a/source/exampleApp/config/initializers/session_store.rb +++ /dev/null @@ -1,3 +0,0 @@ -# Be sure to restart your server when you modify this file. - -ExampleApp::Application.config.session_store :cookie_store, key: '_exampleApp_session' diff --git a/source/exampleApp/config/initializers/wrap_parameters.rb b/source/exampleApp/config/initializers/wrap_parameters.rb deleted file mode 100644 index 33725e95f..000000000 --- a/source/exampleApp/config/initializers/wrap_parameters.rb +++ /dev/null @@ -1,14 +0,0 @@ -# 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/exampleApp/config/locales/en.yml b/source/exampleApp/config/locales/en.yml deleted file mode 100644 index 065395716..000000000 --- a/source/exampleApp/config/locales/en.yml +++ /dev/null @@ -1,23 +0,0 @@ -# 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/exampleApp/config/routes.rb b/source/exampleApp/config/routes.rb deleted file mode 100644 index bf48e892d..000000000 --- a/source/exampleApp/config/routes.rb +++ /dev/null @@ -1,60 +0,0 @@ -ExampleApp::Application.routes.draw do - resources :charges - - resources :customers - - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end -end diff --git a/source/exampleApp/db/migrate/20210420034344_create_customers.rb b/source/exampleApp/db/migrate/20210420034344_create_customers.rb deleted file mode 100644 index f17897892..000000000 --- a/source/exampleApp/db/migrate/20210420034344_create_customers.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateCustomers < ActiveRecord::Migration - def change - create_table :customers do |t| - t.string :first_name, null: false, limit: 50 - t.string :last_name, null: false, limit: 50 - - t.timestamps - end - end -end diff --git a/source/exampleApp/db/migrate/20210420045643_create_charges.rb b/source/exampleApp/db/migrate/20210420045643_create_charges.rb deleted file mode 100644 index 9c50d5b5e..000000000 --- a/source/exampleApp/db/migrate/20210420045643_create_charges.rb +++ /dev/null @@ -1,22 +0,0 @@ -class CreateCharges < ActiveRecord::Migration - def change - create_table :charges do |t| - t.integer :created, null: false - t.boolean :paid, null: false, default: false - t.decimal :amount - t.string :currency, null: false - t.boolean :refunded, null: false, default: false - t.references :customer, index: true, null: false - - t.timestamps - end - reversible do |dir| - dir.up do - execute <<-SQL - ALTER TABLE charges - ALTER COLUMN created SET DEFAULT date_part('epoch', current_timestamp); - SQL - end - end - end -end diff --git a/source/exampleApp/db/schema.rb b/source/exampleApp/db/schema.rb deleted file mode 100644 index 5485080e2..000000000 --- a/source/exampleApp/db/schema.rb +++ /dev/null @@ -1,39 +0,0 @@ -# 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: 20210420045643) do - - # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" - - create_table "charges", force: true do |t| - t.integer "created", null: false - t.boolean "paid", default: false, null: false - t.decimal "amount" - t.string "currency", null: false - t.boolean "refunded", default: false, null: false - t.integer "customer_id", null: false - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "charges", ["customer_id"], name: "index_charges_on_customer_id", using: :btree - - create_table "customers", force: true do |t| - t.string "first_name", limit: 50, null: false - t.string "last_name", limit: 50, null: false - t.datetime "created_at" - t.datetime "updated_at" - end - -end diff --git a/source/exampleApp/db/seeds.rb b/source/exampleApp/db/seeds.rb deleted file mode 100644 index 4b8ca8706..000000000 --- a/source/exampleApp/db/seeds.rb +++ /dev/null @@ -1,51 +0,0 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) - -Customer.create(first_name: "Johny", last_name: "Flow") -Customer.create(first_name: "Raj", last_name: "Jamnis") -Customer.create(first_name: "Andrew", last_name: "Chung") -Customer.create(first_name: "Mike", last_name: "Smith") - -# 10 Should be successful Charges: -# - 5 Should be linked to Customer 1 -# - 3 Should be linked to Customer 2 -# - 1 Should be linked to Customer 3 -# - 1 Should be linked to Customer 4 - -Charge.create(paid: true, amount: 10.50, currency: 'usd', customer_id: 1) -Charge.create(paid: true, amount: 150, currency: 'usd', customer_id: 1) -Charge.create(paid: true, amount: 20, currency: 'usd', customer_id: 1) -Charge.create(paid: true, amount: 30, currency: 'usd', customer_id: 1) -Charge.create(paid: true, amount: 45, currency: 'usd', customer_id: 1) - -Charge.create(paid: true, amount: 10.50, currency: 'usd', customer_id: 2) -Charge.create(paid: true, amount: 150, currency: 'usd', customer_id: 2) -Charge.create(paid: true, amount: 20, currency: 'usd', customer_id: 2) - -Charge.create(paid: true, amount: 30, currency: 'usd', customer_id: 3) - -Charge.create(paid: true, amount: 45, currency: 'usd', customer_id: 4) - - -# 5 Should be Charges that failed: -# - 3 Should be linked to Customer 3 -# - 2 Should be linked to Customer 4 - -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 3) - -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 4) -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 4) - -# 5 should be disputed: -# - 3 should be linked to Customer 1 -# - 2 should be linked to customer 2 - -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 1) -Charge.create(paid: false, amount: 45, currency: 'usd', refunded: true, customer_id: 2) diff --git a/source/exampleApp/lib/assets/.keep b/source/exampleApp/lib/assets/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/lib/tasks/.keep b/source/exampleApp/lib/tasks/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/log/.keep b/source/exampleApp/log/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/public/404.html b/source/exampleApp/public/404.html deleted file mode 100644 index a0daa0c15..000000000 --- a/source/exampleApp/public/404.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - 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/exampleApp/public/422.html b/source/exampleApp/public/422.html deleted file mode 100644 index fbb4b84d7..000000000 --- a/source/exampleApp/public/422.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - 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/exampleApp/public/500.html b/source/exampleApp/public/500.html deleted file mode 100644 index e9052d35b..000000000 --- a/source/exampleApp/public/500.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - 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/exampleApp/public/favicon.ico b/source/exampleApp/public/favicon.ico deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/public/robots.txt b/source/exampleApp/public/robots.txt deleted file mode 100644 index 1a3a5e4dd..000000000 --- a/source/exampleApp/public/robots.txt +++ /dev/null @@ -1,5 +0,0 @@ -# See http://www.robotstxt.org/wc/norobots.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/exampleApp/spec/rails_helper.rb b/source/exampleApp/spec/rails_helper.rb deleted file mode 100644 index f4fd4d440..000000000 --- a/source/exampleApp/spec/rails_helper.rb +++ /dev/null @@ -1,63 +0,0 @@ -# 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')].each { |f| require f } - -# Checks for pending migrations before tests are run. -# If you are not using ActiveRecord, you can remove these lines. -begin - ActiveRecord::Migration.check_pending! -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 - - # 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/exampleApp/spec/spec_helper.rb b/source/exampleApp/spec/spec_helper.rb deleted file mode 100644 index ce33d66df..000000000 --- a/source/exampleApp/spec/spec_helper.rb +++ /dev/null @@ -1,96 +0,0 @@ -# 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/exampleApp/spec/views/charges/index.html.erb_spec.rb b/source/exampleApp/spec/views/charges/index.html.erb_spec.rb deleted file mode 100644 index f6bdc1ef7..000000000 --- a/source/exampleApp/spec/views/charges/index.html.erb_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "rails_helper" - -RSpec.describe "charges/index" do - it "contains a table for successful charges" do - render - - expect(rendered).to match /Failed Charges/ - end -end \ No newline at end of file diff --git a/source/exampleApp/vendor/assets/javascripts/.keep b/source/exampleApp/vendor/assets/javascripts/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/source/exampleApp/vendor/assets/stylesheets/.keep b/source/exampleApp/vendor/assets/stylesheets/.keep deleted file mode 100644 index e69de29bb..000000000 From 1a1e10a45eb853c3b0214497d37709b7fbff83c8 Mon Sep 17 00:00:00 2001 From: abdelp Date: Tue, 20 Apr 2021 12:15:27 -0400 Subject: [PATCH 40/40] Add helpers format_full_name: to format first_name and last_name of person passed epoch_to_date: to convert integer epoch to date string --- source/example-app/app/helpers/application_helper.rb | 7 +++++++ .../app/views/charges/_not_successful_charge.html.erb | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/example-app/app/helpers/application_helper.rb b/source/example-app/app/helpers/application_helper.rb index de6be7945..2069138ce 100644 --- a/source/example-app/app/helpers/application_helper.rb +++ b/source/example-app/app/helpers/application_helper.rb @@ -1,2 +1,9 @@ module ApplicationHelper + def format_full_name(person) + "#{person.first_name} #{person.last_name}" + end + + def epoch_to_date(epoch) + Time.at(epoch) + end end diff --git a/source/example-app/app/views/charges/_not_successful_charge.html.erb b/source/example-app/app/views/charges/_not_successful_charge.html.erb index fb6f16bef..43eb2ec05 100644 --- a/source/example-app/app/views/charges/_not_successful_charge.html.erb +++ b/source/example-app/app/views/charges/_not_successful_charge.html.erb @@ -1,7 +1,7 @@ - <%= "#{charge.customer.first_name} #{charge.customer.last_name}" %> + <%= format_full_name(charge.customer) %> <%= "#{charge.amount} #{charge.currency}" %> - <%= charge.created %> + <%= epoch_to_date(charge.created) %> <%= link_to 'Show', charge %> <%= link_to 'Edit', edit_charge_path(charge) %>