From 5f26243e151070034deb3bfede357c60c8986d62 Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 7 Oct 2019 15:47:41 -0700 Subject: [PATCH 001/118] rails new --- .gitignore | 30 ++ .ruby-version | 1 + Gemfile | 83 ++++++ Gemfile.lock | 277 ++++++++++++++++++ Guardfile | 9 + Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 16 + app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 app/assets/stylesheets/application.css | 15 + app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 2 + app/controllers/concerns/.keep | 0 app/helpers/application_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 15 + app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 36 +++ bin/spring | 17 ++ bin/update | 31 ++ bin/yarn | 11 + config.ru | 5 + config/application.rb | 26 ++ config/boot.rb | 4 + config/cable.yml | 10 + config/credentials.yml.enc | 1 + config/database.yml | 85 ++++++ config/environment.rb | 5 + config/environments/development.rb | 61 ++++ config/environments/production.rb | 94 ++++++ config/environments/test.rb | 46 +++ config/initializers/action_view.rb | 1 + .../application_controller_renderer.rb | 8 + config/initializers/assets.rb | 14 + config/initializers/backtrace_silencers.rb | 7 + .../initializers/content_security_policy.rb | 25 ++ config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 + config/initializers/mime_types.rb | 4 + config/initializers/wrap_parameters.rb | 14 + config/locales/en.yml | 33 +++ config/puma.rb | 34 +++ config/routes.rb | 3 + config/spring.rb | 6 + config/storage.yml | 34 +++ lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 package.json | 5 + public/404.html | 67 +++++ public/422.html | 67 +++++ public/500.html | 66 +++++ public/apple-touch-icon-precomposed.png | 0 public/apple-touch-icon.png | 0 public/favicon.ico | 0 public/robots.txt | 1 + storage/.keep | 0 test/application_system_test_case.rb | 5 + test/controllers/.keep | 0 test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/system/.keep | 0 test/test_helper.rb | 10 + tmp/.keep | 0 vendor/.keep | 0 80 files changed, 1385 insertions(+) create mode 100644 .gitignore create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Guardfile create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/helpers/application_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100755 bin/yarn create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/credentials.yml.enc create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/action_view.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/content_security_policy.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/spring.rb create mode 100644 config/storage.yml create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 package.json create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/apple-touch-icon-precomposed.png create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 storage/.keep create mode 100644 test/application_system_test_case.rb create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/system/.keep create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..b37716faa --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history + /coverage + .DS_Store + + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..160fe391c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.5 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..87a48610f --- /dev/null +++ b/Gemfile @@ -0,0 +1,83 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.5.5' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.3' +# Use postgresql as the database for Active Record +gem 'pg', '>= 0.18', '< 2.0' +# Use Puma as the app server +gem 'puma', '~> 3.11' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'mini_racer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-turbolinks' +gem 'jquery-rails' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' + gem 'debase', '>= 0.2.4.1' + gem 'ruby-debug-ide', '>= 0.7.0' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' + gem 'minitest-skip' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..1696f55d3 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,277 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.3) + actionpack (= 5.2.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.3) + actionview (= 5.2.3) + activesupport (= 5.2.3) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.3) + activesupport (= 5.2.3) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.3) + activesupport (= 5.2.3) + globalid (>= 0.3.6) + activemodel (5.2.3) + activesupport (= 5.2.3) + activerecord (5.2.3) + activemodel (= 5.2.3) + activesupport (= 5.2.3) + arel (>= 9.0) + activestorage (5.2.3) + actionpack (= 5.2.3) + activerecord (= 5.2.3) + marcel (~> 0.3.1) + activesupport (5.2.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + ansi (1.5.0) + archive-zip (0.12.0) + io-like (~> 0.3.0) + arel (9.0.0) + better_errors (2.5.1) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) + bindex (0.8.1) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + bootsnap (1.4.5) + msgpack (~> 1.0) + builder (3.2.3) + byebug (11.0.1) + capybara (3.29.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + childprocess (3.0.0) + chromedriver-helper (2.1.1) + archive-zip (~> 0.10) + nokogiri (~> 1.8) + coderay (1.1.2) + concurrent-ruby (1.1.5) + crass (1.0.4) + debase (0.2.4.1) + debase-ruby_core_source (>= 0.10.2) + debase-ruby_core_source (0.10.6) + debug_inspector (0.0.3) + erubi (1.9.0) + execjs (2.7.0) + ffi (1.11.1) + formatador (0.2.5) + globalid (0.4.2) + activesupport (>= 4.2.0) + guard (2.15.1) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-minitest (2.4.6) + guard-compat (~> 1.2) + minitest (>= 3.0) + i18n (1.7.0) + concurrent-ruby (~> 1.0) + io-like (0.3.0) + jbuilder (2.9.1) + activesupport (>= 4.2.0) + jquery-rails (4.3.5) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-turbolinks (2.1.0) + railties (>= 3.1.0) + turbolinks + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.3.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + lumberjack (1.0.13) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.2) + mimemagic (0.3.3) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.12.2) + minitest-rails (5.2.0) + minitest (~> 5.10) + railties (~> 5.2.0) + minitest-reporters (1.4.0) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + minitest-skip (0.0.1) + minitest (~> 5.0) + msgpack (1.3.1) + nenv (0.3.0) + nio4r (2.5.2) + nokogiri (1.10.4) + mini_portile2 (~> 2.4.0) + notiffany (0.1.3) + nenv (~> 0.1) + shellany (~> 0.0) + pg (1.1.4) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.9) + pry (>= 0.10.4) + public_suffix (4.0.1) + puma (3.12.1) + rack (2.0.7) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.3) + actioncable (= 5.2.3) + actionmailer (= 5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + activemodel (= 5.2.3) + activerecord (= 5.2.3) + activestorage (= 5.2.3) + activesupport (= 5.2.3) + bundler (>= 1.3.0) + railties (= 5.2.3) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.2.3) + actionpack (= 5.2.3) + activesupport (= 5.2.3) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rake (13.0.0) + rb-fsevent (0.10.3) + rb-inotify (0.10.0) + ffi (~> 1.0) + regexp_parser (1.6.0) + ruby-debug-ide (0.7.0) + rake (>= 0.8.1) + ruby-progressbar (1.10.1) + ruby_dep (1.5.0) + rubyzip (2.0.0) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.1.0) + railties (>= 5.2.0) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.142.6) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) + shellany (0.0.1) + spring (2.1.0) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.20.3) + thread_safe (0.3.6) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.1) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.4) + xpath (3.2.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + bootsnap (>= 1.1.0) + byebug + capybara (>= 2.15) + chromedriver-helper + debase (>= 0.2.4.1) + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + minitest-skip + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.3) + ruby-debug-ide (>= 0.7.0) + sass-rails (~> 5.0) + selenium-webdriver + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +RUBY VERSION + ruby 2.5.5p157 + +BUNDLED WITH + 2.0.2 diff --git a/Guardfile b/Guardfile new file mode 100644 index 000000000..e34f706f4 --- /dev/null +++ b/Guardfile @@ -0,0 +1,9 @@ +guard :minitest, autorun: false, spring: true do + watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/.+_test.rb$}) + watch(%r{^test/test_helper.rb$}) { 'test' } +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..e85f91391 --- /dev/null +++ b/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_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 000000000..b16e53d6d --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 000000000..82e6f0f6c --- /dev/null +++ b/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, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require rails-ujs +//= require activestorage +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 000000000..739aa5f02 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 000000000..d05ea0f51 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 000000000..d67269728 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 000000000..0ff5442f4 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 000000000..09705d12a --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 000000000..a009ace51 --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..286b2239d --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 000000000..692ca547e --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,15 @@ + + + + RideShareRails + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 000000000..cbd34d2e9 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 000000000..37f0bddbd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..f19acf5b5 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 000000000..5badb2fde --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..d87d5f578 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..94fd4d797 --- /dev/null +++ b/bin/setup @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 000000000..d89ee495f --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads Spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == 'spring' } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/update b/bin/update new file mode 100755 index 000000000..58bfaed51 --- /dev/null +++ b/bin/update @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 000000000..460dd565b --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 000000000..f7ba0b527 --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 000000000..c3cd1cf95 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,26 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module RideShareRails + class Application < Rails::Application + config.generators do |g| + # Force new test files to be generated in the minitest-spec style + g.test_framework :minitest, spec: true + + # Always use .js files, never .coffee + g.javascript_engine :js + end + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 000000000..b9e460cef --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 000000000..0b6186ad8 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: ride-share-rails_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 000000000..7daf75d0b --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +ZzIMJM6DVqh1MivGX0Ukr3a6sQiCgdStdpyNUQ92+AWUkURzUlv7fQ3ON+Tp+gNRk6yfnl3LIRLJOlFo6Bt9P3FQj+4pBYZUV7EgCkZOSLnARIB0EkJTODri2jyZqNWOHuJxgfh8+ZmCjI3Vo2jIC2poH8ibMO2uqJ35sYREOXdl3Q3sw5gU770c2F2Uuh3RVDdxx6qH1i/mPWzzWcOXUXVKHJHUX2waIwd+CTnyF/b6VgIV/RiWJBoUBLyhJ9BPaakDdxKZE2UmxRejdaR5E6zgnDznR8HcP1i5R9tI/+bUNmqVGegjq6YHgwnYwChGzRGW2CezwUZH31lBLA9u4fpwAgb/b1JFoER8Z+6qltQIpmLWety01E+06X/SzgadMwZOO/YXtlKWISxlObzH+7eWOArDHlHCoRfx--X84BMWzGbAdJYdBD--81KDgpkcWvhL0VZ8sp+6VA== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 000000000..684902e69 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: ride-share-rails_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: ride-share-rails + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: ride-share-rails_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: ride-share-rails_production + username: ride-share-rails + password: <%= ENV['RIDE-SHARE-RAILS_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 000000000..426333bb4 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 000000000..1311e3e4e --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,61 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = 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 + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # 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 + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 000000000..cee449f7b --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,94 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # 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 + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "ride-share-rails_#{Rails.env}" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 000000000..0a38fd3ce --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,46 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # 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 + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = 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 + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb new file mode 100644 index 000000000..142d382f8 --- /dev/null +++ b/config/initializers/action_view.rb @@ -0,0 +1 @@ +Rails.application.config.action_view.form_with_generates_remote_forms = false diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..4b828e80c --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/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/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 000000000..d3bcaa5ec --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..5a6a32d37 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/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/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/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/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 000000000..dc1899682 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..bbfc3961b --- /dev/null +++ b/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] +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/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 000000000..decc5a857 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,33 @@ +# 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. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 000000000..a5eccf816 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 000000000..787824f88 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +end diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 000000000..9fa7863f9 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 000000000..d32f76e8f --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/log/.keep b/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json new file mode 100644 index 000000000..75b35d319 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "ride-share-rails", + "private": true, + "dependencies": {} +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 000000000..2be3af26f --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 000000000..c08eac0d1 --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 000000000..78a030af2 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png new file mode 100644 index 000000000..e69de29bb diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 000000000..e69de29bb diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 000000000..37b576a4a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 000000000..d19212abd --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 000000000..3ab84e3d1 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,10 @@ +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 000000000..e69de29bb From 79fd814695baf75a10e495fc0528b6c7f41ef421 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 15:50:46 -0700 Subject: [PATCH 002/118] added rb-readline gem to gemfile --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 87a48610f..420e0bc1c 100644 --- a/Gemfile +++ b/Gemfile @@ -74,6 +74,7 @@ group :development do gem 'guard-minitest' gem 'debase', '>= 0.2.4.1' gem 'ruby-debug-ide', '>= 0.7.0' + gem 'rb-readline' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 1696f55d3..55874998b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -183,6 +183,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) + rb-readline (0.5.5) regexp_parser (1.6.0) ruby-debug-ide (0.7.0) rake (>= 0.8.1) @@ -260,6 +261,7 @@ DEPENDENCIES pry-rails puma (~> 3.11) rails (~> 5.2.3) + rb-readline ruby-debug-ide (>= 0.7.0) sass-rails (~> 5.0) selenium-webdriver From cf84667ab8359617b39ada96d444f73a2775d11d Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:01:09 -0700 Subject: [PATCH 003/118] set up models and schema --- app/models/driver.rb | 3 ++ app/models/passenger.rb | 3 ++ app/models/trip.rb | 4 ++ db/migrate/20191007225217_create_drivers.rb | 10 ++++ .../20191007225306_create_passengers.rb | 10 ++++ db/migrate/20191007225525_create_trips.rb | 11 +++++ .../20191007225718_add_driver_id_to_trips.rb | 5 ++ ...0191007230003_add_passenger_id_to_trips.rb | 5 ++ db/schema.rb | 46 +++++++++++++++++++ 9 files changed, 97 insertions(+) create mode 100644 app/models/driver.rb create mode 100644 app/models/passenger.rb create mode 100644 app/models/trip.rb create mode 100644 db/migrate/20191007225217_create_drivers.rb create mode 100644 db/migrate/20191007225306_create_passengers.rb create mode 100644 db/migrate/20191007225525_create_trips.rb create mode 100644 db/migrate/20191007225718_add_driver_id_to_trips.rb create mode 100644 db/migrate/20191007230003_add_passenger_id_to_trips.rb create mode 100644 db/schema.rb diff --git a/app/models/driver.rb b/app/models/driver.rb new file mode 100644 index 000000000..197e65507 --- /dev/null +++ b/app/models/driver.rb @@ -0,0 +1,3 @@ +class Driver < ApplicationRecord + has_many :trips +end diff --git a/app/models/passenger.rb b/app/models/passenger.rb new file mode 100644 index 000000000..2fef89192 --- /dev/null +++ b/app/models/passenger.rb @@ -0,0 +1,3 @@ +class Passenger < ApplicationRecord + has_many :trips +end diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 000000000..8e2566cd8 --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,4 @@ +class Trip < ApplicationRecord + belongs_to :driver + belongs_to :passenger +end diff --git a/db/migrate/20191007225217_create_drivers.rb b/db/migrate/20191007225217_create_drivers.rb new file mode 100644 index 000000000..fa5b1488f --- /dev/null +++ b/db/migrate/20191007225217_create_drivers.rb @@ -0,0 +1,10 @@ +class CreateDrivers < ActiveRecord::Migration[5.2] + def change + create_table :drivers do |t| + t.string :name + t.string :vin + + t.timestamps + end + end +end diff --git a/db/migrate/20191007225306_create_passengers.rb b/db/migrate/20191007225306_create_passengers.rb new file mode 100644 index 000000000..e7fdfed0a --- /dev/null +++ b/db/migrate/20191007225306_create_passengers.rb @@ -0,0 +1,10 @@ +class CreatePassengers < ActiveRecord::Migration[5.2] + def change + create_table :passengers do |t| + t.string :name + t.string :phone_num + + t.timestamps + end + end +end diff --git a/db/migrate/20191007225525_create_trips.rb b/db/migrate/20191007225525_create_trips.rb new file mode 100644 index 000000000..1a8642bbe --- /dev/null +++ b/db/migrate/20191007225525_create_trips.rb @@ -0,0 +1,11 @@ +class CreateTrips < ActiveRecord::Migration[5.2] + def change + create_table :trips do |t| + t.datetime :date + t.integer :rating + t.integer :cost + + t.timestamps + end + end +end diff --git a/db/migrate/20191007225718_add_driver_id_to_trips.rb b/db/migrate/20191007225718_add_driver_id_to_trips.rb new file mode 100644 index 000000000..22c611432 --- /dev/null +++ b/db/migrate/20191007225718_add_driver_id_to_trips.rb @@ -0,0 +1,5 @@ +class AddDriverIdToTrips < ActiveRecord::Migration[5.2] + def change + add_reference :trips, :driver, foreign_key: true + end +end diff --git a/db/migrate/20191007230003_add_passenger_id_to_trips.rb b/db/migrate/20191007230003_add_passenger_id_to_trips.rb new file mode 100644 index 000000000..fffb1117a --- /dev/null +++ b/db/migrate/20191007230003_add_passenger_id_to_trips.rb @@ -0,0 +1,5 @@ +class AddPassengerIdToTrips < ActiveRecord::Migration[5.2] + def change + add_reference :trips, :passenger, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..0fbad72ff --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,46 @@ +# 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: 2019_10_07_230003) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "drivers", force: :cascade do |t| + t.string "name" + t.string "vin" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "passengers", force: :cascade do |t| + t.string "name" + t.string "phone_num" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "trips", force: :cascade do |t| + t.datetime "date" + t.integer "rating" + t.integer "cost" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "driver_id" + t.bigint "passenger_id" + t.index ["driver_id"], name: "index_trips_on_driver_id" + t.index ["passenger_id"], name: "index_trips_on_passenger_id" + end + + add_foreign_key "trips", "drivers" + add_foreign_key "trips", "passengers" +end From af207119f4ace934371e7d96815d6a79915f5473 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:08:37 -0700 Subject: [PATCH 004/118] generated homepages controller --- app/assets/javascripts/homepages.js | 2 ++ app/assets/stylesheets/homepages.scss | 3 +++ app/controllers/homepages_controller.rb | 2 ++ app/helpers/homepages_helper.rb | 2 ++ 4 files changed, 9 insertions(+) create mode 100644 app/assets/javascripts/homepages.js create mode 100644 app/assets/stylesheets/homepages.scss create mode 100644 app/controllers/homepages_controller.rb create mode 100644 app/helpers/homepages_helper.rb diff --git a/app/assets/javascripts/homepages.js b/app/assets/javascripts/homepages.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/homepages.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/homepages.scss b/app/assets/stylesheets/homepages.scss new file mode 100644 index 000000000..2305c36d1 --- /dev/null +++ b/app/assets/stylesheets/homepages.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Homepages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/homepages_controller.rb b/app/controllers/homepages_controller.rb new file mode 100644 index 000000000..8663bd848 --- /dev/null +++ b/app/controllers/homepages_controller.rb @@ -0,0 +1,2 @@ +class HomepagesController < ApplicationController +end diff --git a/app/helpers/homepages_helper.rb b/app/helpers/homepages_helper.rb new file mode 100644 index 000000000..4bd8098f3 --- /dev/null +++ b/app/helpers/homepages_helper.rb @@ -0,0 +1,2 @@ +module HomepagesHelper +end From 4462ecaf3a42260f6aee210043ac18eefd53158d Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:09:15 -0700 Subject: [PATCH 005/118] generated passengers controller --- app/assets/javascripts/passengers.js | 2 ++ app/assets/stylesheets/passengers.scss | 3 +++ app/controllers/passengers_controller.rb | 2 ++ app/helpers/passengers_helper.rb | 2 ++ 4 files changed, 9 insertions(+) create mode 100644 app/assets/javascripts/passengers.js create mode 100644 app/assets/stylesheets/passengers.scss create mode 100644 app/controllers/passengers_controller.rb create mode 100644 app/helpers/passengers_helper.rb diff --git a/app/assets/javascripts/passengers.js b/app/assets/javascripts/passengers.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/passengers.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/passengers.scss b/app/assets/stylesheets/passengers.scss new file mode 100644 index 000000000..0e27942f7 --- /dev/null +++ b/app/assets/stylesheets/passengers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Passengers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb new file mode 100644 index 000000000..7b08e4832 --- /dev/null +++ b/app/controllers/passengers_controller.rb @@ -0,0 +1,2 @@ +class PassengersController < ApplicationController +end diff --git a/app/helpers/passengers_helper.rb b/app/helpers/passengers_helper.rb new file mode 100644 index 000000000..1af9e68f1 --- /dev/null +++ b/app/helpers/passengers_helper.rb @@ -0,0 +1,2 @@ +module PassengersHelper +end From 01fd1903069dea252371a7531841ef6171c037d6 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:09:36 -0700 Subject: [PATCH 006/118] generated trips controller --- app/assets/javascripts/trips.js | 2 ++ app/assets/stylesheets/trips.scss | 3 +++ app/controllers/trips_controller.rb | 2 ++ app/helpers/trips_helper.rb | 2 ++ 4 files changed, 9 insertions(+) create mode 100644 app/assets/javascripts/trips.js create mode 100644 app/assets/stylesheets/trips.scss create mode 100644 app/controllers/trips_controller.rb create mode 100644 app/helpers/trips_helper.rb diff --git a/app/assets/javascripts/trips.js b/app/assets/javascripts/trips.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/trips.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/trips.scss b/app/assets/stylesheets/trips.scss new file mode 100644 index 000000000..f1f72ad11 --- /dev/null +++ b/app/assets/stylesheets/trips.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Trips controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb new file mode 100644 index 000000000..4275f53c7 --- /dev/null +++ b/app/controllers/trips_controller.rb @@ -0,0 +1,2 @@ +class TripsController < ApplicationController +end diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb new file mode 100644 index 000000000..04f333d46 --- /dev/null +++ b/app/helpers/trips_helper.rb @@ -0,0 +1,2 @@ +module TripsHelper +end From a4bb7262bdb64d7aaf808022c2d685c845992e45 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:09:55 -0700 Subject: [PATCH 007/118] generated drivers controller --- app/assets/javascripts/drivers.js | 2 ++ app/assets/stylesheets/drivers.scss | 3 +++ app/controllers/drivers_controller.rb | 2 ++ app/helpers/drivers_helper.rb | 2 ++ 4 files changed, 9 insertions(+) create mode 100644 app/assets/javascripts/drivers.js create mode 100644 app/assets/stylesheets/drivers.scss create mode 100644 app/controllers/drivers_controller.rb create mode 100644 app/helpers/drivers_helper.rb diff --git a/app/assets/javascripts/drivers.js b/app/assets/javascripts/drivers.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/drivers.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/drivers.scss b/app/assets/stylesheets/drivers.scss new file mode 100644 index 000000000..8c1768a14 --- /dev/null +++ b/app/assets/stylesheets/drivers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Drivers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb new file mode 100644 index 000000000..951cb9876 --- /dev/null +++ b/app/controllers/drivers_controller.rb @@ -0,0 +1,2 @@ +class DriversController < ApplicationController +end diff --git a/app/helpers/drivers_helper.rb b/app/helpers/drivers_helper.rb new file mode 100644 index 000000000..e5fc532e4 --- /dev/null +++ b/app/helpers/drivers_helper.rb @@ -0,0 +1,2 @@ +module DriversHelper +end From 8fd92f136a091651599bb7f4ab768565a5a56063 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:14:21 -0700 Subject: [PATCH 008/118] added routes --- config/routes.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 787824f88..e96f6cbba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,12 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + # root "homepages#index" + # get '/home', to: 'homepages#index', as "home" + + resources :drivers + + resources :passengers + + resources :trips end From b40dfc27725ec9e9e94457b7a6675fd68b5fb519 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:23:02 -0700 Subject: [PATCH 009/118] added minitest/rails to test_helper --- test/test_helper.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ab84e3d1..5b12bbf05 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,9 +2,15 @@ require_relative '../config/environment' require 'rails/test_help' +require 'minitest/rails' +require 'minitest/autorun' +require 'minitest/reporters' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all - + # Add more helper methods to be used by all tests here... end From ace45690cf82a9614d6f66d0c06bfa8427a6ab3a Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:25:26 -0700 Subject: [PATCH 010/118] added drivers#index and test --- app/controllers/drivers_controller.rb | 3 + app/views/drivers/index.html.erb | 0 test/controllers/drivers_controller_test.rb | 108 ++++++++++---------- 3 files changed, 59 insertions(+), 52 deletions(-) create mode 100644 app/views/drivers/index.html.erb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 951cb9876..09b897289 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,2 +1,5 @@ class DriversController < ApplicationController + def index + + end end diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 48aef7556..9cf3eae0d 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -2,81 +2,85 @@ describe DriversController do # Note: If any of these tests have names that conflict with either the requirements or your team's decisions, feel empowered to change the test names. For example, if a given test name says "responds with 404" but your team's decision is to respond with redirect, please change the test name. - + describe "index" do it "responds with success when there are many drivers saved" do # Arrange # Ensure that there is at least one Driver saved - + driver = Driver.create(name: "Bernardo Prosacco", vin: "WBWSS52P9NEYLVDE9") + driver = Driver.create(name: "Minnie Dach", vin: "XF9Z0ST7X18WD41HT") + # Act - + get drivers_path # Assert - + must_respond_with :success end - + it "responds with success when there are no drivers saved" do # Arrange # Ensure that there are zero drivers saved - + driver_list = Driver.all + expect(driver_list.blank?).must_equal true + # Act - + get drivers_path # Assert - + must_respond_with :success end end - + describe "show" do it "responds with success when showing an existing valid driver" do # Arrange # Ensure that there is a driver saved - + # Act - + # Assert - + end - + it "responds with 404 with an invalid driver id" do # Arrange # Ensure that there is an id that points to no driver - + # Act - + # Assert - + end end - + describe "new" do it "responds with success" do end end - + describe "create" do it "can create a new driver with valid information accurately, and redirect" do # Arrange # Set up the form data - + # Act-Assert # Ensure that there is a change of 1 in Driver.count - + # Assert # Find the newly created Driver, and check that all its attributes match what was given in the form data # Check that the controller redirected the user - + end - + it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do # Note: This will not pass until ActiveRecord Validations lesson # Arrange # Set up the form data so that it violates Driver validations - + # Act-Assert # Ensure that there is no change in Driver.count - + # Assert # Check that the controller redirects - + end end @@ -84,92 +88,92 @@ it "responds with success when getting the edit page for an existing, valid driver" do # Arrange # Ensure there is an existing driver saved - + # Act - + # Assert - + end - + it "responds with redirect when getting the edit page for a non-existing driver" do # Arrange # Ensure there is an invalid id that points to no driver - + # Act - + # Assert - + end end - + describe "update" do it "can update an existing driver with valid information accurately, and redirect" do # Arrange # Ensure there is an existing driver saved # Assign the existing driver's id to a local variable # Set up the form data - + # Act-Assert # Ensure that there is no change in Driver.count - + # Assert # Use the local variable of an existing driver's id to find the driver again, and check that its attributes are updated # Check that the controller redirected the user - + end - + it "does not update any driver if given an invalid id, and responds with a 404" do # Arrange # Ensure there is an invalid id that points to no driver # Set up the form data - + # Act-Assert # Ensure that there is no change in Driver.count - + # Assert # Check that the controller gave back a 404 - + end - + it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do # Note: This will not pass until ActiveRecord Validations lesson # Arrange # Ensure there is an existing driver saved # Assign the existing driver's id to a local variable # Set up the form data so that it violates Driver validations - + # Act-Assert # Ensure that there is no change in Driver.count - + # Assert # Check that the controller redirects - + end end - + describe "destroy" do it "destroys the driver instance in db when driver exists, then redirects" do # Arrange # Ensure there is an existing driver saved - + # Act-Assert # Ensure that there is a change of -1 in Driver.count - + # Assert # Check that the controller redirects - + end - + it "does not change the db when the driver does not exist, then responds with " do # Arrange # Ensure there is an invalid id that points to no driver - + # Act-Assert # Ensure that there is no change in Driver.count - + # Assert # Check that the controller responds or redirects with whatever your group decides - + end end end From 2e61378a6a90c9560c48b4e1d05f5825a140b367 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:26:13 -0700 Subject: [PATCH 011/118] added code for drivers#index --- app/controllers/drivers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 09b897289..fa03c2e90 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,5 +1,5 @@ class DriversController < ApplicationController def index - + @drivers = Driver.all end end From 72961c327d927adc469a20330af450d959f31eff Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 7 Oct 2019 16:37:17 -0700 Subject: [PATCH 012/118] added passenger index + tests --- app/controllers/passengers_controller.rb | 97 +++++++++++++++++++ app/views/passengers/index.html.erb | 0 .../controllers/passengers_controller_test.rb | 28 ++++-- 3 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 app/views/passengers/index.html.erb diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 7b08e4832..799b863a8 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -1,2 +1,99 @@ class PassengersController < ApplicationController + def index + @passengers = Passenger.all + end + + def show + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + redirect_to root_path + return + end + end + + def new + @passenger = Passenger.new + end + + def create + @passenger = Passenger.new(passenger_params) + if @passenger.save + redirect_to passenger_path(@passenger.id) + return + else + render :new + return + end + end + + def edit + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + redirect_to root_path + return + end + end + + def update + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + redirect_to root_path + return + end + + if @passenger.update(passenger_params) + redirect_to passenger_path (@passenger.id) + return + else + render :edit + return + end + end + + def destroy + passenger_id = params[:id] + @passenger = Passenger.find_by(id: passenger_id) + + if @passenger.nil? + redirect_to passengers_path + return + end + + @passenger.destroy + + redirect_to passengers_path + return + end + + def complete + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + redirect_to passengers_path + return + end + + if @passenger.completion_date == nil + @passenger.completion_date = Time.now + else + @passenger.completion_date = nil + end + + unless @passenger.save + redirect_to passengers_path + end + + redirect_to passengers_path + return + end + + private + + def passenger_params + return params.require(:passenger).permit(:name, :phone_num) + end + end diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 60acbdfb6..1ba582dfe 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -1,30 +1,40 @@ require "test_helper" describe PassengersController do - describe "index" do - # Your tests go here + describe "index" do + it "responds with success when there are many passengers saved" do + test_passenger = Passenger.create(name: "test person", phone_num: "1234567") + get passengers_path + must_respond_with :success + end + + it "responds with success when there are no passengers saved" do + expect(Passenger.count).must_equal 0 + get passengers_path + must_respond_with :success + end end - + describe "show" do - # Your tests go here + end - + describe "new" do # Your tests go here end - + describe "create" do # Your tests go here end - + describe "edit" do # Your tests go here end - + describe "update" do # Your tests go here end - + describe "destroy" do # Your tests go here end From 9f72e78326d308e0ce8f8fb390d3dcdcea7deff1 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 16:42:59 -0700 Subject: [PATCH 013/118] added view for index action --- app/views/drivers/index.html.erb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index e69de29bb..7982080a4 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -0,0 +1,11 @@ +
+

