From cade5a85ce5c0cb00a8e86f531bb5f94a6771b88 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Mon, 7 Oct 2019 16:02:45 -0700 Subject: [PATCH 01/46] Generated Rails files --- .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..6424e062d --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +tCipn0gQToe/cq2VmBUYlbBs+B9rCu/vjGmpWR+xCqBhMaCsrg7Wd/vpfAqCMWQDWHy8dQ6Dojqh7NuaL8smXYLhydfO2vdo4WEl23NjnLL1XAT2kXPjnuI77XpIjUmu0O2obHP18XPHDThDurHpZsPEHOVXnhqgm/4qymoEG/Wz8SF9DLXlOMwRpuwoVLsI8qWRJ/EmKFVTLpF7W3nEgjqgPgah+naR2i5xDS4Hb20+Mwl9LfYH4j28Obj0Mwgj5mWOGQzaiHh6ehAYvPQFwqsXhQR6rEjUNkTbHrTMJDQqT80zg1/iMOx+9JlBNnEzGV78gFI67FJ2gFVha9wCt0ycwRPngLwQP6v1qjvxmzOQcRdCmIig6ngpW5EToAUTvpHrQS6vFROc2B3CrgvX1dxkjKXKWirubmMZ--ZuDtEtkfvcxcDfu2--oSB69Vs0lMkW2qJS28TWjg== \ 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 e4051080f6245f832e4d4f036003b7076d639496 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Mon, 7 Oct 2019 16:27:00 -0700 Subject: [PATCH 02/46] Added index, show, new, create methods to Driver Controller --- app/assets/javascripts/drivers.js | 2 + app/assets/stylesheets/drivers.scss | 3 + app/controllers/drivers_controller.rb | 37 ++++++ app/helpers/drivers_helper.rb | 2 + config/routes.rb | 9 +- test/controllers/drivers_controller_test.rb | 139 +++++++++++++------- 6 files changed, 143 insertions(+), 49 deletions(-) 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..6cb725946 --- /dev/null +++ b/app/controllers/drivers_controller.rb @@ -0,0 +1,37 @@ +class DriversController < ApplicationController + + def index + @drivers = Driver.all + end + + def show + @driver = Driver.find_by(id: params[:id]) + + if @driver.nil? + head :not_found + return + end + end + + def new + @driver = Driver.new + end + + def create + @driver = Driver.new(driver_params) + + if @driver.save + redirect_to driver_path + else + render "new" + return + end + end + + private + + def driver_params + return params.require(:driver).permit(:name, :vin, :available) + end + +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 diff --git a/config/routes.rb b/config/routes.rb index 787824f88..ae2c91b25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,10 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + get "/drivers" , to: "drivers#index", as: :drivers + post "/drivers" , to: "drivers#create" + get "/drivers/new" , to: "drivers#new", as: :new_driver + get "/drivers/:id" , to: "drivers#show", as: :driver + patch "/drivers/:id" , to: "drivers#update" + delete "/drivers/:id" , to: "drivers#destroy" + get "/drivers/:id/edit" , to: "drivers#edit", as: :edit_driver + end diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 48aef7556..bbe04d506 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -2,65 +2,108 @@ 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 - + new_driver = Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true + # 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 - + # Act - + get drivers_path + # Assert - + must_respond_with :success + end end - + describe "show" do + before do + Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true + end + it "responds with success when showing an existing valid driver" do # Arrange # Ensure that there is a driver saved - + # Act - + get driver_path(driver.id) + # Assert - + + must_respond_with :success + must_redirect_to driver_path(driver.id) + end - + it "responds with 404 with an invalid driver id" do # Arrange # Ensure that there is an id that points to no driver - + + invalid_id = -1 + # Act - + + get driver_path(invalid_id) + # Assert - + must_respond_with :redirect + must_redirect_to drivers_path + end end - + describe "new" do it "responds with success" do + get new_driver_path + + must_respond_with :success end end - + describe "create" do it "can create a new driver with valid information accurately, and redirect" do + # Arrange # Set up the form data - + + driver_hash = { + driver: { + name: "Bob's Burgers", + vin: "FDJSKFJD84938", + available: true + } + } + # Act-Assert # Ensure that there is a change of 1 in Driver.count + + expect { + post driver_path, params: driver_hash + }.must_change "Driver.count", 1 + + new_driver = Driver.find_by(name: driver_hash[:driver][:name]) # Assert + + expect(new_driver.vin).must_equal driver_hash[:driver][:vin] + expect(new_driver.available).must_equal driver_hash[:driver][:available] + + must_respond_with :redirect + must_redirect_to driver_path(new_driver.id) # 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 @@ -70,35 +113,35 @@ # 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 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 @@ -108,42 +151,42 @@ # 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 @@ -151,25 +194,25 @@ 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 576c3bace7f1e64dcd193e27d52df4311efdc288 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Mon, 7 Oct 2019 20:38:49 -0700 Subject: [PATCH 03/46] Created index, new, show, and partial view files and generated Driver model --- app/controllers/drivers_controller.rb | 19 +++++++-------- app/models/driver.rb | 2 ++ app/views/drivers/_form.html.erb | 9 +++++++ app/views/drivers/index.html.erb | 13 +++++++++++ app/views/drivers/new.html.erb | 1 + app/views/drivers/show.html.erb | 4 ++++ db/migrate/20191007233914_create_drivers.rb | 11 +++++++++ db/schema.rb | 26 +++++++++++++++++++++ 8 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 app/models/driver.rb create mode 100644 app/views/drivers/_form.html.erb create mode 100644 app/views/drivers/index.html.erb create mode 100644 app/views/drivers/new.html.erb create mode 100644 app/views/drivers/show.html.erb create mode 100644 db/migrate/20191007233914_create_drivers.rb create mode 100644 db/schema.rb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 6cb725946..8b8bc2232 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,37 +1,36 @@ class DriversController < ApplicationController - def index @drivers = Driver.all end - + def show @driver = Driver.find_by(id: params[:id]) - + if @driver.nil? head :not_found return end end - + def new @driver = Driver.new end - + def create @driver = Driver.new(driver_params) - + if @driver.save - redirect_to driver_path + redirect_to driver_path(@driver) + return else render "new" return end end - + private - + def driver_params return params.require(:driver).permit(:name, :vin, :available) end - end diff --git a/app/models/driver.rb b/app/models/driver.rb new file mode 100644 index 000000000..1ff364562 --- /dev/null +++ b/app/models/driver.rb @@ -0,0 +1,2 @@ +class Driver < ApplicationRecord +end diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb new file mode 100644 index 000000000..a0b1d4774 --- /dev/null +++ b/app/views/drivers/_form.html.erb @@ -0,0 +1,9 @@ +<%= form_with model: @driver, class: "#{action_name}-driver" do |f| %> + <%= f.label :name %> + <%= f.text_field :name %>
+ + <%= f.label :vin %> + <%= f.text_field :vin %>
+ + <%= f.submit "#{action_name.capitalize} Driver", class: "drivers-button" %> +<% end %> \ No newline at end of file diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb new file mode 100644 index 000000000..da8fc73a6 --- /dev/null +++ b/app/views/drivers/index.html.erb @@ -0,0 +1,13 @@ +

List of Drivers

+ +<%= link_to "Create a new Driver", new_driver_path %> + +
    + <% @drivers.each do |driver| %> +
  • + <%= link_to driver.name, driver_path(driver) %>
    + <%= driver.vin %>
    + <%= driver.available %> +
  • + <% end %> +
\ No newline at end of file diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb new file mode 100644 index 000000000..e9254372d --- /dev/null +++ b/app/views/drivers/new.html.erb @@ -0,0 +1 @@ +<%= render :partial => "drivers/form", locals: { action_name: "create" } %> \ No newline at end of file diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb new file mode 100644 index 000000000..853998e54 --- /dev/null +++ b/app/views/drivers/show.html.erb @@ -0,0 +1,4 @@ +

Driver name: <%= @driver.name %>

+

VIN: <%= @driver.vin %>

+

Status: <%= @driver.available %>

+ diff --git a/db/migrate/20191007233914_create_drivers.rb b/db/migrate/20191007233914_create_drivers.rb new file mode 100644 index 000000000..54628a037 --- /dev/null +++ b/db/migrate/20191007233914_create_drivers.rb @@ -0,0 +1,11 @@ +class CreateDrivers < ActiveRecord::Migration[5.2] + def change + create_table :drivers do |t| + t.string :name + t.string :vin + t.boolean :available + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..753f27a54 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# 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_233914) 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.boolean "available" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From 5cf435fb23b450dd6d900742eb6643486a1c68a8 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 11:01:21 -0700 Subject: [PATCH 04/46] Added make and model columns to driver model --- app/controllers/drivers_controller.rb | 1 + config/routes.rb | 14 +++++++------- .../20191008175947_add_model_and_make_columns.rb | 6 ++++++ db/schema.rb | 4 +++- 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20191008175947_add_model_and_make_columns.rb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 8b8bc2232..2e066b72b 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -18,6 +18,7 @@ def new def create @driver = Driver.new(driver_params) + @driver.available = true if @driver.save redirect_to driver_path(@driver) diff --git a/config/routes.rb b/config/routes.rb index ae2c91b25..3e50ec550 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,10 @@ Rails.application.routes.draw do - get "/drivers" , to: "drivers#index", as: :drivers - post "/drivers" , to: "drivers#create" - get "/drivers/new" , to: "drivers#new", as: :new_driver - get "/drivers/:id" , to: "drivers#show", as: :driver - patch "/drivers/:id" , to: "drivers#update" - delete "/drivers/:id" , to: "drivers#destroy" - get "/drivers/:id/edit" , to: "drivers#edit", as: :edit_driver + get "/drivers", to: "drivers#index", as: :drivers + post "/drivers", to: "drivers#create" + get "/drivers/new", to: "drivers#new", as: :new_driver + get "/drivers/:id", to: "drivers#show", as: :driver + patch "/drivers/:id", to: "drivers#update" + delete "/drivers/:id", to: "drivers#destroy" + get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver end diff --git a/db/migrate/20191008175947_add_model_and_make_columns.rb b/db/migrate/20191008175947_add_model_and_make_columns.rb new file mode 100644 index 000000000..ccf8bee27 --- /dev/null +++ b/db/migrate/20191008175947_add_model_and_make_columns.rb @@ -0,0 +1,6 @@ +class AddModelAndMakeColumns < ActiveRecord::Migration[5.2] + def change + add_column :drivers, :make, :string + add_column :drivers, :model, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 753f27a54..644354e7e 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_233914) do +ActiveRecord::Schema.define(version: 2019_10_08_175947) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,6 +21,8 @@ t.boolean "available" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "make" + t.string "model" end end From 1ee17f6013edcf469896ce7b6d6ad2d371d31deb Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 11:09:44 -0700 Subject: [PATCH 05/46] Additions to test_helper.rb --- test/test_helper.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ab84e3d1..2d723d0c9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,18 @@ -ENV['RAILS_ENV'] ||= 'test' -require_relative '../config/environment' +ENV['RAILS_ENV'] = 'test' +require File.expand_path('../config/environments', __FILE__) require 'rails/test_help' +require 'minitest/rails' +require 'minitest/autorun' +require 'minitest/reporters' + +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all From 3a98e279f0f29b1ffe33078d428b71b5f6df6836 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Tue, 8 Oct 2019 12:34:35 -0700 Subject: [PATCH 06/46] Created edit, update, and destroy actions and ran tests --- app/controllers/drivers_controller.rb | 41 +++++- test/controllers/drivers_controller_test.rb | 129 ++++++++--------- test/controllers/homepages_controller_test.rb | 12 +- .../controllers/passengers_controller_test.rb | 48 +++---- test/controllers/trips_controller_test.rb | 36 ++--- test/models/driver_test.rb | 132 +++++++++--------- test/models/passenger_test.rb | 118 ++++++++-------- test/models/trip_test.rb | 38 ++--- test/test_helper.rb | 22 +-- 9 files changed, 310 insertions(+), 266 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 2e066b72b..6c25bc633 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -7,7 +7,10 @@ def show @driver = Driver.find_by(id: params[:id]) if @driver.nil? - head :not_found + redirect_to drivers_path + return + else + redirect_to driver_path(@driver) return end end @@ -29,6 +32,42 @@ def create end end + def edit + @driver = Driver.find_by(id: params[:id]) + + if @driver.nil? + redirect_to drivers_path + return + end + end + + def update + @driver = Driver.find_by(id: params[:id]) + + if @driver.nil? + redirect_to drivers_path + return + end + + @driver.update(driver_params) + + redirect_to driver_path(@driver) + return + end + + def destroy + @driver = Driver.find_by(id: params[:id]) + + if @driver.nil? + redirect_to drivers_path + return + end + + @driver.destroy + redirect_to drivers_path + return + end + private def driver_params diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index bbe04d506..3dcfa418f 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -2,97 +2,93 @@ 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 - new_driver = Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true - + new_driver = Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true + # 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 - + # Act get drivers_path - + # Assert must_respond_with :success - end end - + describe "show" do - before do - Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true + before do + @driver = Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true end - + it "responds with success when showing an existing valid driver" do # Arrange # Ensure that there is a driver saved - + # Act - get driver_path(driver.id) - + get driver_path(@driver.id) + # Assert - - must_respond_with :success - must_redirect_to driver_path(driver.id) - + + must_respond_with :redirect + must_redirect_to driver_path(@driver.id) end - + it "responds with 404 with an invalid driver id" do # Arrange # Ensure that there is an id that points to no driver - + invalid_id = -1 - + # Act - + get driver_path(invalid_id) - + # Assert must_respond_with :redirect must_redirect_to drivers_path - end end - + describe "new" do it "responds with success" do get new_driver_path - + must_respond_with :success end end - + describe "create" do it "can create a new driver with valid information accurately, and redirect" do - + # Arrange # Set up the form data - + driver_hash = { driver: { name: "Bob's Burgers", vin: "FDJSKFJD84938", - available: true - } + available: true, + }, } - + # Act-Assert # Ensure that there is a change of 1 in Driver.count - + expect { - post driver_path, params: driver_hash + post drivers_path, params: driver_hash }.must_change "Driver.count", 1 new_driver = Driver.find_by(name: driver_hash[:driver][:name]) @@ -113,13 +109,13 @@ # 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 @@ -127,21 +123,26 @@ it "responds with success when getting the edit page for an existing, valid driver" do # Arrange # Ensure there is an existing driver saved - + + @driver = Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true + # 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 # Arrange # Ensure there is an invalid id that points to no driver - + # Act - + get edit_driver_path(-1) + # Assert - + must_respond_with :redirect + must_redirect_to drivers_path end end @@ -151,42 +152,42 @@ # 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 @@ -194,25 +195,25 @@ 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 diff --git a/test/controllers/homepages_controller_test.rb b/test/controllers/homepages_controller_test.rb index 9dd7648db..6dc5fd65f 100644 --- a/test/controllers/homepages_controller_test.rb +++ b/test/controllers/homepages_controller_test.rb @@ -1,9 +1,9 @@ require "test_helper" -describe HomepagesController do - it "can get the homepage" do - get root_path +# describe HomepagesController do +# it "can get the homepage" do +# get root_path - must_respond_with :success - end -end +# must_respond_with :success +# end +# end diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 60acbdfb6..842f387a6 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -1,31 +1,31 @@ -require "test_helper" +# require "test_helper" -describe PassengersController do - describe "index" do - # Your tests go here - end +# describe PassengersController do +# describe "index" do +# # Your tests go here +# end - describe "show" do - # Your tests go here - end +# describe "show" do +# # Your tests go here +# end - describe "new" do - # Your tests go here - end +# describe "new" do +# # Your tests go here +# end - describe "create" do - # Your tests go here - end +# describe "create" do +# # Your tests go here +# end - describe "edit" do - # Your tests go here - end +# describe "edit" do +# # Your tests go here +# end - describe "update" do - # Your tests go here - end +# describe "update" do +# # Your tests go here +# end - describe "destroy" do - # Your tests go here - end -end +# describe "destroy" do +# # Your tests go here +# end +# end diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index 59455c041..c004f9d20 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -1,23 +1,23 @@ -require "test_helper" +# require "test_helper" -describe TripsController do - describe "show" do - # Your tests go here - end +# describe TripsController do +# describe "show" do +# # Your tests go here +# end - describe "create" do - # Your tests go here - end +# describe "create" do +# # Your tests go here +# end - describe "edit" do - # Your tests go here - end +# describe "edit" do +# # Your tests go here +# end - describe "update" do - # Your tests go here - end +# describe "update" do +# # Your tests go here +# end - describe "destroy" do - # Your tests go here - end -end +# describe "destroy" do +# # Your tests go here +# end +# end diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 9f12d286c..275c2bfa1 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -1,80 +1,80 @@ -require "test_helper" +# require "test_helper" -describe Driver do - 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 +# describe Driver do +# let (:new_driver) { +# Driver.new(name: "Kari", vin: "123", available: 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| +# 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 +# # 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 +# 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| - expect(trip).must_be_instance_of Trip - end - end - end +# # Assert +# expect(driver.trips.count).must_be :>=, 0 +# driver.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_driver.name = nil +# 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 +# # 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 +# 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 +# # 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 - end +# # Tests for methods you create should go here +# describe "custom methods" do +# describe "average rating" do +# # Your code here +# end - describe "total earnings" do - # Your code here - end +# describe "total earnings" do +# # Your code here +# end - describe "can go online" do - # Your code here - end +# describe "can go online" do +# # Your code here +# end - describe "can go offline" do - # Your code here - end +# describe "can go offline" do +# # Your code here +# end - # You may have additional methods to test - end -end +# # You may have additional methods to test +# end +# end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 66ac353d3..f6849f30f 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -1,70 +1,70 @@ -require "test_helper" +# require "test_helper" -describe Passenger do - let (:new_passenger) { - Passenger.new(name: "Kari", phone_number: "111-111-1211") - } - it "can be instantiated" do - # Assert - expect(new_passenger.valid?).must_equal true - end +# describe Passenger do +# let (:new_passenger) { +# Passenger.new(name: "Kari", phone_number: "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_number].each do |field| +# it "will have the required fields" do +# # Arrange +# new_passenger.save +# passenger = Passenger.first +# [:name, :phone_number].each do |field| - # Assert - expect(passenger).must_respond_to field - end - end +# # Assert +# expect(passenger).must_respond_to field +# end +# end - describe "relationships" do - it "can have many trips" do - # Arrange - new_passenger.save - passenger = Passenger.first +# 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 +# # 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 +# 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 +# # 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 +# 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 - end +# # 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 +# end - # Tests for methods you create should go here - describe "custom methods" do - describe "request a ride" do - # Your code here - 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 - end -end +# describe "complete trip" do +# # Your code here +# end +# # You may have additional methods to test here +# end +# end diff --git a/test/models/trip_test.rb b/test/models/trip_test.rb index 0b0b2da32..acbfa7f4b 100644 --- a/test/models/trip_test.rb +++ b/test/models/trip_test.rb @@ -1,24 +1,24 @@ -require "test_helper" +# require "test_helper" -describe Trip do - it "can be instantiated" do - # Your code here - end +# describe Trip do +# it "can be instantiated" do +# # Your code here +# end - it "will have the required fields" do - # Your code here - end +# it "will have the required fields" do +# # Your code here +# end - describe "relationships" do - # Your tests go here - end +# describe "relationships" do +# # Your tests go here +# end - describe "validations" do - # Your tests go here - end +# describe "validations" do +# # Your tests go here +# end - # Tests for methods you create should go here - describe "custom methods" do - # Your tests here - end -end +# # Tests for methods you create should go here +# describe "custom methods" do +# # Your tests here +# end +# end diff --git a/test/test_helper.rb b/test/test_helper.rb index 2d723d0c9..ea10bc02d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,21 +1,25 @@ -ENV['RAILS_ENV'] = 'test' -require File.expand_path('../config/environments', __FILE__) -require 'rails/test_help' - -require 'minitest/rails' -require 'minitest/autorun' -require 'minitest/reporters' - +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" # for Colorized output +# For colorful output! Minitest::Reporters.use!( Minitest::Reporters::SpecReporter.new, ENV, Minitest.backtrace_filter ) - 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 + +# 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 848c3f83cfde27ba8a025578b6583f56e3c964f6 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Tue, 8 Oct 2019 14:24:08 -0700 Subject: [PATCH 07/46] Updated links in edit and show, and updated drivers_controller_test --- app/controllers/drivers_controller.rb | 7 ++-- app/views/drivers/edit.html.erb | 1 + app/views/drivers/show.html.erb | 2 +- test/controllers/drivers_controller_test.rb | 39 ++++++++++++++++++--- 4 files changed, 39 insertions(+), 10 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 6c25bc633..6f0ca421f 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -7,10 +7,7 @@ def show @driver = Driver.find_by(id: params[:id]) if @driver.nil? - redirect_to drivers_path - return - else - redirect_to driver_path(@driver) + head :not_found return end end @@ -45,7 +42,7 @@ def update @driver = Driver.find_by(id: params[:id]) if @driver.nil? - redirect_to drivers_path + head :not_found return end diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb new file mode 100644 index 000000000..6f3f89562 --- /dev/null +++ b/app/views/drivers/edit.html.erb @@ -0,0 +1 @@ +<%= render :partial => "drivers/form", locals: { action_name: "edit" } %> \ No newline at end of file diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 853998e54..6aa6cee63 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,4 +1,4 @@

