From ff06da2502258f9cdcb65fa8a3ad494ec112ad21 Mon Sep 17 00:00:00 2001 From: jackie Date: Wed, 17 Oct 2018 09:58:34 -0700 Subject: [PATCH 001/196] Initial 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 | 25 ++ tmp/.keep | 0 vendor/.keep | 0 80 files changed, 1407 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..51100b2a1d --- /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.2 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..3285252ed0 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +GXWq0KkwTw898gFPOUhWWvmu8GDv6fSl3vFgVmg/ryWeXcaOSvKT7Q5lJZBgnlED0XJTzLQxDk0+yRVsnnZfFQwAWidUpLTAzqS++CXuydWMSu1F7tWCSSSyVXqCHLTStG0pSZ+gTCd+Ephw4fEdIBOF8tt96n52U17KYeJ5oKBeWHkywhepuqBox5EA0aNOjqoDq3f2h7LrVcWwHK/9ZOSCqTwQvopuLpWG4mcmFsuJt5VCq0hRqwdq8caOT3RDKGG0ezVNF6kHmBsbn1Im+yHdVpzea1vv6FzJdT4xauoji2hB6xmei+cm8CFVfPt55PPoi4zZbuzctz0ZCRqlAhCwBPJ+5ZlP0eJQ4Rgr/usaTNTSsZ2t7jmrH4DgeV+E2gt/azZ95HEznF8sOZEXcwFt7FRx5GJdGOPZ--S1T1MFF4YoXwPmXG--g+7+Or7izUAf4ur433chfA== \ 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..fb7dd505e2 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,25 @@ +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 709852159366876a0fea32c4dba95b0cc594c4f8 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 14:20:17 -0700 Subject: [PATCH 002/196] user model and users controller and views pages finished --- app/assets/javascripts/user.js | 2 ++ app/assets/stylesheets/user.scss | 3 ++ app/controllers/user_controller.rb | 23 +++++++++++++ app/helpers/user_helper.rb | 2 ++ app/models/buyer.rb | 2 ++ app/models/user.rb | 2 ++ app/views/user/destroy.html.erb | 2 ++ app/views/user/edit.html.erb | 2 ++ app/views/user/index.html.erb | 2 ++ app/views/user/new.html.erb | 2 ++ app/views/user/show.html.erb | 2 ++ app/views/user/update.html.erb | 2 ++ config/routes.rb | 7 ++++ db/migrate/20181017210800_create_users.rb | 8 +++++ db/migrate/20181017210816_create_buyers.rb | 8 +++++ test/controllers/user_controller_test.rb | 39 ++++++++++++++++++++++ test/fixtures/buyers.yml | 11 ++++++ test/fixtures/users.yml | 11 ++++++ test/models/buyer_test.rb | 9 +++++ test/models/user_test.rb | 9 +++++ 20 files changed, 148 insertions(+) create mode 100644 app/assets/javascripts/user.js create mode 100644 app/assets/stylesheets/user.scss create mode 100644 app/controllers/user_controller.rb create mode 100644 app/helpers/user_helper.rb create mode 100644 app/models/buyer.rb create mode 100644 app/models/user.rb create mode 100644 app/views/user/destroy.html.erb create mode 100644 app/views/user/edit.html.erb create mode 100644 app/views/user/index.html.erb create mode 100644 app/views/user/new.html.erb create mode 100644 app/views/user/show.html.erb create mode 100644 app/views/user/update.html.erb create mode 100644 db/migrate/20181017210800_create_users.rb create mode 100644 db/migrate/20181017210816_create_buyers.rb create mode 100644 test/controllers/user_controller_test.rb create mode 100644 test/fixtures/buyers.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/buyer_test.rb create mode 100644 test/models/user_test.rb diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/user.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/user.scss b/app/assets/stylesheets/user.scss new file mode 100644 index 0000000000..c47a13e0c4 --- /dev/null +++ b/app/assets/stylesheets/user.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the User 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/user_controller.rb b/app/controllers/user_controller.rb new file mode 100644 index 0000000000..ef8c82517d --- /dev/null +++ b/app/controllers/user_controller.rb @@ -0,0 +1,23 @@ +class UserController < ApplicationController + def index + + end + + def new + end + + def show + end + + def update + end + + def destroy + end + + def edit + end + + def create + end +end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 0000000000..0147c3fe6a --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +end diff --git a/app/models/buyer.rb b/app/models/buyer.rb new file mode 100644 index 0000000000..7f39d8f26a --- /dev/null +++ b/app/models/buyer.rb @@ -0,0 +1,2 @@ +class Buyer < User +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/user/destroy.html.erb b/app/views/user/destroy.html.erb new file mode 100644 index 0000000000..a328fb9b19 --- /dev/null +++ b/app/views/user/destroy.html.erb @@ -0,0 +1,2 @@ +

User#destroy

+

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

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

User#edit

+

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

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

User#index

+

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

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

User#new

+

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

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

User#show

+

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

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

User#update

+

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

diff --git a/config/routes.rb b/config/routes.rb index 787824f888..06f822b06b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,10 @@ Rails.application.routes.draw do + get 'user/index' + get 'user/new' + get 'user/show' + get 'user/update' + get 'user/destroy' + get 'user/edit' + get 'user/create' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20181017210800_create_users.rb b/db/migrate/20181017210800_create_users.rb new file mode 100644 index 0000000000..8006900e1a --- /dev/null +++ b/db/migrate/20181017210800_create_users.rb @@ -0,0 +1,8 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20181017210816_create_buyers.rb b/db/migrate/20181017210816_create_buyers.rb new file mode 100644 index 0000000000..cc419b7c8c --- /dev/null +++ b/db/migrate/20181017210816_create_buyers.rb @@ -0,0 +1,8 @@ +class CreateBuyers < ActiveRecord::Migration[5.2] + def change + create_table :buyers do |t| + + t.timestamps + end + end +end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb new file mode 100644 index 0000000000..9f2950cc46 --- /dev/null +++ b/test/controllers/user_controller_test.rb @@ -0,0 +1,39 @@ +require "test_helper" + +describe UserController do + it "should get index" do + get user_index_url + value(response).must_be :success? + end + + it "should get new" do + get user_new_url + value(response).must_be :success? + end + + it "should get show" do + get user_show_url + value(response).must_be :success? + end + + it "should get update" do + get user_update_url + value(response).must_be :success? + end + + it "should get destroy" do + get user_destroy_url + value(response).must_be :success? + end + + it "should get edit" do + get user_edit_url + value(response).must_be :success? + end + + it "should get create" do + get user_create_url + value(response).must_be :success? + end + +end diff --git a/test/fixtures/buyers.yml b/test/fixtures/buyers.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/buyers.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/buyer_test.rb b/test/models/buyer_test.rb new file mode 100644 index 0000000000..4dc3a78236 --- /dev/null +++ b/test/models/buyer_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Buyer do + let(:buyer) { Buyer.new } + + it "must be valid" do + value(buyer).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 b72e1a2a502d74be3240658b9e6b075a71ab878e Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Wed, 17 Oct 2018 14:28:58 -0700 Subject: [PATCH 003/196] created controller and model for Product --- app/assets/javascripts/products.js | 2 + app/assets/stylesheets/products.scss | 3 ++ app/controllers/products_controller.rb | 2 + app/helpers/products_helper.rb | 2 + app/models/product.rb | 3 ++ db/migrate/20181017212743_create_products.rb | 15 +++++++ db/schema.rb | 42 ++++++++++++++++++++ test/controllers/products_controller_test.rb | 7 ++++ test/fixtures/products.yml | 19 +++++++++ test/models/product_test.rb | 9 +++++ 10 files changed, 104 insertions(+) create mode 100644 app/assets/javascripts/products.js create mode 100644 app/assets/stylesheets/products.scss create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/models/product.rb create mode 100644 db/migrate/20181017212743_create_products.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/products_controller_test.rb create mode 100644 test/fixtures/products.yml create mode 100644 test/models/product_test.rb diff --git a/app/assets/javascripts/products.js b/app/assets/javascripts/products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..bff386e55a --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..f1ad12ddea --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,2 @@ +class ProductsController < ApplicationController +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/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..2f2fb1bdeb --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,3 @@ +class Product < ApplicationRecord + belongs_to :user +end diff --git a/db/migrate/20181017212743_create_products.rb b/db/migrate/20181017212743_create_products.rb new file mode 100644 index 0000000000..ff23b568b3 --- /dev/null +++ b/db/migrate/20181017212743_create_products.rb @@ -0,0 +1,15 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.references :user, foreign_key: true + t.string :name + t.float :price + t.string :category + t.string :description + t.integer :stock + t.string :photo_url + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..bec8f276db --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,42 @@ +# 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_212743) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "buyers", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "products", force: :cascade do |t| + t.bigint "user_id" + t.string "name" + t.float "price" + t.string "category" + t.string "description" + t.integer "stock" + t.string "photo_url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_products_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_foreign_key "products", "users" +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..392a20e292 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ProductsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..845183c94e --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user: one + name: MyString + price: 1.5 + category: MyString + description: MyString + stock: 1 + photo_url: MyString + +two: + user: two + name: MyString + price: 1.5 + category: MyString + description: MyString + stock: 1 + photo_url: MyString diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..a618b0a156 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Product do + let(:product) { Product.new } + + it "must be valid" do + value(product).must_be :valid? + end +end From f13a500703088495905b0d12674940de7385986f Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 14:33:38 -0700 Subject: [PATCH 004/196] renamed table/model from buyers to merchant (oops) --- app/controllers/user_controller.rb | 11 ++++++-- app/models/buyer.rb | 2 -- app/models/merchant.rb | 2 ++ ...20181017213055_rename_buyer_to_merchant.rb | 5 ++++ db/schema.rb | 28 +++++++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) delete mode 100644 app/models/buyer.rb create mode 100644 app/models/merchant.rb create mode 100644 db/migrate/20181017213055_rename_buyer_to_merchant.rb create mode 100644 db/schema.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index ef8c82517d..547137459b 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,9 +1,13 @@ class UserController < ApplicationController def index - + @users = User.all end def new + @user = User.new + end + + def create end def show @@ -18,6 +22,9 @@ def destroy def edit end - def create + private + + def user_params + return params.require(:user).permit(:name, :address, :email, :cc_num, :merchant_id) end end diff --git a/app/models/buyer.rb b/app/models/buyer.rb deleted file mode 100644 index 7f39d8f26a..0000000000 --- a/app/models/buyer.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Buyer < User -end diff --git a/app/models/merchant.rb b/app/models/merchant.rb new file mode 100644 index 0000000000..c2a004ff6f --- /dev/null +++ b/app/models/merchant.rb @@ -0,0 +1,2 @@ +class Merchant < User +end diff --git a/db/migrate/20181017213055_rename_buyer_to_merchant.rb b/db/migrate/20181017213055_rename_buyer_to_merchant.rb new file mode 100644 index 0000000000..0417e4b036 --- /dev/null +++ b/db/migrate/20181017213055_rename_buyer_to_merchant.rb @@ -0,0 +1,5 @@ +class RenameBuyerToMerchant < ActiveRecord::Migration[5.2] + def change + rename_table :buyers, :merchants + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..a5e2234688 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,28 @@ +# 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_213055) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "merchants", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From 5bdcbb304509f73a74d5a207b9efb7b2dc2d1f6c Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 14:47:09 -0700 Subject: [PATCH 005/196] user model columns added, sti column(type) added for sti --- .../20181017213808_create_columns_for_user_table.rb | 10 ++++++++++ db/schema.rb | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181017213808_create_columns_for_user_table.rb diff --git a/db/migrate/20181017213808_create_columns_for_user_table.rb b/db/migrate/20181017213808_create_columns_for_user_table.rb new file mode 100644 index 0000000000..900e99274f --- /dev/null +++ b/db/migrate/20181017213808_create_columns_for_user_table.rb @@ -0,0 +1,10 @@ +class CreateColumnsForUserTable < ActiveRecord::Migration[5.2] + def change + create_table :columns_for_user_tables do |t| + add_column :users, :name, :string + add_column :users, :address, :string + add_column :users, :cc_num, :string + add_column :users, :type, :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a5e2234688..bedf8ab4f8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_17_213055) do +ActiveRecord::Schema.define(version: 2018_10_17_213808) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "columns_for_user_tables", force: :cascade do |t| + end + create_table "merchants", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -23,6 +26,10 @@ create_table "users", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "name" + t.string "address" + t.string "cc_num" + t.string "type" end end From 36d6b60c6c907922ba16cf47d2ab1bcb63ed68e0 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Wed, 17 Oct 2018 15:03:39 -0700 Subject: [PATCH 006/196] create model for review --- app/models/review.rb | 3 +++ db/migrate/20181017220137_create_reviews.rb | 12 ++++++++++++ db/schema.rb | 13 ++++++++++++- test/fixtures/reviews.yml | 13 +++++++++++++ test/models/review_test.rb | 9 +++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/models/review.rb create mode 100644 db/migrate/20181017220137_create_reviews.rb create mode 100644 test/fixtures/reviews.yml create mode 100644 test/models/review_test.rb diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..949d4ccddb --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,3 @@ +class Review < ApplicationRecord + belongs_to :product +end diff --git a/db/migrate/20181017220137_create_reviews.rb b/db/migrate/20181017220137_create_reviews.rb new file mode 100644 index 0000000000..38ad5457c0 --- /dev/null +++ b/db/migrate/20181017220137_create_reviews.rb @@ -0,0 +1,12 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.references :product, foreign_key: true + t.integer :rating + t.string :name + t.string :comment + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index bec8f276db..7075b8e840 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_212743) do +ActiveRecord::Schema.define(version: 2018_10_17_220137) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -33,10 +33,21 @@ t.index ["user_id"], name: "index_products_on_user_id" end + create_table "reviews", force: :cascade do |t| + t.bigint "product_id" + t.integer "rating" + t.string "name" + t.string "comment" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["product_id"], name: "index_reviews_on_product_id" + end + create_table "users", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_foreign_key "products", "users" + add_foreign_key "reviews", "products" end diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..5ecb4bc68f --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + product: one + rating: 1 + name: MyString + comment: MyString + +two: + product: two + rating: 1 + name: MyString + comment: MyString 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 From da4f834a5b64f818fb53b276f9930e2eac279ef1 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 15:11:29 -0700 Subject: [PATCH 007/196] created columns for cc info to users --- app/controllers/user_controller.rb | 12 +++++++++--- app/models/merchant.rb | 1 + db/migrate/20181017220936_add_cc_columns_to_user.rb | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181017220936_add_cc_columns_to_user.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 547137459b..1156bcd3a0 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,4 +1,6 @@ class UserController < ApplicationController + #before_action is type merchant? + def index @users = User.all end @@ -8,23 +10,27 @@ def new end def create + #check if user wants merchant status end def show end def update + #can become merchant? end - def destroy + def edit + #can become merchant? end - def edit + def destroy + #delete account aka be sent to siberia end private def user_params - return params.require(:user).permit(:name, :address, :email, :cc_num, :merchant_id) + return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip) end end diff --git a/app/models/merchant.rb b/app/models/merchant.rb index c2a004ff6f..cd1648488b 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,2 +1,3 @@ class Merchant < User + #merchant inherits all things from user, but when a new merchant is created the 'type' is automagically set to merchant. end diff --git a/db/migrate/20181017220936_add_cc_columns_to_user.rb b/db/migrate/20181017220936_add_cc_columns_to_user.rb new file mode 100644 index 0000000000..2f5a2890f7 --- /dev/null +++ b/db/migrate/20181017220936_add_cc_columns_to_user.rb @@ -0,0 +1,7 @@ +class AddCcColumnsToUser < ActiveRecord::Migration[5.2] + def change + create_column :users, :cc_csv, :integer + create_column :users, :cc_exp, :date + create_column :users, :bill_zip, :integer + end +end From 4b4bbfd1798959b2cfe04cd88ad084c8b3997ad7 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Wed, 17 Oct 2018 15:14:07 -0700 Subject: [PATCH 008/196] created a routes for product --- config/routes.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 06f822b06b..689a653e89 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,5 +6,9 @@ get 'user/destroy' get 'user/edit' get 'user/create' + + resources :products + + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From 7d6b7ffdc706021104a4278ec1eb92cb536de377 Mon Sep 17 00:00:00 2001 From: jackie Date: Wed, 17 Oct 2018 15:16:09 -0700 Subject: [PATCH 009/196] Generated Order and OrderItem models --- app/models/order.rb | 2 ++ app/models/order_item.rb | 2 ++ db/migrate/20181017221330_create_orders.rb | 9 +++++++++ db/migrate/20181017221402_create_order_items.rb | 9 +++++++++ test/fixtures/order_items.yml | 7 +++++++ test/fixtures/orders.yml | 7 +++++++ test/models/order_item_test.rb | 9 +++++++++ test/models/order_test.rb | 9 +++++++++ 8 files changed, 54 insertions(+) create mode 100644 app/models/order.rb create mode 100644 app/models/order_item.rb create mode 100644 db/migrate/20181017221330_create_orders.rb create mode 100644 db/migrate/20181017221402_create_order_items.rb create mode 100644 test/fixtures/order_items.yml create mode 100644 test/fixtures/orders.yml create mode 100644 test/models/order_item_test.rb create mode 100644 test/models/order_test.rb diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..10281b3450 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,2 @@ +class Order < ApplicationRecord +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..acc6099fd0 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,2 @@ +class OrderItem < ApplicationRecord +end diff --git a/db/migrate/20181017221330_create_orders.rb b/db/migrate/20181017221330_create_orders.rb new file mode 100644 index 0000000000..e9c5332869 --- /dev/null +++ b/db/migrate/20181017221330_create_orders.rb @@ -0,0 +1,9 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.symbol :status + + t.timestamps + end + end +end diff --git a/db/migrate/20181017221402_create_order_items.rb b/db/migrate/20181017221402_create_order_items.rb new file mode 100644 index 0000000000..cd9db5ef0d --- /dev/null +++ b/db/migrate/20181017221402_create_order_items.rb @@ -0,0 +1,9 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + t.integer :quantity + + t.timestamps + end + end +end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..6609c00aa6 --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + quantity: 1 + +two: + quantity: 1 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..24de587694 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + status: + +two: + status: diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..19a9bf8f58 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderItem do + let(:order_item) { OrderItem.new } + + it "must be valid" do + value(order_item).must_be :valid? + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..df80f10fb6 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + + it "must be valid" do + value(order).must_be :valid? + end +end From 3321bd698a176438571cdac391fcc03e3871207a Mon Sep 17 00:00:00 2001 From: jackie Date: Wed, 17 Oct 2018 15:39:47 -0700 Subject: [PATCH 010/196] set up foreign keys for order and orderproduct --- app/assets/javascripts/orders.js | 2 ++ app/assets/stylesheets/orders.scss | 3 ++ app/controllers/orders_controller.rb | 19 +++++++++++ app/helpers/orders_helper.rb | 2 ++ app/views/orders/create.html.erb | 2 ++ app/views/orders/edit.html.erb | 2 ++ app/views/orders/index.html.erb | 2 ++ app/views/orders/new.html.erb | 2 ++ app/views/orders/show.html.erb | 2 ++ app/views/orders/update.html.erb | 2 ++ config/routes.rb | 6 ++++ db/migrate/20181017221330_create_orders.rb | 2 +- ...dd_product_and_order_i_ds_to_order_item.rb | 6 ++++ .../20181017222331_add_user_to_order.rb | 5 +++ .../20181017223632_rename_order_item_table.rb | 5 +++ .../20181017223749_rename_order_product.rb | 5 +++ db/schema.rb | 23 ++++++++++++- test/controllers/orders_controller_test.rb | 34 +++++++++++++++++++ 18 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/views/orders/create.html.erb create mode 100644 app/views/orders/edit.html.erb create mode 100644 app/views/orders/index.html.erb create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/show.html.erb create mode 100644 app/views/orders/update.html.erb create mode 100644 db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb create mode 100644 db/migrate/20181017222331_add_user_to_order.rb create mode 100644 db/migrate/20181017223632_rename_order_item_table.rb create mode 100644 db/migrate/20181017223749_rename_order_product.rb create mode 100644 test/controllers/orders_controller_test.rb diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..741506954d --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..f8cb7f227f --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,19 @@ +class OrdersController < ApplicationController + def index + end + + def show + end + + def new + end + + def create + end + + def edit + end + + def update + end +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/views/orders/create.html.erb b/app/views/orders/create.html.erb new file mode 100644 index 0000000000..295bd84094 --- /dev/null +++ b/app/views/orders/create.html.erb @@ -0,0 +1,2 @@ +

Orders#create

+

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

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

Orders#edit

+

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

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

Orders#index

+

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

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

Orders#new

+

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

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

Orders#show

+

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

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

Orders#update

+

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

diff --git a/config/routes.rb b/config/routes.rb index 06f822b06b..bf9b182d11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,10 @@ Rails.application.routes.draw do + get 'orders/index' + get 'orders/show' + get 'orders/new' + get 'orders/create' + get 'orders/edit' + get 'orders/update' get 'user/index' get 'user/new' get 'user/show' diff --git a/db/migrate/20181017221330_create_orders.rb b/db/migrate/20181017221330_create_orders.rb index e9c5332869..ac0f931eea 100644 --- a/db/migrate/20181017221330_create_orders.rb +++ b/db/migrate/20181017221330_create_orders.rb @@ -1,7 +1,7 @@ class CreateOrders < ActiveRecord::Migration[5.2] def change create_table :orders do |t| - t.symbol :status + t.string :status t.timestamps end diff --git a/db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb b/db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb new file mode 100644 index 0000000000..0e022e90aa --- /dev/null +++ b/db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb @@ -0,0 +1,6 @@ +class AddProductAndOrderIDsToOrderItem < ActiveRecord::Migration[5.2] + def change + add_reference :order_items, :product, foreign_key: true + add_reference :order_items, :order, foreign_key: true + end +end diff --git a/db/migrate/20181017222331_add_user_to_order.rb b/db/migrate/20181017222331_add_user_to_order.rb new file mode 100644 index 0000000000..85c311cf28 --- /dev/null +++ b/db/migrate/20181017222331_add_user_to_order.rb @@ -0,0 +1,5 @@ +class AddUserToOrder < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :user, foreign_key: true + end +end diff --git a/db/migrate/20181017223632_rename_order_item_table.rb b/db/migrate/20181017223632_rename_order_item_table.rb new file mode 100644 index 0000000000..a34451cb95 --- /dev/null +++ b/db/migrate/20181017223632_rename_order_item_table.rb @@ -0,0 +1,5 @@ +class RenameOrderItemTable < ActiveRecord::Migration[5.2] + def change + rename_table :order_items, :order_product + end +end diff --git a/db/migrate/20181017223749_rename_order_product.rb b/db/migrate/20181017223749_rename_order_product.rb new file mode 100644 index 0000000000..9011d3cb75 --- /dev/null +++ b/db/migrate/20181017223749_rename_order_product.rb @@ -0,0 +1,5 @@ +class RenameOrderProduct < ActiveRecord::Migration[5.2] + def change + rename_table :order_product, :order_products + end +end diff --git a/db/schema.rb b/db/schema.rb index 7075b8e840..f23760580b 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_220137) do +ActiveRecord::Schema.define(version: 2018_10_17_223749) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,24 @@ t.datetime "updated_at", null: false end + create_table "order_products", force: :cascade do |t| + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.bigint "order_id" + t.index ["order_id"], name: "index_order_products_on_order_id" + t.index ["product_id"], name: "index_order_products_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.string "status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.index ["user_id"], name: "index_orders_on_user_id" + end + create_table "products", force: :cascade do |t| t.bigint "user_id" t.string "name" @@ -48,6 +66,9 @@ t.datetime "updated_at", null: false end + add_foreign_key "order_products", "orders" + add_foreign_key "order_products", "products" + add_foreign_key "orders", "users" add_foreign_key "products", "users" add_foreign_key "reviews", "products" end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..c7582dae4d --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,34 @@ +require "test_helper" + +describe OrdersController do + it "should get index" do + get orders_index_url + value(response).must_be :success? + end + + it "should get show" do + get orders_show_url + value(response).must_be :success? + end + + it "should get new" do + get orders_new_url + value(response).must_be :success? + end + + it "should get create" do + get orders_create_url + value(response).must_be :success? + end + + it "should get edit" do + get orders_edit_url + value(response).must_be :success? + end + + it "should get update" do + get orders_update_url + value(response).must_be :success? + end + +end From fa93d116c6a7605049ef0b0d856269852d436465 Mon Sep 17 00:00:00 2001 From: jackie Date: Wed, 17 Oct 2018 15:41:23 -0700 Subject: [PATCH 011/196] Setup order routes --- config/routes.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index bf9b182d11..3edfd7d464 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,6 @@ Rails.application.routes.draw do - get 'orders/index' - get 'orders/show' - get 'orders/new' - get 'orders/create' - get 'orders/edit' - get 'orders/update' + resources :orders, except: [:destroy] + get 'user/index' get 'user/new' get 'user/show' From 449f2458b0922a7e59d1af7a7a9405e48bc64456 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 15:42:05 -0700 Subject: [PATCH 012/196] omniauth gem and omniauth-github gem added --- app/controllers/user_controller.rb | 25 ++++++++++++++++++++++++- app/models/merchant.rb | 1 + config/routes.rb | 8 +------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 1156bcd3a0..fc440a418d 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,4 +1,5 @@ class UserController < ApplicationController + before_action :find_user #before_action is type merchant? def index @@ -10,9 +11,21 @@ def new end def create - #check if user wants merchant status + #if merchant checked, type is filled (in forms), otherwise it is not -- passive method + @user = User.new(user_params) + if @user.save + flash[:success] = 'Success' + redirect_to root_path + else + flash.now[:error] = 'No success' + @user.errors.messages.each do |field, messages| + flash.now[field] = messages + end + end + render :new end + def show end @@ -30,6 +43,16 @@ def destroy private + def find_user + id = params[:id].to_i + @user = User.find_by(id: id) + + if @user.nil? + flash.now[:warning] = "Imposter!" + render :not_found + end + end + def user_params return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip) end diff --git a/app/models/merchant.rb b/app/models/merchant.rb index cd1648488b..e03a781007 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,3 +1,4 @@ class Merchant < User #merchant inherits all things from user, but when a new merchant is created the 'type' is automagically set to merchant. + #merchant needs ability to fulfill orders as 'shipped' end diff --git a/config/routes.rb b/config/routes.rb index 06f822b06b..c8c8ab112a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,4 @@ Rails.application.routes.draw do - get 'user/index' - get 'user/new' - get 'user/show' - get 'user/update' - get 'user/destroy' - get 'user/edit' - get 'user/create' + resources :users # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From 895e512143b3256313dc7671b82b132831ccaffc Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 15:49:15 -0700 Subject: [PATCH 013/196] dotenv gem added --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 18b43c9cd2..a08194509e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ /public/assets .byebug_history +.env # Ignore master key for decrypting credentials and more. /config/master.key From 8519bccac72c19a35132ba3a96ae98759a00542c Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 17 Oct 2018 16:02:38 -0700 Subject: [PATCH 014/196] weird table removed, user table fixed --- .env | 2 ++ db/migrate/20181017230015_add_cc_info_to_user.rb | 7 +++++++ db/schema.rb | 11 +++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 db/migrate/20181017230015_add_cc_info_to_user.rb diff --git a/.env b/.env new file mode 100644 index 0000000000..13dfa493bb --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +GITHUB_CLIENT_ID: 27ec83359222828f81a9 +GITHUB_CLIENT_SECRET: 41dc9cd19938ea508d763c10cbfd1df965c92a93 diff --git a/db/migrate/20181017230015_add_cc_info_to_user.rb b/db/migrate/20181017230015_add_cc_info_to_user.rb new file mode 100644 index 0000000000..be4fb5d23a --- /dev/null +++ b/db/migrate/20181017230015_add_cc_info_to_user.rb @@ -0,0 +1,7 @@ +class AddCcInfoToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :cc_exp, :datetime + add_column :users, :bill_zip, :integer + add_column :users, :cc_csv, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index f23760580b..8b6f8376b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,12 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_17_223749) do +ActiveRecord::Schema.define(version: 2018_10_17_230015) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "buyers", force: :cascade do |t| + create_table "merchants", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -64,6 +64,13 @@ create_table "users", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "name" + t.string "address" + t.string "cc_num" + t.string "type" + t.datetime "cc_exp" + t.integer "bill_zip" + t.integer "cc_csv" end add_foreign_key "order_products", "orders" From b853e23c245e8d06a98d31b50e7deaa741f76123 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Wed, 17 Oct 2018 21:19:50 -0700 Subject: [PATCH 015/196] set up fkey user_id to reviews --- .env | 2 + README.md | 2 +- app/assets/javascripts/orders.js | 2 + app/assets/stylesheets/orders.scss | 3 ++ app/controllers/orders_controller.rb | 19 ++++++++++ app/controllers/products_controller.rb | 33 ++++++++++++++++ app/controllers/user_controller.rb | 2 +- app/helpers/orders_helper.rb | 2 + app/models/order.rb | 2 + app/models/order_item.rb | 2 + app/models/product.rb | 38 +++++++++++++++++++ app/models/review.rb | 5 +++ app/views/orders/create.html.erb | 2 + app/views/orders/edit.html.erb | 2 + app/views/orders/index.html.erb | 2 + app/views/orders/new.html.erb | 2 + app/views/orders/show.html.erb | 2 + app/views/orders/update.html.erb | 2 + config/routes.rb | 2 + db/migrate/20181017221330_create_orders.rb | 9 +++++ .../20181017221402_create_order_items.rb | 9 +++++ ...dd_product_and_order_i_ds_to_order_item.rb | 6 +++ .../20181017222331_add_user_to_order.rb | 5 +++ .../20181017223632_rename_order_item_table.rb | 5 +++ .../20181017223749_rename_order_product.rb | 5 +++ .../20181017230015_add_cc_info_to_user.rb | 7 ++++ .../20181018040120_change_reviews_column.rb | 6 +++ db/schema.rb | 30 ++++++++++++++- test/controllers/orders_controller_test.rb | 34 +++++++++++++++++ test/fixtures/order_items.yml | 7 ++++ test/fixtures/orders.yml | 7 ++++ test/models/order_item_test.rb | 9 +++++ test/models/order_test.rb | 9 +++++ 33 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 .env create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/models/order.rb create mode 100644 app/models/order_item.rb create mode 100644 app/views/orders/create.html.erb create mode 100644 app/views/orders/edit.html.erb create mode 100644 app/views/orders/index.html.erb create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/show.html.erb create mode 100644 app/views/orders/update.html.erb create mode 100644 db/migrate/20181017221330_create_orders.rb create mode 100644 db/migrate/20181017221402_create_order_items.rb create mode 100644 db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb create mode 100644 db/migrate/20181017222331_add_user_to_order.rb create mode 100644 db/migrate/20181017223632_rename_order_item_table.rb create mode 100644 db/migrate/20181017223749_rename_order_product.rb create mode 100644 db/migrate/20181017230015_add_cc_info_to_user.rb create mode 100644 db/migrate/20181018040120_change_reviews_column.rb create mode 100644 test/controllers/orders_controller_test.rb create mode 100644 test/fixtures/order_items.yml create mode 100644 test/fixtures/orders.yml create mode 100644 test/models/order_item_test.rb create mode 100644 test/models/order_test.rb diff --git a/.env b/.env new file mode 100644 index 0000000000..13dfa493bb --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +GITHUB_CLIENT_ID: 27ec83359222828f81a9 +GITHUB_CLIENT_SECRET: 41dc9cd19938ea508d763c10cbfd1df965c92a93 diff --git a/README.md b/README.md index 9f398a6bde..1864d2b973 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Due date: EOD Friday October 26 - Groups of three or four will collaborate in pairs or individually and will report to their assigned Project Manager (one of the instructors) - Use a task manager like [Trello](http://trello.com) to track your team's efforts - Build a logical user-flow that moves across multiple controllers and models -- Use HTML/CSS and Foundation to style your website +- Use HTML/CSS and Bootstap or another CSS framework to style your website ## Getting Started 1. As a group decide on an app name (this may help lead the aesthetic) diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..741506954d --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..f8cb7f227f --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,19 @@ +class OrdersController < ApplicationController + def index + end + + def show + end + + def new + end + + def create + end + + def edit + end + + def update + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f1ad12ddea..6658598255 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,2 +1,35 @@ class ProductsController < ApplicationController + + def index + @products = Product.all + @products_by_category = Product.product_by_category + @pruducts_by_merchant = Product.product_by_merchant + end + + def show + Product + + end + + def new + + + end + + def create + + end + + def edit + + end + + def update + + end + + def destroy + + end + end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index ef8c82517d..cf561569d1 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,6 +1,6 @@ class UserController < ApplicationController def index - + end def new 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/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/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..acc6099fd0 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,2 @@ +class OrderItem < ApplicationRecord +end diff --git a/app/models/product.rb b/app/models/product.rb index 2f2fb1bdeb..3090755b1e 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,3 +1,41 @@ class Product < ApplicationRecord belongs_to :user + + validates :name, presence :true, + uniqueness: { scope: :category } + + validates :price, presence :true + + validates :user_id, presence :true + validates :stock, presence :true + + validates :category, presence: true, + inclusion: { in: @category } + + before_validation :fix_category + + def self.to_category_hash + data = {} + CATEGORIES.each do |cat| + data[cat] = by_category(cat) + end + return data + end + + def self.by_category(category) + category = category.singularize.downcase + self.where(category: category).order(vote_count: :desc) + end + + + + + private + def fix_category + if self.category + self.category = self.category.downcase.singularize + end + end + end + end diff --git a/app/models/review.rb b/app/models/review.rb index 949d4ccddb..b2cdc731fc 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,3 +1,8 @@ class Review < ApplicationRecord belongs_to :product + + validates :rating, presence :true + validates :product_id, presence :true + validates :name, presence :true + end diff --git a/app/views/orders/create.html.erb b/app/views/orders/create.html.erb new file mode 100644 index 0000000000..295bd84094 --- /dev/null +++ b/app/views/orders/create.html.erb @@ -0,0 +1,2 @@ +

