From 516d3861a42e989473c84cb302b92b8584d6b9e5 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Wed, 17 Oct 2018 10:29:28 -0700 Subject: [PATCH 001/192] rails setup --- .gitignore | 27 ++ .ruby-version | 1 + Gemfile | 81 +++++ Gemfile.lock | 277 ++++++++++++++++++ Guardfile | 9 + 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 80 files changed, 1406 insertions(+) create mode 100644 .gitignore create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Guardfile create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/stylesheets/application.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..25c81fe399 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.5.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..6219256bd8 --- /dev/null +++ b/Gemfile @@ -0,0 +1,81 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.5.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..90a29ea433 --- /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.5.1p57 + +BUNDLED WITH + 1.16.3 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/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..2170aafac5 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +6qMkHjG2FcVe8v2LPgI4ogyQYaCK5bMWmEkSKjF4CJMmfhWKZ2OeTv/ePiXOcz3w/Kn5GX0h21i4dHUPl9MQinnI3QepErVUXUR4rFZZbqBI39sAu1MqSmu3OMlKPnunn7jcwgcol3H3akRkdhgL/GapeGVNzu+oR4NSDKmvsBpNHDKLxu6P3aSFBzRHiHcNXi0EO8JIK/XVa2ZiKu8v+Y03hbieJhmXwLqCUJE7YSJ47SlKYw4YYl4Ed0fYmaFtTKfq8c6MI+ziyepXL4X9AHBwFlgs95nKRYHeAscruwXZ1GfLrkzqdnppGq+W+VxmMXdxa7sWi7v06UlXsGfZxd9HemBiib3pFZxDyVU6SqA0XFxmFCblO7rNsiuT5LrOMZZ2PXDwybPkYF8M/wOrAxuHH/uW30R36X5D--N0APY7pCr5Quvg0+--jT6K103BvIqvpfllNATnjg== \ 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 2f2a626a90742e602bd66dc9ed48c75bc1ba995d Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Wed, 17 Oct 2018 16:50:40 -0700 Subject: [PATCH 002/192] rails scaffold user product order and review, model category --- .gitignore | 2 + app/assets/javascripts/orders.js | 2 + app/assets/javascripts/products.js | 2 + app/assets/javascripts/reviews.js | 2 + app/assets/javascripts/users.js | 2 + app/assets/stylesheets/orders.scss | 3 + app/assets/stylesheets/products.scss | 3 + app/assets/stylesheets/reviews.scss | 3 + app/assets/stylesheets/scaffolds.scss | 84 +++++++++++++++++++ app/assets/stylesheets/users.scss | 3 + app/controllers/orders_controller.rb | 74 ++++++++++++++++ app/controllers/products_controller.rb | 74 ++++++++++++++++ app/controllers/reviews_controller.rb | 74 ++++++++++++++++ app/controllers/users_controller.rb | 74 ++++++++++++++++ app/helpers/orders_helper.rb | 2 + app/helpers/products_helper.rb | 2 + app/helpers/reviews_helper.rb | 2 + app/helpers/users_helper.rb | 2 + app/models/category.rb | 2 + app/models/order.rb | 2 + app/models/product.rb | 2 + app/models/review.rb | 2 + app/models/user.rb | 2 + app/views/orders/_form.html.erb | 62 ++++++++++++++ app/views/orders/_order.json.jbuilder | 2 + app/views/orders/edit.html.erb | 6 ++ app/views/orders/index.html.erb | 43 ++++++++++ app/views/orders/index.json.jbuilder | 1 + app/views/orders/new.html.erb | 5 ++ app/views/orders/show.html.erb | 49 +++++++++++ app/views/orders/show.json.jbuilder | 1 + app/views/products/_form.html.erb | 42 ++++++++++ app/views/products/_product.json.jbuilder | 2 + app/views/products/edit.html.erb | 6 ++ app/views/products/index.html.erb | 35 ++++++++ app/views/products/index.json.jbuilder | 1 + app/views/products/new.html.erb | 5 ++ app/views/products/show.html.erb | 29 +++++++ app/views/products/show.json.jbuilder | 1 + app/views/reviews/_form.html.erb | 27 ++++++ app/views/reviews/_review.json.jbuilder | 2 + app/views/reviews/edit.html.erb | 6 ++ app/views/reviews/index.html.erb | 29 +++++++ app/views/reviews/index.json.jbuilder | 1 + app/views/reviews/new.html.erb | 5 ++ app/views/reviews/show.html.erb | 14 ++++ app/views/reviews/show.json.jbuilder | 1 + app/views/users/_form.html.erb | 32 +++++++ app/views/users/_user.json.jbuilder | 2 + app/views/users/edit.html.erb | 6 ++ app/views/users/index.html.erb | 31 +++++++ app/views/users/index.json.jbuilder | 1 + app/views/users/new.html.erb | 5 ++ app/views/users/show.html.erb | 19 +++++ app/views/users/show.json.jbuilder | 1 + config/routes.rb | 4 + db/migrate/20181017233257_create_users.rb | 11 +++ db/migrate/20181017233513_create_products.rb | 13 +++ db/migrate/20181017233535_create_orders.rb | 17 ++++ db/migrate/20181017233629_create_reviews.rb | 10 +++ .../20181017233954_create_categories.rb | 9 ++ ...7234540_create_categories_products_join.rb | 8 ++ db/schema.rb | 70 ++++++++++++++++ temp.txt | 12 +++ test/controllers/orders_controller_test.rb | 46 ++++++++++ test/controllers/products_controller_test.rb | 46 ++++++++++ test/controllers/reviews_controller_test.rb | 46 ++++++++++ test/controllers/users_controller_test.rb | 46 ++++++++++ test/fixtures/categories.yml | 7 ++ test/fixtures/orders.yml | 23 +++++ test/fixtures/products.yml | 15 ++++ test/fixtures/reviews.yml | 9 ++ test/fixtures/users.yml | 11 +++ test/models/category_test.rb | 9 ++ test/models/order_test.rb | 9 ++ test/models/product_test.rb | 9 ++ test/models/review_test.rb | 9 ++ test/models/user_test.rb | 9 ++ 78 files changed, 1340 insertions(+) create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/javascripts/products.js create mode 100644 app/assets/javascripts/reviews.js create mode 100644 app/assets/javascripts/users.js create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/assets/stylesheets/products.scss create mode 100644 app/assets/stylesheets/reviews.scss create mode 100644 app/assets/stylesheets/scaffolds.scss create mode 100644 app/assets/stylesheets/users.scss create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/controllers/products_controller.rb create mode 100644 app/controllers/reviews_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/helpers/reviews_helper.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/category.rb create mode 100644 app/models/order.rb create mode 100644 app/models/product.rb create mode 100644 app/models/review.rb create mode 100644 app/models/user.rb create mode 100644 app/views/orders/_form.html.erb create mode 100644 app/views/orders/_order.json.jbuilder create mode 100644 app/views/orders/edit.html.erb create mode 100644 app/views/orders/index.html.erb create mode 100644 app/views/orders/index.json.jbuilder create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/show.html.erb create mode 100644 app/views/orders/show.json.jbuilder create mode 100644 app/views/products/_form.html.erb create mode 100644 app/views/products/_product.json.jbuilder create mode 100644 app/views/products/edit.html.erb create mode 100644 app/views/products/index.html.erb create mode 100644 app/views/products/index.json.jbuilder create mode 100644 app/views/products/new.html.erb create mode 100644 app/views/products/show.html.erb create mode 100644 app/views/products/show.json.jbuilder create mode 100644 app/views/reviews/_form.html.erb create mode 100644 app/views/reviews/_review.json.jbuilder create mode 100644 app/views/reviews/edit.html.erb create mode 100644 app/views/reviews/index.html.erb create mode 100644 app/views/reviews/index.json.jbuilder create mode 100644 app/views/reviews/new.html.erb create mode 100644 app/views/reviews/show.html.erb create mode 100644 app/views/reviews/show.json.jbuilder create mode 100644 app/views/users/_form.html.erb create mode 100644 app/views/users/_user.json.jbuilder create mode 100644 app/views/users/edit.html.erb create mode 100644 app/views/users/index.html.erb create mode 100644 app/views/users/index.json.jbuilder create mode 100644 app/views/users/new.html.erb create mode 100644 app/views/users/show.html.erb create mode 100644 app/views/users/show.json.jbuilder create mode 100644 db/migrate/20181017233257_create_users.rb create mode 100644 db/migrate/20181017233513_create_products.rb create mode 100644 db/migrate/20181017233535_create_orders.rb create mode 100644 db/migrate/20181017233629_create_reviews.rb create mode 100644 db/migrate/20181017233954_create_categories.rb create mode 100644 db/migrate/20181017234540_create_categories_products_join.rb create mode 100644 db/schema.rb create mode 100644 temp.txt create mode 100644 test/controllers/orders_controller_test.rb create mode 100644 test/controllers/products_controller_test.rb create mode 100644 test/controllers/reviews_controller_test.rb create mode 100644 test/controllers/users_controller_test.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/fixtures/orders.yml create mode 100644 test/fixtures/products.yml create mode 100644 test/fixtures/reviews.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/category_test.rb create mode 100644 test/models/order_test.rb create mode 100644 test/models/product_test.rb create mode 100644 test/models/review_test.rb create mode 100644 test/models/user_test.rb diff --git a/.gitignore b/.gitignore index 18b43c9cd2..5f25c781d5 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ # Ignore master key for decrypting credentials and more. /config/master.key +.idea +.env 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/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/javascripts/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.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/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/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..3b0428a94e --- /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/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..89e2e8db07 --- /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/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000000..6045188032 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..1efc835ccd --- /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/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..3dbd0b994d --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,74 @@ +class OrdersController < ApplicationController + before_action :set_order, only: [:show, :edit, :update, :destroy] + + # GET /orders + # GET /orders.json + def index + @orders = Order.all + end + + # GET /orders/1 + # GET /orders/1.json + def show + end + + # GET /orders/new + def new + @order = Order.new + end + + # GET /orders/1/edit + def edit + end + + # POST /orders + # POST /orders.json + def create + @order = Order.new(order_params) + + respond_to do |format| + if @order.save + format.html { redirect_to @order, notice: 'Order was successfully created.' } + format.json { render :show, status: :created, location: @order } + else + format.html { render :new } + format.json { render json: @order.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /orders/1 + # PATCH/PUT /orders/1.json + def update + respond_to do |format| + if @order.update(order_params) + format.html { redirect_to @order, notice: 'Order was successfully updated.' } + format.json { render :show, status: :ok, location: @order } + else + format.html { render :edit } + format.json { render json: @order.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /orders/1 + # DELETE /orders/1.json + def destroy + @order.destroy + respond_to do |format| + format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_order + @order = Order.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def order_params + params.require(:order).permit(:status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip) + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..b63b4fbac6 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,74 @@ +class ProductsController < ApplicationController + before_action :set_product, only: [:show, :edit, :update, :destroy] + + # GET /products + # GET /products.json + def index + @products = Product.all + end + + # GET /products/1 + # GET /products/1.json + def show + end + + # GET /products/new + def new + @product = Product.new + end + + # GET /products/1/edit + def edit + end + + # POST /products + # POST /products.json + def create + @product = Product.new(product_params) + + respond_to do |format| + if @product.save + format.html { redirect_to @product, notice: 'Product was successfully created.' } + format.json { render :show, status: :created, location: @product } + else + format.html { render :new } + format.json { render json: @product.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /products/1 + # PATCH/PUT /products/1.json + def update + respond_to do |format| + if @product.update(product_params) + format.html { redirect_to @product, notice: 'Product was successfully updated.' } + format.json { render :show, status: :ok, location: @product } + else + format.html { render :edit } + format.json { render json: @product.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /products/1 + # DELETE /products/1.json + def destroy + @product.destroy + respond_to do |format| + format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_product + @product = Product.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def product_params + params.require(:product).permit(:category, :prod_name, :description, :price, :inv_qty) + end +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..3f705a5fe1 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,74 @@ +class ReviewsController < ApplicationController + before_action :set_review, only: [:show, :edit, :update, :destroy] + + # GET /reviews + # GET /reviews.json + def index + @reviews = Review.all + end + + # GET /reviews/1 + # GET /reviews/1.json + def show + end + + # GET /reviews/new + def new + @review = Review.new + end + + # GET /reviews/1/edit + def edit + end + + # POST /reviews + # POST /reviews.json + def create + @review = Review.new(review_params) + + respond_to do |format| + if @review.save + format.html { redirect_to @review, notice: 'Review was successfully created.' } + format.json { render :show, status: :created, location: @review } + else + format.html { render :new } + format.json { render json: @review.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /reviews/1 + # PATCH/PUT /reviews/1.json + def update + respond_to do |format| + if @review.update(review_params) + format.html { redirect_to @review, notice: 'Review was successfully updated.' } + format.json { render :show, status: :ok, location: @review } + else + format.html { render :edit } + format.json { render json: @review.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /reviews/1 + # DELETE /reviews/1.json + def destroy + @review.destroy + respond_to do |format| + format.html { redirect_to reviews_url, notice: 'Review was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_review + @review = Review.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def review_params + params.require(:review).permit(:rating, :description) + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..84de981537 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,74 @@ +class UsersController < ApplicationController + before_action :set_user, only: [:show, :edit, :update, :destroy] + + # GET /users + # GET /users.json + def index + @users = User.all + end + + # GET /users/1 + # GET /users/1.json + def show + end + + # GET /users/new + def new + @user = User.new + end + + # GET /users/1/edit + def edit + end + + # POST /users + # POST /users.json + def create + @user = User.new(user_params) + + respond_to do |format| + if @user.save + format.html { redirect_to @user, notice: 'User was successfully created.' } + format.json { render :show, status: :created, location: @user } + else + format.html { render :new } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /users/1 + # PATCH/PUT /users/1.json + def update + respond_to do |format| + if @user.update(user_params) + format.html { redirect_to @user, notice: 'User was successfully updated.' } + format.json { render :show, status: :ok, location: @user } + else + format.html { render :edit } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user.destroy + respond_to do |format| + format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_user + @user = User.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def user_params + params.require(:user).permit(:uid, :username, :email) + 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/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/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +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/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/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/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/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..b2ca4935ed --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,2 @@ +class Review < ApplicationRecord +end 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/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb new file mode 100644 index 0000000000..73b90ac643 --- /dev/null +++ b/app/views/orders/_form.html.erb @@ -0,0 +1,62 @@ +<%= form_with(model: order, local: true) do |form| %> + <% if order.errors.any? %> +
+

<%= pluralize(order.errors.count, "error") %> prohibited this order from being saved:

+ +
    + <% order.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :status %> + <%= form.text_field :status %> +
+ +
+ <%= form.label :cust_name %> + <%= form.text_field :cust_name %> +
+ +
+ <%= form.label :cust_email %> + <%= form.text_field :cust_email %> +
+ +
+ <%= form.label :mailing_address %> + <%= form.number_field :mailing_address %> +
+ +
+ <%= form.label :cc_name %> + <%= form.text_field :cc_name %> +
+ +
+ <%= form.label :cc_digit %> + <%= form.number_field :cc_digit %> +
+ +
+ <%= form.label :cc_expiration %> + <%= form.date_select :cc_expiration %> +
+ +
+ <%= form.label :cc_cvv %> + <%= form.number_field :cc_cvv %> +
+ +
+ <%= form.label :cc_zip %> + <%= form.number_field :cc_zip %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/orders/_order.json.jbuilder b/app/views/orders/_order.json.jbuilder new file mode 100644 index 0000000000..a835c48875 --- /dev/null +++ b/app/views/orders/_order.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! order, :id, :status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :created_at, :updated_at +json.url order_url(order, format: :json) diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000000..e23883cb10 --- /dev/null +++ b/app/views/orders/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Order

+ +<%= render 'form', order: @order %> + +<%= link_to 'Show', @order %> | +<%= link_to 'Back', orders_path %> diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000000..1812dcc922 --- /dev/null +++ b/app/views/orders/index.html.erb @@ -0,0 +1,43 @@ +

<%= notice %>

+ +

Orders

+ + + + + + + + + + + + + + + + + + + <% @orders.each do |order| %> + + + + + + + + + + + + + + + <% end %> + +
StatusCust nameCust emailMailing addressCc nameCc digitCc expirationCc cvvCc zip
<%= order.status %><%= order.cust_name %><%= order.cust_email %><%= order.mailing_address %><%= order.cc_name %><%= order.cc_digit %><%= order.cc_expiration %><%= order.cc_cvv %><%= order.cc_zip %><%= link_to 'Show', order %><%= link_to 'Edit', edit_order_path(order) %><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Order', new_order_path %> diff --git a/app/views/orders/index.json.jbuilder b/app/views/orders/index.json.jbuilder new file mode 100644 index 0000000000..9916098449 --- /dev/null +++ b/app/views/orders/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @orders, partial: 'orders/order', as: :order diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..d4e1de2d69 --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,5 @@ +

New Order

+ +<%= render 'form', order: @order %> + +<%= link_to 'Back', orders_path %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..169b3e9abb --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,49 @@ +

<%= notice %>

+ +

+ Status: + <%= @order.status %> +

+ +

+ Cust name: + <%= @order.cust_name %> +

+ +

+ Cust email: + <%= @order.cust_email %> +

+ +

+ Mailing address: + <%= @order.mailing_address %> +

+ +

+ Cc name: + <%= @order.cc_name %> +

+ +

+ Cc digit: + <%= @order.cc_digit %> +

+ +

+ Cc expiration: + <%= @order.cc_expiration %> +

+ +

+ Cc cvv: + <%= @order.cc_cvv %> +

+ +

+ Cc zip: + <%= @order.cc_zip %> +

+ +<%= link_to 'Edit', edit_order_path(@order) %> | +<%= link_to 'Back', orders_path %> diff --git a/app/views/orders/show.json.jbuilder b/app/views/orders/show.json.jbuilder new file mode 100644 index 0000000000..2ddef40c5d --- /dev/null +++ b/app/views/orders/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "orders/order", order: @order diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..d59de70c7b --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,42 @@ +<%= form_with(model: product, local: true) do |form| %> + <% if product.errors.any? %> +
+

<%= pluralize(product.errors.count, "error") %> prohibited this product from being saved:

+ +
    + <% product.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :category %> + <%= form.text_field :category %> +
+ +
+ <%= form.label :prod_name %> + <%= form.text_field :prod_name %> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description %> +
+ +
+ <%= form.label :price %> + <%= form.text_field :price %> +
+ +
+ <%= form.label :inv_qty %> + <%= form.number_field :inv_qty %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/products/_product.json.jbuilder b/app/views/products/_product.json.jbuilder new file mode 100644 index 0000000000..95125c7434 --- /dev/null +++ b/app/views/products/_product.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! product, :id, :category, :prod_name, :description, :price, :inv_qty, :created_at, :updated_at +json.url product_url(product, format: :json) diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..fc16e133a0 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Product

+ +<%= render 'form', product: @product %> + +<%= link_to 'Show', @product %> | +<%= link_to 'Back', products_path %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..117ba8e012 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,35 @@ +

<%= notice %>

+ +

Products

+ + + + + + + + + + + + + + + <% @products.each do |product| %> + + + + + + + + + + + <% end %> + +
CategoryProd nameDescriptionPriceInv qty
<%= product.category %><%= product.prod_name %><%= product.description %><%= product.price %><%= product.inv_qty %><%= link_to 'Show', product %><%= link_to 'Edit', edit_product_path(product) %><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Product', new_product_path %> diff --git a/app/views/products/index.json.jbuilder b/app/views/products/index.json.jbuilder new file mode 100644 index 0000000000..4eec33e096 --- /dev/null +++ b/app/views/products/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @products, partial: 'products/product', as: :product diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..a06963dc59 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,5 @@ +

New Product

+ +<%= render 'form', product: @product %> + +<%= link_to 'Back', products_path %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..f051a18ec5 --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

+ Category: + <%= @product.category %> +

+ +

+ Prod name: + <%= @product.prod_name %> +

+ +

+ Description: + <%= @product.description %> +

+ +

+ Price: + <%= @product.price %> +

+ +

+ Inv qty: + <%= @product.inv_qty %> +

+ +<%= link_to 'Edit', edit_product_path(@product) %> | +<%= link_to 'Back', products_path %> diff --git a/app/views/products/show.json.jbuilder b/app/views/products/show.json.jbuilder new file mode 100644 index 0000000000..03b16eccd7 --- /dev/null +++ b/app/views/products/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "products/product", product: @product diff --git a/app/views/reviews/_form.html.erb b/app/views/reviews/_form.html.erb new file mode 100644 index 0000000000..7630f8d8fa --- /dev/null +++ b/app/views/reviews/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: review, local: true) do |form| %> + <% if review.errors.any? %> +
+

<%= pluralize(review.errors.count, "error") %> prohibited this review from being saved:

+ +
    + <% review.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :rating %> + <%= form.number_field :rating %> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/reviews/_review.json.jbuilder b/app/views/reviews/_review.json.jbuilder new file mode 100644 index 0000000000..fa440c2fbd --- /dev/null +++ b/app/views/reviews/_review.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! review, :id, :rating, :description, :created_at, :updated_at +json.url review_url(review, format: :json) diff --git a/app/views/reviews/edit.html.erb b/app/views/reviews/edit.html.erb new file mode 100644 index 0000000000..285ef567de --- /dev/null +++ b/app/views/reviews/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Review

+ +<%= render 'form', review: @review %> + +<%= link_to 'Show', @review %> | +<%= link_to 'Back', reviews_path %> diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb new file mode 100644 index 0000000000..3f87e9c4d7 --- /dev/null +++ b/app/views/reviews/index.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

Reviews

+ + + + + + + + + + + + <% @reviews.each do |review| %> + + + + + + + + <% end %> + +
RatingDescription
<%= review.rating %><%= review.description %><%= link_to 'Show', review %><%= link_to 'Edit', edit_review_path(review) %><%= link_to 'Destroy', review, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Review', new_review_path %> diff --git a/app/views/reviews/index.json.jbuilder b/app/views/reviews/index.json.jbuilder new file mode 100644 index 0000000000..f7cfc190fd --- /dev/null +++ b/app/views/reviews/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @reviews, partial: 'reviews/review', as: :review diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..9015a5da1a --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,5 @@ +

New Review

+ +<%= render 'form', review: @review %> + +<%= link_to 'Back', reviews_path %> diff --git a/app/views/reviews/show.html.erb b/app/views/reviews/show.html.erb new file mode 100644 index 0000000000..89dfed02f7 --- /dev/null +++ b/app/views/reviews/show.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

+ Rating: + <%= @review.rating %> +

+ +

+ Description: + <%= @review.description %> +

+ +<%= link_to 'Edit', edit_review_path(@review) %> | +<%= link_to 'Back', reviews_path %> diff --git a/app/views/reviews/show.json.jbuilder b/app/views/reviews/show.json.jbuilder new file mode 100644 index 0000000000..20dd748bfd --- /dev/null +++ b/app/views/reviews/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "reviews/review", review: @review diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb new file mode 100644 index 0000000000..093f90a558 --- /dev/null +++ b/app/views/users/_form.html.erb @@ -0,0 +1,32 @@ +<%= form_with(model: user, local: true) do |form| %> + <% if user.errors.any? %> +
+

<%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:

+ +
    + <% user.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :uid %> + <%= form.number_field :uid %> +
+ +
+ <%= form.label :username %> + <%= form.text_field :username %> +
+ +
+ <%= form.label :email %> + <%= form.text_field :email %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder new file mode 100644 index 0000000000..7fe4c742cf --- /dev/null +++ b/app/views/users/_user.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! user, :id, :uid, :username, :email, :created_at, :updated_at +json.url user_url(user, format: :json) diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000000..1a5c2a64f0 --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,6 @@ +

Editing User

+ +<%= render 'form', user: @user %> + +<%= link_to 'Show', @user %> | +<%= link_to 'Back', users_path %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000000..6437cd103c --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,31 @@ +

<%= notice %>

+ +

Users

+ + + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + + <% end %> + +
UidUsernameEmail
<%= user.uid %><%= user.username %><%= user.email %><%= link_to 'Show', user %><%= link_to 'Edit', edit_user_path(user) %><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New User', new_user_path %> diff --git a/app/views/users/index.json.jbuilder b/app/views/users/index.json.jbuilder new file mode 100644 index 0000000000..2faf5af047 --- /dev/null +++ b/app/views/users/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @users, partial: 'users/user', as: :user diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000000..844c39b14d --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,5 @@ +

New User

+ +<%= render 'form', user: @user %> + +<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000000..5a447a43bf --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,19 @@ +

<%= notice %>

+ +

+ Uid: + <%= @user.uid %> +

+ +

+ Username: + <%= @user.username %> +

+ +

+ Email: + <%= @user.email %> +

+ +<%= link_to 'Edit', edit_user_path(@user) %> | +<%= link_to 'Back', users_path %> diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder new file mode 100644 index 0000000000..ff40bb9607 --- /dev/null +++ b/app/views/users/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "users/user", user: @user diff --git a/config/routes.rb b/config/routes.rb index 787824f888..2fe91f507d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,7 @@ Rails.application.routes.draw do + resources :reviews + resources :orders + resources :products + resources :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20181017233257_create_users.rb b/db/migrate/20181017233257_create_users.rb new file mode 100644 index 0000000000..ce7f9b7096 --- /dev/null +++ b/db/migrate/20181017233257_create_users.rb @@ -0,0 +1,11 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.integer :uid + t.string :username + t.string :email + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233513_create_products.rb b/db/migrate/20181017233513_create_products.rb new file mode 100644 index 0000000000..47529e527d --- /dev/null +++ b/db/migrate/20181017233513_create_products.rb @@ -0,0 +1,13 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.string :category + t.string :prod_name + t.string :description + t.float :price + t.integer :inv_qty + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233535_create_orders.rb b/db/migrate/20181017233535_create_orders.rb new file mode 100644 index 0000000000..71335debcf --- /dev/null +++ b/db/migrate/20181017233535_create_orders.rb @@ -0,0 +1,17 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :status + t.string :cust_name + t.string :cust_email + t.integer :mailing_address + t.string :cc_name + t.integer :cc_digit + t.date :cc_expiration + t.integer :cc_cvv + t.integer :cc_zip + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233629_create_reviews.rb b/db/migrate/20181017233629_create_reviews.rb new file mode 100644 index 0000000000..b3b1f0c445 --- /dev/null +++ b/db/migrate/20181017233629_create_reviews.rb @@ -0,0 +1,10 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.integer :rating + t.string :description + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233954_create_categories.rb b/db/migrate/20181017233954_create_categories.rb new file mode 100644 index 0000000000..6cfb9a0962 --- /dev/null +++ b/db/migrate/20181017233954_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + t.string :category + + t.timestamps + end + end +end diff --git a/db/migrate/20181017234540_create_categories_products_join.rb b/db/migrate/20181017234540_create_categories_products_join.rb new file mode 100644 index 0000000000..09fe47a944 --- /dev/null +++ b/db/migrate/20181017234540_create_categories_products_join.rb @@ -0,0 +1,8 @@ +class CreateCategoriesProductsJoin < ActiveRecord::Migration[5.2] + def change + create_table :categories_products do |t| + t.belongs_to :category, index: true + t.belongs_to :product, index: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..4cad43ef14 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,70 @@ +# 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: 2018_10_17_234540) 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 "category" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "categories_products", force: :cascade do |t| + t.bigint "category_id" + t.bigint "product_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.string "cust_name" + t.string "cust_email" + t.integer "mailing_address" + t.string "cc_name" + t.integer "cc_digit" + t.date "cc_expiration" + t.integer "cc_cvv" + t.integer "cc_zip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "products", force: :cascade do |t| + t.string "category" + t.string "prod_name" + t.string "description" + t.float "price" + t.integer "inv_qty" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "reviews", force: :cascade do |t| + t.integer "rating" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.integer "uid" + t.string "username" + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/temp.txt b/temp.txt new file mode 100644 index 0000000000..40ae76a92d --- /dev/null +++ b/temp.txt @@ -0,0 +1,12 @@ +rails generate scaffold user uid:integer username:string email:string + +rails generate scaffold product category:string prod_name:string description:string price:float inv_qty:integer + +rails generate scaffold order status:string cust_name:string cust_email:string mailing_address:integer cc_name:string cc_digit:integer cc_expiration:date cc_cvv:integer cc_zip:integer + +rails generate scaffold review rating:integer description:string + + +rails g migration CreateCategoriesProductsJoin + +rails db:migrate \ No newline at end of file diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..80c13241dc --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,46 @@ +require "test_helper" + +describe OrdersController do + let(:order) { orders :one } + + it "gets index" do + get orders_url + value(response).must_be :success? + end + + it "gets new" do + get new_order_url + value(response).must_be :success? + end + + it "creates order" do + expect { + post orders_url, params: { order: { cc_cvv: order.cc_cvv, cc_digit: order.cc_digit, cc_expiration: order.cc_expiration, cc_name: order.cc_name, cc_zip: order.cc_zip, cust_email: order.cust_email, cust_name: order.cust_name, mailing_address: order.mailing_address, status: order.status } } + }.must_change "Order.count" + + must_redirect_to order_path(Order.last) + end + + it "shows order" do + get order_url(order) + value(response).must_be :success? + end + + it "gets edit" do + get edit_order_url(order) + value(response).must_be :success? + end + + it "updates order" do + patch order_url(order), params: { order: { cc_cvv: order.cc_cvv, cc_digit: order.cc_digit, cc_expiration: order.cc_expiration, cc_name: order.cc_name, cc_zip: order.cc_zip, cust_email: order.cust_email, cust_name: order.cust_name, mailing_address: order.mailing_address, status: order.status } } + must_redirect_to order_path(order) + end + + it "destroys order" do + expect { + delete order_url(order) + }.must_change "Order.count", -1 + + must_redirect_to orders_path + end +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..22a2624cd2 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,46 @@ +require "test_helper" + +describe ProductsController do + let(:product) { products :one } + + it "gets index" do + get products_url + value(response).must_be :success? + end + + it "gets new" do + get new_product_url + value(response).must_be :success? + end + + it "creates product" do + expect { + post products_url, params: { product: { category: product.category, description: product.description, inv_qty: product.inv_qty, price: product.price, prod_name: product.prod_name } } + }.must_change "Product.count" + + must_redirect_to product_path(Product.last) + end + + it "shows product" do + get product_url(product) + value(response).must_be :success? + end + + it "gets edit" do + get edit_product_url(product) + value(response).must_be :success? + end + + it "updates product" do + patch product_url(product), params: { product: { category: product.category, description: product.description, inv_qty: product.inv_qty, price: product.price, prod_name: product.prod_name } } + must_redirect_to product_path(product) + end + + it "destroys product" do + expect { + delete product_url(product) + }.must_change "Product.count", -1 + + must_redirect_to products_path + end +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..3ef4e255d2 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,46 @@ +require "test_helper" + +describe ReviewsController do + let(:review) { reviews :one } + + it "gets index" do + get reviews_url + value(response).must_be :success? + end + + it "gets new" do + get new_review_url + value(response).must_be :success? + end + + it "creates review" do + expect { + post reviews_url, params: { review: { description: review.description, rating: review.rating } } + }.must_change "Review.count" + + must_redirect_to review_path(Review.last) + end + + it "shows review" do + get review_url(review) + value(response).must_be :success? + end + + it "gets edit" do + get edit_review_url(review) + value(response).must_be :success? + end + + it "updates review" do + patch review_url(review), params: { review: { description: review.description, rating: review.rating } } + must_redirect_to review_path(review) + end + + it "destroys review" do + expect { + delete review_url(review) + }.must_change "Review.count", -1 + + must_redirect_to reviews_path + end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..82ffc317fe --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,46 @@ +require "test_helper" + +describe UsersController do + let(:user) { users :one } + + it "gets index" do + get users_url + value(response).must_be :success? + end + + it "gets new" do + get new_user_url + value(response).must_be :success? + end + + it "creates user" do + expect { + post users_url, params: { user: { email: user.email, uid: user.uid, username: user.username } } + }.must_change "User.count" + + must_redirect_to user_path(User.last) + end + + it "shows user" do + get user_url(user) + value(response).must_be :success? + end + + it "gets edit" do + get edit_user_url(user) + value(response).must_be :success? + end + + it "updates user" do + patch user_url(user), params: { user: { email: user.email, uid: user.uid, username: user.username } } + must_redirect_to user_path(user) + end + + it "destroys user" do + expect { + delete user_url(user) + }.must_change "User.count", -1 + + must_redirect_to users_path + end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..b59cc5c7f5 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + category: MyString + +two: + category: MyString diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..f72bfa9e00 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,23 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + status: MyString + cust_name: MyString + cust_email: MyString + mailing_address: 1 + cc_name: MyString + cc_digit: 1 + cc_expiration: 2018-10-17 + cc_cvv: 1 + cc_zip: 1 + +two: + status: MyString + cust_name: MyString + cust_email: MyString + mailing_address: 1 + cc_name: MyString + cc_digit: 1 + cc_expiration: 2018-10-17 + cc_cvv: 1 + cc_zip: 1 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..ba5adc2dd4 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + category: MyString + prod_name: MyString + description: MyString + price: 1.5 + inv_qty: 1 + +two: + category: MyString + prod_name: MyString + description: MyString + price: 1.5 + inv_qty: 1 diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..41c2fd15d3 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + rating: 1 + description: MyString + +two: + rating: 1 + description: MyString diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..3710d0e0b2 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + uid: 1 + username: MyString + email: MyString + +two: + uid: 1 + username: MyString + email: 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 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 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 diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..ce8378a033 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Review do + let(:review) { Review.new } + + it "must be valid" do + value(review).must_be :valid? + end +end 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 db11c3135bee7d9c389f7a2f3eed54a860c0eae0 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 17 Oct 2018 17:53:52 -0700 Subject: [PATCH 003/192] product validations --- app/models/product.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/product.rb b/app/models/product.rb index 35a85acab3..a338ad0612 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,2 +1,5 @@ class Product < ApplicationRecord + validates :prod_name, presence: true, uniqueness: true + validates :prod_name, presence: true, numericality: { only_integer: true, greater_than: 0} + belongs_to :user end From fca1703530e18e9a9050a0cd684a3ebd0ed42f47 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 17 Oct 2018 17:56:16 -0700 Subject: [PATCH 004/192] missed the s in users - following chema --- app/models/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/product.rb b/app/models/product.rb index a338ad0612..130f3c647f 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,5 +1,5 @@ class Product < ApplicationRecord validates :prod_name, presence: true, uniqueness: true validates :prod_name, presence: true, numericality: { only_integer: true, greater_than: 0} - belongs_to :user + belongs_to :users end From a4ed675a9a80e2becbff9011be108df7ebff5baa Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 17 Oct 2018 17:57:52 -0700 Subject: [PATCH 005/192] validations for user --- app/models/user.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 379658a509..83fdffdefc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,4 @@ class User < ApplicationRecord + validates :username, presence: true, uniqueness: true + validates :email, presence: true, uniqueness: true end From 5b94dcf6e5f338d49206a1bb4197c696d2c20bc1 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 17 Oct 2018 18:02:30 -0700 Subject: [PATCH 006/192] and order has one to many products --- app/models/order.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/order.rb b/app/models/order.rb index 10281b3450..2afcf20c05 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,3 @@ class Order < ApplicationRecord + has_many :products end From 4022fe113a13363b79b8944113565f37c5bf69a0 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 17 Oct 2018 18:04:29 -0700 Subject: [PATCH 007/192] a rating must be greater than 1 and less than 5 --- app/models/review.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/review.rb b/app/models/review.rb index b2ca4935ed..673b85f321 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,2 +1,3 @@ class Review < ApplicationRecord + validates :rating, presence: true, numericality: { only_integer: true, greater_than: 1, less_than: 5} end From c9b2aa31af1ecf23981625018f0967660a122d4c Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Wed, 17 Oct 2018 20:47:15 -0700 Subject: [PATCH 008/192] json refs removed --- Gemfile | 10 ++++++++++ Gemfile.lock | 9 +++++++++ app/controllers/orders_controller.rb | 25 ++++++++++++------------- app/controllers/products_controller.rb | 11 +---------- app/controllers/reviews_controller.rb | 8 -------- app/controllers/users_controller.rb | 6 ------ app/views/users/_user.json.jbuilder | 2 -- app/views/users/index.json.jbuilder | 1 - app/views/users/show.json.jbuilder | 1 - db/generate_seeds.rb | 26 ++++++++++++++++++++++++++ db/products_seeds.csv | 0 11 files changed, 58 insertions(+), 41 deletions(-) delete mode 100644 app/views/users/_user.json.jbuilder delete mode 100644 app/views/users/index.json.jbuilder delete mode 100644 app/views/users/show.json.jbuilder create mode 100644 db/generate_seeds.rb create mode 100644 db/products_seeds.csv diff --git a/Gemfile b/Gemfile index 6219256bd8..e51e0df11b 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,13 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'mini_racer', platforms: :ruby +# + +# Bakesy added gems +gem 'faker' + + + # Use CoffeeScript for .coffee assets and views # gem 'coffee-rails', '~> 4.2' @@ -56,6 +63,9 @@ group :test do gem 'selenium-webdriver' # Easy installation and use of chromedriver to run system tests with Chrome gem 'chromedriver-helper' + + # Bakesy installed test gems + gem 'factory_bot_rails' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 90a29ea433..b380092f61 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,13 @@ GEM debug_inspector (0.0.3) erubi (1.7.1) execjs (2.7.0) + factory_bot (4.11.1) + activesupport (>= 3.0.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) + railties (>= 3.0.0) + faker (1.9.1) + i18n (>= 0.7) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -249,6 +256,8 @@ DEPENDENCIES byebug capybara (>= 2.15) chromedriver-helper + factory_bot_rails + faker guard guard-minitest jbuilder (~> 2.5) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 3dbd0b994d..c292c1ee76 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -2,13 +2,11 @@ class OrdersController < ApplicationController before_action :set_order, only: [:show, :edit, :update, :destroy] # GET /orders - # GET /orders.json def index @orders = Order.all end # GET /orders/1 - # GET /orders/1.json def show end @@ -22,42 +20,43 @@ def edit end # POST /orders - # POST /orders.json def create @order = Order.new(order_params) - respond_to do |format| if @order.save - format.html { redirect_to @order, notice: 'Order was successfully created.' } - format.json { render :show, status: :created, location: @order } + flash[:success] = 'Order was successfully created.' + redirect_to order_path(@order.id) + else - format.html { render :new } - format.json { render json: @order.errors, status: :unprocessable_entity } + flash.now[:warning] = 'Order not created' + @order.errors.messages.each do |field, msg| + flash.now[field] = messages + end + render :new end end end # PATCH/PUT /orders/1 - # PATCH/PUT /orders/1.json def update respond_to do |format| if @order.update(order_params) format.html { redirect_to @order, notice: 'Order was successfully updated.' } - format.json { render :show, status: :ok, location: @order } + else format.html { render :edit } - format.json { render json: @order.errors, status: :unprocessable_entity } + end end end # DELETE /orders/1 - # DELETE /orders/1.json + def destroy @order.destroy respond_to do |format| format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } - format.json { head :no_content } + end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index b63b4fbac6..1f0e3bbffe 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -2,13 +2,12 @@ class ProductsController < ApplicationController before_action :set_product, only: [:show, :edit, :update, :destroy] # GET /products - # GET /products.json def index @products = Product.all end # GET /products/1 - # GET /products/1.json + def show end @@ -22,42 +21,34 @@ def edit end # POST /products - # POST /products.json def create @product = Product.new(product_params) respond_to do |format| if @product.save format.html { redirect_to @product, notice: 'Product was successfully created.' } - format.json { render :show, status: :created, location: @product } else format.html { render :new } - format.json { render json: @product.errors, status: :unprocessable_entity } end end end # PATCH/PUT /products/1 - # PATCH/PUT /products/1.json def update respond_to do |format| if @product.update(product_params) format.html { redirect_to @product, notice: 'Product was successfully updated.' } - format.json { render :show, status: :ok, location: @product } else format.html { render :edit } - format.json { render json: @product.errors, status: :unprocessable_entity } end end end # DELETE /products/1 - # DELETE /products/1.json def destroy @product.destroy respond_to do |format| format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } - format.json { head :no_content } end end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 3f705a5fe1..1702496a6b 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -2,13 +2,11 @@ class ReviewsController < ApplicationController before_action :set_review, only: [:show, :edit, :update, :destroy] # GET /reviews - # GET /reviews.json def index @reviews = Review.all end # GET /reviews/1 - # GET /reviews/1.json def show end @@ -22,17 +20,14 @@ def edit end # POST /reviews - # POST /reviews.json def create @review = Review.new(review_params) respond_to do |format| if @review.save format.html { redirect_to @review, notice: 'Review was successfully created.' } - format.json { render :show, status: :created, location: @review } else format.html { render :new } - format.json { render json: @review.errors, status: :unprocessable_entity } end end end @@ -43,10 +38,8 @@ def update respond_to do |format| if @review.update(review_params) format.html { redirect_to @review, notice: 'Review was successfully updated.' } - format.json { render :show, status: :ok, location: @review } else format.html { render :edit } - format.json { render json: @review.errors, status: :unprocessable_entity } end end end @@ -57,7 +50,6 @@ def destroy @review.destroy respond_to do |format| format.html { redirect_to reviews_url, notice: 'Review was successfully destroyed.' } - format.json { head :no_content } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 84de981537..8c9eb329b6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,13 +2,11 @@ class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] # GET /users - # GET /users.json def index @users = User.all end # GET /users/1 - # GET /users/1.json def show end @@ -22,7 +20,6 @@ def edit end # POST /users - # POST /users.json def create @user = User.new(user_params) @@ -38,7 +35,6 @@ def create end # PATCH/PUT /users/1 - # PATCH/PUT /users/1.json def update respond_to do |format| if @user.update(user_params) @@ -52,12 +48,10 @@ def update end # DELETE /users/1 - # DELETE /users/1.json def destroy @user.destroy respond_to do |format| format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } - format.json { head :no_content } end end diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder deleted file mode 100644 index 7fe4c742cf..0000000000 --- a/app/views/users/_user.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.extract! user, :id, :uid, :username, :email, :created_at, :updated_at -json.url user_url(user, format: :json) diff --git a/app/views/users/index.json.jbuilder b/app/views/users/index.json.jbuilder deleted file mode 100644 index 2faf5af047..0000000000 --- a/app/views/users/index.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.array! @users, partial: 'users/user', as: :user diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder deleted file mode 100644 index ff40bb9607..0000000000 --- a/app/views/users/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "users/user", user: @user diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb new file mode 100644 index 0000000000..3f971dbbf6 --- /dev/null +++ b/db/generate_seeds.rb @@ -0,0 +1,26 @@ +require 'faker' +require 'date' +require 'csv' + +# feel free to +# run this script in order to replace it and generate a new one +# run using the command: +# $ ruby db/generate_seeds.rb +# if satisfied with this new media_seeds.csv file, recreate the db with: +# $ rails db:reset +# doesn't currently check for if titles are unique against each other + +CSV.open('db/products_seeds.csv', "w", :write_headers=> true, + :headers => ["category", "prod_name", "description", "price", "inv_qty"]) do |csv| + + 25.times do + category = %w(birthday wedding chocolate vanilla buttercream).sample + prod_name = Faker::Dessert.variety + Faker::Dessert.topping + Faker::Dessert.flavor + description = Faker::Coffee.notes + price = Faker::Number.decimal(2, 2) + inv_qty = Faker::Number.between(0, 30) + + csv << [category, prod_name, description, price, inv_qty] + end +end + diff --git a/db/products_seeds.csv b/db/products_seeds.csv new file mode 100644 index 0000000000..e69de29bb2 From 72e35aaec77aba7dcb5b8243a308d7355210bafe Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 17 Oct 2018 21:19:59 -0700 Subject: [PATCH 009/192] psuedocode custom methods for product, user, order models --- app/models/order.rb | 25 +++++++++++++++++++++++++ app/models/product.rb | 12 ++++++++++++ app/models/user.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/app/models/order.rb b/app/models/order.rb index 10281b3450..687b3c526d 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,27 @@ class Order < ApplicationRecord + + + + + + def total_price + # self.products.each multiply price by qty + + # sum + + # apply tax? + + # return total + + end + + def place_order + # self.products.each decrease inventory + # find qty in OrdersProducts by order_id & product_id + + # self.order = "paid" + + # clears current cart () + + end end diff --git a/app/models/product.rb b/app/models/product.rb index 35a85acab3..e03a8afafa 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,2 +1,14 @@ class Product < ApplicationRecord + + + + + + def avg_rating + # sum = sum up self.reviews + + # num = self.reviews.length + + # return sum / num + end end diff --git a/app/models/user.rb b/app/models/user.rb index 379658a509..db29c42dbf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,34 @@ class User < ApplicationRecord + + + + + + def net_revenue + # Order.all where order.products each have merchant_id == self.id + + # sum up orders + + # return net_revenue + + end + + def total_revenue(status) + # self.net_revenue where Order.status == status + + end + + def total_orders + # Order.all where order.products each have merchant_id == self.id + + # count up orders + + # return count + end + + def num_orders(status) + # self.total_orders where Order.status == status + end + + end From 5c8d96983af393adc9c57d90fd873bfffb975d7d Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Wed, 17 Oct 2018 22:21:44 -0700 Subject: [PATCH 010/192] created seed file generator.rb and seed files for products orders and reviews --- .DS_Store | Bin 0 -> 6148 bytes Gemfile | 7 +++++-- Gemfile.lock | 11 ++++++++--- db/generate_seeds.rb | 40 +++++++++++++++++++++++++++++++++++++--- db/order_seeds.csv | 11 +++++++++++ db/product_seeds.csv | 31 +++++++++++++++++++++++++++++++ db/products_seeds.csv | 0 db/review_seeds.csv | 11 +++++++++++ test/test_helper.rb | 10 +++++++++- 9 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 .DS_Store create mode 100644 db/order_seeds.csv create mode 100644 db/product_seeds.csv delete mode 100644 db/products_seeds.csv create mode 100644 db/review_seeds.csv diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..380ad3887f52be96eeef8b471abe2a5fb1326501 GIT binary patch literal 6148 zcmeH~u?oUK42F~HP;lw!c#99<8yuxRfiECZaFGgv&iCm4$z`!ROOZd2e3x89+kfaa zBBK3c+>3M~(!!0hvoJG7-pDBD=kY#WZ_@?2)y$d-&r$1SwjbLB6`%rCfC^9nDzG30 z;v8=`3wkC#3KgIN%TU0+4+(C}!BXj;4g?jDS;a)h^^03>!4Z{cp(PqqMauvDS~= 1.3.0' # gem 'mini_racer', platforms: :ruby # -# Bakesy added gems -gem 'faker' + @@ -46,6 +45,8 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + + gem 'faker', git: 'https://github.com/stympy/faker' end group :development do @@ -55,6 +56,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' + end group :test do @@ -74,6 +76,7 @@ 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 diff --git a/Gemfile.lock b/Gemfile.lock index b380092f61..12e522aa1a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/stympy/faker + revision: 069817eb06825b10f8e74f83ef2c50a001b72d96 + specs: + faker (1.9.1) + i18n (>= 0.7) + GEM remote: https://rubygems.org/ specs: @@ -88,8 +95,6 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faker (1.9.1) - i18n (>= 0.7) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -257,7 +262,7 @@ DEPENDENCIES capybara (>= 2.15) chromedriver-helper factory_bot_rails - faker + faker! guard guard-minitest jbuilder (~> 2.5) diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb index 3f971dbbf6..61b79bacaf 100644 --- a/db/generate_seeds.rb +++ b/db/generate_seeds.rb @@ -1,3 +1,4 @@ + require 'faker' require 'date' require 'csv' @@ -10,12 +11,12 @@ # $ rails db:reset # doesn't currently check for if titles are unique against each other -CSV.open('db/products_seeds.csv', "w", :write_headers=> true, +CSV.open('db/product_seeds.csv', "w", :write_headers=> true, :headers => ["category", "prod_name", "description", "price", "inv_qty"]) do |csv| - 25.times do + 30.times do category = %w(birthday wedding chocolate vanilla buttercream).sample - prod_name = Faker::Dessert.variety + Faker::Dessert.topping + Faker::Dessert.flavor + prod_name = Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor description = Faker::Coffee.notes price = Faker::Number.decimal(2, 2) inv_qty = Faker::Number.between(0, 30) @@ -24,3 +25,36 @@ end end + +CSV.open('db/review_seeds.csv', "w", :write_headers=> true, + :headers => ["rating", "description"]) do |csv| + + 10.times do + rating = Faker::Number.between(1, 5) + description = ["Tasted like ", "Deliciously flavored ", "Oddly it smelled like "].sample + Faker::Coffee.notes + + csv << [rating, description] + end +end + + +CSV.open('db/order_seeds.csv', "w", :write_headers=> true, + :headers => ["status", "cust_name", "cust_email", "mailing_address", + "cc_name", "cc_digit", "cc_expiration", "cc_cvv", + "cc_zip"]) do |csv| + + 10.times do + status = %w(pending paid complete cancelled).sample + cust_name = Faker::RuPaul.queen + cust_email = Faker::Internet.safe_email + mailing_address = Faker::Address.full_address + cc_name = Faker::FunnyName.two_word_name + cc_digit = Faker::Finance.credit_card + cc_expiration = Faker::Business.credit_card_expiry_date + cc_cvv = Faker::Number.number(3) + cc_zip = Faker::Number.number(5) + + csv << [status, cust_name, cust_email, mailing_address, cc_name, cc_digit, cc_expiration, cc_cvv, cc_zip] + end +end + diff --git a/db/order_seeds.csv b/db/order_seeds.csv new file mode 100644 index 0000000000..b6b6d976da --- /dev/null +++ b/db/order_seeds.csv @@ -0,0 +1,11 @@ +status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip +cancelled,Mimi Imfurst,keren@example.com,"910 Donnelly Plaza, Lake Donny, LA 76231-1944",Missy Sippy,3682-737873-0109,2022-10-16,195,61612 +pending,Morgan McMichaels,leonore@example.com,"91039 Kirlin Grove, Lake Aleidaside, NC 83287-5526",Otto Carr,6771-8988-2922-2828,2019-10-17,232,41487 +paid,Sharon Needles,ethyl@example.org,"591 Hagenes Bridge, Dickensland, MN 11885",Nida Lyte,6759-9611-2192-9288,2021-10-16,357,49306 +paid,Peppermint,nohemi@example.net,"Apt. 893 257 Wuckert Villages, Sawaynmouth, KY 00116",Justin Thyme,5019-8705-9583-9485,2019-10-17,131,58421 +paid,Tatianna,blaine.huel@example.net,"Suite 732 4230 Bradtke Club, Port Rodneyhaven, MN 78814",Rocky Shore,6771-8947-0306-0269,2020-10-16,306,66953 +cancelled,Tyra Sanchez,edgar@example.net,"Suite 463 5785 Gislason Port, New Kylefort, SD 51965-0066",Owen Big,5019-1686-8367-5774,2022-10-16,276,50800 +complete,Jiggly Caliente,mireille.fay@example.org,"Suite 479 3801 Lon Terrace, Mahaliaville, TX 96183-7295",Bart Ender,3011-197451-9661,2022-10-16,495,51195 +paid,Bianca Del Rio,patricia@example.com,"199 Willis Drive, New Amiraburgh, MT 22929-0978",Sue Yu,6759-4902-8505-8029-87,2021-10-16,241,61894 +pending,Kenya Michaels,lida@example.com,"Apt. 550 90130 Tula Rest, New Marcos, FL 51936",Mike Czech,6542-9716-5710-8605,2020-10-16,811,63748 +cancelled,Tatianna,elbert@example.org,"Apt. 100 732 Schumm Mall, Boehmfort, MA 09876-7672",Evan Keel,6767-3572-7623-7934,2022-10-16,699,96687 diff --git a/db/product_seeds.csv b/db/product_seeds.csv new file mode 100644 index 0000000000..357c2aa13f --- /dev/null +++ b/db/product_seeds.csv @@ -0,0 +1,31 @@ +category,prod_name,description,price,inv_qty +birthday,Upside Down Pineapple Cake Peanuts Banana,"pointed, watery, barley, cherry, white pepper",88.62,1 +chocolate,Frozen Yogurt Berry Compote French Vanilla,"complex, full, mango, black currant, black cherry",36.46,27 +buttercream,Sundae Glaze Red Velvet,"juicy, slick, bakers chocolate, soil, snow pea",57.67,10 +wedding,Key Lime Pie Chocolate Sprinkles Chocolate Chip Cookie Dough,"dry, silky, ginger, cocoa powder, passion fruit",51.81,7 +buttercream,Brownie Butterscotch Syrup Rocky Road,"complex, watery, papaya, mango, graham cracker",88.19,20 +buttercream,Pudding Chocolate Syrup Red Velvet,"soft, syrupy, peach, meyer lemon, nutmeg",76.01,14 +buttercream,Trifle Cheesecake Bites Blondie,"wild, silky, maple syrup, cashew, mango",41.72,30 +wedding,Cake Pop Bacon Oatmeal,"mild, velvety, meyer lemon, lemonade, sweet pea",42.66,19 +vanilla,Cake Pop Chocolate Sprinkles Apple,"dull, silky, pineapple, nectarine, fresh wood",34.86,19 +buttercream,Cobbler Whipped Cream Butterscotch,"dense, syrupy, mango, dates, butter",70.22,18 +chocolate,Cake Cookie Dough Oatmeal,"tart, juicy, hazelnut, kiwi, kiwi",39.05,30 +birthday,Sweet Bread Caramel Butterscotch,"delicate, tea-like, musty, sage, clove",59.23,28 +vanilla,Fruit Cake Chocolate Syrup Apple,"crisp, syrupy, granola, snow pea, curry",73.23,22 +chocolate,Ice Cream Cake Peanut Butter Banana,"quick, round, carmel, fresh wood, cranberry",45.42,20 +birthday,Cake Chocolate Chips Pumpkin,"astringent, round, cream, graham cracker, tobacco",29.75,1 +wedding,Cupcake Granola Funfetti,"astringent, silky, raspberry, mango, cantaloupe",93.03,14 +vanilla,Frozen Yogurt Caramel Butterscotch,"complex, velvety, maple syrup, pineapple, cocoa powder",58.87,25 +buttercream,Pudding Chocolate Syrup Peanut Butter,"dirty, round, tobacco, ginger, curry",47.39,17 +buttercream,Sweet Bread Glaze Coconut,"faint, round, mango, mango, leafy greens",85.94,3 +buttercream,Parfait Granola Butterscotch,"complex, big, butter, cream, bittersweet chocolate",72.19,10 +vanilla,Sweet Bread Chocolate Sprinkles Chocolate Chip Cookie Dough,"deep, full, orange, nutella, concord grape",40.17,28 +vanilla,Brownie Caramel Espresso,"structured, silky, hops, rubber, raspberry",19.26,0 +birthday,Ice Cream Gummy Bears Oatmeal,"soft, syrupy, rose hips, blueberry, vanilla",10.66,6 +chocolate,Upside Down Pineapple Cake Caramel Rocky Road,"deep, smooth, green pepper, clove, leathery",96.82,11 +birthday,Sundae Granola Caramel,"dirty, round, orange creamsicle, meyer lemon, lemon verbena",88.94,24 +vanilla,Parfait Bacon Blondie,"pointed, creamy, nutmeg, walnut, corriander",63.12,0 +chocolate,Cobbler Marshmallows Banana,"mild, tea-like, passion fruit, walnut, potato defect!",95.57,26 +chocolate,Pie Bacon Mint Chocolate Chip,"astringent, watery, musty, mushroom, peanut",19.44,5 +buttercream,Cheesecake Chocolate Syrup French Vanilla,"complex, smooth, hops, cola, sundried tomato",60.83,9 +birthday,Cupcake Cinnamon Apple,"mild, watery, lemonade, maple syrup, white pepper",77.82,5 diff --git a/db/products_seeds.csv b/db/products_seeds.csv deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/db/review_seeds.csv b/db/review_seeds.csv new file mode 100644 index 0000000000..720ee4fb9c --- /dev/null +++ b/db/review_seeds.csv @@ -0,0 +1,11 @@ +rating,description +4,"Tasted like dry, slick, coconut, hay, mango" +3,"Tasted like delicate, silky, hops, orange, tobacco" +3,"Tasted like lingering, slick, blueberry, carbon, fresh bread" +4,"Deliciously flavored deep, tea-like, fresh wood, kiwi, sweet pea" +3,"Oddly it smelled like wild, tea-like, honeydew, apricot, almond" +5,"Oddly it smelled like dull, watery, marshmallow, marshmallow, honeydew" +4,"Tasted like structured, syrupy, squash, lemon verbena, smokey" +4,"Tasted like muted, slick, ginger, lychee, leathery" +3,"Tasted like dense, syrupy, lychee, magnolia, cola" +2,"Oddly it smelled like sharp, creamy, cacao nibs, mint, fresh bread" diff --git a/test/test_helper.rb b/test/test_helper.rb index 2b5172a7d6..7a253b59ea 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,10 @@ ENV["RAILS_ENV"] = "test" 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 +require 'faker' + # For colorful output! Minitest::Reporters.use!( Minitest::Reporters::SpecReporter.new, @@ -22,3 +25,8 @@ class ActiveSupport::TestCase fixtures :all # Add more helper methods to be used by all tests here... end + +class ActiveSupport::TestCase + include FactoryBot::Syntax::Methods +end + From 0682add601dba121f9dca9ffe545af58404231fd Mon Sep 17 00:00:00 2001 From: Jazz Date: Wed, 17 Oct 2018 22:52:45 -0700 Subject: [PATCH 011/192] added styling to forms --- app/assets/stylesheets/application.scss | 18 ++++ app/assets/stylesheets/products.scss | 129 ++++++++++++++++++++++++ app/views/layouts/application.html.erb | 35 +++++++ app/views/orders/_form.html.erb | 54 +++++----- app/views/products/_form.html.erb | 24 +++-- app/views/products/index.html.erb | 39 +++++++ app/views/reviews/_form.html.erb | 12 +-- 7 files changed, 267 insertions(+), 44 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8b1701e581..c15396e640 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,3 +16,21 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; + +body { + padding-bottom: 20px; +} + +.navbar { + margin-bottom: 20px; +} + +.fa-github-square { + font-size: 3em; + color: white; +} + + +.right { + padding-right: 10px; +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 89e2e8db07..cfab7e0731 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -1,3 +1,132 @@ // 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/ +// +// Base styles +// + +.product-grid3{font-family:Roboto,sans-serif;text-align:center;position:relative;z-index:1} +.product-grid3:before{content:"";height:81%;width:100%;background:#fff;border:1px solid rgba(0,0,0,.1);opacity:0;position:absolute;top:0;left:0;z-index:-1;transition:all .5s ease 0s} +.product-grid3:hover:before{opacity:1;height:100%} +.product-grid3 .product-image3{position:relative} +.product-grid3 .product-image3 a{display:block} +.product-grid3 .product-image3 img{width:100%;height:auto} +.product-grid3 .pic-1{opacity:1;transition:all .5s ease-out 0s} +.product-grid3:hover .pic-1{opacity:0} +.product-grid3 .pic-2{position:absolute;top:0;left:0;opacity:0;transition:all .5s ease-out 0s} +.product-grid3:hover .pic-2{opacity:1} +.product-grid3 .social{width:120px;padding:0;margin:0 auto;list-style:none;opacity:0;position:absolute;right:0;left:0;bottom:-23px;transform:scale(0);transition:all .3s ease 0s} +.product-grid3:hover .social{opacity:1;transform:scale(1)} +.product-grid3:hover .product-discount-label,.product-grid3:hover .product-new-label,.product-grid3:hover .title{opacity:0} +.product-grid3 .social li{display:inline-block} +.product-grid3 .social li a{color:#e67e22;background:#fff;font-size:18px;line-height:50px;width:50px;height:50px;border:1px solid rgba(0,0,0,.1);border-radius:50%;margin:0 2px;display:block;transition:all .3s ease 0s} +.product-grid3 .social li a:hover{background:#e67e22;color:#fff} +.product-grid3 .product-discount-label,.product-grid3 .product-new-label{background-color:#e67e22;color:#fff;font-size:17px;padding:2px 10px;position:absolute;right:10px;top:10px;transition:all .3s} +.product-grid3 .product-content{z-index:-1;padding:15px;text-align:left} +.product-grid3 .title{font-size:14px;text-transform:capitalize;margin:0 0 7px;transition:all .3s ease 0s} +.product-grid3 .title a{color:#414141} +.product-grid3 .price{color:#000;font-size:16px;letter-spacing:1px;font-weight:600;margin-right:2px;display:inline-block} +.product-grid3 .price span{color:#909090;font-size:14px;font-weight:500;letter-spacing:0;text-decoration:line-through;text-align:left;display:inline-block;margin-top:-2px} +.product-grid3 .rating{padding:0;margin:-22px 0 0;list-style:none;text-align:right;display:block} +.product-grid3 .rating li{color:#ffd200;font-size:13px;display:inline-block} +.product-grid3 .rating li.disable{color:#dcdcdc} +@media only screen and (max-width:1200px){.product-grid3 .rating{margin:0} +} +@media only screen and (max-width:990px){.product-grid3{margin-bottom:30px} +.product-grid3 .rating{margin:-22px 0 0} +} +@media only screen and (max-width:359px){.product-grid3 .rating{margin:0} +} + + +/* GLOBAL STYLES +-------------------------------------------------- */ +/* Padding below the footer and lighter body text */ +/*homepage for products +body { + padding-top: 3rem; + padding-bottom: 3rem; + color: #5a5a5a; +} + + +/* CUSTOMIZE THE CAROUSEL +-------------------------------------------------- */ + +/* Carousel base class */ +.carousel { + margin-bottom: 4rem; +} +/* Since positioning the image, we need to help out the caption */ +.carousel-caption { + bottom: 3rem; + z-index: 10; +} + +/* Declare heights because of positioning of img element */ +.carousel-item { + height: 32rem; + background-color: #777; +} +.carousel-item > img { + position: absolute; + top: 0; + left: 0; + min-width: 100%; + height: 32rem; +} + + +/* MARKETING CONTENT +-------------------------------------------------- */ + +/* Center align the text within the three columns below the carousel */ +.marketing .col-lg-4 { + margin-bottom: 1.5rem; + text-align: center; +} +.marketing h2 { + font-weight: 400; +} +.marketing .col-lg-4 p { + margin-right: .75rem; + margin-left: .75rem; +} + + +/* Featurettes +------------------------- */ + +.featurette-divider { + margin: 5rem 0; /* Space out the Bootstrap
more */ +} + +/* Thin out the marketing headings */ +.featurette-heading { + font-weight: 300; + line-height: 1; + letter-spacing: -.05rem; +} + + +/* RESPONSIVE CSS +-------------------------------------------------- */ + +@media (min-width: 40em) { + /* Bump up size of carousel content */ + .carousel-caption p { + margin-bottom: 1.25rem; + font-size: 1.25rem; + line-height: 1.4; + } + + .featurette-heading { + font-size: 50px; + } +} + +@media (min-width: 62em) { + .featurette-heading { + margin-top: 7rem; + } +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f18f1b6820..b0521bcc28 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,8 +7,43 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + <%= yield %> diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 73b90ac643..2834459c88 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -11,52 +11,52 @@ <% end %> -
+
<%= form.label :status %> - <%= form.text_field :status %> + <%= form.text_field :status, class: "form-control" %>
-
- <%= form.label :cust_name %> - <%= form.text_field :cust_name %> +
+ <%= form.label "Name" %> + <%= form.text_field :cust_name, class: "form-control" %>
-
- <%= form.label :cust_email %> - <%= form.text_field :cust_email %> +
+ <%= form.label "Email" %> + <%= form.text_field :cust_email, class: "form-control" %>
-
+
<%= form.label :mailing_address %> - <%= form.number_field :mailing_address %> + <%= form.number_field :mailing_address, class: "form-control" %>
-
- <%= form.label :cc_name %> - <%= form.text_field :cc_name %> +
+ <%= form.label "Name on Card" %> + <%= form.text_field :cc_name, class: "form-control" %>
-
- <%= form.label :cc_digit %> - <%= form.number_field :cc_digit %> +
+ <%= form.label "Credit Card Number" %> + <%= form.number_field :cc_digit, class: "form-control" %>
-
- <%= form.label :cc_expiration %> - <%= form.date_select :cc_expiration %> +
+ <%= form.label "Expiration Date" %> + <%= form.date_select :cc_expiration, class: "form-control" %>
-
- <%= form.label :cc_cvv %> - <%= form.number_field :cc_cvv %> +
+ <%= form.label "CVV" %> + <%= form.number_field :cc_cvv, class: "form-control" %>
-
- <%= form.label :cc_zip %> - <%= form.number_field :cc_zip %> +
+ <%= form.label "Zip Code" %> + <%= form.number_field :cc_zip, class: "form-control" %>
-
- <%= form.submit %> +
+ <%= form.submit class: "btn btn-primary" %>
<% end %> diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index d59de70c7b..6a178af807 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -11,32 +11,34 @@
<% end %> -
+
<%= form.label :category %> - <%= form.text_field :category %> + <%= form.text_field :category, class: "form-control" %> + <%#= form.select :category, class: "form-control" {}, ["Special Occassion", "Custom Order]" %> +
-
+
<%= form.label :prod_name %> - <%= form.text_field :prod_name %> + <%= form.text_field :prod_name, class: "form-control"%>
-
+
<%= form.label :description %> - <%= form.text_field :description %> + <%= form.text_field :description, class: "form-control"%>
-
+
<%= form.label :price %> - <%= form.text_field :price %> + <%= form.text_field :price, class: "form-control"%>
-
+
<%= form.label :inv_qty %> - <%= form.number_field :inv_qty %> + <%= form.number_field :inv_qty, class: "form-control"%>
- <%= form.submit %> + <%= form.submit class: "btn btn-primary" %>
<% end %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 117ba8e012..aa487255cc 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -33,3 +33,42 @@
<%= link_to 'New Product', new_product_path %> + +<% @products.each do |product| %> +
+

Products

+
+
+
+
+ + + + + + New +
+
+

<%= product.prod_name %>

+
+ <%= product.price %> + <%= product.inv_qty %> +
+
    +
  • +
  • +
  • +
  • +
  • +
+ <% end %> +
+
+
+
+
+
diff --git a/app/views/reviews/_form.html.erb b/app/views/reviews/_form.html.erb index 7630f8d8fa..0933cb7a3f 100644 --- a/app/views/reviews/_form.html.erb +++ b/app/views/reviews/_form.html.erb @@ -11,17 +11,17 @@
<% end %> -
+
<%= form.label :rating %> - <%= form.number_field :rating %> + <%= form.number_field :rating, class: "form-control" %>
-
+
<%= form.label :description %> - <%= form.text_field :description %> + <%= form.text_field :description, class: "form-control" %>
-
- <%= form.submit %> +
+ <%= form.submit class: "btn btn-primary"%>
<% end %> From 5a036ecac2ef1cbeb2ae71860a07a0a41db97859 Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 00:00:40 -0700 Subject: [PATCH 012/192] added home page links --- app/assets/stylesheets/application.scss | 17 ++++- app/assets/stylesheets/products.scss | 4 +- app/views/layouts/application.html.erb | 6 +- app/views/products/home.html.erb | 83 +++++++++++++++++++++++++ config/routes.rb | 3 + 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 app/views/products/home.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c15396e640..36177cc485 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,6 +19,7 @@ body { padding-bottom: 20px; + margin-bottom: 60px; } .navbar { @@ -26,11 +27,23 @@ body { } .fa-github-square { - font-size: 3em; + font-size: 2em; + color: lightgrey; +} + +.fa-github-square:hover { color: white; } +.fa-sign-in-alt { + font-size: 2em; + color: lightgrey; +} + +.fa-sign-in-alt:hover { + color: white; +} .right { - padding-right: 10px; + padding-right: 13px; } diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index cfab7e0731..4fa8ead22b 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -42,7 +42,7 @@ /* GLOBAL STYLES -------------------------------------------------- */ /* Padding below the footer and lighter body text */ -/*homepage for products +/*homepage for products body { padding-top: 3rem; padding-bottom: 3rem; @@ -85,7 +85,7 @@ body { margin-bottom: 1.5rem; text-align: center; } -.marketing h2 { +.marketing h4 { font-weight: 400; } .marketing .col-lg-4 p { diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b0521bcc28..9273eb1df9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,7 +19,7 @@ @@ -47,4 +47,6 @@ <%= yield %> + + diff --git a/app/views/products/home.html.erb b/app/views/products/home.html.erb new file mode 100644 index 0000000000..1bad7c5db8 --- /dev/null +++ b/app/views/products/home.html.erb @@ -0,0 +1,83 @@ +
+ + + + + + + +
+ + +
+
+ Generic placeholder image +

Vanilla, "I Vote Cupcake"

+

Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.

+

View details »

+
+
+ Generic placeholder image +

Pumpkin Cardamom

+

Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.

+

View details »

+
+
+ Generic placeholder image +

Fig & Honey

+

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

+

View details »

+
+
+ + +
+ + diff --git a/config/routes.rb b/config/routes.rb index 2fe91f507d..7822b759c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + + root 'products#home' + resources :reviews resources :orders resources :products From 3fe715e7d5460c01405cea6bec858eec299be44a Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 09:47:59 -0700 Subject: [PATCH 013/192] minor edit on user --- app/views/users/_form.html.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 093f90a558..14d148098a 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -11,22 +11,22 @@
<% end %> -
+
<%= form.label :uid %> - <%= form.number_field :uid %> + <%= form.number_field :uid, class: "form-control" %>
-
+
<%= form.label :username %> - <%= form.text_field :username %> + <%= form.text_field :username, class: "form-control" %>
-
+
<%= form.label :email %> - <%= form.text_field :email %> + <%= form.text_field :email, class: "form-control" %>
-
- <%= form.submit %> +
+ <%= form.submit class: "btn btn-primary" %>
<% end %> From 3b8042166ec3a7ebed6e0a16cb2dc1799a202d5f Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 18 Oct 2018 11:02:52 -0700 Subject: [PATCH 014/192] fixed seed_generator --- .gitignore | 2 ++ db/generate_seeds.rb | 6 ++++-- .../20181018174629_add_active_image_fields_to_product.rb | 6 ++++++ db/schema.rb | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181018174629_add_active_image_fields_to_product.rb diff --git a/.gitignore b/.gitignore index 5f25c781d5..e1cd8d6140 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ /config/master.key .idea .env +/coverage +.DS_Store diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb index 61b79bacaf..c1df81ac4c 100644 --- a/db/generate_seeds.rb +++ b/db/generate_seeds.rb @@ -12,7 +12,7 @@ # doesn't currently check for if titles are unique against each other CSV.open('db/product_seeds.csv', "w", :write_headers=> true, - :headers => ["category", "prod_name", "description", "price", "inv_qty"]) do |csv| + :headers => ["category", "prod_name", "description", "price", "inv_qty", "active", "image"]) do |csv| 30.times do category = %w(birthday wedding chocolate vanilla buttercream).sample @@ -20,8 +20,10 @@ description = Faker::Coffee.notes price = Faker::Number.decimal(2, 2) inv_qty = Faker::Number.between(0, 30) + active = Faker::Boolean.boolean + image = Faker::LoremPixel.image("50x60", false, 'food') - csv << [category, prod_name, description, price, inv_qty] + csv << [category, prod_name, description, price, inv_qty, active, image] end end diff --git a/db/migrate/20181018174629_add_active_image_fields_to_product.rb b/db/migrate/20181018174629_add_active_image_fields_to_product.rb new file mode 100644 index 0000000000..d40a6b8492 --- /dev/null +++ b/db/migrate/20181018174629_add_active_image_fields_to_product.rb @@ -0,0 +1,6 @@ +class AddActiveImageFieldsToProduct < ActiveRecord::Migration[5.2] + def change + add_column :products, :image, :string + add_column :products, :active, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4cad43ef14..5d417e2579 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_17_234540) do +ActiveRecord::Schema.define(version: 2018_10_18_174629) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -50,6 +50,8 @@ t.integer "inv_qty" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "image" + t.boolean "active", default: true end create_table "reviews", force: :cascade do |t| From 11b8dcc4354c9feafb9a09a36235bb09294fcde7 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 18 Oct 2018 11:04:15 -0700 Subject: [PATCH 015/192] generate seeds --- db/order_seeds.csv | 20 +++++++------- db/product_seeds.csv | 62 ++++++++++++++++++++++---------------------- db/review_seeds.csv | 20 +++++++------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/db/order_seeds.csv b/db/order_seeds.csv index b6b6d976da..c722dd04ec 100644 --- a/db/order_seeds.csv +++ b/db/order_seeds.csv @@ -1,11 +1,11 @@ status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip -cancelled,Mimi Imfurst,keren@example.com,"910 Donnelly Plaza, Lake Donny, LA 76231-1944",Missy Sippy,3682-737873-0109,2022-10-16,195,61612 -pending,Morgan McMichaels,leonore@example.com,"91039 Kirlin Grove, Lake Aleidaside, NC 83287-5526",Otto Carr,6771-8988-2922-2828,2019-10-17,232,41487 -paid,Sharon Needles,ethyl@example.org,"591 Hagenes Bridge, Dickensland, MN 11885",Nida Lyte,6759-9611-2192-9288,2021-10-16,357,49306 -paid,Peppermint,nohemi@example.net,"Apt. 893 257 Wuckert Villages, Sawaynmouth, KY 00116",Justin Thyme,5019-8705-9583-9485,2019-10-17,131,58421 -paid,Tatianna,blaine.huel@example.net,"Suite 732 4230 Bradtke Club, Port Rodneyhaven, MN 78814",Rocky Shore,6771-8947-0306-0269,2020-10-16,306,66953 -cancelled,Tyra Sanchez,edgar@example.net,"Suite 463 5785 Gislason Port, New Kylefort, SD 51965-0066",Owen Big,5019-1686-8367-5774,2022-10-16,276,50800 -complete,Jiggly Caliente,mireille.fay@example.org,"Suite 479 3801 Lon Terrace, Mahaliaville, TX 96183-7295",Bart Ender,3011-197451-9661,2022-10-16,495,51195 -paid,Bianca Del Rio,patricia@example.com,"199 Willis Drive, New Amiraburgh, MT 22929-0978",Sue Yu,6759-4902-8505-8029-87,2021-10-16,241,61894 -pending,Kenya Michaels,lida@example.com,"Apt. 550 90130 Tula Rest, New Marcos, FL 51936",Mike Czech,6542-9716-5710-8605,2020-10-16,811,63748 -cancelled,Tatianna,elbert@example.org,"Apt. 100 732 Schumm Mall, Boehmfort, MA 09876-7672",Evan Keel,6767-3572-7623-7934,2022-10-16,699,96687 +pending,Jujubee,jeie@example.com,"Apt. 877 77845 Medhurst Field, West Claudiofurt, DE 31531",Tina See,3008-507303-8056,2020-10-17,829,17663 +complete,Alexis Mateo,ali.koelpin@example.net,"Suite 242 2202 Arnoldo Trace, Bayershire, OR 01892-0307",Helen Highwater,5019-8802-3565-7940,2022-10-17,800,42569 +paid,Raven,elliott_koepp@example.com,"970 Wintheiser Lights, Port Meganstad, FL 02978",Emma Royds,6759-1236-2510-3777-16,2020-10-17,721,21243 +complete,Detox,broderick.kshlerin@example.org,"Suite 544 1395 Langosh Cliffs, Ricechester, CO 34158-2143",Adam Zapel,5019-7154-3494-6316,2022-10-17,911,12769 +paid,Naomi Smalls,lucien@example.com,"5530 Tromp Glens, Morissettestad, SC 23008",Jerry Atrics,6592-6207-3238-5746-3249,2020-10-17,875,47435 +cancelled,Chad Michaels,jee@example.com,"Suite 445 2804 Gibson Motorway, East Rudolf, SD 99825-7189",Sal Minella,575512778804525,2021-10-17,102,29099 +pending,Alexis Mateo,brandon.ward@example.net,"Apt. 873 96231 Kendra Junction, East Halfurt, HI 56794-8059",Hy Marx,6007-2284-8253-5306,2021-10-17,776,43846 +complete,Violet Chachki,yajaira.schimmel@example.net,"5517 Jacobi Stream, Clydeside, PA 81594-0046",Ilene Left,6007-2233-4178-2199,2020-10-17,497,93629 +cancelled,Violet Chachki,guy_johnson@example.net,"4830 Fernando Forks, Berneicehaven, MA 69689-4175",Don Key,5012425796817686,2019-10-18,535,36242 +pending,Adore Delano,rodger.stroman@example.net,"Suite 605 5429 Hills Wall, Lucienneberg, CA 25884-4712",Gus Tofwin,6007-2290-8336-7131,2022-10-17,214,40838 diff --git a/db/product_seeds.csv b/db/product_seeds.csv index 357c2aa13f..97aa7ec11f 100644 --- a/db/product_seeds.csv +++ b/db/product_seeds.csv @@ -1,31 +1,31 @@ -category,prod_name,description,price,inv_qty -birthday,Upside Down Pineapple Cake Peanuts Banana,"pointed, watery, barley, cherry, white pepper",88.62,1 -chocolate,Frozen Yogurt Berry Compote French Vanilla,"complex, full, mango, black currant, black cherry",36.46,27 -buttercream,Sundae Glaze Red Velvet,"juicy, slick, bakers chocolate, soil, snow pea",57.67,10 -wedding,Key Lime Pie Chocolate Sprinkles Chocolate Chip Cookie Dough,"dry, silky, ginger, cocoa powder, passion fruit",51.81,7 -buttercream,Brownie Butterscotch Syrup Rocky Road,"complex, watery, papaya, mango, graham cracker",88.19,20 -buttercream,Pudding Chocolate Syrup Red Velvet,"soft, syrupy, peach, meyer lemon, nutmeg",76.01,14 -buttercream,Trifle Cheesecake Bites Blondie,"wild, silky, maple syrup, cashew, mango",41.72,30 -wedding,Cake Pop Bacon Oatmeal,"mild, velvety, meyer lemon, lemonade, sweet pea",42.66,19 -vanilla,Cake Pop Chocolate Sprinkles Apple,"dull, silky, pineapple, nectarine, fresh wood",34.86,19 -buttercream,Cobbler Whipped Cream Butterscotch,"dense, syrupy, mango, dates, butter",70.22,18 -chocolate,Cake Cookie Dough Oatmeal,"tart, juicy, hazelnut, kiwi, kiwi",39.05,30 -birthday,Sweet Bread Caramel Butterscotch,"delicate, tea-like, musty, sage, clove",59.23,28 -vanilla,Fruit Cake Chocolate Syrup Apple,"crisp, syrupy, granola, snow pea, curry",73.23,22 -chocolate,Ice Cream Cake Peanut Butter Banana,"quick, round, carmel, fresh wood, cranberry",45.42,20 -birthday,Cake Chocolate Chips Pumpkin,"astringent, round, cream, graham cracker, tobacco",29.75,1 -wedding,Cupcake Granola Funfetti,"astringent, silky, raspberry, mango, cantaloupe",93.03,14 -vanilla,Frozen Yogurt Caramel Butterscotch,"complex, velvety, maple syrup, pineapple, cocoa powder",58.87,25 -buttercream,Pudding Chocolate Syrup Peanut Butter,"dirty, round, tobacco, ginger, curry",47.39,17 -buttercream,Sweet Bread Glaze Coconut,"faint, round, mango, mango, leafy greens",85.94,3 -buttercream,Parfait Granola Butterscotch,"complex, big, butter, cream, bittersweet chocolate",72.19,10 -vanilla,Sweet Bread Chocolate Sprinkles Chocolate Chip Cookie Dough,"deep, full, orange, nutella, concord grape",40.17,28 -vanilla,Brownie Caramel Espresso,"structured, silky, hops, rubber, raspberry",19.26,0 -birthday,Ice Cream Gummy Bears Oatmeal,"soft, syrupy, rose hips, blueberry, vanilla",10.66,6 -chocolate,Upside Down Pineapple Cake Caramel Rocky Road,"deep, smooth, green pepper, clove, leathery",96.82,11 -birthday,Sundae Granola Caramel,"dirty, round, orange creamsicle, meyer lemon, lemon verbena",88.94,24 -vanilla,Parfait Bacon Blondie,"pointed, creamy, nutmeg, walnut, corriander",63.12,0 -chocolate,Cobbler Marshmallows Banana,"mild, tea-like, passion fruit, walnut, potato defect!",95.57,26 -chocolate,Pie Bacon Mint Chocolate Chip,"astringent, watery, musty, mushroom, peanut",19.44,5 -buttercream,Cheesecake Chocolate Syrup French Vanilla,"complex, smooth, hops, cola, sundried tomato",60.83,9 -birthday,Cupcake Cinnamon Apple,"mild, watery, lemonade, maple syrup, white pepper",77.82,5 +category,prod_name,description,price,inv_qty,active,image +buttercream,Cookie Toffee Bits Almond,"complex, slick, lemongrass, smokey, watermelon",43.57,0,true,https://lorempixel.com/50/60/food +buttercream,Doughnut Gummy Bears Mint Chocolate Chip,"quick, velvety, hay, mandarin, coconut",81.33,5,true,https://lorempixel.com/50/60/food +wedding,Upside Down Pineapple Cake Frosting Red Velvet,"mild, silky, butter, lychee, leafy greens",77.14,1,true,https://lorempixel.com/50/60/food +vanilla,Trifle Powdered Sugar Vanilla,"complex, big, carmel, watermelon, potato defect!",73.02,27,false,https://lorempixel.com/50/60/food +vanilla,Doughnut Bacon Cherry,"deep, syrupy, pecan, soy sauce, banana",34.88,29,true,https://lorempixel.com/50/60/food +wedding,Doughnut Whipped Cream Cherry,"unbalanced, chewy, leafy greens, raisin, green apple",30.44,29,false,https://lorempixel.com/50/60/food +chocolate,Cake Frosting Butter Pecan,"dense, big, mandarin, carbon, white grape",46.14,30,true,https://lorempixel.com/50/60/food +vanilla,Cobbler Granola Chocolate Chip Cookie Dough,"unbalanced, full, honeydew, toast, clementine",67.49,22,true,https://lorempixel.com/50/60/food +wedding,Cake Chocolate Syrup Red Velvet,"clean, velvety, cacao nibs, hay, lemon",35.27,21,true,https://lorempixel.com/50/60/food +wedding,Frozen Yogurt Butterscotch Syrup Blondie,"juicy, big, tomato, barley, bergamot",59.86,4,true,https://lorempixel.com/50/60/food +wedding,Pie Cinnamon Cheesecake,"clean, smooth, potato defect!, cola, carmel",72.07,22,true,https://lorempixel.com/50/60/food +birthday,Cupcake Whipped Cream Apple,"pointed, silky, carbon, blueberry, banana",90.76,21,true,https://lorempixel.com/50/60/food +chocolate,Key Lime Pie Berry Compote Oatmeal,"unbalanced, creamy, graham cracker, bittersweet chocolate, brown sugar",26.28,18,true,https://lorempixel.com/50/60/food +birthday,Key Lime Pie Cookie Dough Strawberry,"complex, big, marshmallow, fresh bread, lime",27.37,27,false,https://lorempixel.com/50/60/food +buttercream,Sweet Bread Chocolate Sprinkles Vanilla,"dry, tea-like, rubber, milk chocolate, fresh wood",74.26,23,false,https://lorempixel.com/50/60/food +vanilla,Pie Chocolate Sprinkles Caramel,"clean, velvety, sage, tomato, squash",55.03,4,true,https://lorempixel.com/50/60/food +vanilla,Pudding Butterscotch Syrup Espresso,"dirty, watery, grassy, potato defect!, musty",46.93,11,true,https://lorempixel.com/50/60/food +vanilla,Parfait Peanuts Peanut Butter,"pointed, tea-like, mango, cedar, jasmine",61.43,6,false,https://lorempixel.com/50/60/food +birthday,Coffee Cake Chocolate Syrup Mint Chocolate Chip,"sharp, tea-like, lemongrass, dates, coconut",21.51,4,true,https://lorempixel.com/50/60/food +buttercream,Upside Down Pineapple Cake Toffee Bits Pistachio,"faint, round, clementine, nutmeg, medicinal",34.96,28,true,https://lorempixel.com/50/60/food +birthday,Doughnut Chocolate Syrup Mint Chocolate Chip,"unbalanced, smooth, quakery, butter, cacao nibs",26.61,0,true,https://lorempixel.com/50/60/food +wedding,Cake Chocolate Syrup Apple,"vibrant, chewy, rye, milk chocolate, smokey",18.21,22,true,https://lorempixel.com/50/60/food +vanilla,Ice Cream Walnuts Apple,"soft, syrupy, fresh bread, honeydew, cashew",39.06,26,false,https://lorempixel.com/50/60/food +birthday,Cheesecake Rainbow Sprinkles Cookies 'n Cream,"soft, creamy, bittersweet chocolate, tomato, vanilla",13.66,9,true,https://lorempixel.com/50/60/food +vanilla,Pie Rainbow Sprinkles Almond,"dirty, round, honey, graham cracker, medicinal",77.43,23,false,https://lorempixel.com/50/60/food +wedding,Parfait Chocolate Sprinkles Neapolitan,"dull, smooth, sweet pea, lemonade, vanilla",62.62,6,false,https://lorempixel.com/50/60/food +chocolate,Cheesecake Peanuts Salted Caramel,"crisp, creamy, white pepper, granola, clementine",66.31,27,false,https://lorempixel.com/50/60/food +birthday,Cheesecake Frosting Rocky Road,"lingering, tea-like, liquorice, cinnamon, cocoa powder",44.35,28,false,https://lorempixel.com/50/60/food +vanilla,Fruit Cake Caramel Funfetti,"rounded, big, apricot, sweet pea, kiwi",65.43,29,false,https://lorempixel.com/50/60/food +birthday,Cheesecake Chocolate Sprinkles Pistachio,"juicy, silky, lemon, granola, green apple",74.98,11,true,https://lorempixel.com/50/60/food diff --git a/db/review_seeds.csv b/db/review_seeds.csv index 720ee4fb9c..0f7dba601d 100644 --- a/db/review_seeds.csv +++ b/db/review_seeds.csv @@ -1,11 +1,11 @@ rating,description -4,"Tasted like dry, slick, coconut, hay, mango" -3,"Tasted like delicate, silky, hops, orange, tobacco" -3,"Tasted like lingering, slick, blueberry, carbon, fresh bread" -4,"Deliciously flavored deep, tea-like, fresh wood, kiwi, sweet pea" -3,"Oddly it smelled like wild, tea-like, honeydew, apricot, almond" -5,"Oddly it smelled like dull, watery, marshmallow, marshmallow, honeydew" -4,"Tasted like structured, syrupy, squash, lemon verbena, smokey" -4,"Tasted like muted, slick, ginger, lychee, leathery" -3,"Tasted like dense, syrupy, lychee, magnolia, cola" -2,"Oddly it smelled like sharp, creamy, cacao nibs, mint, fresh bread" +2,"Tasted like complex, full, hibiscus, plum, coconut" +1,"Tasted like delicate, full, lemonade, sugar cane, milk chocolate" +5,"Oddly it smelled like balanced, chewy, cacao nibs, cocoa powder, leafy greens" +4,"Deliciously flavored crisp, creamy, watermelon, brown sugar, peanut" +2,"Deliciously flavored tart, silky, butter, white pepper, brown sugar" +3,"Oddly it smelled like bright, watery, rose hips, raspberry, green pepper" +5,"Tasted like quick, round, bakers chocolate, meyer lemon, bakers chocolate" +1,"Deliciously flavored mild, creamy, sugar cane, banana, nougat" +3,"Oddly it smelled like soft, creamy, rubber, nutmeg, golden raisin" +2,"Oddly it smelled like tart, creamy, meyer lemon, lemongrass, figs" From 5974f83e1a9da4adb2ec6c123cbc6d692bca7ddc Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 11:08:04 -0700 Subject: [PATCH 016/192] added seed data --- app/views/orders/_form.html.erb | 2 + db/seeds.rb | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 2834459c88..3146efc248 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -60,3 +60,5 @@ <%= form.submit class: "btn btn-primary" %>
<% end %> + + diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2accd..5ca28ae5d2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,74 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +require 'csv' + +ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') +puts "Loading raw driver data from #{ORDER_FILE}" + +order_failures = [] +CSV.foreach(ORDER_FILE, :headers => true) do |row| + order = Order.new + order.status = row['status'] + order.cust_name = row['cust_name'] + order.cust_email = row['cust_email'] + order.mailing_address = row['mailing_address'] + order.cc_name = row['cc_name'] + order.cc_digit = row['cc_digit'] + order.cc_expiration = row['cc_expiration'] + order.cc_cvv = row['cc_cvv'] + order.cc_zip = row['cc_zip'] + successful = order.save + if !successful + order_failures << order + puts "Failed to save order: #{order.inspect}" + else + puts "Created order: #{order.inspect}" + end +end + +puts "Added #{Order.count} order records" +puts "#{order_failures.length} order failed to save" + +PRODUCT_FILE = Rails.root.join('db', 'product_seeds.csv') +puts "Loading raw driver data from #{PRODUCT_FILE}" + +product_failures = [] +CSV.foreach(PRODUCT_FILE, :headers => true) do |row| + product = Product.new + product.category = row['category'] + product.prod_name = row['prod_name'] + product.description = row['description'] + product.price = row['price'] + product.inv_qty = row['inv_qty'] + successful = product.save + if !successful + product_failures << product + puts "Failed to save product: #{product.inspect}" + else + puts "Created product: #{product.inspect}" + end +end + +puts "Added #{Product.count} product records" +puts "#{product_failures.length} product failed to save" + +REVIEW_FILE = Rails.root.join('db', 'review_seeds.csv') +puts "Loading raw driver data from #{REVIEW_FILE}" + +product_failures = [] +CSV.foreach(REVIEW_FILE, :headers => true) do |row| + review = Review.new + review.rating = row['rating'] + review.description = row['description'] + successful = review.save + if !successful + review_failures << review + puts "Failed to save review: #{review.inspect}" + else + puts "Created review: #{review.inspect}" + end +end + +puts "Added #{Review.count} review records" +puts "#{review_failures.length} review failed to save" From 77f97e5a58e26876fb47a361458796ab81d05b58 Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 11:47:47 -0700 Subject: [PATCH 017/192] added seed file --- db/order_seeds.csv | 6 +++--- db/seeds.rb | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/db/order_seeds.csv b/db/order_seeds.csv index c722dd04ec..f6a10f85b8 100644 --- a/db/order_seeds.csv +++ b/db/order_seeds.csv @@ -3,9 +3,9 @@ pending,Jujubee,jeie@example.com,"Apt. 877 77845 Medhurst Field, West Claudiofur complete,Alexis Mateo,ali.koelpin@example.net,"Suite 242 2202 Arnoldo Trace, Bayershire, OR 01892-0307",Helen Highwater,5019-8802-3565-7940,2022-10-17,800,42569 paid,Raven,elliott_koepp@example.com,"970 Wintheiser Lights, Port Meganstad, FL 02978",Emma Royds,6759-1236-2510-3777-16,2020-10-17,721,21243 complete,Detox,broderick.kshlerin@example.org,"Suite 544 1395 Langosh Cliffs, Ricechester, CO 34158-2143",Adam Zapel,5019-7154-3494-6316,2022-10-17,911,12769 -paid,Naomi Smalls,lucien@example.com,"5530 Tromp Glens, Morissettestad, SC 23008",Jerry Atrics,6592-6207-3238-5746-3249,2020-10-17,875,47435 -cancelled,Chad Michaels,jee@example.com,"Suite 445 2804 Gibson Motorway, East Rudolf, SD 99825-7189",Sal Minella,575512778804525,2021-10-17,102,29099 +paid,Naomi Smalls,lucien@example.com,"5530 Tromp Glens, Morissettestad, SC 23008",Jerry Atrics,6592-6207-3238-5746,2020-10-17,875,47435 +cancelled,Chad Michaels,jee@example.com,"Suite 445 2804 Gibson Motorway, East Rudolf, SD 99825-7189",Sal Minella,5755-1277-8800-4525,2021-10-17,102,29099 pending,Alexis Mateo,brandon.ward@example.net,"Apt. 873 96231 Kendra Junction, East Halfurt, HI 56794-8059",Hy Marx,6007-2284-8253-5306,2021-10-17,776,43846 complete,Violet Chachki,yajaira.schimmel@example.net,"5517 Jacobi Stream, Clydeside, PA 81594-0046",Ilene Left,6007-2233-4178-2199,2020-10-17,497,93629 -cancelled,Violet Chachki,guy_johnson@example.net,"4830 Fernando Forks, Berneicehaven, MA 69689-4175",Don Key,5012425796817686,2019-10-18,535,36242 +cancelled,Violet Chachki,guy_johnson@example.net,"4830 Fernando Forks, Berneicehaven, MA 69689-4175",Don Key,5012-4257-9681-7686,2019-10-18,535,36242 pending,Adore Delano,rodger.stroman@example.net,"Suite 605 5429 Hills Wall, Lucienneberg, CA 25884-4712",Gus Tofwin,6007-2290-8336-7131,2022-10-17,214,40838 diff --git a/db/seeds.rb b/db/seeds.rb index 5ca28ae5d2..e2357ac241 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,7 +8,7 @@ require 'csv' ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') -puts "Loading raw driver data from #{ORDER_FILE}" +puts "Loading raw order data from #{ORDER_FILE}" order_failures = [] CSV.foreach(ORDER_FILE, :headers => true) do |row| @@ -34,8 +34,10 @@ puts "Added #{Order.count} order records" puts "#{order_failures.length} order failed to save" + + PRODUCT_FILE = Rails.root.join('db', 'product_seeds.csv') -puts "Loading raw driver data from #{PRODUCT_FILE}" +puts "Loading raw review data from #{PRODUCT_FILE}" product_failures = [] CSV.foreach(PRODUCT_FILE, :headers => true) do |row| @@ -45,6 +47,8 @@ product.description = row['description'] product.price = row['price'] product.inv_qty = row['inv_qty'] + product.active = row['active'] + product.image = row['image'] successful = product.save if !successful product_failures << product @@ -57,10 +61,10 @@ puts "Added #{Product.count} product records" puts "#{product_failures.length} product failed to save" -REVIEW_FILE = Rails.root.join('db', 'review_seeds.csv') -puts "Loading raw driver data from #{REVIEW_FILE}" +REVIEW_FILE = Rails.root.join('db','review_seeds.csv') +puts "Loading raw review data from #{REVIEW_FILE}" -product_failures = [] +review_failures = [] CSV.foreach(REVIEW_FILE, :headers => true) do |row| review = Review.new review.rating = row['rating'] From 8ba1767fa615af6be1599b6cd9f23a4fd63ab45f Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 12:29:48 -0700 Subject: [PATCH 018/192] Omni files set up --- Gemfile | 6 +++-- Gemfile.lock | 30 ++++++++++++++++++++- app/views/layouts/application.html.erb | 2 +- app/views/products/index.html.erb | 36 ++------------------------ config/initializers/omniauth.rb | 3 +++ 5 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 config/initializers/omniauth.rb diff --git a/Gemfile b/Gemfile index c660214a20..d9a8e1154e 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,8 @@ gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'mini_racer', platforms: :ruby # - +gem "omniauth" +gem "omniauth-github" @@ -45,8 +46,9 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] - + gem 'faker', git: 'https://github.com/stympy/faker' + gem 'dotenv-rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 12e522aa1a..1b84abb182 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -88,6 +88,10 @@ 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) factory_bot (4.11.1) @@ -95,6 +99,8 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) + faraday (0.15.3) + multipart-post (>= 1.2, < 3) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -112,6 +118,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) @@ -125,6 +132,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) @@ -152,6 +160,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) @@ -159,6 +169,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) @@ -261,6 +286,7 @@ DEPENDENCIES byebug capybara (>= 2.15) chromedriver-helper + dotenv-rails factory_bot_rails faker! guard @@ -271,6 +297,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) @@ -288,4 +316,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.3 + 1.16.5 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9273eb1df9..a77d078ac3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -37,7 +37,7 @@ diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index aa487255cc..542a4b7617 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,38 +1,6 @@

<%= notice %>

-

Products

- - - - - - - - - - - - - - <% @products.each do |product| %> - - - - - - - - - - - <% end %> - -
CategoryProd nameDescriptionPriceInv qty
<%= product.category %><%= product.prod_name %><%= product.description %><%= product.price %><%= product.inv_qty %><%= link_to 'Show', product %><%= link_to 'Edit', edit_product_path(product) %><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Product', new_product_path %> <% @products.each do |product| %>
@@ -41,8 +9,8 @@
- - + + - <% end %>
+ +<% end %> +
+ + +
diff --git a/test/factories/order.rb b/test/factories/order.rb new file mode 100644 index 0000000000..dd38697f9c --- /dev/null +++ b/test/factories/order.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + factory :order do + status { %w(pending paid complete cancelled).sample} + cust_name { Faker::RuPaul.queen} + cust_email { Faker::Internet.safe_email} + mailing_address { Faker::Address.full_address} + cc_name { Faker::FunnyName.two_word_name} + cc_digit { Faker::Finance.credit_card.number(16)} + cc_expiration { Faker::Business.credit_card_expiry_date} + cc_cvv { Faker::Number.number(3)} + cc_zip { Faker::Number.number(5) } + end +end diff --git a/test/factories/product.rb b/test/factories/product.rb new file mode 100644 index 0000000000..9cd139cd85 --- /dev/null +++ b/test/factories/product.rb @@ -0,0 +1,11 @@ +FactoryBot.define do + factory :product do + category { %w(birthday wedding chocolate vanilla buttercream).sample} + prod_name { Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor} + description { Faker::Coffee.notes} + price { Faker::Number.decimal(2, 2)} + inv_qty { Faker::Number.between(0, 30)} + active { Faker::Boolean.boolean} + image { "image test"} + end +end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index ba5adc2dd4..159c34702d 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -1,14 +1,14 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - category: MyString - prod_name: MyString - description: MyString - price: 1.5 + category: Wedding Cake + prod_name: Vanilla Cake + description: "Frosted cake with sprinkles to highlight any celebration" + price: 250.50 inv_qty: 1 two: - category: MyString + category: Wedding Cake prod_name: MyString description: MyString price: 1.5 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 3710d0e0b2..50a0ddc177 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -2,10 +2,10 @@ one: uid: 1 - username: MyString - email: MyString + username: Lady Bird + email: lbird@ada. two: - uid: 1 + uid: 2 username: MyString email: MyString diff --git a/test/models/order_test.rb b/test/models/order_test.rb index df80f10fb6..d70c96e196 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -3,7 +3,68 @@ describe Order do let(:order) { Order.new } - it "must be valid" do - value(order).must_be :valid? + describe "validation" do + before do + order = create(:order) + end + + it "must be a valid order" do + + expect(order.valid?).must_equal true + end + + it "must be invalid without a customer name " do + order.cust_name = nil + + expect(order.cust_name.valid?).must_equal false + expect(order.errors.messages).must_include :cust_name + end + + it "must be invalid without an email address " do + order.cust_email = nil + + expect(order.cust_email.valid?).must_equal false + expect(order.errors.messages).must_include :cust_email + end + + + it "must be invalid without a mailing address" do + order.mailing_address = nil + + expect(order.description.valid?).must_equal false + expect(order.errors.messages).must_include :mailing_address + end + + + it "must be invalid without a customer name" do + order.cc_name = nil + + expect(order.cc_name.valid?).must_equal false + expect(order.errors.messages).must_include :price + end + + + it "must have a unique name for each order" do + order = orders(:one) + order2 = orders(:one) + + expect(order2.name.valid?).must_equal false + end end + + + describe "relations" do + + it "belong to a user" do + order = user.order + #add the yml file + expect(order).must_be_instance_of User + expect(order.id).must_equal user.order_id + end + + it "can have a rating" do + order = rating.order + expect(order).must_be_instance_of Review + expect(order.id).must_equal review.order_id + end end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index a618b0a156..7bd595accf 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -3,7 +3,94 @@ describe Product do let(:product) { Product.new } - it "must be valid" do - value(product).must_be :valid? + describe "validation" do + + it "must be valid" do + 2.times do + product = create(:product) + end + + expect(product.valid?).must_equal true + end + + it "must be invalid without a category " do + 1.times do + product = create(:product) + end + + product.category = nil + + expect(product.category.valid?).must_equal false + expect(product.errors.messages).must_include :category + end + + it "must be invalid without a product name " do + 1.times do + product = create(:product) + end + product.prod_name = nil + + expect(product.prod_name.valid?).must_equal false + expect(product.errors.messages).must_include :prod_name + end + + it "must be a string for product name " do + 1.times do + product = create(:product) + end + product.prod_name = 123 + + expect(product.prod_name.valid?).must_be_instance_of String + expect(product.errors.messages).must_include :prod_name + end + + it "must be invalid without a description" do + 1.times do + product = create(:product) + end + + product.description = nil + + expect(product.description.valid?).must_equal false + expect(product.errors.messages).must_include :description + end + + + it "must be invalid without a price" do + 1.times do + product = create(:product) + end + + product.price = nil + + expect(product.price.valid?).must_equal false + expect(product.errors.messages).must_include :price + end + + + it "must have a unique name for each product" do + product = products(:one) + product2 = products(:one) + + expect(product2.name.valid?).must_equal false + end + end + + + describe "relations" do + + it "belong to a user" do + product = user.product + #add the yml file + expect(product).must_be_instance_of User + expect(product.id).must_equal user.product_id + end + + it "can have a rating" do + product = rating.product + expect(product).must_be_instance_of Review + expect(product.id).must_equal review.product_id + end + end end From 8f98dd062d8c67765fe4e765fff117dd6befa59d Mon Sep 17 00:00:00 2001 From: Trang Date: Thu, 18 Oct 2018 16:57:52 -0700 Subject: [PATCH 024/192] create cart show page --- app/controllers/order_items_controller.rb | 7 ++++++ app/views/carts/show.html.erb | 28 +++++++++++++++++++++-- app/views/order_items/create.html.erb | 2 -- app/views/order_items/destroy.html.erb | 2 -- app/views/order_items/update.html.erb | 2 -- app/views/products/show.html.erb | 7 ++---- config/routes.rb | 2 +- 7 files changed, 36 insertions(+), 14 deletions(-) delete mode 100644 app/views/order_items/create.html.erb delete mode 100644 app/views/order_items/destroy.html.erb delete mode 100644 app/views/order_items/update.html.erb diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 1ab049a747..1b98f4ecf0 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -4,13 +4,18 @@ class OrderItemsController < ApplicationController def create @order = current_order + # check if item is in stock + @order_item = @order.order_items.new(order_item_params) @order.save session[:order_id] = @order.id + + redirect_to cart_path(@order.id) end def update @order = current_order + # check if item is in stock @order_item = @order.order_items.find(params[:id]) @order_item.update_attributes(order_item_params) @order.save @@ -22,6 +27,8 @@ def destroy @order_item = @order.order_items.find(params[:id]) @order_item.destroy @order_items = @order.order_items + + redirect_to cart_path(@order.id) end private diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 5d5b7a71dd..396c86d8e8 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -1,2 +1,26 @@ -

Carts#show

-

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

+

Your Cart

+ + + + + + + + + + + <% @order_items.each do |item| %> + + + + <%= form_with model: @order_item do |f| %> + + <%= f.hidden_field :product_id, :value => item.product.id %> + + + <% end %> + + + <% end %> + +
ItemPriceQuantitySubtotal
<%= item.product.prod_name %><%= item.product.price %><%= f.select :qty, (1..item.product.inv_qty).to_a %><%= item.subtotal %><%= f.submit "Update" %><%= link_to "Remove", order_item_path(item.id), method: :delete %>
diff --git a/app/views/order_items/create.html.erb b/app/views/order_items/create.html.erb deleted file mode 100644 index cfb578be81..0000000000 --- a/app/views/order_items/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

OrderItems#create

-

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

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

OrderItems#destroy

-

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

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

OrderItems#update

-

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

diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index c7e12cae1e..ea5433e01e 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -29,13 +29,10 @@ <%= f.label :qty %> <%= f.text_field :qty %> - <%= f.label :product_id %> - <%= f.text_field :product_id, :value => @product.id %> + <%= f.hidden_field :product_id, :value => @product.id %> - <%= f.submit %> + <%= f.submit "Add to cart", class: "btn btn-primary" %> <% end %> -<%= link_to 'Add to Cart', order_items_path, method: :post %> - <%= link_to 'Edit', edit_product_path(@product) %> | <%= link_to 'Back', products_path %> diff --git a/config/routes.rb b/config/routes.rb index 1807be9388..c63ff58b9a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do - resources :cart, only: [:show] + resources :carts, only: [:show] resources :order_items, only: [:create, :update, :destroy] root 'products#home' From b5b2f384e229a73a670fb028ef16ef6a43759ab7 Mon Sep 17 00:00:00 2001 From: Trang Date: Thu, 18 Oct 2018 17:04:34 -0700 Subject: [PATCH 025/192] fix merge conflicts --- app/models/order.rb | 6 ++---- app/models/product.rb | 13 +++++++------ app/models/user.rb | 10 ++++------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index a0d08b821b..e4167c7590 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,5 +1,5 @@ class Order < ApplicationRecord -<<<<<<< HEAD + has_many :products has_many :order_items @@ -18,7 +18,5 @@ def place_order # clears current cart () end -======= - has_many :products ->>>>>>> 7c43e0f5f0607301dda2104e44013f217f0a8853 + end diff --git a/app/models/product.rb b/app/models/product.rb index 2ff9d1f772..d01b48ad46 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,7 +1,10 @@ class Product < ApplicationRecord -<<<<<<< HEAD has_many :order_items + validates :prod_name, presence: true, uniqueness: true + validates :prod_name, presence: true, numericality: { only_integer: true, greater_than: 0} + belongs_to :users + @@ -12,9 +15,7 @@ def avg_rating # return sum / num end -======= - validates :prod_name, presence: true, uniqueness: true - validates :prod_name, presence: true, numericality: { only_integer: true, greater_than: 0} - belongs_to :users ->>>>>>> 7c43e0f5f0607301dda2104e44013f217f0a8853 + + + end diff --git a/app/models/user.rb b/app/models/user.rb index 5f61703ac6..cc462974a7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,7 @@ class User < ApplicationRecord -<<<<<<< HEAD + validates :username, presence: true, uniqueness: true + validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } + @@ -31,9 +33,5 @@ def num_orders(status) # self.total_orders where Order.status == status end - -======= - validates :username, presence: true, uniqueness: true - validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } ->>>>>>> 7c43e0f5f0607301dda2104e44013f217f0a8853 + end From fb86bf8b17d5705e5625f1caddabecd0a6b4754b Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 17:18:14 -0700 Subject: [PATCH 026/192] order testing model in progress --- test/models/order_test.rb | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/test/models/order_test.rb b/test/models/order_test.rb index d70c96e196..9696584fdd 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -20,8 +20,9 @@ expect(order.errors.messages).must_include :cust_name end - it "must be invalid without an email address " do + it "must be invalid without an email address or correct data type " do order.cust_email = nil + order.cust_email = 123 expect(order.cust_email.valid?).must_equal false expect(order.errors.messages).must_include :cust_email @@ -31,7 +32,7 @@ it "must be invalid without a mailing address" do order.mailing_address = nil - expect(order.description.valid?).must_equal false + expect(order.mailing_address.valid?).must_equal false expect(order.errors.messages).must_include :mailing_address end @@ -43,28 +44,30 @@ expect(order.errors.messages).must_include :price end + it "must be invalid if date has expired" do - it "must have a unique name for each order" do - order = orders(:one) - order2 = orders(:one) + end + + it "must be invalid with more than 16 digits for credit card" do + + end + + it "must have only 3 digits for CVV" do + + end + + it " must be 5 digits in length for zip code" do - expect(order2.name.valid?).must_equal false end - end describe "relations" do - it "belong to a user" do - order = user.order + it "belong to a product" do + order = product.order #add the yml file - expect(order).must_be_instance_of User - expect(order.id).must_equal user.order_id + expect(order).must_be_instance_of Product + expect(order.id).must_equal product.order_id end - it "can have a rating" do - order = rating.order - expect(order).must_be_instance_of Review - expect(order.id).must_equal review.order_id - end end From 13812abb793771af05185bc329e11f95d365c48e Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 17:31:28 -0700 Subject: [PATCH 027/192] minor edit with head tag --- app/models/product.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index a7b320a689..881b801f74 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -4,10 +4,10 @@ class Product < ApplicationRecord validates :prod_name, presence: true, uniqueness: true validates :inv_qty, presence: true, numericality: { only_integer: true, greater_than: 0} belongs_to :users -<<<<<<< HEAD + has_many :reviews has_and_belongs_to_many :orders -======= + @@ -22,5 +22,4 @@ def avg_rating ->>>>>>> b5b2f384e229a73a670fb028ef16ef6a43759ab7 end From 70fa4198a11b0ac56726e322b65bd6adb91ed34b Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 18 Oct 2018 21:21:13 -0700 Subject: [PATCH 028/192] fixed a merge conflict --- app/models/product.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index a7b320a689..fa78fab3f2 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -4,10 +4,8 @@ class Product < ApplicationRecord validates :prod_name, presence: true, uniqueness: true validates :inv_qty, presence: true, numericality: { only_integer: true, greater_than: 0} belongs_to :users -<<<<<<< HEAD has_many :reviews has_and_belongs_to_many :orders -======= @@ -22,5 +20,4 @@ def avg_rating ->>>>>>> b5b2f384e229a73a670fb028ef16ef6a43759ab7 end From bcbc5a2047e5c1cda891d44d9fc6d43efb4ecbe1 Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 18 Oct 2018 22:00:45 -0700 Subject: [PATCH 029/192] updated params method to allow id for user --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8c9eb329b6..d663e5c3a2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -63,6 +63,6 @@ def set_user # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:uid, :username, :email) + params.require(:user).permit(:uid, :username, :email, :id) end end From f8d2247308b4f61dbbad160957ef15ddf791e2d2 Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 18 Oct 2018 22:06:25 -0700 Subject: [PATCH 030/192] updated new user form so the user cannot choose id-it is generated by model --- app/views/users/_form.html.erb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 14d148098a..98a9f3d923 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -11,11 +11,6 @@
<% end %> -
- <%= form.label :uid %> - <%= form.number_field :uid, class: "form-control" %> -
-
<%= form.label :username %> <%= form.text_field :username, class: "form-control" %> From 02aa8012c2aad36965b2d124aa7a06603345e6ae Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 18 Oct 2018 22:33:59 -0700 Subject: [PATCH 031/192] formatting index complete --- app/assets/stylesheets/products.scss | 62 +++++++++++++--------------- app/views/products/index.html.erb | 62 ++++++++++++++-------------- test/models/product_test.rb | 2 +- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index ba2fe2bf3b..2b39b1a435 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -3,40 +3,6 @@ // You can use Sass (SCSS) here: http://sass-lang.com/ // // Base styles -// - -.product-grid3{font-family:Roboto,sans-serif;text-align:center;position:relative;z-index:1} -.product-grid3:before{content:"";height:81%;width:100%;background:#fff;border:1px solid rgba(0,0,0,.1);opacity:0;position:absolute;top:0;left:0;z-index:-1;transition:all .5s ease 0s} -.product-grid3:hover:before{opacity:1;height:100%} -.product-grid3 .product-image3{position:relative} -.product-grid3 .product-image3 a{display:block} -.product-grid3 .product-image3 img{width:100%;height:auto} -.product-grid3 .pic-1{opacity:1;transition:all .5s ease-out 0s; width: 240px; height:307px} -.product-grid3:hover .pic-1{opacity:0} -.product-grid3 .pic-2{position:absolute;top:0;left:0;opacity:0;transition:all .5s ease-out 0s} -.product-grid3:hover .pic-2{opacity:1} -.product-grid3 .social{width:120px;padding:0;margin:0 auto;list-style:none;opacity:0;position:absolute;right:0;left:0;bottom:-23px;transform:scale(0);transition:all .3s ease 0s} -.product-grid3:hover .social{opacity:1;transform:scale(1)} -.product-grid3:hover .product-discount-label,.product-grid3:hover .product-new-label,.product-grid3:hover .title{opacity:0} -.product-grid3 .social li{display:inline-block} -.product-grid3 .social li a{color:#e67e22;background:#fff;font-size:18px;line-height:50px;width:50px;height:50px;border:1px solid rgba(0,0,0,.1);border-radius:50%;margin:0 2px;display:block;transition:all .3s ease 0s} -.product-grid3 .social li a:hover{background:#e67e22;color:#fff} -.product-grid3 .product-discount-label,.product-grid3 .product-new-label{background-color:#e67e22;color:#fff;font-size:17px;padding:2px 10px;position:absolute;right:10px;top:10px;transition:all .3s} -.product-grid3 .product-content{z-index:-1;padding:15px;text-align:left} -.product-grid3 .title{font-size:14px;text-transform:capitalize;margin:0 0 7px;transition:all .3s ease 0s} -.product-grid3 .title a{color:#414141} -.product-grid3 .price{color:#000;font-size:16px;letter-spacing:1px;font-weight:600;margin-right:2px;display:inline-block} -.product-grid3 .price span{color:#909090;font-size:14px;font-weight:500;letter-spacing:0;text-decoration:line-through;text-align:left;display:inline-block;margin-top:-2px} -.product-grid3 .rating{padding:0;margin:-22px 0 0;list-style:none;text-align:right;display:block} -.product-grid3 .rating li{color:#ffd200;font-size:13px;display:inline-block} -.product-grid3 .rating li.disable{color:#dcdcdc} -@media only screen and (max-width:1200px){.product-grid3 .rating{margin:0} -} -@media only screen and (max-width:990px){.product-grid3{margin-bottom:30px} -.product-grid3 .rating{margin:-22px 0 0} -} -@media only screen and (max-width:359px){.product-grid3 .rating{margin:0} -} .parent { display: flex; @@ -51,6 +17,34 @@ } +.product-grid6,.product-grid6 .product-image6{overflow:hidden} +.product-grid6{font-family:'Open Sans',sans-serif;text-align:center;position:relative;transition:all .5s ease 0s} +.product-grid6:hover{box-shadow:0 0 10px rgba(0,0,0,.3)} +.product-grid6 .product-image6 a{display:block} +.product-grid6 .product-image6 img{width:100%;height:auto;transition:all .5s ease 0s} +.product-grid6:hover .product-image6 img{transform:scale(1.1)} +.product-grid6 .product-content{padding:12px 12px 15px;transition:all .5s ease 0s} +.product-grid6:hover .product-content{opacity:0} +.product-grid6 .title{font-size:20px;font-weight:600;text-transform:capitalize;margin:0 0 10px;transition:all .3s ease 0s} +.product-grid6 .title a{color:#000} +.product-grid6 .title a:hover{color:#2e86de} +.product-grid6 .price{font-size:18px;font-weight:600;color:#2e86de} +.product-grid6 .price span{color:#999;font-size:15px;font-weight:400;text-decoration:line-through;margin-left:7px;display:inline-block} +.product-grid6 .social{background-color:#fff;width:100%;padding:0;margin:0;list-style:none;opacity:0;transform:translateX(-50%);position:absolute;bottom:-50%;left:50%;z-index:1;transition:all .5s ease 0s} +.product-grid6:hover .social{opacity:1;bottom:20px} +.product-grid6 .social li{display:inline-block} +.product-grid6 .social li a{color:#909090;font-size:16px;line-height:45px;text-align:center;height:45px;width:45px;margin:0 7px;border:1px solid #909090;border-radius:50px;display:block;position:relative;transition:all .3s ease-in-out} +.product-grid6 .social li a:hover{color:#fff;background-color:#2e86de;width:80px} +.product-grid6 .social li a:after,.product-grid6 .social li a:before{content:attr(data-tip);color:#fff;background-color:#2e86de;font-size:12px;letter-spacing:1px;line-height:20px;padding:1px 5px;border-radius:5px;white-space:nowrap;opacity:0;transform:translateX(-50%);position:absolute;left:50%;top:-30px} +.product-grid6 .social li a:after{content:'';height:15px;width:15px;border-radius:0;transform:translateX(-50%) rotate(45deg);top:-20px;z-index:-1} +.product-grid6 .social li a:hover:after,.product-grid6 .social li a:hover:before{opacity:1} +@media only screen and (max-width:990px){.product-grid6{margin-bottom:30px} +} + +.col-sm-6{ + padding-bottom: 1em; +} + /* GLOBAL STYLES -------------------------------------------------- */ /* Padding below the footer and lighter body text */ diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 95a6e06486..cc94cf4fc5 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,47 +1,49 @@

<%= notice %>

-

Products

+

Cakes for All Occassions

+
-<% @products.each do |product| %> -
+
+ +
+
-
-
-
- + <% @products.each do |product| %> +
- +
+ +
+ + - - New
-

<%= product.prod_name %>

-
- <%= product.price %> - <%= product.inv_qty %> +

<%= product.prod_name %>

+
$<%= product.price %> + <%= product.inv_qty %> in stock
-
    -
  • -
  • -
  • -
  • -
  • -
+
+ + +
+
+ <% end %>
- -<% end %>
- - - +

diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 7bd595accf..2fd1b154ac 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -72,7 +72,7 @@ product = products(:one) product2 = products(:one) - expect(product2.name.valid?).must_equal false + expect(product2.prod_name.valid?).must_equal false end end From 588bc8bdfd0eb1599051239db23c1cd26e40631c Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 18 Oct 2018 22:53:41 -0700 Subject: [PATCH 032/192] removed unnecesary methods and test using ERD, updated create method, and test for it --- app/controllers/users_controller.rb | 42 ++++------------------- test/controllers/users_controller_test.rb | 36 ++++++------------- 2 files changed, 16 insertions(+), 62 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d663e5c3a2..4c540308f5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,11 +1,6 @@ class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] - # GET /users - def index - @users = User.all - end - # GET /users/1 def show end @@ -15,43 +10,18 @@ def new @user = User.new end - # GET /users/1/edit - def edit - end - # POST /users def create @user = User.new(user_params) - respond_to do |format| - if @user.save - format.html { redirect_to @user, notice: 'User was successfully created.' } - format.json { render :show, status: :created, location: @user } - else - format.html { render :new } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - end - end + if @user.save # save returns true if the database insert succeeds + flash[:success] = 'user Created!' - # PATCH/PUT /users/1 - def update - respond_to do |format| - if @user.update(user_params) - format.html { redirect_to @user, notice: 'User was successfully updated.' } - format.json { render :show, status: :ok, location: @user } - else - format.html { render :edit } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - 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] = 'user not created!' - # DELETE /users/1 - def destroy - @user.destroy - respond_to do |format| - format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + render :new, status: :bad_request# show the new book form view again end end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 82ffc317fe..5c875a1bb0 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -3,44 +3,28 @@ describe UsersController do let(:user) { users :one } - it "gets index" do - get users_url - value(response).must_be :success? - end - it "gets new" do get new_user_url value(response).must_be :success? end it "creates user" do + user_hash= { + user: { + email: 'user3@gmail.com', + uid: 2, + username: 'newuser' + } + } expect { - post users_url, params: { user: { email: user.email, uid: user.uid, username: user.username } } - }.must_change "User.count" + post users_path, params: user_hash + }.must_change "User.count", 1 - must_redirect_to user_path(User.last) + must_redirect_to root_path end it "shows user" do get user_url(user) value(response).must_be :success? end - - it "gets edit" do - get edit_user_url(user) - value(response).must_be :success? - end - - it "updates user" do - patch user_url(user), params: { user: { email: user.email, uid: user.uid, username: user.username } } - must_redirect_to user_path(user) - end - - it "destroys user" do - expect { - delete user_url(user) - }.must_change "User.count", -1 - - must_redirect_to users_path - end end From 5682bb9b58979a87edca33f13aa6dad10d9ae592 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 18 Oct 2018 23:10:20 -0700 Subject: [PATCH 033/192] fixed model validations, relationships, seed data and seed.rb - db:seed now works for users products reviews and orders --- app/controllers/order_items_controller.rb | 2 +- app/controllers/products_controller.rb | 2 +- app/models/category.rb | 6 ++ app/models/order.rb | 9 +- app/models/order_item.rb | 2 + app/models/product.rb | 17 ++-- app/models/review.rb | 6 +- app/models/user.rb | 4 + db/generate_seeds.rb | 28 ++++-- ...1019014144_add_foreign_key_associations.rb | 6 ++ ...019035503_remove_category_from_products.rb | 5 + ...019041122_change_cc_digit_int_to_bigint.rb | 5 + ...41908_change_order_mail_address_to_text.rb | 5 + ...2145_change_reviews_description_to_text.rb | 5 + ...229_change_products_description_to_text.rb | 5 + db/order_seeds.csv | 21 ++--- db/product_seeds.csv | 62 ++++++------- db/review_seeds.csv | 22 ++--- db/schema.rb | 17 ++-- db/seeds.rb | 91 ++++++++++++++----- db/user_seeds.csv | 6 ++ test/factories/category.rb | 5 + test/factories/user.rb | 5 + test/fixtures/categories.yml | 7 +- test/fixtures/products.yml | 34 ++++--- test/models/category_test.rb | 20 ++++ 26 files changed, 278 insertions(+), 119 deletions(-) create mode 100644 db/migrate/20181019014144_add_foreign_key_associations.rb create mode 100644 db/migrate/20181019035503_remove_category_from_products.rb create mode 100644 db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb create mode 100644 db/migrate/20181019041908_change_order_mail_address_to_text.rb create mode 100644 db/migrate/20181019042145_change_reviews_description_to_text.rb create mode 100644 db/migrate/20181019042229_change_products_description_to_text.rb create mode 100644 db/user_seeds.csv create mode 100644 test/factories/category.rb create mode 100644 test/factories/user.rb diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 1b98f4ecf0..b2e119f58f 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -35,7 +35,7 @@ def destroy def order_item_params - params.require(:order_item).permit(:product_id, :qty) + params.require(:order_item).permit(:qty, product_ids: []) end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 9818349a82..2f356261e1 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -61,6 +61,6 @@ def set_product # Never trust parameters from the scary internet, only allow the white list through. def product_params - params.require(:product).permit(:category, :prod_name, :description, :price, :inv_qty) + params.require(:product).permit(:prod_name, :description, :price, :inv_qty, category_ids: []) end end diff --git a/app/models/category.rb b/app/models/category.rb index 54cb6aee3f..4a839b1d0d 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,2 +1,8 @@ class Category < ApplicationRecord + # validations + + # relationships + + has_and_belongs_to_many :products + end diff --git a/app/models/order.rb b/app/models/order.rb index 492760049e..fedca62a55 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,9 +1,12 @@ class Order < ApplicationRecord - has_many :products - has_many :order_items - has_and_belongs_to_many :products + #validations + + #relationships + # has_and_belongs_to_many :products + has_many :order_items + def total_price order_items.collect { |order_item| order_item.quantity * order_item.unit_price }.sum diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 04f8bbfe04..7dab398f7e 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,4 +1,6 @@ class OrderItem < ApplicationRecord + #validations - n/a + #relationships belongs_to :product belongs_to :order diff --git a/app/models/product.rb b/app/models/product.rb index a7b320a689..8b103ae9a8 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,13 +1,14 @@ class Product < ApplicationRecord - has_many :order_items - + # validations validates :prod_name, presence: true, uniqueness: true - validates :inv_qty, presence: true, numericality: { only_integer: true, greater_than: 0} - belongs_to :users -<<<<<<< HEAD + validates :inv_qty, presence: true, numericality: { only_integer: true, greater_than: -1} + # relationships + belongs_to :user has_many :reviews - has_and_belongs_to_many :orders -======= + # has_and_belongs_to_many :orders + + has_and_belongs_to_many :categories + has_many :order_items @@ -22,5 +23,5 @@ def avg_rating ->>>>>>> b5b2f384e229a73a670fb028ef16ef6a43759ab7 + end diff --git a/app/models/review.rb b/app/models/review.rb index e652dcf617..1e11925f71 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,4 +1,6 @@ class Review < ApplicationRecord - validates :rating, presence: true, numericality: { only_integer: true, greater_than: 1, less_than: 5} - belongs_to :products + #validations + validates :rating, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 6} + #relationships + belongs_to :product end diff --git a/app/models/user.rb b/app/models/user.rb index 91c07f3ed7..6d0c7f08f3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,9 @@ class User < ApplicationRecord + # validations validates :username, presence: true, uniqueness: true validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } + # relationships has_many :products + + end diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb index bd6935e40f..50be8fcf5c 100644 --- a/db/generate_seeds.rb +++ b/db/generate_seeds.rb @@ -11,31 +11,45 @@ # $ rails db:reset # doesn't currently check for if titles are unique against each other +CSV.open('db/user_seeds.csv', "w", :write_headers=> true, + :headers => ["uid", "username", "email"]) do |csv| + + 5.times do + uid = Faker::Number.between(1, 5) + username = Faker::Internet.username + email= Faker::Internet.safe_email + csv << [uid, username, email] + end +end + + + CSV.open('db/product_seeds.csv', "w", :write_headers=> true, - :headers => ["category", "prod_name", "description", "price", "inv_qty", "active", "image"]) do |csv| + :headers => ["prod_name", "user_id", "description", "price", "inv_qty", "active", "image"]) do |csv| 30.times do - category = %w(birthday wedding chocolate vanilla buttercream).sample + # category = %w(birthday wedding chocolate vanilla buttercream).sample prod_name = Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor + user_id = Faker::Number.between(1, 4) description = Faker::Coffee.notes price = Faker::Number.decimal(2, 2) inv_qty = Faker::Number.between(0, 30) active = Faker::Boolean.boolean - image = Faker::LoremPixel.image("50x60", false, 'food') + image = Faker::LoremPixel.image("200x300", false, 'food') - csv << [category, prod_name, description, price, inv_qty, active, image] + csv << [prod_name, user_id, description, price, inv_qty, active, image] end end CSV.open('db/review_seeds.csv', "w", :write_headers=> true, - :headers => ["rating", "description"]) do |csv| + :headers => ["rating", "description", "product_id"]) do |csv| 10.times do rating = Faker::Number.between(1, 5) description = ["Tasted like ", "Deliciously flavored ", "Oddly it smelled like "].sample + Faker::Coffee.notes - - csv << [rating, description] + product_id = Faker::Number.between(1, 15) + csv << [rating, description, product_id] end end diff --git a/db/migrate/20181019014144_add_foreign_key_associations.rb b/db/migrate/20181019014144_add_foreign_key_associations.rb new file mode 100644 index 0000000000..7a0e41e91f --- /dev/null +++ b/db/migrate/20181019014144_add_foreign_key_associations.rb @@ -0,0 +1,6 @@ +class AddForeignKeyAssociations < ActiveRecord::Migration[5.2] + def change + add_reference :products, :user, foreign_key: true + add_reference :reviews, :product, foreign_key: true + end +end diff --git a/db/migrate/20181019035503_remove_category_from_products.rb b/db/migrate/20181019035503_remove_category_from_products.rb new file mode 100644 index 0000000000..4a5939d3d9 --- /dev/null +++ b/db/migrate/20181019035503_remove_category_from_products.rb @@ -0,0 +1,5 @@ +class RemoveCategoryFromProducts < ActiveRecord::Migration[5.2] + def change + remove_column :products, :category + end +end diff --git a/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb b/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb new file mode 100644 index 0000000000..757f155371 --- /dev/null +++ b/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb @@ -0,0 +1,5 @@ +class ChangeCcDigitIntToBigint < ActiveRecord::Migration[5.2] + def change + change_column :orders, :cc_digit, :bigint + end +end diff --git a/db/migrate/20181019041908_change_order_mail_address_to_text.rb b/db/migrate/20181019041908_change_order_mail_address_to_text.rb new file mode 100644 index 0000000000..1e95d824b2 --- /dev/null +++ b/db/migrate/20181019041908_change_order_mail_address_to_text.rb @@ -0,0 +1,5 @@ +class ChangeOrderMailAddressToText < ActiveRecord::Migration[5.2] + def change + change_column :orders, :mailing_address, :text + end +end diff --git a/db/migrate/20181019042145_change_reviews_description_to_text.rb b/db/migrate/20181019042145_change_reviews_description_to_text.rb new file mode 100644 index 0000000000..5dfb97e329 --- /dev/null +++ b/db/migrate/20181019042145_change_reviews_description_to_text.rb @@ -0,0 +1,5 @@ +class ChangeReviewsDescriptionToText < ActiveRecord::Migration[5.2] + def change + change_column :reviews, :description, :text + end +end diff --git a/db/migrate/20181019042229_change_products_description_to_text.rb b/db/migrate/20181019042229_change_products_description_to_text.rb new file mode 100644 index 0000000000..5ea37ef928 --- /dev/null +++ b/db/migrate/20181019042229_change_products_description_to_text.rb @@ -0,0 +1,5 @@ +class ChangeProductsDescriptionToText < ActiveRecord::Migration[5.2] + def change + change_column :products, :description, :text + end +end diff --git a/db/order_seeds.csv b/db/order_seeds.csv index 41cd81f7a1..1130c1cfaa 100644 --- a/db/order_seeds.csv +++ b/db/order_seeds.csv @@ -1,12 +1,11 @@ status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip -pending,Jujubee,jeie@example.com,"Apt. 877 77845 Medhurst Field, West Claudiofurt, DE 31531",Tina See,3008-507303-8056,2020-10-17,829,17663 -complete,Alexis Mateo,ali.koelpin@example.net,"Suite 242 2202 Arnoldo Trace, Bayershire, OR 01892-0307",Helen Highwater,5019-8802-3565-7940,2022-10-17,800,42569 -paid,Raven,elliott_koepp@example.com,"970 Wintheiser Lights, Port Meganstad, FL 02978",Emma Royds,6759-1236-2510-3777-16,2020-10-17,721,21243 -complete,Detox,broderick.kshlerin@example.org,"Suite 544 1395 Langosh Cliffs, Ricechester, CO 34158-2143",Adam Zapel,5019-7154-3494-6316,2022-10-17,911,12769 -paid,Naomi Smalls,lucien@example.com,"5530 Tromp Glens, Morissettestad, SC 23008",Jerry Atrics,6592-6207-3238-5746,2020-10-17,875,47435 -cancelled,Chad Michaels,jee@example.com,"Suite 445 2804 Gibson Motorway, East Rudolf, SD 99825-7189",Sal Minella,5755-1277-8800-4525,2021-10-17,102,29099 -pending,Alexis Mateo,brandon.ward@example.net,"Apt. 873 96231 Kendra Junction, East Halfurt, HI 56794-8059",Hy Marx,6007-2284-8253-5306,2021-10-17,776,43846 -complete,Violet Chachki,yajaira.schimmel@example.net,"5517 Jacobi Stream, Clydeside, PA 81594-0046",Ilene Left,6007-2233-4178-2199,2020-10-17,497,93629 -cancelled,Violet Chachki,guy_johnson@example.net,"4830 Fernando Forks, Berneicehaven, MA 69689-4175",Don Key,5012-4257-9681-7686,2019-10-18,535,36242 -pending,Adore Delano,rodger.stroman@example.net,"Suite 605 5429 Hills Wall, Lucienneberg, CA 25884-4712",Gus Tofwin,6007-2290-8336-7131,2022-10-17,214,40838 - +pending,Thorgy Thor,willa@example.com,"5493 Emely Branch, Feilchester, WI 17591-1680",Ilene North,9675258621115789,2019-10-18,197,54820 +cancelled,Jujubee,vannesa_treutel@example.net,"Suite 470 446 Volkman Stravenue, Wymanhaven, VT 40432-0667",Darren Deeds,4994537217918278,2022-10-17,492,48391 +complete,Farrah Moan,wilburn@example.com,"Apt. 701 5457 Mellissa Locks, South Salvador, DE 91591",Howie Doohan,6046910104486392,2019-10-18,671,47996 +cancelled,BenDeLaCreme,hung@example.org,"8006 Mayert Creek, Port Boydburgh, GA 67344-0146",Chanda Lear,5705706804044600,2021-10-17,410,81845 +pending,Phi Phi O'Hara,wendell@example.com,"229 Stehr Islands, New Karin, AZ 69278-0408",Ilene Left,9725219929234895,2020-10-17,616,52259 +pending,Alyssa Edwards,jacinda@example.org,"6897 Reichel Manor, East Carroll, KY 63730-3126",Evans Gayte,6722041749449069,2022-10-17,157,18554 +pending,Alaska,shaina_parker@example.com,"Apt. 476 67391 Beer Road, North Reubenburgh, RI 28019",Rusty Steele,1149577765372457,2021-10-17,402,22706 +complete,Chad Michaels,sam.jast@example.net,"984 Ruthe Summit, South Dwight, VA 25459",M. Balmer,7121448368152429,2020-10-17,122,44807 +paid,Acid Betty,moises@example.org,"Suite 618 2906 Fritz Locks, New Josette, AL 93558",Sarah Bellum,3208164991667526,2019-10-18,610,62312 +pending,Pandora Boxx,kelley@example.org,"Apt. 118 7556 German Place, Xiaohaven, AL 36947-4162",Joe King,8968566940150310,2020-10-17,306,26539 diff --git a/db/product_seeds.csv b/db/product_seeds.csv index ce333c1837..0065046b80 100644 --- a/db/product_seeds.csv +++ b/db/product_seeds.csv @@ -1,31 +1,31 @@ -category,prod_name,description,price,inv_qty,active,image -birthday,Pudding Peanut Butter Birthday Cake,"pointed, creamy, orange creamsicle, jasmine, plum",15.11,11,false,https://lorempixel.com/50/60/food -buttercream,Parfait Frosting Peanut Butter,"soft, chewy, black currant, watermelon, mandarin",14.95,24,false,https://lorempixel.com/50/60/food -wedding,Cheesecake Caramel Strawberry,"bright, creamy, graham cracker, lemonade, nectarine",79.52,15,false,https://lorempixel.com/50/60/food -wedding,Cake Chocolate Sprinkles Butter Pecan,"complex, coating, hops, star fruit, honeysuckle",95.56,30,false,https://lorempixel.com/50/60/food -birthday,Key Lime Pie Bacon Cookies 'n Cream,"juicy, silky, strawberry, corriander, snow pea",78.21,3,true,https://lorempixel.com/50/60/food -wedding,Cupcake Cinnamon Cheesecake,"dry, syrupy, dates, nutella, snow pea",80.41,30,false,https://lorempixel.com/50/60/food -wedding,Key Lime Pie Bacon Cheesecake,"quick, smooth, peach, smokey, lemonade",58.48,7,true,https://lorempixel.com/50/60/food -chocolate,Cookie Gummy Bears Green Tea,"rounded, big, kiwi, sundried tomato, musty",31.74,8,true,https://lorempixel.com/50/60/food -birthday,Pudding Berry Compote Vanilla,"wild, big, brown sugar, apricot, butter",79.65,24,false,https://lorempixel.com/50/60/food -chocolate,Pie Bacon Banana,"crisp, creamy, peanut, honeysuckle, lychee",88.81,28,false,https://lorempixel.com/50/60/food -wedding,Sweet Bread Marshmallows Chocolate,"bright, watery, prune, lemon verbena, cacao nibs",41.87,10,true,https://lorempixel.com/50/60/food -vanilla,Doughnut Chocolate Sprinkles Birthday Cake,"vibrant, chewy, rose hips, quakery, sugar cane",22.54,13,false,https://lorempixel.com/50/60/food -buttercream,Fruit Cake Caramel Birthday Cake,"lingering, juicy, white grape, tamarind, black cherry",46.01,14,false,https://lorempixel.com/50/60/food -chocolate,Cheesecake Granola Blondie,"balanced, creamy, cranberry, molasses, toast",88.12,6,true,https://lorempixel.com/50/60/food -buttercream,Upside Down Pineapple Cake Peanuts Espresso,"pointed, chewy, lemon, milk chocolate, pineapple",25.46,23,true,https://lorempixel.com/50/60/food -vanilla,Key Lime Pie Butterscotch Syrup Espresso,"bright, syrupy, green-tea, barley, cranberry",17.27,11,false,https://lorempixel.com/50/60/food -wedding,Cobbler Granola Peanut Butter,"structured, tea-like, pineapple, lemon, granola",51.67,9,false,https://lorempixel.com/50/60/food -buttercream,Brownie Peanut Butter Espresso,"quick, creamy, golden raisin, tobacco, vanilla",26.36,25,true,https://lorempixel.com/50/60/food -birthday,Ice Cream Glaze Cheesecake,"lingering, watery, raspberry, tangerine, tamarind",60.21,25,false,https://lorempixel.com/50/60/food -buttercream,Pudding Marshmallows Almond,"soft, juicy, black-tea, rose hips, bergamot",26.78,5,true,https://lorempixel.com/50/60/food -buttercream,Brownie Chocolate Sprinkles Blondie,"complex, silky, clementine, green pepper, tomato",79.68,20,true,https://lorempixel.com/50/60/food -vanilla,Parfait Peanuts Strawberry,"dirty, chewy, musty, ginger, olive",52.14,14,false,https://lorempixel.com/50/60/food -vanilla,Fruit Cake Cheesecake Bites Vanilla,"structured, silky, cocoa powder, pineapple, sweet pea",23.05,15,false,https://lorempixel.com/50/60/food -buttercream,Cheesecake Chocolate Sprinkles Butterscotch,"muted, big, cedar, coconut, tomato",46.79,20,true,https://lorempixel.com/50/60/food -buttercream,Cheesecake Mocha Drizzle Blondie,"wild, syrupy, granola, sundried tomato, medicinal",98.21,24,true,https://lorempixel.com/50/60/food -chocolate,Ice Cream Whipped Cream Pumpkin,"dense, smooth, lemon, pecan, fresh bread",87.67,3,false,https://lorempixel.com/50/60/food -birthday,Ice Cream Cake Glaze Lemon,"delicate, creamy, nougat, lemon verbena, nougat",38.94,16,true,https://lorempixel.com/50/60/food -birthday,Fruit Cake Bacon Cookies 'n Cream,"vibrant, tea-like, butter, orange, lime",26.92,12,true,https://lorempixel.com/50/60/food -birthday,Coffee Cake Chocolate Chips Chocolate Chip Cookie Dough,"muted, syrupy, mandarin, strawberry, jasmine",10.93,12,false,https://lorempixel.com/50/60/food -chocolate,Cobbler Chocolate Syrup Pumpkin,"bright, big, peanut, curry, green apple",10.12,24,true,https://lorempixel.com/50/60/food +prod_name,user_id,description,price,inv_qty,active,image +Sweet Bread Marshmallows Peanut Butter,1,"lingering, watery, almond, concord grape, almond",41.62,8,false,https://lorempixel.com/200/300/food +Cobbler Gummy Bears Pistachio,1,"lingering, chewy, lemon verbena, concord grape, golden raisin",31.68,10,true,https://lorempixel.com/200/300/food +Cake Toffee Bits Mint Chocolate Chip,3,"structured, full, marzipan, cinnamon, black currant",68.56,12,false,https://lorempixel.com/200/300/food +Cheesecake Berry Compote Birthday Cake,1,"vibrant, juicy, kiwi, nutella, soy sauce",49.24,28,true,https://lorempixel.com/200/300/food +Frozen Yogurt Cookie Dough Strawberry,2,"vibrant, chewy, honeysuckle, maple syrup, white pepper",26.09,5,false,https://lorempixel.com/200/300/food +Cupcake Peanuts Chocolate,1,"deep, round, lemon, soil, bittersweet chocolate",72.45,25,true,https://lorempixel.com/200/300/food +Upside Down Pineapple Cake Gummy Bears Lemon,3,"dull, full, cedar, clementine, molasses",86.88,18,false,https://lorempixel.com/200/300/food +Cookie Berry Compote Neapolitan,4,"complex, silky, lemon, star fruit, bittersweet chocolate",22.42,15,true,https://lorempixel.com/200/300/food +Key Lime Pie Glaze Apple,1,"mild, full, cacao nibs, curry, peach",97.65,13,false,https://lorempixel.com/200/300/food +Ice Cream Cake Chocolate Syrup Vanilla,2,"clean, watery, milk chocolate, nutmeg, sweet pea",67.38,13,false,https://lorempixel.com/200/300/food +Cobbler Butterscotch Syrup Cheesecake,4,"rounded, full, grapefruit, curry, peanut",65.75,21,true,https://lorempixel.com/200/300/food +Ice Cream Caramel Chocolate Chip Cookie Dough,4,"delicate, round, mango, quakery, lemon verbena",99.79,23,false,https://lorempixel.com/200/300/food +Doughnut Chocolate Syrup Butter Pecan,2,"mild, watery, tobacco, hazelnut, hay",76.99,13,true,https://lorempixel.com/200/300/food +Coffee Cake Walnuts Neapolitan,3,"dense, big, potato defect!, bakers chocolate, wheat",64.28,18,true,https://lorempixel.com/200/300/food +Trifle Marshmallows Chocolate Chip Cookie Dough,1,"wild, watery, grassy, raisin, peanut",87.35,23,true,https://lorempixel.com/200/300/food +Sundae Cookie Dough Almond,4,"dirty, syrupy, lemonade, lemon, nutmeg",79.92,0,true,https://lorempixel.com/200/300/food +Cupcake Berry Compote Cookies 'n Cream,1,"clean, creamy, sage, sundried tomato, lemongrass",72.88,12,false,https://lorempixel.com/200/300/food +Upside Down Pineapple Cake Peanut Butter Butter Pecan,3,"pointed, chewy, lemonade, medicinal, pecan",16.11,0,true,https://lorempixel.com/200/300/food +Sweet Bread Gummy Bears Coconut,3,"mild, syrupy, clove, peach, brown sugar",72.36,7,true,https://lorempixel.com/200/300/food +Ice Cream Cake Glaze Caramel,3,"muted, full, grapefruit, lychee, orange blossom",84.03,24,true,https://lorempixel.com/200/300/food +Pudding Marshmallows Neapolitan,3,"rounded, slick, banana, cola, snow pea",15.72,28,false,https://lorempixel.com/200/300/food +Doughnut Walnuts Birthday Cake,1,"soft, velvety, red apple, marshmallow, concord grape",91.39,28,true,https://lorempixel.com/200/300/food +Pudding Granola Red Velvet,2,"dull, creamy, pineapple, mint, white grape",46.66,29,false,https://lorempixel.com/200/300/food +Pie Bacon Rocky Road,3,"quick, silky, figs, burnt sugar, rye",97.55,8,true,https://lorempixel.com/200/300/food +Cheesecake Berry Compote Butter Pecan,2,"balanced, tea-like, lemon, lemon verbena, magnolia",93.64,0,true,https://lorempixel.com/200/300/food +Cobbler Toffee Bits Cookies 'n Cream,3,"soft, syrupy, pecan, sage, honeydew",59.69,27,true,https://lorempixel.com/200/300/food +Cake Peanut Butter Funfetti,4,"complex, round, molasses, tobacco, lemongrass",14.64,19,true,https://lorempixel.com/200/300/food +Sweet Bread Gummy Bears Green Tea,3,"sharp, tea-like, grapefruit, peanut, squash",55.56,7,true,https://lorempixel.com/200/300/food +Key Lime Pie Frosting Rocky Road,3,"unbalanced, silky, walnut, butter, mushroom",36.01,19,false,https://lorempixel.com/200/300/food +Doughnut Toffee Bits Salted Caramel,2,"pointed, slick, green grape, raspberry, burnt sugar",90.71,15,true,https://lorempixel.com/200/300/food diff --git a/db/review_seeds.csv b/db/review_seeds.csv index 7bd5aa72d9..bebc6cce86 100644 --- a/db/review_seeds.csv +++ b/db/review_seeds.csv @@ -1,11 +1,11 @@ -rating,description -4,"Oddly it smelled like unbalanced, silky, mango, sage, ginger" -5,"Oddly it smelled like soft, chewy, green-tea, snow pea, corriander" -5,"Oddly it smelled like tart, slick, sweet pea, tangerine, peach" -2,"Oddly it smelled like faint, full, quakery, tomato, rose hips" -2,"Oddly it smelled like tart, round, fresh wood, green apple, sugar cane" -3,"Deliciously flavored structured, tea-like, hops, peach, strawberry" -5,"Oddly it smelled like tart, smooth, tomato, rubber, nutella" -2,"Oddly it smelled like dull, syrupy, rose hips, dates, liquorice" -5,"Deliciously flavored mild, silky, grassy, kiwi, lavender" -5,"Tasted like juicy, syrupy, nutella, orange blossom, cola" +rating,description,product_id +1,"Deliciously flavored deep, creamy, white grape, grapefruit, vanilla",13 +4,"Tasted like unbalanced, round, nutmeg, mushroom, blueberry",6 +2,"Deliciously flavored astringent, creamy, hazelnut, liquorice, grassy",6 +2,"Oddly it smelled like balanced, juicy, nougat, papaya, strawberry",15 +5,"Tasted like tart, creamy, white grape, molasses, clove",9 +3,"Tasted like mild, watery, lime, green pepper, dill",14 +5,"Oddly it smelled like balanced, juicy, cacao nibs, fresh bread, brown sugar",14 +4,"Tasted like vibrant, juicy, cinnamon, bakers chocolate, honeydew",7 +5,"Deliciously flavored lingering, watery, blueberry, green grape, watermelon",3 +5,"Tasted like sharp, chewy, lime, kiwi, tangerine",5 diff --git a/db/schema.rb b/db/schema.rb index 31f3d9eab6..3f9d4a8251 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_181858) do +ActiveRecord::Schema.define(version: 2018_10_19_042229) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,9 +41,9 @@ t.string "status" t.string "cust_name" t.string "cust_email" - t.integer "mailing_address" + t.text "mailing_address" t.string "cc_name" - t.integer "cc_digit" + t.bigint "cc_digit" t.date "cc_expiration" t.integer "cc_cvv" t.integer "cc_zip" @@ -52,22 +52,25 @@ end create_table "products", force: :cascade do |t| - t.string "category" t.string "prod_name" - t.string "description" + t.text "description" t.float "price" t.integer "inv_qty" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "image" t.boolean "active", default: true + t.bigint "user_id" + t.index ["user_id"], name: "index_products_on_user_id" end create_table "reviews", force: :cascade do |t| t.integer "rating" - t.string "description" + t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "product_id" + t.index ["product_id"], name: "index_reviews_on_product_id" end create_table "users", force: :cascade do |t| @@ -78,4 +81,6 @@ t.datetime "updated_at", null: false end + add_foreign_key "products", "users" + add_foreign_key "reviews", "products" end diff --git a/db/seeds.rb b/db/seeds.rb index e2357ac241..f7e0d26619 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,33 +6,27 @@ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) require 'csv' +USER_FILE = Rails.root.join('db', 'user_seeds.csv') +puts "Loading raw review data from #{USER_FILE}" -ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') -puts "Loading raw order data from #{ORDER_FILE}" - -order_failures = [] -CSV.foreach(ORDER_FILE, :headers => true) do |row| - order = Order.new - order.status = row['status'] - order.cust_name = row['cust_name'] - order.cust_email = row['cust_email'] - order.mailing_address = row['mailing_address'] - order.cc_name = row['cc_name'] - order.cc_digit = row['cc_digit'] - order.cc_expiration = row['cc_expiration'] - order.cc_cvv = row['cc_cvv'] - order.cc_zip = row['cc_zip'] - successful = order.save +user_failures = [] +CSV.foreach(USER_FILE, :headers => true) do |row| + user = User.new + user.uid = row['uid'] + user.username = row['username'] + user.email = row['email'] + successful = user.save if !successful - order_failures << order - puts "Failed to save order: #{order.inspect}" + review_failures << user + puts "Failed to save user: #{user.inspect}" + puts "Error: #{user.errors}" else - puts "Created order: #{order.inspect}" + puts "Created user: #{user.inspect}" end end -puts "Added #{Order.count} order records" -puts "#{order_failures.length} order failed to save" +puts "Added #{User.count} user records" +puts "#{user_failures.length} user failed to save" @@ -42,8 +36,8 @@ product_failures = [] CSV.foreach(PRODUCT_FILE, :headers => true) do |row| product = Product.new - product.category = row['category'] product.prod_name = row['prod_name'] + product.user_id = row['user_id'] product.description = row['description'] product.price = row['price'] product.inv_qty = row['inv_qty'] @@ -53,6 +47,7 @@ if !successful product_failures << product puts "Failed to save product: #{product.inspect}" + puts "Error: #{product.errors}" else puts "Created product: #{product.inspect}" end @@ -61,7 +56,39 @@ puts "Added #{Product.count} product records" puts "#{product_failures.length} product failed to save" -REVIEW_FILE = Rails.root.join('db','review_seeds.csv') +ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') +puts "Loading raw order data from #{ORDER_FILE}" + +order_failures = [] +CSV.foreach(ORDER_FILE, :headers => true) do |row| + order = Order.new + order.status = row['status'] + order.cust_name = row['cust_name'] + order.cust_email = row['cust_email'] + order.mailing_address = row['mailing_address'] + order.cc_name = row['cc_name'] + order.cc_digit = row['cc_digit'] + order.cc_expiration = row['cc_expiration'] + order.cc_cvv = row['cc_cvv'] + order.cc_zip = row['cc_zip'] + successful = order.save + if !successful + order_failures << order + puts "Failed to save order: #{order.inspect}" + puts "Error: #{order.errors}" + else + puts "Created order: #{order.inspect}" + end +end + +puts "Added #{Order.count} order records" +puts "#{order_failures.length} order failed to save" + + + + + +REVIEW_FILE = Rails.root.join('db', 'review_seeds.csv') puts "Loading raw review data from #{REVIEW_FILE}" review_failures = [] @@ -69,10 +96,12 @@ review = Review.new review.rating = row['rating'] review.description = row['description'] + review.product_id = row['product_id'] successful = review.save if !successful review_failures << review puts "Failed to save review: #{review.inspect}" + puts "Error: #{review.errors}" else puts "Created review: #{review.inspect}" end @@ -80,3 +109,19 @@ puts "Added #{Review.count} review records" puts "#{review_failures.length} review failed to save" + + + + +#Populate order_items table + +# OrderItem.create(order_id: 2, product_id: 1, qty: 1, shipped: false) +# add 3 items to first order +# Order.first.order_items << Product.sample(3) +# # +# #Populate categories_products table +# Product.all.each do +# Product.categories << Category.all.sample +# end +# # add 3 items to first order +# Product.first.categories << Category.sample(2) diff --git a/db/user_seeds.csv b/db/user_seeds.csv new file mode 100644 index 0000000000..857072cc05 --- /dev/null +++ b/db/user_seeds.csv @@ -0,0 +1,6 @@ +uid,username,email +1,oscar,jayna_lubowitz@example.org +2,arie.heidenreich,kevin@example.com +5,sarah,amado.glover@example.net +2,darin_beahan,linn_thompson@example.com +4,johnnie.boehm,miranda_williamson@example.org diff --git a/test/factories/category.rb b/test/factories/category.rb new file mode 100644 index 0000000000..1c7bc92210 --- /dev/null +++ b/test/factories/category.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :category do + category Faker::Name.first_name + end +end \ No newline at end of file diff --git a/test/factories/user.rb b/test/factories/user.rb new file mode 100644 index 0000000000..d667909da4 --- /dev/null +++ b/test/factories/user.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :user do + name { Faker::Name.first_name } + end +end \ No newline at end of file diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml index b59cc5c7f5..8492e33dc5 100644 --- a/test/fixtures/categories.yml +++ b/test/fixtures/categories.yml @@ -1,7 +1,10 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - category: MyString + category: birthday two: - category: MyString + category: wedding + +three: + category: chocolate diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index ba5adc2dd4..1859032f59 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -1,15 +1,23 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - category: MyString - prod_name: MyString - description: MyString - price: 1.5 - inv_qty: 1 - -two: - category: MyString - prod_name: MyString - description: MyString - price: 1.5 - inv_qty: 1 +cake1: + category: wedding + prod_name: a wedding cake + description: yum + price: 15.5 + inv_qty: 5 + +cake2: + category: chocolate + prod_name: chocolate goodness + description: the best + price: 19.5 + inv_qty: 0 + + +cake3: + category: vanilla + prod_name: vanilla plains + description: real vanilla + price: 20.5 + inv_qty: 3 diff --git a/test/models/category_test.rb b/test/models/category_test.rb index 781320ad8e..9a2ad9c30b 100644 --- a/test/models/category_test.rb +++ b/test/models/category_test.rb @@ -6,4 +6,24 @@ it "must be valid" do value(category).must_be :valid? end + + describe 'validations' do + it 'has required fields' do + fields = [:category] + + fields.each do |field| + expect(book).must_respond_to field + end + end + end + + describe 'relationship' do + let(:product) { products(:cake1) } + it 'belongs to product' do + cat = product.category + + expect(cat).must_be_instance_of Product + expect(cat.id).must_equal product.category_id + end + end end From f154a8dd4055dd519657cf2503168f965071bf77 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Fri, 19 Oct 2018 00:24:27 -0700 Subject: [PATCH 034/192] user session and oauth integration complete --- app/assets/javascripts/sessions.js | 2 + app/assets/stylesheets/sessions.scss | 3 + app/controllers/application_controller.rb | 23 +++++ app/controllers/sessions_controller.rb | 39 ++++++++ app/controllers/users_controller.rb | 94 ++++++++++--------- app/helpers/sessions_helper.rb | 2 + app/models/user.rb | 8 ++ app/views/layouts/application.html.erb | 15 +++ app/views/sessions/destroy.html.erb | 2 + app/views/sessions/login.html.erb | 11 +++ app/views/sessions/new.html.erb | 2 + config/routes.rb | 8 ++ .../20181019064613_add_provider_col_user.rb | 16 ++++ ...181019070105_provider_not_nullable_user.rb | 5 + db/schema.rb | 7 +- test/controllers/sessions_controller_test.rb | 19 ++++ 16 files changed, 207 insertions(+), 49 deletions(-) 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 db/migrate/20181019064613_add_provider_col_user.rb create mode 100644 db/migrate/20181019070105_provider_not_nullable_user.rb 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/application_controller.rb b/app/controllers/application_controller.rb index 13c8b539db..2ca82bbd55 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,7 @@ class ApplicationController < ActionController::Base + before_action :find_user + # before_action :require_login, except: [:create, :root] + helper_method :current_order def current_order @@ -9,4 +12,24 @@ def current_order end end + def render_404 + raise ActionController::RoutingError.new('Not Found') + end + + private + def find_user + if session[:user_id] + @login_user ||= User.find(session[:user_id]) if session[:user_id] + end + end + + + def require_login + if session[:user_id].nil? + flash[:status] = :failure + flash[:result_text] = "You must be logged in to view this section" + redirect_to root_path + end + end end + diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..c0bcc64d66 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,39 @@ +class SessionsController < ApplicationController + # skip_before_action :require_login, only: :create + + def create + 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[:status] = :success + flash[:result_text] = "Successfully logged in as existing user #{user.username}" + else + # User doesn't match anything in the DB + user = User.new_user(auth_hash) + # Attempt to create a new user + if user.save + flash[:status] = :success + flash[:result_text] = "Successfully created new user #{user.username} with ID #{user.id}" + else + flash.now[:status] = :failure + flash.now[:result_text] = "Could not log in" + flash.now[:messages] = user.errors.messages + render "login", status: :bad_request + redirect_to root_path + end + end + + session[:user_id] = user.id + session[:username] = user.username + redirect_to root_path + end + + def destroy + session[:user_id] = nil + flash[:status] = :success + flash[:result_text] = "Successfully logged out" + + redirect_to root_path + end +end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8c9eb329b6..c77fabba68 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -8,6 +8,8 @@ def index # GET /users/1 def show + @user = User.find_by(id: params[:id]) + render_404 unless @user end # GET /users/new @@ -19,50 +21,50 @@ def new def edit end - # POST /users - def create - @user = User.new(user_params) - - respond_to do |format| - if @user.save - format.html { redirect_to @user, notice: 'User was successfully created.' } - format.json { render :show, status: :created, location: @user } - else - format.html { render :new } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /users/1 - def update - respond_to do |format| - if @user.update(user_params) - format.html { redirect_to @user, notice: 'User was successfully updated.' } - format.json { render :show, status: :ok, location: @user } - else - format.html { render :edit } - format.json { render json: @user.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /users/1 - def destroy - @user.destroy - respond_to do |format| - format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_user - @user = User.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def user_params - params.require(:user).permit(:uid, :username, :email) - end + # # POST /users + # def create + # @user = User.new(user_params) + # + # respond_to do |format| + # if @user.save + # format.html { redirect_to @user, notice: 'User was successfully created.' } + # format.json { render :show, status: :created, location: @user } + # else + # format.html { render :new } + # format.json { render json: @user.errors, status: :unprocessable_entity } + # end + # end + # end + # + # # PATCH/PUT /users/1 + # def update + # respond_to do |format| + # if @user.update(user_params) + # format.html { redirect_to @user, notice: 'User was successfully updated.' } + # format.json { render :show, status: :ok, location: @user } + # else + # format.html { render :edit } + # format.json { render json: @user.errors, status: :unprocessable_entity } + # end + # end + # end + # + # # DELETE /users/1 + # def destroy + # @user.destroy + # respond_to do |format| + # format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + # end + # end + # + # private + # # Use callbacks to share common setup or constraints between actions. + # def set_user + # @user = User.find(params[:id]) + # end + # + # # Never trust parameters from the scary internet, only allow the white list through. + # def user_params + # params.require(:user).permit(:uid, :username, :email) + # 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/models/user.rb b/app/models/user.rb index 6d0c7f08f3..19b6bf07dd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,5 +5,13 @@ class User < ApplicationRecord # relationships has_many :products + def self.new_user(auth_hash) + new_user = User.new(email: auth_hash[:info][:email], + username: auth_hash[:info][:nickname], + uid: auth_hash[:uid], + provider: 'github') + + return new_user + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a77d078ac3..9a271666ce 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -36,7 +36,22 @@
+ -
diff --git a/config/routes.rb b/config/routes.rb index adea8cf7bf..2ba2ab14e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - root "products#index" + root 'products#home' get "/auth/:provider/callback", to: "sessions#create" @@ -11,8 +11,6 @@ resources :carts, only: [:show] resources :order_items, only: [:create, :update, :destroy] - root 'products#home' - resources :reviews resources :orders resources :products diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb index 50be8fcf5c..510c564dcb 100644 --- a/db/generate_seeds.rb +++ b/db/generate_seeds.rb @@ -73,4 +73,3 @@ csv << [status, cust_name, cust_email, mailing_address, cc_name, cc_digit, cc_expiration, cc_cvv, cc_zip] end end - diff --git a/db/migrate/20181019215535_change_null_user_provider.rb b/db/migrate/20181019215535_change_null_user_provider.rb new file mode 100644 index 0000000000..39203a422a --- /dev/null +++ b/db/migrate/20181019215535_change_null_user_provider.rb @@ -0,0 +1,5 @@ +class ChangeNullUserProvider < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string, null: true + end +end diff --git a/db/order_seeds.csv b/db/order_seeds.csv index 1130c1cfaa..ee85190734 100644 --- a/db/order_seeds.csv +++ b/db/order_seeds.csv @@ -1,11 +1,11 @@ status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip -pending,Thorgy Thor,willa@example.com,"5493 Emely Branch, Feilchester, WI 17591-1680",Ilene North,9675258621115789,2019-10-18,197,54820 -cancelled,Jujubee,vannesa_treutel@example.net,"Suite 470 446 Volkman Stravenue, Wymanhaven, VT 40432-0667",Darren Deeds,4994537217918278,2022-10-17,492,48391 -complete,Farrah Moan,wilburn@example.com,"Apt. 701 5457 Mellissa Locks, South Salvador, DE 91591",Howie Doohan,6046910104486392,2019-10-18,671,47996 -cancelled,BenDeLaCreme,hung@example.org,"8006 Mayert Creek, Port Boydburgh, GA 67344-0146",Chanda Lear,5705706804044600,2021-10-17,410,81845 -pending,Phi Phi O'Hara,wendell@example.com,"229 Stehr Islands, New Karin, AZ 69278-0408",Ilene Left,9725219929234895,2020-10-17,616,52259 -pending,Alyssa Edwards,jacinda@example.org,"6897 Reichel Manor, East Carroll, KY 63730-3126",Evans Gayte,6722041749449069,2022-10-17,157,18554 -pending,Alaska,shaina_parker@example.com,"Apt. 476 67391 Beer Road, North Reubenburgh, RI 28019",Rusty Steele,1149577765372457,2021-10-17,402,22706 -complete,Chad Michaels,sam.jast@example.net,"984 Ruthe Summit, South Dwight, VA 25459",M. Balmer,7121448368152429,2020-10-17,122,44807 -paid,Acid Betty,moises@example.org,"Suite 618 2906 Fritz Locks, New Josette, AL 93558",Sarah Bellum,3208164991667526,2019-10-18,610,62312 -pending,Pandora Boxx,kelley@example.org,"Apt. 118 7556 German Place, Xiaohaven, AL 36947-4162",Joe King,8968566940150310,2020-10-17,306,26539 +paid,Cynthia Lee Fontaine,senaida.denesik@example.org,"177 Homenick Green, Ornton, RI 34675",Haywood Jashootmee,4754273727523216,2020-10-18,337,95469 +paid,Robbie Turner,marilu.orn@example.com,"Apt. 537 5818 Bashirian Parkways, Schimmelborough, NH 60022",Jay Bird,8366675421429518,2021-10-18,503,64253 +complete,Willam,evan.sanford@example.org,"Apt. 579 21108 Romaguera Streets, Wernerton, VA 55952-6463",Bea Lowe,8391310779425036,2020-10-18,505,18693 +complete,Robbie Turner,kristen@example.com,"Apt. 858 44579 Klein Estate, South Beatriceport, WI 53692-4114",Sal Ami,1998157122694545,2019-10-19,357,86806 +pending,Aja,salvador@example.com,"82705 Cesar Alley, West Julianne, FL 52280-7511",Sue Jeu,1701549691688109,2022-10-18,182,24283 +paid,Laganja Estranja,jenee.armstrong@example.net,"Suite 527 129 Hugo View, Kristenport, CT 52543",Sarah Bellum,3683520186659493,2020-10-18,703,77235 +paid,Trinity Taylor,rosendo@example.org,"69345 Greenfelder Branch, North Fairyborough, FL 34289",Ilene Dover,7411654544283191,2019-10-19,322,23781 +paid,Aja,edna_ullrich@example.com,"40351 Reinger Falls, West Stacey, SC 77500-7297",Bart Ender,2236576507485718,2019-10-19,415,72313 +cancelled,Delta Work,jere_treutel@example.com,"4012 Charlott Estate, Bruenfort, NC 14030-6143",Bea Sting,7007152551899496,2020-10-18,275,26593 +complete,Jinkx Monsoon,dante.heel@example.net,"Suite 426 951 Antoine Lake, Port Lamontchester, MS 78369-1701",Will Power,6651824002750866,2020-10-18,101,81022 diff --git a/db/product_seeds.csv b/db/product_seeds.csv index 0065046b80..41a69c5f20 100644 --- a/db/product_seeds.csv +++ b/db/product_seeds.csv @@ -1,31 +1,31 @@ prod_name,user_id,description,price,inv_qty,active,image -Sweet Bread Marshmallows Peanut Butter,1,"lingering, watery, almond, concord grape, almond",41.62,8,false,https://lorempixel.com/200/300/food -Cobbler Gummy Bears Pistachio,1,"lingering, chewy, lemon verbena, concord grape, golden raisin",31.68,10,true,https://lorempixel.com/200/300/food -Cake Toffee Bits Mint Chocolate Chip,3,"structured, full, marzipan, cinnamon, black currant",68.56,12,false,https://lorempixel.com/200/300/food -Cheesecake Berry Compote Birthday Cake,1,"vibrant, juicy, kiwi, nutella, soy sauce",49.24,28,true,https://lorempixel.com/200/300/food -Frozen Yogurt Cookie Dough Strawberry,2,"vibrant, chewy, honeysuckle, maple syrup, white pepper",26.09,5,false,https://lorempixel.com/200/300/food -Cupcake Peanuts Chocolate,1,"deep, round, lemon, soil, bittersweet chocolate",72.45,25,true,https://lorempixel.com/200/300/food -Upside Down Pineapple Cake Gummy Bears Lemon,3,"dull, full, cedar, clementine, molasses",86.88,18,false,https://lorempixel.com/200/300/food -Cookie Berry Compote Neapolitan,4,"complex, silky, lemon, star fruit, bittersweet chocolate",22.42,15,true,https://lorempixel.com/200/300/food -Key Lime Pie Glaze Apple,1,"mild, full, cacao nibs, curry, peach",97.65,13,false,https://lorempixel.com/200/300/food -Ice Cream Cake Chocolate Syrup Vanilla,2,"clean, watery, milk chocolate, nutmeg, sweet pea",67.38,13,false,https://lorempixel.com/200/300/food -Cobbler Butterscotch Syrup Cheesecake,4,"rounded, full, grapefruit, curry, peanut",65.75,21,true,https://lorempixel.com/200/300/food -Ice Cream Caramel Chocolate Chip Cookie Dough,4,"delicate, round, mango, quakery, lemon verbena",99.79,23,false,https://lorempixel.com/200/300/food -Doughnut Chocolate Syrup Butter Pecan,2,"mild, watery, tobacco, hazelnut, hay",76.99,13,true,https://lorempixel.com/200/300/food -Coffee Cake Walnuts Neapolitan,3,"dense, big, potato defect!, bakers chocolate, wheat",64.28,18,true,https://lorempixel.com/200/300/food -Trifle Marshmallows Chocolate Chip Cookie Dough,1,"wild, watery, grassy, raisin, peanut",87.35,23,true,https://lorempixel.com/200/300/food -Sundae Cookie Dough Almond,4,"dirty, syrupy, lemonade, lemon, nutmeg",79.92,0,true,https://lorempixel.com/200/300/food -Cupcake Berry Compote Cookies 'n Cream,1,"clean, creamy, sage, sundried tomato, lemongrass",72.88,12,false,https://lorempixel.com/200/300/food -Upside Down Pineapple Cake Peanut Butter Butter Pecan,3,"pointed, chewy, lemonade, medicinal, pecan",16.11,0,true,https://lorempixel.com/200/300/food -Sweet Bread Gummy Bears Coconut,3,"mild, syrupy, clove, peach, brown sugar",72.36,7,true,https://lorempixel.com/200/300/food -Ice Cream Cake Glaze Caramel,3,"muted, full, grapefruit, lychee, orange blossom",84.03,24,true,https://lorempixel.com/200/300/food -Pudding Marshmallows Neapolitan,3,"rounded, slick, banana, cola, snow pea",15.72,28,false,https://lorempixel.com/200/300/food -Doughnut Walnuts Birthday Cake,1,"soft, velvety, red apple, marshmallow, concord grape",91.39,28,true,https://lorempixel.com/200/300/food -Pudding Granola Red Velvet,2,"dull, creamy, pineapple, mint, white grape",46.66,29,false,https://lorempixel.com/200/300/food -Pie Bacon Rocky Road,3,"quick, silky, figs, burnt sugar, rye",97.55,8,true,https://lorempixel.com/200/300/food -Cheesecake Berry Compote Butter Pecan,2,"balanced, tea-like, lemon, lemon verbena, magnolia",93.64,0,true,https://lorempixel.com/200/300/food -Cobbler Toffee Bits Cookies 'n Cream,3,"soft, syrupy, pecan, sage, honeydew",59.69,27,true,https://lorempixel.com/200/300/food -Cake Peanut Butter Funfetti,4,"complex, round, molasses, tobacco, lemongrass",14.64,19,true,https://lorempixel.com/200/300/food -Sweet Bread Gummy Bears Green Tea,3,"sharp, tea-like, grapefruit, peanut, squash",55.56,7,true,https://lorempixel.com/200/300/food -Key Lime Pie Frosting Rocky Road,3,"unbalanced, silky, walnut, butter, mushroom",36.01,19,false,https://lorempixel.com/200/300/food -Doughnut Toffee Bits Salted Caramel,2,"pointed, slick, green grape, raspberry, burnt sugar",90.71,15,true,https://lorempixel.com/200/300/food +Fruit Cake Chocolate Sprinkles Butterscotch,3,"quick, syrupy, mushroom, burnt sugar, milk chocolate",61.17,21,true,https://lorempixel.com/200/300/food +Trifle Chocolate Chips Cherry,1,"sharp, round, green grape, plum, marzipan",81.33,5,false,https://lorempixel.com/200/300/food +Coffee Cake Caramel Chocolate Chip Cookie Dough,4,"dry, juicy, orange blossom, ginger, passion fruit",24.69,18,false,https://lorempixel.com/200/300/food +Ice Cream Granola Mint Chocolate Chip,1,"dull, tea-like, curry, graham cracker, burnt sugar",88.22,27,true,https://lorempixel.com/200/300/food +Cookie Granola Chocolate,3,"pointed, slick, golden raisin, soy sauce, pecan",49.86,20,true,https://lorempixel.com/200/300/food +Cupcake Berry Compote Oatmeal,4,"faint, coating, coconut, grapefruit, grapefruit",33.27,7,false,https://lorempixel.com/200/300/food +Cupcake Powdered Sugar Green Tea,2,"clean, watery, mango, watermelon, nutella",80.01,19,false,https://lorempixel.com/200/300/food +Ice Cream Cake Glaze Green Tea,4,"crisp, smooth, blueberry, pecan, milk chocolate",78.64,15,false,https://lorempixel.com/200/300/food +Pie Peanut Butter French Vanilla,3,"tart, full, apricot, soy sauce, meyer lemon",33.25,9,true,https://lorempixel.com/200/300/food +Cake Pop Whipped Cream Rocky Road,2,"faint, juicy, blueberry, passion fruit, cantaloupe",97.84,18,true,https://lorempixel.com/200/300/food +Cake Cinnamon Cherry,4,"muted, velvety, cashew, grassy, lemon",52.32,28,false,https://lorempixel.com/200/300/food +Pie Chocolate Chips Pistachio,4,"pointed, full, tobacco, mango, hay",76.47,16,true,https://lorempixel.com/200/300/food +Cookie Mocha Drizzle Caramel,2,"unbalanced, big, dill, orange blossom, prune",56.19,2,false,https://lorempixel.com/200/300/food +Cake Pop Berry Compote Funfetti,4,"tart, coating, honey, soy sauce, golden raisin",34.28,26,false,https://lorempixel.com/200/300/food +Cobbler Toffee Bits Vanilla,4,"quick, coating, butter, cola, barley",91.16,25,false,https://lorempixel.com/200/300/food +Cookie Toffee Bits Cheesecake,1,"juicy, full, sage, clementine, hibiscus",39.69,25,true,https://lorempixel.com/200/300/food +Sweet Bread Berry Compote Red Velvet,3,"quick, watery, clove, clementine, honeysuckle",44.89,27,false,https://lorempixel.com/200/300/food +Key Lime Pie Glaze Chocolate,4,"unbalanced, coating, pineapple, curry, lemon",97.39,17,true,https://lorempixel.com/200/300/food +Brownie Berry Compote Banana,3,"rounded, round, baggy, meyer lemon, granola",41.57,2,false,https://lorempixel.com/200/300/food +Brownie Frosting Rocky Road,4,"soft, round, bakers chocolate, musty, grapefruit",71.52,5,true,https://lorempixel.com/200/300/food +Cake Chocolate Chips Butter Pecan,1,"pointed, full, toast, prune, green-tea",60.26,20,true,https://lorempixel.com/200/300/food +Cheesecake Rainbow Sprinkles Green Tea,1,"astringent, big, raisin, sugar cane, smokey",68.83,30,true,https://lorempixel.com/200/300/food +Cake Pop Caramel Caramel,3,"dirty, silky, corriander, fresh bread, butter",56.11,18,false,https://lorempixel.com/200/300/food +Sweet Bread Bacon Butter Pecan,2,"faint, round, honeydew, mango, smokey",35.32,23,true,https://lorempixel.com/200/300/food +Cupcake Marshmallows Red Velvet,3,"unbalanced, velvety, prune, ginger, sugar cane",40.45,6,true,https://lorempixel.com/200/300/food +Ice Cream Cake Toffee Bits Caramel,4,"rounded, velvety, nutella, hops, burnt sugar",52.75,13,true,https://lorempixel.com/200/300/food +Cupcake Whipped Cream Peanut Butter,1,"structured, tea-like, maple syrup, carmel, jasmine",33.54,22,false,https://lorempixel.com/200/300/food +Ice Cream Cake Chocolate Syrup Cookies 'n Cream,2,"mild, full, molasses, clementine, magnolia",33.12,1,false,https://lorempixel.com/200/300/food +Pudding Gummy Bears Almond,3,"balanced, smooth, molasses, honeysuckle, sage",80.17,11,false,https://lorempixel.com/200/300/food +Frozen Yogurt Cookie Dough Banana,1,"crisp, syrupy, sage, honey, green grape",28.84,8,false,https://lorempixel.com/200/300/food diff --git a/db/review_seeds.csv b/db/review_seeds.csv index bebc6cce86..0f81504e0a 100644 --- a/db/review_seeds.csv +++ b/db/review_seeds.csv @@ -1,11 +1,11 @@ rating,description,product_id -1,"Deliciously flavored deep, creamy, white grape, grapefruit, vanilla",13 -4,"Tasted like unbalanced, round, nutmeg, mushroom, blueberry",6 -2,"Deliciously flavored astringent, creamy, hazelnut, liquorice, grassy",6 -2,"Oddly it smelled like balanced, juicy, nougat, papaya, strawberry",15 -5,"Tasted like tart, creamy, white grape, molasses, clove",9 -3,"Tasted like mild, watery, lime, green pepper, dill",14 -5,"Oddly it smelled like balanced, juicy, cacao nibs, fresh bread, brown sugar",14 -4,"Tasted like vibrant, juicy, cinnamon, bakers chocolate, honeydew",7 -5,"Deliciously flavored lingering, watery, blueberry, green grape, watermelon",3 -5,"Tasted like sharp, chewy, lime, kiwi, tangerine",5 +3,"Oddly it smelled like deep, tea-like, clementine, sugar cane, passion fruit",3 +5,"Deliciously flavored pointed, juicy, grapefruit, marshmallow, squash",13 +4,"Oddly it smelled like sharp, full, bittersweet chocolate, green grape, quakery",11 +4,"Tasted like sharp, full, apricot, vanilla, cantaloupe",11 +4,"Oddly it smelled like dense, smooth, clove, lychee, almond",12 +3,"Oddly it smelled like dense, creamy, plum, lemon, black pepper",11 +2,"Tasted like mild, big, barley, bittersweet chocolate, banana",11 +1,"Oddly it smelled like rounded, juicy, maple syrup, honeysuckle, jasmine",12 +2,"Deliciously flavored rounded, velvety, corriander, lime, squash",11 +2,"Deliciously flavored pointed, velvety, red apple, lemon verbena, green apple",11 diff --git a/db/schema.rb b/db/schema.rb index 06f16b7dcc..8a77e95596 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_19_070105) do +ActiveRecord::Schema.define(version: 2018_10_19_215535) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -79,7 +79,7 @@ t.string "email" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "provider", null: false + t.string "provider" end add_foreign_key "products", "users" diff --git a/db/user_seeds.csv b/db/user_seeds.csv index 857072cc05..85c9a6abbf 100644 --- a/db/user_seeds.csv +++ b/db/user_seeds.csv @@ -1,6 +1,6 @@ uid,username,email -1,oscar,jayna_lubowitz@example.org -2,arie.heidenreich,kevin@example.com -5,sarah,amado.glover@example.net -2,darin_beahan,linn_thompson@example.com -4,johnnie.boehm,miranda_williamson@example.org +3,jennette_bradtke,felix@example.org +1,elana_schneider,brittanie@example.net +1,lorean_pfeffer,lakeshia@example.org +3,margarito_white,michael@example.org +1,delphia,terica@example.org From d600459e0c651ebc900e663db530392b94755616 Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 19 Oct 2018 15:20:52 -0700 Subject: [PATCH 043/192] updated faker --- Gemfile | 2 +- Gemfile.lock | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 5b76ff157c..3ec7b66dd4 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,7 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] - gem 'faker', git: 'https://github.com/stympy/faker' + gem 'faker' gem 'dotenv-rails' end diff --git a/Gemfile.lock b/Gemfile.lock index c0bfb7391a..51bd558f59 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/stympy/faker - revision: 069817eb06825b10f8e74f83ef2c50a001b72d96 - specs: - faker (1.9.1) - i18n (>= 0.7) - GEM remote: https://rubygems.org/ specs: @@ -99,6 +92,8 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) + faker (1.9.1) + i18n (>= 0.7) faraday (0.15.3) multipart-post (>= 1.2, < 3) ffi (1.9.25) @@ -289,7 +284,7 @@ DEPENDENCIES dotenv-rails factory_bot factory_bot_rails - faker! + faker guard guard-minitest jbuilder (~> 2.5) @@ -317,4 +312,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.5 + 1.16.6 From ae65e5f5cf0100ca77091dc42e417ddcf8b5f0c8 Mon Sep 17 00:00:00 2001 From: Jazz Date: Fri, 19 Oct 2018 15:36:15 -0700 Subject: [PATCH 044/192] hide index page, add github logo --- app/controllers/application_controller.rb | 2 +- app/views/users/{index.html.erb => notinuse.html.erb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename app/views/users/{index.html.erb => notinuse.html.erb} (100%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2ca82bbd55..934c50ff02 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -31,5 +31,5 @@ def require_login redirect_to root_path end end -end +end diff --git a/app/views/users/index.html.erb b/app/views/users/notinuse.html.erb similarity index 100% rename from app/views/users/index.html.erb rename to app/views/users/notinuse.html.erb From b555c6d1a5f5310c41d95a288b4f23f1d951d31d Mon Sep 17 00:00:00 2001 From: Trang Date: Fri, 19 Oct 2018 16:28:01 -0700 Subject: [PATCH 045/192] add category to seeds --- Gemfile | 2 +- Gemfile.lock | 11 +--- config/routes.rb | 6 +- db/category_seeds.csv | 6 ++ db/generate_seeds.rb | 1 - ...20181019215725_change_provider_in_users.rb | 5 ++ db/order_seeds.csv | 20 +++---- db/product_seeds.csv | 60 +++++++++---------- db/review_seeds.csv | 20 +++---- db/schema.rb | 4 +- db/seeds.rb | 33 ++++++++-- db/user_seeds.csv | 10 ++-- 12 files changed, 103 insertions(+), 75 deletions(-) create mode 100644 db/category_seeds.csv create mode 100644 db/migrate/20181019215725_change_provider_in_users.rb diff --git a/Gemfile b/Gemfile index 5b76ff157c..3ec7b66dd4 100644 --- a/Gemfile +++ b/Gemfile @@ -47,7 +47,7 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] - gem 'faker', git: 'https://github.com/stympy/faker' + gem 'faker' gem 'dotenv-rails' end diff --git a/Gemfile.lock b/Gemfile.lock index c0bfb7391a..61bdeaf8f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/stympy/faker - revision: 069817eb06825b10f8e74f83ef2c50a001b72d96 - specs: - faker (1.9.1) - i18n (>= 0.7) - GEM remote: https://rubygems.org/ specs: @@ -99,6 +92,8 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) + faker (1.9.1) + i18n (>= 0.7) faraday (0.15.3) multipart-post (>= 1.2, < 3) ffi (1.9.25) @@ -289,7 +284,7 @@ DEPENDENCIES dotenv-rails factory_bot factory_bot_rails - faker! + faker guard guard-minitest jbuilder (~> 2.5) diff --git a/config/routes.rb b/config/routes.rb index adea8cf7bf..c4f369b6ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do - root "products#index" - + root 'products#home' + get "/auth/:provider/callback", to: "sessions#create" get 'sessions/login', to: "sessions#new" #page for a new session @@ -11,7 +11,7 @@ resources :carts, only: [:show] resources :order_items, only: [:create, :update, :destroy] - root 'products#home' + resources :reviews resources :orders diff --git a/db/category_seeds.csv b/db/category_seeds.csv new file mode 100644 index 0000000000..a3b13693b2 --- /dev/null +++ b/db/category_seeds.csv @@ -0,0 +1,6 @@ +id,category +1,cake +2,pie +3,cupcake +4,cookie +5,ice cream diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb index 50be8fcf5c..510c564dcb 100644 --- a/db/generate_seeds.rb +++ b/db/generate_seeds.rb @@ -73,4 +73,3 @@ csv << [status, cust_name, cust_email, mailing_address, cc_name, cc_digit, cc_expiration, cc_cvv, cc_zip] end end - diff --git a/db/migrate/20181019215725_change_provider_in_users.rb b/db/migrate/20181019215725_change_provider_in_users.rb new file mode 100644 index 0000000000..b3dd455255 --- /dev/null +++ b/db/migrate/20181019215725_change_provider_in_users.rb @@ -0,0 +1,5 @@ +class ChangeProviderInUsers < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string, null: true + end +end diff --git a/db/order_seeds.csv b/db/order_seeds.csv index 1130c1cfaa..c91fc198b8 100644 --- a/db/order_seeds.csv +++ b/db/order_seeds.csv @@ -1,11 +1,11 @@ status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip -pending,Thorgy Thor,willa@example.com,"5493 Emely Branch, Feilchester, WI 17591-1680",Ilene North,9675258621115789,2019-10-18,197,54820 -cancelled,Jujubee,vannesa_treutel@example.net,"Suite 470 446 Volkman Stravenue, Wymanhaven, VT 40432-0667",Darren Deeds,4994537217918278,2022-10-17,492,48391 -complete,Farrah Moan,wilburn@example.com,"Apt. 701 5457 Mellissa Locks, South Salvador, DE 91591",Howie Doohan,6046910104486392,2019-10-18,671,47996 -cancelled,BenDeLaCreme,hung@example.org,"8006 Mayert Creek, Port Boydburgh, GA 67344-0146",Chanda Lear,5705706804044600,2021-10-17,410,81845 -pending,Phi Phi O'Hara,wendell@example.com,"229 Stehr Islands, New Karin, AZ 69278-0408",Ilene Left,9725219929234895,2020-10-17,616,52259 -pending,Alyssa Edwards,jacinda@example.org,"6897 Reichel Manor, East Carroll, KY 63730-3126",Evans Gayte,6722041749449069,2022-10-17,157,18554 -pending,Alaska,shaina_parker@example.com,"Apt. 476 67391 Beer Road, North Reubenburgh, RI 28019",Rusty Steele,1149577765372457,2021-10-17,402,22706 -complete,Chad Michaels,sam.jast@example.net,"984 Ruthe Summit, South Dwight, VA 25459",M. Balmer,7121448368152429,2020-10-17,122,44807 -paid,Acid Betty,moises@example.org,"Suite 618 2906 Fritz Locks, New Josette, AL 93558",Sarah Bellum,3208164991667526,2019-10-18,610,62312 -pending,Pandora Boxx,kelley@example.org,"Apt. 118 7556 German Place, Xiaohaven, AL 36947-4162",Joe King,8968566940150310,2020-10-17,306,26539 +paid,Darienne Lake,rico.ryan@example.net,"Suite 960 578 Marvin Park, West Astridstad, MT 01415",Lisa Ford,6035639394729400,2019-10-19,389,14426 +pending,Ivy Winters,nyla_franecki@example.com,"5674 Reilly Harbors, North Robtstad, MI 99155-6727",Raney Schauer,8457979720710740,2019-10-19,159,53937 +pending,Shangela Wadley,jettie@example.com,"Apt. 969 46932 Hilario Valley, West Argelia, VA 43770",Corey Ander,2007884983346426,2020-10-18,549,98342 +pending,Gia Gunn,dacia.kuvalis@example.com,"Apt. 759 7349 Patsy Causeway, East Britt, CT 35870-2289",Harry Caray,2770308763453191,2022-10-18,975,78875 +pending,Pandora Boxx,terica@example.org,"Apt. 648 80138 Benita Ranch, Koelpinport, TX 48639",Dan Deline,5641993516865447,2021-10-18,575,60845 +complete,Courtney Act,ashly@example.com,"35916 Suk Meadow, Jamelburgh, GA 97021-3752",Doug Graves,7338489640103556,2020-10-18,634,14112 +cancelled,Raven,elijah@example.org,"434 Feil Track, North Lorenza, NE 65653",Otto Carr,4654686111473618,2021-10-18,680,57067 +cancelled,Willam,ester_boyer@example.com,"2533 Treutel Stream, East Staciabury, CT 84859-0331",Sal Ami,8428384784025760,2022-10-18,349,88220 +complete,Alaska,jospeh_murphy@example.com,"279 Burma Lock, North Dallasland, WI 22415-0417",Howie Doohan,2114720957413829,2019-10-19,165,77757 +paid,Ginger Minj,justin.herman@example.org,"Apt. 252 29289 Marcene Row, Giselaport, HI 92110-8091",Dee Kay,2236090706908599,2020-10-18,407,71607 diff --git a/db/product_seeds.csv b/db/product_seeds.csv index 0065046b80..4cb9916109 100644 --- a/db/product_seeds.csv +++ b/db/product_seeds.csv @@ -1,31 +1,31 @@ prod_name,user_id,description,price,inv_qty,active,image -Sweet Bread Marshmallows Peanut Butter,1,"lingering, watery, almond, concord grape, almond",41.62,8,false,https://lorempixel.com/200/300/food -Cobbler Gummy Bears Pistachio,1,"lingering, chewy, lemon verbena, concord grape, golden raisin",31.68,10,true,https://lorempixel.com/200/300/food -Cake Toffee Bits Mint Chocolate Chip,3,"structured, full, marzipan, cinnamon, black currant",68.56,12,false,https://lorempixel.com/200/300/food -Cheesecake Berry Compote Birthday Cake,1,"vibrant, juicy, kiwi, nutella, soy sauce",49.24,28,true,https://lorempixel.com/200/300/food -Frozen Yogurt Cookie Dough Strawberry,2,"vibrant, chewy, honeysuckle, maple syrup, white pepper",26.09,5,false,https://lorempixel.com/200/300/food -Cupcake Peanuts Chocolate,1,"deep, round, lemon, soil, bittersweet chocolate",72.45,25,true,https://lorempixel.com/200/300/food -Upside Down Pineapple Cake Gummy Bears Lemon,3,"dull, full, cedar, clementine, molasses",86.88,18,false,https://lorempixel.com/200/300/food -Cookie Berry Compote Neapolitan,4,"complex, silky, lemon, star fruit, bittersweet chocolate",22.42,15,true,https://lorempixel.com/200/300/food -Key Lime Pie Glaze Apple,1,"mild, full, cacao nibs, curry, peach",97.65,13,false,https://lorempixel.com/200/300/food -Ice Cream Cake Chocolate Syrup Vanilla,2,"clean, watery, milk chocolate, nutmeg, sweet pea",67.38,13,false,https://lorempixel.com/200/300/food -Cobbler Butterscotch Syrup Cheesecake,4,"rounded, full, grapefruit, curry, peanut",65.75,21,true,https://lorempixel.com/200/300/food -Ice Cream Caramel Chocolate Chip Cookie Dough,4,"delicate, round, mango, quakery, lemon verbena",99.79,23,false,https://lorempixel.com/200/300/food -Doughnut Chocolate Syrup Butter Pecan,2,"mild, watery, tobacco, hazelnut, hay",76.99,13,true,https://lorempixel.com/200/300/food -Coffee Cake Walnuts Neapolitan,3,"dense, big, potato defect!, bakers chocolate, wheat",64.28,18,true,https://lorempixel.com/200/300/food -Trifle Marshmallows Chocolate Chip Cookie Dough,1,"wild, watery, grassy, raisin, peanut",87.35,23,true,https://lorempixel.com/200/300/food -Sundae Cookie Dough Almond,4,"dirty, syrupy, lemonade, lemon, nutmeg",79.92,0,true,https://lorempixel.com/200/300/food -Cupcake Berry Compote Cookies 'n Cream,1,"clean, creamy, sage, sundried tomato, lemongrass",72.88,12,false,https://lorempixel.com/200/300/food -Upside Down Pineapple Cake Peanut Butter Butter Pecan,3,"pointed, chewy, lemonade, medicinal, pecan",16.11,0,true,https://lorempixel.com/200/300/food -Sweet Bread Gummy Bears Coconut,3,"mild, syrupy, clove, peach, brown sugar",72.36,7,true,https://lorempixel.com/200/300/food -Ice Cream Cake Glaze Caramel,3,"muted, full, grapefruit, lychee, orange blossom",84.03,24,true,https://lorempixel.com/200/300/food -Pudding Marshmallows Neapolitan,3,"rounded, slick, banana, cola, snow pea",15.72,28,false,https://lorempixel.com/200/300/food -Doughnut Walnuts Birthday Cake,1,"soft, velvety, red apple, marshmallow, concord grape",91.39,28,true,https://lorempixel.com/200/300/food -Pudding Granola Red Velvet,2,"dull, creamy, pineapple, mint, white grape",46.66,29,false,https://lorempixel.com/200/300/food -Pie Bacon Rocky Road,3,"quick, silky, figs, burnt sugar, rye",97.55,8,true,https://lorempixel.com/200/300/food -Cheesecake Berry Compote Butter Pecan,2,"balanced, tea-like, lemon, lemon verbena, magnolia",93.64,0,true,https://lorempixel.com/200/300/food -Cobbler Toffee Bits Cookies 'n Cream,3,"soft, syrupy, pecan, sage, honeydew",59.69,27,true,https://lorempixel.com/200/300/food -Cake Peanut Butter Funfetti,4,"complex, round, molasses, tobacco, lemongrass",14.64,19,true,https://lorempixel.com/200/300/food -Sweet Bread Gummy Bears Green Tea,3,"sharp, tea-like, grapefruit, peanut, squash",55.56,7,true,https://lorempixel.com/200/300/food -Key Lime Pie Frosting Rocky Road,3,"unbalanced, silky, walnut, butter, mushroom",36.01,19,false,https://lorempixel.com/200/300/food -Doughnut Toffee Bits Salted Caramel,2,"pointed, slick, green grape, raspberry, burnt sugar",90.71,15,true,https://lorempixel.com/200/300/food +Cobbler Butterscotch Syrup Salted Caramel,1,"balanced, big, leathery, cashew, banana",17.93,14,false,https://lorempixel.com/200/300/food +Cake Pop Mocha Drizzle Pistachio,4,"wild, full, clove, pecan, grapefruit",34.93,16,true,https://lorempixel.com/200/300/food +Cake Mocha Drizzle French Vanilla,2,"dirty, big, black-tea, cream, quakery",99.04,15,true,https://lorempixel.com/200/300/food +Brownie Gummy Bears Rocky Road,2,"dense, juicy, black cherry, fresh bread, coconut",85.48,22,true,https://lorempixel.com/200/300/food +Fruit Cake Powdered Sugar Butterscotch,4,"complex, smooth, honey, corriander, green pepper",17.93,2,true,https://lorempixel.com/200/300/food +Coffee Cake Cheesecake Bites Funfetti,4,"unbalanced, chewy, green apple, sundried tomato, black-tea",72.12,2,true,https://lorempixel.com/200/300/food +Trifle Chocolate Syrup Vanilla,1,"muted, tea-like, honey, lemon, tomato",91.77,3,false,https://lorempixel.com/200/300/food +Sweet Bread Powdered Sugar Lemon,2,"dry, velvety, green apple, hops, lime",26.16,23,false,https://lorempixel.com/200/300/food +Cheesecake Berry Compote Blondie,4,"clean, creamy, dill, dates, jasmine",77.23,8,false,https://lorempixel.com/200/300/food +Cupcake Marshmallows Butter Pecan,4,"dry, smooth, black-tea, honeysuckle, white pepper",21.23,21,true,https://lorempixel.com/200/300/food +Pie Cookie Dough Caramel,3,"delicate, silky, toast, sundried tomato, milk chocolate",76.19,25,true,https://lorempixel.com/200/300/food +Sundae Walnuts Butter Pecan,1,"muted, velvety, rose hips, magnolia, ginger",30.24,3,true,https://lorempixel.com/200/300/food +Pie Butterscotch Syrup Butterscotch,3,"bright, coating, musty, grassy, dill",42.11,17,true,https://lorempixel.com/200/300/food +Doughnut Granola Mint Chocolate Chip,2,"bright, creamy, milk chocolate, marzipan, bakers chocolate",42.14,30,true,https://lorempixel.com/200/300/food +Ice Cream Chocolate Chips Butter Pecan,2,"muted, silky, mint, peach, cocoa powder",43.21,5,false,https://lorempixel.com/200/300/food +Doughnut Berry Compote Apple,2,"wild, juicy, grapefruit, lavender, vanilla",90.84,12,false,https://lorempixel.com/200/300/food +Cake Chocolate Chips Coconut,1,"clean, velvety, kiwi, figs, cedar",39.53,5,true,https://lorempixel.com/200/300/food +Cupcake Glaze Apple,1,"clean, syrupy, lavender, barley, passion fruit",40.34,28,false,https://lorempixel.com/200/300/food +Cobbler Bacon Cheesecake,4,"unbalanced, syrupy, musty, potato defect!, cocoa powder",25.75,20,true,https://lorempixel.com/200/300/food +Trifle Powdered Sugar Vanilla,3,"delicate, silky, mint, cola, cantaloupe",46.87,18,false,https://lorempixel.com/200/300/food +Cheesecake Walnuts Lemon,4,"muted, tea-like, nectarine, peanut, bergamot",72.66,30,false,https://lorempixel.com/200/300/food +Frozen Yogurt Butterscotch Syrup Neapolitan,4,"dull, tea-like, rubber, marzipan, black currant",39.42,7,false,https://lorempixel.com/200/300/food +Cheesecake Walnuts Mint Chocolate Chip,4,"bright, big, almond, maple syrup, bakers chocolate",30.68,7,true,https://lorempixel.com/200/300/food +Trifle Butterscotch Syrup Cheesecake,3,"pointed, silky, peanut, milk chocolate, lime",35.69,11,false,https://lorempixel.com/200/300/food +Cobbler Toffee Bits Rocky Road,2,"astringent, creamy, papaya, sweet pea, snow pea",26.22,7,false,https://lorempixel.com/200/300/food +Cookie Berry Compote Cherry,2,"dirty, smooth, honeysuckle, green grape, red grape",68.57,9,true,https://lorempixel.com/200/300/food +Cookie Bacon Vanilla,1,"rounded, full, bergamot, tamarind, cherry",74.82,10,true,https://lorempixel.com/200/300/food +Coffee Cake Cheesecake Bites Mint Chocolate Chip,2,"dirty, tea-like, brown sugar, black pepper, tobacco",70.76,26,false,https://lorempixel.com/200/300/food +Key Lime Pie Cookie Dough Red Velvet,4,"structured, velvety, black pepper, burnt sugar, lemonade",35.45,2,true,https://lorempixel.com/200/300/food +Brownie Gummy Bears Neapolitan,2,"dry, syrupy, orange blossom, papaya, olive",84.08,10,false,https://lorempixel.com/200/300/food diff --git a/db/review_seeds.csv b/db/review_seeds.csv index bebc6cce86..9acbf90968 100644 --- a/db/review_seeds.csv +++ b/db/review_seeds.csv @@ -1,11 +1,11 @@ rating,description,product_id -1,"Deliciously flavored deep, creamy, white grape, grapefruit, vanilla",13 -4,"Tasted like unbalanced, round, nutmeg, mushroom, blueberry",6 -2,"Deliciously flavored astringent, creamy, hazelnut, liquorice, grassy",6 -2,"Oddly it smelled like balanced, juicy, nougat, papaya, strawberry",15 -5,"Tasted like tart, creamy, white grape, molasses, clove",9 -3,"Tasted like mild, watery, lime, green pepper, dill",14 -5,"Oddly it smelled like balanced, juicy, cacao nibs, fresh bread, brown sugar",14 -4,"Tasted like vibrant, juicy, cinnamon, bakers chocolate, honeydew",7 -5,"Deliciously flavored lingering, watery, blueberry, green grape, watermelon",3 -5,"Tasted like sharp, chewy, lime, kiwi, tangerine",5 +2,"Oddly it smelled like faint, smooth, sweet pea, black pepper, milk chocolate",9 +1,"Oddly it smelled like dirty, syrupy, mandarin, hazelnut, mushroom",8 +4,"Deliciously flavored sharp, big, bergamot, barley, red grape",1 +2,"Oddly it smelled like pointed, big, mushroom, mint, cinnamon",9 +5,"Tasted like tart, coating, sundried tomato, coconut, cashew",12 +3,"Tasted like wild, slick, cherry, rose hips, lemon verbena",4 +3,"Deliciously flavored pointed, silky, cashew, almond, almond",10 +2,"Tasted like dense, chewy, sage, hops, dill",5 +3,"Oddly it smelled like tart, chewy, dill, green grape, granola",6 +5,"Oddly it smelled like unbalanced, velvety, hops, golden raisin, musty",7 diff --git a/db/schema.rb b/db/schema.rb index 06f16b7dcc..cce70d47b2 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_19_070105) do +ActiveRecord::Schema.define(version: 2018_10_19_215725) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -79,7 +79,7 @@ t.string "email" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "provider", null: false + t.string "provider" end add_foreign_key "products", "users" diff --git a/db/seeds.rb b/db/seeds.rb index f7e0d26619..83af81db6b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,7 +17,7 @@ user.email = row['email'] successful = user.save if !successful - review_failures << user + user_failures << user puts "Failed to save user: #{user.inspect}" puts "Error: #{user.errors}" else @@ -119,9 +119,32 @@ # add 3 items to first order # Order.first.order_items << Product.sample(3) # # -# #Populate categories_products table -# Product.all.each do -# Product.categories << Category.all.sample -# end +#Populate categories_products table + +CATEGORY_FILE = Rails.root.join('db', 'category_seeds.csv') +puts "Loading raw review data from #{REVIEW_FILE}" + +category_failures = [] +CSV.foreach(CATEGORY_FILE, :headers => true) do |row| + category = Category.new + category.category = row['category'] + + successful = category.save + if !successful + category_failures << category + puts "Failed to save category: #{category.inspect}" + puts "Error: #{category.errors}" + else + puts "Created category: #{category.inspect}" + end +end + +puts "Added #{Category.count} category records" +puts "#{category_failures.length} category failed to save" + + +Product.all.each do |product| + product.categories << Category.all.sample +end # # add 3 items to first order # Product.first.categories << Category.sample(2) diff --git a/db/user_seeds.csv b/db/user_seeds.csv index 857072cc05..ac05cbf940 100644 --- a/db/user_seeds.csv +++ b/db/user_seeds.csv @@ -1,6 +1,6 @@ uid,username,email -1,oscar,jayna_lubowitz@example.org -2,arie.heidenreich,kevin@example.com -5,sarah,amado.glover@example.net -2,darin_beahan,linn_thompson@example.com -4,johnnie.boehm,miranda_williamson@example.org +1,warner,rasheeda_stiedemann@example.com +3,sheena.rowe,willia@example.org +1,shin.green,carrol.larkin@example.com +2,del,drucilla@example.net +3,ezra_moen,zenia_jerde@example.com From ea4c8ce317b52c26b741afbe61cd564f466f4542 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Fri, 19 Oct 2018 16:38:28 -0700 Subject: [PATCH 046/192] fixed merchant show --- app/views/products/show.html.erb | 2 +- app/views/users/index.html.erb | 2 +- db/seeds.rb | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 79a4ef8179..7ff710416c 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -2,7 +2,7 @@

Category: - <%= @product.category %> + <%= @product.category_ids %>

diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 6437cd103c..ce997e44a9 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -13,7 +13,7 @@ - <% @users.each do |user| %> + <% User.all.each do |user| %> <%= user.uid %> <%= user.username %> diff --git a/db/seeds.rb b/db/seeds.rb index f7e0d26619..590d65748c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -120,8 +120,8 @@ # Order.first.order_items << Product.sample(3) # # # #Populate categories_products table -# Product.all.each do -# Product.categories << Category.all.sample -# end -# # add 3 items to first order -# Product.first.categories << Category.sample(2) +Product.all.each do + Product.categories << Category.all.sample +end +# add 3 items to first order +Product.first.categories << Category.sample(2) From adebf727c6ea3ce8f23553a078d7e6872a59dd2e Mon Sep 17 00:00:00 2001 From: Jazz Date: Fri, 19 Oct 2018 16:45:09 -0700 Subject: [PATCH 047/192] pull master --- app/assets/stylesheets/application.scss | 5 +++++ app/controllers/orders_controller.rb | 2 +- app/views/layouts/application.html.erb | 5 ++--- app/views/products/show.html.erb | 2 +- app/views/users/_form.html.erb | 2 +- app/views/users/{notinuse.html.erb => index.html.erb} | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) rename app/views/users/{notinuse.html.erb => index.html.erb} (94%) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 36177cc485..f803328dd0 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -47,3 +47,8 @@ body { .right { padding-right: 13px; } + +.form-group { + margin-left: 20px; + margin-right: 20px; +} diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index c292c1ee76..4fc71e52a5 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -35,7 +35,7 @@ def create render :new end end - end + # PATCH/PUT /orders/1 def update diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6821987649..4a399e7732 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -45,14 +45,13 @@ <%= link_to "Log out", logout_path, method: "delete" %> <% else %>

  • <%= link_to raw(''), "/auth/github" %> -
  • +
  • <%= link_to "Login with Github", "/auth/github", class: "btn btn-warning" %>
  • <% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 79a4ef8179..7ff710416c 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -2,7 +2,7 @@

    Category: - <%= @product.category %> + <%= @product.category_ids %>

    diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 98a9f3d923..ab597c73f2 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -11,7 +11,7 @@

    <% end %> -
    +
    <%= form.label :username %> <%= form.text_field :username, class: "form-control" %>
    diff --git a/app/views/users/notinuse.html.erb b/app/views/users/index.html.erb similarity index 94% rename from app/views/users/notinuse.html.erb rename to app/views/users/index.html.erb index 6437cd103c..ce997e44a9 100644 --- a/app/views/users/notinuse.html.erb +++ b/app/views/users/index.html.erb @@ -13,7 +13,7 @@ - <% @users.each do |user| %> + <% User.all.each do |user| %> <%= user.uid %> <%= user.username %> From ca34e76863e902189940b4d8bc9b5a8b2a83f787 Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 19 Oct 2018 16:45:28 -0700 Subject: [PATCH 048/192] small changes to make links work --- app/controllers/order_items_controller.rb | 3 ++- app/views/products/show.html.erb | 2 +- app/views/users/index.html.erb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 3771bb9e30..f4ce48ca02 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -7,6 +7,7 @@ def create # check if item is in stock @order_item = @order.order_items.new(order_item_params) + binding.pry @order.save session[:order_id] = @order.id @@ -19,7 +20,7 @@ def update @order_item = @order.order_items.find(params[:id]) @order_item.update_attributes(order_item_params) @order.save - + redirect_to cart_path(@order.id) end diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 79a4ef8179..7ff710416c 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -2,7 +2,7 @@

    Category: - <%= @product.category %> + <%= @product.category_ids %>

    diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 6437cd103c..ce997e44a9 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -13,7 +13,7 @@ - <% @users.each do |user| %> + <% User.all.each do |user| %> <%= user.uid %> <%= user.username %> From e504db5110db8b8089ec39dec80635135745dd87 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Fri, 19 Oct 2018 16:56:44 -0700 Subject: [PATCH 049/192] categories showing --- app/views/products/show.html.erb | 4 +++- db/schema.rb | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 7ff710416c..c7f7512b0b 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -2,7 +2,9 @@

    Category: - <%= @product.category_ids %> + <% @product.categories.each do |cat| %> + <%= cat.category.capitalize %>
    + <% end %>

    diff --git a/db/schema.rb b/db/schema.rb index 8c7731e85c..cce70d47b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD ActiveRecord::Schema.define(version: 2018_10_19_215725) do -======= -ActiveRecord::Schema.define(version: 2018_10_19_215535) do ->>>>>>> ae65e5f5cf0100ca77091dc42e417ddcf8b5f0c8 # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 56a15d80cd457616eb2e20bca93209050977c015 Mon Sep 17 00:00:00 2001 From: Trang Date: Fri, 19 Oct 2018 19:26:59 -0700 Subject: [PATCH 050/192] fixed shopping cart create order_item bug --- app/controllers/order_items_controller.rb | 5 +++-- app/controllers/products_controller.rb | 5 +++-- app/views/products/show.html.erb | 4 +++- db/schema.rb | 4 ---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 3771bb9e30..bd46ef4283 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -7,6 +7,7 @@ def create # check if item is in stock @order_item = @order.order_items.new(order_item_params) + @order_item.save @order.save session[:order_id] = @order.id @@ -19,7 +20,7 @@ def update @order_item = @order.order_items.find(params[:id]) @order_item.update_attributes(order_item_params) @order.save - + redirect_to cart_path(@order.id) end @@ -37,7 +38,7 @@ def destroy def order_item_params - params.require(:order_item).permit(:qty, product_ids: []) + params.require(:order_item).permit(:product_id, :qty) end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 46fa17f791..aaa6982efd 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -11,12 +11,13 @@ def index # GET /products/1 def show - @order_item = current_order.order_items.find_by(product_id: params[:id]) + @order = current_order + @order_item = @order.order_items.find_by(product_id: params[:id]) if @order_item.nil? @order_item = current_order.order_items.new end - + end # GET /products/new diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 79a4ef8179..47f1ab9951 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -2,7 +2,9 @@

    Category: - <%= @product.category %> + <% @product.categories.each do |cat| %> + <%= cat.category %>
    + <% end %>

    diff --git a/db/schema.rb b/db/schema.rb index 8c7731e85c..cce70d47b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD ActiveRecord::Schema.define(version: 2018_10_19_215725) do -======= -ActiveRecord::Schema.define(version: 2018_10_19_215535) do ->>>>>>> ae65e5f5cf0100ca77091dc42e417ddcf8b5f0c8 # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 328895ae36cf58cb28afb2467ac1d482ae960bfd Mon Sep 17 00:00:00 2001 From: Jazz Date: Fri, 19 Oct 2018 19:55:36 -0700 Subject: [PATCH 051/192] pulling master --- app/views/products/show.html.erb | 4 +++- db/schema.rb | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 7ff710416c..d5aecaef18 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -2,7 +2,9 @@

    Category: - <%= @product.category_ids %> + <% @product.categories.each do |cat| %> + <%= cat.category.capitalize %> + <% end %>

    diff --git a/db/schema.rb b/db/schema.rb index 8c7731e85c..cce70d47b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD ActiveRecord::Schema.define(version: 2018_10_19_215725) do -======= -ActiveRecord::Schema.define(version: 2018_10_19_215535) do ->>>>>>> ae65e5f5cf0100ca77091dc42e417ddcf8b5f0c8 # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 8630692b9a73b00e921078b4ae4392d2685d0798 Mon Sep 17 00:00:00 2001 From: Trang Date: Sat, 20 Oct 2018 12:27:05 -0700 Subject: [PATCH 052/192] fix quick_shop link and remove pry --- app/assets/stylesheets/products.scss | 12 ++++++++ app/controllers/application_controller.rb | 6 ++++ app/controllers/order_items_controller.rb | 11 +++++-- app/controllers/products_controller.rb | 7 +++-- app/models/product.rb | 12 +++++++- app/views/layouts/application.html.erb | 6 ++-- app/views/products/category.html.erb | 35 +++++++++++++++++++++++ config/routes.rb | 6 ++-- db/product_seeds.csv | 2 -- 9 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 app/views/products/category.html.erb diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 2b39b1a435..0a9ff890e1 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -132,3 +132,15 @@ margin-top: 7rem; } } + +.products { + padding-left: 2rem; +} + +li { + list-style: none; +} + +.category { + color: #f45381; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 934c50ff02..5f03ad4a25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,15 @@ class ApplicationController < ActionController::Base before_action :find_user + before_action :list_categories # before_action :require_login, except: [:create, :root] helper_method :current_order + def list_categories + @categories = Category.all + end + + def current_order if !session[:order_id].nil? Order.find(session[:order_id]) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index bd46ef4283..cbdaaf286c 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,5 +1,3 @@ -require 'pry' - class OrderItemsController < ApplicationController def create @@ -22,7 +20,16 @@ def update @order.save redirect_to cart_path(@order.id) + end + + def cart_direct + @order = current_order + @order_item = @order.order_items.new(product_id: params[:id], qty: 1) + @order_item.save + @order.save + session[:order_id] = @order.id + redirect_to cart_path(@order.id) end def destroy diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index aaa6982efd..d76fd20e74 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,3 @@ -require 'pry' - class ProductsController < ApplicationController before_action :set_product, only: [:show, :edit, :update, :destroy] @@ -61,6 +59,11 @@ def destroy end end + def category + @category = Category.find_by(id: params[:id]) + @products = Product.by_category(params[:id]) + end + private # Use callbacks to share common setup or constraints between actions. def set_product diff --git a/app/models/product.rb b/app/models/product.rb index 5117ae578c..a6c00e53c6 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -10,7 +10,17 @@ class Product < ApplicationRecord has_and_belongs_to_many :categories has_many :order_items - + def self.by_category(id) + all_products = Product.all + category_products = [] + + all_products.each do |product| + if product.categories.find_by(id: id) + category_products << product + end + end + return category_products + end def avg_rating diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6821987649..9094d708c5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -30,9 +30,9 @@

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

    <%= @category.category %>

    + +
    +
    + <% @products.each do |product| %> +
    +
    +
    + <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %> +
    +
    +

    <%= product.prod_name %>

    +
    $<%= product.price %> + <%= product.inv_qty %> in stock +
    +
    + + +
    +
    + <% end %> +
    +
    +
    + diff --git a/config/routes.rb b/config/routes.rb index 3619958dc7..5c9a61c4cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,12 +9,14 @@ # get 'sessions/new', to: "sessions#create" #create a new session login # get 'sessions/destroy', to: "sessions#destroy" #delete a session logout resources :carts, only: [:show] - resources :order_items, only: [:create, :update, :destroy] - + post "order_items/cart_direct/:id", to: "order_items#cart_direct", as: "quick_shop" + resources :order_items, only: [:create, :update, :destroy] resources :reviews resources :orders + + get 'products/category/:id', to: "products#category", as: "category" resources :products resources :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html diff --git a/db/product_seeds.csv b/db/product_seeds.csv index fa04f1afa5..19cc92307e 100644 --- a/db/product_seeds.csv +++ b/db/product_seeds.csv @@ -1,5 +1,4 @@ prod_name,user_id,description,price,inv_qty,active,image -<<<<<<< HEAD Cobbler Butterscotch Syrup Salted Caramel,1,"balanced, big, leathery, cashew, banana",17.93,14,false,https://lorempixel.com/200/300/food Cake Pop Mocha Drizzle Pistachio,4,"wild, full, clove, pecan, grapefruit",34.93,16,true,https://lorempixel.com/200/300/food Cake Mocha Drizzle French Vanilla,2,"dirty, big, black-tea, cream, quakery",99.04,15,true,https://lorempixel.com/200/300/food @@ -61,4 +60,3 @@ Cupcake Whipped Cream Peanut Butter,1,"structured, tea-like, maple syrup, carmel Ice Cream Cake Chocolate Syrup Cookies 'n Cream,2,"mild, full, molasses, clementine, magnolia",33.12,1,false,https://lorempixel.com/200/300/food Pudding Gummy Bears Almond,3,"balanced, smooth, molasses, honeysuckle, sage",80.17,11,false,https://lorempixel.com/200/300/food Frozen Yogurt Cookie Dough Banana,1,"crisp, syrupy, sage, honey, green grape",28.84,8,false,https://lorempixel.com/200/300/food ->>>>>>> ae65e5f5cf0100ca77091dc42e417ddcf8b5f0c8 From 1880896a1acd2dc41e2fb1ef589acb1f2009553e Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Sat, 20 Oct 2018 12:31:02 -0700 Subject: [PATCH 053/192] added alternate link for login when fa fa login not working --- app/views/layouts/application.html.erb | 1 + config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6821987649..82938344bd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -45,6 +45,7 @@ <%= link_to "Log out", logout_path, method: "delete" %> <% else %>
  • <%= link_to raw(''), "/auth/github" %>
  • <% end %> diff --git a/config/routes.rb b/config/routes.rb index 3619958dc7..b85db4c8f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do root 'products#home' - get "/auth/:provider/callback", to: "sessions#create" + get "/auth/:provider/callback", to: "sessions#create", as: "login" get 'sessions/login', to: "sessions#new" #page for a new session delete "/logout", to: "sessions#destroy", as: "logout" From 82b17478ab012176d064fec95aab536a9211e891 Mon Sep 17 00:00:00 2001 From: Trang Date: Sat, 20 Oct 2018 13:05:47 -0700 Subject: [PATCH 054/192] create partial for products_list --- app/assets/stylesheets/products.scss | 8 ---- app/views/layouts/application.html.erb | 2 + app/views/products/_product.json.jbuilder | 2 - app/views/products/_productslist.html.erb | 32 ++++++++++++++ app/views/products/category.html.erb | 35 +-------------- app/views/products/index.html.erb | 53 ++--------------------- 6 files changed, 40 insertions(+), 92 deletions(-) delete mode 100644 app/views/products/_product.json.jbuilder create mode 100644 app/views/products/_productslist.html.erb diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 0a9ff890e1..14130541c7 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -136,11 +136,3 @@ .products { padding-left: 2rem; } - -li { - list-style: none; -} - -.category { - color: #f45381; -} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9094d708c5..2e96d6ad44 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -48,6 +48,8 @@
  • <%= link_to raw(''), "/auth/github" %>
  • <% end %> + + +
    +
    + <% end %> +
    +
    +
    diff --git a/app/views/products/category.html.erb b/app/views/products/category.html.erb index a8febc3b58..667748bbed 100644 --- a/app/views/products/category.html.erb +++ b/app/views/products/category.html.erb @@ -1,35 +1,4 @@
    -

    <%= @category.category %>

    - -
    -
    - <% @products.each do |product| %> -
    -
    -
    - <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %> -
    -
    -

    <%= product.prod_name %>

    -
    $<%= product.price %> - <%= product.inv_qty %> in stock -
    -
    - - -
    -
    - <% end %> -
    -
    -
    +

    <%= @category.category.pluralize %>

    + <%= render partial: "productslist", locals: { } %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index fec5c3efde..f7670f2154 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,49 +1,4 @@ -

    <%= notice %>

    - -

    Cakes for All Occassions

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

    <%= product.prod_name %>

    -
    $<%= product.price %> - <%= product.inv_qty %> in stock -
    - -
    - - -
    -
    - <% end %> -
    -
    -
    -
    -
    -
    -
    +
    +

    All Sweets

    + <%= render partial: "productslist", locals: { } %> +
    From 80bdf2f13fcee873637267db4cac2d0b08bb736e Mon Sep 17 00:00:00 2001 From: Trang Date: Sat, 20 Oct 2018 13:11:33 -0700 Subject: [PATCH 055/192] fix order_controller error for deployment --- app/controllers/orders_controller.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index c292c1ee76..1ba48c813c 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -23,17 +23,18 @@ def edit def create @order = Order.new(order_params) - if @order.save - flash[:success] = 'Order was successfully created.' - redirect_to order_path(@order.id) + if @order.save + flash[:success] = 'Order was successfully created.' + redirect_to order_path(@order.id) - else - flash.now[:warning] = 'Order not created' - @order.errors.messages.each do |field, msg| - flash.now[field] = messages - end - render :new + else + flash.now[:warning] = 'Order not created' + + @order.errors.messages.each do |field, msg| + flash.now[field] = messages end + + render :new end end @@ -42,10 +43,8 @@ def update respond_to do |format| if @order.update(order_params) format.html { redirect_to @order, notice: 'Order was successfully updated.' } - else format.html { render :edit } - end end end @@ -56,7 +55,6 @@ def destroy @order.destroy respond_to do |format| format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } - end end From 58d4935316cbff1a25ac89736af21069fa965a04 Mon Sep 17 00:00:00 2001 From: Trang Date: Sat, 20 Oct 2018 20:10:06 -0700 Subject: [PATCH 056/192] remove scaffolding css defaults --- app/assets/stylesheets/application.scss | 15 +++ app/assets/stylesheets/scaffolds.scss | 166 ++++++++++++------------ app/views/layouts/application.html.erb | 15 ++- 3 files changed, 108 insertions(+), 88 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 36177cc485..86309e4c6b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -26,6 +26,10 @@ body { margin-bottom: 20px; } +.navbar-brand { + color: hotpink; +} + .fa-github-square { font-size: 2em; color: lightgrey; @@ -47,3 +51,14 @@ body { .right { padding-right: 13px; } + +.btn-primary { + background-color: #EC407A; + border: #F48FB1; + color: white; +} + +.btn:hover { + opacity: 0.5; + background-color: #EC407A; +} diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss index ee3696cb17..370275046d 100644 --- a/app/assets/stylesheets/scaffolds.scss +++ b/app/assets/stylesheets/scaffolds.scss @@ -1,83 +1,83 @@ -body { - background-color: #fff; - color: #333; - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - - &:visited { - color: #666; - } - - &:hover { - color: #fff; - background-color: #000; - } -} - -th { - padding-bottom: 5px; -} - -td { - padding: 0 5px 7px; -} - -div { - &.field, &.actions { - margin-bottom: 10px; - } -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px 7px 0; - margin-bottom: 20px; - background-color: #f0f0f0; - - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px -7px 0; - background-color: #c00; - color: #fff; - } - - ul li { - font-size: 12px; - list-style: square; - } -} - -label { - display: block; -} +// body { +// background-color: #fff; +// color: #333; +// font-family: verdana, arial, helvetica, sans-serif; +// font-size: 13px; +// line-height: 18px; +// } +// +// p, ol, ul, td { +// font-family: verdana, arial, helvetica, sans-serif; +// font-size: 13px; +// line-height: 18px; +// } +// +// pre { +// background-color: #eee; +// padding: 10px; +// font-size: 11px; +// } +// +// a { +// color: #000; +// +// &:visited { +// color: #666; +// } +// +// &:hover { +// color: #fff; +// background-color: #000; +// } +// } +// +// th { +// padding-bottom: 5px; +// } +// +// td { +// padding: 0 5px 7px; +// } +// +// div { +// &.field, &.actions { +// margin-bottom: 10px; +// } +// } +// +// #notice { +// color: green; +// } +// +// .field_with_errors { +// padding: 2px; +// background-color: red; +// display: table; +// } +// +// #error_explanation { +// width: 450px; +// border: 2px solid red; +// padding: 7px 7px 0; +// margin-bottom: 20px; +// background-color: #f0f0f0; +// +// h2 { +// text-align: left; +// font-weight: bold; +// padding: 5px 5px 5px 15px; +// font-size: 12px; +// margin: -7px -7px 0; +// background-color: #c00; +// color: #fff; +// } +// +// ul li { +// font-size: 12px; +// list-style: square; +// } +// } +// +// label { +// display: block; +// } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2e96d6ad44..4b01f8f711 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -21,20 +21,25 @@ - + -<%= link_to "Add a new category", new_categories_path %> \ No newline at end of file +<%= link_to "Add a new category", new_category_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 303a504b67..9a21acc3b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,6 @@ get 'products/category/:id', to: "products#category", as: "category" resources :products resources :users - resource :categories + resources :categories end From 20f3882fb2198a81d153b7681991b8b2ed5db69d Mon Sep 17 00:00:00 2001 From: Jazz Date: Sun, 21 Oct 2018 00:08:21 -0700 Subject: [PATCH 063/192] added review --- app/controllers/products_controller.rb | 3 ++ app/controllers/reviews_controller.rb | 42 +++++++++++++++++--------- app/views/products/show.html.erb | 2 +- app/views/reviews/new.html.erb | 18 ++++++++++- config/routes.rb | 3 +- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index aaa6982efd..66f29dc4f9 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -18,6 +18,9 @@ def show @order_item = current_order.order_items.new end + @product = Product.find(params[:id]) + @reviews = Review.where(product_id: @product) + end # GET /products/new diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 6d96bb18ca..a0790e746d 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -23,11 +23,11 @@ def new # @review = Review.new #post route to /review only - #can't find post route for this method - if params[:product_id] - @product = Product.find_by(id: params[:product_id]) - @reviews = @product.reviews.new - end + # can't find post route for this method + # if params[:product_id] + @product = Product.find(params[:product_id]) + @review = Review.new(product: @product) + # end end @@ -37,15 +37,27 @@ def edit # POST /reviews def create - @review = Review.new(review_params) - - respond_to do |format| - if @review.save - format.html { redirect_to @review, notice: 'Review was successfully created.' } - else - format.html { render :new } - end - end + #@product = Product.find_by(id: params[:product_id]) + # @reviews = @product.Reviews.new + # @review = Review.new(review_params) + + @product = Product.find(params[:product_id]) + @review = @product.reviews.build(review_params) + @review.product = @product + @review.save + redirect_to @product + + + # @product = Product.find_by(id: params[:product_id]) + # @review = @product.reviews.build(params[:review]) + + # respond_to do |format| + # if @review.save + # format.html { redirect_to @review, notice: 'Review was successfully created.' } + # else + # format.html { render :new } + # end + # end end @@ -79,6 +91,6 @@ def set_review # Never trust parameters from the scary internet, only allow the white list through. def review_params - params.require(:review).permit(:rating, :description, :product_id) + params.require(:review).permit(:rating, :description) end end diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index ee1191a29d..bb5ccdba01 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -39,7 +39,7 @@ <%= link_to 'Back', products_path %> - +

    Reviews

    diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb index b41a406ad9..e08ab1c49c 100644 --- a/app/views/reviews/new.html.erb +++ b/app/views/reviews/new.html.erb @@ -1,3 +1,19 @@

    New Review

    -<%= render 'form', review: @review %> +<%#= render 'form', review: @review %> +<%= form_for [@product, @review] do |form| %> + +
    + <%= form.label :rating %> + <%= form.number_field :rating, class: "form-control" %> +
    + +
    + <%= form.label :description %> + <%= form.text_field :description, class: "form-control" %> +
    + +
    + <%= form.submit class: "btn btn-primary"%> +
    +<% end %> diff --git a/config/routes.rb b/config/routes.rb index e25199dac7..3fa028ff1d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,8 @@ resources :products do resources :reviews, only: [:new, :create] end - + + get "/auth/:provider/callback", to: "sessions#create" get 'sessions/login', to: "sessions#new" #page for a new session From fadf62a898060038de420e79db8d4c1c7eb134d9 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Sun, 21 Oct 2018 14:38:18 -0700 Subject: [PATCH 064/192] merchant can retire-activate product - if retired prod does not show on index page --- app/controllers/products_controller.rb | 22 ++++++++--- app/models/product.rb | 8 ++++ app/views/products/_productslist.html.erb | 48 ++++++++++++----------- app/views/users/show.html.erb | 19 ++++++--- config/routes.rb | 1 + 5 files changed, 64 insertions(+), 34 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index a6a9e875a0..30e38a2982 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,5 @@ class ProductsController < ApplicationController - before_action :set_product, only: [:show, :edit, :update, :destroy] + before_action :set_product, only: [:show, :edit, :update, :destroy, :status] # GET /products def index @@ -24,8 +24,7 @@ def new end # GET /products/1/edit - def edit - end + def edit; end # POST /products def create @@ -44,9 +43,10 @@ def create def update respond_to do |format| if @product.update(product_params) - format.html { redirect_to @product, notice: 'Product was successfully updated.' } + flash[:notice] = "#{@product.prod_name} was successfully updated." + redirect_to product_path else - format.html { render :edit } + render :edit end end end @@ -64,6 +64,18 @@ def category @products = Product.by_category(params[:id]) end + def status + if @product.active + @product.update(active: false) + flash[:notice] = "#{@product.prod_name} status successfully updated." + redirect_back(fallback_location: root_path) + else + @product.update(active: true) + flash[:warning] = "Product could not updated." + redirect_back(fallback_location: products_path) + end + end + private # Use callbacks to share common setup or constraints between actions. def set_product diff --git a/app/models/product.rb b/app/models/product.rb index a6c00e53c6..d284aa5fe8 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -31,5 +31,13 @@ def avg_rating # return sum / num end + # def self.status(product) + # if product.active + # product.update(active: false) + # else + # product.update(active: true) + # end + # + # end end diff --git a/app/views/products/_productslist.html.erb b/app/views/products/_productslist.html.erb index efdccb1379..c84268b97a 100644 --- a/app/views/products/_productslist.html.erb +++ b/app/views/products/_productslist.html.erb @@ -2,31 +2,33 @@
    <% @products.each do |product| %> -
    -
    -
    - <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %> + <% if product.active %> +
    +
    +
    + <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %> +
    +
    +

    <%= product.prod_name %>

    +
    $<%= product.price %> + <%= product.inv_qty %> in stock +
    +
    + + +
    -
    -

    <%= product.prod_name %>

    -
    $<%= product.price %> - <%= product.inv_qty %> in stock -
    -
    - - -
    -
    <% end %> + <% end %>
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 07467e2e2c..c2120a527a 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -15,24 +15,24 @@ <%= @user.email %>

    -<%= link_to 'List a Product', new_product_path, class: "sell-link" %> +
    +<%= link_to 'List a Product', new_product_path, class: "sell-link btn btn-info" %> | +<%= link_to 'View Categories', categories_path, class: "btn btn-info" %> +
    -<%# create a method that allows merchant to create a new category%> -<%= link_to 'View Categories', categories_path%> - - -<%# list all products listed by this merchant allow them to edit%> + + @@ -45,6 +45,13 @@ + <% if product.active %> + + + <% else %> + + + <% end %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 9a21acc3b3..e20e6eafb3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ resources :orders get 'products/category/:id', to: "products#category", as: "category" + patch 'products/:id/retire', to: "products#status", as: "product_status" resources :products resources :users resources :categories From 439e5550313d925b8e4842a6d02f80364cf2ef94 Mon Sep 17 00:00:00 2001 From: Jazz Date: Sun, 21 Oct 2018 15:57:58 -0700 Subject: [PATCH 065/192] pull master --- app/models/product.rb | 8 ++++++++ app/views/products/show.html.erb | 5 ++++- db/user_seeds.csv | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index f8c1a8eb40..32a5fcbcc4 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -18,4 +18,12 @@ def avg_rating return average_rating end + # def avg_rating + # total = 0 + # self.reviews.each do |review| + # total += review.rating + # end + # return total/reviews.count.to_f + # end + end diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index bb5ccdba01..f136c4d01d 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -45,9 +45,12 @@
    <% @product.avg_rating.round.times do %> rating star - <% end %> +<% end %>
    <% @product.reviews.each do |review| %> +

    Rating: <%= review.rating %>

    <%= review.description %>

    <% end %> + + diff --git a/db/user_seeds.csv b/db/user_seeds.csv index d262dd4daa..ef72e7b929 100644 --- a/db/user_seeds.csv +++ b/db/user_seeds.csv @@ -5,7 +5,7 @@ uid,username,email 1,shin.green,carrol.larkin@example.com 2,del,drucilla@example.net 3,ezra_moen,zenia_jerde@example.com -======= + 3,jennette_bradtke,felix@example.org 1,elana_schneider,brittanie@example.net 1,lorean_pfeffer,lakeshia@example.org From 8fd89ea36eadaf3b39ae4dc2cc8f4d095c2736f7 Mon Sep 17 00:00:00 2001 From: Jazz Date: Sun, 21 Oct 2018 18:48:33 -0700 Subject: [PATCH 066/192] working on model test --- app/assets/stylesheets/products.scss | 82 ++++++++++++++++++++++++++- app/controllers/orders_controller.rb | 1 + app/controllers/reviews_controller.rb | 22 ++----- app/models/product.rb | 20 +++---- app/views/carts/show.html.erb | 3 + app/views/products/show.html.erb | 71 ++++++++++++++++++++--- test/models/order_test.rb | 27 ++++++++- 7 files changed, 190 insertions(+), 36 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 142e7936b0..7c8679c5c6 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -16,10 +16,90 @@ height: auto; } -.reviews h2 { +.reviews > h2 { text-align: center; } +.table-responsive-md { + margin-left: 25px; + margin-right: 25px; +} + +.rating { + text-align: center; +} + + +//############ Review Button ############## +.inline{ + text-align: center; +} + +.inline > .buttonContainer { + display: inline-block; +} + +.buttonContainer{ + margin-top:45px; + // text-align:center; + padding-bottom: 2em; +} + +a.button{ + display:inline-block; + + font:normal normal 300 1.3em 'Open Sans'; + text-decoration:none; + + color:rgba(28, 190, 131, 1); + brackground-color:transparent; + border:1px solid rgba(28, 190, 131, 1); + border-radius:100px; + + padding: .3em 1.2em; + margin:5px; + + background-size: 200% 100%; + background-image: linear-gradient(to right, transparent 50%, rgba(28, 190, 131, 1) 50%); + transition: background-position .3s cubic-bezier(0.19, 1, 0.22, 1) .1s, color .5s ease 0s, background-color .5s ease; +} + +a.button:hover{ + color:rgba(255, 255, 255, 1); + background-color:rgba(28, 190, 131, 1); + background-position: -100% 100%; +} + +.passenger-form { + margin-top: 3em; + margin-right: 3em; + margin-left: 3em; + padding-top: 1em; + padding-bottom: 2.5em; + text-align: center; + background: #67D4C4; +} + +.passenger-button:hover { + background: blue; + border-radius: 15%; + color: white; + cursor: pointer; +} + +.parah { + font-size: 1.25em; +} + +.header_font { + text-transform: capitalize; + background: lightgrey; + position: sticky; + top: 0; +} + + +//###########body grid for index page############ .product-grid6,.product-grid6 .product-image6{overflow:hidden} .product-grid6{font-family:'Open Sans',sans-serif;text-align:center;position:relative;transition:all .5s ease 0s} diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 675521bed7..eb6bdd08af 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -32,6 +32,7 @@ def create @order.errors.messages.each do |field, msg| flash.now[field] = messages + end end render :new diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index a0790e746d..0dac36c2bd 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -20,15 +20,8 @@ def show # GET /reviews/new def new - # @review = Review.new - #post route to /review only - - # can't find post route for this method - # if params[:product_id] @product = Product.find(params[:product_id]) @review = Review.new(product: @product) - # end - end # GET /reviews/1/edit @@ -37,19 +30,16 @@ def edit # POST /reviews def create - #@product = Product.find_by(id: params[:product_id]) - # @reviews = @product.Reviews.new - # @review = Review.new(review_params) - @product = Product.find(params[:product_id]) @review = @product.reviews.build(review_params) @review.product = @product - @review.save - redirect_to @product - + if @review.save + redirect_to @product + else + flash.now[:warning] = "Please enter all fields" + render :new + end - # @product = Product.find_by(id: params[:product_id]) - # @review = @product.reviews.build(params[:review]) # respond_to do |format| # if @review.save diff --git a/app/models/product.rb b/app/models/product.rb index 7266bc4123..4444b66cdc 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -23,17 +23,17 @@ def self.by_category(id) end - def avg_rating - average_rating = self.reviews.reduce(0) { |sum, review| sum + review.rating } - return average_rating - end - # def avg_rating - # total = 0 - # self.reviews.each do |review| - # total += review.rating - # end - # return total/reviews.count.to_f + # average_rating = self.reviews.reduce(0) { |sum, review| sum + review.rating } + # return average_rating # end + def avg_rating + total = 0 + self.reviews.each do |review| + total += review.rating + end + return total/reviews.count + end + end diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 8ad9b4e12d..cf467d8ec1 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -29,3 +29,6 @@ <% end %>
    NAME PRICE QUANTITY RATINGSTATUS
    <%= format_price(product.price)%> <%= product.inv_qty %> <%= product.avg_rating %>ACTIVE<%= link_to "RETIRE", product_status_path(product), class: "btn btn-warning ", method: :patch%>RETIRED<%= link_to "ACTIVATE", product_status_path(product), class: "btn btn-success", method: :patch%>
    + +
    <%= link_to "Checkout", new_order_path, class: "button" %>
    +
    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index f136c4d01d..261573aa24 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,5 +1,45 @@

    <%= notice %>

    +
    +
    +
    +
    +
    + <%=link_to image_tag("#{@product.image}", alt: "#{@product.description}"), product_path(@product.id) %> +
    +
    +

    <%= @product.prod_name %>

    +
    $<%= @product.price %> + <%= @product.inv_qty %> in stock +
    +
    + + +
    +
    +
    +
    +
    + +
    <%= link_to "Write A Review", new_product_review_path(@product), class: "button" %>
    +
    +

    Category: <% @product.categories.each do |cat| %> @@ -36,21 +76,38 @@ <%= f.submit "Add to cart", class: "btn btn-primary" %> <% end %> -<%= link_to 'Back', products_path %> +<%= link_to 'Back', products_path, class: "btn btn-success" %> + -

    Reviews

    -
    +
    Average Rating: <% @product.avg_rating.round.times do %> rating star <% end %>
    - <% @product.reviews.each do |review| %> -

    Rating: <%= review.rating %>

    -

    <%= review.description %>

    - <% end %> +
    + + + + + + + + + + + <% @product.reviews.each do |review| %> + + + + + <% end %> + +
    RatingReviewEdit
    <%= review.rating%> <%= review.description%><%= link_to 'Edit', edit_review_path(review) %>
    + +
    diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 9696584fdd..4222aa1aac 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -41,23 +41,44 @@ order.cc_name = nil expect(order.cc_name.valid?).must_equal false - expect(order.errors.messages).must_include :price + expect(order.errors.messages).must_include :cc_name end it "must be invalid if date has expired" do + order.cc_expiration = 2018/08/21 + expect(order.cc_name.valid?).must_equal false + expect(order.errors.messages).must_include :cc_expiration end it "must be invalid with more than 16 digits for credit card" do + order.cc_digit = 123 + order2.cc_digit = "hi" + expect(order.cc_digit.valid?).must_equal false + expect(order2.cc_digit.valid?).must_equal false + expect(order.errors.messages).must_include :cc_digit + expect(order2.errors.messages).must_include :cc_digit end it "must have only 3 digits for CVV" do + order.cc_cvv = 12 + order2.cc_cvv = "hi" + expect(order.cc_cvv.valid?).must_equal false + expect(order2.cc_cvv.valid?).must_equal false + expect(order.errors.messages).must_include :cc_cvv + expect(order2.errors.messages).must_include :cc_cvv end - it " must be 5 digits in length for zip code" do + it "must be 5 digits in length for zip code" do + order.cc_zip = 12 + order2.cc_zip = "hi" + expect(order.cc_zip.valid?).must_equal false + expect(order2.cc_zip.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip + expect(order2.errors.messages).must_include :cc_zip end @@ -69,5 +90,7 @@ expect(order).must_be_instance_of Product expect(order.id).must_equal product.order_id end + end end +end From e4bb6e841ca4493bfeca82ba7401fd84a7ced6d7 Mon Sep 17 00:00:00 2001 From: Jazz Date: Sun, 21 Oct 2018 21:33:36 -0700 Subject: [PATCH 067/192] added review test, 2 user test --- app/assets/stylesheets/users.scss | 39 ++++++++++++++++++++++ app/controllers/users_controller.rb | 9 ++++++ app/views/products/show.html.erb | 8 +++-- app/views/users/show.html.erb | 50 ++++++++++++++++++++++++++--- test/factories/product.rb | 2 +- test/fixtures/products.yml | 6 ++-- test/models/order_test.rb | 28 +++++++++------- test/models/product_test.rb | 2 +- test/models/review_test.rb | 32 ++++++++++++++++-- test/models/user_test.rb | 46 ++++++++++++++++++++++++-- 10 files changed, 192 insertions(+), 30 deletions(-) diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index 1efc835ccd..6545f9e6ff 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -1,3 +1,42 @@ + +.parent { + display: flex; + flex-wrap: wrap; + margin: 15px; +} + +.child { + flex: 1 0 25%; /* explanation below */ + margin: 5px; + height: auto; +} // 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/ +.product-grid6,.product-grid6 .product-image6{overflow:hidden} +.product-grid6{font-family:'Open Sans',sans-serif;text-align:center;position:relative;transition:all .5s ease 0s} +.product-grid6:hover{box-shadow:0 0 10px rgba(0,0,0,.3)} +.product-grid6 .product-image6 a{display:block} +.product-grid6 .product-image6 img{width:100%;height:auto;transition:all .5s ease 0s} +.product-grid6:hover .product-image6 img{transform:scale(1.1)} +.product-grid6 .product-content{padding:12px 12px 15px;transition:all .5s ease 0s} +.product-grid6:hover .product-content{opacity:0} +.product-grid6 .title{font-size:20px;font-weight:600;text-transform:capitalize;margin:0 0 10px;transition:all .3s ease 0s} +.product-grid6 .title a{color:#000} +.product-grid6 .title a:hover{color:#2e86de} +.product-grid6 .price{font-size:18px;font-weight:600;color:#2e86de} +.product-grid6 .price span{color:#999;font-size:15px;font-weight:400;text-decoration:line-through;margin-left:7px;display:inline-block} +.product-grid6 .social{background-color:#fff;width:100%;padding:0;margin:0;list-style:none;opacity:0;transform:translateX(-50%);position:absolute;bottom:-50%;left:50%;z-index:1;transition:all .5s ease 0s} +.product-grid6:hover .social{opacity:1;bottom:20px} +.product-grid6 .social li{display:inline-block} +.product-grid6 .social li a{color:#909090;font-size:16px;line-height:45px;text-align:center;height:45px;width:45px;margin:0 7px;border:1px solid #909090;border-radius:50px;display:block;position:relative;transition:all .3s ease-in-out} +.product-grid6 .social li a:hover{color:#fff;background-color:#2e86de;width:80px} +.product-grid6 .social li a:after,.product-grid6 .social li a:before{content:attr(data-tip);color:#fff;background-color:#2e86de;font-size:12px;letter-spacing:1px;line-height:20px;padding:1px 5px;border-radius:5px;white-space:nowrap;opacity:0;transform:translateX(-50%);position:absolute;left:50%;top:-30px} +.product-grid6 .social li a:after{content:'';height:15px;width:15px;border-radius:0;transform:translateX(-50%) rotate(45deg);top:-20px;z-index:-1} +.product-grid6 .social li a:hover:after,.product-grid6 .social li a:hover:before{opacity:1} +@media only screen and (max-width:990px){.product-grid6{margin-bottom:30px} +} + +.col-sm-6{ + padding-bottom: 1em; +} diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a1d618861f..a759e906d9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,6 +5,15 @@ class UsersController < ApplicationController def show @user = User.find_by(id: params[:id]) render_404 unless @user + + @order = current_order + @order_item = @order.order_items.find_by(product_id: params[:id]) + + if @order_item.nil? + @order_item = current_order.order_items.new + end + + @products = Product.where(user_id: @user) end # GET /users/new diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 261573aa24..e83047e98a 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -83,9 +83,11 @@

    Reviews

    Average Rating: - <% @product.avg_rating.round.times do %> - rating star -<% end %> + <% if @product.reviews.length >= 1 %> + <% @product.avg_rating.round.times do %> + rating star + <% end %> + <% end %>
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 5a447a43bf..2cde116c7e 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,19 +1,59 @@ -

    <%= notice %>

    + + +
    +
    + + <% @user.products.each do |product| %> +
    +
    +
    + <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %> +
    +
    +

    <%= product.prod_name %>

    +
    $<%= product.price %> + <%= product.inv_qty %> in stock +
    +
    + + +
    +
    + <% end %> +
    +
    +
    + <%= link_to 'Back', users_path %> diff --git a/test/factories/product.rb b/test/factories/product.rb index 9cd139cd85..1f8f856e3e 100644 --- a/test/factories/product.rb +++ b/test/factories/product.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :product do - category { %w(birthday wedding chocolate vanilla buttercream).sample} + # category { %w(birthday wedding chocolate vanilla buttercream).sample} prod_name { Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor} description { Faker::Coffee.notes} price { Faker::Number.decimal(2, 2)} diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 1859032f59..50f681481c 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -1,14 +1,14 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html cake1: - category: wedding + prod_name: a wedding cake description: yum price: 15.5 inv_qty: 5 cake2: - category: chocolate + prod_name: chocolate goodness description: the best price: 19.5 @@ -16,7 +16,7 @@ cake2: cake3: - category: vanilla + prod_name: vanilla plains description: real vanilla price: 20.5 diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 4222aa1aac..76247fdc11 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,19 +1,23 @@ require "test_helper" describe Order do - let(:order) { Order.new } + describe "validation" do + let(:user) { user(:one) } before do - order = create(:order) + 1.times do + order = create(:order) + end end - it "must be a valid order" do - - expect(order.valid?).must_equal true - end + # it "must be a valid order" do + # + # expect(order.valid?).must_equal true + # end it "must be invalid without a customer name " do + order.cust_name = nil expect(order.cust_name.valid?).must_equal false @@ -44,12 +48,12 @@ expect(order.errors.messages).must_include :cc_name end - it "must be invalid if date has expired" do - order.cc_expiration = 2018/08/21 - - expect(order.cc_name.valid?).must_equal false - expect(order.errors.messages).must_include :cc_expiration - end + # it "must be invalid if date has expired" do + # order.cc_expiration = 2018/08/21 + # + # expect(order.cc_name.valid?).must_equal false + # expect(order.errors.messages).must_include :cc_expiration + # end it "must be invalid with more than 16 digits for credit card" do order.cc_digit = 123 diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 2fd1b154ac..30b526c60e 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe Product do - let(:product) { Product.new } + # let(:product) { Product.new } describe "validation" do diff --git a/test/models/review_test.rb b/test/models/review_test.rb index ce8378a033..aa99e2f6ac 100644 --- a/test/models/review_test.rb +++ b/test/models/review_test.rb @@ -3,7 +3,35 @@ describe Review do let(:review) { Review.new } - it "must be valid" do - value(review).must_be :valid? + # it "must be valid" do + # value(review).must_be :valid? + # end + + describe "relations" do + + it "has a product" do + review = review(:cake1) + review.must_respond_to :product + review.product.must_be_kind_of Product + end + end + + describe "validations" do + before do + + + it "allows multiple users to review for a product" do + review1 = Review.new(product: cake1) + review1.save! + review2 = Review.new(product: cake1) + review2.valid?.must_equal true + end + + # it "doesn't allow the merchant to leave a review for their own work" do + # review1 = Review.new(product: cake1) + # review1.save! + # review1.errors.messages.must_include :user + # end end + end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index cc862ac2d9..cd9152db7b 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,9 +1,49 @@ require "test_helper" describe User do - let(:user) { User.new } + # let(:user) { User.new } + # + # it "must be valid" do + # value(user).must_be :valid? + # end + + describe "relations" do + before do + user = User.new + end + + it "has a list of products" do + + user = product(:create) + + user.must_respond_to :product + user.products.each do |product| + product.must_be_kind_of Product + end + end + + end + + describe "validations" do + it "requires a username" do + user = User.new + user.valid?.must_equal false + user.errors.messages.must_include :username + end + + it "requires a unique username" do + username = "test username" + user1 = User.new(username: username) + + # This must go through, so we use create! + user1.save! + + user2 = User.new(username: username) + result = user2.save + result.must_equal false + user2.errors.messages.must_include :username + end + - it "must be valid" do - value(user).must_be :valid? end end From 87a6aff3d4b33a89895da497bdeb7e189aad2c41 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Sun, 21 Oct 2018 21:45:46 -0700 Subject: [PATCH 068/192] order_status table created --- app/controllers/users_controller.rb | 7 ++++--- app/models/order.rb | 10 +++++++++- app/models/order_status.rb | 2 ++ app/models/user.rb | 9 +++++++++ db/migrate/20181021220825_create_order_statuses.rb | 9 +++++++++ db/schema.rb | 8 +++++++- db/seeds.rb | 6 ++++++ test/fixtures/order_statuses.yml | 7 +++++++ test/models/order_status_test.rb | 9 +++++++++ 9 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 app/models/order_status.rb create mode 100644 db/migrate/20181021220825_create_order_statuses.rb create mode 100644 test/fixtures/order_statuses.yml create mode 100644 test/models/order_status_test.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a1d618861f..fca93808bc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -12,6 +12,10 @@ def new @user = User.new end + # GET /users/1/edit + def edit + end + # POST /users def create @user = User.new(user_params) @@ -38,9 +42,6 @@ def user_params params.require(:user).permit(:uid, :username, :email, :id) end - # GET /users/1/edit - def edit - end end diff --git a/app/models/order.rb b/app/models/order.rb index fedca62a55..2abf21976c 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -4,9 +4,11 @@ class Order < ApplicationRecord #relationships # has_and_belongs_to_many :products - + belongs_to :order_status has_many :order_items + before_create :set_order_status + def total_price order_items.collect { |order_item| order_item.quantity * order_item.unit_price }.sum @@ -23,4 +25,10 @@ def place_order end + private + + def set_order_status + self.order_status_id = 1 + end + end diff --git a/app/models/order_status.rb b/app/models/order_status.rb new file mode 100644 index 0000000000..c98cd5a403 --- /dev/null +++ b/app/models/order_status.rb @@ -0,0 +1,2 @@ +class OrderStatus < ApplicationRecord +end diff --git a/app/models/user.rb b/app/models/user.rb index 19b6bf07dd..bc97fe412a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,4 +14,13 @@ def self.new_user(auth_hash) return new_user end + def revenue + @pending = self.orders.where(status: 1) + @paid = self.orders.where(status: 2) + @shipped = self.orders.where(status: 3) + @completed = self.orders.where(status: 4) + + end + + end diff --git a/db/migrate/20181021220825_create_order_statuses.rb b/db/migrate/20181021220825_create_order_statuses.rb new file mode 100644 index 0000000000..e5627c8c77 --- /dev/null +++ b/db/migrate/20181021220825_create_order_statuses.rb @@ -0,0 +1,9 @@ +class CreateOrderStatuses < ActiveRecord::Migration[5.2] + def change + create_table :order_statuses do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index cce70d47b2..da02e30f50 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_19_215725) do +ActiveRecord::Schema.define(version: 2018_10_21_220825) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -37,6 +37,12 @@ t.datetime "updated_at", null: false end + create_table "order_statuses", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "orders", force: :cascade do |t| t.string "status" t.string "cust_name" diff --git a/db/seeds.rb b/db/seeds.rb index a092537358..294b633737 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -147,3 +147,9 @@ product.categories << Category.all.sample end + +OrderStatus.delete_all +OrderStatus.create! id: 1, name: "In Progress" +OrderStatus.create! id: 2, name: "Placed" +OrderStatus.create! id: 3, name: "Shipped" +OrderStatus.create! id: 4, name: "Cancelled" diff --git a/test/fixtures/order_statuses.yml b/test/fixtures/order_statuses.yml new file mode 100644 index 0000000000..56066c68af --- /dev/null +++ b/test/fixtures/order_statuses.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/order_status_test.rb b/test/models/order_status_test.rb new file mode 100644 index 0000000000..ab042fbd3e --- /dev/null +++ b/test/models/order_status_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderStatus do + let(:order_status) { OrderStatus.new } + + it "must be valid" do + value(order_status).must_be :valid? + end +end From 92c096261aa1a80bd413377b9dac808426e1651e Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Sun, 21 Oct 2018 22:18:54 -0700 Subject: [PATCH 069/192] order_status migration --- app/views/users/show.html.erb | 39 ++++++++++++++++++- ...add_reference_order_status_id_to_orders.rb | 5 +++ db/schema.rb | 5 ++- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181022045157_add_reference_order_status_id_to_orders.rb diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c2120a527a..1054954585 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -59,9 +59,44 @@ -<%= link_to 'Back', users_path %> +<%# view all orders that belong to this%> + + + + + + + + + + + + <% if @user.order_items.empty? %> + <%= "No Products List to Sell" %> + <% else %> + <% @user.order_items.each do |product| %> + + + + + + <% if product.active %> + + + <% else %> + + + <% end %> + + <% end %> + <% end %> + +
    NAMEPRICEQUANTITYRATINGSTATUS
    <%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= product.inv_qty %> <%= product.avg_rating %>ACTIVE<%= link_to "RETIRE", product_status_path(product), class: "btn btn-warning ", method: :patch%>RETIRED<%= link_to "ACTIVATE", product_status_path(product), class: "btn btn-success", method: :patch%>
    + + +<%= link_to 'Back', root_path %> + -<%# view all orders that belong to this%> <%# view order fulfillment%> diff --git a/db/migrate/20181022045157_add_reference_order_status_id_to_orders.rb b/db/migrate/20181022045157_add_reference_order_status_id_to_orders.rb new file mode 100644 index 0000000000..a917c7d004 --- /dev/null +++ b/db/migrate/20181022045157_add_reference_order_status_id_to_orders.rb @@ -0,0 +1,5 @@ +class AddReferenceOrderStatusIdToOrders < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :order_status, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index da02e30f50..2ef825c182 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_220825) do +ActiveRecord::Schema.define(version: 2018_10_22_045157) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -55,6 +55,8 @@ t.integer "cc_zip" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "order_status_id" + t.index ["order_status_id"], name: "index_orders_on_order_status_id" end create_table "products", force: :cascade do |t| @@ -88,6 +90,7 @@ t.string "provider" end + add_foreign_key "orders", "order_statuses" add_foreign_key "products", "users" add_foreign_key "reviews", "products" end From 9d11e69496a68642b041a1a7e2f999e4b9308015 Mon Sep 17 00:00:00 2001 From: Trang Date: Sun, 21 Oct 2018 23:07:53 -0700 Subject: [PATCH 070/192] styled nav and home --- app/assets/stylesheets/application.scss | 42 +++++++++++++++++++------ app/assets/stylesheets/products.scss | 34 +++++++++++++++----- app/models/product.rb | 4 +-- app/views/layouts/application.html.erb | 7 +++-- app/views/products/home.html.erb | 4 +-- 5 files changed, 67 insertions(+), 24 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 86309e4c6b..57d0a8a2db 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -22,16 +22,29 @@ body { margin-bottom: 60px; } +p { + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + .navbar { - margin-bottom: 20px; + font-family: 'Alegreya Sans SC', sans-serif; } .navbar-brand { - color: hotpink; + color: #8ff9f6 !important; + font-weight: bold; +} + +.navbar-brand:hover { + color: #0abab5 !important; + font-weight: bold; } .fa-github-square { - font-size: 2em; + font-size: 1.75em; color: lightgrey; } @@ -40,7 +53,7 @@ body { } .fa-sign-in-alt { - font-size: 2em; + font-size: 1.5em; color: lightgrey; } @@ -48,17 +61,28 @@ body { color: white; } +.fa-shopping-cart { + font-size: 1.25rem; + color: lightgrey; + padding-top: .25rem; +} + +.fa-shopping-cart:hover { + color: white; +} + .right { padding-right: 13px; } -.btn-primary { - background-color: #EC407A; - border: #F48FB1; +.btn { + background-color: #0abab5; + border: #0abab5; color: white; } .btn:hover { - opacity: 0.5; - background-color: #EC407A; + opacity: 0.75; + background-color: #0abab5; + border: #0abab5; } diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 14130541c7..34edcee0aa 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -56,9 +56,12 @@ -------------------------------------------------- */ /* Carousel base class */ -.carousel { - margin-bottom: 4rem; + +#myCarousel { + margin: auto; + margin-bottom: 3rem; } + /* Since positioning the image, we need to help out the caption */ .carousel-caption { bottom: 3rem; @@ -70,14 +73,29 @@ height: 32rem; background-color: #777; } -.carousel-item > img { - position: absolute; - top: 0; - left: 0; - min-width: 100%; - height: 32rem; + +// .carousel-item > img { +// position: absolute; +// top: 0; +// left: 0; +// min-width: 100%; +// height: 32rem; +// } + +.carousel-item img { + object-position: center; /* Center the image within the element */ + width: 100%; } +h4 { + font-family: 'Alegreya Sans SC', sans-serif; +} + +.rounded-circle { + width: 220px; + height: auto; + margin-bottom: 1rem; +} /* MARKETING CONTENT -------------------------------------------------- */ diff --git a/app/models/product.rb b/app/models/product.rb index 88516e5462..0bbcd7569e 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,7 +11,7 @@ class Product < ApplicationRecord has_many :order_items def self.by_category(id) - all_products = Product.all + all_products = Product.all.where(active: true) category_products = [] all_products.each do |product| @@ -23,7 +23,7 @@ def self.by_category(id) end def self.by_merchant(id) - all_products = Product.all + all_products = Product.all.where(active: true) merchant_products = [] all_products.each do |product| diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9d8eb4185d..fe263b2e49 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,18 +7,19 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - + +
    +
    From dadd615c2320633595d92ea682a1485367a6ca98 Mon Sep 17 00:00:00 2001 From: Trang Date: Mon, 22 Oct 2018 13:48:46 -0700 Subject: [PATCH 091/192] add fa fa log out --- app/assets/stylesheets/application.scss | 10 ++++++++++ app/models/order_item.rb | 6 ++---- app/views/layouts/application.html.erb | 9 ++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 9b88858a1d..c86b86886c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -65,10 +65,20 @@ p { color: white; } +.fa-sign-out-alt { + font-size: 1.5rem; + color: lightgrey; +} + +.fa-sign-out-alt:hover { + color: white; +} + .fa-shopping-cart { font-size: 1.25rem; color: lightgrey; padding-top: .25rem; + padding-left: .5rem; } .fa-shopping-cart:hover { diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 7dab398f7e..51eef879dc 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,13 +1,11 @@ class OrderItem < ApplicationRecord - #validations - n/a - #relationships + validates :qty, numericality: { only_integer: true } + belongs_to :product belongs_to :order - - def subtotal return self.product.price * qty end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ee095d272d..1c197e9b7c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,7 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + @@ -45,14 +46,12 @@ +
    + <%= yield %> + +
    + + +
    + + +
    + + +
    + + +
    Bakesy
    +

    Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

    + +
    + + +
    + + +
    + + +
    + +
      +
    • + <%= link_to "Home", root_path%> +
    • +
    • + <%= link_to "All Products", products_path %> +
    • +
    • + <%= link_to "Login with Github", "/auth/github" %> +
    • +
    • + Shopping Cart +
    • +
    + +
    + + + +
    + + +
    + +
      +
    • + Shop by Merchant + +
    • +
    • + Shop by Category + +
    • +
    + +
    + + +
    + + +
    + + + + + + +
    + diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 846478e4ff..dc33b5476e 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -1,5 +1,5 @@ <%= form_with(model: order, local: true) do |form| %> - <% render partial "/layouts/form_errors", locals: { error_hash: order}%> + <%# render partial "/layouts/form_errors", locals: { error_hash: order}%>
    diff --git a/app/views/products/_productslist.html.erb b/app/views/products/_productslist.html.erb index ba1a87e03c..fa14944119 100644 --- a/app/views/products/_productslist.html.erb +++ b/app/views/products/_productslist.html.erb @@ -6,7 +6,8 @@
    - <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %> + + <%#=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id) %>

    <%= product.prod_name %>

    @@ -23,7 +24,7 @@ -->
    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index b4ae27141d..26dc6ee18a 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -76,12 +76,100 @@ <%= f.submit "Add to cart", class: "btn btn-primary" %> <% end %> +adddfdd <%= link_to 'Back', products_path %> <%= link_to 'Back', products_path, class: "btn btn-success" %> + + + + + + +
    +
    +
    + <%=link_to image_tag("#{@product.image}", alt: "#{@product.description}"), product_path(@product.id) %> +
    +
    +
    +
    +

    <%= @product.prod_name %>

    +
    +
    +
    +
    + <% @product.categories.each do |cat| %> + <%= cat.category.capitalize %> + <% end %> + <%@product.id%> +
    +
    + +
    +
    +

    + Tasting Notes: <%= @product.description %> +

    +
    + +
    +
    + Four out of Five Stars + + + + + + 61 +
    +
    + Write a Review +
    +
    + +
    +
    +

    $129.00

    +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + In Stock +
    +
    +
    +
    +
    + +
    +
    +
    + + + + + + + + + +
    @@ -95,6 +183,7 @@ +
    diff --git a/test/factories/category.rb b/test/factories/category.rb index 1c7bc92210..53208610a8 100644 --- a/test/factories/category.rb +++ b/test/factories/category.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :category do - category Faker::Name.first_name + category { Faker::Name.first_name } end -end \ No newline at end of file +end diff --git a/test/factories/order.rb b/test/factories/order.rb index dd38697f9c..9aad8ac4bf 100644 --- a/test/factories/order.rb +++ b/test/factories/order.rb @@ -5,7 +5,7 @@ cust_email { Faker::Internet.safe_email} mailing_address { Faker::Address.full_address} cc_name { Faker::FunnyName.two_word_name} - cc_digit { Faker::Finance.credit_card.number(16)} + cc_digit { "1" * 16} cc_expiration { Faker::Business.credit_card_expiry_date} cc_cvv { Faker::Number.number(3)} cc_zip { Faker::Number.number(5) } diff --git a/test/factories/product.rb b/test/factories/product.rb index 1f8f856e3e..32d88c7eea 100644 --- a/test/factories/product.rb +++ b/test/factories/product.rb @@ -7,5 +7,6 @@ inv_qty { Faker::Number.between(0, 30)} active { Faker::Boolean.boolean} image { "image test"} + user end end diff --git a/test/factories/user.rb b/test/factories/user.rb index d667909da4..d63e3989ff 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -1,5 +1,7 @@ FactoryBot.define do factory :user do - name { Faker::Name.first_name } + uid { "1"} + username { Faker::Name.first_name } + email { "lbird@ada.com" } end -end \ No newline at end of file +end diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index f72bfa9e00..ace7215bc5 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -1,15 +1,15 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - status: MyString + status: pending cust_name: MyString - cust_email: MyString - mailing_address: 1 + cust_email: MyString@yahoo.com + mailing_address: 123 Broadway St. cc_name: MyString - cc_digit: 1 + cc_digit: 1111111111111111 cc_expiration: 2018-10-17 - cc_cvv: 1 - cc_zip: 1 + cc_cvv: 123 + cc_zip: 98765 two: status: MyString diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 76247fdc11..cadde6d816 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -4,23 +4,12 @@ describe "validation" do - let(:user) { user(:one) } - before do - 1.times do - order = create(:order) - end - end - - # it "must be a valid order" do - # - # expect(order.valid?).must_equal true - # end + let(:order) { build(:order) } it "must be invalid without a customer name " do - order.cust_name = nil - expect(order.cust_name.valid?).must_equal false + expect(order.valid?).must_equal false expect(order.errors.messages).must_include :cust_name end @@ -28,7 +17,7 @@ order.cust_email = nil order.cust_email = 123 - expect(order.cust_email.valid?).must_equal false + expect(order.valid?).must_equal false expect(order.errors.messages).must_include :cust_email end @@ -36,16 +25,16 @@ it "must be invalid without a mailing address" do order.mailing_address = nil - expect(order.mailing_address.valid?).must_equal false + expect(order.valid?).must_equal false expect(order.errors.messages).must_include :mailing_address end it "must be invalid without a customer name" do - order.cc_name = nil + order.cust_name = nil - expect(order.cc_name.valid?).must_equal false - expect(order.errors.messages).must_include :cc_name + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cust_name end # it "must be invalid if date has expired" do @@ -55,46 +44,56 @@ # expect(order.errors.messages).must_include :cc_expiration # end - it "must be invalid with more than 16 digits for credit card" do + it "must be invalid with less than 16 digits for credit card" do order.cc_digit = 123 - order2.cc_digit = "hi" - expect(order.cc_digit.valid?).must_equal false - expect(order2.cc_digit.valid?).must_equal false + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_digit + + order.cc_digit = "hi" + + expect(order.valid?).must_equal false expect(order.errors.messages).must_include :cc_digit - expect(order2.errors.messages).must_include :cc_digit end it "must have only 3 digits for CVV" do order.cc_cvv = 12 - order2.cc_cvv = "hi" - expect(order.cc_cvv.valid?).must_equal false - expect(order2.cc_cvv.valid?).must_equal false + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_cvv + + order.cc_cvv = "hi" + + expect(order.valid?).must_equal false expect(order.errors.messages).must_include :cc_cvv - expect(order2.errors.messages).must_include :cc_cvv end - it "must be 5 digits in length for zip code" do - order.cc_zip = 12 - order2.cc_zip = "hi" + it "must have only 16 digits for Credit Card number" do + order.cc_digit = 1234123412341234 - expect(order.cc_zip.valid?).must_equal false - expect(order2.cc_zip.valid?).must_equal false - expect(order.errors.messages).must_include :cc_zip - expect(order2.errors.messages).must_include :cc_zip + expect(order.valid?).must_equal true end + it "must be 5 digits in length for zip code" do + order.cc_zip = 1255 + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip - describe "relations" do + order.cc_zip = "hi" - it "belong to a product" do - order = product.order - #add the yml file - expect(order).must_be_instance_of Product - expect(order.id).must_equal product.order_id + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip end - end + + + # describe "relations" do + # + # it "belong to a product" do + # expect(order.user).must_be_instance_of User + # expect(order.user.orders).must_include Order + # end + # end end end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 30b526c60e..e5c59e6d78 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,95 +1,58 @@ require "test_helper" describe Product do - # let(:product) { Product.new } + let(:product) { build(:product) } + let(:product2) { create(:product)} describe "validation" do it "must be valid" do - 2.times do - product = create(:product) - end - expect(product.valid?).must_equal true end - it "must be invalid without a category " do - 1.times do - product = create(:product) - end - - product.category = nil - - expect(product.category.valid?).must_equal false - expect(product.errors.messages).must_include :category - end - it "must be invalid without a product name " do - 1.times do - product = create(:product) - end product.prod_name = nil - expect(product.prod_name.valid?).must_equal false - expect(product.errors.messages).must_include :prod_name - end - - it "must be a string for product name " do - 1.times do - product = create(:product) - end - product.prod_name = 123 - - expect(product.prod_name.valid?).must_be_instance_of String + expect(product.valid?).must_equal false expect(product.errors.messages).must_include :prod_name end it "must be invalid without a description" do - 1.times do - product = create(:product) - end - product.description = nil - expect(product.description.valid?).must_equal false + expect(product.valid?).must_equal false expect(product.errors.messages).must_include :description end it "must be invalid without a price" do - 1.times do - product = create(:product) - end - product.price = nil - expect(product.price.valid?).must_equal false + expect(product.valid?).must_equal false expect(product.errors.messages).must_include :price end - it "must have a unique name for each product" do - product = products(:one) - product2 = products(:one) - - expect(product2.prod_name.valid?).must_equal false + it "must have a unique product name" do + product.prod_name = product2.prod_name + expect(product.valid?).must_equal false end end describe "relations" do - it "belong to a user" do - product = user.product - #add the yml file - expect(product).must_be_instance_of User - expect(product.id).must_equal user.product_id + # it "belong to a user" do + # expect(product.user).must_be_instance_of User + # expect(product.user.products).must_include product + # end + + it "must respond to reviews" do + expect(product).must_respond_to :reviews end - it "can have a rating" do - product = rating.product - expect(product).must_be_instance_of Review - expect(product.id).must_equal review.product_id + it "responds to categories" do + expect(product).must_respond_to :categories end end From 4d426745c1743ee4091fa1ed80fa2b09392e2f51 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 08:14:21 -0700 Subject: [PATCH 100/192] order_status --- app/controllers/order_items_controller.rb | 37 ++++++++---- app/controllers/orders_controller.rb | 7 ++- app/models/order.rb | 20 +++++-- app/models/order_item.rb | 8 +-- app/models/order_status.rb | 2 +- app/models/product.rb | 31 ++--------- app/models/user.rb | 14 ++--- app/views/users/show.html.erb | 68 +++++++++-------------- config/routes.rb | 6 +- 9 files changed, 86 insertions(+), 107 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index be987ab74c..cc481742a5 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,17 +1,15 @@ class OrderItemsController < ApplicationController + before_action :set_order, only: [:create, :update, :cart_direct] + def create @order = current_order # check if item is in stock - @order_item = @order.order_items.new(order_item_params) if @order.save session[:order_id] = @order.id - redirect_to cart_path(@order.id) - else - raise flash[:warning] = "Item order not placed" redirect_to root_path end @@ -19,18 +17,18 @@ def create end def update - @order = current_order + # @order = current_order <- moved to controller filter # check if item is in stock @order_item = @order.order_items.find(params[:id]) @order_item.update_attributes(order_item_params) @order.save - redirect_to cart_path(@order.id) + redirect_back(fallback_location: cart_path(@order.id)) end def cart_direct - @order = current_order - @order_item = @order.order_items.new(product_id: params[:id], qty: 1, order_status_id: 1) + # @order = current_order <- moved to controller filter + @order_item = @order.order_items.new(product_id: params[:id], qty: 1, shipped: false) @order_item.save @order.save session[:order_id] = @order.id @@ -39,7 +37,7 @@ def cart_direct end def destroy - @order = current_order + # @order = current_order <- moved to controller filter @order_item = @order.order_items.find(params[:id]) @order_item.destroy @order_items = @order.order_items @@ -47,13 +45,28 @@ def destroy redirect_to cart_path(@order.id) end - private + def ship + @order_item = OrderItem.find_by(product_id: params[:id]) + @order_item.shipped = true + Order.check_order_status(@order) + if @order_item.save + flash[:success] = 'Item(s) have been marked as shipped' + redirect_back(fallback_location: root_path) + else + flash.now[:warning] = 'Error in shipment status.' + render :show + end - def order_item_params + end - params.require(:order_item).permit(:product_id, :qty, :order_status_id) + private + def order_item_params + params.require(:order_item).permit(:product_id, :qty, :shipped) end + def set_order + @order = current_order + end end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2416300218..4846897d80 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,6 +1,7 @@ class OrdersController < ApplicationController before_action :set_order, only: [:show, :edit, :update, :destroy] + before_action :check_status, only: [:show] # GET /orders def index @@ -29,7 +30,7 @@ def edit # flash notices do not workx def create @order = Order.new(order_params) - + # @order.status = "Pending" if @order.save @order.place_order flash[:success] = 'Order was successfully created.' @@ -76,4 +77,8 @@ def set_order def order_params params.require(:order).permit(:status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) end + + def check_status + Order.check_order_status(@order) + end end diff --git a/app/models/order.rb b/app/models/order.rb index 9f44cb4eaf..72fc115785 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -2,12 +2,9 @@ class Order < ApplicationRecord #validations #relationships - has_many :order_items - - def total_price self.order_items.sum do |order_item| product_id = Product.find_by(id: order_item.product_id) @@ -20,15 +17,16 @@ def place_order self.order_items do |order_item| product = Product.find_by(id: order_item.product_id) quantity = product.inv_qty - quantity -= 1 + quantity -= 1 # needs to reduce by qty purchased product = quantity product.save end self.status = "Paid" self.save + # order is not getting updated + raise # clears current cart () erase order_id - end @@ -36,6 +34,18 @@ def date_of_order return self.created_at.strftime("%B %d, %Y") end + def check_order_status(order) + if order.order_items.all? {|item| item.shipped} + order.status = "Complete" + raise + order.save + end + end + + def destroy + # method to cancel order + end + private # def set_order_status diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 024ea18f99..cf67924416 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -3,9 +3,9 @@ class OrderItem < ApplicationRecord belongs_to :product belongs_to :order - belongs_to :order_status - before_save :set_order_status + + # before_save :set_order_status def subtotal return self.product.price * qty @@ -13,8 +13,6 @@ def subtotal private - def set_order_status - self.order_status_id = 1 - end + end diff --git a/app/models/order_status.rb b/app/models/order_status.rb index 8ae42b9d91..53cc240f47 100644 --- a/app/models/order_status.rb +++ b/app/models/order_status.rb @@ -1,6 +1,6 @@ class OrderStatus < ApplicationRecord #relationships - has_many :order_items + # has_many :order_items end diff --git a/app/models/product.rb b/app/models/product.rb index 487f0e58d5..1812807f66 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -35,33 +35,12 @@ def self.by_merchant(id) end - # def avg_rating - # average_rating = self.reviews.reduce(0) { |sum, review| sum + review.rating } - # return average_rating - # end - - - # def self.status(product) - # if product.active - # product.update(active: false) - # else - # product.update(active: true) - # end - # - # end - def avg_rating - total = 0 - if self.reviews.count > 0 - self.reviews.each do |review| - total += review.rating - end + reviews = self.reviews + if reviews.count > 0 + total = reviews.reduce(0) { |sum, review| sum + review.rating } + avg = total/reviews.count return avg - - else - return 0 end end - - -end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 9a4c3ca4ad..cd2c7ec52a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,21 +24,15 @@ def find_orders end end - # OrderItem.all.each do |item| - # if self.products.include? item.product_id - # sold << item - # end - # end - # binding.pry return sold end def revenue - @pending = self.orders.where(status: 1) - @paid = self.orders.where(status: 2) - @shipped = self.orders.where(status: 3) - @completed = self.orders.where(status: 4) + @pending = self.orders.where(status: "Pending") + @paid = self.orders.where(status: "Paid") + @shipped = self.orders.where(status: "Complete") + @completed = self.orders.where(status: "Cancelled") end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 6bb0e083b5..615f28165f 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -19,13 +19,9 @@
    <%= link_to 'List a Product', new_product_path, class: "sell-link btn btn-info" %> | - <%= link_to 'View Categories', categories_path, class: "btn btn-info" %>
    - - -
    @@ -61,8 +57,7 @@ -<%# need to use orderitem table to find all occurences where product_id matches the - merchant's products%> +
    NAME
    @@ -70,48 +65,37 @@ - - + + - - - <% sold = @user.find_orders %> - - <% if sold.empty? %> - <%= "No Products Have Sold" %> - <% else %> - <% sold.each do |product| %> - - - <% or_item = OrderItem.find_by(product_id: product.id) %> - - - - - - <% if or_item.order_status%> - - - <% else %> - - - - <% end %> + <% sold = @user.find_orders %> + <% if sold.empty? %> + <%= "No Products Have Sold" %> + <% else %> + <% sold.each do |product| %> + + <% or_item = OrderItem.find_by(product_id: product.id) %> + + + + + + <% if or_item.shipped %> + + <% else %> + + <% end %> + <% ord = Order.find(or_item.order.id) %> + <% Order.check_order_status(ord) %> + + + <% end %> <% end %> - <% end %>
    ORDER #PRICE QUANTITY SUBTOTALSTATUS ITEM STATUSORDER STATUS
    <%= or_item.id %> <%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= or_item.qty %> <%= format_price(product.price * or_item.qty) %>PENDING<%# link_to "RETIRE", product_status_path(product), class: "btn btn-warning ", method: :patch%>SHIPPED<%# link_to "ACTIVATE", product_status_path(product), class: "btn btn-success", method: :patch%>
    <%= or_item.order.id %> <%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= or_item.qty %> <%= format_price(product.price * or_item.qty) %>SHIPPED PAID + <%= link_to "CONFIRM SHIPPED", ship_item_path(product), class: "btn btn-outline-info btn-sm", method: :patch%> <%= ord.status %>
    <%# view order fulfillment%> <%= link_to 'Back', root_path %> - - - - - - - - -<%# view order fulfillment%> diff --git a/config/routes.rb b/config/routes.rb index bcdadf0440..31c8b30729 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,17 +1,14 @@ Rails.application.routes.draw do root 'products#home' - get "/auth/:provider/callback", to: "sessions#create", as: "login" resources :products do resources :reviews, only: [:new, :create] end - get "/auth/:provider/callback", to: "sessions#create" - # get 'sessions/login', to: "sessions#new" #page for a new session delete "/logout", to: "sessions#destroy", as: "logout" @@ -21,6 +18,7 @@ resources :carts, only: [:show] + patch 'order_items/:id/ship', to: "order_items#ship", as: "ship_item" post "order_items/cart_direct/:id", to: "order_items#cart_direct", as: "quick_shop" resources :order_items, only: [:create, :update, :destroy] @@ -28,9 +26,7 @@ resources :orders get 'products/category/:id', to: "products#category", as: "category" - patch 'products/:id/retire', to: "products#status", as: "product_status" - get 'products/merchant/:id', to: "products#merchant", as: "merchant" resources :products resources :users From 2d3722082a8e07183db5721937029ddc23bccd7c Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 08:21:56 -0700 Subject: [PATCH 101/192] oauth user fixture added --- test/fixtures/users.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 50a0ddc177..50fcb0f6bb 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,11 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - uid: 1 - username: Lady Bird - email: lbird@ada. +ada: + provider: github + uid: 2354234 + email: ada@lovelace.com + username: countess_ada -two: - uid: 2 - username: MyString - email: MyString +grace: + provider: github + uid: 13371337 + email: grace@hopper.com + username: graceful_hopps \ No newline at end of file From de83a1364a652f7e3203823a1c22e8aebb709fc1 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 11:16:13 -0700 Subject: [PATCH 102/192] quantity of product gets updated with purchase --- app/controllers/orders_controller.rb | 7 ++++--- app/models/order.rb | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2416300218..fa05205d08 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,4 +1,4 @@ - +require 'pry' class OrdersController < ApplicationController before_action :set_order, only: [:show, :edit, :update, :destroy] @@ -10,9 +10,11 @@ def index # show Confirmation Page def show @order = Order.find_by(id: session[:order_id]) + @order.place_order @order_items = Order.find_by(id: session[:order_id]).order_items # clear shopping cart after it Confirmation page has been shown session[:order_id] = nil + binding.pry end # GET /orders/new @@ -26,12 +28,11 @@ def edit # POST /orders # must change database - # flash notices do not workx + # flash notices do not have color def create @order = Order.new(order_params) if @order.save - @order.place_order flash[:success] = 'Order was successfully created.' redirect_to order_path(@order.id) else diff --git a/app/models/order.rb b/app/models/order.rb index 6f1cf80ffb..faf2acfdd0 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,3 +1,4 @@ +require 'pry' class Order < ApplicationRecord #validations @@ -17,18 +18,16 @@ def total_price def place_order #decrease inventory + binding.pry self.order_items do |order_item| product = Product.find_by(id: order_item.product_id) quantity = product.inv_qty quantity -= 1 - product = quantity + product.inv_qty = quantity product.save end - self.status = "Paid" self.save - # clears current cart () erase order_id - end def date_of_order From 51da54ce7a4a0caba053cd672ddd4bf3babadd78 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 11:34:32 -0700 Subject: [PATCH 103/192] sucessfully decreases inventory quantity in the db, but product show page does not reflect it --- app/controllers/orders_controller.rb | 1 - app/models/order.rb | 11 ++++++++--- app/views/orders/show.html.erb | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index fa05205d08..2184a9cadf 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -14,7 +14,6 @@ def show @order_items = Order.find_by(id: session[:order_id]).order_items # clear shopping cart after it Confirmation page has been shown session[:order_id] = nil - binding.pry end # GET /orders/new diff --git a/app/models/order.rb b/app/models/order.rb index faf2acfdd0..2a11b55b62 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -18,11 +18,16 @@ def total_price def place_order #decrease inventory - binding.pry + self.order_items do |order_item| - product = Product.find_by(id: order_item.product_id) + product_id = order_item.product_id + order_quantity = order_item.qty + product = Product.find_by(id: product_id) + # get quantity quantity = product.inv_qty - quantity -= 1 + # substract amount defined in order + quantity -= order_quantity + # save quantity in product product.inv_qty = quantity product.save end diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 574e117703..23d4bd8c01 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -32,6 +32,11 @@ <%= @order.date_of_order %>

    +

    + Customer: + <%= @order.cust_name %> +

    +

    Total Price: $<%=@order.total_price %> From a04813e731f3b42c2d74f2f6144e19f6779dbca0 Mon Sep 17 00:00:00 2001 From: Trang Date: Tue, 23 Oct 2018 13:20:32 -0700 Subject: [PATCH 104/192] add number of items to display on shopping cart --- app/assets/images/github-square-brands.svg | 1 + app/assets/images/shopping-cart-solid.svg | 1 + app/assets/images/sign-out-alt-solid.svg | 1 + app/assets/stylesheets/application.scss | 62 +++++++++++++++++++--- app/assets/stylesheets/products.scss | 11 ++++ app/controllers/application_controller.rb | 7 ++- app/controllers/order_items_controller.rb | 38 ++++++------- app/controllers/products_controller.rb | 2 +- app/models/order.rb | 12 ++++- app/models/product.rb | 1 + app/views/layouts/application.html.erb | 29 +++++----- app/views/products/home.html.erb | 28 +++++----- app/views/products/show.html.erb | 12 ++--- 13 files changed, 133 insertions(+), 72 deletions(-) create mode 100644 app/assets/images/github-square-brands.svg create mode 100644 app/assets/images/shopping-cart-solid.svg create mode 100644 app/assets/images/sign-out-alt-solid.svg diff --git a/app/assets/images/github-square-brands.svg b/app/assets/images/github-square-brands.svg new file mode 100644 index 0000000000..6f560917f5 --- /dev/null +++ b/app/assets/images/github-square-brands.svg @@ -0,0 +1 @@ + diff --git a/app/assets/images/shopping-cart-solid.svg b/app/assets/images/shopping-cart-solid.svg new file mode 100644 index 0000000000..5ca1647b84 --- /dev/null +++ b/app/assets/images/shopping-cart-solid.svg @@ -0,0 +1 @@ + diff --git a/app/assets/images/sign-out-alt-solid.svg b/app/assets/images/sign-out-alt-solid.svg new file mode 100644 index 0000000000..6ffd6a88e5 --- /dev/null +++ b/app/assets/images/sign-out-alt-solid.svg @@ -0,0 +1 @@ + diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 58f8d04bd8..d23d1ddb3a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -47,9 +47,41 @@ p { font-weight: bold; } +.right-items { + height: 50px; +} + +.login { + width: 35px; + padding-top: .6rem; + opacity: .5; +} + +.login:hover { + opacity: 1; +} + +.main-cart { + padding-left: 1.5rem; + font-size: 1.75rem; +} + +.logout { + width: 35px; + padding-top: .6rem; + opacity: .5; +} + +.logout:hover { + opacity: 1; +} + .fa-github-square { font-size: 1.75em; color: lightgrey; + padding-right: .75rem; + padding-left: .75rem; + padding-top: .5rem; } .fa-github-square:hover { @@ -68,18 +100,16 @@ p { .fa-sign-out-alt { font-size: 1.5rem; color: lightgrey; - padding-left: .5rem; + padding-right: .75rem; + padding-left: .75rem; } .fa-sign-out-alt:hover { - color: white; + color: white; } .fa-shopping-cart { - font-size: 1.25rem; - color: lightgrey; - padding-top: .25rem; - padding-left: .5rem; + color: lightgray; } .fa-shopping-cart:hover { @@ -87,9 +117,25 @@ p { } .right { - padding-right: 13px; -} + padding-right: 13px; +} + +.fa-stack[data-count]:after{ + position: absolute; + right: 0%; + top: 5%; + content: attr(data-count); + font-size: 40%; + padding: .6em; + border-radius: 999px; + line-height: .75em; + color: white; + text-align: center; + min-width: 2em; + font-weight: bold; + background: #0abab5; +} .form-group { margin-left: 20px; diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index a57a6a6b3b..bfbad2b6c5 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -156,6 +156,15 @@ a.button:hover{ margin-bottom: 3rem; } +#seasonal { + font-family: 'Charmonman', cursive; + font-size: 40px; + font-weight: 500; + color: #333; + text-align: center; + padding-bottom: 1rem; +} + /* Since positioning the image, we need to help out the caption */ .carousel-caption { bottom: 3rem; @@ -179,6 +188,7 @@ a.button:hover{ .carousel-item img { object-position: center; /* Center the image within the element */ width: 100%; + opacity: .75; } .rounded-circle { @@ -228,6 +238,7 @@ a.button:hover{ margin-bottom: 1.25rem; font-size: 1.25rem; line-height: 1.4; + color: lightgray; } .featurette-heading { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 115b018260..1d710c0673 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,6 @@ class ApplicationController < ActionController::Base before_action :find_user - before_action :list_categories, :list_merchants + before_action :list_categories, :list_merchants, :current_order # before_action :require_login, except: [:create, :root] helper_method :current_order @@ -13,12 +13,11 @@ def list_merchants @users = User.all end - def current_order if !session[:order_id].nil? - Order.find(session[:order_id]) + @current_order = Order.find(session[:order_id]) else - Order.new + @current_order = Order.new end end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index be987ab74c..f74214ec19 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,17 +1,15 @@ class OrderItemsController < ApplicationController def create - @order = current_order - # check if item is in stock - - @order_item = @order.order_items.new(order_item_params) - if @order.save - session[:order_id] = @order.id + @order_item = @current_order.order_items.new(order_item_params) + @order_item.save + if @current_order.save + session[:order_id] = @current_order.id - redirect_to cart_path(@order.id) + redirect_to cart_path(@current_order.id) else - raise + flash[:warning] = "Item order not placed" redirect_to root_path end @@ -19,32 +17,28 @@ def create end def update - @order = current_order - # check if item is in stock - @order_item = @order.order_items.find(params[:id]) + @order_item = @current_order.order_items.find(params[:id]) @order_item.update_attributes(order_item_params) - @order.save + @current_order.save - redirect_to cart_path(@order.id) + redirect_to cart_path(@current_order.id) end def cart_direct - @order = current_order - @order_item = @order.order_items.new(product_id: params[:id], qty: 1, order_status_id: 1) + @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, order_status_id: 1) @order_item.save - @order.save - session[:order_id] = @order.id + @current_order.save + session[:order_id] = @current_order.id - redirect_to cart_path(@order.id) + redirect_to cart_path(@current_order.id) end def destroy - @order = current_order - @order_item = @order.order_items.find(params[:id]) + @order_item = @current_order.order_items.find(params[:id]) @order_item.destroy - @order_items = @order.order_items + @order_items = @current_order.order_items - redirect_to cart_path(@order.id) + redirect_to cart_path(@current_order.id) end private diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f07049d67f..5cb982625e 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -35,7 +35,7 @@ def create @product.user_id = session[:user_id] if @product.save(product_params) flash[:notice] = "#{@product.prod_name} was successfully created." - redirect_to user_path(user_id) + redirect_to root_path else render :new end diff --git a/app/models/order.rb b/app/models/order.rb index 510f44b249..7f94b801c0 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -5,7 +5,17 @@ class Order < ApplicationRecord has_many :order_items - + def items_in_cart + num = 0 + if self.order_items.empty? + return nil + else + self.order_items.each do |item| + num += item.qty + end + end + return num + end def total_price diff --git a/app/models/product.rb b/app/models/product.rb index 487f0e58d5..e9fba0b9cd 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -56,6 +56,7 @@ def avg_rating self.reviews.each do |review| total += review.rating end + avg = total/self.reviews.count return avg else diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b51fea14c9..3bdfaaba66 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -43,26 +43,23 @@ <% end %>

    + -
    diff --git a/app/views/products/home.html.erb b/app/views/products/home.html.erb index a2b14c3059..0f5a954f0d 100644 --- a/app/views/products/home.html.erb +++ b/app/views/products/home.html.erb @@ -11,19 +11,19 @@ First slide
    @@ -31,9 +31,9 @@ Third slide
    @@ -56,24 +56,24 @@
    - +

    Seasonal Favorites

    Generic placeholder image

    Vanilla, "I Vote Cupcake"

    -

    Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.

    +

    Show your red, white, and blue this midterm election with our patriotic cupcakes.

    View details »

    Generic placeholder image

    Pumpkin Cardamom

    -

    Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.

    +

    Cozy up this Autumn with our Pumpkin Cardamom spiced cupcakes.

    View details »

    Generic placeholder image

    Fig & Honey

    -

    Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

    +

    Try a taste of this seasonal favorite, with locally sourced figs and honey.

    View details »

    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index b4ae27141d..4ff8c371c9 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -67,14 +67,14 @@ <%= @product.inv_qty %>

    -<%= form_with model: @order_item do |f| %> - <%= f.label :qty %> - <%= f.select :qty, (1..@product.inv_qty).to_a %> +<%#= form_with model: @order_item do |f| %> + <%#= f.label :qty %> + <%#= f.select :qty, (1..@product.inv_qty).to_a %> - <%= f.hidden_field :product_id, :value => @product.id %> + <%#= f.hidden_field :product_id, :value => @product.id %> - <%= f.submit "Add to cart", class: "btn btn-primary" %> -<% end %> + <%#= f.submit "Add to cart", class: "btn btn-primary" %> +<%# end %> From 8eb97da11bb1bb9ae40f2a10faac65b382ed10e4 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 13:38:55 -0700 Subject: [PATCH 105/192] customer info is saved to the right order --- app/controllers/orders_controller.rb | 7 +++---- app/controllers/products_controller.rb | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2184a9cadf..aa7825689d 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -9,10 +9,8 @@ def index # show Confirmation Page def show - @order = Order.find_by(id: session[:order_id]) - @order.place_order @order_items = Order.find_by(id: session[:order_id]).order_items - # clear shopping cart after it Confirmation page has been shown + # clear shopping cart after confirmation page has been shown session[:order_id] = nil end @@ -30,8 +28,9 @@ def edit # flash notices do not have color def create @order = Order.new(order_params) - + # it successfully grabs and saves all fields put in the form if @order.save + @order.save flash[:success] = 'Order was successfully created.' redirect_to order_path(@order.id) else diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index fb5bb3f928..1d51f13ce7 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -12,6 +12,7 @@ def show @order = current_order @order_item = @order.order_items.find_by(product_id: params[:id]) + # setting up space, creating a blank row, not filling out items if @order_item.nil? @order_item = current_order.order_items.new end @@ -70,7 +71,7 @@ def category def merchant @user = User.find_by(id: params[:id]) @products = Product.by_merchant(params[:id].to_i) - + end private From a749bbdc47f63eacc57849e58ea812d504621e00 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 14:04:41 -0700 Subject: [PATCH 106/192] order items from the sessions are saved to the order that contains client information --- app/controllers/orders_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index aa7825689d..7dcb7e4cf6 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -9,7 +9,13 @@ def index # show Confirmation Page def show + # session id is not the same as current_order id - their difference is by 1 + # get current order that has customer info with @order + @order.place_order # decrease inventory and change status to paid + # order items are in the current session @order_items = Order.find_by(id: session[:order_id]).order_items + # save order items from the current session to the session that has the personal information + @order.order_items = @order_items # clear shopping cart after confirmation page has been shown session[:order_id] = nil end From 7b1544f0d0bd008669bf05de40dc034ac7f20bf6 Mon Sep 17 00:00:00 2001 From: Trang Date: Tue, 23 Oct 2018 14:06:11 -0700 Subject: [PATCH 107/192] cart styling --- app/assets/stylesheets/application.scss | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index d23d1ddb3a..955aac335d 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -48,12 +48,12 @@ p { } .right-items { - height: 50px; + height: 40px; } .login { - width: 35px; - padding-top: .6rem; + width: 25px; + padding-top: .5rem; opacity: .5; } @@ -63,12 +63,13 @@ p { .main-cart { padding-left: 1.5rem; - font-size: 1.75rem; + font-size: 1.5rem; + margin-bottom: 1.5rem; } .logout { - width: 35px; - padding-top: .6rem; + width: 25px; + padding-top: .5rem; opacity: .5; } @@ -123,9 +124,9 @@ p { .fa-stack[data-count]:after{ position: absolute; right: 0%; - top: 5%; + top: 0%; content: attr(data-count); - font-size: 40%; + font-size: 35%; padding: .6em; border-radius: 999px; line-height: .75em; From c6072b9c5163544e7ec88866efd7f5bd860fd4ba Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 14:09:28 -0700 Subject: [PATCH 108/192] save order items to the order --- 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 7dcb7e4cf6..76dcb7d3e7 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -16,6 +16,7 @@ def show @order_items = Order.find_by(id: session[:order_id]).order_items # save order items from the current session to the session that has the personal information @order.order_items = @order_items + @order.save # clear shopping cart after confirmation page has been shown session[:order_id] = nil end From 3d5e099cc1d78e26b0be0df3886c99f163901827 Mon Sep 17 00:00:00 2001 From: Jazz Date: Tue, 23 Oct 2018 14:34:53 -0700 Subject: [PATCH 109/192] completing test --- app/assets/stylesheets/products.scss | 5 + app/controllers/order_items_controller.rb | 5 + app/controllers/products_controller.rb | 10 +- app/models/order.rb | 14 +-- app/models/order_item.rb | 2 +- app/models/review.rb | 1 - app/models/user.rb | 4 +- app/views/carts/show.html.erb | 2 - app/views/products/show.html.erb | 117 ++++++++++------------ test/factories/product.rb | 2 +- test/factories/user.rb | 5 +- test/models/product_test.rb | 2 + test/models/review_test.rb | 52 ++++++---- 13 files changed, 122 insertions(+), 99 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index a57a6a6b3b..b3ed113812 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -28,6 +28,7 @@ .reviews > h2 { text-align: center; + padding-top: 2em; } .table-responsive-md { @@ -244,3 +245,7 @@ a.button:hover{ .products { padding-left: 2rem; } + +#product-section { + padding-top: 20px; +} diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 96a8311941..87e26171c9 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -5,14 +5,19 @@ def create # check if item is in stock @order_item = @order.order_items.new(order_item_params) + @order_item.save + if @order.save + session[:order_id] = @order.id redirect_to cart_path(@order.id) else + flash[:warning] = "Item order not placed" redirect_to root_path + end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f07049d67f..f69fa84935 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -16,8 +16,16 @@ def show @order_item = current_order.order_items.new end + @product.user_id = session[:user_id] + @session_user = @product.user_id @product = Product.find(params[:id]) + # @reviews = Review.where(product_id: @product) + @reviews = Review.where(product_id: @product) + # if @product.user_id == @session_user + # flash.now[:warning] = "You may not review your own products" + # redirect_to products_path + # end end @@ -35,7 +43,7 @@ def create @product.user_id = session[:user_id] if @product.save(product_params) flash[:notice] = "#{@product.prod_name} was successfully created." - redirect_to user_path(user_id) + redirect_to user_path(session[:user_id]) else render :new end diff --git a/app/models/order.rb b/app/models/order.rb index 459d0ef208..ff52b28ca6 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,12 +1,12 @@ class Order < ApplicationRecord #validations - validates :cust_name, presence: true, format: { with: /[a-zA-Z]/, on: :create} - validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, on: :create} - validates :cc_expiration, presence: true - validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/, on: :create} - validates :cc_zip, presence: true, format: { with: /[0-9]{5}/, on: :create} - validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } - validates :mailing_address, presence: true + validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :create + validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/ }, on: :create + validates :cc_expiration, presence: true, on: :create + validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :create + validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :create + validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :create + validates :mailing_address, presence: true, on: :create #relationships has_many :order_items diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 0e599e7cea..76f5584621 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -3,7 +3,7 @@ class OrderItem < ApplicationRecord #relationships belongs_to :product belongs_to :order - belongs_to :order_status + # belongs_to :order_status before_save :set_order_status diff --git a/app/models/review.rb b/app/models/review.rb index 04b124217e..1e11925f71 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,7 +1,6 @@ class Review < ApplicationRecord #validations validates :rating, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 6} - validates :user, uniqueness: { scope: :product, message: "can't review own work" } #relationships belongs_to :product end diff --git a/app/models/user.rb b/app/models/user.rb index 9a4c3ca4ad..fea3ce2030 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,9 @@ class User < ApplicationRecord # validations validates :username, presence: true, uniqueness: true - validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } + validates :uid, presence: true, uniqueness: {scope: :provider} + validates :email, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i } + # relationships has_many :products has_many :order_items, through: :products diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 7d52bddeee..ede3ddbdcf 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -30,6 +30,4 @@ <%= link_to "Checkout", new_order_path(), class: "btn btn-primary" %> - -
    <%= link_to "Checkout", new_order_path, class: "button" %>
    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 26dc6ee18a..35a88fda4c 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,16 +1,16 @@

    <%= notice %>

    -
    + - + + + + <%# @product.categories.each do |cat| %> + + <%# end %> + -

    + -<%= form_with model: @order_item do |f| %> - <%= f.label :qty %> - <%= f.select :qty, (1..@product.inv_qty).to_a %> +<%#= form_with model: @order_item do |f| %> + <%#= f.label :qty %> + <%#= f.select :qty, (1..@product.inv_qty).to_a %> - <%= f.hidden_field :product_id, :value => @product.id %> + <%#= f.hidden_field :product_id, :value => @product.id %> - <%= f.submit "Add to cart", class: "btn btn-primary" %> -<% end %> + <%#= f.submit "Add to cart", class: "btn btn-primary" %> +<%# end %> -adddfdd + -<%= link_to 'Back', products_path %> +<%#= link_to 'Back', products_path %> -<%= link_to 'Back', products_path, class: "btn btn-success" %> +<%#= link_to 'Back', products_path, class: "btn btn-success" %> - + @@ -92,7 +92,8 @@

    - <%=link_to image_tag("#{@product.image}", alt: "#{@product.description}"), product_path(@product.id) %> + +
    @@ -118,33 +119,34 @@
    - Four out of Five Stars - - - - - - 61 + <% if @product.reviews.length >= 1 %> + <% @product.avg_rating.round.times do %> + rating star + <% end %> + <% end %>
    - Write a Review + <%= link_to "Write A Review", new_product_review_path(@product), class:"btn btn-danger" %> +
    -

    $129.00

    +

    $<%= @product.price %>

    - + <%= form_with model: @order_item do |f| %> + <%= f.label :qty %> + <%= f.select :qty, (1..@product.inv_qty).to_a %> + <%= f.hidden_field :product_id, :value => @product.id %>
    - + <%= f.submit "Add to cart", class: "btn btn-sm btn-brand btn-full-width" %> + <% end %>
    @@ -163,15 +165,6 @@ - - - - - - - - -

    Reviews

    Average Rating: @@ -182,8 +175,6 @@ <% end %>
    - -
    diff --git a/test/factories/product.rb b/test/factories/product.rb index 32d88c7eea..7055e310d7 100644 --- a/test/factories/product.rb +++ b/test/factories/product.rb @@ -7,6 +7,6 @@ inv_qty { Faker::Number.between(0, 30)} active { Faker::Boolean.boolean} image { "image test"} - user + user end end diff --git a/test/factories/user.rb b/test/factories/user.rb index d63e3989ff..eef4244669 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -1,7 +1,8 @@ FactoryBot.define do factory :user do - uid { "1"} + uid { rand(1..(2**31)).to_s} + provider { "github" } username { Faker::Name.first_name } - email { "lbird@ada.com" } + email { Faker::Internet.email } end end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index e5c59e6d78..c2115fbe04 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -37,6 +37,8 @@ product.prod_name = product2.prod_name expect(product.valid?).must_equal false end + + end diff --git a/test/models/review_test.rb b/test/models/review_test.rb index aa99e2f6ac..76b4d82758 100644 --- a/test/models/review_test.rb +++ b/test/models/review_test.rb @@ -2,36 +2,48 @@ describe Review do let(:review) { Review.new } + let(:review1) {create(:review)} + let(:one) {create(:one)} - # it "must be valid" do - # value(review).must_be :valid? - # end + it "must be valid" do + expect(review1.valid?).must_equal true + end describe "relations" do - it "has a product" do - review = review(:cake1) - review.must_respond_to :product - review.product.must_be_kind_of Product + it "must respond to product" do + expect(review).must_respond_to :product end + end describe "validations" do - before do - + let (:user1) { User.new(username: 'chris') } + let (:user2) { User.new(username: 'chris') } + let (:work1) { Work.new(category: 'book', title: 'House of Leaves') } + let (:work2) { Work.new(category: 'book', title: 'For Whom the Bell Tolls') } + + it "allows one user to vote for multiple works" do + vote1 = Vote.new(user: user1, work: work1) + vote1.save! + vote2 = Vote.new(user: user1, work: work2) + vote2.valid?.must_equal true + end - it "allows multiple users to review for a product" do - review1 = Review.new(product: cake1) - review1.save! - review2 = Review.new(product: cake1) - review2.valid?.must_equal true + it "allows multiple users to vote for a work" do + vote1 = Vote.new(user: user1, work: work1) + vote1.save! + vote2 = Vote.new(user: user2, work: work1) + vote2.valid?.must_equal true end - # it "doesn't allow the merchant to leave a review for their own work" do - # review1 = Review.new(product: cake1) - # review1.save! - # review1.errors.messages.must_include :user - # end + it "doesn't allow the same user to vote for the same work twice" do + vote1 = Vote.new(user: user1, work: work1) + vote1.save! + vote2 = Vote.new(user: user1, work: work1) + vote2.valid?.must_equal false + vote2.errors.messages.must_include :user + end end - +end end From 9751800d592fb7510ceba8aa611c3e0e7a2229f4 Mon Sep 17 00:00:00 2001 From: Jazz Date: Tue, 23 Oct 2018 15:23:01 -0700 Subject: [PATCH 110/192] validate merchant can't review own work, navbar fix --- app/controllers/products_controller.rb | 9 -------- app/controllers/reviews_controller.rb | 7 ++++++- app/views/layouts/application.html.erb | 29 ++++++-------------------- test/models/review_test.rb | 8 ++----- 4 files changed, 14 insertions(+), 39 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f69fa84935..0471cf1899 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -16,17 +16,8 @@ def show @order_item = current_order.order_items.new end - @product.user_id = session[:user_id] - @session_user = @product.user_id @product = Product.find(params[:id]) - # @reviews = Review.where(product_id: @product) - @reviews = Review.where(product_id: @product) - # if @product.user_id == @session_user - # flash.now[:warning] = "You may not review your own products" - # redirect_to products_path - # end - end # GET /products/new diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 0dac36c2bd..9c16ac898b 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -33,7 +33,12 @@ def create @product = Product.find(params[:product_id]) @review = @product.reviews.build(review_params) @review.product = @product - if @review.save + + if @product.user_id == session[:user_id] + flash[:warning] = "You can't review your own Product" + redirect_to products_path + elsif + @review.save redirect_to @product else flash.now[:warning] = "Please enter all fields" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4f11ec2df3..9c739ab4e5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -51,34 +51,17 @@ diff --git a/test/models/review_test.rb b/test/models/review_test.rb index 76b4d82758..986f17f72c 100644 --- a/test/models/review_test.rb +++ b/test/models/review_test.rb @@ -6,7 +6,7 @@ let(:one) {create(:one)} it "must be valid" do - expect(review1.valid?).must_equal true + expect(review.valid?).must_equal true end describe "relations" do @@ -14,14 +14,10 @@ it "must respond to product" do expect(review).must_respond_to :product end - + end describe "validations" do - let (:user1) { User.new(username: 'chris') } - let (:user2) { User.new(username: 'chris') } - let (:work1) { Work.new(category: 'book', title: 'House of Leaves') } - let (:work2) { Work.new(category: 'book', title: 'For Whom the Bell Tolls') } it "allows one user to vote for multiple works" do vote1 = Vote.new(user: user1, work: work1) From 43e83235d5fc275724beab4d8fc2fb823c7a1671 Mon Sep 17 00:00:00 2001 From: Trang Date: Tue, 23 Oct 2018 15:52:24 -0700 Subject: [PATCH 111/192] merge conflicts --- app/controllers/products_controller.rb | 3 +-- app/models/order.rb | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 5cb982625e..77a6f44c28 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -9,8 +9,7 @@ def index # GET /products/1 def show - @order = current_order - @order_item = @order.order_items.find_by(product_id: params[:id]) + @order_item = @current_order.order_items.find_by(product_id: params[:id]) if @order_item.nil? @order_item = current_order.order_items.new diff --git a/app/models/order.rb b/app/models/order.rb index b18bda92e5..7124928b3e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -11,7 +11,9 @@ def items_in_cart return nil else self.order_items.each do |item| - num += item.qty + if item.qty != nil + num += item.qty + end end end return num From 1820854ea5cf81a24797d06f19d9b11e4d0c5eba Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 16:13:04 -0700 Subject: [PATCH 112/192] wrote test to for place_order method and fixed method. The method works --- app/models/order.rb | 19 ++-- test/fixtures/order_items.yml | 16 +-- test/fixtures/orders.yml | 6 +- test/fixtures/products.yml | 6 +- test/fixtures/users.yml | 4 +- test/models/order_test.rb | 197 ++++++++++++++++++---------------- 6 files changed, 132 insertions(+), 116 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 2a11b55b62..a59542910f 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -18,21 +18,20 @@ def total_price def place_order #decrease inventory - - self.order_items do |order_item| - product_id = order_item.product_id - order_quantity = order_item.qty - product = Product.find_by(id: product_id) + self.order_items.each do |order_item| + product = order_item.product # get quantity quantity = product.inv_qty # substract amount defined in order - quantity -= order_quantity - # save quantity in product - product.inv_qty = quantity - product.save + new_inv_qty = product.inv_qty - order_item.qty + product.inv_qty = new_inv_qty + + product.update(inv_qty: new_inv_qty) + product.save! + binding.pry end self.status = "Paid" - self.save + self.save! end def date_of_order diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml index 247b36971f..4787440708 100644 --- a/test/fixtures/order_items.yml +++ b/test/fixtures/order_items.yml @@ -1,13 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - order_id: 1 - product_id: 1 - qty: 1 +line1: + order: one + product: cake1 + qty: 2 shipped: false -two: - order_id: 1 - product_id: 1 - qty: 1 +line2: + order: one + product: cake2 + qty: 2 shipped: false diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index f72bfa9e00..c7dcf770dd 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -1,9 +1,9 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - status: MyString - cust_name: MyString - cust_email: MyString + status: pending + cust_name: Laura + cust_email: laura@gmail.com mailing_address: 1 cc_name: MyString cc_digit: 1 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 50f681481c..1a2df5c7aa 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -6,17 +6,19 @@ cake1: description: yum price: 15.5 inv_qty: 5 + user: laura cake2: prod_name: chocolate goodness description: the best price: 19.5 - inv_qty: 0 + inv_qty: 5 + user: laura cake3: - + prod_name: vanilla plains description: real vanilla price: 20.5 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 50a0ddc177..63b86a08b8 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,9 +1,9 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: +laura: uid: 1 username: Lady Bird - email: lbird@ada. + email: lbird@ada.com two: uid: 2 diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 76247fdc11..fa9aad8e0d 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -3,98 +3,113 @@ describe Order do - describe "validation" do - let(:user) { user(:one) } - before do - 1.times do - order = create(:order) - end - end - - # it "must be a valid order" do - # - # expect(order.valid?).must_equal true - # end - - it "must be invalid without a customer name " do - - order.cust_name = nil - - expect(order.cust_name.valid?).must_equal false - expect(order.errors.messages).must_include :cust_name - end - - it "must be invalid without an email address or correct data type " do - order.cust_email = nil - order.cust_email = 123 - - expect(order.cust_email.valid?).must_equal false - expect(order.errors.messages).must_include :cust_email - end - - - it "must be invalid without a mailing address" do - order.mailing_address = nil - - expect(order.mailing_address.valid?).must_equal false - expect(order.errors.messages).must_include :mailing_address - end - - - it "must be invalid without a customer name" do - order.cc_name = nil - - expect(order.cc_name.valid?).must_equal false - expect(order.errors.messages).must_include :cc_name - end - - # it "must be invalid if date has expired" do - # order.cc_expiration = 2018/08/21 - # - # expect(order.cc_name.valid?).must_equal false - # expect(order.errors.messages).must_include :cc_expiration - # end - - it "must be invalid with more than 16 digits for credit card" do - order.cc_digit = 123 - order2.cc_digit = "hi" - - expect(order.cc_digit.valid?).must_equal false - expect(order2.cc_digit.valid?).must_equal false - expect(order.errors.messages).must_include :cc_digit - expect(order2.errors.messages).must_include :cc_digit - end - - it "must have only 3 digits for CVV" do - order.cc_cvv = 12 - order2.cc_cvv = "hi" - - expect(order.cc_cvv.valid?).must_equal false - expect(order2.cc_cvv.valid?).must_equal false - expect(order.errors.messages).must_include :cc_cvv - expect(order2.errors.messages).must_include :cc_cvv - end - - it "must be 5 digits in length for zip code" do - order.cc_zip = 12 - order2.cc_zip = "hi" - - expect(order.cc_zip.valid?).must_equal false - expect(order2.cc_zip.valid?).must_equal false - expect(order.errors.messages).must_include :cc_zip - expect(order2.errors.messages).must_include :cc_zip - end - - - describe "relations" do - - it "belong to a product" do - order = product.order - #add the yml file - expect(order).must_be_instance_of Product - expect(order.id).must_equal product.order_id +# xdescribe "validation" do +# let(:user) { user(:one) } +# before do +# 1.times do +# order = create(:order) +# end +# end +# +# # it "must be a valid order" do +# # +# # expect(order.valid?).must_equal true +# # end +# +# it "must be invalid without a customer name " do +# +# order.cust_name = nil +# +# expect(order.cust_name.valid?).must_equal false +# expect(order.errors.messages).must_include :cust_name +# end +# +# it "must be invalid without an email address or correct data type " do +# order.cust_email = nil +# order.cust_email = 123 +# +# expect(order.cust_email.valid?).must_equal false +# expect(order.errors.messages).must_include :cust_email +# end +# +# +# it "must be invalid without a mailing address" do +# order.mailing_address = nil +# +# expect(order.mailing_address.valid?).must_equal false +# expect(order.errors.messages).must_include :mailing_address +# end +# +# +# it "must be invalid without a customer name" do +# order.cc_name = nil +# +# expect(order.cc_name.valid?).must_equal false +# expect(order.errors.messages).must_include :cc_name +# end +# +# # it "must be invalid if date has expired" do +# # order.cc_expiration = 2018/08/21 +# # +# # expect(order.cc_name.valid?).must_equal false +# # expect(order.errors.messages).must_include :cc_expiration +# # end +# +# it "must be invalid with more than 16 digits for credit card" do +# order.cc_digit = 123 +# order2.cc_digit = "hi" +# +# expect(order.cc_digit.valid?).must_equal false +# expect(order2.cc_digit.valid?).must_equal false +# expect(order.errors.messages).must_include :cc_digit +# expect(order2.errors.messages).must_include :cc_digit +# end +# +# it "must have only 3 digits for CVV" do +# order.cc_cvv = 12 +# order2.cc_cvv = "hi" +# +# expect(order.cc_cvv.valid?).must_equal false +# expect(order2.cc_cvv.valid?).must_equal false +# expect(order.errors.messages).must_include :cc_cvv +# expect(order2.errors.messages).must_include :cc_cvv +# end +# +# it "must be 5 digits in length for zip code" do +# order.cc_zip = 12 +# order2.cc_zip = "hi" +# +# expect(order.cc_zip.valid?).must_equal false +# expect(order2.cc_zip.valid?).must_equal false +# expect(order.errors.messages).must_include :cc_zip +# expect(order2.errors.messages).must_include :cc_zip +# end +# +# +# xdescribe "relations" do +# +# it "belong to a product" do +# order = product.order +# #add the yml file +# expect(order).must_be_instance_of Product +# expect(order.id).must_equal product.order_id +# end +# end + + describe "place order" do + + it "reduces inventory quantity by order item quantity" do + order = orders(:one) + inv_qty_before = order.order_items.first.product.inv_qty + order_qty = order.order_items.first.qty + + order.place_order + order = orders(:one) + + inv_qty_after = order.order_items.first.product.inv_qty + expect(order.order_items.first.product.inv_qty).must_equal inv_qty_after + expect(inv_qty_after).must_equal inv_qty_before - order_qty end end end -end From 9413874d8c90df3796334923ac035b508cf2a61c Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 16:38:17 -0700 Subject: [PATCH 113/192] uncommented tests --- test/models/order_test.rb | 212 +++++++++++++++++++------------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/test/models/order_test.rb b/test/models/order_test.rb index fa9aad8e0d..36508e8128 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -2,114 +2,114 @@ describe Order do + describe "place order" do -# xdescribe "validation" do -# let(:user) { user(:one) } -# before do -# 1.times do -# order = create(:order) -# end -# end -# -# # it "must be a valid order" do -# # -# # expect(order.valid?).must_equal true -# # end -# -# it "must be invalid without a customer name " do -# -# order.cust_name = nil -# -# expect(order.cust_name.valid?).must_equal false -# expect(order.errors.messages).must_include :cust_name -# end -# -# it "must be invalid without an email address or correct data type " do -# order.cust_email = nil -# order.cust_email = 123 -# -# expect(order.cust_email.valid?).must_equal false -# expect(order.errors.messages).must_include :cust_email -# end -# -# -# it "must be invalid without a mailing address" do -# order.mailing_address = nil -# -# expect(order.mailing_address.valid?).must_equal false -# expect(order.errors.messages).must_include :mailing_address -# end -# -# -# it "must be invalid without a customer name" do -# order.cc_name = nil -# -# expect(order.cc_name.valid?).must_equal false -# expect(order.errors.messages).must_include :cc_name -# end -# -# # it "must be invalid if date has expired" do -# # order.cc_expiration = 2018/08/21 -# # -# # expect(order.cc_name.valid?).must_equal false -# # expect(order.errors.messages).must_include :cc_expiration -# # end -# -# it "must be invalid with more than 16 digits for credit card" do -# order.cc_digit = 123 -# order2.cc_digit = "hi" -# -# expect(order.cc_digit.valid?).must_equal false -# expect(order2.cc_digit.valid?).must_equal false -# expect(order.errors.messages).must_include :cc_digit -# expect(order2.errors.messages).must_include :cc_digit -# end -# -# it "must have only 3 digits for CVV" do -# order.cc_cvv = 12 -# order2.cc_cvv = "hi" -# -# expect(order.cc_cvv.valid?).must_equal false -# expect(order2.cc_cvv.valid?).must_equal false -# expect(order.errors.messages).must_include :cc_cvv -# expect(order2.errors.messages).must_include :cc_cvv -# end -# -# it "must be 5 digits in length for zip code" do -# order.cc_zip = 12 -# order2.cc_zip = "hi" -# -# expect(order.cc_zip.valid?).must_equal false -# expect(order2.cc_zip.valid?).must_equal false -# expect(order.errors.messages).must_include :cc_zip -# expect(order2.errors.messages).must_include :cc_zip -# end -# -# -# xdescribe "relations" do -# -# it "belong to a product" do -# order = product.order -# #add the yml file -# expect(order).must_be_instance_of Product -# expect(order.id).must_equal product.order_id -# end -# end - - describe "place order" do - - it "reduces inventory quantity by order item quantity" do - order = orders(:one) - inv_qty_before = order.order_items.first.product.inv_qty - order_qty = order.order_items.first.qty - - order.place_order - order = orders(:one) - - inv_qty_after = order.order_items.first.product.inv_qty - expect(order.order_items.first.product.inv_qty).must_equal inv_qty_after - expect(inv_qty_after).must_equal inv_qty_before - order_qty + it "reduces inventory quantity by order item quantity" do + order = orders(:one) + inv_qty_before = order.order_items.first.product.inv_qty + order_qty = order.order_items.first.qty + + order.place_order + order = orders(:one) + + inv_qty_after = order.order_items.first.product.inv_qty + expect(order.order_items.first.product.inv_qty).must_equal inv_qty_after + expect(inv_qty_after).must_equal inv_qty_before - order_qty + end + end + + +describe "validation" do + let(:user) { user(:one) } + before do + 1.times do + order = create(:order) end end + # it "must be a valid order" do + # + # expect(order.valid?).must_equal true + # end + + it "must be invalid without a customer name " do + + order.cust_name = nil + + expect(order.cust_name.valid?).must_equal false + expect(order.errors.messages).must_include :cust_name + end + + it "must be invalid without an email address or correct data type " do + order.cust_email = nil + order.cust_email = 123 + + expect(order.cust_email.valid?).must_equal false + expect(order.errors.messages).must_include :cust_email + end + + + it "must be invalid without a mailing address" do + order.mailing_address = nil + + expect(order.mailing_address.valid?).must_equal false + expect(order.errors.messages).must_include :mailing_address + end + + + it "must be invalid without a customer name" do + order.cc_name = nil + + expect(order.cc_name.valid?).must_equal false + expect(order.errors.messages).must_include :cc_name + end + + # it "must be invalid if date has expired" do + # order.cc_expiration = 2018/08/21 + # + # expect(order.cc_name.valid?).must_equal false + # expect(order.errors.messages).must_include :cc_expiration + # end + + it "must be invalid with more than 16 digits for credit card" do + order.cc_digit = 123 + order2.cc_digit = "hi" + + expect(order.cc_digit.valid?).must_equal false + expect(order2.cc_digit.valid?).must_equal false + expect(order.errors.messages).must_include :cc_digit + expect(order2.errors.messages).must_include :cc_digit + end + + it "must have only 3 digits for CVV" do + order.cc_cvv = 12 + order2.cc_cvv = "hi" + + expect(order.cc_cvv.valid?).must_equal false + expect(order2.cc_cvv.valid?).must_equal false + expect(order.errors.messages).must_include :cc_cvv + expect(order2.errors.messages).must_include :cc_cvv + end + + it "must be 5 digits in length for zip code" do + order.cc_zip = 12 + order2.cc_zip = "hi" + + expect(order.cc_zip.valid?).must_equal false + expect(order2.cc_zip.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip + expect(order2.errors.messages).must_include :cc_zip + end + +end +describe "relations" do + + it "belong to a product" do + order = product.order + #add the yml file + expect(order).must_be_instance_of Product + expect(order.id).must_equal product.order_id + end +end + end From 6450de83610cb399ba606c339a0965851decb3b8 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 16:40:19 -0700 Subject: [PATCH 114/192] added comments and put place_order methods in the right place --- app/controllers/orders_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 76dcb7d3e7..46d166e999 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,4 +1,3 @@ -require 'pry' class OrdersController < ApplicationController before_action :set_order, only: [:show, :edit, :update, :destroy] @@ -9,14 +8,14 @@ def index # show Confirmation Page def show - # session id is not the same as current_order id - their difference is by 1 + # session id is not the same as current order id - their difference is 1 # get current order that has customer info with @order - @order.place_order # decrease inventory and change status to paid # order items are in the current session @order_items = Order.find_by(id: session[:order_id]).order_items # save order items from the current session to the session that has the personal information @order.order_items = @order_items @order.save + @order.place_order # decrease inventory and change status to paid # clear shopping cart after confirmation page has been shown session[:order_id] = nil end From 96494ff52736c1bb923411ff8b9801188e37163e Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 16:40:43 -0700 Subject: [PATCH 115/192] oauth tests, flash partials and only show logged in users own show page --- Gemfile | 2 + Gemfile.lock | 8 ++ app/controllers/application_controller.rb | 2 +- app/controllers/carts_controller.rb | 1 + app/controllers/categories_controller.rb | 3 +- app/controllers/order_items_controller.rb | 1 + app/controllers/orders_controller.rb | 24 +++--- app/controllers/products_controller.rb | 21 +++-- app/controllers/reviews_controller.rb | 1 + app/controllers/sessions_controller.rb | 6 +- app/controllers/users_controller.rb | 35 +++++--- app/models/user.rb | 6 ++ app/views/layouts/_flash_errs.html.erb | 15 ++++ app/views/products/category.html.erb | 2 + app/views/products/home.html.erb | 2 + app/views/products/index.html.erb | 2 + app/views/products/merchant.html.erb | 2 + app/views/products/new.html.erb | 2 + app/views/products/show.html.erb | 2 + app/views/reviews/edit.html.erb | 2 + app/views/reviews/index.html.erb | 2 + app/views/reviews/show.html.erb | 2 + app/views/users/index.html.erb | 1 + app/views/users/show.html.erb | 5 +- config/routes.rb | 7 +- test/controllers/sessions_controller_test.rb | 91 +++++++++++++++++--- test/controllers/users_controller_test.rb | 46 ++++++++-- test/factories/category.rb | 2 +- test/factories/order.rb | 4 +- test/factories/user.rb | 5 -- test/test_helper.rb | 32 ++++++- 31 files changed, 265 insertions(+), 71 deletions(-) create mode 100644 app/views/layouts/_flash_errs.html.erb delete mode 100644 test/factories/user.rb diff --git a/Gemfile b/Gemfile index 3ec7b66dd4..49c9525a55 100644 --- a/Gemfile +++ b/Gemfile @@ -72,6 +72,8 @@ group :test do gem 'factory_bot_rails' gem 'factory_bot' + gem 'simplecov' + end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 51bd558f59..a49979382d 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) dotenv (2.5.0) dotenv-rails (2.5.0) dotenv (= 2.5.0) @@ -127,6 +128,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks + json (2.1.0) jwt (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) @@ -237,6 +239,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) @@ -301,6 +308,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/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 115b018260..194ac667e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base before_action :find_user before_action :list_categories, :list_merchants - # before_action :require_login, except: [:create, :root] + before_action :require_login helper_method :current_order diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb index be4e5e49fb..f71e47daaa 100644 --- a/app/controllers/carts_controller.rb +++ b/app/controllers/carts_controller.rb @@ -1,4 +1,5 @@ class CartsController < ApplicationController + skip_before_action :require_login, only: [:show] def show @order_items = current_order.order_items.order(:created_at) end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 290e50ee0c..702e4ab1a8 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,4 +1,5 @@ class CategoriesController < ApplicationController + skip_before_action :require_login, only: [:index, :show] # GET /category def index @categories = Category.all @@ -23,7 +24,7 @@ def create if @category.save flash[:success] = 'Category was successfully created.' - redirect_to categories_pathgit + redirect_to categories_path else flash.now[:warning] = 'Category not created' @category.errors.messages.each do |field, msg| diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index cc481742a5..8ee90ca66e 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,4 +1,5 @@ class OrderItemsController < ApplicationController + skip_before_action :require_login, only: [:ship] before_action :set_order, only: [:create, :update, :cart_direct] diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 4846897d80..589e6dca9b 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,5 +1,6 @@ class OrdersController < ApplicationController + skip_before_action :require_login before_action :set_order, only: [:show, :edit, :update, :destroy] before_action :check_status, only: [:show] @@ -68,17 +69,18 @@ def destroy end private - # Use callbacks to share common setup or constraints between actions. - def set_order - @order = Order.find(params[:id]) - end - # Never trust parameters from the scary internet, only allow the white list through. - def order_params - params.require(:order).permit(:status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) - end + # Use callbacks to share common setup or constraints between actions. + def set_order + @order = Order.find(params[:id]) + end - def check_status - Order.check_order_status(@order) - end + # Never trust parameters from the scary internet, only allow the white list through. + def order_params + params.require(:order).permit(:status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) + end + + def check_status + Order.check_order_status(@order) + end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f07049d67f..76f8a7a4ff 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,7 @@ class ProductsController < ApplicationController + skip_before_action :require_login, only: [:index, :show] before_action :set_product, only: [:show, :edit, :update, :destroy, :status] + before_action :require_login, only: [:edit, :update, :create, :status] # GET /products def index @@ -35,7 +37,7 @@ def create @product.user_id = session[:user_id] if @product.save(product_params) flash[:notice] = "#{@product.prod_name} was successfully created." - redirect_to user_path(user_id) + redirect_to user_path(session[:user_id]) else render :new end @@ -87,13 +89,14 @@ def merchant end private - # Use callbacks to share common setup or constraints between actions. - def set_product - @product = Product.find(params[:id]) - end - # Never trust parameters from the scary internet, only allow the white list through. - def product_params - params.require(:product).permit(:prod_name, :description, :price, :inv_qty, category_ids: []) - end + # Use callbacks to share common setup or constraints between actions. + def set_product + @product = Product.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def product_params + params.require(:product).permit(:prod_name, :description, :price, :inv_qty, category_ids: []) + end end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 0dac36c2bd..db479bf6d9 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -1,4 +1,5 @@ class ReviewsController < ApplicationController + skip_before_action :require_login before_action :set_review, only: [:show, :edit, :update, :destroy] # GET /reviews diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index c0bcc64d66..b237fc745e 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,5 @@ class SessionsController < ApplicationController - # skip_before_action :require_login, only: :create + skip_before_action :require_login, only: [:create] def create auth_hash = request.env['omniauth.auth'] @@ -20,7 +20,7 @@ def create flash.now[:result_text] = "Could not log in" flash.now[:messages] = user.errors.messages render "login", status: :bad_request - redirect_to root_path + return end end @@ -31,6 +31,8 @@ def create def destroy session[:user_id] = nil + @user = nil + # session.clear flash[:status] = :success flash[:result_text] = "Successfully logged out" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 509113a5aa..b53dc9c02e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,9 +1,9 @@ class UsersController < ApplicationController + # skip_before_action :require_login, only: [:create] before_action :set_user, only: [:show, :edit, :update, :destroy] - + before_action :authorized?, only: :show # GET /users/1 def show - @user = User.find_by(id: params[:id]) render_404 unless @user @order = current_order @@ -26,33 +26,44 @@ def edit end # POST /users + # require login before create?? def create @user = User.new(user_params) if @user.save # save returns true if the database insert succeeds flash[:success] = 'user Created!' - redirect_to root_path # go to the index so we can see the book in the list + redirect_to root_path else # save failed :( flash.now[:danger] = 'user not created!' - render :new, status: :bad_request# show the new book form view again + # render :new, status: :bad_request# show the new book form view again end end private - # Use callbacks to share common setup or constraints between actions. - def set_user - @user = User.find(params[:id]) - end - # Never trust parameters from the scary internet, only allow the white list through. - def user_params - params.require(:user).permit(:uid, :username, :email, :id) - end + # Use callbacks to share common setup or constraints between actions. + def set_user + @user = User.find(params[:id]) + end + # Never trust parameters from the scary internet, only allow the white list through. + def user_params + params.require(:user).permit(:uid, :username, :email, :id) + end + def authorized? + @user = User.find_by(id: params[:id]) + if @user.nil? + flash[:warning] = "Unauthorized" + redirect_to root_path + elsif @user.id != session[:user_id] + flash[:warning] = "You may only view your own account." + redirect_to user_path(session[:user_id]) + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index cd2c7ec52a..56819a1262 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,5 +36,11 @@ def revenue end + def authorized? + if self.id != 2 + raise + end + + end end diff --git a/app/views/layouts/_flash_errs.html.erb b/app/views/layouts/_flash_errs.html.erb new file mode 100644 index 0000000000..129c7bed3d --- /dev/null +++ b/app/views/layouts/_flash_errs.html.erb @@ -0,0 +1,15 @@ +
    +<% flash.each do |name, message| %> + <% if message.class == Array %> +
    + <% message.each do |msg| %> +

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

    + <% end %> +
    + <% else %> +
    + <%= message %> +
    + <% end %> +<% end %> +
    diff --git a/app/views/products/category.html.erb b/app/views/products/category.html.erb index 9e79db12af..202cd3b7c0 100644 --- a/app/views/products/category.html.erb +++ b/app/views/products/category.html.erb @@ -1,3 +1,5 @@ +<%= render partial: "/layouts/flash_errs" %> +

    <%= @category.category.pluralize %>

    <%= render partial: "productslist", locals: { } %> diff --git a/app/views/products/home.html.erb b/app/views/products/home.html.erb index a2b14c3059..d21aa5f3b4 100644 --- a/app/views/products/home.html.erb +++ b/app/views/products/home.html.erb @@ -1,3 +1,5 @@ +<%= render partial: "/layouts/flash_errs" %> +
    + <%# Order.check_order_status(ord) %> + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 31c8b30729..9b5a213249 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,13 +7,9 @@ resources :reviews, only: [:new, :create] end - get "/auth/:provider/callback", to: "sessions#create" - - # get 'sessions/login', to: "sessions#new" #page for a new session + get "/auth/:provider/callback", to: "sessions#create", as: "auth_callback" delete "/logout", to: "sessions#destroy", as: "logout" - # get 'sessions/new', to: "sessions#create" #create a new session login - # get 'sessions/destroy', to: "sessions#destroy" #delete a session logout resources :reviews resources :carts, only: [:show] @@ -29,6 +25,7 @@ patch 'products/:id/retire', to: "products#status", as: "product_status" get 'products/merchant/:id', to: "products#merchant", as: "merchant" resources :products + resources :users resources :categories diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 5506a8a666..8663792f55 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -1,19 +1,86 @@ require "test_helper" describe SessionsController do - it "should get login" do - get login_path - value(response).must_be :success? - end + # it "should get login" do + # get login_path + # value(response).must_be :success? + # end + # + # it "should get new" do + # get sessions_new_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 + describe "auth_callback" do - it "should get destroy" do - get sessions_destroy_url - value(response).must_be :success? - end + it "logs in an existing user" do + start_count = User.count + user = users(:grace) + + perform_login(user) + + must_redirect_to root_path + expect(flash[:result_text]).must_match /Successfully logged*/ + session[:user_id].must_equal user.id + + # Should *not* have created a new user + User.count.must_equal start_count + end + + it "can login in a new user with good data" do + user = users(:ada) + # remove ada test user from test db + user.destroy + # login ada as new user to test db + perform_login(user) + # user count should increase by 1 + expect do + get auth_callback_path(:github).must_change('User.count' +1) + end + # redirect to root_path + must_redirect_to root_path + expect(flash[:result_text]).must_match /Successfully created*/ + expect(session[:user_id]).wont_be_nil + end + + it "rejects an invalid user login with bad data" do + user = users(:ada) + user.uid = nil + + perform_login(user) + + expect do + get auth_callback_path(:github).wont_change 'User.count' + end + must_respond_with :bad_request + expect(session[:user_id]).must_be_nil + + end + + describe "logout" do + it 'can log out' do + user = users(:grace) + + perform_login(user) + + delete logout_path + + expect do + get auth_callback_path(:github).wont_change 'User.count' + end + + must_redirect_to root_path + expect(session[:user_id]).must_be_nil + + end + + + end + end end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 5c875a1bb0..7609157f04 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,11 +1,11 @@ require "test_helper" describe UsersController do - let(:user) { users :one } + let(:user) { users :ada } it "gets new" do get new_user_url - value(response).must_be :success? + value(response).must_be :successful? end it "creates user" do @@ -23,8 +23,44 @@ must_redirect_to root_path end - it "shows user" do - get user_url(user) - value(response).must_be :success? + + # User test are create and and show order fulfillment if logged in + describe "Logged in users" do + before do + perform_login(users(:grace)) + end + + describe "show" do + # Just the standard show tests + it "succeeds for logged in user" do + get user_path(session[:user_id]) + must_respond_with :success + + end + + it "returns 404 a user who is not the logged in user" do + a = users(:ada) + a_id = a.id + get user_path(a_id) + must_redirect + end + end + + # can change an items status to shipped + # can add new products + # can retire a product + + end + + describe "Guest users" do + # it "returns 404 a user who is not the logged in user" do + # get user_path(session[:user_id] - 1) + # must_respond_with :forbidden + # end + + + end end + + diff --git a/test/factories/category.rb b/test/factories/category.rb index 1c7bc92210..281aded1c8 100644 --- a/test/factories/category.rb +++ b/test/factories/category.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :category do - category Faker::Name.first_name + category { Faker::Name.first_name } end end \ No newline at end of file diff --git a/test/factories/order.rb b/test/factories/order.rb index dd38697f9c..813f6b0158 100644 --- a/test/factories/order.rb +++ b/test/factories/order.rb @@ -5,9 +5,9 @@ cust_email { Faker::Internet.safe_email} mailing_address { Faker::Address.full_address} cc_name { Faker::FunnyName.two_word_name} - cc_digit { Faker::Finance.credit_card.number(16)} + cc_digit { Faker::Number.number(16)} cc_expiration { Faker::Business.credit_card_expiry_date} - cc_cvv { Faker::Number.number(3)} + cc_cvv { Faker::Number.number(3) } cc_zip { Faker::Number.number(5) } end end diff --git a/test/factories/user.rb b/test/factories/user.rb deleted file mode 100644 index d667909da4..0000000000 --- a/test/factories/user.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :user do - name { Faker::Name.first_name } - end -end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 7a253b59ea..84b8e24a29 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,10 +23,36 @@ class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all + # Add more helper methods to be used by all tests here... -end + class ActiveSupport::TestCase + include FactoryBot::Syntax::Methods + end + + #oauth testing setup + def setup + OmniAuth.config.test_mode = true + end + # Test helper method to generate a mock auth hash + # for fixture data + def mock_auth_hash(user) + return { + provider: user.provider, + uid: user.uid, + info: { + email: user.email, + nickname: user.username + } + } + end + + # oauth mock login + def perform_login(user) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + end -class ActiveSupport::TestCase - include FactoryBot::Syntax::Methods end + + From 9816796f917043e2ae9f2662d21afc6f49bf6d3c Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 16:40:48 -0700 Subject: [PATCH 116/192] comments --- app/controllers/products_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 1d51f13ce7..c842ec0b24 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -12,7 +12,7 @@ def show @order = current_order @order_item = @order.order_items.find_by(product_id: params[:id]) - # setting up space, creating a blank row, not filling out items + # setting up space, creating a blank row, not filling out if @order_item.nil? @order_item = current_order.order_items.new end From 3b47332e6693c426decfe78ceac5c2100a6729c5 Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 23 Oct 2018 16:41:18 -0700 Subject: [PATCH 117/192] removed pry --- app/models/order.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index a59542910f..df177c6b2a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,3 @@ -require 'pry' class Order < ApplicationRecord #validations @@ -28,7 +27,6 @@ def place_order product.update(inv_qty: new_inv_qty) product.save! - binding.pry end self.status = "Paid" self.save! From 53ad1b8176a63e08ccfbc5377cb302c997a8e051 Mon Sep 17 00:00:00 2001 From: Jazz Date: Tue, 23 Oct 2018 17:04:53 -0700 Subject: [PATCH 118/192] model testing review, products, order --- app/models/order.rb | 4 +++- test/fixtures/reviews.yml | 1 + test/models/order_test.rb | 4 ++++ test/models/review_test.rb | 28 +++++----------------------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 4b7cfa9dc4..dd7babcf7e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -17,7 +17,9 @@ def items_in_cart return nil else self.order_items.each do |item| - num += item.qty + if item.qty != nil + num += item.qty + end end end return num diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml index 41c2fd15d3..27fde1e798 100644 --- a/test/fixtures/reviews.yml +++ b/test/fixtures/reviews.yml @@ -3,6 +3,7 @@ one: rating: 1 description: MyString + product: cake1 two: rating: 1 diff --git a/test/models/order_test.rb b/test/models/order_test.rb index cadde6d816..42f1e5ca48 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -6,6 +6,10 @@ describe "validation" do let(:order) { build(:order) } + it "must be valid with all parameters" do + expect(order.valid?).must_equal true + end + it "must be invalid without a customer name " do order.cust_name = nil diff --git a/test/models/review_test.rb b/test/models/review_test.rb index 986f17f72c..507bfc4621 100644 --- a/test/models/review_test.rb +++ b/test/models/review_test.rb @@ -1,9 +1,7 @@ require "test_helper" describe Review do - let(:review) { Review.new } - let(:review1) {create(:review)} - let(:one) {create(:one)} + let(:review) { Review.new(rating: "1", description: "this is great", product: Product.new) } it "must be valid" do expect(review.valid?).must_equal true @@ -19,27 +17,11 @@ describe "validations" do - it "allows one user to vote for multiple works" do - vote1 = Vote.new(user: user1, work: work1) - vote1.save! - vote2 = Vote.new(user: user1, work: work2) - vote2.valid?.must_equal true + it "invalid without a rating" do + review.rating = nil + expect(review.valid?).must_equal false + expect(review.errors.messages).must_include :rating end - it "allows multiple users to vote for a work" do - vote1 = Vote.new(user: user1, work: work1) - vote1.save! - vote2 = Vote.new(user: user2, work: work1) - vote2.valid?.must_equal true - end - - it "doesn't allow the same user to vote for the same work twice" do - vote1 = Vote.new(user: user1, work: work1) - vote1.save! - vote2 = Vote.new(user: user1, work: work1) - vote2.valid?.must_equal false - vote2.errors.messages.must_include :user - end end end -end From 911a0cd98fb2066a36111f255e4c086a44c9bc90 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 20:07:50 -0700 Subject: [PATCH 119/192] fixed nil categories --- app/controllers/application_controller.rb | 13 ++++++------- app/controllers/categories_controller.rb | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4a06843674..f782cb5955 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,12 +1,12 @@ class ApplicationController < ActionController::Base - before_action :find_user - #before_action :list_categories, :list_merchants, :current_order - # before_action :require_login, except: [:create, :root] - # before_action :list_categories, :list_merchants - before_action :require_login + before_action :list_categories, :list_merchants, :current_order + + # before_action :list_categories, :list_merchants + before_action :require_login, except: [:current_order, :render_404, :find_user] + before_action :find_user helper_method :current_order @@ -40,8 +40,7 @@ def find_user def require_login if session[:user_id].nil? - flash[:status] = :failure - flash[:result_text] = "You must be logged in to view this section" + flash[:error] = "You must be logged in to view this section" redirect_to root_path end end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 702e4ab1a8..b974a3e0f3 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,5 +1,5 @@ class CategoriesController < ApplicationController - skip_before_action :require_login, only: [:index, :show] + # skip_before_action :require_login, except: [:create, :update, :edit] # GET /category def index @categories = Category.all From d140970073d00736fdd89a58fd4009fd4082beae Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 21:00:07 -0700 Subject: [PATCH 120/192] fixed order validations to on place_order --- app/controllers/application_controller.rb | 5 ++-- app/controllers/carts_controller.rb | 2 +- app/controllers/order_items_controller.rb | 35 +++++++++++------------ app/controllers/sessions_controller.rb | 2 +- app/models/order.rb | 14 ++++----- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f782cb5955..021f8507cb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,6 @@ class ApplicationController < ActionController::Base - before_action :list_categories, :list_merchants, :current_order - - # before_action :list_categories, :list_merchants before_action :require_login, except: [:current_order, :render_404, :find_user] before_action :find_user @@ -24,6 +21,8 @@ def current_order else @current_order = Order.new end + + return @current_order end def render_404 diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb index f71e47daaa..75b6e884da 100644 --- a/app/controllers/carts_controller.rb +++ b/app/controllers/carts_controller.rb @@ -1,5 +1,5 @@ class CartsController < ApplicationController - skip_before_action :require_login, only: [:show] + skip_before_action :require_login def show @order_items = current_order.order_items.order(:created_at) end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index c4819f31ae..58eec01b11 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,19 +1,17 @@ class OrderItemsController < ApplicationController - skip_before_action :require_login, only: [:ship] + skip_before_action :require_login before_action :set_order, only: [:create, :update, :cart_direct] def create # check if item is in stock @order_item = @order.order_items.new(order_item_params) - @order_item.save - if @order.save session[:order_id] = @order.id # TODO DETERMINE WHICH REDIRECT IS NEEDED # @CURRENT_ORDER OR @ORDER??????????????????? - # redirect_to cart_path(@current_order.id) - redirect_to cart_path(@order.id) + redirect_to cart_path(@current_order.id) + # redirect_to cart_path(@order.id) else flash[:warning] = "Item order not placed" redirect_to root_path @@ -25,31 +23,32 @@ def create def update # TODO DETERMINE WHICH INSTANCE IS NEEDED # @CURRENT_ORDER OR @ORDER??????????????????? - # @order_item = @current_order.order_items.find(params[:id]) + @order_item = @current_order.order_items.find(params[:id]) # @order = current_order <- moved to controller filter # check if item is in stock - @order_item = @order.order_items.find(params[:id]) + # @order_item = @order.order_items.find(params[:id]) @order_item.update_attributes(order_item_params) @current_order.save redirect_to cart_path(@current_order.id) end - -# def cart_direct -# # TODO DETERMINE WHICH INSTANCE IS NEEDED -# # @CURRENT_ORDER OR @ORDER??????????????????? +# +# # def cart_direct +# # # TODO DETERMINE WHICH INSTANCE IS NEEDED +# # # @CURRENT_ORDER OR @ORDER??????????????????? # @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, order_status_id: 1) -# redirect_back(fallback_location: cart_path(@order.id)) -# end +# # redirect_back(fallback_location: cart_path(@order.id)) +# # end def cart_direct # @order = current_order <- moved to controller filter - @order_item = @order.order_items.new(product_id: params[:id], qty: 1, shipped: false) - + @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, shipped: false) @order_item.save + @current_order.save + session[:order_id] = @current_order.id redirect_to cart_path(@current_order.id) @@ -58,10 +57,10 @@ def cart_direct def destroy # TODO DETERMINE WHICH INSTANCE IS NEEDED # # @CURRENT_ORDER OR @ORDER??????????????????? - # @order_item = @current_order.order_items.find(params[:id]) + @order_item = @current_order.order_items.find(params[:id]) # @order = current_order <- moved to controller filter - @order_item = @order.order_items.find(params[:id]) + # @order_item = @order.order_items.find(params[:id]) @order_item.destroy @order_items = @current_order.order_items @@ -72,7 +71,7 @@ def destroy def ship @order_item = OrderItem.find_by(product_id: params[:id]) @order_item.shipped = true - Order.check_order_status(@order) + Order.check_order_status(@current_order) if @order_item.save flash[:success] = 'Item(s) have been marked as shipped' redirect_back(fallback_location: root_path) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b237fc745e..2dd4e72c4b 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,5 @@ class SessionsController < ApplicationController - skip_before_action :require_login, only: [:create] + skip_before_action :require_login def create auth_hash = request.env['omniauth.auth'] diff --git a/app/models/order.rb b/app/models/order.rb index 67c53f009e..cccd0f65f1 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,12 +1,12 @@ class Order < ApplicationRecord #validations - validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :create - validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/ }, on: :create - validates :cc_expiration, presence: true, on: :create - validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :create - validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :create - validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :create - validates :mailing_address, presence: true, on: :create + validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :place_order + validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/ }, on: :place_order + validates :cc_expiration, presence: true, on: :place_order + validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :place_order + validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :place_order + validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :place_order + validates :mailing_address, presence: true, on: :place_order #relationships has_many :order_items From ef8c4377c33d4b18ec9fe80119b61d6fafe86651 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 21:08:55 -0700 Subject: [PATCH 121/192] flash message username on logout --- app/controllers/sessions_controller.rb | 4 ++-- app/models/order.rb | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2dd4e72c4b..60d98dca23 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,5 @@ class SessionsController < ApplicationController - skip_before_action :require_login + skip_before_action :require_login, except: :destroy def create auth_hash = request.env['omniauth.auth'] @@ -34,7 +34,7 @@ def destroy @user = nil # session.clear flash[:status] = :success - flash[:result_text] = "Successfully logged out" + flash[:result_text] = "Goodbye #{session[:username]}!" redirect_to root_path end diff --git a/app/models/order.rb b/app/models/order.rb index cccd0f65f1..202db8dfc1 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -44,9 +44,7 @@ def place_order product.update(inv_qty: new_inv_qty) product.save! end - self.status = "Paid" - self.save! - + self.update(status: "Paid") end From bd0e9e0481d9946501f189f1cb7af4ca95f4ff45 Mon Sep 17 00:00:00 2001 From: Trang Date: Tue, 23 Oct 2018 21:13:56 -0700 Subject: [PATCH 122/192] order_items testing --- app/controllers/order_items_controller.rb | 16 +--- app/models/order_item.rb | 3 +- .../order_items_controller_test.rb | 79 ++++++++++++++++--- test/fixtures/order_items.yml | 16 ++-- test/models/order_item_test.rb | 67 +++++++++++++++- 5 files changed, 147 insertions(+), 34 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 17ba6141b5..41ac25f223 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,25 +1,15 @@ class OrderItemsController < ApplicationController def create - @order = current_order - # check if item is in stock - - @order_item = @order.order_items.new(order_item_params) - @order_item.save - - if @order.save - - session[:order_id] = @order.id + @order_item = @current_order.order_items.new(order_item_params) + if @order_item.save + session[:order_id] = @current_order.id redirect_to cart_path(@current_order.id) - else - flash[:warning] = "Item order not placed" redirect_to root_path - end - end def update diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 0ab81b3885..b150b64c81 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,5 +1,6 @@ class OrderItem < ApplicationRecord - validates :qty, numericality: { only_integer: true } + validates :qty, presence: true, numericality: { only_integer: true } + validates :shipped, presence: true belongs_to :product belongs_to :order diff --git a/test/controllers/order_items_controller_test.rb b/test/controllers/order_items_controller_test.rb index 62b82cc575..b61aebac15 100644 --- a/test/controllers/order_items_controller_test.rb +++ b/test/controllers/order_items_controller_test.rb @@ -1,19 +1,80 @@ require "test_helper" describe OrderItemsController do - it "should get create" do - get order_items_create_url - value(response).must_be :success? + + let (:order) { orders(:one) } + let (:product) { products(:cake1) } + + let (:order_item_on_existing_order) { + { + order_item: { + order_id: order.id, + product_id: product.id, + qty: 5, + shipped: true + } + } + } + + describe 'create' do + + it 'can create a new order line item when order already exists' do + + expect { + post order_items_path, params: order_item_on_existing_order + }.must_change 'OrderItem.count', 1 + + must_respond_with :redirect + expect(OrderItem.last.order_id).must_equal order.id + end + + it 'can create a new order line item when order does not already exist' do + end + + it 'can not add a line order item if item is out of stock' do + end + end - it "should get update" do - get order_items_update_url - value(response).must_be :success? + describe 'update' do + + it 'can update an existing order line item with valid data' do + end + + it 'will not update an existing order line item with invalid data' do + end + + it 'will render not_found when a line order item does not exist to update' do + end + + it 'will will not update existing order line item when qty exceeds inventory count' do + end + + it 'can not add a line order item if item is out of stock' do + end + end - it "should get destroy" do - get order_items_destroy_url - value(response).must_be :success? + describe 'destroy' do + + it 'can delete an existing order line item' do + end + + it 'will render not_found when a line order item does not exist to delete' do + end + + end + + describe 'cart_direct' do + + it 'can add a line order item with a qty of 1 when existing order exists' do + end + + it 'can add a line order item with a qty of 1 when existing order does not exist' do + end + + it 'can not add a line order item if item is out of stock' do + end end end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml index 247b36971f..42fd28686f 100644 --- a/test/fixtures/order_items.yml +++ b/test/fixtures/order_items.yml @@ -1,13 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - order_id: 1 - product_id: 1 - qty: 1 - shipped: false +line_one: + order: one + product: cake1 + qty: 2 + shipped: true -two: - order_id: 1 - product_id: 1 +line_two: + order: one + product: cake3 qty: 1 shipped: false diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb index 19a9bf8f58..715a0f6ca5 100644 --- a/test/models/order_item_test.rb +++ b/test/models/order_item_test.rb @@ -1,9 +1,70 @@ require "test_helper" describe OrderItem do - let(:order_item) { OrderItem.new } + let(:order_item) { order_items(:line_one) } - it "must be valid" do - value(order_item).must_be :valid? + describe 'relationships' do + it 'must belong to a product' do + product = order_item.product + + expect(product).must_be_instance_of Product + expect(product.id).must_equal order_item.product.id + + end + + it 'must belong to an order' do + order = order_item.order + + expect(order).must_be_instance_of Order + expect(order.id).must_equal order_item.order.id + end end + + describe 'validations' do + it 'must be valid with all fields' do + another_order_item = order_items(:line_two) + + expect(order_item).must_be :valid? + expect(another_order_item).must_be :valid? + end + + it 'must have qty' do + order_item.qty = nil + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :qty + end + + it 'must have shipped status' do + order_item.shipped = nil + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :shipped + end + end + + describe 'subtotal' do + it 'must be able to calculate subtotal for order_item' do + subtotal = order_item.subtotal + + expect(subtotal).must_equal order_item.product.price * order_item.qty + end + + it 'must be able to calculate subtotal for order_item with qty of 0' do + order_item.qty = 0 + order_item.save + + subtotal = order_item.subtotal + + expect(subtotal).must_equal 0 + end + + end + + + end From 5dec77c35014d1b1478e6f7dd161bcb9ba82e041 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Tue, 23 Oct 2018 22:13:45 -0700 Subject: [PATCH 123/192] removed session clear on logout --- app/controllers/sessions_controller.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 60d98dca23..0ecc72bccc 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -6,18 +6,16 @@ def create user = User.find_by(uid: auth_hash[:uid], provider: 'github') if user # User was found in the database - flash[:status] = :success - flash[:result_text] = "Successfully logged in as existing user #{user.username}" + flash[:success] = "Successfully logged in as #{user.username}" else # User doesn't match anything in the DB user = User.new_user(auth_hash) # Attempt to create a new user if user.save - flash[:status] = :success - flash[:result_text] = "Successfully created new user #{user.username} with ID #{user.id}" + flash[:success] = "Successfully created new user #{user.username} with ID #{user.id}" else - flash.now[:status] = :failure - flash.now[:result_text] = "Could not log in" + + flash.now[:warning] = "Could not log in" flash.now[:messages] = user.errors.messages render "login", status: :bad_request return @@ -33,8 +31,7 @@ def destroy session[:user_id] = nil @user = nil # session.clear - flash[:status] = :success - flash[:result_text] = "Goodbye #{session[:username]}!" + flash[:notice] = "Goodbye #{session[:username]}!" redirect_to root_path end From 42c656b989c8e3e91dde61d02de26c035ecf8ccf Mon Sep 17 00:00:00 2001 From: Jazz Date: Tue, 23 Oct 2018 22:57:38 -0700 Subject: [PATCH 124/192] review controller testing almost complete --- test/controllers/reviews_controller_test.rb | 134 +++++++++++++++++--- test/fixtures/users.yml | 9 +- 2 files changed, 118 insertions(+), 25 deletions(-) diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index 3ef4e255d2..bcc0661a8f 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -5,30 +5,107 @@ it "gets index" do get reviews_url - value(response).must_be :success? + value(response).must_be :successful? end - it "gets new" do - get new_review_url - value(response).must_be :success? - end + # describe "show" do + + # it "gets a review show page" do + # id = products(:cake1).id + # + # get reviews_path(id) + # value(response).must_be :successful? + # end + + # it "shows review" do + # get review_url(review) + # value(response).must_be :successful? + # end + # + # end + + # it "should repond with not_found if given an invalid id" do + # id = -1 + # + # get new_product_review_path(id) + # + # value(response).must_be :not_found + # end + # end + + + describe "new" do - it "creates review" do - expect { - post reviews_url, params: { review: { description: review.description, rating: review.rating } } - }.must_change "Review.count" + it "gets the form with the new review page" do + id = products(:cake1).id + + get new_product_review_path(id) + value(response).must_be :successful? + end - must_redirect_to review_path(Review.last) end - it "shows review" do - get review_url(review) - value(response).must_be :success? + describe "create" do + + it "creates a new review given valid params" do + id = products(:cake1).id + review_hash = { review: { description: review.description, rating: review.rating} } + + expect { + post product_reviews_path(id), params: review_hash + }.must_change "Review.count", 1 + + must_redirect_to product_path(id) + + expect(Review.last.description).must_equal review_hash[:review][:description] + expect(Review.last.rating).must_equal review_hash[:review][:rating] + end + + it "respond with an redirect for invalid params" do + id = products(:cake1).id + review_hash = { review: { description: review.description } } + + expect { + post product_reviews_path(id), params: review_hash + }.wont_change "Review.count" + + must_respond_with :success + expect(flash[:warning]).must_equal "Please enter all fields" + end + + # it "respond with an error if merchant reviews their own product" do + # get "/auth/github", params: {username: "laura"} + # expect(session[:user_id]).wont_be_nil + # + # id = products(:cake1).id + # review_hash = { review: { description: review.description, rating: review.rating} } + # + # expect { + # post product_reviews_path(id), params: review_hash + # }.wont_change "Review.count" + # + # must_redirect_to products_path + # expect(flash[:warning]).must_equal "You can't review your own Product" + # end end - it "gets edit" do - get edit_review_url(review) - value(response).must_be :success? + + describe "edit" do + + it "can get the edit page for a valid review" do + id = products(:cake1).id + + get edit_review_url(review) + value(response).must_be :successful? + end + + # it "should resond with not_found if given an invalid id" do + # id = -1 + # + # get review_path(id) + # + # must_respond_with :not_found + # end end it "updates review" do @@ -36,11 +113,26 @@ must_redirect_to review_path(review) end - it "destroys review" do - expect { - delete review_url(review) - }.must_change "Review.count", -1 + describe "destroy" do + + it "destroys review given a valid id" do + expect { + delete review_url(review) + }.must_change "Review.count", -1 - must_redirect_to reviews_path + must_redirect_to reviews_path + end + + # it "cant destroy a review given an invalid id" do + # id = -1 + # + # expect { + # delete book_path(id) + # }.wont_change 'Book.count' + # + # must_respond_with :not_found + # expect(flash[:danger]).must_equal "Cannot find the book #{id}" + # end end + end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index b2972654c5..97b51aa1d9 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -2,10 +2,11 @@ laura: - uid: 1 - username: Lady Bird - email: lbird@ada.com provider: github + uid: 13371338 + email: lbird@ada.com + username: Lady Bird + ada: provider: github @@ -18,4 +19,4 @@ grace: provider: github uid: 13371337 email: grace@hopper.com - username: graceful_hopps \ No newline at end of file + username: graceful_hopps From 9e6ce609aa54f5336e92f905ff391323d5b77ead Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 08:47:06 -0700 Subject: [PATCH 125/192] merge conflicts --- app/controllers/order_items_controller.rb | 1 + .../order_items_controller_test.rb | 26 ++++++++++++++----- test/models/order_item_test.rb | 4 +-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 857db03146..e961501f6b 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -5,6 +5,7 @@ class OrderItemsController < ApplicationController def create @order_item = @current_order.order_items.new(order_item_params) + @current_order.save if @order_item.save session[:order_id] = @current_order.id diff --git a/test/controllers/order_items_controller_test.rb b/test/controllers/order_items_controller_test.rb index b61aebac15..ae89e24984 100644 --- a/test/controllers/order_items_controller_test.rb +++ b/test/controllers/order_items_controller_test.rb @@ -2,30 +2,42 @@ describe OrderItemsController do - let (:order) { orders(:one) } let (:product) { products(:cake1) } - let (:order_item_on_existing_order) { + let (:order_item_hash1) { { order_item: { - order_id: order.id, - product_id: product.id, + product_id: products(:cake3), qty: 5, shipped: true } } } + let (:order_item_hash2) { + { + order_item: { + product_id: product.id, + qty: 3, + shipped: true + } + } + } + describe 'create' do - it 'can create a new order line item when order already exists' do + it 'can create a new order line item to existing order' do + + post order_items_path, params: order_item_hash1 + order_id = Order.last.id expect { - post order_items_path, params: order_item_on_existing_order + post order_items_path, params: order_item_hash2 }.must_change 'OrderItem.count', 1 must_respond_with :redirect - expect(OrderItem.last.order_id).must_equal order.id + expect(OrderItem.last.product_id).must_equal product.id + expect(OrderItem.last.order_id).must_equal order_id end it 'can create a new order line item when order does not already exist' do diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb index 715a0f6ca5..21d7cb8485 100644 --- a/test/models/order_item_test.rb +++ b/test/models/order_item_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe OrderItem do - let(:order_item) { order_items(:line_one) } + let(:order_item) { order_items(:line1) } describe 'relationships' do it 'must belong to a product' do @@ -22,7 +22,7 @@ describe 'validations' do it 'must be valid with all fields' do - another_order_item = order_items(:line_two) + another_order_item = order_items(:line2) expect(order_item).must_be :valid? expect(another_order_item).must_be :valid? From abd78e0073630b070cb720cdd92398956e56c3fd Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 09:06:00 -0700 Subject: [PATCH 126/192] OrderItem model testing --- app/models/order_item.rb | 1 - test/models/order_item_test.rb | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 585eb97be8..ae6d3d4fd5 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,6 +1,5 @@ class OrderItem < ApplicationRecord validates :qty, presence: true, numericality: { only_integer: true } - validates :shipped, presence: true belongs_to :product belongs_to :order diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb index 21d7cb8485..8fa0c99140 100644 --- a/test/models/order_item_test.rb +++ b/test/models/order_item_test.rb @@ -25,6 +25,7 @@ another_order_item = order_items(:line2) expect(order_item).must_be :valid? + expect(another_order_item).must_be :valid? end @@ -36,15 +37,6 @@ expect(valid).must_equal false expect(order_item.errors.messages).must_include :qty end - - it 'must have shipped status' do - order_item.shipped = nil - - valid = order_item.save - - expect(valid).must_equal false - expect(order_item.errors.messages).must_include :shipped - end end describe 'subtotal' do From 6dd143e1c4a7067dafa2f4ae91699e87bec0f752 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Wed, 24 Oct 2018 09:57:31 -0700 Subject: [PATCH 127/192] fixed order item placement from product show page --- app/views/products/show.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 2b137830ee..114eb6a293 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -153,6 +153,7 @@ <%= f.label :qty %> <%= f.select :qty, (1..@product.inv_qty).to_a %> <%= f.hidden_field :product_id, :value => @product.id %> + <%= f.hidden_field :shipped, :value => false %>
    <%= f.submit "Add to cart", class: "btn btn-sm btn-brand btn-full-width" %> From 0eaaedce502b66005a57ec1f4a509ac67d0fea63 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 10:08:52 -0700 Subject: [PATCH 128/192] solving merge conflict and fixing route id difference --- app/controllers/orders_controller.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 821d4587ed..54ec0e6be7 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -13,9 +13,10 @@ def show # session id is not the same as current order id - their difference is 1 # get current order that has customer info with @order # order items are in the current session - @order_items = Order.find_by(id: session[:order_id]).order_items + #@order_items = Order.find_by(id: session[:order_id]).order_items # save order items from the current session to the session that has the personal information - @order.order_items = @order_items + #@order.order_items = @order_items + @order_items = @order.order_items @order.save @order.place_order # decrease inventory and change status to paid # clear shopping cart after confirmation page has been shown @@ -24,7 +25,6 @@ def show # GET /orders/new def new - @order = Order.new end # GET /orders/1/edit @@ -35,7 +35,8 @@ def edit # must change database # flash notices do not have color def create - @order = Order.new(order_params) + @order = @current_order.update(order_params) + # it successfully grabs and saves all fields put in the form if @order.save flash[:success] = 'Order was successfully created.' redirect_to order_path(@order.id) From cdc7e33b2b0ff1110ff5da851f71d69bdd6553a5 Mon Sep 17 00:00:00 2001 From: Jazz Date: Wed, 24 Oct 2018 10:18:21 -0700 Subject: [PATCH 129/192] stash changes ffrom master --- app/controllers/orders_controller.rb | 5 ++- app/models/order.rb | 16 ++++----- app/views/orders/_form.html.erb | 2 +- app/views/products/show.html.erb | 1 + test/controllers/products_controller_test.rb | 36 +++++++++++++------- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 821d4587ed..a7daaf5cdc 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,7 +1,7 @@ class OrdersController < ApplicationController skip_before_action :require_login before_action :set_order, only: [:show, :edit, :update, :destroy] - before_action :check_status, only: [:show] + # before_action :check_status, only: [:show] # GET /orders def index @@ -14,6 +14,9 @@ def show # get current order that has customer info with @order # order items are in the current session @order_items = Order.find_by(id: session[:order_id]).order_items + if order_items.nil? + redirect_to products_path + end # save order items from the current session to the session that has the personal information @order.order_items = @order_items @order.save diff --git a/app/models/order.rb b/app/models/order.rb index 202db8dfc1..61ce82783a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,7 +1,7 @@ class Order < ApplicationRecord #validations validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :place_order - validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/ }, on: :place_order + validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, maxlength: 16 }, on: :place_order validates :cc_expiration, presence: true, on: :place_order validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :place_order validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :place_order @@ -52,13 +52,13 @@ def date_of_order return self.created_at.strftime("%B %d, %Y") end - def check_order_status(order) - if order.order_items.all? {|item| item.shipped} - order.status = "Complete" - raise - order.save - end - end + # def check_order_status(order) + # if order.order_items.all? {|item| item.shipped} + # order.status = "Complete" + # raise + # order.save + # end + # end def destroy # method to cancel order diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index a1aaccb730..1a7fa80f16 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -24,7 +24,7 @@
    <%= form.label "Credit Card Number" %> - <%= form.number_field :cc_digit, class: "form-control" %> + <%= form.number_field :cc_digit, class: "form-control", input_html: {:pattern => /[0-9]{16}/}%>
    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 2b137830ee..114eb6a293 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -153,6 +153,7 @@ <%= f.label :qty %> <%= f.select :qty, (1..@product.inv_qty).to_a %> <%= f.hidden_field :product_id, :value => @product.id %> + <%= f.hidden_field :shipped, :value => false %>
    <%= f.submit "Add to cart", class: "btn btn-sm btn-brand btn-full-width" %> diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 22a2624cd2..20efab0ef4 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -1,44 +1,56 @@ require "test_helper" describe ProductsController do - let(:product) { products :one } + let(:product) { build(:product) } it "gets index" do get products_url - value(response).must_be :success? + value(response).must_be :successful? end it "gets new" do - get new_product_url - value(response).must_be :success? + get new_product_path + value(response).must_be :successful? end it "creates product" do + id = users(:laura).id + product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: id } } + expect { - post products_url, params: { product: { category: product.category, description: product.description, inv_qty: product.inv_qty, price: product.price, prod_name: product.prod_name } } + post products_path, params: product_hash }.must_change "Product.count" - must_redirect_to product_path(Product.last) + must_redirect_to user_path(session[:user_id]) + expect(flash[:notice]).must_equal "#{@product.prod_name} was successfully created." end it "shows product" do - get product_url(product) - value(response).must_be :success? + id = products(product).id + + get product_path(id) + value(response).must_be :successful? end it "gets edit" do - get edit_product_url(product) - value(response).must_be :success? + id = products(:cake1).id + + get edit_product_path(id) + value(response).must_be :successful? end it "updates product" do - patch product_url(product), params: { product: { category: product.category, description: product.description, inv_qty: product.inv_qty, price: product.price, prod_name: product.prod_name } } + id = products(:cake1).id + + patch product_path(id) must_redirect_to product_path(product) end it "destroys product" do + id = products(:cake1).id + expect { - delete product_url(product) + delete product_path(id) }.must_change "Product.count", -1 must_redirect_to products_path From 7aecb5196dd045d040a489c7c7b3c13dd125f5d9 Mon Sep 17 00:00:00 2001 From: Jazz Date: Wed, 24 Oct 2018 11:16:18 -0700 Subject: [PATCH 130/192] add confirm method to order --- app/controllers/orders_controller.rb | 29 +++++++++++++++------------- config/routes.rb | 2 ++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index a7daaf5cdc..fb0f26913e 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -8,21 +8,24 @@ def index @orders = Order.all end - # show Confirmation Page - def show - # session id is not the same as current order id - their difference is 1 - # get current order that has customer info with @order - # order items are in the current session - @order_items = Order.find_by(id: session[:order_id]).order_items - if order_items.nil? + def confirm_order + if @order_items.nil? + flash[:warning] = "You have zero items in your cart" redirect_to products_path + else + @order_items = Order.find_by(id: session[:order_id]).order_items + # save order items from the current session to the session that has the personal information + @order.order_items = @order_items + @order.save + @order.place_order # decrease inventory and change status to paid + # clear shopping cart after confirmation page has been shown + session[:order_id] = nil + # show Confirmation Page end - # save order items from the current session to the session that has the personal information - @order.order_items = @order_items - @order.save - @order.place_order # decrease inventory and change status to paid - # clear shopping cart after confirmation page has been shown - session[:order_id] = nil + end + + def show + @order_items = Order.find_by(id: session[:order_id]).order_items end # GET /orders/new diff --git a/config/routes.rb b/config/routes.rb index 9b5a213249..1c07d7d9e0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,9 @@ resources :order_items, only: [:create, :update, :destroy] resources :reviews + resources :orders + patch 'order/confirm_order/:id', to: "order#confirm_order", as: "confirm_order" get 'products/category/:id', to: "products#category", as: "category" patch 'products/:id/retire', to: "products#status", as: "product_status" From f41680d67bacfde89c56b505b5a1ed890f9d605d Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 11:24:39 -0700 Subject: [PATCH 131/192] change path for checkout button updates order instead of creating new order --- app/views/carts/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index ede3ddbdcf..5d2fb93d19 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -28,6 +28,6 @@ <% end %> -
    +
    <%= ord.status %>
    <%= link_to "Checkout", new_order_path(), class: "btn btn-primary" %><%= link_to "Checkout", order_path(@current_order.id), class: "btn btn-primary" %>
    From 02e04b2372bfb96e7456d27193d5ad332ffda1b9 Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 11:54:38 -0700 Subject: [PATCH 132/192] complete create tests --- app/controllers/order_items_controller.rb | 29 +++---- .../order_items_controller_test.rb | 78 ++++++++++++++++--- 2 files changed, 82 insertions(+), 25 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index e961501f6b..306b02e526 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -4,27 +4,28 @@ class OrderItemsController < ApplicationController def create - @order_item = @current_order.order_items.new(order_item_params) - @current_order.save - - if @order_item.save - session[:order_id] = @current_order.id - redirect_to cart_path(@current_order.id) + product = Product.find_by(id: params[:order_item][:product_id]) + if params[:order_item][:qty].to_i > product.inv_qty + flash[:warning] = "Quantity selected exceeds amount availabe in inventory" + redirect_to product_path(product.id) else - flash[:warning] = "Item order not placed" - redirect_to root_path + @order_item = @current_order.order_items.new(order_item_params) + @current_order.save + + if @order_item.save + session[:order_id] = @current_order.id + redirect_to cart_path(@current_order.id) + else + flash[:warning] = "Item order not placed" + redirect_to root_path + end + end end def update - # TODO DETERMINE WHICH INSTANCE IS NEEDED - # @CURRENT_ORDER OR @ORDER??????????????????? @order_item = @current_order.order_items.find(params[:id]) - # @order = current_order <- moved to controller filter - # check if item is in stock - # @order_item = @order.order_items.find(params[:id]) - @order_item.update_attributes(order_item_params) @current_order.save diff --git a/test/controllers/order_items_controller_test.rb b/test/controllers/order_items_controller_test.rb index ae89e24984..ff8e6d93e6 100644 --- a/test/controllers/order_items_controller_test.rb +++ b/test/controllers/order_items_controller_test.rb @@ -2,14 +2,14 @@ describe OrderItemsController do - let (:product) { products(:cake1) } + let (:product1) { products(:cake1) } + let (:product2) { products(:cake3) } let (:order_item_hash1) { { order_item: { - product_id: products(:cake3), - qty: 5, - shipped: true + product_id: product1.id, + qty: 5 } } } @@ -17,15 +17,51 @@ let (:order_item_hash2) { { order_item: { - product_id: product.id, - qty: 3, - shipped: true + product_id: product2.id, + qty: 3 + } + } + } + + let (:exceeds_inventory) { + { + order_item: { + product_id: product2.id, + qty: 5 + } + } + } + + let (:update_order_item1) { + { + order_item: { + product_id: product1.id, + qty: 3 } } } describe 'create' do + it 'can create a new order line item when order does not already exist' do + + orders_before = Order.count + + expect { + post order_items_path, params: order_item_hash1 + }.must_change 'OrderItem.count', 1 + + orders_after = Order.count + order_id = Order.last.id + + must_respond_with :redirect + must_redirect_to cart_path(order_id) + + expect(orders_after).must_equal orders_before + 1 + expect(OrderItem.last.product_id).must_equal product1.id + expect(OrderItem.last.order_id).must_equal order_id + end + it 'can create a new order line item to existing order' do post order_items_path, params: order_item_hash1 @@ -36,14 +72,20 @@ }.must_change 'OrderItem.count', 1 must_respond_with :redirect - expect(OrderItem.last.product_id).must_equal product.id + must_redirect_to cart_path(order_id) + expect(OrderItem.last.product_id).must_equal product2.id expect(OrderItem.last.order_id).must_equal order_id end - it 'can create a new order line item when order does not already exist' do - end - it 'can not add a line order item if item is out of stock' do + + expect { + post order_items_path, params: exceeds_inventory + }.wont_change 'OrderItem.count' + + must_respond_with :redirect + must_redirect_to product_path(product2.id) + end end @@ -51,6 +93,20 @@ describe 'update' do it 'can update an existing order line item with valid data' do + post order_items_path, params: order_item_hash1 + order_id = Order.last.id + order_item_id = OrderItem.last.id + before_qty = OrderItem.find_by(id: order_item_id).qty + + expect { + patch order_item_path(order_item_id), params: update_order_item1 + }.wont_change 'OrderItem.count' + + after_qty = OrderItem.find_by(id: order_item_id).qty + + must_respond_with :redirect + must_redirect_to cart_path(order_id) + end it 'will not update an existing order line item with invalid data' do From 69f920ac8de4da23ec87962568f11891a0569f95 Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 12:06:39 -0700 Subject: [PATCH 133/192] remove fa-stack if items in cart is zero --- app/models/order.rb | 2 +- app/views/layouts/application.html.erb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 202db8dfc1..bae54d839b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -14,7 +14,7 @@ class Order < ApplicationRecord def items_in_cart num = 0 if self.order_items.empty? - return nil + return 0 else self.order_items.each do |item| if item.qty != nil diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9c739ab4e5..ff4a7f93c6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -59,7 +59,12 @@ <%= link_to image_tag("github-square-brands.svg", class: "login"), "/auth/github" %> <% end %>
    From 8e1d6937fe545efa8288fc8c9cb0bee39d5159c1 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 12:25:42 -0700 Subject: [PATCH 134/192] order work flow, but the confirm_order is never called --- app/controllers/orders_controller.rb | 10 ++++------ app/views/carts/show.html.erb | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 45ffeed16b..67a032b950 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -13,19 +13,17 @@ def confirm_order flash[:warning] = "You have zero items in your cart" redirect_to products_path else - @order_items = Order.find_by(id: session[:order_id]).order_items - # save order items from the current session to the session that has the personal information - @order.order_items = @order_items - @order.save + @order.update(order_params) @order.place_order # decrease inventory and change status to paid - # clear shopping cart after confirmation page has been shown + # show confirmation page + render :show session[:order_id] = nil - # show Confirmation Page end end def show @order_items = Order.find_by(id: session[:order_id]).order_items + @order = Order.find_by(id: session[:order_id]) end # GET /orders/new diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 5d2fb93d19..2759bf18b6 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -28,6 +28,6 @@ <% end %> - <%= link_to "Checkout", order_path(@current_order.id), class: "btn btn-primary" %> + <%= link_to "Checkout", edit_order_path(@current_order.id), class: "btn btn-primary" %>
    From 60c7df78c6b4bbf7d2ef3e1381b7d99465a3daca Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 12:29:22 -0700 Subject: [PATCH 135/192] add new view when order_items is empty --- app/assets/stylesheets/carts.scss | 5 +++++ app/models/order.rb | 6 +++--- app/views/carts/new.html.erb | 4 ++++ app/views/layouts/application.html.erb | 6 +++++- config/routes.rb | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 app/views/carts/new.html.erb diff --git a/app/assets/stylesheets/carts.scss b/app/assets/stylesheets/carts.scss index 2fe1b9e710..9b1b49fdb7 100644 --- a/app/assets/stylesheets/carts.scss +++ b/app/assets/stylesheets/carts.scss @@ -1,3 +1,8 @@ // Place all the styles related to the Carts controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ +.empty-cart { + padding-top: 8rem; + text-align: center; + padding-bottom: 8rem; +} diff --git a/app/models/order.rb b/app/models/order.rb index bae54d839b..d72346fbc5 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -12,17 +12,17 @@ class Order < ApplicationRecord def items_in_cart - num = 0 + num_in_cart = 0 if self.order_items.empty? return 0 else self.order_items.each do |item| if item.qty != nil - num += item.qty + num_in_cart += item.qty end end end - return num + return num_in_cart end def total_price diff --git a/app/views/carts/new.html.erb b/app/views/carts/new.html.erb new file mode 100644 index 0000000000..e62db72ffd --- /dev/null +++ b/app/views/carts/new.html.erb @@ -0,0 +1,4 @@ +
    +

    Your cart is empty.

    +

    <%= link_to "Discover something scrumptious to fill it up", products_path %>

    +
    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ff4a7f93c6..25dce9427c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -59,7 +59,11 @@ <%= link_to image_tag("github-square-brands.svg", class: "login"), "/auth/github" %> <% end %>
    +<%if @product.inv_qty > 0 %>
    <%= form_with model: @order_item do |f| %> @@ -160,10 +161,15 @@ <% end %>
    +<%end%>
    - In Stock + <%if @product.inv_qty > 0 %> + In Stock + <%else %> + Out of Stock + <%end%>
    From 20e9c27456f46f87c69aa8b1408c0370780f5cab Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 15:08:53 -0700 Subject: [PATCH 145/192] show out of stock in cart if inv_qty is less than 1 --- app/views/carts/show.html.erb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 2759bf18b6..46e9e640e7 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -15,13 +15,16 @@ <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %> <%= order_item.product.price %> - - <%= form_with model: order_item do |f| %> - <%= f.select :qty, (1..order_item.product.inv_qty).to_a %> - <%= f.hidden_field :product_id, :value => order_item.product.id %> - <%= f.submit 'Update', class: "btn btn-primary" %> - <% end %> - + <%if order_item.product.inv_qty > 0 %> + <%= form_with model: order_item do |f| %> + <%= f.select :qty, (1..order_item.product.inv_qty).to_a %> + <%= f.hidden_field :product_id, :value => order_item.product.id %> + <%= f.submit 'Update', class: "btn btn-primary" %> + <% end %> + + <% else %> + Out of Stock + <%end%> <%= format_price(order_item.subtotal) %> <%= link_to "Remove", order_item_path(order_item.id), method: :delete, class: "btn btn-outline-danger" %> From 061db106f96903272de0e5e00cc57d84ed60739f Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 15:15:07 -0700 Subject: [PATCH 146/192] make out of stock align --- app/views/carts/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 46e9e640e7..1c9bc82bad 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -23,7 +23,7 @@ <% end %> <% else %> - Out of Stock + Out of Stock <%end%> <%= format_price(order_item.subtotal) %> From f39b0aed4b5de4cbe133464a0b1aee4ccf0ebb42 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 15:41:37 -0700 Subject: [PATCH 147/192] format decimal in total price --- 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 a5900db493..42a50708fc 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -15,7 +15,7 @@ <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %> <%= order_item.qty %> - $<%= order_item.subtotal %> + $<%= format_price(order_item.subtotal) %> <% end %> From c98a82a955ca29ae608fb5d0fff769f1fed0c546 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 24 Oct 2018 15:42:18 -0700 Subject: [PATCH 148/192] removed extra $ --- 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 42a50708fc..734b3c43ce 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -15,7 +15,7 @@ <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %> <%= order_item.qty %> - $<%= format_price(order_item.subtotal) %> + <%= format_price(order_item.subtotal) %> <% end %> From df08c390b40930fa9365892e7f253f1aa0a34e79 Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 20:18:49 -0700 Subject: [PATCH 149/192] update OrderItemController, ProductShow and fix when cart is empty --- app/controllers/application_controller.rb | 10 +++---- app/controllers/carts_controller.rb | 2 +- app/controllers/order_items_controller.rb | 33 +++++++++++++++-------- app/controllers/products_controller.rb | 20 ++++++++------ app/views/layouts/application.html.erb | 12 +++------ app/views/products/show.html.erb | 14 +++++----- 6 files changed, 51 insertions(+), 40 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 021f8507cb..5cf55a71a1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,13 +16,13 @@ def list_merchants end def current_order - if !session[:order_id].nil? + if session[:order_id] @current_order = Order.find(session[:order_id]) - else - @current_order = Order.new + # else + # @current_order = Order.new end - - return @current_order + # + # return @current_order end def render_404 diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb index 75b6e884da..46a37a8029 100644 --- a/app/controllers/carts_controller.rb +++ b/app/controllers/carts_controller.rb @@ -1,6 +1,6 @@ class CartsController < ApplicationController skip_before_action :require_login def show - @order_items = current_order.order_items.order(:created_at) + @order_items = @current_order.order_items.order(:created_at) end end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 622bd0c82d..b9f34b70f4 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,6 +1,6 @@ class OrderItemsController < ApplicationController skip_before_action :require_login - before_action :set_order, only: [:create, :update, :cart_direct] + # before_action :set_order, only: [:create, :update, :cart_direct] def create @@ -9,16 +9,22 @@ def create flash[:warning] = "Quantity selected exceeds amount availabe in inventory" redirect_to product_path(product.id) else + + if @current_order.nil? + @current_order = Order.new + @current_order.save + end + @order_item = @current_order.order_items.new(order_item_params) + @order_item.save @current_order.save - if @order_item.save - session[:order_id] = @current_order.id - redirect_to cart_path(@current_order.id) - else - flash[:warning] = "Item order not placed" - redirect_to root_path - end + session[:order_id] = @current_order.id + redirect_to cart_path(@current_order.id) + # else + # flash[:warning] = "Item order not placed" + # redirect_to root_path + # # end end end @@ -53,6 +59,11 @@ def cart_direct flash[:warning] = "Product is out of stock" redirect_to products_path else + if @current_order.nil? + @current_order = Order.new + @current_order.save + end + @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, shipped: false) @order_item.save @current_order.save @@ -90,8 +101,8 @@ def order_item_params params.require(:order_item).permit(:product_id, :qty, :shipped) end - def set_order - @order = current_order - end + # def set_order + # @order = current_order + # end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 864a0680ce..62196b5539 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -11,14 +11,18 @@ def index # GET /products/1 def show - @order_item = @current_order.order_items.find_by(product_id: params[:id]) - - # setting up space, creating a blank row, not filling out - if @order_item.nil? - @order_item = current_order.order_items.new - end - - @product = Product.find(params[:id]) + # if @current_order.order_items.find_by(product_id: params[:id]).nil? + @order_item = OrderItem.new + # else + # @order_item = @current_order.order_items.find_by(product_id: params[:id]) + # end + # + # # setting up space, creating a blank row, not filling out + # if @order_item.nil? + # @order_item = current_order.order_items.new + # end + + # @product = Product.find(params[:id]) @reviews = Review.where(product_id: @product) end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 25dce9427c..4ee5f6a207 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -59,16 +59,12 @@ <%= link_to image_tag("github-square-brands.svg", class: "login"), "/auth/github" %> <% end %>
    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 114eb6a293..ae3a372169 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -149,13 +149,13 @@
    - <%= form_with model: @order_item do |f| %> - <%= f.label :qty %> - <%= f.select :qty, (1..@product.inv_qty).to_a %> - <%= f.hidden_field :product_id, :value => @product.id %> - <%= f.hidden_field :shipped, :value => false %> -
    -
    + <%= form_with model: @order_item do |f| %> + <%= f.label :qty %> + <%= f.select :qty, (1..@product.inv_qty).to_a %> + <%= f.hidden_field :product_id, :value => @product.id %> + <%= f.hidden_field :shipped, :value => false %> + <%= f.submit "Add to cart", class: "btn btn-sm btn-brand btn-full-width" %> <% end %>
    From f52be28d507a1f0539ad02fe76f781099ba48008 Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 21:12:14 -0700 Subject: [PATCH 150/192] cart controller testing --- app/assets/stylesheets/application.scss | 2 +- app/assets/stylesheets/products.scss | 2 +- app/controllers/carts_controller.rb | 8 ++++- app/views/carts/not_found | 1 + app/views/layouts/application.html.erb | 7 +++- ...25035101_add_default_item_shipped_false.rb | 5 +++ db/schema.rb | 4 +-- test/controllers/carts_controller_test.rb | 33 +++++++++++++++++-- 8 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 app/views/carts/not_found create mode 100644 db/migrate/20181025035101_add_default_item_shipped_false.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 3fc82fe2b6..e58be567ec 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -177,7 +177,7 @@ p { .page-footer { color: #8ff9f6 !important; - font-weight: bold; + // font-weight: bold; background: #343a40 !important; bottom:0; } diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index bd2cecb1d5..b06d01fc37 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -189,7 +189,7 @@ a.button:hover{ .carousel-item img { object-position: center; /* Center the image within the element */ width: 100%; - opacity: .75; + // opacity: .75; } .rounded-circle { diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb index 46a37a8029..797632aab5 100644 --- a/app/controllers/carts_controller.rb +++ b/app/controllers/carts_controller.rb @@ -1,6 +1,12 @@ class CartsController < ApplicationController skip_before_action :require_login + def show - @order_items = @current_order.order_items.order(:created_at) + if @current_order.nil? + render :not_found, status: :not_found + else + @order_items = @current_order.order_items.order(:created_at) + end end + end diff --git a/app/views/carts/not_found b/app/views/carts/not_found new file mode 100644 index 0000000000..478f28b68c --- /dev/null +++ b/app/views/carts/not_found @@ -0,0 +1 @@ +

    404 Not Found

    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4ee5f6a207..caa00533be 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -113,8 +113,13 @@ <%= link_to "Login with Github", "/auth/github" %>
  • - Shopping Cart + <% if session[:order_id] %> + <%= link_to "Shopping Cart", cart_path(@current_order.id) %> + <% else %> + <%= link_to "Shopping Cart", new_cart_path %> + <% end %>
  • +
  • Order Status
  • diff --git a/db/migrate/20181025035101_add_default_item_shipped_false.rb b/db/migrate/20181025035101_add_default_item_shipped_false.rb new file mode 100644 index 0000000000..1a0ae7d566 --- /dev/null +++ b/db/migrate/20181025035101_add_default_item_shipped_false.rb @@ -0,0 +1,5 @@ +class AddDefaultItemShippedFalse < ActiveRecord::Migration[5.2] + def change + change_column_default :order_items, :shipped, false + end +end diff --git a/db/schema.rb b/db/schema.rb index f9eb20bc24..c3ca907a71 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_22_232304) do +ActiveRecord::Schema.define(version: 2018_10_25_035101) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -30,7 +30,7 @@ create_table "order_items", force: :cascade do |t| t.integer "qty" - t.boolean "shipped" + t.boolean "shipped", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "product_id" diff --git a/test/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb index 7a23b04176..4eae0b05ab 100644 --- a/test/controllers/carts_controller_test.rb +++ b/test/controllers/carts_controller_test.rb @@ -1,9 +1,36 @@ require "test_helper" describe CartsController do - it "should get show" do - get carts_show_url - value(response).must_be :success? + + let (:product1) { products(:cake1) } + + let (:order_item_hash1) { + { + order_item: { + product_id: product1.id, + qty: 5 + } + } + } + + + it "should get a cart's show if order exists" do + post order_items_path, params: order_item_hash1 + order_id = Order.last.id + + get cart_path(order_id) + + must_respond_with :success + + end + + it "should respond with not_found given an invalid order_id" do + order_id = -1 + + get cart_path(order_id) + + must_respond_with :not_found + end end From c759730ca9162d993a7ac866f08bf959a4791de2 Mon Sep 17 00:00:00 2001 From: Jazz Date: Wed, 24 Oct 2018 21:19:08 -0700 Subject: [PATCH 151/192] product controller testing --- app/assets/stylesheets/application.scss | 8 +- app/assets/stylesheets/products.scss | 8 + app/controllers/orders_controller.rb | 7 + app/controllers/products_controller.rb | 32 ++- app/models/order.rb | 14 +- app/views/orders/_form.html.erb | 2 +- app/views/products/not_found.html.erb | 1 + app/views/products/show.html.erb | 8 +- test/controllers/products_controller_test.rb | 228 ++++++++++++++++--- test/controllers/reviews_controller_test.rb | 89 +------- test/fixtures/products.yml | 2 +- 11 files changed, 266 insertions(+), 133 deletions(-) create mode 100644 app/views/products/not_found.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 3fc82fe2b6..ef81e13f02 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,10 +19,10 @@ -body { - padding-bottom: 20px; - margin-bottom: 60px; -} +// body { +// padding-bottom: 20px; +// margin-bottom: 60px; +// } h1, h2, h3, h4 { font-family: 'Alegreya Sans SC', sans-serif; diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index bd2cecb1d5..2008c49551 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -31,6 +31,14 @@ padding-top: 2em; } +.rating-stars { + display: flex; +} + +.add-review-btn { + margin-left: 2rem; +} + .table-responsive-md { margin-left: 25px; margin-right: 25px; diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index fb0f26913e..14f8dca4a3 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -26,6 +26,13 @@ def confirm_order def show @order_items = Order.find_by(id: session[:order_id]).order_items + # @order_items = Order.find_by(id: session[:order_id]).order_items + # # save order items from the current session to the session that has the personal information + # @order.order_items = @order_items + # @order.save + # @order.place_order # decrease inventory and change status to paid + # # clear shopping cart after confirmation page has been shown + # session[:order_id] = nil end # GET /orders/new diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 864a0680ce..24e5b56263 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -11,29 +11,44 @@ def index # GET /products/1 def show + # @product = Product.find(params[:id]) + @order_item = @current_order.order_items.find_by(product_id: params[:id]) - # setting up space, creating a blank row, not filling out + # setting up space, creating a blank row, not filling out if @order_item.nil? @order_item = current_order.order_items.new end - @product = Product.find(params[:id]) + @reviews = Review.where(product_id: @product) end # GET /products/new def new - @product = Product.new + if session[:user_id].nil? + redirect_to root_path + flash[:danger] = "You must log in to access this feature" + else + @product = Product.new + end end # GET /products/1/edit - def edit; end + def edit + if @product.user_id != session[:user_id] + flash[:danger] = "You don't have access to edit this product." + redirect_to product_path(@product.id) + end + end # POST /products def create @product = Product.new(product_params) @product.user_id = session[:user_id] + + return redirect_to root_path if session[:user_id].nil? + if @product.save(product_params) flash[:notice] = "#{@product.prod_name} was successfully created." redirect_to user_path(session[:user_id]) @@ -44,14 +59,15 @@ def create # PATCH/PUT /products/1 def update - respond_to do |format| + # respond_to do |format| if @product.update(product_params) flash[:notice] = "#{@product.prod_name} was successfully updated." redirect_to product_path else + flash[:warning] = "Edit was unsuccessful" render :edit end - end + # end end # DELETE /products/1 @@ -91,7 +107,11 @@ def merchant # Use callbacks to share common setup or constraints between actions. def set_product + begin @product = Product.find(params[:id]) + rescue + render :not_found, status: :not_found + end end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/models/order.rb b/app/models/order.rb index 61ce82783a..2a16040935 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,12 +1,12 @@ class Order < ApplicationRecord #validations - validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :place_order - validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, maxlength: 16 }, on: :place_order - validates :cc_expiration, presence: true, on: :place_order - validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :place_order - validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :place_order - validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :place_order - validates :mailing_address, presence: true, on: :place_order + validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :confirm_order + validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, maxlength: 16 }, on: :confirm_order + validates :cc_expiration, presence: true, on: :confirm_order + validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :confirm_order + validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :confirm_order + validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :confirm_order + validates :mailing_address, presence: true, on: :confirm_order #relationships has_many :order_items diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 1a7fa80f16..9fec032f37 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -24,7 +24,7 @@
    <%= form.label "Credit Card Number" %> - <%= form.number_field :cc_digit, class: "form-control", input_html: {:pattern => /[0-9]{16}/}%> + <%= form.number_field :cc_digit, class: "form-control", maxlength: "16"%>
    diff --git a/app/views/products/not_found.html.erb b/app/views/products/not_found.html.erb new file mode 100644 index 0000000000..478f28b68c --- /dev/null +++ b/app/views/products/not_found.html.erb @@ -0,0 +1 @@ +

    404 Not Found

    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 114eb6a293..62d3e622dc 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -101,7 +101,7 @@
    -
    +
    @@ -128,14 +128,14 @@
    -
    +
    <% if @product.reviews.length >= 1 %> <% @product.avg_rating.round.times do %> rating star <% end %> <% end %>
    -
    +
    <%= link_to "Write A Review", new_product_review_path(@product), class:"btn btn-danger" %>
    @@ -151,7 +151,7 @@
    <%= form_with model: @order_item do |f| %> <%= f.label :qty %> - <%= f.select :qty, (1..@product.inv_qty).to_a %> + <%= f.select :qty, (1..@product.inv_qty).to_a, {}, class: 'some-class' %> <%= f.hidden_field :product_id, :value => @product.id %> <%= f.hidden_field :shipped, :value => false %>
    diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 20efab0ef4..dd9fa74552 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -8,51 +8,219 @@ value(response).must_be :successful? end - it "gets new" do - get new_product_path - value(response).must_be :successful? - end + describe "new" do + + it "gets new form for a logged in user" do + user = users(:laura) + perform_login(user) - it "creates product" do - id = users(:laura).id - product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: id } } + get new_product_path + value(response).must_be :successful? + end - expect { - post products_path, params: product_hash - }.must_change "Product.count" + it "is an invalid request if merchant is not logged in" do + get new_product_path - must_redirect_to user_path(session[:user_id]) - expect(flash[:notice]).must_equal "#{@product.prod_name} was successfully created." + must_redirect_to root_path + value(response).must_be :redirection? + expect(flash[:danger]).must_equal "You must log in to access this feature" + end end - it "shows product" do - id = products(product).id + describe "create" do - get product_path(id) - value(response).must_be :successful? + it "creates product" do + user = users(:laura) + perform_login(user) + + id = users(:laura).id + product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: id } } + + expect { + post products_path, params: product_hash + }.must_change "Product.count" + + must_redirect_to user_path(session[:user_id]) + expect(flash[:notice]).must_equal "#{product.prod_name} was successfully created." + end + + it "is an forbidden request if user is not logged in" do + product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: nil } } + + expect { + post products_path, params: product_hash + }.wont_change "Product.count" + + must_redirect_to root_path + expect(response.response_code).must_equal 302 + end end - it "gets edit" do - id = products(:cake1).id + describe "show" do + + it "show a single product detail page" do + id = Product.first.id + + get product_path(id) + value(response).must_be :successful? + end + + it "should repond with not_found if given an invalid id" do + id = -1 + + get product_path(id) + + must_respond_with :not_found + end - get edit_product_path(id) - value(response).must_be :successful? end - it "updates product" do - id = products(:cake1).id + describe "edit" do + + it "gets edit form page for a logged in merchant" do + user = users(:laura) + perform_login(user) + + id = products(:cake1).id + + get edit_product_path(id) + value(response).must_be :successful? + end + + it "should respond with not_found if an invalid product id is entered" do + user = users(:laura) + perform_login(user) + + id = products(:cake2).id + + get edit_product_path(id) + + must_redirect_to product_path(id) + expect(flash[:danger]).must_equal "You don't have access to edit this product." + end + + it "does not give a logged out user access to a product edit page" do + id = products(:cake2).id - patch product_path(id) - must_redirect_to product_path(product) + get edit_product_path(id) + + must_redirect_to root_path + end + + it "should respond with not_found if given an invalid id" do + user = users(:laura) + perform_login(user) + + id = -1 + + get edit_product_path(id) + + must_respond_with :not_found + end end - it "destroys product" do - id = products(:cake1).id + describe "update" do + let(:laura) {users(:laura)} + let (:product_hash) do + { + product: { + prod_name: product.prod_name, + description: product.description, + price: product.price, + inv_qty: product.inv_qty, + user: laura.id + } + } + end + + it "a merchant can update their product" do + user = users(:laura) + perform_login(user) + + id = products(:cake1).id + + expect { + patch product_path(id), params: product_hash + }.wont_change "Product.count" + + must_redirect_to product_path + expect(flash[:notice]).must_equal "#{product.prod_name} was successfully updated." + + new_product = Product.find_by(id: id) + + expect(new_product.prod_name).must_equal product_hash[:product][:prod_name] + expect(new_product.description).must_equal product_hash[:product][:description] + end + + it "a user not logged in cant update a product" do + id = products(:cake1).id - expect { - delete product_path(id) - }.must_change "Product.count", -1 + expect { + patch product_path(id), params: product_hash + }.wont_change "Product.count" - must_redirect_to products_path + must_redirect_to root_path(id) + end + + it "a gives an error if the product params are invalid" do + user = users(:laura) + perform_login(user) + + cake1 = products(:cake1) + product_hash[:product][:prod_name] = cake1.prod_name + + id = products(:cake2).id + old_product = products(:cake2) + + expect { + patch product_path(id), params: product_hash + }.wont_change "Product.count" + + new_product = Product.find(id) + + must_respond_with :success + expect(old_product.prod_name).must_equal new_product.prod_name + expect(old_product.description).must_equal new_product.description + expect(flash[:warning]).must_equal "Edit was unsuccessful" + end + + it "gives not_found for a product that doesnt exist" do + id = -1 + + expect { + patch product_path(id) + }.wont_change 'Product.count' + + must_respond_with :not_found + end end + + # describe "destroy" do + # + # it "can destroy a product with a logged in merchant" do + # user = users(:laura) + # perform_login(user) + # + # id = products(:cake1).id + # + # expect { + # delete product_path(id) + # }.must_change 'Product.count', -1 + # + # must_respond_with :redirect + # expect(Product.find_by(id: id)).must_equal nil + # end + # + # end + + # it "can destroy a book given a vlid id" do + # id = -1 + # + # expect { + # delete book_path(id) + # }.wont_change 'Book.count' + # + # must_respond_with :not_found + # expect(flash[:danger]).must_equal "Cannot find the book #{id}" + # end end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index bcc0661a8f..a8e29675d5 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -8,32 +8,6 @@ value(response).must_be :successful? end - # describe "show" do - - # it "gets a review show page" do - # id = products(:cake1).id - # - # get reviews_path(id) - # value(response).must_be :successful? - # end - - # it "shows review" do - # get review_url(review) - # value(response).must_be :successful? - # end - # - # end - - # it "should repond with not_found if given an invalid id" do - # id = -1 - # - # get new_product_review_path(id) - # - # value(response).must_be :not_found - # end - # end - - describe "new" do it "gets the form with the new review page" do @@ -73,66 +47,21 @@ expect(flash[:warning]).must_equal "Please enter all fields" end - # it "respond with an error if merchant reviews their own product" do - # get "/auth/github", params: {username: "laura"} - # expect(session[:user_id]).wont_be_nil - # - # id = products(:cake1).id - # review_hash = { review: { description: review.description, rating: review.rating} } - # - # expect { - # post product_reviews_path(id), params: review_hash - # }.wont_change "Review.count" - # - # must_redirect_to products_path - # expect(flash[:warning]).must_equal "You can't review your own Product" - # end - end - - - describe "edit" do + it "respond with an error if merchant reviews their own product" do + user = users(:laura) + perform_login(user) - it "can get the edit page for a valid review" do id = products(:cake1).id + review_hash = { review: { description: review.description, rating: review.rating} } - get edit_review_url(review) - value(response).must_be :successful? - end - - # it "should resond with not_found if given an invalid id" do - # id = -1 - # - # get review_path(id) - # - # must_respond_with :not_found - # end - end - - it "updates review" do - patch review_url(review), params: { review: { description: review.description, rating: review.rating } } - must_redirect_to review_path(review) - end - - describe "destroy" do - - it "destroys review given a valid id" do expect { - delete review_url(review) - }.must_change "Review.count", -1 + post product_reviews_path(id), params: review_hash + }.wont_change "Review.count" - must_redirect_to reviews_path + must_redirect_to products_path + expect(flash[:warning]).must_equal "You can't review your own Product" end - - # it "cant destroy a review given an invalid id" do - # id = -1 - # - # expect { - # delete book_path(id) - # }.wont_change 'Book.count' - # - # must_respond_with :not_found - # expect(flash[:danger]).must_equal "Cannot find the book #{id}" - # end end + end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 1a2df5c7aa..81f7140f1e 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -14,7 +14,7 @@ cake2: description: the best price: 19.5 inv_qty: 5 - user: laura + user: grace cake3: From c5228f52e0e310d301816d7e8f91671419daeefd Mon Sep 17 00:00:00 2001 From: Trang Date: Wed, 24 Oct 2018 21:27:10 -0700 Subject: [PATCH 152/192] test Order model for items_in_cart --- app/assets/stylesheets/application.scss | 6 ++++++ app/assets/stylesheets/carts.scss | 5 ----- app/views/carts/new.html.erb | 2 +- app/views/carts/not_found | 1 - app/views/carts/not_found.html.erb | 3 +++ app/views/products/not_found.html.erb | 4 +++- test/fixtures/orders.yml | 11 +++++++++++ test/models/order_test.rb | 17 +++++++++++++++++ 8 files changed, 41 insertions(+), 8 deletions(-) delete mode 100644 app/views/carts/not_found create mode 100644 app/views/carts/not_found.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index e58be567ec..e49b84b1bf 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -199,3 +199,9 @@ p { #fotp { color: white; } + +.message { + padding-top: 8rem; + text-align: center; + padding-bottom: 8rem; +} diff --git a/app/assets/stylesheets/carts.scss b/app/assets/stylesheets/carts.scss index 9b1b49fdb7..2fe1b9e710 100644 --- a/app/assets/stylesheets/carts.scss +++ b/app/assets/stylesheets/carts.scss @@ -1,8 +1,3 @@ // Place all the styles related to the Carts controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.empty-cart { - padding-top: 8rem; - text-align: center; - padding-bottom: 8rem; -} diff --git a/app/views/carts/new.html.erb b/app/views/carts/new.html.erb index e62db72ffd..1dbb6c5c5d 100644 --- a/app/views/carts/new.html.erb +++ b/app/views/carts/new.html.erb @@ -1,4 +1,4 @@ -
    +

    Your cart is empty.

    <%= link_to "Discover something scrumptious to fill it up", products_path %>

    diff --git a/app/views/carts/not_found b/app/views/carts/not_found deleted file mode 100644 index 478f28b68c..0000000000 --- a/app/views/carts/not_found +++ /dev/null @@ -1 +0,0 @@ -

    404 Not Found

    diff --git a/app/views/carts/not_found.html.erb b/app/views/carts/not_found.html.erb new file mode 100644 index 0000000000..6156bba9d2 --- /dev/null +++ b/app/views/carts/not_found.html.erb @@ -0,0 +1,3 @@ +
    +

    404 Not Found

    +
    diff --git a/app/views/products/not_found.html.erb b/app/views/products/not_found.html.erb index 478f28b68c..6156bba9d2 100644 --- a/app/views/products/not_found.html.erb +++ b/app/views/products/not_found.html.erb @@ -1 +1,3 @@ -

    404 Not Found

    +
    +

    404 Not Found

    +
    diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index e2b00532c2..d7e7dfd27b 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -21,3 +21,14 @@ two: cc_expiration: 2018-10-17 cc_cvv: 1 cc_zip: 1 + +three: + status: pending + cust_name: ada + cust_email: ada@gmail.com + mailing_address: 1 + cc_name: MyString + cc_digit: 1111111111111111 + cc_expiration: 2018-10-17 + cc_cvv: 123 + cc_zip: 98765 diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 039098a5ad..7290b3298f 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -2,6 +2,23 @@ describe Order do + describe "items_in_cart" do + + it "returns the total quantity of items in cart" do + order = orders(:one) + number = order.items_in_cart + + expect(number).must_equal 4 + end + + it "returns 0 when no items in cart" do + order = orders(:three) + number = order.items_in_cart + + expect(number).must_equal 0 + end + end + describe "place order" do it "reduces inventory quantity by order item quantity" do From e651e0a913cd21bfcc0a3634ab43caff71c7c253 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Wed, 24 Oct 2018 21:46:03 -0700 Subject: [PATCH 153/192] add nested routes products nested inusers --- config/routes.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 2fff3178b5..a548a01cac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,8 +18,6 @@ post "order_items/cart_direct/:id", to: "order_items#cart_direct", as: "quick_shop" resources :order_items, only: [:create, :update, :destroy] - resources :reviews - resources :orders patch 'order/confirm_order/:id', to: "order#confirm_order", as: "confirm_order" @@ -29,6 +27,13 @@ resources :products resources :users + + resources :users do + resources :products, only: [:index, :new, :show, :create, :update] + end + + + resources :categories end From e31b27e526771e5ea2d4bb3e0d18dab78b014d30 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 25 Oct 2018 00:53:49 -0700 Subject: [PATCH 154/192] added merchant order info --- app/controllers/categories_controller.rb | 2 +- app/controllers/order_items_controller.rb | 57 ++++++------- app/controllers/orders_controller.rb | 38 ++++----- app/controllers/products_controller.rb | 40 ++++++--- app/controllers/users_controller.rb | 16 ++-- app/models/category.rb | 1 + app/models/order.rb | 22 +++-- app/models/user.rb | 19 +++-- app/views/categories/_form.html.erb | 5 +- app/views/orders/_form.html.erb | 5 +- app/views/orders/show.html.erb | 2 +- app/views/products/_form.html.erb | 4 +- app/views/products/show.html.erb | 98 ----------------------- app/views/users/show.html.erb | 52 +++++++++--- config/routes.rb | 3 +- 15 files changed, 163 insertions(+), 201 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index b974a3e0f3..6896d744bb 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -28,7 +28,7 @@ def create else flash.now[:warning] = 'Category not created' @category.errors.messages.each do |field, msg| - flash.now[field] = messages + flash.now[field] = msg end render :new end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index b9f34b70f4..0636bb8371 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -1,6 +1,6 @@ class OrderItemsController < ApplicationController skip_before_action :require_login - # before_action :set_order, only: [:create, :update, :cart_direct] + # before_action :set_order, only: [:ship] def create @@ -8,30 +8,27 @@ def create if params[:order_item][:qty].to_i > product.inv_qty flash[:warning] = "Quantity selected exceeds amount availabe in inventory" redirect_to product_path(product.id) - else + elsif @current_order.nil? + @current_order = Order.new + # @current_order.save + end - if @current_order.nil? - @current_order = Order.new - @current_order.save - end + @order_item = @current_order.order_items.new(order_item_params) + @order_item.save + @current_order.save - @order_item = @current_order.order_items.new(order_item_params) - @order_item.save - @current_order.save - - session[:order_id] = @current_order.id - redirect_to cart_path(@current_order.id) - # else - # flash[:warning] = "Item order not placed" - # redirect_to root_path - # # end - end + session[:order_id] = @current_order.id + redirect_to cart_path(@current_order.id) + # else + # flash[:warning] = "Item order not placed" + # redirect_to root_path + # # end end def update product = Product.find_by(id: params[:order_item][:product_id]) if params[:order_item][:qty].to_i > product.inv_qty - flash[:warning] = "Quantity selected exceeds amount availabe in inventory" + flash[:warning] = "Quantity selected exceeds amount available in inventory" redirect_to product_path(product.id) else @order_item = @current_order.order_items.find_by(id: params[:id]) @@ -58,19 +55,17 @@ def cart_direct if product.inv_qty == 0 flash[:warning] = "Product is out of stock" redirect_to products_path - else - if @current_order.nil? - @current_order = Order.new - @current_order.save - end - - @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, shipped: false) - @order_item.save + elsif @current_order.nil? + @current_order = Order.new @current_order.save - - session[:order_id] = @current_order.id - redirect_to cart_path(@current_order.id) end + + @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, shipped: false) + @order_item.save + @current_order.save + + session[:order_id] = @current_order.id + redirect_to cart_path(@current_order.id) end def destroy @@ -83,8 +78,8 @@ def destroy def ship @order_item = OrderItem.find_by(product_id: params[:id]) - @order_item.shipped = true - Order.check_order_status(@current_order) + @order_item.update(shipped: true) + @order_item.order.check_order_status if @order_item.save flash[:success] = 'Item(s) have been marked as shipped' redirect_back(fallback_location: root_path) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2a2e896ee8..789b3ae546 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -27,22 +27,22 @@ def edit # POST /orders # must change database # flash notices do not have color - def create - @order = @current_order.update(order_params) - # it successfully grabs and saves all fields put in the form - if @order.save - flash[:success] = 'Order was successfully created.' - redirect_to order_path(@order.id) - else - flash.now[:warning] = 'Order not created' - - @order.errors.messages.each do |field, msg| - flash.now[field] = msg - end - - render :new - end - end + # def create + # @order = @current_order.update(order_params) + # # it successfully grabs and saves all fields put in the form + # if @order.save + # flash[:success] = 'Order was successfully created.' + # redirect_to order_path(@order.id) + # else + # flash.now[:warning] = 'Order not created' + # + # @order.errors.messages.each do |field, msg| + # flash.now[field] = msg + # end + # + # render :new + # end + # end # PATCH/PUT /orders/1 @@ -82,7 +82,7 @@ def order_params params.require(:order).permit(:status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) end - def check_status - Order.check_order_status(@order) - end + # def check_status + # Order.check_order_status(@order) + # end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 62196b5539..4c7ea03c9b 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -5,14 +5,25 @@ class ProductsController < ApplicationController # GET /products def index - @products = Product.all + # if user logged in then get just their products + if session[:user_id] + @products = @login_user.products + else + @products = Product.all + end + end # GET /products/1 def show + @product = Product.find(params[:id]) + # if @login_user + # @products = @login_user.products + # end + # # if @current_order.order_items.find_by(product_id: params[:id]).nil? - @order_item = OrderItem.new + # @order_item = OrderItem.new # else # @order_item = @current_order.order_items.find_by(product_id: params[:id]) # end @@ -28,7 +39,14 @@ def show # GET /products/new def new - @product = Product.new + + if params[:user_id] + # nested route: /user/user_id/products/new + user = User.find_by(id: params[:user_id]) + @product = user.products.new + else + @product = Product.new + end end # GET /products/1/edit @@ -39,7 +57,7 @@ def create @product = Product.new(product_params) @product.user_id = session[:user_id] if @product.save(product_params) - flash[:notice] = "#{@product.prod_name} was successfully created." + flash[:notice] = "#{@product.prod_name} was added to your inventory." redirect_to user_path(session[:user_id]) else render :new @@ -48,16 +66,15 @@ def create # PATCH/PUT /products/1 def update - respond_to do |format| - if @product.update(product_params) - flash[:notice] = "#{@product.prod_name} was successfully updated." - redirect_to product_path - else - render :edit - end + if @product.update(product_params) + flash[:notice] = "#{@product.prod_name} was successfully updated." + redirect_to product_path + else + render :edit end end + # DELETE /products/1 def destroy @product.destroy @@ -88,7 +105,6 @@ def status def merchant @user = User.find_by(id: params[:id]) @products = Product.by_merchant(params[:id].to_i) - end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b53dc9c02e..e830ead1e4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,14 +6,14 @@ class UsersController < ApplicationController def show render_404 unless @user - @order = current_order - @order_item = @order.order_items.find_by(product_id: params[:id]) - - if @order_item.nil? - @order_item = current_order.order_items.new - end - - @products = Product.where(user_id: @user) + # @order = current_order + # @order_item = @order.order_items.find_by(product_id: params[:id]) + # + # if @order_item.nil? + # @order_item = current_order.order_items.new + # end + # + # @products = Product.where(user_id: @user) end # GET /users/new diff --git a/app/models/category.rb b/app/models/category.rb index 4a839b1d0d..64237aa325 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,5 +1,6 @@ class Category < ApplicationRecord # validations + validates :category, presence: true, uniqueness: true # relationships diff --git a/app/models/order.rb b/app/models/order.rb index 4cac6528ed..a8e773e012 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -52,13 +52,21 @@ def date_of_order return self.created_at.strftime("%B %d, %Y") end - # def check_order_status(order) - # if order.order_items.all? {|item| item.shipped} - # order.status = "Complete" - # raise - # order.save - # end - # end + def check_order_status + @order = self + all_shipped = true + @order.order_items.each do |item| + if !item.shipped + all_shipped = false + end + end + binding.pry + if all_shipped + @order.update(status: "Complete") + end + + return @order + end def destroy # method to cancel order diff --git a/app/models/user.rb b/app/models/user.rb index c50ea0e710..6247a1afd7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,12 +30,21 @@ def find_orders end - def revenue - @pending = self.orders.where(status: "Pending") - @paid = self.orders.where(status: "Paid") - @shipped = self.orders.where(status: "Complete") - @completed = self.orders.where(status: "Cancelled") + def revenue(status_filter) + case status_filter + when "Pending" + rev = self.orders.where(status: "Pending").order_items.subtotal.sum + when "Paid" + rev = self.orders.where(status: "Paid").order_items.subtotal.sum + when "Completed" + rev = self.orders.where(status: "Complete").order_items.subtotal.sum + when "Cancelled" + rev = self.orders.where(status: "Cancelled").order_items.subtotal.sum + when "Total" + rev = self.orders.order_items.subtotal.sum - self.orders.where(status: "Cancelled").order_items.subtotal.sum + end + return rev end diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index dd9dcb481b..d9c7221335 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -1,6 +1,7 @@ -<%= form_with(model: category, local: true) do |form| %> - <% render partial: "layouts/form_errors", locals: { error_hash: @category } %> +<% render partial: "layouts/form_errors", locals: { error_hash: @category } %> +<%= render partial: "/layouts/flash_errs" %> +<%= form_with(model: category, local: true) do |form| %>
    <%= form.label :category %> <%= form.text_field :category, class: "form-control"%> diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 1a7fa80f16..3e928aab4e 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -1,5 +1,6 @@ +<% render partial: "layouts/form_errors", locals: { error_hash: @order } %> + <%= form_with(model: order, local: true) do |form| %> - <%# render partial "/layouts/form_errors", locals: { error_hash: order}%>
    @@ -46,5 +47,3 @@ <%= form.submit class: "btn btn-primary" %>
    <% end %> - - diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index a5900db493..31a19000a2 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,4 +1,4 @@ -

    <%= notice %>

    +

    Confirmation Page

    diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index f92ad2897a..5ae38aafe7 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,6 +1,6 @@ -<%= form_with(model: product, local: true) do |form| %> - <% render partial: "layouts/form_errors", locals: { error_hash: @product } %> +<% render partial: "layouts/form_errors", locals: { error_hash: @product } %> +<%= form_with(model: product, local: true) do |form| %>
    <%= form.label :prod_name %> <%= form.text_field :prod_name, class: "form-control"%> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index ae3a372169..024113ea81 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,102 +1,4 @@ <%= render partial: "/layouts/flash_errs" %> - -

    <%= notice %>

    - - - - <%#= form_with model: @order_item do |f| %> - <%#= f.label :qty %> - <%#= f.select :qty, (1..@product.inv_qty).to_a %> - - <%#= f.hidden_field :product_id, :value => @product.id %> - - <%#= f.submit "Add to cart", class: "btn btn-primary" %> - <%# end %> - - - - - - <%# @product.categories.each do |cat| %> - - <%# end %> - - - - -<%#= form_with model: @order_item do |f| %> - <%#= f.label :qty %> - <%#= f.select :qty, (1..@product.inv_qty).to_a %> - -<%#= form_with model: @order_item do |f| %> - <%#= f.label :qty %> - <%#= f.select :qty, (1..@product.inv_qty).to_a %> - - <%#= f.hidden_field :product_id, :value => @product.id %> - - <%#= f.submit "Add to cart", class: "btn btn-primary" %> -<%# end %> - <%#= f.hidden_field :product_id, :value => @product.id %> - - <%#= f.submit "Add to cart", class: "btn btn-primary" %> -<%# end %> - - - - -<%#= link_to 'Back', products_path %> - -<%#= link_to 'Back', products_path, class: "btn btn-success" %> - - - - -
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index f3c4cc69b3..37b1c47d7c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,8 +1,7 @@ -

    <%= notice %>

    <%= render partial: "/layouts/flash_errs" %>

    - Uid: + User ID: <%= @user.uid %>

    @@ -19,8 +18,9 @@
    -<%= link_to 'List a Product', new_product_path, class: "sell-link btn btn-info" %> | -<%= link_to 'View Categories', categories_path, class: "btn btn-info" %> + <%= link_to 'View Your Bakes', user_products_path(@user), class: "btn btn-info" %> + <%= link_to 'List a New Bake', new_user_product_path(@user), class: "sell-link btn btn-info" %> | + <%= link_to 'View Categories', categories_path, class: "btn btn-info" %>
    @@ -84,19 +84,49 @@ <% if or_item.shipped %> - - <% else %> - + + <% elsif !or_item.shipped && or_item.order.status == "Paid"%> + + <%else %> + <% end %> - <% ord = Order.find(or_item.order.id) %> - <%# Order.check_order_status(ord) %> - + <% ord = Order.find(or_item.order.id) %> + <% end %> <% end %>
    <%= or_item.qty %> <%= format_price(product.price * or_item.qty) %>SHIPPED PAID - <%= link_to "CONFIRM SHIPPED", ship_item_path(product), class: "btn btn-outline-info btn-sm", method: :patch%>SHIPPED PAID + <%= link_to "CONFIRM SHIPPED", ship_item_path(product), class: "btn btn-outline-info btn-sm", method: :patch%> + PENDING PAYMENT<%= ord.status.upcase %>
    +

    REVENUE

    + + + + + + + + + + + <% sold = @user.find_orders %> + <% if sold.empty? %> + <%= "No Products Have Sold" %> + <% else %> + + + + + + + + + <% end %> + +
    PENDINGPAIDCANCELLEDCOMPLETETOTAL
    <%= @user.revenue("Pending") %> <%= @user.revenue("Paid") %> <%= @user.revenue("Complete") %> <%= @user.revenue("Cancelled") %> <%= @user.revenue("Total") %>
    + + <%# view order fulfillment%> <%= link_to 'Back', root_path %> diff --git a/config/routes.rb b/config/routes.rb index a548a01cac..cb2e43310d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,7 +29,8 @@ resources :users resources :users do - resources :products, only: [:index, :new, :show, :create, :update] + resources :products, only: [:index, :show, :new] + resources :orders, only: [:index, :show] end From 3e62221644e9232d083d6cc51a17fe1edfcec8ff Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 25 Oct 2018 01:17:31 -0700 Subject: [PATCH 155/192] added order id link for editing but links to order confirmation CC entry page instead of show page --- app/models/user.rb | 25 +++++++++++++------------ app/views/users/show.html.erb | 8 +++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6247a1afd7..2bdbe58a85 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -31,21 +31,22 @@ def find_orders def revenue(status_filter) - case status_filter - when "Pending" - rev = self.orders.where(status: "Pending").order_items.subtotal.sum - when "Paid" - rev = self.orders.where(status: "Paid").order_items.subtotal.sum - when "Completed" - rev = self.orders.where(status: "Complete").order_items.subtotal.sum - when "Cancelled" - rev = self.orders.where(status: "Cancelled").order_items.subtotal.sum - when "Total" - rev = self.orders.order_items.subtotal.sum - self.orders.where(status: "Cancelled").order_items.subtotal.sum + rev = 0 + if status_filter == "Total" + self.order_items.each do |item| + rev += item.subtotal + end + return rev + else + self.order_items.each do |item| + if item.order.status == status_filter + rev += item.subtotal + end + end end return rev end +end -end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 37b1c47d7c..907b22a9c1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -23,6 +23,8 @@ <%= link_to 'View Categories', categories_path, class: "btn btn-info" %> + +

    LISTED BAKES

    @@ -58,7 +60,7 @@ - +

    ORDER FULFILLMENT

    NAME
    @@ -78,7 +80,7 @@ <% sold.each do |product| %> <% or_item = OrderItem.find_by(product_id: product.id) %> - + @@ -105,8 +107,8 @@ - + From 798ff1d534a2b058771030d9dd5d9e78c213f2d6 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 25 Oct 2018 01:18:18 -0700 Subject: [PATCH 156/192] order show page add option to cancel order --- app/views/users/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 907b22a9c1..d6c2660896 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -80,7 +80,7 @@ <% sold.each do |product| %> <% or_item = OrderItem.find_by(product_id: product.id) %> - + From 3c3ae4a530e0b2a5943ef8e6e1b7bb381acab72b Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 25 Oct 2018 10:12:48 -0700 Subject: [PATCH 157/192] deactivate a product when product inv is less than 0 --- .DS_Store | Bin 6148 -> 6148 bytes app/models/order.rb | 3 +++ 2 files changed, 3 insertions(+) diff --git a/.DS_Store b/.DS_Store index 380ad3887f52be96eeef8b471abe2a5fb1326501..914ca6c5c45749cfb5b6298c5b50b46721f02f0a 100644 GIT binary patch delta 221 zcmZoMXfc=|#>B`mF;R?_gMono$Pkfb0y02=6^I!b7z7w{^7GOmYzF3uiOcIj5=;y! z3`u3dMR~}Q3?&S?3AjHu~68Qk%57Mi6Mm{sVulCFDE}Q9mofXfdCVP0`q}l0t_(u%@Y~R p*fuX Date: Thu, 25 Oct 2018 10:21:20 -0700 Subject: [PATCH 158/192] fixed bugs in order fulfillments, order status creation set to pending, fixed some format_price --- app/controllers/order_items_controller.rb | 4 +-- app/controllers/products_controller.rb | 20 ++---------- app/models/order.rb | 1 - app/models/user.rb | 13 ++++---- app/views/carts/show.html.erb | 2 +- app/views/orders/show.html.erb | 4 +-- app/views/users/show.html.erb | 39 +++++++++++------------ config/routes.rb | 2 +- 8 files changed, 34 insertions(+), 51 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 0636bb8371..9240bc59ab 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -10,13 +10,13 @@ def create redirect_to product_path(product.id) elsif @current_order.nil? @current_order = Order.new - # @current_order.save + @current_order.save end @order_item = @current_order.order_items.new(order_item_params) @order_item.save @current_order.save - + @current_order.update(status: "Pending") session[:order_id] = @current_order.id redirect_to cart_path(@current_order.id) # else diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 4c7ea03c9b..fd7a5d1c79 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -5,8 +5,7 @@ class ProductsController < ApplicationController # GET /products def index - # if user logged in then get just their products - if session[:user_id] + if params[:user_id] @products = @login_user.products else @products = Product.all @@ -17,23 +16,8 @@ def index # GET /products/1 def show - @product = Product.find(params[:id]) - # if @login_user - # @products = @login_user.products - # end - # - # if @current_order.order_items.find_by(product_id: params[:id]).nil? - # @order_item = OrderItem.new - # else - # @order_item = @current_order.order_items.find_by(product_id: params[:id]) - # end - # - # # setting up space, creating a blank row, not filling out - # if @order_item.nil? - # @order_item = current_order.order_items.new - # end - # @product = Product.find(params[:id]) + @order_item = OrderItem.new @reviews = Review.where(product_id: @product) end diff --git a/app/models/order.rb b/app/models/order.rb index a8e773e012..49225ead85 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -60,7 +60,6 @@ def check_order_status all_shipped = false end end - binding.pry if all_shipped @order.update(status: "Complete") end diff --git a/app/models/user.rb b/app/models/user.rb index 2bdbe58a85..5eec377eef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,15 +18,16 @@ def self.new_user(auth_hash) end - def find_orders - sold = [] + def find_ordered_items + ordered_items = [] self.products.each do |product| - if !product.order_items.empty? - sold << product + unless product.order_items.empty? + product.order_items.each do |ord_item| + ordered_items << ord_item + end end end - - return sold + return ordered_items end diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 2759bf18b6..522bc8d2f0 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -14,7 +14,7 @@ <% @order_items.each do |order_item| %> - + <%= form_with model: order_item do |f| %> - + <% end %> @@ -39,7 +39,7 @@

    Total Price: - $<%=@order.total_price %> + $<%=format_price(@order.total_price) %>

    <%#= link_to 'Edit', edit_order_path(@order) %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index d6c2660896..8afc4c7133 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -18,7 +18,7 @@
    - <%= link_to 'View Your Bakes', user_products_path(@user), class: "btn btn-info" %> + <%= link_to 'View Your Bakes', user_products_path(@user.id), class: "btn btn-info" %> <%= link_to 'List a New Bake', new_user_product_path(@user), class: "sell-link btn btn-info" %> | <%= link_to 'View Categories', categories_path, class: "btn btn-info" %>
    @@ -73,28 +73,27 @@ - <% sold = @user.find_orders %> - <% if sold.empty? %> + <% ordered_items = @user.find_ordered_items %> + <% if ordered_items.empty? %> <%= "No Products Have Sold" %> <% else %> - <% sold.each do |product| %> + <% ordered_items.each do |item| %> - <% or_item = OrderItem.find_by(product_id: product.id) %> - - - - - - <% if or_item.shipped %> + + + + + + <% if item.shipped %> - <% elsif !or_item.shipped && or_item.order.status == "Paid"%> + <% elsif !item.shipped && item.order.status == "Paid"%> <%else %> <% end %> - <% ord = Order.find(or_item.order.id) %> + <% ord = Order.find(item.order.id) %> <% end %> @@ -113,16 +112,16 @@ - <% sold = @user.find_orders %> + <% sold = @user.find_ordered_items %> <% if sold.empty? %> <%= "No Products Have Sold" %> <% else %> - - - - - + + + + + <% end %> diff --git a/config/routes.rb b/config/routes.rb index cb2e43310d..361dc74f77 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,7 +30,7 @@ resources :users do resources :products, only: [:index, :show, :new] - resources :orders, only: [:index, :show] + # resources :orders, only: [:index, :show] end From f5291eb14df11546bdf6b4be22e40d33284db5bf Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 25 Oct 2018 10:22:45 -0700 Subject: [PATCH 159/192] moved confirmation page to away from show page, and remove validation that prevents a inv qty to be less than 0 (we are making it inactive, when it is) --- app/controllers/orders_controller.rb | 4 +-- app/models/product.rb | 4 +-- app/views/orders/confirmation.html.erb | 43 ++++++++++++++++++++++++++ app/views/orders/show.html.erb | 42 ------------------------- 4 files changed, 47 insertions(+), 46 deletions(-) create mode 100644 app/views/orders/confirmation.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2a2e896ee8..4b2eeb5b69 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -9,7 +9,7 @@ def index @orders = Order.all end - def confirm_order + def confirmation end def show @@ -55,7 +55,7 @@ def update @current_order.place_order # decrease inventory and change status to paid # show confirmation page @order = @current_order # needed for rendering order information in show - render :show + render :confirmation session[:order_id] = nil end diff --git a/app/models/product.rb b/app/models/product.rb index 4802537ae9..3d1ea4b7a4 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -2,7 +2,7 @@ class Product < ApplicationRecord # validations validates :prod_name, presence: true, uniqueness: true validates :description, :price, presence: true - validates :inv_qty, presence: true, numericality: { only_integer: true, greater_than: -1} + validates :inv_qty, presence: true, numericality: { only_integer: true} # no need to validate inv_qty less than 0 because I am making it inactive # relationships belongs_to :user has_many :reviews @@ -45,4 +45,4 @@ def avg_rating return avg end end -end \ No newline at end of file +end diff --git a/app/views/orders/confirmation.html.erb b/app/views/orders/confirmation.html.erb new file mode 100644 index 0000000000..13401004a6 --- /dev/null +++ b/app/views/orders/confirmation.html.erb @@ -0,0 +1,43 @@ +

    <%= notice %>

    +

    Confirmation Page

    +
    ORDER #
    <%= or_item.order.id %> <%= link_to "#{or_item.order.id}", edit_order_path(or_item.order.id) %> <%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= or_item.qty %>
    PENDING PAIDCANCELLED COMPLETECANCELLED TOTAL
    <%= link_to "#{or_item.order.id}", edit_order_path(or_item.order.id) %> <%= link_to "#{or_item.order.id}", order_path(or_item.order.id) %> <%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= or_item.qty %>
    <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %><%= order_item.product.price %><%= format_price(order_item.product.price) %><%= f.select :qty, (1..order_item.product.inv_qty).to_a %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 31a19000a2..580aaec341 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -15,7 +15,7 @@
    <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %> <%= order_item.qty %>$<%= order_item.subtotal %>$<%= format_price(order_item.subtotal) %>
    <%= link_to "#{or_item.order.id}", order_path(or_item.order.id) %> <%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= or_item.qty %> <%= format_price(product.price * or_item.qty) %> <%= link_to "#{item.order.id}", order_path(item.order.id) %> <%= link_to "#{item.product.prod_name}", edit_product_path(item.product.id)%> <%= format_price(item.product.price)%> <%= item.qty %> <%= format_price(item.product.price * item.qty) %>SHIPPED PAID - <%= link_to "CONFIRM SHIPPED", ship_item_path(product), class: "btn btn-outline-info btn-sm", method: :patch%> + <%= link_to "CONFIRM SHIPPED", ship_item_path(item.product), class: "btn btn-outline-info btn-sm", method: :patch%> PENDING PAYMENT<%= ord.status.upcase %>
    <%= @user.revenue("Pending") %> <%= @user.revenue("Paid") %> <%= @user.revenue("Complete") %> <%= @user.revenue("Cancelled") %> <%= @user.revenue("Total") %> <%= format_price(@user.revenue("Pending")) %> <%= format_price(@user.revenue("Paid")) %> <%= format_price(@user.revenue("Complete"))%> <%= format_price(@user.revenue("Cancelled")) %> <%= format_price(@user.revenue("Total")) %>
    + + + + + + + + + <%# link_to 'Description', product_path(@order) %> + + <% @order.order_items.each do |order_item| %> + + + + + + <% end %> + + +
    ItemQuantitySubtotal
    <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %><%= order_item.qty %><%= format_price(order_item.subtotal) %>
    + +

    + Status: + <%= @order.status %> +

    + +

    + Date: + <%= @order.date_of_order %> +

    + +

    + Customer: + <%= @order.cust_name %> +

    + +

    + Total Price: + $<%=@order.total_price %> +

    diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 734b3c43ce..c79197e910 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,46 +1,4 @@ -

    <%= notice %>

    -

    Confirmation Page

    - - - - - - - - - - <%# link_to 'Description', product_path(@order) %> - - <% @order.order_items.each do |order_item| %> - - - - - - <% end %> - -
    ItemQuantitySubtotal
    <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %><%= order_item.qty %><%= format_price(order_item.subtotal) %>
    - -

    - Status: - <%= @order.status %> -

    - -

    - Date: - <%= @order.date_of_order %> -

    - -

    - Customer: - <%= @order.cust_name %> -

    - -

    - Total Price: - $<%=@order.total_price %> -

    <%#= link_to 'Edit', edit_order_path(@order) %> <%#= link_to 'Back', orders_path %> From 49afecf64fe0d86e4dc70445ef8d835a24144588 Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 25 Oct 2018 13:11:19 -0700 Subject: [PATCH 160/192] controller product testing in progress --- app/assets/stylesheets/orders.scss | 44 ++++++ app/controllers/products_controller.rb | 9 +- app/models/product.rb | 2 +- app/views/layouts/application.html.erb | 2 + app/views/orders/_form.html.erb | 149 +++++++++++++------ test/controllers/products_controller_test.rb | 65 ++++++++ test/fixtures/products.yml | 2 +- 7 files changed, 226 insertions(+), 47 deletions(-) diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss index 3b0428a94e..2165eb0ca0 100644 --- a/app/assets/stylesheets/orders.scss +++ b/app/assets/stylesheets/orders.scss @@ -1,3 +1,47 @@ // 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/ +/* Padding - just for asthetics on Bootsnipp.com */ +// body { margin-top:20px; } + +/* CSS for Credit Card Payment form */ +.credit-card-box .panel-title { + display: inline; + font-weight: bold; +} +.credit-card-box .form-control.error { + border-color: red; + outline: 0; + box-shadow: inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(255,0,0,0.6); +} +.credit-card-box label.error { + font-weight: bold; + color: red; + padding: 2px 8px; + margin-top: 2px; +} +.credit-card-box .payment-errors { + font-weight: bold; + color: red; + padding: 2px 8px; + margin-top: 2px; +} +.credit-card-box label { + display: block; +} +/* The old "center div vertically" hack */ +.credit-card-box .display-table { + display: table; +} +.credit-card-box .display-tr { + display: table-row; +} +.credit-card-box .display-td { + display: table-cell; + vertical-align: middle; + width: 50%; +} +/* Just looks nicer */ +.credit-card-box .panel-heading img { + min-width: 180px; +} diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 24e5b56263..daeb3d4ed3 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -80,6 +80,10 @@ def destroy def category @category = Category.find_by(id: params[:id]) + if @category.nil? + flash[:warning] = "Category is invalid" + redirect_to root_path + end @products = Product.by_category(params[:id]) end @@ -99,8 +103,11 @@ def status def merchant @user = User.find_by(id: params[:id]) + if @user.nil? + flash[:warning] = "User is invalid" + redirect_to root_path + end @products = Product.by_merchant(params[:id].to_i) - end private diff --git a/app/models/product.rb b/app/models/product.rb index 4802537ae9..507108ff04 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -45,4 +45,4 @@ def avg_rating return avg end end -end \ No newline at end of file +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9c739ab4e5..eed06e3120 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,8 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 9fec032f37..c4cdf7a499 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -1,50 +1,111 @@ <%= form_with(model: order, local: true) do |form| %> <%# render partial "/layouts/form_errors", locals: { error_hash: order}%> + + -
    - <%= form.label "Name" %> - <%= form.text_field :cust_name, class: "form-control" %> -
    - -
    - <%= form.label "Email" %> - <%= form.text_field :cust_email, class: "form-control" %> -
    - -
    - <%= form.label :mailing_address %> - <%= form.text_field :mailing_address, class: "form-control" %> -
    - -
    - <%= form.label "Name on Card" %> - <%= form.text_field :cc_name, class: "form-control" %> -
    - -
    - <%= form.label "Credit Card Number" %> - <%= form.number_field :cc_digit, class: "form-control", maxlength: "16"%> -
    - -
    - <%= form.label "Expiration Date" %> - <%= form.date_select :cc_expiration, class: "form-control" %> -
    - -
    - <%= form.label "CVV" %> - <%= form.number_field :cc_cvv, class: "form-control" %> -
    - -
    - <%= form.label "Zip Code" %> - <%= form.number_field :cc_zip, class: "form-control" %> -
    - -
    - <%= form.submit class: "btn btn-primary" %> -
    -<% end %> +
    +
    + +
    + + + +
    +
    +
    +

    Payment Details

    +
    + +
    +
    +
    +
    +
    +
    +
    +
    + <%= form.label "NAME ON CARD" %> + <%= form.text_field :cc_name, class: "form-control" %> +
    +
    +
    +
    +
    +
    + <%= form.label "CREDIT CARD NUMBER" %> +
    + <%= form.number_field :cc_digit, class: "form-control", maxlength: "16", for:"cardExpiry"%> + +
    +
    +
    +
    +
    +
    +
    + <%= form.label "Expiration Date" %> + <%= form.date_select :cc_expiration, class: "form-control" %> +
    +
    +
    +
    + <%= form.label "CVV", for: "cardCVC" %> + <%= form.number_field :cc_cvv, class: "form-control" %> +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    + <%= form.submit class: "btn btn-primary" %> +
    +
    + +
    +
    +
    + + + +
    + +
    +
    + <%= form.label "Name" %> + <%= form.text_field :cust_name, class: "form-control" %> +
    +
    + <%= form.label "Email" %> + <%= form.text_field :cust_email, class: "form-control" %> +
    + +
    + <%= form.label :mailing_address %> + <%= form.text_field :mailing_address, class: "form-control" %> +
    + +
    + <%= form.label "Zip Code" %> + <%= form.number_field :cc_zip, class: "form-control" %> +
    + +
    + +
    +
    +<% end %> diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index dd9fa74552..aa70531541 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -195,6 +195,71 @@ end end +describe "category" do + + it "finds a category for product" do + id = Category.first.id + + get category_path(id) + + value(response).must_be :successful? + end + + it "redirects to root_path for invalid category" do + id = 56 + + get category_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "Category is invalid" + end + +end + +describe "category" do + + it "finds a category for product" do + id = Category.first.id + + get category_path(id) + + value(response).must_be :successful? + end + + it "redirects to root_path for invalid category" do + id = 56 + + get category_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "Category is invalid" + end + +end + +describe "mechant" do + + it "finds a merchant for a product" do + id = User.first.id + + get merchant_path(id) + + value(response).must_be :successful? + end + + it "redirects to root_path for invalid category" do + id = -56 + + get merchant_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "User is invalid" + end + +end # describe "destroy" do # # it "can destroy a product with a logged in merchant" do diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 81f7140f1e..17f4f88cb3 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -18,8 +18,8 @@ cake2: cake3: - prod_name: vanilla plains description: real vanilla price: 20.5 inv_qty: 3 + user: ada From 70ec391e7a568cb5cf03774d715c64b92a0386ec Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 25 Oct 2018 13:48:54 -0700 Subject: [PATCH 161/192] product test complete --- test/controllers/products_controller_test.rb | 142 ++++++++++--------- 1 file changed, 73 insertions(+), 69 deletions(-) diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index aa70531541..ffe6ae37f8 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -195,97 +195,101 @@ end end -describe "category" do + describe "category" do - it "finds a category for product" do - id = Category.first.id + it "finds a category for product" do + id = Category.first.id - get category_path(id) + get category_path(id) - value(response).must_be :successful? - end + value(response).must_be :successful? + end - it "redirects to root_path for invalid category" do - id = 56 + it "redirects to root_path for invalid category" do + id = 56 - get category_path(id) + get category_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "Category is invalid" + end - # value(response).must_be :successful? - must_redirect_to root_path - expect(flash[:warning]).must_equal "Category is invalid" end -end + describe "category" do -describe "category" do + it "finds a category for product" do + id = Category.first.id - it "finds a category for product" do - id = Category.first.id + get category_path(id) - get category_path(id) + value(response).must_be :successful? + end - value(response).must_be :successful? - end + describe "category" do - it "redirects to root_path for invalid category" do - id = 56 + it "finds a category for product" do + id = Category.first.id - get category_path(id) + get category_path(id) - # value(response).must_be :successful? - must_redirect_to root_path - expect(flash[:warning]).must_equal "Category is invalid" - end + value(response).must_be :successful? + end -end + it "redirects to root_path for invalid category" do + id = 56 -describe "mechant" do + get category_path(id) - it "finds a merchant for a product" do - id = User.first.id + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "Category is invalid" + end - get merchant_path(id) + end - value(response).must_be :successful? - end + describe "merchant" do - it "redirects to root_path for invalid category" do - id = -56 + it "finds a merchant for a product" do + id = User.first.id - get merchant_path(id) + get merchant_path(id) - # value(response).must_be :successful? - must_redirect_to root_path - expect(flash[:warning]).must_equal "User is invalid" - end + value(response).must_be :successful? + end -end - # describe "destroy" do - # - # it "can destroy a product with a logged in merchant" do - # user = users(:laura) - # perform_login(user) - # - # id = products(:cake1).id - # - # expect { - # delete product_path(id) - # }.must_change 'Product.count', -1 - # - # must_respond_with :redirect - # expect(Product.find_by(id: id)).must_equal nil - # end - # - # end - - # it "can destroy a book given a vlid id" do - # id = -1 - # - # expect { - # delete book_path(id) - # }.wont_change 'Book.count' - # - # must_respond_with :not_found - # expect(flash[:danger]).must_equal "Cannot find the book #{id}" - # end + it "redirects to root_path for invalid category" do + id = -56 + + get merchant_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "User is invalid" + end + + end + + describe "status" do + + it "finds a merchant for a product" do + id = Product.first.id + + patch product_status_path(id) + + must_respond_with :redirect + end + + it "redirects to root_path for invalid category" do + id = -56 + + patch product_status_path(id) + + # value(response).must_be :successful? + must_respond_with :not_found + end + + end + end end From bd94dd8e32bd4b4f8545e47e0409fa4d7a2be60f Mon Sep 17 00:00:00 2001 From: Trang Date: Thu, 25 Oct 2018 13:50:41 -0700 Subject: [PATCH 162/192] add search order button --- app/controllers/orders_controller.rb | 18 ++++++++-- app/controllers/users_controller.rb | 4 +-- app/models/order_item.rb | 2 +- app/views/layouts/application.html.erb | 7 +++- app/views/orders/index.html.erb | 49 ++++++++++---------------- app/views/orders/not_found.html.erb | 3 ++ test/models/order_item_test.rb | 19 ++++++++++ 7 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 app/views/orders/not_found.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 2a2e896ee8..d598172476 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,18 +1,30 @@ require 'pry' class OrdersController < ApplicationController skip_before_action :require_login - before_action :set_order, only: [:show, :edit, :update, :destroy] + before_action :set_order, only: [:edit, :update, :destroy] # before_action :check_status, only: [:show] # GET /orders def index - @orders = Order.all + @order = Order.find_by(id: params[:id].to_i) + @order_items = @order.order_items + + if @order.nil? + flash.now[:danger] = "Cannot find the order #{params[:id]}" + render :not_found, status: :not_found + end end def confirm_order end def show + @order = Order.find_by(id: params[:id].to_i) + + if @order.nil? + flash.now[:danger] = "Cannot find the order #{params[:id]}" + render :not_found, status: :not_found + end # show view used when calling rendering in update - do not remove html show page end @@ -79,7 +91,7 @@ def set_order # Never trust parameters from the scary internet, only allow the white list through. def order_params - params.require(:order).permit(:status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) + params.require(:order).permit(:id, :status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) end def check_status diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b53dc9c02e..7b59151ded 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,8 +6,8 @@ class UsersController < ApplicationController def show render_404 unless @user - @order = current_order - @order_item = @order.order_items.find_by(product_id: params[:id]) + # @order = current_order + @order_item = @current_order.order_items.find_by(product_id: params[:id]) if @order_item.nil? @order_item = current_order.order_items.new diff --git a/app/models/order_item.rb b/app/models/order_item.rb index ae6d3d4fd5..a690f97f3b 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,5 +1,5 @@ class OrderItem < ApplicationRecord - validates :qty, presence: true, numericality: { only_integer: true } + validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 } belongs_to :product belongs_to :order diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index caa00533be..213bfc030b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -119,7 +119,12 @@ <%= link_to "Shopping Cart", new_cart_path %> <% end %> -
  • Order Status
  • +
  • <%= form_tag(orders_path, method: :get) do %> + + <%= text_field_tag :id, params[:id], placeholder: "Order ID" %> + <%= submit_tag("Order Details", name: nil) %> + <% end %> +
  • diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb index 1812dcc922..e4f20c0fd5 100644 --- a/app/views/orders/index.html.erb +++ b/app/views/orders/index.html.erb @@ -1,43 +1,30 @@

    <%= notice %>

    -

    Orders

    +

    Order #<%=@order.id %> Details

    - +
    + + + + - - - - - - - - - - - <% @orders.each do |order| %> - - - - - - - - - - - - - - + <% @order_items.each do |order_item| %> + + + + + + <% if order_item.subtotal == true %> + + <% else %> + + <% end %> + <% end %>
    ItemPriceQuantitySubtotal StatusCust nameCust emailMailing addressCc nameCc digitCc expirationCc cvvCc zip
    <%= order.status %><%= order.cust_name %><%= order.cust_email %><%= order.mailing_address %><%= order.cc_name %><%= order.cc_digit %><%= order.cc_expiration %><%= order.cc_cvv %><%= order.cc_zip %><%= link_to 'Show', order %><%= link_to 'Edit', edit_order_path(order) %><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %>
    <%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %><%= order_item.product.price %><%= order_item.qty %><%= order_item.subtotal %>ShippedPending
    - -
    - -<%= link_to 'New Order', new_order_path %> diff --git a/app/views/orders/not_found.html.erb b/app/views/orders/not_found.html.erb new file mode 100644 index 0000000000..6156bba9d2 --- /dev/null +++ b/app/views/orders/not_found.html.erb @@ -0,0 +1,3 @@ +
    +

    404 Not Found

    +
    diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb index 8fa0c99140..3f69f96891 100644 --- a/test/models/order_item_test.rb +++ b/test/models/order_item_test.rb @@ -37,6 +37,25 @@ expect(valid).must_equal false expect(order_item.errors.messages).must_include :qty end + + it 'must have a quantity greater than 0' do + order_item.qty = 0 + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :qty + end + + it 'must have a quantity that is an integer' do + order_item.qty = 1.5 + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :qty + end + end describe 'subtotal' do From a42b73d44bec6ae1217c3767d2b877b2c80a6a2a Mon Sep 17 00:00:00 2001 From: Laura Date: Thu, 25 Oct 2018 14:19:36 -0700 Subject: [PATCH 163/192] do not let user save an order with invalid personal information --- app/controllers/orders_controller.rb | 15 +++++++++++---- app/models/order.rb | 14 +++++++------- app/views/layouts/application.html.erb | 14 ++++++++++++++ app/views/orders/_form.html.erb | 2 +- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 4b2eeb5b69..b71178b4a2 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -50,14 +50,21 @@ def update if @current_order.order_items.nil? flash[:warning] = "You have zero items in your cart" redirect_to products_path - else - @current_order.update(order_params) + elsif @current_order.update(order_params) + flash.now[:success] = "Order was accepted" @current_order.place_order # decrease inventory and change status to paid + @current_order.save # show confirmation page - @order = @current_order # needed for rendering order information in show + @order = @current_order # needed for rendering order information in confirmation page render :confirmation session[:order_id] = nil - + else + binding.pry + flash.now[:warning] = 'Order was not not created' + @current_order.errors.messages.each do |field, msg| + flash.now[field] = msg + end + render :edit end end diff --git a/app/models/order.rb b/app/models/order.rb index 2a4767cc21..af5ee560b3 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,12 +1,12 @@ class Order < ApplicationRecord #validations - validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :place_order - validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, maxlength: 16 }, on: :place_order - validates :cc_expiration, presence: true, on: :place_order - validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :place_order - validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :place_order - validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :place_order - validates :mailing_address, presence: true, on: :place_order + validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :update + validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, maxlength: 16 }, on: :update + validates :cc_expiration, presence: true, on: :update + validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :update + validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :update + validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :update + validates :mailing_address, presence: true, on: :update #relationships has_many :order_items diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9c739ab4e5..b8014b808e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -67,6 +67,20 @@ +
    + <% flash.each do |name, message| %> + <% if message.class == Array %> + <% message.each do |msg| %> +
    + <%= "#{name}:" %><%= " #{msg}" %>
    + <% end %> + <% else %> +
    + <%= message %> +
    + <% end %> + <% end %> +
    <%= yield %> diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb index 1a7fa80f16..0534698e84 100644 --- a/app/views/orders/_form.html.erb +++ b/app/views/orders/_form.html.erb @@ -1,5 +1,5 @@ <%= form_with(model: order, local: true) do |form| %> - <%# render partial "/layouts/form_errors", locals: { error_hash: order}%> + <%# render partial "/layouts/form_errors", locals: { error_hash: @order}%>
    From c3d0e4c098453db6eb2b6151dbcf921ce4cd54a9 Mon Sep 17 00:00:00 2001 From: xLJohnsonx Date: Thu, 25 Oct 2018 14:57:34 -0700 Subject: [PATCH 164/192] removed binding --- app/controllers/orders_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index e747c5d0d0..abb04788de 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -59,7 +59,6 @@ def update render :confirmation session[:order_id] = nil else - binding.pry flash.now[:warning] = 'Order was not not created' @current_order.errors.messages.each do |field, msg| flash.now[field] = msg From 701af127728f601dc182b6e37fb1796000266809 Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 25 Oct 2018 14:58:34 -0700 Subject: [PATCH 165/192] order controller test --- test/controllers/orders_controller_test.rb | 66 +++++++++++++++------- test/fixtures/order_items.yml | 2 +- test/fixtures/orders.yml | 20 +++---- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 80c13241dc..4952e16f33 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -5,42 +5,66 @@ it "gets index" do get orders_url - value(response).must_be :success? + + value(response).must_be :successful? end it "gets new" do get new_order_url - value(response).must_be :success? + + value(response).must_be :successful? end - it "creates order" do - expect { - post orders_url, params: { order: { cc_cvv: order.cc_cvv, cc_digit: order.cc_digit, cc_expiration: order.cc_expiration, cc_name: order.cc_name, cc_zip: order.cc_zip, cust_email: order.cust_email, cust_name: order.cust_name, mailing_address: order.mailing_address, status: order.status } } - }.must_change "Order.count" + # it "creates order" do + # expect { + # post orders_url, params: { order: { cc_cvv: order.cc_cvv, cc_digit: order.cc_digit, cc_expiration: order.cc_expiration, cc_name: order.cc_name, cc_zip: order.cc_zip, cust_email: order.cust_email, cust_name: order.cust_name, mailing_address: order.mailing_address, status: order.status } } + # }.must_change "Order.count" + # + # must_redirect_to order_path(Order.last) + # end +describe "show" do - must_redirect_to order_path(Order.last) - end + it "it shows an order for that merchant" do + user = users(:laura) + perform_login(user) + + id = orders(:one).id - it "shows order" do - get order_url(order) - value(response).must_be :success? + get orders_path(id) + + value(response).must_be :successful? end - it "gets edit" do - get edit_order_url(order) - value(response).must_be :success? + it "will not allow another merchant to view an order without their product" do + user = users(:laura) + perform_login(user) + + id = orders(:two).id + + get orders_path(id) + + value(response).must_be :successful? end +end + # + # it "gets edit" do + # get edit_order_url(order) + # value(response).must_be :successful? + # end + + +#placing the order we use update it "updates order" do patch order_url(order), params: { order: { cc_cvv: order.cc_cvv, cc_digit: order.cc_digit, cc_expiration: order.cc_expiration, cc_name: order.cc_name, cc_zip: order.cc_zip, cust_email: order.cust_email, cust_name: order.cust_name, mailing_address: order.mailing_address, status: order.status } } must_redirect_to order_path(order) end - it "destroys order" do - expect { - delete order_url(order) - }.must_change "Order.count", -1 - - must_redirect_to orders_path - end + # it "destroys order" do + # expect { + # delete order_url(order) + # }.must_change "Order.count", -1 + # + # must_redirect_to orders_path + # end end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml index 4787440708..d78a92642c 100644 --- a/test/fixtures/order_items.yml +++ b/test/fixtures/order_items.yml @@ -7,7 +7,7 @@ line1: shipped: false line2: - order: one + order: two product: cake2 qty: 2 shipped: false diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index e2b00532c2..ca74193fd9 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -4,20 +4,20 @@ one: status: pending cust_name: Laura cust_email: laura@gmail.com - mailing_address: 1 - cc_name: MyString + mailing_address: 123 Front St. + cc_name: Laura Liz cc_digit: 1111111111111111 cc_expiration: 2018-10-17 cc_cvv: 123 cc_zip: 98765 two: - status: MyString - cust_name: MyString - cust_email: MyString - mailing_address: 1 - cc_name: MyString - cc_digit: 1 + status: pending + cust_name: Grace + cust_email: grace@gmail.com + mailing_address: 123 Front St. + cc_name: Laura Liz + cc_digit: 1111111111111111 cc_expiration: 2018-10-17 - cc_cvv: 1 - cc_zip: 1 + cc_cvv: 123 + cc_zip: 98765 From 95f6fd67866a3eacd5bd9e046f3920e0c03efb2b Mon Sep 17 00:00:00 2001 From: Jazz Date: Thu, 25 Oct 2018 15:55:20 -0700 Subject: [PATCH 166/192] fix test errors to product controller. --- test/controllers/products_controller_test.rb | 38 ++------------------ test/fixtures/products.yml | 1 + 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index ffe6ae37f8..91296cd3cd 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -41,7 +41,7 @@ }.must_change "Product.count" must_redirect_to user_path(session[:user_id]) - expect(flash[:notice]).must_equal "#{product.prod_name} was successfully created." + expect(flash[:notice]).must_equal "#{product.prod_name} was added to your inventory." end it "is an forbidden request if user is not logged in" do @@ -197,38 +197,6 @@ describe "category" do - it "finds a category for product" do - id = Category.first.id - - get category_path(id) - - value(response).must_be :successful? - end - - it "redirects to root_path for invalid category" do - id = 56 - - get category_path(id) - - # value(response).must_be :successful? - must_redirect_to root_path - expect(flash[:warning]).must_equal "Category is invalid" - end - - end - - describe "category" do - - it "finds a category for product" do - id = Category.first.id - - get category_path(id) - - value(response).must_be :successful? - end - - describe "category" do - it "finds a category for product" do id = Category.first.id @@ -246,9 +214,9 @@ must_redirect_to root_path expect(flash[:warning]).must_equal "Category is invalid" end - end + describe "merchant" do it "finds a merchant for a product" do @@ -291,5 +259,5 @@ end end - end + end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index fc7d954175..88a704fa9a 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -22,6 +22,7 @@ cake3: description: real vanilla price: 20.5 inv_qty: 3 + user: grace brownie: prod_name: chocolate brownie From 2fd3da872598662f938217f1766e1e6712015b21 Mon Sep 17 00:00:00 2001 From: Trang Date: Thu, 25 Oct 2018 15:55:31 -0700 Subject: [PATCH 167/192] seed reset --- app/assets/stylesheets/application.scss | 29 ++++++-- app/assets/stylesheets/products.scss | 3 - app/views/layouts/application.html.erb | 73 +++++++++---------- db/category_seeds.csv | 8 +- ...0181025223530_remove_order_status_table.rb | 5 ++ db/order_seeds.csv | 9 --- db/product_seeds.csv | 68 +---------------- db/review_seeds.csv | 14 +--- db/seeds.rb | 2 +- db/user_seeds.csv | 6 +- 10 files changed, 72 insertions(+), 145 deletions(-) create mode 100644 db/migrate/20181025223530_remove_order_status_table.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index e49b84b1bf..ace801f728 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,11 +19,6 @@ -body { - padding-bottom: 20px; - margin-bottom: 60px; -} - h1, h2, h3, h4 { font-family: 'Alegreya Sans SC', sans-serif; } @@ -49,6 +44,15 @@ p { font-weight: bold; } +.nav-link { + color: lightgray; + line-height: 12px; +} + +.nav-link:hover { + color: white !important; +} + .right-items { height: 40px; } @@ -192,10 +196,21 @@ p { color: #8ff9f6 !important; } -.footer-copyright > a { - color:white; +.footer-copyright p { + color: lightgray; +} +.footer-copyright a { + font-family: 'Alegreya Sans SC', sans-serif; + font-size: 16px; + color: #8ff9f6; + text-decoration: none; } + +.footer-copyright a:hover { + color: white; +} + #fotp { color: white; } diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index b06d01fc37..64d292cd96 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -4,9 +4,6 @@ // // Base styles -.products { - padding-bottom: 1rem; -} .category { object-position: center; /* Center the image within the element */ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 213bfc030b..079682ee16 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -68,11 +68,13 @@
    - + - <%= yield %> +
    + <%= yield %> +
    @@ -102,30 +104,16 @@
    -
      -
    • - <%= link_to "Home", root_path%> -
    • -
    • - <%= link_to "All Products", products_path %> -
    • -
    • - <%= link_to "Login with Github", "/auth/github" %> -
    • -
    • +
    • -
    • <%= form_tag(orders_path, method: :get) do %> - - <%= text_field_tag :id, params[:id], placeholder: "Order ID" %> - <%= submit_tag("Order Details", name: nil) %> - <% end %> -
    • -
    +
    @@ -136,24 +124,29 @@
    -
      -
    • +
    • -
    • + +
    + @@ -165,8 +158,8 @@ -