Driver name: <%= @driver.name %>

VIN: <%= @driver.vin %>

Status: <%= @driver.available %>

- +<%= link_to "Edit Driver", edit_driver_path(@driver) %> diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 3dcfa418f..cbe60436f 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -42,8 +42,8 @@ # Assert - must_respond_with :redirect - must_redirect_to driver_path(@driver.id) + must_respond_with :success + # must_redirect_to driver_path(@driver.id) end it "responds with 404 with an invalid driver id" do @@ -57,8 +57,7 @@ get driver_path(invalid_id) # Assert - must_respond_with :redirect - must_redirect_to drivers_path + must_respond_with :not_found end end @@ -153,6 +152,26 @@ # Assign the existing driver's id to a local variable # Set up the form data + existing_driver = Driver.create name: "Harry Potter", vin: "HOGWA4RT$" + + updated_driver_hash = { + driver: { + name: "Ron Weasley", + vin: "ASDASDKJ456", + }, + } + + expect { + patch driver_path(existing_driver.id), params: updated_driver_hash + }.wont_change "Driver.count" + + updated_driver = Driver.find_by(id: existing_driver.id) + + expect(updated_driver.name).must_equal updated_driver_hash[:driver][:name] + expect(updated_driver.vin).must_equal updated_driver_hash[:driver][:vin] + + must_respond_with :redirect + must_redirect_to driver_path(updated_driver) # Act-Assert # Ensure that there is no change in Driver.count @@ -166,6 +185,18 @@ # Arrange # Ensure there is an invalid id that points to no driver # Set up the form data + updated_driver_hash = { + driver: { + name: "Ron Weasley", + vin: "ASDASDKJ456", + }, + } + + invalid_driver_id = -1 + + patch driver_path(invalid_driver_id), params: updated_driver_hash + + must_respond_with :not_found # Act-Assert # Ensure that there is no change in Driver.count From 2155c9da4179a245b78e95057533abe9878ed807 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 14:30:02 -0700 Subject: [PATCH 08/46] Added passenger controller and model --- app/assets/javascripts/passengers.js | 2 ++ app/assets/stylesheets/passengers.scss | 3 +++ app/controllers/passengers_controller.rb | 2 ++ app/helpers/passengers_helper.rb | 2 ++ app/models/passenger.rb | 2 ++ db/migrate/20191008212903_create_passengers.rb | 10 ++++++++++ db/schema.rb | 9 ++++++++- 7 files changed, 29 insertions(+), 1 deletion(-) 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 create mode 100644 app/models/passenger.rb create mode 100644 db/migrate/20191008212903_create_passengers.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 diff --git a/app/models/passenger.rb b/app/models/passenger.rb new file mode 100644 index 000000000..2c5748ac2 --- /dev/null +++ b/app/models/passenger.rb @@ -0,0 +1,2 @@ +class Passenger < ApplicationRecord +end diff --git a/db/migrate/20191008212903_create_passengers.rb b/db/migrate/20191008212903_create_passengers.rb new file mode 100644 index 000000000..aeced4891 --- /dev/null +++ b/db/migrate/20191008212903_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/schema.rb b/db/schema.rb index 644354e7e..a87de3b96 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_08_175947) do +ActiveRecord::Schema.define(version: 2019_10_08_212903) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,4 +25,11 @@ t.string "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 + end From 0d93dec4729c91efd37b9417d54e19ae722c917e Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 14:35:09 -0700 Subject: [PATCH 09/46] Added methods index, show, new, create to Passenger --- app/controllers/passengers_controller.rb | 35 ++++++++++++++++++++++++ config/routes.rb | 9 +++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 7b08e4832..b21bdbec8 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -1,2 +1,37 @@ class PassengersController < ApplicationController + + def index + @passengers = Passenger.all + end + + def show + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + head :not_found + return + end + end + + def new + @passenger = Passenger.new + end + + def create + @passenger = Passenger.new(passenger_params) + + if @passenger.save + redirect_to passenger_path(@passenger) + return + else + render "new" + return + end + end + + private + + def passenger_params + return params.require(:passenger).permit(:name, :phone_num) + end end diff --git a/config/routes.rb b/config/routes.rb index 3e50ec550..2fec1ac5d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,5 +6,12 @@ patch "/drivers/:id", to: "drivers#update" delete "/drivers/:id", to: "drivers#destroy" get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver - + + get "/passengers", to: "passengers#index", as: :passengers + post "/passengers", to: "passengers#create" + get "/passengers/new", to: "passengers#new", as: :new_passenger + get "/passengers/:id", to: "passengers#show", as: :passenger + patch "/passengers/:id", to: "passengers#update" + delete "/passengers/:id", to: "passengers#destroy" + get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger end From d33d1de1ad254f73941db536d8eb29eb12dae30b Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 14:45:58 -0700 Subject: [PATCH 10/46] Added HomePages controller and Passenger views --- app/assets/javascripts/homepages.js | 2 ++ app/assets/stylesheets/homepages.scss | 3 +++ app/controllers/homepages_controller.rb | 6 ++++++ app/helpers/homepages_helper.rb | 2 ++ app/views/homepages/index.html.erb | 4 ++++ app/views/passengers/index.html.erb | 12 ++++++++++++ config/initializers/postgresql_database_tasks.rb | 11 +++++++++++ config/routes.rb | 2 ++ 8 files changed, 42 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 create mode 100644 app/views/homepages/index.html.erb create mode 100644 app/views/passengers/index.html.erb create mode 100644 config/initializers/postgresql_database_tasks.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..0b23bc3ff --- /dev/null +++ b/app/controllers/homepages_controller.rb @@ -0,0 +1,6 @@ +class HomepagesController < ApplicationController + + def index + end + +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 diff --git a/app/views/homepages/index.html.erb b/app/views/homepages/index.html.erb new file mode 100644 index 000000000..a4596cb6c --- /dev/null +++ b/app/views/homepages/index.html.erb @@ -0,0 +1,4 @@ +Welcome to Rideshare! + +<%= link_to "View Drivers", drivers_path %> +<%= link_to "View Passengers", passengers_path %> diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb new file mode 100644 index 000000000..35f3b6fd5 --- /dev/null +++ b/app/views/passengers/index.html.erb @@ -0,0 +1,12 @@ +

List of Passengers

+ +<%= link_to "Create a new Passenger", new_passenger_path %> + +
    + <% @passengers.each do |passenger| %> +
  • + <%= link_to passenger.name, passenger_path(passenger) %>
    + <%= passenger.phone_num %> +
  • + <% end %> +
\ No newline at end of file diff --git a/config/initializers/postgresql_database_tasks.rb b/config/initializers/postgresql_database_tasks.rb new file mode 100644 index 000000000..8883701bb --- /dev/null +++ b/config/initializers/postgresql_database_tasks.rb @@ -0,0 +1,11 @@ +module ActiveRecord + module Tasks + class PostgreSQLDatabaseTasks + def drop + establish_master_connection + connection.select_all "select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where datname='#{configuration['database']}' AND state='idle';" + connection.drop_database configuration['database'] + end + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2fec1ac5d..807acea94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + root 'homepages#index' + get "/drivers", to: "drivers#index", as: :drivers post "/drivers", to: "drivers#create" get "/drivers/new", to: "drivers#new", as: :new_driver From d51657337271d6f26c1d972f07ede427203f6234 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 14:57:12 -0700 Subject: [PATCH 11/46] Added edit, update, destroy methods and views to Passenger class --- app/controllers/passengers_controller.rb | 36 ++++++++++++++++++++++++ app/views/passengers/_form.html.erb | 9 ++++++ app/views/passengers/edit.html.erb | 1 + app/views/passengers/new.html.erb | 1 + app/views/passengers/show.html.erb | 3 ++ 5 files changed, 50 insertions(+) create mode 100644 app/views/passengers/_form.html.erb create mode 100644 app/views/passengers/edit.html.erb create mode 100644 app/views/passengers/new.html.erb create mode 100644 app/views/passengers/show.html.erb diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index b21bdbec8..fb3d40838 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -29,6 +29,42 @@ def create end end + def edit + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + redirect_to passengers_path + return + end + end + + def update + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + head :not_found + return + end + + @passenger.update(passenger_params) + + redirect_to passenger_path(@passenger) + return + end + + def destroy + @passenger = Passenger.find_by(id: params[:id]) + + if @passenger.nil? + redirect_to passengers_path + return + end + + @passenger.destroy + redirect_to passengers_path + return + end + private def passenger_params diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb new file mode 100644 index 000000000..915157dcd --- /dev/null +++ b/app/views/passengers/_form.html.erb @@ -0,0 +1,9 @@ +<%= form_with model: @passenger, class: "#{action_name}-passenger" do |f| %> + <%= f.label :name %> + <%= f.text_field :name %>
+ + <%= f.label "Phone Number" %> + <%= f.text_field :phone_num %>
+ + <%= f.submit "#{action_name.capitalize} Passenger", class: "passenger-button" %> +<% end %> \ No newline at end of file diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb new file mode 100644 index 000000000..fae04e76d --- /dev/null +++ b/app/views/passengers/edit.html.erb @@ -0,0 +1 @@ +<%= render :partial => "passengers/form", locals: { action_name: "edit" } %> \ 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..f85bdb1ab --- /dev/null +++ b/app/views/passengers/new.html.erb @@ -0,0 +1 @@ +<%= render :partial => "passengers/form", locals: { action_name: "create" } %> \ No newline at end of file diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb new file mode 100644 index 000000000..1f40d2ce6 --- /dev/null +++ b/app/views/passengers/show.html.erb @@ -0,0 +1,3 @@ +

Passenger name: <%= @passenger.name %>

+

Phone Number: <%= @passenger.phone_num %>