Orders#create

+

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

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

Orders#edit

+

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

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

Orders#index

+

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

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

Orders#new

+

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

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

Orders#show

+

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

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

Orders#update

+

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

diff --git a/config/routes.rb b/config/routes.rb index 689a653e89..e2affd5131 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + resources :orders, except: [:destroy] + get 'user/index' get 'user/new' get 'user/show' diff --git a/db/migrate/20181017221330_create_orders.rb b/db/migrate/20181017221330_create_orders.rb new file mode 100644 index 0000000000..ac0f931eea --- /dev/null +++ b/db/migrate/20181017221330_create_orders.rb @@ -0,0 +1,9 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :status + + t.timestamps + end + end +end diff --git a/db/migrate/20181017221402_create_order_items.rb b/db/migrate/20181017221402_create_order_items.rb new file mode 100644 index 0000000000..cd9db5ef0d --- /dev/null +++ b/db/migrate/20181017221402_create_order_items.rb @@ -0,0 +1,9 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb b/db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb new file mode 100644 index 0000000000..0e022e90aa --- /dev/null +++ b/db/migrate/20181017222202_add_product_and_order_i_ds_to_order_item.rb @@ -0,0 +1,6 @@ +class AddProductAndOrderIDsToOrderItem < ActiveRecord::Migration[5.2] + def change + add_reference :order_items, :product, foreign_key: true + add_reference :order_items, :order, foreign_key: true + end +end diff --git a/db/migrate/20181017222331_add_user_to_order.rb b/db/migrate/20181017222331_add_user_to_order.rb new file mode 100644 index 0000000000..85c311cf28 --- /dev/null +++ b/db/migrate/20181017222331_add_user_to_order.rb @@ -0,0 +1,5 @@ +class AddUserToOrder < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :user, foreign_key: true + end +end diff --git a/db/migrate/20181017223632_rename_order_item_table.rb b/db/migrate/20181017223632_rename_order_item_table.rb new file mode 100644 index 0000000000..a34451cb95 --- /dev/null +++ b/db/migrate/20181017223632_rename_order_item_table.rb @@ -0,0 +1,5 @@ +class RenameOrderItemTable < ActiveRecord::Migration[5.2] + def change + rename_table :order_items, :order_product + end +end diff --git a/db/migrate/20181017223749_rename_order_product.rb b/db/migrate/20181017223749_rename_order_product.rb new file mode 100644 index 0000000000..9011d3cb75 --- /dev/null +++ b/db/migrate/20181017223749_rename_order_product.rb @@ -0,0 +1,5 @@ +class RenameOrderProduct < ActiveRecord::Migration[5.2] + def change + rename_table :order_product, :order_products + end +end diff --git a/db/migrate/20181017230015_add_cc_info_to_user.rb b/db/migrate/20181017230015_add_cc_info_to_user.rb new file mode 100644 index 0000000000..be4fb5d23a --- /dev/null +++ b/db/migrate/20181017230015_add_cc_info_to_user.rb @@ -0,0 +1,7 @@ +class AddCcInfoToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :cc_exp, :datetime + add_column :users, :bill_zip, :integer + add_column :users, :cc_csv, :integer + end +end diff --git a/db/migrate/20181018040120_change_reviews_column.rb b/db/migrate/20181018040120_change_reviews_column.rb new file mode 100644 index 0000000000..7cd38e6ef1 --- /dev/null +++ b/db/migrate/20181018040120_change_reviews_column.rb @@ -0,0 +1,6 @@ +class ChangeReviewsColumn < ActiveRecord::Migration[5.2] + def change + add_reference :reviews, :user, foreign_key: true + remove_column :reviews, :name + end +end diff --git a/db/schema.rb b/db/schema.rb index 7075b8e840..c1c7ceb50b 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_220137) do +ActiveRecord::Schema.define(version: 2018_10_18_040120) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,24 @@ t.datetime "updated_at", null: false end + create_table "order_products", force: :cascade do |t| + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.bigint "order_id" + t.index ["order_id"], name: "index_order_products_on_order_id" + t.index ["product_id"], name: "index_order_products_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.string "status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.index ["user_id"], name: "index_orders_on_user_id" + end + create_table "products", force: :cascade do |t| t.bigint "user_id" t.string "name" @@ -36,18 +54,26 @@ create_table "reviews", force: :cascade do |t| t.bigint "product_id" t.integer "rating" - t.string "name" t.string "comment" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "user_id" t.index ["product_id"], name: "index_reviews_on_product_id" + t.index ["user_id"], name: "index_reviews_on_user_id" end create_table "users", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.datetime "cc_exp" + t.integer "bill_zip" + t.integer "cc_csv" end + add_foreign_key "order_products", "orders" + add_foreign_key "order_products", "products" + add_foreign_key "orders", "users" add_foreign_key "products", "users" add_foreign_key "reviews", "products" + add_foreign_key "reviews", "users" end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..c7582dae4d --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,34 @@ +require "test_helper" + +describe OrdersController do + it "should get index" do + get orders_index_url + value(response).must_be :success? + end + + it "should get show" do + get orders_show_url + value(response).must_be :success? + end + + it "should get new" do + get orders_new_url + value(response).must_be :success? + end + + it "should get create" do + get orders_create_url + value(response).must_be :success? + end + + it "should get edit" do + get orders_edit_url + value(response).must_be :success? + end + + it "should get update" do + get orders_update_url + value(response).must_be :success? + end + +end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..6609c00aa6 --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + quantity: 1 + +two: + quantity: 1 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..24de587694 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + status: + +two: + status: diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..19a9bf8f58 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderItem do + let(:order_item) { OrderItem.new } + + it "must be valid" do + value(order_item).must_be :valid? + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..df80f10fb6 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + + it "must be valid" do + value(order).must_be :valid? + end +end From b3cfd7e66881115bc16dd9e3a277c41c562d2f89 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Wed, 17 Oct 2018 21:45:09 -0700 Subject: [PATCH 016/196] created category control and model --- app/assets/javascripts/categorys.js | 2 ++ app/assets/stylesheets/categorys.scss | 3 +++ app/controllers/categorys_controller.rb | 2 ++ app/helpers/categorys_helper.rb | 2 ++ app/models/category.rb | 2 ++ db/migrate/20181018044236_create_categories.rb | 9 +++++++++ db/schema.rb | 8 +++++++- test/controllers/categorys_controller_test.rb | 7 +++++++ test/fixtures/categories.yml | 7 +++++++ test/models/category_test.rb | 9 +++++++++ 10 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/categorys.js create mode 100644 app/assets/stylesheets/categorys.scss create mode 100644 app/controllers/categorys_controller.rb create mode 100644 app/helpers/categorys_helper.rb create mode 100644 app/models/category.rb create mode 100644 db/migrate/20181018044236_create_categories.rb create mode 100644 test/controllers/categorys_controller_test.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb diff --git a/app/assets/javascripts/categorys.js b/app/assets/javascripts/categorys.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/categorys.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/categorys.scss b/app/assets/stylesheets/categorys.scss new file mode 100644 index 0000000000..b948799c17 --- /dev/null +++ b/app/assets/stylesheets/categorys.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Categorys 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/categorys_controller.rb b/app/controllers/categorys_controller.rb new file mode 100644 index 0000000000..429f0c561a --- /dev/null +++ b/app/controllers/categorys_controller.rb @@ -0,0 +1,2 @@ +class CategorysController < ApplicationController +end diff --git a/app/helpers/categorys_helper.rb b/app/helpers/categorys_helper.rb new file mode 100644 index 0000000000..a23d614633 --- /dev/null +++ b/app/helpers/categorys_helper.rb @@ -0,0 +1,2 @@ +module CategorysHelper +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/db/migrate/20181018044236_create_categories.rb b/db/migrate/20181018044236_create_categories.rb new file mode 100644 index 0000000000..6ccc3914a0 --- /dev/null +++ b/db/migrate/20181018044236_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c1c7ceb50b..69160759c3 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_040120) do +ActiveRecord::Schema.define(version: 2018_10_18_044236) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,12 @@ t.datetime "updated_at", null: false end + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "order_products", force: :cascade do |t| t.integer "quantity" t.datetime "created_at", null: false diff --git a/test/controllers/categorys_controller_test.rb b/test/controllers/categorys_controller_test.rb new file mode 100644 index 0000000000..1481019f07 --- /dev/null +++ b/test/controllers/categorys_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe CategorysController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..56066c68af --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..781320ad8e --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new } + + it "must be valid" do + value(category).must_be :valid? + end +end From 29f5230282a3e8d074ca261332fa41631c9deaa4 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Wed, 17 Oct 2018 23:03:36 -0700 Subject: [PATCH 017/196] update product model methods --- app/controllers/products_controller.rb | 29 +++++++++++++++---- app/models/category.rb | 1 + app/models/product.rb | 20 +++++++++++-- config/routes.rb | 4 +-- ...1018050221_add_category_fkey_to_product.rb | 6 ++++ db/schema.rb | 6 ++-- 6 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20181018050221_add_category_fkey_to_product.rb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 6658598255..7e3e54357c 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,21 +1,24 @@ class ProductsController < ApplicationController + before_action :find_product, only: [:show, :edit, :update, :destroy] def index - @products = Product.all - @products_by_category = Product.product_by_category - @pruducts_by_merchant = Product.product_by_merchant + @products = Product.in_stock + @products_by_category = @products.product_by_category + @pruducts_by_merchant = @products.product_by_merchant + end def show - Product + end def new - + @product = Product.new end + def create end @@ -30,6 +33,22 @@ def update def destroy + + + end + + private + def find_product + @product = Product.find_by(id: params[:id].to_i) + + if @product.nil? + flash.now[:danger] = "Cannot find the product #{params[:id]}" + render :notfound, status: :not_found + end + end + + def product_params + return params.require(:product).permit(:name, :category_id, :price, :description, :stock, :photo_url) end end diff --git a/app/models/category.rb b/app/models/category.rb index 54cb6aee3f..dd435ade10 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,2 +1,3 @@ class Category < ApplicationRecord + has_many :product end diff --git a/app/models/product.rb b/app/models/product.rb index 3090755b1e..6f7b997e46 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,5 +1,6 @@ class Product < ApplicationRecord belongs_to :user + belongs_to :category validates :name, presence :true, uniqueness: { scope: :category } @@ -10,13 +11,17 @@ class Product < ApplicationRecord validates :stock, presence :true validates :category, presence: true, - inclusion: { in: @category } + inclusion: { in: @categories } before_validation :fix_category + def self.in_stock + return Product.all.select {|prod| prod.stock >= 1} + end + def self.to_category_hash data = {} - CATEGORIES.each do |cat| + Category.each do |cat| data[cat] = by_category(cat) end return data @@ -27,8 +32,17 @@ def self.by_category(category) self.where(category: category).order(vote_count: :desc) end - + def self.to_merchant_hash + data = {} + Category.each do |cat| + data[cat] = by_category(cat) + end + return data + end + def self.by_merchant(merchant) + self.where(user: merchant).order(vote_count: :desc) + end private def fix_category diff --git a/config/routes.rb b/config/routes.rb index e2affd5131..5b311b5d30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do resources :orders, except: [:destroy] - + get 'user/index' get 'user/new' get 'user/show' @@ -10,7 +10,7 @@ get 'user/create' resources :products - + resources :category, only: [:new, :create] # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20181018050221_add_category_fkey_to_product.rb b/db/migrate/20181018050221_add_category_fkey_to_product.rb new file mode 100644 index 0000000000..fdfa4e4eac --- /dev/null +++ b/db/migrate/20181018050221_add_category_fkey_to_product.rb @@ -0,0 +1,6 @@ +class AddCategoryFkeyToProduct < ActiveRecord::Migration[5.2] + def change + remove_column :products, :category + add_reference :products, :category, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 69160759c3..979d505413 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_044236) do +ActiveRecord::Schema.define(version: 2018_10_18_050221) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -48,12 +48,13 @@ t.bigint "user_id" t.string "name" t.float "price" - t.string "category" t.string "description" t.integer "stock" t.string "photo_url" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "category_id" + t.index ["category_id"], name: "index_products_on_category_id" t.index ["user_id"], name: "index_products_on_user_id" end @@ -79,6 +80,7 @@ add_foreign_key "order_products", "orders" add_foreign_key "order_products", "products" add_foreign_key "orders", "users" + add_foreign_key "products", "categories" add_foreign_key "products", "users" add_foreign_key "reviews", "products" add_foreign_key "reviews", "users" From 4c12f19b23d0c3f4163a6b64b10e82eaff760786 Mon Sep 17 00:00:00 2001 From: leannerivera <31866543+leannerivera@users.noreply.github.com> Date: Thu, 18 Oct 2018 09:37:25 -0700 Subject: [PATCH 018/196] Delete .env --- .env | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 13dfa493bb..0000000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -GITHUB_CLIENT_ID: 27ec83359222828f81a9 -GITHUB_CLIENT_SECRET: 41dc9cd19938ea508d763c10cbfd1df965c92a93 From 5321bcb4f0fa6850e7efeb776d1e86c9c65f9868 Mon Sep 17 00:00:00 2001 From: leannerivera <31866543+leannerivera@users.noreply.github.com> Date: Thu, 18 Oct 2018 09:38:23 -0700 Subject: [PATCH 019/196] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 18b43c9cd2..a08194509e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ /public/assets .byebug_history +.env # Ignore master key for decrypting credentials and more. /config/master.key From b81a389191eb38dedbac964febdd9bbb167641c3 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 09:56:05 -0700 Subject: [PATCH 020/196] commited files --- .env | 2 ++ app/controllers/products_controller.rb | 2 ++ app/controllers/sessions_controller.rb | 5 +++++ config/initializers/omniauth.rb | 4 ++++ db/migrate/20181017222331_add_user_to_order.rb | 5 +++++ db/migrate/20181017230015_add_cc_info_to_user.rb | 7 +++++++ 6 files changed, 25 insertions(+) create mode 100644 .env create mode 100644 app/controllers/products_controller.rb create mode 100644 app/controllers/sessions_controller.rb create mode 100644 config/initializers/omniauth.rb create mode 100644 db/migrate/20181017222331_add_user_to_order.rb create mode 100644 db/migrate/20181017230015_add_cc_info_to_user.rb diff --git a/.env b/.env new file mode 100644 index 0000000000..13dfa493bb --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +GITHUB_CLIENT_ID: 27ec83359222828f81a9 +GITHUB_CLIENT_SECRET: 41dc9cd19938ea508d763c10cbfd1df965c92a93 diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..f1ad12ddea --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,2 @@ +class ProductsController < ApplicationController +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..dfc0fceb95 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,5 @@ +class SessionsController < ApplicationController + def create + auth_hash = request.env['omniauth.auth'] + end +end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..ef8c60c371 --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,4 @@ +# config/initializers/omniauth.rb +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/db/migrate/20181017222331_add_user_to_order.rb b/db/migrate/20181017222331_add_user_to_order.rb new file mode 100644 index 0000000000..85c311cf28 --- /dev/null +++ b/db/migrate/20181017222331_add_user_to_order.rb @@ -0,0 +1,5 @@ +class AddUserToOrder < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :user, foreign_key: true + end +end diff --git a/db/migrate/20181017230015_add_cc_info_to_user.rb b/db/migrate/20181017230015_add_cc_info_to_user.rb new file mode 100644 index 0000000000..be4fb5d23a --- /dev/null +++ b/db/migrate/20181017230015_add_cc_info_to_user.rb @@ -0,0 +1,7 @@ +class AddCcInfoToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :cc_exp, :datetime + add_column :users, :bill_zip, :integer + add_column :users, :cc_csv, :integer + end +end From d8271a5db7e23a8a0149de9e37607dd5ac317319 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 10:06:04 -0700 Subject: [PATCH 021/196] merge conflicts fixed --- config/routes.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 7a45a0516d..f623301199 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,7 @@ Rails.application.routes.draw do -<<<<<<< HEAD - resources :users -======= + resources :users resources :orders, except: [:destroy] - + get 'user/index' get 'user/new' get 'user/show' @@ -11,6 +9,6 @@ get 'user/destroy' get 'user/edit' get 'user/create' ->>>>>>> master + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From a824943bf49d53d1e1b237454e7b15b00d1c4a8c Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 10:13:19 -0700 Subject: [PATCH 022/196] omniauth entered --- Gemfile | 3 +++ Gemfile.lock | 28 ++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 5 +++++ config/initializers/omniauth.rb | 3 +++ config/routes.rb | 3 +++ 5 files changed, 42 insertions(+) create mode 100644 config/initializers/omniauth.rb diff --git a/Gemfile b/Gemfile index 6219256bd8..87cbaaad31 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,8 @@ gem 'jbuilder', '~> 2.5' # gem 'redis', '~> 4.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' +gem 'omniauth' +gem 'omniauth-github' # Use ActiveStorage variant # gem 'mini_magick', '~> 4.8' @@ -73,6 +75,7 @@ group :development do gem 'binding_of_caller' gem 'guard' gem 'guard-minitest' + gem 'dotenv-rails' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 51100b2a1d..6ffb22fbfa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,8 +81,14 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) debug_inspector (0.0.3) + dotenv (2.5.0) + dotenv-rails (2.5.0) + dotenv (= 2.5.0) + railties (>= 3.2, < 6.0) erubi (1.7.1) execjs (2.7.0) + faraday (0.15.3) + multipart-post (>= 1.2, < 3) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -100,6 +106,7 @@ GEM guard-minitest (2.4.6) guard-compat (~> 1.2) minitest (>= 3.0) + hashie (3.5.7) i18n (1.1.1) concurrent-ruby (~> 1.0) io-like (0.3.0) @@ -113,6 +120,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks + jwt (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -140,6 +148,8 @@ GEM ruby-progressbar msgpack (1.2.4) multi_json (1.13.1) + multi_xml (0.6.0) + multipart-post (2.0.0) nenv (0.3.0) nio4r (2.3.1) nokogiri (1.8.5) @@ -147,6 +157,21 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) + oauth2 (1.4.1) + faraday (>= 0.8, < 0.16.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.8.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) + omniauth-github (1.3.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-oauth2 (1.5.0) + oauth2 (~> 1.1) + omniauth (~> 1.2) pg (1.1.3) popper_js (1.14.3) pry (0.11.3) @@ -249,6 +274,7 @@ DEPENDENCIES byebug capybara (>= 2.15) chromedriver-helper + dotenv-rails guard guard-minitest jbuilder (~> 2.5) @@ -257,6 +283,8 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) minitest-rails minitest-reporters + omniauth + omniauth-github pg (>= 0.18, < 2.0) pry-rails puma (~> 3.11) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f18f1b6820..25310e9a94 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,11 @@ + <% if session[:user_id] %> + <%= link_to "Log out", logout_path, method: "delete" %> +<% else %> + <%= link_to "Login with Github", "/auth/github" %> +<% end %> <%= yield %> diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..fd4416122a --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/config/routes.rb b/config/routes.rb index f623301199..e6a85bbcf5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ Rails.application.routes.draw do + get "/auth/:provider/callback", to: "sessions#create" + delete "/logout", to: "sessions#destroy", as: "logout" + resources :users resources :orders, except: [:destroy] From 14c13b9fcd8df4074efbe2647f307fd498c50682 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 10:29:04 -0700 Subject: [PATCH 023/196] omniauth columns added to user table --- ...72139_add_auth_hash_info_to_users_table.rb | 7 ++++++ db/schema.rb | 23 ++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 db/migrate/20181018172139_add_auth_hash_info_to_users_table.rb diff --git a/db/migrate/20181018172139_add_auth_hash_info_to_users_table.rb b/db/migrate/20181018172139_add_auth_hash_info_to_users_table.rb new file mode 100644 index 0000000000..5ceeeb54f6 --- /dev/null +++ b/db/migrate/20181018172139_add_auth_hash_info_to_users_table.rb @@ -0,0 +1,7 @@ +class AddAuthHashInfoToUsersTable < ActiveRecord::Migration[5.2] + def change + add_column :users, :uid, :integer, null: false + add_column :users, :provider, :string, null: false + add_column :users, :email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3cabfe981a..9d15f1ad1b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,23 +10,11 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD -ActiveRecord::Schema.define(version: 2018_10_17_213808) do -======= -ActiveRecord::Schema.define(version: 2018_10_17_230015) do ->>>>>>> master +ActiveRecord::Schema.define(version: 2018_10_18_172139) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -<<<<<<< HEAD - create_table "columns_for_user_tables", force: :cascade do |t| - end - - create_table "merchants", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false -======= create_table "merchants", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -71,7 +59,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["product_id"], name: "index_reviews_on_product_id" ->>>>>>> master end create_table "users", force: :cascade do |t| @@ -81,13 +68,12 @@ t.string "address" t.string "cc_num" t.string "type" -<<<<<<< HEAD - end - -======= t.datetime "cc_exp" t.integer "bill_zip" t.integer "cc_csv" + t.integer "uid", null: false + t.string "provider", null: false + t.string "email" end add_foreign_key "order_products", "orders" @@ -95,5 +81,4 @@ add_foreign_key "orders", "users" add_foreign_key "products", "users" add_foreign_key "reviews", "products" ->>>>>>> master end From 6e7cd9e88d143fb969b78078475bf636b6a95973 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 10:53:15 -0700 Subject: [PATCH 024/196] working on omniauth sessions --- app/controllers/user_controller.rb | 59 ---------------------- app/controllers/users_controller.rb | 74 ++++++++++++++++++++++++++++ app/views/layouts/not_found.html.erb | 1 + app/views/user/not_found.html.erb | 1 + config/routes.rb | 11 +---- 5 files changed, 78 insertions(+), 68 deletions(-) delete mode 100644 app/controllers/user_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/views/layouts/not_found.html.erb create mode 100644 app/views/user/not_found.html.erb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb deleted file mode 100644 index fc440a418d..0000000000 --- a/app/controllers/user_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -class UserController < ApplicationController - before_action :find_user - #before_action is type merchant? - - def index - @users = User.all - end - - def new - @user = User.new - end - - def create - #if merchant checked, type is filled (in forms), otherwise it is not -- passive method - @user = User.new(user_params) - if @user.save - flash[:success] = 'Success' - redirect_to root_path - else - flash.now[:error] = 'No success' - @user.errors.messages.each do |field, messages| - flash.now[field] = messages - end - end - render :new - end - - - def show - end - - def update - #can become merchant? - end - - def edit - #can become merchant? - end - - def destroy - #delete account aka be sent to siberia - end - - private - - def find_user - id = params[:id].to_i - @user = User.find_by(id: id) - - if @user.nil? - flash.now[:warning] = "Imposter!" - render :not_found - end - end - - def user_params - return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip) - end -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..fdcc9e7a4a --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,74 @@ +class UsersController < ApplicationController + before_action :find_user + #before_action is type merchant? + + def index + @users = User.all + end + + def new + @user = User.new + end + + def create + #if merchant checked, type is filled (in forms), otherwise it is not -- passive method + + auth_hash = request.env['omniauth.auth'] + user = User.find_by(uid: auth_hash[:uid], provider: 'github') + if user + # User was found in the database + flash[:success] = "Logged in as returning user #{user.name}" + else + # render :new + # User doesn't match anything in the DB + # TODO: Attempt to create a new user + end + + # session[:user_id] = user.id + redirect_to users_path + end + # @user = User.new(user_params) + # if @user.save + # flash[:success] = 'Success' + # redirect_to root_path + # else + # flash.now[:error] = 'No success' + # @user.errors.messages.each do |field, messages| + # flash.now[field] = messages + # end + # end + + + + + def show + end + + def update + #can become merchant? + end + + def edit + #can become merchant? + end + + def destroy + #delete account aka be sent to siberia + end + + private + + def find_user + id = params[:id].to_i + @user = User.find_by(id: id) + + if @user.nil? + flash.now[:warning] = "Imposter!" + # render :not_found + end + end + + def user_params + return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip) + end +end diff --git a/app/views/layouts/not_found.html.erb b/app/views/layouts/not_found.html.erb new file mode 100644 index 0000000000..9b8bbf779b --- /dev/null +++ b/app/views/layouts/not_found.html.erb @@ -0,0 +1 @@ +

NOT FOUND

diff --git a/app/views/user/not_found.html.erb b/app/views/user/not_found.html.erb new file mode 100644 index 0000000000..9b8bbf779b --- /dev/null +++ b/app/views/user/not_found.html.erb @@ -0,0 +1 @@ +

NOT FOUND

diff --git a/config/routes.rb b/config/routes.rb index e6a85bbcf5..789cb6c074 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,17 +1,10 @@ Rails.application.routes.draw do - get "/auth/:provider/callback", to: "sessions#create" - delete "/logout", to: "sessions#destroy", as: "logout" + get "/auth/:provider/callback", to: "users#create" + # delete "/logout", to: "sessions#destroy", as: "logout" resources :users resources :orders, except: [:destroy] - get 'user/index' - get 'user/new' - get 'user/show' - get 'user/update' - get 'user/destroy' - get 'user/edit' - get 'user/create' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From a01b3ac945a20e927e5af9fb668cfbad799390fd Mon Sep 17 00:00:00 2001 From: Jacquelyn Cheng <35181875+jacquelynoelle@users.noreply.github.com> Date: Thu, 18 Oct 2018 10:54:05 -0700 Subject: [PATCH 025/196] Update routes.rb --- config/routes.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index e6a85bbcf5..2cb97ff58b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,13 +5,5 @@ resources :users resources :orders, except: [:destroy] - get 'user/index' - get 'user/new' - get 'user/show' - get 'user/update' - get 'user/destroy' - get 'user/edit' - get 'user/create' - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From fa260d3c7645cae5a1476e7e60804b62b10d1ba2 Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 11:13:11 -0700 Subject: [PATCH 026/196] Added shell product controller actions, routes, and show view --- app/controllers/products_controller.rb | 36 ++++++++++++++++++++++++++ app/views/products/show.html.erb | 1 + config/routes.rb | 1 + 3 files changed, 38 insertions(+) create mode 100644 app/views/products/show.html.erb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index f1ad12ddea..a35a69b305 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,2 +1,38 @@ class ProductsController < ApplicationController + before_action :find_product, except: [:index, :new, :create] + + def index + @products = Product.all + end + + def show; end + + def new + @product = Product.new + end + + def create + end + + def edit; end + + def update + end + + def destroy + end + + private + + def product_params + return params.require(:product).permit(:name, :price, :category, :description, :merchant, :stock, :photo_url) + end + + def find_product + @product = Product.find_by(id: params[:id].to_i) + + if @product.nil? + render :notfound, status: :not_found + end + end end diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..eae26663ce --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1 @@ +

