diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..914ca6c5c4 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..e1cd8d6140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# 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 +.idea +.env +/coverage +.DS_Store 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..49c9525a55 --- /dev/null +++ b/Gemfile @@ -0,0 +1,100 @@ +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 +# +gem "omniauth" +gem "omniauth-github" + + + + + +# 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] + + gem 'faker' + gem 'dotenv-rails' +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' + + # Bakesy installed test gems + gem 'factory_bot_rails' + gem 'factory_bot' + + gem 'simplecov' + +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..a49979382d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,323 @@ +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) + docile (1.3.1) + dotenv (2.5.0) + dotenv-rails (2.5.0) + dotenv (= 2.5.0) + railties (>= 3.2, < 6.0) + erubi (1.7.1) + execjs (2.7.0) + factory_bot (4.11.1) + activesupport (>= 3.0.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) + railties (>= 3.0.0) + faker (1.9.1) + i18n (>= 0.7) + faraday (0.15.3) + multipart-post (>= 1.2, < 3) + 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) + hashie (3.5.7) + 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 + json (2.1.0) + jwt (2.1.0) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + 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) + multi_xml (0.6.0) + multipart-post (2.0.0) + 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) + 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) + 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) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + 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 + dotenv-rails + factory_bot + factory_bot_rails + faker + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + omniauth + omniauth-github + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.1) + sass-rails (~> 5.0) + selenium-webdriver + simplecov + 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.6 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000000..e34f706f4a --- /dev/null +++ b/Guardfile @@ -0,0 +1,9 @@ +guard :minitest, autorun: false, spring: true do + watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/.+_test.rb$}) + watch(%r{^test/test_helper.rb$}) { 'test' } +end diff --git a/README.md b/README.md index 9f398a6bde..c72506ff7d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a [Stage 3](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md) project requiring you to expand upon what you have learned in class. -Due date: EOD Friday October 26 +**Final Project**:https://bakesy.herokuapp.com ## Project Learning Goals - Core comprehension of: 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/images/41250510-rough-wooden-used-cutting-board-background-with-vertical-lines-and-cutting-traces.jpg b/app/assets/images/41250510-rough-wooden-used-cutting-board-background-with-vertical-lines-and-cutting-traces.jpg new file mode 100644 index 0000000000..cb8e7c5110 Binary files /dev/null and b/app/assets/images/41250510-rough-wooden-used-cutting-board-background-with-vertical-lines-and-cutting-traces.jpg differ diff --git a/app/assets/images/github-square-brands.svg b/app/assets/images/github-square-brands.svg new file mode 100644 index 0000000000..6f560917f5 --- /dev/null +++ b/app/assets/images/github-square-brands.svg @@ -0,0 +1 @@ + diff --git a/app/assets/images/making-bakery-in-the-kitchen_1101-153.jpg b/app/assets/images/making-bakery-in-the-kitchen_1101-153.jpg new file mode 100644 index 0000000000..b00ee2d305 Binary files /dev/null and b/app/assets/images/making-bakery-in-the-kitchen_1101-153.jpg differ diff --git a/app/assets/images/pexels-photo-239581.jpeg b/app/assets/images/pexels-photo-239581.jpeg new file mode 100644 index 0000000000..23509f7ca5 Binary files /dev/null and b/app/assets/images/pexels-photo-239581.jpeg differ diff --git a/app/assets/images/pexels-photo-959079.jpeg b/app/assets/images/pexels-photo-959079.jpeg new file mode 100644 index 0000000000..cda6261b65 Binary files /dev/null and b/app/assets/images/pexels-photo-959079.jpeg differ diff --git a/app/assets/images/shopping-cart-solid.svg b/app/assets/images/shopping-cart-solid.svg new file mode 100644 index 0000000000..5ca1647b84 --- /dev/null +++ b/app/assets/images/shopping-cart-solid.svg @@ -0,0 +1 @@ + diff --git a/app/assets/images/sign-out-alt-solid.svg b/app/assets/images/sign-out-alt-solid.svg new file mode 100644 index 0000000000..6ffd6a88e5 --- /dev/null +++ b/app/assets/images/sign-out-alt-solid.svg @@ -0,0 +1 @@ + diff --git a/app/assets/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/carts.js b/app/assets/javascripts/carts.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/carts.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/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/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/order_items.js b/app/assets/javascripts/order_items.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order_items.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/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/products.js b/app/assets/javascripts/products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/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/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..718e4a70e8 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,325 @@ +/* + * 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 "**/*"; + +.main-container { + padding: 2rem 2rem; +} + + +h1, h2, h3, h4 { + font-family: 'Alegreya Sans SC', sans-serif; +} + +p { + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +.navbar { + font-family: 'Alegreya Sans SC', sans-serif; +} + +.navbar-brand { + color: #8ff9f6 !important; + font-weight: bold; +} + +.navbar-brand:hover { + color: #0abab5 !important; + font-weight: bold; +} + +.nav-link { + color: lightgray; + line-height: 12px; +} + +.nav-link:hover { + color: white !important; +} + +.right-items { + height: 40px; +} + +.login { + width: 25px; + padding-top: .5rem; + opacity: .5; +} + +.login:hover { + opacity: 1; +} + +.main-cart { + padding-left: 1.5rem; + font-size: 1.5rem; + margin-bottom: 1.5rem; +} + +.logout { + width: 25px; + padding-top: .5rem; + opacity: .5; +} + +.logout:hover { + opacity: 1; +} + +.fa-github-square { + font-size: 1.75em; + color: lightgrey; + padding-right: .75rem; + padding-left: .75rem; + padding-top: .5rem; +} + +.fa-github-square:hover { + color: white; +} + +.fa-sign-in-alt { + font-size: 1.5em; + color: lightgrey; +} + +.fa-sign-in-alt:hover { + color: white; +} + +.fa-sign-out-alt { + font-size: 1.5rem; + color: lightgrey; + padding-right: .75rem; + padding-left: .75rem; +} + +.fa-sign-out-alt:hover { + color: white; +} + +.fa-shopping-cart { + color: lightgray; +} + +#navfa { + font-size: 1.75em !important; + color: lightgrey; + padding-top: .20rem; + padding-right: .75em; +} + +#navfa:hover { + color: #8ff9f6 !important; +} + +.fa-shopping-cart:hover { + color: white; +} + +.right { + padding-right: 13px; +} + +.fa-stack[data-count]:after{ + position: absolute; + right: 0%; + top: 0%; + content: attr(data-count); + font-size: 35%; + padding: .6em; + border-radius: 999px; + line-height: .75em; + color: white; + text-align: center; + min-width: 2em; + font-weight: bold; + background: #0abab5; + +} + +.form-group { + margin-left: 20px; + margin-right: 20px; +} + +.star { + font-size: 25px; + color: gold; + padding: 3px; + } + +.btn { + background-color: #0abab5; + border: #0abab5; + color: white; +} + +.btn:hover { + opacity: 0.75; + background-color: #0abab5; + border: #0abab5; + +} + +.page-footer { + color: #8ff9f6 !important; + // font-weight: bold; + background: #343a40 !important; + bottom:0; +} + +.list-unstyled > li > a { + list-style: none; + color: white; +} + +.list-unstyled > li > a:hover { + text-decoration: none; + color: #8ff9f6 !important; +} + +.footer-copyright p { + color: lightgray; +} + +.footer-copyright a { + font-family: 'Alegreya Sans SC', sans-serif; + font-size: 16px; + color: #8ff9f6; + text-decoration: none; +} + +.footer-copyright a:hover { + color: white; +} + +.brand { + font-family: 'Alegreya Sans SC', sans-serif; + font-size: 24px; +} + +#fotp { + color: lightgray; +} + +.message { + padding-top: 8rem; + text-align: center; + padding-bottom: 8rem; +} + +.merchant { + background-image: url("41250510-rough-wooden-used-cutting-board-background-with-vertical-lines-and-cutting-traces.jpg"); + margin: 0; +} + +.merchant-actions, .cart-actions { + margin-top: 5rem; + margin-bottom: 10rem; +} + +.merchant-card{ + padding: 3rem; + padding-bottom: 5rem; + color: #333a40; + +} + +.merchant-card div, .customer-card div{ + border-width: 2px; + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); +} + +.merchant-prod-list, .merchant-order-list, .merchant-rev-list { + margin: 5rem; +} + +.merchant-btn:hover { + box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); + +} + +.merchant-btn { + color: #2E2F30; + background-color: #5efef9; +} + +.merchant-btn .btn-retire{ + background-color: #fec603; +} + +.merchant-card .card-title{ + background-color: #5efef9; +} + +.merchant table,.merchant-table{ + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); +} + +.order-details { + background-image: url("pexels-photo-239581.jpeg"); + margin: 0; +} + +.customer-card { + padding: 5rem; +} + +.sm-date { + font-size: small; +} + +.back-btn{ + margin-left: 23rem; +} + +.order-h2{ + color: #fec603; + background-color: rgba(119,136,142,0.79); + text-align: center; + box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 40px 0 rgba(0, 0, 0, 0.19); + +} + + + +.cart-details { + margin: 5rem; +} + +.action-btn:hover { + box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); + +} + +.empty-table-txt{ + color: #fec603; + background-color: rgba(119,136,142,0.79); + text-align: center; + box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 40px 0 rgba(0, 0, 0, 0.19); +} + +span#price-show { + text-decoration: none; +} \ No newline at end of file diff --git a/app/assets/stylesheets/carts.scss b/app/assets/stylesheets/carts.scss new file mode 100644 index 0000000000..aebbcccc57 --- /dev/null +++ b/app/assets/stylesheets/carts.scss @@ -0,0 +1,56 @@ +// Place all the styles related to the Carts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +.empty-cart { + padding-top: 8rem; + text-align: center; + padding-bottom: 8rem; +} + +.cart-title { + text-align: center; +} + +body .cart { + background-image: url("pexels-photo-959079.jpeg"); + +} + + +.imgsize img { + height: 100px; + width: 80px; +} + +.center > img { + align-items: center; + object-position: center; + height: 110px; + width: 100px; + overflow: hidden; +} + +.center { + display: block; + margin-left: auto; + margin-right: auto; + width: 50%; +} + +td > a { + color:black; +} + +td > a:hover { + color: #ff0065; + cursor: pointer; + text-decoration: none; +} + +.d-flex { + padding-top: 1em; + border-top: 2px solid lightgrey; + padding-right: 10px; + padding-left: 10px; + margin-bottom: 2em; +} diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..42976cbc11 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/order_items.scss b/app/assets/stylesheets/order_items.scss new file mode 100644 index 0000000000..584862de9b --- /dev/null +++ b/app/assets/stylesheets/order_items.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderItems 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/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..53d024397b --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,51 @@ +// Place all the styles related to the orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +/* Padding - just for asthetics on Bootsnipp.com */ +// body { margin-top:20px; } + +/* CSS for Credit Card Payment form */ +.credit-card-box .panel-title { + display: inline; + font-weight: bold; +} +.credit-card-box .form-control.error { + border-color: red; + outline: 0; + box-shadow: inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(255,0,0,0.6); +} +.credit-card-box label.error { + font-weight: bold; + color: red; + padding: 2px 8px; + margin-top: 2px; +} +.credit-card-box .payment-errors { + font-weight: bold; + color: red; + padding: 2px 8px; + margin-top: 2px; +} +.credit-card-box label { + display: block; +} +/* The old "center div vertically" hack */ +.credit-card-box .display-table { + display: table; +} +.credit-card-box .display-tr { + display: table-row; +} +.credit-card-box .display-td { + display: table-cell; + vertical-align: middle; + width: 50%; +} +/* Just looks nicer */ +.credit-card-box .panel-heading img { + min-width: 180px; +} + +.confirm { + text-align: center; +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..7882adf17d --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,285 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +// +// Base styles + + +.category { + object-position: center; /* Center the image within the element */ + width: 100%; + height: auto; +} + +.parent { + display: flex; + flex-wrap: wrap; + margin: 15px; +} + +.child { + flex: 1 0 25%; /* explanation below */ + margin: 5px; + height: auto; +} + +.reviews > h2 { + text-align: center; + padding-top: 2em; +} + +.rating-stars { + display: flex; +} + +.add-review-btn { + margin-left: 2rem; +} + +.table-responsive-md { + margin-left: 25px; + margin-right: 25px; +} + +.rating { + text-align: center; +} + + +//############ Review Button ############## +.inline{ + text-align: center; +} + +.inline > .buttonContainer { + display: inline-block; +} + +.buttonContainer{ + margin-top:45px; + // text-align:center; + padding-bottom: 2em; +} + +a.button{ + display:inline-block; + + font:normal normal 300 1.3em 'Open Sans'; + text-decoration:none; + + color:rgba(28, 190, 131, 1); + brackground-color:transparent; + border:1px solid rgba(28, 190, 131, 1); + border-radius:100px; + + padding: .3em 1.2em; + margin:5px; + + background-size: 200% 100%; + background-image: linear-gradient(to right, transparent 50%, rgba(28, 190, 131, 1) 50%); + transition: background-position .3s cubic-bezier(0.19, 1, 0.22, 1) .1s, color .5s ease 0s, background-color .5s ease; +} + +a.button:hover{ + color:rgba(255, 255, 255, 1); + background-color:rgba(28, 190, 131, 1); + background-position: -100% 100%; +} + +.passenger-form { + margin-top: 3em; + margin-right: 3em; + margin-left: 3em; + padding-top: 1em; + padding-bottom: 2.5em; + text-align: center; + background: #67D4C4; +} + +.passenger-button:hover { + background: blue; + border-radius: 15%; + color: white; + cursor: pointer; +} + +.parah { + font-size: 1.25em; +} + +.header_font { + text-transform: capitalize; + background: lightgrey; + position: sticky; + top: 0; +} + + +//###########body grid for index page############ + +.product-grid6,.product-grid6 .product-image6{overflow:hidden} +.product-grid6{font-family:'Open Sans',sans-serif;text-align:center;position:relative;transition:all .5s ease 0s} +.product-grid6:hover{box-shadow:0 0 10px rgba(0,0,0,.3)} +.product-grid6 .product-image6 a{display:block} +.product-grid6 .product-image6 img{width:100%;height:auto;transition:all .5s ease 0s} +.product-grid6:hover .product-image6 img{transform:scale(1.1)} +.product-grid6 .product-content{padding:12px 12px 15px;transition:all .5s ease 0s} +.product-grid6:hover .product-content{opacity:0} +.product-grid6 .title{font-size:20px;font-weight:600;text-transform:capitalize;margin:0 0 10px;transition:all .3s ease 0s} +.product-grid6 .title a{color:#000} +.product-grid6 .title a:hover{color:#2e86de} +.product-grid6 .price{font-size:18px;font-weight:600;color:#2e86de} +.product-grid6 .price span{color:#999;font-size:15px;font-weight:400;text-decoration:line-through;margin-left:7px;display:inline-block} +.product-grid6 .social{background-color:#fff;width:100%;padding:0;margin:0;list-style:none;opacity:0;transform:translateX(-50%);position:absolute;bottom:-50%;left:50%;z-index:1;transition:all .5s ease 0s} +.product-grid6:hover .social{opacity:1;bottom:20px} +.product-grid6 .social li{display:inline-block} +.product-grid6 .social li a{color:#909090;font-size:16px;line-height:45px;text-align:center;height:45px;width:45px;margin:0 7px;border:1px solid #909090;border-radius:50px;display:block;position:relative;transition:all .3s ease-in-out} +.product-grid6 .social li a:hover{color:#fff;background-color:#2e86de;width:80px} +.product-grid6 .social li a:after,.product-grid6 .social li a:before{content:attr(data-tip);color:#fff;background-color:#2e86de;font-size:12px;letter-spacing:1px;line-height:20px;padding:1px 5px;border-radius:5px;white-space:nowrap;opacity:0;transform:translateX(-50%);position:absolute;left:50%;top:-30px} +.product-grid6 .social li a:after{content:'';height:15px;width:15px;border-radius:0;transform:translateX(-50%) rotate(45deg);top:-20px;z-index:-1} +.product-grid6 .social li a:hover:after,.product-grid6 .social li a:hover:before{opacity:1} +@media only screen and (max-width:990px){.product-grid6{margin-bottom:30px} +} + +.col-sm-6{ + padding-bottom: 1em; +} + +/* GLOBAL STYLES +-------------------------------------------------- */ +/* Padding below the footer and lighter body text */ +/*homepage for products + + + +/* CUSTOMIZE THE CAROUSEL +-------------------------------------------------- */ + +/* Carousel base class */ + +#myCarousel { + margin: auto; + margin-bottom: 3rem; +} + +#seasonal { + font-family: 'Charmonman', cursive; + font-size: 40px; + font-weight: 500; + color: #333; + text-align: center; + padding-bottom: 1rem; +} + +/* Since positioning the image, we need to help out the caption */ +.carousel-caption { + bottom: 3rem; + z-index: 10; +} + +/* Declare heights because of positioning of img element */ +.carousel-item { + height: 32rem; + background-color: #777; +} + +// .carousel-item > img { +// position: absolute; +// top: 0; +// left: 0; +// min-width: 100%; +// height: 32rem; +// } + +.carousel-item img { + object-position: center; /* Center the image within the element */ + width: 100%; + // opacity: .75; +} + +.rounded-circle { + width: 220px; + height: auto; + margin-bottom: 1rem; +} + +/* MARKETING CONTENT +-------------------------------------------------- */ + +/* Center align the text within the three columns below the carousel */ +.marketing .col-lg-4 { + margin-bottom: 1.5rem; + text-align: center; +} +.marketing h4 { + font-weight: 400; +} +.marketing .col-lg-4 p { + margin-right: .75rem; + margin-left: .75rem; +} + + +/* Featurettes +------------------------- */ + +.featurette-divider { + margin: 5rem 0; /* Space out the Bootstrap
more */ +} + +/* Thin out the marketing headings */ +.featurette-heading { + font-weight: 300; + line-height: 1; + letter-spacing: -.05rem; +} + + +/* RESPONSIVE CSS +-------------------------------------------------- */ + +@media (min-width: 40em) { + /* Bump up size of carousel content */ + .carousel-caption p { + margin-bottom: 1.25rem; + font-size: 1.25rem; + line-height: 1.4; + color: white; + } + + .featurette-heading { + font-size: 50px; + } +} + +@media (min-width: 62em) { + .featurette-heading { + margin-top: 7rem; + } +} + + +#product-section { + padding-top: 2rem; +} + +// .product-image6 { +// width: 240px; +// height: 360px; +// // overflow: hidden; +// } +// +// // .product-img { +// // // object-position: center; /* Center the image within the element */ +// // width: 240px; +// // height: 360px; +// // object-fit: cover; +// // } + +.product-img-show { + object-position: center; /* Center the image within the element */ + width: 350px; + height: 100%; + overflow: hidden; + padding-left: 2rem; +} diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000000..370275046d --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,83 @@ +// body { +// background-color: #fff; +// color: #333; +// font-family: verdana, arial, helvetica, sans-serif; +// font-size: 13px; +// line-height: 18px; +// } +// +// p, ol, ul, td { +// font-family: verdana, arial, helvetica, sans-serif; +// font-size: 13px; +// line-height: 18px; +// } +// +// pre { +// background-color: #eee; +// padding: 10px; +// font-size: 11px; +// } +// +// a { +// color: #000; +// +// &:visited { +// color: #666; +// } +// +// &:hover { +// color: #fff; +// background-color: #000; +// } +// } +// +// th { +// padding-bottom: 5px; +// } +// +// td { +// padding: 0 5px 7px; +// } +// +// div { +// &.field, &.actions { +// margin-bottom: 10px; +// } +// } +// +// #notice { +// color: green; +// } +// +// .field_with_errors { +// padding: 2px; +// background-color: red; +// display: table; +// } +// +// #error_explanation { +// width: 450px; +// border: 2px solid red; +// padding: 7px 7px 0; +// margin-bottom: 20px; +// background-color: #f0f0f0; +// +// h2 { +// text-align: left; +// font-weight: bold; +// padding: 5px 5px 5px 15px; +// font-size: 12px; +// margin: -7px -7px 0; +// background-color: #c00; +// color: #fff; +// } +// +// ul li { +// font-size: 12px; +// list-style: square; +// } +// } +// +// label { +// display: block; +// } diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..ccb1ed25b2 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..6545f9e6ff --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,42 @@ + +.parent { + display: flex; + flex-wrap: wrap; + margin: 15px; +} + +.child { + flex: 1 0 25%; /* explanation below */ + margin: 5px; + height: auto; +} +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +.product-grid6,.product-grid6 .product-image6{overflow:hidden} +.product-grid6{font-family:'Open Sans',sans-serif;text-align:center;position:relative;transition:all .5s ease 0s} +.product-grid6:hover{box-shadow:0 0 10px rgba(0,0,0,.3)} +.product-grid6 .product-image6 a{display:block} +.product-grid6 .product-image6 img{width:100%;height:auto;transition:all .5s ease 0s} +.product-grid6:hover .product-image6 img{transform:scale(1.1)} +.product-grid6 .product-content{padding:12px 12px 15px;transition:all .5s ease 0s} +.product-grid6:hover .product-content{opacity:0} +.product-grid6 .title{font-size:20px;font-weight:600;text-transform:capitalize;margin:0 0 10px;transition:all .3s ease 0s} +.product-grid6 .title a{color:#000} +.product-grid6 .title a:hover{color:#2e86de} +.product-grid6 .price{font-size:18px;font-weight:600;color:#2e86de} +.product-grid6 .price span{color:#999;font-size:15px;font-weight:400;text-decoration:line-through;margin-left:7px;display:inline-block} +.product-grid6 .social{background-color:#fff;width:100%;padding:0;margin:0;list-style:none;opacity:0;transform:translateX(-50%);position:absolute;bottom:-50%;left:50%;z-index:1;transition:all .5s ease 0s} +.product-grid6:hover .social{opacity:1;bottom:20px} +.product-grid6 .social li{display:inline-block} +.product-grid6 .social li a{color:#909090;font-size:16px;line-height:45px;text-align:center;height:45px;width:45px;margin:0 7px;border:1px solid #909090;border-radius:50px;display:block;position:relative;transition:all .3s ease-in-out} +.product-grid6 .social li a:hover{color:#fff;background-color:#2e86de;width:80px} +.product-grid6 .social li a:after,.product-grid6 .social li a:before{content:attr(data-tip);color:#fff;background-color:#2e86de;font-size:12px;letter-spacing:1px;line-height:20px;padding:1px 5px;border-radius:5px;white-space:nowrap;opacity:0;transform:translateX(-50%);position:absolute;left:50%;top:-30px} +.product-grid6 .social li a:after{content:'';height:15px;width:15px;border-radius:0;transform:translateX(-50%) rotate(45deg);top:-20px;z-index:-1} +.product-grid6 .social li a:hover:after,.product-grid6 .social li a:hover:before{opacity:1} +@media only screen and (max-width:990px){.product-grid6{margin-bottom:30px} +} + +.col-sm-6{ + padding-bottom: 1em; +} diff --git a/app/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..321f380236 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,48 @@ +class ApplicationController < ActionController::Base + + before_action :list_categories, :list_merchants, :current_order + # before_action :list_categories, :list_merchants + before_action :require_login, except: [:current_order, :render_404, :find_user] + before_action :find_user + + helper_method :current_order + + def list_categories + @categories = Category.all + end + + def list_merchants + @users = User.all + end + + def current_order + if session[:order_id] + @current_order = Order.find(session[:order_id]) + + # else + # @current_order = Order.new + end + # + # return @current_order + end + + def render_404 + raise ActionController::RoutingError.new('Not Found') + end + + private + def find_user + if session[:user_id] + @login_user ||= User.find(session[:user_id]) if session[:user_id] + end + end + + + def require_login + if session[:user_id].nil? + flash[:error] = "You must be logged in to view this section" + redirect_to root_path + end + end + +end diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb new file mode 100644 index 0000000000..797632aab5 --- /dev/null +++ b/app/controllers/carts_controller.rb @@ -0,0 +1,12 @@ +class CartsController < ApplicationController + skip_before_action :require_login + + def show + if @current_order.nil? + render :not_found, status: :not_found + else + @order_items = @current_order.order_items.order(:created_at) + end + end + +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..c431ec170c --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,42 @@ +class CategoriesController < ApplicationController + # skip_before_action :require_login, except: [:create, :update, :edit] + # GET /category + def index + @categories = Category.all + end + + # GET /category/1 + # def show + # end + + # GET /categories/new + def new + @category = Category.new + end + + # GET /categories/1/edit + # def edit + # end + + # POST /categories + def create + @category = Category.new(category_params) + + if @category.save + flash[:success] = 'Category was successfully created.' + redirect_to categories_path + else + flash.now[:warning] = 'Category not created' + @category.errors.messages.each do |field, msg| + flash.now[field] = msg + end + render :new + end + end + + private + + def category_params + params.require(:category).permit(:category) + end +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb new file mode 100644 index 0000000000..da8ee80463 --- /dev/null +++ b/app/controllers/order_items_controller.rb @@ -0,0 +1,104 @@ +class OrderItemsController < ApplicationController + skip_before_action :require_login + # before_action :set_order, only: [:ship] + + + def create + product = Product.find_by(id: params[:order_item][:product_id]) + if params[:order_item][:qty].to_i > product.inv_qty + flash[:warning] = "Quantity selected exceeds amount availabe in inventory" + redirect_to product_path(product.id) + elsif @current_order.nil? + @current_order = Order.new + @current_order.save + end + + @order_item = @current_order.order_items.new(order_item_params) + @order_item.save + @current_order.save + @current_order.update(status: "Pending") + session[:order_id] = @current_order.id + redirect_to cart_path(@current_order.id) + # else + # flash[:warning] = "Item order not placed" + # redirect_to root_path + # # end + end + + def update + product = Product.find_by(id: params[:order_item][:product_id]) + if params[:order_item][:qty].to_i > product.inv_qty + flash[:warning] = "Quantity selected exceeds amount available in inventory" + redirect_to product_path(product.id) + else + @order_item = @current_order.order_items.find_by(id: params[:id]) + if @order_item.nil? + flash[:warning] = "Order item not found" + redirect_to root_path + else + @order_item.update_attributes(order_item_params) + @current_order.save + + if @order_item.save + redirect_to cart_path(@current_order.id) + else + flash[:warning] = "Item order not updated" + redirect_to root_path + end + end + end + end + + + def cart_direct + product = Product.find_by(id: params[:id]) + if product.inv_qty == 0 + flash[:warning] = "Product is out of stock" + redirect_to products_path + elsif @current_order.nil? + @current_order = Order.new + @current_order.save + end + + @order_item = @current_order.order_items.new(product_id: params[:id], qty: 1, shipped: false) + @order_item.save + @current_order.save + + session[:order_id] = @current_order.id + redirect_to cart_path(@current_order.id) + end + + def destroy + @order_item = @current_order.order_items.find(params[:id]) + @order_item.destroy + @order_items = @current_order.order_items + + redirect_to cart_path(@current_order.id) + end + + def ship + @order_item = OrderItem.find_by(order_id: params[:id]) + @order_item.update(shipped: true) + @order_item.order.check_order_status + @order = @order_item.order + @order.save + if @order_item.save + flash[:success] = 'Item(s) have been marked as shipped' + redirect_back(fallback_location: root_path) + else + flash.now[:warning] = 'Error in shipment status.' + # render :show + end + end + + private + + def order_item_params + params.require(:order_item).permit(:product_id, :qty, :shipped) + end + + def set_order + @order = current_order + end + +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..f9e582312c --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,111 @@ + +class OrdersController < ApplicationController + skip_before_action :require_login + before_action :set_order, only: [:edit, :update, :destroy] + # before_action :check_status, only: [:show] + + # GET /orders + def index + @order = Order.find_by(id: params[:id].to_i) + @order_items = @order.order_items + + if @order.nil? + flash.now[:danger] = "Cannot find the order #{params[:id]}" + render :not_found, status: :not_found + end + end + + # def confirmation + # end + + def show + @order = Order.find_by(id: params[:id].to_i) + + if @order.nil? + flash.now[:danger] = "Cannot find the order #{params[:id]}" + render :not_found, status: :not_found + end + # show view used when calling rendering in update - do not remove html show page + end + + # GET /orders/new + # def new + # end + + # GET /orders/1/edit + # def edit + # end + + # POST /orders + # must change database + # flash notices do not have color + # def create + # @order = @current_order.update(order_params) + # # it successfully grabs and saves all fields put in the form + # if @order.save + # flash[:success] = 'Order was successfully created.' + # redirect_to order_path(@order.id) + # else + # flash.now[:warning] = 'Order not created' + # + # @order.errors.messages.each do |field, msg| + # flash.now[field] = msg + # end + # + # render :new + # end + # end + + + # PATCH/PUT /orders/1 + def update + if @current_order.order_items.empty? + flash[:warning] = "You have zero items in your cart" + redirect_to products_path + elsif @current_order.update(order_params) + flash.now[:success] = "Order was accepted" + @current_order.place_order # decrease inventory and change status to paid + @current_order.save + # show confirmation page + @order = @current_order # needed for rendering order information in confirmation page + render :confirmation + session[:order_id] = nil + else + flash.now[:warning] = 'Order was not created' + @current_order.errors.messages.each do |field, msg| + flash.now[field] = msg + end + render :edit + end + end + + # DELETE /orders/1 + # + # def destroy + # @order.destroy + # respond_to do |format| + # format.html { redirect_to orders_url, notice: 'Order was successfully destroyed.' } + # end + # end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_order + begin + @order = Order.find(params[:id]) + rescue + flash[:now] = "Order does not exsist" + redirect_to order_path + end + end + + # Never trust parameters from the scary internet, only allow the white list through. + def order_params + params.require(:order).permit(:id, :status, :cust_name, :cust_email, :mailing_address, :cc_name, :cc_digit, :cc_expiration, :cc_cvv, :cc_zip, :user_id) + end + + # def check_status + # Order.check_order_status(@order) + # end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..3dbb4bce23 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,132 @@ +class ProductsController < ApplicationController + skip_before_action :require_login, only: [:index, :show] + before_action :set_product, only: [:show, :edit, :update, :destroy, :status] + before_action :require_login, only: [:edit, :update, :create, :status] + + # GET /products + def index + if params[:user_id] + @products = @login_user.products + else + @products = Product.all + end + + end + + # GET /products/1 + + def show + # @product = Product.find(params[:id]) + @order_item = OrderItem.new + @reviews = Review.where(product_id: @product) + end + + # GET /products/new + def new + if session[:user_id].nil? + redirect_to root_path + flash[:danger] = "You must log in to access this feature" + end + + if params[:user_id] + # nested route: /user/user_id/products/new + user = User.find_by(id: params[:user_id]) + @product = user.products.new + else + @product = Product.new + end + end + + # GET /products/1/edit + def edit + if @product.user_id != session[:user_id] + flash[:danger] = "You don't have access to edit this product." + redirect_to product_path(@product.id) + end + end + + # POST /products + def create + @product = Product.new(product_params) + @product.user_id = session[:user_id] + + return redirect_to root_path if session[:user_id].nil? + + if @product.save(product_params) + flash[:notice] = "#{@product.prod_name} was added to your inventory." + redirect_to user_path(session[:user_id]) + else + render :new + end + end + + # PATCH/PUT /products/1 + def update + # respond_to do |format| + if @product.update(product_params) + flash[:notice] = "#{@product.prod_name} was successfully updated." + redirect_to product_path + else + flash[:warning] = "Edit was unsuccessful" + render :edit + end + # end + end + + + # DELETE /products/1 + def destroy + @product.destroy + respond_to do |format| + format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } + end + end + + def category + @category = Category.find_by(id: params[:id]) + if @category.nil? + flash[:warning] = "Category is invalid" + redirect_to root_path + end + @products = Product.by_category(params[:id]) + end + + + def status + if @product.active + @product.update(active: false) + flash[:notice] = "#{@product.prod_name} status successfully retired." + redirect_back(fallback_location: root_path) + else + @product.update(active: true) + flash[:warning] = "#{@product.prod_name} status successfully reactivated" + redirect_back(fallback_location: products_path) + end + end + + + def merchant + @user = User.find_by(id: params[:id]) + if @user.nil? + flash[:warning] = "User is invalid" + redirect_to root_path + end + @products = Product.by_merchant(params[:id].to_i) + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_product + begin + @product = Product.find(params[:id]) + rescue + render :not_found, status: :not_found + end + end + + # Never trust parameters from the scary internet, only allow the white list through. + def product_params + params.require(:product).permit(:prod_name, :description, :price, :active, :inv_qty, :image, category_ids: []) + end +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..0e582c89d2 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,92 @@ +class ReviewsController < ApplicationController + skip_before_action :require_login + before_action :set_review, only: [:show, :edit, :update, :destroy] + + # GET /reviews + def index + if params[:product_id] + # This is the nested route, /author/:author_id/books/new + product = Product.find_by(id: params[:product_id]) + @reviews = product.reviews.new + + else + @reviews = Review.all + end + + end + + # GET /reviews/1 + # def show + # end + + # GET /reviews/new + def new + @product = Product.find(params[:product_id]) + @review = Review.new(product: @product) + end + + # GET /reviews/1/edit + # def edit + # end + + # POST /reviews + def create + @product = Product.find(params[:product_id]) + @review = @product.reviews.build(review_params) + @review.product = @product + + if @product.user_id == session[:user_id] + flash[:warning] = "You can't review your own Product" + redirect_to products_path + elsif + @review.save + redirect_to @product + else + flash.now[:warning] = "Please enter all fields" + render :new + end + + + # respond_to do |format| + # if @review.save + # format.html { redirect_to @review, notice: 'Review was successfully created.' } + # else + # format.html { render :new } + # end + # end + end + + + # PATCH/PUT /reviews/1 + # PATCH/PUT /reviews/1.json + # def update + # respond_to do |format| + # if @review.update(review_params) + # format.html { redirect_to @review, notice: 'Review was successfully updated.' } + # else + # format.html { render :edit } + # end + # end + # end + + + # DELETE /reviews/1 + # DELETE /reviews/1.json + def destroy + @review.destroy + respond_to do |format| + format.html { redirect_to reviews_url, notice: 'Review was successfully destroyed.' } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_review + @review = Review.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def review_params + params.require(:review).permit(:rating, :description) + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..0ecc72bccc --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,38 @@ +class SessionsController < ApplicationController + skip_before_action :require_login, except: :destroy + + def create + auth_hash = request.env['omniauth.auth'] + user = User.find_by(uid: auth_hash[:uid], provider: 'github') + if user + # User was found in the database + flash[:success] = "Successfully logged in as #{user.username}" + else + # User doesn't match anything in the DB + user = User.new_user(auth_hash) + # Attempt to create a new user + if user.save + flash[:success] = "Successfully created new user #{user.username} with ID #{user.id}" + else + + flash.now[:warning] = "Could not log in" + flash.now[:messages] = user.errors.messages + render "login", status: :bad_request + return + end + end + + session[:user_id] = user.id + session[:username] = user.username + redirect_to root_path + end + + def destroy + session[:user_id] = nil + @user = nil + # session.clear + flash[:notice] = "Goodbye #{session[:username]}!" + + redirect_to root_path + end +end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..976ae4ad23 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,60 @@ +class UsersController < ApplicationController + skip_before_action :require_login, only: [:create] + before_action :set_user, only: [:show, :edit, :update, :destroy] + before_action :authorized?, only: :show + # GET /users/1 + def show + render_404 unless @user + @products = Product.where(user_id: @user) + end + + # GET /users/new + # def new + # @user = User.new + # end + # + # # GET /users/1/edit + # def edit + # end + + # POST /users + def create + @user = User.new(user_params) + + if @user.save # save returns true if the database insert succeeds + flash[:success] = 'user Created!' + + redirect_to root_path + else # save failed :( + flash.now[:danger] = 'user not created!' + + # render :new, status: :bad_request# show the new book form view again + end + end + + + + private + + # Use callbacks to share common setup or constraints between actions. + def set_user + @user = User.find(params[:id]) + end + + + # Never trust parameters from the scary internet, only allow the white list through. + def user_params + params.require(:user).permit(:uid, :username, :email, :id) + end + + def authorized? + @user = User.find_by(id: params[:id]) + if @user.nil? + flash[:warning] = "Unauthorized" + redirect_to root_path + elsif @user.id != session[:user_id] + flash[:warning] = "You may only view your own account." + redirect_to user_path(session[:user_id]) + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..43321796a0 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,7 @@ +module ApplicationHelper + + + def format_price(amt) + ("" + ("$%.2f" % amt) + "").html_safe + end +end diff --git a/app/helpers/carts_helper.rb b/app/helpers/carts_helper.rb new file mode 100644 index 0000000000..d99c380cb5 --- /dev/null +++ b/app/helpers/carts_helper.rb @@ -0,0 +1,2 @@ +module CartsHelper +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/order_items_helper.rb b/app/helpers/order_items_helper.rb new file mode 100644 index 0000000000..e197528ae1 --- /dev/null +++ b/app/helpers/order_items_helper.rb @@ -0,0 +1,2 @@ +module OrderItemsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/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/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/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/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..64237aa325 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,9 @@ +class Category < ApplicationRecord + # validations + validates :category, presence: true, uniqueness: true + + # relationships + + has_and_belongs_to_many :products + +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..881c3986fa --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,87 @@ +class Order < ApplicationRecord + #validations + validates :cust_name, presence: true, format: { with: /[a-zA-Z]/ }, on: :update + validates :cc_digit, presence: true, format: { with: /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}\b/, maxlength: 16 }, on: :update + validates :cc_expiration, presence: true, on: :update + validates :cc_cvv, presence: true, format: { with: /[0-9]{3}/ }, on: :update + validates :cc_zip, presence: true, format: { with: /[0-9]{5}/ }, on: :update + validates :cust_email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }, on: :update + validates :mailing_address, presence: true, on: :update + #relationships + has_many :order_items + + + def items_in_cart + num_in_cart = 0 + if self.order_items.empty? + return 0 + else + self.order_items.each do |item| + if item.qty != nil + num_in_cart += item.qty + end + end + end + return num_in_cart + end + + def total_price + self.order_items.sum do |order_item| + product_id = Product.find_by(id: order_item.product_id) + order_item.qty * product_id.price + end + end + + def place_order + #decrease inventory + self.order_items.each do |order_item| + product = order_item.product + # get quantity + quantity = product.inv_qty + # substract amount defined in order + new_inv_qty = quantity - order_item.qty + product.inv_qty = new_inv_qty + product.update(inv_qty: new_inv_qty) + if product.inv_qty <= 0 + product.update(active:false) + end + product.save! + end + self.update(status: "Paid") + end + + + def date_of_order + return self.created_at.strftime("%B %d, %Y") + end + + def check_order_status + @order = self + + all_shipped = true + @order.order_items.each do |item| + if !item.shipped + all_shipped = false + end + end + + if all_shipped + @order.status = "Complete" + @order.save + end + + + end + + def destroy + # method to cancel order + end + + private + + # def set_order_status + # self.order_status_id = 1 + # end + + +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..a690f97f3b --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,16 @@ +class OrderItem < ApplicationRecord + validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 } + + belongs_to :product + belongs_to :order + + + def subtotal + return self.product.price * qty + end + + private + + + +end diff --git a/app/models/order_status.rb b/app/models/order_status.rb new file mode 100644 index 0000000000..53cc240f47 --- /dev/null +++ b/app/models/order_status.rb @@ -0,0 +1,6 @@ +class OrderStatus < ApplicationRecord + + #relationships + # has_many :order_items + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..3d1ea4b7a4 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,48 @@ +class Product < ApplicationRecord + # validations + validates :prod_name, presence: true, uniqueness: true + validates :description, :price, presence: true + validates :inv_qty, presence: true, numericality: { only_integer: true} # no need to validate inv_qty less than 0 because I am making it inactive + # relationships + belongs_to :user + has_many :reviews + # has_and_belongs_to_many :orders + + has_and_belongs_to_many :categories + has_many :order_items + + def self.by_category(id) + all_products = Product.all.where(active: true) + category_products = [] + + all_products.each do |product| + if product.categories.find_by(id: id) + category_products << product + end + end + return category_products + end + + def self.by_merchant(id) + all_products = Product.all.where(active: true) + merchant_products = [] + + all_products.each do |product| + if product.user.id == id + merchant_products << product + end + end + return merchant_products + end + + + def avg_rating + reviews = self.reviews + if reviews.count > 0 + total = reviews.reduce(0) { |sum, review| sum + review.rating } + avg = total/reviews.count + + return avg + end + end +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..1e11925f71 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,6 @@ +class Review < ApplicationRecord + #validations + validates :rating, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 6} + #relationships + belongs_to :product +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..5eec377eef --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,53 @@ +class User < ApplicationRecord + # validations + validates :username, presence: true, uniqueness: true + validates :uid, presence: true, uniqueness: {scope: :provider} + validates :email, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i } + + # relationships + has_many :products + has_many :order_items, through: :products + + def self.new_user(auth_hash) + new_user = User.new(email: auth_hash[:info][:email], + username: auth_hash[:info][:nickname], + uid: auth_hash[:uid], + provider: 'github') + + return new_user + end + + + def find_ordered_items + ordered_items = [] + self.products.each do |product| + unless product.order_items.empty? + product.order_items.each do |ord_item| + ordered_items << ord_item + end + end + end + return ordered_items + end + + + def revenue(status_filter) + rev = 0 + if status_filter == "Total" + self.order_items.each do |item| + rev += item.subtotal + end + return rev + else + self.order_items.each do |item| + if item.order.status == status_filter + rev += item.subtotal + end + end + end + + return rev + end +end + + diff --git a/app/views/carts/new.html.erb b/app/views/carts/new.html.erb new file mode 100644 index 0000000000..1dbb6c5c5d --- /dev/null +++ b/app/views/carts/new.html.erb @@ -0,0 +1,4 @@ +
+

