From 21dfde9e2a889540579a7928c1665d7d20222b2e Mon Sep 17 00:00:00 2001 From: Suraj Vadgama Date: Fri, 17 Jan 2020 11:47:25 +0000 Subject: [PATCH] Rescue invalid date query param --- .babelrc | 18 --------- app/controllers/application_controller.rb | 6 +++ app/controllers/partners_controller.rb | 4 +- app/controllers/referrals_controller.rb | 4 -- test/system/month_picker_test.rb | 6 +++ yarn.lock | 49 ----------------------- 6 files changed, 13 insertions(+), 74 deletions(-) delete mode 100644 .babelrc diff --git a/.babelrc b/.babelrc deleted file mode 100644 index ded31c0..0000000 --- a/.babelrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "presets": [ - ["env", { - "modules": false, - "targets": { - "browsers": "> 1%", - "uglify": true - }, - "useBuiltIns": true - }] - ], - - "plugins": [ - "syntax-dynamic-import", - "transform-object-rest-spread", - ["transform-class-properties", { "spec": true }] - ] -} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3ac1ff5..1354c12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,10 @@ class ApplicationController < ActionController::Base def render_status(status) render file: "#{Rails.root}/public/#{status}.html", status: status end + + def parse_date + @date = params[:date]&.to_date || Date.today + rescue ArgumentError + @date = Date.today + end end diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb index 7866384..ef7962c 100644 --- a/app/controllers/partners_controller.rb +++ b/app/controllers/partners_controller.rb @@ -1,9 +1,7 @@ class PartnersController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user!, :parse_date def index - @date = params[:date]&.to_date || Date.today - @usage ||= Referral.joins(:partner).used .by_month(@date, col: 'referrals.created_at') .group('partners.slug').size diff --git a/app/controllers/referrals_controller.rb b/app/controllers/referrals_controller.rb index 0d6c072..6f3ba08 100644 --- a/app/controllers/referrals_controller.rb +++ b/app/controllers/referrals_controller.rb @@ -27,8 +27,4 @@ def show def load_partner @partner = Partner.active.find_by(slug: params[:slug]) end - - def parse_date - @date = params[:date]&.to_date || Date.today - end end diff --git a/test/system/month_picker_test.rb b/test/system/month_picker_test.rb index af74f4f..a568c54 100644 --- a/test/system/month_picker_test.rb +++ b/test/system/month_picker_test.rb @@ -36,4 +36,10 @@ class MonthPickerTest < ApplicationSystemTestCase sign_in assert_text('No referrals this month.') end + + test 'invalid date returns current day' do + visit root_path(date: '2020-1') + sign_in + assert_text("#{Date::MONTHNAMES[Date.today.month]} Referrals #{Date.today.year}") + end end diff --git a/yarn.lock b/yarn.lock index a65c371..27cc3a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4545,14 +4545,6 @@ minipass@^2.2.1, minipass@^2.3.3: safe-buffer "^5.1.2" yallist "^3.0.0" -minipass@^2.8.6, minipass@^2.9.0: - version "2.9.0" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6" - integrity sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg== - dependencies: - safe-buffer "^5.1.2" - yallist "^3.0.0" - minipass@^3.0.0, minipass@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.1.1.tgz#7607ce778472a185ad6d89082aa2070f79cedcd5" @@ -4567,13 +4559,6 @@ minizlib@^1.1.0: dependencies: minipass "^2.2.1" -minizlib@^1.2.1: - version "1.3.3" - resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.3.tgz#2290de96818a34c29551c8a8d301216bd65a861d" - integrity sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q== - dependencies: - minipass "^2.9.0" - mississippi@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/mississippi/-/mississippi-3.0.0.tgz#ea0a3291f97e0b5e8776b363d5f0a12d94c67022" @@ -4753,22 +4738,6 @@ node-libs-browser@^2.2.1: util "^0.11.0" vm-browserify "^1.0.1" -node-pre-gyp@*: - version "0.14.0" - resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.14.0.tgz#9a0596533b877289bcad4e143982ca3d904ddc83" - integrity sha512-+CvDC7ZttU/sSt9rFjix/P05iS43qHCOOGzcr3Ry99bXG7VX953+vFyEuph/tfqoYu8dttBkE86JSKBO2OzcxA== - dependencies: - detect-libc "^1.0.2" - mkdirp "^0.5.1" - needle "^2.2.1" - nopt "^4.0.1" - npm-packlist "^1.1.6" - npmlog "^4.0.2" - rc "^1.2.7" - rimraf "^2.6.1" - semver "^5.3.0" - tar "^4.4.2" - node-pre-gyp@^0.10.0: version "0.10.3" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" @@ -7158,19 +7127,6 @@ tar@^4: safe-buffer "^5.1.2" yallist "^3.0.2" -tar@^4.4.2: - version "4.4.13" - resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525" - integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA== - dependencies: - chownr "^1.1.1" - fs-minipass "^1.2.5" - minipass "^2.8.6" - minizlib "^1.2.1" - mkdirp "^0.5.0" - safe-buffer "^5.1.2" - yallist "^3.0.3" - terser-webpack-plugin@^1.4.3: version "1.4.3" resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.3.tgz#5ecaf2dbdc5fb99745fd06791f46fc9ddb1c9a7c" @@ -7773,11 +7729,6 @@ yallist@^3.0.0, yallist@^3.0.2: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9" integrity sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k= -yallist@^3.0.3: - version "3.1.1" - resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" - integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== - yallist@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"