From 564ffbcc931c77b70dbf52ce2d7584cf50c776c3 Mon Sep 17 00:00:00 2001 From: Kay Date: Wed, 17 Oct 2018 17:20:31 -0700 Subject: [PATCH 001/239] setting up fresh betzy rails app --- .gitignore | 27 ++ .ruby-version | 1 + Gemfile | 81 +++++ Gemfile.lock | 277 ++++++++++++++++++ Guardfile | 9 + README.md | 242 +-------------- Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 20 ++ app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 app/assets/stylesheets/application.scss | 18 ++ 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 | 25 ++ 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 +++ .../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 +++ db/seeds.rb | 7 + 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 | 24 ++ tmp/.keep | 0 vendor/.keep | 0 81 files changed, 1419 insertions(+), 229 deletions(-) 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.scss 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/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 db/seeds.rb 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 0000000000..18b43c9cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# 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 + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..e54d447e8f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.4.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..8406aeb8bb --- /dev/null +++ b/Gemfile @@ -0,0 +1,81 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.4.1' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.1' +# 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-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..ca4832eed6 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,277 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.1) + actionpack (= 5.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.1) + actionview (= 5.2.1) + activesupport (= 5.2.1) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.1) + activesupport (= 5.2.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.1) + activesupport (= 5.2.1) + globalid (>= 0.3.6) + activemodel (5.2.1) + activesupport (= 5.2.1) + activerecord (5.2.1) + activemodel (= 5.2.1) + activesupport (= 5.2.1) + arel (>= 9.0) + activestorage (5.2.1) + actionpack (= 5.2.1) + activerecord (= 5.2.1) + marcel (~> 0.3.1) + activesupport (5.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ansi (1.5.0) + archive-zip (0.11.0) + io-like (~> 0.3.0) + arel (9.0.0) + autoprefixer-rails (9.2.1) + execjs + better_errors (2.5.0) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) + bindex (0.5.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + bootsnap (1.3.2) + msgpack (~> 1.0) + bootstrap (4.1.3) + autoprefixer-rails (>= 6.0.3) + popper_js (>= 1.12.9, < 2) + sass (>= 3.5.2) + builder (3.2.3) + byebug (10.0.2) + capybara (3.9.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + xpath (~> 3.1) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (2.1.0) + archive-zip (~> 0.10) + nokogiri (~> 1.8) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + debug_inspector (0.0.3) + erubi (1.7.1) + execjs (2.7.0) + ffi (1.9.25) + formatador (0.2.5) + globalid (0.4.1) + activesupport (>= 4.2.0) + guard (2.14.2) + 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.1.1) + concurrent-ruby (~> 1.0) + io-like (0.3.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.3) + 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.2.2) + 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.0) + mimemagic (0.3.2) + mini_mime (1.0.1) + mini_portile2 (2.3.0) + minitest (5.11.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.3.5) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + msgpack (1.2.4) + multi_json (1.13.1) + nenv (0.3.0) + nio4r (2.3.1) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + pg (1.1.3) + popper_js (1.14.3) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.3) + puma (3.12.0) + rack (2.0.5) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.1) + actioncable (= 5.2.1) + actionmailer (= 5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + activemodel (= 5.2.1) + activerecord (= 5.2.1) + activestorage (= 5.2.1) + activesupport (= 5.2.1) + bundler (>= 1.3.0) + railties (= 5.2.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.2.1) + actionpack (= 5.2.1) + activesupport (= 5.2.1) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + ruby-progressbar (1.10.0) + ruby_dep (1.5.0) + rubyzip (1.2.2) + sass (3.6.0) + 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.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.14.1) + childprocess (~> 0.5) + rubyzip (~> 1.2, >= 1.2.2) + shellany (0.0.1) + spring (2.0.2) + activesupport (>= 4.2) + 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.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.19) + 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.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.2.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + bootsnap (>= 1.1.0) + bootstrap (~> 4.1.3) + byebug + capybara (>= 2.15) + chromedriver-helper + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.1) + 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.4.1p111 + +BUNDLED WITH + 1.16.4 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000000..e34f706f4a --- /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/README.md b/README.md index 1864d2b973..7db80e4ca1 100644 --- a/README.md +++ b/README.md @@ -1,240 +1,24 @@ -# bEtsy -[Much like other e-commerce platforms](https://www.etsy.com/), your team will make an online store where a wide variety of products can be listed and sold by any user. This project focuses on reinforcing the major components of Rails, model validations, testing, and more complex logic such as user authentication. +# README -This is a [Stage 3](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md) project requiring you to expand upon what you have learned in class. +This README would normally document whatever steps are necessary to get the +application up and running. -Due date: EOD Friday October 26 +Things you may want to cover: -## Project Learning Goals -- Core comprehension of: - - Routes - - Controllers - - Models - - Views -- User based application logic -- User authentication -- Testing on models and controllers -- Agile practices -- Feature branch management with Git -- Group project ownership +* Ruby version -## Guidelines -- Groups of three or four will collaborate in pairs or individually and will report to their assigned Project Manager (one of the instructors) -- Use a task manager like [Trello](http://trello.com) to track your team's efforts -- Build a logical user-flow that moves across multiple controllers and models -- Use HTML/CSS and Bootstap or another CSS framework to style your website +* System dependencies -## Getting Started -1. As a group decide on an app name (this may help lead the aesthetic) -1. As a group decide on a team name (this will amuse your instructors) -1. Have one person on your team fork/clone the project master as per usual - 1. Create a new rails app using `rails new .` - 1. Add all other team members as collaborators - 1. Each team member should clone the repo to their computer -1. Figure out your workflow for the project, re: Git and Task management - 1. Do you want to use git branches? Pull requests? - 1. Determine who will be the Stand Up Leader and Task Leader for the first week -1. Create a Trello board to use as a Kanban board and ensure that all team members and instructors have access -1. Review the User Stories below and create Trello tasks to represent them -1. Slack your team name, app name, and link to your Trello board to your Project Manager +* Configuration -## Expectations -Build an online system for listing, selling, reviewing, and buying a wide variety of products listed by multiple merchants. +* Database creation -### General Requirements -- Unit tests and/or specs for - - Models - - Controllers -- Test code coverage (using SimpleCov - remember me!) - - 90% for all controller and model classes +* Database initialization -### Prioritization +* How to run the test suite -This project contains many user stories, some of which are more relevant to our in-class learning goals than others. Here is a rough categorization of how important various features are: +* Services (job queues, cache servers, search engines, etc.) -#### High Priority +* Deployment instructions -- Browsing products -- Using the shopping cart (adding items, checking out) -- Authentication as a merchant -- CRUD on products, including authorization rules -- Model testing, particularly for any custom logic -- Controller testing - -#### Medium Priority - -- Product categories -- Basic validations (things that will break the site) -- Tracking product inventory -- Order fulfillment - -#### Low Priority - -- Reviews and ratings -- Comprehensive validations, particularly around submitting an order - -### User Stories -#### Guest User (Unauthenticated) -As a guest to the website (not signed in) I **can**: - -- Browse all products -- Browse products by category -- Browse products by merchant (users) -- View any individual product with additional details -- Leave a review for a product providing: - - A text review - - A rating out of 5 -- Add in-stock products to my cart -- Remove products from my cart -- Change the quantity of an existing product in my cart -- Purchase the items in my cart, providing: - - Email Address - - Mailing Address - - Name on credit card - - Credit card number - - Credit cart expiration - - Credit Card CVV (security code) - - Billing zip code -- Purchasing an order makes the following changes: - - Reduces the number of inventory for each product - - Changes the order state from "pending" to "paid" - - Clears the current cart -- After purchasing an order, I can view a confirmation screen including: - - Each item in the order with a quantity and line-item subtotal - - A link to the item description page - - Order total price - - Date/time the order was placed - - The current status of the order -- Sign up to be a merchant using OAuth - - Every merchant must have a username -- Sign in to my merchant account using OAuth - -As a guest I **cannot**: - -- Add products to the cart that are out of stock -- View any link or page to manage any products -- View any of the account pages - -#### Authenticated Users -As a signed-in user, I **can**: - -- Do everything a guest user can do except for sign up and sign in -- Sign out -- Create new categories (categories are shared between all merchants) -- Create a new product providing: - - name - - description - - price - - photo URL - - stock -- Assign my products to any number of categories -- Retire a product from being sold, which hides it from browsing -- View an account page to edit/update my existing products -- View an account page showing my order fulfillment -- On the order fulfillment page: - - Total Revenue - - Total Revenue by status - - Total number of orders by status - - Filter orders displayed by status - - Link to each individual order - - A list of orders including at least one of my products: - - Each order item sold by me with a quantity and line-item subtotal - - A link to the item description page - - DateTime the order was placed - - Link to transition the order item to marked as shipped - - The current status of the order ("pending", "paid", "complete", "cancelled") -- View an individual order to see the user's: - - Name - - Email address - - Mailing address - - Last four digits of their credit card - - Credit card expiration date - -As a signed-in user, I **cannot**: - -- Review my own products -- View order items from a shared order that belong to another merchant -- View another user's private data (i.e. order fulfillment or product management) - -### Validations -Many of our models will have attributes that are required for our application to use and display data consistently. Each model will have attributes with requirements for a valid record. The requirements are summarized below: - -#### Merchant -- Username must be present -- Username must be unique -- Email Address must be present -- Email Address must be unique - -#### Product -- Name must be present -- Name must be unique -- Price must be present -- Price must be a number -- Price must be greater than 0 -- Product must belong to a User - -#### Order -- An Order must have one or more Order Items - -#### OrderItem -- Must belong to a Product -- Must belong to an Order -- Quantity must be present -- Quantity must be an integer -- Quantity must be greater than 0 - -#### Review -- Rating must be present -- Rating must be an integer -- Rating must be between 1 and 5 - -## Process - -We expect you to follow the agile process we've learned about in class as you work on this project. - -### Team Leaders -Each team will have team leaders who are responsible for keeping track of each team member's contributions. Rotate leader roles at the beginning of the second week; every team member should be in at least one leader role during the project. - -- **Stand Up Leader** - - Notifies team members about meeting schedule and ensures that everyone is present and ready - - Takes notes about each person's daily report in Stand Up - - Keeps the meeting moving -- **Task Leader** - - Leads discussion on task assignment and prioritization - - Decide if a task should be completed alone or in a pair - - Assign tasks based on... - - Individual comfort - - Desire - - Ability - - Ensures the Kanban board stays up to date - -### Stand Up Meetings -The Stand Up Leader should determine the daily time for your stand up meeting with the team. Once you come up with a time, confirm with your PM that this time will work for them. - -At the end of each day, your team's assigned Project Manager will review the Trello board to ensure it captures the updates that your team has made throughout the day. - -### Interim Demo -In a real world work environment, a team's success is measured by their product as opposed to each individual's contribution. - -Each team will present their progress and respond to questions from their Project Manager on the first Friday. Every team member will participate in these demos; the PM will ask specific questions regarding -1. The team's progress and plan for completing the project -1. The technical decisions and implementation -1. Every team member's understanding of the underlying technical structures - -### Midpoint Retrospective - -On the first Friday, instead of our normal full-class retro, each team will get together and conduct a small-scale retro. One team member should facilitate, this may be the standup leader or someone else. Your retro should focus on the following questions: -- What has gone well? -- What could have gone better? -- Where is our direction still unclear? - -## Final Presentation -Each team will present their product in a final presentation to the group on the final Friday. Your presentation should be no more than 7 minutes. The presentation should include every team member and: -- what you learned as individuals and as a group -- a short story-driven demo of interesting features - -## Submission Guidelines -Your final project must be deployed to [Heroku](http://heroku.com). Your team will open a single pull request for the entire project. There are comprehension questions to answer with your submission that you should complete together as a group. Remember, you can submit a PR and still make some final changes to your code, so don't wait until the last minute. - -## What Instructors Are Looking For -Check out the [feedback template](feedback.md) which lists the items instructors will be looking for as they evaluate your project. +* ... diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /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 0000000000..b16e53d6d5 --- /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 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..4f73c21a7d --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,20 @@ +// 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 jquery3 + //= require popper + //= require bootstrap-sprockets + +// +//= 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 0000000000..739aa5f022 --- /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 0000000000..e69de29bb2 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..8b1701e581 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,18 @@ +/* + * 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. + * + */ + +/* Custom bootstrap variables must be set or imported *before* bootstrap. */ +@import "bootstrap"; +/* Import scss content */ +@import "**/*"; diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000..d672697283 --- /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 0000000000..0ff5442f47 --- /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 0000000000..09705d12ab --- /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 0000000000..e69de29bb2 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /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 0000000000..a009ace51c --- /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 0000000000..286b2239d1 --- /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 0000000000..10a4cba84d --- /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 0000000000..e69de29bb2 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..f18f1b6820 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,15 @@ + + + + Betsy + <%= 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 0000000000..cbd34d2e9d --- /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 0000000000..37f0bddbd7 --- /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 0000000000..f19acf5b5c --- /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 0000000000..5badb2fde0 --- /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 0000000000..d87d5f5781 --- /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 0000000000..94fd4d7977 --- /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 0000000000..fb2ec2ebb4 --- /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 0000000000..58bfaed518 --- /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 0000000000..460dd565b4 --- /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 0000000000..f7ba0b527b --- /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 0000000000..5c09a3eefc --- /dev/null +++ b/config/application.rb @@ -0,0 +1,25 @@ +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 Betsy + 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 0000000000..b9e460cef3 --- /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 0000000000..dd2a324c68 --- /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: betsy_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000000..f3ace6252e --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +Yrstgg9sorjB/ZS1a5+M/U2GLzIl0iktu5DZoqKVSrfFOjklP4AZ6hl+uhygpNm8LVT4bidJ9LB8chGqCy4AWlBSUxO2HwZFoOsuPWgjRXDrUdvddZzu+Nlqwe+Tj65ncHxSkKNzjA8ovyRiQgTfj7R4uzeoHjGKCtbBbVSw9LqKcFh75B/hBYGd0Qku6cY7CB1Bfbdwo52vxMdp5SNTAvtGmxYYEpXBF/K8XQOG2S9Wmt+N+RaacZfpw8xTSxdGCc8qo8GmTbugjHn6gsTnkPBCOi2iaqe3WIWHs2pNyGNTOh+tjSxSaObGqS/jeYDLv1MCWBk2raIfMSAyEkBrDGCh9vpWAL+qZu1baEbTsVKlUvNLnVoI7Bziti233RhrRHsoHme3Cj6qOUA7/r77+/4MXSE5EtcUXQ+m--iYF4uUdqfhBX+QPj--4p+KRRR2mbsZrMhQvcjuXQ== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..6903bb6083 --- /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: betsy_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: betsy + + # 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: betsy_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: betsy_production + username: betsy + password: <%= ENV['BETSY_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000..426333bb46 --- /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 0000000000..1311e3e4ef --- /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 0000000000..5f6f3058c6 --- /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 = "betsy_#{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 0000000000..0a38fd3ce9 --- /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/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000000..89d2efab2b --- /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 0000000000..4b828e80cb --- /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 0000000000..59385cdf37 --- /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 0000000000..d3bcaa5ec8 --- /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 0000000000..5a6a32d371 --- /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 0000000000..4a994e1e7b --- /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 0000000000..ac033bf9dc --- /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 0000000000..dc1899682b --- /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 0000000000..bbfc3961bf --- /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 0000000000..decc5a8573 --- /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 0000000000..a5eccf816b --- /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 0000000000..787824f888 --- /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 0000000000..9fa7863f99 --- /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 0000000000..d32f76e8fb --- /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/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..1beea2accd --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json new file mode 100644 index 0000000000..f874acf437 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "betsy", + "private": true, + "dependencies": {} +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000000..2be3af26fc --- /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 0000000000..c08eac0d1d --- /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 0000000000..78a030af22 --- /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 0000000000..e69de29bb2 diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000000..37b576a4a0 --- /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 0000000000..e69de29bb2 diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /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 0000000000..e69de29bb2 diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000000..2b5172a7d6 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,24 @@ +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 +) + + +# To add Capybara feature tests add `gem "minitest-rails-capybara"` +# to the test group in the Gemfile and uncomment the following: +# require "minitest/rails/capybara" + +# Uncomment for awesome colorful output +# require "minitest/pride" + +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 0000000000..e69de29bb2 diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2 From e6445103aed67ea17a604b54bf9aeeb57c5ce315 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:02:59 -0700 Subject: [PATCH 002/239] Generated Orders controller --- app/assets/javascripts/orders.js | 2 ++ app/assets/stylesheets/orders.scss | 3 +++ app/controllers/orders_controller.rb | 10 ++++++++++ app/helpers/orders_helper.rb | 2 ++ app/views/orders/create.html.erb | 2 ++ app/views/orders/new.html.erb | 2 ++ app/views/orders/show.html.erb | 2 ++ config/routes.rb | 3 +++ db/schema.rb | 18 ++++++++++++++++++ test/controllers/orders_controller_test.rb | 19 +++++++++++++++++++ 10 files changed, 63 insertions(+) create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/views/orders/create.html.erb create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/show.html.erb create mode 100644 db/schema.rb create mode 100644 test/controllers/orders_controller_test.rb diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.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/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..741506954d --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Orders 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/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..67bbbde994 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,10 @@ +class OrdersController < ApplicationController + def new + end + + def create + end + + def show + end +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/views/orders/create.html.erb b/app/views/orders/create.html.erb new file mode 100644 index 0000000000..295bd84094 --- /dev/null +++ b/app/views/orders/create.html.erb @@ -0,0 +1,2 @@ +

Orders#create

+

Find me in app/views/orders/create.html.erb

diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..1bc27609ce --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,2 @@ +

Orders#new

+

Find me in app/views/orders/new.html.erb

diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..22eb495f6f --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,2 @@ +

Orders#show

+

Find me in app/views/orders/show.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 787824f888..fe50c9f5af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,6 @@ Rails.application.routes.draw do + get 'orders/new' + get 'orders/create' + get 'orders/show' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..2611543b38 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,18 @@ +# 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: 0) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..7546b83a1a --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +describe OrdersController do + it "should get new" do + get orders_new_url + value(response).must_be :success? + end + + it "should get create" do + get orders_create_url + value(response).must_be :success? + end + + it "should get show" do + get orders_show_url + value(response).must_be :success? + end + +end From 4f64996e097ac092513c2ed6ff7babc7ed1fc70c Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:05:13 -0700 Subject: [PATCH 003/239] Created CAtegories controller --- app/assets/javascripts/categories.js | 2 ++ app/assets/stylesheets/categories.scss | 3 +++ app/controllers/categories_controller.rb | 7 +++++++ app/helpers/categories_helper.rb | 2 ++ app/views/categories/create.html.erb | 2 ++ app/views/categories/new.html.erb | 2 ++ config/routes.rb | 2 ++ test/controllers/categories_controller_test.rb | 14 ++++++++++++++ 8 files changed, 34 insertions(+) create mode 100644 app/assets/javascripts/categories.js create mode 100644 app/assets/stylesheets/categories.scss create mode 100644 app/controllers/categories_controller.rb create mode 100644 app/helpers/categories_helper.rb create mode 100644 app/views/categories/create.html.erb create mode 100644 app/views/categories/new.html.erb create mode 100644 test/controllers/categories_controller_test.rb diff --git a/app/assets/javascripts/categories.js b/app/assets/javascripts/categories.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/categories.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/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..42976cbc11 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Categories 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/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..0e3d845f08 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,7 @@ +class CategoriesController < ApplicationController + def new + end + + def create + end +end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/views/categories/create.html.erb b/app/views/categories/create.html.erb new file mode 100644 index 0000000000..63069b0005 --- /dev/null +++ b/app/views/categories/create.html.erb @@ -0,0 +1,2 @@ +

Categories#create

+

Find me in app/views/categories/create.html.erb

diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..7e5c27307e --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,2 @@ +

Categories#new

+

Find me in app/views/categories/new.html.erb

diff --git a/config/routes.rb b/config/routes.rb index fe50c9f5af..21a44e8165 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + get 'categories/new' + get 'categories/create' get 'orders/new' get 'orders/create' get 'orders/show' diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..f50efa8fb0 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +describe CategoriesController do + it "should get new" do + get categories_new_url + value(response).must_be :success? + end + + it "should get create" do + get categories_create_url + value(response).must_be :success? + end + +end From 3c8392b5a5c3e5e8f1459ca2440b9d8c51539c92 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:06:32 -0700 Subject: [PATCH 004/239] Created Products controller --- app/assets/javascripts/products.js | 2 + app/assets/stylesheets/products.scss | 3 ++ app/controllers/products_controller.rb | 22 +++++++++++ app/helpers/products_helper.rb | 2 + app/views/products/create.html.erb | 2 + app/views/products/destroy.html.erb | 2 + app/views/products/edit.html.erb | 2 + app/views/products/index.html.erb | 2 + app/views/products/new.html.erb | 2 + app/views/products/show.html.erb | 2 + app/views/products/update.html.erb | 2 + config/routes.rb | 7 ++++ test/controllers/products_controller_test.rb | 39 ++++++++++++++++++++ 13 files changed, 89 insertions(+) create mode 100644 app/assets/javascripts/products.js create mode 100644 app/assets/stylesheets/products.scss create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/views/products/create.html.erb create mode 100644 app/views/products/destroy.html.erb create mode 100644 app/views/products/edit.html.erb create mode 100644 app/views/products/index.html.erb create mode 100644 app/views/products/new.html.erb create mode 100644 app/views/products/show.html.erb create mode 100644 app/views/products/update.html.erb create mode 100644 test/controllers/products_controller_test.rb diff --git a/app/assets/javascripts/products.js b/app/assets/javascripts/products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/products.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/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..bff386e55a --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Products 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/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..5b7080f883 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,22 @@ +class ProductsController < ApplicationController + def index + end + + def show + end + + def update + end + + def new + end + + def create + end + + def edit + end + + def destroy + end +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/views/products/create.html.erb b/app/views/products/create.html.erb new file mode 100644 index 0000000000..d546021001 --- /dev/null +++ b/app/views/products/create.html.erb @@ -0,0 +1,2 @@ +

Products#create

+

Find me in app/views/products/create.html.erb

diff --git a/app/views/products/destroy.html.erb b/app/views/products/destroy.html.erb new file mode 100644 index 0000000000..d5c678b499 --- /dev/null +++ b/app/views/products/destroy.html.erb @@ -0,0 +1,2 @@ +

Products#destroy

+

Find me in app/views/products/destroy.html.erb

diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..279b066f30 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,2 @@ +

Products#edit

+

Find me in app/views/products/edit.html.erb

diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..f8eeb82674 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,2 @@ +

Products#index

+

Find me in app/views/products/index.html.erb

diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..a14e0d91b6 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,2 @@ +

Products#new

+

Find me in app/views/products/new.html.erb

diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..5f44ec44d2 --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,2 @@ +

Products#show

+

Find me in app/views/products/show.html.erb

diff --git a/app/views/products/update.html.erb b/app/views/products/update.html.erb new file mode 100644 index 0000000000..039889ac02 --- /dev/null +++ b/app/views/products/update.html.erb @@ -0,0 +1,2 @@ +

Products#update

+

Find me in app/views/products/update.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 21a44e8165..9ca6bd15fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,11 @@ Rails.application.routes.draw do + get 'products/index' + get 'products/show' + get 'products/update' + get 'products/new' + get 'products/create' + get 'products/edit' + get 'products/destroy' get 'categories/new' get 'categories/create' get 'orders/new' diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..32fca2d900 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,39 @@ +require "test_helper" + +describe ProductsController do + it "should get index" do + get products_index_url + value(response).must_be :success? + end + + it "should get show" do + get products_show_url + value(response).must_be :success? + end + + it "should get update" do + get products_update_url + value(response).must_be :success? + end + + it "should get new" do + get products_new_url + value(response).must_be :success? + end + + it "should get create" do + get products_create_url + value(response).must_be :success? + end + + it "should get edit" do + get products_edit_url + value(response).must_be :success? + end + + it "should get destroy" do + get products_destroy_url + value(response).must_be :success? + end + +end From ec24ba6b72ec97964df9fe2aef3ac70a810ff752 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:16:10 -0700 Subject: [PATCH 005/239] Created Users controller --- app/assets/javascripts/users.js | 2 ++ app/assets/stylesheets/users.scss | 3 +++ app/controllers/users_controller.rb | 10 ++++++++++ app/helpers/users_helper.rb | 2 ++ app/views/users/create.html.erb | 2 ++ app/views/users/new.html.erb | 2 ++ app/views/users/show.html.erb | 2 ++ config/routes.rb | 3 +++ test/controllers/users_controller_test.rb | 19 +++++++++++++++++++ 9 files changed, 45 insertions(+) create mode 100644 app/assets/javascripts/users.js create mode 100644 app/assets/stylesheets/users.scss create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/views/users/create.html.erb create mode 100644 app/views/users/new.html.erb create mode 100644 app/views/users/show.html.erb create mode 100644 test/controllers/users_controller_test.rb diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/users.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/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..31a2eacb84 --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users 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/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..cdd598fe30 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,10 @@ +class UsersController < ApplicationController + def new + end + + def create + end + + def show + end +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/views/users/create.html.erb b/app/views/users/create.html.erb new file mode 100644 index 0000000000..48ea02e600 --- /dev/null +++ b/app/views/users/create.html.erb @@ -0,0 +1,2 @@ +