Your cart is empty.

+

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

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

404 Not Found

+
diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb new file mode 100644 index 0000000000..558062c4a3 --- /dev/null +++ b/app/views/carts/show.html.erb @@ -0,0 +1,46 @@ + +
+ +

Your Cart

+ + + + + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + <%if order_item.product.inv_qty > 0 %> + <%= form_with model: order_item do |f| %> + + <% else %> + + <%end%> + + + + <% end %> + +
ItemPriceQuantitySubtotalRemove Item
<%=link_to image_tag("#{order_item.product.image}", alt: "#{order_item.product.description}"), product_url, class: "imgsize"%>
<%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %>
<%=order_item.product.description%>
<%= format_price(order_item.product.price) %><%= f.select :qty, (1..order_item.product.inv_qty).to_a %> + <%= f.hidden_field :product_id, :value => order_item.product.id %> + <%= f.submit 'Update', class: "btn btn-primary" %> + <% end %> + Out of Stock <%= format_price(order_item.subtotal) %><%= link_to "Remove", order_item_path(order_item.id), method: :delete, class: "btn btn-outline-danger" %>
+
+ +
+ <%= link_to "Continue Shopping", products_path, class: "btn btn-primary " %> + <%= link_to "Checkout", edit_order_path(@current_order.id), class: "btn btn-primary" %> +
+ + diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb new file mode 100644 index 0000000000..195cea753e --- /dev/null +++ b/app/views/categories/_form.html.erb @@ -0,0 +1,12 @@ +<%# render partial: "layouts/form_errors", locals: { error_hash: @category } %> +<%= render partial: "layouts/flash_errs" %> +<%= form_with(model: category, local: true) do |form| %> +
+ <%= form.label :category %> + <%= form.text_field :category, class: "form-control"%> +
+ +
+ <%= form.submit class: "btn btn-primary" %> +
+<% end %> \ No newline at end of file diff --git a/app/views/categories/create.html.erb b/app/views/categories/create.html.erb new file mode 100644 index 0000000000..19d08fb435 --- /dev/null +++ b/app/views/categories/create.html.erb @@ -0,0 +1,4 @@ +
+

