From 698db01588d6f2d1acb29ccd71dcac71d2dbd20a Mon Sep 17 00:00:00 2001 From: Jane Date: Wed, 17 Oct 2018 11:42:20 -0700 Subject: [PATCH 001/215] Created rails app --- .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..81054d63bb --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +zp/2At8o7D7zjNjZECssyNuJCFGe2yW5X+jNQ60fENNZ3bcpltND+2CPFxxXJkef+NPXgbVWDgnBMIY0gY+6c6+3Qvsj01iYThtAAsI23JlavNRYzCVbCuebwHVdHS6j2AvKlZZslNQKx+V7tvQm1YwVEo9OBUT2zOhzto+lhhX4ZmOVk4DbIzk8LBbF3ZbZFtDQaP14DUohInTuy4p+7HQ3iDBr3VrwozVzW1gOkTXO7URzEBQVCfuqW1Frh1MU+Qw3imWcJ18kUFyjTULaoQu95Gzdto1BSnyo5GjWqADm1zxQGh6Lw8F1Avg4jO0rukn1t6VECML3ngZaPjEgxpTIujvkBFe9Pkv/GilCErzswnDAuoJSryh4CU6ZZOKtqvMpy0f11W3Y1WMYxJ3S4qd5SA5RqLbVJP+3--CqQA02MptuQmrkjE--KjCmy4Q38OB0rSBzHLNq3w== \ 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..59e480ec83 --- /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 8e1bb7608400ea0070c47ef62d0adae1c8f66820 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 14:47:23 -0700 Subject: [PATCH 002/215] migrations created --- app/models/order.rb | 2 ++ app/models/orderproduct.rb | 4 ++++ app/models/product.rb | 2 ++ app/models/review.rb | 2 ++ app/models/user.rb | 2 ++ db/migrate/20181017211006_create_orders.rb | 17 ++++++++++++++ db/migrate/20181017211109_create_users.rb | 10 ++++++++ db/migrate/20181017211147_create_products.rb | 9 ++++++++ .../20181017211201_add_columns_product.rb | 12 ++++++++++ .../20181017213714_create_orderproducts.rb | 11 +++++++++ db/migrate/20181017214200_create_reviews.rb | 12 ++++++++++ test/fixtures/orderproducts.yml | 11 +++++++++ test/fixtures/orders.yml | 23 +++++++++++++++++++ test/fixtures/products.yml | 11 +++++++++ test/fixtures/reviews.yml | 15 ++++++++++++ test/fixtures/users.yml | 9 ++++++++ test/models/order_test.rb | 9 ++++++++ test/models/orderproduct_test.rb | 9 ++++++++ test/models/product_test.rb | 9 ++++++++ test/models/review_test.rb | 9 ++++++++ test/models/user_test.rb | 9 ++++++++ 21 files changed, 197 insertions(+) create mode 100644 app/models/order.rb create mode 100644 app/models/orderproduct.rb create mode 100644 app/models/product.rb create mode 100644 app/models/review.rb create mode 100644 app/models/user.rb create mode 100644 db/migrate/20181017211006_create_orders.rb create mode 100644 db/migrate/20181017211109_create_users.rb create mode 100644 db/migrate/20181017211147_create_products.rb create mode 100644 db/migrate/20181017211201_add_columns_product.rb create mode 100644 db/migrate/20181017213714_create_orderproducts.rb create mode 100644 db/migrate/20181017214200_create_reviews.rb create mode 100644 test/fixtures/orderproducts.yml create mode 100644 test/fixtures/orders.yml create mode 100644 test/fixtures/products.yml create mode 100644 test/fixtures/reviews.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/order_test.rb create mode 100644 test/models/orderproduct_test.rb create mode 100644 test/models/product_test.rb create mode 100644 test/models/review_test.rb create mode 100644 test/models/user_test.rb diff --git a/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/orderproduct.rb b/app/models/orderproduct.rb new file mode 100644 index 0000000000..2be353fe43 --- /dev/null +++ b/app/models/orderproduct.rb @@ -0,0 +1,4 @@ +class Orderproduct < ApplicationRecord + belongs_to :order + belongs_to :product +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..35a85acab3 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,2 @@ +class Product < ApplicationRecord +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..b2ca4935ed --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,2 @@ +class Review < ApplicationRecord +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..379658a509 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ApplicationRecord +end diff --git a/db/migrate/20181017211006_create_orders.rb b/db/migrate/20181017211006_create_orders.rb new file mode 100644 index 0000000000..878ac6ec14 --- /dev/null +++ b/db/migrate/20181017211006_create_orders.rb @@ -0,0 +1,17 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :name + t.string :email + t.string :mailing_address + t.integer :zip_code + t.integer :cc_number + t.integer :cc_expiration + t.integer :cc_cvv + t.string :status + t.integer :total_cost + + t.timestamps + end + end +end diff --git a/db/migrate/20181017211109_create_users.rb b/db/migrate/20181017211109_create_users.rb new file mode 100644 index 0000000000..5fd691b5d3 --- /dev/null +++ b/db/migrate/20181017211109_create_users.rb @@ -0,0 +1,10 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.string :name + t.string :email + + t.timestamps + end + end +end diff --git a/db/migrate/20181017211147_create_products.rb b/db/migrate/20181017211147_create_products.rb new file mode 100644 index 0000000000..afb64f7619 --- /dev/null +++ b/db/migrate/20181017211147_create_products.rb @@ -0,0 +1,9 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.belongs_to :user, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20181017211201_add_columns_product.rb b/db/migrate/20181017211201_add_columns_product.rb new file mode 100644 index 0000000000..35b819d1d9 --- /dev/null +++ b/db/migrate/20181017211201_add_columns_product.rb @@ -0,0 +1,12 @@ +class AddColumnsProduct < ActiveRecord::Migration[5.2] + def change + add_column :product, :stock_count, :integer + add_column :product, :user_id + add_column :product, :price, :integer + add_column :product, :category, :string + add_column :product, :photo_url, :string + add_column :product, :description, :string + add_column :product, :name, :string + + end +end diff --git a/db/migrate/20181017213714_create_orderproducts.rb b/db/migrate/20181017213714_create_orderproducts.rb new file mode 100644 index 0000000000..b6ac99fe13 --- /dev/null +++ b/db/migrate/20181017213714_create_orderproducts.rb @@ -0,0 +1,11 @@ +class CreateOrderproducts < ActiveRecord::Migration[5.2] + def change + create_table :orderproducts do |t| + t.belongs_to :order, index: true + t.belongs_to :product, index: true + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/migrate/20181017214200_create_reviews.rb b/db/migrate/20181017214200_create_reviews.rb new file mode 100644 index 0000000000..fe9ea1d5c8 --- /dev/null +++ b/db/migrate/20181017214200_create_reviews.rb @@ -0,0 +1,12 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.string :name + t.integer :rating + t.string :review + t.belongs_to :product, index: true + + t.timestamps + end + end +end diff --git a/test/fixtures/orderproducts.yml b/test/fixtures/orderproducts.yml new file mode 100644 index 0000000000..7475c73ddd --- /dev/null +++ b/test/fixtures/orderproducts.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + order: one + product: one + quantity: 1 + +two: + order: two + product: two + quantity: 1 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..bfcd8b54f5 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,23 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + email: MyString + mailing_address: MyString + zip_code: 1 + cc_number: 1 + cc_expiration: 1 + cc_cvv: 1 + status: MyString + total_cost: 1 + +two: + name: MyString + email: MyString + mailing_address: MyString + zip_code: 1 + cc_number: 1 + cc_expiration: 1 + cc_cvv: 1 + status: MyString + total_cost: 1 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/products.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/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..52a11154f5 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + rating: 1 + review: MyString + user_id: 1 + product_id: 1 + +two: + name: MyString + rating: 1 + review: MyString + user_id: 1 + product_id: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..5dc4ddf033 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + email: MyString + +two: + name: MyString + email: MyString diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..df80f10fb6 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + + it "must be valid" do + value(order).must_be :valid? + end +end diff --git a/test/models/orderproduct_test.rb b/test/models/orderproduct_test.rb new file mode 100644 index 0000000000..0e29f8e9af --- /dev/null +++ b/test/models/orderproduct_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Orderproduct do + let(:orderproduct) { Orderproduct.new } + + it "must be valid" do + value(orderproduct).must_be :valid? + end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..a618b0a156 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Product do + let(:product) { Product.new } + + it "must be valid" do + value(product).must_be :valid? + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..ce8378a033 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Review do + let(:review) { Review.new } + + it "must be valid" do + value(review).must_be :valid? + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..cc862ac2d9 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe User do + let(:user) { User.new } + + it "must be valid" do + value(user).must_be :valid? + end +end From 6af5d05b2a5a3d7370b2b75b04b5e8a461c7b2b4 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 14:58:24 -0700 Subject: [PATCH 003/215] deleted migration file --- .../20181017211201_add_columns_product.rb | 12 ---- db/schema.rb | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 12 deletions(-) delete mode 100644 db/migrate/20181017211201_add_columns_product.rb create mode 100644 db/schema.rb diff --git a/db/migrate/20181017211201_add_columns_product.rb b/db/migrate/20181017211201_add_columns_product.rb deleted file mode 100644 index 35b819d1d9..0000000000 --- a/db/migrate/20181017211201_add_columns_product.rb +++ /dev/null @@ -1,12 +0,0 @@ -class AddColumnsProduct < ActiveRecord::Migration[5.2] - def change - add_column :product, :stock_count, :integer - add_column :product, :user_id - add_column :product, :price, :integer - add_column :product, :category, :string - add_column :product, :photo_url, :string - add_column :product, :description, :string - add_column :product, :name, :string - - end -end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..824ec249cb --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,66 @@ +# 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_214200) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "orderproducts", force: :cascade do |t| + t.bigint "order_id" + t.bigint "product_id" + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["order_id"], name: "index_orderproducts_on_order_id" + t.index ["product_id"], name: "index_orderproducts_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "mailing_address" + t.integer "zip_code" + t.integer "cc_number" + t.integer "cc_expiration" + t.integer "cc_cvv" + t.string "status" + t.integer "total_cost" + 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.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_products_on_user_id" + end + + create_table "reviews", force: :cascade do |t| + t.string "name" + t.integer "rating" + t.string "review" + t.bigint "product_id" + 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.string "name" + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From 8ab6265f72bacfbcd337c0f0152ffcc981f47bc9 Mon Sep 17 00:00:00 2001 From: Divya Date: Wed, 17 Oct 2018 15:11:29 -0700 Subject: [PATCH 004/215] Product model updated with columns --- db/migrate/20181017220145_add_columns_to_products.rb | 5 +++++ db/migrate/20181017220527_add_more_columns_products.rb | 9 +++++++++ db/schema.rb | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181017220145_add_columns_to_products.rb create mode 100644 db/migrate/20181017220527_add_more_columns_products.rb diff --git a/db/migrate/20181017220145_add_columns_to_products.rb b/db/migrate/20181017220145_add_columns_to_products.rb new file mode 100644 index 0000000000..862c745a8b --- /dev/null +++ b/db/migrate/20181017220145_add_columns_to_products.rb @@ -0,0 +1,5 @@ +class AddColumnsToProducts < ActiveRecord::Migration[5.2] + def change + add_column(:products, :stock_count, :integer) + end +end diff --git a/db/migrate/20181017220527_add_more_columns_products.rb b/db/migrate/20181017220527_add_more_columns_products.rb new file mode 100644 index 0000000000..95d67d19bb --- /dev/null +++ b/db/migrate/20181017220527_add_more_columns_products.rb @@ -0,0 +1,9 @@ +class AddMoreColumnsProducts < ActiveRecord::Migration[5.2] + def change + add_column(:products, :price, :integer) + add_column(:products, :category, :string) + add_column(:products, :photo_url, :string) + add_column(:products, :description, :string) + add_column(:products, :name, :string) + end +end diff --git a/db/schema.rb b/db/schema.rb index 824ec249cb..2f158a8b53 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_214200) do +ActiveRecord::Schema.define(version: 2018_10_17_220527) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -43,6 +43,12 @@ t.bigint "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "stock_count" + t.integer "price" + t.string "category" + t.string "photo_url" + t.string "description" + t.string "name" t.index ["user_id"], name: "index_products_on_user_id" end From 91e7526b730af24db5b94fa35feffd38affdc56b Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Wed, 17 Oct 2018 15:22:36 -0700 Subject: [PATCH 005/215] model relationships added --- app/models/order.rb | 2 ++ app/models/product.rb | 3 +++ app/models/review.rb | 1 + app/models/user.rb | 1 + 4 files changed, 7 insertions(+) diff --git a/app/models/order.rb b/app/models/order.rb index 10281b3450..1bf6819058 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,4 @@ class Order < ApplicationRecord + has_many :orderproducts + belongs_to :user, optional :true end diff --git a/app/models/product.rb b/app/models/product.rb index 35a85acab3..4a99707d6f 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,2 +1,5 @@ class Product < ApplicationRecord + belongs_to :user + has_many :reviews + has_many :orderproducts end diff --git a/app/models/review.rb b/app/models/review.rb index b2ca4935ed..949d4ccddb 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,2 +1,3 @@ class Review < ApplicationRecord + belongs_to :product 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 From ff54e08e9710a04bcf093f9bbdda239d3da03b1c Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 15:31:40 -0700 Subject: [PATCH 006/215] change to optional:true syntax for order --- app/models/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/order.rb b/app/models/order.rb index 1bf6819058..c9c7536e0f 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,4 @@ class Order < ApplicationRecord has_many :orderproducts - belongs_to :user, optional :true + belongs_to :user, optional: true end From 0e86c3970eac5fe539cf94d50281950deec89c15 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 15:40:07 -0700 Subject: [PATCH 007/215] add has many relationship for orders to user model --- app/models/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user.rb b/app/models/user.rb index 067b4f19c0..98d80278b6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ class User < ApplicationRecord has_many :products + has_many :orders end From 367b89761474b7f091c4918c19e7996ad370ff2b Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 16:59:26 -0700 Subject: [PATCH 008/215] add category id reference --- app/models/category.rb | 3 +++ app/models/product.rb | 1 + config/routes.rb | 10 ++++++++++ db/migrate/20181017234407_create_categories.rb | 9 +++++++++ .../20181017234721_change_column_name_in_products.rb | 5 +++++ ...17235412_create_category_id_column_for_products.rb | 5 +++++ db/schema.rb | 11 +++++++++-- test/fixtures/categories.yml | 7 +++++++ test/models/category_test.rb | 9 +++++++++ 9 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 app/models/category.rb create mode 100644 db/migrate/20181017234407_create_categories.rb create mode 100644 db/migrate/20181017234721_change_column_name_in_products.rb create mode 100644 db/migrate/20181017235412_create_category_id_column_for_products.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..343b339c34 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,3 @@ +class Category < ApplicationRecord + has_many :products +end diff --git a/app/models/product.rb b/app/models/product.rb index 4a99707d6f..587bbb9d9d 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -2,4 +2,5 @@ class Product < ApplicationRecord belongs_to :user has_many :reviews has_many :orderproducts + belongs_to :category end diff --git a/config/routes.rb b/config/routes.rb index 787824f888..050e2f200f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,13 @@ Rails.application.routes.draw do + resources :orders + + resources :products do + resources :reviews, only: [:new, :create] + end + + resources :users, except: [:edit, :delete] + + resources :categories + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20181017234407_create_categories.rb b/db/migrate/20181017234407_create_categories.rb new file mode 100644 index 0000000000..6ccc3914a0 --- /dev/null +++ b/db/migrate/20181017234407_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/migrate/20181017234721_change_column_name_in_products.rb b/db/migrate/20181017234721_change_column_name_in_products.rb new file mode 100644 index 0000000000..ca839f9cb6 --- /dev/null +++ b/db/migrate/20181017234721_change_column_name_in_products.rb @@ -0,0 +1,5 @@ +class ChangeColumnNameInProducts < ActiveRecord::Migration[5.2] + def change + remove_column :products, :category + end +end diff --git a/db/migrate/20181017235412_create_category_id_column_for_products.rb b/db/migrate/20181017235412_create_category_id_column_for_products.rb new file mode 100644 index 0000000000..5e015b5d84 --- /dev/null +++ b/db/migrate/20181017235412_create_category_id_column_for_products.rb @@ -0,0 +1,5 @@ +class CreateCategoryIdColumnForProducts < ActiveRecord::Migration[5.2] + def change + add_reference :products, :category, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 2f158a8b53..e375571d4b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_17_220527) do +ActiveRecord::Schema.define(version: 2018_10_17_235412) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "orderproducts", force: :cascade do |t| t.bigint "order_id" t.bigint "product_id" @@ -45,10 +51,11 @@ t.datetime "updated_at", null: false t.integer "stock_count" t.integer "price" - t.string "category" t.string "photo_url" t.string "description" t.string "name" + 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 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 6bcc87ec9f6d4cbd0f0217c3a7c753257f898349 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 18:24:00 -0700 Subject: [PATCH 009/215] add .csv file for seeds --- db/cute_creature_seeds.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 db/cute_creature_seeds.rb diff --git a/db/cute_creature_seeds.rb b/db/cute_creature_seeds.rb new file mode 100644 index 0000000000..e69de29bb2 From 86da020edabe4259f8ca31972f058ba643b6ec36 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Wed, 17 Oct 2018 19:03:34 -0700 Subject: [PATCH 010/215] seed files in place --- db/category_seeds.csv | 7 +++++ db/creature_seeds.csv | 2 ++ db/cute_creature_seeds.rb | 0 db/seeds.rb | 54 +++++++++++++++++++++++++++++++++++++++ db/user_seeds.csv | 3 +++ 5 files changed, 66 insertions(+) create mode 100644 db/category_seeds.csv create mode 100644 db/creature_seeds.csv delete mode 100644 db/cute_creature_seeds.rb create mode 100644 db/user_seeds.csv diff --git a/db/category_seeds.csv b/db/category_seeds.csv new file mode 100644 index 0000000000..17b71fe764 --- /dev/null +++ b/db/category_seeds.csv @@ -0,0 +1,7 @@ +name +mammals +amphibians +reptiles +birds +sea creatures +anthropods diff --git a/db/creature_seeds.csv b/db/creature_seeds.csv new file mode 100644 index 0000000000..93be8bbd54 --- /dev/null +++ b/db/creature_seeds.csv @@ -0,0 +1,2 @@ +name,stock_count,description,price,photo_url +Frog,4,Your favorite cuddley non-posionous amphibian.,2000,https://dummyimage.com/600x400/000/fff diff --git a/db/cute_creature_seeds.rb b/db/cute_creature_seeds.rb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2accd..35446f0693 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,57 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +require 'csv' + +USER_FILE = Rails.root.join('db', 'user_seeds.csv') + +user_failures = [] +CSV.foreach(USER_FILE, :headers => true) do |row| + user = User.new + user.name = row['name'] + user.email = row['email'] + successful = user.save + if !successful + user_failures << user + else + puts "User created: #{user.inspect}" + end +end + +CATEGORY_FILE = Rails.root.join('db', 'category_seeds.csv') +category_failures = [] +CSV.foreach(CATEGORY_FILE, :headers => true) do |row| + category = Category.new + category.name = row['name'] + successful = category.save + if !successful + category_failures << category + else + puts "Category created: #{category.inspect}" + end +end + + +CREATURE_FILE = Rails.root.join('db', 'creature_seeds.csv') + +creature_failures = [] +CSV.foreach(CREATURE_FILE, :headers => true) do |row| + creature = Product.new + creature.name = row['name'] + creature.stock_count = row['stock_count'] + creature.description = row['description'] + creature.price = row['price'] + creature.photo_url = row['photo_url'] + ids = User.pluck(:id) + random_record = User.find(ids.sample) + creature.user_id = random_record.id + ids = Category.pluck(:id) + random_record = Category.find(ids.sample) + creature.category_id = random_record.id + successful = creature.save + if !successful + creature_failures << creature + else + puts "Creature created: #{creature.inspect}" + end +end diff --git a/db/user_seeds.csv b/db/user_seeds.csv new file mode 100644 index 0000000000..3b3cc4fe2f --- /dev/null +++ b/db/user_seeds.csv @@ -0,0 +1,3 @@ +name,email +Soren Smuggler,topsecret@gmail.com +Kylie Muramatsu,dontaskdontell@yahoo.com From 263f880cc1f556ff515bd2791b49f1db46b06766 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Wed, 17 Oct 2018 23:40:07 -0700 Subject: [PATCH 011/215] ordersrevired controller created, reviews controller created, view files created for new reviews --- app/assets/javascripts/orders_products.js | 2 ++ app/assets/javascripts/reviews.js | 2 ++ app/assets/stylesheets/orders_products.scss | 3 +++ app/assets/stylesheets/reviews.scss | 3 +++ app/controllers/orders_products_controller.rb | 2 ++ app/controllers/reviews_controller.rb | 14 ++++++++++++++ app/helpers/orders_products_helper.rb | 2 ++ app/helpers/reviews_helper.rb | 2 ++ app/views/reviews/new.html.erb | 1 + .../controllers/orders_products_controller_test.rb | 7 +++++++ test/controllers/reviews_controller_test.rb | 7 +++++++ 11 files changed, 45 insertions(+) create mode 100644 app/assets/javascripts/orders_products.js create mode 100644 app/assets/javascripts/reviews.js create mode 100644 app/assets/stylesheets/orders_products.scss create mode 100644 app/assets/stylesheets/reviews.scss create mode 100644 app/controllers/orders_products_controller.rb create mode 100644 app/controllers/reviews_controller.rb create mode 100644 app/helpers/orders_products_helper.rb create mode 100644 app/helpers/reviews_helper.rb create mode 100644 app/views/reviews/new.html.erb create mode 100644 test/controllers/orders_products_controller_test.rb create mode 100644 test/controllers/reviews_controller_test.rb diff --git a/app/assets/javascripts/orders_products.js b/app/assets/javascripts/orders_products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders_products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/orders_products.scss b/app/assets/stylesheets/orders_products.scss new file mode 100644 index 0000000000..84ea664e8a --- /dev/null +++ b/app/assets/stylesheets/orders_products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrdersProducts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/orders_products_controller.rb b/app/controllers/orders_products_controller.rb new file mode 100644 index 0000000000..373ac2941e --- /dev/null +++ b/app/controllers/orders_products_controller.rb @@ -0,0 +1,2 @@ +class OrdersProductsController < ApplicationController +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..73778ea84c --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,14 @@ +class ReviewsController < ApplicationController + +def new + @review = Review.new +end + +def create + +end + +# def edit +# end + +end diff --git a/app/helpers/orders_products_helper.rb b/app/helpers/orders_products_helper.rb new file mode 100644 index 0000000000..159322c253 --- /dev/null +++ b/app/helpers/orders_products_helper.rb @@ -0,0 +1,2 @@ +module OrdersProductsHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..5f0c2f80f5 --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1 @@ +

review form goes here