+<%= link_to "Edit Passenger", edit_passenger_path(@passenger) %> From a5aa04fa243bf4856c9e194e5c4e042692da8e16 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 15:08:58 -0700 Subject: [PATCH 12/46] Added tests for Passenger class --- .../controllers/passengers_controller_test.rb | 165 +++++++++++++++--- 1 file changed, 141 insertions(+), 24 deletions(-) diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 842f387a6..059aa6c57 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -1,31 +1,148 @@ -# require "test_helper" +require "test_helper" -# describe PassengersController do -# describe "index" do -# # Your tests go here -# end +describe PassengersController do + describe "index" do + it "responds with success when there are many passengers saved" do -# describe "show" do -# # Your tests go here -# end + new_passenger = Passenger.create name: "Random name", phone_num: "206-123-3333" -# describe "new" do -# # Your tests go here -# end + get passengers_path -# describe "create" do -# # Your tests go here -# end + must_respond_with :success + end -# describe "edit" do -# # Your tests go here -# end + it "responds with success when there are no passengers saved" do + get passengers_path -# describe "update" do -# # Your tests go here -# end + must_respond_with :success + end + end -# describe "destroy" do -# # Your tests go here -# end -# end + describe "show" do + before do + @passenger = Passenger.create name: "Random name", phone_num: "206-123-3333" + end + + it "responds with success when showing an existing valid passenger" do + get passenger_path(@passenger.id) + + must_respond_with :success + end + + it "responds with 404 with an invalid passenger id" do + invalid_id = -1 + + get passenger_path(invalid_id) + + must_respond_with :not_found + end + end + + describe "new" do + it "responds with success" do + get new_passenger_path + + must_respond_with :success + end + end + + describe "create" do + it "can create a new passenger with valid information accurately, and redirect" do + + passenger_hash = { + passenger: { + name: "Bob's Burgers", + phone_num: "XXX-XXX-XXXX" + }, + } + + expect { + post passengers_path, params: passenger_hash + }.must_change "Passenger.count", 1 + + new_passenger = Passenger.find_by(name: 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 + end + end + + describe "edit" do + it "responds with success when getting the edit page for an existing, valid passenger" do + + @passenger = Passenger.create name: "Random name", phone_num: "XXX-XXX-XXXX" + + get edit_passenger_path(@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 + it "can update an existing passenger with valid information accurately, and redirect" do + + existing_passenger = Passenger.create name: "Harry Potter", phone_num: "aaa-aaa-aaaa" + + updated_passenger_hash = { + passenger: { + name: "Ron Weasley", + phone_num: "zzz-zzz-zzzz" + }, + } + + expect { + patch passenger_path(existing_passenger.id), params: updated_passenger_hash + }.wont_change "Passenger.count" + + updated_passenger = Passenger.find_by(id: existing_passenger.id) + + expect(updated_passenger.name).must_equal updated_passenger_hash[:passenger][:name] + expect(updated_passenger.phone_num).must_equal updated_passenger_hash[:passenger][:phone_num] + + must_respond_with :redirect + must_redirect_to passenger_path(updated_passenger) + + end + + it "does not update any passenger if given an invalid id, and responds with a 404" do + + updated_passenger_hash = { + passenger: { + name: "Ron Weasley", + phone_num: "zzz-zzz-zzzz" + }, + } + + invalid_passenger_id = -1 + + patch passenger_path(invalid_passenger_id), params: updated_passenger_hash + + 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 + + end + end + + describe "destroy" do + + end +end From 7699db85f456aa2553c1aafcb087254f7fe2475d Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Tue, 8 Oct 2019 15:23:46 -0700 Subject: [PATCH 13/46] Created Trip model and 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 ++ app/models/trip.rb | 2 ++ db/migrate/20191008221949_create_trips.rb | 11 +++++++++++ ...18_add_driver_id_and_passenger_id_to_trips.rb | 6 ++++++ db/schema.rb | 16 +++++++++++++++- 8 files changed, 43 insertions(+), 1 deletion(-) 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 create mode 100644 app/models/trip.rb create mode 100644 db/migrate/20191008221949_create_trips.rb create mode 100644 db/migrate/20191008222118_add_driver_id_and_passenger_id_to_trips.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 diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 000000000..a8c077a10 --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,2 @@ +class Trip < ApplicationRecord +end diff --git a/db/migrate/20191008221949_create_trips.rb b/db/migrate/20191008221949_create_trips.rb new file mode 100644 index 000000000..0082137f6 --- /dev/null +++ b/db/migrate/20191008221949_create_trips.rb @@ -0,0 +1,11 @@ +class CreateTrips < ActiveRecord::Migration[5.2] + def change + create_table :trips do |t| + t.date :date + t.integer :rating + t.float :cost + + t.timestamps + end + end +end diff --git a/db/migrate/20191008222118_add_driver_id_and_passenger_id_to_trips.rb b/db/migrate/20191008222118_add_driver_id_and_passenger_id_to_trips.rb new file mode 100644 index 000000000..f3722a09f --- /dev/null +++ b/db/migrate/20191008222118_add_driver_id_and_passenger_id_to_trips.rb @@ -0,0 +1,6 @@ +class AddDriverIdAndPassengerIdToTrips < ActiveRecord::Migration[5.2] + def change + add_reference :trips, :driver, foreign_key: :true + add_reference :trips, :passenger, foreign_key: :true + end +end diff --git a/db/schema.rb b/db/schema.rb index a87de3b96..a8128f8de 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_08_212903) do +ActiveRecord::Schema.define(version: 2019_10_08_222118) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,4 +32,18 @@ t.datetime "updated_at", null: false end + create_table "trips", force: :cascade do |t| + t.date "date" + t.integer "rating" + t.float "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 cf0666f93ad20b7e39da7e1e5455f40f95897566 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Tue, 8 Oct 2019 15:52:27 -0700 Subject: [PATCH 14/46] Created one-to-many relationships between driver, passenger, and trips. Also created validations --- app/models/driver.rb | 4 ++++ app/models/passenger.rb | 4 ++++ app/models/trip.rb | 2 ++ app/views/drivers/_form.html.erb | 4 ++-- app/views/drivers/new.html.erb | 10 ++++++++++ app/views/trips/index.html.erb | 1 + config/routes.rb | 28 +++++++++++++++------------- 7 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 app/views/trips/index.html.erb diff --git a/app/models/driver.rb b/app/models/driver.rb index 1ff364562..5d88e3279 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,2 +1,6 @@ class Driver < ApplicationRecord + has_many :trips + + validates :name, presence: true + validates :vin, presence: true end diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 2c5748ac2..5df27c9a8 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,2 +1,6 @@ class Passenger < ApplicationRecord + has_many :trips + + validates :name, presence: true + validates :phone_num, presence: true end diff --git a/app/models/trip.rb b/app/models/trip.rb index a8c077a10..8e2566cd8 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,2 +1,4 @@ class Trip < ApplicationRecord + belongs_to :driver + belongs_to :passenger end diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index a0b1d4774..b59256360 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -1,8 +1,8 @@ <%= form_with model: @driver, class: "#{action_name}-driver" do |f| %> - <%= f.label :name %> + <%= f.label :name %>
<%= f.text_field :name %>
- <%= f.label :vin %> + <%= f.label :vin %>
<%= f.text_field :vin %>
<%= f.submit "#{action_name.capitalize} Driver", class: "drivers-button" %> diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index e9254372d..85989f015 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -1 +1,11 @@ +<% if @driver.errors.any? %> +
    + <% @driver.errors.each do |column, message| %> +
  • + <%= column.capitalize %> <%= message %> +
  • + <% end %> +
+<% end %> + <%= render :partial => "drivers/form", locals: { action_name: "create" } %> \ No newline at end of file diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb new file mode 100644 index 000000000..4e19f854d --- /dev/null +++ b/app/views/trips/index.html.erb @@ -0,0 +1 @@ +

List of Trips

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 807acea94..99d984f08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,19 +1,21 @@ Rails.application.routes.draw do - root 'homepages#index' + root "homepages#index" - get "/drivers", to: "drivers#index", as: :drivers - post "/drivers", to: "drivers#create" - get "/drivers/new", to: "drivers#new", as: :new_driver - get "/drivers/:id", to: "drivers#show", as: :driver - patch "/drivers/:id", to: "drivers#update" + get "/drivers", to: "drivers#index", as: :drivers + post "/drivers", to: "drivers#create" + get "/drivers/new", to: "drivers#new", as: :new_driver + get "/drivers/:id", to: "drivers#show", as: :driver + patch "/drivers/:id", to: "drivers#update" delete "/drivers/:id", to: "drivers#destroy" - get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver + get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver - get "/passengers", to: "passengers#index", as: :passengers - post "/passengers", to: "passengers#create" - get "/passengers/new", to: "passengers#new", as: :new_passenger - get "/passengers/:id", to: "passengers#show", as: :passenger - patch "/passengers/:id", to: "passengers#update" + get "/passengers", to: "passengers#index", as: :passengers + post "/passengers", to: "passengers#create" + get "/passengers/new", to: "passengers#new", as: :new_passenger + get "/passengers/:id", to: "passengers#show", as: :passenger + patch "/passengers/:id", to: "passengers#update" delete "/passengers/:id", to: "passengers#destroy" - get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger + get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger + + get "/trips", to: "trips#index", as: :trips end From d044ea38e7827bb43f58a1e9275d473e8022c812 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Tue, 8 Oct 2019 16:17:59 -0700 Subject: [PATCH 15/46] Added create method to Trip class --- app/controllers/trips_controller.rb | 18 ++++ config/routes.rb | 33 ++++--- test/models/passenger_test.rb | 139 ++++++++++++++-------------- 3 files changed, 106 insertions(+), 84 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 4275f53c7..0705ee768 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,2 +1,20 @@ class TripsController < ApplicationController + def create + if params[:driver_id] && params[:passenger_id] + @trip = Trip.new(trip_params) + if @trip.save + redirect_to passenger_path(params[:passenger_id]) + return + else + render "new" + return + end + end + end + + private + + def trip_params + return params.require(:trip).permit(:date, :rating, :cost, :driver_id, :passenger_id) + end end diff --git a/config/routes.rb b/config/routes.rb index 99d984f08..8f5649770 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,21 +1,26 @@ Rails.application.routes.draw do root "homepages#index" - get "/drivers", to: "drivers#index", as: :drivers - post "/drivers", to: "drivers#create" - get "/drivers/new", to: "drivers#new", as: :new_driver - get "/drivers/:id", to: "drivers#show", as: :driver - patch "/drivers/:id", to: "drivers#update" - delete "/drivers/:id", to: "drivers#destroy" - get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver + resources :drivers + # get "/drivers", to: "drivers#index", as: :drivers + # post "/drivers", to: "drivers#create" + # get "/drivers/new", to: "drivers#new", as: :new_driver + # get "/drivers/:id", to: "drivers#show", as: :driver + # patch "/drivers/:id", to: "drivers#update" + # delete "/drivers/:id", to: "drivers#destroy" + # get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver - get "/passengers", to: "passengers#index", as: :passengers - post "/passengers", to: "passengers#create" - get "/passengers/new", to: "passengers#new", as: :new_passenger - get "/passengers/:id", to: "passengers#show", as: :passenger - patch "/passengers/:id", to: "passengers#update" - delete "/passengers/:id", to: "passengers#destroy" - get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger + resources :passengers do + resources :trips, only: [:create] + end + + # get "/passengers", to: "passengers#index", as: :passengers + # post "/passengers", to: "passengers#create" + # get "/passengers/new", to: "passengers#new", as: :new_passenger + # get "/passengers/:id", to: "passengers#show", as: :passenger + # patch "/passengers/:id", to: "passengers#update" + # delete "/passengers/:id", to: "passengers#destroy" + # get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger get "/trips", to: "trips#index", as: :trips end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index f6849f30f..3ecf89bad 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -1,70 +1,69 @@ -# require "test_helper" - -# describe Passenger do -# let (:new_passenger) { -# Passenger.new(name: "Kari", phone_number: "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_number].each do |field| - -# # Assert -# expect(passenger).must_respond_to field -# 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 - -# 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 -# 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 -# end -# end +require "test_helper" +​ +describe Passenger do + let (:new_passenger) { + 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(passenger).must_respond_to field + 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 +​ + 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 + end \ No newline at end of file From 1bdd2f443b3fe0c1ca9df62e7acbdbd431d013fe Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 16:53:16 -0700 Subject: [PATCH 16/46] Added testing for Driver and Passenger validation --- app/controllers/trips_controller.rb | 5 + app/views/trips/index.html.erb | 16 +- test/controllers/drivers_controller_test.rb | 96 ++++-------- .../controllers/passengers_controller_test.rb | 27 +++- test/models/passenger_test.rb | 137 +++++++++--------- 5 files changed, 141 insertions(+), 140 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 0705ee768..91b0018d5 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,4 +1,9 @@ class TripsController < ApplicationController + + def index + @trips = Trip.all + end + def create if params[:driver_id] && params[:passenger_id] @trip = Trip.new(trip_params) diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb index 4e19f854d..0df947f22 100644 --- a/app/views/trips/index.html.erb +++ b/app/views/trips/index.html.erb @@ -1 +1,15 @@ -

List of Trips

\ No newline at end of file +

List of Trips

+ +<%= link_to "Create a new trip", passengers_path %> + +
    + <% @trips.each do |trip| %> +
  • + <%= trip.date %>
    + <%= link_to trip.passenger.name, passenger_path(trip.passenger) %>
    + <%= link_to trip.driver.name, driver_path(trip.driver) %>
    + <%= trip.rating %>
    + <%= trip.cost %> +
  • + <% end %> +