Users#create

+

Find me in app/views/users/create.html.erb

diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000000..c21a1adf19 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,2 @@ +

Users#new

+

Find me in app/views/users/new.html.erb

diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000000..e5fa3adf14 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,2 @@ +

Users#show

+

Find me in app/views/users/show.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 9ca6bd15fb..333c0ee563 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + get 'users/new' + get 'users/create' + get 'users/show' get 'products/index' get 'products/show' get 'products/update' diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..84a226911b --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +describe UsersController do + it "should get new" do + get users_new_url + value(response).must_be :success? + end + + it "should get create" do + get users_create_url + value(response).must_be :success? + end + + it "should get show" do + get users_show_url + value(response).must_be :success? + end + +end From 9aec3c98307aec705ca2e7c710d7d315fa8607e5 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:18:05 -0700 Subject: [PATCH 006/239] Created Sessions controller --- app/assets/javascripts/sessions.js | 2 ++ app/assets/stylesheets/sessions.scss | 3 +++ app/controllers/sessions_controller.rb | 10 ++++++++++ app/helpers/sessions_helper.rb | 2 ++ app/views/sessions/destroy.html.erb | 2 ++ app/views/sessions/login.html.erb | 2 ++ app/views/sessions/new.html.erb | 2 ++ config/routes.rb | 3 +++ test/controllers/sessions_controller_test.rb | 19 +++++++++++++++++++ 9 files changed, 45 insertions(+) create mode 100644 app/assets/javascripts/sessions.js create mode 100644 app/assets/stylesheets/sessions.scss create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/views/sessions/destroy.html.erb create mode 100644 app/views/sessions/login.html.erb create mode 100644 app/views/sessions/new.html.erb create mode 100644 test/controllers/sessions_controller_test.rb diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/sessions.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/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..ccb1ed25b2 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sessions 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/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..6737c8cf46 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,10 @@ +class SessionsController < ApplicationController + def login + end + + def destroy + end + + def new + end +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/views/sessions/destroy.html.erb b/app/views/sessions/destroy.html.erb new file mode 100644 index 0000000000..d75237d982 --- /dev/null +++ b/app/views/sessions/destroy.html.erb @@ -0,0 +1,2 @@ +

Sessions#destroy

+

Find me in app/views/sessions/destroy.html.erb

diff --git a/app/views/sessions/login.html.erb b/app/views/sessions/login.html.erb new file mode 100644 index 0000000000..6fbfe54fd5 --- /dev/null +++ b/app/views/sessions/login.html.erb @@ -0,0 +1,2 @@ +

Sessions#login

+

Find me in app/views/sessions/login.html.erb

diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000000..b39a3bc951 --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,2 @@ +

Sessions#new

+

