From b3d628a22f76848bd0adf57a97e648dd78920ac8 Mon Sep 17 00:00:00 2001 From: jacky Date: Wed, 21 Apr 2021 22:35:51 +0700 Subject: [PATCH 1/6] Init project --- source/card_charge/.gitignore | 16 +++ source/card_charge/Gemfile | 45 +++++++ source/card_charge/Gemfile.lock | 120 ++++++++++++++++++ source/card_charge/README.rdoc | 28 ++++ source/card_charge/Rakefile | 6 + source/card_charge/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/card_charge/app/mailers/.keep | 0 source/card_charge/app/models/.keep | 0 source/card_charge/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 14 ++ source/card_charge/bin/bundle | 3 + source/card_charge/bin/rails | 4 + source/card_charge/bin/rake | 4 + source/card_charge/config.ru | 4 + source/card_charge/config/application.rb | 23 ++++ source/card_charge/config/boot.rb | 4 + source/card_charge/config/database.yml | 25 ++++ source/card_charge/config/environment.rb | 5 + .../config/environments/development.rb | 29 +++++ .../config/environments/production.rb | 80 ++++++++++++ .../card_charge/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/card_charge/config/locales/en.yml | 23 ++++ source/card_charge/config/routes.rb | 56 ++++++++ source/card_charge/db/seeds.rb | 7 + source/card_charge/lib/assets/.keep | 0 source/card_charge/lib/tasks/.keep | 0 source/card_charge/log/.keep | 0 source/card_charge/public/404.html | 58 +++++++++ source/card_charge/public/422.html | 58 +++++++++ source/card_charge/public/500.html | 57 +++++++++ source/card_charge/public/favicon.ico | 0 source/card_charge/public/robots.txt | 5 + source/card_charge/test/controllers/.keep | 0 source/card_charge/test/fixtures/.keep | 0 source/card_charge/test/helpers/.keep | 0 source/card_charge/test/integration/.keep | 0 source/card_charge/test/mailers/.keep | 0 source/card_charge/test/models/.keep | 0 source/card_charge/test/test_helper.rb | 15 +++ .../vendor/assets/javascripts/.keep | 0 .../vendor/assets/stylesheets/.keep | 0 53 files changed, 822 insertions(+) create mode 100644 source/card_charge/.gitignore create mode 100644 source/card_charge/Gemfile create mode 100644 source/card_charge/Gemfile.lock create mode 100644 source/card_charge/README.rdoc create mode 100644 source/card_charge/Rakefile create mode 100644 source/card_charge/app/assets/images/.keep create mode 100644 source/card_charge/app/assets/javascripts/application.js create mode 100644 source/card_charge/app/assets/stylesheets/application.css create mode 100644 source/card_charge/app/controllers/application_controller.rb create mode 100644 source/card_charge/app/controllers/concerns/.keep create mode 100644 source/card_charge/app/helpers/application_helper.rb create mode 100644 source/card_charge/app/mailers/.keep create mode 100644 source/card_charge/app/models/.keep create mode 100644 source/card_charge/app/models/concerns/.keep create mode 100644 source/card_charge/app/views/layouts/application.html.erb create mode 100755 source/card_charge/bin/bundle create mode 100755 source/card_charge/bin/rails create mode 100755 source/card_charge/bin/rake create mode 100644 source/card_charge/config.ru create mode 100644 source/card_charge/config/application.rb create mode 100644 source/card_charge/config/boot.rb create mode 100644 source/card_charge/config/database.yml create mode 100644 source/card_charge/config/environment.rb create mode 100644 source/card_charge/config/environments/development.rb create mode 100644 source/card_charge/config/environments/production.rb create mode 100644 source/card_charge/config/environments/test.rb create mode 100644 source/card_charge/config/initializers/backtrace_silencers.rb create mode 100644 source/card_charge/config/initializers/filter_parameter_logging.rb create mode 100644 source/card_charge/config/initializers/inflections.rb create mode 100644 source/card_charge/config/initializers/mime_types.rb create mode 100644 source/card_charge/config/initializers/secret_token.rb create mode 100644 source/card_charge/config/initializers/session_store.rb create mode 100644 source/card_charge/config/initializers/wrap_parameters.rb create mode 100644 source/card_charge/config/locales/en.yml create mode 100644 source/card_charge/config/routes.rb create mode 100644 source/card_charge/db/seeds.rb create mode 100644 source/card_charge/lib/assets/.keep create mode 100644 source/card_charge/lib/tasks/.keep create mode 100644 source/card_charge/log/.keep create mode 100644 source/card_charge/public/404.html create mode 100644 source/card_charge/public/422.html create mode 100644 source/card_charge/public/500.html create mode 100644 source/card_charge/public/favicon.ico create mode 100644 source/card_charge/public/robots.txt create mode 100644 source/card_charge/test/controllers/.keep create mode 100644 source/card_charge/test/fixtures/.keep create mode 100644 source/card_charge/test/helpers/.keep create mode 100644 source/card_charge/test/integration/.keep create mode 100644 source/card_charge/test/mailers/.keep create mode 100644 source/card_charge/test/models/.keep create mode 100644 source/card_charge/test/test_helper.rb create mode 100644 source/card_charge/vendor/assets/javascripts/.keep create mode 100644 source/card_charge/vendor/assets/stylesheets/.keep diff --git a/source/card_charge/.gitignore b/source/card_charge/.gitignore new file mode 100644 index 000000000..25a742dff --- /dev/null +++ b/source/card_charge/.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/card_charge/Gemfile b/source/card_charge/Gemfile new file mode 100644 index 000000000..30d54d47a --- /dev/null +++ b/source/card_charge/Gemfile @@ -0,0 +1,45 @@ +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.0.0' + +# Use sqlite3 as the database for Active Record +gem 'sqlite3' + +# 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/card_charge/Gemfile.lock b/source/card_charge/Gemfile.lock new file mode 100644 index 000000000..5e9057174 --- /dev/null +++ b/source/card_charge/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) + 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 (13.0.3) + rdoc (6.2.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) + sqlite3 (1.4.2) + 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 + rails (= 4.0.0) + sass-rails (~> 4.0.0) + sdoc + sqlite3 + turbolinks + uglifier (>= 1.3.0) + +BUNDLED WITH + 1.17.3 diff --git a/source/card_charge/README.rdoc b/source/card_charge/README.rdoc new file mode 100644 index 000000000..dd4e97e22 --- /dev/null +++ b/source/card_charge/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/card_charge/Rakefile b/source/card_charge/Rakefile new file mode 100644 index 000000000..013b9b1d7 --- /dev/null +++ b/source/card_charge/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__) + +CardCharge::Application.load_tasks diff --git a/source/card_charge/app/assets/images/.keep b/source/card_charge/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/app/assets/javascripts/application.js b/source/card_charge/app/assets/javascripts/application.js new file mode 100644 index 000000000..d6925fa43 --- /dev/null +++ b/source/card_charge/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/card_charge/app/assets/stylesheets/application.css b/source/card_charge/app/assets/stylesheets/application.css new file mode 100644 index 000000000..3192ec897 --- /dev/null +++ b/source/card_charge/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/card_charge/app/controllers/application_controller.rb b/source/card_charge/app/controllers/application_controller.rb new file mode 100644 index 000000000..d83690e1b --- /dev/null +++ b/source/card_charge/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/card_charge/app/controllers/concerns/.keep b/source/card_charge/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/app/helpers/application_helper.rb b/source/card_charge/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/source/card_charge/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/source/card_charge/app/mailers/.keep b/source/card_charge/app/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/app/models/.keep b/source/card_charge/app/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/app/models/concerns/.keep b/source/card_charge/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/app/views/layouts/application.html.erb b/source/card_charge/app/views/layouts/application.html.erb new file mode 100644 index 000000000..839d0aeaf --- /dev/null +++ b/source/card_charge/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + CardCharge + <%= 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/card_charge/bin/bundle b/source/card_charge/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/source/card_charge/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/card_charge/bin/rails b/source/card_charge/bin/rails new file mode 100755 index 000000000..728cd85aa --- /dev/null +++ b/source/card_charge/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/card_charge/bin/rake b/source/card_charge/bin/rake new file mode 100755 index 000000000..17240489f --- /dev/null +++ b/source/card_charge/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/source/card_charge/config.ru b/source/card_charge/config.ru new file mode 100644 index 000000000..5bc2a619e --- /dev/null +++ b/source/card_charge/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/card_charge/config/application.rb b/source/card_charge/config/application.rb new file mode 100644 index 000000000..54f926df3 --- /dev/null +++ b/source/card_charge/config/application.rb @@ -0,0 +1,23 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) + +module CardCharge + 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/card_charge/config/boot.rb b/source/card_charge/config/boot.rb new file mode 100644 index 000000000..359673666 --- /dev/null +++ b/source/card_charge/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/card_charge/config/database.yml b/source/card_charge/config/database.yml new file mode 100644 index 000000000..51a4dd459 --- /dev/null +++ b/source/card_charge/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + +# 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: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/source/card_charge/config/environment.rb b/source/card_charge/config/environment.rb new file mode 100644 index 000000000..22b33aeaf --- /dev/null +++ b/source/card_charge/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +CardCharge::Application.initialize! diff --git a/source/card_charge/config/environments/development.rb b/source/card_charge/config/environments/development.rb new file mode 100644 index 000000000..f6957dc9d --- /dev/null +++ b/source/card_charge/config/environments/development.rb @@ -0,0 +1,29 @@ +CardCharge::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/card_charge/config/environments/production.rb b/source/card_charge/config/environments/production.rb new file mode 100644 index 000000000..d5bfee381 --- /dev/null +++ b/source/card_charge/config/environments/production.rb @@ -0,0 +1,80 @@ +CardCharge::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/card_charge/config/environments/test.rb b/source/card_charge/config/environments/test.rb new file mode 100644 index 000000000..5bca0d177 --- /dev/null +++ b/source/card_charge/config/environments/test.rb @@ -0,0 +1,36 @@ +CardCharge::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/card_charge/config/initializers/backtrace_silencers.rb b/source/card_charge/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/source/card_charge/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/card_charge/config/initializers/filter_parameter_logging.rb b/source/card_charge/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/source/card_charge/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/card_charge/config/initializers/inflections.rb b/source/card_charge/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/source/card_charge/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/card_charge/config/initializers/mime_types.rb b/source/card_charge/config/initializers/mime_types.rb new file mode 100644 index 000000000..72aca7e44 --- /dev/null +++ b/source/card_charge/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/card_charge/config/initializers/secret_token.rb b/source/card_charge/config/initializers/secret_token.rb new file mode 100644 index 000000000..ea870bf1c --- /dev/null +++ b/source/card_charge/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. +CardCharge::Application.config.secret_key_base = '36d7b70d70a2f5beacb5b0ffd6a7a1622e949eb3813a26cab017597f8859c84ec06dc0ebf4005bf8c3803e04b17d881f0fc65451cdfb5126c252bea9c554ecc6' diff --git a/source/card_charge/config/initializers/session_store.rb b/source/card_charge/config/initializers/session_store.rb new file mode 100644 index 000000000..d8e5bc687 --- /dev/null +++ b/source/card_charge/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +CardCharge::Application.config.session_store :cookie_store, key: '_card_charge_session' diff --git a/source/card_charge/config/initializers/wrap_parameters.rb b/source/card_charge/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..33725e95f --- /dev/null +++ b/source/card_charge/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/card_charge/config/locales/en.yml b/source/card_charge/config/locales/en.yml new file mode 100644 index 000000000..065395716 --- /dev/null +++ b/source/card_charge/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/card_charge/config/routes.rb b/source/card_charge/config/routes.rb new file mode 100644 index 000000000..3d630f1ea --- /dev/null +++ b/source/card_charge/config/routes.rb @@ -0,0 +1,56 @@ +CardCharge::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/card_charge/db/seeds.rb b/source/card_charge/db/seeds.rb new file mode 100644 index 000000000..4edb1e857 --- /dev/null +++ b/source/card_charge/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/card_charge/lib/assets/.keep b/source/card_charge/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/lib/tasks/.keep b/source/card_charge/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/log/.keep b/source/card_charge/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/public/404.html b/source/card_charge/public/404.html new file mode 100644 index 000000000..a0daa0c15 --- /dev/null +++ b/source/card_charge/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/card_charge/public/422.html b/source/card_charge/public/422.html new file mode 100644 index 000000000..fbb4b84d7 --- /dev/null +++ b/source/card_charge/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/card_charge/public/500.html b/source/card_charge/public/500.html new file mode 100644 index 000000000..e9052d35b --- /dev/null +++ b/source/card_charge/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/card_charge/public/favicon.ico b/source/card_charge/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/public/robots.txt b/source/card_charge/public/robots.txt new file mode 100644 index 000000000..1a3a5e4dd --- /dev/null +++ b/source/card_charge/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/card_charge/test/controllers/.keep b/source/card_charge/test/controllers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/test/fixtures/.keep b/source/card_charge/test/fixtures/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/test/helpers/.keep b/source/card_charge/test/helpers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/test/integration/.keep b/source/card_charge/test/integration/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/test/mailers/.keep b/source/card_charge/test/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/test/models/.keep b/source/card_charge/test/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/test/test_helper.rb b/source/card_charge/test/test_helper.rb new file mode 100644 index 000000000..bc7e05d70 --- /dev/null +++ b/source/card_charge/test/test_helper.rb @@ -0,0 +1,15 @@ +ENV["RAILS_ENV"] ||= "test" +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + ActiveRecord::Migration.check_pending! + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/source/card_charge/vendor/assets/javascripts/.keep b/source/card_charge/vendor/assets/javascripts/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/card_charge/vendor/assets/stylesheets/.keep b/source/card_charge/vendor/assets/stylesheets/.keep new file mode 100644 index 000000000..e69de29bb From 52347905823d184bdef3a8237da5daea4163a21e Mon Sep 17 00:00:00 2001 From: jacky Date: Wed, 21 Apr 2021 22:43:18 +0700 Subject: [PATCH 2/6] Fix sqlite version --- source/card_charge/Gemfile | 2 +- source/card_charge/Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/card_charge/Gemfile b/source/card_charge/Gemfile index 30d54d47a..ab9a29457 100644 --- a/source/card_charge/Gemfile +++ b/source/card_charge/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gem 'rails', '4.0.0' # Use sqlite3 as the database for Active Record -gem 'sqlite3' +gem 'sqlite3', '~> 1.3.6' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.0' diff --git a/source/card_charge/Gemfile.lock b/source/card_charge/Gemfile.lock index 5e9057174..57f792f53 100644 --- a/source/card_charge/Gemfile.lock +++ b/source/card_charge/Gemfile.lock @@ -88,7 +88,7 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) - sqlite3 (1.4.2) + sqlite3 (1.3.13) thor (1.1.0) thread_safe (0.3.6) tilt (1.4.1) @@ -112,7 +112,7 @@ DEPENDENCIES rails (= 4.0.0) sass-rails (~> 4.0.0) sdoc - sqlite3 + sqlite3 (~> 1.3.6) turbolinks uglifier (>= 1.3.0) From 046c8c5618c893c8f915c0c7d80da44b9c99a2a4 Mon Sep 17 00:00:00 2001 From: jacky Date: Wed, 21 Apr 2021 22:43:27 +0700 Subject: [PATCH 3/6] Add models --- source/card_charge/app/models/charge.rb | 2 ++ source/card_charge/app/models/customer.rb | 2 ++ .../db/migrate/20210421154056_create_charges.rb | 14 ++++++++++++++ .../db/migrate/20210421154242_create_customers.rb | 10 ++++++++++ 4 files changed, 28 insertions(+) create mode 100644 source/card_charge/app/models/charge.rb create mode 100644 source/card_charge/app/models/customer.rb create mode 100644 source/card_charge/db/migrate/20210421154056_create_charges.rb create mode 100644 source/card_charge/db/migrate/20210421154242_create_customers.rb diff --git a/source/card_charge/app/models/charge.rb b/source/card_charge/app/models/charge.rb new file mode 100644 index 000000000..b7c0e71ec --- /dev/null +++ b/source/card_charge/app/models/charge.rb @@ -0,0 +1,2 @@ +class Charge < ActiveRecord::Base +end diff --git a/source/card_charge/app/models/customer.rb b/source/card_charge/app/models/customer.rb new file mode 100644 index 000000000..047dcb0c0 --- /dev/null +++ b/source/card_charge/app/models/customer.rb @@ -0,0 +1,2 @@ +class Customer < ActiveRecord::Base +end diff --git a/source/card_charge/db/migrate/20210421154056_create_charges.rb b/source/card_charge/db/migrate/20210421154056_create_charges.rb new file mode 100644 index 000000000..9dab677cb --- /dev/null +++ b/source/card_charge/db/migrate/20210421154056_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.integer :customer_id + + t.timestamps + end + end +end diff --git a/source/card_charge/db/migrate/20210421154242_create_customers.rb b/source/card_charge/db/migrate/20210421154242_create_customers.rb new file mode 100644 index 000000000..ab9127003 --- /dev/null +++ b/source/card_charge/db/migrate/20210421154242_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 From 4ad1cc08dd91d1536f8da4f14861c553e644d1de Mon Sep 17 00:00:00 2001 From: jacky Date: Wed, 21 Apr 2021 22:57:09 +0700 Subject: [PATCH 4/6] Add seed --- source/card_charge/app/models/charge.rb | 1 + source/card_charge/app/models/customer.rb | 1 + source/card_charge/db/seeds.rb | 69 ++++++++++++++++++++--- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/source/card_charge/app/models/charge.rb b/source/card_charge/app/models/charge.rb index b7c0e71ec..c17f5e99d 100644 --- a/source/card_charge/app/models/charge.rb +++ b/source/card_charge/app/models/charge.rb @@ -1,2 +1,3 @@ class Charge < ActiveRecord::Base + belongs_to :customer end diff --git a/source/card_charge/app/models/customer.rb b/source/card_charge/app/models/customer.rb index 047dcb0c0..9709ffc4d 100644 --- a/source/card_charge/app/models/customer.rb +++ b/source/card_charge/app/models/customer.rb @@ -1,2 +1,3 @@ class Customer < ActiveRecord::Base + has_many :charges end diff --git a/source/card_charge/db/seeds.rb b/source/card_charge/db/seeds.rb index 4edb1e857..b4e8de500 100644 --- a/source/card_charge/db/seeds.rb +++ b/source/card_charge/db/seeds.rb @@ -1,7 +1,62 @@ -# 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) +# customers ## +customers = [ + { + first_name: 'Johny', + last_name: 'Flow' + }, + { + first_name: 'Raj', + last_name: 'Jamnis' + }, + { + first_name: 'Andrew', + last_name: 'Chung' + }, + { + first_name: 'Mike', + last_name: 'Smith' + } +] + +customers = customers.map do |cus| + Customer.create(cus) +end + +# transactions ## +# success +success_charge = { + paid: true, + amount: rand(1000), + currency: 'usd', + refunded: false, + created: Time.current.to_i +} + +5.times do + customers[0].charges.create(success_charge) +end + +3.times do + customers[1].charges.create(success_charge) +end + +customers[2].charges.create(success_charge) +customers[3].charges.create(success_charge) + +# failed +3.times do + customers[2].charges.create(success_charge.merge!(paid: false)) +end + +2.times do + customers[3].charges.create(success_charge.merge!(paid: false)) +end + +# disputed +3.times do + customers[0].charges.create(success_charge.merge!(refunded: true)) +end + +2.times do + customers[1].charges.create(success_charge.merge!(refunded: true)) +end \ No newline at end of file From 3772a76481bc2e67067835fc7ec2d3deb02cc4ab Mon Sep 17 00:00:00 2001 From: jacky Date: Wed, 21 Apr 2021 23:21:22 +0700 Subject: [PATCH 5/6] Add list page --- .../app/assets/stylesheets/charges.css.scss | 15 +++++ .../app/controllers/charges_controller.rb | 4 ++ source/card_charge/app/models/charge.rb | 5 ++ source/card_charge/app/models/customer.rb | 4 ++ .../app/views/charges/index.html.erb | 64 +++++++++++++++++++ source/card_charge/config/routes.rb | 55 +--------------- ...20210421161153_add_refuned_at_to_charge.rb | 5 ++ source/card_charge/db/seeds.rb | 35 ++++++---- 8 files changed, 122 insertions(+), 65 deletions(-) create mode 100644 source/card_charge/app/assets/stylesheets/charges.css.scss create mode 100644 source/card_charge/app/controllers/charges_controller.rb create mode 100644 source/card_charge/app/views/charges/index.html.erb create mode 100644 source/card_charge/db/migrate/20210421161153_add_refuned_at_to_charge.rb diff --git a/source/card_charge/app/assets/stylesheets/charges.css.scss b/source/card_charge/app/assets/stylesheets/charges.css.scss new file mode 100644 index 000000000..9dcbc8c95 --- /dev/null +++ b/source/card_charge/app/assets/stylesheets/charges.css.scss @@ -0,0 +1,15 @@ +.failed { + .row { + background: #FF0000; + padding: 10; + color: white; + } +} + +.disputed { + .row { + background: #FF5400; + padding: 10; + color: white; + } +} \ No newline at end of file diff --git a/source/card_charge/app/controllers/charges_controller.rb b/source/card_charge/app/controllers/charges_controller.rb new file mode 100644 index 000000000..10d548ec1 --- /dev/null +++ b/source/card_charge/app/controllers/charges_controller.rb @@ -0,0 +1,4 @@ +class ChargesController < ApplicationController + def index + end +end diff --git a/source/card_charge/app/models/charge.rb b/source/card_charge/app/models/charge.rb index c17f5e99d..aabfe6634 100644 --- a/source/card_charge/app/models/charge.rb +++ b/source/card_charge/app/models/charge.rb @@ -1,3 +1,8 @@ class Charge < ActiveRecord::Base belongs_to :customer + + scope :failed, -> { where(paid: false) } + scope :paid, -> { where(paid: true)} + scope :success, -> { paid.where(refunded: false) } + scope :disputed, -> { where(refunded: true) } end diff --git a/source/card_charge/app/models/customer.rb b/source/card_charge/app/models/customer.rb index 9709ffc4d..369714dd3 100644 --- a/source/card_charge/app/models/customer.rb +++ b/source/card_charge/app/models/customer.rb @@ -1,3 +1,7 @@ class Customer < ActiveRecord::Base has_many :charges + + def name + "#{first_name} #{last_name}" + end end diff --git a/source/card_charge/app/views/charges/index.html.erb b/source/card_charge/app/views/charges/index.html.erb new file mode 100644 index 000000000..5da3d1c85 --- /dev/null +++ b/source/card_charge/app/views/charges/index.html.erb @@ -0,0 +1,64 @@ +