Product Show Page

diff --git a/config/routes.rb b/config/routes.rb index 2cb97ff58b..00f87279fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ delete "/logout", to: "sessions#destroy", as: "logout" resources :users + resources :products resources :orders, except: [:destroy] # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html From ec900d294cd8cd452dcadd9b643e978ee90236ff Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Thu, 18 Oct 2018 11:14:59 -0700 Subject: [PATCH 027/196] adjusted the seed file --- app/models/category.rb | 3 +- app/models/product.rb | 99 +++++++++++++++++++++--------------------- app/models/review.rb | 6 +-- app/models/user.rb | 1 + config/routes.rb | 4 -- db/seeds.rb | 29 ++++++++----- 6 files changed, 74 insertions(+), 68 deletions(-) diff --git a/app/models/category.rb b/app/models/category.rb index dd435ade10..ded933dd49 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,4 @@ class Category < ApplicationRecord - has_many :product + has_many :products + validates :name, presence: true end diff --git a/app/models/product.rb b/app/models/product.rb index 6f7b997e46..933bf4877f 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,55 +1,56 @@ class Product < ApplicationRecord belongs_to :user belongs_to :category + has_many :reviews + + # validates :name, presence: true, + # uniqueness: { scope: :category } + # + # validates :price, presence: true + # + # validates :user_id, presence: true + # validates :stock, presence: true + # + # validates :category, presence: true, + # inclusion: { in: @categories } + # + # before_validation :fix_category + # + # def self.in_stock + # return Product.all.select {|prod| prod.stock >= 1} + # end + # + # def self.to_category_hash + # data = {} + # Category.each do |cat| + # data[cat] = by_category(cat) + # end + # return data + # end + # + # def self.by_category(category) + # category = category.singularize.downcase + # self.where(category: category).order(vote_count: :desc) + # end + # + # def self.to_merchant_hash + # data = {} + # Category.each do |cat| + # data[cat] = by_category(cat) + # end + # return data + # end + # + # def self.by_merchant(merchant) + # self.where(user: merchant).order(vote_count: :desc) + # end + # + # private + # def fix_category + # if self.category + # self.category = self.category.downcase.singularize + # end + # end - validates :name, presence :true, - uniqueness: { scope: :category } - - validates :price, presence :true - - validates :user_id, presence :true - validates :stock, presence :true - - validates :category, presence: true, - inclusion: { in: @categories } - - before_validation :fix_category - - def self.in_stock - return Product.all.select {|prod| prod.stock >= 1} - end - - def self.to_category_hash - data = {} - Category.each do |cat| - data[cat] = by_category(cat) - end - return data - end - - def self.by_category(category) - category = category.singularize.downcase - self.where(category: category).order(vote_count: :desc) - end - - def self.to_merchant_hash - data = {} - Category.each do |cat| - data[cat] = by_category(cat) - end - return data - end - - def self.by_merchant(merchant) - self.where(user: merchant).order(vote_count: :desc) - end - - private - def fix_category - if self.category - self.category = self.category.downcase.singularize - end - end - end end diff --git a/app/models/review.rb b/app/models/review.rb index b2cdc731fc..aa2cd4bd4d 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,8 +1,8 @@ class Review < ApplicationRecord belongs_to :product - validates :rating, presence :true - validates :product_id, presence :true - validates :name, presence :true + validates :rating, presence: true + validates :product_id, presence: true + validates :name, presence: true end diff --git a/app/models/user.rb b/app/models/user.rb index 379658a509..067b4f19c0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,3 @@ class User < ApplicationRecord + has_many :products end diff --git a/config/routes.rb b/config/routes.rb index ff6a894cd1..5b311b5d30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,6 @@ Rails.application.routes.draw do resources :orders, except: [:destroy] -<<<<<<< HEAD -======= - ->>>>>>> 5321bcb4f0fa6850e7efeb776d1e86c9c65f9868 get 'user/index' get 'user/new' get 'user/show' diff --git a/db/seeds.rb b/db/seeds.rb index cd457536c2..163c343d43 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -13,9 +13,9 @@ cate_list = ["book", "movie","album","furnitue","appliance"] -cate_list.each do |name| +cate_list.each do |cate| category = Category.new - category.name = name + category.name = cate successful = category.save if !successful category_failures << category @@ -28,11 +28,14 @@ puts "Added #{Category.count} category records" puts "#{category_failures.length} category failed to save" +user_name_list = ["lily", "Jessy", "Mary", "Michael", "Frank","Susan"] + user_failures = [] -10.times do - creator= Faker::Name.name + +user_name_list.each do |nam| + user = User.new - user.name = creator + user.name = nam successful = user.save if !successful user_failures << user @@ -46,14 +49,18 @@ puts "#{user_failures.length} users failed to save" product_failures = [] -10.times do |i| + +5.times do |i| + category = Category.find(i+1) + user = User.find(i+1) product_name = Faker::Name.name product = Product.new product.name = product_name - stock = 10 - product.price = i - product.category_id = (0..4).random - product.user_id = i + product.stock = 10 + product.description = "just a test" + product.price = 100 + product.category = category + product.user = user successful = product.save if !successful product_failures << product @@ -63,5 +70,5 @@ end end -puts "Added #{product.count} product records" +puts "Added #{Product.count} product records" puts "#{product_failures.length} products failed to save" From 91fabbb24cd42bcea8d5174740822a850ef1993e Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Thu, 18 Oct 2018 11:43:52 -0700 Subject: [PATCH 028/196] added an index html --- app/models/product.rb | 98 +++++++++++++++---------------- app/views/products/index.html.erb | 26 ++++++++ 2 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 app/views/products/index.html.erb diff --git a/app/models/product.rb b/app/models/product.rb index 933bf4877f..89c1a82c2f 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,56 +1,56 @@ class Product < ApplicationRecord belongs_to :user - belongs_to :category + belongs_to :categorys has_many :reviews - # validates :name, presence: true, - # uniqueness: { scope: :category } - # - # validates :price, presence: true - # - # validates :user_id, presence: true - # validates :stock, presence: true - # - # validates :category, presence: true, - # inclusion: { in: @categories } - # - # before_validation :fix_category - # - # def self.in_stock - # return Product.all.select {|prod| prod.stock >= 1} - # end - # - # def self.to_category_hash - # data = {} - # Category.each do |cat| - # data[cat] = by_category(cat) - # end - # return data - # end - # - # def self.by_category(category) - # category = category.singularize.downcase - # self.where(category: category).order(vote_count: :desc) - # end - # - # def self.to_merchant_hash - # data = {} - # Category.each do |cat| - # data[cat] = by_category(cat) - # end - # return data - # end - # - # def self.by_merchant(merchant) - # self.where(user: merchant).order(vote_count: :desc) - # end - # - # private - # def fix_category - # if self.category - # self.category = self.category.downcase.singularize - # end - # end + validates :name, presence: true, + uniqueness: { scope: :category } + + validates :price, presence: true + + validates :user_id, presence: true + validates :stock, presence: true + + validates :category, presence: true, + inclusion: { in: @categories } + + before_validation :fix_category + + def self.in_stock + return Product.all.select {|prod| prod.stock >= 1} + end + + def self.to_category_hash + data = {} + Category.each do |cat| + data[cat] = by_category(cat) + end + return data + end + + def self.by_category(category) + category = category.singularize.downcase + self.where(category: category).order(vote_count: :desc) + end + + def self.to_merchant_hash + data = {} + Category.each do |cat| + data[cat] = by_category(cat) + end + return data + end + + def self.by_merchant(merchant) + self.where(user: merchant).order(vote_count: :desc) + end + + private + def fix_category + if self.category + self.category = self.category.downcase.singularize + end + end end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..1063e930d9 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,26 @@ +

List of Products

+ + + +
+ + + + + + + + + + + <% @products.each do |product|%> + + + + + + + <%end%> + +
NameSellerCreated at
<%= link_to "#{product.title}", product_path(product.id) %><%= prodcut.user %><%= product.created_at %>
+
From c7d1da65b06258978141a405d0d07bff1b233f40 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 12:42:48 -0700 Subject: [PATCH 029/196] sessions controller added, omniauth methods switched to sessions --- app/assets/javascripts/sessions.js | 2 ++ app/assets/stylesheets/sessions.scss | 3 ++ app/controllers/application_controller.rb | 8 ++++++ app/controllers/sessions_controller.rb | 30 ++++++++++++++++++++ app/controllers/users_controller.rb | 30 -------------------- app/helpers/sessions_helper.rb | 2 ++ app/models/user.rb | 11 +++++++ app/views/layouts/application.html.erb | 10 +++---- app/views/{user => users}/destroy.html.erb | 0 app/views/{user => users}/edit.html.erb | 0 app/views/{user => users}/index.html.erb | 2 ++ app/views/{user => users}/new.html.erb | 0 app/views/{user => users}/not_found.html.erb | 0 app/views/{user => users}/show.html.erb | 0 app/views/{user => users}/update.html.erb | 0 config/routes.rb | 4 +-- test/controllers/sessions_controller_test.rb | 7 +++++ 17 files changed, 72 insertions(+), 37 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 rename app/views/{user => users}/destroy.html.erb (100%) rename app/views/{user => users}/edit.html.erb (100%) rename app/views/{user => users}/index.html.erb (79%) rename app/views/{user => users}/new.html.erb (100%) rename app/views/{user => users}/not_found.html.erb (100%) rename app/views/{user => users}/show.html.erb (100%) rename app/views/{user => users}/update.html.erb (100%) 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 09705d12ab..45521d82be 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,10 @@ class ApplicationController < ActionController::Base + before_action :find_user + + private + + def find_user + @current_user ||= session[:user_id] && User.find_by(id: session[:user_id]) + end + end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..cfa4e66044 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,30 @@ +class SessionsController < ApplicationController + + def create + auth_hash = request.env['omniauth.auth'] + + @user = User.find_by(uid: auth_hash[:uid], provider: 'github') + if @user + flash[:success] = "Welcome back #{@user.name}" + else + #try to make a new user + @user = User.build_from_github(auth_hash) + if @user.save + flash[:success] = "Welcome #{@user.name}" + else + flash[:error] = "Could not create account: #{@user.errors.messages}" + redirect_to users_path + return + end + end + session[:user_id] = @user.id + redirect_to users_path + end + + def destroy + session[:user_id] = nil + flash[:success] = "Bye!" + + redirect_to users_path + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fdcc9e7a4a..1148730373 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,36 +10,6 @@ def new @user = User.new end - def create - #if merchant checked, type is filled (in forms), otherwise it is not -- passive method - - auth_hash = request.env['omniauth.auth'] - user = User.find_by(uid: auth_hash[:uid], provider: 'github') - if user - # User was found in the database - flash[:success] = "Logged in as returning user #{user.name}" - else - # render :new - # User doesn't match anything in the DB - # TODO: Attempt to create a new user - end - - # session[:user_id] = user.id - redirect_to users_path - end - # @user = User.new(user_params) - # if @user.save - # flash[:success] = 'Success' - # redirect_to root_path - # else - # flash.now[:error] = 'No success' - # @user.errors.messages.each do |field, messages| - # flash.now[field] = messages - # end - # end - - - def show 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 379658a509..8995549f0e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,13 @@ class User < ApplicationRecord + + def self.build_from_github(auth_hash) + user = User.new + user.uid = auth_hash[:uid] + user.provider = 'github' + user.name = auth_hash['info']['name'] + user.email = auth_hash['info']['email'] + + # Note that the user has not been saved + return user + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 25310e9a94..f982a19b2f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,11 +10,11 @@ - <% if session[:user_id] %> - <%= link_to "Log out", logout_path, method: "delete" %> -<% else %> - <%= link_to "Login with Github", "/auth/github" %> -<% end %> + <% if @current_user %> + <%= link_to "Log out" %> + <% else %> + <%= link_to "Login with Github", "/auth/github" %> + <% end %> <%= yield %> diff --git a/app/views/user/destroy.html.erb b/app/views/users/destroy.html.erb similarity index 100% rename from app/views/user/destroy.html.erb rename to app/views/users/destroy.html.erb diff --git a/app/views/user/edit.html.erb b/app/views/users/edit.html.erb similarity index 100% rename from app/views/user/edit.html.erb rename to app/views/users/edit.html.erb diff --git a/app/views/user/index.html.erb b/app/views/users/index.html.erb similarity index 79% rename from app/views/user/index.html.erb rename to app/views/users/index.html.erb index c825aaffc5..184f0620f4 100644 --- a/app/views/user/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,2 +1,4 @@

User#index

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

+ +This is writing. diff --git a/app/views/user/new.html.erb b/app/views/users/new.html.erb similarity index 100% rename from app/views/user/new.html.erb rename to app/views/users/new.html.erb diff --git a/app/views/user/not_found.html.erb b/app/views/users/not_found.html.erb similarity index 100% rename from app/views/user/not_found.html.erb rename to app/views/users/not_found.html.erb diff --git a/app/views/user/show.html.erb b/app/views/users/show.html.erb similarity index 100% rename from app/views/user/show.html.erb rename to app/views/users/show.html.erb diff --git a/app/views/user/update.html.erb b/app/views/users/update.html.erb similarity index 100% rename from app/views/user/update.html.erb rename to app/views/users/update.html.erb diff --git a/config/routes.rb b/config/routes.rb index 789cb6c074..2804d69b14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do - get "/auth/:provider/callback", to: "users#create" - # delete "/logout", to: "sessions#destroy", as: "logout" + get "/auth/:provider/callback", to: "sessions#create" + delete "/logout", to: "sessions#destroy", as: "logout" resources :users resources :orders, except: [:destroy] diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..c2632a720b --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe SessionsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From 57d37bee5f8015c0cd22f86f0dcbd4db9cce83e5 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Thu, 18 Oct 2018 12:52:39 -0700 Subject: [PATCH 030/196] fixed the seeds and added a index --- Gemfile.lock | 7 ++- app/controllers/products_controller.rb | 6 +-- app/models/product.rb | 70 +++++++++++--------------- app/views/products/index.html.erb | 4 +- db/schema.rb | 6 +-- db/seeds.rb | 18 ++++--- 6 files changed, 53 insertions(+), 58 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8da1398fc9..7b5037cb15 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,8 @@ GEM execjs (2.7.0) faker (1.9.1) i18n (>= 0.7) + faraday (0.15.3) + multipart-post (>= 1.2, < 3) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -274,11 +276,8 @@ DEPENDENCIES byebug capybara (>= 2.15) chromedriver-helper -<<<<<<< HEAD - faker -======= dotenv-rails ->>>>>>> fa260d3c7645cae5a1476e7e60804b62b10d1ba2 + faker guard guard-minitest jbuilder (~> 2.5) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 7e3e54357c..dd6a64d98a 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -2,9 +2,9 @@ class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :destroy] def index - @products = Product.in_stock - @products_by_category = @products.product_by_category - @pruducts_by_merchant = @products.product_by_merchant + @products = Product.all + @products_by_category = Product.to_category_hash.in_stock + @pruducts_by_merchant = Product.to_merchant_hash.in_stock end diff --git a/app/models/product.rb b/app/models/product.rb index 89c1a82c2f..3e22b6cb9c 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,6 +1,6 @@ class Product < ApplicationRecord belongs_to :user - belongs_to :categorys + belongs_to :category has_many :reviews validates :name, presence: true, @@ -12,45 +12,35 @@ class Product < ApplicationRecord validates :stock, presence: true validates :category, presence: true, - inclusion: { in: @categories } - - before_validation :fix_category - - def self.in_stock - return Product.all.select {|prod| prod.stock >= 1} - end - - def self.to_category_hash - data = {} - Category.each do |cat| - data[cat] = by_category(cat) - end - return data - end - - def self.by_category(category) - category = category.singularize.downcase - self.where(category: category).order(vote_count: :desc) - end - - def self.to_merchant_hash - data = {} - Category.each do |cat| - data[cat] = by_category(cat) - end - return data - end - - def self.by_merchant(merchant) - self.where(user: merchant).order(vote_count: :desc) - end - - private - def fix_category - if self.category - self.category = self.category.downcase.singularize - end - end + inclusion: { in: Category.all } + + + + # + # + # def self.to_category_hash + # data = {} + # Category.all.each do |cat| + # data[cat] = by_category(cat) + # end + # return data + # end + # + # def self.by_category(category) + # self.where(category: category) + # end + # + # def self.to_merchant_hash + # data = {} + # Merchant.all.each do |user| + # data[user] = by_merchant(user) + # end + # return data + # end + # + # def self.by_merchant(merchant) + # self.where(user: merchant) + # end end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 1063e930d9..0367ce6628 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -15,8 +15,8 @@ <% @products.each do |product|%> - <%= link_to "#{product.title}", product_path(product.id) %> - <%= prodcut.user %> + <%= link_to "#{product.name}", product_path(product.id) %> + <%= product.user %> <%= product.created_at %> diff --git a/db/schema.rb b/db/schema.rb index 36e5bb4dec..9b513fc42b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -15,13 +15,13 @@ # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "merchants", force: :cascade do |t| + create_table "categories", force: :cascade do |t| + t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false end - create_table "categories", force: :cascade do |t| - t.string "name" + create_table "merchants", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/db/seeds.rb b/db/seeds.rb index 163c343d43..442850ca85 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,6 +8,7 @@ require 'faker' require 'date' +require 'pry' category_failures = [] @@ -28,14 +29,16 @@ puts "Added #{Category.count} category records" puts "#{category_failures.length} category failed to save" -user_name_list = ["lily", "Jessy", "Mary", "Michael", "Frank","Susan"] -user_failures = [] -user_name_list.each do |nam| +user_failures = [] +5.times do |i| + user_name = Faker::Name.name user = User.new - user.name = nam + user.name = user_name + user.uid = rand(10) + user.provider = "github" successful = user.save if !successful user_failures << user @@ -51,8 +54,9 @@ product_failures = [] 5.times do |i| - category = Category.find(i+1) - user = User.find(i+1) + category_list = Category.all + category = category_list.sample + user = User.all.first product_name = Faker::Name.name product = Product.new product.name = product_name @@ -61,7 +65,9 @@ product.price = 100 product.category = category product.user = user + product.photo_url = "https://pixfeeds.com/images/33/609988/1200-609988-483425824.jpg" successful = product.save + if !successful product_failures << product puts "Failed to save product: #{product.inspect}" # so user can check that work to see what happened From ccb2f936999509acf0702b96687389e538154024 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 13:11:13 -0700 Subject: [PATCH 031/196] user model method added ; --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index 8995549f0e..92d9848457 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord + has_many :products def self.build_from_github(auth_hash) user = User.new From df42b2c2ce7b5c774c938f18d918936b06a3613c Mon Sep 17 00:00:00 2001 From: Jessie <36865499+jessiezhang2017@users.noreply.github.com> Date: Thu, 18 Oct 2018 13:15:16 -0700 Subject: [PATCH 032/196] Update products_controller.rb --- app/controllers/products_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index dd6a64d98a..d9806debb9 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -3,8 +3,7 @@ class ProductsController < ApplicationController def index @products = Product.all - @products_by_category = Product.to_category_hash.in_stock - @pruducts_by_merchant = Product.to_merchant_hash.in_stock + end From 3f977692ea58a110c8f23426a28227f5db116229 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 13:49:33 -0700 Subject: [PATCH 033/196] merged conflicts --- config/initializers/omniauth.rb | 4 ---- config/routes.rb | 5 ----- 2 files changed, 9 deletions(-) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index da1ffff0dd..fd4416122a 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,7 +1,3 @@ -<<<<<<< HEAD -# config/initializers/omniauth.rb -======= ->>>>>>> leanne-feature-merchant Rails.application.config.middleware.use OmniAuth::Builder do provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" end diff --git a/config/routes.rb b/config/routes.rb index 9e3f6658dc..3d742ffae3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,9 +6,4 @@ resources :products resources :orders, except: [:destroy] -<<<<<<< HEAD - -======= ->>>>>>> fa260d3c7645cae5a1476e7e60804b62b10d1ba2 - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From ddd4491b163c3cf7c3cc2eea02a25a335db3a170 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 14:13:17 -0700 Subject: [PATCH 034/196] can recognize current user --- app/controllers/application_controller.rb | 2 +- app/controllers/sessions_controller.rb | 1 + app/controllers/users_controller.rb | 2 +- app/helpers/application_helper.rb | 6 ++++++ app/views/layouts/application.html.erb | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 45521d82be..c63ff874a5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base private def find_user - @current_user ||= session[:user_id] && User.find_by(id: session[:user_id]) + @current_user ||= User.find_by(id: session[:user_id]) end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index cfa4e66044..c6bc7d7e23 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,6 +11,7 @@ def create @user = User.build_from_github(auth_hash) if @user.save flash[:success] = "Welcome #{@user.name}" + #would you like to register as a merchant? else flash[:error] = "Could not create account: #{@user.errors.messages}" redirect_to users_path diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1148730373..cf2f517446 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -39,6 +39,6 @@ def find_user end def user_params - return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip) + return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip, :provider) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945c..0e97d682ad 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,8 @@ module ApplicationHelper + +private + + def current_user + @current_user ||= User.find_by(id: session[:user_id]) + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f982a19b2f..6599170ea5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,7 +10,7 @@ - <% if @current_user %> + <% if current_user %> <%= link_to "Log out" %> <% else %> <%= link_to "Login with Github", "/auth/github" %> From 283ae6b103d6a29a61ae2db873b5a81e6e6eb0ab Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 18 Oct 2018 14:31:50 -0700 Subject: [PATCH 035/196] fixed application.html - flash messages work, log in is now in nav tags --- app/controllers/sessions_controller.rb | 8 ++++---- app/controllers/users_controller.rb | 11 ----------- app/views/layouts/application.html.erb | 23 +++++++++++++++++++++-- config/routes.rb | 1 + 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index c6bc7d7e23..18f41bfd03 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,7 @@ class SessionsController < ApplicationController def create auth_hash = request.env['omniauth.auth'] - @user = User.find_by(uid: auth_hash[:uid], provider: 'github') + @user = User.find_by(uid: auth_hash[:uid], name: auth_hash[:name], provider: 'github') if @user flash[:success] = "Welcome back #{@user.name}" else @@ -14,18 +14,18 @@ def create #would you like to register as a merchant? else flash[:error] = "Could not create account: #{@user.errors.messages}" - redirect_to users_path + redirect_to root_path return end end session[:user_id] = @user.id - redirect_to users_path + redirect_to root_path end def destroy session[:user_id] = nil flash[:success] = "Bye!" - redirect_to users_path + redirect_to root_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cf2f517446..6b2af2bf79 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,4 @@ class UsersController < ApplicationController - before_action :find_user #before_action is type merchant? def index @@ -28,16 +27,6 @@ def destroy private - def find_user - id = params[:id].to_i - @user = User.find_by(id: id) - - if @user.nil? - flash.now[:warning] = "Imposter!" - # render :not_found - end - end - def user_params return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip, :provider) end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6599170ea5..fa6d6ea4c3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,11 +10,30 @@ + +
+
+ <%flash.each do |name, message|%> + <% if message.class == Array %> + <%message.each do |msg|%> + + <%end%> + <%else%> + + <%end%> + <%end%> +
+ <%= yield %> +
diff --git a/config/routes.rb b/config/routes.rb index 3d742ffae3..28fc243729 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + root "users#index" get "/auth/:provider/callback", to: "sessions#create" delete "/logout", to: "sessions#destroy", as: "logout" From f0e9121f503d6ef36a545a6c9d06477e3fcef81e Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 15:37:14 -0700 Subject: [PATCH 036/196] Remove non-working migration to add CC columns --- db/migrate/20181017220936_add_cc_columns_to_user.rb | 7 ------- db/schema.rb | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 db/migrate/20181017220936_add_cc_columns_to_user.rb diff --git a/db/migrate/20181017220936_add_cc_columns_to_user.rb b/db/migrate/20181017220936_add_cc_columns_to_user.rb deleted file mode 100644 index 2f5a2890f7..0000000000 --- a/db/migrate/20181017220936_add_cc_columns_to_user.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddCcColumnsToUser < ActiveRecord::Migration[5.2] - def change - create_column :users, :cc_csv, :integer - create_column :users, :cc_exp, :date - create_column :users, :bill_zip, :integer - end -end diff --git a/db/schema.rb b/db/schema.rb index 9b513fc42b..ba906711f6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -21,6 +21,9 @@ t.datetime "updated_at", null: false end + create_table "columns_for_user_tables", force: :cascade do |t| + end + create_table "merchants", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false From 6676ac2af367e1a149ecc1b7d6de8ef0af5c30d4 Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 15:39:03 -0700 Subject: [PATCH 037/196] Remove unused table from schema --- db/migrate/20181018223725_remove_extra_table.rb | 5 +++++ db/schema.rb | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20181018223725_remove_extra_table.rb diff --git a/db/migrate/20181018223725_remove_extra_table.rb b/db/migrate/20181018223725_remove_extra_table.rb new file mode 100644 index 0000000000..34038b84e2 --- /dev/null +++ b/db/migrate/20181018223725_remove_extra_table.rb @@ -0,0 +1,5 @@ +class RemoveExtraTable < ActiveRecord::Migration[5.2] + def change + drop_table :columns_for_user_tables + end +end diff --git a/db/schema.rb b/db/schema.rb index ba906711f6..0aef960899 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_172139) do +ActiveRecord::Schema.define(version: 2018_10_18_223725) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,9 +21,6 @@ t.datetime "updated_at", null: false end - create_table "columns_for_user_tables", force: :cascade do |t| - end - create_table "merchants", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false From b561d0c85d6ef264c55ac69ce49e034e5d0bf8df Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 15:49:32 -0700 Subject: [PATCH 038/196] Remove merge conflict markers from routes.rb --- config/routes.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index f336f06970..42af8f0341 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,11 +7,7 @@ resources :products resources :orders, except: [:destroy] -<<<<<<< HEAD -======= - resources :category, only: [:new, :create] # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html ->>>>>>> 15e082d8069160141aa6a3cb60f5180ca973f182 end From d78053860f199a7852a6bfc7e6af576ebe1a0e0e Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 17:01:21 -0700 Subject: [PATCH 039/196] Fixed formatting in application view --- app/views/layouts/application.html.erb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index fa6d6ea4c3..56848a7170 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,20 +19,20 @@
- <%flash.each do |name, message|%> - <% if message.class == Array %> - <%message.each do |msg|%> + <%flash.each do |name, message|%> + <% if message.class == Array %> + <%message.each do |msg|%> + + <%end%> + <%else%> <%end%> - <%else%> - - <%end%> - <%end%> -
+ <%end%> + <%= yield %>
From 31e4b4257f248bcdd0500b71fb70f4c81710f1fc Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 17:17:05 -0700 Subject: [PATCH 040/196] Added basic navigation for testing purposes --- app/assets/javascripts/home.js | 2 ++ app/assets/stylesheets/home.scss | 3 +++ app/controllers/home_controller.rb | 4 ++++ app/controllers/orders_controller.rb | 6 ++++++ app/helpers/home_helper.rb | 2 ++ app/views/home/index.html.erb | 1 + app/views/layouts/application.html.erb | 15 ++++++++++----- app/views/orders/cart.html.erb | 1 + app/views/orders/checkout.html.erb | 1 + config/routes.rb | 8 +++++--- test/controllers/home_controller_test.rb | 9 +++++++++ 11 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/home.js create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/orders/cart.html.erb create mode 100644 app/views/orders/checkout.html.erb create mode 100644 test/controllers/home_controller_test.rb diff --git a/app/assets/javascripts/home.js b/app/assets/javascripts/home.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/home.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/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000000..7131aac4df --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Home 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/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000000..95f29929ca --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index f8cb7f227f..e517ccd868 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -16,4 +16,10 @@ def edit def update end + + def cart + end + + def checkout + end end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000000..23de56ac60 --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000000..65d2b04a3e --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1 @@ +