\ No newline at end of file diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index cbe60436f..6cc18f60e 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -5,25 +5,16 @@ describe "index" do it "responds with success when there are many drivers saved" do - # Arrange - # Ensure that there is at least one Driver saved new_driver = Driver.create name: "Random name", vin: "XFHJKDHSLFKJDKL", available: true - # 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 - - # Act get drivers_path - # Assert must_respond_with :success end end @@ -34,29 +25,17 @@ end it "responds with success when showing an existing valid driver" do - # Arrange - # Ensure that there is a driver saved - - # Act get driver_path(@driver.id) - # Assert - must_respond_with :success # must_redirect_to driver_path(@driver.id) end it "responds with 404 with an invalid driver id" do - # Arrange - # Ensure that there is an id that points to no driver - invalid_id = -1 - # Act - get driver_path(invalid_id) - # Assert must_respond_with :not_found end end @@ -71,36 +50,25 @@ describe "create" do it "can create a new driver with valid information accurately, and redirect" do - - # Arrange - # Set up the form data - driver_hash = { driver: { name: "Bob's Burgers", vin: "FDJSKFJD84938", - available: true, - }, + available: true + } } - # Act-Assert - # Ensure that there is a change of 1 in Driver.count - expect { post drivers_path, params: driver_hash }.must_change "Driver.count", 1 new_driver = Driver.find_by(name: driver_hash[:driver][:name]) - # Assert - expect(new_driver.vin).must_equal driver_hash[:driver][:vin] expect(new_driver.available).must_equal driver_hash[:driver][:available] must_respond_with :redirect must_redirect_to driver_path(new_driver.id) - # 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 @@ -108,12 +76,23 @@ # Note: This will not pass until ActiveRecord Validations lesson # Arrange # Set up the form data so that it violates Driver validations + driver_hash = { + driver: { + vin: "FDJSKFJD84938", + available: true + } + } + + expect { + post drivers_path, params: driver_hash + }.wont_change "Driver.count" # Act-Assert # Ensure that there is no change in Driver.count # Assert # Check that the controller redirects + must_respond_with :success end end @@ -133,13 +112,8 @@ 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 get edit_driver_path(-1) - # Assert must_respond_with :redirect must_redirect_to drivers_path end @@ -147,10 +121,6 @@ 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 existing_driver = Driver.create name: "Harry Potter", vin: "HOGWA4RT$" @@ -172,19 +142,9 @@ must_respond_with :redirect must_redirect_to driver_path(updated_driver) - # 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 updated_driver_hash = { driver: { name: "Ron Weasley", @@ -197,27 +157,25 @@ patch driver_path(invalid_driver_id), params: updated_driver_hash must_respond_with :not_found - - # 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 + existing_driver = Driver.create name: "Harry Potter", vin: "HOGWA4RT$" + updated_driver_hash = { + driver: { + name: "Ron Weasley" + } + } - # Assert - # Check that the controller redirects + expect { + patch driver_path(existing_driver.id), params: updated_driver_hash + }.wont_change "Driver.count" + + driver_id = Driver.find_by(id: existing_driver.id) + + must_respond_with :redirect + must_redirect_to driver_path(driver_id) end end diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 059aa6c57..25495df8d 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -69,7 +69,17 @@ 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 + passenger_hash = { + passenger: { + phone_num: "XXX-XXX-XXX" + } + } + + expect { + post passengers_path, params: passenger_hash + }.wont_change "Passenger.count" + + must_respond_with :success end end @@ -138,7 +148,22 @@ 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 + existing_passenger = Passenger.create name: "Harry Potter", phone_num: "XXX-XXX-XXXX" + updated_passenger_hash = { + passenger: { + name: "Ron Weasley" + } + } + + expect { + patch passenger_path(existing_passenger.id), params: updated_passenger_hash + }.wont_change "Passenger.count" + + passenger_id = Passenger.find_by(id: existing_passenger.id) + + must_respond_with :redirect + must_redirect_to passenger_path(passenger_id) end end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 3ecf89bad..410849434 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -1,69 +1,68 @@ -require "test_helper" -​ -describe Passenger do - let (:new_passenger) { - 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(passenger).must_respond_to field - 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 -​ - 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 - end \ No newline at end of file +# require "test_helper" + +# describe Passenger do +# let (:new_passenger) { +# 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(passenger).must_respond_to field +# 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 + +# 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 +# end +# end \ No newline at end of file From 2c8cd767d14324b4567b6e4294865735c828fdf5 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Tue, 8 Oct 2019 16:59:29 -0700 Subject: [PATCH 17/46] Uncommented Passenger model tests --- test/models/passenger_test.rb | 122 ++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 410849434..70a54bad2 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -1,68 +1,72 @@ -# require "test_helper" +require "test_helper" -# describe Passenger do -# let (:new_passenger) { -# Passenger.new(name: "Kari", phone_num: "111-111-1211") -# } -# it "can be instantiated" do -# # Assert -# expect(new_passenger.valid?).must_equal true -# end +describe Passenger do + let (:new_passenger) { + 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(passenger).must_respond_to field -# end -# end + it "will have the required fields" do + # Arrange + new_passenger.save + passenger = Passenger.first + [:name, :phone_num].each do |field| + # Assert + expect(passenger).must_respond_to field + 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 "relationships" do + it "can have many trips" do + # Arrange + new_passenger.save + passenger = Passenger.first -# describe "validations" do -# it "must have a name" do -# # Arrange -# new_passenger.name = nil + #Note: add instances of trip to passenger + # Assert + expect(passenger.trips.count).must_be :>, 0 -# # 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 + passenger.trips.each do |trip| + expect(trip).must_be_instance_of Trip + end -# it "must have a phone number" do -# # Arrange -# new_passenger.phone_num = nil + end + 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 -# 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 + + # 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 + # 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 \ No newline at end of file + describe "complete trip" do + # Your code here + end + # You may have additional methods to test here + end +end \ No newline at end of file From 640334e3874465ed8cf164fa1f6871ce7183633b Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Tue, 8 Oct 2019 23:10:28 -0700 Subject: [PATCH 18/46] Added dropdown menu for drivers and passengers and created home button. Also styled the navigation bar --- app/assets/stylesheets/application.css | 62 ++++++++++++++++++++++++++ app/views/homepages/index.html.erb | 6 +-- app/views/layouts/application.html.erb | 20 +++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f51..16b2c323d 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,65 @@ *= require_tree . *= require_self */ + +.nav-bar { + background-color: lightgrey; +} + +.home-button { + background-color: #4CAF50; + color: white; + padding: 16px; + font-size: 16px; + border: none; +} + +.home-button a { + text-decoration: none; + color: white; +} + +.title-section { + display: inline; + padding-right: 50px; +} +.dropbtn { + background-color: #4CAF50; + color: white; + padding: 16px; + font-size: 16px; + border: none; +} + +.dropdown { + position: relative; + display: inline-block; +} + +.dropdown-content { + display: none; + position: absolute; + background-color: #f1f1f1; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1; +} + +.dropdown-content a { + color: black; + padding: 12px 16px; + text-decoration: none; + display: block; +} + +.dropdown-content a:hover { + background-color: #ddd; +} + +.dropdown:hover .dropdown-content { + display: block; +} + +.dropdown:hover .dropbtn { + background-color: #3e8e41; +} \ No newline at end of file diff --git a/app/views/homepages/index.html.erb b/app/views/homepages/index.html.erb index a4596cb6c..8fe955446 100644 --- a/app/views/homepages/index.html.erb +++ b/app/views/homepages/index.html.erb @@ -1,4 +1,4 @@ -Welcome to Rideshare! +<%# Welcome to Rideshare! %> -<%= link_to "View Drivers", drivers_path %> -<%= link_to "View Passengers", passengers_path %> +<%# <%= link_to "View Drivers", drivers_path %> +<%# <%= link_to "View Passengers", passengers_path %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 692ca547e..c56cad799 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,26 @@ + <%= yield %> From 828c94fef15a0c01b0f5ed1e1a1c793f6cd4ad42 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Wed, 9 Oct 2019 14:31:37 -0700 Subject: [PATCH 19/46] Removed make and model columns from Drivers model --- db/migrate/20191009212940_remove_model_and_make_columns.rb | 6 ++++++ db/schema.rb | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20191009212940_remove_model_and_make_columns.rb diff --git a/db/migrate/20191009212940_remove_model_and_make_columns.rb b/db/migrate/20191009212940_remove_model_and_make_columns.rb new file mode 100644 index 000000000..7ed48b660 --- /dev/null +++ b/db/migrate/20191009212940_remove_model_and_make_columns.rb @@ -0,0 +1,6 @@ +class RemoveModelAndMakeColumns < ActiveRecord::Migration[5.2] + def change + remove_column :drivers, :make + remove_column :drivers, :model + end +end diff --git a/db/schema.rb b/db/schema.rb index a8128f8de..6a6d1c54f 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_08_222118) do +ActiveRecord::Schema.define(version: 2019_10_09_212940) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,8 +21,6 @@ t.boolean "available" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "make" - t.string "model" end create_table "passengers", force: :cascade do |t| From 8964b0e97d2b6777f54fbc94c9465d079565a02d Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Wed, 9 Oct 2019 14:43:12 -0700 Subject: [PATCH 20/46] Added custom model methods to driver and passenger --- app/models/driver.rb | 21 +++++ app/models/passenger.rb | 4 + test/models/driver_test.rb | 158 +++++++++++++++++----------------- test/models/passenger_test.rb | 11 ++- 4 files changed, 110 insertions(+), 84 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 5d88e3279..44e87c073 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -3,4 +3,25 @@ class Driver < ApplicationRecord validates :name, presence: true validates :vin, presence: true + + def total_earnings + return ( self.trips.sum{ |trip| (trip.cost - 165 ) * 0.8} )/100 + end + + def average_rating + total_rating = 0 + count = 0 + self.trips.each do |trip| + if trip.rating + total_rating += trip.rating + count += 1 + end + end + + if count = 0 + return "This driver has no ratings" + else + return total_rating/count + end + end end diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 5df27c9a8..0aa06e336 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -3,4 +3,8 @@ class Passenger < ApplicationRecord validates :name, presence: true validates :phone_num, presence: true + + def total_charged + return self.trips.sum(&:cost) + end end diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 275c2bfa1..58797297f 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -1,80 +1,78 @@ -# require "test_helper" - -# describe Driver do -# let (:new_driver) { -# Driver.new(name: "Kari", vin: "123", available: 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| -# expect(trip).must_be_instance_of Trip -# 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 -# 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 +require "test_helper" + +describe Driver do + let (:new_driver) { + Driver.new(name: "Kari", vin: "123", available: 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| + expect(trip).must_be_instance_of Trip + 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 + + end + + describe "total earnings" do + + end + + describe "can go online" do + + end + + describe "can go offline" do + + end + end +end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 70a54bad2..aa8bb6112 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -61,12 +61,15 @@ # 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 + describe "total charged method" do + + end - # You may have additional methods to test here end + + end \ No newline at end of file From 2afd73c9931078b8ee06e0c1cbcd584ce6a93396 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Wed, 9 Oct 2019 15:48:09 -0700 Subject: [PATCH 21/46] Nested routes for passenger and trips to create new trip within passenger :) --- app/controllers/trips_controller.rb | 19 ++++++++++++++++--- app/models/driver.rb | 2 +- app/models/passenger.rb | 2 +- app/models/trip.rb | 8 ++++++++ app/views/trips/index.html.erb | 2 +- config/routes.rb | 6 ++++-- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 91b0018d5..e0e641b62 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,12 +1,23 @@ class TripsController < ApplicationController def index - @trips = Trip.all + if params[:passenger_id] + passenger = Passenger.find_by(id: params[:passenger_id]) + @trips = passenger.trips + else + @trips = Trip.all + end end def create - if params[:driver_id] && params[:passenger_id] - @trip = Trip.new(trip_params) + if params[:passenger_id] + trip_parameters = Trip.create_new_trip + @trip = Trip.new( + passenger_id: params[:passenger_id], + date: trip_parameters[:date], + cost: trip_parameters[:cost], + driver_id: trip_parameters[:driver_id] + ) if @trip.save redirect_to passenger_path(params[:passenger_id]) return @@ -14,6 +25,8 @@ def create render "new" return end + else + redirect_to trips_path end end diff --git a/app/models/driver.rb b/app/models/driver.rb index 44e87c073..53d095236 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: :destroy validates :name, presence: true validates :vin, presence: true diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 0aa06e336..f94ac8a66 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: :destroy validates :name, presence: true validates :phone_num, presence: true diff --git a/app/models/trip.rb b/app/models/trip.rb index 8e2566cd8..9a89ad417 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,4 +1,12 @@ class Trip < ApplicationRecord belongs_to :driver belongs_to :passenger + + def self.create_new_trip + driver = Driver.all.find{ |driver| driver.available } + date = Date.today + cost = rand(1000..5000) + + return { driver_id: driver.id, date: date, cost: cost } + end end diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb index 0df947f22..9d74de46c 100644 --- a/app/views/trips/index.html.erb +++ b/app/views/trips/index.html.erb @@ -1,6 +1,6 @@

List of Trips