Drivers

+ +
    + <% @drivers.each do |driver| %> +
  1. + <%= driver.name %> +
  2. + <% end %> +
+
From e33dd3c2717f43348fa53a1d010053da23cb013c Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 7 Oct 2019 16:43:02 -0700 Subject: [PATCH 014/118] added view for index action for passenger --- app/views/passengers/index.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index e69de29bb..0db0db5c0 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -0,0 +1,12 @@ +
+

Passengers

+
    + <% @passengers.each do |passenger| %> +
  1. + <%= passenger.name %> + <%= passenger.phone_num %> +
  2. + <% end %> +
+ +
\ No newline at end of file From 2787abe5caecbdf6d156e150300ffdc206b656ea Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 19:21:09 -0700 Subject: [PATCH 015/118] added and tested driver#show --- app/controllers/drivers_controller.rb | 11 +++++ app/views/drivers/show.html.erb | 51 +++++++++++++++++++++ test/controllers/drivers_controller_test.rb | 13 +++--- 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 app/views/drivers/show.html.erb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index fa03c2e90..8cda147d5 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -2,4 +2,15 @@ class DriversController < ApplicationController def index @drivers = Driver.all end + + def show + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + head :not_found + return + end + end + end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb new file mode 100644 index 000000000..7232e1b5c --- /dev/null +++ b/app/views/drivers/show.html.erb @@ -0,0 +1,51 @@ +
+ <%# name %> +

<%= @driver.name %>

+ + <%# average rating %> +
Average Rating: <%# @driver.rating %>
+ + <%# model %> +
Model: <%= @driver.vin %>
+ + <%# total earnings %> +
Total Earnings: <%# @driver.total_earnings %>
+ + <%# trips list %> +
+

Trips

+ + + + + + + + + + <% @driver.trips.each do |trip| %> + + + + + + + + + <% end %> +
IDDateDriverPassengerPriceRating
+ <%= trip.id %> + + <%= trip.date %> + + <%= trip.driver.name %> + + <%= trip.passenger.name %> + + TBA + + <%= trip.rating %> +
+
+ +
diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 9cf3eae0d..44afdc598 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -2,13 +2,14 @@ describe DriversController do # Note: If any of these tests have names that conflict with either the requirements or your team's decisions, feel empowered to change the test names. For example, if a given test name says "responds with 404" but your team's decision is to respond with redirect, please change the test name. + let(:driver) { + Driver.create(name: "Bernardo Prosacco", vin: "WBWSS52P9NEYLVDE9") + } describe "index" do it "responds with success when there are many drivers saved" do # Arrange # Ensure that there is at least one Driver saved - driver = Driver.create(name: "Bernardo Prosacco", vin: "WBWSS52P9NEYLVDE9") - driver = Driver.create(name: "Minnie Dach", vin: "XF9Z0ST7X18WD41HT") # Act get drivers_path @@ -35,9 +36,9 @@ # Ensure that there is a driver saved # Act - + get driver_path(driver.id) # Assert - + must_respond_with :success end it "responds with 404 with an invalid driver id" do @@ -45,9 +46,9 @@ # Ensure that there is an id that points to no driver # Act - + get driver_path(-1) # Assert - + must_respond_with :not_found end end From 9e87d5409c90d443f3ba33a8347c1152e66cc27a Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 7 Oct 2019 20:12:39 -0700 Subject: [PATCH 016/118] added show method + tests --- app/controllers/passengers_controller.rb | 2 +- app/views/passengers/show.html.erb | 7 +++++++ test/controllers/passengers_controller_test.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/views/passengers/show.html.erb diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 799b863a8..5bc84f4e1 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -7,7 +7,7 @@ def show @passenger = Passenger.find_by(id: params[:id]) if @passenger.nil? - redirect_to root_path + head :not_found return end end diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb new file mode 100644 index 000000000..0740b5011 --- /dev/null +++ b/app/views/passengers/show.html.erb @@ -0,0 +1,7 @@ +
+

Passenger

+

+ Name: <%= @passenger.name %>
+ Phone Number: <%= @passenger.phone_num %> +

+
\ No newline at end of file diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 1ba582dfe..0a6b08c99 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -5,18 +5,31 @@ it "responds with success when there are many passengers saved" do test_passenger = Passenger.create(name: "test person", phone_num: "1234567") get passengers_path + must_respond_with :success end it "responds with success when there are no passengers saved" do expect(Passenger.count).must_equal 0 get passengers_path + must_respond_with :success end end describe "show" do + it "responds with success when showing an existing valid passenger" do + test_passenger = Passenger.create(name: "test person", phone_num: "1234567") + get passenger_path(test_passenger.id) + + must_respond_with :success + end + it "responds with 404 with an invalid passenger id" do + get passenger_path(99999) + + must_respond_with :not_found + end end describe "new" do From eecd90e6522e831f77af045eb80aa65d5cc147d6 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 20:32:18 -0700 Subject: [PATCH 017/118] implemented and tested driver#average_rating --- app/models/driver.rb | 16 ++++++++ app/views/drivers/show.html.erb | 8 ++-- test/models/driver_test.rb | 65 ++++++++++++++++++++++++--------- 3 files changed, 67 insertions(+), 22 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 197e65507..a8c2d0d7a 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,3 +1,19 @@ class Driver < ApplicationRecord has_many :trips + + def average_rating + if self.trips.empty? + average = nil + else + total_rating = 0 + counter = 0 + self.trips.each do |trip| + total_rating += trip.rating + counter += 1 + end + average = (total_rating / counter) + end + return average + end + end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 7232e1b5c..ce9444406 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -3,10 +3,10 @@

<%= @driver.name %>