Welcome to Sovietski!

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 56848a7170..929732e2bd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,11 +11,16 @@
diff --git a/app/views/orders/cart.html.erb b/app/views/orders/cart.html.erb new file mode 100644 index 0000000000..babd9fe34a --- /dev/null +++ b/app/views/orders/cart.html.erb @@ -0,0 +1 @@ +This is the shopping cart! diff --git a/app/views/orders/checkout.html.erb b/app/views/orders/checkout.html.erb new file mode 100644 index 0000000000..ff339cf785 --- /dev/null +++ b/app/views/orders/checkout.html.erb @@ -0,0 +1 @@ +This is the checkout page. diff --git a/config/routes.rb b/config/routes.rb index 42af8f0341..23640bb2d6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,15 @@ Rails.application.routes.draw do - root "users#index" + root "home#index" get "/auth/:provider/callback", to: "sessions#create" delete "/logout", to: "sessions#destroy", as: "logout" resources :users resources :products - resources :orders, except: [:destroy] - resources :category, only: [:new, :create] + resources :orders, except: [:destroy] + get "/cart", to: "orders#cart", as: "cart" + get "/checkout", to: "orders#checkout", as: "checkout" + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000000..e29fcdf5ba --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe HomeController do + it "should get index" do + get home_index_url + value(response).must_be :success? + end + +end From aefae420df157d32c67e749d183035dfd548a9c4 Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 18:11:08 -0700 Subject: [PATCH 041/196] Created form partial for use on product show page --- app/assets/javascripts/order_products.js | 2 ++ app/assets/stylesheets/order_products.scss | 3 +++ app/controllers/application_controller.rb | 13 +++++++++++++ app/controllers/order_products_controller.rb | 2 ++ app/controllers/products_controller.rb | 4 ++-- app/helpers/order_products_helper.rb | 2 ++ app/models/order_item.rb | 2 -- app/models/order_product.rb | 2 ++ app/views/order_products/_form.html.erb | 12 ++++++++++++ app/views/products/show.html.erb | 2 ++ test/controllers/order_products_controller_test.rb | 7 +++++++ 11 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/order_products.js create mode 100644 app/assets/stylesheets/order_products.scss create mode 100644 app/controllers/order_products_controller.rb create mode 100644 app/helpers/order_products_helper.rb delete mode 100644 app/models/order_item.rb create mode 100644 app/models/order_product.rb create mode 100644 app/views/order_products/_form.html.erb create mode 100644 test/controllers/order_products_controller_test.rb diff --git a/app/assets/javascripts/order_products.js b/app/assets/javascripts/order_products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order_products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/order_products.scss b/app/assets/stylesheets/order_products.scss new file mode 100644 index 0000000000..4e38cdae9b --- /dev/null +++ b/app/assets/stylesheets/order_products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderProducts 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 c63ff874a5..77819d8063 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,18 @@ class ApplicationController < ActionController::Base + protect_from_forgery with: :exception + before_action :find_user + before_action :current_order + + def current_order + if session[:order_id] + @current_order = Order.find_by(id: session[:order_id].to_i) + else + @current_order = Order.create(status: "pending") + session[:order_id] = @current_order.id + end + return @current_order + end private diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb new file mode 100644 index 0000000000..8fc2a16bfe --- /dev/null +++ b/app/controllers/order_products_controller.rb @@ -0,0 +1,2 @@ +class OrderProductsController < ApplicationController +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index d9806debb9..988a2c7d8b 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -3,12 +3,12 @@ class ProductsController < ApplicationController def index @products = Product.all - + end def show - + @op = current_order.order_products.new end diff --git a/app/helpers/order_products_helper.rb b/app/helpers/order_products_helper.rb new file mode 100644 index 0000000000..fb2828b523 --- /dev/null +++ b/app/helpers/order_products_helper.rb @@ -0,0 +1,2 @@ +module OrderProductsHelper +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb deleted file mode 100644 index acc6099fd0..0000000000 --- a/app/models/order_item.rb +++ /dev/null @@ -1,2 +0,0 @@ -class OrderItem < ApplicationRecord -end diff --git a/app/models/order_product.rb b/app/models/order_product.rb new file mode 100644 index 0000000000..5a1d864dff --- /dev/null +++ b/app/models/order_product.rb @@ -0,0 +1,2 @@ +class OrderProduct < ApplicationRecord +end diff --git a/app/views/order_products/_form.html.erb b/app/views/order_products/_form.html.erb new file mode 100644 index 0000000000..54e7459655 --- /dev/null +++ b/app/views/order_products/_form.html.erb @@ -0,0 +1,12 @@ +
+ <%= form_with model: @op, class: "form", locals: true do |f|%> +

<%= "Product Name" %>

+ +
+ <%= f.label :quantity %> + <%= f.select :quantity, [1, 2, 3, 4, 5], {}, class: "form-control" %> +
+ + <%= f.submit button_title, class: "btn btn-primary" %> + <% end %> +
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index eae26663ce..e09aa416e9 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1 +1,3 @@

Product Show Page

+ +<%= render partial: "form", locals: { button_title: "Add to cart" } %> diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb new file mode 100644 index 0000000000..868bc2929c --- /dev/null +++ b/test/controllers/order_products_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrderProductsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From 76402d1174417e256bbe9b0527e4b726b3ebcd42 Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 19:50:29 -0700 Subject: [PATCH 042/196] Basic functionality to add products to cart now working --- app/controllers/application_controller.rb | 2 +- app/controllers/order_products_controller.rb | 15 +++++++++++ app/models/order.rb | 28 ++++++++++++++++++++ app/models/order_product.rb | 11 ++++++++ app/views/order_products/_form.html.erb | 2 ++ app/views/orders/cart.html.erb | 6 ++++- app/views/products/show.html.erb | 2 +- config/routes.rb | 1 + 8 files changed, 64 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 77819d8063..55fc232d67 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,7 @@ def current_order if session[:order_id] @current_order = Order.find_by(id: session[:order_id].to_i) else - @current_order = Order.create(status: "pending") + @current_order = Order.create(status: "shopping") session[:order_id] = @current_order.id end return @current_order diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 8fc2a16bfe..8e6c6ac6e9 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -1,2 +1,17 @@ +require 'pry' + class OrderProductsController < ApplicationController + + def create + product = Product.find_by(id: params[:order_product][:product_id].to_i) + quantity = params[:order_product][:quantity].to_i + + @current_order.add_product(product, quantity) + # check quantity against stock? + + redirect_to cart_path + end + + + end diff --git a/app/models/order.rb b/app/models/order.rb index 10281b3450..43c6a09bc1 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,30 @@ class Order < ApplicationRecord + belongs_to :user + has_many :order_products, dependent: :destroy + + validates :user, presence: true + validates :order_products, presence: true + validates :status, inclusion: { in: %w(shopping paid shipped), + message: "%{value} is not a valid order status" } + + def total + return order_products.map { |op| op.valid? ? op.subtotal : 0 }.sum + end + + def add_product(product, quantity) + # check if product is already in cart + current_op = order_products.find_by(product_id: product.id) + + if current_op # if so, edit quantity within existing orderproduct + current_op.quantity += quantity + else # if not, add new orderproduct + current_op = order_products.new(product_id: product.id, quantity: quantity, order_id: self.id) + end + + if current_op.save + # success stuff here + else + # error stuff here + end + end end diff --git a/app/models/order_product.rb b/app/models/order_product.rb index 5a1d864dff..7e21bcc00e 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -1,2 +1,13 @@ class OrderProduct < ApplicationRecord + belongs_to :order + belongs_to :product + + validates :quantity, presence: true + validates :quantity, numericality: { only_integer: true, greater_than: 0 } + validates :order, presence: true + validates :product, presence: true + + def subtotal + return product.price * product.quantity + end end diff --git a/app/views/order_products/_form.html.erb b/app/views/order_products/_form.html.erb index 54e7459655..f7f97cecef 100644 --- a/app/views/order_products/_form.html.erb +++ b/app/views/order_products/_form.html.erb @@ -7,6 +7,8 @@ <%= f.select :quantity, [1, 2, 3, 4, 5], {}, class: "form-control" %> + <%= f.hidden_field :product_id, value: @product.id %> + <%= f.submit button_title, class: "btn btn-primary" %> <% end %>
diff --git a/app/views/orders/cart.html.erb b/app/views/orders/cart.html.erb index babd9fe34a..24f28508bb 100644 --- a/app/views/orders/cart.html.erb +++ b/app/views/orders/cart.html.erb @@ -1 +1,5 @@ -This is the shopping cart! +

This is the shopping cart!

+ +<% @current_order.order_products.each do |op| %> +

<%= "Product ID: #{op.product_id}, Quantity: #{op.quantity}" %>

+<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index e09aa416e9..96ac80618e 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,3 +1,3 @@

Product Show Page

-<%= render partial: "form", locals: { button_title: "Add to cart" } %> +<%= render partial: "order_products/form", locals: { button_title: "Add to cart" } %> diff --git a/config/routes.rb b/config/routes.rb index 23640bb2d6..c204845109 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ resources :products resources :category, only: [:new, :create] + resources :order_products resources :orders, except: [:destroy] get "/cart", to: "orders#cart", as: "cart" get "/checkout", to: "orders#checkout", as: "checkout" From 6622b4a826fc6891c080b8db43bde04a105c6760 Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 20:27:23 -0700 Subject: [PATCH 043/196] Added shells of tests for order and orderproduct validations, relationships, and model methods --- app/models/order.rb | 2 +- test/fixtures/order_items.yml | 7 ----- test/fixtures/order_products.yml | 11 +++++++ test/fixtures/orders.yml | 8 ++---- test/fixtures/products.yml | 4 +-- test/fixtures/users.yml | 4 +-- test/models/order_item_test.rb | 9 ------ test/models/order_product_test.rb | 40 ++++++++++++++++++++++++++ test/models/order_test.rb | 48 +++++++++++++++++++++++++++++-- 9 files changed, 105 insertions(+), 28 deletions(-) delete mode 100644 test/fixtures/order_items.yml create mode 100644 test/fixtures/order_products.yml delete mode 100644 test/models/order_item_test.rb create mode 100644 test/models/order_product_test.rb diff --git a/app/models/order.rb b/app/models/order.rb index 43c6a09bc1..3da487e025 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -3,7 +3,7 @@ class Order < ApplicationRecord has_many :order_products, dependent: :destroy validates :user, presence: true - validates :order_products, presence: true + validates :order_products, presence: true, uniqueness: true validates :status, inclusion: { in: %w(shopping paid shipped), message: "%{value} is not a valid order status" } diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml deleted file mode 100644 index 6609c00aa6..0000000000 --- a/test/fixtures/order_items.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - quantity: 1 - -two: - quantity: 1 diff --git a/test/fixtures/order_products.yml b/test/fixtures/order_products.yml new file mode 100644 index 0000000000..66fd7291ea --- /dev/null +++ b/test/fixtures/order_products.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +shirts: + quantity: 1 + order: shopping_order + product: shirt + +dresses: + quantity: 2 + order: shopping_order + product: dress diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index 24de587694..303d8564e8 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -1,7 +1,5 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - status: - -two: - status: +shopping_order: + status: "shopping" + user: user1 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 845183c94e..43917a7ba1 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -1,6 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: +shirt: user: one name: MyString price: 1.5 @@ -9,7 +9,7 @@ one: stock: 1 photo_url: MyString -two: +dress: user: two name: MyString price: 1.5 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index dc3ee79b5d..7fb0f760bb 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -4,8 +4,8 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: {} +user1: {} # column: value # -two: {} +user2: {} # column: value diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb deleted file mode 100644 index 19a9bf8f58..0000000000 --- a/test/models/order_item_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -describe OrderItem do - let(:order_item) { OrderItem.new } - - it "must be valid" do - value(order_item).must_be :valid? - end -end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb new file mode 100644 index 0000000000..25eb7407ba --- /dev/null +++ b/test/models/order_product_test.rb @@ -0,0 +1,40 @@ +require "test_helper" + +describe OrderProduct do + let(:shirts) { order_products(:shirts) } + let(:dresses) { order_products(:dresses) } + + it "must be valid" do + value(shirts).must_be :valid? + end + + describe "relationships" do + it "must belong to an order" do + end + + it "must belong to a product" do + end + end + + describe "validations" do + it "must have a quantity" do + end + + it "must have an integer quantity greater than 0" do + end + + it "must have an order" do + end + + it "must have a product" do + end + end + + describe "subtotal" do + it "must return a float" do + end + + it "must return the cost of the product times its quantity" do + end + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb index df80f10fb6..9cbddc2753 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,9 +1,53 @@ require "test_helper" describe Order do - let(:order) { Order.new } + let(:shopping_order) { orders(:shopping_order) } it "must be valid" do - value(order).must_be :valid? + value(shopping_order).must_be :valid? + end + + describe "relationships" do + it "belongs to a user" do + end + + it "has many order products" do + end + end + + describe "validations" do + it "must have a user" do + end + + it "must have at least one order product" do + end + + it "must have only unique order products" do + end + + it "must have a status" do + end + + it "must have a status equal to shopping, paid, or shipped" do + end + end + + describe "total" do + it "returns the sum of all of the order's order product subtotals" do + end + + it "returns a float" do + end + end + + describe "add_product" do + it "adds an order product to the cart" do + end + + it "updates the existing order product quantity if product already exists in cart" do + end + + it "creates a new order product in the cart if product not already on order" do + end end end From 846f2a952ad023454ceb29688d6f7878fa68c2c0 Mon Sep 17 00:00:00 2001 From: jackie Date: Thu, 18 Oct 2018 22:32:15 -0700 Subject: [PATCH 044/196] Implemented some tests for order and orderproduct models, skipped tests are failing and need work --- app/models/order_product.rb | 2 +- test/fixtures/categories.yml | 8 +- test/fixtures/{buyers.yml => merchants.yml} | 12 ++- test/fixtures/products.yml | 10 +- test/fixtures/reviews.yml | 2 - test/fixtures/users.yml | 12 ++- test/models/buyer_test.rb | 9 -- test/models/merchant_test.rb | 9 ++ test/models/order_product_test.rb | 105 +++++++++++++++++++- test/models/order_test.rb | 99 +++++++++++++++++- 10 files changed, 234 insertions(+), 34 deletions(-) rename test/fixtures/{buyers.yml => merchants.yml} (80%) delete mode 100644 test/models/buyer_test.rb create mode 100644 test/models/merchant_test.rb diff --git a/app/models/order_product.rb b/app/models/order_product.rb index 7e21bcc00e..80c93d3206 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -8,6 +8,6 @@ class OrderProduct < ApplicationRecord validates :product, presence: true def subtotal - return product.price * product.quantity + return product.price * quantity end end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml index 56066c68af..d3d183377b 100644 --- a/test/fixtures/categories.yml +++ b/test/fixtures/categories.yml @@ -1,7 +1,7 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - name: MyString +catgory1: + name: "category 1" -two: - name: MyString +category2: + name: "category 2" diff --git a/test/fixtures/buyers.yml b/test/fixtures/merchants.yml similarity index 80% rename from test/fixtures/buyers.yml rename to test/fixtures/merchants.yml index dc3ee79b5d..8c2ed25c29 100644 --- a/test/fixtures/buyers.yml +++ b/test/fixtures/merchants.yml @@ -4,8 +4,10 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: {} -# column: value -# -two: {} -# column: value +one: + uid: 789 + provider: 'github' + +two: + uid: 100 + provider: 'github' diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 43917a7ba1..9d7aaa6336 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -4,8 +4,8 @@ shirt: user: one name: MyString price: 1.5 - category: MyString - description: MyString + category: category1 + description: "a nice shirt" stock: 1 photo_url: MyString @@ -13,7 +13,7 @@ dress: user: two name: MyString price: 1.5 - category: MyString - description: MyString - stock: 1 + category: category1 + description: "a nice dress" + stock: 5 photo_url: MyString diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml index 5ecb4bc68f..4cc862bcbf 100644 --- a/test/fixtures/reviews.yml +++ b/test/fixtures/reviews.yml @@ -3,11 +3,9 @@ one: product: one rating: 1 - name: MyString comment: MyString two: product: two rating: 1 - name: MyString comment: MyString diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 7fb0f760bb..46f9bf9290 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -4,8 +4,10 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -user1: {} -# column: value -# -user2: {} -# column: value +user1: + uid: 123 + provider: 'github' + +user2: + uid: 456 + provider: 'github' diff --git a/test/models/buyer_test.rb b/test/models/buyer_test.rb deleted file mode 100644 index 4dc3a78236..0000000000 --- a/test/models/buyer_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -describe Buyer do - let(:buyer) { Buyer.new } - - it "must be valid" do - value(buyer).must_be :valid? - end -end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..1cc99d985f --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Merchant do + let(:merchant) { Merchant.new } + + it "must be valid" do + value(merchant).must_be :valid? + end +end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index 25eb7407ba..0acbc8c158 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -8,33 +8,136 @@ value(shirts).must_be :valid? end + it 'has required fields' do + fields = [:quantity, :product_id, :order_id] + + fields.each do |field| + expect(shirts).must_respond_to field + end + end + describe "relationships" do it "must belong to an order" do + # Arrange is done with let + + # Act + order = shirts.order + + # Assert + expect(shirts).must_be_instance_of OrderProduct + expect(order).must_be_instance_of Order end it "must belong to a product" do + # Arrange is done with let + + # Act + product = shirts.product + + # Assert + expect(shirts).must_be_instance_of OrderProduct + expect(product).must_be_instance_of Product end end describe "validations" do it "must have a quantity" do + # Arrange + shirts.quantity = nil + + # Act + valid = shirts.valid? + + # Assert + expect(valid).must_equal false + expect(shirts.errors.messages).must_include :quantity + expect(shirts.errors.messages[:quantity]).must_include "can't be blank", "is not a number" + + # Rearrange + shirts.quantity = 2 + + # Re-Act + valid = shirts.valid? + + # Reassert + expect(valid).must_equal true end - it "must have an integer quantity greater than 0" do + it "must have an integer quantity greater than or equal to 1" do + # Arrange done with let + + # Act + qt = shirts.quantity + + # Assert + expect(qt).must_be_instance_of Integer + expect(qt).must_be :>=, 1 end it "must have an order" do + # Arrange + shirts.order = nil + + # Act + valid = shirts.valid? + + # Assert + expect(valid).must_equal false + expect(shirts.errors.messages).must_include :order + expect(shirts.errors.messages[:order]).must_include "can't be blank", "must exist" + + # Rearrange + shirts.order = orders(:shopping_order) + + # Re-Act + valid = shirts.valid? + + # Reassert + expect(valid).must_equal true end it "must have a product" do + # Arrange + shirts.product = nil + + # Act + valid = shirts.valid? + + # Assert + expect(valid).must_equal false + expect(shirts.errors.messages).must_include :product + expect(shirts.errors.messages[:product]).must_include "can't be blank", "must exist" + + # Rearrange + shirts.product = products(:shirt) + + # Re-Act + valid = shirts.valid? + + # Reassert + expect(valid).must_equal true end end describe "subtotal" do it "must return a float" do + # Arrange done with let + + # Act + result = dresses.subtotal + + # Assert + expect(result).must_be_instance_of Float end it "must return the cost of the product times its quantity" do + # Arrange done with let + + # Act + result = dresses.subtotal + + # Assert + expect(result).must_equal dresses.quantity * products(:dress).price end end end diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 9cbddc2753..349d46446d 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -4,39 +4,134 @@ let(:shopping_order) { orders(:shopping_order) } it "must be valid" do + skip #TODO value(shopping_order).must_be :valid? end + it 'has required fields' do + fields = [:status, :user_id] + + fields.each do |field| + expect(shopping_order).must_respond_to field + end + end + describe "relationships" do it "belongs to a user" do + # Arrange is done with let + + # Act + user = shopping_order.user + + # Assert + expect(shopping_order).must_be_instance_of Order + expect(user).must_be_instance_of User end it "has many order products" do + # Arrange is done with let + + # Act + ops = shopping_order.order_products + + # Assert + expect(shopping_order).must_be_instance_of Order + + expect(ops.length).must_be :>=, 1 + ops.each do |op| + expect(op).must_be_instance_of OrderProduct + end + end + + it "has many products through orderproducts(?)" do + skip #TODO end end describe "validations" do it "must have a user" do + skip #TODO + # Arrange + shopping_order.user = nil + + # Act + valid = shopping_order.valid? + + # Assert + expect(valid).must_equal false + expect(shopping_order.errors.messages).must_include :user + expect(shopping_order.errors.messages[:user]).must_include "can't be blank", "must exist" + + # Rearrange + shopping_order.user = users(:user1) + + # Re-Act + valid = shopping_order.valid? + + # Reassert + expect(valid).must_equal true end it "must have at least one order product" do - end + skip #TODO + # Arrange done with let + + # Act + ops = shopping_order.order_products - it "must have only unique order products" do + # Assert + expect(ops).must_be_instance_of Array + expect(ops.length).must_be :>=, 1 end it "must have a status" do + skip #TODO + # Arrange + shopping_order.status = nil + + # Act + valid = shopping_order.valid? + + # Assert + expect(valid).must_equal false + expect(shopping_order.errors.messages).must_include :status + expect(shopping_order.errors.messages[:status]).must_include "can't be blank", "must exist" + + # Rearrange + shopping_order.status = "shopping" + + # Re-Act + valid = shopping_order.valid? + + # Reassert + expect(valid).must_equal true end it "must have a status equal to shopping, paid, or shipped" do + skip #TODO end end describe "total" do it "returns the sum of all of the order's order product subtotals" do + # Arrange done with let + + # Act + result = shopping_order.total + subtotals = shopping_order.order_products.map { |op| op.subtotal } + + # Assert + expect(result).must_equal subtotals.sum end it "returns a float" do + # Arrange done with let + + # Act + result = shopping_order.total + + # Assert + expect(result).must_be_instance_of Float end end From 374049653c90784e75b7d653974a424d23d75210 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 07:11:54 -0700 Subject: [PATCH 045/196] nav added --- app/views/layouts/application.html.erb | 10 ++++++++-- config/routes.rb | 6 ------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index fa6d6ea4c3..3848455acd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,11 +11,17 @@
diff --git a/config/routes.rb b/config/routes.rb index f336f06970..70902d9ef7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,12 +6,6 @@ resources :users resources :products resources :orders, except: [:destroy] - -<<<<<<< HEAD -======= - resources :category, only: [:new, :create] - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html ->>>>>>> 15e082d8069160141aa6a3cb60f5180ca973f182 end From 6afa2a799679926a2210ebc3c3e0fac3008d609f Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 07:32:44 -0700 Subject: [PATCH 046/196] merchant fixtures added --- app/controllers/categories_controller.rb | 2 ++ app/controllers/categorys_controller.rb | 2 -- app/helpers/categories_helper.rb | 2 ++ app/helpers/categorys_helper.rb | 2 -- test/fixtures/{buyers.yml => merchants.yml} | 17 +++++++++++++++-- test/models/buyer_test.rb | 9 --------- test/models/merchant_test.rb | 17 +++++++++++++++++ test/models/order_item_test.rb | 9 --------- 8 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 app/controllers/categories_controller.rb delete mode 100644 app/controllers/categorys_controller.rb create mode 100644 app/helpers/categories_helper.rb delete mode 100644 app/helpers/categorys_helper.rb rename test/fixtures/{buyers.yml => merchants.yml} (59%) delete mode 100644 test/models/buyer_test.rb create mode 100644 test/models/merchant_test.rb delete mode 100644 test/models/order_item_test.rb diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..a14959525a --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,2 @@ +class CategoriesController < ApplicationController +end diff --git a/app/controllers/categorys_controller.rb b/app/controllers/categorys_controller.rb deleted file mode 100644 index 429f0c561a..0000000000 --- a/app/controllers/categorys_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class CategorysController < ApplicationController -end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/helpers/categorys_helper.rb b/app/helpers/categorys_helper.rb deleted file mode 100644 index a23d614633..0000000000 --- a/app/helpers/categorys_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CategorysHelper -end diff --git a/test/fixtures/buyers.yml b/test/fixtures/merchants.yml similarity index 59% rename from test/fixtures/buyers.yml rename to test/fixtures/merchants.yml index dc3ee79b5d..e995fc4383 100644 --- a/test/fixtures/buyers.yml +++ b/test/fixtures/merchants.yml @@ -4,8 +4,21 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: {} +merchant: + name: leanne + type: Merchant + # column: value # -two: {} +email_merchant: + name: jackie + type: Merchant + email: jackie@jackie.com # column: value + +git_merchant: + name: jessie + type: Merchant + email: jessie@jessie.com + uid: 34578908 + provider: github diff --git a/test/models/buyer_test.rb b/test/models/buyer_test.rb deleted file mode 100644 index 4dc3a78236..0000000000 --- a/test/models/buyer_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -describe Buyer do - let(:buyer) { Buyer.new } - - it "must be valid" do - value(buyer).must_be :valid? - end -end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..a6e17f146d --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +describe Merchant do + let(:merchant) { merchants(:merchant1) } + + it "must be valid" do + value(buyer).must_be :valid? + end + + it 'must be an instance of user' do + expect(:merchant).must_be_instance_of User + end + + it 'must be an instance of merchant' do + expect(:merchant).must_be_instance_of Merchant + end +end diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb deleted file mode 100644 index 19a9bf8f58..0000000000 --- a/test/models/order_item_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -describe OrderItem do - let(:order_item) { OrderItem.new } - - it "must be valid" do - value(order_item).must_be :valid? - end -end From a1b120b11bb57c89d4f099b1aca97aacfd8190c3 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 08:47:39 -0700 Subject: [PATCH 047/196] merge from gh done --- app/views/users/edit.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 21cbe9f3e6..ad1914a417 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,2 +1,3 @@

User#edit

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

+ From 52bc1e9dc6fcc07bed8741d388fc9007ec137765 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 09:47:28 -0700 Subject: [PATCH 048/196] cc user fixture added --- test/fixtures/users.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index dc3ee79b5d..efdfdd3517 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -4,8 +4,19 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: {} +user1: + name: jazz + uid: 89076543 + provider: github # column: value # -two: {} +cc_user: + name: hannah + uid: 97532187 + provider: github + cc_num: 8790451276789084 + cc_csv: 678 + cc_exp: 09/08/22 + address: 123 Main St USA + bill_zip: 10012 # column: value From dc092fba3d8c31509d2c4b7c8a693d2da56e1e67 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 09:55:00 -0700 Subject: [PATCH 049/196] users nwe form --- app/views/layouts/_form_errors.html.erb | 14 +++++++++++++ app/views/products/index.html.erb | 2 -- app/views/users/new.html.erb | 28 +++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 app/views/layouts/_form_errors.html.erb diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb new file mode 100644 index 0000000000..ec72172d15 --- /dev/null +++ b/app/views/layouts/_form_errors.html.erb @@ -0,0 +1,14 @@ +<% if model.errors.any? %> +
    + <% model.errors.messages.each do |column, problem_list| %> + <% problem_list.each do |problem| %> +
  • + + <%= column.capitalize %> + + <%= problem %> +
  • + <% end %> + <% end %> +
+<% end %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 0367ce6628..2357a71457 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,7 +1,5 @@

List of Products

- -
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 8e6ddd5245..d202f57690 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,2 +1,26 @@ -

User#new

-

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

+

New Account

+<%= render partial: "layouts/form_errors", locals: { model: User } %> + +<%= form_with model: User, local: true do |f|%> + +

Enter more information to create your account.

+ + +
+ <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
+ +
+ <%= f.label :type %> + + <%= f.checkbox :type, 'Merchant' %> +
+ + <% if @current_user %> + <%= f.submit button_title, class: "btn btn-primary" %> + <% else %> + <%= f.submit button_title, class: "btn btn-primary", disabled: true %> + <% end %> + +<% end %> From 10a5c85604c9fdec795ed7ef9734600b6a6c0ce0 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 10:02:16 -0700 Subject: [PATCH 050/196] form fixed kind of --- app/views/users/new.html.erb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index d202f57690..e1a6375642 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,5 +1,4 @@

New Account