Failed Charges

+ +
+ + + + + + + + + <% Charge.failed.each do |charge| %> + + + + + + <% end %> + +
CustomerAmountDate
<%= charge.customer.name %><%= number_to_currency(charge.amount / 100) %><%= Time.at(charge.created).strftime('%d/%m/%Y') %>
+
+ + +

Disputed/Refunded Charges

+
+ + + + + + + + + <% Charge.disputed.each do |charge| %> + + + + + + <% end %> + +
CustomerAmountDate
<%= charge.customer.name %><%= number_to_currency(charge.amount / 100) %><%= charge.refunded_at.strftime('%d/%m/%Y') %>
+
+ +

Successful Charges

+ \ No newline at end of file diff --git a/source/card_charge/config/routes.rb b/source/card_charge/config/routes.rb index 3d630f1ea..fbf5fb54e 100644 --- a/source/card_charge/config/routes.rb +++ b/source/card_charge/config/routes.rb @@ -1,56 +1,3 @@ CardCharge::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 + resources :charges, only: [:index] end diff --git a/source/card_charge/db/migrate/20210421161153_add_refuned_at_to_charge.rb b/source/card_charge/db/migrate/20210421161153_add_refuned_at_to_charge.rb new file mode 100644 index 000000000..cf9952c2a --- /dev/null +++ b/source/card_charge/db/migrate/20210421161153_add_refuned_at_to_charge.rb @@ -0,0 +1,5 @@ +class AddRefunedAtToCharge < ActiveRecord::Migration + def change + add_column :charges, :refunded_at, :datetime + end +end diff --git a/source/card_charge/db/seeds.rb b/source/card_charge/db/seeds.rb index b4e8de500..1e7eb087b 100644 --- a/source/card_charge/db/seeds.rb +++ b/source/card_charge/db/seeds.rb @@ -24,39 +24,52 @@ # transactions ## # success -success_charge = { - paid: true, - amount: rand(1000), +charge = { currency: 'usd', refunded: false, created: Time.current.to_i } +paid_charge = charge.merge({ + amount: rand(1000), + paid: true +}) + 5.times do - customers[0].charges.create(success_charge) + customers[0].charges.create(paid_charge) end 3.times do - customers[1].charges.create(success_charge) + customers[1].charges.create(paid_charge) end -customers[2].charges.create(success_charge) -customers[3].charges.create(success_charge) +customers[2].charges.create(paid_charge) +customers[3].charges.create(paid_charge) # failed +failed_charge = charge.merge({ + amount: rand(1000), + paid: false +}) 3.times do - customers[2].charges.create(success_charge.merge!(paid: false)) + customers[2].charges.create(failed_charge) end 2.times do - customers[3].charges.create(success_charge.merge!(paid: false)) + customers[3].charges.create(failed_charge) end # disputed +disputed_charge = charge.merge({ + amount: rand(1000), + paid: true, + refunded: true, + refunded_at: rand(40).day.ago +}) 3.times do - customers[0].charges.create(success_charge.merge!(refunded: true)) + customers[0].charges.create(disputed_charge) end 2.times do - customers[1].charges.create(success_charge.merge!(refunded: true)) + customers[1].charges.create(disputed_charge) end \ No newline at end of file From 55341fbd448a3dc9c43bccb9f705c034da0552cb Mon Sep 17 00:00:00 2001 From: jacky Date: Wed, 21 Apr 2021 23:37:07 +0700 Subject: [PATCH 6/6] Add rspec --- source/card_charge/Gemfile | 11 +++ source/card_charge/Gemfile.lock | 63 ++++++++++++ .../card_charge/spec/features/charges_spec.rb | 17 ++++ source/card_charge/spec/rails_helper.rb | 63 ++++++++++++ source/card_charge/spec/spec_helper.rb | 96 +++++++++++++++++++ 5 files changed, 250 insertions(+) create mode 100644 source/card_charge/spec/features/charges_spec.rb create mode 100644 source/card_charge/spec/rails_helper.rb create mode 100644 source/card_charge/spec/spec_helper.rb diff --git a/source/card_charge/Gemfile b/source/card_charge/Gemfile index ab9a29457..e40b2e752 100644 --- a/source/card_charge/Gemfile +++ b/source/card_charge/Gemfile @@ -43,3 +43,14 @@ end # Use debugger # gem 'debugger', group: [:development, :test] + + +group :test do + gem 'capybara' + gem 'database_cleaner' + gem 'rspec-rails' + gem 'selenium-webdriver' + gem 'webdrivers', '3.6.0' + gem 'factory_bot_rails' + gem 'puma' +end diff --git a/source/card_charge/Gemfile.lock b/source/card_charge/Gemfile.lock index 57f792f53..8fbd0b63b 100644 --- a/source/card_charge/Gemfile.lock +++ b/source/card_charge/Gemfile.lock @@ -25,8 +25,19 @@ 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) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -35,8 +46,16 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.8) + database_cleaner (1.99.0) + diff-lcs (1.4.4) erubis (2.7.0) execjs (2.7.0) + factory_bot (4.11.1) + activesupport (>= 3.0.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) + railties (>= 3.0.0) + ffi (1.12.2) hike (1.2.3) i18n (0.9.5) concurrent-ruby (~> 1.0) @@ -50,9 +69,18 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) + mini_mime (1.1.0) + mini_portile2 (2.4.0) minitest (4.7.5) multi_json (1.15.0) + net_http_ssl_fix (0.0.10) + nio4r (2.3.1) + nokogiri (1.9.1) + mini_portile2 (~> 2.4.0) polyglot (0.3.5) + public_suffix (3.1.1) + puma (5.2.2) + nio4r (~> 2.0) rack (1.5.5) rack-test (0.6.3) rack (>= 1.0) @@ -71,6 +99,24 @@ GEM thor (>= 0.18.1, < 2.0) rake (13.0.3) rdoc (6.2.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) + rubyzip (1.3.0) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -79,6 +125,9 @@ GEM sprockets-rails (~> 2.0) sdoc (2.1.0) rdoc (>= 5.0) + selenium-webdriver (3.141.0) + childprocess (~> 0.5) + rubyzip (~> 1.2, >= 1.2.2) sprockets (2.12.5) hike (~> 1.2) multi_json (~> 1.0) @@ -101,20 +150,34 @@ GEM tzinfo (0.3.60) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + webdrivers (3.6.0) + net_http_ssl_fix + nokogiri (~> 1.6) + rubyzip (~> 1.0) + selenium-webdriver (~> 3.0) + xpath (3.1.0) + nokogiri (~> 1.8) PLATFORMS ruby DEPENDENCIES + capybara coffee-rails (~> 4.0.0) + database_cleaner + factory_bot_rails jbuilder (~> 1.2) jquery-rails + puma rails (= 4.0.0) + rspec-rails sass-rails (~> 4.0.0) sdoc + selenium-webdriver sqlite3 (~> 1.3.6) turbolinks uglifier (>= 1.3.0) + webdrivers (= 3.6.0) BUNDLED WITH 1.17.3 diff --git a/source/card_charge/spec/features/charges_spec.rb b/source/card_charge/spec/features/charges_spec.rb new file mode 100644 index 000000000..29029daff --- /dev/null +++ b/source/card_charge/spec/features/charges_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.feature "Charges", type: :feature do + before(:each) { load "#{Rails.root}/db/seeds.rb"} + + scenario 'Show the list of charged by group' do + visit charges_path + + expect(page).to have_content('Failed Charges') + expect(page).to have_content('Disputed/Refunded Charges') + expect(page).to have_content('Successful Charges') + + expect(all('.failed tr').count).to eq(5) + expect(all('.disputed tr').count).to eq(5) + expect(all('.paid tr').count).to eq(10) + end +end diff --git a/source/card_charge/spec/rails_helper.rb b/source/card_charge/spec/rails_helper.rb new file mode 100644 index 000000000..f4fd4d440 --- /dev/null +++ b/source/card_charge/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/card_charge/spec/spec_helper.rb b/source/card_charge/spec/spec_helper.rb new file mode 100644 index 000000000..ce33d66df --- /dev/null +++ b/source/card_charge/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