-<%= link_to "Create a new trip", passengers_path %> +<%= link_to "Create a new trip", passenger_trips_path(params[:passenger_id]), method: :post %>
    <% @trips.each do |trip| %> diff --git a/config/routes.rb b/config/routes.rb index 8f5649770..76bd5d75d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,9 +11,11 @@ # get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver resources :passengers do - resources :trips, only: [:create] + resources :trips, only: [:index, :create] end + resources :trips, except: [:create, :new] + # get "/passengers", to: "passengers#index", as: :passengers # post "/passengers", to: "passengers#create" # get "/passengers/new", to: "passengers#new", as: :new_passenger @@ -22,5 +24,5 @@ # delete "/passengers/:id", to: "passengers#destroy" # get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger - get "/trips", to: "trips#index", as: :trips + # get "/trips", to: "trips#index", as: :trips end From a53e0428ecf7fc51c92112d051c41a757d9fe5cf Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Wed, 9 Oct 2019 19:29:08 -0700 Subject: [PATCH 22/46] Created show, edit, update, and destroy methods in TripsController --- app/controllers/trips_controller.rb | 50 +++++++++++++++++++++++++++-- app/models/trip.rb | 2 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index e0e641b62..d477e169c 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,5 +1,4 @@ class TripsController < ApplicationController - def index if params[:passenger_id] passenger = Passenger.find_by(id: params[:passenger_id]) @@ -9,14 +8,23 @@ def index end end + def show + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + head :not_found + return + end + end + def create if params[:passenger_id] trip_parameters = Trip.create_new_trip @trip = Trip.new( - passenger_id: params[:passenger_id], + passenger_id: params[:passenger_id], date: trip_parameters[:date], cost: trip_parameters[:cost], - driver_id: trip_parameters[:driver_id] + driver_id: trip_parameters[:driver_id], ) if @trip.save redirect_to passenger_path(params[:passenger_id]) @@ -30,6 +38,42 @@ def create end end + def edit + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + redirect_to passenger_trips_path + return + end + end + + def update + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + head :not_found + return + end + + @trip.update(trip_params) + + redirect_to passenger_trips_path + return + end + + def destroy + @trip = Trip.find_by(id: params[:id]) + + if @trip.nil? + redirect_to passenger_trips_path + return + end + + @trip.destroy + redirect_to passenger_trips_path + return + end + private def trip_params diff --git a/app/models/trip.rb b/app/models/trip.rb index 9a89ad417..1f247b628 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -3,7 +3,7 @@ class Trip < ApplicationRecord belongs_to :passenger def self.create_new_trip - driver = Driver.all.find{ |driver| driver.available } + driver = Driver.all.find { |driver| driver.available } date = Date.today cost = rand(1000..5000) From f371dd6584031da024901aa6a34d6dc731609726 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Wed, 9 Oct 2019 19:29:42 -0700 Subject: [PATCH 23/46] Incorporated bootstrap to format table in passenger's trips' page --- app/assets/stylesheets/application.css | 4 +++ app/views/layouts/application.html.erb | 4 +++ app/views/trips/index.html.erb | 35 ++++++++++++++++++-------- app/views/trips/show.html.erb | 1 + 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 app/views/trips/show.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 16b2c323d..4ca56186c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -74,4 +74,8 @@ .dropdown:hover .dropbtn { background-color: #3e8e41; +} + +table, th, td { + border: 1px solid black; } \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c56cad799..781b81862 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,10 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb index 9d74de46c..9c56375fc 100644 --- a/app/views/trips/index.html.erb +++ b/app/views/trips/index.html.erb @@ -1,15 +1,30 @@ -

    List of Trips

    +

    <%= @trips[0].passenger.name %>'s Trips

    <%= link_to "Create a new trip", passenger_trips_path(params[:passenger_id]), method: :post %> -
      +
      +
      +
      + + + + + + + + + <% @trips.each do |trip| %> -
    • - <%= trip.date %>
      - <%= link_to trip.passenger.name, passenger_path(trip.passenger) %>
      - <%= link_to trip.driver.name, driver_path(trip.driver) %>
      - <%= trip.rating %>
      - <%= trip.cost %> -
    • + + + + + + + + <% end %> - \ No newline at end of file +
      IDDatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      +
      +
      \ 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..835dacaad --- /dev/null +++ b/app/views/trips/show.html.erb @@ -0,0 +1 @@ +

      Trip

      \ No newline at end of file From 889fcba8445e6a2eee9dfae77d3952fb0a4cf634 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Wed, 9 Oct 2019 21:07:24 -0700 Subject: [PATCH 24/46] Bootstrap to format list of passengers and list of drivers tables --- app/views/drivers/index.html.erb | 37 ++++++++++++++++++------ app/views/passengers/index.html.erb | 28 ++++++++++++------ app/views/trips/index.html.erb | 44 ++++++++++++++--------------- 3 files changed, 70 insertions(+), 39 deletions(-) diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index da8fc73a6..a7b7fb7ad 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -2,12 +2,31 @@ <%= link_to "Create a new Driver", new_driver_path %> -
        - <% @drivers.each do |driver| %> -
      • - <%= link_to driver.name, driver_path(driver) %>
        - <%= driver.vin %>
        - <%= driver.available %> -
      • - <% end %> -
      \ No newline at end of file +
      +
      +
      + + + + + + + + <% @drivers.each do |driver| %> + + + + + + + <% end %> +
      IDNameVINStatus
      <%= driver.id %> <%= link_to driver.name, driver_path(driver) %> <%= driver.vin %> + <% if driver.available %> + Available + <% else %> + Unavailable + <% end %> +
      +
      +
      +
      diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 35f3b6fd5..af52c4a19 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -2,11 +2,23 @@ <%= link_to "Create a new Passenger", new_passenger_path %> -
        - <% @passengers.each do |passenger| %> -
      • - <%= link_to passenger.name, passenger_path(passenger) %>
        - <%= passenger.phone_num %> -
      • - <% end %> -
      \ No newline at end of file +
      +
      +
      + + + + + + + <% @passengers.each do |passenger| %> + + + + + + <% end %> +
      IDNamePhone Number
      <%= passenger.id %> <%= link_to passenger.name, passenger_path(passenger) %> <%= passenger.phone_num %>
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb index 9c56375fc..c4940134a 100644 --- a/app/views/trips/index.html.erb +++ b/app/views/trips/index.html.erb @@ -5,26 +5,26 @@
      - - - - - - - - - - <% @trips.each do |trip| %> - - - - - - - - - <% end %> -
      IDDatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      -
      -
      + + + + + + + + + + <% @trips.each do |trip| %> + + + + + + + + + <% end %> +
      IDDatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      + \ No newline at end of file From a2d1eac11306885b3fc1f1ce78eab39f6aa1e2e7 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Wed, 9 Oct 2019 21:41:31 -0700 Subject: [PATCH 25/46] Updated view for TripsController edit, updated Passenger and Driver show views with model methods --- app/controllers/trips_controller.rb | 8 +++---- app/views/drivers/show.html.erb | 6 ++++- app/views/passengers/show.html.erb | 34 ++++++++++++++++++++++++++++- app/views/trips/edit.html.erb | 12 ++++++++++ app/views/trips/show.html.erb | 12 +++++++++- 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 app/views/trips/edit.html.erb diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index d477e169c..8cac0ad3d 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -42,7 +42,7 @@ def edit @trip = Trip.find_by(id: params[:id]) if @trip.nil? - redirect_to passenger_trips_path + redirect_to passenger_path(@trip.passenger.id) return end end @@ -57,7 +57,7 @@ def update @trip.update(trip_params) - redirect_to passenger_trips_path + redirect_to passenger_path(@trip.passenger.id) return end @@ -65,12 +65,12 @@ def destroy @trip = Trip.find_by(id: params[:id]) if @trip.nil? - redirect_to passenger_trips_path + redirect_to passenger_path(@trip.passenger.id) return end @trip.destroy - redirect_to passenger_trips_path + redirect_to passenger_path(@trip.passenger.id) return end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 6aa6cee63..dd0382e87 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,4 +1,8 @@

      Driver name: <%= @driver.name %>

      VIN: <%= @driver.vin %>

      Status: <%= @driver.available %>

      -<%= link_to "Edit Driver", edit_driver_path(@driver) %> +

      Total Earnings: <%= @driver.total_earnings %>

      +

      Average Rating: <%= @driver.average_rating %>

      + +<%= link_to "Edit Driver", edit_driver_path(@driver) %>
      +<%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %>
      diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 1f40d2ce6..f8177201d 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,3 +1,35 @@

      Passenger name: <%= @passenger.name %>

      Phone Number: <%= @passenger.phone_num %>

      -<%= link_to "Edit Passenger", edit_passenger_path(@passenger) %> +

      Total Charged: $<%= @passenger.total_charged/100 %>

      +<%= link_to "Edit Passenger", edit_passenger_path(@passenger) %>
      +<%= link_to "Delete Passenger", passenger_path(@passenger), method: :delete, data: { confirm: "Are you sure you want to delete this passenger?" } %>
      +<%= link_to "Create a new trip", passenger_trips_path(@passenger.id), method: :post %>
      + +

      <%= @passenger.name %>'s Trips

      + +
      +
      +
      + + + + + + + + + + <% @passenger.trips.each do |trip| %> + + + + + + + + + <% end %> +
      Trip IDTrip DatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/trips/edit.html.erb b/app/views/trips/edit.html.erb new file mode 100644 index 000000000..e886b2187 --- /dev/null +++ b/app/views/trips/edit.html.erb @@ -0,0 +1,12 @@ +<%= form_with model: @trip, class: "edit-trip" do |f| %> + <%= f.label :date %> + <%= f.text_field :date %>
      + + <%= f.label :cost %> + <%= f.text_field :cost %>
      + + <%= f.label :rating %> + <%= f.text_field :rating %>
      + + <%= f.submit "Edit Trip", class: "trip-button" %> +<% end %> \ No newline at end of file diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 835dacaad..49fc2628d 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -1 +1,11 @@ -

      Trip

      \ No newline at end of file +

      Trip Details

      + +

      Trip ID: <%= @trip.id %>

      +

      Trip Date: <%= @trip.date %>

      +

      Trip Cost: <%= @trip.cost %>

      +

      Trip Rating: <%= @trip.rating %>

      +

      Passenger Name: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>

      +

      Driver Name: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>

      + +<%= link_to "Edit Trip", edit_trip_path(@trip) %>
      +<%= link_to "Delete Trip", trip_path(@trip), method: :delete, data: { confirm: "Are you sure you want to delete this trip?" } %>
      \ No newline at end of file From 0746c46f2d43321208bc8c08760168b3a1cc9c43 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Wed, 9 Oct 2019 21:47:27 -0700 Subject: [PATCH 26/46] Added nested driver route for driver trips --- app/controllers/trips_controller.rb | 3 +++ app/views/drivers/show.html.erb | 30 +++++++++++++++++++++++++++++ config/routes.rb | 4 +++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 8cac0ad3d..5c63afa41 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -3,6 +3,9 @@ def index if params[:passenger_id] passenger = Passenger.find_by(id: params[:passenger_id]) @trips = passenger.trips + elsif params[:driver_id] + driver = Driver.find_by(id: params[:driver_id]) + @driver = driver.trips else @trips = Trip.all end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index dd0382e87..4820e4756 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -6,3 +6,33 @@ <%= link_to "Edit Driver", edit_driver_path(@driver) %>
      <%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %>
      + + +

      <%= @driver.name %>'s Trips

      + +
      +
      +
      + + + + + + + + + + <% @driver.trips.each do |trip| %> + + + + + + + + + <% end %> +
      Trip IDTrip DatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      +
      +
      \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 76bd5d75d..35d1dbb5f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,9 @@ Rails.application.routes.draw do root "homepages#index" - resources :drivers + resources :drivers do + resources :trips, only: [:index] + end # get "/drivers", to: "drivers#index", as: :drivers # post "/drivers", to: "drivers#create" # get "/drivers/new", to: "drivers#new", as: :new_driver From cf93e575aab784a911b152cbb986d96bab45c178 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 10:08:10 -0700 Subject: [PATCH 27/46] Commented out model tests and started writing tests for TripsController --- app/models/driver.rb | 6 +- test/controllers/trips_controller_test.rb | 97 +++++++++++--- test/models/driver_test.rb | 156 +++++++++++----------- test/models/passenger_test.rb | 121 ++++++++--------- 4 files changed, 219 insertions(+), 161 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 53d095236..809dfc842 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -5,7 +5,7 @@ class Driver < ApplicationRecord validates :vin, presence: true def total_earnings - return ( self.trips.sum{ |trip| (trip.cost - 165 ) * 0.8} )/100 + return (self.trips.sum { |trip| (trip.cost - 165) * 0.8 }) / 100 end def average_rating @@ -18,10 +18,10 @@ def average_rating end end - if count = 0 + if count == 0 return "This driver has no ratings" else - return total_rating/count + return total_rating / count end end end diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index c004f9d20..e62f487d5 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -1,23 +1,84 @@ -# require "test_helper" +require "test_helper" -# describe TripsController do -# describe "show" do -# # Your tests go here -# end +describe TripsController do + describe "show" do + it "must respond with success when showing a specific trip by its ID" do + trip = Trip.create date: Date.today, rating: 5, cost: 2300, driver_id: 1, passenger_id: 5 -# describe "create" do -# # Your tests go here -# end + get trip_path(trip.id) -# describe "edit" do -# # Your tests go here -# end + must_respond_with :success + end -# describe "update" do -# # Your tests go here -# end + it "must respond with a 404 for a non-existing trip" do + invalid_trip_id = 12903 -# describe "destroy" do -# # Your tests go here -# end -# end + get trip_path(invalid_trip_id) + + must_respond_with :not_found + end + end + + describe "create" do + it "can create a new trip with valid information and redirects" do + trip_parameters = Trip.create_new_trip + trip_hash = { + trip: { + passenger_id: params[:passenger_id], + date: trip_parameters[:date], + cost: trip_parameters[:cost], + driver_id: trip_parameters[:driver_id], + }, + } + + expect { + post passenger_trips_path, params: trip_hash + }.must_change "Trip.count", 1 + end + end + + describe "edit" do + before do + @trip = Trip.create date: Date.today, rating: 5, cost: 2300, driver_id: 1, passenger_id: 5 + end + it "responds with success when getting the edit page of an existing trip" do + get edit_trip_path(@trip.id) + + must_respond_with :success + end + + it "responds with redirect when getting the edit page for a non-existing trip" do + get edit_trip_path(-1) + + must_respond_with :redirect + must_redirect_to passenger_path(@trip.passenger.id) + end + end + + describe "update" do + it "can update an existing trip with valid information accurately, and redirect" do + existing_trip = Trip.create date: Date.today, rating: 3, cost: 1240, driver_id: 8, passenger_id: 15 + + updated_trip_hash = { + trip: { + rating: 5, + }, + } + + expect { + patch trip_path(existing_trip.id), params: updated_trip_hash + }.wont_change "Trip.count" + + updated_trip = Trip.find_by(id: existing_trip.id) + + expect(updated_trip.rating).must_equal updated_trip_hash[:trip][:rating] + + must_respond_with :redirect + must_redirect_to passenger_path(updated_trip.passenger.id) + end + end + + describe "destroy" do + # Your tests go here + end +end diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 58797297f..6864232da 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -1,78 +1,78 @@ -require "test_helper" - -describe Driver do - let (:new_driver) { - Driver.new(name: "Kari", vin: "123", available: 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| - expect(trip).must_be_instance_of Trip - 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 - - end - - describe "total earnings" do - - end - - describe "can go online" do - - end - - describe "can go offline" do - - end - end -end +# require "test_helper" + +# describe Driver do +# let (:new_driver) { +# Driver.new(name: "Kari", vin: "123", available: 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| +# expect(trip).must_be_instance_of Trip +# 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 + +# end + +# describe "total earnings" do + +# end + +# describe "can go online" do + +# end + +# describe "can go offline" do + +# end +# end +# end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index aa8bb6112..40a4ac433 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -1,75 +1,72 @@ -require "test_helper" +# require "test_helper" -describe Passenger do - let (:new_passenger) { - Passenger.new(name: "Kari", phone_num: "111-111-1211") - } - it "can be instantiated" do - # Assert - expect(new_passenger.valid?).must_equal true - end +# describe Passenger do +# let (:new_passenger) { +# 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(passenger).must_respond_to field - end - end +# it "will have the required fields" do +# # Arrange +# new_passenger.save +# passenger = Passenger.first +# [:name, :phone_num].each do |field| +# # Assert +# expect(passenger).must_respond_to field +# end +# end - describe "relationships" do - it "can have many trips" do - # Arrange - new_passenger.save - passenger = Passenger.first +# describe "relationships" do +# it "can have many trips" do +# # Arrange +# new_passenger.save +# passenger = Passenger.first - #Note: add instances of trip to passenger - # Assert - expect(passenger.trips.count).must_be :>, 0 - - passenger.trips.each do |trip| - expect(trip).must_be_instance_of Trip - end +# #Note: add instances of trip to passenger +# # Assert +# expect(passenger.trips.count).must_be :>, 0 - end - end +# passenger.trips.each do |trip| +# expect(trip).must_be_instance_of Trip +# 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 +# end +# end - it "must have a phone number" do - # Arrange - new_passenger.phone_num = nil +# 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 :phone_num - expect(new_passenger.errors.messages[:phone_num]).must_equal ["can't be blank"] - end - end +# # 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 - # Tests for methods you create should go here - describe "custom methods" do - describe "request a ride" do - - - end +# it "must have a phone number" do +# # Arrange +# new_passenger.phone_num = nil - describe "total charged method" do +# # 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 - end - end +# end - -end \ No newline at end of file +# describe "total charged method" do + +# end +# end + +# end From 65740183db90ec85c1fe34152e3871bb7f973379 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 13:00:15 -0700 Subject: [PATCH 28/46] Revised average rating method for Driver model and added some tests for TripsController --- test/controllers/trips_controller_test.rb | 66 +++++------------------ 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index e62f487d5..83a2b25b7 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -1,11 +1,23 @@ require "test_helper" describe TripsController do + before do + @passenger = Passenger.create name: "A Passenger", phone_num: "206-123-3333" + @available_driver = Driver.create name: "Random Driver", vin: "XFHJKDHSLFKJDKL", available: true + end describe "show" do it "must respond with success when showing a specific trip by its ID" do - trip = Trip.create date: Date.today, rating: 5, cost: 2300, driver_id: 1, passenger_id: 5 + trip_parameters = Trip.create_new_trip + trip = Trip.new( + passenger_id: @passenger.id, + date: trip_parameters[:date], + cost: trip_parameters[:cost], + driver_id: @available_driver.id, + ) + + trip.save - get trip_path(trip.id) + get trips_path(trip.id) must_respond_with :success end @@ -20,62 +32,12 @@ end describe "create" do - it "can create a new trip with valid information and redirects" do - trip_parameters = Trip.create_new_trip - trip_hash = { - trip: { - passenger_id: params[:passenger_id], - date: trip_parameters[:date], - cost: trip_parameters[:cost], - driver_id: trip_parameters[:driver_id], - }, - } - - expect { - post passenger_trips_path, params: trip_hash - }.must_change "Trip.count", 1 - end end describe "edit" do - before do - @trip = Trip.create date: Date.today, rating: 5, cost: 2300, driver_id: 1, passenger_id: 5 - end - it "responds with success when getting the edit page of an existing trip" do - get edit_trip_path(@trip.id) - - must_respond_with :success - end - - it "responds with redirect when getting the edit page for a non-existing trip" do - get edit_trip_path(-1) - - must_respond_with :redirect - must_redirect_to passenger_path(@trip.passenger.id) - end end describe "update" do - it "can update an existing trip with valid information accurately, and redirect" do - existing_trip = Trip.create date: Date.today, rating: 3, cost: 1240, driver_id: 8, passenger_id: 15 - - updated_trip_hash = { - trip: { - rating: 5, - }, - } - - expect { - patch trip_path(existing_trip.id), params: updated_trip_hash - }.wont_change "Trip.count" - - updated_trip = Trip.find_by(id: existing_trip.id) - - expect(updated_trip.rating).must_equal updated_trip_hash[:trip][:rating] - - must_respond_with :redirect - must_redirect_to passenger_path(updated_trip.passenger.id) - end end describe "destroy" do From d042bc3526785edd22376ec3225ab38bda036949 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 13:57:32 -0700 Subject: [PATCH 29/46] Added tests for Trip, Driver, and Passenger controllers --- app/controllers/trips_controller.rb | 6 +- test/controllers/drivers_controller_test.rb | 45 +++----- .../controllers/passengers_controller_test.rb | 45 +++++--- test/controllers/trips_controller_test.rb | 109 ++++++++++++++++-- 4 files changed, 148 insertions(+), 57 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 5c63afa41..266b59100 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -45,7 +45,7 @@ def edit @trip = Trip.find_by(id: params[:id]) if @trip.nil? - redirect_to passenger_path(@trip.passenger.id) + redirect_to passengers_path return end end @@ -68,12 +68,12 @@ def destroy @trip = Trip.find_by(id: params[:id]) if @trip.nil? - redirect_to passenger_path(@trip.passenger.id) + redirect_to passengers_path return end @trip.destroy - redirect_to passenger_path(@trip.passenger.id) + redirect_to passengers_path return end diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 6cc18f60e..64db0d365 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -54,8 +54,8 @@ driver: { name: "Bob's Burgers", vin: "FDJSKFJD84938", - available: true - } + available: true, + }, } expect { @@ -69,7 +69,6 @@ must_respond_with :redirect 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 @@ -79,8 +78,8 @@ driver_hash = { driver: { vin: "FDJSKFJD84938", - available: true - } + available: true, + }, } expect { @@ -93,7 +92,6 @@ # Assert # Check that the controller redirects must_respond_with :success - end end @@ -121,7 +119,6 @@ describe "update" do it "can update an existing driver with valid information accurately, and redirect" do - existing_driver = Driver.create name: "Harry Potter", vin: "HOGWA4RT$" updated_driver_hash = { @@ -160,12 +157,11 @@ end it "does not create a driver if the form data violates Driver validations, and responds with a redirect" do - existing_driver = Driver.create name: "Harry Potter", vin: "HOGWA4RT$" updated_driver_hash = { driver: { - name: "Ron Weasley" - } + name: "Ron Weasley", + }, } expect { @@ -176,33 +172,30 @@ must_respond_with :redirect must_redirect_to driver_path(driver_id) - 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 + before do + @driver_to_be_deleted = Driver.create!(name: "Freddy Krueger", vin: "ASDJ2343") + end - # Assert - # Check that the controller redirects + it "destroys the driver instance in db when driver exists, then redirects" do + expect { + delete driver_path(@driver_to_be_deleted.id) + }.must_change "Driver.count", 1 + must_respond_with :redirect + 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_driver_id = -1 - # Act-Assert - # Ensure that there is no change in Driver.count - - # Assert - # Check that the controller responds or redirects with whatever your group decides + delete driver_path(invalid_driver_id) + must_respond_with :redirect + must_redirect_to drivers_path end end end diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb index 25495df8d..34867dd9a 100644 --- a/test/controllers/passengers_controller_test.rb +++ b/test/controllers/passengers_controller_test.rb @@ -3,7 +3,6 @@ describe PassengersController do describe "index" do it "responds with success when there are many passengers saved" do - new_passenger = Passenger.create name: "Random name", phone_num: "206-123-3333" get passengers_path @@ -48,11 +47,10 @@ describe "create" do it "can create a new passenger with valid information accurately, and redirect" do - passenger_hash = { passenger: { name: "Bob's Burgers", - phone_num: "XXX-XXX-XXXX" + phone_num: "XXX-XXX-XXXX", }, } @@ -71,21 +69,20 @@ it "does not create a passenger if the form data violates Passenger validations, and responds with a redirect" do passenger_hash = { passenger: { - phone_num: "XXX-XXX-XXX" - } + phone_num: "XXX-XXX-XXX", + }, } expect { post passengers_path, params: passenger_hash }.wont_change "Passenger.count" - must_respond_with :success + must_respond_with :success end end describe "edit" do it "responds with success when getting the edit page for an existing, valid passenger" do - @passenger = Passenger.create name: "Random name", phone_num: "XXX-XXX-XXXX" get edit_passenger_path(@passenger.id) @@ -94,7 +91,6 @@ 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 @@ -104,13 +100,12 @@ describe "update" do it "can update an existing passenger with valid information accurately, and redirect" do - existing_passenger = Passenger.create name: "Harry Potter", phone_num: "aaa-aaa-aaaa" updated_passenger_hash = { passenger: { name: "Ron Weasley", - phone_num: "zzz-zzz-zzzz" + phone_num: "zzz-zzz-zzzz", }, } @@ -125,15 +120,13 @@ must_respond_with :redirect must_redirect_to passenger_path(updated_passenger) - end it "does not update any passenger if given an invalid id, and responds with a 404" do - updated_passenger_hash = { passenger: { name: "Ron Weasley", - phone_num: "zzz-zzz-zzzz" + phone_num: "zzz-zzz-zzzz", }, } @@ -142,8 +135,6 @@ patch passenger_path(invalid_passenger_id), params: updated_passenger_hash 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 @@ -152,8 +143,8 @@ updated_passenger_hash = { passenger: { - name: "Ron Weasley" - } + name: "Ron Weasley", + }, } expect { @@ -168,6 +159,26 @@ end describe "destroy" do + before do + @passenger_to_be_deleted = Passenger.create!(name: "Freddy Krueger", phone_num: "(206)-111-2222") + end + + it "destroys the passenger instance in db when passenger exists, then redirects" do + expect { + delete passenger_path(@passenger_to_be_deleted.id) + }.must_change "Passenger.count", 1 + + must_respond_with :redirect + must_redirect_to passengers_path + end + + it "does not change the db when the passenger does not exist, then responds with redirect" do + invalid_passenger_id = -1 + + delete passenger_path(invalid_passenger_id) + must_respond_with :redirect + must_redirect_to passengers_path + end end end diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb index 83a2b25b7..970c3d7ed 100644 --- a/test/controllers/trips_controller_test.rb +++ b/test/controllers/trips_controller_test.rb @@ -4,20 +4,18 @@ before do @passenger = Passenger.create name: "A Passenger", phone_num: "206-123-3333" @available_driver = Driver.create name: "Random Driver", vin: "XFHJKDHSLFKJDKL", available: true + @trip = Trip.new( + passenger_id: @passenger.id, + date: Date.today, + cost: 1000, + driver_id: @available_driver.id, + ) end describe "show" do it "must respond with success when showing a specific trip by its ID" do - trip_parameters = Trip.create_new_trip - trip = Trip.new( - passenger_id: @passenger.id, - date: trip_parameters[:date], - cost: trip_parameters[:cost], - driver_id: @available_driver.id, - ) + @trip.save - trip.save - - get trips_path(trip.id) + get trip_path(@trip.id) must_respond_with :success end @@ -32,15 +30,104 @@ end describe "create" do + it "can create a new trip with valid inputs" do + new_trip_hash = { + trip: { + passenger_id: @passenger.id, + date: Date.today, + cost: 1500, + driver_id: @available_driver.id, + }, + } + + expect { + post passenger_trips_path(@passenger.id), params: new_trip_hash + }.must_change "Trip.count", 1 + + new_trip = Trip.find(Trip.last.id) + + expect(new_trip.passenger_id).must_equal new_trip_hash[:trip][:passenger_id] + + must_respond_with :redirect + must_redirect_to passenger_path(@passenger.id) + end end describe "edit" do + it "can get the edit page for an existing trip" do + @trip.save + + get edit_trip_path(@trip.id) + + must_respond_with :success + end + + it "it will respond with a redirect when attempting to edit a non-existing trip" do + invalid_trip_id = -1 + + get edit_trip_path(invalid_trip_id) + + must_respond_with :redirect + must_redirect_to passengers_path + end end describe "update" do + it "can update an existing trip" do + updated_trip = { + trip: { + passenger_id: @passenger.id, + date: Date.today, + cost: 2000, + driver_id: @available_driver.id, + }, + } + + @trip.save + + trip_id = @trip.id + patch trip_path(trip_id), params: updated_trip + + edited_trip = Trip.find_by(id: trip_id) + expect(edited_trip.passenger_id).must_equal updated_trip[:trip][:passenger_id] + expect(edited_trip.cost).must_equal updated_trip[:trip][:cost] + end + + it "will redirect to the list of trips if given an invalid ID" do + # Your code here + invalid_trip_id = -1 + patch trip_path(invalid_trip_id), params: @updated_trip + + must_respond_with :not_found + end end describe "destroy" do - # Your tests go here + before do + @trip_to_be_deleted = Trip.create!(passenger_id: @passenger.id, date: Date.today, cost: 3000, driver_id: @available_driver.id) + end + it "can delete an existing trip" do + expect { + delete trip_path(@trip_to_be_deleted.id) + }.must_change "Trip.count", 1 + + must_respond_with :redirect + must_redirect_to passengers_path + end + + it "must respond with 'not found' if given an invalid ID" do + invalid_trip_id = 23152 + + delete trip_path(invalid_trip_id) + + must_respond_with :redirect + must_redirect_to passengers_path + end + + it "won't change the driver and passenger count when a trip is destroyed" do + expect { + delete trip_path(@trip_to_be_deleted.id) + }.wont_change "Driver.count" + end end end From aee2d05e96216afe0f82d27e72da25d3620ff7c3 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 14:39:43 -0700 Subject: [PATCH 30/46] Added tests for passenger and driver controllers and models. Created toggle available and toggle unavailable controller methods --- app/controllers/drivers_controller.rb | 24 +++ app/models/driver.rb | 2 +- config/routes.rb | 21 +-- test/controllers/drivers_controller_test.rb | 38 +++- test/models/driver_test.rb | 190 ++++++++++++-------- 5 files changed, 177 insertions(+), 98 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 6f0ca421f..ef2138340 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -65,6 +65,30 @@ def destroy return end + def toggle_available + @driver = Driver.find_by(id: params[:id]) + + if @driver.nil? + redirect_to drivers_path + else + @driver.available = true + @driver.save + redirect_to driver_path(@driver) + end + end + + def toggle_unavailable + @driver = Driver.find_by(id: params[:id]) + + if @driver.nil? + redirect_to drivers_path + else + @driver.available = false + @driver.save + redirect_to driver_path(@driver) + end + end + private def driver_params diff --git a/app/models/driver.rb b/app/models/driver.rb index 809dfc842..ab086485b 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -21,7 +21,7 @@ def average_rating if count == 0 return "This driver has no ratings" else - return total_rating / count + return total_rating.to_f / count end end end diff --git a/config/routes.rb b/config/routes.rb index 35d1dbb5f..49eb697d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,27 +4,14 @@ resources :drivers do resources :trips, only: [:index] end - # get "/drivers", to: "drivers#index", as: :drivers - # post "/drivers", to: "drivers#create" - # get "/drivers/new", to: "drivers#new", as: :new_driver - # get "/drivers/:id", to: "drivers#show", as: :driver - # patch "/drivers/:id", to: "drivers#update" - # delete "/drivers/:id", to: "drivers#destroy" - # get "/drivers/:id/edit", to: "drivers#edit", as: :edit_driver + + patch "/drivers/:id/available", to: "drivers#toggle_available", as: "make_available" + + patch "/drivers/:id/unavailable", to: "drivers#toggle_unavailable", as: "make_unavailable" resources :passengers do resources :trips, only: [:index, :create] end resources :trips, except: [:create, :new] - - # get "/passengers", to: "passengers#index", as: :passengers - # post "/passengers", to: "passengers#create" - # get "/passengers/new", to: "passengers#new", as: :new_passenger - # get "/passengers/:id", to: "passengers#show", as: :passenger - # patch "/passengers/:id", to: "passengers#update" - # delete "/passengers/:id", to: "passengers#destroy" - # get "/passengers/:id/edit", to: "passengers#edit", as: :edit_passenger - - # get "/trips", to: "trips#index", as: :trips end diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb index 64db0d365..c458bec8c 100644 --- a/test/controllers/drivers_controller_test.rb +++ b/test/controllers/drivers_controller_test.rb @@ -1,7 +1,6 @@ require "test_helper" 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 @@ -28,7 +27,6 @@ get driver_path(@driver.id) must_respond_with :success - # must_redirect_to driver_path(@driver.id) end it "responds with 404 with an invalid driver id" do @@ -198,4 +196,40 @@ must_redirect_to drivers_path end end + + describe "can change driver status" do + before do + @new_driver = Driver.create!(name: "Ghost Driver", vin: "ASDJ2343") + end + + it "can go online" do + @new_driver.update(available: false) + + patch make_available_path(@new_driver.id) + + expect((Driver.find(@new_driver.id)).available).must_equal true + must_respond_with :redirect + must_redirect_to driver_path(@new_driver.id) + end + + it "can go offline" do + @new_driver.update(available: true) + + patch make_unavailable_path(@new_driver.id) + + expect((Driver.find(@new_driver.id)).available).must_equal false + must_respond_with :redirect + must_redirect_to driver_path(@new_driver.id) + end + + it "if driver not specified, redirects to drivers list" do + invalid_driver_id = -1 + + patch make_available_path(invalid_driver_id) + + must_respond_with :redirect + must_redirect_to drivers_path + end + end + end diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 6864232da..858958cf0 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -1,78 +1,112 @@ -# require "test_helper" - -# describe Driver do -# let (:new_driver) { -# Driver.new(name: "Kari", vin: "123", available: 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| -# expect(trip).must_be_instance_of Trip -# 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 - -# end - -# describe "total earnings" do - -# end - -# describe "can go online" do - -# end - -# describe "can go offline" do - -# end -# end -# end +require "test_helper" + +describe Driver do + let (:new_driver) { + Driver.new(name: "Kari", vin: "123") + } + + it "can be instantiated" do + expect(new_driver.valid?).must_equal true + end + + it "will have the required fields" do + new_driver.save + driver = Driver.first + [:name, :vin, :available].each do |field| + + 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| + expect(trip).must_be_instance_of Trip + 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 + let (:new_passenger) { + Passenger.new(name: "Chris", phone_num: "123-333-3333") + } + + before do + new_passenger.save + new_driver.save + @trip1 = Trip.create( + passenger_id: new_passenger.id, + date: Date.today, + cost: 1000, + rating: 5, + driver_id: new_driver.id, + ) + + @trip2 = Trip.create( + passenger_id: new_passenger.id, + date: Date.today, + cost: 1500, + rating: 4, + driver_id: new_driver.id, + ) + + @trip3 = Trip.create( + passenger_id: new_passenger.id, + date: Date.today, + cost: 1500, + rating: 3, + driver_id: new_driver.id, + ) + end + describe "average rating" do + it "calculates average rating for driver with ratings" do + expect(new_driver.average_rating).must_equal 4.0 + end + + it "returns 'driver has no rating' for driver without ratings" do + driver_no_trips = Driver.create(name: "It", vin: "123") + expect(driver_no_trips.average_rating).must_equal "This driver has no ratings" + end + end + + describe "total earnings" do + it "totals earnings for driver" do + expect(new_driver.total_earnings).must_equal (( @trip1.cost + @trip2.cost + @trip3.cost - ( 3 * 165 )) * 0.8 ) / 100 + end + + it "returns 0 when no earnings" do + driver_no_trips = Driver.create(name: "It", vin: "123") + expect(driver_no_trips.total_earnings).must_equal 0 + end + end + end +end From 74e96567a41970f3ce29120bc07c066c4244827b Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 14:46:52 -0700 Subject: [PATCH 31/46] Updated Passenger model tests --- test/models/passenger_test.rb | 182 ++++++++++++++++++++-------------- test/models/trip_test.rb | 38 +++---- 2 files changed, 129 insertions(+), 91 deletions(-) diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb index 40a4ac433..b613b298b 100644 --- a/test/models/passenger_test.rb +++ b/test/models/passenger_test.rb @@ -1,72 +1,110 @@ -# require "test_helper" - -# describe Passenger do -# let (:new_passenger) { -# 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(passenger).must_respond_to field -# end -# end - -# describe "relationships" do -# it "can have many trips" do -# # Arrange -# new_passenger.save -# passenger = Passenger.first - -# #Note: add instances of trip to passenger -# # 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 - -# 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 - -# end - -# describe "total charged method" do - -# end -# end - -# end +require "test_helper" + +describe Passenger do + let (:new_passenger) { + Passenger.new(name: "Kari", phone_num: "111-111-1211") + } + + it "can be instantiated" do + 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(passenger).must_respond_to field + end + end + + describe "relationships" do + it "can have many trips" do + # Arrange + new_passenger.save + passenger = Passenger.first + new_driver = Driver.create(name: "Kari", vin: "123") + + @trip1 = Trip.create( + passenger_id: passenger.id, + date: Date.today, + cost: 1000, + rating: 5, + driver_id: new_driver.id, + ) + + @trip2 = Trip.create( + passenger_id: passenger.id, + date: Date.today, + cost: 1500, + rating: 4, + driver_id: new_driver.id, + ) + + 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 + + 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 "total charged method" do + before do + new_passenger.save + new_driver = Driver.create(name: "Kari", vin: "123") + @trip1 = Trip.create( + passenger_id: new_passenger.id, + date: Date.today, + cost: 1000, + rating: 5, + driver_id: new_driver.id, + ) + + @trip2 = Trip.create( + passenger_id: new_passenger.id, + date: Date.today, + cost: 1500, + rating: 4, + driver_id: new_driver.id, + ) + end + + it "calculates total charged in trips for passenger" do + expect(new_passenger.total_charged).must_equal @trip1.cost + @trip2.cost + end + + it "returns 0 if no trips for passenger" do + passenger_no_trips = Passenger.create(name: "Ghost Passenger", phone_num: "111-111-1211") + + expect(passenger_no_trips.total_charged).must_equal 0 + end + end + end +end diff --git a/test/models/trip_test.rb b/test/models/trip_test.rb index acbfa7f4b..0b0b2da32 100644 --- a/test/models/trip_test.rb +++ b/test/models/trip_test.rb @@ -1,24 +1,24 @@ -# require "test_helper" +require "test_helper" -# describe Trip do -# it "can be instantiated" do -# # Your code here -# end +describe Trip do + it "can be instantiated" do + # Your code here + end -# it "will have the required fields" do -# # Your code here -# end + it "will have the required fields" do + # Your code here + end -# describe "relationships" do -# # Your tests go here -# end + describe "relationships" do + # Your tests go here + end -# describe "validations" do -# # Your tests go here -# end + describe "validations" do + # Your tests go here + end -# # Tests for methods you create should go here -# describe "custom methods" do -# # Your tests here -# end -# end + # Tests for methods you create should go here + describe "custom methods" do + # Your tests here + end +end From 01947b06f3a703cffe5615c07ce054815096a4f8 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 15:01:43 -0700 Subject: [PATCH 32/46] Updated Trip model tests --- app/models/trip.rb | 1 + test/models/trip_test.rb | 45 +++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/models/trip.rb b/app/models/trip.rb index 1f247b628..c7ea2900e 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -6,6 +6,7 @@ def self.create_new_trip driver = Driver.all.find { |driver| driver.available } date = Date.today cost = rand(1000..5000) + driver.update(available: false) return { driver_id: driver.id, date: date, cost: cost } end diff --git a/test/models/trip_test.rb b/test/models/trip_test.rb index 0b0b2da32..5029d0b18 100644 --- a/test/models/trip_test.rb +++ b/test/models/trip_test.rb @@ -1,24 +1,49 @@ require "test_helper" describe Trip do + before do + @driver = Driver.create(name: "Jelly Bean", vin: "4839204380") + @passenger = Passenger.create(name: "Chucky", phone_num: "222-222-2222") + end + + let (:new_trip) { + Trip.new(passenger_id: @passenger.id, driver_id: @driver.id, cost: 1000, date: Date.today) + } + it "can be instantiated" do - # Your code here + expect(new_trip.valid?).must_equal true end it "will have the required fields" do - # Your code here + new_trip.save + trip = Trip.first + [:passenger_id, :driver_id, :cost, :date].each do |field| + expect(trip).must_respond_to field + end end describe "relationships" do - # Your tests go here - end - - describe "validations" do - # Your tests go here + it "has Driver and Passenger" do + new_trip.save + expect(new_trip.passenger).must_be_instance_of Passenger + expect(new_trip.driver).must_be_instance_of Driver + end end # Tests for methods you create should go here - describe "custom methods" do - # Your tests here - end + # describe "custom methods" do + # before do + # @driver_unavailable = Driver.create(name: "XX", vin: "4839204380", available: false) + # @driver_available = Driver.create(name: "JJ", vin: "4839204380", available: true) + + # @passenger = Passenger.create(name: "Chucky", phone_num: "222-222-2222") + # end + + # it "create trip method finds first available driver" do + # Trip.create_new_trip(@passenger.id) + + # expect(@driver_available.available).must_equal false + # end + + # end end From 92c630767197899e14875bf3f223502cd2c98763 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 15:06:22 -0700 Subject: [PATCH 33/46] Added toggle available/unavailable to Driver show view --- app/views/drivers/show.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 4820e4756..550bbff74 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -4,6 +4,12 @@

      Total Earnings: <%= @driver.total_earnings %>

      Average Rating: <%= @driver.average_rating %>

      +<% if @driver.available %> + <%= link_to "Make Unavailable", make_unavailable_path(@driver.id), method: :patch %>
      +<% else %> + <%= link_to "Make Available", make_available_path(@driver.id), method: :patch %>
      +<%end%> + <%= link_to "Edit Driver", edit_driver_path(@driver) %>
      <%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %>
      From 9402e57b6c2de4f1a9ba36ddf34217e260ee19b8 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 15:33:38 -0700 Subject: [PATCH 34/46] Updated Driver and Trips views, removed index route for Trip, updated cost format in seeds.rb --- app/controllers/trips_controller.rb | 12 ------------ app/models/driver.rb | 2 +- app/views/drivers/show.html.erb | 4 ++-- app/views/trips/edit.html.erb | 2 +- app/views/trips/index.html.erb | 30 ----------------------------- config/routes.rb | 2 +- db/seeds.rb | 2 +- test/models/driver_test.rb | 8 ++++---- 8 files changed, 10 insertions(+), 52 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 266b59100..8e151a184 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,16 +1,4 @@ class TripsController < ApplicationController - def index - if params[:passenger_id] - passenger = Passenger.find_by(id: params[:passenger_id]) - @trips = passenger.trips - elsif params[:driver_id] - driver = Driver.find_by(id: params[:driver_id]) - @driver = driver.trips - else - @trips = Trip.all - end - end - def show @trip = Trip.find_by(id: params[:id]) diff --git a/app/models/driver.rb b/app/models/driver.rb index ab086485b..55c29c654 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -5,7 +5,7 @@ class Driver < ApplicationRecord validates :vin, presence: true def total_earnings - return (self.trips.sum { |trip| (trip.cost - 165) * 0.8 }) / 100 + return (self.trips.sum { |trip| (trip.cost - 1.65) * 0.8 }) end def average_rating diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 550bbff74..d107db5e8 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,8 +1,8 @@

      Driver name: <%= @driver.name %>

      VIN: <%= @driver.vin %>

      Status: <%= @driver.available %>

      -

      Total Earnings: <%= @driver.total_earnings %>

      -

      Average Rating: <%= @driver.average_rating %>

      +

      Total Earnings: $<%= "%.2f" % @driver.total_earnings %>

      +

      Average Rating: <%= "%.2f" % @driver.average_rating %>

      <% if @driver.available %> <%= link_to "Make Unavailable", make_unavailable_path(@driver.id), method: :patch %>
      diff --git a/app/views/trips/edit.html.erb b/app/views/trips/edit.html.erb index e886b2187..e9e3e0cd4 100644 --- a/app/views/trips/edit.html.erb +++ b/app/views/trips/edit.html.erb @@ -6,7 +6,7 @@ <%= f.text_field :cost %>
      <%= f.label :rating %> - <%= f.text_field :rating %>
      + <%= f.select :rating, [1, 2, 3, 4, 5] %>
      <%= f.submit "Edit Trip", class: "trip-button" %> <% end %> \ No newline at end of file diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb deleted file mode 100644 index c4940134a..000000000 --- a/app/views/trips/index.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -

      <%= @trips[0].passenger.name %>'s Trips

      - -<%= link_to "Create a new trip", passenger_trips_path(params[:passenger_id]), method: :post %> - -
      -
      -
      - - - - - - - - - - <% @trips.each do |trip| %> - - - - - - - - - <% end %> -
      IDDatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      -
      -
      -
      \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 49eb697d0..40184125e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,5 +13,5 @@ resources :trips, only: [:index, :create] end - resources :trips, except: [:create, :new] + resources :trips, except: [:create, :new, :index] end diff --git a/db/seeds.rb b/db/seeds.rb index eab2a92ee..b1273a7bc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -57,7 +57,7 @@ trip.passenger_id = row['passenger_id'] trip.date = Date.strptime(row['date'], '%Y-%m-%d') trip.rating = row['rating'] - trip.cost = row['cost'] + trip.cost = (row['cost'].to_f / 100.0) successful = trip.save if !successful trip_failures << trip diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 858958cf0..83ce24e01 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -66,7 +66,7 @@ @trip1 = Trip.create( passenger_id: new_passenger.id, date: Date.today, - cost: 1000, + cost: 10.00, rating: 5, driver_id: new_driver.id, ) @@ -74,7 +74,7 @@ @trip2 = Trip.create( passenger_id: new_passenger.id, date: Date.today, - cost: 1500, + cost: 15.00, rating: 4, driver_id: new_driver.id, ) @@ -82,7 +82,7 @@ @trip3 = Trip.create( passenger_id: new_passenger.id, date: Date.today, - cost: 1500, + cost: 15.00, rating: 3, driver_id: new_driver.id, ) @@ -100,7 +100,7 @@ describe "total earnings" do it "totals earnings for driver" do - expect(new_driver.total_earnings).must_equal (( @trip1.cost + @trip2.cost + @trip3.cost - ( 3 * 165 )) * 0.8 ) / 100 + expect(new_driver.total_earnings).must_equal ( @trip1.cost + @trip2.cost + @trip3.cost - ( 3 * 1.65 )) * 0.8 end it "returns 0 when no earnings" do From 9f2860291d044184c57cd0c97cfe35522f4763fc Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 15:59:36 -0700 Subject: [PATCH 35/46] Edited view files for Driver, Passenger, added Homepages Controller Test --- app/controllers/drivers_controller.rb | 10 ++++++---- app/models/driver.rb | 2 +- app/views/drivers/_form.html.erb | 11 +++++++++++ app/views/drivers/new.html.erb | 10 ---------- app/views/passengers/_form.html.erb | 11 +++++++++++ app/views/passengers/show.html.erb | 2 +- test/controllers/homepages_controller_test.rb | 12 ++++++------ test/models/driver_test.rb | 2 +- 8 files changed, 37 insertions(+), 23 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index ef2138340..62ecfa3af 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -46,10 +46,12 @@ def update return end - @driver.update(driver_params) - - redirect_to driver_path(@driver) - return + if @driver.update(driver_params) + redirect_to driver_path(@driver) + return + else + render "new" + end end def destroy diff --git a/app/models/driver.rb b/app/models/driver.rb index 55c29c654..a465f3d48 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -19,7 +19,7 @@ def average_rating end if count == 0 - return "This driver has no ratings" + return 0 else return total_rating.to_f / count end diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index b59256360..e0ad1d1e1 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -1,3 +1,14 @@ +<% if @driver.errors.any? %> +

      Errors

      +
        + <% @driver.errors.each do |column, message| %> +
      • + <%= column.capitalize %> <%= message %> +
      • + <% end %> +
      +<% end %> + <%= form_with model: @driver, class: "#{action_name}-driver" do |f| %> <%= f.label :name %>
      <%= f.text_field :name %>
      diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index 85989f015..e9254372d 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -1,11 +1 @@ -<% if @driver.errors.any? %> -
        - <% @driver.errors.each do |column, message| %> -
      • - <%= column.capitalize %> <%= message %> -
      • - <% end %> -
      -<% end %> - <%= render :partial => "drivers/form", locals: { action_name: "create" } %> \ No newline at end of file diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb index 915157dcd..3071926df 100644 --- a/app/views/passengers/_form.html.erb +++ b/app/views/passengers/_form.html.erb @@ -1,3 +1,14 @@ +<% if @passenger.errors.any? %> +

      Errors

      +
        + <% @passenger.errors.each do |column, message| %> +
      • + <%= column.capitalize %> <%= message %> +
      • + <% end %> +
      +<% end %> + <%= form_with model: @passenger, class: "#{action_name}-passenger" do |f| %> <%= f.label :name %> <%= f.text_field :name %>
      diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index f8177201d..0457a1649 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,6 +1,6 @@

      Passenger name: <%= @passenger.name %>

      Phone Number: <%= @passenger.phone_num %>

      -

      Total Charged: $<%= @passenger.total_charged/100 %>

      +

      Total Charged: $<%= @passenger.total_charged %>

      <%= link_to "Edit Passenger", edit_passenger_path(@passenger) %>
      <%= link_to "Delete Passenger", passenger_path(@passenger), method: :delete, data: { confirm: "Are you sure you want to delete this passenger?" } %>
      <%= link_to "Create a new trip", passenger_trips_path(@passenger.id), method: :post %>
      diff --git a/test/controllers/homepages_controller_test.rb b/test/controllers/homepages_controller_test.rb index 6dc5fd65f..9dd7648db 100644 --- a/test/controllers/homepages_controller_test.rb +++ b/test/controllers/homepages_controller_test.rb @@ -1,9 +1,9 @@ require "test_helper" -# describe HomepagesController do -# it "can get the homepage" do -# get root_path +describe HomepagesController do + it "can get the homepage" do + get root_path -# must_respond_with :success -# end -# end + must_respond_with :success + end +end diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb index 83ce24e01..1032b6d16 100644 --- a/test/models/driver_test.rb +++ b/test/models/driver_test.rb @@ -94,7 +94,7 @@ it "returns 'driver has no rating' for driver without ratings" do driver_no_trips = Driver.create(name: "It", vin: "123") - expect(driver_no_trips.average_rating).must_equal "This driver has no ratings" + expect(driver_no_trips.average_rating).must_equal 0 end end From fe5b629d4f9dcc6a519f7e9d348ba7de8f6572cb Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Thu, 10 Oct 2019 16:15:18 -0700 Subject: [PATCH 36/46] Updated schema to include default available driver column --- .../20191010231326_change_drivers_available_default.rb | 5 +++++ db/schema.rb | 4 ++-- db/seeds.rb | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20191010231326_change_drivers_available_default.rb diff --git a/db/migrate/20191010231326_change_drivers_available_default.rb b/db/migrate/20191010231326_change_drivers_available_default.rb new file mode 100644 index 000000000..86d341584 --- /dev/null +++ b/db/migrate/20191010231326_change_drivers_available_default.rb @@ -0,0 +1,5 @@ +class ChangeDriversAvailableDefault < ActiveRecord::Migration[5.2] + def change + change_column :drivers, :available, :boolean, :default => true + end +end diff --git a/db/schema.rb b/db/schema.rb index 6a6d1c54f..491347219 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_09_212940) do +ActiveRecord::Schema.define(version: 2019_10_10_231326) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -18,7 +18,7 @@ create_table "drivers", force: :cascade do |t| t.string "name" t.string "vin" - t.boolean "available" + t.boolean "available", default: true t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/db/seeds.rb b/db/seeds.rb index b1273a7bc..fd821de3e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -58,6 +58,7 @@ trip.date = Date.strptime(row['date'], '%Y-%m-%d') trip.rating = row['rating'] trip.cost = (row['cost'].to_f / 100.0) + successful = trip.save if !successful trip_failures << trip From bac16c2e1be52b31b825823f12f074489d884fde Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 18:57:58 -0700 Subject: [PATCH 37/46] Styled buttons for creating a new driver and passenger in their index.html.erb files --- app/assets/stylesheets/application.css | 20 ++++++++++++++++++++ app/views/drivers/index.html.erb | 4 +++- app/views/passengers/index.html.erb | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 4ca56186c..d95086e90 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -78,4 +78,24 @@ table, th, td { border: 1px solid black; +} + +.create-button { + display: flex; + flex-direction: row; + justify-content: center; + padding-bottom: 25px; +} + +.create-button a { + border: 2px solid lightgrey; + background-color: #3e8e41; + color: white; + padding: 18px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + border-radius: 12px; + margin-bottom: 0; } \ No newline at end of file diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index a7b7fb7ad..f1c13b27d 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,6 +1,8 @@

      List of Drivers

      -<%= link_to "Create a new Driver", new_driver_path %> +
      + <%= link_to "Create a new Driver", new_driver_path %> +
      diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index af52c4a19..7de7daf36 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,6 +1,8 @@

      List of Passengers

      -<%= link_to "Create a new Passenger", new_passenger_path %> +
      + <%= link_to "Create a new Passenger", new_passenger_path %> +
      From 4c1428c49a61f546231a60b681018f7dfd21e611 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 20:05:10 -0700 Subject: [PATCH 38/46] Added images to homepage --- app/assets/stylesheets/application.css | 23 ++++++++++++++++++++++- app/views/homepages/index.html.erb | 11 +++++++++++ app/views/passengers/_form.html.erb | 4 ++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d95086e90..ce21024c9 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -35,6 +35,7 @@ display: inline; padding-right: 50px; } + .dropbtn { background-color: #4CAF50; color: white; @@ -87,9 +88,13 @@ table, th, td { padding-bottom: 25px; } +.welcome-background { + background-image: url("https://images.pexels.com/photos/336948/pexels-photo-336948.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=624&w=390") +} + .create-button a { border: 2px solid lightgrey; - background-color: #3e8e41; + background-color: #4CAF50; color: white; padding: 18px 32px; text-align: center; @@ -98,4 +103,20 @@ table, th, td { font-size: 16px; border-radius: 12px; margin-bottom: 0; +} + +.container { + position: relative; +} + +.text-block { + position: absolute; + top: 270px; + left: 80%; + justify-content: center; + background-color: black; + color: white; + padding-left: 20px; + padding-right: 20px; + opacity: 0.8; } \ No newline at end of file diff --git a/app/views/homepages/index.html.erb b/app/views/homepages/index.html.erb index 8fe955446..5691aa66e 100644 --- a/app/views/homepages/index.html.erb +++ b/app/views/homepages/index.html.erb @@ -2,3 +2,14 @@ <%# <%= link_to "View Drivers", drivers_path %> <%# <%= link_to "View Passengers", passengers_path %> +
      +
      + <%= image_tag "https://images.pexels.com/photos/7674/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=640&w=400", alt: "cars in traffic" %> +
      +

      Need a ride?

      +

      Request one through our site!

      +
      +
      +
      + + diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb index 3071926df..907b7bf6b 100644 --- a/app/views/passengers/_form.html.erb +++ b/app/views/passengers/_form.html.erb @@ -10,10 +10,10 @@ <% end %> <%= form_with model: @passenger, class: "#{action_name}-passenger" do |f| %> - <%= f.label :name %> + <%= f.label :name %>
      <%= f.text_field :name %>
      - <%= f.label "Phone Number" %> + <%= f.label "Phone Number" %>
      <%= f.text_field :phone_num %>
      <%= f.submit "#{action_name.capitalize} Passenger", class: "passenger-button" %> From f286f380a86c021c79317cfd65952a4a79f591d8 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 20:19:48 -0700 Subject: [PATCH 39/46] Styled buttons in driver, passenger, and trip show views. Also bolded the field names --- app/assets/stylesheets/application.css | 6 ++---- app/views/drivers/index.html.erb | 2 +- app/views/drivers/show.html.erb | 26 +++++++++++++++++--------- app/views/passengers/index.html.erb | 2 +- app/views/passengers/show.html.erb | 21 +++++++++++++++------ app/views/trips/show.html.erb | 21 +++++++++++++-------- 6 files changed, 49 insertions(+), 29 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ce21024c9..25548fbc3 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -81,18 +81,16 @@ table, th, td { border: 1px solid black; } -.create-button { +.button { display: flex; flex-direction: row; - justify-content: center; - padding-bottom: 25px; } .welcome-background { background-image: url("https://images.pexels.com/photos/336948/pexels-photo-336948.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=624&w=390") } -.create-button a { +.button a { border: 2px solid lightgrey; background-color: #4CAF50; color: white; diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index f1c13b27d..48e2b0bdc 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,6 +1,6 @@

      List of Drivers

      -
      +
      <%= link_to "Create a new Driver", new_driver_path %>
      diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index d107db5e8..f0bf41f1d 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,17 +1,25 @@ -

      Driver name: <%= @driver.name %>

      -

      VIN: <%= @driver.vin %>

      -

      Status: <%= @driver.available %>

      -

      Total Earnings: $<%= "%.2f" % @driver.total_earnings %>

      -

      Average Rating: <%= "%.2f" % @driver.average_rating %>

      +

      Driver name: <%= @driver.name %>

      +

      VIN: <%= @driver.vin %>

      +

      Status: <%= @driver.available %>

      +

      Total Earnings: $<%= "%.2f" % @driver.total_earnings %>

      +

      Average Rating: <%= "%.2f" % @driver.average_rating %>

      <% if @driver.available %> - <%= link_to "Make Unavailable", make_unavailable_path(@driver.id), method: :patch %>
      +
      + <%= link_to "Make Unavailable", make_unavailable_path(@driver.id), method: :patch %> +

      <% else %> - <%= link_to "Make Available", make_available_path(@driver.id), method: :patch %>
      +
      + <%= link_to "Make Available", make_available_path(@driver.id), method: :patch %> +

      <%end%> +
      + <%= link_to "Edit Driver", edit_driver_path(@driver) %> +

      -<%= link_to "Edit Driver", edit_driver_path(@driver) %>
      -<%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %>
      +
      + <%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %> +

      <%= @driver.name %>'s Trips

      diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 7de7daf36..4c8ace3df 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,6 +1,6 @@

      List of Passengers

      -
      +
      <%= link_to "Create a new Passenger", new_passenger_path %>
      diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 0457a1649..18ace8d37 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,9 +1,18 @@ -

      Passenger name: <%= @passenger.name %>

      -

      Phone Number: <%= @passenger.phone_num %>

      -

      Total Charged: $<%= @passenger.total_charged %>

      -<%= link_to "Edit Passenger", edit_passenger_path(@passenger) %>
      -<%= link_to "Delete Passenger", passenger_path(@passenger), method: :delete, data: { confirm: "Are you sure you want to delete this passenger?" } %>
      -<%= link_to "Create a new trip", passenger_trips_path(@passenger.id), method: :post %>
      +

      Passenger name: <%= @passenger.name %>

      +

      Phone Number: <%= @passenger.phone_num %>

      +

      Total Charged: $<%= @passenger.total_charged %>

      + +
      + <%= link_to "Edit Passenger", edit_passenger_path(@passenger) %> +

      + +
      + <%= link_to "Delete Passenger", passenger_path(@passenger), method: :delete, data: { confirm: "Are you sure you want to delete this passenger?" } %> +

      + +
      + <%= link_to "Create a new trip", passenger_trips_path(@passenger.id), method: :post %> +

      <%= @passenger.name %>'s Trips

      diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 49fc2628d..bc2148f05 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -1,11 +1,16 @@

      Trip Details

      -

      Trip ID: <%= @trip.id %>

      -

      Trip Date: <%= @trip.date %>

      -

      Trip Cost: <%= @trip.cost %>

      -

      Trip Rating: <%= @trip.rating %>

      -

      Passenger Name: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>

      -

      Driver Name: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>

      +

      Trip ID: <%= @trip.id %>

      +

      Trip Date: <%= @trip.date %>

      +

      Trip Cost: <%= @trip.cost %>

      +

      Trip Rating: <%= @trip.rating %>

      +

      Passenger Name: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>

      +

      Driver Name: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>

      -<%= link_to "Edit Trip", edit_trip_path(@trip) %>
      -<%= link_to "Delete Trip", trip_path(@trip), method: :delete, data: { confirm: "Are you sure you want to delete this trip?" } %>
      \ No newline at end of file +
      + <%= link_to "Edit Trip", edit_trip_path(@trip) %> +

      + +
      + <%= link_to "Delete Trip", trip_path(@trip), method: :delete, data: { confirm: "Are you sure you want to delete this trip?" } %> +

      \ No newline at end of file From dbd0aae3387fa49cc8bd07086c349b4cb122f862 Mon Sep 17 00:00:00 2001 From: Nicky Choi Date: Thu, 10 Oct 2019 20:25:53 -0700 Subject: [PATCH 40/46] Changed one of the images on the homepage --- app/assets/stylesheets/application.css | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 25548fbc3..2db019dc2 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -87,7 +87,7 @@ table, th, td { } .welcome-background { - background-image: url("https://images.pexels.com/photos/336948/pexels-photo-336948.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=624&w=390") + background-image: url("http://images.pexels.com/photos/699122/pexels-photo-699122.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=624&w=390") } .button a { @@ -109,12 +109,12 @@ table, th, td { .text-block { position: absolute; - top: 270px; - left: 80%; + top: 285px; + left: 73%; justify-content: center; background-color: black; color: white; - padding-left: 20px; - padding-right: 20px; - opacity: 0.8; + padding-left: 30px; + padding-right: 30px; + opacity: 0.9 } \ No newline at end of file From 208584552a1a100a2e2712f08d3d3fcc65535f7e Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Fri, 11 Oct 2019 06:49:18 -0700 Subject: [PATCH 41/46] Adjusted page margins --- app/assets/stylesheets/application.css | 4 ++ app/views/drivers/edit.html.erb | 4 +- app/views/drivers/index.html.erb | 60 +++++++++--------- app/views/drivers/new.html.erb | 4 +- app/views/drivers/show.html.erb | 84 +++++++++++++------------- app/views/homepages/index.html.erb | 2 +- app/views/passengers/edit.html.erb | 4 +- app/views/passengers/index.html.erb | 44 +++++++------- app/views/passengers/new.html.erb | 4 +- app/views/passengers/show.html.erb | 74 ++++++++++++----------- app/views/trips/edit.html.erb | 20 +++--- app/views/trips/show.html.erb | 28 +++++---- 12 files changed, 178 insertions(+), 154 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 2db019dc2..b889c0c52 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -14,6 +14,10 @@ *= require_self */ +.page-container { + padding: 30px; +} + .nav-bar { background-color: lightgrey; } diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb index 6f3f89562..0046127c2 100644 --- a/app/views/drivers/edit.html.erb +++ b/app/views/drivers/edit.html.erb @@ -1 +1,3 @@ -<%= render :partial => "drivers/form", locals: { action_name: "edit" } %> \ No newline at end of file +
      + <%= render :partial => "drivers/form", locals: { action_name: "edit" } %> +
      \ No newline at end of file diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 48e2b0bdc..a9aed9b7e 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,34 +1,36 @@ -

      List of Drivers

      +
      +

      List of Drivers

      -
      - <%= link_to "Create a new Driver", new_driver_path %> -
      +
      + <%= link_to "Create a new Driver", new_driver_path %> +
      -
      -
      -
      - - - - - - - - <% @drivers.each do |driver| %> - - - - - - - <% end %> -
      IDNameVINStatus
      <%= driver.id %> <%= link_to driver.name, driver_path(driver) %> <%= driver.vin %> - <% if driver.available %> - Available - <% else %> - Unavailable - <% end %> -
      +
      +
      +
      + + + + + + + + <% @drivers.each do |driver| %> + + + + + + + <% end %> +
      IDNameVINStatus
      <%= driver.id %> <%= link_to driver.name, driver_path(driver) %> <%= driver.vin %> + <% if driver.available %> + Available + <% else %> + Unavailable + <% end %> +
      +
      diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index e9254372d..7162a62e5 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -1 +1,3 @@ -<%= render :partial => "drivers/form", locals: { action_name: "create" } %> \ No newline at end of file +
      + <%= render :partial => "drivers/form", locals: { action_name: "create" } %> +
      \ No newline at end of file diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index f0bf41f1d..d4e19c6e9 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,52 +1,54 @@ -

      Driver name: <%= @driver.name %>

      -

      VIN: <%= @driver.vin %>

      -

      Status: <%= @driver.available %>

      -

      Total Earnings: $<%= "%.2f" % @driver.total_earnings %>

      -

      Average Rating: <%= "%.2f" % @driver.average_rating %>

      +
      +

      Driver name: <%= @driver.name %>

      +

      VIN: <%= @driver.vin %>

      +

      Status: <%= @driver.available %>

      +

      Total Earnings: $<%= "%.2f" % @driver.total_earnings %>

      +

      Average Rating: <%= "%.2f" % @driver.average_rating %>

      -<% if @driver.available %> + <% if @driver.available %> +
      + <%= link_to "Make Unavailable", make_unavailable_path(@driver.id), method: :patch %> +

      + <% else %> +
      + <%= link_to "Make Available", make_available_path(@driver.id), method: :patch %> +

      + <%end%>
      - <%= link_to "Make Unavailable", make_unavailable_path(@driver.id), method: :patch %> + <%= link_to "Edit Driver", edit_driver_path(@driver) %>

      -<% else %> +
      - <%= link_to "Make Available", make_available_path(@driver.id), method: :patch %> + <%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %>

      -<%end%> -
      - <%= link_to "Edit Driver", edit_driver_path(@driver) %> -

      - -
      - <%= link_to "Delete Driver", driver_path(@driver), method: :delete, data: { confirm: "Are you sure you want to delete this driver?" } %> -

      -

      <%= @driver.name %>'s Trips

      +

      <%= @driver.name %>'s Trips

      -
      -
      -
      - - - - - - - - - - <% @driver.trips.each do |trip| %> - - - - - - - - - <% end %> -
      Trip IDTrip DatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      +
      +
      + + + + + + + + + + <% @driver.trips.each do |trip| %> + + + + + + + + + <% end %> +
      Trip IDTrip DatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      \ No newline at end of file diff --git a/app/views/homepages/index.html.erb b/app/views/homepages/index.html.erb index 5691aa66e..facc0a192 100644 --- a/app/views/homepages/index.html.erb +++ b/app/views/homepages/index.html.erb @@ -2,7 +2,7 @@ <%# <%= link_to "View Drivers", drivers_path %> <%# <%= link_to "View Passengers", passengers_path %> -
      +
      <%= image_tag "https://images.pexels.com/photos/7674/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=640&w=400", alt: "cars in traffic" %>
      diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb index fae04e76d..cb7dc028b 100644 --- a/app/views/passengers/edit.html.erb +++ b/app/views/passengers/edit.html.erb @@ -1 +1,3 @@ -<%= render :partial => "passengers/form", locals: { action_name: "edit" } %> \ No newline at end of file +
      + <%= render :partial => "passengers/form", locals: { action_name: "edit" } %> +
      \ No newline at end of file diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 4c8ace3df..b7e716f67 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,26 +1,28 @@ -

      List of Passengers

      +
      +

      List of Passengers

      -
      - <%= link_to "Create a new Passenger", new_passenger_path %> -
      +
      + <%= link_to "Create a new Passenger", new_passenger_path %> +
      -
      -
      -
      - - - - - - - <% @passengers.each do |passenger| %> - - - - - - <% end %> -
      IDNamePhone Number
      <%= passenger.id %> <%= link_to passenger.name, passenger_path(passenger) %> <%= passenger.phone_num %>
      +
      +
      +
      + + + + + + + <% @passengers.each do |passenger| %> + + + + + + <% end %> +
      IDNamePhone Number
      <%= passenger.id %> <%= link_to passenger.name, passenger_path(passenger) %> <%= passenger.phone_num %>
      +
      \ No newline at end of file diff --git a/app/views/passengers/new.html.erb b/app/views/passengers/new.html.erb index f85bdb1ab..30b0bbce9 100644 --- a/app/views/passengers/new.html.erb +++ b/app/views/passengers/new.html.erb @@ -1 +1,3 @@ -<%= render :partial => "passengers/form", locals: { action_name: "create" } %> \ No newline at end of file +
      + <%= render :partial => "passengers/form", locals: { action_name: "create" } %> +
      \ No newline at end of file diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 18ace8d37..0b186fa7b 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,44 +1,46 @@ -

      Passenger name: <%= @passenger.name %>

      -

      Phone Number: <%= @passenger.phone_num %>

      -

      Total Charged: $<%= @passenger.total_charged %>

      +
      +

      Passenger name: <%= @passenger.name %>

      +

      Phone Number: <%= @passenger.phone_num %>

      +

      Total Charged: $<%= @passenger.total_charged %>

      -
      - <%= link_to "Edit Passenger", edit_passenger_path(@passenger) %> -

      +
      + <%= link_to "Edit Passenger", edit_passenger_path(@passenger) %> +

      -
      - <%= link_to "Delete Passenger", passenger_path(@passenger), method: :delete, data: { confirm: "Are you sure you want to delete this passenger?" } %> -

      +
      + <%= link_to "Delete Passenger", passenger_path(@passenger), method: :delete, data: { confirm: "Are you sure you want to delete this passenger?" } %> +

      -
      - <%= link_to "Create a new trip", passenger_trips_path(@passenger.id), method: :post %> -

      +
      + <%= link_to "Create a new trip", passenger_trips_path(@passenger.id), method: :post %> +

      -

      <%= @passenger.name %>'s Trips

      +

      <%= @passenger.name %>'s Trips

      -
      -
      -
      - - - - - - - - - - <% @passenger.trips.each do |trip| %> - - - - - - - - - <% end %> -
      Trip IDTrip DatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      +
      +
      + + + + + + + + + + <% @passenger.trips.each do |trip| %> + + + + + + + + + <% end %> +
      Trip IDTrip DatePassenger NameDriver NameRatingCost
      <%= link_to trip.id, trip_path(trip.id) %> <%= trip.date %> <%= link_to trip.passenger.name, passenger_path(trip.passenger) %><%= link_to trip.driver.name, driver_path(trip.driver) %><%= trip.rating %><%= trip.cost %>
      +
      \ No newline at end of file diff --git a/app/views/trips/edit.html.erb b/app/views/trips/edit.html.erb index e9e3e0cd4..90e398a8e 100644 --- a/app/views/trips/edit.html.erb +++ b/app/views/trips/edit.html.erb @@ -1,12 +1,14 @@ -<%= form_with model: @trip, class: "edit-trip" do |f| %> - <%= f.label :date %> - <%= f.text_field :date %>
      +
      + <%= form_with model: @trip, class: "edit-trip" do |f| %> + <%= f.label :date %> + <%= f.text_field :date %>
      - <%= f.label :cost %> - <%= f.text_field :cost %>
      + <%= f.label :cost %> + <%= f.text_field :cost %>
      - <%= f.label :rating %> - <%= f.select :rating, [1, 2, 3, 4, 5] %>
      + <%= f.label :rating %> + <%= f.select :rating, [1, 2, 3, 4, 5] %>
      - <%= f.submit "Edit Trip", class: "trip-button" %> -<% end %> \ No newline at end of file + <%= f.submit "Edit Trip", class: "trip-button" %> + <% end %> +
      \ No newline at end of file diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index bc2148f05..919113bd3 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -1,16 +1,18 @@ -

      Trip Details

      +
      +

      Trip Details

      -

      Trip ID: <%= @trip.id %>

      -

      Trip Date: <%= @trip.date %>

      -

      Trip Cost: <%= @trip.cost %>

      -

      Trip Rating: <%= @trip.rating %>

      -

      Passenger Name: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>

      -

      Driver Name: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>

      +

      Trip ID: <%= @trip.id %>

      +

      Trip Date: <%= @trip.date %>

      +

      Trip Cost: <%= @trip.cost %>

      +

      Trip Rating: <%= @trip.rating %>

      +

      Passenger Name: <%= link_to @trip.passenger.name, passenger_path(@trip.passenger.id) %>

      +

      Driver Name: <%= link_to @trip.driver.name, driver_path(@trip.driver.id) %>

      -
      - <%= link_to "Edit Trip", edit_trip_path(@trip) %> -

      +
      + <%= link_to "Edit Trip", edit_trip_path(@trip) %> +

      -
      - <%= link_to "Delete Trip", trip_path(@trip), method: :delete, data: { confirm: "Are you sure you want to delete this trip?" } %> -

      \ No newline at end of file +
      + <%= link_to "Delete Trip", trip_path(@trip), method: :delete, data: { confirm: "Are you sure you want to delete this trip?" } %> +

      +
      \ No newline at end of file From 9aa342df52d47112537bbcacbe2772038454adb4 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Fri, 11 Oct 2019 07:27:36 -0700 Subject: [PATCH 42/46] Formatted forms and date input type for Trips edit view --- app/assets/stylesheets/application.css | 22 ++++++++++++++++++++++ app/views/drivers/_form.html.erb | 2 ++ app/views/passengers/_form.html.erb | 2 ++ app/views/trips/edit.html.erb | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b889c0c52..d50ed8050 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -121,4 +121,26 @@ table, th, td { padding-left: 30px; padding-right: 30px; opacity: 0.9 +} + + +table { + margin: 20px; +} + +td{ + text-align: center; +} + +.edit-passenger, .create-passenger, .edit-driver, .create-driver { + display: grid; + grid-template-columns: 200px 400px; + row-gap: 0.5em; + column-gap: 0.3em; +} + +.edit-trip { + display: grid; + grid-template-columns: 200px; + row-gap: -0.2em; } \ No newline at end of file diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index e0ad1d1e1..ec8971450 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -9,6 +9,8 @@
    <% end %> +

    Please provide the following information to <%="#{action_name}"%> the driver in our database:

    + <%= form_with model: @driver, class: "#{action_name}-driver" do |f| %> <%= f.label :name %>
    <%= f.text_field :name %>
    diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb index 907b7bf6b..fe99f828d 100644 --- a/app/views/passengers/_form.html.erb +++ b/app/views/passengers/_form.html.erb @@ -9,6 +9,8 @@
<% end %> +

Please provide the following information to <%="#{action_name}"%> the passenger in our database:

+ <%= form_with model: @passenger, class: "#{action_name}-passenger" do |f| %> <%= f.label :name %>
<%= f.text_field :name %>
diff --git a/app/views/trips/edit.html.erb b/app/views/trips/edit.html.erb index 90e398a8e..f7d17bb8f 100644 --- a/app/views/trips/edit.html.erb +++ b/app/views/trips/edit.html.erb @@ -1,7 +1,7 @@
<%= form_with model: @trip, class: "edit-trip" do |f| %> <%= f.label :date %> - <%= f.text_field :date %>
+ <%= f.date_field :date, value: f.object.try(:strftime,"%Y-%m-%d") %>
<%= f.label :cost %> <%= f.text_field :cost %>
From 8f32e3f0b9c975ea761637a00487a4ab6e39e9f0 Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Fri, 11 Oct 2019 09:49:49 -0700 Subject: [PATCH 43/46] Formatted table headers --- app/assets/stylesheets/application.css | 2 +- app/views/drivers/index.html.erb | 2 +- app/views/drivers/show.html.erb | 2 +- app/views/passengers/index.html.erb | 2 +- app/views/passengers/show.html.erb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d50ed8050..8f04a2a3a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -128,7 +128,7 @@ table { margin: 20px; } -td{ +td, .table-header { text-align: center; } diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index a9aed9b7e..b00b37a24 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -9,7 +9,7 @@
- + diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index d4e19c6e9..e66d1640f 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -29,7 +29,7 @@
ID Name VIN
- + diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index b7e716f67..b6cc5427e 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -9,7 +9,7 @@
Trip ID Trip Date Passenger Name
- + diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 0b186fa7b..56c135672 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -21,7 +21,7 @@
ID Name Phone Number
- + From 18c2d70e7977c769b8e6ea2a7a19bf2222597e9f Mon Sep 17 00:00:00 2001 From: Raisah Vesteinsdottir Date: Fri, 11 Oct 2019 10:03:51 -0700 Subject: [PATCH 44/46] Formatted drop down menu in nav --- app/assets/stylesheets/application.css | 14 ++++++++++++-- app/views/layouts/application.html.erb | 11 ++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 8f04a2a3a..2d21f859d 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -20,6 +20,10 @@ .nav-bar { background-color: lightgrey; + padding: 15px; + vertical-align: center; + display: grid; + grid-template-columns: 65% auto auto auto; } .home-button { @@ -35,6 +39,11 @@ color: white; } +.home-button a:hover { + text-decoration: none; + color: white; +} + .title-section { display: inline; padding-right: 50px; @@ -71,13 +80,14 @@ .dropdown-content a:hover { background-color: #ddd; + text-decoration: none; } -.dropdown:hover .dropdown-content { +.dropdown:hover .dropdown-content{ display: block; } -.dropdown:hover .dropbtn { +.dropdown:hover .dropbtn, .home-button:hover { background-color: #3e8e41; } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 781b81862..cf65a6a80 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,9 +15,14 @@
Trip ID Trip Date Passenger Name