-<%= render partial: "layouts/form_errors", locals: { model: User } %> <%= form_with model: User, local: true do |f|%> @@ -14,13 +13,13 @@
<%= f.label :type %> - <%= f.checkbox :type, 'Merchant' %> + <%= f.check_box :type %>
<% if @current_user %> - <%= f.submit button_title, class: "btn btn-primary" %> + <%= f.submit "New!", class: "btn btn-primary" %> <% else %> - <%= f.submit button_title, class: "btn btn-primary", disabled: true %> + <%= f.submit "New!", class: "btn btn-primary", disabled: true %> <% end %> <% end %> From 09b936d9383de4cda5695c05fddc949f12992f50 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 10:16:07 -0700 Subject: [PATCH 051/196] added cc merchant --- app/views/users/new.html.erb | 3 ++- test/fixtures/merchants.yml | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index e1a6375642..ffbb7e262f 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -11,9 +11,10 @@
+ <% type = 'Merchant' %> <%= f.label :type %> - <%= f.check_box :type %> + <%= f.check_box :type, {}, type %>
<% if @current_user %> diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml index e995fc4383..1a4c143ffe 100644 --- a/test/fixtures/merchants.yml +++ b/test/fixtures/merchants.yml @@ -22,3 +22,14 @@ git_merchant: email: jessie@jessie.com uid: 34578908 provider: github + +cc_merchant: + name: Amanda + type: Merchant + uid: 97532187 + provider: github + cc_num: 8790451276789084 + cc_csv: 678 + cc_exp: 09/08/22 + address: 123 Main St USA + bill_zip: 10012 From a40f9780a33d28d49bdde7d1eb6acbc7f8faee22 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 10:44:32 -0700 Subject: [PATCH 052/196] added helper methods to override oauth during testing to test_helper.rb --- app/views/users/new.html.erb | 1 + db/migrate/20181018223725_remove_extra_table.rb | 5 +++++ test/test_helper.rb | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 db/migrate/20181018223725_remove_extra_table.rb diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index ffbb7e262f..6c025d6123 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -6,6 +6,7 @@
+ <%= f.label :name %> <%= f.text_field :name, class: "form-control" %>
diff --git a/db/migrate/20181018223725_remove_extra_table.rb b/db/migrate/20181018223725_remove_extra_table.rb new file mode 100644 index 0000000000..34038b84e2 --- /dev/null +++ b/db/migrate/20181018223725_remove_extra_table.rb @@ -0,0 +1,5 @@ +class RemoveExtraTable < ActiveRecord::Migration[5.2] + def change + drop_table :columns_for_user_tables + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index fb7dd505e2..0f843f685c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,4 +22,21 @@ 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... + def setup + # !!!! Once you have enabled test mode, all requests to OmniAuth will be short circuited to use the mock authentication hash. + # A request to /auth/provider will redirect immediately to /auth/provider/callback!!!! + 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.oauth_provider, + uid: user.oauth_uid, + info: { + email: user.email, + name: user.name + } + } + end end From 80bd566104f40860d05154338e94fa2ea5947be2 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 13:03:51 -0700 Subject: [PATCH 053/196] commiting test auth changes --- test/fixtures/users.yml | 9 --------- test/models/user_test.rb | 13 ++++++++++++- test/test_helper.rb | 8 +++++++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index ccbe27ff50..efdfdd3517 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -5,7 +5,6 @@ # below each fixture, per the syntax in the comments below # user1: -<<<<<<< HEAD name: jazz uid: 89076543 provider: github @@ -21,11 +20,3 @@ cc_user: address: 123 Main St USA bill_zip: 10012 # column: value -======= - uid: 123 - provider: 'github' - -user2: - uid: 456 - provider: 'github' ->>>>>>> master diff --git a/test/models/user_test.rb b/test/models/user_test.rb index cc862ac2d9..02026ff75c 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,9 +1,20 @@ require "test_helper" describe User do - let(:user) { User.new } + let(:user) { :user1 } it "must be valid" do value(user).must_be :valid? end + + it "logs in an existing user" do + start_count = User.count + + perform_login(user) + must_redirect_to root_path + session[:user_id].must_equal user.id + + # Should *not* have created a new user + User.count.must_equal start_count + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0f843f685c..dd3e4dfbd9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,7 +24,7 @@ class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... def setup # !!!! Once you have enabled test mode, all requests to OmniAuth will be short circuited to use the mock authentication hash. - # A request to /auth/provider will redirect immediately to /auth/provider/callback!!!! + # A request to /auth/provider will redirect immediately to /auth/provider/callback !!!! OmniAuth.config.test_mode = true end @@ -39,4 +39,10 @@ def mock_auth_hash(user) } } end + + #used to dry up code in our tests, since logins will be performed often during testing + def perform_login(user) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + end end From 3f51ad93664a493568d5b5bfd4b96c9ee5d419d6 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 13:43:00 -0700 Subject: [PATCH 054/196] fixed user controller test - moved from model testing --- .../20181018223725_remove_extra_table.rb | 5 --- test/controllers/user_controller_test.rb | 12 +++++++ test/fixtures/merchants.yml | 34 +++++++++++++++---- test/models/user_test.rb | 11 ------ 4 files changed, 40 insertions(+), 22 deletions(-) delete mode 100644 db/migrate/20181018223725_remove_extra_table.rb diff --git a/db/migrate/20181018223725_remove_extra_table.rb b/db/migrate/20181018223725_remove_extra_table.rb deleted file mode 100644 index 34038b84e2..0000000000 --- a/db/migrate/20181018223725_remove_extra_table.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RemoveExtraTable < ActiveRecord::Migration[5.2] - def change - drop_table :columns_for_user_tables - end -end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index 9f2950cc46..bd645ed764 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -1,6 +1,18 @@ require "test_helper" describe UserController do + + it "logs in an existing user" do + start_count = User.count + + perform_login(user) + must_redirect_to root_path + session[:user_id].must_equal user.id + + # Should *not* have created a new user + User.count.must_equal start_count + end + it "should get index" do get user_index_url value(response).must_be :success? diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml index 8c2ed25c29..e34fdaa6df 100644 --- a/test/fixtures/merchants.yml +++ b/test/fixtures/merchants.yml @@ -4,10 +4,32 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: - uid: 789 - provider: 'github' +merchant: + name: leanne + type: Merchant -two: - uid: 100 - provider: 'github' +# column: value +# +email_merchant: + name: jackie + type: Merchant + email: jackie@jackie.com +# column: value + +git_merchant: + name: jessie + type: Merchant + email: jessie@jessie.com + uid: 34578908 + provider: github + +cc_merchant: + name: charles + type: Merchant + uid: 97532187 + provider: github + cc_num: 8790451276789084 + cc_csv: 678 + cc_exp: 09/08/22 + address: 123 Main St USA + bill_zip: 10012 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 02026ff75c..8ef0196c0d 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -6,15 +6,4 @@ it "must be valid" do value(user).must_be :valid? end - - it "logs in an existing user" do - start_count = User.count - - perform_login(user) - must_redirect_to root_path - session[:user_id].must_equal user.id - - # Should *not* have created a new user - User.count.must_equal start_count - end end From 76959c351a2bc050db4cd380814694509d84fff6 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 13:49:34 -0700 Subject: [PATCH 055/196] user controller test skeletons added --- test/controllers/user_controller_test.rb | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index bd645ed764..88dade2f9f 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -2,6 +2,22 @@ describe UserController do + describe Merchant do + + it "should allow edits to own products" do + + end + + it "should not allow type-merchant to purchase own products" do + + end + + it "allows a merchant to downgrade to a regular user" do + + end + + end #merchant tests end + it "logs in an existing user" do start_count = User.count @@ -13,6 +29,35 @@ User.count.must_equal start_count end + it "does not allow edits to products" do + + end + + it "does not allow deletion of products" do + + end + + it "allows user to edit quantity in order(shopping cart)" do + + end + + it "allows user to remove items to cart" do + + end + + it "allows user to add items to cart" do + + end + + it "allows user to edit their user information" do + + end + + it "allows a user to become a merchant" do + + end + + it "should get index" do get user_index_url value(response).must_be :success? From fd74d67391482d1ab8814647ae750c6233a94390 Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 19 Oct 2018 13:51:56 -0700 Subject: [PATCH 056/196] Fixed issue with order validation --- app/controllers/application_controller.rb | 15 ++++++++++++--- app/controllers/order_products_controller.rb | 9 ++++++--- app/controllers/products_controller.rb | 2 +- app/models/order.rb | 10 +++------- app/views/orders/cart.html.erb | 9 ++++++--- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 55fc232d67..7b1d5e8dc2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,10 +8,8 @@ def current_order if session[:order_id] @current_order = Order.find_by(id: session[:order_id].to_i) else - @current_order = Order.create(status: "shopping") - session[:order_id] = @current_order.id + @current_order = generate_guest_cart end - return @current_order end private @@ -20,4 +18,15 @@ def find_user @current_user ||= User.find_by(id: session[:user_id]) end + def generate_guest_cart + order = Order.new(status: "shopping") + if find_user + order.user_id = find_user.user_id + else + user = User.create(username: "sovietski-guest", uid: (User.last.id + 1), provider: "sovietski") + order.user_id = user.id + end + return order + end + end diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 8e6c6ac6e9..bb408a4358 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -1,13 +1,16 @@ -require 'pry' - class OrderProductsController < ApplicationController def create + # pull in product and quantity from form partial on product show page product = Product.find_by(id: params[:order_product][:product_id].to_i) quantity = params[:order_product][:quantity].to_i + # create the orderproduct, add it to the current cart, and save it @current_order.add_product(product, quantity) - # check quantity against stock? + + # save the cart and update the session + @current_order.save + session[:order_id] = @current_order.id redirect_to cart_path end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 988a2c7d8b..1c01e9592f 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -8,7 +8,7 @@ def index end def show - @op = current_order.order_products.new + @op = @current_order.order_products.new end diff --git a/app/models/order.rb b/app/models/order.rb index 3da487e025..c6fa0308f3 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -3,7 +3,7 @@ class Order < ApplicationRecord has_many :order_products, dependent: :destroy validates :user, presence: true - validates :order_products, presence: true, uniqueness: true + # validates :order_products, presence: true, uniqueness: true validates :status, inclusion: { in: %w(shopping paid shipped), message: "%{value} is not a valid order status" } @@ -18,13 +18,9 @@ def add_product(product, quantity) if current_op # if so, edit quantity within existing orderproduct current_op.quantity += quantity else # if not, add new orderproduct - current_op = order_products.new(product_id: product.id, quantity: quantity, order_id: self.id) + current_op = self.order_products.new(product_id: product.id, quantity: quantity, order_id: self.id) end - if current_op.save - # success stuff here - else - # error stuff here - end + current_op.save end end diff --git a/app/views/orders/cart.html.erb b/app/views/orders/cart.html.erb index 24f28508bb..2ef6c42504 100644 --- a/app/views/orders/cart.html.erb +++ b/app/views/orders/cart.html.erb @@ -1,5 +1,8 @@

This is the shopping cart!

- -<% @current_order.order_products.each do |op| %> -

<%= "Product ID: #{op.product_id}, Quantity: #{op.quantity}" %>

+<% if @current_order %> + <% @current_order.order_products.each do |op| %> +

<%= "Product ID: #{op.product_id}, Quantity: #{op.quantity}" %>

+ <% end %> +<% else %> +

Nothing here yet... go shopping!

<% end %> From 76af1ea91f96cabd6f3f0c8b71c1bb0ed3ec86cb Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 13:56:01 -0700 Subject: [PATCH 057/196] change from application controller from username to name --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7b1d5e8dc2..03d0908547 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,7 +23,7 @@ def generate_guest_cart if find_user order.user_id = find_user.user_id else - user = User.create(username: "sovietski-guest", uid: (User.last.id + 1), provider: "sovietski") + user = User.create(name: "sovietski-guest", uid: (User.last.id + 1), provider: "sovietski") order.user_id = user.id end return order From e96f88078aeba092809c744d61d4b064cb665c70 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:00:04 -0700 Subject: [PATCH 058/196] db fixed --- db/migrate/20181018223725_remove_extra_table.rb | 5 +++++ db/schema.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181018223725_remove_extra_table.rb diff --git a/db/migrate/20181018223725_remove_extra_table.rb b/db/migrate/20181018223725_remove_extra_table.rb new file mode 100644 index 0000000000..34038b84e2 --- /dev/null +++ b/db/migrate/20181018223725_remove_extra_table.rb @@ -0,0 +1,5 @@ +class RemoveExtraTable < ActiveRecord::Migration[5.2] + def change + drop_table :columns_for_user_tables + end +end diff --git a/db/schema.rb b/db/schema.rb index 9b513fc42b..0aef960899 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_172139) do +ActiveRecord::Schema.define(version: 2018_10_18_223725) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From bc6be916de08ce864807f1817e397ec247fada00 Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 19 Oct 2018 14:01:09 -0700 Subject: [PATCH 059/196] fixed typo --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7b1d5e8dc2..03d0908547 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,7 +23,7 @@ def generate_guest_cart if find_user order.user_id = find_user.user_id else - user = User.create(username: "sovietski-guest", uid: (User.last.id + 1), provider: "sovietski") + user = User.create(name: "sovietski-guest", uid: (User.last.id + 1), provider: "sovietski") order.user_id = user.id end return order From 2d3665ab46543074d1f239ceef2e07459b33e244 Mon Sep 17 00:00:00 2001 From: Jacquelyn Cheng <35181875+jacquelynoelle@users.noreply.github.com> Date: Fri, 19 Oct 2018 14:13:27 -0700 Subject: [PATCH 060/196] Already fixed this on master --- app/controllers/application_controller.rb | 32 ----------------------- 1 file changed, 32 deletions(-) delete mode 100644 app/controllers/application_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb deleted file mode 100644 index 03d0908547..0000000000 --- a/app/controllers/application_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -class ApplicationController < ActionController::Base - protect_from_forgery with: :exception - - before_action :find_user - before_action :current_order - - def current_order - if session[:order_id] - @current_order = Order.find_by(id: session[:order_id].to_i) - else - @current_order = generate_guest_cart - end - end - - private - - def find_user - @current_user ||= User.find_by(id: session[:user_id]) - end - - def generate_guest_cart - order = Order.new(status: "shopping") - if find_user - order.user_id = find_user.user_id - else - user = User.create(name: "sovietski-guest", uid: (User.last.id + 1), provider: "sovietski") - order.user_id = user.id - end - return order - end - -end From 77f7e0bfb900d3a2ea2bf003e78c3522da51e975 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:19:34 -0700 Subject: [PATCH 061/196] merged --- test/controllers/user_controller_test.rb | 4 ++-- test/fixtures/merchants.yml | 6 ++++++ test/models/user_test.rb | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index 88dade2f9f..e94b2248c6 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -1,6 +1,6 @@ require "test_helper" -describe UserController do +describe UsersController do describe Merchant do @@ -14,7 +14,7 @@ it "allows a merchant to downgrade to a regular user" do - end + end end #merchant tests end diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml index e34fdaa6df..a6dbdc6632 100644 --- a/test/fixtures/merchants.yml +++ b/test/fixtures/merchants.yml @@ -6,18 +6,23 @@ # merchant: name: leanne + uid: 897 type: Merchant + provider: github # column: value # email_merchant: name: jackie + uid: 9076 type: Merchant email: jackie@jackie.com + provider: github # column: value git_merchant: name: jessie + uid: 9086 type: Merchant email: jessie@jessie.com uid: 34578908 @@ -25,6 +30,7 @@ git_merchant: cc_merchant: name: charles + uid: 9876 type: Merchant uid: 97532187 provider: github diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 8ef0196c0d..f7f450d56f 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,9 +1,14 @@ require "test_helper" describe User do + + describe Merchant do + + end + let(:user) { :user1 } it "must be valid" do - value(user).must_be :valid? + value(:user).must_be :valid? end end From e99bc6cd0080a4bb78d7721a90e7c78870780082 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:21:48 -0700 Subject: [PATCH 062/196] fixed fixtures --- test/fixtures/merchants.yml | 1 - test/models/user_test.rb | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml index a6dbdc6632..3e774ab7d7 100644 --- a/test/fixtures/merchants.yml +++ b/test/fixtures/merchants.yml @@ -22,7 +22,6 @@ email_merchant: git_merchant: name: jessie - uid: 9086 type: Merchant email: jessie@jessie.com uid: 34578908 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index f7f450d56f..cb69c037b3 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -3,10 +3,10 @@ describe User do describe Merchant do - + let (:merchant) {merchant(:merchant)} end - - let(:user) { :user1 } + + let(:user) { user(:user1) } it "must be valid" do value(:user).must_be :valid? From c04653fb698bc208fb8a729b5f67320bb3d1d160 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:35:57 -0700 Subject: [PATCH 063/196] merchant tests passed --- test/models/merchant_test.rb | 15 ++++++--------- test/models/user_test.rb | 9 +++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index a6e17f146d..f3d1785394 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -1,17 +1,14 @@ -require "test_helper" +require 'test_helper' describe Merchant do - let(:merchant) { merchants(:merchant1) } + let (:merchant) {merchants(:merchant)} - it "must be valid" do - value(buyer).must_be :valid? + it "must be an instance of Merchant" do + expect(merchant).must_be_instance_of Merchant end - it 'must be an instance of user' do - expect(:merchant).must_be_instance_of User + it "must be kind of User" do + expect(merchant).must_be_kind_of User end - it 'must be an instance of merchant' do - expect(:merchant).must_be_instance_of Merchant - end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index cb69c037b3..6dbb282cb1 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -2,13 +2,10 @@ describe User do - describe Merchant do - let (:merchant) {merchant(:merchant)} - end - - let(:user) { user(:user1) } + let(:user) { users(:user1) } it "must be valid" do - value(:user).must_be :valid? + value(user).must_be :valid? end + end From ba6bb2043426a6283aefc0de0584383f2d6eed86 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:37:55 -0700 Subject: [PATCH 064/196] merchant valid test added --- test/models/merchant_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index f3d1785394..111f833a32 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -3,6 +3,10 @@ describe Merchant do let (:merchant) {merchants(:merchant)} + it "must be valid" do + value(merchant).must_be :valid? + end + it "must be an instance of Merchant" do expect(merchant).must_be_instance_of Merchant end From 97c61649f752a6d1fed46e1af9d20e5a04c76ba8 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:44:46 -0700 Subject: [PATCH 065/196] testing user types tests pass --- app/models/merchant.rb | 1 + test/models/merchant_test.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/models/merchant.rb b/app/models/merchant.rb index e03a781007..117d9c7cff 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,4 +1,5 @@ class Merchant < User + validates :type, presence: true #merchant inherits all things from user, but when a new merchant is created the 'type' is automagically set to merchant. #merchant needs ability to fulfill orders as 'shipped' end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index 111f833a32..d30d050e15 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -15,4 +15,11 @@ expect(merchant).must_be_kind_of User end + it "only users with type merchant are instance of merchant" do + not_merchant = users(:user1) + + expect(not_merchant).must_be_instance_of User + expect(not_merchant).wont_be_instance_of Merchant + end + end From eb17044b1dfe1d24f55033ae4a6c0f6aa9e4ac20 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 14:56:12 -0700 Subject: [PATCH 066/196] validation for merchant added --- app/models/merchant.rb | 2 ++ test/models/merchant_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/models/merchant.rb b/app/models/merchant.rb index 117d9c7cff..1493d719e2 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,5 +1,7 @@ class Merchant < User validates :type, presence: true #merchant inherits all things from user, but when a new merchant is created the 'type' is automagically set to merchant. + + #create method to be sure it is not nil, then add to validation #merchant needs ability to fulfill orders as 'shipped' end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index d30d050e15..4669c6b4f2 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -22,4 +22,18 @@ expect(not_merchant).wont_be_instance_of Merchant end + it "will not create a new merchant if type is nil" do + not_a_merchant = Merchant.new( + name: 'Newbie', + uid: 890, + provider: 'github', + email: 'newbie@newbs.com', + type: nil + ) + + expect(not_a_merchant.type).must_equal nil + expect(not_a_merchant).wont_be_instance_of Merchant + + end + end From 9589c759047e26fd704e0393850654f4539349a6 Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 19 Oct 2018 15:21:47 -0700 Subject: [PATCH 067/196] Added functionality to delete order products from cart --- app/assets/stylesheets/orders.scss | 10 +++++ app/controllers/order_products_controller.rb | 11 ++++- app/views/orders/cart.html.erb | 46 +++++++++++++++++--- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss index 741506954d..827f73d991 100644 --- a/app/assets/stylesheets/orders.scss +++ b/app/assets/stylesheets/orders.scss @@ -1,3 +1,13 @@ // 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/ + +section.cart { + display: flex; + flex-direction: column; + margin: 2rem; +} + +article.card { + width: 60%; +} diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index bb408a4358..34c646df10 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -15,6 +15,13 @@ def create redirect_to cart_path end - - + def destroy + op = OrderProduct.find_by(id: params[:id]) + if op.destroy + # display confirmation + else + # display error + end + redirect_back fallback_location: cart_path + end end diff --git a/app/views/orders/cart.html.erb b/app/views/orders/cart.html.erb index 2ef6c42504..b6d57c857a 100644 --- a/app/views/orders/cart.html.erb +++ b/app/views/orders/cart.html.erb @@ -1,8 +1,42 @@

This is the shopping cart!

-<% if @current_order %> - <% @current_order.order_products.each do |op| %> -

<%= "Product ID: #{op.product_id}, Quantity: #{op.quantity}" %>

+
+ <% if @current_order %> + <% @current_order.order_products.each do |op| %> +
+
+
+ Product +
+
+
+
<%= op.product.name %>
+
+

<%= "Quantity: #{op.quantity}" %>

+

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

+
+
+
+
+ +
+ <% end %> + + + + <% else %> +

Nothing here yet... go shopping!

<% end %> -<% else %> -

Nothing here yet... go shopping!

-<% end %> +
From 0937a4d19eb5279a93548365109f4f4ff492de9b Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 15:46:12 -0700 Subject: [PATCH 068/196] merchant seed added --- app/controllers/users_controller.rb | 1 + app/views/users/index.html.erb | 29 ++++++++++++++++++++++++++++- db/seeds.rb | 21 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6b2af2bf79..a866cf4e41 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,6 +3,7 @@ class UsersController < ApplicationController def index @users = User.all + @merchants = Merchant.all #adding merchants to index for viewing and sorting in views end def new diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 184f0620f4..7c64b077f1 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,4 +1,31 @@

User#index

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

-This is writing. +<% if @merchants.empty? %> +

There are no merchants yet

+<% else %> +
+ + + + + + + + + <% @merchants.each do |merchant| %> + + + + + + <% end %> + +
Storefront NameJoined
+

img goes here

+
+ <%= link_to merchant.name, user_path(user.id) %> + + <%= "#{merchant.created_at.strftime("%b. %d, %Y")}" %> +
+<% end %> diff --git a/db/seeds.rb b/db/seeds.rb index e105c457f3..971d66b9e2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -51,6 +51,27 @@ puts "Added #{User.count} user records" puts "#{user_failures.length} users failed to save" +merchant_failures = [] + +8.times do |i| + merchant_name = Faker::Name.name + merchant = Merchant.new + merchant.type = "Merchant" + merchant.name = merchant_name + merchant.uid = rand(10) + merchant.provider = "github" + successful = merchant.save + if !successful + merchant_failures << merchant + puts "Failed to save merchant: #{merchant.inspect}" # so user can check that work to see what happened + else + puts "Created merchant: #{merchant.inspect}" + end +end + +puts "Added #{Merchant.count} merchant records" +puts "#{merchant_failures.length} merchant failed to save" + product_failures = [] 10.times do |i| From 52abaf9a38960b67faf11013846b08cd62c142e4 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 15:48:54 -0700 Subject: [PATCH 069/196] can see list of merchants --- app/views/users/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 7c64b077f1..3c402c8561 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -19,7 +19,7 @@

img goes here

- <%= link_to merchant.name, user_path(user.id) %> + <%= link_to merchant.name, user_path(merchant.id) %> <%= "#{merchant.created_at.strftime("%b. %d, %Y")}" %> From 63355f8e94a01f8835d21949b49b1aa2994b2c67 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Fri, 19 Oct 2018 15:50:25 -0700 Subject: [PATCH 070/196] merchants have own nav link --- app/views/layouts/application.html.erb | 1 + app/views/users/index.html.erb | 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 929732e2bd..1955fcb363 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,6 +13,7 @@
+
+ + <%= f.label "EMail" %> + <%= f.text_field :email, class: "form-control" %> +
+
<%= f.label :address%> @@ -47,8 +53,6 @@ <%= f.text_field :cc_csv, class: "form-control" %>
- - <% if @current_user %> <%= f.submit "Update", class: "btn btn-primary" %> <% else %> From 5c223baf403c191415d9c90562005ea9160aa446 Mon Sep 17 00:00:00 2001 From: leannerivera <31866543+leannerivera@users.noreply.github.com> Date: Mon, 22 Oct 2018 08:01:56 -0700 Subject: [PATCH 081/196] Delete Gemfile --- Gemfile | 85 --------------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 Gemfile diff --git a/Gemfile b/Gemfile deleted file mode 100644 index e12218d913..0000000000 --- a/Gemfile +++ /dev/null @@ -1,85 +0,0 @@ -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' -gem 'omniauth' -gem 'omniauth-github' -gem 'bootstrap-toggle-rails' - -# 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 -gem 'faker' -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' - gem 'dotenv-rails' -end - -group :test do - gem 'minitest-rails' - gem 'minitest-reporters' -end From 0bc564cce8763f559f93b29b270f0414f58b099b Mon Sep 17 00:00:00 2001 From: jackie Date: Mon, 22 Oct 2018 09:13:18 -0700 Subject: [PATCH 082/196] Tests for order --- app/models/order.rb | 11 +- app/models/order_product.rb | 4 + test/fixtures/categories.yml | 2 +- test/models/order_test.rb | 245 +++++++++++++++++++++++++++++++++-- 4 files changed, 241 insertions(+), 21 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index f8747fd920..2d5e1ec4b7 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -7,6 +7,7 @@ class Order < ApplicationRecord validates :user, presence: true # validates :order_products, presence: true, uniqueness: true + validates :status, presence: true validates :status, inclusion: { in: %w(pending paid shipped), message: "%{value} is not a valid order status" } @@ -19,17 +20,15 @@ def add_product(product, quantity) current_op = order_products.find_by(product_id: product.id) if current_op # if so, edit quantity within existing orderproduct - current_op.quantity += quantity + new_quantity = current_op.quantity + quantity + current_op.edit_quantity(new_quantity) else # if not, add new orderproduct - current_op = self.order_products.new(product_id: product.id, quantity: quantity, order_id: self.id) + current_op = self.order_products.create(product_id: product.id, quantity: quantity, order_id: self.id) end - - current_op.save end def edit_quantity(op, new_quantity) - op.quantity = new_quantity - op.save + op.edit_quantity(new_quantity) end def submit_order diff --git a/app/models/order_product.rb b/app/models/order_product.rb index 74b3253723..1586f74835 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -15,4 +15,8 @@ def update_stock product.update_stock(quantity) self.save end + + def edit_quantity(new_quantity) + self.update(quantity: new_quantity) + end end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml index d3d183377b..75fab053a0 100644 --- a/test/fixtures/categories.yml +++ b/test/fixtures/categories.yml @@ -1,6 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -catgory1: +category1: name: "category 1" category2: diff --git a/test/models/order_test.rb b/test/models/order_test.rb index e4421ca10e..112cfe8efb 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -4,7 +4,6 @@ let(:pending_order) { orders(:pending_order) } it "must be valid" do - skip #TODO value(pending_order).must_be :valid? end @@ -28,7 +27,7 @@ expect(user).must_be_instance_of User end - it "has many order products" do + it "can have many order products" do # Arrange is done with let # Act @@ -43,14 +42,51 @@ end end - it "has many products through orderproducts(?)" do - skip #TODO + it "can have 0 order products when status is pending" do + # Arrange + pending_order.order_products.each do |op| + op.destroy + end + + # Act + order = Order.find_by(id: pending_order.id) + ops = order.order_products + + # Assert + expect(order.status).must_equal "pending" + expect(ops.length).must_equal 0 + end + + it "can have many products through orderproducts" do + # Arrange is done with let + + # Act + products_in_order = pending_order.products + + # Assert + expect(products_in_order.length).must_be :>=, 1 + products_in_order.each do |product| + expect(product).must_be_instance_of Product + end + end + + it "can have 0 products through orderproducts when status is pending" do + # Arrange + pending_order.order_products.each do |op| + op.destroy + end + + # Act + products_in_order = pending_order.products + + # Assert + expect(pending_order.status).must_equal "pending" + expect(products_in_order.length).must_equal 0 end end describe "validations" do it "must have a user" do - skip #TODO # Arrange pending_order.user = nil @@ -73,19 +109,17 @@ end it "must have at least one order product" do - skip #TODO # Arrange done with let # Act ops = pending_order.order_products # Assert - expect(ops).must_be_instance_of Array + expect(ops.first).must_be_instance_of OrderProduct expect(ops.length).must_be :>=, 1 end it "must have a status" do - skip #TODO # Arrange pending_order.status = nil @@ -98,7 +132,7 @@ expect(pending_order.errors.messages[:status]).must_include "can't be blank", "must exist" # Rearrange - pending_order.status = "shopping" + pending_order.status = "pending" # Re-Act valid = pending_order.valid? @@ -107,8 +141,44 @@ expect(valid).must_equal true end - it "must have a status equal to shopping, paid, or shipped" do - skip #TODO + it "must have a status equal to pending, paid, or shipped" do + # Arrange + pending_order.status = "test" + + # Act + valid = pending_order.valid? + + # Assert + expect(valid).must_equal false + expect(pending_order.errors.messages).must_include :status + expect(pending_order.errors.messages[:status]).must_include "test is not a valid order status" + + # Rearrange + pending_order.status = "pending" + + # Re-Act + valid = pending_order.valid? + + # Reassert + expect(valid).must_equal true + + # Rearrange + pending_order.status = "paid" + + # Re-Act + valid = pending_order.valid? + + # Reassert + expect(valid).must_equal true + + # Rearrange + pending_order.status = "shipped" + + # Re-Act + valid = pending_order.valid? + + # Reassert + expect(valid).must_equal true end end @@ -136,13 +206,160 @@ end describe "add_product" do - it "adds an order product to the cart" do + let (:new_product) { + Product.new( + user: merchants(:merchant), + name: "pants", + price: 3, + category: categories(:category1), + description: "a nice pair of pants", + stock: 10, + photo_url: "photo" + ) + } + + it "adds a new order product with the designated quantity to the order if product not in cart" do + # Arrange done with let + + # Act - Assert + expect { + pending_order.add_product(new_product, 2) + }.must_change 'pending_order.order_products.length', 1 + + expect(pending_order.order_products.last).must_be_instance_of OrderProduct + expect(pending_order.order_products.last.quantity).must_equal 2 + end + + it "updates the existing order product quantity if the product is already in the cart" do + # Arrange done with let and fixtures + + # Before addition + expect(order_products(:dresses).quantity).must_equal 2 + + expect { + pending_order.add_product(products(:dress), 2) + }.wont_change 'pending_order.order_products.length' + + # After addition + op = OrderProduct.find_by(id: order_products(:dresses).id) + expect(op.quantity).must_equal 4 + end + + it "will return true if successful" do + # Arrange done with let and before + + # Act - Assert + expect(pending_order.add_product(products(:dress), 2)).must_equal true + expect(pending_order.add_product(new_product, 2)).must_equal true + end + + it "will return false if requested quantity exceeds stock" do + # Arrange done with let and before + + # Act - Assert + expect(pending_order.add_product(products(:dress), 20)).must_equal false + expect(pending_order.add_product(new_product, 20)).must_equal false + end + + it "will return false if requested quantity is less than 1 or a non-integer" do + # Arrange done with let and before + + # Act - Assert + expect(pending_order.add_product(products(:dress), 0)).must_equal false + expect(pending_order.add_product(new_product, -2)).must_equal false + expect(pending_order.add_product(new_product, 1.5)).must_equal false + end + end + + describe "edit_quantity" do + let (:dresses) { order_products(:dresses) } + + it "updates the quantity to the designated value" do + # Arrange done with let + + # Act - Assert + expect{ + pending_order.edit_quantity(dresses, 3) + }.must_change 'dresses.quantity', 3 + end + + it "cannot update the quantity to a value less than 1 or a non-integer" do + # Arrange done with let + + # Act - Assert + expect{ + pending_order.edit_quantity(dresses, 0) + }.wont_change 'dresses.quantity' + + expect{ + pending_order.edit_quantity(dresses, -1) + }.wont_change 'dresses.quantity' + + expect{ + pending_order.edit_quantity(dresses, 2.5) + }.wont_change 'dresses.quantity' + end + + it "must return true when successful" do + # Arrange done with let + + # Act - Assert + expect(pending_order.edit_quantity(dresses, 3)).must_equal true + end + + it "must return false when unsuccessful" do + # Arrange done with let + + # Act - Assert + expect(pending_order.edit_quantity(dresses, -2)).must_equal false end - it "updates the existing order product quantity if product already exists in cart" do + it "cannot increase the quantity beyond the available stock" do + # Arrange done with let + + # Act - Assert + expect{ + pending_order.edit_quantity(dresses, products(:dress).stock + 1) + }.wont_change 'dresses.quantity' + + expect(pending_order.edit_quantity(dresses, products(:dress).stock + 1)).must_equal false end + end + + describe "submit_order" do + it "updates the order status from pending to paid" do + # Arrange done with let + + # Act - Assert + expect(pending_order.status).must_equal "pending" + order_status = pending_order.submit_order + expect(order_status).must_equal "paid" + end + + it "updates the stock of the product on order" do + # Arrange + change = order_products(:dresses).quantity + + # Act - Assert + expect{ + pending_order.submit_order + }.must_change 'products(:dress).stock', change + end + + it "returns false if order submission fails" do + # Arrange done with let + + # Act - Assert + expect( + 10.times { pending_order.submit_order } # should fail bec not enough stock + ).must_equal true + end + + it "returns true if order submission succeeds" do + # Arrange done with let - it "creates a new order product in the cart if product not already on order" do + # Act - Assert + expect(pending_order.submit_order).must_equal true end end end From 21f08c0d24ad717ff311f6460d23a371fb3fe887 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 22 Oct 2018 09:13:32 -0700 Subject: [PATCH 083/196] merge with master --- app/views/users/_info.html.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/views/users/_info.html.rb diff --git a/app/views/users/_info.html.rb b/app/views/users/_info.html.rb new file mode 100644 index 0000000000..e69de29bb2 From 3b973b6c951f187673a5c1693ba59126ea8ebb2a Mon Sep 17 00:00:00 2001 From: jackie Date: Mon, 22 Oct 2018 09:15:01 -0700 Subject: [PATCH 084/196] Re-adding lost Gemfile --- Gemfile | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Gemfile diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..ffcf460b79 --- /dev/null +++ b/Gemfile @@ -0,0 +1,84 @@ +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' +gem 'omniauth' +gem 'omniauth-github' + +# 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 +gem 'faker' +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' + gem 'dotenv-rails' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end From e2bfdcd3954af10345be24d52a223a6fe7abe4d9 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 22 Oct 2018 09:18:22 -0700 Subject: [PATCH 085/196] stuff --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index e12218d913..ffcf460b79 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,6 @@ gem 'jbuilder', '~> 2.5' # gem 'bcrypt', '~> 3.1.7' gem 'omniauth' gem 'omniauth-github' -gem 'bootstrap-toggle-rails' # Use ActiveStorage variant # gem 'mini_magick', '~> 4.8' From 0f6e02fc2b81daaaee60526205ed6a0ba3d5447a Mon Sep 17 00:00:00 2001 From: jackie Date: Mon, 22 Oct 2018 09:51:18 -0700 Subject: [PATCH 086/196] Added order product tests and tweaked edit quantity method --- app/models/order.rb | 11 ++--- app/models/order_product.rb | 3 +- test/models/order_product_test.rb | 82 +++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 7 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 2d5e1ec4b7..943e6c52ea 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -15,20 +15,19 @@ def total return order_products.map { |op| op.valid? ? op.subtotal : 0 }.sum end - def add_product(product, quantity) + def add_product(product, quantity_ordered) # check if product is already in cart current_op = order_products.find_by(product_id: product.id) if current_op # if so, edit quantity within existing orderproduct - new_quantity = current_op.quantity + quantity - current_op.edit_quantity(new_quantity) + current_op.edit_quantity(quantity_ordered) else # if not, add new orderproduct - current_op = self.order_products.create(product_id: product.id, quantity: quantity, order_id: self.id) + current_op = self.order_products.create(product_id: product.id, quantity: quantity_ordered, order_id: self.id) end end - def edit_quantity(op, new_quantity) - op.edit_quantity(new_quantity) + def edit_quantity(op, quantity_ordered) + op.edit_quantity(quantity_ordered) end def submit_order diff --git a/app/models/order_product.rb b/app/models/order_product.rb index 1586f74835..ac6cd25b7e 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -16,7 +16,8 @@ def update_stock self.save end - def edit_quantity(new_quantity) + def edit_quantity(quantity_ordered) + new_quantity = quantity + quantity_ordered self.update(quantity: new_quantity) end end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index 1472184111..a9071b7d84 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -140,4 +140,86 @@ expect(result).must_equal dresses.quantity * products(:dress).price end end + + describe "edit_quantity" do + it "updates the quantity to the designated value" do + # Arrange done with let + + # Act - Assert + expect{ + dresses.edit_quantity(3) + }.must_change 'dresses.quantity', 1 #previously 2 + end + + it "cannot update the quantity to a value less than 1 or a non-integer" do + # Arrange done with let + + # Act - Assert + expect{ + dresses.edit_quantity(0) + }.wont_change 'dresses.quantity' + + expect{ + dresses.edit_quantity(-1) + }.wont_change 'dresses.quantity' + + expect{ + dresses.edit_quantity(2.5) + }.wont_change 'dresses.quantity' + end + + it "must return true when successful" do + # Arrange done with let + + # Act - Assert + expect(dresses.edit_quantity(3)).must_equal true + end + + it "must return false when unsuccessful" do + # Arrange done with let + + # Act - Assert + expect(dresses.edit_quantity(-2)).must_equal false + end + + it "cannot increase the quantity beyond the available stock" do + # Arrange done with let + + # Act - Assert + expect{ + dresses.edit_quantity(products(:dress).stock + 1) + }.wont_change 'dresses.quantity' + + expect(dresses.edit_quantity(products(:dress).stock + 1)).must_equal false + end + end + + describe "update_stock" do + it "reduces the stock by the quantity ordered" do + expect{ + dresses.update_stock(2) + }.must_change 'dresses.quantity', 2 + end + + it "returns true if successful" do + expect(dresses.update_stock(2)).must_equal true + end + + it "returns false if unsuccessful" do + expect(dresses.update_stock(2)).must_equal false + end + + it "cannot reduce the stock below 0 or to a non-integer" do + # Arrange done with let + + # Act - Assert + expect{ + dresses.update_stock(dresses.product.stock + 1) + }.wont_change 'dresses.quantity' + + expect{ + dresses.update_stock(1.5) + }.wont_change 'dresses.quantity' + end + end end From 5239565be8736ed73b2033ceb3f32ea309181cc8 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 22 Oct 2018 11:24:58 -0700 Subject: [PATCH 087/196] fix oath --- app/controllers/application_controller.rb | 1 + app/controllers/order_products_controller.rb | 1 + app/controllers/sessions_controller.rb | 5 ++-- app/controllers/users_controller.rb | 13 +++++----- app/views/order_products/_form.html.erb | 5 +++- app/views/products/index.html.erb | 2 +- app/views/products/show.html.erb | 2 ++ app/views/users/edit.html.erb | 6 ++++- app/views/users/show.html.erb | 25 ++++++++++++++------ 9 files changed, 42 insertions(+), 18 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fee9c3dfe8..2e2750c5fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,6 +16,7 @@ def current_order def find_user @current_user ||= User.find_by(id: session[:user_id]) + end def generate_cart diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index a53bbd7452..ffba14ccff 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -6,6 +6,7 @@ def create quantity = params[:order_product][:quantity].to_i # create the orderproduct, add it to the current cart, and save it + @current_order.save @current_order.add_product(product, quantity) # save the cart and update the session diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e47ea1b71e..be0f8b4c3e 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -6,6 +6,7 @@ def create @user = User.find_by(uid: auth_hash[:uid], name: auth_hash[:name], provider: 'github') if @user flash[:success] = "Welcome back #{@user.name}" + redirect_to root_path else #try to make a new user @user = User.build_from_github(auth_hash) @@ -19,14 +20,14 @@ def create return end end + session[:user_id] = @user.id - redirect_to root_path + end def destroy session[:user_id] = nil flash[:success] = "Bye!" - redirect_to root_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 38a6d3305d..2a4ee1e62d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,9 +1,10 @@ class UsersController < ApplicationController - before_action :find_merchant + before_action :find_merchant, except: [:index, :edit] + before_action :find_user def index - @users = User.all @merchants = Merchant.all #adding merchants to index for viewing and sorting in views + # @users = User.all end def new @@ -26,9 +27,9 @@ def update end def edit - @user ||= User.find_by(id: params[:id].to_i) - - if @user.nil? + @current_user.id + + if @current_user.nil? render :not_found, status: :not_found end end @@ -40,7 +41,7 @@ def destroy private def find_merchant - @merchant ||= User.find_by(id: params[:id].to_i) + @merchant ||= User.find_by(id: params[:id].to_i, type: "Merchant") if @merchant.nil? render :not_found diff --git a/app/views/order_products/_form.html.erb b/app/views/order_products/_form.html.erb index 4ee088abb6..cabfce8f62 100644 --- a/app/views/order_products/_form.html.erb +++ b/app/views/order_products/_form.html.erb @@ -1,7 +1,8 @@
- <% if op_id %> + <% if op_id %> <% @op = @current_order.order_products.find_by(id: op_id) %> <% end %> + <%= form_with model: @op, class: "form", locals: true do |f|%>
<%= f.label :quantity %> @@ -11,5 +12,7 @@ <%= f.hidden_field :product_id, value: product_id %> <%= f.submit button_title, class: "btn btn-primary" %> + + <% end %>
diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 2357a71457..fe9200931b 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -14,7 +14,7 @@ <% @products.each do |product|%> <%= link_to "#{product.name}", product_path(product.id) %> - <%= product.user %> + <%= product.user.name %> <%= product.created_at %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 09793a995d..2d78f2a077 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,3 +1,5 @@