Categories#create

+

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

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

Categories

+ + + + <%= link_to "Add a new category", new_category_path, class: "btn btn-small" %> +
diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..c83c0911d1 --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,7 @@ +
+

New Category

+ + <%= render 'form', category: @category %> + + <%= link_to 'Back', categories_path %> +
diff --git a/app/views/layouts/_flash_errs.html.erb b/app/views/layouts/_flash_errs.html.erb new file mode 100644 index 0000000000..129c7bed3d --- /dev/null +++ b/app/views/layouts/_flash_errs.html.erb @@ -0,0 +1,15 @@ +
+<% flash.each do |name, message| %> + <% if message.class == Array %> +
+ <% message.each do |msg| %> +

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

+ <% end %> +
+ <% else %> +
+ <%= message %> +
+ <% end %> +<% end %> +
diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb new file mode 100644 index 0000000000..18cf62108d --- /dev/null +++ b/app/views/layouts/_form_errors.html.erb @@ -0,0 +1,14 @@ +
+ <% if error_hash.errors.any? %> +
+
+ The form contains <%= pluralize(error_hash.errors.count, "error") %>. +
+ +
+ <% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..0b1328c4f2 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,169 @@ + + + + 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/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb new file mode 100644 index 0000000000..03ff096b0e --- /dev/null +++ b/app/views/orders/_form.html.erb @@ -0,0 +1,112 @@ + + +<% render partial: "layouts/form_errors", locals: { error_hash: @order } %> + +<%= form_with(model: order, local: true) do |form| %> + <%# render partial "/layouts/form_errors", locals: { error_hash: order}%> + +
+
+ +
+ + + +
+
+
+