<%# average rating %> -
Average Rating: <%# @driver.rating %>
+
Average Rating: <%= @driver.average_rating %>
- <%# model %> -
Model: <%= @driver.vin %>
+ <%# vin %> +
Vin: <%= @driver.vin %>
<%# total earnings %>
Total Earnings: <%# @driver.total_earnings %>
@@ -38,7 +38,7 @@ <%= trip.passenger.name %> - TBA + $<%= trip.cost %> <%= trip.rating %> diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 9f12d286c..7953d70e1 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -1,32 +1,30 @@ require "test_helper" describe Driver do - let (:new_driver) { - Driver.new(name: "Kari", vin: "123", active: true, - car_make: "Cherry", car_model: "DR5") - } + let (:new_driver) {Driver.new(name: "Kari", vin: "123", active: true, car_make: "Cherry", car_model: "DR5")} + it "can be instantiated" do # Assert expect(new_driver.valid?).must_equal true end - + it "will have the required fields" do # Arrange new_driver.save driver = Driver.first [:name, :vin, :active, :car_make, :car_model].each do |field| - + # Assert expect(driver).must_respond_to field end end - + describe "relationships" do it "can have many trips" do # Arrange new_driver.save driver = Driver.first - + # Assert expect(driver.trips.count).must_be :>=, 0 driver.trips.each do |trip| @@ -34,47 +32,78 @@ end end end - + describe "validations" do it "must have a name" do # Arrange new_driver.name = nil - + # Assert expect(new_driver.valid?).must_equal false expect(new_driver.errors.messages).must_include :name expect(new_driver.errors.messages[:name]).must_equal ["can't be blank"] end - + it "must have a VIN number" do # Arrange new_driver.vin = nil - + # Assert expect(new_driver.valid?).must_equal false expect(new_driver.errors.messages).must_include :vin expect(new_driver.errors.messages[:vin]).must_equal ["can't be blank"] end end - + # Tests for methods you create should go here describe "custom methods" do + describe "average rating" do - # Your code here + it "can calculate the average rating of multiple trips" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # create a passenger for the trips + passenger = Passenger.create(name: "Nina", phone_num: "560.815.3059") + # create two trips + trip_one = Trip.create(date: Date.current, rating: 5, cost: 1200, driver_id: driver.id, passenger_id: passenger.id) + trip_two = Trip.create(date: Date.current, rating: 3, cost: 1400, driver_id: driver.id, passenger_id: passenger.id) + + # assert + expect(driver.average_rating).must_equal 4 + end + + it "can calculate the average rating of one trip" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # create a passenger for the trips + passenger = Passenger.create(name: "Nina", phone_num: "560.815.3059") + # create two trips + trip_one = Trip.create(date: Date.current, rating: 5, cost: 1200, driver_id: driver.id, passenger_id: passenger.id) + + # assert + expect(driver.average_rating).must_equal 5 + end + + it "returns nil for a driver with no trips" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # assert + expect(driver.average_rating).must_be_nil + end end - + describe "total earnings" do # Your code here end - + describe "can go online" do # Your code here end - + describe "can go offline" do # Your code here end - + # You may have additional methods to test end end From ddd69a4fed47b06d367784d46e45b20c6669b250 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 20:46:46 -0700 Subject: [PATCH 018/118] implemented and tested driver#total_earnings --- app/models/driver.rb | 8 ++++++++ app/views/drivers/show.html.erb | 4 ++-- test/models/driver_test.rb | 32 +++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index a8c2d0d7a..981f96945 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -16,4 +16,12 @@ def average_rating return average end + def total_earnings + total = 0 + self.trips.each do |trip| + total += trip.cost + end + return total + end + end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index ce9444406..9838d1828 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -9,7 +9,7 @@
Vin: <%= @driver.vin %>
<%# total earnings %> -
Total Earnings: <%# @driver.total_earnings %>
+
Total Earnings: <%= number_to_currency(@driver.total_earnings / 100.0) %>
<%# trips list %>
@@ -38,7 +38,7 @@ <%= trip.passenger.name %> - $<%= trip.cost %> + <%= number_to_currency(trip.cost / 100.0) %> <%= trip.rating %> diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 7953d70e1..dee0e5dd2 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -93,7 +93,37 @@ end describe "total earnings" do - # Your code here + it "can calculate the total earnings for multiple trips" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # create a passenger for the trips + passenger = Passenger.create(name: "Nina", phone_num: "560.815.3059") + # create two trips + trip_one = Trip.create(date: Date.current, rating: 5, cost: 1200, driver_id: driver.id, passenger_id: passenger.id) + trip_two = Trip.create(date: Date.current, rating: 3, cost: 1400, driver_id: driver.id, passenger_id: passenger.id) + + # assert + expect(driver.total_earnings).must_equal 2600 + end + + it "can calculate the total earnings for one trip" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # create a passenger for the trips + passenger = Passenger.create(name: "Nina", phone_num: "560.815.3059") + # create two trips + trip_one = Trip.create(date: Date.current, rating: 5, cost: 1200, driver_id: driver.id, passenger_id: passenger.id) + + # assert + expect(driver.total_earnings).must_equal 1200 + end + + it "returns nil for a driver with no trips" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # assert + expect(driver.total_earnings).must_equal 0 + end end describe "can go online" do From f11e8783d610dfdae1ef441ec01175bea95a38ee Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 7 Oct 2019 20:48:24 -0700 Subject: [PATCH 019/118] added crud tests/functions to passenger --- app/controllers/passengers_controller.rb | 4 +- app/views/passengers/edit.html.erb | 3 + app/views/passengers/new.html.erb | 3 + .../controllers/passengers_controller_test.rb | 113 +++++++++++++++++- 4 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 app/views/passengers/edit.html.erb create mode 100644 app/views/passengers/new.html.erb diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 5bc84f4e1..c7d8fb4a3 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -31,7 +31,7 @@ def edit @passenger = Passenger.find_by(id: params[:id]) if @passenger.nil? - redirect_to root_path + redirect_to passengers_path return end end @@ -40,7 +40,7 @@ def update @passenger = Passenger.find_by(id: params[:id]) if @passenger.nil? - redirect_to root_path + head :not_found return end diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb new file mode 100644 index 000000000..5c53a95f7 --- /dev/null +++ b/app/views/passengers/edit.html.erb @@ -0,0 +1,3 @@ +
+a form for editing a new passenger +
\ No newline at end of file diff --git a/app/views/passengers/new.html.erb b/app/views/passengers/new.html.erb new file mode 100644 index 000000000..2c88884f8 --- /dev/null +++ b/app/views/passengers/new.html.erb @@ -0,0 +1,3 @@ +
+a form for creating a new passenger +
\ No newline at end of file diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 0a6b08c99..5669eeb07 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -26,29 +26,130 @@ end it "responds with 404 with an invalid passenger id" do - get passenger_path(99999) + get passenger_path(-1) must_respond_with :not_found end end describe "new" do - # Your tests go here + it "responds with success" do + get new_passenger_path + must_respond_with :success + end end describe "create" do - # Your tests go here + it "can create a new passenger with valid information accurately, and redirect" do + passenger_hash = { + passenger: { + name: "test passenger", + phone_num: "1234567" + } + } + + expect { + post passengers_path, params: passenger_hash + }.must_differ 'Passenger.count', 1 + + new_passenger = Passenger.find_by(name: passenger_hash[:passenger][:name]) + expect(new_passenger.name).must_equal passenger_hash[:passenger][:name] + expect(new_passenger.phone_num).must_equal passenger_hash[:passenger][:phone_num] + + must_respond_with :redirect + must_redirect_to passenger_path(new_passenger.id) + end + + it "does not create a passenger if the form data violates Passenger validations, and responds with a redirect" do + # Note: This will not pass until ActiveRecord Validations lesson + # Arrange + # Set up the form data so that it violates Driver validations + + # Act-Assert + # Ensure that there is no change in Driver.count + + # Assert + # Check that the controller redirects + + end end describe "edit" do - # Your tests go here + it "responds with success when getting the edit page for an existing, valid passenger" do + test_passenger = Passenger.create(name: "test person", phone_num: "1234567") + get edit_passenger_path(test_passenger.id) + + must_respond_with :success + end + + it "responds with redirect when getting the edit page for a non-existing passenger" do + get edit_passenger_path(-1) + + must_respond_with :redirect + must_redirect_to passengers_path + end end describe "update" do - # Your tests go here + before do + @test_passenger = Passenger.create(name: "test person", phone_num: "1234567") + @test_passenger_id = @test_passenger.id + @passenger_hash = { + passenger: { + name: "changed passenger name", + phone_num: "changed number" + } + } + end + it "can update an existing passenger with valid information accurately, and redirect" do + expect {patch passenger_path(@test_passenger_id), params: @passenger_hash}.wont_change "Passenger.count" + + new_passenger = Passenger.find_by(name: @passenger_hash[:passenger][:name]) + expect(new_passenger.name).must_equal @passenger_hash[:passenger][:name] + expect(new_passenger.phone_num).must_equal @passenger_hash[:passenger][:phone_num] + + must_respond_with :redirect + must_redirect_to passenger_path(new_passenger.id) + end + + it "does not update any passenger if given an invalid id, and responds with a 404" do + expect {patch passenger_path(-1), params: @passenger_hash}.wont_change "Passenger.count" + + must_respond_with :not_found + end + + it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do + # Note: This will not pass until ActiveRecord Validations lesson + # Arrange + # Ensure there is an existing driver saved + # Assign the existing driver's id to a local variable + # Set up the form data so that it violates Driver validations + + # Act-Assert + # Ensure that there is no change in Driver.count + + # Assert + # Check that the controller redirects + + end end describe "destroy" do - # Your tests go here + it "destroys the driver instance in db when driver exists, then redirects" do + test_passenger = Passenger.create(name: "test person", phone_num: "1234567") + new_passenger = Passenger.find_by(id: test_passenger.id) + + expect {delete passenger_path(new_passenger.id) }.must_differ 'Passenger.count', -1 + + must_respond_with :redirect + must_redirect_to passengers_path + end + + it "does not change the db when the driver does not exist, then responds with " do + expect {delete passenger_path(-1)}.wont_change 'Passenger.count' + + must_respond_with :redirect + must_redirect_to passengers_path + end end end From 390e81a2d43106be34a77c00eff17e5ca5d3cd9d Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Mon, 7 Oct 2019 21:36:43 -0700 Subject: [PATCH 020/118] implemented and tested driver new and create actions --- app/controllers/drivers_controller.rb | 28 +++++++++++++++++++++ app/views/drivers/new.html.erb | 15 +++++++++++ app/views/drivers/show.html.erb | 2 +- test/controllers/drivers_controller_test.rb | 24 +++++++++++++++++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 app/views/drivers/new.html.erb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 8cda147d5..12e9de0e2 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -13,4 +13,32 @@ def show end end + def new + @driver = Driver.new + end + + def create + params = driver_params + if !params.nil? + @driver = Driver.new(params) + + if @driver.save + redirect_to driver_path(@driver.id) + return + end + end + redirect_to new_driver_path + return + end + + private + + def driver_params + if !params[:driver].nil? + return params.require(:driver).permit(:name, :vin) + else + return nil + end + end + end diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb new file mode 100644 index 000000000..19dd21029 --- /dev/null +++ b/app/views/drivers/new.html.erb @@ -0,0 +1,15 @@ +
+

Add a New Driver

+ + <%= form_with model: @driver, class: "driver-form" do |f| %> +

Please enter information to add a new driver

+ + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :vin %> + <%= f.text_field :vin %> + + <%= f.submit "Add Driver", class: "submit-button" %> + <% end %> +
\ No newline at end of file diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 9838d1828..7ad3f740b 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -3,7 +3,7 @@

<%= @driver.name %>

<%# average rating %> -
Average Rating: <%= @driver.average_rating %>
+
Average Rating: <%= @driver.average_rating.nil? ? "N/A" : @driver.average_rating %>
<%# vin %>
Vin: <%= @driver.vin %>
diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 44afdc598..a37749e60 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -54,6 +54,11 @@ describe "new" do it "responds with success" do + # Act + get new_driver_path + + # Assert + must_respond_with :success end end @@ -61,27 +66,44 @@ it "can create a new driver with valid information accurately, and redirect" do # Arrange # Set up the form data + data_hash = { + driver: { + name: "Micky Mouse", + vin: "777" + } + } # Act-Assert # Ensure that there is a change of 1 in Driver.count + expect { + post drivers_path, params: data_hash + }.must_change 'Driver.count', 1 # Assert # Find the newly created Driver, and check that all its attributes match what was given in the form data # Check that the controller redirected the user + new_driver = Driver.find_by(name: data_hash[:driver][:name]) + expect(new_driver.name).must_equal data_hash[:driver][:name] + expect(new_driver.vin).must_equal data_hash[:driver][:vin] + must_redirect_to driver_path(new_driver.id) end it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do # Note: This will not pass until ActiveRecord Validations lesson # Arrange # Set up the form data so that it violates Driver validations + data_hash = {} # Act-Assert # Ensure that there is no change in Driver.count + expect { + post drivers_path, params: data_hash + }.wont_change 'Driver.count' # Assert # Check that the controller redirects - + must_redirect_to new_driver_path end end From 917cccb2071676937ae3ccc25ec427ec2d6b40f6 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 08:09:29 -0700 Subject: [PATCH 021/118] added nav bar --- app/assets/stylesheets/application.css | 22 ++++++++++++++++++++++ app/views/layouts/application.html.erb | 22 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f51..02b8546ec 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,25 @@ *= require_tree . *= require_self */ + +nav > * { + display: inline-block; +} + +/* css dropdown on hover: https://www.w3schools.com/css/css_dropdowns.asp */ +.dropdown-container { + position: relative; +} + +.dropdown-content { + display: none; + position: absolute; +} + +.dropdown-container:hover .dropdown-content { + display: block; + width: max-content; + + /* make sure it appears on top of everything else */ + z-index: 1; +} \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 692ca547e..433c28c6d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,26 @@ - <%= yield %> + + +
+ <%= yield %> +
From f52e449adf9ed7c3b5fecb8b1088d8336ba6b49b Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 08:11:20 -0700 Subject: [PATCH 022/118] made each list item in driver index a link --- app/views/drivers/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 7982080a4..58395ab37 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -4,7 +4,7 @@
    <% @drivers.each do |driver| %>
  1. - <%= driver.name %> + <%= link_to driver.name, driver_path(driver.id) %>
  2. <% end %>
From 74aea53327943cbb9d1b9103b32aba34560a219b Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 08:22:22 -0700 Subject: [PATCH 023/118] added driver_controller#edit --- app/controllers/drivers_controller.rb | 10 ++++++++++ app/views/drivers/edit.html.erb | 15 +++++++++++++++ app/views/drivers/show.html.erb | 6 ++++++ test/controllers/drivers_controller_test.rb | 8 ++++---- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 app/views/drivers/edit.html.erb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 12e9de0e2..6f8385d4d 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -31,6 +31,16 @@ def create return end + def edit + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + redirect_to drivers_path + return + end + end + private def driver_params diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb new file mode 100644 index 000000000..c28c54407 --- /dev/null +++ b/app/views/drivers/edit.html.erb @@ -0,0 +1,15 @@ +
+

Update this Driver

+ + <%= form_with model: @driver, class: "driver-form" do |f| %> +

Please enter information to update this driver

+ + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :vin %> + <%= f.text_field :vin %> + + <%= f.submit "Update Driver", class: "submit-button" %> + <% end %> +
\ No newline at end of file diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 7ad3f740b..00096f97e 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -11,6 +11,12 @@ <%# total earnings %>
Total Earnings: <%= number_to_currency(@driver.total_earnings / 100.0) %>
+ <%# edit/delete options %> +
+
<%= link_to "Edit", edit_driver_path(@driver.id) %>
+
Delete
+
+ <%# trips list %>

Trips

diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index a37749e60..a4d7495b8 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -113,9 +113,9 @@ # Ensure there is an existing driver saved # Act - + get edit_driver_path(driver.id) # Assert - + must_respond_with :success end it "responds with redirect when getting the edit page for a non-existing driver" do @@ -123,9 +123,9 @@ # Ensure there is an invalid id that points to no driver # Act - + get edit_driver_path(-1) # Assert - + must_redirect_to drivers_path end end From b2ecce1c2867123d93d8639714256657b49ea32a Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 08:32:19 -0700 Subject: [PATCH 024/118] added driver_controller#update --- app/controllers/drivers_controller.rb | 16 ++++++++++++ test/controllers/drivers_controller_test.rb | 29 +++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 6f8385d4d..f71536f1d 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -41,6 +41,22 @@ def edit end end + def update + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + head :not_found + return + elsif @driver.update(driver_params) + redirect_to driver_path(@driver.id) + return + else + render :edit + return + end + end + private def driver_params diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index a4d7495b8..815a2d250 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -133,29 +133,54 @@ it "can update an existing driver with valid information accurately, and redirect" do # Arrange # Ensure there is an existing driver saved + driver = Driver.create(name: "Micky", vin: "777") # Assign the existing driver's id to a local variable + driver_id = driver.id # Set up the form data + data_hash = { + driver: { + name: "Minnie", + vin: "888" + } + } # Act-Assert # Ensure that there is no change in Driver.count + expect { + patch driver_path(driver_id), params: data_hash + }.wont_change "Driver.count" # Assert # Use the local variable of an existing driver's id to find the driver again, and check that its attributes are updated - # Check that the controller redirected the user + updated_driver = Driver.find_by(id: driver_id) + expect(updated_driver.name).must_equal data_hash[:driver][:name] + expect(updated_driver.vin).must_equal data_hash[:driver][:vin] + # Check that the controller redirected the user + must_redirect_to driver_path(updated_driver.id) end it "does not update any driver if given an invalid id, and responds with a 404" do # Arrange # Ensure there is an invalid id that points to no driver + invalid_id = -1 # Set up the form data + data_hash = { + driver: { + name: "Minnie", + vin: "888" + } + } # Act-Assert # Ensure that there is no change in Driver.count + expect { + patch driver_path(invalid_id), params: data_hash + }.wont_change "Driver.count" # Assert # Check that the controller gave back a 404 - + must_respond_with :not_found end it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do From f848a5afd13c6791d22afe619093d2bf6cebe7d1 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 08:38:59 -0700 Subject: [PATCH 025/118] added driver_controller#destroy --- app/controllers/drivers_controller.rb | 14 ++++++++++++++ app/views/drivers/show.html.erb | 2 +- test/controllers/drivers_controller_test.rb | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index f71536f1d..5359384a9 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -57,6 +57,20 @@ def update end end + def destroy + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + head :not_found + return + else + @driver.destroy + redirect_to drivers_path + return + end + end + private def driver_params diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 00096f97e..68c9ac058 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -14,7 +14,7 @@ <%# edit/delete options %>
<%= link_to "Edit", edit_driver_path(@driver.id) %>
-
Delete
+
<%= link_to "Delete", driver_path(@driver.id), method: :delete %>
<%# trips list %> diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 815a2d250..dc909020f 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -203,25 +203,36 @@ it "destroys the driver instance in db when driver exists, then redirects" do # Arrange # Ensure there is an existing driver saved + wrong_driver = Driver.create(name: "Micky", vin: "777") + wrong_driver_id = wrong_driver.id # Act-Assert # Ensure that there is a change of -1 in Driver.count + expect { + delete driver_path(wrong_driver_id) + }.must_change "Driver.count", -1 # Assert + deleted_driver = Driver.find_by(id: wrong_driver_id) + expect(deleted_driver).must_be_nil # Check that the controller redirects - + must_redirect_to drivers_path end it "does not change the db when the driver does not exist, then responds with " do # Arrange # Ensure there is an invalid id that points to no driver + invalid_id = -1 # Act-Assert # Ensure that there is no change in Driver.count + expect { + delete driver_path(invalid_id) + }.wont_change "Driver.count" # Assert # Check that the controller responds or redirects with whatever your group decides - + must_respond_with :not_found end end end From 0656402f060509184cd817af089c61ab52537c0a Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 08:59:14 -0700 Subject: [PATCH 026/118] udpated driver earnings to follow fee and percentage instructions --- app/models/driver.rb | 16 ++++++++++++ app/views/drivers/show.html.erb | 2 +- test/models/driver_test.rb | 43 ++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 981f96945..2d688eb68 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -24,4 +24,20 @@ def total_earnings return total end + # The driver gets 80% of the trip cost after a fee of $1.65 is subtracted + def driver_earnings + before_fee = self.total_earnings + + if before_fee == 0 + return 0 + end + + after_fee = (before_fee - 165) + + percentage = 0.8 + driver_earnings = after_fee * percentage + + return driver_earnings + end + end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 68c9ac058..ce076f32b 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -9,7 +9,7 @@
Vin: <%= @driver.vin %>
<%# total earnings %> -
Total Earnings: <%= number_to_currency(@driver.total_earnings / 100.0) %>
+
Total Earnings: <%= number_to_currency(@driver.driver_earnings / 100.0) %>
<%# edit/delete options %>
diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index dee0e5dd2..55d433aab 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -118,7 +118,7 @@ expect(driver.total_earnings).must_equal 1200 end - it "returns nil for a driver with no trips" do + it "returns 0 for a driver with no trips" do # arrange driver = Driver.create(name: "Kari", vin: "123") # assert @@ -126,6 +126,47 @@ end end + describe "driver earnings" do + it "can calculate the driver's earnings for multiple trips" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # create a passenger for the trips + passenger = Passenger.create(name: "Nina", phone_num: "560.815.3059") + # create two trips + trip_one = Trip.create(date: Date.current, rating: 5, cost: 1200, driver_id: driver.id, passenger_id: passenger.id) + trip_two = Trip.create(date: Date.current, rating: 3, cost: 1400, driver_id: driver.id, passenger_id: passenger.id) + + # 1200 + 1400 = 2600 + # 2600 - 165 = 2435 + # 2435 * 0.8 = 1948 + + # assert + expect(driver.driver_earnings).must_equal 1948 + end + + it "can calculate the driver's earnings for one trip" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # create a passenger for the trips + passenger = Passenger.create(name: "Nina", phone_num: "560.815.3059") + # create two trips + trip_one = Trip.create(date: Date.current, rating: 5, cost: 1200, driver_id: driver.id, passenger_id: passenger.id) + + # 1200 - 165 = 1035 + # 1035 * 0.8 = 828 + + # assert + expect(driver.driver_earnings).must_equal 828 + end + + it "returns 0 for a driver with no trips" do + # arrange + driver = Driver.create(name: "Kari", vin: "123") + # assert + expect(driver.driver_earnings).must_equal 0 + end + end + describe "can go online" do # Your code here end From b3469e9f025c3644b4d5aa56fcbf8bb7f074fb53 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 09:26:02 -0700 Subject: [PATCH 027/118] added views for passenger edit/index/show --- app/views/passengers/edit.html.erb | 14 +++++++++- app/views/passengers/index.html.erb | 3 +- app/views/passengers/show.html.erb | 43 +++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb index 5c53a95f7..93e4d3019 100644 --- a/app/views/passengers/edit.html.erb +++ b/app/views/passengers/edit.html.erb @@ -1,3 +1,15 @@
-a form for editing a new passenger +