Product Show Page

<%= render partial: "order_products/form", locals: { button_title: "Add to cart", op_id: nil, product_id: @product.id } %> + + diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 02953bd440..a8283b8c8e 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,12 +1,16 @@

Account Information

+<% if current_user.type == "Merchant" %> +

Hi Merchant

+<% end %> + <%= form_with model: @user, local: true do |f|%>

Enter more information to create your account.

<% type = 'Merchant' %> - <%= f.label "Would you like to become a merchant?" %> +<%= f.label "Would you like to become a merchant?" %> <%= f.check_box :type, {}, type %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 3e0fe0cb03..4ce06c60eb 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,7 +1,8 @@

<%= "#{@merchant.name}'s Good's Distribution Store" %>

-

+

Joined site on <%= "#{@merchant.created_at.strftime ("%b. %d, %Y")}" %> -

+

+ @@ -10,17 +11,27 @@ - + <% if !current_user || current_user.id != @merchant.id %> + + <% else %> + + + <% end %> <% @merchant.products.each do |product| %> - - - - + + + + <% if current_user.id != @merchant.id %> + + <% else %> + + + <% end %> <% end %> From 3b931e89f796144aa30ca62244a4c0da2c3a294e Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 22 Oct 2018 11:41:30 -0700 Subject: [PATCH 088/196] edit user --- app/controllers/users_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2a4ee1e62d..da8f42eb26 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -27,9 +27,9 @@ def update end def edit - @current_user.id - - if @current_user.nil? + @user ||= User.find_by(id: params[:id].to_i) + + if @user.nil? render :not_found, status: :not_found end end From 2f6852863d1aadcd0d2e1d517e2e0afdcaf6e62b Mon Sep 17 00:00:00 2001 From: jackie Date: Mon, 22 Oct 2018 12:29:48 -0700 Subject: [PATCH 089/196] Merge --- app/controllers/order_products_controller.rb | 1 + app/controllers/orders_controller.rb | 3 +- app/controllers/sessions_controller.rb | 2 +- app/models/order.rb | 25 +++++++++----- app/models/order_product.rb | 16 ++++++--- app/models/product.rb | 19 +++++++++-- test/fixtures/products.yml | 8 ++--- test/models/order_product_test.rb | 36 +++++++++++++------- test/models/order_test.rb | 21 ++++++------ 9 files changed, 86 insertions(+), 45 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index a53bbd7452..ffba14ccff 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -6,6 +6,7 @@ def create quantity = params[:order_product][:quantity].to_i # create the orderproduct, add it to the current cart, and save it + @current_order.save @current_order.add_product(product, quantity) # save the cart and update the session diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 83a6a13815..4171221312 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -19,7 +19,8 @@ def checkout def update @current_order.update(order_user_params) - paid_order_number = @current_order.submit_order + @current_order.submit_order + paid_order_number = @current_order.id session[:order_id] = nil diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e47ea1b71e..33c2de7cef 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -6,6 +6,7 @@ def create @user = User.find_by(uid: auth_hash[:uid], name: auth_hash[:name], provider: 'github') if @user flash[:success] = "Welcome back #{@user.name}" + redirect_to root_path else #try to make a new user @user = User.build_from_github(auth_hash) @@ -20,7 +21,6 @@ def create end end session[:user_id] = @user.id - redirect_to root_path end def destroy diff --git a/app/models/order.rb b/app/models/order.rb index 943e6c52ea..c913cb6c1a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -19,21 +19,28 @@ def add_product(product, quantity_ordered) # check if product is already in cart current_op = order_products.find_by(product_id: product.id) - if current_op # if so, edit quantity within existing orderproduct - current_op.edit_quantity(quantity_ordered) - else # if not, add new orderproduct - current_op = self.order_products.create(product_id: product.id, quantity: quantity_ordered, order_id: self.id) + if product.available?(quantity_ordered) + if current_op + current_op.edit_quantity(quantity_ordered) + else + current_op = self.order_products.create(product_id: product.id, quantity: quantity_ordered, order_id: self.id) + end + return current_op.save + else + return false end end def edit_quantity(op, quantity_ordered) - op.edit_quantity(quantity_ordered) + return op.edit_quantity(quantity_ordered) end def submit_order - self.status = "paid" - order_products.each { |op| op.update_stock } - self.save - return self.id + if order_products.each { |op| op.update_stock } + self.status = "paid" + return self.save + else + return false + end end end diff --git a/app/models/order_product.rb b/app/models/order_product.rb index ac6cd25b7e..49aefae652 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -1,3 +1,4 @@ +require 'pry' class OrderProduct < ApplicationRecord belongs_to :order belongs_to :product @@ -12,12 +13,19 @@ def subtotal end def update_stock - product.update_stock(quantity) - self.save + if product.update_stock(quantity) + return self.save + else + return false + end end def edit_quantity(quantity_ordered) - new_quantity = quantity + quantity_ordered - self.update(quantity: new_quantity) + if product.available?(quantity_ordered) + new_quantity = quantity + quantity_ordered + return self.update(quantity: new_quantity) + else + return false + end end end diff --git a/app/models/product.rb b/app/models/product.rb index 6082eafb85..53be091a41 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -42,9 +42,22 @@ class Product < ApplicationRecord # self.where(user: merchant) # end - def update_stock(quantity_purchased) - self.stock -= quantity_purchased - self.save + def update_stock(quantity_ordered) + if self.available?(quantity_ordered) + self.stock -= quantity_ordered + return self.save + else + return false + end end + def available?(quantity_ordered) + return false unless (quantity_ordered >= 1 && (quantity_ordered.is_a? Integer)) + + if quantity_ordered <= self.stock + return true + else + return false + end + end end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 9d7aaa6336..e0231effdf 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -1,8 +1,8 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html shirt: - user: one - name: MyString + user: merchant + name: "Shirt" price: 1.5 category: category1 description: "a nice shirt" @@ -10,8 +10,8 @@ shirt: photo_url: MyString dress: - user: two - name: MyString + user: merchant + name: "Dress" price: 1.5 category: category1 description: "a nice dress" diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index a9071b7d84..9601c888ca 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -3,6 +3,7 @@ describe OrderProduct do let(:shirts) { order_products(:shirts) } let(:dresses) { order_products(:dresses) } + let(:dress) { products(:dress) } it "must be valid" do value(shirts).must_be :valid? @@ -137,7 +138,7 @@ result = dresses.subtotal # Assert - expect(result).must_equal dresses.quantity * products(:dress).price + expect(result).must_equal dresses.quantity * dress.price end end @@ -147,8 +148,8 @@ # Act - Assert expect{ - dresses.edit_quantity(3) - }.must_change 'dresses.quantity', 1 #previously 2 + dresses.edit_quantity(1) + }.must_change 'dresses.quantity', 1 end it "cannot update the quantity to a value less than 1 or a non-integer" do @@ -187,26 +188,31 @@ # Act - Assert expect{ - dresses.edit_quantity(products(:dress).stock + 1) + dresses.edit_quantity(dress.stock + 1) }.wont_change 'dresses.quantity' - expect(dresses.edit_quantity(products(:dress).stock + 1)).must_equal false + expect(dresses.edit_quantity(dress.stock + 1)).must_equal false end end describe "update_stock" do it "reduces the stock by the quantity ordered" do expect{ - dresses.update_stock(2) - }.must_change 'dresses.quantity', 2 + dresses.update_stock + }.must_change 'dresses.product.stock', -2 end it "returns true if successful" do - expect(dresses.update_stock(2)).must_equal true + expect(shirts.update_stock).must_equal true end it "returns false if unsuccessful" do - expect(dresses.update_stock(2)).must_equal false + # Arrange + dresses.update(quantity: dresses.product.stock + 1) + op = OrderProduct.find_by(id: dresses.id) + + # Act - Assert + expect(op.update_stock).must_equal false end it "cannot reduce the stock below 0 or to a non-integer" do @@ -214,12 +220,16 @@ # Act - Assert expect{ - dresses.update_stock(dresses.product.stock + 1) - }.wont_change 'dresses.quantity' + dresses.update(quantity: dresses.product.stock + 1) + op = OrderProduct.find_by(id: dresses.id) + op.update_stock + }.wont_change 'dress.stock' expect{ - dresses.update_stock(1.5) - }.wont_change 'dresses.quantity' + dresses.update(quantity: 1.5) + op = OrderProduct.find_by(id: dresses.id) + op.update_stock + }.wont_change 'dress.stock' end end end diff --git a/test/models/order_test.rb b/test/models/order_test.rb index 112cfe8efb..e5bf3a77e0 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,5 +1,5 @@ require "test_helper" - +require 'pry' describe Order do let(:pending_order) { orders(:pending_order) } @@ -246,7 +246,8 @@ end it "will return true if successful" do - # Arrange done with let and before + # Arrange + new_product.save # Act - Assert expect(pending_order.add_product(products(:dress), 2)).must_equal true @@ -332,27 +333,27 @@ # Act - Assert expect(pending_order.status).must_equal "pending" - order_status = pending_order.submit_order - expect(order_status).must_equal "paid" + pending_order.submit_order + + expect(pending_order.status).must_equal "paid" end it "updates the stock of the product on order" do # Arrange - change = order_products(:dresses).quantity + change = -(order_products(:dresses).quantity) # Act - Assert expect{ pending_order.submit_order - }.must_change 'products(:dress).stock', change + }.must_change 'Product.find_by(id: order_products(:dresses).product.id).stock', change end it "returns false if order submission fails" do - # Arrange done with let + # Arrange + pending_order.user = nil # Act - Assert - expect( - 10.times { pending_order.submit_order } # should fail bec not enough stock - ).must_equal true + expect(pending_order.submit_order).must_equal false end it "returns true if order submission succeeds" do From 3cffd8bcc668db456acff95722046dbfa97aeb21 Mon Sep 17 00:00:00 2001 From: Jessie <36865499+jessiezhang2017@users.noreply.github.com> Date: Mon, 22 Oct 2018 12:36:53 -0700 Subject: [PATCH 090/196] Update order_product.rb --- app/models/order_product.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/order_product.rb b/app/models/order_product.rb index 49aefae652..da62914b6f 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -1,4 +1,3 @@ -require 'pry' class OrderProduct < ApplicationRecord belongs_to :order belongs_to :product From b4236a2c4db50320fa3d3cdc7a031e7c0b4036f8 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 12:55:16 -0700 Subject: [PATCH 091/196] adjusted the category controller name issue --- config/routes.rb | 2 +- ...tegorys_controller_test.rb => categories_controller_test.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename test/controllers/{categorys_controller_test.rb => categories_controller_test.rb} (74%) diff --git a/config/routes.rb b/config/routes.rb index ceca22225b..1329d4575d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ delete "/logout", to: "sessions#destroy", as: "logout" resources :users - resources :products + resources :products, except: [:destroy] resources :category, only: [:new, :create] resources :order_products diff --git a/test/controllers/categorys_controller_test.rb b/test/controllers/categories_controller_test.rb similarity index 74% rename from test/controllers/categorys_controller_test.rb rename to test/controllers/categories_controller_test.rb index 1481019f07..125dd4c91d 100644 --- a/test/controllers/categorys_controller_test.rb +++ b/test/controllers/categories_controller_test.rb @@ -1,6 +1,6 @@ require "test_helper" -describe CategorysController do +describe CategoriesController do # it "must be a real test" do # flunk "Need real tests" # end From caa8c6e4b13119bb14e4d5fc1f35c479061fe5c5 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 12:58:26 -0700 Subject: [PATCH 092/196] added routes for product index page --- config/routes.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 1329d4575d..7f0a8ed11e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,5 +14,9 @@ get "/checkout", to: "orders#checkout", as: "checkout" get "/order/:id", to: "orders#confirmation", as: "confirmation" + patch "/products/:id/retire", to: "products#retire", as: "retire" + get "/Products_by_category", to: "products#bycategory", as:"bycategory" + get "/Products_by_merchant", to: "products#bymerchant", as:"bymerchant" + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From 288e6d091a5cf300ee97500bd32693d5f22fcb34 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:01:47 -0700 Subject: [PATCH 093/196] updated category controller --- app/controllers/categories_controller.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index a14959525a..abfae0b96b 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,2 +1,26 @@ class CategoriesController < ApplicationController + def new + @category = Category.new + end + + def create + @category = Category.new(category_params) + if @category.save + flash[:success] = "Successfully created #{@category.name}!" + + redirect_to products_path + else + flash.now[:warning] = "Category is not created!" + @category.errors.messages.each do |field, messages| + flash.now[field] = messages + end + render :new + end + end + + private + + def category_params + return params.require(:category).permit(:name) + end end From 4b8e0cb37afcae1f5c9134f2a37d64597b949978 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:03:44 -0700 Subject: [PATCH 094/196] added actions to product controller --- app/controllers/products_controller.rb | 57 ++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 1c01e9592f..1a78123a2e 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,10 +1,17 @@ class ProductsController < ApplicationController - before_action :find_product, only: [:show, :edit, :update, :destroy] + before_action :find_product, only: [:show, :edit, :update, :retire] def index - @products = Product.all + @products = Product.active_products + end + + def bycategory + @products_by_category = Product.to_category_hash + end + def bymerchant + @products_by_merchant = Product.to_merchant_hash end def show @@ -14,25 +21,50 @@ def show def new @product = Product.new - + if session[:user_id] + @product = @current_user.products.new + end end def create - end + if session[:user_id] - def edit + product = @current_user.products.new(product_params) + if @current_user.save + flash[:success] = 'Product Created!' + redirect_to product_path(id: product.id) + else + flash.now[:danger] = 'Product not created!' + render :new, status: :bad_request + end + else + flash.now[:danger] = 'Not a Merchant!' + end end - def update - end + def edit; end - def destroy + def update + if @product && @product.update(product_params) + redirect_to product_path(@product.id) + elsif @product + render :edit, status: :bad_request + end + end + def retire + @product.status = false + if @product.save + flash[:success] = "#{@product.name} retired" + redirect_to products_path + else + lash[:warning] = "#{@product.name} is not retired" + end end @@ -46,8 +78,15 @@ def find_product end end + def find_merchant + @merchant = Merchant.find_by(id: session[:user_id].to_i) + if @merchant.nil? + flash.now[:danger] = "Cannot find the merchant #{session[:user_id]}" + render :notfound, status: :not_found + end + end + def product_params return params.require(:product).permit(:name, :category_id, :price, :description, :stock, :photo_url) end - end From a99262d65569ee371788f30828120996dc6a224c Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:05:32 -0700 Subject: [PATCH 095/196] added category list method to category model --- app/models/category.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/category.rb b/app/models/category.rb index ded933dd49..f6bc87c99b 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,10 @@ class Category < ApplicationRecord has_many :products validates :name, presence: true + + def self.category_list + return Category.all.map do |category| + [category.name, category.id] + end + end end From 919adeda4635cf4828a2a8b979a7dff9ea3e4d04 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:07:04 -0700 Subject: [PATCH 096/196] added product model methods --- app/models/product.rb | 86 ++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index 53be091a41..abf224d076 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -6,41 +6,59 @@ class Product < ApplicationRecord validates :name, presence: true, uniqueness: { scope: :category } - validates :price, presence: true - validates :user_id, presence: true - validates :stock, presence: true - - validates :category, presence: true, - inclusion: { in: Category.all } - - - - # - # - # def self.to_category_hash - # data = {} - # Category.all.each do |cat| - # data[cat] = by_category(cat) - # end - # return data - # end - # - # def self.by_category(category) - # self.where(category: category) - # end - # - # def self.to_merchant_hash - # data = {} - # Merchant.all.each do |user| - # data[user] = by_merchant(user) - # end - # return data - # end - # - # def self.by_merchant(merchant) - # self.where(user: merchant) - # end + validates :stock, presence: true, numericality: { :only_integer => true, :greater_than_or_equal_to => 0} + + validates :price, presence: true, numericality: {:greater_than_or_equal_to => 0} + validates :category_id, presence: true + + def self.active_products + return Product.all.select {|e| e.status == true} + end + + + def self.to_category_hash + data = {} + Category.all.each do |cat| + data[cat] = by_category(cat) + end + return data + end + + def self.by_category(category) + self.active_products.select {|prod| prod.category == category} + end + + def self.to_merchant_hash + data = {} + Merchant.all.each do |user| + data[user] = by_merchant(user) + end + return data + end + + def self.by_merchant(merchant) + self.active_products.select {|prod| prod.user == merchant} + end + + def update_stock(quantity_ordered) + if self.available?(quantity_ordered) + self.stock -= quantity_ordered + return self.save + else + return false + end + end + + def available?(quantity_ordered) + return false unless (quantity_ordered >= 1 && (quantity_ordered.is_a? Integer)) + + if quantity_ordered <= self.stock + return true + else + return false + end + end def update_stock(quantity_ordered) if self.available?(quantity_ordered) From 6ac20cd649258ae2760808ab89e163c6e15826d1 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:10:00 -0700 Subject: [PATCH 097/196] udpated the prod index page --- app/views/products/index.html.erb | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index fe9200931b..371f8add6c 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,12 +1,25 @@

List of Products

+ +
-
Product Name Quantity CategoryAdd to CartAdd to CartRemove productEdit stock
product image <%= "#{product.name}" %> <%= "#{product.quantity}" %> <%= "#{product.category}" %> add to cart <%= link_to "#{product.name}", product_path(product.id) %> <%= "#{product.stock}" %> <%= "#{product.category.name}" %> add to cart delete product increase stock
+
- + - + + @@ -14,9 +27,9 @@ <% @products.each do |product|%> - - - + + + <%end%> From 44ebcf8ff3a3e04586893c7e9c10a83f356d6944 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:11:06 -0700 Subject: [PATCH 098/196] prod show page --- app/views/products/show.html.erb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 2d78f2a077..a4e5cf2610 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,5 +1,21 @@ -

Product Show Page

+

Product Details: <%= @product.name %>

-<%= render partial: "order_products/form", locals: { button_title: "Add to cart", op_id: nil, product_id: @product.id } %> + - +

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

+

Description: <%= @product.description%>

+

Merchant: <%= @product.user.name%>

+

Price: <%= @product.price%>

+

Quantity available: <%= @product.stock%>

+

status: <%= @product.status%>

+ +<%if @product.stock != 0 %> + <%= render partial: "order_products/form", locals: { button_title: "Add to cart", op_id: nil, product_id: @product.id } %> +<%end%> From 752644d299b8fe1c02e7a2e53b6042d3275d3d83 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:13:16 -0700 Subject: [PATCH 099/196] created files for html.erb --- app/views/products/_form.html.erb | 0 app/views/products/edit.html.erb | 0 app/views/products/new.html.erb | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/views/products/_form.html.erb create mode 100644 app/views/products/edit.html.erb create mode 100644 app/views/products/new.html.erb diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..e69de29bb2 From 313d98342f61279f15dd9023c087fee230fb14e8 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:14:28 -0700 Subject: [PATCH 100/196] updated form html for prod --- app/views/products/_form.html.erb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index e69de29bb2..99771f9c14 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -0,0 +1,27 @@ + +

<%= action_name %>

+ +<%= render partial: "layouts/form_errors", locals: { model: @product } %> + +<%= form_with model: @product, class: "product-form" do |f|%> + + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :category_id, "Category" %> + <%= f.select :category_id, Category.category_list %> + + <%= f.label :description %> + <%= f.text_field :description%> + + <%= f.label :price %> + <%= f.text_area :price %> + + <%= f.label :stock %> + <%= f.text_area :stock %> + + <%= f.label :photo_url %> + <%= f.text_area :photo_url %> + + <%= f.submit button_title, class: "btn btn-primary" %> +<% end %> From efdffecb40ca8d29e36e5f0c1dd6ec014c77e5fe Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:15:10 -0700 Subject: [PATCH 101/196] updated the edit html for prod --- app/views/products/edit.html.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb index e69de29bb2..3ff43d1ffa 100644 --- a/app/views/products/edit.html.erb +++ b/app/views/products/edit.html.erb @@ -0,0 +1,3 @@ +<%= render partial: "form", + locals: { action_name: 'Edit product', + button_title: 'Edit' } %> From eea9352fb64fb7ce024b4a42f4f15050026a2079 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:17:09 -0700 Subject: [PATCH 102/196] added two pages to products --- app/views/products/bycategory.html.erb | 0 app/views/products/bymerchant.html.erb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/views/products/bycategory.html.erb create mode 100644 app/views/products/bymerchant.html.erb diff --git a/app/views/products/bycategory.html.erb b/app/views/products/bycategory.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/products/bymerchant.html.erb b/app/views/products/bymerchant.html.erb new file mode 100644 index 0000000000..e69de29bb2 From 3624b3d46313f5d54ac6a49f8af241c91575960c Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:18:23 -0700 Subject: [PATCH 103/196] updated the bymerchant html --- app/views/products/bymerchant.html.erb | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/views/products/bymerchant.html.erb b/app/views/products/bymerchant.html.erb index e69de29bb2..bb5f15f4be 100644 --- a/app/views/products/bymerchant.html.erb +++ b/app/views/products/bymerchant.html.erb @@ -0,0 +1,39 @@ +