Payment Details

+
+ +
+
+
+
+
+
+
+
+ <%= form.label "NAME ON CARD" %> + <%= form.text_field :cc_name, class: "form-control", placeholder: "Ada Lovelace" %> +
+
+
+
+
+
+ <%= form.label "CREDIT CARD NUMBER" %> +
+ <%= form.number_field :cc_digit, class: "form-control", maxlength: "16", for:"cardExpiry", placeholder: "Add 16 DIGIT CARD NUMBER"%> + +
+
+
+
+
+
+
+ <%= form.label "Expiration Date" %> + <%= form.date_select :cc_expiration, class: "form-control"%> +
+
+
+
+ <%= form.label "CVV", for: "cardCVC" %> + <%= form.number_field :cc_cvv, class: "form-control", placeholder: "435" %> +
+
+
+
+
+
+ + +
+
+
+
+
+ <%= form.submit "Confirm Order", class: "btn btn-primary" %> +
+
+ +
+
+
+ + + +
+ +
+
+ <%= form.label "Name" %> + <%= form.text_field :cust_name, class: "form-control" %> +
+ +
+ <%= form.label "Email" %> + <%= form.text_field :cust_email, class: "form-control" %> +
+ +
+ <%= form.label :mailing_address %> + <%= form.text_field :mailing_address, class: "form-control" %> +
+ +
+ <%= form.label "Zip Code" %> + <%= form.number_field :cc_zip, class: "form-control" %> +
+ +
+ +
+
+<% end %> + diff --git a/app/views/orders/confirmation.html.erb b/app/views/orders/confirmation.html.erb new file mode 100644 index 0000000000..9b6d3bbb0c --- /dev/null +++ b/app/views/orders/confirmation.html.erb @@ -0,0 +1,44 @@ + +
+

Order Confirmation Page

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

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

+ +

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

+ +

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

+ +

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

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

Confirm Your Order

+ +
+ <%= render partial: "/layouts/flash_errs" %> + + <%= render 'form', order: @order %> + + <%= link_to 'Back', cart_path, class: "btn btn-danger"%> + +
diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000000..acf4059ec5 --- /dev/null +++ b/app/views/orders/index.html.erb @@ -0,0 +1,31 @@ +
+ +

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

+ + + + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + + <% if order_item.subtotal == true %> + + <% else %> + + <% end %> + + <% end %> + +
ItemPriceQuantitySubtotalStatus
<%= link_to "#{order_item.product.prod_name}", product_path(order_item.product.id) %><%= order_item.product.price %><%= order_item.qty %><%= order_item.subtotal %>ShippedPending
+
diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..4bc2bd9751 --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,7 @@ +
+

New Order

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

404 Not Found

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

ORDER #<%=@order.id %>

+
+
CUSTOMER INFORMATION
+

Status: <%= @order.status %>

+

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

+

Customer email: <%= @order.cust_email %>

+

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

+

Card name: <%= @order.cc_name %>

+

Card last 4: XXXX XXXX XXXX <%= @order.cc_digit %>

+

Card expiration: <%= @order.cc_expiration %>

+

Card CVV: <%= @order.cc_cvv %>

+

Card zip code:<%= @order.cc_zip %>

+
+
+
+ +
+

ORDERED ITEMS

+ + + + + + + + + + + + + <% ordered_items = @login_user.find_ordered_items %> + <% ordered_items.each do |item| %> + <% if item.order.id == @order.id %> + + + + + + + <% if item.shipped %> + + <% elsif !item.shipped && item.order.status == "Paid"%> + + <% else %> + + <% end %> + <% ord = Order.find(item.order.id) %> + + + <% end %> + <% end %> + +
ORDER #ITEMPRICEQUANTITYSUBTOTALITEM STATUSORDER DATE
<%= "#{item.order.id}" %> <%= link_to "#{item.product.prod_name}", edit_product_path(item.product.id)%> <%= format_price(item.product.price)%> <%= item.qty %> <%= format_price(item.product.price * item.qty) %>SHIPPEDPAID
+ <%= link_to "CONFIRM SHIPPED", ship_item_path(item.product), class: "merchant-btn btn btn-outline-info btn-sm ", method: :patch%> +
PENDING PAYMENT<%= ord.date_of_order %>
+ <%= link_to 'Back', user_path(session[:user_id]), class: "back-btn btn btn-primary merchant-btn" %> +
+
+ + + + + + + + diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..614e681151 --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,39 @@ +<% render partial: "layouts/form_errors", locals: { error_hash: @product } %> + +<%= form_with(model: product, local: true) do |form| %> +
+ <%= form.label :prod_name %> + <%= form.text_field :prod_name, class: "form-control"%> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description, class: "form-control"%> +
+ +
+ <%= form.label :price %> + <%= form.text_field :price, class: "form-control"%> +
+ +
+ <%= form.label :inv_qty %> + <%= form.number_field :inv_qty, class: "form-control"%> +
+ +
+ <%= form.label :image %> + <%= form.text_field :image, class: "form-control"%> +
+ +
+ <%= form.label :categories %> + <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :category) %> +
+ +
+ <%= form.submit class: "btn btn-primary" %> +
+ + +<% end %> diff --git a/app/views/products/_productslist.html.erb b/app/views/products/_productslist.html.erb new file mode 100644 index 0000000000..0d8c57bfbe --- /dev/null +++ b/app/views/products/_productslist.html.erb @@ -0,0 +1,35 @@ + +
+
+ <% @products.each do |product| %> + <% if product.active %> +
+
+
+ <%=link_to image_tag("#{product.image}", alt: "#{product.description}"), product_path(product.id), class: "product-img" %> +
+
+

<%= product.prod_name %>

+
<%= ("$%.2f" %product.price) %> + <%= product.inv_qty %> in stock +
+
+ + +
+
+ <% end %> + <% end %> +
+
+ + diff --git a/app/views/products/category.html.erb b/app/views/products/category.html.erb new file mode 100644 index 0000000000..915a69a07c --- /dev/null +++ b/app/views/products/category.html.erb @@ -0,0 +1,7 @@ +<%= render partial: "/layouts/flash_errs" %> +
+ +

<%= @category.category.pluralize %>

+ <%= render partial: "productslist", locals: { } %> + +
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..ca5698e096 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,10 @@ +
+<%= render partial: "/layouts/flash_errs" %> + +

Editing Product

+ + <%= render 'form', product: @product %> + + <%= link_to 'Show', @product %> | + <%= link_to 'Back', products_path %> +
diff --git a/app/views/products/home.html.erb b/app/views/products/home.html.erb new file mode 100644 index 0000000000..33e63560b2 --- /dev/null +++ b/app/views/products/home.html.erb @@ -0,0 +1,86 @@ +<%= render partial: "/layouts/flash_errs" %> + + + + + + + + + +
+ + +

Seasonal Favorites

+
+
+ Generic placeholder image +

Vanilla, "I Vote Cupcake"

+

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

+

View details »

+
+
+ Generic placeholder image +

Pumpkin Cardamom

+

Cozy up this Autumn with our Pumpkin Cardamom spiced cupcakes.

+

View details »

+
+
+ Generic placeholder image +

Fig & Honey

+

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

+

View details »

+
+
+ + +
+ + diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..d3d78bda31 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,7 @@ +<%= render partial: "/layouts/flash_errs" %> +
+ +

All Sweets

+ <%= render partial: "productslist", locals: { } %> + +
diff --git a/app/views/products/merchant.html.erb b/app/views/products/merchant.html.erb new file mode 100644 index 0000000000..25fe0e1f00 --- /dev/null +++ b/app/views/products/merchant.html.erb @@ -0,0 +1,7 @@ +<%= render partial: "/layouts/flash_errs" %> +
+ +

<%= @user.username %>

+ <%= render partial: "productslist", locals: { } %> + +
diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..60d6fc38bb --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,8 @@ +<%= render partial: "/layouts/flash_errs" %> +
+

New Product

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

404 Not Found

+
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..93af4f3b73 --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,118 @@ +<%= render partial: "/layouts/flash_errs" %> + +
+
+
+
+ + +
+
+
+
+

<%= @product.prod_name %>

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

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

+
+ +
+
+ <% if @product.reviews.length >= 1 %> + <% @product.avg_rating.round.times do %> + rating star + <% end %> + <% end %> +
+
+ <%= link_to "Write A Review", new_product_review_path(@product), class:"btn btn-danger" %> + +
+
+ +
+
+

<%= format_price(@product.price) %>

+
+
+ + <%if @product.inv_qty > 0 %> +
+
+ <%= form_with model: @order_item do |f| %> + <%= f.label :qty %> + <%= f.select :qty, (1..@product.inv_qty).to_a %> + <%= f.hidden_field :product_id, :value => @product.id %> + <%= f.hidden_field :shipped, :value => false %> + + <%= f.submit "Add to cart", class: "btn btn-sm btn-brand btn-full-width" %> + <% end %> +
+
+ <%end%> + +
+
+ <%if @product.inv_qty > 0 %> + In Stock + <%else %> + Out of Stock + <%end%> +
+
+
+
+
+ +
+
+
+ + + +
+

Reviews

+
Average Rating: + <% if @product.reviews.length >= 1 %> + <% @product.avg_rating.round.times do %> + rating star + <% end %> + <% end %> +
+ +
+ + + + + + + + + + + <% @product.reviews.each do |review| %> + + + + + <% end %> + +
RatingReviewEdit
<%= review.rating%> <%= review.description%><%= link_to 'Edit', edit_review_path(review) %>
+ +
+
diff --git a/app/views/reviews/_form.html.erb b/app/views/reviews/_form.html.erb new file mode 100644 index 0000000000..53cb0e5ffa --- /dev/null +++ b/app/views/reviews/_form.html.erb @@ -0,0 +1,31 @@ +<%= form_with(model: review, local: true) do |form| %> + + <% render partial: "layouts/form_errors", locals: { error_hash: @review } %> + + <%# if review.errors.any? %> +
+

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

+ + +
+ <%# end %> + + +
+ <%= form.label :rating %> + <%= form.number_field :rating, class: "form-control" %> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description, class: "form-control" %> +
+ +
+ <%= form.submit class: "btn btn-primary"%> +
+<% end %> diff --git a/app/views/reviews/edit.html.erb b/app/views/reviews/edit.html.erb new file mode 100644 index 0000000000..95a8f04858 --- /dev/null +++ b/app/views/reviews/edit.html.erb @@ -0,0 +1,8 @@ +<%= render partial: "/layouts/flash_errs" %> +
+

Editing Review

+ + <%= render 'form', review: @review %> + + <%= link_to 'Show', @review %> | +
diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb new file mode 100644 index 0000000000..0107b2c066 --- /dev/null +++ b/app/views/reviews/index.html.erb @@ -0,0 +1,31 @@ +<%= render partial: "/layouts/flash_errs" %> + +

<%= notice %>

+ +

Reviews

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

New Review

+ + <%#= render 'form', review: @review %> + <%= form_for [@product, @review] do |form| %> + +
+ <%= form.label :rating %> + <%= form.number_field :rating, class: "form-control" %> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description, class: "form-control" %> +
+ +
+ <%= form.submit class: "btn btn-primary"%> +
+ <% end %> +
diff --git a/app/views/reviews/show.html.erb b/app/views/reviews/show.html.erb new file mode 100644 index 0000000000..8111a01020 --- /dev/null +++ b/app/views/reviews/show.html.erb @@ -0,0 +1,15 @@ + +<%= render partial: "/layouts/flash_errs" %> +

<%= notice %>

+ +

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

+ +

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

+ +<%= link_to 'Edit', edit_review_path(@review) %> | diff --git a/app/views/sessions/destroy.html.erb b/app/views/sessions/destroy.html.erb new file mode 100644 index 0000000000..d75237d982 --- /dev/null +++ b/app/views/sessions/destroy.html.erb @@ -0,0 +1,2 @@ +

Sessions#destroy

+

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

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

Log In

+ + <%= form_tag do %> +
+ <%= label_tag :username, "Username" %> + <%= text_field_tag :username, nil, class: "form-control" %> +
+
+ <%= submit_tag "Log In", 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..b39a3bc951 --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,2 @@ +

Sessions#new

+

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

diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb new file mode 100644 index 0000000000..ab597c73f2 --- /dev/null +++ b/app/views/users/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: user, local: true) do |form| %> + <% if user.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= form.label :username %> + <%= form.text_field :username, class: "form-control" %> +
+ +
+ <%= form.label :email %> + <%= form.text_field :email, class: "form-control" %> +
+ +
+ <%= form.submit class: "btn btn-primary" %> +
+<% end %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000000..6fa1b2b121 --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,8 @@ +
+

Editing User

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

<%= notice %>

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

Users

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

New User

+ + <%= render 'form', user: @user %> + + <%= link_to 'Back', users_path %> +
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000000..5ecb64e2cc --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,143 @@ +
+<%= render partial: "/layouts/flash_errs" %> +
+
+ + <%= image_tag "making-bakery-in-the-kitchen_1101-153.jpg", :alt => 'making bakes', class: "card-img-top"%> +
+

<%= @user.username %>

+
AVG RATING: 4 + average rating
+

<%= @user.email %>

+

USER ID: <%= @user.uid %>

+
+
+
+ + + + +
+ <%= link_to 'View Your Bakes', user_products_path(@user.id), class: "merchant-btn btn btn-info" %> + <%= link_to 'List a New Bake', new_user_product_path(@user), class: "merchant-btn sell-link btn btn-info" %> + <%= link_to 'View Categories', categories_path, class: "merchant-btn btn btn-info" %> +
+ +
+

LISTED BAKES

+ + + + + + + + + + + + + + <% if @user.products.empty? %> +

<%= "No Products Have Been Listed to Sell" %>

+ <% else %> + <% @user.products.each do |product| %> + + + + + + <% if product.active %> + + + <% else %> + + + <% end %> + + <% end %> + <% end %> + +
NAMEPRICEQUANTITYRATINGSTATUS
<%= link_to "#{product.prod_name}", edit_product_path(product.id)%> <%= format_price(product.price)%> <%= product.inv_qty %> <%= product.avg_rating %>ACTIVE<%= link_to "RETIRE", product_status_path(product), class: "merchant-btn btn btn-retire", method: :patch%>RETIRED<%= link_to "ACTIVATE", product_status_path(product), class: "merchant-btn btn btn-activate", method: :patch%>
+
+ + + +
+

ORDER FULFILLMENT

+ + + + + + + + + + + + + <% ordered_items = @user.find_ordered_items %> + <% if ordered_items.empty? %> +

<%= "No Products Have Sold" %>