Find me in app/views/sessions/new.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 333c0ee563..ddb939cc31 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + get 'sessions/login' + get 'sessions/destroy' + get 'sessions/new' get 'users/new' get 'users/create' get 'users/show' diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..e3ccc2c2a6 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +describe SessionsController do + it "should get login" do + get sessions_login_url + value(response).must_be :success? + end + + it "should get destroy" do + get sessions_destroy_url + value(response).must_be :success? + end + + it "should get new" do + get sessions_new_url + value(response).must_be :success? + end + +end From 0ff70660394f322972e558bf6aa3f0fd7ae129ed Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:28:08 -0700 Subject: [PATCH 007/239] Created category model --- app/models/category.rb | 2 ++ db/migrate/20181018012217_create_categories.rb | 9 +++++++++ test/fixtures/categories.yml | 7 +++++++ test/models/category_test.rb | 9 +++++++++ 4 files changed, 27 insertions(+) create mode 100644 app/models/category.rb create mode 100644 db/migrate/20181018012217_create_categories.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..54cb6aee3f --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,2 @@ +class Category < ApplicationRecord +end diff --git a/db/migrate/20181018012217_create_categories.rb b/db/migrate/20181018012217_create_categories.rb new file mode 100644 index 0000000000..6ccc3914a0 --- /dev/null +++ b/db/migrate/20181018012217_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..56066c68af --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..781320ad8e --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new } + + it "must be valid" do + value(category).must_be :valid? + end +end From 46f4083d249e8473a59e614e179a3c5ee9aa2725 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:35:59 -0700 Subject: [PATCH 008/239] Created Product model --- app/models/product.rb | 2 ++ db/migrate/20181018013548_create_products.rb | 13 +++++++++++++ test/fixtures/products.yml | 15 +++++++++++++++ test/models/product_test.rb | 9 +++++++++ 4 files changed, 39 insertions(+) create mode 100644 app/models/product.rb create mode 100644 db/migrate/20181018013548_create_products.rb create mode 100644 test/fixtures/products.yml create mode 100644 test/models/product_test.rb diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..35a85acab3 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,2 @@ +class Product < ApplicationRecord +end diff --git a/db/migrate/20181018013548_create_products.rb b/db/migrate/20181018013548_create_products.rb new file mode 100644 index 0000000000..5ae1a20fb2 --- /dev/null +++ b/db/migrate/20181018013548_create_products.rb @@ -0,0 +1,13 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.string :name + t.decimal :price + t.string :description + t.string :photo + t.integer :stock + + t.timestamps + end + end +end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..bb8375a334 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + price: 9.99 + description: MyString + photo: MyString + stock: 1 + +two: + name: MyString + price: 9.99 + description: MyString + photo: MyString + stock: 1 diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..a618b0a156 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Product do + let(:product) { Product.new } + + it "must be valid" do + value(product).must_be :valid? + end +end From a644e6452b624ddaa4133632b1d19da1b6f8ec69 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:43:12 -0700 Subject: [PATCH 009/239] crated category products join table --- .../20181018014144_create_categorys_products_join.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/migrate/20181018014144_create_categorys_products_join.rb diff --git a/db/migrate/20181018014144_create_categorys_products_join.rb b/db/migrate/20181018014144_create_categorys_products_join.rb new file mode 100644 index 0000000000..12a1b487b3 --- /dev/null +++ b/db/migrate/20181018014144_create_categorys_products_join.rb @@ -0,0 +1,8 @@ +class CreateCategorysProductsJoin < ActiveRecord::Migration[5.2] + def change + create_table :categories_products do |t| + t.belongs_to :product, index: true + t.belongs_to :category, index: true + end + end +end From 0698979d2e6eeaccb71ac7f84c2374d58c801a74 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 18:47:18 -0700 Subject: [PATCH 010/239] Created order model --- app/models/order.rb | 2 ++ db/migrate/20181018014707_create_orders.rb | 9 +++++++++ test/fixtures/orders.yml | 7 +++++++ test/models/order_test.rb | 9 +++++++++ 4 files changed, 27 insertions(+) create mode 100644 app/models/order.rb create mode 100644 db/migrate/20181018014707_create_orders.rb create mode 100644 test/fixtures/orders.yml create mode 100644 test/models/order_test.rb diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..10281b3450 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,2 @@ +class Order < ApplicationRecord +end diff --git a/db/migrate/20181018014707_create_orders.rb b/db/migrate/20181018014707_create_orders.rb new file mode 100644 index 0000000000..ac0f931eea --- /dev/null +++ b/db/migrate/20181018014707_create_orders.rb @@ -0,0 +1,9 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :status + + t.timestamps + end + end +end diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..56b4f9ba1e --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + status: MyString + +two: + status: MyString diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..df80f10fb6 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + + it "must be valid" do + value(order).must_be :valid? + end +end From ea78bb06174d7b6c9cc21182a8142e6dbbb4e3a6 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 19:01:04 -0700 Subject: [PATCH 011/239] Created User model --- app/models/user.rb | 2 ++ db/migrate/20181018020046_create_users.rb | 19 ++++++++++++++++ test/fixtures/users.yml | 27 +++++++++++++++++++++++ test/models/user_test.rb | 9 ++++++++ 4 files changed, 57 insertions(+) create mode 100644 app/models/user.rb create mode 100644 db/migrate/20181018020046_create_users.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..379658a509 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ApplicationRecord +end diff --git a/db/migrate/20181018020046_create_users.rb b/db/migrate/20181018020046_create_users.rb new file mode 100644 index 0000000000..aa902609f0 --- /dev/null +++ b/db/migrate/20181018020046_create_users.rb @@ -0,0 +1,19 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :street + t.string :city + t.string :state + t.integer :zip + t.integer :creditcard + t.date :ccexpiration + t.integer :cvv + t.integer :billingzip + t.string :photo + + t.timestamps + end + end +end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..17d6b21171 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,27 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + email: MyString + street: MyString + city: MyString + state: MyString + zip: 1 + creditcard: 1 + ccexpiration: 2018-10-17 + cvv: 1 + billingzip: 1 + photo: MyString + +two: + name: MyString + email: MyString + street: MyString + city: MyString + state: MyString + zip: 1 + creditcard: 1 + ccexpiration: 2018-10-17 + cvv: 1 + billingzip: 1 + photo: MyString diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..cc862ac2d9 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe User do + let(:user) { User.new } + + it "must be valid" do + value(user).must_be :valid? + end +end From 37247a7403c7777dd9ae8ece37284e791abc340d Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 19:04:03 -0700 Subject: [PATCH 012/239] Created order items join migration --- db/migrate/20181018020214_create_orders_items_join.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/migrate/20181018020214_create_orders_items_join.rb diff --git a/db/migrate/20181018020214_create_orders_items_join.rb b/db/migrate/20181018020214_create_orders_items_join.rb new file mode 100644 index 0000000000..7a750bb543 --- /dev/null +++ b/db/migrate/20181018020214_create_orders_items_join.rb @@ -0,0 +1,8 @@ +class CreateOrdersItemsJoin < ActiveRecord::Migration[5.2] + def change + create_table :orders_items do |t| + t.belongs_to :order, index: true + t.belongs_to :product, index: true + end + end +end From e365f939fc33f48cfc140e4811e45d29687047e2 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 19:32:32 -0700 Subject: [PATCH 013/239] Created order_item model/order items join table --- app/models/category.rb | 1 + app/models/order_item.rb | 2 ++ app/models/product.rb | 1 + db/migrate/20181018022823_create_order_items.rb | 9 +++++++++ test/fixtures/order_items.yml | 11 +++++++++++ test/models/order_item_test.rb | 9 +++++++++ 6 files changed, 33 insertions(+) create mode 100644 app/models/order_item.rb create mode 100644 db/migrate/20181018022823_create_order_items.rb create mode 100644 test/fixtures/order_items.yml create mode 100644 test/models/order_item_test.rb diff --git a/app/models/category.rb b/app/models/category.rb index 54cb6aee3f..ef4a201ed6 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,2 +1,3 @@ class Category < ApplicationRecord + has_and_belongs_to_many :products end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..acc6099fd0 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,2 @@ +class OrderItem < ApplicationRecord +end diff --git a/app/models/product.rb b/app/models/product.rb index 35a85acab3..fb4f0fbddd 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,2 +1,3 @@ class Product < ApplicationRecord + has_and_belongs_to_many :categories end diff --git a/db/migrate/20181018022823_create_order_items.rb b/db/migrate/20181018022823_create_order_items.rb new file mode 100644 index 0000000000..bf5aa2f290 --- /dev/null +++ b/db/migrate/20181018022823_create_order_items.rb @@ -0,0 +1,9 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + t.integer :order_id + t.integer :product_id + t.timestamps + end + end +end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..19a9bf8f58 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderItem do + let(:order_item) { OrderItem.new } + + it "must be valid" do + value(order_item).must_be :valid? + end +end From 22c9e946b3bb38a0679d27aa7b97dbc69697b7ab Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 19:45:10 -0700 Subject: [PATCH 014/239] Decided we did not need order item model. Using joined table instead --- app/models/order_item.rb | 2 -- app/models/product.rb | 2 ++ db/migrate/20181018022823_create_order_items.rb | 9 --------- test/fixtures/order_items.yml | 11 ----------- test/models/order_item_test.rb | 9 --------- 5 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 app/models/order_item.rb delete mode 100644 db/migrate/20181018022823_create_order_items.rb delete mode 100644 test/fixtures/order_items.yml delete mode 100644 test/models/order_item_test.rb diff --git a/app/models/order_item.rb b/app/models/order_item.rb deleted file mode 100644 index acc6099fd0..0000000000 --- a/app/models/order_item.rb +++ /dev/null @@ -1,2 +0,0 @@ -class OrderItem < ApplicationRecord -end diff --git a/app/models/product.rb b/app/models/product.rb index fb4f0fbddd..7ebba04dec 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,3 +1,5 @@ class Product < ApplicationRecord has_and_belongs_to_many :categories + belongs_to :user + end diff --git a/db/migrate/20181018022823_create_order_items.rb b/db/migrate/20181018022823_create_order_items.rb deleted file mode 100644 index bf5aa2f290..0000000000 --- a/db/migrate/20181018022823_create_order_items.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateOrderItems < ActiveRecord::Migration[5.2] - def change - create_table :order_items do |t| - t.integer :order_id - t.integer :product_id - t.timestamps - end - end -end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml deleted file mode 100644 index dc3ee79b5d..0000000000 --- a/test/fixtures/order_items.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -# This model initially had no columns defined. If you add columns to the -# model remove the "{}" from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb deleted file mode 100644 index 19a9bf8f58..0000000000 --- a/test/models/order_item_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -describe OrderItem do - let(:order_item) { OrderItem.new } - - it "must be valid" do - value(order_item).must_be :valid? - end -end From f3ff124655884d21394192cbc055a5fc4bf2be06 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 19:55:00 -0700 Subject: [PATCH 015/239] Arrange relationship in orders items join table --- app/models/order.rb | 1 + app/models/product.rb | 4 +++- db/migrate/20181018020214_create_orders_items_join.rb | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 10281b3450..9f077367bc 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,3 @@ class Order < ApplicationRecord + has_many :products, through: :orders_items end diff --git a/app/models/product.rb b/app/models/product.rb index 7ebba04dec..600c64e97c 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,5 +1,7 @@ class Product < ApplicationRecord has_and_belongs_to_many :categories belongs_to :user - + has_many :products, through: :orders_items + + end diff --git a/db/migrate/20181018020214_create_orders_items_join.rb b/db/migrate/20181018020214_create_orders_items_join.rb index 7a750bb543..faa57e4304 100644 --- a/db/migrate/20181018020214_create_orders_items_join.rb +++ b/db/migrate/20181018020214_create_orders_items_join.rb @@ -1,8 +1,8 @@ class CreateOrdersItemsJoin < ActiveRecord::Migration[5.2] def change create_table :orders_items do |t| - t.belongs_to :order, index: true - t.belongs_to :product, index: true + t.belongs_to :order, index: true, foreign_key: true + t.belongs_to :product, index: true, foreign_key: true end end end From b03b5407e91a20305fd7e9d5b8f04d990cbd6152 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 17 Oct 2018 19:57:01 -0700 Subject: [PATCH 016/239] Ran migrations --- db/schema.rb | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 2611543b38..6e4a1a16c3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,63 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do +ActiveRecord::Schema.define(version: 2018_10_18_020214) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "categories_products", force: :cascade do |t| + t.bigint "product_id" + t.bigint "category_id" + t.index ["category_id"], name: "index_categories_products_on_category_id" + t.index ["product_id"], name: "index_categories_products_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.string "status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "orders_items", force: :cascade do |t| + t.bigint "order_id" + t.bigint "product_id" + t.index ["order_id"], name: "index_orders_items_on_order_id" + t.index ["product_id"], name: "index_orders_items_on_product_id" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.decimal "price" + t.string "description" + t.string "photo" + t.integer "stock" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "street" + t.string "city" + t.string "state" + t.integer "zip" + t.integer "creditcard" + t.date "ccexpiration" + t.integer "cvv" + t.integer "billingzip" + t.string "photo" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_foreign_key "orders_items", "orders" + add_foreign_key "orders_items", "products" end From e0f116df51eb25f3458bbb55f9512fcb3196ac47 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 09:37:18 -0700 Subject: [PATCH 017/239] Changed product model has_many products to has_many orders --- app/models/product.rb | 2 +- db/migrate/20181018014144_create_categorys_products_join.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index 600c64e97c..46ae089a03 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,7 +1,7 @@ class Product < ApplicationRecord has_and_belongs_to_many :categories belongs_to :user - has_many :products, through: :orders_items + has_many :orders, through: :orders_items end diff --git a/db/migrate/20181018014144_create_categorys_products_join.rb b/db/migrate/20181018014144_create_categorys_products_join.rb index 12a1b487b3..03f743338a 100644 --- a/db/migrate/20181018014144_create_categorys_products_join.rb +++ b/db/migrate/20181018014144_create_categorys_products_join.rb @@ -2,7 +2,7 @@ class CreateCategorysProductsJoin < ActiveRecord::Migration[5.2] def change create_table :categories_products do |t| t.belongs_to :product, index: true - t.belongs_to :category, index: true + t.belongs_to :category, index: true end end end From 81950cdd74082635676a98f77c070b5b24df2913 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 09:38:51 -0700 Subject: [PATCH 018/239] Added User relationship to orders and products --- app/models/order.rb | 1 + app/models/user.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/models/order.rb b/app/models/order.rb index 9f077367bc..35552b8ea7 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,3 +1,4 @@ class Order < ApplicationRecord has_many :products, through: :orders_items + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index 379658a509..86a4c59f8a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,4 @@ class User < ApplicationRecord + has_many :orders + has_many :products end From 03aaa5d4ad6af007a781dfbfa1fbaa356f7e2b05 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 10:04:11 -0700 Subject: [PATCH 019/239] Created new branch for all Merchant/User functionalituy --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 86a4c59f8a..6d16d1e0ef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord has_many :orders - has_many :products + has_many :products + # end From 0e708fe6d23ccd8b8fd6c6db1624ef0545efcdb9 Mon Sep 17 00:00:00 2001 From: KatherineJF Date: Thu, 18 Oct 2018 10:07:05 -0700 Subject: [PATCH 020/239] branch test --- app/controllers/categories_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 0e3d845f08..97fbdc7648 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -3,5 +3,6 @@ def new end def create + #git test end end From a867e717977a03125d63948f0b74ece0cf67c1e4 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 10:08:02 -0700 Subject: [PATCH 021/239] Test comment --- app/models/user.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 86a4c59f8a..e4c9004847 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,7 @@ class User < ApplicationRecord has_many :orders - has_many :products + has_many :products end + + +# Test Comment From c037947ac86470c4674746141bec2c26210c0e6e Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 10:08:20 -0700 Subject: [PATCH 022/239] Testing branch --- app/models/user.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6d16d1e0ef..661dc23ebb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,7 @@ class User < ApplicationRecord has_many :orders has_many :products - # + + def new_user + end end From 8f82580853b284b6aebf5d9010ec63e2c1004c10 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 11:15:05 -0700 Subject: [PATCH 023/239] Began test for orders controller. Added simplecov --- .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 8 ++++++++ test/controllers/orders_controller_test.rb | 16 ++++++++++++++-- test/test_helper.rb | 9 +++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 18b43c9cd2..610761f8fc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Ignore bundler config. /.bundle +coverage/* # Ignore all logfiles and tempfiles. /log/* diff --git a/Gemfile b/Gemfile index 8406aeb8bb..881dbe7870 100644 --- a/Gemfile +++ b/Gemfile @@ -78,4 +78,5 @@ end group :test do gem 'minitest-rails' gem 'minitest-reporters' + gem 'simplecov', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index ca4832eed6..8c3b11cf06 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,7 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) debug_inspector (0.0.3) + docile (1.3.1) erubi (1.7.1) execjs (2.7.0) ffi (1.9.25) @@ -113,6 +114,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks + json (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -205,6 +207,11 @@ GEM childprocess (~> 0.5) rubyzip (~> 1.2, >= 1.2.2) shellany (0.0.1) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -263,6 +270,7 @@ DEPENDENCIES rails (~> 5.2.1) sass-rails (~> 5.0) selenium-webdriver + simplecov spring spring-watcher-listen (~> 2.0.0) turbolinks (~> 5) diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 7546b83a1a..31b2313cc2 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -1,14 +1,26 @@ require "test_helper" describe OrdersController do + # Test new, create, and show it "should get new" do get orders_new_url value(response).must_be :success? end it "should get create" do - get orders_create_url - value(response).must_be :success? + order_hash = { + order: { + status: "pending" + } + } + + expect { + post orders_path, params: order_hash + }.must_change 'Order.count', 1 + + must_respond_with :redirect + + expect(Order.last.status).must_equal order_hash[:order][:status] end it "should get show" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 2b5172a7d6..aacd844785 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,12 @@ +require 'simplecov' +SimpleCov.start 'rails' do + add_filter '/bin/' + add_filter '/db/' + add_filter '/spec/' # for rspec + add_filter '/test/' # for minitest +end ENV["RAILS_ENV"] = "test" + require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" require "minitest/rails"require "minitest/reporters" # for Colorized output @@ -10,6 +18,7 @@ ) + # To add Capybara feature tests add `gem "minitest-rails-capybara"` # to the test group in the Gemfile and uncomment the following: # require "minitest/rails/capybara" From 367b2ac4fdb2f6836ab816c66516c71dbe5b9fe0 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 11:23:55 -0700 Subject: [PATCH 024/239] Added login method for authenticated user to the User Controller --- app/controllers/sessions_controller.rb | 30 ++++++++++++++++++++++++++ app/controllers/users_controller.rb | 15 +++++++++++++ app/models/user.rb | 10 ++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 6737c8cf46..883ef2d961 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,10 +1,40 @@ class SessionsController < ApplicationController def login + auth_hash = request.env['omniauth.auth'] + + user = User.find_by(uid: auth_hash[:uid], provider: 'github') + if user + # User was found in the database + flash[:success] = "Logged in as returning user #{user.name}" + + else + # User doesn't match anything in the DB + # Attempt to create a new user + user = User.build_from_github(auth_hash) + + if user.save + flash[:success] = "Logged in as new user #{user.name}" + + else + # Couldn't save the user for some reason. If we + # hit this it probably means there's a bug with the + # way we've configured GitHub. Our strategy will + # be to display error messages to make future + # debugging easier. + flash[:error] = "Could not create new user account: #{user.errors.messages}" + redirect_to root_path + return + end + end + # If we get here, we have a valid user instance + session[:user_id] = user.id + redirect_to root_path end def destroy end def new + @user = User.new end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cdd598fe30..4f001fdbd5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,4 +7,19 @@ def create def show end + + private + + def find_user + @user = User.find_by(id: params[:id]) + + if @user.nil? + flash.now[:danger] = "Cannot find the user #{params[:id]}" + render :notfound, status: :not_found + end + end + + def user_params + return params.require(:user).permit(:name, :email, :street, :city, :state, :zip, :creditcard, :ccexpiration, :cvv, :billingzip, :photo) + end end diff --git a/app/models/user.rb b/app/models/user.rb index 661dc23ebb..cdd5081534 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,14 @@ class User < ApplicationRecord has_many :orders has_many :products - def new_user + def self.build_from_github(auth_hash) + new_user = User.new + + new_user.uid = auth_hash[:uid] + new_user.provider = 'github' + new_user.name = auth_hash[:info][:name] + new_user.email = auth_hash[:info][:email] + + return new_user end end From e48885c83b5cc75eaf0f61e4a60cb97ffbdeb4c6 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 11:32:49 -0700 Subject: [PATCH 025/239] Commented out unused routes, created routes for order show, new, and create --- config/routes.rb | 37 +++++++++++++++++++------------------ test/test_helper.rb | 3 ++- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index ddb939cc31..a40e7fa816 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,21 +1,22 @@ Rails.application.routes.draw do - get 'sessions/login' - get 'sessions/destroy' - get 'sessions/new' - get 'users/new' - get 'users/create' - get 'users/show' - get 'products/index' - get 'products/show' - get 'products/update' - get 'products/new' - get 'products/create' - get 'products/edit' - get 'products/destroy' - get 'categories/new' - get 'categories/create' - get 'orders/new' - get 'orders/create' - get 'orders/show' + resources :orders, only: [:show, :new, :create] + # get 'sessions/login' + # get 'sessions/destroy' + # get 'sessions/new' + # get 'users/new' + # get 'users/create' + # get 'users/show' + # get 'products/index' + # get 'products/show' + # get 'products/update' + # get 'products/new' + # get 'products/create' + # get 'products/edit' + # get 'products/destroy' + # get 'categories/new' + # get 'categories/create' + # get 'orders/new' + # get 'orders/create' + # get 'orders/show' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/test/test_helper.rb b/test/test_helper.rb index aacd844785..4acc0bcb39 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,7 +9,8 @@ require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" -require "minitest/rails"require "minitest/reporters" # for Colorized output +require "minitest/rails" +require "minitest/reporters" # for Colorized output # For colorful output! Minitest::Reporters.use!( Minitest::Reporters::SpecReporter.new, From 67b4cfff937b727937db55c2b682f9fb473a5f2e Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 11:41:41 -0700 Subject: [PATCH 026/239] Added .env file nad omniauth.rb file to authenticate user --- .gitignore | 3 +++ Gemfile | 3 +++ Gemfile.lock | 28 ++++++++++++++++++++++++++++ app/controllers/users_controller.rb | 1 + config/initializers/omniauth.rb | 3 +++ config/routes.rb | 6 ++++-- 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 config/initializers/omniauth.rb diff --git a/.gitignore b/.gitignore index 18b43c9cd2..4d1a6a32c9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +# Ignore .env file +.env diff --git a/Gemfile b/Gemfile index 8406aeb8bb..c18c5284ae 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,8 @@ gem 'jbuilder', '~> 2.5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false +gem 'omniauth' +gem 'omniauth-github' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console @@ -48,6 +50,7 @@ group :development do # 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' + gem 'dotenv-rails' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index ca4832eed6..f8ba9a6b8d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,8 +81,14 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) debug_inspector (0.0.3) + dotenv (2.5.0) + dotenv-rails (2.5.0) + dotenv (= 2.5.0) + railties (>= 3.2, < 6.0) erubi (1.7.1) execjs (2.7.0) + faraday (0.15.3) + multipart-post (>= 1.2, < 3) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -100,6 +106,7 @@ GEM guard-minitest (2.4.6) guard-compat (~> 1.2) minitest (>= 3.0) + hashie (3.5.7) i18n (1.1.1) concurrent-ruby (~> 1.0) io-like (0.3.0) @@ -113,6 +120,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks + jwt (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -140,6 +148,8 @@ GEM ruby-progressbar msgpack (1.2.4) multi_json (1.13.1) + multi_xml (0.6.0) + multipart-post (2.0.0) nenv (0.3.0) nio4r (2.3.1) nokogiri (1.8.5) @@ -147,6 +157,21 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) + oauth2 (1.4.1) + faraday (>= 0.8, < 0.16.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.8.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) + omniauth-github (1.3.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-oauth2 (1.5.0) + oauth2 (~> 1.1) + omniauth (~> 1.2) pg (1.1.3) popper_js (1.14.3) pry (0.11.3) @@ -249,6 +274,7 @@ DEPENDENCIES byebug capybara (>= 2.15) chromedriver-helper + dotenv-rails guard guard-minitest jbuilder (~> 2.5) @@ -257,6 +283,8 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) minitest-rails minitest-reporters + omniauth + omniauth-github pg (>= 0.18, < 2.0) pry-rails puma (~> 3.11) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4f001fdbd5..3e37cc1aa0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,6 @@ class UsersController < ApplicationController def new + end def create diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..fd4416122a --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/config/routes.rb b/config/routes.rb index ddb939cc31..a84b17a834 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,8 +2,10 @@ get 'sessions/login' get 'sessions/destroy' get 'sessions/new' - get 'users/new' - get 'users/create' + # get 'users/new' + # get 'users/create' + + #resources :users, only: [:] get 'users/show' get 'products/index' get 'products/show' From 9963eb8d786c08ac5af1825431b6fa3d7270631c Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 11:46:16 -0700 Subject: [PATCH 027/239] Added created to orders. Will probably need to be changed. Group will work together on controllers --- test/controllers/orders_controller_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 31b2313cc2..d580965aa4 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -1,4 +1,5 @@ require "test_helper" +require 'pry' describe OrdersController do # Test new, create, and show @@ -13,7 +14,7 @@ status: "pending" } } - + binding.pry expect { post orders_path, params: order_hash }.must_change 'Order.count', 1 From abaff1808bbd5d4ca2d358f227b1bafbf5ecdef0 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 11:47:25 -0700 Subject: [PATCH 028/239] Added authorize user route --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index a84b17a834..86bab6ca10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ get 'sessions/new' # get 'users/new' # get 'users/create' - + get "/auth/:provider/callback", to: "sessions#create" #resources :users, only: [:] get 'users/show' get 'products/index' From 93479e546c5a43e6dc5ac6aa67c514d6aca356c3 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 18 Oct 2018 11:49:32 -0700 Subject: [PATCH 029/239] Added orders controller' --- app/controllers/orders_controller.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 67bbbde994..3f08acec8b 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,10 +1,35 @@ class OrdersController < ApplicationController def new + @order = Order.new + # Find user + # If no user, User.create + if params[:user_id] + @user_id = params[:user_id].to_i + user = User.find_by(id: @user_id) + if user.nil? + flash.now[:warning] = "That user doesn't exit" + end + @order.user_id = @user_id + end end def create - end + @order = Order.new(book_params) + if @order.save # save returns true if the database insert succeeds + flash[:success] = 'Order Created!' + + redirect_to root_path # go to the index so we can see the book in the list + else # save failed :( + flash.now[:danger] = 'Order not created!' + + render :new, status: :bad_request # show the new book form view again + end + end def show end + + def order_params + return params.require(:order).permit(:status) + end end From a7cfde25cb0ebc35e554e09ce32b04b56d9ddfef Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 12:02:34 -0700 Subject: [PATCH 030/239] Merge conflict in the gemfile.lock --- Gemfile.lock | 3 --- 1 file changed, 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 706e25e86c..9d26dd6b94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,11 +124,8 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks -<<<<<<< HEAD jwt (2.1.0) -======= json (2.1.0) ->>>>>>> 93479e546c5a43e6dc5ac6aa67c514d6aca356c3 listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) From e0ee307d2003ba3a57942d1f0cbec7fad4e64c07 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 18 Oct 2018 12:03:35 -0700 Subject: [PATCH 031/239] deleted random line in gemlock file --- Gemfile.lock | 3 --- app/controllers/users_controller.rb | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9d26dd6b94..68f54119bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,14 +81,11 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) debug_inspector (0.0.3) -<<<<<<< HEAD dotenv (2.5.0) dotenv-rails (2.5.0) dotenv (= 2.5.0) railties (>= 3.2, < 6.0) -======= docile (1.3.1) ->>>>>>> 93479e546c5a43e6dc5ac6aa67c514d6aca356c3 erubi (1.7.1) execjs (2.7.0) faraday (0.15.3) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e37cc1aa0..99f91b2861 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController def new - + end def create @@ -21,6 +21,8 @@ def find_user end def user_params + raise return params.require(:user).permit(:name, :email, :street, :city, :state, :zip, :creditcard, :ccexpiration, :cvv, :billingzip, :photo) + raise end end From 59127004226f28fce086e5abf18a9f94cffb1f33 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 15:19:53 -0700 Subject: [PATCH 032/239] We updated the users to have the Oauth fields and then moved all an orders shipping info to the Orders class --- Gemfile.lock | 4 +-- ...20181018220858_move_usercolumnsto_order.rb | 25 +++++++++++++++++++ db/schema.rb | 20 ++++++++------- 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20181018220858_move_usercolumnsto_order.rb diff --git a/Gemfile.lock b/Gemfile.lock index 68f54119bc..5b12ef51ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,11 +81,11 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) debug_inspector (0.0.3) + docile (1.3.1) dotenv (2.5.0) dotenv-rails (2.5.0) dotenv (= 2.5.0) railties (>= 3.2, < 6.0) - docile (1.3.1) erubi (1.7.1) execjs (2.7.0) faraday (0.15.3) @@ -121,8 +121,8 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks - jwt (2.1.0) json (2.1.0) + jwt (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) diff --git a/db/migrate/20181018220858_move_usercolumnsto_order.rb b/db/migrate/20181018220858_move_usercolumnsto_order.rb new file mode 100644 index 0000000000..a889115ccd --- /dev/null +++ b/db/migrate/20181018220858_move_usercolumnsto_order.rb @@ -0,0 +1,25 @@ +class MoveUsercolumnstoOrder < ActiveRecord::Migration[5.2] + def change + #Removing the fields from user and adding them to the orders db and we are also adding the Oauth fields to User + remove_column :users,:street + remove_column :users,:city + remove_column :users,:state + remove_column :users,:zip + remove_column :users,:creditcard + remove_column :users,:ccexpiration + remove_column :users,:cvv + remove_column :users,:billingzip + add_column :users, :uid, :integer, null: false + add_column :users, :provider, :string, null: false + + #User info is stored to an order + add_column :orders, :street, :string + add_column :orders, :city, :string + add_column :orders, :state, :string + add_column :orders, :zip, :integer + add_column :orders, :creditcard, :integer + add_column :orders, :ccexpiration, :date + add_column :orders, :cvv, :integer + add_column :orders, :billingzip, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e4a1a16c3..4d9290d578 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: 2018_10_18_020214) do +ActiveRecord::Schema.define(version: 2018_10_18_220858) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,6 +32,14 @@ t.string "status" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "street" + t.string "city" + t.string "state" + t.integer "zip" + t.integer "creditcard" + t.date "ccexpiration" + t.integer "cvv" + t.integer "billingzip" end create_table "orders_items", force: :cascade do |t| @@ -54,17 +62,11 @@ create_table "users", force: :cascade do |t| t.string "name" t.string "email" - t.string "street" - t.string "city" - t.string "state" - t.integer "zip" - t.integer "creditcard" - t.date "ccexpiration" - t.integer "cvv" - t.integer "billingzip" t.string "photo" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "uid", null: false + t.string "provider", null: false end add_foreign_key "orders_items", "orders" From d3b11d8c13a1fe7979e3a42a85fc2b1294de799a Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 16:32:51 -0700 Subject: [PATCH 033/239] Added Category controller methods and application controller methods --- app/controllers/application_controller.rb | 13 +++++++++++++ app/controllers/categories_controller.rb | 22 ++++++++++++++++++++++ app/controllers/sessions_controller.rb | 6 +----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12ab..e8cafbf2cd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,15 @@ class ApplicationController < ActionController::Base + before_action :find_user + + private + + # def find_user + # @current_user = User.find_by(id: session[:user_id]) + # end + # + # def is_merchant? + # return User.find_by(uid: session[:uid], provider: 'github') + # end + + end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 0e3d845f08..c7cf745702 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -3,5 +3,27 @@ def new end def create + @category = Category.new(category_params) + + if @category.save + flash[:success] = "#{@category.name} added!" + redirect_to user_path end + + def show + @category = Category.find_by(id: params[:id]) + + if @cateogry.nil? + flash.now[:danger] = "Cannot find the category #{params[:id]}" + render :notfound, status: :not_found + end + end + + private + + def category_params + return params.require(:category).permit(:name) + end + + end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 883ef2d961..9d264826b6 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -16,11 +16,7 @@ def login flash[:success] = "Logged in as new user #{user.name}" else - # Couldn't save the user for some reason. If we - # hit this it probably means there's a bug with the - # way we've configured GitHub. Our strategy will - # be to display error messages to make future - # debugging easier. + # Couldn't save the user flash[:error] = "Could not create new user account: #{user.errors.messages}" redirect_to root_path return From fcb633ffa924bade9f96c970572d6c56ebb855d6 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 16:56:01 -0700 Subject: [PATCH 034/239] Added is_merchant method to the application controller --- app/controllers/application_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e8cafbf2cd..f079c9e414 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - before_action :find_user + before_action :is_merchant? private @@ -7,9 +7,9 @@ class ApplicationController < ActionController::Base # @current_user = User.find_by(id: session[:user_id]) # end # - # def is_merchant? - # return User.find_by(uid: session[:uid], provider: 'github') - # end + def is_merchant? + return User.find_by(id: session[:user_id], provider: 'github') + end end From 0a22aa23f714b298e6aeba2d4a331408e5cbc965 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 17:29:34 -0700 Subject: [PATCH 035/239] Added the application controller methods find_merchant, is_merchant, set_order --- app/controllers/application_controller.rb | 31 ++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f079c9e414..a52893a914 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,15 +1,34 @@ class ApplicationController < ActionController::Base + before_action :find_merchant before_action :is_merchant? - + before_action :set_order private - # def find_user - # @current_user = User.find_by(id: session[:user_id]) - # end - # + def find_merchant + @merchant = User.find_by(id: session[:user_id], provider: 'github') + end + def is_merchant? - return User.find_by(id: session[:user_id], provider: 'github') + return @merchant + end + + def set_order + #Does an order exist? + @order = Order.find(session[:order_id]) + + #There is no order in the db + if @order.nil? + if @merchant #Does the order have a merchant? + @order = Order.create(user_id: @merchant.id, status: "pending") + session[:order_id] = @order.id + else #They are checking out as a guest, there won't be a user_id relation + @order = Order.create(status: "pending") + session[:order_id] = @order.id + end + end + end + end From 2da6c719037436aa8a440c1cebd9da8879a9b59b Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 18 Oct 2018 18:15:28 -0700 Subject: [PATCH 036/239] removed user params that had all address info --- app/controllers/users_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 99f91b2861..4f001fdbd5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,5 @@ class UsersController < ApplicationController def new - end def create @@ -21,8 +20,6 @@ def find_user end def user_params - raise return params.require(:user).permit(:name, :email, :street, :city, :state, :zip, :creditcard, :ccexpiration, :cvv, :billingzip, :photo) - raise end end From 774f7dd23ad5490c98db26f2991baa5971819630 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 19:14:03 -0700 Subject: [PATCH 037/239] Added the seed files --- app/models/order.rb | 2 +- db/schema.rb | 9 +++-- db/seeds.rb | 99 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 4 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 35552b8ea7..fc4180aa27 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,4 @@ class Order < ApplicationRecord has_many :products, through: :orders_items - belongs_to :user + belongs_to :user, optional: true end diff --git a/db/schema.rb b/db/schema.rb index 4d9290d578..1330c614e6 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: 2018_10_18_220858) do +ActiveRecord::Schema.define(version: 2018_10_19_013807) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -57,6 +57,8 @@ t.integer "stock" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "user_id" + t.index ["user_id"], name: "index_products_on_user_id" end create_table "users", force: :cascade do |t| @@ -65,10 +67,11 @@ t.string "photo" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "uid", null: false - t.string "provider", null: false + t.integer "uid" + t.string "provider" end add_foreign_key "orders_items", "orders" add_foreign_key "orders_items", "products" + add_foreign_key "products", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2accd..8a7f9b1ea6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,102 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +require 'csv' + + +CATEGORY_FILE = Rails.root.join('db', 'category_seeds.csv') +puts "Loading raw category data from #{CATEGORY_FILE}" + +category_failures = [] +CSV.foreach(CATEGORY_FILE, :headers => true) do |row| + category = Category.new + category.name = row['name'] + successful = category.save + if !successful + category_failures << category + puts "Failed to save categories: #{category.inspect}" + else + puts "Created categories: #{category.inspect}" + end +end + +puts "Added #{Category.count} category records" +puts "#{category_failures.length} category failed to save" + +#-------------------------------------------------------- + +USER_FILE = Rails.root.join('db', 'user_seeds.csv') +puts "Loading raw user data from #{USER_FILE}" + +user_failures = [] +CSV.foreach(USER_FILE, :headers => true) do |row| + user = User.new + user.name = row['name'] + user.email = row['email'] + user.photo = row['photo'] + successful = user.save + if !successful + user_failures << user + puts "Failed to save users: #{user.inspect}" + else + puts "Created users: #{user.inspect}" + end +end + +puts "Added #{User.count} user records" +puts "#{user_failures.length} user failed to save" + +#-------------------------------------------------------- + +ORDERS_FILE = Rails.root.join('db', 'order_seeds.csv') +puts "Loading raw order data from #{ORDERS_FILE}" + +order_failures = [] +CSV.foreach(ORDERS_FILE, :headers => true) do |row| + order= Order.new + order.status = row['status'] + order.street = row['street'] + order.city = row['city'] + order.state = row['state'] + order.zip = row['zip'] + order.creditcard = row['creditcard'] + order.ccexpiration = Date.parse(row['ccexpiration']) + order.cvv = row['cvv'] + order.billingzip = row['billingzip'] + successful = order.save + if !successful + order_failures << order + puts "Failed to save orders: #{order.inspect}" + else + puts "Created orders: #{order.inspect}" + end +end + +puts "Added #{Order.count} order records" +puts "#{order_failures.length} order failed to save" + +#-------------------------------------------------------- + +PRODUCTS_FILE = Rails.root.join('db', 'product_seeds.csv') +puts "Loading raw product data from #{PRODUCTS_FILE}" + +product_failures = [] +CSV.foreach(PRODUCTS_FILE, :headers => true) do |row| + product = Product.new + product.name = row['name'] + product.price = row['price'] + product.description = row['description'] + product.photo = row['photo'] + product.stock = row['stock'] + product.user_id = row['user_id'] + successful = product.save + if !successful + product_failures << product + puts "Failed to save products: #{product.inspect}" + else + puts "Created products: #{product.inspect}" + end +end + +puts "Added #{Product.count} product records" +puts "#{product_failures.length} product failed to save" From b7f120681591b510c39483e7229c5fd6686fd0c7 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 18 Oct 2018 19:17:33 -0700 Subject: [PATCH 038/239] Updated the fk to the product to tie to the suer and then, and removed the requirement for user to have an id --- .../20181019011642_removerequirementfor_usercolumns.rb | 6 ++++++ db/migrate/20181019012707_remvoing.rb | 6 ++++++ .../20181019012938_add_uidand_providerto_useras_optional.rb | 6 ++++++ db/migrate/20181019013807_fk_userto_product.rb | 5 +++++ 4 files changed, 23 insertions(+) create mode 100644 db/migrate/20181019011642_removerequirementfor_usercolumns.rb create mode 100644 db/migrate/20181019012707_remvoing.rb create mode 100644 db/migrate/20181019012938_add_uidand_providerto_useras_optional.rb create mode 100644 db/migrate/20181019013807_fk_userto_product.rb diff --git a/db/migrate/20181019011642_removerequirementfor_usercolumns.rb b/db/migrate/20181019011642_removerequirementfor_usercolumns.rb new file mode 100644 index 0000000000..19cf142838 --- /dev/null +++ b/db/migrate/20181019011642_removerequirementfor_usercolumns.rb @@ -0,0 +1,6 @@ +class RemoverequirementforUsercolumns < ActiveRecord::Migration[5.2] + def change + change_column :users, :uid, :integer, optional: true + change_column :users, :provider, :string, optional: true + end +end diff --git a/db/migrate/20181019012707_remvoing.rb b/db/migrate/20181019012707_remvoing.rb new file mode 100644 index 0000000000..605c7ac131 --- /dev/null +++ b/db/migrate/20181019012707_remvoing.rb @@ -0,0 +1,6 @@ +class Remvoing < ActiveRecord::Migration[5.2] + def change + remove_column :users, :uid + remove_column :users, :provider + end +end diff --git a/db/migrate/20181019012938_add_uidand_providerto_useras_optional.rb b/db/migrate/20181019012938_add_uidand_providerto_useras_optional.rb new file mode 100644 index 0000000000..d2f3849788 --- /dev/null +++ b/db/migrate/20181019012938_add_uidand_providerto_useras_optional.rb @@ -0,0 +1,6 @@ +class AddUidandProvidertoUserasOptional < ActiveRecord::Migration[5.2] + def change + add_column :users, :uid, :integer, optional: true + add_column :users, :provider, :string, optional: true + end +end diff --git a/db/migrate/20181019013807_fk_userto_product.rb b/db/migrate/20181019013807_fk_userto_product.rb new file mode 100644 index 0000000000..2c236d90bb --- /dev/null +++ b/db/migrate/20181019013807_fk_userto_product.rb @@ -0,0 +1,5 @@ +class FkUsertoProduct < ActiveRecord::Migration[5.2] + def change + add_reference :products, :user, foreign_key: true + end +end From f00742262d6b63acd9213a87ad3254387f26baba Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 18 Oct 2018 19:28:59 -0700 Subject: [PATCH 039/239] created product index pg and work pg and started a form page which the merchant will use to add new products --- app/assets/stylesheets/application.scss | 87 ++++++++++++++++++++++- app/controllers/application_controller.rb | 2 +- app/views/layouts/application.html.erb | 26 +++++++ app/views/products/_form.html.erb | 37 ++++++++++ app/views/products/index.html.erb | 2 + app/views/products/show.html.erb | 18 +++++ config/routes.rb | 4 +- 7 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 app/views/products/_form.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8b1701e581..be9bf95309 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,6 +13,91 @@ */ /* Custom bootstrap variables must be set or imported *before* bootstrap. */ -@import "bootstrap"; + /* Import scss content */ @import "**/*"; + +@import "bootstrap"; + + +$primary-font: 'Gudea', sans-serif; +$primary-teal: #26A69A; +$dark-teal: #00796B; +$secondary-color: grey; +$light-gray: #EEEEEE; +$dark-gray: #424242; +$gold: #FF5722; + +$default-border: 2px solid; + +body, h1, h2, h3, h4, h5 { + font-family: $primary-font +} + +h1, h2, h3, h4, h5 { + font-weight: bold; +} + +a, h2, h3 { + color: $primary-teal; +} + +a:hover { + color: $dark-teal; + text-decoration: none; +} + + + + +// navigation styling + + +.app-header__nav { + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.app-header__nav_item { + margin-top: 1rem; +} + +.app-header__nav_item .nav-link { + color: white; +} + +.app-header__site-nav-container .app-header__nav_item { + margin-right: 2rem; +} + +.app-header__user-nav-container .nav-item { + margin-left: 2rem; +} + +.list-group-item { + border: none; +} + +.app-header__header { + max-width: 100%; + background-color: $secondary-color; + margin-bottom: 0.5rem; + padding: 2rem 1rem 0.5rem 1rem; + h1 { + text-align: center; + margin: 25px auto 40px auto; + a { + color: black; + padding-right: 25px; + margin-right: 15px; + } + small { + color: white; + border-bottom: white 2px solid; + } + } + p { + margin-bottom: 5px; + } +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a52893a914..a2afc502b1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,7 +14,7 @@ def is_merchant? def set_order #Does an order exist? - @order = Order.find(session[:order_id]) + @order = Order.find_by(id:session[:order_id]) #There is no order in the db if @order.nil? diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f18f1b6820..567bef47d2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,32 @@ +
+

+ <%= link_to "Thrillow", products_path %> + find your thrill +

+ +

My Products

    - <%= @merchant.products.each do |product| %> + <% @merchant.products.each do |product| %>
  • <%= "#{product.name}" %>

    - <%# image_tag("product.photo"), alt="#{product.name} image" %>

    <%= "Price: #{product.price}" %>

    <%= "Description: #{product.description}" %>

    <%= "Stock: #{product.stock}" %>

    - <%= link_to "Retire Product", retire_path(product.id), class: "btn btn-primary", method: :post %> + <%# link_to "Retire Product", retire_path(product.id), class: "btn btn-primary", method: :post %> <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %>
  • @@ -43,8 +54,8 @@

    Orders

    - <%= render partial: "statussummary" %> -
      + <%= render partial: "statussummary" %> + - <% @order_items.each do |item| %> - - - <%= link_to "#{item.order.id}", order_path(item.order.id) %> - - - <%= item.order.updated_at %> - - - <%= link_to "#{item.product.name}", product_path(item.product.id) %> - - - <%= item.product.price %> - - - <%= item.quantity %> - - - <%= "Subtotal Here - Katherine creating this in order item?" %> - - - <%= item.order.status.capitalize %> - - - <%= "TODO SHIPPED STATUS" %> - - - <%= "TODO - Option to edit shipped status" %> - - - <% end %> - - +
    <% end %> From 55ff390a77bccdc2ea2bda0e51bdff7aa81ada10 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 17:06:30 -0700 Subject: [PATCH 131/239] Continued work on dashboard --- app/views/users/_statussummary.html.erb | 3 +- app/views/users/dashboard.html.erb | 51 ++++++++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index 309892fc4c..c99e331780 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -1,5 +1,4 @@ -

    <%= "#{action_name} Order Summary" %>

    -

    <%= "Summary" %>

    +

    <%= "Order Summary" %>

    diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index aacbaa99b0..584ba3a728 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -34,21 +34,52 @@

    My Products

    -
      - <% @merchant.products.each do |product| %> -
    • -

      <%= "#{product.name}" %>

      -

      <%= "Price: #{product.price}" %>

      -

      <%= "Description: #{product.description}" %>

      -

      <%= "Stock: #{product.stock}" %>

      + +
    + + + + + + + + + + <% @merchant.products.each do |product| %> + + + + + + + + <%# link_to "Retire Product", retire_path(product.id), class: "btn btn-primary", method: :post %> <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %> - - <% end %> - + <% end %> + + +
    + <%= "Name" %> + + <%= "Price" %> + + <%= "Description" %> + + <%= "Stock" %> +
    +

    <%= "#{product.name}" %>

    +
    +

    <%= "Price: #{product.price}" %>

    +
    +

    <%= "Description: #{product.description}" %>

    +
    +

    <%= "Stock: #{product.stock}" %>

    +
    +