List of Products by Merchant

+ + + +<% @products_by_merchant.each do |key, value|%> + +

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

+
NameProduct Name SellerCreated atPriceReview
<%= link_to "#{product.name}", product_path(product.id) %><%= product.user.name %><%= product.created_at %><%= link_to "#{product.user.name}", user_path(product.user.id) %><%= product.price %>
+ + + + + + + + + + <% value.each do |product|%> + + + + + + + <%end%> + +
Product NameCategoryPriceReview
<%= link_to "#{product.name}", product_path(product.id) %><%= link_to "#{product.category.name}", user_path(product.user.id) %><%= product.price %>
+ +<%end%> From 2bd7fb231a60173d1e64712e5a48cf8dc7de09d9 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:20:11 -0700 Subject: [PATCH 104/196] udated the bycategory html --- app/views/products/bycategory.html.erb | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/views/products/bycategory.html.erb b/app/views/products/bycategory.html.erb index e69de29bb2..2b00aebfbd 100644 --- a/app/views/products/bycategory.html.erb +++ b/app/views/products/bycategory.html.erb @@ -0,0 +1,39 @@ +

List of Products by Category

+ + + +<% @products_by_category.each do |key, value|%> + +

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

+ + + + + + + + + + + <% value.each do |product|%> + + + + + + + <%end%> + +
Product NameSellerPriceReview
<%= link_to "#{product.name}", product_path(product.id) %><%= link_to "#{product.user.name}", user_path(product.user.id) %><%= product.price %>
+
+<%end%> From 18de0f97872fc523b8f06191418a3315e5031c20 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:24:23 -0700 Subject: [PATCH 105/196] added category folder in view --- app/views/categories/new.html.erb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/views/categories/new.html.erb diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..e69de29bb2 From 985b8b899dfcd49cb349f79a414e574f1d4ad9a1 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:25:05 -0700 Subject: [PATCH 106/196] udpated the new.html for category --- app/views/categories/new.html.erb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb index e69de29bb2..1de29144e0 100644 --- a/app/views/categories/new.html.erb +++ b/app/views/categories/new.html.erb @@ -0,0 +1,17 @@ +

New Category

+ +<%= form_with model: @category, local: true do |f|%> +

Enter more information to create a new category.