+ <% else %> + <% ordered_items.sort_by {|item| item.updated_at }.each do |item| %> + + + + + + + <% if !item.shipped && item.order.status == "Paid"%> + + <% elsif item.shipped %> + + <% else %> + + <% end %> + <% ord = Order.find_by(id: item.order.id) %> + <% if ord.status.nil? %> + + <% else %> + + <% end %> + + <% end %> + <% end %> + +
ORDER #ITEMPRICEQUANTITYSUBTOTALITEM STATUSORDER STATUS
<%= link_to "#{item.order.id}", order_path(item.order.id) %> +

<%= item.order.date_of_order %>

<%= link_to "#{item.product.prod_name}", edit_product_path(item.product.id)%> <%= format_price(item.product.price)%> <%= item.qty %> <%= format_price(item.product.price * item.qty) %>PAID
+ <%= link_to "CONFIRM SHIPPED", ship_item_path(item.order_id), class: "merchant-btn btn btn-outline-info btn-sm ", method: :patch%>
SHIPPEDPENDING PAYMENTPENDING PAYMENT<%= ord.status.upcase %>
+
+ +
+

REVENUE

+ + + + + + + + + + + + <% sold = @user.find_ordered_items %> + <% if sold.empty? %> + <%= "No Products Have Sold" %> + <% else %> + + + + + + + + <% end %> + +
PENDINGPAIDCOMPLETECANCELLEDTOTAL
<%= format_price(@user.revenue("Pending")) %> <%= format_price(@user.revenue("Paid")) %> <%= format_price(@user.revenue("Complete"))%> <%= format_price(@user.revenue("Cancelled")) %> <%= format_price(@user.revenue("Total")) %>
+
+ + + <%= link_to 'Back', root_path %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000000..f19acf5b5c --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000000..5badb2fde0 --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000000..d87d5f5781 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000000..94fd4d7977 --- /dev/null +++ b/bin/setup @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000000..fb2ec2ebb4 --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000000..58bfaed518 --- /dev/null +++ b/bin/update @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 0000000000..460dd565b4 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..f7ba0b527b --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000000..5c09a3eefc --- /dev/null +++ b/config/application.rb @@ -0,0 +1,25 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Betsy + class Application < Rails::Application + config.generators do |g| + # Force new test files to be generated in the minitest-spec style + g.test_framework :minitest, spec: true + # Always use .js files, never .coffee + g.javascript_engine :js + end + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000000..b9e460cef3 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000000..dd2a324c68 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: betsy_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000000..2170aafac5 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +6qMkHjG2FcVe8v2LPgI4ogyQYaCK5bMWmEkSKjF4CJMmfhWKZ2OeTv/ePiXOcz3w/Kn5GX0h21i4dHUPl9MQinnI3QepErVUXUR4rFZZbqBI39sAu1MqSmu3OMlKPnunn7jcwgcol3H3akRkdhgL/GapeGVNzu+oR4NSDKmvsBpNHDKLxu6P3aSFBzRHiHcNXi0EO8JIK/XVa2ZiKu8v+Y03hbieJhmXwLqCUJE7YSJ47SlKYw4YYl4Ed0fYmaFtTKfq8c6MI+ziyepXL4X9AHBwFlgs95nKRYHeAscruwXZ1GfLrkzqdnppGq+W+VxmMXdxa7sWi7v06UlXsGfZxd9HemBiib3pFZxDyVU6SqA0XFxmFCblO7rNsiuT5LrOMZZ2PXDwybPkYF8M/wOrAxuHH/uW30R36X5D--N0APY7pCr5Quvg0+--jT6K103BvIqvpfllNATnjg== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..6903bb6083 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: betsy_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: betsy + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: betsy_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: betsy_production + username: betsy + password: <%= ENV['BETSY_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000..426333bb46 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000000..1311e3e4ef --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,61 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000000..5f6f3058c6 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,94 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "betsy_#{Rails.env}" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000000..0a38fd3ce9 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,46 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb new file mode 100644 index 0000000000..142d382f87 --- /dev/null +++ b/config/initializers/action_view.rb @@ -0,0 +1 @@ +Rails.application.config.action_view.form_with_generates_remote_forms = false diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 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/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/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..dcffbb0cd5 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,40 @@ +Rails.application.routes.draw do + root 'products#home' + + get "/auth/:provider/callback", to: "sessions#create", as: "login" + + resources :products do + resources :reviews, only: [:new, :create] + end + + get "/auth/:provider/callback", to: "sessions#create", as: "auth_callback" + delete "/logout", to: "sessions#destroy", as: "logout" + + resources :reviews, :except => [:show] + + resources :carts, only: [:show, :new] + + patch 'order_items/:id/ship', to: "order_items#ship", as: "ship_item" + post "order_items/cart_direct/:id", to: "order_items#cart_direct", as: "quick_shop" + resources :order_items, only: [:create, :update, :destroy] + + resources :orders + patch 'order/confirm_order/:id', to: "order#confirm_order", as: "confirm_order" + + get 'products/category/:id', to: "products#category", as: "category" + patch 'products/:id/retire', to: "products#status", as: "product_status" + get 'products/merchant/:id', to: "products#merchant", as: "merchant" + resources :products, :except => [:destroy] + + resources :users, :except => [:destroy, :index] + + resources :users do + resources :products, only: [:index, :show, :new] + # resources :orders, only: [:index, :show] + end + + + + resources :categories, :except => [:destroy] + +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/category_seeds.csv b/db/category_seeds.csv new file mode 100644 index 0000000000..b418136fd9 --- /dev/null +++ b/db/category_seeds.csv @@ -0,0 +1,4 @@ +id,category +1,Cupcake +2,Pie +3,Cake diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb new file mode 100644 index 0000000000..510c564dcb --- /dev/null +++ b/db/generate_seeds.rb @@ -0,0 +1,75 @@ + +require 'faker' +require 'date' +require 'csv' + +# feel free to +# run this script in order to replace it and generate a new one +# run using the command: +# $ ruby db/generate_seeds.rb +# if satisfied with this new media_seeds.csv file, recreate the db with: +# $ rails db:reset +# doesn't currently check for if titles are unique against each other + +CSV.open('db/user_seeds.csv', "w", :write_headers=> true, + :headers => ["uid", "username", "email"]) do |csv| + + 5.times do + uid = Faker::Number.between(1, 5) + username = Faker::Internet.username + email= Faker::Internet.safe_email + csv << [uid, username, email] + end +end + + + +CSV.open('db/product_seeds.csv', "w", :write_headers=> true, + :headers => ["prod_name", "user_id", "description", "price", "inv_qty", "active", "image"]) do |csv| + + 30.times do + # category = %w(birthday wedding chocolate vanilla buttercream).sample + prod_name = Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor + user_id = Faker::Number.between(1, 4) + description = Faker::Coffee.notes + price = Faker::Number.decimal(2, 2) + inv_qty = Faker::Number.between(0, 30) + active = Faker::Boolean.boolean + image = Faker::LoremPixel.image("200x300", false, 'food') + + csv << [prod_name, user_id, description, price, inv_qty, active, image] + end +end + + +CSV.open('db/review_seeds.csv', "w", :write_headers=> true, + :headers => ["rating", "description", "product_id"]) do |csv| + + 10.times do + rating = Faker::Number.between(1, 5) + description = ["Tasted like ", "Deliciously flavored ", "Oddly it smelled like "].sample + Faker::Coffee.notes + product_id = Faker::Number.between(1, 15) + csv << [rating, description, product_id] + end +end + + +CSV.open('db/order_seeds.csv', "w", :write_headers=> true, + :headers => ["status", "cust_name", "cust_email", "mailing_address", + "cc_name", "cc_digit", "cc_expiration", "cc_cvv", + "cc_zip"]) do |csv| + + 10.times do + status = %w(pending paid complete cancelled).sample + cust_name = Faker::RuPaul.queen + cust_email = Faker::Internet.safe_email + mailing_address = Faker::Address.full_address + cc_name = Faker::FunnyName.two_word_name + cc_digit = Faker::Number.number(16) + cc_expiration = Faker::Business.credit_card_expiry_date + cc_cvv = Faker::Number.number(3) + cc_zip = Faker::Number.number(5) + + csv << [status, cust_name, cust_email, mailing_address, cc_name, cc_digit, cc_expiration, cc_cvv, cc_zip] + end +end diff --git a/db/migrate/20181017233257_create_users.rb b/db/migrate/20181017233257_create_users.rb new file mode 100644 index 0000000000..ce7f9b7096 --- /dev/null +++ b/db/migrate/20181017233257_create_users.rb @@ -0,0 +1,11 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.integer :uid + t.string :username + t.string :email + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233513_create_products.rb b/db/migrate/20181017233513_create_products.rb new file mode 100644 index 0000000000..47529e527d --- /dev/null +++ b/db/migrate/20181017233513_create_products.rb @@ -0,0 +1,13 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.string :category + t.string :prod_name + t.string :description + t.float :price + t.integer :inv_qty + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233535_create_orders.rb b/db/migrate/20181017233535_create_orders.rb new file mode 100644 index 0000000000..71335debcf --- /dev/null +++ b/db/migrate/20181017233535_create_orders.rb @@ -0,0 +1,17 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :status + t.string :cust_name + t.string :cust_email + t.integer :mailing_address + t.string :cc_name + t.integer :cc_digit + t.date :cc_expiration + t.integer :cc_cvv + t.integer :cc_zip + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233629_create_reviews.rb b/db/migrate/20181017233629_create_reviews.rb new file mode 100644 index 0000000000..b3b1f0c445 --- /dev/null +++ b/db/migrate/20181017233629_create_reviews.rb @@ -0,0 +1,10 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.integer :rating + t.string :description + + t.timestamps + end + end +end diff --git a/db/migrate/20181017233954_create_categories.rb b/db/migrate/20181017233954_create_categories.rb new file mode 100644 index 0000000000..6cfb9a0962 --- /dev/null +++ b/db/migrate/20181017233954_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + t.string :category + + t.timestamps + end + end +end diff --git a/db/migrate/20181017234540_create_categories_products_join.rb b/db/migrate/20181017234540_create_categories_products_join.rb new file mode 100644 index 0000000000..09fe47a944 --- /dev/null +++ b/db/migrate/20181017234540_create_categories_products_join.rb @@ -0,0 +1,8 @@ +class CreateCategoriesProductsJoin < ActiveRecord::Migration[5.2] + def change + create_table :categories_products do |t| + t.belongs_to :category, index: true + t.belongs_to :product, index: true + end + end +end diff --git a/db/migrate/20181018174629_add_active_image_fields_to_product.rb b/db/migrate/20181018174629_add_active_image_fields_to_product.rb new file mode 100644 index 0000000000..d40a6b8492 --- /dev/null +++ b/db/migrate/20181018174629_add_active_image_fields_to_product.rb @@ -0,0 +1,6 @@ +class AddActiveImageFieldsToProduct < ActiveRecord::Migration[5.2] + def change + add_column :products, :image, :string + add_column :products, :active, :boolean, default: true + end +end diff --git a/db/migrate/20181018181858_create_order_items.rb b/db/migrate/20181018181858_create_order_items.rb new file mode 100644 index 0000000000..c2c48ba42f --- /dev/null +++ b/db/migrate/20181018181858_create_order_items.rb @@ -0,0 +1,12 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + t.integer :order_id + t.integer :product_id + t.integer :qty + t.boolean :shipped + + t.timestamps + end + end +end diff --git a/db/migrate/20181019014144_add_foreign_key_associations.rb b/db/migrate/20181019014144_add_foreign_key_associations.rb new file mode 100644 index 0000000000..7a0e41e91f --- /dev/null +++ b/db/migrate/20181019014144_add_foreign_key_associations.rb @@ -0,0 +1,6 @@ +class AddForeignKeyAssociations < ActiveRecord::Migration[5.2] + def change + add_reference :products, :user, foreign_key: true + add_reference :reviews, :product, foreign_key: true + end +end diff --git a/db/migrate/20181019035503_remove_category_from_products.rb b/db/migrate/20181019035503_remove_category_from_products.rb new file mode 100644 index 0000000000..4a5939d3d9 --- /dev/null +++ b/db/migrate/20181019035503_remove_category_from_products.rb @@ -0,0 +1,5 @@ +class RemoveCategoryFromProducts < ActiveRecord::Migration[5.2] + def change + remove_column :products, :category + end +end diff --git a/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb b/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb new file mode 100644 index 0000000000..757f155371 --- /dev/null +++ b/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb @@ -0,0 +1,5 @@ +class ChangeCcDigitIntToBigint < ActiveRecord::Migration[5.2] + def change + change_column :orders, :cc_digit, :bigint + end +end diff --git a/db/migrate/20181019041908_change_order_mail_address_to_text.rb b/db/migrate/20181019041908_change_order_mail_address_to_text.rb new file mode 100644 index 0000000000..1e95d824b2 --- /dev/null +++ b/db/migrate/20181019041908_change_order_mail_address_to_text.rb @@ -0,0 +1,5 @@ +class ChangeOrderMailAddressToText < ActiveRecord::Migration[5.2] + def change + change_column :orders, :mailing_address, :text + end +end diff --git a/db/migrate/20181019042145_change_reviews_description_to_text.rb b/db/migrate/20181019042145_change_reviews_description_to_text.rb new file mode 100644 index 0000000000..5dfb97e329 --- /dev/null +++ b/db/migrate/20181019042145_change_reviews_description_to_text.rb @@ -0,0 +1,5 @@ +class ChangeReviewsDescriptionToText < ActiveRecord::Migration[5.2] + def change + change_column :reviews, :description, :text + end +end diff --git a/db/migrate/20181019042229_change_products_description_to_text.rb b/db/migrate/20181019042229_change_products_description_to_text.rb new file mode 100644 index 0000000000..5ea37ef928 --- /dev/null +++ b/db/migrate/20181019042229_change_products_description_to_text.rb @@ -0,0 +1,5 @@ +class ChangeProductsDescriptionToText < ActiveRecord::Migration[5.2] + def change + change_column :products, :description, :text + end +end diff --git a/db/migrate/20181019064613_add_provider_col_user.rb b/db/migrate/20181019064613_add_provider_col_user.rb new file mode 100644 index 0000000000..b2fff32f05 --- /dev/null +++ b/db/migrate/20181019064613_add_provider_col_user.rb @@ -0,0 +1,16 @@ +class AddProviderColUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :provider, :string + change_column :users, :uid, :integer, null: false + change_column :users, :username, :string, null: false + + # reset column info to prevent strange things + User.reset_column_information + + # update vote count values in db + User.all.each do |user| + user.update_attribute :provider, 'github' + end + + end +end diff --git a/db/migrate/20181019070105_provider_not_nullable_user.rb b/db/migrate/20181019070105_provider_not_nullable_user.rb new file mode 100644 index 0000000000..54079f4dcf --- /dev/null +++ b/db/migrate/20181019070105_provider_not_nullable_user.rb @@ -0,0 +1,5 @@ +class ProviderNotNullableUser < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string, null: false + end +end diff --git a/db/migrate/20181019214941_changeprovidernill.rb b/db/migrate/20181019214941_changeprovidernill.rb new file mode 100644 index 0000000000..38e7272eb0 --- /dev/null +++ b/db/migrate/20181019214941_changeprovidernill.rb @@ -0,0 +1,5 @@ +class Changeprovidernill < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string + end +end diff --git a/db/migrate/20181019215248_providernil.rb b/db/migrate/20181019215248_providernil.rb new file mode 100644 index 0000000000..ce89d9e851 --- /dev/null +++ b/db/migrate/20181019215248_providernil.rb @@ -0,0 +1,5 @@ +class Providernil < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string, null: true + end +end diff --git a/db/migrate/20181019215535_change_null_user_provider.rb b/db/migrate/20181019215535_change_null_user_provider.rb new file mode 100644 index 0000000000..39203a422a --- /dev/null +++ b/db/migrate/20181019215535_change_null_user_provider.rb @@ -0,0 +1,5 @@ +class ChangeNullUserProvider < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string, null: true + end +end diff --git a/db/migrate/20181019215725_change_provider_in_users.rb b/db/migrate/20181019215725_change_provider_in_users.rb new file mode 100644 index 0000000000..b3dd455255 --- /dev/null +++ b/db/migrate/20181019215725_change_provider_in_users.rb @@ -0,0 +1,5 @@ +class ChangeProviderInUsers < ActiveRecord::Migration[5.2] + def change + change_column :users, :provider, :string, null: true + end +end diff --git a/db/migrate/20181021220825_create_order_statuses.rb b/db/migrate/20181021220825_create_order_statuses.rb new file mode 100644 index 0000000000..4b19173f11 --- /dev/null +++ b/db/migrate/20181021220825_create_order_statuses.rb @@ -0,0 +1,10 @@ +class CreateOrderStatuses < ActiveRecord::Migration[5.2] + def change + # drop_table :order_statuses, force: :cascade + create_table :order_statuses do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20181022054705_add_references_products_orders.rb b/db/migrate/20181022054705_add_references_products_orders.rb new file mode 100644 index 0000000000..b3be5f55d5 --- /dev/null +++ b/db/migrate/20181022054705_add_references_products_orders.rb @@ -0,0 +1,8 @@ +class AddReferencesProductsOrders < ActiveRecord::Migration[5.2] + def change + remove_column :order_items, :product_id + remove_column :order_items, :order_id + add_reference :order_items, :product, foreign_key: true + add_reference :order_items, :order, foreign_key: true + end +end diff --git a/db/migrate/20181022070614_add_reference_order_status_to_order_items.rb b/db/migrate/20181022070614_add_reference_order_status_to_order_items.rb new file mode 100644 index 0000000000..7e11969ad8 --- /dev/null +++ b/db/migrate/20181022070614_add_reference_order_status_to_order_items.rb @@ -0,0 +1,5 @@ +class AddReferenceOrderStatusToOrderItems < ActiveRecord::Migration[5.2] + def change + add_reference :order_items, :order_status, foreign_key: true + end +end diff --git a/db/migrate/20181022232304_remove_reference_order_item_status.rb b/db/migrate/20181022232304_remove_reference_order_item_status.rb new file mode 100644 index 0000000000..12e5e00540 --- /dev/null +++ b/db/migrate/20181022232304_remove_reference_order_item_status.rb @@ -0,0 +1,6 @@ +class RemoveReferenceOrderItemStatus < ActiveRecord::Migration[5.2] + def change + remove_reference(:order_items, :order_status, index: true) + + end +end diff --git a/db/migrate/20181025035101_add_default_item_shipped_false.rb b/db/migrate/20181025035101_add_default_item_shipped_false.rb new file mode 100644 index 0000000000..1a0ae7d566 --- /dev/null +++ b/db/migrate/20181025035101_add_default_item_shipped_false.rb @@ -0,0 +1,5 @@ +class AddDefaultItemShippedFalse < ActiveRecord::Migration[5.2] + def change + change_column_default :order_items, :shipped, false + end +end diff --git a/db/migrate/20181025223530_remove_order_status_table.rb b/db/migrate/20181025223530_remove_order_status_table.rb new file mode 100644 index 0000000000..d2966097bf --- /dev/null +++ b/db/migrate/20181025223530_remove_order_status_table.rb @@ -0,0 +1,5 @@ +class RemoveOrderStatusTable < ActiveRecord::Migration[5.2] + def change + + end +end diff --git a/db/order_seeds.csv b/db/order_seeds.csv new file mode 100644 index 0000000000..dac1543e7b --- /dev/null +++ b/db/order_seeds.csv @@ -0,0 +1,2 @@ +status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip +paid,Darienne Lake,rico.ryan@example.net,"Suite 960 578 Marvin Park, West Astridstad, MT 01415",Lisa Ford,6035639394729400,2019-10-19,389,14426 diff --git a/db/product_seeds.csv b/db/product_seeds.csv new file mode 100644 index 0000000000..21d72bba9b --- /dev/null +++ b/db/product_seeds.csv @@ -0,0 +1,4 @@ +prod_name,user_id,description,price,inv_qty,active,image +I Vote Cupcake,1,Vanilla cake topped with vanilla buttercream and “I Vote Cupcake” edible image,2.50,10,active,https://www.cupcakeroyale.com/wp-content/uploads/2018/08/20180827-I-Vote-Cupcake-003-620x620.jpg +Pumpkin Cardamom,1,Pumpkin spice cake with cardamom cream cheese frosting and spiced pumpkin seeds!,2.75,8,active,https://www.cupcakeroyale.com/wp-content/uploads/2016/02/20170925-Pumpkin-Cardamom-011-sq-620x620.jpg +Fig and Honey,1,Brown butter vanilla cake filled with a rich and citrusy fig compote,2.25,10,active,https://www.cupcakeroyale.com/wp-content/uploads/2017/08/20170817-Fig-and-Honey-120-620x413.jpg diff --git a/db/review_seeds.csv b/db/review_seeds.csv new file mode 100644 index 0000000000..d6681f8d81 --- /dev/null +++ b/db/review_seeds.csv @@ -0,0 +1,5 @@ +rating,description,product_id +3,"It was delicious, like a party in my mouth",1 +5,"Pleasantly spiced and full of pumpkin flavor",2 +4,"Tasted like Fall, the fig compote was super yum!",3 +3,"So so good, like nothing I've ever tasted",2 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..4602181ee8 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,97 @@ +# 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_25_223530) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.string "category" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "categories_products", force: :cascade do |t| + t.bigint "category_id" + t.bigint "product_id" + t.index ["category_id"], name: "index_categories_products_on_category_id" + t.index ["product_id"], name: "index_categories_products_on_product_id" + end + + create_table "order_items", force: :cascade do |t| + t.integer "qty" + t.boolean "shipped", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.bigint "order_id" + t.index ["order_id"], name: "index_order_items_on_order_id" + t.index ["product_id"], name: "index_order_items_on_product_id" + end + + create_table "order_statuses", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "orders", force: :cascade do |t| + t.string "status" + t.string "cust_name" + t.string "cust_email" + t.text "mailing_address" + t.string "cc_name" + t.bigint "cc_digit" + t.date "cc_expiration" + t.integer "cc_cvv" + t.integer "cc_zip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "products", force: :cascade do |t| + t.string "prod_name" + t.text "description" + t.float "price" + t.integer "inv_qty" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "image" + t.boolean "active", default: true + t.bigint "user_id" + t.index ["user_id"], name: "index_products_on_user_id" + end + + create_table "reviews", force: :cascade do |t| + t.integer "rating" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.index ["product_id"], name: "index_reviews_on_product_id" + end + + create_table "users", force: :cascade do |t| + t.integer "uid", null: false + t.string "username", null: false + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "provider" + end + + add_foreign_key "order_items", "orders" + add_foreign_key "order_items", "products" + add_foreign_key "products", "users" + add_foreign_key "reviews", "products" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..7562e82309 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,155 @@ +# 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' +USER_FILE = Rails.root.join('db', 'user_seeds.csv') +puts "Loading raw review data from #{USER_FILE}" + +user_failures = [] +CSV.foreach(USER_FILE, :headers => true) do |row| + user = User.new + user.uid = row['uid'] + user.username = row['username'] + user.email = row['email'] + successful = user.save + if !successful + user_failures << user + puts "Failed to save user: #{user.inspect}" + puts "Error: #{user.errors}" + else + puts "Created user: #{user.inspect}" + end +end + +puts "Added #{User.count} user records" +puts "#{user_failures.length} user failed to save" + + + +PRODUCT_FILE = Rails.root.join('db', 'product_seeds.csv') +puts "Loading raw review data from #{PRODUCT_FILE}" + +product_failures = [] +CSV.foreach(PRODUCT_FILE, :headers => true) do |row| + product = Product.new + product.prod_name = row['prod_name'] + product.user_id = row['user_id'] + product.description = row['description'] + product.price = row['price'] + product.inv_qty = row['inv_qty'] + product.active = row['active'] + product.image = row['image'] + successful = product.save + if !successful + product_failures << product + puts "Failed to save product: #{product.inspect}" + puts "Error: #{product.errors}" + else + puts "Created product: #{product.inspect}" + end +end + +puts "Added #{Product.count} product records" +puts "#{product_failures.length} product failed to save" + +ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') +puts "Loading raw order data from #{ORDER_FILE}" + +order_failures = [] +CSV.foreach(ORDER_FILE, :headers => true) do |row| + order = Order.new + order.status = row['status'] + order.cust_name = row['cust_name'] + order.cust_email = row['cust_email'] + order.mailing_address = row['mailing_address'] + order.cc_name = row['cc_name'] + order.cc_digit = row['cc_digit'] + order.cc_expiration = row['cc_expiration'] + order.cc_cvv = row['cc_cvv'] + order.cc_zip = row['cc_zip'] + successful = order.save + if !successful + order_failures << order + puts "Failed to save order: #{order.inspect}" + puts "Error: #{order.errors}" + else + puts "Created order: #{order.inspect}" + end +end + +puts "Added #{Order.count} order records" +puts "#{order_failures.length} order failed to save" + + + + + +REVIEW_FILE = Rails.root.join('db', 'review_seeds.csv') +puts "Loading raw review data from #{REVIEW_FILE}" + +review_failures = [] +CSV.foreach(REVIEW_FILE, :headers => true) do |row| + review = Review.new + review.rating = row['rating'] + review.description = row['description'] + review.product_id = row['product_id'] + successful = review.save + if !successful + review_failures << review + puts "Failed to save review: #{review.inspect}" + puts "Error: #{review.errors}" + else + puts "Created review: #{review.inspect}" + end +end + +puts "Added #{Review.count} review records" +puts "#{review_failures.length} review failed to save" + + + + +#Populate order_items table + +# OrderItem.create(order_id: 2, product_id: 1, qty: 1, shipped: false) +# add 3 items to first order +# Order.first.order_items << Product.sample(3) +# # + + +CATEGORY_FILE = Rails.root.join('db', 'category_seeds.csv') +puts "Loading raw review data from #{REVIEW_FILE}" + +category_failures = [] +CSV.foreach(CATEGORY_FILE, :headers => true) do |row| + category = Category.new + category.category = row['category'] + + successful = category.save + if !successful + category_failures << category + puts "Failed to save category: #{category.inspect}" + puts "Error: #{category.errors}" + else + puts "Created category: #{category.inspect}" + end +end + +puts "Added #{Category.count} category records" +puts "#{category_failures.length} category failed to save" + + +Product.all.each do |product| + product.categories << Category.first +end + + +OrderStatus.delete_all +OrderStatus.create! id: 1, name: "In Progress" +OrderStatus.create! id: 2, name: "Placed" +OrderStatus.create! id: 3, name: "Shipped" +OrderStatus.create! id: 4, name: "Cancelled" diff --git a/db/user_seeds.csv b/db/user_seeds.csv new file mode 100644 index 0000000000..ccc1f078c7 --- /dev/null +++ b/db/user_seeds.csv @@ -0,0 +1,2 @@ +uid,username,email +1,cupcakeroyale,cupcakes@cupcakes.com 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/temp.txt b/temp.txt new file mode 100644 index 0000000000..40ae76a92d --- /dev/null +++ b/temp.txt @@ -0,0 +1,12 @@ +rails generate scaffold user uid:integer username:string email:string + +rails generate scaffold product category:string prod_name:string description:string price:float inv_qty:integer + +rails generate scaffold order status:string cust_name:string cust_email:string mailing_address:integer cc_name:string cc_digit:integer cc_expiration:date cc_cvv:integer cc_zip:integer + +rails generate scaffold review rating:integer description:string + + +rails g migration CreateCategoriesProductsJoin + +rails db:migrate \ No newline at end of file diff --git a/test/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/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb new file mode 100644 index 0000000000..4eae0b05ab --- /dev/null +++ b/test/controllers/carts_controller_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +describe CartsController do + + let (:product1) { products(:cake1) } + + let (:order_item_hash1) { + { + order_item: { + product_id: product1.id, + qty: 5 + } + } + } + + + it "should get a cart's show if order exists" do + post order_items_path, params: order_item_hash1 + order_id = Order.last.id + + get cart_path(order_id) + + must_respond_with :success + + end + + it "should respond with not_found given an invalid order_id" do + order_id = -1 + + get cart_path(order_id) + + must_respond_with :not_found + + end + +end diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..1ae548a028 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +describe CategoriesController do + it "should get index" do + get categories_index_url + value(response).must_be :success? + end + + it "should get new" do + get categories_new_url + value(response).must_be :success? + end + + it "should get create" do + get categories_create_url + value(response).must_be :success? + end + +end diff --git a/test/controllers/order_items_controller_test.rb b/test/controllers/order_items_controller_test.rb new file mode 100644 index 0000000000..10f938e3fe --- /dev/null +++ b/test/controllers/order_items_controller_test.rb @@ -0,0 +1,241 @@ +require "test_helper" + +describe OrderItemsController do + + let (:product1) { products(:cake1) } + let (:product2) { products(:cake3) } + + let (:order_item_hash1) { + { + order_item: { + product_id: product1.id, + qty: 5 + } + } + } + + let (:order_item_hash2) { + { + order_item: { + product_id: product2.id, + qty: 3 + } + } + } + + let (:exceeds_inventory) { + { + order_item: { + product_id: product1.id, + qty: 8 + } + } + } + + let (:update_order_item1) { + { + order_item: { + product_id: product1.id, + qty: 3 + } + } + } + + let (:invalid_data) { + { + order_item: { + product_id: product1.id, + qty: nil + } + } + } + + describe 'create' do + + it 'can create a new order line item when order does not already exist' do + + orders_before = Order.count + + expect { + post order_items_path, params: order_item_hash1 + }.must_change 'OrderItem.count', 1 + + orders_after = Order.count + order_id = Order.last.id + + must_respond_with :redirect + must_redirect_to cart_path(order_id) + + expect(orders_after).must_equal orders_before + 1 + expect(OrderItem.last.product_id).must_equal product1.id + expect(OrderItem.last.order_id).must_equal order_id + end + + it 'can create a new order line item to existing order' do + + post order_items_path, params: order_item_hash1 + order_id = Order.last.id + + expect { + post order_items_path, params: order_item_hash2 + }.must_change 'OrderItem.count', 1 + + must_respond_with :redirect + must_redirect_to cart_path(order_id) + expect(OrderItem.last.product_id).must_equal product2.id + expect(OrderItem.last.order_id).must_equal order_id + end + + it 'can not add a line order item if quantity exceeds inventory' do + + expect { + post order_items_path, params: exceeds_inventory + }.wont_change 'OrderItem.count' + + must_respond_with :redirect + must_redirect_to product_path(product1.id) + + end + + end + + describe 'update' do + + before do + post order_items_path, params: order_item_hash1 + @order_id = Order.last.id + @order_item_id = OrderItem.last.id + @before_qty = OrderItem.find_by(id: @order_item_id).qty + end + + it 'can update an existing order line item with valid data' do + + expect { + patch order_item_path(@order_item_id), params: update_order_item1 + }.wont_change 'OrderItem.count' + + after_qty = OrderItem.find_by(id: @order_item_id).qty + + expect(after_qty).must_equal update_order_item1[:order_item][:qty] + must_respond_with :redirect + must_redirect_to cart_path(@order_id) + + end + + it 'will not update an existing order line item with invalid data' do + + expect { + patch order_item_path(@order_item_id), params: invalid_data + }.wont_change 'OrderItem.count' + + after_qty = OrderItem.find_by(id: @order_item_id).qty + + expect(after_qty).must_equal @before_qty + + must_respond_with :redirect + must_redirect_to root_path + end + + it 'will redirect when a line order item does not exist to update' do + + expect { + patch order_item_path(-1), params: update_order_item1 + }.wont_change 'OrderItem.count' + + must_respond_with :redirect + must_redirect_to root_path + + end + + it 'will will not update existing order line item when qty exceeds inventory count' do + + expect { + patch order_item_path(@order_item_id), params: exceeds_inventory + }.wont_change 'OrderItem.count' + + after_qty = OrderItem.find_by(id: @order_item_id).qty + + expect(after_qty).must_equal @before_qty + + must_respond_with :redirect + must_redirect_to product_path(product1.id) + end + end + + describe 'destroy' do + + before do + post order_items_path, params: order_item_hash1 + @order_id = Order.last.id + @order_item_id = OrderItem.last.id + @before_qty = OrderItem.find_by(id: @order_item_id).qty + end + + it 'can delete an existing order line item' do + + expect{ + delete order_item_path(@order_item_id) + }.must_change 'OrderItem.count', -1 + + must_respond_with :redirect + must_redirect_to cart_path(@order_id) + expect(OrderItem.find_by(id: @order_item_id)).must_be_nil + end + + it 'will render not_found when a line order item does not exist to delete' do + end + + end + + describe 'cart_direct' do + + it 'can add a line order item with a qty of 1 when existing order exists' do + post order_items_path, params: order_item_hash1 + order_id = Order.last.id + + new_item = products(:cake3) + + expect { + post quick_shop_path(new_item.id) + }.must_change 'OrderItem.count', 1 + + must_respond_with :redirect + must_redirect_to cart_path(order_id) + expect(OrderItem.last.product_id).must_equal new_item.id + expect(OrderItem.last.order_id).must_equal order_id + + end + + it 'can add a line order item with a qty of 1 when existing order does not exist' do + + orders_before = Order.count + new_item = products(:cake3) + + expect { + post quick_shop_path(new_item.id) + }.must_change 'OrderItem.count', 1 + + orders_after = Order.count + order_id = Order.last.id + + must_respond_with :redirect + must_redirect_to cart_path(order_id) + + expect(orders_after).must_equal orders_before + 1 + expect(OrderItem.last.product_id).must_equal new_item.id + expect(OrderItem.last.order_id).must_equal order_id + end + + it 'can not add a line order item if item is out of stock' do + product = products(:brownie) + + expect { + post quick_shop_path(product.id) + }.wont_change 'OrderItem.count' + + must_respond_with :redirect + must_redirect_to products_path + end + end + +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..8bb3a58a44 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,158 @@ +require "test_helper" + +describe OrdersController do + let(:order) { orders :one } + + it "gets index" do + get orders_url + + value(response).must_be :successful? + end + + describe "show" do + + it "it shows an order for that merchant" do + user = users(:laura) + perform_login(user) + + id = orders(:one).id + + get orders_path(id) + + value(response).must_be :successful? + end + + it "will not allow another merchant to view an order without their product" do + user = users(:laura) + perform_login(user) + + id = orders(:two).id + + get orders_path(id) + + value(response).must_be :successful? + end + end + + describe "update" do + # placing the order we use update + let (:product) { products(:cake1) } + + let (:order_item_hash) { + { + order_item: { + product_id: product.id, + qty: 5 + } + } + } + + let (:confirm_hash) do + { + order: { + cc_cvv: order.cc_cvv, + cc_digit: order.cc_digit, + cc_expiration: order.cc_expiration, + cc_name: order.cc_name, + cc_zip: order.cc_zip, + cust_email: order.cust_email, + cust_name: order.cust_name, + mailing_address: order.mailing_address, + status: order.status + } + } + end + #PATCH /orders/:id + it "will allow merchant confirm a purchase with valid params" do + user = users(:laura) + perform_login(user) + + expect { + post order_items_path, params: order_item_hash + }.must_change 'OrderItem.count', 1 + + id = Order.last.id + + expect { + patch order_path(id), params: confirm_hash + }.wont_change "Order.count" + + expect(flash.now[:success]).must_equal "Order was accepted" + expect(order.cc_name).must_equal confirm_hash[:order][:cc_name] + expect(order.cust_email).must_equal confirm_hash[:order][:cust_email] + end + + it "does not confirm a order with zero items in the cart" do + user = users(:laura) + perform_login(user) + + expect { + post order_items_path, params: order_item_hash + }.must_change 'OrderItem.count', 1 + + order = Order.last + order.order_items.destroy_all + + expect { + patch order_path(order.id), params: confirm_hash + }.wont_change "Order.count" + + must_redirect_to products_path + expect(flash[:warning]).must_equal "You have zero items in your cart" + end + + it "allow a guest user add items to cart" do + expect { + post order_items_path, params: order_item_hash + }.must_change 'OrderItem.count', 1 + + id = Order.last.id + + expect { + patch order_path(id), params: confirm_hash + }.wont_change "Order.count" + + expect(flash.now[:success]).must_equal "Order was accepted" + end + + it "does not complete an order with invalid params" do + confirm_hash[:order][:cust_name] = nil + + expect { + post order_items_path, params: order_item_hash + }.must_change 'OrderItem.count', 1 + + id = Order.last.id + + expect { + patch order_path(id), params: confirm_hash + }.wont_change "Order.count" + + must_respond_with :success + expect(flash.now[:warning]).must_equal 'Order was not not created' + end + + it "does not load an invalid order" do + id = -1 + + expect { + patch order_path(id) + }.wont_change 'Order.count' + + must_redirect_to order_path + expect(flash[:now]).must_equal "Order does not exsist" + end + + end + + # describe "destroy" do + # it "destroys order" do + # expect { + # delete order_url(order) + # }.must_change "Order.count", -1 + # + # must_redirect_to orders_path + # end + # end + +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..228f527a2a --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,283 @@ +require "test_helper" + +describe ProductsController do + let(:product) { build(:product) } + + it "gets index" do + get products_url + value(response).must_be :successful? + end + + describe "new" do + + it "gets new form for a logged in user" do + user = users(:laura) + perform_login(user) + + get new_product_path + value(response).must_be :successful? + end + + it "is an invalid request if merchant is not logged in" do + get new_product_path + + must_redirect_to root_path + value(response).must_be :redirection? + expect(flash[:danger]).must_equal "You must log in to access this feature" + end + end + + describe "create" do + + it "creates product" do + user = users(:laura) + perform_login(user) + + id = users(:laura).id + product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: id } } + + expect { + post products_path, params: product_hash + }.must_change "Product.count" + + must_redirect_to user_path(session[:user_id]) + expect(flash[:notice]).must_equal "#{product.prod_name} was added to your inventory." + end + + it "is an forbidden request if user is not logged in" do + product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: nil } } + + expect { + post products_path, params: product_hash + }.wont_change "Product.count" + + must_redirect_to root_path + expect(response.response_code).must_equal 302 + end + end + + describe "show" do + + it "show a single product detail page" do + id = Product.first.id + + get product_path(id) + value(response).must_be :successful? + end + + it "should repond with not_found if given an invalid id" do + id = -1 + + get product_path(id) + + must_respond_with :not_found + end + + end + + describe "edit" do + + it "gets edit form page for a logged in merchant" do + user = users(:laura) + perform_login(user) + + id = products(:cake1).id + + get edit_product_path(id) + value(response).must_be :successful? + end + + it "should respond with not_found if an invalid product id is entered" do + user = users(:laura) + perform_login(user) + + id = products(:cake2).id + + get edit_product_path(id) + + must_redirect_to product_path(id) + expect(flash[:danger]).must_equal "You don't have access to edit this product." + end + + it "does not give a logged out user access to a product edit page" do + id = products(:cake2).id + + get edit_product_path(id) + + must_redirect_to root_path + end + + it "should respond with not_found if given an invalid id" do + user = users(:laura) + perform_login(user) + + id = -1 + + get edit_product_path(id) + + must_respond_with :not_found + end + end + + describe "update" do + let(:laura) {users(:laura)} + let (:product_hash) do + { + product: { + prod_name: product.prod_name, + description: product.description, + price: product.price, + inv_qty: product.inv_qty, + user: laura.id + } + } + end + + it "a merchant can update their product" do + user = users(:laura) + perform_login(user) + + id = products(:cake1).id + + expect { + patch product_path(id), params: product_hash + }.wont_change "Product.count" + + must_redirect_to product_path + expect(flash[:notice]).must_equal "#{product.prod_name} was successfully updated." + + new_product = Product.find_by(id: id) + + expect(new_product.prod_name).must_equal product_hash[:product][:prod_name] + expect(new_product.description).must_equal product_hash[:product][:description] + end + + it "a user not logged in cant update a product" do + id = products(:cake1).id + + expect { + patch product_path(id), params: product_hash + }.wont_change "Product.count" + + must_redirect_to root_path(id) + end + + it "a gives an error if the product params are invalid" do + user = users(:laura) + perform_login(user) + + cake1 = products(:cake1) + product_hash[:product][:prod_name] = cake1.prod_name + + id = products(:cake2).id + old_product = products(:cake2) + + expect { + patch product_path(id), params: product_hash + }.wont_change "Product.count" + + new_product = Product.find(id) + + must_respond_with :success + expect(old_product.prod_name).must_equal new_product.prod_name + expect(old_product.description).must_equal new_product.description + expect(flash[:warning]).must_equal "Edit was unsuccessful" + end + + it "gives not_found for a product that doesnt exist" do + id = -1 + + expect { + patch product_path(id) + }.wont_change 'Product.count' + + must_respond_with :not_found + end + end + + describe "category" do + + it "finds a category for product" do + id = Category.first.id + + get category_path(id) + + value(response).must_be :successful? + end + + it "redirects to root_path for invalid category" do + id = 56 + + get category_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "Category is invalid" + end + end + + + describe "merchant" do + + it "finds a merchant for a product" do + id = User.first.id + + get merchant_path(id) + + value(response).must_be :successful? + end + + it "redirects to root_path for invalid category" do + id = -56 + + get merchant_path(id) + + # value(response).must_be :successful? + must_redirect_to root_path + expect(flash[:warning]).must_equal "User is invalid" + end + + end + + describe "status" do + + it "changes an inactive product to active" do + user = users(:laura) + perform_login(user) + + product = Product.find_by(prod_name: "a wedding cake") + + patch product_status_path(product) + + # must_respond_with :redirect + expect(product.active).must_equal true + end + + it "changes an active product to inactive" do + user = users(:laura) + perform_login(user) + + product = Product.find_by(prod_name: "a wedding cake") + product.active = true + product.save + + patch product_status_path(product) + product_new = Product.find_by(prod_name: "a wedding cake") + + # must_respond_with :redirect + expect(product_new.active).must_equal false + expect(flash[:notice]).must_equal "#{product.prod_name} status successfully retired." + end + + it "reponds with not found for invalid product" do + id = -56 + + patch product_status_path(id) + + # value(response).must_be :successful? + must_respond_with :not_found + end + + end + +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..a8e29675d5 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,67 @@ +require "test_helper" + +describe ReviewsController do + let(:review) { reviews :one } + + it "gets index" do + get reviews_url + value(response).must_be :successful? + end + + describe "new" do + + it "gets the form with the new review page" do + id = products(:cake1).id + + get new_product_review_path(id) + value(response).must_be :successful? + end + + end + + describe "create" do + + it "creates a new review given valid params" do + id = products(:cake1).id + review_hash = { review: { description: review.description, rating: review.rating} } + + expect { + post product_reviews_path(id), params: review_hash + }.must_change "Review.count", 1 + + must_redirect_to product_path(id) + + expect(Review.last.description).must_equal review_hash[:review][:description] + expect(Review.last.rating).must_equal review_hash[:review][:rating] + end + + it "respond with an redirect for invalid params" do + id = products(:cake1).id + review_hash = { review: { description: review.description } } + + expect { + post product_reviews_path(id), params: review_hash + }.wont_change "Review.count" + + must_respond_with :success + expect(flash[:warning]).must_equal "Please enter all fields" + end + + it "respond with an error if merchant reviews their own product" do + user = users(:laura) + perform_login(user) + + id = products(:cake1).id + review_hash = { review: { description: review.description, rating: review.rating} } + + expect { + post product_reviews_path(id), params: review_hash + }.wont_change "Review.count" + + must_redirect_to products_path + expect(flash[:warning]).must_equal "You can't review your own Product" + end + end + + +end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..8663792f55 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,86 @@ +require "test_helper" + +describe SessionsController do + # it "should get login" do + # get login_path + # value(response).must_be :success? + # end + # + # it "should get new" do + # get sessions_new_url + # value(response).must_be :success? + # end + # + # it "should get destroy" do + # get sessions_destroy_url + # value(response).must_be :success? + # end + + describe "auth_callback" do + + it "logs in an existing user" do + start_count = User.count + user = users(:grace) + + perform_login(user) + + must_redirect_to root_path + expect(flash[:result_text]).must_match /Successfully logged*/ + session[:user_id].must_equal user.id + + # Should *not* have created a new user + User.count.must_equal start_count + end + + it "can login in a new user with good data" do + user = users(:ada) + # remove ada test user from test db + user.destroy + # login ada as new user to test db + perform_login(user) + # user count should increase by 1 + expect do + get auth_callback_path(:github).must_change('User.count' +1) + end + # redirect to root_path + must_redirect_to root_path + expect(flash[:result_text]).must_match /Successfully created*/ + expect(session[:user_id]).wont_be_nil + end + + it "rejects an invalid user login with bad data" do + user = users(:ada) + user.uid = nil + + perform_login(user) + + expect do + get auth_callback_path(:github).wont_change 'User.count' + end + + must_respond_with :bad_request + expect(session[:user_id]).must_be_nil + + end + + describe "logout" do + it 'can log out' do + user = users(:grace) + + perform_login(user) + + delete logout_path + + expect do + get auth_callback_path(:github).wont_change 'User.count' + end + + must_redirect_to root_path + expect(session[:user_id]).must_be_nil + + end + + + end + end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..7609157f04 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,66 @@ +require "test_helper" + +describe UsersController do + let(:user) { users :ada } + + it "gets new" do + get new_user_url + value(response).must_be :successful? + end + + it "creates user" do + user_hash= { + user: { + email: 'user3@gmail.com', + uid: 2, + username: 'newuser' + } + } + expect { + post users_path, params: user_hash + }.must_change "User.count", 1 + + must_redirect_to root_path + end + + + # User test are create and and show order fulfillment if logged in + describe "Logged in users" do + before do + perform_login(users(:grace)) + end + + describe "show" do + # Just the standard show tests + it "succeeds for logged in user" do + get user_path(session[:user_id]) + must_respond_with :success + + end + + it "returns 404 a user who is not the logged in user" do + a = users(:ada) + a_id = a.id + get user_path(a_id) + must_redirect + end + end + + # can change an items status to shipped + # can add new products + # can retire a product + + end + + describe "Guest users" do + # it "returns 404 a user who is not the logged in user" do + # get user_path(session[:user_id] - 1) + # must_respond_with :forbidden + # end + + + + end +end + + diff --git a/test/factories/category.rb b/test/factories/category.rb new file mode 100644 index 0000000000..53208610a8 --- /dev/null +++ b/test/factories/category.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :category do + category { Faker::Name.first_name } + end +end diff --git a/test/factories/order.rb b/test/factories/order.rb new file mode 100644 index 0000000000..5aa68a6d8d --- /dev/null +++ b/test/factories/order.rb @@ -0,0 +1,13 @@ +FactoryBot.define do + factory :order do + status { %w(pending paid complete cancelled).sample} + cust_name { Faker::RuPaul.queen} + cust_email { Faker::Internet.safe_email} + mailing_address { Faker::Address.full_address} + cc_name { Faker::FunnyName.two_word_name} + cc_digit { "1" * 16} + cc_expiration { Faker::Business.credit_card_expiry_date} + cc_cvv { Faker::Number.number(3) } + cc_zip { Faker::Number.number(5) } + end +end diff --git a/test/factories/product.rb b/test/factories/product.rb new file mode 100644 index 0000000000..7055e310d7 --- /dev/null +++ b/test/factories/product.rb @@ -0,0 +1,12 @@ +FactoryBot.define do + factory :product do + # category { %w(birthday wedding chocolate vanilla buttercream).sample} + prod_name { Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor} + description { Faker::Coffee.notes} + price { Faker::Number.decimal(2, 2)} + inv_qty { Faker::Number.between(0, 30)} + active { Faker::Boolean.boolean} + image { "image test"} + user + end +end diff --git a/test/factories/user.rb b/test/factories/user.rb new file mode 100644 index 0000000000..eef4244669 --- /dev/null +++ b/test/factories/user.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :user do + uid { rand(1..(2**31)).to_s} + provider { "github" } + username { Faker::Name.first_name } + email { Faker::Internet.email } + end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..8492e33dc5 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + category: birthday + +two: + category: wedding + +three: + category: chocolate diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..d78a92642c --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +line1: + order: one + product: cake1 + qty: 2 + shipped: false + +line2: + order: two + product: cake2 + qty: 2 + shipped: false diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..5e5b0dce24 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,45 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + status: Paid + cust_name: Laura + cust_email: laura@gmail.com + mailing_address: 123 Front St. + cc_name: Laura Liz + cc_digit: 1111111111111111 + cc_expiration: 2018-10-17 + cc_cvv: 123 + cc_zip: 98765 + +two: + status: pending + cust_name: Grace + cust_email: grace@gmail.com + mailing_address: 123 Front St. + cc_name: Laura Liz + cc_digit: 1111111111111111 + cc_expiration: 2018-10-17 + cc_cvv: 1 + cc_zip: 1 + +three: + status: pending + cust_name: ada + cust_email: ada@gmail.com + mailing_address: 1 + cc_name: MyString + cc_digit: 1111111111111111 + cc_expiration: 2018-10-17 + cc_cvv: 123 + cc_zip: 98765 + +three: + status: pending + cust_name: ada + cust_email: grace@gmail.com + mailing_address: 123 Front St. + cc_name: Laura Liz + cc_digit: 1111111111111111 + cc_expiration: 2018-10-17 + cc_cvv: 123 + cc_zip: 98765 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..88a704fa9a --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,32 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +cake1: + + prod_name: a wedding cake + description: yum + price: 15.5 + inv_qty: 5 + user: laura + +cake2: + + prod_name: chocolate goodness + description: the best + price: 19.5 + inv_qty: 5 + user: grace + + +cake3: + prod_name: vanilla plains + description: real vanilla + price: 20.5 + inv_qty: 3 + user: grace + +brownie: + prod_name: chocolate brownie + description: decadent + price: 19.5 + inv_qty: 0 + user: ada diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..27fde1e798 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + rating: 1 + description: MyString + product: cake1 + +two: + rating: 1 + description: MyString diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..97b51aa1d9 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,22 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + + +laura: + provider: github + uid: 13371338 + email: lbird@ada.com + username: Lady Bird + + +ada: + provider: github + uid: 2354234 + email: ada@lovelace.com + username: countess_ada + + +grace: + provider: github + uid: 13371337 + email: grace@hopper.com + username: graceful_hopps 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/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..9a2ad9c30b --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,29 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new } + + it "must be valid" do + value(category).must_be :valid? + end + + describe 'validations' do + it 'has required fields' do + fields = [:category] + + fields.each do |field| + expect(book).must_respond_to field + end + end + end + + describe 'relationship' do + let(:product) { products(:cake1) } + it 'belongs to product' do + cat = product.category + + expect(cat).must_be_instance_of Product + expect(cat.id).must_equal product.category_id + end + end +end diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..3f69f96891 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,81 @@ +require "test_helper" + +describe OrderItem do + let(:order_item) { order_items(:line1) } + + describe 'relationships' do + it 'must belong to a product' do + product = order_item.product + + expect(product).must_be_instance_of Product + expect(product.id).must_equal order_item.product.id + + end + + it 'must belong to an order' do + order = order_item.order + + expect(order).must_be_instance_of Order + expect(order.id).must_equal order_item.order.id + end + end + + describe 'validations' do + it 'must be valid with all fields' do + another_order_item = order_items(:line2) + + expect(order_item).must_be :valid? + + expect(another_order_item).must_be :valid? + end + + it 'must have qty' do + order_item.qty = nil + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :qty + end + + it 'must have a quantity greater than 0' do + order_item.qty = 0 + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :qty + end + + it 'must have a quantity that is an integer' do + order_item.qty = 1.5 + + valid = order_item.save + + expect(valid).must_equal false + expect(order_item.errors.messages).must_include :qty + end + + end + + describe 'subtotal' do + it 'must be able to calculate subtotal for order_item' do + subtotal = order_item.subtotal + + expect(subtotal).must_equal order_item.product.price * order_item.qty + end + + it 'must be able to calculate subtotal for order_item with qty of 0' do + order_item.qty = 0 + order_item.save + + subtotal = order_item.subtotal + + expect(subtotal).must_equal 0 + end + + end + + + +end diff --git a/test/models/order_status_test.rb b/test/models/order_status_test.rb new file mode 100644 index 0000000000..ab042fbd3e --- /dev/null +++ b/test/models/order_status_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderStatus do + let(:order_status) { OrderStatus.new } + + it "must be valid" do + value(order_status).must_be :valid? + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..7290b3298f --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,227 @@ +require "test_helper" + +describe Order do + + describe "items_in_cart" do + + it "returns the total quantity of items in cart" do + order = orders(:one) + number = order.items_in_cart + + expect(number).must_equal 4 + end + + it "returns 0 when no items in cart" do + order = orders(:three) + number = order.items_in_cart + + expect(number).must_equal 0 + end + end + + describe "place order" do + + it "reduces inventory quantity by order item quantity" do + order = orders(:one) + inv_qty_before = order.order_items.first.product.inv_qty + order_qty = order.order_items.first.qty + + order.place_order + order = orders(:one) + + inv_qty_after = order.order_items.first.product.inv_qty + expect(order.order_items.first.product.inv_qty).must_equal inv_qty_after + expect(inv_qty_after).must_equal inv_qty_before - order_qty + end + end + + describe "total_price" do + + it "gets the correct total price when the order has items" do + order = orders(:one) + price_first_item = order.order_items.first.product.price * order.order_items.first.qty + price_last_item = order.order_items.last.product.price * order.order_items.last.qty + total_price = price_first_item + price_last_item + + order.total_price + + expect(order.total_price).must_equal total_price + end + end + +describe "validation" do + let(:user) { user(:one) } + before do + 1.times do + order = create(:order) + describe "validation" do + let(:order) { build(:order) } + + it "must be valid with all parameters" do + expect(order.valid?).must_equal true + end + + it "must be invalid without a customer name " do + order.cust_name = nil + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cust_name + end + end + + # it "must be a valid order" do + # + # expect(order.valid?).must_equal true + # end + + it "must be invalid without a customer name " do + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cust_email + end + + order.cust_name = nil + + expect(order.cust_name.valid?).must_equal false + expect(order.errors.messages).must_include :cust_name + end + + it "must be invalid without an email address or correct data type " do + order.cust_email = nil + order.cust_email = 123 + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :mailing_address + end + + expect(order.cust_email.valid?).must_equal false + expect(order.errors.messages).must_include :cust_email + end + + + it "must be invalid without a mailing address" do + order.mailing_address = nil + + expect(order.mailing_address.valid?).must_equal false + expect(order.errors.messages).must_include :mailing_address + end + + + it "must be invalid without a customer name" do + order.cc_name = nil + + expect(order.cc_name.valid?).must_equal false + expect(order.errors.messages).must_include :cc_name + end + + # it "must be invalid if date has expired" do + # order.cc_expiration = 2018/08/21 + # + # expect(order.cc_name.valid?).must_equal false + # expect(order.errors.messages).must_include :cc_expiration + # end + + it "must be invalid with more than 16 digits for credit card" do + order.cc_digit = 123 + order2.cc_digit = "hi" + + expect(order.cc_digit.valid?).must_equal false + expect(order2.cc_digit.valid?).must_equal false + expect(order.errors.messages).must_include :cc_digit + expect(order2.errors.messages).must_include :cc_digit + end + + it "must have only 3 digits for CVV" do + order.cc_cvv = 12 + order2.cc_cvv = "hi" + + expect(order.cc_cvv.valid?).must_equal false + expect(order2.cc_cvv.valid?).must_equal false + expect(order.errors.messages).must_include :cc_cvv + expect(order2.errors.messages).must_include :cc_cvv + end + + it "must be 5 digits in length for zip code" do + order.cc_zip = 12 + order2.cc_zip = "hi" + + expect(order.cc_zip.valid?).must_equal false + expect(order2.cc_zip.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip + expect(order2.errors.messages).must_include :cc_zip + end + it "must be invalid without a customer name" do + order.cust_name = nil + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cust_name + end + + # it "must be invalid if date has expired" do + # order.cc_expiration = 2018/08/21 + # + # expect(order.cc_name.valid?).must_equal false + # expect(order.errors.messages).must_include :cc_expiration + # end + + it "must be invalid with less than 16 digits for credit card" do + order.cc_digit = 123 + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_digit + + order.cc_digit = "hi" + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_digit + end + + it "must have only 3 digits for CVV" do + order.cc_cvv = 12 + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_cvv + + order.cc_cvv = "hi" + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_cvv + end + + it "must have only 16 digits for Credit Card number" do + order.cc_digit = 1234123412341234 + + expect(order.valid?).must_equal true + end + + it "must be 5 digits in length for zip code" do + order.cc_zip = 1255 + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip + + order.cc_zip = "hi" + + expect(order.valid?).must_equal false + expect(order.errors.messages).must_include :cc_zip + end + + + # describe "relations" do + # + # it "belong to a product" do + # expect(order.user).must_be_instance_of User + # expect(order.user.orders).must_include Order + # end + # end + +end +describe "relations" do + + it "belong to a product" do + order = product.order + #add the yml file + expect(order).must_be_instance_of Product + expect(order.id).must_equal product.order_id + end +end + +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..c2115fbe04 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,61 @@ +require "test_helper" + +describe Product do + let(:product) { build(:product) } + let(:product2) { create(:product)} + + describe "validation" do + + it "must be valid" do + expect(product.valid?).must_equal true + end + + it "must be invalid without a product name " do + product.prod_name = nil + + expect(product.valid?).must_equal false + expect(product.errors.messages).must_include :prod_name + end + + it "must be invalid without a description" do + product.description = nil + + expect(product.valid?).must_equal false + expect(product.errors.messages).must_include :description + end + + + it "must be invalid without a price" do + product.price = nil + + expect(product.valid?).must_equal false + expect(product.errors.messages).must_include :price + end + + + it "must have a unique product name" do + product.prod_name = product2.prod_name + expect(product.valid?).must_equal false + end + + + end + + + describe "relations" do + + # it "belong to a user" do + # expect(product.user).must_be_instance_of User + # expect(product.user.products).must_include product + # end + + it "must respond to reviews" do + expect(product).must_respond_to :reviews + end + + it "responds to categories" do + expect(product).must_respond_to :categories + end + + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..507bfc4621 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +describe Review do + let(:review) { Review.new(rating: "1", description: "this is great", product: Product.new) } + + it "must be valid" do + expect(review.valid?).must_equal true + end + + describe "relations" do + + it "must respond to product" do + expect(review).must_respond_to :product + end + + end + + describe "validations" do + + it "invalid without a rating" do + review.rating = nil + expect(review.valid?).must_equal false + expect(review.errors.messages).must_include :rating + end + + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..cd9152db7b --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,49 @@ +require "test_helper" + +describe User do + # let(:user) { User.new } + # + # it "must be valid" do + # value(user).must_be :valid? + # end + + describe "relations" do + before do + user = User.new + end + + it "has a list of products" do + + user = product(:create) + + user.must_respond_to :product + user.products.each do |product| + product.must_be_kind_of Product + end + end + + end + + describe "validations" do + it "requires a username" do + user = User.new + user.valid?.must_equal false + user.errors.messages.must_include :username + end + + it "requires a unique username" do + username = "test username" + user1 = User.new(username: username) + + # This must go through, so we use create! + user1.save! + + user2 = User.new(username: username) + result = user2.save + result.must_equal false + user2.errors.messages.must_include :username + end + + + end +end 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..9e687b9149 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,59 @@ +require 'simplecov' +SimpleCov.start + +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" # for Colorized output +require 'faker' + + +# 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... + class ActiveSupport::TestCase + include FactoryBot::Syntax::Methods + end + + #oauth testing setup + def setup + OmniAuth.config.test_mode = true + end + # Test helper method to generate a mock auth hash + # for fixture data + def mock_auth_hash(user) + return { + provider: user.provider, + uid: user.uid, + info: { + email: user.email, + nickname: user.username + } + } + end + + # oauth mock login + def perform_login(user) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + end + +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