Edit Passenger

+ + <%= form_with model: @passenger, class: "passenger-form" do |form| %> +

Please enter information to edit this passenger:

+ + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :phone_num %> + <%= f.text_field :phone_num %> + + <%= f.submit "Update Passenger", class: "submit-button" %> + <% end %>
\ No newline at end of file diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 0db0db5c0..0d161ac1f 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -3,8 +3,7 @@
    <% @passengers.each do |passenger| %>
  1. - <%= passenger.name %> - <%= passenger.phone_num %> + <%= link_to passenger.name, passenger_path(passenger.id) %>
  2. <% end %>
diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 0740b5011..d1d9f2c8b 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -4,4 +4,47 @@ Name: <%= @passenger.name %>
Phone Number: <%= @passenger.phone_num %>

+ + +
+
<%= link_to "Edit", edit_passenger_path(@passenger.id) %>
+
<%= link_to "Delete", passenger_path(@passenger.id), method: :delete %>
+
+ + <%# trips list %> +
+

Trips

+ + + + + + + + + + <% @passenger.trips.each do |trip| %> + + + + + + + + + <% end %> +
IDDateDriverPassengerPriceRating
+ <%= trip.id %> + + <%= trip.date %> + + <%= trip.driver.name %> + + <%= trip.passenger.name %> + + <%= number_to_currency(trip.cost / 100.0) %> + + <%= trip.rating %> +
+
\ No newline at end of file From ea670a93e2afc9c4aa893e021f803d53e9c10072 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 09:35:53 -0700 Subject: [PATCH 028/118] added a passenger test --- app/controllers/passengers_controller.rb | 21 ++++++++++----- .../controllers/passengers_controller_test.rb | 26 +++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index c7d8fb4a3..0a5be69fd 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -17,14 +17,17 @@ def new end def create + params = passenger_params + @passenger = Passenger.new(passenger_params) - if @passenger.save - redirect_to passenger_path(@passenger.id) - return - else - render :new - return + if !params.nil? + if @passenger.save + redirect_to passenger_path(@passenger.id) + return + end end + redirect_to passengers_path + return end def edit @@ -93,7 +96,11 @@ def complete private def passenger_params - return params.require(:passenger).permit(:name, :phone_num) + if !params[:passenger].nil? + return params.require(:passenger).permit(:name, :phone_num) + else + return nil + end end end diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 5669eeb07..aeb69a65a 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -61,15 +61,13 @@ end it "does not create a passenger if the form data violates Passenger validations, and responds with a redirect" do - # Note: This will not pass until ActiveRecord Validations lesson - # Arrange - # Set up the form data so that it violates Driver validations + passenger_hash = {} - # Act-Assert - # Ensure that there is no change in Driver.count + expect { + post passengers_path, params: passenger_hash + }.wont_change 'Passenger.count' - # Assert - # Check that the controller redirects + must_redirect_to passengers_path end end @@ -118,15 +116,15 @@ must_respond_with :not_found end - it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do + it "does not create a passenger if the form data violates passenger validations, and responds with a redirect" do # Note: This will not pass until ActiveRecord Validations lesson # Arrange - # Ensure there is an existing driver saved - # Assign the existing driver's id to a local variable - # Set up the form data so that it violates Driver validations + # Ensure there is an existing passenger saved + # Assign the existing passenger's id to a local variable + # Set up the form data so that it violates passenger validations # Act-Assert - # Ensure that there is no change in Driver.count + # Ensure that there is no change in passenger.count # Assert # Check that the controller redirects @@ -135,7 +133,7 @@ end describe "destroy" do - it "destroys the driver instance in db when driver exists, then redirects" do + it "destroys the passenger instance in db when passenger exists, then redirects" do test_passenger = Passenger.create(name: "test person", phone_num: "1234567") new_passenger = Passenger.find_by(id: test_passenger.id) @@ -145,7 +143,7 @@ must_redirect_to passengers_path end - it "does not change the db when the driver does not exist, then responds with " do + it "does not change the db when the passenger does not exist, then responds with " do expect {delete passenger_path(-1)}.wont_change 'Passenger.count' must_respond_with :redirect From 2c6b2f1d2749b3d0fac47fde3807deebe14bc5ed Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 09:43:57 -0700 Subject: [PATCH 029/118] added total_charged for passenger --- app/models/passenger.rb | 10 ++++++++++ app/views/passengers/show.html.erb | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 2fef89192..c2bb97767 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,3 +1,13 @@ class Passenger < ApplicationRecord has_many :trips + + def total_charged + total = 0 + self.trips.each do |trip| + total += trip.cost + end + return total + end + end + diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index d1d9f2c8b..30b0120ae 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -5,7 +5,8 @@ Phone Number: <%= @passenger.phone_num %>

- +
Total Charged: <%= number_to_currency(@passenger.total_charged / 100.0) %>
+
<%= link_to "Edit", edit_passenger_path(@passenger.id) %>
<%= link_to "Delete", passenger_path(@passenger.id), method: :delete %>
From b7d6bad0ef2685f128a0db0cf35f5ad12456653c Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 09:45:17 -0700 Subject: [PATCH 030/118] added total trips count and prepped car details section to add make and model later --- app/views/drivers/show.html.erb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index ce076f32b..ae800dcee 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -5,8 +5,13 @@ <%# average rating %>
Average Rating: <%= @driver.average_rating.nil? ? "N/A" : @driver.average_rating %>
- <%# vin %> -
Vin: <%= @driver.vin %>
+ <%# car details %> +
+ <%# vin %> +
Vin: <%= @driver.vin %>
+ <%# car make %> + <%# car model %> +
<%# total earnings %>
Total Earnings: <%= number_to_currency(@driver.driver_earnings / 100.0) %>
@@ -20,6 +25,8 @@ <%# trips list %>

Trips

+ <%# how many rides the driver has given %> +
Total Trips: <%= @driver.trips.count %>
From 015c1f8460e652dc6f31ec529d585a4eb79efb59 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 09:47:36 -0700 Subject: [PATCH 031/118] added a homepage --- app/views/homepages/index.html.erb | 0 app/views/passengers/new.html.erb | 14 +++++++++++++- config/routes.rb | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 app/views/homepages/index.html.erb diff --git a/app/views/homepages/index.html.erb b/app/views/homepages/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/passengers/new.html.erb b/app/views/passengers/new.html.erb index 2c88884f8..897823eea 100644 --- a/app/views/passengers/new.html.erb +++ b/app/views/passengers/new.html.erb @@ -1,3 +1,15 @@
-a form for creating a new passenger +

Add a New Passenger

+ + <%= form_with model: @passenger, class: "passenger-form" do |f| %> +

Please enter information to add a new passenger:

+ + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :phone_num %> + <%= f.text_field :phone_num %> + + <%= f.submit "Add Passenger", class: "submit-button" %> + <% end %>
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e96f6cbba..5c7c00947 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - # root "homepages#index" + root 'homepages#index' # get '/home', to: 'homepages#index', as "home" resources :drivers From e7a6d727b720c83ebec9a11de11dcf1e1c484ef5 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 09:49:35 -0700 Subject: [PATCH 032/118] homepage view --- app/views/homepages/index.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/homepages/index.html.erb b/app/views/homepages/index.html.erb index e69de29bb..db0af8959 100644 --- a/app/views/homepages/index.html.erb +++ b/app/views/homepages/index.html.erb @@ -0,0 +1,2 @@ +
<%= link_to "Manage Drivers", drivers_path %>
+
<%= link_to "Manage Passengers", passengers_path %>
\ No newline at end of file From 7e458e6271e974b28391c6914f8773f588f798e7 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 10:00:53 -0700 Subject: [PATCH 033/118] passenger validation --- app/models/passenger.rb | 1 + app/views/passengers/edit.html.erb | 2 +- test/models/passenger_test.rb | 105 +++++++++++++++-------------- 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/app/models/passenger.rb b/app/models/passenger.rb index c2bb97767..88d3deced 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,5 +1,6 @@ class Passenger < ApplicationRecord has_many :trips + validates :phone_num, :name, presence: true def total_charged total = 0 diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb index 93e4d3019..7946f8bf9 100644 --- a/app/views/passengers/edit.html.erb +++ b/app/views/passengers/edit.html.erb @@ -1,7 +1,7 @@

Edit Passenger

- <%= form_with model: @passenger, class: "passenger-form" do |form| %> + <%= form_with model: @passenger, class: "passenger-form" do |f| %>

Please enter information to edit this passenger:

<%= f.label :name %> diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 66ac353d3..bbb08b5e9 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -2,69 +2,70 @@ describe Passenger do let (:new_passenger) { - Passenger.new(name: "Kari", phone_number: "111-111-1211") - } - it "can be instantiated" do + Passenger.new(name: "Kari", phone_num: "111-111-1211") +} +it "can be instantiated" do + # Assert + expect(new_passenger.valid?).must_equal true +end + +it "will have the required fields" do + # Arrange + new_passenger.save + passenger = Passenger.first + [:name, :phone_num].each do |field| + # Assert - expect(new_passenger.valid?).must_equal true + expect(passenger).must_respond_to field end +end - it "will have the required fields" do +describe "relationships" do + it "can have many trips" do + skip # Arrange new_passenger.save passenger = Passenger.first - [:name, :phone_number].each do |field| - - # Assert - expect(passenger).must_respond_to field + + # Assert + expect(passenger.trips.count).must_be :>, 0 + passenger.trips.each do |trip| + expect(trip).must_be_instance_of Trip end end +end - describe "relationships" do - it "can have many trips" do - # Arrange - new_passenger.save - passenger = Passenger.first - - # Assert - expect(passenger.trips.count).must_be :>, 0 - passenger.trips.each do |trip| - expect(trip).must_be_instance_of Trip - end - end +describe "validations" do + it "must have a name" do + # Arrange + new_passenger.name = nil + + # Assert + expect(new_passenger.valid?).must_equal false + expect(new_passenger.errors.messages).must_include :name + expect(new_passenger.errors.messages[:name]).must_equal ["can't be blank"] end - - describe "validations" do - it "must have a name" do - # Arrange - new_passenger.name = nil - - # Assert - expect(new_passenger.valid?).must_equal false - expect(new_passenger.errors.messages).must_include :name - expect(new_passenger.errors.messages[:name]).must_equal ["can't be blank"] - end - - it "must have a phone number" do - # Arrange - new_passenger.phone_number = nil - - # Assert - expect(new_passenger.valid?).must_equal false - expect(new_passenger.errors.messages).must_include :new_passenger - expect(new_passenger.errors.messages[:new_passenger]).must_equal ["can't be blank"] - end + + it "must have a phone number" do + # Arrange + new_passenger.phone_num = nil + + # Assert + expect(new_passenger.valid?).must_equal false + expect(new_passenger.errors.messages).must_include :phone_num + expect(new_passenger.errors.messages[:phone_num]).must_equal ["can't be blank"] end +end - # Tests for methods you create should go here - describe "custom methods" do - describe "request a ride" do - # Your code here - end - - describe "complete trip" do - # Your code here - end - # You may have additional methods to test here +# Tests for methods you create should go here +describe "custom methods" do + describe "request a ride" do + # Your code here + end + + describe "complete trip" do + # Your code here end + # You may have additional methods to test here +end end From 9678400b0ea004472e14c61eb82d06f55505eea1 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 10:28:44 -0700 Subject: [PATCH 034/118] migrated to add active, car make, and car model to drivers table --- db/migrate/20191008172631_add_car_details_to_drivers.rb | 8 ++++++++ db/schema.rb | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20191008172631_add_car_details_to_drivers.rb diff --git a/db/migrate/20191008172631_add_car_details_to_drivers.rb b/db/migrate/20191008172631_add_car_details_to_drivers.rb new file mode 100644 index 000000000..05b486fb3 --- /dev/null +++ b/db/migrate/20191008172631_add_car_details_to_drivers.rb @@ -0,0 +1,8 @@ +class AddCarDetailsToDrivers < ActiveRecord::Migration[5.2] + def change + add_column :drivers, :active, :boolean + + add_column :drivers, :car_make, :string + add_column :drivers, :car_model, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0fbad72ff..4af4a4f77 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_10_07_230003) do +ActiveRecord::Schema.define(version: 2019_10_08_172631) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,9 @@ t.string "vin" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "active" + t.string "car_make" + t.string "car_model" end create_table "passengers", force: :cascade do |t| From bf953a699864e9a9722f969a24898c54bf644e35 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 10:32:39 -0700 Subject: [PATCH 035/118] made driver validation require name and vin --- app/models/driver.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/driver.rb b/app/models/driver.rb index 2d688eb68..cc853b799 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,6 +1,14 @@ class Driver < ApplicationRecord has_many :trips + # validations + + validates :name, presence: true + validates :vin, presence: true + + + # methods + def average_rating if self.trips.empty? average = nil From e8bddb9686d25136af5a24c0fce46407d23ef8de Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 10:59:23 -0700 Subject: [PATCH 036/118] added active, car make, and car model to seed file --- db/seeds.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/seeds.rb b/db/seeds.rb index eab2a92ee..098b12624 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,6 +9,9 @@ driver.id = row['id'] driver.name = row['name'] driver.vin = row['vin'] + driver.active = true + driver.car_make = "Toyota" + driver.car_model = "Prius" successful = driver.save if !successful driver_failures << driver From e473e26b5d335658604c0be654f28890ae83378e Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 11:07:05 -0700 Subject: [PATCH 037/118] added tests for trip_controller#show --- db/schema.rb | 10 ++++----- test/controllers/trips_controller_test.rb | 26 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 4af4a4f77..4d555492f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,10 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_10_08_172631) do - + # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - + create_table "drivers", force: :cascade do |t| t.string "name" t.string "vin" @@ -24,14 +24,14 @@ t.string "car_make" t.string "car_model" end - + create_table "passengers", force: :cascade do |t| t.string "name" t.string "phone_num" t.datetime "created_at", null: false t.datetime "updated_at", null: false end - + create_table "trips", force: :cascade do |t| t.datetime "date" t.integer "rating" @@ -43,7 +43,7 @@ t.index ["driver_id"], name: "index_trips_on_driver_id" t.index ["passenger_id"], name: "index_trips_on_passenger_id" end - + add_foreign_key "trips", "drivers" add_foreign_key "trips", "passengers" end diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index 59455c041..e30fb86a8 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -3,20 +3,38 @@ describe TripsController do describe "show" do # Your tests go here + it "responds with success when showing an existing valid trip" do + # Ensure that there is a trip saved + driver = Driver.create(name: "Bernardo Prosacco", vin: "WBWSS52P9NEYLVDE9") + passenger = Passenger.create(name: "test person", phone_num: "1234567") + trip = Trip.create(date: DateTime.now, rating: 2, cost: 1000, driver_id: driver.id, passenger_id: passenger.id) + + # Act + get trip_path(trip.id) + # Assert + must_respond_with :success + end + + it "responds with 404 with an invalid trip id" do + # Act + get trip_path(-1) + # Assert + must_respond_with :not_found + end end - + describe "create" do # Your tests go here end - + describe "edit" do # Your tests go here end - + describe "update" do # Your tests go here end - + describe "destroy" do # Your tests go here end From 3a49275c742b0228d4d182e05b877e3100611433 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 11:08:11 -0700 Subject: [PATCH 038/118] added trip index and show action/view --- app/controllers/trips_controller.rb | 44 +++++++++++++++++++++++++++++ app/views/trips/index.html.erb | 11 ++++++++ app/views/trips/show.html.erb | 0 3 files changed, 55 insertions(+) create mode 100644 app/views/trips/index.html.erb create mode 100644 app/views/trips/show.html.erb diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 4275f53c7..14e9b4a8a 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,2 +1,46 @@ class TripsController < ApplicationController + def index + @trips = Trip.all + end + + def show + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + head :not_found + return + end + end + + def new + + end + + def create + + end + + def edit + + end + + def update + + end + + def destroy + + end + + def complete + + + end + + private + + def trip_params + + end + end diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb new file mode 100644 index 000000000..bfc23bc9f --- /dev/null +++ b/app/views/trips/index.html.erb @@ -0,0 +1,11 @@ +
+