+ +
+ <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
+ + <% if @current_user %> + <%= f.submit "New!", class: "btn btn-primary" %> + <% else %> + <%= f.submit "New!", class: "btn btn-primary", disabled: true %> + <% end %> + +<% end %> From a5d986c49c9eba48fe50a54e7af49ec07ddd1a5a Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 13:57:05 -0700 Subject: [PATCH 107/196] did the db:seed --- db/schema.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 0aef960899..fcbd8a9595 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_223725) do +ActiveRecord::Schema.define(version: 2018_10_22_202759) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -54,6 +54,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "category_id" + t.boolean "status", default: true t.index ["category_id"], name: "index_products_on_category_id" t.index ["user_id"], name: "index_products_on_user_id" end From 4045d0bfa4d0cbc4c98ff4af22309a7f39a5947f Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 14:02:53 -0700 Subject: [PATCH 108/196] remove the check with merchant for display --- app/views/products/index.html.erb | 2 +- app/views/products/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 371f8add6c..11b0b5ac19 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -5,7 +5,7 @@
  • <%= link_to "All Products", products_path%>
  • <%= link_to "Products by Category", bycategory_path%>
  • <%= link_to "Products by Merchant", bymerchant_path%>
  • - <% if @current_user && @current_user.type == "Merchant"%> + <% if @current_user %>
  • <%= link_to "Add New Category", new_category_path%>
  • <%= link_to "Add New Product", new_product_path%>
  • <%end%> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index a4e5cf2610..c898978122 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,7 +1,7 @@

    Product Details: <%= @product.name %>

    From 3f002430364997feff07563eb57f01d6e2735049 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Mon, 22 Oct 2018 15:04:50 -0700 Subject: [PATCH 113/196] fixed the product show page layout --- app/assets/stylesheets/products.scss | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index bff386e55a..83904e8e1b 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -1,3 +1,21 @@ // 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/ +.product-form { + display: flex; + flex-direction: column; + + margin: 2%; +} + +section { + width: 100%; +} +.table-striped { + width: 100%; + margin-bottom: 2%; +} + +.table-striped th { + width: 30%; +} From f4db419f9189af4c351ae379304633e534278734 Mon Sep 17 00:00:00 2001 From: Jacquelyn Cheng <35181875+jacquelynoelle@users.noreply.github.com> Date: Mon, 22 Oct 2018 15:18:49 -0700 Subject: [PATCH 114/196] Removed duplicate methods --- app/models/product.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index abf224d076..bb1720a7a7 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -59,23 +59,3 @@ def available?(quantity_ordered) return false end end - - def update_stock(quantity_ordered) - if self.available?(quantity_ordered) - self.stock -= quantity_ordered - return self.save - else - return false - end - end - - def available?(quantity_ordered) - return false unless (quantity_ordered >= 1 && (quantity_ordered.is_a? Integer)) - - if quantity_ordered <= self.stock - return true - else - return false - end - end -end From c8de19ec7c7f811d4314a09c7e7aba1e13655239 Mon Sep 17 00:00:00 2001 From: Jacquelyn Cheng <35181875+jacquelynoelle@users.noreply.github.com> Date: Mon, 22 Oct 2018 15:19:17 -0700 Subject: [PATCH 115/196] Re-added removed end --- app/models/product.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/product.rb b/app/models/product.rb index bb1720a7a7..35259cdbf9 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -59,3 +59,4 @@ def available?(quantity_ordered) return false end end +end From 1147e74474c78c3ba2d3343135fa70cdd2d57065 Mon Sep 17 00:00:00 2001 From: Jacquelyn Cheng <35181875+jacquelynoelle@users.noreply.github.com> Date: Mon, 22 Oct 2018 15:22:21 -0700 Subject: [PATCH 116/196] Removed section selector that was too vague We'll fix this later when we do front-end. --- app/assets/stylesheets/products.scss | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 83904e8e1b..d29b878e27 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -8,9 +8,6 @@ margin: 2%; } -section { - width: 100%; -} .table-striped { width: 100%; margin-bottom: 2%; From b26cb6a2df74c9166e156aec58c21841f38bab5d Mon Sep 17 00:00:00 2001 From: jackie Date: Mon, 22 Oct 2018 20:00:20 -0700 Subject: [PATCH 117/196] Header and navigation draft --- app/assets/stylesheets/application.scss | 104 ++++++++++++++++++++++++ app/views/layouts/application.html.erb | 57 +++++++++---- 2 files changed, 147 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8b1701e581..7cbae67d95 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,3 +16,107 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; + +/* Sovietski color scheme */ +$white: #fefdff; + +$dark-grey: #343a40; +$light-grey: #d1d5d7; + +$dark-red: #b20023; +$light-red: #d6798c; + +$dark-blue: #007ea7; +$light-blue: #5cacc7; + +$dark-yellow: #f3ca40; +$light-yellow: #f7dd85; + + +/* +Google Fonts: +font-family: 'Bungee', cursive; +font-family: 'Bungee Shade', cursive; +font-family: 'Raleway', sans-serif; +*/ + +body { + background-color: $white; + color: $dark-grey; + font-family: 'Raleway', sans-serif; + margin: 1rem; +} + +/* Material design icon styling */ +/* Rules for sizing the icon. */ +.material-icons.md-18 { font-size: 18px; } +.material-icons.md-24 { font-size: 24px; } +.material-icons.md-36 { font-size: 36px; } +.material-icons.md-48 { font-size: 48px; } + +/* Rules for using icons as black on a light background. */ +.material-icons.md-dark { color: rgba(0, 0, 0, 0.54); } +.material-icons.md-dark.md-inactive { color: rgba(0, 0, 0, 0.26); } + +/* Rules for using icons as white on a dark background. */ +.material-icons.md-light { color: rgba(255, 255, 255, 1); } +.material-icons.md-light.md-inactive { color: rgba(255, 255, 255, 0.3); } + +#sovietski-header { + justify-content: space-between; +} + +h1.sovietski-logo { + text-align: center; +} + +a.sovietski-logo { + font-family: 'Bungee', cursive; + font-size: 3rem; + color: $dark-grey; + text-decoration: none; + text-align: center; +} + +a.btn-primary { + background-color: $dark-yellow; + border-color: $dark-yellow; + color: $dark-grey; + font-weight: bold; +} + +a.btn-primary:hover { + background-color: $light-yellow; + border-color: $light-yellow; + color: $dark-grey; +} + +div.cart-button { + display: flex; + align-content: center; + justify-content: center; +} + +#shopping-cart-icon { + padding-right: 0.5rem; +} + +nav ul { + list-style: none; +} + +.nav-link { + color: $dark-grey; +} + +.nav-link:hover { + color: $dark-yellow; +} + +.dropdown-item:hover { + background-color: $dark-yellow; +} + +li.user-nav { + margin-right: 1rem; +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 841e149a19..7f09fd0168 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,24 +14,53 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + - +

    <%= link_to "Sovietski", root_path, class: "sovietski-logo" %>

    + + + +
    <%flash.each do |name, message|%> From 9ded81c6dd03061f5e667ad68ca3ebcdd4198f31 Mon Sep 17 00:00:00 2001 From: jackie Date: Mon, 22 Oct 2018 22:21:47 -0700 Subject: [PATCH 118/196] Shopping cart styling, still needs some work --- app/assets/stylesheets/application.scss | 49 ++++++++++++++- app/assets/stylesheets/order_products.scss | 12 ++++ app/assets/stylesheets/orders.scss | 26 ++++++-- app/views/layouts/application.html.erb | 2 +- app/views/order_products/_form.html.erb | 8 +-- app/views/orders/cart.html.erb | 70 ++++++++++++---------- 6 files changed, 121 insertions(+), 46 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7cbae67d95..e4b7efd2b4 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -44,7 +44,11 @@ body { background-color: $white; color: $dark-grey; font-family: 'Raleway', sans-serif; - margin: 1rem; + padding: 2rem 1rem 1rem 1rem; +} + +main { + padding: 2rem 3rem; } /* Material design icon styling */ @@ -78,14 +82,20 @@ a.sovietski-logo { text-align: center; } -a.btn-primary { +a.cart-button { background-color: $dark-yellow; border-color: $dark-yellow; color: $dark-grey; font-weight: bold; } -a.btn-primary:hover { +input.btn-primary { + background-color: $dark-yellow; + border-color: $dark-yellow; + color: $dark-grey; +} + +a.btn-primary:hover, input.btn-primary:hover { background-color: $light-yellow; border-color: $light-yellow; color: $dark-grey; @@ -120,3 +130,36 @@ nav ul { li.user-nav { margin-right: 1rem; } + +a.btn-danger { + background-color: $dark-red; + border-color: $dark-red; + color: $white; +} + +a.btn-danger:hover { + background-color: $light-red; + border-color: $light-red; +} + +a.btn-secondary { + background-color: $dark-blue; + border-color: $dark-blue; + color: $white; +} + +a.btn-secondary:hover { + background-color: $light-blue; + border-color: $light-blue; +} + +a.btn-outline-danger { + border-color: $dark-red; + color: $dark-red; +} + +a.btn-outline-danger:hover { + background-color: $dark-red; + border-color: $dark-red; + color: $white; +} diff --git a/app/assets/stylesheets/order_products.scss b/app/assets/stylesheets/order_products.scss index 4e38cdae9b..1ef27c403b 100644 --- a/app/assets/stylesheets/order_products.scss +++ b/app/assets/stylesheets/order_products.scss @@ -1,3 +1,15 @@ // Place all the styles related to the OrderProducts controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +form.product-quantity-form > * { + padding-right: 1rem; +} + +form.product-quantity-form > .form-group > label { + padding-right: 0.5rem; +} + +input.form-control.quantity-field { + width: 4rem; +} diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss index 827f73d991..cc6bd5e22a 100644 --- a/app/assets/stylesheets/orders.scss +++ b/app/assets/stylesheets/orders.scss @@ -2,12 +2,30 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -section.cart { +div.card-footer.cart-item-actions { + display: flex; + flex-direction: row; + justify-content: flex-end; + align-items: center; +} + +article.checkout-actions { display: flex; flex-direction: column; - margin: 2rem; + align-items: center; +} + +section.cart.card-group { + display: flex; + flex-direction: column; + padding: 0; +} + +section.cart.card-group > .card { + margin-bottom: 1rem; + padding-bottom: 0.75rem; } -article.card { - width: 60%; +div.cart.container-fluid { + margin-top: 1rem; } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7f09fd0168..cbdb4d7b24 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -50,7 +50,7 @@
  • <%= link_to "Login with Github", "/auth/github", class: "nav-item btn btn-outline-dark" %>
  • <% end %>
  • - +
    shopping_cart <%= "#{@current_order.order_products.length} items" %> diff --git a/app/views/order_products/_form.html.erb b/app/views/order_products/_form.html.erb index 317755a91b..02d9febd61 100644 --- a/app/views/order_products/_form.html.erb +++ b/app/views/order_products/_form.html.erb @@ -1,16 +1,14 @@ -
    +
    <% @op = op if op %> - <%= form_with model: @op, class: "form", locals: true do |f|%> + <%= form_with model: @op, class: "form-inline product-quantity-form", locals: true do |f|%>
    <%= f.label :quantity %> - <%= f.select :quantity, (0..Product.find_by(id: product_id).stock), {}, class: "form-control" %> + <%= f.number_field :quantity, in: 0..(Product.find_by(id: product_id).stock), class: "form-control quantity-field" %>
    <%= f.hidden_field :product_id, value: product_id %> <%= f.submit button_title, class: "btn btn-primary" %> - - <% end %>
    diff --git a/app/views/orders/cart.html.erb b/app/views/orders/cart.html.erb index dab8023eb2..1e34a23a92 100644 --- a/app/views/orders/cart.html.erb +++ b/app/views/orders/cart.html.erb @@ -1,35 +1,39 @@ -

    This is the shopping cart!

    -
    - <% if @current_order %> - <% @current_order.order_products.each do |op| %> -
    -
    -
    - Product -
    -
    -
    -
    <%= op.product.name %>
    -
    -

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

    -

    <%= "Quantity: #{op.quantity}" %>

    -

    <%= "Subtotal: #{op.subtotal}" %>

    -
    +

    Shopping Cart

    +
    +
    +
    + <% if @current_order.order_products.any? %> + <% @current_order.order_products.each do |op| %> +
    +
    +
    + Product +
    +
    +
    +
    <%= op.product.name %>
    +
    +

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

    +

    <%= "Quantity: #{op.quantity}" %>

    +

    <%= "Subtotal: #{op.subtotal}" %>

    +
    +
    +
    -
    -
    - -
    - <% end %> -
    - Total: <%= @current_order.total %> - <%= link_to "Checkout", checkout_path, method: :get, class: "btn btn-info" %> + +
    + <% end %> + + <% else %> +

    Nothing here yet... go shopping!

    + <% end %> +
    +
    +

    Total: <%= @current_order.total %>

    + <%= link_to "Continue to checkout", checkout_path, method: :get, class: "btn btn-secondary" %>
    - - <% else %> -

    Nothing here yet... go shopping!

    - <% end %> -
    +
    + From df12a50aab69873f33e8c5e584800bf3db322772 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Tue, 23 Oct 2018 08:21:51 -0700 Subject: [PATCH 119/196] basic changes to user stuff --- app/controllers/application_controller.rb | 3 +-- app/controllers/sessions_controller.rb | 12 ++++++------ app/controllers/users_controller.rb | 11 ++++------- app/views/layouts/application.html.erb | 1 - app/views/users/_info.html.rb | 1 + app/views/users/edit.html.erb | 4 ++-- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2e2750c5fc..9c3f6176f1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,8 +15,7 @@ def current_order private def find_user - @current_user ||= User.find_by(id: session[:user_id]) - + @current_user ||= User.find_by(id: session[:user_id]) end def generate_cart diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index be0f8b4c3e..1602d16768 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,14 +3,14 @@ class SessionsController < ApplicationController def create auth_hash = request.env['omniauth.auth'] - @user = User.find_by(uid: auth_hash[:uid], name: auth_hash[:name], provider: 'github') - if @user + @current_user = User.find_by(uid: auth_hash[:uid], name: auth_hash[:name], provider: 'github') + if @current_user flash[:success] = "Welcome back #{@user.name}" - redirect_to root_path + redirect_to user_path(@user.id) else #try to make a new user - @user = User.build_from_github(auth_hash) - if @user.save + @current_user = User.build_from_github(auth_hash) + if @current_user.save flash[:success] = "Welcome #{@user.name}" redirect_to edit_user_path(@user.id) #would you like to register as a merchant? @@ -21,7 +21,7 @@ def create end end - session[:user_id] = @user.id + session[:user_id] = @current_user.id end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index da8f42eb26..45e3fbd8bf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController before_action :find_merchant, except: [:index, :edit] - before_action :find_user + # before_action :find_user def index @merchants = Merchant.all #adding merchants to index for viewing and sorting in views @@ -11,13 +11,10 @@ def new @user = User.new end - def create; end - - def show; end def update - if @user && @user.update(user_params) #(if user exists AND can be updated) + if @current_user && @current_user.update(user_params) flash[:success] = "Saved" redirect_to root_path else @@ -27,9 +24,9 @@ def update end def edit - @user ||= User.find_by(id: params[:id].to_i) + @current_user.id - if @user.nil? + if @current_user.nil? render :not_found, status: :not_found end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 841e149a19..e0cb0522bc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -23,7 +23,6 @@
  • <%= link_to "All Merchants", users_path %>
  • <% if current_user %>
  • <%= link_to "Edit Profile", edit_user_path(@current_user.id) %>
  • -
  • <%= link_to "Log out #{@current_user.name}", logout_path, method: 'delete' %>
  • <% else %>
  • <%= link_to "Login with Github", "/auth/github" %>
  • diff --git a/app/views/users/_info.html.rb b/app/views/users/_info.html.rb index e69de29bb2..e016604347 100644 --- a/app/views/users/_info.html.rb +++ b/app/views/users/_info.html.rb @@ -0,0 +1 @@ +# Merchant info for use on product page diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index a8283b8c8e..81db0ef9fe 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -4,12 +4,12 @@

    Hi Merchant

    <% end %> -<%= form_with model: @user, local: true do |f|%> +<%= form_with model: @current_user, local: true do |f|%>

    Enter more information to create your account.

    - <% type = 'Merchant' %> + <% if @current_user.type = 'Merchant' %> <%= f.label "Would you like to become a merchant?" %> <%= f.check_box :type, {}, type %> From c1d23c908b1adc825c40ad65a364f40a26c40ca7 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Tue, 23 Oct 2018 10:10:22 -0700 Subject: [PATCH 120/196] added tests for product model --- test/controllers/products_controller_test.rb | 236 +++++++++++++++++++ test/models/product_test.rb | 218 ++++++++++++++++- 2 files changed, 452 insertions(+), 2 deletions(-) diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 392a20e292..c535454f09 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -4,4 +4,240 @@ # it "must be a real test" do # flunk "Need real tests" # end + + it "should get index" do + get products_path + + must_respond_with :success + end + + describe "show" do + it "should get a product's show page" do + # Arrange + id = products(:poodr).id + + # Act + get product_path(id) + + # Assert + must_respond_with :success + end + + it "should respond with not_found if given an invalid id" do + # Arrange - invalid id + id = -1 + + # Act + get product_path(id) + + # Assert + must_respond_with :not_found + expect(flash[:danger]).must_equal "Cannot find the product -1" + end + end + + describe "new" do + it "can get the new book page" do + + # Act + get new_book_path + + # Assert + must_respond_with :success + end + + it "can get the form with the new_author_book_path" do + # Arrange + id = authors(:jordan).id + + # Act + get new_author_book_path(id) + + # Assert + must_respond_with :success + end + it "must respond with success for an invalid author id" do + # Arrange + id = -1 + + # Act + get new_author_book_path(id) + + # Assert + must_respond_with :success + expect(flash[:warning]).must_equal "That author doesn't exit" + end + end + + describe "edit" do + it "can get the edit page for a valid book" do + # Arrange + id = books(:poodr).id + + # Act + get edit_book_path(id) + + # Assert + must_respond_with :success + end + + it "should respond with not_found if given an invalid id" do + # Arrange - invalid id + id = -1 + + # Act + get edit_book_path(id) + + # Assert + expect(response).must_be :not_found? + must_respond_with :not_found + expect(flash[:danger]).must_equal "Cannot find the book -1" + end + + # not log in user cannot edit + + # log in user can edit own + + # logn in user cannot edit others + + # display not found for invalid post id.. + + + end + + describe "destroy" do + it "can destroy a book given a valid id" do + # Arrange + id = books(:poodr).id + title = books(:poodr).title + + # Act - Assert + expect { + delete book_path(id) + }.must_change 'Book.count', -1 + + must_respond_with :redirect + must_redirect_to books_path + expect(flash[:success]).must_equal "#{title} deleted" + expect(Book.find_by(id: id)).must_equal nil + end + + it "should respond with not_found for an invalid id" do + id = -1 + + # Equivalent + # before_count = Book.count + # delete book_path(id) + # after_count = Book.count + # expect(before_count).must_equal after_count + + expect { + delete book_path(id) + # }.must_change 'Book.count', 0 + }.wont_change 'Book.count' + + must_respond_with :not_found + expect(flash.now[:danger]).must_equal "Cannot find the book #{id}" + end + # only logged in user can delete their own user id /delete/user/:id + # delete /user can only delete a user who is logged in , so they can delete themselves, no-one else. + # delete a user with all their post + # dependant: nullify + # for invlid id , repond with not_found + # making sure the system is not fail if a use has no post delete its self , and did not cause the issue. + # + end + + describe "create & update" do + let (:book_hash) do + { + book: { + title: 'White Teeth', + author_id: authors(:galbraith).id, + description: 'Good book' + } + } + end + + + describe "create" do + it "can create a new book given valid params" do + # Act-Assert + expect { + post books_path, params: book_hash + }.must_change 'Book.count', 1 + + must_respond_with :redirect + must_redirect_to book_path(Book.last.id) + + expect(Book.last.title).must_equal book_hash[:book][:title] + expect(Book.last.author).must_equal Author.find_by(id: book_hash[:book][:author_id]) + expect(Book.last.description).must_equal book_hash[:book][:description] + + end + + it "responds with an error for invalid params" do + # Arranges + book_hash[:book][:title] = nil + + # Act-Assert + expect { + post books_path, params: book_hash + }.wont_change 'Book.count' + + must_respond_with :bad_request + + end + end + + describe "update" do + it "can update a model with valid params" do + id = books(:poodr).id + + expect { + patch book_path(id), params: book_hash + }.wont_change 'Book.count' + + must_respond_with :redirect + must_redirect_to book_path(id) + + new_book = Book.find_by(id: id) + + expect(new_book.title).must_equal book_hash[:book][:title] + expect(new_book.author_id).must_equal book_hash[:book][:author_id] + expect(new_book.description).must_equal book_hash[:book][:description] + end + it "gives an error if the book params are invalid" do + # Arrange + book_hash[:book][:title] = nil + id = books(:poodr).id + old_poodr = books(:poodr) + + + expect { + patch book_path(id), params: book_hash + }.wont_change 'Book.count' + new_poodr = Book.find(id) + + must_respond_with :bad_request + expect(old_poodr.title).must_equal new_poodr.title + expect(old_poodr.author_id).must_equal new_poodr.author_id + expect(old_poodr.description).must_equal new_poodr.description + end + it "gives not_found for a book that doesn't exist" do + id = -1 + + expect { + patch book_path(id), params: book_hash + }.wont_change 'Book.count' + + must_respond_with :not_found + + end + end + + + + end + end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index a618b0a156..9b2bc97ccc 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,9 +1,223 @@ require "test_helper" describe Product do - let(:product) { Product.new } + let(:product) { products(:shirt) } + let(:product2) {products(:dress)} + let(:user) { users(:user1) } + let(:category1) {categories(:category1)} + let(:category2) {categories(:category2)} it "must be valid" do - value(product).must_be :valid? + expect(product).must_be :valid? + end + + it 'has required fields' do + fields = [:name, :user_id, :stock, :category_id, :price, :status] + + fields.each do |field| + expect(product).must_respond_to field + end end + + describe "validations" do + it "requires a name" do + product.name = nil + product.valid?.must_equal false + product.errors.messages.must_include :name + end + + it "requires unique names w/in categories" do + + prod1 = Product.new(name: "Polo shirt") + prod1.user = user + prod1.stock = 10 + prod1.price = 5 + prod1.category = category1 + + prod1.save! + + prod2 = Product.new(name: "Polo shirt") + prod2.user = user + prod2.stock = 10 + prod2.price = 5 + prod2.category = category1 + + prod2.valid?.must_equal false + prod2.errors.messages.must_include :name + end + + it "does not require a unique name if the category is different" do + + prod1 = Product.new(name: "Polo shirt") + prod1.user = user + prod1.stock = 10 + prod1.price = 5 + prod1.category = category1 + + prod1.save! + last = Product.all.count + + prod2 = Product.new(name: "Polo shirt") + prod2.user = user + prod2.stock = 10 + prod2.price = 5 + prod2.category = category2 + + prod2.save! + expect(Product.all.count).must_equal last+1 + end + + it "requires a user_id" do + product.user_id = nil + product.valid?.must_equal false + product.errors.messages.must_include :user_id + end + + it "requires a category_id" do + product.category_id = nil + product.valid?.must_equal false + product.errors.messages.must_include :category_id + end + + + it "reject a invalid stock value" do + product.stock = nil + product.valid?.must_equal false + product.errors.messages.must_include :stock + end + + + it " stock value cannot be negative" do + product.stock = -1 + product.valid?.must_equal false + + end + + it " stock value can be 0" do + last = Product.all.count + + prod2 = Product.new(name: "Polo shirt") + prod2.user = user + prod2.stock = 0 + prod2.price = 5 + prod2.category = category2 + + prod2.save! + expect(Product.all.count).must_equal last+1 + end + + it "it only accept integers as stock quantity" do + product.stock = 2.1 + + product.valid?.must_equal false + + end + + it "reject invalid price" do + product.price = nil + product.valid?.must_equal false + product.errors.messages.must_include :price + end + + it "accept 0 price" do + last = Product.all.count + + prod2 = Product.new(name: "Polo shirt") + prod2.user = user + prod2.stock = 0 + prod2.price = 0 + prod2.category = category2 + + prod2.save! + expect(Product.all.count).must_equal last+1 + end + end + + + describe "active_products" do + it "returns an array" do + products = Product.active_products + expect(products).must_be_instance_of Array + end + + it "returns an empty array if no active products" do + product.status = false + product2.status = false + product.save + product2.save + expect(Product.active_products.empty?).must_equal true + + end + + it "returns an array of product" do + expect(Product.active_products.first).must_be_kind_of Product + end + + it "The array length will be added by 1 for a newly created product" do + prod2 = Product.new(name: "Polo shirt") + prod2.user = user + prod2.stock = 2 + prod2.price = 1 + prod2.category = category2 + count = Product.active_products.length + prod2.save! + + expect(Product.active_products.length).must_equal count+1 + + end + + it "The array will include all the valid product" do + expect(Product.active_products.first).must_equal product + expect(Product.active_products.last).must_equal product2 + + end + end + + + describe "self.by_category" do + + it "returns an array of correct product " do + list1 = Product.by_category(category1) + expect(list1.count).must_equal 2 + + list1.each do |prod| + prod.must_be_kind_of Product + prod.category.must_equal category1 + end + end + + it "returns an empty array if no product in that categor" do + list2 = category.by_category(category2) + expect(list2.empty?).must_equal true + end + end + + describe "self.by_merchant" do + before do + user2 = User.create( + name: jas + uid: 89076544 + provider: github + ) + + end + + it "returns an array of correct product " do + list1 = Product.by_merchant(user) + expect(list1.count).must_equal 2 + + list1.each do |prod| + prod.must_be_kind_of Product + prod.merchant.must_equal user + end + end + + it "returns an empty array if no product in that merchant" do + list2 = Product.by_merchant(user2) + expect(list2.empty?).must_equal true + end + end + + + end From 06b8790f1071351e003080a7555f33d171da7985 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Tue, 23 Oct 2018 10:11:48 -0700 Subject: [PATCH 121/196] user controller --- app/controllers/sessions_controller.rb | 14 +++++--------- app/controllers/users_controller.rb | 9 +++++++++ app/views/users/_user_show.html.erb | 0 app/views/users/edit.html.erb | 2 +- app/views/users/show.html.erb | 11 ++++++++--- 5 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 app/views/users/_user_show.html.erb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 6ba67f29d0..c3b836aa66 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -5,28 +5,24 @@ def create @current_user = User.find_by(uid: auth_hash[:uid], name: auth_hash[:name], provider: 'github') if @current_user - flash[:success] = "Welcome back #{@user.name}" - redirect_to user_path(@user.id) + flash[:success] = "Welcome back #{@current_user.name}" + redirect_to user_path(@current_user.id) else #try to make a new user @current_user = User.build_from_github(auth_hash) if @current_user.save - flash[:success] = "Welcome #{@user.name}" - redirect_to edit_user_path(@user.id) + flash[:success] = "Welcome #{@current_user.name}" + redirect_to edit_user_path(@current_user.id) #would you like to register as a merchant? else - flash[:error] = "Could not create account: #{@user.errors.messages}" + flash[:error] = "Could not create account: #{@current_user.errors.messages}" redirect_to root_path return end end -<<<<<<< HEAD session[:user_id] = @current_user.id -======= - session[:user_id] = @user.id ->>>>>>> master end def destroy diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 45e3fbd8bf..cc5ca3741f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,6 @@ class UsersController < ApplicationController before_action :find_merchant, except: [:index, :edit] + before_action :find_user, only: :show # before_action :find_user def index @@ -37,6 +38,14 @@ def destroy private + def find_user + @user ||= User.find_by(id: params[:id].to_i) + + if @user.nil? + # flash[:warning] = "No such user" + end + end + def find_merchant @merchant ||= User.find_by(id: params[:id].to_i, type: "Merchant") diff --git a/app/views/users/_user_show.html.erb b/app/views/users/_user_show.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 81db0ef9fe..ce73c657f0 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -9,7 +9,7 @@

    Enter more information to create your account.

    - <% if @current_user.type = 'Merchant' %> + <% type = 'Merchant' %> <%= f.label "Would you like to become a merchant?" %> <%= f.check_box :type, {}, type %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 4ce06c60eb..944e89c6b6 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,4 +1,8 @@ -

    <%= "#{@merchant.name}'s Good's Distribution Store" %>

    + +<% if @user.type == "Merchant" %> +

    <%= "#{@merchant.name}'s Good's Distribution Store" %>

    +<% else %> +

    Profile Information

    Joined site on <%= "#{@merchant.created_at.strftime ("%b. %d, %Y")}" %>

    @@ -11,7 +15,7 @@ Product Name Quantity Category - <% if !current_user || current_user.id != @merchant.id %> + <% if !current_user || current_user.id != @merchant.id %> Add to Cart <% else %> Remove product @@ -26,7 +30,7 @@ <%= link_to "#{product.name}", product_path(product.id) %> <%= "#{product.stock}" %> <%= "#{product.category.name}" %> - <% if current_user.id != @merchant.id %> + <% if !current_user || current_user.id != @merchant.id %> add to cart <% else %> delete product @@ -36,3 +40,4 @@ <% end %> +<% end %> From 11eaa574de85f0297d448b2f69ef31583d1733f1 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Tue, 23 Oct 2018 10:47:56 -0700 Subject: [PATCH 122/196] fixed the migration for product status --- app/views/products/show.html.erb | 4 ++-- db/migrate/20181023171757_add_status_to_pd.rb | 5 +++++ db/schema.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181023171757_add_status_to_pd.rb diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 7add8c4fe6..419a54bacf 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,10 +1,10 @@

    Product Details: <%= @product.name %>

    diff --git a/db/migrate/20181023171757_add_status_to_pd.rb b/db/migrate/20181023171757_add_status_to_pd.rb new file mode 100644 index 0000000000..556b9f1a62 --- /dev/null +++ b/db/migrate/20181023171757_add_status_to_pd.rb @@ -0,0 +1,5 @@ +class AddStatusToPd < ActiveRecord::Migration[5.2] + def change + add_column :products, :status, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index fcbd8a9595..f82074cf99 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_202759) do +ActiveRecord::Schema.define(version: 2018_10_23_171757) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 9a1347b6cededd0a5dcb80e692b3bbae30e81532 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Tue, 23 Oct 2018 10:52:39 -0700 Subject: [PATCH 123/196] fixed nav --- app/controllers/users_controller.rb | 10 ++---- app/views/layouts/application.html.erb | 14 ++++++-- .../users/{_info.html.rb => _info.html.erb} | 0 app/views/users/_user_show.html.erb | 32 +++++++++++++++++++ app/views/users/show.html.erb | 2 +- 5 files changed, 47 insertions(+), 11 deletions(-) rename app/views/users/{_info.html.rb => _info.html.erb} (100%) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cc5ca3741f..379ef214f2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController before_action :find_merchant, except: [:index, :edit] - before_action :find_user, only: :show + before_action :find_user, only: [:show, :edit] # before_action :find_user def index @@ -24,13 +24,7 @@ def update end end - def edit - @current_user.id - - if @current_user.nil? - render :not_found, status: :not_found - end - end + def edit; end def destroy #delete account aka be sent to siberia diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cbdb4d7b24..98a4d009e9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -38,9 +38,19 @@
    +
    +

    + This satirical e-commerce site is a version of Betsy, a pun-derful Etsy-inspired project of Ada Developers Academy. +

    +
    diff --git a/app/views/products/_shopping.html.erb b/app/views/products/_shopping.html.erb index 37604467a6..848542adad 100644 --- a/app/views/products/_shopping.html.erb +++ b/app/views/products/_shopping.html.erb @@ -1,22 +1,6 @@
    - + <%= render partial: "shopping_nav", local: true %>
    @@ -27,8 +11,12 @@
    <%= link_to "#{product.name}", product_path(product.id) %>
    Sold by: <%= link_to "#{product.user.name}", bymerchant_path(product.user.id) %>
    + <%= "#{format_money(product.price)}" %>
    - Star review here? + + <% product.categories.each do |cat| %> + <%= cat.name %> + <% end %>
    diff --git a/app/views/products/_shopping_nav.html.erb b/app/views/products/_shopping_nav.html.erb new file mode 100644 index 0000000000..84e856353c --- /dev/null +++ b/app/views/products/_shopping_nav.html.erb @@ -0,0 +1,17 @@ + diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 914e5b6e67..4fae07d2e1 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,34 +1,44 @@ -

    Product Details: <%= @product.name %>

    +
    +
    + <%= render partial: "shopping_nav", local: true %> - +
    +

    <%= @product.name %>

    +

    Sold by: <%= @product.user.name %>

    -

    Categories:

    -
      - <% @product.categories.each do |cat| %> -
    • - <%= cat.name %> -
    • - <% end %> -
    + -

    Description: <%= @product.description%>

    -

    Merchant: <%= @product.user.name%>

    -

    Price: <%= @product.price%>

    -

    Quantity available: <%= @product.stock%>

    -

    status: <%= @product.status%>

    +

    + <%= image_tag(@product.photo_url) %> +

    -<%if @product.stock > 0 && @cuurent_user != @product.user%> - <% if @op %> - <%= render partial: "order_products/form", locals: { button_title: "Update cart", op: @op, product_id: @product.id } %> - <% else %> - <%= render partial: "order_products/form", locals: { button_title: "Add to cart", op: @current_order.order_products.new, product_id: @product.id } %> - <% end %> +

    + <% @product.categories.each do |cat| %> + <%= cat.name %> + <% end %> +

    -<%end%> + <% if @product.stock > 0 && @current_user != @product.user %> +

    + <% if @op %> + <%= render partial: "order_products/form", locals: { button_title: "Update cart", op: @op, product_id: @product.id } %> + <% else %> + <%= render partial: "order_products/form", locals: { button_title: "Add to cart", op: @current_order.order_products.new, product_id: @product.id } %> + <% end %> +

    + <%end%> + +

    <%= @product.description%>

    +

    Price: <%= format_money(@product.price) %>

    +
    + +
    +
    +
    diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 2479aab512..5b1c1e82e3 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -6,7 +6,7 @@ shirt: price: 1.5 description: "a nice shirt" stock: 1 - photo_url: MyString + photo_url: "https://loremflickr.com/cache/resized/791_41048349621_da0130f444_300_300_nofilter.jpg" status: true dress: @@ -15,7 +15,7 @@ dress: price: 1.5 description: "a nice dress" stock: 5 - photo_url: MyString + photo_url: "https://loremflickr.com/cache/resized/791_41048349621_da0130f444_300_300_nofilter.jpg" status: true mumu: @@ -24,5 +24,5 @@ mumu: price: 2 description: "a nice mumu" stock: 5 - photo_url: MyString + photo_url: "https://loremflickr.com/cache/resized/791_41048349621_da0130f444_300_300_nofilter.jpg" status: true From 5192e9bbe10fd79f991457fecb9a8a5515291c7e Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 12:10:49 -0700 Subject: [PATCH 187/196] changed image tag to hopefully work on heroku --- app/views/home/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 552d3d0d39..6520f20b74 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1 +1 @@ -Sovietski hero image +<%= image_tag("homepage-hero.jpg", class: "homepage-hero-img") %> From 36f13f8af2995ba9ea755ff60516f3f39d29838f Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 12:18:15 -0700 Subject: [PATCH 188/196] changed flash[:error] to flash[:warning] --- app/controllers/order_products_controller.rb | 8 ++++---- app/controllers/orders_controller.rb | 6 +++--- app/controllers/sessions_controller.rb | 2 +- test/controllers/order_products_controller_test.rb | 8 ++++---- test/controllers/orders_controller_test.rb | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index f90ecad6e5..cfa6a24428 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -13,7 +13,7 @@ def create redirect_to cart_path else - flash[:error] = "Error: Could not add product to cart" + flash[:warning] = "Error: Could not add product to cart" redirect_back fallback_location: products_path end @@ -29,7 +29,7 @@ def update end redirect_to cart_path else - flash[:error] = "Error: Could not update product order" + flash[:warning] = "Error: Could not update product order" redirect_back fallback_location: cart_path end @@ -46,7 +46,7 @@ def change_status flash[:success] = "Cancelled Product Order ##{op.id}" redirect_back fallback_location: root_path else - flash[:error] = "Could not update status for Product Order ##{op.id}" + flash[:warning] = "Could not update status for Product Order ##{op.id}" redirect_back fallback_location: root_path end end @@ -56,7 +56,7 @@ def destroy if op && op.destroy flash[:success] = "Removed #{op.product.name} from cart" else - flash[:error] = "Error: Could not remove product from cart" + flash[:warning] = "Error: Could not remove product from cart" end redirect_back fallback_location: cart_path end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 921f10cb4c..f4b7dbd774 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -5,7 +5,7 @@ def cart def checkout unless @current_order.order_products.any? redirect_to cart_path - flash[:error] = "You must add something to your cart before you can checkout" + flash[:warning] = "You must add something to your cart before you can checkout" end end @@ -18,7 +18,7 @@ def update redirect_to confirmation_path else redirect_to checkout_path - flash[:error] = "Could not submit order" + flash[:warning] = "Could not submit order" end end @@ -29,7 +29,7 @@ def confirmation session[:paid_order_id] = nil else redirect_to checkout_path - flash[:error] = "Error: Order payment did not go through" + flash[:warning] = "Error: Order payment did not go through" end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b4548ee2c3..0f1e52fa78 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -18,7 +18,7 @@ def create flash[:success] = "Welcome #{current_user.name}!" redirect_to edit_user_path(current_user.id) else - flash[:error] = "Could not create account: #{current_user.errors.messages}" + flash[:warning] = "Could not create account: #{current_user.errors.messages}" redirect_to root_path return end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index 0c8f44a918..ac293e6427 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -56,7 +56,7 @@ must_respond_with :redirect must_redirect_to products_path - expect(flash[:error]).must_equal "Error: Could not add product to cart" + expect(flash[:warning]).must_equal "Error: Could not add product to cart" end end @@ -113,7 +113,7 @@ must_respond_with :redirect must_redirect_to cart_path - expect(flash[:error]).must_equal "Error: Could not update product order" + expect(flash[:warning]).must_equal "Error: Could not update product order" end it "reduces the order product count by 1 if quantity is adjusted to 0" do @@ -169,7 +169,7 @@ must_respond_with :redirect must_redirect_to cart_path - expect(flash[:error]).must_equal "Error: Could not remove product from cart" + expect(flash[:warning]).must_equal "Error: Could not remove product from cart" end end @@ -216,7 +216,7 @@ must_respond_with :redirect must_redirect_to root_path - expect(flash[:error]).must_equal "Could not update status for Product Order ##{dresses.id}" + expect(flash[:warning]).must_equal "Could not update status for Product Order ##{dresses.id}" end end end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 4a16f9fde2..1f5fa6ddd9 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -64,7 +64,7 @@ # Assert must_respond_with :redirect must_redirect_to cart_path - expect(flash[:error]).must_equal "You must add something to your cart before you can checkout" + expect(flash[:warning]).must_equal "You must add something to your cart before you can checkout" end end @@ -131,7 +131,7 @@ must_respond_with :redirect must_redirect_to checkout_path expect(order.status).must_equal "pending" - expect(flash[:error]).must_equal "Could not submit order" + expect(flash[:warning]).must_equal "Could not submit order" expect(session[:order_id]).must_equal order.id end end @@ -181,7 +181,7 @@ must_respond_with :redirect must_redirect_to checkout_path - expect(flash[:error]).must_equal "Error: Order payment did not go through" + expect(flash[:warning]).must_equal "Error: Order payment did not go through" end end end From 700abb292eb6676261c5590470ca8a961cf9476a Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 13:02:47 -0700 Subject: [PATCH 189/196] Styled all forms --- app/assets/stylesheets/products.scss | 5 ++ app/views/categories/new.html.erb | 28 ++++---- app/views/layouts/_form_errors.html.erb | 4 +- app/views/orders/checkout.html.erb | 21 +++--- app/views/products/_form.html.erb | 49 ++++++++------ app/views/products/new.html.erb | 4 +- app/views/users/edit.html.erb | 86 +++++++++++++++---------- 7 files changed, 119 insertions(+), 78 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index b17d62961c..7a1302c792 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -24,3 +24,8 @@ section.product-show { span.badge.category-tag { font-size: 1rem; } + +div.form-check-inline > input { + margin-left: 1rem; + margin-right: 0.5rem; +} diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb index 1de29144e0..7e3b99d2c9 100644 --- a/app/views/categories/new.html.erb +++ b/app/views/categories/new.html.erb @@ -1,17 +1,19 @@ -

    New Category

    +
    +

    Add a Category

    -<%= form_with model: @category, local: true do |f|%> -

    Enter more information to create a new category.

    + <%= form_with model: @category, local: true do |f|%> +

    More election categories? Excellent...

    -
    - <%= f.label :name %> - <%= f.text_field :name, class: "form-control" %> -
    +
    + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
    - <% if @current_user %> - <%= f.submit "New!", class: "btn btn-primary" %> - <% else %> - <%= f.submit "New!", class: "btn btn-primary", disabled: true %> - <% end %> + <% if @current_user.is_a_merchant? %> + <%= f.submit "Add category", class: "btn btn-primary" %> + <% else %> + <%= f.submit "Add category", class: "btn btn-primary", disabled: true %> + <% end %> -<% end %> + <% end %> +
    diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb index ec72172d15..d5eae1366b 100644 --- a/app/views/layouts/_form_errors.html.erb +++ b/app/views/layouts/_form_errors.html.erb @@ -1,6 +1,6 @@ -<% if model.errors.any? %> +<% if item.errors.any? %>
      - <% model.errors.messages.each do |column, problem_list| %> + <% item.errors.messages.each do |column, problem_list| %> <% problem_list.each do |problem| %>
    • diff --git a/app/views/orders/checkout.html.erb b/app/views/orders/checkout.html.erb index 3320e26250..d3d1422c9d 100644 --- a/app/views/orders/checkout.html.erb +++ b/app/views/orders/checkout.html.erb @@ -1,5 +1,6 @@
      -

      This is the checkout page.

      +

      Kindly hand over your personal information.

      +
      <%= form_with model: @current_order, class: "form", locals: true do |f|%> @@ -12,36 +13,38 @@
      - <%= u.label :address %> - <%= u.text_field :address, class: "form-control" %> + <%= u.label :email %> + <%= u.text_field :email, class: "form-control" %>
      - <%= u.label :email %> - <%= u.text_field :email, class: "form-control" %> + <%= u.label :address %> + <%= u.text_field :address, class: "form-control" %>
      +
      +
      Payment Information
      - <%= u.label :cc_num %> + <%= u.label "Credit card number" %> <%= u.text_field :cc_num, class: "form-control" %>
      - <%= u.label :cc_csv %> + <%= u.label "Credit card CSV" %> <%= u.text_field :cc_csv, class: "form-control" %>
      - <%= u.label :cc_exp %> + <%= u.label "Card expiration date" %> <%= u.text_field :cc_exp, class: "form-control" %>
      - <%= u.label :bill_zip %> + <%= u.label "Billing zip code" %> <%= u.text_field :bill_zip, class: "form-control" %>
      diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index a46a12c6ed..df47720957 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,28 +1,41 @@ +
      +

      <%= action_name %>

      -

      <%= action_name %>

      + <%= render partial: "layouts/form_errors", locals: { item: @product } %> + <%= form_with model: @product, local: true do |f|%> -<%= render partial: "layouts/form_errors", locals: { model: @product } %> +
      + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
      -<%= form_with model: @product, class: "product-form" do |f|%> - <%= f.label :name %> - <%= f.text_field :name %> +
      + <%= f.label :categories %> + <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> +
      - <%= f.label :categories %> - <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> +
      + <%= f.label :description %> + <%= f.text_field :description, class: "form-control" %> +
      - <%= f.label :description %> - <%= f.text_field :description%> +
      + <%= f.label :price %> + <%= f.text_field :price, class: "form-control" %> +
      - <%= f.label :price %> - <%= f.text_area :price %> +
      + <%= f.label :stock %> + <%= f.text_field :stock, class: "form-control" %> +
      - <%= f.label :stock %> - <%= f.text_area :stock %> +
      + <%= f.label :photo_url %> + <%= f.text_field :photo_url, class: "form-control" %> +
      - <%= f.label :photo_url %> - <%= f.text_area :photo_url %> - - <%= f.submit button_title, class: "btn btn-primary" %> -<% end %> + <%= f.submit button_title, class: "btn btn-primary" %> + <% end %> +
      diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index 9b53326379..69e186a356 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -1,3 +1,3 @@ <%= render partial: "form", - locals: { action_name: 'Create New Product', - button_title: 'Create' } %> + locals: { action_name: 'Add a product', + button_title: 'Add product' } %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 6677585788..e3fa07f69a 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,34 +1,52 @@ -

      Account Information

      - -<%= form_with model: @current_user, local: true do |f|%> -
      <%= f.label :name %> - <%= f.text_field :name, class: "form-control" %> -
      - -
      <%= f.label "EMail" %> - <%= f.text_field :email, class: "form-control" %> -
      - -
      <%= f.label :address%> - <%= f.text_field :address, class: "form-control" %> -
      - -
      <%= f.label "Billing Zip Code" %> - <%= f.text_field :bill_zip, class: "form-control" %> -
      - -
      <%= f.label "Credit Card Number" %> - <%= f.text_field :cc_num, class: "form-control" %> -
      - -
      <%= f.label "Credit Card Expiration Date" %> - <%= f.text_field :cc_exp, class: "form-control" %> -
      - -
      - <%= f.label "Credit Card CSV Number" %> - <%= f.text_field :cc_csv, class: "form-control" %> -
      - - <%= f.submit "Update", class: "btn btn-primary" %> -<% end %> +
      +

      Account Information

      +
      + + <%= form_with model: @current_user, local: true do |f|%> +
      +
      Shipping Information
      +
      + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
      + +
      + <%= f.label :email %> + <%= f.text_field :email, class: "form-control" %> +
      + +
      + <%= f.label :address %> + <%= f.text_field :address, class: "form-control" %> +
      +
      + +
      + +
      +
      Payment Information
      + +
      + <%= f.label "Credit card number" %> + <%= f.text_field :cc_num, class: "form-control" %> +
      + +
      + <%= f.label "Credit card CSV" %> + <%= f.text_field :cc_csv, class: "form-control" %> +
      + +
      + <%= f.label "Card expiration date" %> + <%= f.text_field :cc_exp, class: "form-control" %> +
      + +
      + <%= f.label "Billing zip code" %> + <%= f.text_field :bill_zip, class: "form-control" %> +
      +
      + + <%= f.submit "Update", class: "btn btn-primary" %> + <% end %> +
      From 139271293aa882e7ae63798c455cfab41192c253 Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 13:22:38 -0700 Subject: [PATCH 190/196] Fixed product form errors - thanks jessie --- app/controllers/products_controller.rb | 10 +++++----- app/views/layouts/_form_errors.html.erb | 4 ++-- app/views/products/_form.html.erb | 2 +- config/application.rb | 2 ++ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index a7f978967e..7b891fc66a 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -37,17 +37,17 @@ def create if @current_user.is_a_merchant? - product = @current_user.products.new(product_params) + @product = @current_user.products.new(product_params) category_ids = params[:product][:category_ids].select(&:present?).map(&:to_i) category_ids.each do |id| c = Category.find(id) - product.categories << c + @product.categories << c end - if product.save + if @product.save flash[:success] = 'Product Created!' - redirect_to product_path(id: product.id) + redirect_to product_path(id: @product.id) else flash.now[:warning] = 'Product not created!' render :new, status: :bad_request @@ -68,7 +68,7 @@ def update c = Category.find(id) @product.categories << c end - + redirect_to product_path(@product.id) elsif @product render :edit, status: :bad_request diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb index d5eae1366b..ec72172d15 100644 --- a/app/views/layouts/_form_errors.html.erb +++ b/app/views/layouts/_form_errors.html.erb @@ -1,6 +1,6 @@ -<% if item.errors.any? %> +<% if model.errors.any? %>
        - <% item.errors.messages.each do |column, problem_list| %> + <% model.errors.messages.each do |column, problem_list| %> <% problem_list.each do |problem| %>
      • diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index df47720957..dbaeee21ca 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,7 +1,7 @@

        <%= action_name %>

        - <%= render partial: "layouts/form_errors", locals: { item: @product } %> + <%= render partial: "layouts/form_errors", locals: { model: @product } %> <%= form_with model: @product, local: true do |f|%> diff --git a/config/application.rb b/config/application.rb index 5c09a3eefc..e7055bb5fa 100644 --- a/config/application.rb +++ b/config/application.rb @@ -21,5 +21,7 @@ class Application < Rails::Application # 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. + + config.action_view.form_with_generates_remote_forms = false end end From f2b1608e104522bfba6bbfb65c005e2074542935 Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 13:29:24 -0700 Subject: [PATCH 191/196] Edit profile update now working -- thanks leanne --- app/controllers/users_controller.rb | 9 +++++++-- app/models/user.rb | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 12034df5aa..5adfd4de11 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -11,7 +11,7 @@ def show; end #TODO change this to be just user profile and create custom route def update if @current_user && @current_user.update(user_params) flash[:success] = "Saved" - redirect_to user_path(@current_user.id) + redirect_to edit_user_path(@current_user.id) else flash.now[:error] = 'Not updated.' render :edit, status: :bad_request @@ -53,6 +53,11 @@ def check_permissions end def user_params - return params.require(:user).permit(:name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip) + allowed_params = :name, :address, :email, :cc_num, :cc_csv, :cc_exp, :type, :bill_zip + unless @current_user.class == Merchant + params.require(:user).permit(allowed_params) + else + params.require(:merchant).permit(allowed_params) + end end end diff --git a/app/models/user.rb b/app/models/user.rb index 735bb08c62..e4db2bbfce 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ class User < ApplicationRecord - has_many :products #TODO REMOVE FOR ANY USER + has_many :products has_many :orders has_many :order_products, through: :products From 76eb2c565fa69b8d828b0f8102e607e0235ebf42 Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 13:37:36 -0700 Subject: [PATCH 192/196] Image alt text and cart image improvements --- app/views/orders/cart.html.erb | 2 +- app/views/orders/confirmation.html.erb | 2 +- app/views/orders/index.html.erb | 2 -- app/views/orders/update.html.erb | 2 -- app/views/products/_shopping.html.erb | 2 +- 5 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 app/views/orders/index.html.erb delete mode 100644 app/views/orders/update.html.erb diff --git a/app/views/orders/cart.html.erb b/app/views/orders/cart.html.erb index 6dfa20386e..fe1f98688c 100644 --- a/app/views/orders/cart.html.erb +++ b/app/views/orders/cart.html.erb @@ -7,7 +7,7 @@ <% @current_order.order_products.each do |op| %>
        - Product + <%= image_tag(op.product.photo_url, alt: op.product.name, class: "col-sm card-img") %>
        <%= op.product.name %>
        diff --git a/app/views/orders/confirmation.html.erb b/app/views/orders/confirmation.html.erb index b09a61cbeb..8ae10b03a8 100644 --- a/app/views/orders/confirmation.html.erb +++ b/app/views/orders/confirmation.html.erb @@ -9,7 +9,7 @@ <% @paid_order.order_products.each do |op| %>
        - Product + <%= image_tag(op.product.photo_url, alt: op.product.name, class: "col-sm card-img") %>
        <%= op.product.name %>
        diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb deleted file mode 100644 index d63a69fb54..0000000000 --- a/app/views/orders/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

        Orders#index

        -

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

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

        Orders#update

        -

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

        diff --git a/app/views/products/_shopping.html.erb b/app/views/products/_shopping.html.erb index 848542adad..f3d34390e7 100644 --- a/app/views/products/_shopping.html.erb +++ b/app/views/products/_shopping.html.erb @@ -6,7 +6,7 @@
        <% product_list.each do |product|%>
        - Product + <%= image_tag(product.photo_url, alt: product.name, class: "card-img-top") %>
        <%= link_to "#{product.name}", product_path(product.id) %>
        From 9281f60c44081ef581fa455b2ddeb5aa4a3ddc0d Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 13:51:26 -0700 Subject: [PATCH 193/196] changes flash now error to flash now warning for styling --- app/controllers/users_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5adfd4de11..5f4254d5d5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -13,7 +13,7 @@ def update flash[:success] = "Saved" redirect_to edit_user_path(@current_user.id) else - flash.now[:error] = 'Not updated.' + flash.now[:warning] = 'Not updated.' render :edit, status: :bad_request end end @@ -38,7 +38,7 @@ def destroy def merchant_dash unless @current_user.is_a_merchant? - flash.now[:error] = 'Not allowed.' + flash.now[:warning] = 'Not allowed.' render :forbidden end end From 54f58f63f64b4959b0942a835544249f947e441f Mon Sep 17 00:00:00 2001 From: jackie Date: Fri, 26 Oct 2018 13:52:55 -0700 Subject: [PATCH 194/196] modified user form error message --- 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 5f4254d5d5..396daea93a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -13,7 +13,7 @@ def update flash[:success] = "Saved" redirect_to edit_user_path(@current_user.id) else - flash.now[:warning] = 'Not updated.' + flash.now[:warning] = 'Please fill in all fields.' render :edit, status: :bad_request end end From 56cb5feb2fe42ffa60076dd604d1a474737cc7b6 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Sat, 27 Oct 2018 12:20:01 -0700 Subject: [PATCH 195/196] updated products controller --- app/assets/images/.DS_Store | Bin 0 -> 6148 bytes app/controllers/application_controller.rb | 1 + app/controllers/products_controller.rb | 21 +++--- app/controllers/reviews_controller.rb | 19 ----- config/application.rb | 3 + test/controllers/products_controller_test.rb | 71 ++++++++++++------- 6 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 app/assets/images/.DS_Store diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1b8bb3f5857f7957181f8de9a0e98386bbb9b1af GIT binary patch literal 6148 zcmeHKJ5B>J5Pe>EdoG~t@# zZz>>nS7L}=+~X1P{qZN^UO2n`siwzYC37#&E#7}{OYG;FZZlyXbTB^>=3$0WXK2oc5`Cx(C5H3i^jCpb2W&k0aJW!>xUjPe6^hf{xqhW|xZ0!jrhqBX zR$#?H4kZ6ybl3mwAbT Date: Sat, 27 Oct 2018 13:49:49 -0700 Subject: [PATCH 196/196] fixed the product controller test --- test/controllers/products_controller_test.rb | 68 ++++++++++++++------ 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 2ad50c37df..71aaba293c 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -7,7 +7,7 @@ let(:user) { users(:user1) } let(:cc_user) { users(:cc_user) } let(:cc_merchant) { merchants(:cc_merchant) } - + let(:merchant) { merchants(:merchant) } let(:category1) {categories(:category1)} let(:category2) {categories(:category2)} @@ -217,10 +217,12 @@ user_id: cc_merchant.id, price: 10, stock: 5, - description: 'Good book' + description: 'Good book', + category_ids: [category1.id] } } + end @@ -243,19 +245,24 @@ must_respond_with :redirect expect(Product.last.name).must_equal product_hash[:product][:name] - expect(Product.last.user).must_equal @merchant - expect(Product.last.stock).must_be product_hash[:product][:stock] - expect(Product.last.price).must_be prooduct_hash[:product][:price] + expect(Product.last.user).must_equal merchant + + expect(Product.last.stock).must_equal product_hash[:product][:stock] + expect(Product.last.price).must_equal product_hash[:product][:price] end it "responds with an error for invalid params" do # Arranges + merchant = merchants(:cc_merchant) + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant)) + get auth_callback_path('github') product_hash[:product][:name] = nil # Act-Assert expect { post products_path, params: product_hash - }.wont_change 'Product.all.count' + }.wont_change 'Product.count' must_respond_with :bad_request @@ -263,31 +270,54 @@ end describe "update" do + let (:update_hash) do + { + product: { + name: 'White Teeth', + user_id: merchant.id, + price: 10, + stock: 5, + description: 'Good book', + category_ids: [category1.id] + } + } + end + + it "can update a product with valid params by logged in user" do - perform_login(cc_user) - product.user = cc_user + merchant = merchants(:merchant) + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant)) + get auth_callback_path('github') + + id = product.id expect { - patch products_path, params: product_hash - }.wont_change 'Product.all.count' + patch product_path(id), params: update_hash + }.wont_change 'Product.count' + must_respond_with :redirect - must_redirect_to products_path(id) + must_redirect_to product_path(id) new_product= Product.find_by(id: id) expect(new_product.name).must_equal product_hash[:product][:name] - expect(new_product.user_id).must_equal product_hash[:product][:user_id] + expect(new_product.user).must_equal merchant expect(new_product.stock).must_equal product_hash[:product][:stock] - expect(new_product.stock).must_equal product_hash[:product][:price] + expect(new_product.price).must_equal product_hash[:product][:price] end it "gives an error if the product params are invalid" do # Arrange product_hash[:product][:name] = nil + merchant = merchants(:merchant) + + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant)) + get auth_callback_path('github') + id = product.id - product.user = cc_user - old_product = product expect { @@ -296,10 +326,10 @@ new_product = Product.find(id) must_respond_with :bad_request - expect(old_product.name).must_equal new_product.name - expect(old_product.user_id).must_equal new_product.user_id - expect(old_product.price).must_equal new_product.price - expect(old_product.stock).must_equal new_product.stock + expect(product.name).must_equal new_product.name + expect(product.user).must_equal merchant + expect(product.price).must_equal new_product.price + expect(product.stock).must_equal new_product.stock end it "gives not_found for a product that doesn't exist" do id = -1