From 52360c498181d541ed0c3dffe843830fe603f402 Mon Sep 17 00:00:00 2001 From: Kay Date: Wed, 24 Oct 2018 17:18:47 -0700 Subject: [PATCH 132/239] working on the new form for product index so that we can assign a product to multiple categories via radio buttons --- app/models/category.rb | 10 ++++++---- app/models/product.rb | 14 +++++++++++++- app/views/products/_form.html.erb | 15 +++++++++------ app/views/products/new.html.erb | 11 ++++++++++- app/views/users/dashboard.html.erb | 2 +- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/models/category.rb b/app/models/category.rb index 7e582446ce..0e0d40e488 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -13,10 +13,12 @@ class Category < ApplicationRecord def product_photo photos = [] - self.products.each do |product| - photos << product.photo - end - return photos.sample + self.products.each do |product| + photos << product.photo end + return photos.sample + end + + end diff --git a/app/models/product.rb b/app/models/product.rb index ba428e2b8d..59e61c7512 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -8,11 +8,23 @@ class Product < ApplicationRecord validates :name, presence: true validates_uniqueness_of :name, :scope => [:user_id] - # message: "user already has a product with that name" } + # message: "user already has a product with that name" } validates :price, presence: true, numericality: {greater_than: 0} validates :description, presence: true validates :photo, presence: true validates :stock, presence: true + + def self.category_list + categories = [] + Product.all.each do |product| + product.categories.each do |category| + categories << category.name + end + end + return categories.uniq + end + + end diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index b27a02bb51..1036496585 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -15,21 +15,24 @@ <% end %> <%= form_with model: @product, class: "form" do |f|%> - <%# f.label :category %> - <%# f.select :category, ['album','book','movie'], class: 'form__input'%> + <%= f.label :category %> + <%= f.radio_button :category, options_for_select(Product.category_list), class: ''%> <%= f.label :price %> - <%= f.text_field :price, class: "form__input"%> + <%= f.text_field :price, class: ""%> <%= f.label :name %> - <%= f.text_field :name, class: "form__input"%> + <%= f.text_field :name, class: ""%> <%= f.label :description %> - <%= f.text_field :description, class: "form__input"%> + <%= f.text_field :description, class: ""%> <%= f.label :stock %> - <%= f.text_field :stock, class: "form__input" %> + <%= f.text_field :stock, class: "" %> + + <%# f.label :photo %> + <%# f.text_field :photo, class: "form__input" %> <%= f.submit button_title, class: 'btn'%> <% end %> diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index a14e0d91b6..1dccc999fa 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -1,2 +1,11 @@ -

Products#new

+
+
+
+ +

Hey <%= @product.user.name %>! Add a New Product!

+

Find me in app/views/products/new.html.erb

+ +
+<%= render partial: "form", locals: { action_name: "Create New Product", button_title: 'Save' } %> +
diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index e91d1b07c1..22fcacae09 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -23,7 +23,7 @@

My Products

    - <%= @merchant.products.each do |product| %> + <% @merchant.products.each do |product| %>
  • <%= "#{product.name}" %>

    <%# image_tag("product.photo"), alt="#{product.name} image" %> From 93715290706b590b567d855ca9ce6c6600895fe7 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Wed, 24 Oct 2018 17:39:41 -0700 Subject: [PATCH 133/239] updated forms --- app/controllers/orders_controller.rb | 45 ++- app/helpers/orders_helper.rb | 53 ++++ app/views/orders/edit.html.erb | 437 +++++++++++++++++++++++++++ app/views/products/_form.html.erb | 5 - app/views/products/index.html.erb | 2 +- config/routes.rb | 4 +- 6 files changed, 528 insertions(+), 18 deletions(-) create mode 100644 app/views/orders/edit.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index b7a804c7a7..50b5aaee35 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -16,18 +16,34 @@ def new end end - def create - @order = Order.new(order_params) - if @order.save # save returns true if the database insert succeeds - flash[:success] = 'Order Created!' + # def create + # @order = Order.new(order_params) + # if @order.save # save returns true if the database insert succeeds + # flash[:success] = 'Order Created!' + # + # redirect_to root_path # go to the index so we can see the book in the list + # else # save failed :( + # flash.now[:danger] = 'Order not created!' + # + # render :new, status: :bad_request # show the new book form view again + # end + # end - redirect_to root_path # go to the index so we can see the book in the list - else # save failed :( - flash.now[:danger] = 'Order not created!' + def edit + end - render :new, status: :bad_request # show the new book form view again - end - end + def update + if @order && @order.update(order_params) + flash[:status] = :success + flash[:result_text] = "Success! Order #{@order.id} is complete! Enjoy your unique home!" + redirect_to order_path(@order.id) #Redirect to order confirmation + else + flash.now[:status] = :failure + flash.now[:result_text] = "Could not update #{@order.id}. Please check the forms" + flash.now[:messages] = @order.errors.messages + render :edit, status: :bad_request + end + end def show @order = Order.find_by(id:session[:order_id]) @@ -42,4 +58,13 @@ def order_params return params.require(:order).permit(:status) end + def find_order + @order = Order.find_by(id: params[:id].to_i) + + if @order.nil? + flash.now[:danger] = "Cannot find the order #{params[:id]}" + render :notfound + end + end + end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 443227fd48..7f94d1f77e 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -1,2 +1,55 @@ module OrdersHelper + def us_states + states =["AL", + "AK", + "AZ", + "AR", + "CA", + "CO", + "CT", + "DE", + "FL", + "GA", + "HI", + "ID", + "IL", + "IN", + "IA", + "KS", + "KY", + "LA", + "ME", + "MD", + "MA", + "MI", + "MN", + "MS", + "MO", + "MT", + "NE", + "NV", + "NH", + "NJ", + "NM", + "NY", + "NC", + "ND", + "OH", + "OK", + "OR", + "PA", + "RI", + "SC", + "SD", + "TN", + "TX", + "UT", + "VT", + "VA", + "WA", + "WV", + "WI", + "WY"] + return states + end end diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000000..09f47a629b --- /dev/null +++ b/app/views/orders/edit.html.erb @@ -0,0 +1,437 @@ + +
    + <% if @order.errors.any? %> +
      + <% @order.errors.each do |column, message| %> +
    • + <%= column.capitalize %> <%= message %> +
    • + <% end %> +
    + <% end %> + +
    +
    + +

    Checkout

    +
    + +
    +
    +

    + Your cart + 3 +

    +
      + <% @order.orders_items.each do |item| %> +
    • +
      +
      <%=item.name%>
      + <%=item.description%> +
      + <%=item.price%> +
    • + <% end %> +
    • + Total (USD) + Update with method +
    • +
    + <%= form_with model: @order, class: "form" do |f|%> + +
    +

    Billing address

    +
    +
    + <%= f.label :name %> +
    + <%= f.text_field :name, class: "form-control" ,id:"username", required:""%> +
    + Your name is required. +
    +
    +
    +
    + + +
    + Please enter a valid email address for shipping updates. +
    +
    + +
    + + +
    + Please enter your shipping address. +
    +
    + +
    + + +
    + +
    +
    + + +
    + Please select a valid country. +
    +
    +
    + <%= f.label :state %> + <%= select_tag :state, options_for_select(us_states) %> +
    + Please provide a valid state. +
    +
    +
    + <%= f.label :zip %> + +
    + Zip code required. +
    +
    +
    +
    +
    + + +
    +
    + + +
    +
    + +

    Payment

    + + +
    +
    + + + Full name as displayed on card +
    + Name on card is required +
    +
    +
    + <%= f.label :creditcard %> + +
    + Credit card number is required +
    +
    +
    +
    +
    + <%= f.label :ccexpiration %> + +
    + Expiration date required +
    +
    +
    + <%= f.label :cvv %> + +
    + Security code required +
    +
    +
    +
    + +
    +
    +
    + + <%# f.label :category %> + <%# f.select :category, ['album','book','movie'], class: 'form__input'%> + + <%= f.label :price %> + <%= f.text_field :price, class: "form__input"%> + + <%= f.label :name %> + <%= f.text_field :name, class: "form__input"%> + + + <%= f.label :description %> + <%= f.text_field :description, class: "form__input"%> + + <%= f.label :stock %> + <%= f.text_field :stock, class: "form__input" %> + + + <%= f.submit 'Checkout', class: 'btn'%> + <% end %> +
    + + +
    +
    + +

    Checkout form

    +

    Below is an example form built entirely with Bootstrap's form controls. Each required form group has a validation state that can be triggered by attempting to submit the form without completing it.

    +
    + +
    +
    +

    + Your cart + <%=@order.orders_items.length%> +

    +
      +
    • +
      +
      Product name
      + Brief description +
      + $12 +
    • +
    • +
      +
      Second product
      + Brief description +
      + $8 +
    • +
    • +
      +
      Third item
      + Brief description +
      + $5 +
    • +
    • +
      +
      Promo code
      + EXAMPLECODE +
      + -$5 +
    • +
    • + Total (USD) + $20 +
    • +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    +

    Billing address

    +
    +
    +
    + + +
    + Valid first name is required. +
    +
    +
    + + +
    + Valid last name is required. +
    +
    +
    + +
    + +
    +
    + @ +
    + +
    + Your username is required. +
    +
    +
    + +
    + + +
    + Please enter a valid email address for shipping updates. +
    +
    + +
    + + +
    + Please enter your shipping address. +
    +
    + +
    + + +
    + +
    +
    + + +
    + Please select a valid country. +
    +
    +
    + + +
    + Please provide a valid state. +
    +
    +
    + + +
    + Zip code required. +
    +
    +
    +
    +
    + + +
    +
    + + +
    +
    + +

    Payment

    + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + + + Full name as displayed on card +
    + Name on card is required +
    +
    +
    + + +
    + Credit card number is required +
    +
    +
    +
    +
    + + +
    + Expiration date required +
    +
    +
    + + +
    + Security code required +
    +
    +
    +
    + +
    +
    +
    + + +
    + + + + + + + + + + + + diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index b27a02bb51..ab9105aa02 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,8 +1,3 @@ - -
    <% if @product.errors.any? %>
      diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index d24c1552c7..495028090b 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -4,7 +4,7 @@
      loop thru all @products
      - <% @products.each do |product| %> +<% @products.each do |product| %>
      diff --git a/config/routes.rb b/config/routes.rb index dedadeadb3..b721509cf8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,10 +33,10 @@ # get '/products/:id', to: 'products#show', as: 'product' resources :categories, only: [ :new, :create, :index , :show] - + # get 'categories/new' # get 'categories/create' - resources :orders, only: [:show, :new, :create, :index] do + resources :orders, only: [:show, :new, :create, :index,:edit,:update] do resources :orders_items, only: [:create, :new, :show] end post '/products/:id/add_to_cart', to: "products#add_to_cart", as: "add_to_cart" From f19836d0fd226a6fe404d4b225f76ba60c1a2e64 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 17:40:19 -0700 Subject: [PATCH 134/239] Dashboard view work --- app/views/users/dashboard.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 584ba3a728..6bc862f190 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -4,7 +4,7 @@
      -

      <%= "#{@merchant.name}'s Dashboard" %>

      +

      <%= "#{@merchant.name}'s Dashboard" %>

      From f7eb5e660c895b0e4db4a690ec3c5a44493ab4cc Mon Sep 17 00:00:00 2001 From: KatherineJF Date: Wed, 24 Oct 2018 17:46:32 -0700 Subject: [PATCH 135/239] Order Cart with subtotal and link --- app/controllers/application_controller.rb | 20 +- app/controllers/orders_controller.rb | 78 +++-- app/controllers/orders_items_controller.rb | 36 +- app/controllers/products_controller.rb | 15 +- app/models/order.rb | 34 +- app/models/orders_item.rb | 4 + app/views/layouts/application.html.erb | 3 + app/views/orders/show.html.erb | 19 +- app/views/orders_items/show.html.erb | 14 - app/views/products/show.html.erb | 8 +- app/views/users/dashboard.html.erb | 2 +- config/routes.rb | 13 +- test/controllers/orders_controller_test.rb | 317 +++++++++--------- .../orders_items_controller_test.rb | 10 + 14 files changed, 328 insertions(+), 245 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1d7951b34c..dcca18e188 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,14 +42,22 @@ def find_user def current_order # If nil, make one # Else, find and use the current one - if session[:order_id].nil? + + #Try and find the order + @current_order = Order.find_by(id: session[:order_id], status: "pending") + #if the @current_order object is nil it will return true + if @current_order.nil? # + #create @current_order if @current_order is nil @current_order = Order.create(status: "pending") - session[:order_id] = @current_order.id - return @current_order - else - @current_order = Order.find_by(id: session[:order_id]) - return @current_order + session[:order_id] = @current_order.id + + # else #needs to move above the create nil + # #write a test to show the weakness of a project + # return @current_order + # + #what happens if find_by returns nil because it can? end + return @current_order end # def current_order diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index b7a804c7a7..6bffbb0d7d 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,33 +1,37 @@ class OrdersController < ApplicationController + # + # def new #WRONG TO HAVE @ORDER + # #doesn't exist on the website + # #new is created by before action + # @order = Order.new + # # Find user + # # If no user, User.create + # if params[:user_id] + # @user_id = params[:user_id].to_i + # user = User.find_by(id: @user_id) + # if user.nil? + # flash.now[:warning] = "That user doesn't exit" + # end + # @order.user_id = @user_id + # end + # end - def new - @order = Order.new - # Find user - # If no user, User.create - if params[:user_id] - @user_id = params[:user_id].to_i - user = User.find_by(id: @user_id) - if user.nil? - flash.now[:warning] = "That user doesn't exit" - end - @order.user_id = @user_id - end - end - - def create - @order = Order.new(order_params) - if @order.save # save returns true if the database insert succeeds - flash[:success] = 'Order Created!' - - redirect_to root_path # go to the index so we can see the book in the list - else # save failed :( - flash.now[:danger] = 'Order not created!' - - render :new, status: :bad_request # show the new book form view again - end - end + # def create + # #don't need create + # + # @current_order = Order.new(order_params) + # if @order.save # save returns true if the database insert succeeds + # flash[:success] = 'Order Created!' + # + # redirect_to root_path # go to the index so we can see the book in the list + # else # save failed :( + # flash.now[:danger] = 'Order not created!' + # + # render :new, status: :bad_request # show the new book form view again + # end + # end def show @order = Order.find_by(id:session[:order_id]) @@ -37,9 +41,29 @@ def index @orders = Order.all end + def edit + #will display the form the user fills out with address ect.. + #this is the view + #partial called edit.erb + #get returns a result + end + + def update + #patch + #this does not have an .erb + #the form posts to the update method + #will recieve a post from edit and it will toggle the order to complete + #save order + #get the order and update it + end + + def destroy + end + private def order_params - return params.require(:order).permit(:status) + return params.require(:order).permit(:status, :street, :city, :state, :zip, + :creditcard, :cvv, :billingzip, :ccexpiration, :user_id) end end diff --git a/app/controllers/orders_items_controller.rb b/app/controllers/orders_items_controller.rb index bc11456cb5..b282b3e9f3 100644 --- a/app/controllers/orders_items_controller.rb +++ b/app/controllers/orders_items_controller.rb @@ -4,28 +4,36 @@ class OrdersItemsController < ApplicationController #add hidden field to products index each do captures price and quantity def new - @orders_items = OrdersItem.new + # @orders_items = OrdersItem.new end def create - @orders_items = OrdersItem.new.add_product(params ) #add orders_items - - #Product id and quantity - # - # redirect_to orders_path - if @order.save - redirect_to orders_path - else - flash[:error] = 'There was a problem addding this to your cart' - redirect_to root_path #update to fallback to last page or product show - end + # @orders_items = OrdersItem.new.add_product(params ) #add orders_items + # + # #Product id and quantity + # # + # # redirect_to orders_path + # if @order.save + # redirect_to orders_path + # else + # flash[:error] = 'There was a problem addding this to your cart' + # redirect_to root_path #update to fallback to last page or product show + # end + end + + def update + #update the quantity of the orderitem end def destroy + + @orders_item = @current_order.orders_items.find(params[:id]) @orders_item.destroy - redirect_to order_path + @current_order.save + redirect_to order_path(@current_order) end + # def add_to_cart # product = Product.find_by(id: params[:id]) # order = Order.find_by(id: session[:order_id])) @@ -43,7 +51,7 @@ def set_order_item end def order_item_params - params.require(:order_item).permit(:product_id, :order_id, :quantity, :price) + params.require(:order_item).permit(:product_id, :order_id, :quantity) end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 09d4d9ccfa..144554a914 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -17,11 +17,18 @@ def index def show; end def add_to_cart - product = Product.find_by(id: params[:id]) - # order = Order.find_by(id: session[:order_id]) - @orders_item = OrdersItem.create(product_id: product.id, order_id: @current_order.id, quantity: 1) - # binding.pry + #calling method add_product in model that + quantity = 1 #if you call this method you get at least one item + #1 becomes the default so you have at least one order item + if !params[:quantity].nil? #making sure not nil + #quantity comes in as a string, to avoid spam comes as 0 + #quantity - checks for positive number greater than one. if you return put + #-4 you would get -4 but with the .max value it get the biggest number + #if they don't pass in a number the default is 1 + quantity = [params[:quantity].to_i, quantity].max + end + @current_order.add_product(params[:product_id], quantity) redirect_to root_path end diff --git a/app/models/order.rb b/app/models/order.rb index b18bf6e86c..6e1b8ff6af 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,5 +1,6 @@ -class Order < ApplicationRecord + class Order < ApplicationRecord has_many :orders_items, dependent: :destroy + #if you destroy the order items associated with it has_many :products, through: :orders_items, dependent: :destroy validates_inclusion_of :status, :in => ["pending", "paid","complete", "cancelled"], presence: :true @@ -23,22 +24,37 @@ class Order < ApplicationRecord # quantity: 20 # } # } - def add_product(product_params) + def add_product(product_id, quantity) #Find out if the current product is in the cart - current_product = OrdersItem.find_by(product_id: product_params[:orders_item][:product_id]) + current_item = OrdersItem.find_by(product_id: product_id, order_id: self.id) #If current_product is in the cart then - if current_product + if current_item #the current_product is an instance of OrdersItem which has quantity attribute - current_product.quantity += product_params[:orders_item][:quantity].to_i - current_product.save + #increase the quantity then update it + current_item.quantity += quantity + current_item.save else #create a new instance of OrderItems with product params - current_product = OrdersItem.create(product_id: product_params[:orders_item][:product_id], - quantity: product_params[:orders_item][:quantity], + #this is what OrderItems was doing - if you have an orderitem you + #want to add it to the order + #when you update cart will create order item + current_item = OrdersItem.create(product_id: product_id, + quantity: quantity, order_id: self.id) end - return current_product + return current_item + end + + # def order_calculate_total(product_id) + # self.orders_items.each do |current_item| + # total_cost += current_item.calculate_total + # end + # end + + def items_in_cart + # TODO: Update to return accurate quanity of all items in cart + return self.orders_items.count end end diff --git a/app/models/orders_item.rb b/app/models/orders_item.rb index bed471418b..cbfcc773b7 100644 --- a/app/models/orders_item.rb +++ b/app/models/orders_item.rb @@ -1,4 +1,8 @@ class OrdersItem < ApplicationRecord belongs_to :product belongs_to :order + + def calculate_total + return self.product.price * self.quantity + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1778dbf644..fe427b9ccc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -27,6 +27,9 @@
    • <%= link_to "Shop By Sellers", users_path, class: "" %>
    • +
    • + <%= link_to "Shopping Cart (#{@current_order.items_in_cart})", order_path(@current_order), class: "" %> +
    • <% if session[:user_id] %> <%= link_to "Log out", logout_path, method: "delete" %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 3c89e8f240..2a5180c03e 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -12,6 +12,21 @@
    • <%= orders_item.product.price %>
    • - <% end %> -
    +
  • + <%= orders_item.quantity %> +
  • +
  • + <%= orders_item.calculate_total %> +
  • +
  • <%= link_to "Remove Item from Cart", order_orders_item_path(@order.id, orders_item.id), :method => :delete %>
  • + + + + + <% end %> +<% end %> +
+/orders/:order_id/orders_items/:id(.:format) + diff --git a/app/views/orders_items/show.html.erb b/app/views/orders_items/show.html.erb index e3ea18db00..e69de29bb2 100644 --- a/app/views/orders_items/show.html.erb +++ b/app/views/orders_items/show.html.erb @@ -1,14 +0,0 @@ -

- Order Items -