diff --git a/test/controllers/orders_products_controller_test.rb b/test/controllers/orders_products_controller_test.rb new file mode 100644 index 0000000000..e0213b449d --- /dev/null +++ b/test/controllers/orders_products_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrdersProductsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..386065239a --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ReviewsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From 4c804094c89c766210115ccb47a04ec0868da780 Mon Sep 17 00:00:00 2001 From: Divya Date: Thu, 18 Oct 2018 09:37:25 -0700 Subject: [PATCH 012/215] Made a start on products controller and views --- app/assets/javascripts/categories.js | 2 + app/assets/javascripts/products.js | 2 + app/assets/stylesheets/application.scss | 98 +++++++++++++++++++ app/assets/stylesheets/categories.scss | 3 + app/assets/stylesheets/products.scss | 3 + app/controllers/categories_controller.rb | 4 + app/controllers/products_controller.rb | 52 ++++++++++ app/helpers/categories_helper.rb | 2 + app/helpers/products_helper.rb | 2 + app/views/layouts/application.html.erb | 49 ++++++++++ app/views/products/_form.html.erb | 47 +++++++++ app/views/products/edit.html.erb | 2 + app/views/products/index.html.erb | 23 +++++ app/views/products/new.html.erb | 2 + app/views/products/show.html.erb | 81 +++++++++++++++ config/routes.rb | 1 + .../20181017234407_create_categories.rb | 9 -- ...17234721_change_column_name_in_products.rb | 5 - ..._create_category_id_column_for_products.rb | 5 - db/seed_data/product.csv | 79 +++++++++++++++ db/seed_data/seeds.rb | 84 ++++++++++++++++ db/seeds.rb | 7 -- .../controllers/categories_controller_test.rb | 7 ++ test/controllers/products_controller_test.rb | 7 ++ 24 files changed, 550 insertions(+), 26 deletions(-) create mode 100644 app/assets/javascripts/categories.js create mode 100644 app/assets/javascripts/products.js create mode 100644 app/assets/stylesheets/categories.scss create mode 100644 app/assets/stylesheets/products.scss create mode 100644 app/controllers/categories_controller.rb create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/categories_helper.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/views/products/_form.html.erb create mode 100644 app/views/products/edit.html.erb create mode 100644 app/views/products/index.html.erb create mode 100644 app/views/products/new.html.erb create mode 100644 app/views/products/show.html.erb delete mode 100644 db/migrate/20181017234407_create_categories.rb delete mode 100644 db/migrate/20181017234721_change_column_name_in_products.rb delete mode 100644 db/migrate/20181017235412_create_category_id_column_for_products.rb create mode 100644 db/seed_data/product.csv create mode 100644 db/seed_data/seeds.rb delete mode 100644 db/seeds.rb create mode 100644 test/controllers/categories_controller_test.rb create mode 100644 test/controllers/products_controller_test.rb diff --git a/app/assets/javascripts/categories.js b/app/assets/javascripts/categories.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/categories.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/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/application.scss b/app/assets/stylesheets/application.scss index 8b1701e581..210bc5b478 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,3 +16,101 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; + +body { + background-color: white; + color: black; +} + +main { + margin: 20vh 5vw; +} + +h2 { + text-align: center; +} +.top-bar, footer{ + background-color: white; + color: pink; + font-size: 1.5em; +} + +.top-bar { + position: fixed; + top: 0; + width: 100vw; + z-index: 5; +} + +footer { + position: fixed; + bottom: 0; + width: 100vw; +} + +.top-bar a, .top-bar ul li { + background-color: white; + color: hotpink; +} + +.top-bar-left a { + font-size: 2.5em; + font-weight: bold; + font-family: Arnoldboecklin, fantasy; + padding: 30px; +} + +.top-bar-right li { + padding: 1vw; +} + +.vertical a:hover { + font-weight: bold; +} + +.top-bar-left:hover { + font-weight: bold; +} + +.product-container { + display: flex; + flex-flow: row wrap; + justify-content: space-between; + align-content: center; + align-items: center; + text-align: center; + } + +.product-box { + width: 200px; + height: 300px; + /* border: 1px black solid; */ + margin: 0 0 1em 1em; + // display: flex; + // width: 100%; + // height: 80%; + // flex-wrap: wrap; + // flex-direction: row; + // justify-content: center; + +} + +pic { + text-align: center; +} + + +#tab-block-item { + overflow-y: scroll; + max-height: 47vh; +} + +.form-two-section { + overflow: hidden; +} + +.form-two-section select { + display: inline; + float: right; + width: 50%; +} diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..ef1657f8c9 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..89e2e8db07 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..5b255bea20 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,4 @@ +class CategoriesController < ApplicationController + def show + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..e7d9385767 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,52 @@ +class ProductsController < ApplicationController + class ProductsController < ApplicationController + before_action :find_product, only: [:show, :edit, :update, :destroy, :retire] + + def index + @products = Product.order(:name) + end + + def new + @product = Product.new(user_id: session[:user_id]) + end + + def create + @product = Product.new(product_params) + if @product.save + redirect_to products_path + else + flash[:failure] = "failed to save" + render :new, :status => :bad_request + end + end + + def show + end + + def edit;end + + def update + if @product.save + redirect_to product_path(@product) + else + render :edit, :status => :bad_request + end + end + + private + def product_params + return params.require(:product).permit(:name, :price, :stock, :product_status, :user_id, :image, :description, category_ids: []) + end + + def find_product + @product = Product.find_by(id: params[:id]) + if !@product + @product = Product.find_by(id: params[:product_id]) + end + + head :not_found unless @product + end + +end + +end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f18f1b6820..6c621cdaf7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,3 +13,52 @@ <%= yield %> + + + +
+ +
+ +
+
+ <% flash.each do |name, message| %> +
<%= message %>
+ <% end %> +
+ + <%= yield %> +
+ +
+
© 2018 Adoptsy
+
+ + + diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..4f08543a54 --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,47 @@ +<%= render partial: "layouts/errors", locals: { model: @product} %> +

+ <% page_title ||= "Product Changes" %> + <%= page_title %> +

+ +<%= form_for @product, html: { multipart: true } do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + + + + <%= f.label :stock_count %> + <%= f.number_field :stock_count %> + + <%= f.label :price %> + <%= f.number_field :price %> + + + <%= f.hidden_field :user_id %> + + <%= f.label :description %> + <%= f.text_area :description %> + +
+ + + Select a category from the list (Or create new category in 'Account' page) + +
+ <%= f.label :category %> + <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> +
+ + +
+ + <%= f.label :image %> + <%= f.file_field :image %> + + <%= f.submit class: "button" %> + +<% end %> diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..81bc1cf9a5 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,2 @@ +<%= render partial: "form", locals: { page_title: "Edit an existing product", + product: @product} %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..bdc9b0ff75 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,23 @@ +

Shop by Product

+ +
+ <% if @products %> + <% @products.each do |product| %> + <% if product.stock > 0 %> +
+ + <%= image_tag product.image.url %> + + + <%= link_to(product.name, product_path(product)) %> +
  • + Price: <%= %> +
  • +
  • + Average Rating: <%= '%.2f' % average_rating(product) %> +
  • +
    + <% end %> + <% end %> + <% end %> +
    diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..4643047bec --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,2 @@ +<%= render partial: "form", locals: { page_title: "Add a new product", + product: @product} %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..f332c1ce2d --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,81 @@ +

    Details for <%= @product.name %>

    + +
    + +
    +
      +
    • + + <%= image_tag #@product.image.url(:large) %> + +
    • +
    • +

      Product Info

      +

      <%= @product.name %> Summary

      +

      Average Rating: <%= average_rating(@product) %> | Sold by: <%= link_to @product.user.name, user_path(@product.user)%>

      +

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

      +

      Stock: <%= @product.stock %>

      +

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

      Categories:

      + + <% @product.categories.each do |category| %> + <%= link_to category.name.capitalize, category_path(category.id) %> +
    • + +
    +
    + +
    +

    Read Product Reviews

    +

    Product Reviews

    + + + + + + + + + <% @product.reviews.each do |review| %> + + + + + + + <% end %> +
    UserDateRatingReview
    Anonymous<%= review.created_at %><%= review.rating %><%= review.text %>
    +
    + + <% if session[:user_id] != @product.user_id %> +
    +

    Write New Review

    +

    Submit a New Review + + <%= render partial: "layouts/errors", locals: { model: @review } %> + +

    Rate This Product:

    + + + <%= form_for @review, url: product_reviews_path(@product.id) do |f| %> + + <%= f.label :text %> + <%= f.text_field :text %> + + <%= f.label :rating %> + <%= f.radio_button :rating, 1 %> + <%= label :rating, "1" %> + <%= f.radio_button :rating, 2 %> + <%= label :rating, "2" %> + <%= f.radio_button :rating, 3 %> + <%= label :rating, "3" %> + <%= f.radio_button :rating, 4 %> + <%= label :rating, "4" %> + <%= f.radio_button :rating, 5 %> + <%= label :rating, "5" %> + + <%= f.submit "Review", class:"button" %> + <% end %> +
    + <% end %> +
    diff --git a/config/routes.rb b/config/routes.rb index 050e2f200f..4e2ccbca70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,4 +10,5 @@ resources :categories # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + end diff --git a/db/migrate/20181017234407_create_categories.rb b/db/migrate/20181017234407_create_categories.rb deleted file mode 100644 index 6ccc3914a0..0000000000 --- a/db/migrate/20181017234407_create_categories.rb +++ /dev/null @@ -1,9 +0,0 @@ -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/migrate/20181017234721_change_column_name_in_products.rb b/db/migrate/20181017234721_change_column_name_in_products.rb deleted file mode 100644 index ca839f9cb6..0000000000 --- a/db/migrate/20181017234721_change_column_name_in_products.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChangeColumnNameInProducts < ActiveRecord::Migration[5.2] - def change - remove_column :products, :category - end -end diff --git a/db/migrate/20181017235412_create_category_id_column_for_products.rb b/db/migrate/20181017235412_create_category_id_column_for_products.rb deleted file mode 100644 index 5e015b5d84..0000000000 --- a/db/migrate/20181017235412_create_category_id_column_for_products.rb +++ /dev/null @@ -1,5 +0,0 @@ -class CreateCategoryIdColumnForProducts < ActiveRecord::Migration[5.2] - def change - add_reference :products, :category, index: true - end -end diff --git a/db/seed_data/product.csv b/db/seed_data/product.csv new file mode 100644 index 0000000000..78b8fc1511 --- /dev/null +++ b/db/seed_data/product.csv @@ -0,0 +1,79 @@ +name,stock,price,description,product_status,user_id,category +Cat Happy,,,Buy some Cat Happy today for your pet! You know they need it lately,, +Cat Scared,,,Buy some Cat Scared today for your pet! You know they need it lately,, +Cat Angry,,,Buy some Cat Angry today for your pet! You know they need it lately,, +Cat Sadness,,,Buy some Cat Sadness today for your pet! You know they need it lately,retired, +Cat Joy,,,Buy some Cat Joy today for your pet! You know they need it lately,, +Cat Disgust,,,Buy some Cat Disgust today for your pet! You know they need it lately,, +Cat Surprise,,,Buy some Cat Surprise today for your pet! You know they need it lately,, +Cat Trust,,,Buy some Cat Trust today for your pet! You know they need it lately,retired, +Cat Shame,,,Buy some Cat Shame today for your pet! You know they need it lately,, +Cat Love,,,Buy some Cat Love today for your pet! You know they need it lately,retired, +Dog Happy,,,Buy some Dog Happy today for your pet! You know they need it lately,, +Dog Scared,,,Buy some Dog Scared today for your pet! You know they need it lately,, +Dog Angry,,,Buy some Dog Angry today for your pet! You know they need it lately,, +Dog Sadness,,,Buy some Dog Sadness today for your pet! You know they need it lately,, +Dog Joy,,,Buy some Dog Joy today for your pet! You know they need it lately,retired, +Dog Disgust,,,Buy some Dog Disgust today for your pet! You know they need it lately,, +Dog Surprise,,,Buy some Dog Surprise today for your pet! You know they need it lately,, +Dog Trust,,,Buy some Dog Trust today for your pet! You know they need it lately,, +Dog Shame,,,Buy some Dog Shame today for your pet! You know they need it lately,, +Dog Love,,,Buy some Dog Love today for your pet! You know they need it lately,, +Fish Happy,,,Buy some Fish Happy today for your pet! You know they need it lately,, +Fish Scared,,,Buy some Fish Scared today for your pet! You know they need it lately,retired, +Fish Angry,,,Buy some Fish Angry today for your pet! You know they need it lately,, +Fish Sadness,,,Buy some Fish Sadness today for your pet! You know they need it lately,, +Fish Joy,,,Buy some Fish Joy today for your pet! You know they need it lately,retired, +Fish Disgust,,,Buy some Fish Disgust today for your pet! You know they need it lately,, +Fish Surprise,,,Buy some Fish Surprise today for your pet! You know they need it lately,, +Fish Trust,,,Buy some Fish Trust today for your pet! You know they need it lately,retired, +Fish Shame,,,Buy some Fish Shame today for your pet! You know they need it lately,retired, +Fish Love,,,Buy some Fish Love today for your pet! You know they need it lately,retired, +Horse Happy,,,Buy some Horse Happy today for your pet! You know they need it lately,, +Ferret Scared,,,Buy some Ferret Scared today for your pet! You know they need it lately,retired, +Ferret Angry,,,Buy some Ferret Angry today for your pet! You know they need it lately,retired, +Ferret Sadness,,,Buy some Ferret Sadness today for your pet! You know they need it lately,, +Ferret Joy,,,Buy some Ferret Joy today for your pet! You know they need it lately,retired, +Ferret Disgust,,,Buy some Ferret Disgust today for your pet! You know they need it lately,, +Ferret Surprise,,,Buy some Ferret Surprise today for your pet! You know they need it lately,, +Ferret Trust,,,Buy some Ferret Trust today for your pet! You know they need it lately,retired, +Ferret Shame,,,Buy some Ferret Shame today for your pet! You know they need it lately,, +Ferret Love,,,Buy some Ferret Love today for your pet! You know they need it lately,, +Hamster Happy,,,Buy some Hamster Happy today for your pet! You know they need it lately,, +Hamster Scared,,,Buy some Hamster Scared today for your pet! You know they need it lately,retired, +Hamster Angry,,,Buy some Hamster Angry today for your pet! You know they need it lately,, +Hamster Sadness,,,Buy some Hamster Sadness today for your pet! You know they need it lately,, +Hamster Joy,,,Buy some Hamster Joy today for your pet! You know they need it lately,retired, +Hamster Disgust,,,Buy some Hamster Disgust today for your pet! You know they need it lately,retired, +Hamster Surprise,,,Buy some Hamster Surprise today for your pet! You know they need it lately,, +Hamster Trust,,,Buy some Hamster Trust today for your pet! You know they need it lately,, +Hedgehog Happy,,,Buy some Hedgehog Happy today for your pet! You know they need it lately,, +Hedgehog Scared,,,Buy some Hedgehog Scared today for your pet! You know they need it lately,, +Hedgehog Angry,,,Buy some Hedgehog Angry today for your pet! You know they need it lately,retired, +Hedgehog Sadness,,,Buy some Hedgehog Sadness today for your pet! You know they need it lately,, +Hedgehog Joy,,,Buy some Hedgehog Joy today for your pet! You know they need it lately,, +Hedgehog Disgust,,,Buy some Hedgehog Disgust today for your pet! You know they need it lately,, +Hedgehog Surprise,,,Buy some Hedgehog Surprise today for your pet! You know they need it lately,retired, +Hedgehog Trust,,,Buy some Hedgehog Trust today for your pet! You know they need it lately,, +Hedgehog Shame,,,Buy some Hedgehog Shame today for your pet! You know they need it lately,, +Hedgehog Love,,,Buy some Hedgehog Love today for your pet! You know they need it lately,, +Chinchilla Happy,,,Buy some Chinchilla Happy today for your pet! You know they need it lately,, +Pony Scared,,,Buy some Pony Scared today for your pet! You know they need it lately,, +Chinchilla Angry,,,Buy some Chinchilla Angry today for your pet! You know they need it lately,retired, +Chinchilla Sadness,,,Buy some Chinchilla Sadness today for your pet! You know they need it lately,, +Chinchilla Joy,,,Buy some Chinchilla Joy today for your pet! You know they need it lately,, +Chinchilla Disgust,,,Buy some Chinchilla Disgust today for your pet! You know they need it lately,retired, +Chinchilla Surprise,,,Buy some Chinchilla Surprise today for your pet! You know they need it lately,, +Chinchilla Trust,,,Buy some Chinchilla Trust today for your pet! You know they need it lately,, +Chinchilla Shame,,,Buy some Chinchilla Shame today for your pet! You know they need it lately,retired, +Chinchilla Love,,,Buy some Chinchilla Love today for your pet! You know they need it lately,, +Turtle Happy,,,Buy some Turtle Happy today for your pet! You know they need it lately,, +Turtle Scared,,,Buy some Turtle Scared today for your pet! You know they need it lately,, +Turtle Angry,,,Buy some Turtle Angry today for your pet! You know they need it lately,retired, +Turtle Sadness,,,Buy some Turtle Sadness today for your pet! You know they need it lately,retired, +Turtle Joy,,,Buy some Turtle Joy today for your pet! You know they need it lately,, +Turtle Disgust,,,Buy some Turtle Disgust today for your pet! You know they need it lately,, +Turtle Surprise,,,Buy some Turtle Surprise today for your pet! You know they need it lately,retired, +Turtle Trust,,,Buy some Turtle Trust today for your pet! You know they need it lately,, +Turtle Shame,,,Buy some Turtle Shame today for your pet! You know they need it lately,, +Turtle Love,,,Buy some Turtle Love today for your pet! You know they need it lately,, diff --git a/db/seed_data/seeds.rb b/db/seed_data/seeds.rb new file mode 100644 index 0000000000..e0b4ae25c6 --- /dev/null +++ b/db/seed_data/seeds.rb @@ -0,0 +1,84 @@ +# 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) +require 'csv' + +categories_failures = [] + +CATEGORIES_FILE = Rails.root.join('db','seed_data', 'categories.csv') +CSV.foreach(CATEGORIES_FILE, :headers => true) do |row| + category = Category.new + category.name = row['name'] + + successful = category.save + if !successful + categories_failures << category + puts "Failed to save categories: #{category.inspect}" + else + puts "Created categories: #{category.inspect}" + end + +end + +puts "Added #{Category.count} categories records" +puts "#{categories_failures.length} categories failed to save" + +users_failures = [] + +USERS_FILE = Rails.root.join('db','seed_data', 'users.csv') +CSV.foreach(USERS_FILE, :headers => true) do |row| + user = User.new + user.name = row['name'] + user.email = row['email'] + user.uid = row['uid'] + user.provider = row['provider'] + + successful = user.save + if !successful + users_failures << user + puts "Failed to save users: #{user.inspect}" + else + puts "Created users: #{user.inspect}" + end +end + +puts "Added #{Category.count} categories records" +puts "#{categories_failures.length} categories failed to save" + + +product_failures = [] + +PRODUCT_FILE = Rails.root.join('db','seed_data', 'product.csv') +CSV.foreach(PRODUCT_FILE, :headers => true) do |row| + product = Product.new + product.name = row['name'] + product.stock = rand(1..38) + product.price = rand(8.25..200.89) + product.description = row['description'] + product.product_status = row['product_status'] + product.user = User.all.sample + + successful = product.save + if !successful + product_failures << product + puts "Failed to save products: #{product.inspect}" + else + puts "Created products: #{product.inspect}" + end + +end + +puts "Added #{Product.count} product records" +puts "#{product_failures.length} products failed to save" + +#adds categories to products +100.times do + category = Category.all.sample + prod = Product.all.sample + + prod.categories << category +end diff --git a/db/seeds.rb b/db/seeds.rb deleted file mode 100644 index 1beea2accd..0000000000 --- a/db/seeds.rb +++ /dev/null @@ -1,7 +0,0 @@ -# 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/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..125dd4c91d --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe CategoriesController do + # it "must be a real test" do + # flunk "Need real tests" + # end +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 From 8e806f5619ac43340d80dfba2290eda1a4317297 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 18 Oct 2018 09:43:52 -0700 Subject: [PATCH 013/215] Added total_revenue to User model and index/show to User controller --- app/controllers/users_controller.rb | 10 ++++++++++ app/models/user.rb | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 app/controllers/users_controller.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..8f9d14e037 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,10 @@ +class UsersController < ApplicationController + def index + @users = User.all + end + + def show + @user = User.find_by(id: params[:id]) + # render_404 unless @user + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 98d80278b6..3cd8685142 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,15 @@ class User < ApplicationRecord has_many :products has_many :orders + + def total_revenue + sum = 0 + self.products.each do |product| + product.orderproducts.each do |orderproduct| + sum += (orderproduct.product.cost * orderproduct.quantity) + end + end + return sum + end + end From 86aa4b917d1767a0f1c0f8cb0ad87e9b1d1d7fdc Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 09:44:46 -0700 Subject: [PATCH 014/215] add seed branch --- app/assets/javascripts/orders.js | 2 ++ app/assets/stylesheets/orders.scss | 3 +++ app/controllers/orders_controller.rb | 13 ++++++++++++ app/helpers/orders_helper.rb | 2 ++ app/views/orders/create.html.erb | 2 ++ app/views/orders/edit.html.erb | 2 ++ app/views/orders/new.html.erb | 2 ++ app/views/orders/update.html.erb | 2 ++ config/routes.rb | 4 ++++ test/controllers/orders_controller_test.rb | 24 ++++++++++++++++++++++ 10 files changed, 56 insertions(+) create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/views/orders/create.html.erb create mode 100644 app/views/orders/edit.html.erb create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/update.html.erb 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..dd6b6d9a80 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,13 @@ +class OrdersController < ApplicationController + 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/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/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 050e2f200f..a3423342b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ Rails.application.routes.draw do + get 'orders/new' + get 'orders/create' + get 'orders/edit' + get 'orders/update' resources :orders resources :products do diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..43a040e5ef --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,24 @@ +require "test_helper" + +describe OrdersController do + it "should get new" do + get orders_new_url + value(response).must_be :success? + end + + it "should get create" do + get orders_create_url + value(response).must_be :success? + end + + it "should get 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 05a3aa3c5c8cb37cc59b6f0c011f8ebfd436ee06 Mon Sep 17 00:00:00 2001 From: Divya Date: Thu, 18 Oct 2018 09:47:10 -0700 Subject: [PATCH 015/215] Merge branch 'master' of https://github.com/jfahmy/betsy # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. --- app/controllers/products_controller.rb | 1 - db/seed_data/product.csv | 79 ------------------------ db/seed_data/seeds.rb | 84 -------------------------- 3 files changed, 164 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index e7d9385767..7d33e6e3d4 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,4 @@ class ProductsController < ApplicationController - class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :destroy, :retire] def index diff --git a/db/seed_data/product.csv b/db/seed_data/product.csv index 78b8fc1511..e69de29bb2 100644 --- a/db/seed_data/product.csv +++ b/db/seed_data/product.csv @@ -1,79 +0,0 @@ -name,stock,price,description,product_status,user_id,category -Cat Happy,,,Buy some Cat Happy today for your pet! You know they need it lately,, -Cat Scared,,,Buy some Cat Scared today for your pet! You know they need it lately,, -Cat Angry,,,Buy some Cat Angry today for your pet! You know they need it lately,, -Cat Sadness,,,Buy some Cat Sadness today for your pet! You know they need it lately,retired, -Cat Joy,,,Buy some Cat Joy today for your pet! You know they need it lately,, -Cat Disgust,,,Buy some Cat Disgust today for your pet! You know they need it lately,, -Cat Surprise,,,Buy some Cat Surprise today for your pet! You know they need it lately,, -Cat Trust,,,Buy some Cat Trust today for your pet! You know they need it lately,retired, -Cat Shame,,,Buy some Cat Shame today for your pet! You know they need it lately,, -Cat Love,,,Buy some Cat Love today for your pet! You know they need it lately,retired, -Dog Happy,,,Buy some Dog Happy today for your pet! You know they need it lately,, -Dog Scared,,,Buy some Dog Scared today for your pet! You know they need it lately,, -Dog Angry,,,Buy some Dog Angry today for your pet! You know they need it lately,, -Dog Sadness,,,Buy some Dog Sadness today for your pet! You know they need it lately,, -Dog Joy,,,Buy some Dog Joy today for your pet! You know they need it lately,retired, -Dog Disgust,,,Buy some Dog Disgust today for your pet! You know they need it lately,, -Dog Surprise,,,Buy some Dog Surprise today for your pet! You know they need it lately,, -Dog Trust,,,Buy some Dog Trust today for your pet! You know they need it lately,, -Dog Shame,,,Buy some Dog Shame today for your pet! You know they need it lately,, -Dog Love,,,Buy some Dog Love today for your pet! You know they need it lately,, -Fish Happy,,,Buy some Fish Happy today for your pet! You know they need it lately,, -Fish Scared,,,Buy some Fish Scared today for your pet! You know they need it lately,retired, -Fish Angry,,,Buy some Fish Angry today for your pet! You know they need it lately,, -Fish Sadness,,,Buy some Fish Sadness today for your pet! You know they need it lately,, -Fish Joy,,,Buy some Fish Joy today for your pet! You know they need it lately,retired, -Fish Disgust,,,Buy some Fish Disgust today for your pet! You know they need it lately,, -Fish Surprise,,,Buy some Fish Surprise today for your pet! You know they need it lately,, -Fish Trust,,,Buy some Fish Trust today for your pet! You know they need it lately,retired, -Fish Shame,,,Buy some Fish Shame today for your pet! You know they need it lately,retired, -Fish Love,,,Buy some Fish Love today for your pet! You know they need it lately,retired, -Horse Happy,,,Buy some Horse Happy today for your pet! You know they need it lately,, -Ferret Scared,,,Buy some Ferret Scared today for your pet! You know they need it lately,retired, -Ferret Angry,,,Buy some Ferret Angry today for your pet! You know they need it lately,retired, -Ferret Sadness,,,Buy some Ferret Sadness today for your pet! You know they need it lately,, -Ferret Joy,,,Buy some Ferret Joy today for your pet! You know they need it lately,retired, -Ferret Disgust,,,Buy some Ferret Disgust today for your pet! You know they need it lately,, -Ferret Surprise,,,Buy some Ferret Surprise today for your pet! You know they need it lately,, -Ferret Trust,,,Buy some Ferret Trust today for your pet! You know they need it lately,retired, -Ferret Shame,,,Buy some Ferret Shame today for your pet! You know they need it lately,, -Ferret Love,,,Buy some Ferret Love today for your pet! You know they need it lately,, -Hamster Happy,,,Buy some Hamster Happy today for your pet! You know they need it lately,, -Hamster Scared,,,Buy some Hamster Scared today for your pet! You know they need it lately,retired, -Hamster Angry,,,Buy some Hamster Angry today for your pet! You know they need it lately,, -Hamster Sadness,,,Buy some Hamster Sadness today for your pet! You know they need it lately,, -Hamster Joy,,,Buy some Hamster Joy today for your pet! You know they need it lately,retired, -Hamster Disgust,,,Buy some Hamster Disgust today for your pet! You know they need it lately,retired, -Hamster Surprise,,,Buy some Hamster Surprise today for your pet! You know they need it lately,, -Hamster Trust,,,Buy some Hamster Trust today for your pet! You know they need it lately,, -Hedgehog Happy,,,Buy some Hedgehog Happy today for your pet! You know they need it lately,, -Hedgehog Scared,,,Buy some Hedgehog Scared today for your pet! You know they need it lately,, -Hedgehog Angry,,,Buy some Hedgehog Angry today for your pet! You know they need it lately,retired, -Hedgehog Sadness,,,Buy some Hedgehog Sadness today for your pet! You know they need it lately,, -Hedgehog Joy,,,Buy some Hedgehog Joy today for your pet! You know they need it lately,, -Hedgehog Disgust,,,Buy some Hedgehog Disgust today for your pet! You know they need it lately,, -Hedgehog Surprise,,,Buy some Hedgehog Surprise today for your pet! You know they need it lately,retired, -Hedgehog Trust,,,Buy some Hedgehog Trust today for your pet! You know they need it lately,, -Hedgehog Shame,,,Buy some Hedgehog Shame today for your pet! You know they need it lately,, -Hedgehog Love,,,Buy some Hedgehog Love today for your pet! You know they need it lately,, -Chinchilla Happy,,,Buy some Chinchilla Happy today for your pet! You know they need it lately,, -Pony Scared,,,Buy some Pony Scared today for your pet! You know they need it lately,, -Chinchilla Angry,,,Buy some Chinchilla Angry today for your pet! You know they need it lately,retired, -Chinchilla Sadness,,,Buy some Chinchilla Sadness today for your pet! You know they need it lately,, -Chinchilla Joy,,,Buy some Chinchilla Joy today for your pet! You know they need it lately,, -Chinchilla Disgust,,,Buy some Chinchilla Disgust today for your pet! You know they need it lately,retired, -Chinchilla Surprise,,,Buy some Chinchilla Surprise today for your pet! You know they need it lately,, -Chinchilla Trust,,,Buy some Chinchilla Trust today for your pet! You know they need it lately,, -Chinchilla Shame,,,Buy some Chinchilla Shame today for your pet! You know they need it lately,retired, -Chinchilla Love,,,Buy some Chinchilla Love today for your pet! You know they need it lately,, -Turtle Happy,,,Buy some Turtle Happy today for your pet! You know they need it lately,, -Turtle Scared,,,Buy some Turtle Scared today for your pet! You know they need it lately,, -Turtle Angry,,,Buy some Turtle Angry today for your pet! You know they need it lately,retired, -Turtle Sadness,,,Buy some Turtle Sadness today for your pet! You know they need it lately,retired, -Turtle Joy,,,Buy some Turtle Joy today for your pet! You know they need it lately,, -Turtle Disgust,,,Buy some Turtle Disgust today for your pet! You know they need it lately,, -Turtle Surprise,,,Buy some Turtle Surprise today for your pet! You know they need it lately,retired, -Turtle Trust,,,Buy some Turtle Trust today for your pet! You know they need it lately,, -Turtle Shame,,,Buy some Turtle Shame today for your pet! You know they need it lately,, -Turtle Love,,,Buy some Turtle Love today for your pet! You know they need it lately,, diff --git a/db/seed_data/seeds.rb b/db/seed_data/seeds.rb index e0b4ae25c6..e69de29bb2 100644 --- a/db/seed_data/seeds.rb +++ b/db/seed_data/seeds.rb @@ -1,84 +0,0 @@ -# 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) -require 'csv' - -categories_failures = [] - -CATEGORIES_FILE = Rails.root.join('db','seed_data', 'categories.csv') -CSV.foreach(CATEGORIES_FILE, :headers => true) do |row| - category = Category.new - category.name = row['name'] - - successful = category.save - if !successful - categories_failures << category - puts "Failed to save categories: #{category.inspect}" - else - puts "Created categories: #{category.inspect}" - end - -end - -puts "Added #{Category.count} categories records" -puts "#{categories_failures.length} categories failed to save" - -users_failures = [] - -USERS_FILE = Rails.root.join('db','seed_data', 'users.csv') -CSV.foreach(USERS_FILE, :headers => true) do |row| - user = User.new - user.name = row['name'] - user.email = row['email'] - user.uid = row['uid'] - user.provider = row['provider'] - - successful = user.save - if !successful - users_failures << user - puts "Failed to save users: #{user.inspect}" - else - puts "Created users: #{user.inspect}" - end -end - -puts "Added #{Category.count} categories records" -puts "#{categories_failures.length} categories failed to save" - - -product_failures = [] - -PRODUCT_FILE = Rails.root.join('db','seed_data', 'product.csv') -CSV.foreach(PRODUCT_FILE, :headers => true) do |row| - product = Product.new - product.name = row['name'] - product.stock = rand(1..38) - product.price = rand(8.25..200.89) - product.description = row['description'] - product.product_status = row['product_status'] - product.user = User.all.sample - - successful = product.save - if !successful - product_failures << product - puts "Failed to save products: #{product.inspect}" - else - puts "Created products: #{product.inspect}" - end - -end - -puts "Added #{Product.count} product records" -puts "#{product_failures.length} products failed to save" - -#adds categories to products -100.times do - category = Category.all.sample - prod = Product.all.sample - - prod.categories << category -end From 59f381b8013163a6819e13ac41e1a53b3d0a9aba Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 18 Oct 2018 09:48:48 -0700 Subject: [PATCH 016/215] Deleted fake seed data --- db/seed_data/product.csv | 79 ------------------------------------- db/seed_data/seeds.rb | 84 ---------------------------------------- 2 files changed, 163 deletions(-) delete mode 100644 db/seed_data/product.csv delete mode 100644 db/seed_data/seeds.rb diff --git a/db/seed_data/product.csv b/db/seed_data/product.csv deleted file mode 100644 index 78b8fc1511..0000000000 --- a/db/seed_data/product.csv +++ /dev/null @@ -1,79 +0,0 @@ -name,stock,price,description,product_status,user_id,category -Cat Happy,,,Buy some Cat Happy today for your pet! You know they need it lately,, -Cat Scared,,,Buy some Cat Scared today for your pet! You know they need it lately,, -Cat Angry,,,Buy some Cat Angry today for your pet! You know they need it lately,, -Cat Sadness,,,Buy some Cat Sadness today for your pet! You know they need it lately,retired, -Cat Joy,,,Buy some Cat Joy today for your pet! You know they need it lately,, -Cat Disgust,,,Buy some Cat Disgust today for your pet! You know they need it lately,, -Cat Surprise,,,Buy some Cat Surprise today for your pet! You know they need it lately,, -Cat Trust,,,Buy some Cat Trust today for your pet! You know they need it lately,retired, -Cat Shame,,,Buy some Cat Shame today for your pet! You know they need it lately,, -Cat Love,,,Buy some Cat Love today for your pet! You know they need it lately,retired, -Dog Happy,,,Buy some Dog Happy today for your pet! You know they need it lately,, -Dog Scared,,,Buy some Dog Scared today for your pet! You know they need it lately,, -Dog Angry,,,Buy some Dog Angry today for your pet! You know they need it lately,, -Dog Sadness,,,Buy some Dog Sadness today for your pet! You know they need it lately,, -Dog Joy,,,Buy some Dog Joy today for your pet! You know they need it lately,retired, -Dog Disgust,,,Buy some Dog Disgust today for your pet! You know they need it lately,, -Dog Surprise,,,Buy some Dog Surprise today for your pet! You know they need it lately,, -Dog Trust,,,Buy some Dog Trust today for your pet! You know they need it lately,, -Dog Shame,,,Buy some Dog Shame today for your pet! You know they need it lately,, -Dog Love,,,Buy some Dog Love today for your pet! You know they need it lately,, -Fish Happy,,,Buy some Fish Happy today for your pet! You know they need it lately,, -Fish Scared,,,Buy some Fish Scared today for your pet! You know they need it lately,retired, -Fish Angry,,,Buy some Fish Angry today for your pet! You know they need it lately,, -Fish Sadness,,,Buy some Fish Sadness today for your pet! You know they need it lately,, -Fish Joy,,,Buy some Fish Joy today for your pet! You know they need it lately,retired, -Fish Disgust,,,Buy some Fish Disgust today for your pet! You know they need it lately,, -Fish Surprise,,,Buy some Fish Surprise today for your pet! You know they need it lately,, -Fish Trust,,,Buy some Fish Trust today for your pet! You know they need it lately,retired, -Fish Shame,,,Buy some Fish Shame today for your pet! You know they need it lately,retired, -Fish Love,,,Buy some Fish Love today for your pet! You know they need it lately,retired, -Horse Happy,,,Buy some Horse Happy today for your pet! You know they need it lately,, -Ferret Scared,,,Buy some Ferret Scared today for your pet! You know they need it lately,retired, -Ferret Angry,,,Buy some Ferret Angry today for your pet! You know they need it lately,retired, -Ferret Sadness,,,Buy some Ferret Sadness today for your pet! You know they need it lately,, -Ferret Joy,,,Buy some Ferret Joy today for your pet! You know they need it lately,retired, -Ferret Disgust,,,Buy some Ferret Disgust today for your pet! You know they need it lately,, -Ferret Surprise,,,Buy some Ferret Surprise today for your pet! You know they need it lately,, -Ferret Trust,,,Buy some Ferret Trust today for your pet! You know they need it lately,retired, -Ferret Shame,,,Buy some Ferret Shame today for your pet! You know they need it lately,, -Ferret Love,,,Buy some Ferret Love today for your pet! You know they need it lately,, -Hamster Happy,,,Buy some Hamster Happy today for your pet! You know they need it lately,, -Hamster Scared,,,Buy some Hamster Scared today for your pet! You know they need it lately,retired, -Hamster Angry,,,Buy some Hamster Angry today for your pet! You know they need it lately,, -Hamster Sadness,,,Buy some Hamster Sadness today for your pet! You know they need it lately,, -Hamster Joy,,,Buy some Hamster Joy today for your pet! You know they need it lately,retired, -Hamster Disgust,,,Buy some Hamster Disgust today for your pet! You know they need it lately,retired, -Hamster Surprise,,,Buy some Hamster Surprise today for your pet! You know they need it lately,, -Hamster Trust,,,Buy some Hamster Trust today for your pet! You know they need it lately,, -Hedgehog Happy,,,Buy some Hedgehog Happy today for your pet! You know they need it lately,, -Hedgehog Scared,,,Buy some Hedgehog Scared today for your pet! You know they need it lately,, -Hedgehog Angry,,,Buy some Hedgehog Angry today for your pet! You know they need it lately,retired, -Hedgehog Sadness,,,Buy some Hedgehog Sadness today for your pet! You know they need it lately,, -Hedgehog Joy,,,Buy some Hedgehog Joy today for your pet! You know they need it lately,, -Hedgehog Disgust,,,Buy some Hedgehog Disgust today for your pet! You know they need it lately,, -Hedgehog Surprise,,,Buy some Hedgehog Surprise today for your pet! You know they need it lately,retired, -Hedgehog Trust,,,Buy some Hedgehog Trust today for your pet! You know they need it lately,, -Hedgehog Shame,,,Buy some Hedgehog Shame today for your pet! You know they need it lately,, -Hedgehog Love,,,Buy some Hedgehog Love today for your pet! You know they need it lately,, -Chinchilla Happy,,,Buy some Chinchilla Happy today for your pet! You know they need it lately,, -Pony Scared,,,Buy some Pony Scared today for your pet! You know they need it lately,, -Chinchilla Angry,,,Buy some Chinchilla Angry today for your pet! You know they need it lately,retired, -Chinchilla Sadness,,,Buy some Chinchilla Sadness today for your pet! You know they need it lately,, -Chinchilla Joy,,,Buy some Chinchilla Joy today for your pet! You know they need it lately,, -Chinchilla Disgust,,,Buy some Chinchilla Disgust today for your pet! You know they need it lately,retired, -Chinchilla Surprise,,,Buy some Chinchilla Surprise today for your pet! You know they need it lately,, -Chinchilla Trust,,,Buy some Chinchilla Trust today for your pet! You know they need it lately,, -Chinchilla Shame,,,Buy some Chinchilla Shame today for your pet! You know they need it lately,retired, -Chinchilla Love,,,Buy some Chinchilla Love today for your pet! You know they need it lately,, -Turtle Happy,,,Buy some Turtle Happy today for your pet! You know they need it lately,, -Turtle Scared,,,Buy some Turtle Scared today for your pet! You know they need it lately,, -Turtle Angry,,,Buy some Turtle Angry today for your pet! You know they need it lately,retired, -Turtle Sadness,,,Buy some Turtle Sadness today for your pet! You know they need it lately,retired, -Turtle Joy,,,Buy some Turtle Joy today for your pet! You know they need it lately,, -Turtle Disgust,,,Buy some Turtle Disgust today for your pet! You know they need it lately,, -Turtle Surprise,,,Buy some Turtle Surprise today for your pet! You know they need it lately,retired, -Turtle Trust,,,Buy some Turtle Trust today for your pet! You know they need it lately,, -Turtle Shame,,,Buy some Turtle Shame today for your pet! You know they need it lately,, -Turtle Love,,,Buy some Turtle Love today for your pet! You know they need it lately,, diff --git a/db/seed_data/seeds.rb b/db/seed_data/seeds.rb deleted file mode 100644 index e0b4ae25c6..0000000000 --- a/db/seed_data/seeds.rb +++ /dev/null @@ -1,84 +0,0 @@ -# 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) -require 'csv' - -categories_failures = [] - -CATEGORIES_FILE = Rails.root.join('db','seed_data', 'categories.csv') -CSV.foreach(CATEGORIES_FILE, :headers => true) do |row| - category = Category.new - category.name = row['name'] - - successful = category.save - if !successful - categories_failures << category - puts "Failed to save categories: #{category.inspect}" - else - puts "Created categories: #{category.inspect}" - end - -end - -puts "Added #{Category.count} categories records" -puts "#{categories_failures.length} categories failed to save" - -users_failures = [] - -USERS_FILE = Rails.root.join('db','seed_data', 'users.csv') -CSV.foreach(USERS_FILE, :headers => true) do |row| - user = User.new - user.name = row['name'] - user.email = row['email'] - user.uid = row['uid'] - user.provider = row['provider'] - - successful = user.save - if !successful - users_failures << user - puts "Failed to save users: #{user.inspect}" - else - puts "Created users: #{user.inspect}" - end -end - -puts "Added #{Category.count} categories records" -puts "#{categories_failures.length} categories failed to save" - - -product_failures = [] - -PRODUCT_FILE = Rails.root.join('db','seed_data', 'product.csv') -CSV.foreach(PRODUCT_FILE, :headers => true) do |row| - product = Product.new - product.name = row['name'] - product.stock = rand(1..38) - product.price = rand(8.25..200.89) - product.description = row['description'] - product.product_status = row['product_status'] - product.user = User.all.sample - - successful = product.save - if !successful - product_failures << product - puts "Failed to save products: #{product.inspect}" - else - puts "Created products: #{product.inspect}" - end - -end - -puts "Added #{Product.count} product records" -puts "#{product_failures.length} products failed to save" - -#adds categories to products -100.times do - category = Category.all.sample - prod = Product.all.sample - - prod.categories << category -end From 12c04d5b93d6f7c8c3a83c723373c0c07519b75e Mon Sep 17 00:00:00 2001 From: Divya Date: Thu, 18 Oct 2018 10:11:46 -0700 Subject: [PATCH 017/215] Edited syntax errors --- app/controllers/products_controller.rb | 2 -- db/schema.rb | 11 ++--------- db/seed_data/product.csv | 0 db/seed_data/seeds.rb | 0 4 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 db/seed_data/product.csv delete mode 100644 db/seed_data/seeds.rb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 7d33e6e3d4..9dec9f2222 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -47,5 +47,3 @@ def find_product end end - -end diff --git a/db/schema.rb b/db/schema.rb index e375571d4b..2f158a8b53 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,17 +10,11 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_17_235412) do +ActiveRecord::Schema.define(version: 2018_10_17_220527) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "categories", force: :cascade do |t| - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "orderproducts", force: :cascade do |t| t.bigint "order_id" t.bigint "product_id" @@ -51,11 +45,10 @@ t.datetime "updated_at", null: false t.integer "stock_count" t.integer "price" + t.string "category" t.string "photo_url" t.string "description" t.string "name" - 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 diff --git a/db/seed_data/product.csv b/db/seed_data/product.csv deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/db/seed_data/seeds.rb b/db/seed_data/seeds.rb deleted file mode 100644 index e69de29bb2..0000000000 From 1fc6ac6b8c4a5875398662101a1838676e1d2927 Mon Sep 17 00:00:00 2001 From: Divya Date: Thu, 18 Oct 2018 10:21:21 -0700 Subject: [PATCH 018/215] Made changes to controller --- app/controllers/products_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 9dec9f2222..3d06c37f5c 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -43,7 +43,6 @@ def find_product @product = Product.find_by(id: params[:product_id]) end - head :not_found unless @product end end From cb1a05b14cfa0a07303460441d7f1e2965bce5b6 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 13:28:32 -0700 Subject: [PATCH 019/215] add categories to schema --- app/models/category.rb | 2 +- db/migrate/20181018202045_create_categories.rb | 9 +++++++++ db/migrate/20181018202318_add_products_category_id.rb | 5 +++++ .../20181018202554_add_relationship_to_product.rb | 5 +++++ db/schema.rb | 10 +++++++++- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20181018202045_create_categories.rb create mode 100644 db/migrate/20181018202318_add_products_category_id.rb create mode 100644 db/migrate/20181018202554_add_relationship_to_product.rb diff --git a/app/models/category.rb b/app/models/category.rb index 343b339c34..097cfb9dc4 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,3 @@ class Category < ApplicationRecord - has_many :products + has_many :products, index: true end diff --git a/db/migrate/20181018202045_create_categories.rb b/db/migrate/20181018202045_create_categories.rb new file mode 100644 index 0000000000..6ccc3914a0 --- /dev/null +++ b/db/migrate/20181018202045_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/migrate/20181018202318_add_products_category_id.rb b/db/migrate/20181018202318_add_products_category_id.rb new file mode 100644 index 0000000000..fcd0bbf112 --- /dev/null +++ b/db/migrate/20181018202318_add_products_category_id.rb @@ -0,0 +1,5 @@ +class AddProductsCategoryId < ActiveRecord::Migration[5.2] + def change + add_column :products, :category_id, :integer + end +end diff --git a/db/migrate/20181018202554_add_relationship_to_product.rb b/db/migrate/20181018202554_add_relationship_to_product.rb new file mode 100644 index 0000000000..05d8e09ca9 --- /dev/null +++ b/db/migrate/20181018202554_add_relationship_to_product.rb @@ -0,0 +1,5 @@ +class AddRelationshipToProduct < ActiveRecord::Migration[5.2] + def change + add_index :products, :category_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 2f158a8b53..9b6eda5481 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_17_220527) do +ActiveRecord::Schema.define(version: 2018_10_18_202554) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "orderproducts", force: :cascade do |t| t.bigint "order_id" t.bigint "product_id" @@ -49,6 +55,8 @@ t.string "photo_url" t.string "description" t.string "name" + t.integer "category_id" + t.index ["category_id"], name: "index_products_on_category_id" t.index ["user_id"], name: "index_products_on_user_id" end From 8bb63c486c64939631498c02f1b51037270c022e Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 13:33:14 -0700 Subject: [PATCH 020/215] remove typo --- app/models/category.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/category.rb b/app/models/category.rb index 097cfb9dc4..343b339c34 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,3 @@ class Category < ApplicationRecord - has_many :products, index: true + has_many :products end From efd3ac1493e95bc5fbf5c743181fb46362344ad2 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 18 Oct 2018 13:41:03 -0700 Subject: [PATCH 021/215] Added order new/create methods and updated some views --- app/assets/stylesheets/application.scss | 98 --------------------- app/controllers/orderproducts_controller.rb | 2 + app/views/layouts/application.html.erb | 83 ++++++++--------- app/views/products/index.html.erb | 23 +++-- 4 files changed, 50 insertions(+), 156 deletions(-) create mode 100644 app/controllers/orderproducts_controller.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 210bc5b478..8b1701e581 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,101 +16,3 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; - -body { - background-color: white; - color: black; -} - -main { - margin: 20vh 5vw; -} - -h2 { - text-align: center; -} -.top-bar, footer{ - background-color: white; - color: pink; - font-size: 1.5em; -} - -.top-bar { - position: fixed; - top: 0; - width: 100vw; - z-index: 5; -} - -footer { - position: fixed; - bottom: 0; - width: 100vw; -} - -.top-bar a, .top-bar ul li { - background-color: white; - color: hotpink; -} - -.top-bar-left a { - font-size: 2.5em; - font-weight: bold; - font-family: Arnoldboecklin, fantasy; - padding: 30px; -} - -.top-bar-right li { - padding: 1vw; -} - -.vertical a:hover { - font-weight: bold; -} - -.top-bar-left:hover { - font-weight: bold; -} - -.product-container { - display: flex; - flex-flow: row wrap; - justify-content: space-between; - align-content: center; - align-items: center; - text-align: center; - } - -.product-box { - width: 200px; - height: 300px; - /* border: 1px black solid; */ - margin: 0 0 1em 1em; - // display: flex; - // width: 100%; - // height: 80%; - // flex-wrap: wrap; - // flex-direction: row; - // justify-content: center; - -} - -pic { - text-align: center; -} - - -#tab-block-item { - overflow-y: scroll; - max-height: 47vh; -} - -.form-two-section { - overflow: hidden; -} - -.form-two-section select { - display: inline; - float: right; - width: 50%; -} diff --git a/app/controllers/orderproducts_controller.rb b/app/controllers/orderproducts_controller.rb new file mode 100644 index 0000000000..e5039f7210 --- /dev/null +++ b/app/controllers/orderproducts_controller.rb @@ -0,0 +1,2 @@ +class OrderproductsController < ApplicationController +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6c621cdaf7..739523823c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,55 +1,48 @@ - - 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 %> - - - - - -
    - + + 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' %> + + +
    +
    <% flash.each do |name, message| %> -
    <%= message %>
    +
    <%= message %>
    <% end %>
    diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index bdc9b0ff75..316e7ba818 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,23 +1,20 @@

    Shop by Product

    -
    +
    <% if @products %> <% @products.each do |product| %> - <% if product.stock > 0 %> -
    - <%= image_tag product.image.url %> +

    <%= image_tag product.photo_url %>

    +
      + +
    • <%= link_to product.name, product_path(product.id) %>
    • +
    • <%= product.price %>
    • +
    • <%= product.stock_count %>
    • +
    • <%= product.category.name %>
    • +
    • <%= product.description %>
    • +
    - <%= link_to(product.name, product_path(product)) %> -
  • - Price: <%= %> -
  • -
  • - Average Rating: <%= '%.2f' % average_rating(product) %> -
  • -
    - <% end %> <% end %> <% end %>
    From 302efef4379157e826dbf0052ed91ece31b074bd Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 18 Oct 2018 13:42:48 -0700 Subject: [PATCH 022/215] removed show page --- app/views/products/show.html.erb | 81 -------------------------------- 1 file changed, 81 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index f332c1ce2d..e69de29bb2 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,81 +0,0 @@ -

    Details for <%= @product.name %>

    - -
    - -
    -
      -
    • - - <%= image_tag #@product.image.url(:large) %> - -
    • -
    • -

      Product Info

      -

      <%= @product.name %> Summary

      -

      Average Rating: <%= average_rating(@product) %> | Sold by: <%= link_to @product.user.name, user_path(@product.user)%>

      -

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

      -

      Stock: <%= @product.stock %>

      -

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

      Categories:

      - - <% @product.categories.each do |category| %> - <%= link_to category.name.capitalize, category_path(category.id) %> -
    • - -
    -
    - -
    -

    Read Product Reviews

    -

    Product Reviews

    - - - - - - - - - <% @product.reviews.each do |review| %> - - - - - - - <% end %> -
    UserDateRatingReview
    Anonymous<%= review.created_at %><%= review.rating %><%= review.text %>
    -
    - - <% if session[:user_id] != @product.user_id %> -
    -

    Write New Review

    -

    Submit a New Review - - <%= render partial: "layouts/errors", locals: { model: @review } %> - -

    Rate This Product:

    - - - <%= form_for @review, url: product_reviews_path(@product.id) do |f| %> - - <%= f.label :text %> - <%= f.text_field :text %> - - <%= f.label :rating %> - <%= f.radio_button :rating, 1 %> - <%= label :rating, "1" %> - <%= f.radio_button :rating, 2 %> - <%= label :rating, "2" %> - <%= f.radio_button :rating, 3 %> - <%= label :rating, "3" %> - <%= f.radio_button :rating, 4 %> - <%= label :rating, "4" %> - <%= f.radio_button :rating, 5 %> - <%= label :rating, "5" %> - - <%= f.submit "Review", class:"button" %> - <% end %> -
    - <% end %> -
    From 995595726bb3543ec7a3784d590a6dcaed4233f0 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Thu, 18 Oct 2018 13:49:40 -0700 Subject: [PATCH 023/215] session login --- .gitignore | 1 + Gemfile | 4 + Gemfile.lock | 28 ++++++ app/assets/javascripts/sessions.js | 2 + app/assets/stylesheets/application.scss | 98 -------------------- app/assets/stylesheets/sessions.scss | 3 + app/controllers/application_controller.rb | 5 + app/controllers/sessions_controller.rb | 38 ++++++++ app/controllers/users_controller.rb | 7 ++ app/helpers/sessions_helper.rb | 2 + app/views/layouts/application.html.erb | 22 ++--- app/views/sessions/new.html.erb | 10 ++ app/views/users/show.html.erb | 3 + config/initializers/omniauth.rb | 3 + config/routes.rb | 9 +- test/controllers/sessions_controller_test.rb | 7 ++ 16 files changed, 131 insertions(+), 111 deletions(-) create mode 100644 app/assets/javascripts/sessions.js create mode 100644 app/assets/stylesheets/sessions.scss create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/views/sessions/new.html.erb create mode 100644 app/views/users/show.html.erb create mode 100644 config/initializers/omniauth.rb create mode 100644 test/controllers/sessions_controller_test.rb diff --git a/.gitignore b/.gitignore index 18b43c9cd2..9e321bba40 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ /tmp/* !/log/.keep !/tmp/.keep +.env # Ignore uploaded files in development /storage/* diff --git a/Gemfile b/Gemfile index 6219256bd8..bc5ffd33f3 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,9 @@ gem 'jbuilder', '~> 2.5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false +gem "omniauth" +gem "omniauth-github" + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] @@ -48,6 +51,7 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'dotenv-rails' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 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/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/application.scss b/app/assets/stylesheets/application.scss index 210bc5b478..8b1701e581 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,101 +16,3 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; - -body { - background-color: white; - color: black; -} - -main { - margin: 20vh 5vw; -} - -h2 { - text-align: center; -} -.top-bar, footer{ - background-color: white; - color: pink; - font-size: 1.5em; -} - -.top-bar { - position: fixed; - top: 0; - width: 100vw; - z-index: 5; -} - -footer { - position: fixed; - bottom: 0; - width: 100vw; -} - -.top-bar a, .top-bar ul li { - background-color: white; - color: hotpink; -} - -.top-bar-left a { - font-size: 2.5em; - font-weight: bold; - font-family: Arnoldboecklin, fantasy; - padding: 30px; -} - -.top-bar-right li { - padding: 1vw; -} - -.vertical a:hover { - font-weight: bold; -} - -.top-bar-left:hover { - font-weight: bold; -} - -.product-container { - display: flex; - flex-flow: row wrap; - justify-content: space-between; - align-content: center; - align-items: center; - text-align: center; - } - -.product-box { - width: 200px; - height: 300px; - /* border: 1px black solid; */ - margin: 0 0 1em 1em; - // display: flex; - // width: 100%; - // height: 80%; - // flex-wrap: wrap; - // flex-direction: row; - // justify-content: center; - -} - -pic { - text-align: center; -} - - -#tab-block-item { - overflow-y: scroll; - max-height: 47vh; -} - -.form-two-section { - overflow: hidden; -} - -.form-two-section select { - display: inline; - float: right; - width: 50%; -} diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..7bef9cf826 --- /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..41bd944ae7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,7 @@ class ApplicationController < ActionController::Base + + private + def find_user + @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 new file mode 100644 index 0000000000..2653f5ebea --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,38 @@ +class SessionsController < ApplicationController + def create + # auth_hash = request.env['omniauth.auth'] + # + # user = User.find_by(uid: auth_hash[:uid], provider: 'github') || + # User.create_from_github(auth_hash) + + user = User.find_by(username: params[:user][:name]) + + if user.nil? + user = User.create(name: params[:user][:name], email: params[:user][:email]) + + if user.save + session[:user_id] = user.id + flash[:success] = "#{ user.name } Successfully logged in!" + redirect_to root_path + else + flash[:warning] = "#{ user.name } Unable to log in!" + redirect_to root_path + end + + else + session[:user_id] = user.id + flash[:success] = "#{ user.name } Successfully logged in!" + redirect_to root_path + end + end + + def new + @user = User.new + end + + def destroy + session[:user_id] = nil + flash[:success] = 'Successfully logged out' + redirect_back fallback_location: root_path + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8f9d14e037..467e2df6ea 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,4 +7,11 @@ def show @user = User.find_by(id: params[:id]) # render_404 unless @user end + + + private + + def user_params + return params.require(:user).permit(:name, :email) + end end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6c621cdaf7..cb77ae0f03 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,11 +9,6 @@ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - - <%= yield %> - - -
    @@ -33,13 +28,16 @@
  • <%= link_to "By Category", categories_path %>
  • - <% if session[:user_id] %> - <% @user = User.find(session[:user_id]) %> - <% end %> -
  • <%= link_to "Account"%>
  • -
  • <%= link_to "Logout"%>
  • -
  • <%= link_to "Login" %>
  • -
  • <%= link_to "Cart"%>
  • + +
      + <% if @current_user %> +
    • <%= link_to "Logged in as #{@current_user.username}", user_path(@current_user.id), class: "btn btn-primary" %>
    • +
    • <%= link_to "Log Out", logout_path, method: :delete, data: { confirm: "Are you sure you want to log out?" }, class: "btn btn-primary" %>
    • + <% else %> +
    • <%= link_to "Log In", login_path, class: "btn btn-primary" %>
    • + <% end %> +
    + diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000000..2204c8c04f --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,10 @@ +

    Log In

    + +<%= form_with model: @user, class: "user-form", url: login_path, method: :post do |f|%> +

    Please enter login details:

    + + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.submit "Log In"%> +<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000000..2710e33c14 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,3 @@ +

    User account page

    + +

    View list of products with option to update and edit them

    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 f073653c6e..60074e2e42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,13 @@ get 'orders/create' get 'orders/edit' get 'orders/update' + + post 'sessions/login', to: 'sessions#login', as: 'login' + get 'sessions/login', to: 'sessions#new' + delete 'sessions/destroy', to: 'sessions#destroy', as: 'logout' + + # get "/auth/:provider/callback", to: "sessions#create" + resources :orders resources :products do @@ -14,5 +21,5 @@ resources :categories # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - + end 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 9aa5be0dfdcd214cd438219ede8e95e5b086eea9 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Thu, 18 Oct 2018 15:09:49 -0700 Subject: [PATCH 024/215] user index --- app/views/users/index.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/views/users/index.html.erb diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000000..4bd6fb7de2 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,6 @@ +

    Sellers Pages

    + +<% @users.each do |user| %> + <%= link_to user.name, user_path(user) %> +
    +<% end %> From bf334e8185ffa9fc4f9f06ae3f40345cab247251 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 15:42:28 -0700 Subject: [PATCH 025/215] form submission works --- app/controllers/reviews_controller.rb | 21 +++++++++++++-------- app/views/reviews/new.html.erb | 17 ++++++++++++++++- config/routes.rb | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 73778ea84c..8e13dfeb2b 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -1,14 +1,19 @@ class ReviewsController < ApplicationController -def new - @review = Review.new -end - -def create + def new + @review = Review.new + @product = Product.find_by(id: params[:product_id]) + end -end + def create + @review = Review.new(review_params) + @review.save + redirect_to product_path(@review.product_id) + end -# def edit -# end +private + def review_params + params.require(:review).permit(:name, :rating, :review, :product_id) + end end diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb index 5f0c2f80f5..314e80255f 100644 --- a/app/views/reviews/new.html.erb +++ b/app/views/reviews/new.html.erb @@ -1 +1,16 @@ -

    review form goes here

    +

    Review form goes here

    + +<%= form_with(model: @review, url: [@product, @review]) do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :rating %> + <%= f.select :rating, [1, 2, 3, 4, 5] %> + + <%= f.label :review %> + <%= f.text_field :review %> + + <%= f.hidden_field :product_id, :value => @product.id %> + + <%= f.submit class: "btn" %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index f073653c6e..04976ded8d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,5 +14,5 @@ resources :categories # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - + end From 0320e1877a0c578bcb3f235f3a75896026c71f37 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 16:02:13 -0700 Subject: [PATCH 026/215] add 3 creature seeds --- db/creature_seeds.csv | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/creature_seeds.csv b/db/creature_seeds.csv index 93be8bbd54..aeb42cdc73 100644 --- a/db/creature_seeds.csv +++ b/db/creature_seeds.csv @@ -1,2 +1,4 @@ name,stock_count,description,price,photo_url -Frog,4,Your favorite cuddley non-posionous amphibian.,2000,https://dummyimage.com/600x400/000/fff +Frog,4,Your favorite cuddley non-posionous amphibian.,2000,https://i.imgur.com/JvI9dY9.jpg +Puppy,2,A baby dalmatian!,1500,https://i.imgur.com/gdxm25d.jpg +Hippo,1,Cute and dangerous!,100000,https://i.imgur.com/YDCtFMB.jpg From 8d848932094eb6449fff6813575e80baf3a510a7 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 16:22:18 -0700 Subject: [PATCH 027/215] built out product view show, added review button --- app/views/products/show.html.erb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index e69de29bb2..d9929cd1d6 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -0,0 +1,16 @@ +

    <%= @product.name %>

    + +<%= image_tag @product.photo_url %> + +<%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> + +

    Creature reviews:

    +<% @product.reviews.each do |review| %> +
      +
    • +

      Reviewer: <%= review.name %>

      +

      Rating: <%= review.rating %>

      +

      Review: <%= review.review %>

      +
    • +
    +<% end %> From 517d1059b5cee74f345f45d27466b4c112598929 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Thu, 18 Oct 2018 16:32:18 -0700 Subject: [PATCH 028/215] seed data updated, uid and provider added to users table --- app/controllers/application_controller.rb | 12 ++++++--- app/controllers/sessions_controller.rb | 27 ++++++------------- app/models/user.rb | 17 +++++++++++- app/views/layouts/application.html.erb | 6 ++--- config/routes.rb | 7 +++-- .../20181018230310_add_userid_to_user.rb | 6 +++++ db/schema.rb | 4 ++- db/seeds.rb | 2 ++ db/user_seeds.csv | 6 ++--- 9 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20181018230310_add_userid_to_user.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 41bd944ae7..e6c91fea0e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,13 @@ class ApplicationController < ActionController::Base + helper_method :logged_in? + helper_method :current_user private - def find_user - @current_user = User.find_by(id: session[:user_id]) - end + def logged_in? + current_user.present? + end + + def current_user + @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 2653f5ebea..7b46a15f51 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,27 +1,16 @@ class SessionsController < ApplicationController def create - # auth_hash = request.env['omniauth.auth'] - # - # user = User.find_by(uid: auth_hash[:uid], provider: 'github') || - # User.create_from_github(auth_hash) + auth_hash = request.env['omniauth.auth'] - user = User.find_by(username: params[:user][:name]) + user = User.find_by(uid: auth_hash[:uid], provider: 'github') || + User.create_from_github(auth_hash) - if user.nil? - user = User.create(name: params[:user][:name], email: params[:user][:email]) - - if user.save - session[:user_id] = user.id - flash[:success] = "#{ user.name } Successfully logged in!" - redirect_to root_path - else - flash[:warning] = "#{ user.name } Unable to log in!" - redirect_to root_path - end - - else + if user + flash[:result_text] = "Logged in as returning user #{user.name}" session[:user_id] = user.id - flash[:success] = "#{ user.name } Successfully logged in!" + redirect_to root_path + else + flash[:error] = "Could not create new user account: #{user.errors.messages}" redirect_to root_path end end diff --git a/app/models/user.rb b/app/models/user.rb index 3cd8685142..7c93941e23 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,7 @@ class User < ApplicationRecord has_many :products has_many :orders - + def total_revenue sum = 0 self.products.each do |product| @@ -12,4 +12,19 @@ def total_revenue return sum end + def self.build_from_github(auth_hash) + User.new( + uid: auth_hash[:uid], + provider: 'github', + username: auth_hash['info']['name'], + email: auth_hash['info']['email'] + ) + end + + def self.create_from_github(auth_hash) + user = build_from_github(auth_hash) + user.save + user + end + end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8c24dffbfa..b64a79f024 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -30,11 +30,11 @@
      - <% if @current_user %> -
    • <%= link_to "Logged in as #{@current_user.username}", user_path(@current_user.id), class: "btn btn-primary" %>
    • + <% if logged_in? %> +
    • <%= link_to "Logged in as #{@current_user.name}", user_path(@current_user.id), class: "btn btn-primary" %>
    • <%= link_to "Log Out", logout_path, method: :delete, data: { confirm: "Are you sure you want to log out?" }, class: "btn btn-primary" %>
    • <% else %> -
    • <%= link_to "Log In", login_path, class: "btn btn-primary" %>
    • +
    • <%= link_to "Log In", "/auth/github", class: "btn btn-primary" %>
    • <% end %>
    diff --git a/config/routes.rb b/config/routes.rb index 60074e2e42..b2f9944334 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,12 +4,11 @@ get 'orders/edit' get 'orders/update' - post 'sessions/login', to: 'sessions#login', as: 'login' - get 'sessions/login', to: 'sessions#new' + # post 'sessions/login', to: 'sessions#login', as: 'login' + # get 'sessions/login', to: 'sessions#new' + get "/auth/:provider/callback", to: "sessions#create" delete 'sessions/destroy', to: 'sessions#destroy', as: 'logout' - # get "/auth/:provider/callback", to: "sessions#create" - resources :orders resources :products do diff --git a/db/migrate/20181018230310_add_userid_to_user.rb b/db/migrate/20181018230310_add_userid_to_user.rb new file mode 100644 index 0000000000..05944ee5b1 --- /dev/null +++ b/db/migrate/20181018230310_add_userid_to_user.rb @@ -0,0 +1,6 @@ +class AddUseridToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :uid, :integer, :null => false + add_column :users, :provider, :string, :null => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 9b6eda5481..ec1ee2ecc7 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_202554) do +ActiveRecord::Schema.define(version: 2018_10_18_230310) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -75,6 +75,8 @@ t.string "email" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "uid", null: false + t.string "provider", null: false end end diff --git a/db/seeds.rb b/db/seeds.rb index 35446f0693..c6dadc5e59 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -14,6 +14,8 @@ user = User.new user.name = row['name'] user.email = row['email'] + user.uid = row['uid'] + user.provider = row['provider'] successful = user.save if !successful user_failures << user diff --git a/db/user_seeds.csv b/db/user_seeds.csv index 3b3cc4fe2f..3a4807dee8 100644 --- a/db/user_seeds.csv +++ b/db/user_seeds.csv @@ -1,3 +1,3 @@ -name,email -Soren Smuggler,topsecret@gmail.com -Kylie Muramatsu,dontaskdontell@yahoo.com +name,email,uid,provider +Soren Smuggler,topsecret@gmail.com,1,github +Kylie Muramatsu,dontaskdontell@yahoo.comg,2,github From 16cb27f6d8daef73a4da1eab86808ea73b37d5dc Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Thu, 18 Oct 2018 17:01:54 -0700 Subject: [PATCH 029/215] OAuth activated --- app/controllers/application_controller.rb | 2 ++ app/controllers/sessions_controller.rb | 1 + app/models/user.rb | 4 ++-- config/routes.rb | 5 +++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6c91fea0e..b28da73886 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ class ApplicationController < ActionController::Base + before_action :current_user + helper_method :logged_in? helper_method :current_user diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 7b46a15f51..2fce9bb549 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,4 +1,5 @@ class SessionsController < ApplicationController + def create auth_hash = request.env['omniauth.auth'] diff --git a/app/models/user.rb b/app/models/user.rb index 7c93941e23..ba4346abc3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,7 +16,7 @@ def self.build_from_github(auth_hash) User.new( uid: auth_hash[:uid], provider: 'github', - username: auth_hash['info']['name'], + name: auth_hash['info']['name'], email: auth_hash['info']['email'] ) end @@ -26,5 +26,5 @@ def self.create_from_github(auth_hash) user.save user end - + end diff --git a/config/routes.rb b/config/routes.rb index b2f9944334..6289846a5c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,11 +4,12 @@ get 'orders/edit' get 'orders/update' - # post 'sessions/login', to: 'sessions#login', as: 'login' - # get 'sessions/login', to: 'sessions#new' + root "products#index" + get "/auth/:provider/callback", to: "sessions#create" delete 'sessions/destroy', to: 'sessions#destroy', as: 'logout' + resources :orders resources :products do From cab82faa697d3e79f8407838a3a1ab73acf88644 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 17:06:15 -0700 Subject: [PATCH 030/215] hid review button from logged in user if they are viewing their own product --- app/views/products/show.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index d9929cd1d6..ff0eedf36a 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,8 +1,9 @@

    <%= @product.name %>

    <%= image_tag @product.photo_url %> - -<%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> +<% if @product.user != @current_user %> + <%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> +<% end %>

    Creature reviews:

    <% @product.reviews.each do |review| %> From b2a3547a6ff5b6d812a8fb9fc58a84a21174aff2 Mon Sep 17 00:00:00 2001 From: Jane Date: Thu, 18 Oct 2018 18:14:30 -0700 Subject: [PATCH 031/215] Added Order controller methods --- app/controllers/orders_controller.rb | 44 ++++++++++++++++++- app/controllers/orders_products_controller.rb | 2 - app/views/orders/create.html.erb | 2 - app/views/orders/new.html.erb | 30 ++++++++++++- app/views/orders/update.html.erb | 2 - 5 files changed, 70 insertions(+), 10 deletions(-) delete mode 100644 app/controllers/orders_products_controller.rb delete mode 100644 app/views/orders/create.html.erb delete mode 100644 app/views/orders/update.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index dd6b6d9a80..696a45fbcf 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,13 +1,53 @@ class OrdersController < ApplicationController def new + @order = Order.new end def create + @order = Order.new(order_params) + @order.status = "paid" + + # session[:products].each do |key, value| + # # OrderProducts.new(key: value, order_id: @order.id) + # end + # + # total_cost = 0 + # @order.orderproducts.each do |orderproduct| + # total_cost += (orderproduct.product.price * orderproduct.quantity) + # end + # @order.total_cost = total_cost + + if @order.save + flash[:success] = 'Your purchase is complete!' + redirect_to root_path + else + flash.now[:danger] = 'Unable to complete order' + render :new, status: :bad_request + end end - def edit + # def edit; end + # + # def update + # if @order && @order.update(params[:status]) + # redirect_to order_path(@order.id) + # elsif @order + # render :edit, status: :bad_request + # end + # end + + private + + def find_order + @order = Order.find_by(id: params[:id].to_i) + + if @order.nil? + flash.now[:danger] = "Cannot find the order #{params[:id]}" + end end - def update + def order_params + return params.require(:order).permit(:name, :email, :mailing_address, :zip_code, :cc_number, :cc_expiration, :cc_cvv) end + end diff --git a/app/controllers/orders_products_controller.rb b/app/controllers/orders_products_controller.rb deleted file mode 100644 index 373ac2941e..0000000000 --- a/app/controllers/orders_products_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class OrdersProductsController < ApplicationController -end diff --git a/app/views/orders/create.html.erb b/app/views/orders/create.html.erb deleted file mode 100644 index 295bd84094..0000000000 --- a/app/views/orders/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

    Orders#create

    -

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

    diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb index 1bc27609ce..b18d708515 100644 --- a/app/views/orders/new.html.erb +++ b/app/views/orders/new.html.erb @@ -1,2 +1,28 @@ -

    Orders#new

    -

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

    +
    + <%= form_with model: @order do |f| %> + + <%= f.label :name, "Name: " %> + <%= f.text_field :name %> + + <%= f.label :email, "Email: " %> + <%= f.text_field :email %> + + <%= f.label :mailing_address, "Mailing Address: " %> + <%= f.text_field :mailing_address %> + + <%= f.label :zip_code, "Zip Code: " %> + <%= f.text_field :zip_code %> + + <%= f.label :cc_number, "Credit Card Number: " %> + <%= f.text_field :cc_number %> + + <%= f.label :cc_expiration, "Credit Card Expiration: " %> + <%= f.text_field :cc_expiration %> + + <%= f.label :cc_cvv, "Credit Card Security Code (cvv): " %> + <%= f.text_field :cc_cvv %> + + <%= f.submit "Submit" %> + + <% end %> +
    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

    From 4e620878c76d8c3f80580d43dcb7e910ebbc84f5 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Thu, 18 Oct 2018 20:03:34 -0700 Subject: [PATCH 032/215] product new and edit views working --- app/controllers/products_controller.rb | 8 ++-- app/models/category.rb | 9 +++++ app/views/products/_form.html.erb | 55 ++++++++++---------------- app/views/products/edit.html.erb | 3 +- app/views/products/new.html.erb | 3 +- app/views/products/show.html.erb | 8 +++- 6 files changed, 42 insertions(+), 44 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 3d06c37f5c..5381dbc0ed 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -6,13 +6,15 @@ def index end def new - @product = Product.new(user_id: session[:user_id]) + @product = Product.new end def create @product = Product.new(product_params) + category = Category.find_by(name: product_params[:category_id]) + @product.category_id = category.id if @product.save - redirect_to products_path + redirect_to product_path(@product.id) else flash[:failure] = "failed to save" render :new, :status => :bad_request @@ -34,7 +36,7 @@ def update private def product_params - return params.require(:product).permit(:name, :price, :stock, :product_status, :user_id, :image, :description, category_ids: []) + return params.require(:product).permit(:name, :price, :stock_count, :user_id, :photo_url, :description, :category_id) end def find_product diff --git a/app/models/category.rb b/app/models/category.rb index 343b339c34..7a4c47b807 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,12 @@ class Category < ApplicationRecord has_many :products + + def self.category_list + category_list = [] + Category.all.each do |cat| + category_list << cat.name + end + category_list + end + end diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index 4f08543a54..f6277c9d03 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,47 +1,32 @@ -<%= render partial: "layouts/errors", locals: { model: @product} %> -

    - <% page_title ||= "Product Changes" %> - <%= page_title %> -

    +<% if @current_user %> -<%= form_for @product, html: { multipart: true } do |f| %> - <%= f.label :name %> - <%= f.text_field :name %> + <%= form_with model: @product do |f|%> - +

    <%= page_title %>

    - <%= f.label :stock_count %> - <%= f.number_field :stock_count %> + <%= f.label :name %> + <%= f.text_field :name %> - <%= f.label :price %> - <%= f.number_field :price %> + <%= f.label :stock_count %> + <%= f.text_field :stock_count %> + <%= f.label :price %> + <%= f.text_field :price %> - <%= f.hidden_field :user_id %> + <%= f.label :description %> + <%= f.text_area :description %> - <%= f.label :description %> - <%= f.text_area :description %> + <%= f.label :photo_url %> + <%= f.text_field :photo_url %> -
    + <%= f.label :category_id %> + <%= f.select :category_id, Category.category_list %> + <%= f.hidden_field :user_id, :value => @current_user.id %> - Select a category from the list (Or create new category in 'Account' page) - -
    - <%= f.label :category %> - <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> -
    - - -
    - - <%= f.label :image %> - <%= f.file_field :image %> - - <%= f.submit class: "button" %> + <%= f.submit "Save Creature", class: "btn btn-primary" %> + <% end %> +<% else %> +

    Hi Animal Mom, sorry, you must be signed in to add inventory to your creature product line.

    <% end %> diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb index 81bc1cf9a5..1d7f0ed1ab 100644 --- a/app/views/products/edit.html.erb +++ b/app/views/products/edit.html.erb @@ -1,2 +1 @@ -<%= render partial: "form", locals: { page_title: "Edit an existing product", - product: @product} %> +<%= render partial: "form", locals: { page_title: "Edit the creature in your inventory:"} %> diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb index 4643047bec..22f338a207 100644 --- a/app/views/products/new.html.erb +++ b/app/views/products/new.html.erb @@ -1,2 +1 @@ -<%= render partial: "form", locals: { page_title: "Add a new product", - product: @product} %> +<%= render partial: "form", locals: { page_title: "Add a new creature to you inventory:"} %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index ff0eedf36a..a0cc87388b 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,10 +1,14 @@

    <%= @product.name %>

    - <%= image_tag @product.photo_url %> +

    Type: <%= @product.category.name.capitalize %>

    +

    Description: <%= @product.description %>

    +

    Price: <%= @product.price %>

    + <% if @product.user != @current_user %> <%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> <% end %> - +
    +

    Creature reviews:

    <% @product.reviews.each do |review| %>
      From 2dcf807d99bdb11cbf9486fdbdbceaca54aac457 Mon Sep 17 00:00:00 2001 From: Jane Date: Fri, 19 Oct 2018 14:38:53 -0700 Subject: [PATCH 033/215] added build shopping cart and add to cart methods --- app/controllers/application_controller.rb | 6 +- app/controllers/products_controller.rb | 101 ++++++++++++---------- config/routes.rb | 7 +- 3 files changed, 60 insertions(+), 54 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b28da73886..284fcc601d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,10 +1,14 @@ class ApplicationController < ActionController::Base before_action :current_user - + before_action :build_cart helper_method :logged_in? helper_method :current_user private + def build_cart + session[:cart] = Array.new if !session[:cart] + end + def logged_in? current_user.present? end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 5381dbc0ed..33fbbfb993 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,50 +1,57 @@ class ProductsController < ApplicationController - before_action :find_product, only: [:show, :edit, :update, :destroy, :retire] - - def index - @products = Product.order(:name) - end - - def new - @product = Product.new - end - - def create - @product = Product.new(product_params) - category = Category.find_by(name: product_params[:category_id]) - @product.category_id = category.id - if @product.save - redirect_to product_path(@product.id) - else - flash[:failure] = "failed to save" - render :new, :status => :bad_request - end - end - - def show - end - - def edit;end - - def update - if @product.save - redirect_to product_path(@product) - else - render :edit, :status => :bad_request - end - end - - private - def product_params - return params.require(:product).permit(:name, :price, :stock_count, :user_id, :photo_url, :description, :category_id) - end - - def find_product - @product = Product.find_by(id: params[:id]) - if !@product - @product = Product.find_by(id: params[:product_id]) - end - - end + before_action :find_product + + def index + @products = Product.order(:name) + end + + def new + @product = Product.new + end + + def create + @product = Product.new(product_params) + category = Category.find_by(name: product_params[:category_id]) + @product.category_id = category.id + if @product.save + redirect_to product_path(@product.id) + else + flash[:failure] = "failed to save" + render :new, :status => :bad_request + end + end + + def show + end + + def edit;end + + def update + if @product.save + redirect_to product_path(@product) + else + render :edit, :status => :bad_request + end + end + + def add_to_cart + id = @product.id + quantity = 1 + session[:cart] << { id => quantity} + redirect_to product_path(@product.id) + end + + private + def product_params + return params.require(:product).permit(:name, :price, :stock_count, :user_id, :photo_url, :description, :category_id) + end + + def find_product + @product = Product.find_by(id: params[:id]) + if !@product + @product = Product.find_by(id: params[:product_id]) + end + + end end diff --git a/config/routes.rb b/config/routes.rb index 6289846a5c..04879a344a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,20 +1,15 @@ Rails.application.routes.draw do - get 'orders/new' - get 'orders/create' - get 'orders/edit' - get 'orders/update' - root "products#index" get "/auth/:provider/callback", to: "sessions#create" delete 'sessions/destroy', to: 'sessions#destroy', as: 'logout' - resources :orders resources :products do resources :reviews, only: [:new, :create] end + get "/products/:id/add_to_cart", to: "products#add_to_cart", as: "add_to_cart" resources :users, except: [:edit, :delete] From 8f202ff0063ac740d152f579db9ec23f6dd0f30b Mon Sep 17 00:00:00 2001 From: Jane Date: Fri, 19 Oct 2018 14:47:54 -0700 Subject: [PATCH 034/215] Added add to cart button --- app/views/products/show.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index a0cc87388b..895f0f627b 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -7,6 +7,7 @@ <% if @product.user != @current_user %> <%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> <% end %> + <%= link_to "Add to Cart", add_to_cart_path(@product.id), class: "btn btn-primary" %>

      Creature reviews:

      From 88e0994e52b3a22bba83a2b9f3058aa52d4b5777 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Fri, 19 Oct 2018 15:04:51 -0700 Subject: [PATCH 035/215] mergeing --- app/controllers/application_controller.rb | 6 ++++++ app/controllers/users_controller.rb | 11 +++++++---- app/views/users/show.html.erb | 11 ++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b28da73886..a04045ff8b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base before_action :current_user + before_action :find_user helper_method :logged_in? helper_method :current_user @@ -12,4 +13,9 @@ def logged_in? def current_user @current_user ||= User.find_by(id: session[:user_id]) end + + def find_user + @user = User.find_by(id: params[:id]) + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 467e2df6ea..3bb2932f72 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,14 +1,17 @@ class UsersController < ApplicationController + before_action :find_user, only: [:show] + def index @users = User.all end - def show - @user = User.find_by(id: params[:id]) - # render_404 unless @user - end + def show ;end + def print_products + @user.products + end + private def user_params diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 2710e33c14..43268f8372 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,12 @@ -

      User account page

      +

      Creature Parent

      +

      <%= @user.name %>

      + +
        + <%= @user.products.each do |product_details| %> + <%= product_details.each do |product|%> +
      • <%= product.name %>
      • + <% end %> + <% end %> +

      View list of products with option to update and edit them

      From 5869b8d8a4870b88ea026b0370b0d9cf828d8ad3 Mon Sep 17 00:00:00 2001 From: Jane Date: Fri, 19 Oct 2018 16:19:20 -0700 Subject: [PATCH 036/215] Add to cart form and method updates --- app/controllers/products_controller.rb | 17 +++++++++++++-- app/views/products/show.html.erb | 30 ++++++++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 33fbbfb993..0a8bb41fef 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -35,10 +35,23 @@ def update end def add_to_cart - id = @product.id - quantity = 1 + id = @product.id.to_i + quantity = params[:quantity].to_i +# session[:cart] = nil + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + return session[:cart][index][key] = value + quantity + redirect_to product_path(@product.id) + end + end + end + + # # # # # @product.stock_count #something session[:cart] << { id => quantity} + flash[:success] = "Added to cart" redirect_to product_path(@product.id) + end private diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 895f0f627b..cb4e0e3cdf 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -5,18 +5,30 @@

      Price: <%= @product.price %>

      <% if @product.user != @current_user %> - <%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> +<%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> <% end %> - <%= link_to "Add to Cart", add_to_cart_path(@product.id), class: "btn btn-primary" %> + +<%= form_with url: add_to_cart_path(@product.id), method: :get do |f| %> + +<% if @product.stock_count > 1 %> +<%= f.label :quantity, "Quantity"%>
      +<%= f.select :quantity, options_for_select([*1..@product.stock_count]) %> +<% else %> +<%= f.select :quantity, options_for_select([@product.stock_count]) %> +<% end %> +<%= f.submit "Add to Cart", class: "btn btn-primary"%> +<% end %> + +

      <%= session[:cart] %>

      Creature reviews:

      <% @product.reviews.each do |review| %> -
        -
      • -

        Reviewer: <%= review.name %>

        -

        Rating: <%= review.rating %>

        -

        Review: <%= review.review %>

        -
      • -
      +
        +
      • +

        Reviewer: <%= review.name %>

        +

        Rating: <%= review.rating %>

        +

        Review: <%= review.review %>

        +
      • +
      <% end %> From f30cd738f808dcee55641774920871406c50294a Mon Sep 17 00:00:00 2001 From: jfahmy Date: Fri, 19 Oct 2018 16:19:43 -0700 Subject: [PATCH 037/215] orderproduct and order controller, small changes --- app/controllers/orderproducts_controller.rb | 2 -- app/controllers/orders_controller.rb | 33 +++++++++------------ app/models/order.rb | 12 ++++++++ app/models/orderproduct.rb | 8 +++++ 4 files changed, 34 insertions(+), 21 deletions(-) delete mode 100644 app/controllers/orderproducts_controller.rb diff --git a/app/controllers/orderproducts_controller.rb b/app/controllers/orderproducts_controller.rb deleted file mode 100644 index e5039f7210..0000000000 --- a/app/controllers/orderproducts_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class OrderproductsController < ApplicationController -end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 696a45fbcf..d148775a4b 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,22 +1,17 @@ class OrdersController < ApplicationController + def new @order = Order.new end def create - @order = Order.new(order_params) - @order.status = "paid" - - # session[:products].each do |key, value| - # # OrderProducts.new(key: value, order_id: @order.id) - # end - # - # total_cost = 0 - # @order.orderproducts.each do |orderproduct| - # total_cost += (orderproduct.product.price * orderproduct.quantity) - # end - # @order.total_cost = total_cost + @order = Order.new + @order.status = "pending" + @order.save + create_product_orders(order_id) + @order.total_cost = @order.order_total + @order = Order.update(order_params) if @order.save flash[:success] = 'Your purchase is complete!' redirect_to root_path @@ -28,13 +23,13 @@ def create # def edit; end # - # def update - # if @order && @order.update(params[:status]) - # redirect_to order_path(@order.id) - # elsif @order - # render :edit, status: :bad_request - # end - # end + def update + if @order && @order.update(params[:status]) + redirect_to order_path(@order.id) + elsif @order + render :edit, status: :bad_request + end + end private diff --git a/app/models/order.rb b/app/models/order.rb index c9c7536e0f..01433ae223 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,16 @@ class Order < ApplicationRecord has_many :orderproducts belongs_to :user, optional: true + + validates :name, :email, :mailing_address, :zip_code, :cc_number, + :cc_expiration, :cc_cvv, :status, :tota_cost, presence: true, on: :update + + def order_total + total_cost = 0 + @order.orderproducts.each do |orderproduct| + total_cost += (orderproduct.product.price * orderproduct.quantity) + end + total_cost + end + end diff --git a/app/models/orderproduct.rb b/app/models/orderproduct.rb index 2be353fe43..b619226b36 100644 --- a/app/models/orderproduct.rb +++ b/app/models/orderproduct.rb @@ -1,4 +1,12 @@ class Orderproduct < ApplicationRecord belongs_to :order belongs_to :product + + + def create_product_orders(order_id, ) + session[:cart].each do |key, value| + OrderProducts.new(product_id: key, quantity: value, order_id: order_id) + end + end + end From ab22dead7eff44e677279ff07ecd314b69690845 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Fri, 19 Oct 2018 16:25:24 -0700 Subject: [PATCH 038/215] merhant views display products, new nave options --- app/views/layouts/application.html.erb | 8 ++++++-- app/views/users/show.html.erb | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b64a79f024..cebdc721ef 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,8 +31,12 @@
        <% if logged_in? %> -
      • <%= link_to "Logged in as #{@current_user.name}", user_path(@current_user.id), class: "btn btn-primary" %>
      • -
      • <%= link_to "Log Out", logout_path, method: :delete, data: { confirm: "Are you sure you want to log out?" }, class: "btn btn-primary" %>
      • +
          +
        • <%= link_to "Logged in as #{@current_user.name}", user_path(@current_user.id) %>
        • +
        • <%= link_to "Log Out", logout_path, method: :delete, data: { confirm: "Are you sure you want to log out?" } %>
        • +
        • <%= link_to "Add Creature", new_product_path %>
        • +
        • <%= link_to "Add Category", new_category_path %>
        • +
        • <%= link_to "Fulfillment Page(dummy button)" %>
        • <% else %>
        • <%= link_to "Log In", "/auth/github", class: "btn btn-primary" %>
        • <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 43268f8372..466b2ce138 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,12 +1,14 @@

          Creature Parent

          <%= @user.name %>

          -
            - <%= @user.products.each do |product_details| %> - <%= product_details.each do |product|%> -
          • <%= product.name %>
          • +
            +

            Creatures

            +
              + <% @user.products.each do |product| %> +
            • <%= link_to "#{product.name}", product_path(product.id) %>
            • + <% if logged_in? %> + <%= link_to "Edit", edit_product_path(product.id)%> + <% end %> <% end %> - <% end %> -
            - -

            View list of products with option to update and edit them

            +

          +
          From 3924d43c0790ae9c7eb2aa95a8c6ce6171a45e89 Mon Sep 17 00:00:00 2001 From: Jane Date: Fri, 19 Oct 2018 17:01:25 -0700 Subject: [PATCH 039/215] more changed to add_to_cart logic --- app/controllers/products_controller.rb | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 0a8bb41fef..b9aacefabb 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -37,21 +37,25 @@ def update def add_to_cart id = @product.id.to_i quantity = params[:quantity].to_i -# session[:cart] = nil - session[:cart].each.with_index do |hash, index| - hash.each do |key, value| - if key == id.to_s - return session[:cart][index][key] = value + quantity - redirect_to product_path(@product.id) + + if quantity > @product.stock_count + flash[:failure] = "Failure to add to cart" + redirect_to product_path(@product.id) + return + else + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + session[:cart][index][key] = value + quantity + redirect_to product_path(@product.id) + return + end end end + session[:cart] << { id => quantity} + flash[:success] = "Added to cart" + redirect_to product_path(@product.id) end - - # # # # # @product.stock_count #something - session[:cart] << { id => quantity} - flash[:success] = "Added to cart" - redirect_to product_path(@product.id) - end private From 0d9462cf8d33379de233525bd1eda4c190d6c708 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Fri, 19 Oct 2018 18:19:20 -0700 Subject: [PATCH 040/215] fix for product edit form bug --- app/controllers/orders_controller.rb | 2 +- app/controllers/products_controller.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 696a45fbcf..de4c66e925 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -5,7 +5,7 @@ def new def create @order = Order.new(order_params) - @order.status = "paid" + @order.status = "pending" # session[:products].each do |key, value| # # OrderProducts.new(key: value, order_id: @order.id) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 0a8bb41fef..74b3fee26a 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -27,6 +27,9 @@ def show def edit;end def update + @product.update(product_params) + category = Category.find_by(name: product_params[:category_id]) + @product.category_id = category.id if @product.save redirect_to product_path(@product) else @@ -46,7 +49,7 @@ def add_to_cart end end end - + # # # # # @product.stock_count #something session[:cart] << { id => quantity} flash[:success] = "Added to cart" From a355858de1b96442ed7499d8b2950c80ce0adaff Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 14:10:46 -0700 Subject: [PATCH 041/215] Added cart_view method and cart.html.erb page --- app/assets/stylesheets/application.scss | 5 +++++ app/controllers/products_controller.rb | 11 +++++++++++ app/views/products/cart.html.erb | 19 +++++++++++++++++++ config/routes.rb | 5 ++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/views/products/cart.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8b1701e581..f120b3f2c8 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,3 +16,8 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; + +.cart-img { + width: 150px; + height: 150px; +} diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index b2d3e7e5c3..0c58504449 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -61,6 +61,17 @@ def add_to_cart end end + def cart_view + @cart_items = [] + session[:cart].each.with_index do |hash| + hash.each do |key, value| + cart_product = Product.find_by(id: key.to_i) + @cart_items << [cart_product, value] + end + end + render :cart + end + private def product_params return params.require(:product).permit(:name, :price, :stock_count, :user_id, :photo_url, :description, :category_id) diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb new file mode 100644 index 0000000000..5df2a50191 --- /dev/null +++ b/app/views/products/cart.html.erb @@ -0,0 +1,19 @@ +
          + <% total = 0 %> + <% @cart_items.each do |cart_array| %> +
            +
          • <%= image_tag cart_array[0].photo_url, class: "cart-img"%>
          • +
          • <%= cart_array[0].name%>
          • +
          • Price: $<%= cart_array[0].price%>
          • +
          • Quantity: <%= cart_array[1]%>
          • + <% total += (cart_array[1] * cart_array[0].price) %> +
          • Total: <%= cart_array[1] * cart_array[0].price %>
          • +
          • Update Quantity
          • +
          • Remove from Cart
          • +
          + <% end %> +
          +
          +

          Cart Total: $<%= total %>

          +

          Checkout Cart

          +
          diff --git a/config/routes.rb b/config/routes.rb index 04879a344a..cd47ad18a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Rails.application.routes.draw do root "products#index" - + get "/products/cart", to: "products#cart_view", as: "cart" + get "/auth/:provider/callback", to: "sessions#create" delete 'sessions/destroy', to: 'sessions#destroy', as: 'logout' @@ -9,8 +10,10 @@ resources :products do resources :reviews, only: [:new, :create] end + get "/products/:id/add_to_cart", to: "products#add_to_cart", as: "add_to_cart" + resources :users, except: [:edit, :delete] resources :categories From 448718928406a0f982cb529c92493eec8a1c6b9b Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 14:53:06 -0700 Subject: [PATCH 042/215] Added update cart and remove from cart methods --- app/controllers/products_controller.rb | 53 ++++++++++++++++++++------ app/views/layouts/application.html.erb | 1 + app/views/products/cart.html.erb | 33 ++++++++++++---- app/views/products/show.html.erb | 3 +- config/routes.rb | 3 +- 5 files changed, 71 insertions(+), 22 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 0c58504449..c036c2bf9c 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -40,25 +40,26 @@ def update def add_to_cart id = @product.id.to_i quantity = params[:quantity].to_i - - if quantity > @product.stock_count - flash[:failure] = "Failure to add to cart" - redirect_to product_path(@product.id) - return - else - session[:cart].each.with_index do |hash, index| - hash.each do |key, value| - if key == id.to_s + # session[:cart] = nil + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + new_quantity = value + quantity + if new_quantity <= @product.stock_count session[:cart][index][key] = value + quantity redirect_to product_path(@product.id) return + else + flash[:failure] = "Failure to add to cart. Not enough stock." + redirect_to product_path(@product.id) + return end end end - session[:cart] << { id => quantity} - flash[:success] = "Added to cart" - redirect_to product_path(@product.id) end + session[:cart] << { id => quantity} + flash[:success] = "Added to cart" + redirect_to product_path(@product.id) end def cart_view @@ -72,6 +73,34 @@ def cart_view render :cart end + def update_quantity + id = @product.id.to_i + quantity = params[:quantity].to_i + + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + session[:cart][index][key] = quantity + flash[:success] = "Successfully updated cart." + redirect_to cart_path + end + end + end + end + + def remove_from_cart + id = @product.id.to_i + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + session[:cart][index][key] = 0 + flash[:success] = "Successfully removed from cart." + redirect_to cart_path + end + end + end + end + private def product_params return params.require(:product).permit(:name, :price, :stock_count, :user_id, :photo_url, :description, :category_id) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cebdc721ef..ed7e9f18df 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,6 +26,7 @@
        • <%= link_to "All Products", products_path %>
        • <%= link_to "By Seller", users_path %>
        • <%= link_to "By Category", categories_path %>
        • +
        • <%= link_to "View Cart", cart_path %>
        diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index 5df2a50191..cfb7da263a 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -1,19 +1,38 @@
        <% total = 0 %> + <% if @cart_items.length > 0 %> <% @cart_items.each do |cart_array| %> + <% if cart_array[1] > 0 %> + <% product = cart_array[0] %> + <% quantity = cart_array[1] %>
          -
        • <%= image_tag cart_array[0].photo_url, class: "cart-img"%>
        • -
        • <%= cart_array[0].name%>
        • -
        • Price: $<%= cart_array[0].price%>
        • -
        • Quantity: <%= cart_array[1]%>
        • - <% total += (cart_array[1] * cart_array[0].price) %> -
        • Total: <%= cart_array[1] * cart_array[0].price %>
        • +
        • <%= image_tag product.photo_url, class: "cart-img"%>
        • +
        • <%= link_to product.name, product_path(product.id) %>
        • +
        • Price: $<%= product.price%>
        • +
        • Quantity: <%= quantity%>
        • + <% total += (quantity * product.price) %> +
        • Total: $<%= quantity * product.price %>
        • Update Quantity
        • -
        • Remove from Cart
        • + <%= form_with url: update_cart_path(product.id), method: :get do |f| %> + <% if product.stock_count > 1 %> + <%= f.label :quantity, "Update Quantity"%>
          + <%= f.select :quantity, options_for_select([*1..product.stock_count]) %> + <% else %> + <%= f.select :quantity, options_for_select([product.stock_count]) %> + <% end %> + <%= f.submit "Update Quantity", class: "btn btn-primary"%> + <% end %> +
        • <%= link_to "Remove from Cart", remove_from_cart_path(product.id), class: "btn btn-primary"%>
        <% end %> + <% end %>

        Cart Total: $<%= total %>

        Checkout Cart

        +<% else %> +
        +

        Your cart is empty

        +
        +<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index cb4e0e3cdf..4bebf12f52 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -9,7 +9,6 @@ <% end %> <%= form_with url: add_to_cart_path(@product.id), method: :get do |f| %> - <% if @product.stock_count > 1 %> <%= f.label :quantity, "Quantity"%>
        <%= f.select :quantity, options_for_select([*1..@product.stock_count]) %> @@ -18,7 +17,7 @@ <% end %> <%= f.submit "Add to Cart", class: "btn btn-primary"%> <% end %> - +

        <%= session[:cart] %>

        diff --git a/config/routes.rb b/config/routes.rb index cd47ad18a3..9c05820702 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,8 @@ end get "/products/:id/add_to_cart", to: "products#add_to_cart", as: "add_to_cart" - + get "/products/:id/update_cart", to: "products#update_quantity", as: "update_cart" + get "/products/:id/remove", to: "products#remove_from_cart", as: "remove_from_cart" resources :users, except: [:edit, :delete] From 712b099b2f29e4712dd725eca93e0c101d4491e8 Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 15:06:35 -0700 Subject: [PATCH 043/215] Changed some logic on the cart view page --- app/views/products/cart.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index cfb7da263a..3ec88e2451 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -1,6 +1,6 @@ -

        +

        Shopping Cart

        <% total = 0 %> - <% if @cart_items.length > 0 %> +
        <% @cart_items.each do |cart_array| %> <% if cart_array[1] > 0 %> <% product = cart_array[0] %> @@ -27,6 +27,7 @@ <% end %> <% end %>
        +<% if total > 0 %>

        Cart Total: $<%= total %>

        Checkout Cart

        From 6d49e10cf1b4576636652c7bf0f9b0ae21e5f5ca Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 15:10:14 -0700 Subject: [PATCH 044/215] More logic/html changes on the cart view page --- app/views/products/cart.html.erb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index 3ec88e2451..92b7ef6fd6 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -12,15 +12,13 @@
      • Quantity: <%= quantity%>
      • <% total += (quantity * product.price) %>
      • Total: $<%= quantity * product.price %>
      • -
      • Update Quantity
      • <%= form_with url: update_cart_path(product.id), method: :get do |f| %> <% if product.stock_count > 1 %> - <%= f.label :quantity, "Update Quantity"%>
        - <%= f.select :quantity, options_for_select([*1..product.stock_count]) %> +
      • <%= f.select :quantity, options_for_select([*1..product.stock_count]) %> <% else %> - <%= f.select :quantity, options_for_select([product.stock_count]) %> +
      • <%= f.select :quantity, options_for_select([product.stock_count]) %> <% end %> - <%= f.submit "Update Quantity", class: "btn btn-primary"%> + <%= f.submit "Update Quantity", class: "btn btn-primary"%>
      • <% end %>
      • <%= link_to "Remove from Cart", remove_from_cart_path(product.id), class: "btn btn-primary"%>
      From 535381329bc5814d03990ff42c71a5f4a7da1cb0 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Sat, 20 Oct 2018 16:04:14 -0700 Subject: [PATCH 045/215] add 404 not found for creature show page --- app/assets/stylesheets/application.scss | 10 ++++++++++ app/controllers/products_controller.rb | 7 +++++-- app/views/products/notfound.html.erb | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 app/views/products/notfound.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index f120b3f2c8..be5035c54c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -21,3 +21,13 @@ width: 150px; height: 150px; } + +.notfound { + text-align: center; + align-self: center; + width: 70%; +} + +.not_found { + font-size: 4rem; +} diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index c036c2bf9c..4dd1c48621 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -108,9 +108,12 @@ def product_params def find_product @product = Product.find_by(id: params[:id]) - if !@product - @product = Product.find_by(id: params[:product_id]) + if @product.nil? + render :notfound, status: :not_found end + # if !@product + # @product = Product.find_by(id: params[:product_id]) + # end end diff --git a/app/views/products/notfound.html.erb b/app/views/products/notfound.html.erb new file mode 100644 index 0000000000..4d2d9bd6b1 --- /dev/null +++ b/app/views/products/notfound.html.erb @@ -0,0 +1,4 @@ +
      +

      404

      +

      Oops! The creature you were looking for cannot be found. It must have found a home.

      +
      From a3f8c130502ff85bc82b14d17556edd54b77a8b5 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Sat, 20 Oct 2018 16:11:46 -0700 Subject: [PATCH 046/215] adjust before_action in products controller --- app/controllers/products_controller.rb | 2 +- app/controllers/sessions_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 4dd1c48621..7c8fe4cd81 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,5 @@ class ProductsController < ApplicationController - before_action :find_product + before_action :find_product, only: [:show, :edit, :update] def index @products = Product.order(:name) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2fce9bb549..9b41fee466 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,5 @@ class SessionsController < ApplicationController - + def create auth_hash = request.env['omniauth.auth'] From c0be07fd216f5c785c0559a2a1a545642de89bd5 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Sat, 20 Oct 2018 16:13:59 -0700 Subject: [PATCH 047/215] adjust product before methods --- app/controllers/products_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 7c8fe4cd81..1b6eb6c3d7 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,5 @@ class ProductsController < ApplicationController - before_action :find_product, only: [:show, :edit, :update] + before_action :find_product, only: [:show, :edit, :update, :add_to_cart] def index @products = Product.order(:name) @@ -108,12 +108,12 @@ def product_params def find_product @product = Product.find_by(id: params[:id]) + if !@product + @product = Product.find_by(id: params[:product_id]) + end if @product.nil? render :notfound, status: :not_found end - # if !@product - # @product = Product.find_by(id: params[:product_id]) - # end end From 26d5bf915dcc47d7789bd99301150121638708a1 Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 17:13:09 -0700 Subject: [PATCH 048/215] Fixed flash problems --- app/controllers/products_controller.rb | 21 ++++++++++++--------- app/controllers/sessions_controller.rb | 6 +++--- app/views/layouts/application.html.erb | 12 ++++++------ app/views/products/cart.html.erb | 2 +- app/views/products/show.html.erb | 2 +- config/routes.rb | 4 ++-- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index c036c2bf9c..8173f829e4 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,3 +1,4 @@ +require 'pry' class ProductsController < ApplicationController before_action :find_product @@ -14,9 +15,10 @@ def create category = Category.find_by(name: product_params[:category_id]) @product.category_id = category.id if @product.save + flash[:success] = "New creature added!" redirect_to product_path(@product.id) else - flash[:failure] = "failed to save" + flash[:danger] = "Failed to save creature." render :new, :status => :bad_request end end @@ -31,6 +33,7 @@ def update category = Category.find_by(name: product_params[:category_id]) @product.category_id = category.id if @product.save + flash[:success] = "Successfully updated creatures." redirect_to product_path(@product) else render :edit, :status => :bad_request @@ -41,24 +44,25 @@ def add_to_cart id = @product.id.to_i quantity = params[:quantity].to_i # session[:cart] = nil + item = false session[:cart].each.with_index do |hash, index| hash.each do |key, value| if key == id.to_s + item = true new_quantity = value + quantity if new_quantity <= @product.stock_count session[:cart][index][key] = value + quantity - redirect_to product_path(@product.id) - return + flash[:success] = "Added to cart" else - flash[:failure] = "Failure to add to cart. Not enough stock." - redirect_to product_path(@product.id) - return + flash[:warning] = "Failure to add to cart. Not enough stock." end end end end - session[:cart] << { id => quantity} - flash[:success] = "Added to cart" + if item == false + session[:cart] << { id => quantity} + flash[:success] = "Added to cart" + end redirect_to product_path(@product.id) end @@ -111,7 +115,6 @@ def find_product if !@product @product = Product.find_by(id: params[:product_id]) end - end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2fce9bb549..6fde2a7925 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,5 @@ class SessionsController < ApplicationController - + def create auth_hash = request.env['omniauth.auth'] @@ -7,11 +7,11 @@ def create User.create_from_github(auth_hash) if user - flash[:result_text] = "Logged in as returning user #{user.name}" + flash[:success] = "Logged in as returning user #{user.name}" session[:user_id] = user.id redirect_to root_path else - flash[:error] = "Could not create new user account: #{user.errors.messages}" + flash[:danger] = "Could not create new user account: #{user.errors.messages}" redirect_to root_path end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ed7e9f18df..4aa9eb0c57 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -49,13 +49,13 @@
    -
    -
    - <% flash.each do |name, message| %> -
    <%= message %>
    - <% end %> -
    +
    + <% flash.each do |name, message| %> +
    <%= message %>
    + <% end %> +
    +
    <%= yield %>
    diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index 92b7ef6fd6..c0437ac6b4 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -12,7 +12,7 @@
  • Quantity: <%= quantity%>
  • <% total += (quantity * product.price) %>
  • Total: $<%= quantity * product.price %>
  • - <%= form_with url: update_cart_path(product.id), method: :get do |f| %> + <%= form_with url: update_cart_path(product.id), method: :patch do |f| %> <% if product.stock_count > 1 %>
  • <%= f.select :quantity, options_for_select([*1..product.stock_count]) %> <% else %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 4bebf12f52..869fc8017d 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -8,7 +8,7 @@ <%= link_to "Review Creature", new_product_review_path(@product.id), class: "btn btn-primary" %> <% end %> -<%= form_with url: add_to_cart_path(@product.id), method: :get do |f| %> +<%= form_with url: add_to_cart_path(@product.id), method: :post do |f| %> <% if @product.stock_count > 1 %> <%= f.label :quantity, "Quantity"%>
    <%= f.select :quantity, options_for_select([*1..@product.stock_count]) %> diff --git a/config/routes.rb b/config/routes.rb index 9c05820702..bc1595c9b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,8 +11,8 @@ resources :reviews, only: [:new, :create] end - get "/products/:id/add_to_cart", to: "products#add_to_cart", as: "add_to_cart" - get "/products/:id/update_cart", to: "products#update_quantity", as: "update_cart" + post "/products/:id/add_to_cart", to: "products#add_to_cart", as: "add_to_cart" + patch "/products/:id/update_cart", to: "products#update_quantity", as: "update_cart" get "/products/:id/remove", to: "products#remove_from_cart", as: "remove_from_cart" resources :users, except: [:edit, :delete] From 2623ad0a87e96183b9610c0def82b427993efb43 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Sat, 20 Oct 2018 17:15:59 -0700 Subject: [PATCH 049/215] checkout creates order and orderproducts --- app/controllers/orders_controller.rb | 6 +++--- app/models/order.rb | 4 ++-- app/models/orderproduct.rb | 8 +++++--- app/views/products/cart.html.erb | 2 +- db/migrate/20181021000611_change_int_limit.rb | 5 +++++ db/schema.rb | 4 ++-- 6 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20181021000611_change_int_limit.rb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index d148775a4b..c976060f92 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -8,10 +8,10 @@ def create @order = Order.new @order.status = "pending" @order.save - create_product_orders(order_id) + Orderproduct.create_product_orders(@order.id, session[:cart]) @order.total_cost = @order.order_total - @order = Order.update(order_params) + @order.update(order_params) if @order.save flash[:success] = 'Your purchase is complete!' redirect_to root_path @@ -42,7 +42,7 @@ def find_order end def order_params - return params.require(:order).permit(:name, :email, :mailing_address, :zip_code, :cc_number, :cc_expiration, :cc_cvv) + return params.require(:order).permit(:name, :email, :mailing_address, :zip_code, :cc_number, :cc_expiration, :cc_cvv, :total_cost) end end diff --git a/app/models/order.rb b/app/models/order.rb index 01433ae223..2d51d71a5c 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -3,11 +3,11 @@ class Order < ApplicationRecord belongs_to :user, optional: true validates :name, :email, :mailing_address, :zip_code, :cc_number, - :cc_expiration, :cc_cvv, :status, :tota_cost, presence: true, on: :update + :cc_expiration, :cc_cvv, :status, :total_cost, presence: true, on: :update def order_total total_cost = 0 - @order.orderproducts.each do |orderproduct| + self.orderproducts.each do |orderproduct| total_cost += (orderproduct.product.price * orderproduct.quantity) end total_cost diff --git a/app/models/orderproduct.rb b/app/models/orderproduct.rb index b619226b36..b348093d0a 100644 --- a/app/models/orderproduct.rb +++ b/app/models/orderproduct.rb @@ -3,9 +3,11 @@ class Orderproduct < ApplicationRecord belongs_to :product - def create_product_orders(order_id, ) - session[:cart].each do |key, value| - OrderProducts.new(product_id: key, quantity: value, order_id: order_id) + def self.create_product_orders(order_id, session) + session.each do |item| + item.each do |key, value| + Orderproduct.create(product_id: key.to_i, quantity: value, order_id: order_id) + end end end diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index 92b7ef6fd6..cc45ea07f4 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -28,7 +28,7 @@ <% if total > 0 %>

    Cart Total: $<%= total %>

    -

    Checkout Cart

    +

    <%= link_to "Checkout Cart", new_order_path %>

    <% else %>
    diff --git a/db/migrate/20181021000611_change_int_limit.rb b/db/migrate/20181021000611_change_int_limit.rb new file mode 100644 index 0000000000..c55417492f --- /dev/null +++ b/db/migrate/20181021000611_change_int_limit.rb @@ -0,0 +1,5 @@ +class ChangeIntLimit < ActiveRecord::Migration[5.2] + def change + change_column :orders, :cc_number, :integer, limit: 8 + end +end diff --git a/db/schema.rb b/db/schema.rb index ec1ee2ecc7..054a792114 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_230310) do +ActiveRecord::Schema.define(version: 2018_10_21_000611) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -36,7 +36,7 @@ t.string "email" t.string "mailing_address" t.integer "zip_code" - t.integer "cc_number" + t.bigint "cc_number" t.integer "cc_expiration" t.integer "cc_cvv" t.string "status" From 9b81d2951e4f3653afc60916addf56d0b50cdd39 Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 17:30:13 -0700 Subject: [PATCH 050/215] Added skip_before_action for find_product method --- app/controllers/products_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 9e000ebc37..398e5a37a8 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,6 +1,6 @@ -require 'pry' class ProductsController < ApplicationController - before_action :find_product, only: [:show, :edit, :update, :add_to_cart] + before_action :find_product + skip_before_action :find_product, only: [:index, :cart_view] def index @products = Product.order(:name) From 4aacf44f1abf2779e7302ff4aa18f0201e7cd589 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Sat, 20 Oct 2018 17:30:36 -0700 Subject: [PATCH 051/215] edit creature feature in creature show page --- app/views/products/show.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index cb4e0e3cdf..797015ac0d 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -32,3 +32,9 @@
  • <% end %> + +<% if logged_in? %> + <% if current_user.id == @product.user.id %> + <%= link_to "Update Creature", edit_product_path(@product.id)%> + <% end %> +<% end %> From c6c24500850152d540852c75a4eda458c71f6cbd Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Sat, 20 Oct 2018 18:42:44 -0700 Subject: [PATCH 052/215] user models tests added for relationships and vaidations not for custom methods yet --- app/controllers/users_controller.rb | 2 +- app/models/user.rb | 3 ++ test/fixtures/reviews.yml | 2 -- test/fixtures/users.yml | 16 +++++---- test/models/user_test.rb | 51 +++++++++++++++++++++++++++-- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3bb2932f72..4876ee9511 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,7 +6,7 @@ def index end def show ;end - +# render_404 unless @user def print_products @user.products diff --git a/app/models/user.rb b/app/models/user.rb index ba4346abc3..4a60ecb211 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,9 @@ class User < ApplicationRecord has_many :products has_many :orders + validates :name, uniqueness: true, presence: true + validates :email, uniqueness: true, presence: true + def total_revenue sum = 0 self.products.each do |product| diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml index 52a11154f5..2f4037b832 100644 --- a/test/fixtures/reviews.yml +++ b/test/fixtures/reviews.yml @@ -4,12 +4,10 @@ one: name: MyString rating: 1 review: MyString - user_id: 1 product_id: 1 two: name: MyString rating: 1 review: MyString - user_id: 1 product_id: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 5dc4ddf033..ef11c7d57a 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,9 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - name: MyString - email: MyString +kit: + name: kit + email: kit@gmail.com + uid: 2378 + provider: github -two: - name: MyString - email: MyString +tan: + name: tan + email: tan@gmail.com + uid: 8769 + provider: github diff --git a/test/models/user_test.rb b/test/models/user_test.rb index cc862ac2d9..6df11bf628 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,9 +1,54 @@ require "test_helper" describe User do - let(:user) { User.new } + describe "relations" do + let(:kit) { users(:kit) } - it "must be valid" do - value(user).must_be :valid? + it "has a list of products" do + kit.must_respond_to :products + + kit.products.each do |product| + product.must_be_kind_of Product + end + end + + it "has a list of orders" do + kit.must_respond_to :orders + + kit.products.each do |order| + product.must_be_kind_of Order + end + end end + + describe "validations" do + it "requires a name and email" do + user = User.new + user.valid?.must_equal false + user.errors.messages.must_include :name, :email + end + + it "requires a unique user name and email" do + user1 = User.new(name: 'mat', email: 'mat@gmail.com', + uid: 1234, provider: 'github') + user1.save! + + user2 = User.new(name: 'mat', email: 'mat@gmail.com', + uid: 1234, provider: 'github') + result = user2.save + + result.must_equal false + user2.errors.messages.must_include :name, :email + end + end + + describe 'custom methods' do + describe 'total_revenue' do + end + describe 'build_from_github(auth_hash)' do + end + describe 'create_from_github(auth_hash)' do + end + end + end From c1e8eaa523be658782fe48e4b38abffc92d2db89 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Sat, 20 Oct 2018 19:49:33 -0700 Subject: [PATCH 053/215] user controller added and some sessions controller --- app/controllers/users_controller.rb | 5 +-- app/views/layouts/application.html.erb | 8 ++--- app/views/users/notfound.html.erb | 1 + config/routes.rb | 2 +- test/controllers/sessions_controller_test.rb | 28 +++++++++++++-- test/controllers/users_controller_test.rb | 36 ++++++++++++++++++++ test/models/user_test.rb | 4 +-- test/test_helper.rb | 24 ++++++++++++- 8 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 app/views/users/notfound.html.erb create mode 100644 test/controllers/users_controller_test.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4876ee9511..33dcbf999f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,8 +5,9 @@ def index @users = User.all end - def show ;end -# render_404 unless @user + def show + render :notfound, status: :not_found unless @user + end def print_products @user.products diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4aa9eb0c57..727f2ba6d1 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -20,8 +20,6 @@
    diff --git a/app/views/users/notfound.html.erb b/app/views/users/notfound.html.erb new file mode 100644 index 0000000000..c37ab2ebaa --- /dev/null +++ b/app/views/users/notfound.html.erb @@ -0,0 +1 @@ +

    Not Found 404

    diff --git a/config/routes.rb b/config/routes.rb index bc1595c9b8..fb4a6ee04f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ root "products#index" get "/products/cart", to: "products#cart_view", as: "cart" - get "/auth/:provider/callback", to: "sessions#create" + get "/auth/:provider/callback", to: "sessions#create", as: "login" delete 'sessions/destroy', to: 'sessions#destroy', as: 'logout' resources :orders diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index c2632a720b..e65d62e226 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -1,7 +1,29 @@ require "test_helper" describe SessionsController do - # it "must be a real test" do - # flunk "Need real tests" - # end + describe 'create' do + let(:kit) { users(:kit) } + + it "logs in an exiting user and redirects to the root route" do + expect {perform_login(kit)}.wont_change('User.count') + + must_redirect_to root_path + expect(session[:user_id]).must_equal kit.id + end + + # it "creates an account for a new user and redirects to the root route" do + # user = users(:kit) + # user.destroy + # + # expect{perform_login(user)}.must_change('User.count', +1) + # + # must_redirect_to root_path + # expect(session[:user_id]).wont_be_nil id + # end + + it "redirects to the login route if given invalid user data" do + + end + end + end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..3a7f402370 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,36 @@ +require 'test_helper' + +describe UsersController do + + describe "index" do + it "succeeds when there are users" do + get users_path + + must_respond_with :success + end + + it "succeeds when there are no users" do + users = User.all + users = nil + + get users_path + must_respond_with :success + end + end + + describe "show" do + it "succeeds for an existing user" do + id = users(:tan).id + + get user_path(id) + + must_respond_with :success + end + + it "renders 404 not_found for a bogus user ID" do + id = -1 + get user_path(id) + must_respond_with :not_found + end + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 6df11bf628..ca72f56880 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -2,7 +2,7 @@ describe User do describe "relations" do - let(:kit) { users(:kit) } + let(:kit) { users(:kit) } it "has a list of products" do kit.must_respond_to :products @@ -43,7 +43,7 @@ end describe 'custom methods' do - describe 'total_revenue' do + describe 'total_revenue' do end describe 'build_from_github(auth_hash)' do end diff --git a/test/test_helper.rb b/test/test_helper.rb index 59e480ec83..f0d21f83cc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,7 @@ ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" -require "minitest/rails" +require "minitest/rails" require "minitest/reporters" # for Colorized output # For colorful output! Minitest::Reporters.use!( @@ -22,4 +22,26 @@ 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 + OmniAuth.config.test_mode = true + end + + def perform_login(user) + OmniAuth.config.mock_auth[:github] = + OmniAuth::AuthHash.new(mock_auth_hash(user)) + + get login_path('github') + end + + def mock_auth_hash(user) + return { + provider: user.provider, + uid: user.uid, + info: { + email: user.email, + username: user.name + } + } + end + end From 23096a92e57bc8720f76c50b06b8e426f0154b35 Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 21:17:20 -0700 Subject: [PATCH 054/215] Changed remove_from_cart logic --- app/controllers/products_controller.rb | 2 +- app/views/products/cart.html.erb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 398e5a37a8..ff5f78945f 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -97,7 +97,7 @@ def remove_from_cart session[:cart].each.with_index do |hash, index| hash.each do |key, value| if key == id.to_s - session[:cart][index][key] = 0 + session[:cart].delete_at(index) flash[:success] = "Successfully removed from cart." redirect_to cart_path end diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index 871a4a5a78..be573435be 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -2,7 +2,6 @@ <% total = 0 %>
    <% @cart_items.each do |cart_array| %> - <% if cart_array[1] > 0 %> <% product = cart_array[0] %> <% quantity = cart_array[1] %>
      @@ -23,7 +22,6 @@
    • <%= link_to "Remove from Cart", remove_from_cart_path(product.id), class: "btn btn-primary"%>
    <% end %> - <% end %>
    <% if total > 0 %>
    From 2afeb09bc51478b0b2d33b204344280a00cf35c3 Mon Sep 17 00:00:00 2001 From: Jane Date: Sat, 20 Oct 2018 21:29:56 -0700 Subject: [PATCH 055/215] Added logic to prevent user from changing product quantity in cart to invalid amount --- app/controllers/products_controller.rb | 51 +++++++++++++++----------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index ff5f78945f..ae615a53af 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -44,24 +44,28 @@ def add_to_cart id = @product.id.to_i quantity = params[:quantity].to_i # session[:cart] = nil - item = false - session[:cart].each.with_index do |hash, index| - hash.each do |key, value| - if key == id.to_s - item = true - new_quantity = value + quantity - if new_quantity <= @product.stock_count - session[:cart][index][key] = value + quantity - flash[:success] = "Added to cart" - else - flash[:warning] = "Failure to add to cart. Not enough stock." + if [*1..@product.stock_count].include? (quantity) + item = false + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + item = true + new_quantity = value + quantity + if new_quantity <= @product.stock_count + session[:cart][index][key] = value + quantity + flash[:success] = "Added to cart" + else + flash[:warning] = "Failure to add to cart. Not enough stock." + end end end end - end - if item == false - session[:cart] << { id => quantity} - flash[:success] = "Added to cart" + if item == false + session[:cart] << { id => quantity} + flash[:success] = "Added to cart" + end + else + flash[:warning] = "Failure to add to cart. Invalid quantity." end redirect_to product_path(@product.id) end @@ -80,16 +84,19 @@ def cart_view def update_quantity id = @product.id.to_i quantity = params[:quantity].to_i - - session[:cart].each.with_index do |hash, index| - hash.each do |key, value| - if key == id.to_s - session[:cart][index][key] = quantity - flash[:success] = "Successfully updated cart." - redirect_to cart_path + if [*1..@product.stock_count].include? (quantity) + session[:cart].each.with_index do |hash, index| + hash.each do |key, value| + if key == id.to_s + session[:cart][index][key] = quantity + flash[:success] = "Successfully updated cart." + end end end + else + flash[:warning] = "Failure to add to cart. Invalid quantity." end + redirect_to cart_path end def remove_from_cart From 052f6a70c3dd103dbf164d3bcfc16f797f145333 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Sun, 21 Oct 2018 12:39:59 -0700 Subject: [PATCH 056/215] add method that reduces stock count when order completes and clears cart session --- app/controllers/orders_controller.rb | 3 +++ app/models/order.rb | 6 ++++++ app/models/product.rb | 8 ++++++++ app/views/products/cart.html.erb | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index c976060f92..b0edfe915e 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -13,7 +13,10 @@ def create @order.update(order_params) if @order.save + @order.reduce_stock + @order.status = "paid" flash[:success] = 'Your purchase is complete!' + session[:cart] = nil redirect_to root_path else flash.now[:danger] = 'Unable to complete order' diff --git a/app/models/order.rb b/app/models/order.rb index 2d51d71a5c..721b394ce9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -13,4 +13,10 @@ def order_total total_cost end + def reduce_stock + self.orderproducts.each do |item| + Product.adjust_stock_count(item.product_id, item.quantity) + end + end + end diff --git a/app/models/product.rb b/app/models/product.rb index 587bbb9d9d..5826f5257e 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -3,4 +3,12 @@ class Product < ApplicationRecord has_many :reviews has_many :orderproducts belongs_to :category + + def self.adjust_stock_count(product_id, count_sold) + product = Product.find(product_id) + reduced_stock = product.stock_count - count_sold + product.update(stock_count: reduced_stock) + product.save + end + end diff --git a/app/views/products/cart.html.erb b/app/views/products/cart.html.erb index be573435be..78c78b7059 100644 --- a/app/views/products/cart.html.erb +++ b/app/views/products/cart.html.erb @@ -26,7 +26,7 @@ <% if total > 0 %>

    Cart Total: $<%= total %>

    -

    <%= link_to "Checkout Cart", new_order_path %>

    +

    <%= link_to "Checkout Cart", new_order_path, class: "btn btn-primary"%>

    <% else %>
    From 568532d6186c95ff1f0026c9d9d4ce223beb32ef Mon Sep 17 00:00:00 2001 From: jfahmy Date: Sun, 21 Oct 2018 14:37:37 -0700 Subject: [PATCH 057/215] add model tests for Orders --- app/controllers/orders_controller.rb | 1 - app/models/order.rb | 3 +- ...1915_change_order_cardexpiration_column.rb | 5 + db/schema.rb | 4 +- test/fixtures/orderproducts.yml | 13 +-- test/fixtures/orders.yml | 40 ++++---- test/fixtures/products.yml | 28 +++++- test/models/order_test.rb | 92 ++++++++++++++++++- 8 files changed, 144 insertions(+), 42 deletions(-) create mode 100644 db/migrate/20181021201915_change_order_cardexpiration_column.rb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index b0edfe915e..0caeac77e8 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -7,7 +7,6 @@ def new def create @order = Order.new @order.status = "pending" - @order.save Orderproduct.create_product_orders(@order.id, session[:cart]) @order.total_cost = @order.order_total diff --git a/app/models/order.rb b/app/models/order.rb index 721b394ce9..3db5c4daeb 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,7 +1,6 @@ class Order < ApplicationRecord has_many :orderproducts - belongs_to :user, optional: true - + validates :orderproducts, :length => { :minimum => 1 } validates :name, :email, :mailing_address, :zip_code, :cc_number, :cc_expiration, :cc_cvv, :status, :total_cost, presence: true, on: :update diff --git a/db/migrate/20181021201915_change_order_cardexpiration_column.rb b/db/migrate/20181021201915_change_order_cardexpiration_column.rb new file mode 100644 index 0000000000..2bcf544e2f --- /dev/null +++ b/db/migrate/20181021201915_change_order_cardexpiration_column.rb @@ -0,0 +1,5 @@ +class ChangeOrderCardexpirationColumn < ActiveRecord::Migration[5.2] + def change + change_column :orders, :cc_expiration, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 054a792114..d7a001e3ca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_21_000611) do +ActiveRecord::Schema.define(version: 2018_10_21_201915) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -37,7 +37,7 @@ t.string "mailing_address" t.integer "zip_code" t.bigint "cc_number" - t.integer "cc_expiration" + t.string "cc_expiration" t.integer "cc_cvv" t.string "status" t.integer "total_cost" diff --git a/test/fixtures/orderproducts.yml b/test/fixtures/orderproducts.yml index 7475c73ddd..8854d395c9 100644 --- a/test/fixtures/orderproducts.yml +++ b/test/fixtures/orderproducts.yml @@ -1,11 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - order: one - product: one - quantity: 1 - -two: - order: two - product: two - quantity: 1 +orderproduct1: + order: complete_order + product: product1 + quantity: 3 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index bfcd8b54f5..dad7cad40c 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -1,23 +1,23 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - name: MyString - email: MyString - mailing_address: MyString - zip_code: 1 - cc_number: 1 - cc_expiration: 1 - cc_cvv: 1 - status: MyString - total_cost: 1 +complete_order: + name: Monique Marie + email: testemail@gmail.com + mailing_address: 4150 Delridge Way SW + zip_code: 44903 + cc_number: 8275928304958372 + cc_expiration: 04/21 + cc_cvv: 843 + status: paid + total_cost: 8000 -two: - name: MyString - email: MyString - mailing_address: MyString - zip_code: 1 - cc_number: 1 - cc_expiration: 1 - cc_cvv: 1 - status: MyString - total_cost: 1 +pending_order: + name: nil + email: nil + mailing_address: nil + zip_code: nil + cc_number: nil + cc_expiration: nil + cc_cvv: nil + status: pending + total_cost: nil diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index dc3ee79b5d..fa785120cc 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -4,8 +4,26 @@ # 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 +product1: + name: nil + stock_count: nil + description: nil + price: 100 + user: tan + category: nil + photo_url: nil + + + # + # t.bigint "user_id" + # t.datetime "created_at", null: false + # t.datetime "updated_at", null: false + # t.integer "stock_count" + # t.integer "price" + # t.string "category" + # t.string "photo_url" + # t.string "description" + # t.string "name" + # t.integer "category_id" + # t.index ["category_id"], name: "index_products_on_category_id" + # t.index ["user_id"], name: "index_products_on_user_id" diff --git a/test/models/order_test.rb b/test/models/order_test.rb index df80f10fb6..b92e50dd5f 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,9 +1,95 @@ require "test_helper" describe Order do - let(:order) { Order.new } + describe "validations" do + let(:order) { Order.create(status: "pending") } - it "must be valid" do - value(order).must_be :valid? + it "must be invalid without customer info provided" do + order.valid?.must_equal false + end + + it "will not update order without all customer info" do + order2 = orders(:complete_order) + + order2.valid?.must_equal true + order2.update(name:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(name:"Monique Marie") + order2.valid?.must_equal true + + order2.update(email:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(email:"testemail@gmail.com") + order2.valid?.must_equal true + + order2.update(mailing_address:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(mailing_address:"4150 Delridge Way SW") + order2.valid?.must_equal true + + order2.update(zip_code:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(zip_code:44903) + order2.valid?.must_equal true + + order2.update(cc_number:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(cc_number:8275928304958372) + order2.valid?.must_equal true + + order2.update(cc_expiration:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(cc_expiration:"04/21") + order2.valid?.must_equal true + + order2.update(cc_cvv:nil) + order2.valid?.must_equal false + expect(order2.save).must_equal false + order2.update(cc_cvv:843) + order2.valid?.must_equal true + end + end + + describe "relations" do + let(:order) { + Order.new(name:"No OrderProducts McGee", email:"testemail@gmail.com", + mailing_address:"4150 Delridge Way SW", zip_code:44903, + cc_number: 8275928304958372, cc_expiration: "04/21", cc_cvv: 843, + status: "paid", total_cost: 8000) + } + + it "must have one or many orderproducts" do + #no orderproducts attached + expect(order.save).must_equal false + + #adding orderproduct to order + orderproduct1 = orderproducts(:orderproduct1) + order.orderproducts << orderproduct1 + expect(order.save).must_equal true + expect(order.orderproducts.length).must_be :>, 0 + end + end + + describe "order model methods" do + describe "Order#order_total" do + it "will tally the cost of products for a given order" do + order = orders(:complete_order) + + expect(order.order_total).must_equal 300 + + end + end + + describe "Order#reduce_stock" do + it "will reduce product stock related to a given order" do + + end + end end end From af16b7759062d35e213910bc67616a790440875e Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 16:02:06 -0700 Subject: [PATCH 058/215] Added more creature seeds --- db/creature_seeds.csv | 30 ++++++++++++++++++++++++++---- db/seeds.rb | 7 ++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/db/creature_seeds.csv b/db/creature_seeds.csv index aeb42cdc73..2c2fbe9d23 100644 --- a/db/creature_seeds.csv +++ b/db/creature_seeds.csv @@ -1,4 +1,26 @@ -name,stock_count,description,price,photo_url -Frog,4,Your favorite cuddley non-posionous amphibian.,2000,https://i.imgur.com/JvI9dY9.jpg -Puppy,2,A baby dalmatian!,1500,https://i.imgur.com/gdxm25d.jpg -Hippo,1,Cute and dangerous!,100000,https://i.imgur.com/YDCtFMB.jpg +name,stock_count,description,price,category_id,photo_url +Frog,4,Your favorite cuddley non-posionous amphibian,2000,2,https://i.imgur.com/JvI9dY9.jpg +Puppy,2,A baby dalmatian!,1500,1,https://i.imgur.com/gdxm25d.jpg +Hippo,1,Cute and dangerous!,100000,2,https://i.imgur.com/YDCtFMB.jpg +Sloth,2,Adorable!,20000,1,https://i.imgur.com/Ht1hezp.jpg +Pomeranian,3,Fluffy like a huge cloud!,2000,1,https://i.imgur.com/Om3wQCW.jpg +Python,2,Baby ball python with pretty reticulated pattern,200,3,https://i.imgur.com/IbbN3gc.jpg +Elephant,1,Cute and friendly baby elephant,3000,1,https://i.imgur.com/DZ2o9Um.jpg +Labrador,2,Playful and adorable - your new best friend,200,1,https://i.imgur.com/YXg8LXR.jpg +Piglet,5,Lovely pink and friendly,100,1,https://i.imgur.com/MpKih6T.jpg +Parrot,2,Gorgeous colors - talk like human beings,4000,4,https://i.imgur.com/YDknvAm.jpg +Meerkat,2,Fun to watch - shrewd little animals,3000,1,https://i.imgur.com/Kc3P7k3.jpg +Lamb,3,Soft and gentle,200,1,https://i.imgur.com/gA9xPLp.jpg +Leopard,2,15 day old leopard cubs,5000,1,https://i.imgur.com/9POrqMS.jpg +Gibbon,1,Smart as a whistle,2000,1,https://i.imgur.com/0tVvi5N.jpg +Fox,2,Cubs-playful and fun to watch,2500,1,https://i.imgur.com/QBF7Gm4.jpg +Giraffe,1,New born baby giraffe,4000,1,https://i.imgur.com/4WkiWsX.jpg +Fawn,2,Timid little baby fawn,1000,1,https://i.imgur.com/5NVi4vr.jpg +Turtle,2,Tine little freshwater turtle,500,5,https://i.imgur.com/I2ICTfg.jpg +Red-panda,2,Beautiful red fur and bushy tail,3000,1,https://i.imgur.com/abDkafw.jpg +Owl,2,Clever little baby owl,2000,4,https://i.imgur.com/v1oRd62.jpg +Orangutan,1,Fun to watch antics - very sociable,4000,1,https://i.imgur.com/d66wSjt.jpg +Squirrel,2,Baby squirrel will eat nuts out of your hand,400,1,https://i.imgur.com/La3e2BD.jpg +Duckling,3,Lovely bright sunshine yellow,100,4,https://i.imgur.com/fyZBhtU.jpg +Dormouse,1,Inquisitive baby dormouse,200,1,https://i.imgur.com/NyKcY9y.jpg +Hedgehog,1,Cute little baby hedgehog,300,1,https://i.imgur.com/MNSTA7a.jpg diff --git a/db/seeds.rb b/db/seeds.rb index c6dadc5e59..2fc57a3e49 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -48,12 +48,13 @@ creature.description = row['description'] creature.price = row['price'] creature.photo_url = row['photo_url'] + creature.category_id = row['category_id'] ids = User.pluck(:id) random_record = User.find(ids.sample) creature.user_id = random_record.id - ids = Category.pluck(:id) - random_record = Category.find(ids.sample) - creature.category_id = random_record.id + # ids = Category.pluck(:id) + # random_record = Category.find(ids.sample) + # creature.category_id = random_record.id successful = creature.save if !successful creature_failures << creature From e861d0e7a631389a47f8796d95fb6ded114eb96f Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 16:46:45 -0700 Subject: [PATCH 059/215] Added new animals to seed data and linked them to categories --- db/creature_seeds.csv | 2 +- db/seeds.rb | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/db/creature_seeds.csv b/db/creature_seeds.csv index 2c2fbe9d23..6e9c1dbd5c 100644 --- a/db/creature_seeds.csv +++ b/db/creature_seeds.csv @@ -9,7 +9,7 @@ Elephant,1,Cute and friendly baby elephant,3000,1,https://i.imgur.com/DZ2o9Um.jp Labrador,2,Playful and adorable - your new best friend,200,1,https://i.imgur.com/YXg8LXR.jpg Piglet,5,Lovely pink and friendly,100,1,https://i.imgur.com/MpKih6T.jpg Parrot,2,Gorgeous colors - talk like human beings,4000,4,https://i.imgur.com/YDknvAm.jpg -Meerkat,2,Fun to watch - shrewd little animals,3000,1,https://i.imgur.com/Kc3P7k3.jpg +Meerkat,2,Fun to watch and lively - shrewd little animals,3000,1,https://i.imgur.com/Kc3P7k3.jpg Lamb,3,Soft and gentle,200,1,https://i.imgur.com/gA9xPLp.jpg Leopard,2,15 day old leopard cubs,5000,1,https://i.imgur.com/9POrqMS.jpg Gibbon,1,Smart as a whistle,2000,1,https://i.imgur.com/0tVvi5N.jpg diff --git a/db/seeds.rb b/db/seeds.rb index 2fc57a3e49..579c6aeb32 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -52,9 +52,6 @@ ids = User.pluck(:id) random_record = User.find(ids.sample) creature.user_id = random_record.id - # ids = Category.pluck(:id) - # random_record = Category.find(ids.sample) - # creature.category_id = random_record.id successful = creature.save if !successful creature_failures << creature From bf3553fef7afee7d1ea3fc92a7247cbd39c4d5bc Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 18:19:16 -0700 Subject: [PATCH 060/215] Some tests for products --- test/models/product_test.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/models/product_test.rb b/test/models/product_test.rb index a618b0a156..bc598103b9 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,9 +1,23 @@ require "test_helper" describe Product do - let(:product) { Product.new } - it "must be valid" do - value(product).must_be :valid? - end + it "has a list of categories" do + @product.categories << categories(:sleepy) + @product.must_respond_to :categories + + @product.categories.each do |category| + category.must_be_kind_of Category + end + end + + it "has a list of reviews" do + @product.must_respond_to :reviews + + @product.reviews << reviews(:one) + @product.reviews.each do |review| + review.must_be_kind_of Review + end + + #review cant belong to two items end From 6d1fb73394cc8ceffd7cf5465dbd3e866e71d8d2 Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 18:20:07 -0700 Subject: [PATCH 061/215] Tests for model Product --- test/models/category_test.rb | 77 ++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/test/models/category_test.rb b/test/models/category_test.rb index 781320ad8e..2d98c11d7b 100644 --- a/test/models/category_test.rb +++ b/test/models/category_test.rb @@ -1,9 +1,80 @@ require "test_helper" describe Category do - let(:category) { Category.new } + describe "validations" do + before do + + category = Category.first + + @category = Category.new(name: "test name") + end + + it "can be created with all required fields" do + result = @category.valid? + result.must_equal true + + end + + it "is invalid without a name" do + @category.name = nil + + result = @category.valid? + + result.must_equal false + # @category.must_include :name + end + + it "is invalid with a duplicate name" do + dup_category = Category.first + @category.name = dup_category.name + + result = @category.valid? + + result.must_equal false + # @category.must_include :name + end + end + + describe "relations" do + before do + @category = Category.new(name: 'test name') + end + + + it "connects products and product_ids" do + # Arrange + product = Product.first + + # Act + @category.products << product + + # Assert + @category.product_ids.must_include product.id + + puts categories(:happy).id + end + end + + describe 'self.select_with_products' do + it "can return all categories that aren't empty" do + Category.destroy_all + category = Category.create(name: "Smile") + category.products << products(:toy) + + category2 = Category.create(name: "Sad") + + valid_cat_count = Category.select_with_products.count + + valid_cat_count.must_equal 1 + end + + # it "will exclude empty categories" do + # @category.products << products(:toy) + # + # valid_cat_count = Category.select_with_products.count + # + # valid_cat_count.must_equal 1 + # end - it "must be valid" do - value(category).must_be :valid? end end From e8ff9ab1295a66689869e8e5a17be5444c9f9fae Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 20:59:49 -0700 Subject: [PATCH 062/215] Categories controller updated --- app/controllers/categories_controller.rb | 53 +++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 5b255bea20..37c1631ce5 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,4 +1,53 @@ class CategoriesController < ApplicationController - def show - end +before_action :find_category, only: [:show, :destroy] +#before_action :require_login, except: [:index, :show] + + def index + @categories = Category.category_list + end + + def show; end + + def new + @category = Category.new + end + + def create + @products = Product.new + @category = Category.new(category_params) + + if @category.save + # redirect_to '/books' + flash[:success] = "Category created successfully" + redirect_to categories_path + else + # Validations failed! What do we do? + # This flash message is redundant but for demonstration purposes + flash.now[:failure] = "Validations Failed" + render :new, status: :bad_request + end + end + + def destroy + + if @category.products.count > 0 + flash.now[:failure] = "Category contains active products, deletion failed." + else + @category.destroy + flash[:success] = "Category deleted successfully" + end + + redirect_to categories_path + end + +private + def find_category + @category = Category.find_by(id: params[:id]) + + head :not_found unless @category + end + + def category_params + params.require(:category).permit(:name, product_ids: []) + end end From 4e022b8d57c33ef86fff1d39cb0d87d172b0aeb6 Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 21:00:31 -0700 Subject: [PATCH 063/215] Category index - add category button with functionality --- app/views/categories/index.html.erb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/views/categories/index.html.erb diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 0000000000..dc7a8c8296 --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,8 @@ +

    Here are the categories:

    +<% @categories = Category.all %> +<% @categories.each do |cat| %> +

    + +

    +<% end %> + From 7415543dc1adb17a75778a15b9b451fb9d79cbe8 Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 21:00:52 -0700 Subject: [PATCH 064/215] Form to add new category --- app/views/categories/new.html.erb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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..1a4f08f43f --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,17 @@ + + + <%= form_with model: @product do |f|%> + + + + <%= f.label :name %> + <%= f.text_field :name %> + + + + <%= f.submit "Add category", class: "btn btn-primary" %> + + <% end %> + +

    Hi You have to be signed in to add a Category

    + From fdaeee18be9baed45439c4cb1967a1087c5a5402 Mon Sep 17 00:00:00 2001 From: Divya Date: Sun, 21 Oct 2018 21:01:21 -0700 Subject: [PATCH 065/215] Show view modified --- app/views/categories/show.html.erb | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 app/views/categories/show.html.erb diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000000..08cfe62557 --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,46 @@ +

    Pets according to <%= @category.name %> category

    + +<% @category.products.each do |product| %> + +

    <%= product.name %>

    +<%= image_tag product.photo_url %> +

    Type: <%= product.category.name.capitalize %>

    +

    Description: <%= product.description %>

    +

    Price: <%= product.price %>

    + +<% if product.user != @current_user %> +<%= link_to "Review Creature", new_product_review_path(product.id), class: "btn btn-primary" %> +<% end %> + +<%= form_with url: add_to_cart_path(product.id), method: :post do |f| %> +<% if product.stock_count > 1 %> +<%= f.label :quantity, "Quantity"%>
    +<%= f.select :quantity, options_for_select([*1..product.stock_count]) %> +<% else %> +<%= f.select :quantity, options_for_select([product.stock_count]) %> +<% end %> +<%= f.submit "Add to Cart", class: "btn btn-primary"%> +<% end %> + +

    <% session[:cart] %> +
    +
    +

    Creature reviews:

    +<% product.reviews.each do |review| %> +
      +
    • +

      Reviewer: <%= review.name %>

      +

      Rating: <%= review.rating %>

      +

      Review: <%= review.review %>

      +
    • +
    +
    +
    +<% end %> + +<% if logged_in? %> + <% if current_user.id == product.user.id %> + <%= link_to "Update Creature", edit_product_path(product.id)%> + <% end %> +<% end %> +<% end %> From 3bf1986a1a061c70c0d83e26014fc08f54b2fe75 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Mon, 22 Oct 2018 08:39:07 -0700 Subject: [PATCH 066/215] start controller tests for order --- app/controllers/orders_controller.rb | 2 + app/views/categories/new.html.erb | 2 +- test/controllers/orders_controller_test.rb | 97 +++++++++++++++++++--- test/models/order_test.rb | 3 +- 4 files changed, 89 insertions(+), 15 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 0caeac77e8..c39242fbd4 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,4 +1,6 @@ class OrdersController < ApplicationController + before_action :find_order + def new @order = Order.new diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb index 1a4f08f43f..3f27f0c659 100644 --- a/app/views/categories/new.html.erb +++ b/app/views/categories/new.html.erb @@ -1,6 +1,6 @@ - <%= form_with model: @product do |f|%> + <%= form_with model: @category do |f|%> diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 43a040e5ef..07b39507b9 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -1,24 +1,97 @@ require "test_helper" describe OrdersController do - it "should get new" do - get orders_new_url - value(response).must_be :success? + + describe "new" do + it "succeeds" do + get new_order_path + + must_respond_with :success + end end - it "should get create" do - get orders_create_url - value(response).must_be :success? + describe "create" do + let (:order_hash) do + { + order: { + name: 'No OrderProducts McGee', + email: 'testemail@gmail.com', + mailing_address: '4150 Delridge Way SW', + zip_code: 44903, + cc_number: 8275928304958372, + cc_expiration: '04/21', + cc_cvv: 843, + status: 'completed', + total_cost: 8000 + } + } + end + + it "creates an order with paid status" do + + + # Cannot figure out how to create a fake session hash! + # session = {} + # session[:cart] = [{"3" => 2}, {"1" => 1}] + # + # post orders_path, params: order_hash + # + # must_respond_with :redirect + # expect(flash[:success]).must_equal 'Your purchase is complete!' + # expect(order.status).must_equal 'paid' + end end - it "should get edit" do - get orders_edit_url - value(response).must_be :success? + describe "new" do + it "succeeds" do + get new_order_path + + must_respond_with :success + end end - it "should get update" do - get orders_update_url - value(response).must_be :success? + describe "update" do + let (:order_params) do + { + order: { + name: 'No OrderProducts McGee', + email: 'testemail@gmail.com', + mailing_address: '4150 Delridge Way SW', + zip_code: 44903, + cc_number: 8275928304958372, + cc_expiration: '04/21', + cc_cvv: 843, + status: 'completed', + total_cost: 8000 + } + } + end + + it "succeeds in updating order status" do + complete_order = orders(:complete_order) + + expect { + patch order_path(complete_order.id), params: order_params + }.wont_change 'Order.count' + + must_respond_with :redirect + must_redirect_to order_path(complete_order.id) + + expect(complete_order.status).must_equal order_params[:order][:status] + end + + it "renders bad_request for updates if not given status param" do + id = orders(:complete_order).id + status = orders(:complete_order).status + + expect { + patch order_path(id), params: nil + }.wont_change 'Order.count' + + must_respond_with :bad_request + expect(completed_order.status).must_equal status + end + end end diff --git a/test/models/order_test.rb b/test/models/order_test.rb index b92e50dd5f..217c3600ab 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -80,9 +80,8 @@ describe "Order#order_total" do it "will tally the cost of products for a given order" do order = orders(:complete_order) - - expect(order.order_total).must_equal 300 + expect(order.order_total).must_equal 300 end end From aa52c55420046c7acfb740a68badf568c2fb7d28 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Mon, 22 Oct 2018 09:34:49 -0700 Subject: [PATCH 067/215] change to skip before action --- app/controllers/products_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index ae615a53af..2e0ee8395f 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,6 +1,6 @@ class ProductsController < ApplicationController before_action :find_product - skip_before_action :find_product, only: [:index, :cart_view] + skip_before_action :find_product, only: [:index, :cart_view, :new, :create] def index @products = Product.order(:name) From bdc37fa267bbae87c331f04b004f2946c0806e36 Mon Sep 17 00:00:00 2001 From: Divya Date: Mon, 22 Oct 2018 10:31:51 -0700 Subject: [PATCH 068/215] Added fulfillment page view and route, temporary --- app/controllers/orders_controller.rb | 3 +++ app/views/orders/fulfillment.html.erb | 1 + config/routes.rb | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 app/views/orders/fulfillment.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index c39242fbd4..029d98170c 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -6,6 +6,9 @@ def new @order = Order.new end + def fulfillment + end + def create @order = Order.new @order.status = "pending" diff --git a/app/views/orders/fulfillment.html.erb b/app/views/orders/fulfillment.html.erb new file mode 100644 index 0000000000..8142af56a4 --- /dev/null +++ b/app/views/orders/fulfillment.html.erb @@ -0,0 +1 @@ +

    <%= @current_user %> Fulfillment page

    diff --git a/config/routes.rb b/config/routes.rb index fb4a6ee04f..20bb39226e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,8 @@ resources :categories + get "/fulfillment", to: "orders#fulfillment", as: "get_orders" + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From c3f5e80f307ab872671af917bf5512639aa63786 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Mon, 22 Oct 2018 10:57:02 -0700 Subject: [PATCH 069/215] push bug fix for order --- app/controllers/orders_controller.rb | 5 +++++ app/models/order.rb | 2 +- app/models/orderproduct.rb | 1 + app/views/orders/fulfillment.html.erb | 6 +++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 029d98170c..b640798933 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,5 +1,6 @@ class OrdersController < ApplicationController before_action :find_order + skip_before_action :find_order, only: [:fulfillment, :new] def new @@ -7,14 +8,18 @@ def new end def fulfillment + # @orders = Order.orderproducts. end def create @order = Order.new @order.status = "pending" + @order.save + binding.pry Orderproduct.create_product_orders(@order.id, session[:cart]) @order.total_cost = @order.order_total + binding.pry @order.update(order_params) if @order.save @order.reduce_stock diff --git a/app/models/order.rb b/app/models/order.rb index 3db5c4daeb..bc7a91dfb3 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,6 +1,5 @@ class Order < ApplicationRecord has_many :orderproducts - validates :orderproducts, :length => { :minimum => 1 } validates :name, :email, :mailing_address, :zip_code, :cc_number, :cc_expiration, :cc_cvv, :status, :total_cost, presence: true, on: :update @@ -18,4 +17,5 @@ def reduce_stock end end + end diff --git a/app/models/orderproduct.rb b/app/models/orderproduct.rb index b348093d0a..47528e9ca0 100644 --- a/app/models/orderproduct.rb +++ b/app/models/orderproduct.rb @@ -6,6 +6,7 @@ class Orderproduct < ApplicationRecord def self.create_product_orders(order_id, session) session.each do |item| item.each do |key, value| + binding.pry Orderproduct.create(product_id: key.to_i, quantity: value, order_id: order_id) end end diff --git a/app/views/orders/fulfillment.html.erb b/app/views/orders/fulfillment.html.erb index 8142af56a4..ef87cebb2a 100644 --- a/app/views/orders/fulfillment.html.erb +++ b/app/views/orders/fulfillment.html.erb @@ -1 +1,5 @@ -

    <%= @current_user %> Fulfillment page

    +<% if @current_user == nil %> +

    You must sign in to view the fulfillment page.

    +<% else %> +

    <%= @current_user.name %>'s Fulfillment page

    +<% end %> From 92859ae8c21a88792b8d32943266371feb6fbb61 Mon Sep 17 00:00:00 2001 From: Jane Date: Mon, 22 Oct 2018 11:01:01 -0700 Subject: [PATCH 070/215] Updated css/html for products show page --- app/assets/stylesheets/application.scss | 16 +++++++++ app/controllers/products_controller.rb | 2 +- app/models/product.rb | 8 +++++ app/views/products/index.html.erb | 44 +++++++++++++++++-------- 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index be5035c54c..8498c25e17 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,12 +16,28 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; +@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"); .cart-img { width: 150px; height: 150px; } +.card-group-container { + display: flex; + justify-content: space-around; + flex-wrap: wrap; + padding: 3em; +} + +.card-container { + margin: 1em; +} + +.checked { + color: black; +} + .notfound { text-align: center; align-self: center; diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 2e0ee8395f..c0a391802f 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -67,7 +67,7 @@ def add_to_cart else flash[:warning] = "Failure to add to cart. Invalid quantity." end - redirect_to product_path(@product.id) + redirect_back(fallback_location: root_path) end def cart_view diff --git a/app/models/product.rb b/app/models/product.rb index 5826f5257e..f8e35acd25 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,4 +11,12 @@ def self.adjust_stock_count(product_id, count_sold) product.save end + def average_rating + sum = self.reviews.reduce(0) do |sum, review| + sum += review.rating + end + return sum / self.reviews.length if self.reviews.length > 0 + return sum + end + end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 316e7ba818..1b1047645b 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,20 +1,36 @@

    Shop by Product

    -
    - <% if @products %> +<% if @products %> +
    <% @products.each do |product| %> +
    + <%= image_tag product.photo_url, class: "card-img-top"%> +
    +
    <%= link_to product.name.capitalize, product_path(product.id) %>
    +

    <%= product.user.name %>

    + <% if product.reviews.length > 0 %> +

    + <% product.average_rating.times do %> + + <% end %> + (<%= product.reviews.length %>) +

    + <% end %> +

    $<%= product.price %>

    +

    <%= form_with url: add_to_cart_path(product.id), method: :post do |f| %> + <% if product.stock_count > 1 %> + <%= f.label :quantity, "Quantity"%>
    + <%= f.select :quantity, options_for_select([*1..product.stock_count]) %> + <% else %> + <%= f.select :quantity, options_for_select([product.stock_count]) %> + <% end %> + <%= f.submit "Add to Cart", class: "btn btn-primary"%> + <% end %> +

    +
    +
    -

    <%= image_tag product.photo_url %>

    -
      - -
    • <%= link_to product.name, product_path(product.id) %>
    • -
    • <%= product.price %>
    • -
    • <%= product.stock_count %>
    • -
    • <%= product.category.name %>
    • -
    • <%= product.description %>
    • -
    - - <% end %> <% end %> -
    + +<% end %> From 608c9b8bd9f187304c3e95fcf93498b143ee83ff Mon Sep 17 00:00:00 2001 From: jfahmy Date: Mon, 22 Oct 2018 11:16:43 -0700 Subject: [PATCH 071/215] fix order create bug so that status can be turned to paid --- app/controllers/orders_controller.rb | 3 +-- app/models/orderproduct.rb | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index b640798933..cc6109192c 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -15,15 +15,14 @@ def create @order = Order.new @order.status = "pending" @order.save - binding.pry Orderproduct.create_product_orders(@order.id, session[:cart]) @order.total_cost = @order.order_total - binding.pry @order.update(order_params) if @order.save @order.reduce_stock @order.status = "paid" + @order.save flash[:success] = 'Your purchase is complete!' session[:cart] = nil redirect_to root_path diff --git a/app/models/orderproduct.rb b/app/models/orderproduct.rb index 47528e9ca0..b348093d0a 100644 --- a/app/models/orderproduct.rb +++ b/app/models/orderproduct.rb @@ -6,7 +6,6 @@ class Orderproduct < ApplicationRecord def self.create_product_orders(order_id, session) session.each do |item| item.each do |key, value| - binding.pry Orderproduct.create(product_id: key.to_i, quantity: value, order_id: order_id) end end From b8ae4678508141f47c0c05d30270a02099d551f4 Mon Sep 17 00:00:00 2001 From: Divya Date: Mon, 22 Oct 2018 12:53:36 -0700 Subject: [PATCH 072/215] Added seed data for orders --- .../20181022180437_remove_category_column.rb | 5 ++++ db/order_seeds.csv | 5 ++++ db/schema.rb | 3 +-- db/seeds.rb | 27 ++++++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181022180437_remove_category_column.rb create mode 100644 db/order_seeds.csv diff --git a/db/migrate/20181022180437_remove_category_column.rb b/db/migrate/20181022180437_remove_category_column.rb new file mode 100644 index 0000000000..46b4318218 --- /dev/null +++ b/db/migrate/20181022180437_remove_category_column.rb @@ -0,0 +1,5 @@ +class RemoveCategoryColumn < ActiveRecord::Migration[5.2] + def change + remove_column :products, :category + end +end diff --git a/db/order_seeds.csv b/db/order_seeds.csv new file mode 100644 index 0000000000..8458682fcc --- /dev/null +++ b/db/order_seeds.csv @@ -0,0 +1,5 @@ +name,email,mailing_address,zip_code,cc_number,cc_expiration,cc_cvv,status,total_cost +Pam,pam89@yahoo.com,No:81 Queen Drive NY,14211,6554323,10/26/2019,322,"pending",3500 +Susan,susan_smith@yahoo.com,18422 Birch Drive WA,19822,2468261,11/20/2020,455,"paid",40000 +Timothy,t_green@hotmail.com,34 5th Avenue VA,98022,34726454,09/23/2021,233,"complete",2800 +David,david_duchovny@hotmail.com,Post Office OR,97033,467542365,10/18/2021,111,"cancelled",30000 diff --git a/db/schema.rb b/db/schema.rb index d7a001e3ca..bce09d7267 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_21_201915) do +ActiveRecord::Schema.define(version: 2018_10_22_180437) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -51,7 +51,6 @@ t.datetime "updated_at", null: false t.integer "stock_count" t.integer "price" - t.string "category" t.string "photo_url" t.string "description" t.string "name" diff --git a/db/seeds.rb b/db/seeds.rb index 579c6aeb32..7181b95a29 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -37,6 +37,28 @@ end end +ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') +order_failures = [] +CSV.foreach(ORDER_FILE, :headers => true) do |row| + order = Order.new + order.name = row['name'] + order.email = row['email'] + order.mailing_address = row['mailing_address'] + order.zip_code = row['zip_code'] + order.cc_number = row['cc_number'] + order.cc_expiration = row['cc_expiration'] + order.cc_cvv = row['cc_cvv'] + order.status = row['status'] + order.total_cost = row['total_cost'] + successful = order.save + if !successful + order_failures << order + puts order_failures + puts order.errors.messages + else + puts "Order created: #{order.inspect}" + end +end CREATURE_FILE = Rails.root.join('db', 'creature_seeds.csv') @@ -52,10 +74,13 @@ ids = User.pluck(:id) random_record = User.find(ids.sample) creature.user_id = random_record.id + # ids = Category.pluck(:id) + # random_record = Category.find(ids.sample) + # creature.category_id = random_record.id successful = creature.save if !successful creature_failures << creature else - puts "Creature created: #{creature.inspect}" + #puts "Creature created: #{creature.inspect}" end end From 128c0dfea8ff98e0e69c523b5d2a0008d710f662 Mon Sep 17 00:00:00 2001 From: jfahmy Date: Mon, 22 Oct 2018 13:00:38 -0700 Subject: [PATCH 073/215] fulfillment method added to order controller, displays info to view --- app/controllers/orders_controller.rb | 3 ++- app/models/application_record.rb | 1 + app/models/order.rb | 27 +++++++++++++++++++++++++++ app/views/orders/fulfillment.html.erb | 24 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index cc6109192c..ca2e4f8b4d 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -8,7 +8,8 @@ def new end def fulfillment - # @orders = Order.orderproducts. + @orders = Order.find_orders(@current_user) + @total_revenue = Order.products_sold_total(@current_user) end def create diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba84d..0e0f662d41 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,4 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + end diff --git a/app/models/order.rb b/app/models/order.rb index bc7a91dfb3..a360b76b43 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -17,5 +17,32 @@ def reduce_stock end end + def self.find_orders(user) + orders = [] + Order.all.each do |order| + order.orderproducts.each do |item| + product = item.product + if user.id == product.user_id + orders << order + end + end + end + orders + end + + def self.products_sold_total(user) + total_revenue = 0 + Order.all.each do |order| + order.orderproducts.each do |item| + product = item.product + if user.id == product.user_id + per_unit_cost = item.product.price + total_revenue += item.quantity * per_unit_cost + end + end + end + total_revenue + end + end diff --git a/app/views/orders/fulfillment.html.erb b/app/views/orders/fulfillment.html.erb index ef87cebb2a..6f9ce0b818 100644 --- a/app/views/orders/fulfillment.html.erb +++ b/app/views/orders/fulfillment.html.erb @@ -2,4 +2,28 @@

    You must sign in to view the fulfillment page.

    <% else %>

    <%= @current_user.name %>'s Fulfillment page

    +

    Total Revenue: <%= @total_revenue %>

    +

    All orders

    +
      + <% @orders.each do |order| %> + <% order.orderproducts.each do |orderproduct| %> +
    • +

      Item sold: <%= orderproduct.product.name %>

      +
        +
      • Cost per creature: <%= orderproduct.product.price %>
      • +
      +
      +
    • +
    • +

      Order number: <%= order.id %>

      +
    • +
    • +

      Seller: <%= orderproduct.product.user_id %> +

    • +
    • +

      Quantity in order <%= orderproduct.quantity %>

      +
    • + <% end %> + <% end %> +
    <% end %> From 78835e14fc33f44fb3df5fd483e2850bf360bb71 Mon Sep 17 00:00:00 2001 From: Divya Date: Mon, 22 Oct 2018 13:57:05 -0700 Subject: [PATCH 074/215] Syntax errors fixed --- app/controllers/categories_controller.rb | 6 ++++++ app/views/categories/index.html.erb | 3 +++ app/views/products/products_of_category | 1 + 3 files changed, 10 insertions(+) create mode 100644 app/views/products/products_of_category diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 37c1631ce5..7715d68b20 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,6 +1,10 @@ class CategoriesController < ApplicationController before_action :find_category, only: [:show, :destroy] +<<<<<<< Updated upstream #before_action :require_login, except: [:index, :show] +======= +before_action :require_login, except: [:index, :show] +>>>>>>> Stashed changes def index @categories = Category.category_list @@ -9,7 +13,9 @@ def index def show; end def new + @category = Category.new + end def create diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index dc7a8c8296..bf73a1e663 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -5,4 +5,7 @@ <% end %> +<<<<<<< Updated upstream +======= +>>>>>>> Stashed changes diff --git a/app/views/products/products_of_category b/app/views/products/products_of_category new file mode 100644 index 0000000000..8c344b5da6 --- /dev/null +++ b/app/views/products/products_of_category @@ -0,0 +1 @@ +

    Products of a category here

    From f4387be5df4597a744e724e44a8f7e0d0638cf46 Mon Sep 17 00:00:00 2001 From: Maryam Shitu Date: Mon, 22 Oct 2018 14:11:00 -0700 Subject: [PATCH 075/215] nav styling --- .../images/shopping-bag-icon-png-17.jpg | Bin 0 -> 15902 bytes app/assets/images/shopping-bag.png | Bin 0 -> 8303 bytes app/assets/stylesheets/application.scss | 44 ++++++++++ app/controllers/application_controller.rb | 9 ++ app/controllers/categories_controller.rb | 2 +- app/views/layouts/application.html.erb | 78 ++++++++---------- 6 files changed, 87 insertions(+), 46 deletions(-) create mode 100644 app/assets/images/shopping-bag-icon-png-17.jpg create mode 100644 app/assets/images/shopping-bag.png diff --git a/app/assets/images/shopping-bag-icon-png-17.jpg b/app/assets/images/shopping-bag-icon-png-17.jpg new file mode 100644 index 0000000000000000000000000000000000000000..70b21fea415033e8b53e8e9172e8077ea249d496 GIT binary patch literal 15902 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 literal 0 HcmV?d00001 diff --git a/app/assets/images/shopping-bag.png b/app/assets/images/shopping-bag.png new file mode 100644 index 0000000000000000000000000000000000000000..b96b3989373d7e4f07279f58b0e7bf4fd98a0e32 GIT binary patch literal 8303 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 DCB_qQ literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index be5035c54c..95ef9cee9d 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -17,6 +17,50 @@ /* Import scss content */ @import "**/*"; +.header { + display: block; + margin: 0px; + padding: 0px; + // padding-left: 45px; + // padding-right: 45px; +} + +.header_container .container { + max-width: 100%; +} + +.top-nav { + position: relative; + display: -webkit-box; + display: -webkit-flex; + display: -moz-box; + display: -ms-flexbox; + display: flex; + justify-content: center; + align-items: center; +} + +.icon img { + height: 27px; + position: relative; +} + +.logo { + display: block; + position: relative; + box-sizing: border-box; +} + +li { + list-style: none; +} + + +ul { + list-style: none; + margin-bottom: 0px; +} + .cart-img { width: 150px; height: 150px; diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1fc5c45eb1..78f452aa9b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,8 @@ class ApplicationController < ActionController::Base before_action :current_user before_action :find_user before_action :build_cart + before_action :all_users + before_action :all_categories helper_method :logged_in? helper_method :current_user @@ -23,4 +25,11 @@ def find_user @user = User.find_by(id: params[:id]) end + def all_users + @users = User.all + end + + def all_categories + @categories = Category.all + end end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 5b255bea20..6118395c11 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,4 +1,4 @@ class CategoriesController < ApplicationController def show - end + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 727f2ba6d1..4acf05d091 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,63 +1,51 @@ - - Betsy - <%= csrf_meta_tags %> - <%= csp_meta_tag %> + + 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' %> - + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +
    -
    -
    -
    - <% flash.each do |name, message| %> -
    <%= message %>
    - <% end %> -
    +
    + +
    + +
    + <% flash.each do |name, message| %> +
    <%= message %>
    + <% end %> +
    -
    - <%= yield %> -
    +
    + <%= yield %> +
    -
    -
    © 2018 Adoptsy
    -
    +
    +
    © 2018 Adoptsy
    +
    From 5284610ea15a78514c7c2187e64a2386d6e96a2c Mon Sep 17 00:00:00 2001 From: jfahmy Date: Mon, 22 Oct 2018 14:33:24 -0700 Subject: [PATCH 076/215] fulfillment view added --- app/controllers/orders_controller.rb | 10 +++++++++- app/views/orders/completed.html.erb | 0 app/views/orders/fulfillment.html.erb | 3 ++- app/views/orders/paid.html.erb | 0 config/routes.rb | 2 ++ 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 app/views/orders/completed.html.erb create mode 100644 app/views/orders/paid.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index ca2e4f8b4d..b429f851af 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,6 +1,6 @@ class OrdersController < ApplicationController before_action :find_order - skip_before_action :find_order, only: [:fulfillment, :new] + skip_before_action :find_order, only: [:fulfillment, :paid, :completed, :new] def new @@ -12,6 +12,14 @@ def fulfillment @total_revenue = Order.products_sold_total(@current_user) end + def paid + @orders = Order.find_orders(@current_user).select { |order| order.status == "paid"} + end + + def completed + @orders = Order.find_orders(@current_user).select { |order| order.status == "completed"} + end + def create @order = Order.new @order.status = "pending" diff --git a/app/views/orders/completed.html.erb b/app/views/orders/completed.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/orders/fulfillment.html.erb b/app/views/orders/fulfillment.html.erb index 6f9ce0b818..edf875c2bb 100644 --- a/app/views/orders/fulfillment.html.erb +++ b/app/views/orders/fulfillment.html.erb @@ -2,8 +2,9 @@

    You must sign in to view the fulfillment page.

    <% else %>

    <%= @current_user.name %>'s Fulfillment page

    +

    Order count: <%= @orders.count %>

    Total Revenue: <%= @total_revenue %>

    -

    All orders

    +