Trips

+
    + <% @trips.each do |trip| %> +
  1. + <%= link_to trip.id, trip_path(trip.id) %> +
  2. + <% end %> +
+ +
\ No newline at end of file diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb new file mode 100644 index 000000000..e69de29bb From 3fa5be57cb38aa382eaebfa66f83f2d2ef9a94d0 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 11:09:55 -0700 Subject: [PATCH 039/118] removed index for trips --- app/controllers/trips_controller.rb | 4 ---- app/views/trips/index.html.erb | 11 ----------- 2 files changed, 15 deletions(-) delete mode 100644 app/views/trips/index.html.erb diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 14e9b4a8a..e05d22743 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,8 +1,4 @@ class TripsController < ApplicationController - def index - @trips = Trip.all - end - def show @trip = Trip.find_by(id: params[:id]) diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb deleted file mode 100644 index bfc23bc9f..000000000 --- a/app/views/trips/index.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -
-

Trips

-
    - <% @trips.each do |trip| %> -
  1. - <%= link_to trip.id, trip_path(trip.id) %> -
  2. - <% end %> -
- -
\ No newline at end of file From 9c60a8414c410c96368ab725af8a38043bd43fbf Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 11:10:20 -0700 Subject: [PATCH 040/118] removed index path from routes --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 5c7c00947..f3d36612a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,5 +8,5 @@ resources :passengers - resources :trips + resources :trips, except: [:index] end From 150ac63f6d1016114e6a5d8c49d1b8ded44c4dc3 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 11:12:45 -0700 Subject: [PATCH 041/118] removed trip#new path from routes --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index f3d36612a..317694d06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,5 +8,5 @@ resources :passengers - resources :trips, except: [:index] + resources :trips, except: [:index, :new] end From 9d2ea1c86741faf275b38560fcd60b965e20ef39 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 11:13:31 -0700 Subject: [PATCH 042/118] updated passenger/trips controller actions --- app/controllers/passengers_controller.rb | 22 ---------------------- app/controllers/trips_controller.rb | 9 --------- 2 files changed, 31 deletions(-) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 0a5be69fd..56eb9e9e0 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -71,28 +71,6 @@ def destroy return end - def complete - @passenger = Passenger.find_by(id: params[:id]) - - if @passenger.nil? - redirect_to passengers_path - return - end - - if @passenger.completion_date == nil - @passenger.completion_date = Time.now - else - @passenger.completion_date = nil - end - - unless @passenger.save - redirect_to passengers_path - end - - redirect_to passengers_path - return - end - private def passenger_params diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index e05d22743..24912668b 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -8,10 +8,6 @@ def show end end - def new - - end - def create end @@ -26,11 +22,6 @@ def update def destroy - end - - def complete - - end private From 5361be6a27c3dc7ad737b9d6254b2606483cd985 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 12:34:42 -0700 Subject: [PATCH 043/118] added trips_controller#create --- app/controllers/trips_controller.rb | 15 +++++-- test/controllers/trips_controller_test.rb | 52 ++++++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 24912668b..59493c1d4 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -8,8 +8,17 @@ def show end end - def create - + def create + if !(params[:trip].nil?) + @trip = Trip.new(trip_params) + + if @trip.save + redirect_to passenger_path(@trip.passenger_id) + return + end + else + redirect_to root_path + end end def edit @@ -27,7 +36,7 @@ def destroy private def trip_params - + return params.require(:trip).permit(:date, :rating, :cost, :driver_id, :passenger_id) end end diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index e30fb86a8..cef890344 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -24,7 +24,57 @@ end describe "create" do - # Your tests go here + it "can create a new trip with valid information accurately, and redirect" do + # Arrange + driver = Driver.create(name: "Bernardo Prosacco", vin: "WBWSS52P9NEYLVDE9") + passenger = Passenger.create(name: "test person", phone_num: "1234567") + + # Set up the form data + data_hash = { + trip: { + date: DateTime.now, + rating: 2, + cost: 1000, + driver_id: driver.id, + passenger_id: passenger.id, + } + } + + # Act-Assert + # Ensure that there is a change of 1 in Trip.count + expect { + post trips_path, params: data_hash + }.must_change 'Trip.count', 1 + + # Assert + # Find the newly created Trip, and check that all its attributes match what was given in the form data + # Check that the controller redirected the user + + new_trip = Trip.first + expect(new_trip.rating).must_equal data_hash[:trip][:rating] + expect(new_trip.cost).must_equal data_hash[:trip][:cost] + expect(new_trip.driver_id).must_equal data_hash[:trip][:driver_id] + expect(new_trip.passenger_id).must_equal data_hash[:trip][:passenger_id] + + must_redirect_to passenger_path(new_trip.passenger_id) + end + + it "does not create a trip if the form data violates Trip validations, and responds with a redirect" do + # Note: This will not pass until ActiveRecord Validations lesson + # Arrange + # Set up the form data so that it violates Trip validations + data_hash = {} + + # Act-Assert + # Ensure that there is no change in Trip.count + expect { + post trips_path, params: data_hash + }.wont_change 'Trip.count' + + # Assert + # Check that the controller redirects + must_redirect_to root_path + end end describe "edit" do From bb56a358623e0cbf8ed52facf9482d23c4608d69 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 12:38:58 -0700 Subject: [PATCH 044/118] edited driver/passenger create action --- app/controllers/drivers_controller.rb | 3 +-- app/controllers/passengers_controller.rb | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 5359384a9..2891d0a01 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -18,9 +18,8 @@ def new end def create - params = driver_params if !params.nil? - @driver = Driver.new(params) + @driver = Driver.new(driver_params) if @driver.save redirect_to driver_path(@driver.id) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 56eb9e9e0..71ebcb8e8 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -17,8 +17,6 @@ def new end def create - params = passenger_params - @passenger = Passenger.new(passenger_params) if !params.nil? if @passenger.save From 30ce146184416bc445d4bfc9eadd44344f78871a Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 12:44:16 -0700 Subject: [PATCH 045/118] added trip link to passenger/driver show view --- app/views/drivers/show.html.erb | 2 +- app/views/passengers/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index ae800dcee..95b2b8a6e 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -39,7 +39,7 @@ <% @driver.trips.each do |trip| %>
+ @@ -13,6 +14,11 @@ + <% if driver.active %> + + <% elsif !driver.active %> + + <% end %> <% end %> From 3fd181036506eaeffd3568e37c9bd39629554185 Mon Sep 17 00:00:00 2001 From: Alice Date: Thu, 10 Oct 2019 21:21:29 -0700 Subject: [PATCH 100/118] added more styling --- app/assets/stylesheets/application.css | 142 ++++++++++++++++++++++++- app/assets/stylesheets/drivers.scss | 53 --------- app/assets/stylesheets/homepages.scss | 1 + app/views/drivers/_form.html.erb | 6 +- app/views/shared/_triptable.html.erb | 4 +- 5 files changed, 146 insertions(+), 60 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 8b109e977..ffff0783b 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -27,6 +27,7 @@ a { nav { background: rgb(255,0,191); + border-radius: 15px; } h1 a:visited { @@ -81,9 +82,12 @@ nav > * { /* table */ .table{ - width: 40rem; + margin-left:auto; + margin-right:auto; + width: auto; table-layout: fixed; border-collapse: collapse; + border: 1px solid black; } .table tbody{ @@ -102,12 +106,53 @@ nav > * { color: white; } +.table th{ + height: 3em; +} + .table th, .table td { - padding: .2em; + padding: .3em; + text-align: left; + width: 12em; + border-bottom: 1px solid #ddd; +} + +.table tr:nth-child(even) { + background-color: #f5f5f5; +} + +/* triptable */ +.trip-table{ + margin-top: 1.5rem; + margin-left:auto; + margin-right:auto; + width: auto; + table-layout: fixed; + border-collapse: collapse; + border: 1px solid black; +} + +.trip-table thead { + background: rgb(255,0,191); + color: white; +} + +.trip-table th, .trip-table td { + padding: .3em; text-align: left; width: 12em; + border-bottom: 1px solid #ddd; +} + +.trip-table tr:nth-child(even) { + background-color: #f5f5f5; +} + +.trip-table th{ + height: 2em; } +/* statuses */ .available { color: green; } @@ -137,4 +182,95 @@ nav > * { display: table; padding: 1em; margin: 1em; -} \ No newline at end of file +} + +.driver-form label{ + display: block; + width: 100%; + padding: .2em; +} + +.driver-form input{ + display: block; + width: 15rem; + padding: .5em; +} + +.submit-button { + background-color: rgb(255,0,191); + margin-top: .7em; + float: left; + color: white; + font-size: 1.2em; + display: inline-block; + text-align: center; + border-radius: 15px; + height: 3rem; +} + +.submit-button:hover { + background-color: rgb(196, 4, 148) +} + +.submit-button:active { + background-color: rgb(196, 4, 148); + box-shadow: 0 5px rgb(102, 102, 102); + transform: translateY(4px); +} + + +/* driver and passenger view pages */ + +main section { + height: max-content; + margin-bottom: 4rem; +} + +$pink: rgb(255,0,191); + +.details { + width: 100%; + display: flex; + flex-direction: column; +} + +.details > * { + background-color: #FFACEA; + border-radius: 15px; + width: max-content; + padding: 1rem; + margin: 0.5rem; +} + +.modify-options { + width: auto; + + display: flex; + flex-flow: row wrap; + justify-content: flex-end; +} + +.modify-options > * { + margin: 0 4rem 0 1rem; +} + +.car-details { + display: grid; + grid-template-columns: 1fr 1fr; + row-gap: 0.5rem; +} + +.vin, .vin-label { + grid-row-start: 1; + grid-row-end: 2; +} + +.make, .make-label { + grid-row-start: 2; + grid-row-end: 3; +} + +.model, .model-label { + grid-row-start: 3; + grid-row-end: 4; +} diff --git a/app/assets/stylesheets/drivers.scss b/app/assets/stylesheets/drivers.scss index 2bbcd6136..8c1768a14 100644 --- a/app/assets/stylesheets/drivers.scss +++ b/app/assets/stylesheets/drivers.scss @@ -1,56 +1,3 @@ // Place all the styles related to the Drivers controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ - -main section { - height: max-content; - margin-bottom: 4rem; -} - -$pink: rgb(255,0,191); - -.details { - width: 100%; - display: flex; - flex-direction: column; -} - -.details > * { - background-color: #FFACEA; - width: max-content; - padding: 1rem; - margin: 0.5rem; -} - -.modify-options { - width: 100%; - - display: flex; - flex-flow: row wrap; - justify-content: flex-end; -} - -.modify-options > * { - margin: 0 4rem 0 1rem; -} - -.car-details { - display: grid; - grid-template-columns: 1fr 1fr; - row-gap: 0.5rem; -} - -.vin, .vin-label { - grid-row-start: 1; - grid-row-end: 2; -} - -.make, .make-label { - grid-row-start: 2; - grid-row-end: 3; -} - -.model, .model-label { - grid-row-start: 3; - grid-row-end: 4; -} diff --git a/app/assets/stylesheets/homepages.scss b/app/assets/stylesheets/homepages.scss index 9fd56ec2f..35af21ef4 100644 --- a/app/assets/stylesheets/homepages.scss +++ b/app/assets/stylesheets/homepages.scss @@ -23,6 +23,7 @@ $pink: rgb(255,0,191); text-align: center; font-size: 3em; color: white; + border-radius: 15px; background-color: $pink; padding: 2rem; diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index 292ea0931..6db2ab910 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -1,8 +1,8 @@ <%= form_with model: @driver, class: "driver-form" do |f| %> -

Please enter information to <%= message %> driver

+

Please enter information to <%= message %> driver:

- <%= f.label :name %> - <%= f.text_field :name %> + <%= f.label :name, class: 'label' %> + <%= f.text_field :name, class: 'name'%> <%= f.label :vin %> <%= f.text_field :vin %> diff --git a/app/views/shared/_triptable.html.erb b/app/views/shared/_triptable.html.erb index cc365b556..d86c5d40c 100644 --- a/app/views/shared/_triptable.html.erb +++ b/app/views/shared/_triptable.html.erb @@ -2,7 +2,8 @@

Trips

<%# how many rides the driver has given %>
Total Trips: <%= object.trips.count %>
-
ID
- <%= trip.id %> + <%= link_to trip.id, trip_path(trip.id)%> <%= trip.date %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 30b0120ae..959943cb4 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -27,7 +27,7 @@ <% @passenger.trips.each do |trip| %>
- <%= trip.id %> + <%= link_to trip.id, trip_path(trip.id)%> <%= trip.date %> From 81ad7ae66c55b4413efd4acc16df263192db14fc Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 12:56:52 -0700 Subject: [PATCH 046/118] added trip show view --- app/views/trips/show.html.erb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index e69de29bb..d5759a4ba 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -0,0 +1,19 @@ +
+

Trip #<%= @trip.id %>

+

+ Date: <%= @trip.date %>
+ Driver: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>
+ Passenger: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>
+ Rating: <%= @trip.rating %>
+ Cost: <%= @trip.cost %>
+

+ + +
+
<%= link_to "Rate Trip" %>
+
<%= link_to "Edit", edit_trip_path(@trip.id) %>
+
<%= link_to "Delete", trip_path(@trip.id), method: :delete %>
+
+ + +
\ No newline at end of file From 457647dc968ff736e8f73695d38a1b8143eb77ea Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 13:12:18 -0700 Subject: [PATCH 047/118] edited driver/passenger show view --- app/views/drivers/show.html.erb | 2 +- app/views/passengers/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 95b2b8a6e..07fbc260a 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -48,7 +48,7 @@ <%= trip.driver.name %>
- <%= trip.passenger.name %> + <%= link_to trip.passenger.name, passenger_path(trip.passenger.id) %> <%= number_to_currency(trip.cost / 100.0) %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 959943cb4..650fead19 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -33,7 +33,7 @@ <%= trip.date %> - <%= trip.driver.name %> + <%= link_to trip.driver.name, driver_path(trip.driver.id) %> <%= trip.passenger.name %> From f2258c1897d28b11dfbf9f4c0e92c88d654538e0 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 14:09:02 -0700 Subject: [PATCH 048/118] made driver show page show status --- app/views/drivers/show.html.erb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 07fbc260a..d9291972b 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -13,6 +13,15 @@ <%# car model %> + <%# driver status %> +
+ <% if @driver.active %> + Active + <% else %> + Inactive + <% end %> +
+ <%# total earnings %>
Total Earnings: <%= number_to_currency(@driver.driver_earnings / 100.0) %>
From 4e3321a36d02d60b4d218c501423abf76e98cceb Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 14:49:18 -0700 Subject: [PATCH 049/118] made driver_controller#create set active to true --- app/controllers/drivers_controller.rb | 2 ++ test/controllers/drivers_controller_test.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 2891d0a01..280e29885 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -19,7 +19,9 @@ def new def create if !params.nil? + @driver = Driver.new(driver_params) + @driver.active = true if @driver.save redirect_to driver_path(@driver.id) diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index dc909020f..b42b4d4c9 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -85,6 +85,7 @@ new_driver = Driver.find_by(name: data_hash[:driver][:name]) expect(new_driver.name).must_equal data_hash[:driver][:name] expect(new_driver.vin).must_equal data_hash[:driver][:vin] + expect(new_driver.active).must_equal true must_redirect_to driver_path(new_driver.id) end From abfe3a56074a716e761e45e72789d8f81cf77e34 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 14:50:42 -0700 Subject: [PATCH 050/118] added number_to_currency to trip show page --- app/views/trips/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index d5759a4ba..baf919f56 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -5,7 +5,7 @@ Driver: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>
Passenger: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>
Rating: <%= @trip.rating %>
- Cost: <%= @trip.cost %>
+ Cost: <%= number_to_currency(@trip.cost / 100.00) %>

From 3dc9df05454031dc2234a7db7f7736265334a282 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 15:11:56 -0700 Subject: [PATCH 051/118] added a test for request trip --- test/controllers/passengers_controller_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index aeb69a65a..40a755723 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -150,4 +150,17 @@ must_redirect_to passengers_path end end + + + describe "request trip" do + it "creates a new trip" do + test_passenger = Passenger.create(name: "test person", phone_num: "1234567") + + expect { + get request_trip_path(test_passenger.id) + }.must_change 'test_passenger.trips.count', 1 + end + end + + end From 08b456ccdd46cd66a06354398f6117b4ca7201fb Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 15:46:42 -0700 Subject: [PATCH 052/118] commented out stuff for nested routes. tomorrow's problem --- app/controllers/passengers_controller.rb | 28 +++++++++++++++++++ app/controllers/trips_controller.rb | 25 +++++++++-------- app/views/passengers/show.html.erb | 2 ++ config/routes.rb | 2 ++ .../controllers/passengers_controller_test.rb | 1 + 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 71ebcb8e8..690881f48 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -69,6 +69,34 @@ def destroy return end + # def request_trip + # passenger_id = params[:id] + # @passenger = Passenger.find_by(id: passenger_id) + + # if @passenger.nil? + # redirect_to passengers_path + # return + # end + + # #call driver to get a driver + # driver = Driver.all.first + # date = DateTime.now + + # trip_params = { + # trip: { + # date: date, + # driver_id: driver.id, + # passenger_id: passenger_id, + # rating: nil, + # cost: nil, + # } + # } + + # redirect_to trips_path, params: trip_params + # # redirect_to root_path + # return + # end + private def passenger_params diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 59493c1d4..c13fcaea9 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -8,18 +8,19 @@ def show end end - def create - if !(params[:trip].nil?) - @trip = Trip.new(trip_params) - - if @trip.save - redirect_to passenger_path(@trip.passenger_id) - return - end - else - redirect_to root_path - end - end + # def create + # if !(params[:trip].nil?) + # @trip = Trip.new(trip_params) + + # if @trip.save + # redirect_to passenger_path(@trip.passenger_id) + # return + # end + # else + # redirect_to root_path + # return + # end + # end def edit diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 650fead19..21a018e9b 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -7,6 +7,8 @@
Total Charged: <%= number_to_currency(@passenger.total_charged / 100.0) %>
+
<%= link_to "Request a Trip", trips_path, method: :post%>
+
<%= link_to "Edit", edit_passenger_path(@passenger.id) %>
<%= link_to "Delete", passenger_path(@passenger.id), method: :delete %>
diff --git a/config/routes.rb b/config/routes.rb index 317694d06..7145f5a43 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,9 @@ resources :drivers + # get '/passengers/:id/request', to: 'passengers#request_trip', as: 'request_trip' resources :passengers + resources :trips, except: [:index, :new] end diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 40a755723..1d0d55f10 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -154,6 +154,7 @@ describe "request trip" do it "creates a new trip" do + test_driver = Driver.create(name: "name", vin: "1234") test_passenger = Passenger.create(name: "test person", phone_num: "1234567") expect { From 1cf79001e4e51754a328dfcaec2d7297bfa88b68 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 15:47:14 -0700 Subject: [PATCH 053/118] added car make and model inputs to new driver form --- app/controllers/drivers_controller.rb | 2 +- app/views/drivers/new.html.erb | 6 ++++++ app/views/passengers/show.html.erb | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 280e29885..11351b057 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -76,7 +76,7 @@ def destroy def driver_params if !params[:driver].nil? - return params.require(:driver).permit(:name, :vin) + return params.require(:driver).permit(:name, :vin, :active, :car_make, :car_model) else return nil end diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index 19dd21029..39be315cf 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -10,6 +10,12 @@ <%= f.label :vin %> <%= f.text_field :vin %> + <%= f.label :car_make %> + <%= f.text_field :car_make %> + + <%= f.label :car_model %> + <%= f.text_field :car_model %> + <%= f.submit "Add Driver", class: "submit-button" %> <% end %> \ No newline at end of file diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 650fead19..0abae9d43 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -6,6 +6,8 @@

Total Charged: <%= number_to_currency(@passenger.total_charged / 100.0) %>
+ +
Request trip link<%# link_to "Request Trip", trips_path(@passenger.id), method: :post %>
<%= link_to "Edit", edit_passenger_path(@passenger.id) %>
From d1cfe90a78dede9450f561c210a5b2d0cce0c95d Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 15:59:39 -0700 Subject: [PATCH 054/118] added gem to test template rendering, added error viewing in new driver show --- Gemfile | 1 + Gemfile.lock | 5 +++++ app/controllers/drivers_controller.rb | 2 +- app/views/drivers/new.html.erb | 10 ++++++++++ test/controllers/drivers_controller_test.rb | 2 +- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 420e0bc1c..ed3b5291c 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,7 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'rails-controller-testing' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 55874998b..8f4145a84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -168,6 +168,10 @@ GEM bundler (>= 1.3.0) railties (= 5.2.3) sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.4) + actionpack (>= 5.0.1.x) + actionview (>= 5.0.1.x) + activesupport (>= 5.0.1.x) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -261,6 +265,7 @@ DEPENDENCIES pry-rails puma (~> 3.11) rails (~> 5.2.3) + rails-controller-testing rb-readline ruby-debug-ide (>= 0.7.0) sass-rails (~> 5.0) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 11351b057..73f32fa00 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -28,7 +28,7 @@ def create return end end - redirect_to new_driver_path + render :new return end diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index 39be315cf..997741764 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -1,6 +1,16 @@

Add a New Driver

+ <% if @driver.errors.any? %> +
    + <% @driver.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+ <% end %> + <%= form_with model: @driver, class: "driver-form" do |f| %>

Please enter information to add a new driver

diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index b42b4d4c9..483b1364f 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -104,7 +104,7 @@ # Assert # Check that the controller redirects - must_redirect_to new_driver_path + assert_template :new end end From d7bd32a88f3774d992d34785ebacb2b998b88745 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:02:09 -0700 Subject: [PATCH 055/118] added passenger errors in view when creating --- app/controllers/passengers_controller.rb | 7 ++++--- app/models/passenger.rb | 3 ++- app/views/passengers/new.html.erb | 15 ++++++++++++++- app/views/passengers/show.html.erb | 10 ++++++++++ test/controllers/passengers_controller_test.rb | 3 +-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 690881f48..0bd9dbbff 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -22,10 +22,11 @@ def create if @passenger.save redirect_to passenger_path(@passenger.id) return + else + render :new + return end - end - redirect_to passengers_path - return + end end def edit diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 88d3deced..64ba086ef 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,6 +1,7 @@ class Passenger < ApplicationRecord has_many :trips - validates :phone_num, :name, presence: true + validates :phone_num, presence: true + validates :name, presence: true def total_charged total = 0 diff --git a/app/views/passengers/new.html.erb b/app/views/passengers/new.html.erb index 897823eea..b396f2923 100644 --- a/app/views/passengers/new.html.erb +++ b/app/views/passengers/new.html.erb @@ -1,6 +1,18 @@
+ +<% if @passenger.errors.any? %> +
    + <% @passenger.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+<% end %> +

Add a New Passenger

+ <%= form_with model: @passenger, class: "passenger-form" do |f| %>

Please enter information to add a new passenger:

@@ -12,4 +24,5 @@ <%= f.submit "Add Passenger", class: "submit-button" %> <% end %> -
\ No newline at end of file +
+ diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 6c7a75345..ea12f1b1f 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,3 +1,13 @@ +<% if @passenger.errors.any? %> +
    + <% @passenger.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+<% end %> +

Passenger

diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 1d0d55f10..7e2ef7142 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -67,8 +67,7 @@ post passengers_path, params: passenger_hash }.wont_change 'Passenger.count' - must_redirect_to passengers_path - + assert_template :new end end From 0ea8f05f0e89732fa98f8f1df6450818983a5e0e Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 16:10:33 -0700 Subject: [PATCH 056/118] added car make and model and error messaging to driver edit --- app/views/drivers/edit.html.erb | 16 ++++++++++++++++ test/controllers/drivers_controller_test.rb | 15 ++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb index c28c54407..fe3fbc8a1 100644 --- a/app/views/drivers/edit.html.erb +++ b/app/views/drivers/edit.html.erb @@ -1,6 +1,16 @@

Update this Driver

+ <% if @driver.errors.any? %> +
    + <% @driver.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+ <% end %> + <%= form_with model: @driver, class: "driver-form" do |f| %>

Please enter information to update this driver

@@ -10,6 +20,12 @@ <%= f.label :vin %> <%= f.text_field :vin %> + <%= f.label :car_make %> + <%= f.text_field :car_make %> + + <%= f.label :car_model %> + <%= f.text_field :car_model %> + <%= f.submit "Update Driver", class: "submit-button" %> <% end %>
\ No newline at end of file diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 483b1364f..91ca6afea 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -188,15 +188,24 @@ # Note: This will not pass until ActiveRecord Validations lesson # Arrange # Ensure there is an existing driver saved + driver = Driver.create(name: "Micky", vin: "777") # Assign the existing driver's id to a local variable + driver_id = driver.id # Set up the form data so that it violates Driver validations - + data_hash = { + driver: { + name: nil, + vin: "888" + } + } # Act-Assert # Ensure that there is no change in Driver.count - + expect { + patch driver_path(driver_id), params: data_hash + }.wont_change 'Driver.count' # Assert # Check that the controller redirects - + assert_template :edit end end From fc66f1b45f02425ac1de0274c088c68f00904e88 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:14:38 -0700 Subject: [PATCH 057/118] removed extra nil check and also edit view errors --- app/controllers/drivers_controller.rb | 21 +++++++++--------- app/controllers/passengers_controller.rb | 21 +++++++++--------- app/views/passengers/show.html.erb | 21 +++++++++--------- .../controllers/passengers_controller_test.rb | 22 +++++++++---------- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 73f32fa00..24d33f3a3 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -18,20 +18,19 @@ def new end def create - if !params.nil? - - @driver = Driver.new(driver_params) - @driver.active = true - - if @driver.save - redirect_to driver_path(@driver.id) - return - end + @driver = Driver.new(driver_params) + @driver.active = true + + if @driver.save + redirect_to driver_path(@driver.id) + return + else + render :new + return end - render :new - return end + def edit driver_id = params[:id].to_i @driver = Driver.find_by(id: driver_id) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 0bd9dbbff..5da654733 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -18,16 +18,16 @@ def new def create @passenger = Passenger.new(passenger_params) - if !params.nil? - if @passenger.save - redirect_to passenger_path(@passenger.id) - return - else - render :new - return - end + + if @passenger.save + redirect_to passenger_path(@passenger.id) + return + else + render :new + return end - end + end + def edit @passenger = Passenger.find_by(id: params[:id]) @@ -36,6 +36,7 @@ def edit redirect_to passengers_path return end + end def update @@ -50,7 +51,7 @@ def update redirect_to passenger_path (@passenger.id) return else - render :edit + render :new return end end diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index ea12f1b1f..10aea8b41 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,15 +1,16 @@ -<% if @passenger.errors.any? %> -
    - <% @passenger.errors.each do |column, message| %> -
  • - <%= column.capitalize %> <%= message %> -
  • - <% end %> -
-<% end %> -

Passenger

+ + <% if @passenger.errors.any? %> +
    + <% @passenger.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+ <% end %> +

Name: <%= @passenger.name %>
Phone Number: <%= @passenger.phone_num %> diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 7e2ef7142..34dc52888 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -115,19 +115,19 @@ must_respond_with :not_found end - it "does not create a passenger if the form data violates passenger validations, and responds with a redirect" do - # Note: This will not pass until ActiveRecord Validations lesson - # Arrange - # Ensure there is an existing passenger saved - # Assign the existing passenger's id to a local variable - # Set up the form data so that it violates passenger validations - - # Act-Assert - # Ensure that there is no change in passenger.count + it "does not create a passenger if the form data violates passenger validations, and responds with a redirect" do + passenger_hash = { + passenger: { + name: nil, + phone_num: nil + } + } - # Assert - # Check that the controller redirects + expect { + patch passenger_path(@test_passenger_id), params: passenger_hash + }.wont_change 'Passenger.count' + assert_template :new end end From 71862e00757e240ca33c6da8e705eae2c91992b2 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:15:12 -0700 Subject: [PATCH 058/118] driver nil check removed --- app/controllers/drivers_controller.rb | 93 ++++++++++++++------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 24d33f3a3..ad8592343 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -27,58 +27,59 @@ def create else render :new return + endt end - end - - - def edit - driver_id = params[:id].to_i - @driver = Driver.find_by(id: driver_id) - if @driver.nil? - redirect_to drivers_path - return + + def edit + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + redirect_to drivers_path + return + end end - end - - def update - driver_id = params[:id].to_i - @driver = Driver.find_by(id: driver_id) - if @driver.nil? - head :not_found - return - elsif @driver.update(driver_params) - redirect_to driver_path(@driver.id) - return - else - render :edit - return + def update + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + head :not_found + return + elsif @driver.update(driver_params) + redirect_to driver_path(@driver.id) + return + else + render :edit + return + end end - end - - def destroy - driver_id = params[:id].to_i - @driver = Driver.find_by(id: driver_id) - if @driver.nil? - head :not_found - return - else - @driver.destroy - redirect_to drivers_path - return + def destroy + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.nil? + head :not_found + return + else + @driver.destroy + redirect_to drivers_path + return + end end - end - - private - - def driver_params - if !params[:driver].nil? - return params.require(:driver).permit(:name, :vin, :active, :car_make, :car_model) - else - return nil + + private + + def driver_params + if !params[:driver].nil? + return params.require(:driver).permit(:name, :vin, :active, :car_make, :car_model) + else + return nil + end end + end - -end + \ No newline at end of file From 3ba23e8f2f82c1e1f875fd5758998b9115af54b4 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:15:47 -0700 Subject: [PATCH 059/118] typo --- app/controllers/drivers_controller.rb | 93 +++++++++++++-------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index ad8592343..24d33f3a3 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -27,59 +27,58 @@ def create else render :new return - endt end + end + + + def edit + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) - - def edit - driver_id = params[:id].to_i - @driver = Driver.find_by(id: driver_id) - - if @driver.nil? - redirect_to drivers_path - return - end + if @driver.nil? + redirect_to drivers_path + return end + end + + def update + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) - def update - driver_id = params[:id].to_i - @driver = Driver.find_by(id: driver_id) - - if @driver.nil? - head :not_found - return - elsif @driver.update(driver_params) - redirect_to driver_path(@driver.id) - return - else - render :edit - return - end + if @driver.nil? + head :not_found + return + elsif @driver.update(driver_params) + redirect_to driver_path(@driver.id) + return + else + render :edit + return end + end + + def destroy + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) - def destroy - driver_id = params[:id].to_i - @driver = Driver.find_by(id: driver_id) - - if @driver.nil? - head :not_found - return - else - @driver.destroy - redirect_to drivers_path - return - end + if @driver.nil? + head :not_found + return + else + @driver.destroy + redirect_to drivers_path + return end - - private - - def driver_params - if !params[:driver].nil? - return params.require(:driver).permit(:name, :vin, :active, :car_make, :car_model) - else - return nil - end + end + + private + + def driver_params + if !params[:driver].nil? + return params.require(:driver).permit(:name, :vin, :active, :car_make, :car_model) + else + return nil end - end - \ No newline at end of file + +end From d3593765b081e65017b9fd71d66934a165974142 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 16:28:48 -0700 Subject: [PATCH 060/118] added toggle for changing driver.active boolean --- app/controllers/drivers_controller.rb | 19 +++++++++++++ app/views/drivers/show.html.erb | 4 +++ config/routes.rb | 1 + test/controllers/drivers_controller_test.rb | 31 +++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 24d33f3a3..50b92dbb8 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -71,6 +71,25 @@ def destroy end end + def toggle_active + driver_id = params[:id].to_i + @driver = Driver.find_by(id: driver_id) + + if @driver.active + @driver.active = false + else + @driver.active = true + end + + if @driver.save + redirect_back(fallback_location: driver_path(driver_id)) + return + else + redirect_back(fallback_location: driver_path(driver_id), flash: { error: "Could not save completion date" }) + return + end + end + private def driver_params diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index d9291972b..c534cb5f6 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -22,6 +22,10 @@ <% end %>

+
+ <%= link_to "Toggle Status", toggle_active_path(@driver.id), method: :patch %> +
+ <%# total earnings %>
Total Earnings: <%= number_to_currency(@driver.driver_earnings / 100.0) %>
diff --git a/config/routes.rb b/config/routes.rb index 7145f5a43..9accc6425 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ root 'homepages#index' # get '/home', to: 'homepages#index', as "home" + patch '/drivers/:id/toggle', to: 'drivers#toggle_active', as: 'toggle_active' resources :drivers # get '/passengers/:id/request', to: 'passengers#request_trip', as: 'request_trip' diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 91ca6afea..abd63eda1 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -245,4 +245,35 @@ must_respond_with :not_found end end + + describe "toggle active" do + it "makes active true if it is false" do + # arrange + driver = Driver.create(name: "Micky", vin: "777", active: false) + driver_id = driver.id + + # act + patch toggle_active_path(driver_id) + + updated_driver = Driver.find_by(id: driver_id) + + # assert + expect(updated_driver.active).must_equal true + end + + it "makes active false if it is true" do + # arrange + driver = Driver.create(name: "Micky", vin: "777", active: true) + driver_id = driver.id + + # act + patch toggle_active_path(driver_id) + + updated_driver = Driver.find_by(id: driver_id) + + # assert + expect(updated_driver.active).must_equal false + end + end + end From 450739fad0879f385ef2e4bc254d2f45cd5b03f8 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:32:14 -0700 Subject: [PATCH 061/118] added nullify thing to deleted drivers/riders --- app/models/driver.rb | 2 +- app/models/passenger.rb | 2 +- app/views/drivers/show.html.erb | 6 +++++- app/views/passengers/show.html.erb | 8 ++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index cc853b799..976993dd5 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,5 +1,5 @@ class Driver < ApplicationRecord - has_many :trips + has_many :trips, dependent: :nullify # validations diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 64ba086ef..b56ceb5fe 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,5 +1,5 @@ class Passenger < ApplicationRecord - has_many :trips + has_many :trips, dependent: :nullify validates :phone_num, presence: true validates :name, presence: true diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index d9291972b..b08bf2d31 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -57,7 +57,11 @@ <%= trip.driver.name %>
- <%= link_to trip.passenger.name, passenger_path(trip.passenger.id) %> + <% if trip.passenger != nil %> + <%= link_to trip.passenger.name, passenger_path(trip.passenger.id) %> + <% else %> + deleted + <% end %> <%= number_to_currency(trip.cost / 100.0) %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 10aea8b41..2f3b3b969 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -48,10 +48,14 @@ <%= trip.date %> - <%= link_to trip.driver.name, driver_path(trip.driver.id) %> + <% if trip.driver != nil %> + <%= link_to trip.driver.name, driver_path(trip.driver.id) %> + <% else %> + deleted + <% end %> - <%= trip.passenger.name %> + <%= link_to trip.passenger.name, trip_path(trip.id)%> <%= number_to_currency(trip.cost / 100.0) %> From fa383cc90b8f5490510a535a136d8e06636109e0 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:37:21 -0700 Subject: [PATCH 062/118] added trip destroy and tests --- app/controllers/trips_controller.rb | 10 +++++++++ test/controllers/trips_controller_test.rb | 26 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index c13fcaea9..e072b3e3b 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -31,7 +31,17 @@ def update end def destroy + trip_id = params[:id].to_i + @trip = Trip.find_by(id: trip_id) + if @trip.nil? + head :not_found + return + else + @trip.destroy + redirect_to root_path + return + end end private diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index cef890344..97073489c 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -86,6 +86,30 @@ end describe "destroy" do - # Your tests go here + it "destroys the trip instance in db when trip exists, then redirects" do + driver = Driver.create(name: "Bernardo Prosacco", vin: "WBWSS52P9NEYLVDE9") + passenger = Passenger.create(name: "test person", phone_num: "1234567") + + test_trip = Trip.create(driver_id: driver.id, passenger_id: passenger.id, cost: nil, date: DateTime.now, rating: nil) + + expect { + delete trip_path(test_trip.id) + }.must_change "Trip.count", -1 + + new_trip = Trip.find_by(id: test_trip.id) + expect(new_trip).must_be_nil + + must_redirect_to root_path + end + + it "does not change the db when the trip does not exist, then responds with " do + invalid_id = -1 + + expect { + delete trip_path(invalid_id) + }.wont_change "Trip.count" + + must_respond_with :not_found + end end end From d35efa495c5e8c9d7af3ca31ec54bc5d753c3bfc Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 8 Oct 2019 16:40:20 -0700 Subject: [PATCH 063/118] edited passenger view --- app/views/passengers/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 2f3b3b969..34d776e0f 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -55,7 +55,7 @@ <% end %> - <%= link_to trip.passenger.name, trip_path(trip.id)%> + <%= @passenger.name %> <%= number_to_currency(trip.cost / 100.0) %> From 4087011724561ce2c4f368d0974ff4190226ef73 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Tue, 8 Oct 2019 16:41:36 -0700 Subject: [PATCH 064/118] made header a link to root page --- app/views/layouts/application.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 433c28c6d..3e977d39e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,7 +11,7 @@
Driver Name VINStatus
<%= link_to driver.name, driver_path(driver.id) %> <%= driver.vin %> AvailableUnavailable
+
+ @@ -11,6 +12,7 @@ + <% object.trips.each do |trip| %>
ID DatePrice Rating
From a4a3b53b404f463df27eb64669494a653b8ac1c6 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Thu, 10 Oct 2019 22:32:14 -0700 Subject: [PATCH 101/118] add pagination to driver and passenger index --- app/assets/stylesheets/application.css | 21 +++++++++++++ app/views/drivers/index.html.erb | 12 ++++++++ app/views/passengers/index.html.erb | 41 ++++++++++++++++++-------- app/views/shared/_tablenav.html.erb | 39 ++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 app/views/shared/_tablenav.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 811ff5065..4a4955f2c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -107,3 +107,24 @@ nav > * { text-align: left; width: 15rem; } + +/* pagination */ + +.pagination-container { + margin-bottom: 1rem; +} + +.pagination { + border: 1px solid pink; + background-color: #FFACEA; + padding: 0.5rem; +} + +.pagination a { + color: #820062 +} + +.disabled_link { + background-color: #FFDDF6; + color: #FF7DDE; +} \ No newline at end of file diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index b07ebe0b0..a063906e4 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,6 +1,14 @@

Drivers

+ <% @DEFAULT_PAGE_SIZE = 10 %> + <%# if there is no page number in params, use zero %> + <% page_num = (request.params["page"].nil? ? 0 : request.params["page"].to_i) %> + <%# if the page size is unspecified in the params, use the default %> + <% page_size = request.params["page_size"].nil? ? @DEFAULT_PAGE_SIZE : request.params["page_size"].to_i %> + + <%= render partial: "shared/tablenav", locals: { list_path: method(:drivers_path), page_size: page_size, page_num: page_num, count: @drivers.count } %> + @@ -9,11 +17,15 @@ + <% position = 0 %> <% @drivers.each do |driver| %> + <% if position >= (page_num * page_size) && position < ((page_num+1) * page_size) %> + <% end %> + <% position += 1 %> <% end %>
<%= link_to driver.name, driver_path(driver.id) %> <%= driver.vin %>
diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 7c4d113d9..69a926ead 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,20 +1,35 @@

Passengers

- - - - - - - - - <% @passengers.each do |passenger| %> + <% @DEFAULT_PAGE_SIZE = 10 %> + <%# if there is no page number in params, use zero %> + <% page_num = (request.params["page"].nil? ? 0 : request.params["page"].to_i) %> + <%# if the page size is unspecified in the params, use the default %> + <% page_size = request.params["page_size"].nil? ? @DEFAULT_PAGE_SIZE : request.params["page_size"].to_i %> + + <%= render partial: "shared/tablenav", locals: { list_path: method(:passengers_path), page_size: page_size, page_num: page_num, count: @passengers.count } %> + +
Passenger NamePhone Number
+ - - + + - <% end %> - + + + + + <% position = 0 %> + <% @passengers.each do |passenger| %> + <% if position >= (page_num * page_size) && position < ((page_num+1) * page_size) %> + + + + + <% end %> + <% position += 1 %> + <% end %> + +
<%= link_to passenger.name, passenger_path(passenger.id) %> <%= passenger.phone_num %> Passenger NamePhone Number
<%= link_to passenger.name, passenger_path(passenger.id) %> <%= passenger.phone_num %>
\ No newline at end of file diff --git a/app/views/shared/_tablenav.html.erb b/app/views/shared/_tablenav.html.erb new file mode 100644 index 000000000..d90545be4 --- /dev/null +++ b/app/views/shared/_tablenav.html.erb @@ -0,0 +1,39 @@ +
+ <%# display previous page links if there is a previous page %> + <% if page_num > 0 %> + <%= link_to "<< First", list_path.call(page: 0) %> + <%= link_to "< Prev", list_path.call(page: page_num - 1) %> + <% else %> + << First + < Prev + <% end %> + + <%# find the number of the last page %> + <% last_page = (count / page_size).ceil %> + + <%# display direct links to adjacent page numbers %> + <% @DISPLAY_PAGE_COUNT = 2 %> + <%# calculates @DISPLAY_PAGE_COUNT number of pages adjacent to current page %> + <%# first page displayed can't be less than zero %> + <% first_page_disp = [0, page_num - @DISPLAY_PAGE_COUNT].max %> + <%# last page displayed can't be greater than number of total pages %> + <% last_page_disp = [(page_num + @DISPLAY_PAGE_COUNT), last_page].min %> + <%# for each page in the range, %> + <%# make a link unless it's the current page %> + <% for p in first_page_disp..last_page_disp %> + <% if p != page_num %> + <%= link_to p+1, list_path.call(page: p) %> + <% else %> + <%= p+1 %> + <% end %> + <% end %> + + <%# display next page links if there is a next page %> + <% if page_num < last_page %> + <%= link_to "Next >", list_path.call(page: page_num + 1) %> + <%= link_to "Last >>", list_path.call(page: last_page) %> + <% else %> + Next > + Last >> + <% end %> +
From 6acab2fdb8315ff869ba01df9cf66c4ae318ff90 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Thu, 10 Oct 2019 22:37:41 -0700 Subject: [PATCH 102/118] removed sass variable from application.css --- app/assets/stylesheets/application.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d0db90de4..6366a77b5 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -164,8 +164,9 @@ nav > * { .unavailable { color: red; } + .unavailable:before { - content: "🚫 " + content: "🚫 "; } .errors { @@ -202,14 +203,15 @@ nav > * { float: left; color: white; font-size: 1.2em; - display: inline-block; + /* css ignores this b/c of the float property */ + /* display: inline-block; */ text-align: center; border-radius: 15px; height: 3rem; } .submit-button:hover { - background-color: rgb(196, 4, 148) + background-color: rgb(196, 4, 148); } .submit-button:active { @@ -226,8 +228,6 @@ main section { margin-bottom: 4rem; } -$pink: rgb(255,0,191); - .details { width: 100%; display: flex; From 7ad1b0e4d1d56ad6ed695d3465d3ff05cd62e33a Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Thu, 10 Oct 2019 22:46:30 -0700 Subject: [PATCH 103/118] positioned dropdown menus and made them more distinct against background --- app/assets/stylesheets/application.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 6366a77b5..a231dac0e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -48,9 +48,10 @@ nav > * { .dropdown-content { display: none; position: absolute; - background: rgb(255,0,191); + background: #FF5CD6; margin-top: 1rem; + margin-left: -1rem; } .dropdown-content > div { From 3c95cfd6da1c82edc6a1f41c0641c18bd69ceef7 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 08:09:27 -0700 Subject: [PATCH 104/118] added inline rating functionality to trip show page --- app/views/shared/_triptable.html.erb | 2 +- app/views/trips/show.html.erb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/views/shared/_triptable.html.erb b/app/views/shared/_triptable.html.erb index d86c5d40c..f70caf45b 100644 --- a/app/views/shared/_triptable.html.erb +++ b/app/views/shared/_triptable.html.erb @@ -3,7 +3,7 @@ <%# how many rides the driver has given %>
Total Trips: <%= object.trips.count %>
- + diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index e37546cc0..388ed161d 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -4,7 +4,18 @@ Date: <%= @trip.date %>
Driver: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>
Passenger: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>
- Rating: <%= @trip.rating %>
+ <% if @trip.rating %> + Rating: <%= @trip.rating %>
+ <% else %> +
+ <%= form_with model: @trip do |f| %> + <%= f.label :rating %>: + <%= f.select :rating, [5, 4, 3, 2, 1] %> + + <%= f.submit "Save Rating", class: "submit-rating" %> + <% end %> +
+ <% end %> Cost: <%= number_to_currency(@trip.cost / 100.00) %>

From a46f07b8b04f42a8113de5bd1c4a5cff52697d7a Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 08:22:10 -0700 Subject: [PATCH 105/118] fixed trip show page to display 'deleted' for deleted drivers/passengers --- app/views/trips/show.html.erb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 388ed161d..b15cfa2d7 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -2,8 +2,27 @@

Trip #<%= @trip.id %>

Date: <%= @trip.date %>
- Driver: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>
- Passenger: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>
+ +

+ Driver: + <% if @trip.driver %> + <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %> + <% else %> + deleted + <% end%> +
+
+ +
+ Passenger: + <% if @trip.passenger %> + <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %> + <% else %> + deleted + <% end%> +
+
+ <% if @trip.rating %> Rating: <%= @trip.rating %>
<% else %> From 8761979da29826fb41375b84f2552fc55c12ea5c Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 08:52:36 -0700 Subject: [PATCH 106/118] added photos to each driver and passenger, and tested --- app/models/driver.rb | 7 +++++++ app/models/passenger.rb | 7 +++++++ app/views/drivers/show.html.erb | 2 ++ app/views/passengers/show.html.erb | 2 ++ test/models/driver_test.rb | 15 +++++++++++++++ test/models/passenger_test.rb | 14 ++++++++++++++ 6 files changed, 47 insertions(+) diff --git a/app/models/driver.rb b/app/models/driver.rb index 2004ad7c8..9b2093f31 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -70,6 +70,13 @@ def go_offline end end + def avatar_image + driver_id = self.id + avatar_link = "https://api.adorable.io/avatars/200/" << driver_id.to_s << ".png" + + return avatar_link + end + # select active driver, set status to inactive def self.get_driver available_driver = Driver.find_by(active: true) diff --git a/app/models/passenger.rb b/app/models/passenger.rb index b56ceb5fe..b2d0cf276 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -11,5 +11,12 @@ def total_charged return total end + def avatar_image + passenger_id = self.id + avatar_link = "https://api.adorable.io/avatars/200/" << passenger_id.to_s << ".png" + + return avatar_link + end + end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 2ba14c8f9..c0aeb5e2e 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -2,6 +2,8 @@ <%# name %>

<%= @driver.name %>

+ <%= image_tag @driver.avatar_image %> +
<%# car details %>
diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index ca6b1f547..9579835e9 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -3,6 +3,8 @@ <%# name %>

<%= @passenger.name %>

+ <%= image_tag @passenger.avatar_image %> + <% if flash[:notice] %>
<%= flash[:notice] %>
<% end %> diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 30402346e..f84d4e955 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -266,5 +266,20 @@ expect(selected_driver).must_be_nil end end + + describe "avatar image" do + it "must return an image link" do + driver = Driver.create(name: "M. Random", vin: "88888888", active: false) + + avatar_url = driver.avatar_image + + url_beginning = !!(avatar_url =~ /\Ahttps:\/\//) + url_ending = !!(avatar_url =~ /\.png\Z/) + + expect(url_beginning).must_equal true + expect(url_ending).must_equal true + end + end + end end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 6330f91d0..0bf3c26bd 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -75,5 +75,19 @@ end end + describe "avatar image" do + it "must return an image link" do + passenger = Passenger.create(name: "M. Random", phone_num: "111.555.111") + + avatar_url = passenger.avatar_image + + url_beginning = !!(avatar_url =~ /\Ahttps:\/\//) + url_ending = !!(avatar_url =~ /\.png\Z/) + + expect(url_beginning).must_equal true + expect(url_ending).must_equal true + end + end + end From 2aec39078bd1dee2008f0a266f582db64c18dd8e Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 09:01:19 -0700 Subject: [PATCH 107/118] formatted driver/passenger show pages into two columns --- app/assets/stylesheets/application.css | 5 ++ app/views/drivers/show.html.erb | 82 +++++++++++++------------- app/views/passengers/show.html.erb | 60 ++++++++++--------- 3 files changed, 78 insertions(+), 69 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a231dac0e..6148befc9 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -229,6 +229,11 @@ main section { margin-bottom: 4rem; } +.details-container { + display: grid; + grid-template-columns: 1fr 1fr; +} + .details { width: 100%; display: flex; diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index c0aeb5e2e..b745626db 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -2,52 +2,54 @@ <%# name %>

<%= @driver.name %>

- <%= image_tag @driver.avatar_image %> - -
- <%# car details %> -
- <%# vin %> -
Vin:
-
<%= @driver.vin %>
- <%# car make %> - <% if !(@driver.car_make.empty?) %> -
Make:
-
<%= @driver.car_make %>
- <% end %> - <%# car model %> - <% if !(@driver.car_model.empty?) %> -
Model:
-
<%= @driver.car_model %>
- <% end %> -
- - <%# average rating %> -
Average Rating: <%= @driver.average_rating.nil? ? "N/A" : @driver.average_rating %>
- - <%# driver status %> -
-
- Status: - <% if @driver.active %> - Available - <% else %> - Unavailable +
+ <%= image_tag @driver.avatar_image %> + +
+ <%# car details %> +
+ <%# vin %> +
Vin:
+
<%= @driver.vin %>
+ <%# car make %> + <% if !(@driver.car_make.empty?) %> +
Make:
+
<%= @driver.car_make %>
+ <% end %> + <%# car model %> + <% if !(@driver.car_model.empty?) %> +
Model:
+
<%= @driver.car_model %>
<% end %>
-
- <%= link_to "Toggle Status", toggle_active_path(@driver.id), method: :patch %> + <%# average rating %> +
Average Rating: <%= @driver.average_rating.nil? ? "N/A" : @driver.average_rating %>
+ + <%# driver status %> +
+
+ Status: + <% if @driver.active %> + Available + <% else %> + Unavailable + <% end %> +
+ +
+ <%= link_to "Toggle Status", toggle_active_path(@driver.id), method: :patch %> +
-
- <%# total earnings %> -
Total Earnings: <%= number_to_currency(@driver.driver_earnings / 100.0) %>
+ <%# total earnings %> +
Total Earnings: <%= number_to_currency(@driver.driver_earnings / 100.0) %>
- <%# edit/delete options %> -
-
<%= link_to "Edit", edit_driver_path(@driver.id) %>
-
<%= link_to "Delete", driver_path(@driver.id), method: :delete %>
+ <%# edit/delete options %> +
+
<%= link_to "Edit", edit_driver_path(@driver.id) %>
+
<%= link_to "Delete", driver_path(@driver.id), method: :delete %>
+
diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 9579835e9..f501e10b2 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -3,35 +3,37 @@ <%# name %>

<%= @passenger.name %>

- <%= image_tag @passenger.avatar_image %> - - <% if flash[:notice] %> -
<%= flash[:notice] %>
- <% end %> - - <% if @passenger.errors.any? %> -
    - <% @passenger.errors.each do |column, message| %> -
  • - <%= column.capitalize %> <%= message %> -
  • - <% end %> -
- <% end %> - -
-

- <%# Name: <%= @passenger.name %> <%#
%> - Phone Number: <%= @passenger.phone_num %> -

- -
Total Charged: <%= number_to_currency(@passenger.total_charged / 100.0) %>
- -
<%= link_to "Request Trip", passenger_trips_path(@passenger.id), method: :post %>
- -
-
<%= link_to "Edit", edit_passenger_path(@passenger.id) %>
-
<%= link_to "Delete", passenger_path(@passenger.id), method: :delete %>
+ <% if flash[:notice] %> +
<%= flash[:notice] %>
+ <% end %> + + <% if @passenger.errors.any? %> +
    + <% @passenger.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+ <% end %> + +
+ <%= image_tag @passenger.avatar_image %> + +
+

+ <%# Name: <%= @passenger.name %> <%#
%> + Phone Number: <%= @passenger.phone_num %> +

+ +
Total Charged: <%= number_to_currency(@passenger.total_charged / 100.0) %>
+ +
<%= link_to "Request Trip", passenger_trips_path(@passenger.id), method: :post %>
+ +
+
<%= link_to "Edit", edit_passenger_path(@passenger.id) %>
+
<%= link_to "Delete", passenger_path(@passenger.id), method: :delete %>
+
From 96228d304ad140775fb57e5aa4e22be882f48d5f Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 09:54:32 -0700 Subject: [PATCH 108/118] modified css for driver/passenger show to arrange image and name --- app/assets/stylesheets/application.css | 12 ++++++++++++ app/views/drivers/show.html.erb | 7 +++++-- app/views/passengers/show.html.erb | 7 +++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 6148befc9..9cb6dff86 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -230,8 +230,20 @@ main section { } .details-container { + margin-top: 2rem; + display: grid; grid-template-columns: 1fr 1fr; + align-items: center; +} + +.details-container > *:first-child { + text-align: center; + justify-self: center; +} + +.details-container > *:first-child > img { + border-radius: 2rem; } .details { diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index b745626db..7f7fdd3fd 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,9 +1,12 @@
<%# name %> -

<%= @driver.name %>

+
- <%= image_tag @driver.avatar_image %> +
+

<%= @driver.name %>

+ <%= image_tag @driver.avatar_image %> +
<%# car details %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index f501e10b2..0b108cbe2 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,7 +1,7 @@
<%#

Passenger

%> <%# name %> -

<%= @passenger.name %>

+ <% if flash[:notice] %>
<%= flash[:notice] %>
@@ -18,7 +18,10 @@ <% end %>
- <%= image_tag @passenger.avatar_image %> +
+

<%= @passenger.name %>

+ <%= image_tag @passenger.avatar_image %> +

From aba4aac4a0de3f1564b59e84fd03fabdbfbea71b Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 11 Oct 2019 09:57:15 -0700 Subject: [PATCH 109/118] table size --- app/assets/stylesheets/application.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 6148befc9..d10fd839a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -95,7 +95,7 @@ nav > * { display: block; width: 100%; overflow: auto; - height: 35rem; + height: auto; } .table thead tr { From b3391c55563b8903d06f016d6ebc8433e990cf07 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 11:12:25 -0700 Subject: [PATCH 110/118] changed height of driver/passenger list to get rid of empty space at the bottom --- app/assets/stylesheets/application.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9cb6dff86..2f242ffcd 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -95,7 +95,7 @@ nav > * { display: block; width: 100%; overflow: auto; - height: 35rem; + height: max-content; } .table thead tr { From a0daa253caf24e0d08a05e7331f1f10589882cd2 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 11:29:20 -0700 Subject: [PATCH 111/118] centered pagination and titles --- app/assets/stylesheets/application.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b1c59acf5..a6f54db3f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -40,6 +40,10 @@ nav > * { color: white; } +section h2 { + text-align: center; +} + /* css dropdown on hover: https://www.w3schools.com/css/css_dropdowns.asp */ .dropdown-container { position: relative; @@ -297,6 +301,7 @@ main section { .pagination-container { margin-bottom: 1rem; + text-align: center; } .pagination { From e039b92f545e13a50021677635d7806f9234cab9 Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 11 Oct 2019 11:51:38 -0700 Subject: [PATCH 112/118] button stylings --- app/assets/stylesheets/application.css | 50 +++++++++++++++++++++----- app/views/trips/show.html.erb | 4 +-- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a6f54db3f..a6e42ad67 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -21,6 +21,11 @@ a { text-decoration: none; + color: black; +} + +a:hover { + color: #A3007A; } /* nav */ @@ -190,32 +195,30 @@ section h2 { margin: 1em; } -.driver-form label{ +.driver-form label, .passenger-form label{ display: block; width: 100%; padding: .2em; } -.driver-form input{ +.driver-form input, .passenger-form input{ display: block; width: 15rem; padding: .5em; } -.submit-button { +.submit-button{ background-color: rgb(255,0,191); margin-top: .7em; - float: left; color: white; font-size: 1.2em; - /* css ignores this b/c of the float property */ - /* display: inline-block; */ + display: block; text-align: center; border-radius: 15px; height: 3rem; } -.submit-button:hover { +.submit-button:hover , .trip-options div:hover{ background-color: rgb(196, 4, 148); } @@ -264,7 +267,7 @@ main section { margin: 0.5rem; } -.modify-options { +.modify-options, .trip-options { width: auto; display: flex; @@ -276,6 +279,21 @@ main section { margin: 0 4rem 0 1rem; } +.trip-options div{ + background-color: rgb(255,0,191); + color: white; + font-size: 1.2em; + display: block; + text-align: center; + border-radius: 15px; + padding:.7em; + margin: 1rem; +} + +.trip-options a { + color: white; +} + .car-details { display: grid; grid-template-columns: 1fr 1fr; @@ -300,7 +318,8 @@ main section { /* pagination */ .pagination-container { - margin-bottom: 1rem; + margin-top: 1.5rem; + margin-bottom: 1.5rem; text-align: center; } @@ -308,12 +327,25 @@ main section { border: 1px solid pink; background-color: #FFACEA; padding: 0.5rem; + border-radius: .5em; } .pagination a { color: #820062 } +.pagination:hover { + background-color: #820062; +} + +.pagination:hover a { + color: #FFBDEE; +} + +.pagination a:active { + border-radius: 5px; +} + .disabled_link { background-color: #FFDDF6; color: #FF7DDE; diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index b15cfa2d7..db7157191 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -1,6 +1,6 @@

Trip #<%= @trip.id %>

-

+

Date: <%= @trip.date %>
@@ -39,7 +39,7 @@

-
+
<%= link_to "Rate Trip", rate_path %>
<%= link_to "Edit", edit_trip_path(@trip.id) %>
<%= link_to "Delete", trip_path(@trip.id), method: :delete %>
From 2938b4d5ad78bd26f1667c07a4930dc8fbac024b Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 13:14:11 -0700 Subject: [PATCH 113/118] centered trip table header --- app/assets/stylesheets/application.css | 16 ++++++++++++++++ app/views/shared/_triptable.html.erb | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a6e42ad67..958e878e9 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -132,6 +132,22 @@ section h2 { } /* triptable */ +.triptable-container h3 { + text-align: center; +} + +.triptable-container h3 { + text-align: center; +} + +.triptable-container > div { + background-color: #FFACEA; + border-radius: 15px; + width: max-content; + padding: 1rem; + margin: auto; +} + .trip-table{ margin-top: 1.5rem; margin-left:auto; diff --git a/app/views/shared/_triptable.html.erb b/app/views/shared/_triptable.html.erb index f70caf45b..869786690 100644 --- a/app/views/shared/_triptable.html.erb +++ b/app/views/shared/_triptable.html.erb @@ -1,4 +1,4 @@ -
+

Trips

<%# how many rides the driver has given %>
Total Trips: <%= object.trips.count %>
From 5f13b2a5ef5d1e109b1c8da2a1dedd154a28110b Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 11 Oct 2019 13:34:06 -0700 Subject: [PATCH 114/118] added flash now --- app/controllers/trips_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 6f081e2e4..4ea1f0455 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -71,18 +71,19 @@ def update end if params[:trip][:driver_name].blank? || params[:trip][:passenger_name].blank? || params[:trip][:cost].blank? - if params[:trip][:rating] + prev = Rails.application.routes.recognize_path(request.referrer) + if prev[:action] == "rate" @trip.rating = params[:trip][:rating] if @trip.save redirect_to trip_path(@trip.id) return else - flash[:notice] = "Unable to save rating." + flash.now[:notice] = "Unable to save rating." render :rate return end else - flash[:notice] = "You must enter a value for all fields." + flash.now[:notice] = "You must enter a value for all fields." render :edit return end @@ -92,13 +93,13 @@ def update passenger = Passenger.find_by(name: params[:trip][:passenger_name]) if driver.nil? - flash[:notice] = "This driver is not in our system." + flash.now[:notice] = "This driver is not in our system." render :edit return end if passenger.nil? - flash[:notice] = "This passenger is not in our system." + flash.now[:notice] = "This passenger is not in our system." render :edit return end From e7c10f2b2a505b68d202f7bbbeddeea0850b04d4 Mon Sep 17 00:00:00 2001 From: Sabrina Lowney Date: Fri, 11 Oct 2019 13:48:07 -0700 Subject: [PATCH 115/118] fixed inline trip rating bug --- app/controllers/trips_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 4ea1f0455..99770e46d 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -72,7 +72,7 @@ def update if params[:trip][:driver_name].blank? || params[:trip][:passenger_name].blank? || params[:trip][:cost].blank? prev = Rails.application.routes.recognize_path(request.referrer) - if prev[:action] == "rate" + if prev[:action] == "rate" || prev[:action] == "show" @trip.rating = params[:trip][:rating] if @trip.save redirect_to trip_path(@trip.id) From b1052ae8696017c72b577c86a01de53b9a8dc531 Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 11 Oct 2019 14:16:45 -0700 Subject: [PATCH 116/118] fixed render/redirect bug ty becca --- app/controllers/trips_controller.rb | 184 ++++++++++++++-------------- app/views/trips/edit.html.erb | 1 - 2 files changed, 92 insertions(+), 93 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 99770e46d..dab5c8b09 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -35,114 +35,114 @@ def create cost = rand(1000..9999).to_i data_hash = { - date: date, - driver_id: driver.id, - passenger_id: params[:passenger_id], - rating: nil, - cost: cost, - } - - @trip = Trip.new(data_hash) - - if @trip.save - redirect_to passenger_path(@trip.passenger_id) - return - else - redirect_to root_path - return - end + date: date, + driver_id: driver.id, + passenger_id: params[:passenger_id], + rating: nil, + cost: cost, + } + + @trip = Trip.new(data_hash) + + if @trip.save + redirect_to passenger_path(@trip.passenger_id) + return + else + redirect_to root_path + return end +end + +def edit + @trip = Trip.find_by(id: params[:id]) - def edit - @trip = Trip.find_by(id: params[:id]) - - if @trip.nil? - redirect_to root_path - return - end + if @trip.nil? + redirect_to root_path + return + end +end + +def update + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + head :not_found + return end - def update - @trip = Trip.find_by(id: params[:id]) - - if @trip.nil? - head :not_found - return - end - - if params[:trip][:driver_name].blank? || params[:trip][:passenger_name].blank? || params[:trip][:cost].blank? - prev = Rails.application.routes.recognize_path(request.referrer) - if prev[:action] == "rate" || prev[:action] == "show" - @trip.rating = params[:trip][:rating] - if @trip.save - redirect_to trip_path(@trip.id) - return - else - flash.now[:notice] = "Unable to save rating." - render :rate - return - end + if params[:trip][:driver_name].blank? || params[:trip][:passenger_name].blank? || params[:trip][:cost].blank? + prev = Rails.application.routes.recognize_path(request.referrer) + if (prev[:action] == "rate" || prev[:action] == "show") && params[:action] != "edit" && prev[:action] != "edit" + @trip.rating = params[:trip][:rating] + if @trip.save + redirect_to trip_path(@trip.id) + return else - flash.now[:notice] = "You must enter a value for all fields." - render :edit + flash[:notice] = "Unable to save rating." + redirect_to rate_path(params[:id]) return end - end - - driver = Driver.find_by(name: params[:trip][:driver_name]) - passenger = Passenger.find_by(name: params[:trip][:passenger_name]) - - if driver.nil? - flash.now[:notice] = "This driver is not in our system." - render :edit - return - end - - if passenger.nil? - flash.now[:notice] = "This passenger is not in our system." - render :edit - return - end - - @trip.driver_id = driver.id - @trip.passenger_id = passenger.id - - if @trip.update(trip_params) - redirect_to trip_path(@trip.id) - return else - render :edit + flash[:notice] = "You must enter a value for all fields." + redirect_to edit_trip_path(params[:id]) return end - end + end - def destroy - trip_id = params[:id].to_i - @trip = Trip.find_by(id: trip_id) - - if @trip.nil? - head :not_found - return - else - @trip.destroy - redirect_to root_path - return - end + driver = Driver.find_by(name: params[:trip][:driver_name]) + passenger = Passenger.find_by(name: params[:trip][:passenger_name]) + + if driver.nil? + flash[:notice] = "This driver is not in our system." + redirect_to edit_trip_path(params[:id]) + return end - def rate - @trip = Trip.find_by(id: params[:id]) - - if @trip.nil? - redirect_to root_path - return - end + if passenger.nil? + flash[:notice] = "This passenger is not in our system." + redirect_to edit_trip_path(params[:id]) + return end - private + @trip.driver_id = driver.id + @trip.passenger_id = passenger.id - def trip_params - return params.require(:trip).permit(:date, :rating, :cost, :driver_id, :passenger_id) + if @trip.update(trip_params) + redirect_to trip_path(@trip.id) + return + else + redirect_to edit_trip_path(params[:id]) + return end +end + +def destroy + trip_id = params[:id].to_i + @trip = Trip.find_by(id: trip_id) + if @trip.nil? + head :not_found + return + else + @trip.destroy + redirect_to root_path + return + end +end + +def rate + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + redirect_to root_path + return + end +end + +private + +def trip_params + return params.require(:trip).permit(:date, :rating, :cost, :driver_id, :passenger_id) +end + end diff --git a/app/views/trips/edit.html.erb b/app/views/trips/edit.html.erb index c34ed0a19..d15ef8fa5 100644 --- a/app/views/trips/edit.html.erb +++ b/app/views/trips/edit.html.erb @@ -1,6 +1,5 @@

Update this Trip

- <% if flash[:notice] %>
<%= flash[:notice] %>
<% end %> From 7baf3461b9960daa9a7739e6f0e39bf1a1c5c81d Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 11 Oct 2019 14:21:12 -0700 Subject: [PATCH 117/118] added driver and passenger model test update --- test/models/driver_test.rb | 8 +- test/models/passenger_test.rb | 148 +++++++++++++++++----------------- 2 files changed, 80 insertions(+), 76 deletions(-) diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index f84d4e955..46be94fb5 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -23,11 +23,13 @@ it "can have many trips" do # Arrange new_driver.save - driver = Driver.first + new_passenger = Passenger.create(name: "Kari", phone_num: "111-111-1211") + trip_1 = Trip.create(driver_id: new_driver.id, passenger_id: new_passenger.id, date: Date.today, rating: 5, cost: 1234) + trip_2 = Trip.create(driver_id: new_driver.id, passenger_id: new_passenger.id, date: Date.today, rating: 3, cost: 6334) # Assert - expect(driver.trips.count).must_be :>=, 0 - driver.trips.each do |trip| + expect(new_driver.trips.count).must_equal 2 + new_driver.trips.each do |trip| expect(trip).must_be_instance_of Trip end end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 0bf3c26bd..952f8bdd9 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -2,92 +2,94 @@ describe Passenger do let (:new_passenger) { - Passenger.new(name: "Kari", phone_num: "111-111-1211") - } - it "can be instantiated" do + Passenger.new(name: "Kari", phone_num: "111-111-1211") +} +it "can be instantiated" do + # Assert + expect(new_passenger.valid?).must_equal true +end + +it "will have the required fields" do + # Arrange + new_passenger.save + passenger = Passenger.first + [:name, :phone_num].each do |field| + # Assert - expect(new_passenger.valid?).must_equal true + expect(passenger).must_respond_to field end - - it "will have the required fields" do +end + +describe "relationships" do + it "can have many trips" do # Arrange new_passenger.save - passenger = Passenger.first - [:name, :phone_num].each do |field| - - # Assert - expect(passenger).must_respond_to field + new_driver = Driver.create(name: "Waldo", vin: "ALWSS52P9NEYLVDE9") + trip_1 = Trip.create(driver_id: new_driver.id, passenger_id: new_passenger.id, date: Date.today, rating: 5, cost: 1234) + trip_2 = Trip.create(driver_id: new_driver.id, passenger_id: new_passenger.id, date: Date.today, rating: 3, cost: 6334) + + + # Assert + expect(new_passenger.trips.count).must_equal 2 + new_passenger.trips.each do |trip| + expect(trip).must_be_instance_of Trip end end - - describe "relationships" do - it "can have many trips" do - # Arrange - new_passenger.save - passenger = Passenger.first - - - # Assert - expect(passenger.trips.count).must_be :>=, 0 - passenger.trips.each do |trip| - expect(trip).must_be_instance_of Trip - end - end +end + +describe "validations" do + it "must have a name" do + # Arrange + new_passenger.name = nil + + # Assert + expect(new_passenger.valid?).must_equal false + expect(new_passenger.errors.messages).must_include :name + expect(new_passenger.errors.messages[:name]).must_equal ["can't be blank"] end - describe "validations" do - it "must have a name" do - # Arrange - new_passenger.name = nil - - # Assert - expect(new_passenger.valid?).must_equal false - expect(new_passenger.errors.messages).must_include :name - expect(new_passenger.errors.messages[:name]).must_equal ["can't be blank"] - end + it "must have a phone number" do + # Arrange + new_passenger.phone_num = nil - it "must have a phone number" do - # Arrange - new_passenger.phone_num = nil - - # Assert - expect(new_passenger.valid?).must_equal false - expect(new_passenger.errors.messages).must_include :phone_num - expect(new_passenger.errors.messages[:phone_num]).must_equal ["can't be blank"] - end + # Assert + expect(new_passenger.valid?).must_equal false + expect(new_passenger.errors.messages).must_include :phone_num + expect(new_passenger.errors.messages[:phone_num]).must_equal ["can't be blank"] end - - describe "total_charged" do - it "can calculate the total charged for a passenger" do - passenger = Passenger.create(name: "test person", phone_num: "1") - driver = Driver.create(name: "test driver", vin: "111") - - trip_one = Trip.create(date: Time.now, rating: nil, cost: 1, driver_id: driver.id, passenger_id: passenger.id) - trip_two = Trip.create(date: Time.now, rating: nil, cost: 2, driver_id: driver.id, passenger_id: passenger.id) - - expect(passenger.total_charged).must_equal 3 - end +end + +describe "total_charged" do + it "can calculate the total charged for a passenger" do + passenger = Passenger.create(name: "test person", phone_num: "1") + driver = Driver.create(name: "test driver", vin: "111") - it "returns 0 if there are no trips" do - passenger = Passenger.create(name: "test person", phone_num: "1") - - expect(passenger.total_charged).must_equal 0 - end + trip_one = Trip.create(date: Time.now, rating: nil, cost: 1, driver_id: driver.id, passenger_id: passenger.id) + trip_two = Trip.create(date: Time.now, rating: nil, cost: 2, driver_id: driver.id, passenger_id: passenger.id) + + expect(passenger.total_charged).must_equal 3 end - describe "avatar image" do - it "must return an image link" do - passenger = Passenger.create(name: "M. Random", phone_num: "111.555.111") - - avatar_url = passenger.avatar_image - - url_beginning = !!(avatar_url =~ /\Ahttps:\/\//) - url_ending = !!(avatar_url =~ /\.png\Z/) - - expect(url_beginning).must_equal true - expect(url_ending).must_equal true - end + it "returns 0 if there are no trips" do + passenger = Passenger.create(name: "test person", phone_num: "1") + + expect(passenger.total_charged).must_equal 0 end - +end + +describe "avatar image" do + it "must return an image link" do + passenger = Passenger.create(name: "M. Random", phone_num: "111.555.111") + + avatar_url = passenger.avatar_image + + url_beginning = !!(avatar_url =~ /\Ahttps:\/\//) + url_ending = !!(avatar_url =~ /\.png\Z/) + + expect(url_beginning).must_equal true + expect(url_ending).must_equal true + end +end + end From ee30ebac4558e41f84a0c9e255e390957415e0ca Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 11 Oct 2019 14:42:29 -0700 Subject: [PATCH 118/118] rating to float --- app/models/driver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 9b2093f31..ecbdadd98 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -21,7 +21,7 @@ def average_rating counter += 1 end end - average = (total_rating / counter) + average = (total_rating.to_f / counter).round(2) end return average end
ID Date