-
    - -

    - <% @orders_items.each do |orders_item| %> -
    -
  • <%= orders_item %>
  • - <% end %> -

    - - -
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 1f09eaecf2..bc828100a6 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -14,7 +14,13 @@
  • <%# @product.category %> look up how to create a dropdown for category
  • <% end %> -<%= button_to "Add to Cart", add_to_cart_path(@product.id), method: :add_to_cart %> + +<%= form_with url: product_add_to_cart_path(@product.id) do |f|%> + <%= f.label :quantity %> + <%= f.text_field :quantity %> + <%= f.submit "Add to Cart" %> +<% end %> + --> diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index e91d1b07c1..84e0852d86 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -32,7 +32,7 @@

    <%= "Stock: #{product.stock}" %>

    - <%= link_to "Retire Product", retire_path(product.id), class: "btn btn-primary", method: :post %> + <%= link_to "Retire Product", product_retire(product.id), class: "btn btn-primary", method: :post %> <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %> diff --git a/config/routes.rb b/config/routes.rb index 5ef6f9450d..15e5ce1ac7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,8 +26,11 @@ # get 'users/new' # get 'users/create' # get 'users/show' - resources :products, except: [:destroy] - post '/products/:id/retire', to: "products#retire", as: "retire" + resources :products, except: [:destroy] do + post 'retire', to: "products#retire", as: "retire" + post 'add_to_cart', to: "products#add_to_cart", as: "add_to_cart" + end + # get '/products', to: 'products#index', as: 'products' # get '/products/:id', to: 'products#show', as: 'product' @@ -36,10 +39,10 @@ end # get 'categories/new' # get 'categories/create' - resources :orders, only: [:show, :new, :create, :index] do - resources :orders_items, only: [:create, :new, :show] + resources :orders, only: [:show, :new, :create, :index, :update] do + resources :orders_items, only: [:create, :new, :show, :destroy] end - post '/products/:id/add_to_cart', to: "products#add_to_cart", as: "add_to_cart" + # get '/order/:id/orders_items', to: 'orders_items#index' diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 928e24651a..4105a70925 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -14,173 +14,166 @@ { order: { status: "pending", street: "123 sunny rd", city: "seattle", state: "WA", zip: 98112, - creditcard: 1234, cvv: 234, billingzip: 98112 + creditcard: 1234, cvv: 234, billingzip: 98112, ccexpiration: Date.today } } end - describe "create" do - it "can create a new order given valid params" do - expect { - post orders_path, params:order_hash - }.must_change 'Order.count', 1 - must_respond_with :redirect - must_redirect_to order_path(Order.last.id) - - expect(Order.last.status).must_equal order_hash[:order][:status] - end - - it "responds with an error for invalid params" do - # Arranges - order_hash[:order][:status] = nil - - # Act-Assert - expect { - post order_path, params: order_hash - }.wont_change 'Order.count' - - must_respond_with :bad_request - - end - end - - describe "update" do - it "can update a order with valid params" do - id = orders(:one).id - - expect { - patch order_path(id), params: order_hash - }.wont_change 'Order.count' - - must_respond_with :redirect - must_redirect_to order_path(id) - - new_order = Order.find_by(id: id) - - expect(new_order.status).must_equal order_hash[:order][:status] - expect(new_order.street).must_equal order_hash[:order][:street] - expect(new_order.city).must_equal order_hash[:order][:city] - expect(new_order.state).must_equal order_hash[:order][:state] - expect(new_order.zip).must_equal order_hash[:order][:zip] - expect(new_order.creditcard).must_equal order_hash[:order][:creditcard] - expect(new_order.cvv).must_equal order_hash[:order][:cvv] - expect(new_order.billingzip).must_equal order_hash[:order][:billingzip] - end - - it "gives an error if the book params are invalid" do - # Arrange - order_hash[:order][:status] = "invalid_status" - id = orders(:one).id - old_order = orders(:one) - - expect { - patch order_path(id), params: order_hash - }.wont_change 'Order.count' - new_order = Order.find(id) - - must_respond_with :bad_request - expect(new_order.status).must_equal new_order.status - expect(new_order.street).must_equal new_order.street - expect(new_order.city).must_equal new_order.city - expect(new_order.state).must_equal new_order.state - expect(new_order.zip).must_equal new_order.zip - expect(new_order.creditcard).must_equal new_order.creditcard - expect(new_order.cvv).must_equal new_order.cvv - expect(new_order.billingzip).must_equal new_order.billingzip - end - it "gives not_found for a order that doesn't exist" do - id = -1 - - expect { - patch order_path(id), params: order_hash - }.wont_change 'Order.count' - - must_respond_with :not_found - - end - - - it "should get an order's show page" do - #Arrange - id = orders(:one).id - #Act - get order_path(id) - #Assert - must_respond_with: success - end - - it "should respond with not_found if given an invalid id" do - #asrrange - invalid id - id = -1 - #Act - get order_path(id) - #Assert - must_respond_with :not_found - expect(flash[:danger]).must_equal "Cannot find the order -1" - end - - - describe "edit" do - it "can get the edit page for a valid order" do - # Arrange - id = orders(:one).id - - # Act - get edit_order_path(id) - - # Assert - must_respond_with :success - end - it "should respond with not_found if given an invalid id" do - # Arrange - invalid id - id = -1 - - # Act - get edit_order_path(id) - - # Assert - expect(response).must_be :not_found? - must_respond_with :not_found - expect(flash[:danger]).must_equal "Cannot find the order -1" - end - end - - describe "destroy" do - it "can destroy a order given a valid id" do - # Arrange - id = orders(:one).id - city = orders(:one).city - - # Act - Assert - expect { - delete book_path(id) - }.must_change 'Book.count', -1 - - must_respond_with :redirect - must_redirect_to books_path - expect(flash[:success]).must_equal "#{title} deleted" - expect(Book.find_by(id: id)).must_equal nil - end - - it "should respond with not_found for an invalid id" do - id = -1 - - # Equivalent - # before_count = Book.count - # delete book_path(id) - # after_count = Book.count - # expect(before_count).must_equal after_count - - expect { - delete book_path(id) - # }.must_change 'Book.count', 0 - }.wont_change 'Book.count' - - must_respond_with :not_found - expect(flash.now[:danger]).must_equal "Cannot find the book #{id}" - end - end + # # describe "create" do + # # it "can create a new order given valid params" do + # # expect { + # # post orders_path, params: order_hash + # # }.must_change 'Order.count', 0 + # # must_respond_with :redirect + # # must_redirect_to order_path(Order.last.id) + # # + # # expect(Order.last.status).must_equal order_hash[:order][:status] + # # end + # # + # # it "responds with an error for invalid params" do + # # # Arranges + # # order_hash[:order][:status] = nil + # # + # # # Act-Assert + # # expect { + # # post order_path, params: order_hash + # # }.wont_change 'Order.count' + # # + # # must_respond_with :bad_request + # # + # # end + # # end + # + # describe "update" do + # it "can update a order with valid params" do + # id = orders(:one).id + # + # expect { + # patch order_path(id), params: order_hash + # }.wont_change 'Order.count' + # + # must_respond_with :redirect + # must_redirect_to order_path(id) + # + # new_order = Order.find_by(id: id) + # + # expect(new_order.status).must_equal order_hash[:order][:status] + # expect(new_order.street).must_equal order_hash[:order][:street] + # expect(new_order.city).must_equal order_hash[:order][:city] + # expect(new_order.state).must_equal order_hash[:order][:state] + # expect(new_order.zip).must_equal order_hash[:order][:zip] + # expect(new_order.creditcard).must_equal order_hash[:order][:creditcard] + # expect(new_order.cvv).must_equal order_hash[:order][:cvv] + # expect(new_order.billingzip).must_equal order_hash[:order][:billingzip] + # end + # + # it "gives an error if the order params are invalid" do + # # Arrange + # order_hash[:order][:status] = "invalid_status" + # id = orders(:one).id + # old_order = orders(:one) + # + # expect { + # patch order_path(id), params: order_hash + # }.wont_change 'Order.count' + # new_order = Order.find(id) + # + # must_respond_with :bad_request + # expect(new_order.status).must_equal new_order.status + # expect(new_order.street).must_equal new_order.street + # expect(new_order.city).must_equal new_order.city + # expect(new_order.state).must_equal new_order.state + # expect(new_order.zip).must_equal new_order.zip + # expect(new_order.creditcard).must_equal new_order.creditcard + # expect(new_order.cvv).must_equal new_order.cvv + # expect(new_order.billingzip).must_equal new_order.billingzip + # end + # it "gives not_found for a order that doesn't exist" do + # id = -1 + # + # expect { + # patch order_path(id), params: order_hash + # }.wont_change 'Order.count' + # + # must_respond_with :not_found + # + # end + # end + # + # it "should get an order's show page" do + # #Arrange + # id = orders(:one).id + # #Act + # get order_path(id) + # #Assert + # must_respond_with :success + # end + # + # it "should respond with not_found if given an invalid id" do + # #asrrange - invalid id + # id = -1 + # #Act + # get order_path(id) + # #Assert + # must_respond_with :not_found + # expect(flash[:danger]).must_equal "Cannot find the order -1" + # end + # + # # + # # describe "edit" do + # # it "can get the edit page for a valid order" do + # # # Arrange + # # id = orders(:one).id + # # + # # # Act + # # get edit_order_path(id) + # # + # # # Assert + # # must_respond_with :success + # # end + # # it "should respond with not_found if given an invalid id" do + # # # Arrange - invalid id + # # id = -1 + # # + # # # Act + # # get edit_order_path(id) + # # + # # # Assert + # # expect(response).must_be :not_found? + # # must_respond_with :not_found + # # expect(flash[:danger]).must_equal "Cannot find the order -1" + # # end + # # end + # + # describe "destroy" do + # it "can destroy a order given a valid id" do + # # Arrange + # id = orders(:one).id + # + # # Act - Assert + # expect { + # delete order_path(id) + # }.must_change 'Order.count', -1 + # + # must_respond_with :redirect + # must_redirect_to orders_path(order.id) + # expect(Order.find_by(id: id)).must_equal nil + # end + # + # it "should respond with not_found for an invalid id" do + # id = -1 + # + # expect { + # delete order_path(id) + # # }.must_change 'Book.count', 0 + # }.wont_change 'Order.count' + # + # must_respond_with :not_found + # expect(flash.now[:danger]).must_equal "Cannot find the order #{id}" + # end + # end + end diff --git a/test/controllers/orders_items_controller_test.rb b/test/controllers/orders_items_controller_test.rb index ed0f9078c5..0cedc9ba35 100644 --- a/test/controllers/orders_items_controller_test.rb +++ b/test/controllers/orders_items_controller_test.rb @@ -5,3 +5,13 @@ # flunk "Need real tests" # end end + + it "can add new items to an order" do + # "order_id" = $1 [["order_id", 193]] + # => [#, + # #] + # [5] pry(main)> Order.find_by(id:193).orders_items + end + + it "can remove new items to an order" do + end From 2d546b6e99b18b892dd54e718496a8cbdd5a7ae7 Mon Sep 17 00:00:00 2001 From: Kay Date: Wed, 24 Oct 2018 18:10:42 -0700 Subject: [PATCH 136/239] yay got a radio button working but we actually need checkboxes for category --- app/views/products/_form.html.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index 1036496585..9b646e8da5 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -15,8 +15,11 @@ <% end %> <%= form_with model: @product, class: "form" do |f|%> - <%= f.label :category %> - <%= f.radio_button :category, options_for_select(Product.category_list), class: ''%> + + <% Product.category_list.each do |category_name|%> + <%= f.label category_name %> + <%= f.radio_button :category_name, category_name, class: ''%> + <% end %> <%= f.label :price %> <%= f.text_field :price, class: ""%> From 5715a6fd27d044faad16ece7ff7a956f403915cc Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Wed, 24 Oct 2018 18:20:21 -0700 Subject: [PATCH 137/239] Added add to cart link on products index page --- app/views/products/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 495028090b..0d2eb55cf1 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -17,7 +17,7 @@
    $<%=readable_price(product.price) %>
    - Add to Cart + <%= link_to "Add to Cart", product_add_to_cart(product.id), class: "btn btn-primary btn-sm"%> From 63f173c49609f85238e7e3a093ed917fe84de2ed Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Wed, 24 Oct 2018 18:21:12 -0700 Subject: [PATCH 138/239] Typo --- app/views/products/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 0d2eb55cf1..03587cd384 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -17,7 +17,7 @@
    $<%=readable_price(product.price) %>
    - <%= link_to "Add to Cart", product_add_to_cart(product.id), class: "btn btn-primary btn-sm"%> + <%= link_to "Add to Cart", product_add_to_cart_path(product.id), class: "btn btn-primary btn-sm"%> From 776bf84d79432462226e8a9d2341199fe2bfca4e Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Wed, 24 Oct 2018 18:23:15 -0700 Subject: [PATCH 139/239] Another typo --- app/views/products/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 03587cd384..37caa7e2f4 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -17,7 +17,7 @@
    $<%=readable_price(product.price) %>
    - <%= link_to "Add to Cart", product_add_to_cart_path(product.id), class: "btn btn-primary btn-sm"%> + <%= link_to "Add to Cart", product_add_to_cart_path(product.id), method: :post, class: "btn btn-primary btn-sm"%> From 39143f32b05ecc72fd29004733b3a97eb079b26d Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 18:41:02 -0700 Subject: [PATCH 140/239] Added styling to user product view --- app/views/users/dashboard.html.erb | 6 +---- app/views/users/products.html.erb | 42 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 7b812b9f68..1c2806acad 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -72,11 +72,7 @@ -<<<<<<< HEAD - <%# link_to "Retire Product", retire_path(product.id), class: "btn btn-primary", method: :post %> -======= - <%= link_to "Retire Product", product_retire(product.id), class: "btn btn-primary", method: :post %> ->>>>>>> order_cart_view + <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %> <% end %> diff --git a/app/views/users/products.html.erb b/app/views/users/products.html.erb index c2c8f752a4..879f9c047d 100644 --- a/app/views/users/products.html.erb +++ b/app/views/users/products.html.erb @@ -10,24 +10,24 @@ <% end %> -
    -

    Products

    -
      - <% if @merchant.products.nil? %> -

      <%= "This merchant has no products" %>

      - - <% else %> - <%= @merchant.products.each do |product| %> -
    • -

      <%= "#{product.name}" %>

      -

      <%= "Price: #{product.price}" %>

      -

      <%= "Description: #{product.description}" %>

      -

      <%= "Stock: #{product.stock}" %>

      - -
    • - - <% end %> - <% end %> - -
    -
    +
    +<% @merchant.products.each do |product| %> +
    +
    +
    + <%= link_to image_tag(product.photo, class: "product_photo"),product_path(product.id) %> +
    <%= link_to product.name , product_path(product.id), class: "btn-overlay"%>
    +
    +
    + <%= link_to product.user.name, merchant_products_path(product.user.id), class: "title"%> +
    +
    + $<%=readable_price(product.price) %> +
    + <%= link_to "Add to Cart", product_add_to_cart_path(product.id), method: :post, class: "btn btn-primary btn-sm"%> +
    +
    +
    +
    +<%end%> +
    From 431103015ef43558c861d6ff89374936c160d115 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 18:42:27 -0700 Subject: [PATCH 141/239] Added bootstrap container around products --- app/views/users/products.html.erb | 60 ++++++++++++++++--------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/app/views/users/products.html.erb b/app/views/users/products.html.erb index 879f9c047d..c4aff9520d 100644 --- a/app/views/users/products.html.erb +++ b/app/views/users/products.html.erb @@ -1,33 +1,35 @@ -

    Merchants

    +
    +

    Merchants

    -<% if @merchant.nil? %> -

    Merchant Not Found

    -<% else %> -

    <%= @merchant.name %>

    -

    - <%= @merchant.email %> -

    + <% if @merchant.nil? %> +

    Merchant Not Found

    + <% else %> +

    <%= @merchant.name %>

    +

    + <%= @merchant.email %> +

    -<% end %> + <% end %> -
    -<% @merchant.products.each do |product| %> -
    -
    -
    - <%= link_to image_tag(product.photo, class: "product_photo"),product_path(product.id) %> -
    <%= link_to product.name , product_path(product.id), class: "btn-overlay"%>
    -
    -
    - <%= link_to product.user.name, merchant_products_path(product.user.id), class: "title"%> -
    -
    - $<%=readable_price(product.price) %> -
    - <%= link_to "Add to Cart", product_add_to_cart_path(product.id), method: :post, class: "btn btn-primary btn-sm"%> -
    -
    -
    -
    -<%end%> +
    + <% @merchant.products.each do |product| %> +
    +
    +
    + <%= link_to image_tag(product.photo, class: "product_photo"),product_path(product.id) %> +
    <%= link_to product.name , product_path(product.id), class: "btn-overlay"%>
    +
    +
    + <%= link_to product.user.name, merchant_products_path(product.user.id), class: "title"%> +
    +
    + $<%=readable_price(product.price) %> +
    + <%= link_to "Add to Cart", product_add_to_cart_path(product.id), method: :post, class: "btn btn-primary btn-sm"%> +
    +
    +
    +
    + <%end%> +
    From eb27d9e9457e233d517679116638e0812abce489 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 18:58:24 -0700 Subject: [PATCH 142/239] Added bootstrap to dashboard table --- app/assets/stylesheets/application.scss | 5 +++++ app/views/users/dashboard.html.erb | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8e828943b9..6f9bd58139 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -207,3 +207,8 @@ body { font-size: 75%; } } + +.dashboard_container { + margin: 2rem; + padding: 2rem; +} diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 1c2806acad..fe56cbb698 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -2,7 +2,7 @@

    User Not Found

    <% else %> -
    +

    <%= "#{@merchant.name}'s Dashboard" %>

    @@ -35,7 +35,7 @@

    My Products

    - +
    From 22f0c29bf6b2c49f0a382e60cb09ce26b1ff2bff Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 18:49:51 -0700 Subject: [PATCH 177/239] fixed bug in order#update so now the stock reduces when we checkout yay --- app/controllers/orders_controller.rb | 58 +++++++++++++++----------- app/controllers/products_controller.rb | 2 + app/models/orders_item.rb | 4 +- app/models/product.rb | 6 ++- app/views/orders/_form.html.erb | 2 + 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index bec9140b6c..c93fea57cb 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,5 +1,5 @@ class OrdersController < ApplicationController - #before_action :find_order, only: [:edit,:update] + #before_action :find_order, only: [:edit,:update] # # def new #WRONG TO HAVE @ORDER @@ -21,14 +21,14 @@ def new @order = Order.new # Find user # If no user, User.create - if params[:user_id] - @user_id = params[:user_id].to_i - user = User.find_by(id: @user_id) - if user.nil? - flash.now[:warning] = "That user doesn't exit" - end - @order.user_id = @user_id - end + if params[:user_id] + @user_id = params[:user_id].to_i + user = User.find_by(id: @user_id) + if user.nil? + flash.now[:warning] = "That user doesn't exit" + end + @order.user_id = @user_id + end end @@ -39,36 +39,46 @@ def edit #get returns a result end + def update if @current_order && @current_order.update(order_params) + order = Order.find_by(id: @current_order.id, status: "pending") + order.status = "paid" + if order.orders_items.nil? + flash.now[:danger] = "Cannot checkout, your cart has no property" + render :edit, status: :bad_request + else + order.orders_items.each do |o_i| + o_i.product.reduce_stock(o_i.quantity) + o_i.product.save + end + # if o_i.product.save + # else + # # binding.pry + # redirect_to order_path(@current_order.id) #Redirect to order confirmation + # end + order.save + end - flash[:status] = :success - flash[:result_text] = "Success! Order #{@current_order.id} is complete! Enjoy your unique home!" - redirect_to order_path(@current_order.id) #Redirect to order confirmation + redirect_to order_path(@current_order.id) else flash.now[:status] = :failure flash.now[:result_text] = "Could not update #{@current_order.id}. Please check the forms" flash.now[:messages] = @current_order.errors.messages render :edit, status: :bad_request - #patch - #this does not have an .erb - #the form posts to the update method - #will recieve a post from edit and it will toggle the order to complete - #save order - #get the order and update it end end def show - @order = Order.find_by(id:session[:order_id]) + @order = Order.find_by(id:session[:order_id]) end - def index - @orders = Order.all - end + def index + @orders = Order.all + end - def destroy - end + def destroy + end private def order_params diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index e00ff32cc2..053eeb0e18 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,3 +1,4 @@ +require 'pry' class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :retire] before_action :require_login, except: [:index, :show, :add_to_cart, :root] @@ -78,6 +79,7 @@ def destroy end + private def find_product diff --git a/app/models/orders_item.rb b/app/models/orders_item.rb index e845895515..1aee07cf2e 100644 --- a/app/models/orders_item.rb +++ b/app/models/orders_item.rb @@ -1,7 +1,9 @@ class OrdersItem < ApplicationRecord belongs_to :product belongs_to :order - + # validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 } + + def calculate_total return self.product.price * self.quantity end diff --git a/app/models/product.rb b/app/models/product.rb index 06f2a4f522..0921f03e88 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -13,7 +13,8 @@ class Product < ApplicationRecord validates :description, presence: true validates :photo, presence: true - validates :stock, presence: true + # validates :stock, presence: true, numericality: { greater_than_or_equal_to: 0 } + def self.category_list @@ -26,5 +27,8 @@ def self.category_list return categories.uniq end + def reduce_stock(quantity) + self.stock = self.stock - quantity + end end diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index b85cd0db6e..e9fb58a785 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -1,3 +1,5 @@ + + From d94eae2d3cf7e119bcd219407e1ff01d5a58e869 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 18:59:40 -0700 Subject: [PATCH 178/239] changed wording in order show page view --- app/controllers/orders_controller.rb | 11 +++++++---- app/models/orders_item.rb | 2 +- app/models/product.rb | 2 +- app/views/orders/show.html.erb | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index c93fea57cb..267190d4fd 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -45,14 +45,18 @@ def update order = Order.find_by(id: @current_order.id, status: "pending") order.status = "paid" if order.orders_items.nil? - flash.now[:danger] = "Cannot checkout, your cart has no property" render :edit, status: :bad_request else order.orders_items.each do |o_i| o_i.product.reduce_stock(o_i.quantity) o_i.product.save - end - # if o_i.product.save + end + end + if o_i.product.save + # MERGE -> once we merge change the redirect path to confirmation :) + # rediret_to confirmation_path(@current_order.id) + redirect_to order_path(@current_order.id) + # else # # binding.pry # redirect_to order_path(@current_order.id) #Redirect to order confirmation @@ -60,7 +64,6 @@ def update order.save end - redirect_to order_path(@current_order.id) else flash.now[:status] = :failure flash.now[:result_text] = "Could not update #{@current_order.id}. Please check the forms" diff --git a/app/models/orders_item.rb b/app/models/orders_item.rb index 1aee07cf2e..3ac788b044 100644 --- a/app/models/orders_item.rb +++ b/app/models/orders_item.rb @@ -1,7 +1,7 @@ class OrdersItem < ApplicationRecord belongs_to :product belongs_to :order - # validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 } + validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 } def calculate_total diff --git a/app/models/product.rb b/app/models/product.rb index 0921f03e88..9d7d358cde 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -13,7 +13,7 @@ class Product < ApplicationRecord validates :description, presence: true validates :photo, presence: true - # validates :stock, presence: true, numericality: { greater_than_or_equal_to: 0 } + validates :stock, presence: true, numericality: { greater_than_or_equal_to: 0 } diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index bdccf772e8..9b3a45f22b 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -6,7 +6,8 @@

    Shopping Cart

    <% if @current_order.products.count == 0 %> -

    There's nothing in your cart!

    +

    Your cart is empty

    +

    Pick your next nightmare home at Shop All Homes above!

    <% else %>
    From 8020453978abbc6f3ec5dabc8828234c68383134 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 25 Oct 2018 19:03:15 -0700 Subject: [PATCH 179/239] Added the logic to destroy item in cart if someone updates the quantity to 0 --- app/controllers/orders_items_controller.rb | 7 +++++++ app/views/orders_items/show.html.erb | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/orders_items_controller.rb b/app/controllers/orders_items_controller.rb index 2968aa8096..8d24cc9988 100644 --- a/app/controllers/orders_items_controller.rb +++ b/app/controllers/orders_items_controller.rb @@ -23,6 +23,12 @@ def create def update # find order item by params id + + if order_item_params[:quantity].to_i == 0 + @orders_item.destroy + flash.now[:danger] = "Removed item from your cart" + redirect_to order_path(@current_order.id) + else if @orders_item && @orders_item.update(order_item_params) flash[:success] = "The cart item #{@orders_item.product.name} has been updated" redirect_to order_path(@current_order.id) @@ -34,6 +40,7 @@ def update redirect_to order_path(@current_order.id) end end + end def destroy diff --git a/app/views/orders_items/show.html.erb b/app/views/orders_items/show.html.erb index 86040e7a64..94be80aaa3 100644 --- a/app/views/orders_items/show.html.erb +++ b/app/views/orders_items/show.html.erb @@ -1,3 +1,13 @@ +<% if @orders_item.errors.any? %> +
      + <% @orders_item.errors.each do |column, message| %> +
    • + <%= column.capitalize %> <%= message %> +
    • + <% end %> +
    +<% end %> +
    @@ -84,7 +84,6 @@
    -

    Orders

    <%= render partial: "statussummary" %> - +
    - @@ -67,7 +68,7 @@ <%= item.order.updated_at %> - <% end %>
    @@ -46,12 +46,13 @@ <%= "Order Status" %> - <%= "Shipped Status" %> + +
    - <%= link_to "#{item.product.name}", product_path(item.product.id) %> + <%= link_to "#{item.product.name.capitalize}", product_path(item.product.id) %> <%= item.product.price %> @@ -76,17 +77,17 @@ <%= item.quantity %> - <%= "Subtotal Here - Katherine creating this in order item?" %> + <%= item.calculate_total %> <%= item.order.status.capitalize %> +
    diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 1c2806acad..80dd562b88 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -35,7 +35,7 @@

    My Products

    - +
    + <% @merchant.products.each do |product| %> + - - <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %> <% end %> From 590e9f9ab56482e7d750429c58000aa5827634ee Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 21:18:30 -0700 Subject: [PATCH 148/239] Continued working on views. Added status to order summary label --- app/controllers/users_controller.rb | 8 +++++--- app/views/users/_statussummary.html.erb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 29c17c330b..8fa05322a5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -74,12 +74,14 @@ def dashboard # @merchant = find_merchant - have this already ######## SORT THESE THINGS !!!! + @products = @merchant.products if params[:status] - - @order_items = @merchant.order_items_for_status(params[:status]) + @status = params[:status] + @order_items = @merchant.order_items_for_status(@status).sort_by &:order_id else - @order_items = @merchant.sold_items + @order_items = @merchant.sold_items.sort_by &:order_id + @status = "All" end diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index 71a430aa42..db201c52b6 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -1,4 +1,4 @@ -

    <%= "Order Summary" %>

    +

    <%= "Order Summary - #{@status.capitalize}" %>

    @@ -84,7 +84,6 @@
    -

    Orders

    <%= render partial: "statussummary" %> -
    -
    - - - Full name as displayed on card -
    - Name on card is required -
    -
    -
    - <%= f.label :creditcard %> - -
    - Credit card number is required -
    -
    -
    -
    -
    - <%= f.label :ccexpiration %> - -
    - Expiration date required -
    -
    -
    - <%= f.label :cvv %> - -
    - Security code required -
    -
    -
    -
    - - - - - - <%# f.label :category %> - <%# f.select :category, ['album','book','movie'], class: 'form__input'%> - - <%= f.label :price %> - <%= f.text_field :price, class: "form__input"%> - - <%= f.label :name %> - <%= f.text_field :name, class: "form__input"%> - - - <%= f.label :description %> - <%= f.text_field :description, class: "form__input"%> - - <%= f.label :stock %> - <%= f.text_field :stock, class: "form__input" %> - - - <%= f.submit 'Checkout', class: 'btn'%> - <% end %> -
    - + <% end %>
    -

    Checkout form

    -

    Below is an example form built entirely with Bootstrap's form controls. Each required form group has a validation state that can be triggered by attempting to submit the form without completing it.

    +

    Checkout

    Your cart - <%=@order.orders_items.length%> + 3

      + <% @order.orders_items.each do |item| %>
    • -
      Product name
      - Brief description -
      - $12 -
    • -
    • -
      -
      Second product
      - Brief description +
      <%=item.product.name%>
      + Qty : <%=item.quantity%>
      - $8 -
    • -
    • -
      -
      Third item
      - Brief description -
      - $5 -
    • -
    • -
      -
      Promo code
      - EXAMPLECODE -
      - -$5 + $<%=readable_price(item.product.price)%>
    • + <% end %>
    • Total (USD) - $20 + Update with method
    - -
    -
    - -
    - -
    -
    -
    -
    -

    Billing address

    -
    -
    -
    - - -
    - Valid first name is required. + + +
    +

    Billing address

    + <%= form_with model: @order, class: "needs-validation" do |f|%> +
    + <%= f.label :name %> +
    + <%= f.text_field :name, class: "form-control" ,id:"username", required:""%> +
    + Your name is required. +
    -
    - - +
    + +
    - Valid last name is required. + Please enter a valid email address for shipping updates.
    -
    -
    - -
    -
    - @ -
    - -
    - Your username is required. +
    + + +
    + Please enter your shipping address.
    -
    - -
    - - -
    - Please enter a valid email address for shipping updates. -
    -
    -
    - - -
    - Please enter your shipping address. +
    + +
    -
    -
    - - -
    - -
    -
    - - -
    - Please select a valid country. +
    +
    + + +
    + Please select a valid country. +
    -
    -
    - - -
    - Please provide a valid state. +
    + <%= f.label :state %> + <%= select_tag :state, options_for_select(us_states), class:"custom-select d-block w-100"%> +
    + Please provide a valid state. +
    -
    -
    - - -
    - Zip code required. +
    + <%= f.label :zip %> + <%= f.text_field :zip, class: "form-control", id: "zip" %> +
    + Zip code required. +
    -
    -
    -
    - - -
    -
    - - -
    -
    - -

    Payment

    - -
    -
    - - -
    -
    - - +
    +
    + +
    -
    - - +
    + +
    -
    -
    -
    - - - Full name as displayed on card -
    - Name on card is required +
    + +

    Payment

    + +
    +
    + + + Full name as displayed on card +
    + Name on card is required +
    -
    -
    - - -
    - Credit card number is required +
    + <%= f.label :creditcard %> + +
    + Credit card number is required +
    -
    -
    -
    - - -
    - Expiration date required +
    +
    + <%= f.label :ccexpiration %> + <%= f.text_field :ccexpiration, class: "form-control", id: "cc-expiration" %> +
    + Expiration date required +
    -
    -
    - - -
    - Security code required +
    + <%= f.label :cvv %> + <%= f.text_field :cvv, class: "form-control", id: "cc-cvv" %> +
    + Security code required +
    -
    -
    - - +
    + <%= f.submit 'Submit Checkout', method: :patch, class: "btn btn-primary btn-lg btn-block"%> + +
    -
    - - -
    - - - - - - - - - + <% end %> + + + + + + + + + + + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 2a5180c03e..1936efb8b0 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,3 +1,9 @@ + + + + + +

    Orders#show

    Find me in app/views/orders/show.html.erb

    @@ -20,13 +26,57 @@
  • <%= link_to "Remove Item from Cart", order_orders_item_path(@order.id, orders_item.id), :method => :delete %>
  • - + <% end %> <% end %> -/orders/:order_id/orders_items/:id(.:format) - + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ProductPriceQuantitySubtotal
    +
    + +
    +

    Product 1

    +

    Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet.

    +
    +
    +
    $1.99 + + 1.99 + + +
    Total 1.99
    Continue ShoppingCheckout
    +
    diff --git a/app/views/orders_items/show.html.erb b/app/views/orders_items/show.html.erb index e69de29bb2..86040e7a64 100644 --- a/app/views/orders_items/show.html.erb +++ b/app/views/orders_items/show.html.erb @@ -0,0 +1,46 @@ +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ProductPriceQuantitySubtotal
    +
    + +
    +

    Product 1

    +

    Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet.

    +
    +
    +
    $1.99 + + 1.99 + + +
    Total 1.99
    Continue ShoppingCheckout
    +
    diff --git a/config/routes.rb b/config/routes.rb index 20b41cb533..a35fbd18b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,7 +38,7 @@ # get 'categories/new' # get 'categories/create' - resources :orders, only: [:show, :new, :create, :index, :update] do + resources :orders, only: [:show, :new, :create, :index, :update, :edit] do resources :orders_items, only: [:create, :new, :show, :destroy] end diff --git a/formhelp.html b/formhelp.html new file mode 100644 index 0000000000..b68a75cdf8 --- /dev/null +++ b/formhelp.html @@ -0,0 +1,251 @@ + + +
    +
    + +

    Checkout form

    +

    Below is an example form built entirely with Bootstrap's form controls. Each required form group has a validation state that can be triggered by attempting to submit the form without completing it.

    +
    + +
    +
    +

    + Your cart + 3 +

    +
      +
    • +
      +
      Product name
      + Brief description +
      + $12 +
    • +
    • +
      +
      Second product
      + Brief description +
      + $8 +
    • +
    • +
      +
      Third item
      + Brief description +
      + $5 +
    • +
    • +
      +
      Promo code
      + EXAMPLECODE +
      + -$5 +
    • +
    • + Total (USD) + $20 +
    • +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    +

    Billing address

    +
    +
    +
    + + +
    + Valid first name is required. +
    +
    +
    + + +
    + Valid last name is required. +
    +
    +
    + +
    + +
    +
    + @ +
    + +
    + Your username is required. +
    +
    +
    + +
    + + +
    + Please enter a valid email address for shipping updates. +
    +
    + +
    + + +
    + Please enter your shipping address. +
    +
    + +
    + + +
    + +
    +
    + + +
    + Please select a valid country. +
    +
    +
    + + +
    + Please provide a valid state. +
    +
    +
    + + +
    + Zip code required. +
    +
    +
    +
    +
    + + +
    +
    + + +
    +
    + +

    Payment

    + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + + + Full name as displayed on card +
    + Name on card is required +
    +
    +
    + + +
    + Credit card number is required +
    +
    +
    +
    +
    + + +
    + Expiration date required +
    +
    +
    + + +
    + Security code required +
    +
    +
    +
    + +
    +
    +
    + + +
    + + + + + + + + + + + + From c3b09276ebc1967fe3787e8491c749ee3215663e Mon Sep 17 00:00:00 2001 From: KatherineJF Date: Wed, 24 Oct 2018 20:43:04 -0700 Subject: [PATCH 146/239] order_total_calculate method working and changes routes to include edit --- app/models/order.rb | 13 ++++++++----- app/views/orders/show.html.erb | 8 ++------ config/routes.rb | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index e4a4029d27..bdaa69a84d 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -47,11 +47,14 @@ def add_product(product_id, quantity) return current_item end - # def order_calculate_total(product_id) - # self.orders_items.each do |current_item| - # total_cost += current_item.calculate_total - # end - # end + + def order_calculate_total(product_id) + total_cost = 0 + self.orders_items.each do |item| + total_cost += item.calculate_total + end + return total_cost + end def items_in_cart # TODO: Update to return accurate quanity of all items in cart diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 2a5180c03e..be33ee7a30 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -20,13 +20,9 @@
  • <%= link_to "Remove Item from Cart", order_orders_item_path(@order.id, orders_item.id), :method => :delete %>
  • - - - + <%= @current_order.order_calculate_total(product_path) %> <% end %> <% end %> + <%= link_to "Complete Order", edit_order_path(@current_order.id)%> -/orders/:order_id/orders_items/:id(.:format) - diff --git a/config/routes.rb b/config/routes.rb index 20b41cb533..a35fbd18b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,7 +38,7 @@ # get 'categories/new' # get 'categories/create' - resources :orders, only: [:show, :new, :create, :index, :update] do + resources :orders, only: [:show, :new, :create, :index, :update, :edit] do resources :orders_items, only: [:create, :new, :show, :destroy] end From 6387f566f1ba364869054662ecae349de1a2daea Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 20:49:36 -0700 Subject: [PATCH 147/239] Added total number of orders/total number of order items --- app/assets/stylesheets/application.scss | 4 ++++ app/controllers/users_controller.rb | 4 +++- app/views/users/_statussummary.html.erb | 8 +++++++- app/views/users/dashboard.html.erb | 16 ++++++++++------ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8e828943b9..06712d01f6 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -207,3 +207,7 @@ body { font-size: 75%; } } + +table { + text-align: center; +} diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c837e18201..29c17c330b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -73,9 +73,10 @@ def dashboard else # @merchant = find_merchant - have this already - # + ######## SORT THESE THINGS !!!! @products = @merchant.products if params[:status] + @order_items = @merchant.order_items_for_status(params[:status]) else @order_items = @merchant.sold_items @@ -95,6 +96,7 @@ def dashboard # order_numbers << item # end @total_orders = order_overview.length + @total_items = order_overview.values.sum end # For each product, search for order items # Params data - assign to filter - value available in the view - ? diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index 3508f33834..71a430aa42 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -1,7 +1,7 @@

    <%= "Order Summary" %>

    - +
    + @@ -19,6 +22,9 @@ +
    @@ -10,6 +10,9 @@ <%= "Number of Orders" %> + <%= "Number of Items Ordered" %> +
    <%= "#{@total_orders}" %> + <%= "#{@total_items}" %> +
    diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 80dd562b88..7c6095fabc 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -50,30 +50,34 @@
    <%= "Stock" %> + Edit +
    -

    <%= "#{product.name}" %>

    +

    <%= "#{product.name.capitalize}" %>

    -

    <%= "Price: #{product.price}" %>

    +

    <%= "#{product.price}" %>

    -

    <%= "Description: #{product.description}" %>

    +

    <%= "#{product.description}" %>

    -

    <%= "Stock: #{product.stock}" %>

    +

    <%= "#{product.stock}" %>

    +
    + <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %>
    From cadb3bd438678cd464fd1ab37af764af64edd550 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Wed, 24 Oct 2018 22:03:58 -0700 Subject: [PATCH 149/239] Revert "Continued working on views. Added status to order summary label" This reverts commit 590e9f9ab56482e7d750429c58000aa5827634ee. Tried working with status and was not successful. Reverting to prior commit. --- app/controllers/users_controller.rb | 8 +++----- app/views/users/_statussummary.html.erb | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8fa05322a5..29c17c330b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -74,14 +74,12 @@ def dashboard # @merchant = find_merchant - have this already ######## SORT THESE THINGS !!!! - @products = @merchant.products if params[:status] - @status = params[:status] - @order_items = @merchant.order_items_for_status(@status).sort_by &:order_id + + @order_items = @merchant.order_items_for_status(params[:status]) else - @order_items = @merchant.sold_items.sort_by &:order_id - @status = "All" + @order_items = @merchant.sold_items end diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index db201c52b6..71a430aa42 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -1,4 +1,4 @@ -

    <%= "Order Summary - #{@status.capitalize}" %>

    +

    <%= "Order Summary" %>

    From 9e9fc7781fb5446730b14ef9eb7c6a28d53ac55d Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 07:17:57 -0700 Subject: [PATCH 150/239] gave merchants card styling and added checkboxes for product that still aren't working --- app/assets/stylesheets/application.scss | 1 - app/controllers/products_controller.rb | 14 +++++++++- app/models/product.rb | 2 +- app/views/categories/index.html.erb | 3 +++ app/views/layouts/application.html.erb | 4 ++- app/views/products/_form.html.erb | 5 +--- app/views/products/new.html.erb | 2 +- app/views/users/index.html.erb | 34 +++++++++++++++++-------- 8 files changed, 46 insertions(+), 19 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8e828943b9..1550ec920a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -32,7 +32,6 @@ $gold: #FF5722; $default-border: 2px solid; - body, h1, h2, h3, h4, h5 { font-family: $primary-font; } diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 25ce8f246f..f81bf631bc 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -25,6 +25,7 @@ def add_to_cart def new @product = Product.new + @categories = Category.all # There should be a merchant to create a new product # @merchant should be available via application controller if @merchant @@ -41,6 +42,16 @@ def retire def create @product = Product.new(product_params) + category = Category.find_by(name: product_params[:category_ids]) + # get array of categories -> form stuff + # loop thru aray of categories + # find the matching cateogry + # update the product to have that category + # category_params.each do |params| + # category = Category.find_by(name: params[:category_name]) + # @product.categories << category + # @product.category_id = category.id + if @product.save flash[:success] = 'Product Created!' @@ -53,6 +64,7 @@ def create end def update + params[:product][:category_ids] ||= [] #if category_ids returns nil it will be set to empty array if @product && @product.update(product_params) redirect_to product_path(@product.id) elsif @product && !@product.valid? #the product exists and it was invalid inputs @@ -77,7 +89,7 @@ def find_product def product_params #can i access :category_id? not unless there isa belongs_to - return params.require(:product).permit(:user_id, :name, :price, :description, :photo, :stock) + return params.require(:product).permit(:user_id, :name, :price, :description, :photo, :stock, category_ids:[]) end end diff --git a/app/models/product.rb b/app/models/product.rb index 59e61c7512..06f2a4f522 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -20,7 +20,7 @@ def self.category_list categories = [] Product.all.each do |product| product.categories.each do |category| - categories << category.name + categories << category end end return categories.uniq diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 4975d0b072..94883595a4 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -1,4 +1,7 @@
    +
    +
    +

    Categories

    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1f59d19dc4..a285be9e9f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,7 +12,8 @@ - + +
    From 62516edb597ae8754e09b271416034f684aa81c4 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 07:21:44 -0700 Subject: [PATCH 151/239] added spacing between category index cards --- app/views/categories/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 94883595a4..05a8e64469 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -10,7 +10,7 @@ <%# @category_photos.each do |photo| %> <% @categories.each do |category| %>
    -
    +
    <%= link_to image_tag(category.product_photo, alt:"Card image cap", class:"card-img-top img-fluid"), category_path(category.id) %>

    <%= category.name %>

    From 7d5dcf8793658194913ae1a95b089b523484a910 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 07:23:06 -0700 Subject: [PATCH 152/239] changed button titles --- app/views/layouts/application.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a285be9e9f..fe03a31d02 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,10 +26,10 @@ <%= link_to "Shop All Homes", products_path, class: "nav-link" %>
    + <% @current_order.orders_items.each do |item| %> - + + <%end%> - + - +
    - <%= "Total Revenue Here" %> + <%= "#{@revenue_total}" %> <%= "#{@total_orders}" %> From 28811c680eeca04dc3af20a72d7791a2dbd63228 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 08:45:10 -0700 Subject: [PATCH 154/239] Debugged issue showing all order items --- app/controllers/users_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e2c55b2173..f900a71d68 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -75,10 +75,9 @@ def dashboard # @merchant = find_merchant - have this already ######## SORT THESE THINGS !!!! @products = @merchant.products - if params[:status] - + if params[:status] && params[:status] != "all" @order_items = @merchant.order_items_for_status(params[:status]) - else + elsif @order_items = @merchant.sold_items end From 63a3dbd50f8bd026783a1633d43c64a9fe88e8cf Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 08:54:06 -0700 Subject: [PATCH 155/239] Used number_to_currency for prices/revenue --- app/views/users/_statussummary.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index c13b27964a..a81aecf022 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -17,7 +17,7 @@
    - <%= "#{@revenue_total}" %> + <%= number_to_currency(@revenue_total) %> <%= "#{@total_orders}" %> @@ -77,7 +77,7 @@ <%= link_to "#{item.product.name.capitalize}", product_path(item.product.id) %> - <%= item.product.price %> + <%= number_to_currency(item.product.price) %> <%= item.quantity %> From 3555cf47cfa1662587c6bb4e550135f32a9597b6 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 08:54:40 -0700 Subject: [PATCH 156/239] Applied currency formatting to subtotals --- app/views/users/_statussummary.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index a81aecf022..2cfdbab088 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -83,7 +83,7 @@ <%= item.quantity %> - <%= item.calculate_total %> + <%= number_to_currency(item.calculate_total) %> <%= item.order.status.capitalize %> From 913ba0fe538f9552addf5a5777e8874bacfffdaf Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 09:01:02 -0700 Subject: [PATCH 157/239] Applied some formatting/more currency formats to dashboard --- app/assets/stylesheets/application.scss | 4 ++++ app/views/users/_statussummary.html.erb | 1 + app/views/users/dashboard.html.erb | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 06712d01f6..c33cb9ff49 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -211,3 +211,7 @@ body { table { text-align: center; } + +#merchant_options .btn { + padding: 5px; +} diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index 2cfdbab088..f1a9017e68 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -1,3 +1,4 @@ +

    <%= "Order Summary" %>

    diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 7c6095fabc..dbe05b5e22 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -3,13 +3,13 @@ <% else %>
    -
    +

    <%= "#{@merchant.name}'s Dashboard" %>

    -
    -

    <%= "#{product.price}" %>

    +

    <%= "#{number_to_currency(product.price)}" %>

    <%= "#{product.description}" %>

    From 016729ecb357625b5ae1b633c04151fc94d6a7da Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 25 Oct 2018 09:19:18 -0700 Subject: [PATCH 158/239] Updated the shopping cart view --- app/models/orders_item.rb | 2 +- app/views/orders/show.html.erb | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/models/orders_item.rb b/app/models/orders_item.rb index cbfcc773b7..e845895515 100644 --- a/app/models/orders_item.rb +++ b/app/models/orders_item.rb @@ -1,7 +1,7 @@ class OrdersItem < ApplicationRecord belongs_to :product belongs_to :order - + def calculate_total return self.product.price * self.quantity end diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 1936efb8b0..81f754b4b5 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -4,8 +4,7 @@ -

    Orders#show

    -

    Find me in app/views/orders/show.html.erb

    +

    Shopping Cart

    <% if @current_order.products.count == 0 %>

    There's nothing in your cart!

    @@ -26,11 +25,7 @@
  • <%= link_to "Remove Item from Cart", order_orders_item_path(@order.id, orders_item.id), :method => :delete %>
  • - - - - -<% end %> + <% end %> <% end %> @@ -46,36 +41,39 @@
    - +
    -

    Product 1

    -

    Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet.

    +

    <%= item.product.name %>

    +

    <%= item.product.description %>

    $1.99$<%= readable_price(item.product.price) %> 1.99 - - + <%= link_to "Update", product_add_to_cart_path(item.product.id) , class: "btn btn-info btn-sm", method: :post%> + <%= link_to "Remove", order_orders_item_path(item.product.id) , class: "btn btn-danger btn-sm", method: :delete%> +
    Total 1.99
    Continue Shopping<%= link_to "Continue Order", products_path, class: "btn btn-warning"%> Checkout <%= link_to "Complete Order", edit_order_path(@current_order.id), class: "btn btn-success btn-block"%>
    From 41aaec00a69fb7123da35d3c36575baf3a7d2726 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 09:22:53 -0700 Subject: [PATCH 159/239] fixed merge conflict in appllication scss --- app/assets/stylesheets/application.scss | 4 +- app/views/users/dashboard.html.erb | 61 ++++--------------------- 2 files changed, 10 insertions(+), 55 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index fc5a843ac6..50996bc927 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -207,16 +207,14 @@ body { } } -<<<<<<< HEAD .dashboard_container { margin: 2rem; padding: 2rem; -======= + table { text-align: center; } #merchant_options .btn { padding: 5px; ->>>>>>> merchant_dashboard_orders } diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index ad073a1882..ab7fe6a707 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -2,19 +2,14 @@

    User Not Found

    <% else %> -<<<<<<< HEAD -
    -
    -=======
    -
    ->>>>>>> merchant_dashboard_orders +

    <%= "#{@merchant.name}'s Dashboard" %>

    -
    $<%= readable_price(item.product.price) %> - <%= form_with url:product_add_to_cart_path(item.product.id) do |f|%> + <%= form_with url:order_orders_item_path(@current_order.id,item.id), method: :patch do |f|%> <%= f.text_field :quantity, placeholder: "#{item.quantity}", class: "form-control text-center" %> <%= f.submit "Update Cart"%> <% end %> diff --git a/config/routes.rb b/config/routes.rb index a35fbd18b9..400bd04f69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,7 +39,7 @@ # get 'categories/new' # get 'categories/create' resources :orders, only: [:show, :new, :create, :index, :update, :edit] do - resources :orders_items, only: [:create, :new, :show, :destroy] + resources :orders_items, only: [:create, :new, :show, :destroy,:update] end From 093be6c160800d6e7bf8df82ba470c9e408c8950 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 25 Oct 2018 17:27:16 -0700 Subject: [PATCH 175/239] Updated paths for the OI update --- app/controllers/orders_items_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/orders_items_controller.rb b/app/controllers/orders_items_controller.rb index 9f01e570d3..2968aa8096 100644 --- a/app/controllers/orders_items_controller.rb +++ b/app/controllers/orders_items_controller.rb @@ -22,17 +22,16 @@ def create end def update - binding.pry # find order item by params id if @orders_item && @orders_item.update(order_item_params) flash[:success] = "The cart item #{@orders_item.product.name} has been updated" - redirect_to orders_path(@current_order.id) + redirect_to order_path(@current_order.id) elsif @orders_item && !@orders_item.valid? #the order item exists and it was invalid input for quantity flash.now[:danger] = "Could not save the quantity to the cart" - redirect_to orders_path(@current_order.id) + redirect_to order_path(@current_order.id) else flash[:danger] = "Something went wrong" - redirect_to orders_path(@current_order.id) + redirect_to order_path(@current_order.id) end end From 638c75b34343dc268d8a3640cd64ffcde112c1bb Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 25 Oct 2018 18:33:43 -0700 Subject: [PATCH 176/239] Updated the form to be a value: instead of placeholder: so no one will accidentally press enter and enter a nil value for products --- app/views/orders/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 9a3203f419..8cff58a475 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -35,7 +35,7 @@ $<%= readable_price(item.product.price) %> <%= form_with url:order_orders_item_path(@current_order.id,item.id), method: :patch do |f|%> - <%= f.text_field :quantity, placeholder: "#{item.quantity}", class: "form-control text-center" %> + <%= f.text_field :quantity, value: "#{item.quantity}", class: "form-control text-center" %> <%= f.submit "Update Cart"%> <% end %>
    From 4437923db5fbcfb23ae1bf1664604eec3ad05c2c Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 19:31:28 -0700 Subject: [PATCH 180/239] Completed confirmation page --- app/assets/stylesheets/application.scss | 1 + app/controllers/orders_controller.rb | 12 ++- app/views/orders/confirmation.html.erb | 75 +++++++++++++++++-- config/routes.rb | 1 + ...81026012310_add_name_and_email_to_order.rb | 6 ++ db/schema.rb | 4 +- 6 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20181026012310_add_name_and_email_to_order.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index af3b1018e2..2f15e5e34f 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -57,6 +57,7 @@ Responsive navbar-brand image CSS - add 100% height and width auto ... similar to how bootstrap img-responsive class works ***********************************/ + .navbar-brand { padding: 0px; font-family: "Butcherman"; diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index bec9140b6c..bc771cc495 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -44,7 +44,7 @@ def update flash[:status] = :success flash[:result_text] = "Success! Order #{@current_order.id} is complete! Enjoy your unique home!" - redirect_to order_path(@current_order.id) #Redirect to order confirmation + redirect_to confirmation_path(@current_order.id) #Redirect to order confirmation else flash.now[:status] = :failure flash.now[:result_text] = "Could not update #{@current_order.id}. Please check the forms" @@ -70,9 +70,17 @@ def index def destroy end + def confirmation + @items_in_cart = @current_order.orders_items + @revenue_total = @items_in_cart.inject(0) { |sum, item| sum + item.calculate_total } + @date_placed = @current_order.updated_at + @order_status = @current_order.status + + end + private def order_params - return params.require(:order).permit(:status, :street, :city, :state, :zip, :creditcard, :cvv, :billingzip, :ccexpiration, :user_id) + return params.require(:order).permit(:status, :street, :city, :state, :zip, :creditcard, :cvv, :billingzip, :ccexpiration, :name, :email, :user_id) end def find_order diff --git a/app/views/orders/confirmation.html.erb b/app/views/orders/confirmation.html.erb index 2991edd4a7..297ff495d2 100644 --- a/app/views/orders/confirmation.html.erb +++ b/app/views/orders/confirmation.html.erb @@ -1,5 +1,70 @@ -<% @items_in_cart.each do |item| %> -

    - <%= "#{item}" %> -

    - <% end %> + +
    +
    +
    +
    +
    + +

    Confirmation

    +
    + + + + + + + + + <% @items_in_cart.each do |item| %> + + + + + + <% end %> + +
    + Item + + Subtotal + + Description +
    + <%= "#{item.product.name}" %> + + <%= number_to_currency(item.calculate_total) %> + + <%= link_to "#{item.product.name.capitalize}", product_path(item.product.id) %> +
    + + + + + + + + + + + + + + + + + +
    + Total + + Time Placed + + Status +
    + <%= number_to_currency(@revenue_total) %> + + <%= format_date(@date_placed) %> + + <%= @order_status.capitalize %> +
    + +
    diff --git a/config/routes.rb b/config/routes.rb index 400bd04f69..428b41712b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ delete "/logout", to: "sessions#destroy", as: "logout" get "users/:id/dashboard", to: "users#dashboard", as: "dashboard" get "users/:user_id/products", to: "users#products", as: "merchant_products" + get "orders/:order_id/confirmation", to: "orders#confirmation", as: "confirmation" # resources :orders, only: [:show, :new, :create, :index] # get 'sessions/login' diff --git a/db/migrate/20181026012310_add_name_and_email_to_order.rb b/db/migrate/20181026012310_add_name_and_email_to_order.rb new file mode 100644 index 0000000000..95c6dec388 --- /dev/null +++ b/db/migrate/20181026012310_add_name_and_email_to_order.rb @@ -0,0 +1,6 @@ +class AddNameAndEmailToOrder < ActiveRecord::Migration[5.2] + def change + add_column :orders, :name, :string + add_column :orders, :email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 176a6d1a6d..da00e58b0a 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: 2018_10_21_213645) do +ActiveRecord::Schema.define(version: 2018_10_26_012310) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,6 +41,8 @@ t.integer "cvv" t.integer "billingzip" t.bigint "user_id" + t.string "name" + t.string "email" t.index ["user_id"], name: "index_orders_on_user_id" end From 8e6143779361447bed2a2b4fe1fa6239c9ee7228 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 19:48:37 -0700 Subject: [PATCH 181/239] added safety loop to order#update --- app/controllers/orders_controller.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 267190d4fd..f3f7931bc7 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -48,19 +48,12 @@ def update render :edit, status: :bad_request else order.orders_items.each do |o_i| - o_i.product.reduce_stock(o_i.quantity) - o_i.product.save + o_i.product.reduce_stock(o_i.quantity) + o_i.product.save + if !o_i.product.save + redirect_to order_path(@current_order.id) + end end - end - if o_i.product.save - # MERGE -> once we merge change the redirect path to confirmation :) - # rediret_to confirmation_path(@current_order.id) - redirect_to order_path(@current_order.id) - - # else - # # binding.pry - # redirect_to order_path(@current_order.id) #Redirect to order confirmation - # end order.save end @@ -84,6 +77,10 @@ def destroy end private + + def adjust_stock(order) + end + def order_params return params.require(:order).permit(:status, :street, :city, :state, :zip, :creditcard, :cvv, :billingzip, :ccexpiration, :user_id) end From 970b219c7ecca0b6fa43fa2e65a8a0f441b670a3 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 19:48:44 -0700 Subject: [PATCH 182/239] Removed order index view and routes --- app/views/orders/index.html.erb | 11 ----------- config/routes.rb | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 app/views/orders/index.html.erb diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb deleted file mode 100644 index 23b51bf113..0000000000 --- a/app/views/orders/index.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -Orders#Index - - - - -

    Orders:

    -

    Here are your orders

    -<% @orders.each do |order| %> -
    - <%=link_to order, order_path(order.id) %> -<% end %> diff --git a/config/routes.rb b/config/routes.rb index 428b41712b..4e2523c1d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,7 +39,7 @@ # get 'categories/new' # get 'categories/create' - resources :orders, only: [:show, :new, :create, :index, :update, :edit] do + resources :orders, only: [:show, :new, :create, :update, :edit] do resources :orders_items, only: [:create, :new, :show, :destroy,:update] end From 1c00950336a76ebfcb0d3d10ebc6a016ab34c719 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 20:02:15 -0700 Subject: [PATCH 183/239] Fixed bug with confirmation page --- app/controllers/orders_controller.rb | 13 +++++++------ app/views/orders/confirmation.html.erb | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2f246f3802..ca6c17ce64 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -50,9 +50,9 @@ def update order.orders_items.each do |o_i| o_i.product.reduce_stock(o_i.quantity) o_i.product.save - if !o_i.product.save - redirect_to order_path(@current_order.id) - end + # if !o_i.product.save + # redirect_to order_path(@current_order.id) + # end end order.save end @@ -80,10 +80,11 @@ def destroy end def confirmation - @items_in_cart = @current_order.orders_items + @confirmed_order = Order.find_by(id: params[:order_id]) + @items_in_cart = @confirmed_order.orders_items @revenue_total = @items_in_cart.inject(0) { |sum, item| sum + item.calculate_total } - @date_placed = @current_order.updated_at - @order_status = @current_order.status + @date_placed = @confirmed_order.updated_at + @order_status = @confirmed_order.status end diff --git a/app/views/orders/confirmation.html.erb b/app/views/orders/confirmation.html.erb index 297ff495d2..f2e44bc4ff 100644 --- a/app/views/orders/confirmation.html.erb +++ b/app/views/orders/confirmation.html.erb @@ -1,4 +1,3 @@ -


    From b6535c6e1100ae78f343327e1814ede5e30c2052 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 20:03:15 -0700 Subject: [PATCH 184/239] a --- app/controllers/orders_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2f246f3802..5f15fc26f7 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -55,6 +55,7 @@ def update end end order.save + raise end flash[:status] = :success From 0d40fd2c6bee91716683ac7e0dd9d23d6ff63834 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 20:06:41 -0700 Subject: [PATCH 185/239] added loop back --- app/controllers/orders_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2b8c35720f..0c3f286003 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -50,9 +50,9 @@ def update order.orders_items.each do |o_i| o_i.product.reduce_stock(o_i.quantity) o_i.product.save - # if !o_i.product.save - # redirect_to order_path(@current_order.id) - # end + if !o_i.product.save + redirect_to order_path(@current_order.id) + end end order.save raise From fd717734b9b069bbd71cb9cbac0560e37d4ca114 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 20:17:25 -0700 Subject: [PATCH 186/239] cleaned up routes --- app/assets/stylesheets/application.scss | 4 +-- app/views/products/index.html.erb | 7 +++-- config/routes.rb | 36 +++---------------------- 3 files changed, 9 insertions(+), 38 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2f15e5e34f..f85abbfd55 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,9 +19,9 @@ @import url("https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"); @import url('https://fonts.googleapis.com/css?family=Butcherman|Creepster'); -// @import url('https://fonts.googleapis.com/css?family=Griffy'); +@import url('https://fonts.googleapis.com/css?family=Audiowide'); -$primary-font: 'Gudea', sans-serif; +$primary-font: 'Audiowide', sans-serif; $primary-teal: #26A69A; $dark-teal: #00796B; $secondary-color: grey; diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 37caa7e2f4..dd15f7daca 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,7 +1,6 @@ - -

    Products#index

    -

    Find me in app/views/products/index.html.erb

    -
    loop thru all @products
    +
    +
    +
    <% @products.each do |product| %> diff --git a/config/routes.rb b/config/routes.rb index 4e2523c1d1..e5af937a8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,54 +1,26 @@ Rails.application.routes.draw do root 'products#root' - - get "/auth/:provider/callback", to: "sessions#login", as: "auth_callback" delete "/logout", to: "sessions#destroy", as: "logout" get "users/:id/dashboard", to: "users#dashboard", as: "dashboard" get "users/:user_id/products", to: "users#products", as: "merchant_products" get "orders/:order_id/confirmation", to: "orders#confirmation", as: "confirmation" - # resources :orders, only: [:show, :new, :create, :index] - # get 'sessions/login' - # get 'sessions/destroy' - # Might not need new/create/show - # Oauth does new/create, show is dashboard resources :users, only: [ :new, :create, :index] -# Creates route for user_products so we can link each merchant to -# users/:user_id/products - # resources :users, only: [:show] do - # resources :products, only: [:index] - # end - - # TODO Added nested routes for orderitems get '/sessions/current_order', to: "sessions#current_order", as: "current_order" - # get 'users/new' - # get 'users/create' - # get 'users/show' + resources :products, except: [:destroy] do post 'retire', to: "products#retire", as: "retire" post 'add_to_cart', to: "products#add_to_cart", as: "add_to_cart" end - # get '/products', to: 'products#index', as: 'products' - # get '/products/:id', to: 'products#show', as: 'product' - resources :categories, only: [ :new, :create, :index , :show] - # get 'categories/new' - # get 'categories/create' - resources :orders, only: [:show, :new, :create, :update, :edit] do - resources :orders_items, only: [:create, :new, :show, :destroy,:update] -end - - - - # get '/order/:id/orders_items', to: 'orders_items#index' - # get '/order/:id/orders_items', to: 'orders_items#new' - # post '/order/:id/orders_items', to: 'orders_items#create' - + resources :orders, only: [:show, :new, :create, :index, :update, :edit] do + resources :orders_items, only: [:create, :new, :show, :destroy,:update] + end end From 57820bed497ac1e53a659c67675890ec3f962fe1 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 20:34:10 -0700 Subject: [PATCH 187/239] deleted pry --- app/assets/stylesheets/application.scss | 2 +- app/controllers/products_controller.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index f85abbfd55..36b79247d3 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -21,7 +21,7 @@ @import url('https://fonts.googleapis.com/css?family=Audiowide'); -$primary-font: 'Audiowide', sans-serif; +$primary-font: 'Gudea', sans-serif; $primary-teal: #26A69A; $dark-teal: #00796B; $secondary-color: grey; diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 053eeb0e18..25d4650b50 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,4 +1,3 @@ -require 'pry' class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :retire] before_action :require_login, except: [:index, :show, :add_to_cart, :root] From 6917adc5d908a5c0572ae77af4c302a8a1ab401c Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 20:42:24 -0700 Subject: [PATCH 188/239] removed raise from order#update --- app/controllers/orders_controller.rb | 1 - app/views/products/new.html.erb | 2 -- app/views/products/show.html.erb | 7 ++++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 0c3f286003..20b3411db6 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -55,7 +55,6 @@ def update end end order.save - raise end flash[:status] = :success diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index 635e675ca2..8db20bdd54 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -2,9 +2,7 @@

    -

    Hey <%# @product.user.name %>! Add a New Product!

    -

    Find me in app/views/products/new.html.erb

    <%= render partial: "form", locals: { action_name: "Create New Product", button_title: 'Save' } %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index caa24850c8..19aad490e8 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,5 +1,6 @@ -

    Products#show

    -

    Find me in app/views/products/show.html.erb

    +
    +
    +
    <% if @product.nil? %>

    404 Not found

    @@ -21,7 +22,7 @@ - + <%# link_to "Edit", edit_product_path(@product.id) %> <%# link_to "Delete #{@product.title}", product_path(@product.id), method: :delete %> From e389625e44eacd5aaf5252920ea7e21beeb1103e Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 25 Oct 2018 20:43:34 -0700 Subject: [PATCH 189/239] Added validation so the quantity is and integer --- app/models/orders_item.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/orders_item.rb b/app/models/orders_item.rb index 3ac788b044..a092a2ea94 100644 --- a/app/models/orders_item.rb +++ b/app/models/orders_item.rb @@ -1,7 +1,7 @@ class OrdersItem < ApplicationRecord belongs_to :product belongs_to :order - validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 } + validates :quantity, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } def calculate_total From 8ac88e91a1ea1c00b4327d0def29bd7df37a614f Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 21:04:44 -0700 Subject: [PATCH 190/239] updated redirect in add_to_cart method so it returns to products pg --- app/controllers/application_controller.rb | 30 +++-------------------- app/controllers/products_controller.rb | 2 +- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 69809081c5..2856c84143 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,19 +1,8 @@ class ApplicationController < ActionController::Base before_action :current_order before_action :find_merchant - before_action :is_merchant? before_action :find_user - def render_404 - # DPR: this will actually render a 404 page in production - render :test => "404 Not Found", :status => 404 - end - -## added - # def list_categories - # @categories = Category.all - # end - private def find_user @@ -21,9 +10,7 @@ def find_user end def require_login - # Check if current user is logged in (has uid/provider) - # Would have user_id and provider and uid - # + # Check if current user is logged in (has uid/provider) # Would have user_id and provider and uid if !find_merchant flash[:danger] = "You must be logged in to view this section" redirect_to root_path @@ -35,20 +22,12 @@ def find_merchant # What if it's nil? end - def is_merchant? - # - return @merchant - end - def find_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end def current_order - # If nil, make one - # Else, find and use the current one - - #Try and find the order + # If nil, make one # Else, find and use the current one #Try and find the order #To avoid getting a complete shopping cart add the complete #at current order status will complete and it will create a new one @current_order = Order.find_by(id: session[:order_id], status: "pending") @@ -57,12 +36,11 @@ def current_order #create @current_order if @current_order is nil @current_order = Order.create(status: "pending") session[:order_id] = @current_order.id - # else #needs to move above the create nil # #write a test to show the weakness of a project # return @current_order # - #what happens if find_by returns nil because it can? + #what happens if find_by returns nil because it can? end return @current_order end @@ -70,7 +48,7 @@ def current_order # def current_order # @order = Order.find_by(id:session[:order_id]) # return @order if @order -# if is_merchant? #Does the order have a merchant? +# if the order has a merchant (use helper method?) # @order = Order.find_by(user_id: @merchant.id, status: "pending")#to find pending orders for a merchant # session[:order_id] = @order.id # else #They are checking out as a guest, there won't be a user_id relation diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 25d4650b50..bb7d29a838 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -28,7 +28,7 @@ def add_to_cart end @current_order.add_product(params[:product_id], quantity) - redirect_to root_path + redirect_to products_path end def new From 07b0dc05e2f257f59590c537547fe0997a54120e Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 25 Oct 2018 21:09:43 -0700 Subject: [PATCH 191/239] edited dashboard view --- app/views/users/dashboard.html.erb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index aff445e911..d42bc83792 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -1,10 +1,15 @@ +
    +
    +
    + + <% if @user.nil? %>

    User Not Found

    <% else %>
    -

    <%= "#{@merchant.name}'s Dashboard" %>

    +

    <%= "#{@merchant.name}'s Dashboard" %>

    From af3ce9b07b4fb948a86d8582575e3a3dab5d2759 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Thu, 25 Oct 2018 22:16:04 -0700 Subject: [PATCH 192/239] Removed default heading on product root page --- app/views/products/root.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb index 4be4119809..7f43209ee0 100644 --- a/app/views/products/root.html.erb +++ b/app/views/products/root.html.erb @@ -1,4 +1,4 @@ -
    this is the home page housed in products#root
    + +
    + <% flash.each do |name, message| %> + <% if message.class == Array %> +
    + <% message.each do |msg| %> +

    <%= "#{name}:" %><%= " #{msg}" %>

    + <% end %> +
    <% else %> - <%= link_to "Login", "/auth/github",class:"btn btn-light btn-capsul px-4 py-2" %> +
    + <%= message %> +
    <% end %> - - -
    -
    - - + <% end %> +
    +
    - <%= yield %> + <%= yield %>
    - - - - + diff --git a/app/views/orders/confirmation.html.erb b/app/views/orders/confirmation.html.erb index f2e44bc4ff..a34b8373ec 100644 --- a/app/views/orders/confirmation.html.erb +++ b/app/views/orders/confirmation.html.erb @@ -1,8 +1,8 @@
    +

    Confirmation

    diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb index 4be4119809..e28da1b5e1 100644 --- a/app/views/products/root.html.erb +++ b/app/views/products/root.html.erb @@ -1,4 +1,3 @@ -
    this is the home page housed in products#root
    diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 76a04cf835..a3109448f7 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -8,7 +8,7 @@ <% @merchants.each do |merchant| %>
    -
    +



    From 5fa224622bd124dfa1dcf28a394fd426b7b08dd7 Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 26 Oct 2018 00:10:18 -0700 Subject: [PATCH 195/239] edited flash msg in order#controller#update --- app/controllers/orders_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 20b3411db6..d13857873c 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -57,11 +57,9 @@ def update order.save end - flash[:status] = :success - flash[:result_text] = "Success! Order #{@current_order.id} is complete! Enjoy your unique home!" + flash[:success] = "Order has been placed! Your ORDER CONFIRMATION ##{@current_order.id} " redirect_to confirmation_path(@current_order.id) #Redirect to order confirmation else - flash.now[:status] = :failure flash.now[:result_text] = "Could not update #{@current_order.id}. Please check the forms" flash.now[:messages] = @current_order.errors.messages render :edit, status: :bad_request From 0cc08d84435eb647bc453c426d3e9c727a30c3d8 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 07:45:04 -0700 Subject: [PATCH 196/239] Reformatted dashboard products so they're in table format --- app/views/users/dashboard.html.erb | 130 ++++++++++------------------- 1 file changed, 45 insertions(+), 85 deletions(-) diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index f0a1ff20c8..5e40dbb818 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -37,96 +37,56 @@ -
    -

    My Products

    -
      - <% @merchant.products.each do |product| %> -
    • -

      <%= "#{product.name.capitalize}" %>

      - <%# image_tag("product.photo"), alt="#{product.name} image" %> -

      <%= "Price: #{number_to_currency(product.price)}" %>

      -

      <%= "Description: #{product.description}" %>

      -

      <%= "Stock: #{product.stock}" %>

      - - - - <%# link_to "Retire Product", retire_path(product.id), class: "btn btn-primary", method: :post %> - - <%# link_to "Retire Product", product_retire(product.id), class: "btn btn-primary", method: :post %> - <%= link_to "Edit Product", edit_product_path(product.id), class: "btn btn-primary" %> - - <% end %> - - -
    - - - + +

    My Products

    + + + + + + + + + + + + <% @merchant.products.each do |product| %> + + + + + + + + + <% end %> + +
    + Name + + Price + + Description + + Stock + + Edit +
    + <%= link_to product.name.capitalize, product_path(product.id) %> + + <%="#{number_to_currency(product.price)}" %> + + <%= "#{product.description}" %> + + <%= "#{product.stock}" %> + + <%= link_to "Edit", edit_product_path(product.id) %> +

    Orders

    <%= render partial: "statussummary" %> - - - -
    <% end %> From becebc193ba46ddb2687f04ac4d747e55e751ef4 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 07:48:08 -0700 Subject: [PATCH 197/239] Moved buttons for order status down to the order summary area --- app/views/users/dashboard.html.erb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 5e40dbb818..01f385cd51 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -22,18 +22,6 @@
  • <%= link_to "Add Category", new_category_path, class:"btn btn-primary" %>
  • -
  • - - <%= link_to "All Orders", dashboard_path(:status=>"all"), class:"btn btn-primary" %> -
  • - - <% @status_types.each do |status| %> -
  • - <%=link_to "#{status.capitalize} Orders", dashboard_path(:status=>"#{status}"), class:"btn btn-primary" %> -
  • - - - <% end %> @@ -85,6 +73,17 @@

    Orders

    +
      +
    • + + <%= link_to "All Orders", dashboard_path(:status=>"all"), class:"btn btn-primary" %> +
    • + <% @status_types.each do |status| %> +
    • + <%=link_to "#{status.capitalize} Orders", dashboard_path(:status=>"#{status}"), class:"btn btn-primary" %> +
    • + <% end %> +
    <%= render partial: "statussummary" %>
    From 303d38d0e14874cfd53ce17c23f11586ab82dda8 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 07:59:12 -0700 Subject: [PATCH 198/239] Added some styling to the dashboard including padding/header formatting --- app/assets/stylesheets/application.scss | 15 +++ app/assets/stylesheets/users.scss | 4 - app/views/users/dashboard.html.erb | 144 ++++++++++++------------ 3 files changed, 87 insertions(+), 76 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 36b79247d3..80489091b1 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -221,3 +221,18 @@ table { #merchant_options .btn { padding: 5px; } + +#dashboard_heading { + color: #26A59A; + text-align: center; + padding: 2rem; + } + + #dashboard_container h2 { + text-align: center; + padding: 1.5rem; + } + + #dashboard_container #order_filter li { + margin: 0.5rem; + } diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index 237e0438f6..31a2eacb84 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -1,7 +1,3 @@ // Place all the styles related to the Users controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.btn .black-button { - background-color: #000; - color: #FFF; -} diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 01f385cd51..416f51e3d6 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -7,85 +7,85 @@

    User Not Found

    <% else %> -
    -
    -

    <%= "#{@merchant.name}'s Dashboard" %>

    - +
    +
    +

    <%= "#{@merchant.name}'s Dashboard" %>

    + -
    +
    - + - -

    My Products

    - - - - - - - - - - - - <% @merchant.products.each do |product| %> +
    - Name - - Price - - Description - - Stock - - Edit -
    +

    My Products

    + - - - - - + + + + + + + + + <% @merchant.products.each do |product| %> + + + + + + + - <% end %> - -
    - <%= link_to product.name.capitalize, product_path(product.id) %> - - <%="#{number_to_currency(product.price)}" %> - - <%= "#{product.description}" %> - - <%= "#{product.stock}" %> - - <%= link_to "Edit", edit_product_path(product.id) %> - + Name + + Price + + Description + + Stock + + Edit +
    + <%= link_to product.name.capitalize, product_path(product.id) %> + + <%="#{number_to_currency(product.price)}" %> + + <%= "#{product.description}" %> + + <%= "#{product.stock}" %> + + <%= link_to "Edit", edit_product_path(product.id) %> +
    + <% end %> + + -
    -

    Orders

    -
      -
    • - - <%= link_to "All Orders", dashboard_path(:status=>"all"), class:"btn btn-primary" %> -
    • - <% @status_types.each do |status| %> -
    • - <%=link_to "#{status.capitalize} Orders", dashboard_path(:status=>"#{status}"), class:"btn btn-primary" %> -
    • - <% end %> -
    - <%= render partial: "statussummary" %> +
    +

    Orders

    +
      +
    • + + <%= link_to "All Orders", dashboard_path(:status=>"all"), class:"btn btn-primary" %> +
    • + <% @status_types.each do |status| %> +
    • + <%=link_to "#{status.capitalize} Orders", dashboard_path(:status=>"#{status}"), class:"btn btn-primary" %> +
    • + <% end %> +
    + <%= render partial: "statussummary" %> -
    +
    <% end %> From 989c77eb491380ed03def2977e7164984f85fc64 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 08:01:38 -0700 Subject: [PATCH 199/239] Wrapped product show page in a container. Set list style type to none to remove bullets --- app/assets/stylesheets/application.scss | 4 +++ app/views/products/show.html.erb | 34 +++++++++++++------------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 80489091b1..a040dce43e 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -236,3 +236,7 @@ table { #dashboard_container #order_filter li { margin: 0.5rem; } + + ul { + list-style-type: none; + } diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 19aad490e8..772812705f 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,24 +1,26 @@


    +
    + <% if @product.nil? %> +

    404 Not found

    + <% else %> +

    <%=@product.name.capitalize%>

    +
    <%#@product.photo %>
    +
      +
    • Price: <%= @product.price %>
    • +
    • Description: <%= @product.description %>
    • +
    • Stock: <%= @product.stock %>
    • +
    + <% end %> -<% if @product.nil? %> -

    404 Not found

    -<% else %> -

    <%=@product.name %>

    -
    <%#@product.photo %>
    -
      -
    • Price: <%= @product.price %>
    • -
    • Description: <%= @product.description %>
    • -
    • Stock: <%= @product.stock %>
    • -
    -<% end %> + <%= form_with url: product_add_to_cart_path(@product.id) do |f|%> + <%= f.label :quantity %> + <%= f.text_field :quantity %> + <%= f.submit "Add to Cart" %> + <% end %> -<%= form_with url: product_add_to_cart_path(@product.id) do |f|%> - <%= f.label :quantity %> - <%= f.text_field :quantity %> - <%= f.submit "Add to Cart" %> -<% end %> +
    From 13d0b7e7dcf4e2d8f2eb2c2b04aae7dc3e3859b5 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 08:02:59 -0700 Subject: [PATCH 200/239] Removed extra padding on product show page ul --- app/assets/stylesheets/application.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index a040dce43e..5f56cddf13 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -239,4 +239,6 @@ table { ul { list-style-type: none; + // margin: 0; + padding: 0; } From 3b9d337cecea33a5d99916bbf7c45907e297ddb1 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 08:26:08 -0700 Subject: [PATCH 201/239] Changed user index to say Agents/wrapped content in a container div --- app/assets/stylesheets/application.scss | 1 + app/views/products/index.html.erb | 2 +- app/views/users/index.html.erb | 36 ++++++++++++------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index dd828d14b3..a75eb828b2 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -246,6 +246,7 @@ table { padding: 0; } + .content-half { background-color: #b35919; } diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index dd15f7daca..0ed273787f 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -16,7 +16,7 @@
    $<%=readable_price(product.price) %>
    - <%= link_to "Add to Cart", product_add_to_cart_path(product.id), method: :post, class: "btn btn-primary btn-sm"%> + <%= link_to "Add to Cart", product_add_to_cart_path(product.id), method: :post, class: "btn btn-primary btn-sm add-to-cart"%> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index a3109448f7..94fef37fa8 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,27 +1,25 @@


    -

    Merchants

    +
    +

    Agents

    -
    -
    +
    +
    - <% @merchants.each do |merchant| %> -
    -
    -
    -
    -
    -
    -
    -

    <%= link_to "#{merchant.name}", merchant_products_path(merchant.id) %>

    + <% @merchants.each do |merchant| %> +
    +

    +
    +
    +
    +
    +

    <%= link_to "#{merchant.name}", merchant_products_path(merchant.id) %>

    +
    +
    -
    - <%end %> - - - - -
    + <%end %> +
    +
    From 7912ae92608ee61759925b47af99d676800eefa4 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 08:41:55 -0700 Subject: [PATCH 202/239] Added text muted class to some headings --- app/assets/stylesheets/application.scss | 4 ++-- app/views/categories/index.html.erb | 6 ++---- app/views/users/_statussummary.html.erb | 4 ++-- app/views/users/dashboard.html.erb | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index a75eb828b2..7d5f24299a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -226,13 +226,13 @@ table { } #dashboard_heading { - color: #26A59A; + // color: #26A59A; text-align: center; padding: 2rem; } #dashboard_container h2 { - text-align: center; + // text-align: center; padding: 1.5rem; } diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 05a8e64469..da5939c040 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -1,10 +1,8 @@
    -
    -
    - -

    Categories

    +

    Categories

    +
    <%# @category_photos.each do |photo| %> diff --git a/app/views/users/_statussummary.html.erb b/app/views/users/_statussummary.html.erb index 31f9bab6fd..1ebed4ddcc 100644 --- a/app/views/users/_statussummary.html.erb +++ b/app/views/users/_statussummary.html.erb @@ -1,8 +1,8 @@ -

    <%= "Order Summary" %>

    +

    <%= "Order Summary" %>

    - +
    - + From 699eb7a8e43fda1f301120f053a44ddeb2ed77e4 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Fri, 26 Oct 2018 09:53:08 -0700 Subject: [PATCH 210/239] updated the carousel to not be full width --- app/assets/stylesheets/application.scss | 12 ++++++++++++ app/views/products/root.html.erb | 5 ++--- test/models/order_test.rb | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7d5f24299a..3b7d51a4d7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -34,6 +34,18 @@ body { // background: black; } +.carousel, .item, .active { + height:100%; +} +.carousel-inner { + width:100%; +} +.fill { + width:100%; + height:100%; + background-position:center; + background-size:cover; +} body, h1, h2, h3, h4, h5 { font-family: $primary-font; diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb index e28da1b5e1..3183957837 100644 --- a/app/views/products/root.html.erb +++ b/app/views/products/root.html.erb @@ -1,12 +1,11 @@ - -
    diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb index 416f51e3d6..7d3b8f1cb4 100644 --- a/app/views/users/dashboard.html.erb +++ b/app/views/users/dashboard.html.erb @@ -9,7 +9,7 @@
    -

    <%= "#{@merchant.name}'s Dashboard" %>

    +

    <%= "#{@merchant.name}'s Dashboard" %>

    @@ -26,7 +26,7 @@ -

    My Products

    +

    My Products

    @@ -72,7 +72,7 @@
    -

    Orders

    +

    Orders

    • From dc580e0fa9fe019f4061d08dff1c1c96025d9cb0 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 08:43:36 -0700 Subject: [PATCH 203/239] Wrapped order not shown page in a container div --- app/views/orders/show.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 9cd9135d6b..4627b9001f 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -3,11 +3,14 @@ -

      Shopping Cart

      <% if @current_order.products.count == 0 %> +
      +

      Shopping Cart

      Your cart is empty

      Pick your next nightmare home at Shop All Homes above!

      +
      + <% else %>
      From e2e8f4dce71612fc8bf80fd8bc359b2434030915 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 08:44:38 -0700 Subject: [PATCH 204/239] Removed odd comment tags that were showing on html --- app/views/orders/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 4627b9001f..11e805b03c 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -2,11 +2,11 @@ - + <% if @current_order.products.count == 0 %>
      -

      Shopping Cart

      +

      Shopping Cart

      Your cart is empty

      Pick your next nightmare home at Shop All Homes above!

      From 805e8c8709d364aea67d2e8ee3b4f39458084c01 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Fri, 26 Oct 2018 09:06:37 -0700 Subject: [PATCH 205/239] fixed some tests --- app/controllers/categories_controller.rb | 2 +- .../controllers/categories_controller_test.rb | 7 +-- test/fixtures/orders_items.yml | 2 +- test/fixtures/products.yml | 2 +- test/models/order_test.rb | 21 ++++---- test/models/ordersitem_test.rb | 26 ++++++++++ test/models/product_test.rb | 50 ++++++++++++++----- 7 files changed, 83 insertions(+), 27 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 581cd66c4c..37b07507bf 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -13,7 +13,7 @@ def create if @category.save flash[:success] = "#{@category.name} added!" - redirect_to root_path #change this to dashboard_path + redirect_to dashboard_path(@current_user.id) else #save failed flash.now[:danger] = "Category #{@category.name} not added!" render :new, status: :bad_request diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb index 82ffe6f217..a4648031ad 100644 --- a/test/controllers/categories_controller_test.rb +++ b/test/controllers/categories_controller_test.rb @@ -25,15 +25,16 @@ it "can create a new category given valid params" do - #blocking this out for now until i have Cassy's dashboard view - # Act-Assert + @current_user = users(:user1) + expect { post categories_path, params: category_hash }.must_change 'Category.count', 1 must_respond_with :redirect - must_redirect_to root_path #do i need to change this to dashboard_path and add user id here? + + must_redirect_to dashboard_path(user.id) expect(Category.last.name).must_equal category_hash[:category][:name] diff --git a/test/fixtures/orders_items.yml b/test/fixtures/orders_items.yml index 01502cf47e..dd7305023e 100644 --- a/test/fixtures/orders_items.yml +++ b/test/fixtures/orders_items.yml @@ -1,7 +1,7 @@ item1: order: one product: product3 - quantity: 2 + quantity: 3 item2: order: one diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 8d923f345d..8b7700b01a 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -21,7 +21,7 @@ product2: product3: name: c product - price: 11.99 + price: 10.00 description: MyString photo: MyString stock: 3 diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 5a7185ce55..9f178a7d8e 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,14 +1,15 @@ require "test_helper" - +require 'pry' describe Order do let(:order) { orders(:one) } it "must be valid" do order = Order.new + order.status = "pending" order.valid?.must_equal true end it "must have required fields" do - fields = [ :status,:street,:city,:state,:zip,:creditcard,:cvv,:billingzip] + fields = [ :status,:street,:city,:state,:zip,:creditcard,:cvv,:billingzip, :name, :email] fields.each do |field| expect(order).must_respond_to field @@ -16,16 +17,17 @@ end describe 'Relationships' do - it 'belongs to user' do - user = order.user + it 'can belong to user' do + user = order.user + binding.pry expect(user).must_be_instance_of User expect(user.id).must_equal order.user_id end it 'can have many products' do - order.products << Product.first + order.products << products(:product1) products = order.products expect(products.length).must_be :>=, 1 @@ -45,7 +47,7 @@ let(:order) { orders(:one) } it "adds product to order" do - product = products(:product2) + product = products(:product1) product_params = { orders_item: { @@ -54,9 +56,10 @@ } } - expect(order.products.count).must_equal 0 - order.add_product(product_params) - expect(order.products.count).must_equal 1 + num_p = order.products.count + order.add_product(product_params,1) + binding.pry + expect(order.products.count).must_equal num_p + 1 expect(order.products.first.id).must_equal product.id end diff --git a/test/models/ordersitem_test.rb b/test/models/ordersitem_test.rb index 260682ed5c..fe9d845586 100644 --- a/test/models/ordersitem_test.rb +++ b/test/models/ordersitem_test.rb @@ -20,5 +20,31 @@ expect(order).must_be_instance_of Order expect(order.id).must_equal item.order_id end + + it 'belongs to product' do + product = item.product + + expect(product).must_be_instance_of Product + expect(product.id).must_equal item.product_id + end + end + + describe 'Validations' do + it 'has valid quantity' do + qtys = ["s", :price, "134e", nil, -1] + + qtys.each do |qty| + item.quantity = qty + valid = item.save + expect(valid).must_equal false + end + end + + end + + describe 'Custom Methods' do + it 'can calculate total revenue for an item' do + expect(item.calculate_total).must_equal 10.00*3 + end end end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 17eed37959..18fe076749 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,5 +1,5 @@ require "test_helper" - +require 'pry' describe Product do let(:product) { products(:product1) } @@ -35,7 +35,7 @@ end it 'can have many orders' do - product.orders << Order.first + orders = product.orders expect(orders.length).must_be :>=, 1 @@ -44,15 +44,15 @@ end end end + describe 'Validations' do it 'must have name' do - product = products(:product2) - product.name = nil - - valid = product.save - expect(valid).must_equal false - expect(product.errors.messages).must_include :name + product = products(:product2) + product.name = nil + valid = product.save + expect(valid).must_equal false + expect(product.errors.messages).must_include :name end it 'must have a unique product name for given merchant' do @@ -92,6 +92,7 @@ product.price = invalid_price valid = product.save expect(valid).must_equal false + expect(product.errors.messages).must_include :price end end @@ -113,16 +114,41 @@ expect(product.errors.messages).must_include :photo end - it 'must have stock' do + it 'must have a valid stock' do product = products(:product2) - product.stock = nil + invalid_stocks = ["s", :price, "134e", nil, -1] + + invalid_stocks.each do |stock| + product.stock = stock + valid = product.save + expect(valid).must_equal false + expect(product.errors.messages).must_include :stock + end + end + + end + + describe 'Custom Methods' do + it 'must create a list of unique categories' do + category_list = Product.category_list + category_list.each do |category| + expect(Category.all).must_include category + end + end + + it 'can reduce stock when there is enough stock' do + stock_check = product.stock + product.reduce_stock(1) + expect(product.stock).must_equal stock_check - 1 + + end + it 'will not reduce stock if there is not enough' do + product.reduce_stock(2) valid = product.save expect(valid).must_equal false expect(product.errors.messages).must_include :stock end - - end end From 871ebf9b0af9b5ee2e78053c6811c91be5dcb628 Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 26 Oct 2018 09:13:39 -0700 Subject: [PATCH 206/239] added category new page and conditional in the caegory index to skip if no product photo --- app/views/categories/_form.html.erb | 26 ++++++++++++++++++++++++++ app/views/categories/index.html.erb | 2 ++ app/views/categories/new.html.erb | 5 +++-- app/views/products/_form.html.erb | 29 ++++++++++++++++------------- app/views/products/new.html.erb | 6 ------ 5 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 app/views/categories/_form.html.erb diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb new file mode 100644 index 0000000000..05f9851e28 --- /dev/null +++ b/app/views/categories/_form.html.erb @@ -0,0 +1,26 @@ +
      + <% if @category.errors.any? %> +
        + <% @category.errors.each do |column, message| %> +
      • + <%= column.capitalize %> <%= message %> +
      • + <% end %> +
      + <% end %> + +
        + <%= form_with model: @category, class: "form" do |f|%> + + <%# f.collection_check_boxes :category_ids, Category.all, :id, :name%> + +
      • <%= f.label :name %>
      • +
      • <%= f.text_field :name, class: ""%>
      • + + + <%= f.submit button_title, class: 'btn'%> + <% end %> +
      + +
      +
    diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index 05a8e64469..4c52245945 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -11,6 +11,7 @@ <% @categories.each do |category| %>
    + <% if !category.product_photo.nil? %> <%= link_to image_tag(category.product_photo, alt:"Card image cap", class:"card-img-top img-fluid"), category_path(category.id) %>

    <%= category.name %>

    @@ -18,6 +19,7 @@
    <% end %> + <% end %> diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb index 7e5c27307e..2f055f4698 100644 --- a/app/views/categories/new.html.erb +++ b/app/views/categories/new.html.erb @@ -1,2 +1,3 @@ -

    Categories#new

    -

    Find me in app/views/categories/new.html.erb

    +
    +<%= render partial: "form", locals: { action_name: "Create New Category", button_title: 'Save' } %> +
    diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index 8a66f7aafc..6dca11c682 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -10,28 +10,31 @@ <% end %> <%= form_with model: @product, class: "form" do |f|%> +
      <%# f.collection_check_boxes :category_ids, Category.all, :id, :name%> - <%= f.label :categories %> - <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> +
    • <%= f.label :categories %>
    • +
    • <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %>
    • - <%= f.label :price %> - <%= f.text_field :price, class: ""%> +
    • <%= f.label :price %>
    • +
    • <%= f.text_field :price, class: ""%>
    • - <%= f.label :name %> - <%= f.text_field :name, class: ""%> +
    • <%= f.label :name %>
    • +
    • <%= f.text_field :name, class: ""%>
    • - <%= f.label :description %> - <%= f.text_field :description, class: ""%> +
    • <%= f.label :description %>
    • +
    • <%= f.text_field :description, class: ""%>
    • - <%= f.label :stock %> - <%= f.text_field :stock, class: "" %> +
    • <%= f.label :stock %>
    • +
    • <%= f.text_field :stock, class: "" %>
    • - <%= f.label :photo %> - <%= f.text_field :photo, class: "" %> +
    • <%= f.label :photo %>
    • +
    • <%= f.text_field :photo, class: "" %>
    • <%= f.submit button_title, class: 'btn'%> - <% end %> + <% end %> +
    + diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index 8db20bdd54..d679e6d6d9 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -1,9 +1,3 @@ -
    -
    -
    - - -
    <%= render partial: "form", locals: { action_name: "Create New Product", button_title: 'Save' } %>
    From e5a220a03a2bd95903073279133a755dae02b5d0 Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 26 Oct 2018 09:18:15 -0700 Subject: [PATCH 207/239] added btn style to add cat and prod --- app/views/categories/_form.html.erb | 2 +- app/views/products/_form.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index 05f9851e28..f0e2c6e6dc 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -18,7 +18,7 @@
  • <%= f.text_field :name, class: ""%>
  • - <%= f.submit button_title, class: 'btn'%> + <%= f.submit button_title, class: 'btn btn-info'%> <% end %> diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index 6dca11c682..5ffa0a47d6 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -32,7 +32,7 @@
  • <%= f.label :photo %>
  • <%= f.text_field :photo, class: "" %>
  • - <%= f.submit button_title, class: 'btn'%> + <%= f.submit button_title, class: 'btn btn-info'%> <% end %> From b5ed89932528cf1f5970c3829e7aaf9b55c2ddbf Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 09:28:52 -0700 Subject: [PATCH 208/239] Commented out a oi save/redirect in the order controller update method --- app/controllers/orders_controller.rb | 6 +++--- app/views/products/_form.html.erb | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index d13857873c..fbadf6802b 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -50,9 +50,9 @@ def update order.orders_items.each do |o_i| o_i.product.reduce_stock(o_i.quantity) o_i.product.save - if !o_i.product.save - redirect_to order_path(@current_order.id) - end + # if !o_i.product.save + # redirect_to order_path(@current_order.id) + # end end order.save end diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index 8a66f7aafc..61958a557e 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,3 +1,4 @@ +
    <% if @product.errors.any? %>
      @@ -34,4 +35,4 @@ <%= f.submit button_title, class: 'btn'%> <% end %>
    - +
    From 5322bb183e5b2618657aef35caf1d7f81e3e48fa Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 09:51:11 -0700 Subject: [PATCH 209/239] Added dollar sign to cart order total --- app/views/orders/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 11e805b03c..a8c764a70e 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -57,7 +57,7 @@
    <%= link_to "Continue Shopping", products_path, class: "btn btn-dark"%> <%= link_to "Complete Order", edit_order_path(@current_order.id), class: "btn btn-success btn-block"%>
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ProductPriceQuantitySubtotal
    -
    - -
    -

    Product 1

    -

    Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet.

    -
    -
    -
    $1.99 - - 1.99 - - -
    Total 1.99
    Continue ShoppingCheckout
    -
    diff --git a/app/views/products/create.html.erb b/app/views/products/create.html.erb deleted file mode 100644 index d546021001..0000000000 --- a/app/views/products/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

    Products#create

    -

    Find me in app/views/products/create.html.erb

    diff --git a/app/views/products/update.html.erb b/app/views/products/update.html.erb deleted file mode 100644 index 039889ac02..0000000000 --- a/app/views/products/update.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

    Products#update

    -

    Find me in app/views/products/update.html.erb

    diff --git a/app/views/users/create.html.erb b/app/views/users/create.html.erb deleted file mode 100644 index 1342ee9725..0000000000 --- a/app/views/users/create.html.erb +++ /dev/null @@ -1,4 +0,0 @@ - - -

    Users#create

    -

    Find me in app/views/users/create.html.erb

    diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb deleted file mode 100644 index aa2f2bc3d0..0000000000 --- a/app/views/users/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ - - - -

    Users#new

    -

    Find me in app/views/users/new.html.erb

    diff --git a/config/routes.rb b/config/routes.rb index 411fac7f5a..7c6ad1d6cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,7 @@ resources :categories, only: [ :new, :create, :index , :show] resources :orders, only: [:show, :update, :edit] do - resources :orders_items, only: [:create, :new, :show, :destroy,:update] + resources :orders_items, only: [:create, :new, :destroy,:update] end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 6947ee5770..cac8f611b8 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,14 +1,6 @@ require "test_helper" describe UsersController do - describe "new" do - it "should get new" do - # Act - get new_user_path - # Assert - must_respond_with :success - end - end describe "index" do it "should get index" do @@ -125,7 +117,8 @@ # Says the count changed :( - must_respond_with :bad_request + must_respond_with :redirect + must_redirect_to root_path end end From 41f739ebc459ee5affc3384ac37b0cadae697fd1 Mon Sep 17 00:00:00 2001 From: Cassandra Archibald Date: Fri, 26 Oct 2018 13:57:51 -0700 Subject: [PATCH 238/239] Removed prys --- test/controllers/categories_controller_test.rb | 2 +- test/controllers/orders_controller_test.rb | 2 -- test/controllers/orders_items_controller_test.rb | 1 - test/models/order_test.rb | 3 +-- test/models/product_test.rb | 1 - test/test_helper.rb | 1 - 6 files changed, 2 insertions(+), 8 deletions(-) diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb index 885607edde..819a99f0a7 100644 --- a/test/controllers/categories_controller_test.rb +++ b/test/controllers/categories_controller_test.rb @@ -1,5 +1,5 @@ require "test_helper" -require 'pry' + describe CategoriesController do it "should get index" do get categories_path diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 874fc42955..445c097ffa 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -22,9 +22,7 @@ order = Order.all.last must_respond_with :redirect - # binding.pry must_redirect_to confirmation_path(order.id) - # binding.pry expect(order.status).must_equal "paid" expect(order.street).must_equal order_hash[:order][:street] diff --git a/test/controllers/orders_items_controller_test.rb b/test/controllers/orders_items_controller_test.rb index ba94a02823..251e767e80 100644 --- a/test/controllers/orders_items_controller_test.rb +++ b/test/controllers/orders_items_controller_test.rb @@ -11,7 +11,6 @@ # "order_id" = $1 [["order_id", 193]] # => [#, # #] - # [5] pry(main)> Order.find_by(id:193).orders_items end it "can remove new items to an order" do diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 6548698d7a..8ee13799b4 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,5 +1,4 @@ require "test_helper" -require 'pry' describe Order do let(:order) { orders(:one) } it "must be valid" do @@ -74,7 +73,7 @@ end it "will not add item if product is nil" do - + end it 'Will sum up an Orders total price' do diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 3a56710568..15a773ce8b 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,5 +1,4 @@ require "test_helper" -require 'pry' describe Product do let(:product) { products(:product1) } diff --git a/test/test_helper.rb b/test/test_helper.rb index 995e23bb7b..65c36903c2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,4 @@ require 'simplecov' -require 'pry' SimpleCov.start 'rails' do add_filter '/bin/' add_filter '/db/' From 9bfeb37615bae2d819b69e167e463769db37d72c Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 26 Oct 2018 13:58:46 -0700 Subject: [PATCH 239/239] deleted pry from files --- app/controllers/orders_controller.rb | 4 --- .../controllers/categories_controller_test.rb | 1 - test/controllers/orders_controller_test.rb | 2 -- test/models/order_test.rb | 32 ++++++++++++++++--- test/models/product_test.rb | 1 - test/test_helper.rb | 1 - 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 430f79e4ff..bfb5b3d963 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -52,10 +52,6 @@ def update end flash[:success] = "Order has been placed! Your ORDER CONFIRMATION ##{@current_order.id} " redirect_to confirmation_path(@current_order.id) #Redirect to order confirmation - else - flash.now[:result_text] = "Could not update #{@current_order.id}. Please check the forms" - flash.now[:messages] = @current_order.errors.messages - render :edit, status: :bad_request end end diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb index 885607edde..aa3aff960d 100644 --- a/test/controllers/categories_controller_test.rb +++ b/test/controllers/categories_controller_test.rb @@ -1,5 +1,4 @@ require "test_helper" -require 'pry' describe CategoriesController do it "should get index" do get categories_path diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 782f189a9c..d9c9f1443f 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -22,9 +22,7 @@ order = Order.all.last must_respond_with :redirect - # binding.pry must_redirect_to confirmation_path(order.id) - # binding.pry expect(order.status).must_equal "paid" expect(order.street).must_equal order_hash[:order][:street] diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 6548698d7a..02cab007dc 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,5 +1,4 @@ require "test_helper" -require 'pry' describe Order do let(:order) { orders(:one) } it "must be valid" do @@ -52,9 +51,32 @@ end describe 'Validations' do - #Need to add tests here - #Validation that a product could not be added - # + + it 'will not save an invalid status' do + invalid_statuses = ["s", :price, "134e", nil, -1] + order = orders(:one) + + invalid_statuses.each do |invalid_status| + order.status = invalid_status + valid = order.save + expect(valid).must_equal false + expect(order.errors.messages).must_include :status + end + + valid_statuses = ["pending", "paid","complete", "cancelled"] + end + + it 'will save with a valid status' do + valid_statuses = ["pending", "paid","complete", "cancelled"] + order = orders(:one) + + valid_statuses.each do |valid_status| + order.status = valid_status + valid = order.save + expect(valid).must_equal true + end + end + end describe "add_product" do @@ -74,7 +96,7 @@ end it "will not add item if product is nil" do - + end it 'Will sum up an Orders total price' do diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 3a56710568..15a773ce8b 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,5 +1,4 @@ require "test_helper" -require 'pry' describe Product do let(:product) { products(:product1) } diff --git a/test/test_helper.rb b/test/test_helper.rb index 995e23bb7b..65c36903c2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,4 @@ require 'simplecov' -require 'pry' SimpleCov.start 'rails' do add_filter '/bin/' add_filter '/db/'