diff --git a/ in product show page b/ in product show page new file mode 100644 index 0000000000..750c9a7c8d --- /dev/null +++ b/ in product show page @@ -0,0 +1,2 @@ +[master 8afd6c0] edited bottom logo and extra / + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..3c910f0305 Binary files /dev/null and b/.DS_Store differ diff --git a/.env b/.env new file mode 100644 index 0000000000..5e37e371b5 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +GITHUB_CLIENT_ID: b707c24d33d96e93b82d +GITHUB_CLIENT_SECRET: fbf345b847f0d51c1ee2f6c10f0729bd04b3395c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..1434065d91 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# 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 +.env + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history +.env + +# Ignore master key for decrypting credentials and more. +/config/master.key +coverage diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..e54d447e8f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.4.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..975af269de --- /dev/null +++ b/Gemfile @@ -0,0 +1,87 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.5.1' + +gem 'simplecov' +gem 'faker' +gem "omniauth" +gem "omniauth-github" +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.1' +# Use postgresql as the database for Active Record +gem 'pg', '>= 0.18', '< 2.0' +# Use Puma as the app server +gem 'puma', '~> 3.11' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'mini_racer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' + gem 'simplecov', require: false +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' + gem 'dotenv-rails' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..735b9d74f5 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,316 @@ +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) + 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 + 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/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/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000..58c830ecf4 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store new file mode 100644 index 0000000000..e9446cb2ea Binary files /dev/null and b/app/assets/.DS_Store differ 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/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000000..4f12eb75cf Binary files /dev/null and b/app/assets/images/.DS_Store differ 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/bg1.jpg b/app/assets/images/bg1.jpg new file mode 100644 index 0000000000..213021c7b9 Binary files /dev/null and b/app/assets/images/bg1.jpg differ diff --git a/app/assets/images/bg2.jpg b/app/assets/images/bg2.jpg new file mode 100644 index 0000000000..829816df0f Binary files /dev/null and b/app/assets/images/bg2.jpg differ diff --git a/app/assets/images/bg8.jpg b/app/assets/images/bg8.jpg new file mode 100644 index 0000000000..d59fbb2ac6 Binary files /dev/null and b/app/assets/images/bg8.jpg differ diff --git a/app/assets/images/bg9.jpg b/app/assets/images/bg9.jpg new file mode 100644 index 0000000000..4451a17fca Binary files /dev/null and b/app/assets/images/bg9.jpg differ diff --git a/app/assets/images/callentani.jpg b/app/assets/images/callentani.jpg new file mode 100644 index 0000000000..60c2d6175c Binary files /dev/null and b/app/assets/images/callentani.jpg differ diff --git a/app/assets/images/capellini.jpg b/app/assets/images/capellini.jpg new file mode 100644 index 0000000000..ab032bbd62 Binary files /dev/null and b/app/assets/images/capellini.jpg differ diff --git a/app/assets/images/ditalini.jpg b/app/assets/images/ditalini.jpg new file mode 100644 index 0000000000..1975560582 Binary files /dev/null and b/app/assets/images/ditalini.jpg differ diff --git a/app/assets/images/elbow.jpg b/app/assets/images/elbow.jpg new file mode 100644 index 0000000000..eee133ba72 Binary files /dev/null and b/app/assets/images/elbow.jpg differ diff --git a/app/assets/images/farfalle.jpg b/app/assets/images/farfalle.jpg new file mode 100644 index 0000000000..4254475aef Binary files /dev/null and b/app/assets/images/farfalle.jpg differ diff --git a/app/assets/images/fettuccine.jpg b/app/assets/images/fettuccine.jpg new file mode 100644 index 0000000000..2ee3d10c19 Binary files /dev/null and b/app/assets/images/fettuccine.jpg differ diff --git a/app/assets/images/gemelli.jpg b/app/assets/images/gemelli.jpg new file mode 100644 index 0000000000..df5770badf Binary files /dev/null and b/app/assets/images/gemelli.jpg differ diff --git a/app/assets/images/gluten-free.jpg b/app/assets/images/gluten-free.jpg new file mode 100644 index 0000000000..e9b3ae7902 Binary files /dev/null and b/app/assets/images/gluten-free.jpg differ diff --git a/app/assets/images/large-shell.jpg b/app/assets/images/large-shell.jpg new file mode 100644 index 0000000000..326f05eaa3 Binary files /dev/null and b/app/assets/images/large-shell.jpg differ diff --git a/app/assets/images/lasagna.jpg b/app/assets/images/lasagna.jpg new file mode 100644 index 0000000000..1a048ffd67 Binary files /dev/null and b/app/assets/images/lasagna.jpg differ diff --git a/app/assets/images/manicotti.jpg b/app/assets/images/manicotti.jpg new file mode 100644 index 0000000000..28a104049c Binary files /dev/null and b/app/assets/images/manicotti.jpg differ diff --git a/app/assets/images/medium-shell.jpg b/app/assets/images/medium-shell.jpg new file mode 100644 index 0000000000..ca5c5ae45a Binary files /dev/null and b/app/assets/images/medium-shell.jpg differ diff --git a/app/assets/images/orzo.jpg b/app/assets/images/orzo.jpg new file mode 100644 index 0000000000..78166663b1 Binary files /dev/null and b/app/assets/images/orzo.jpg differ diff --git a/app/assets/images/pappardelle.jpg b/app/assets/images/pappardelle.jpg new file mode 100644 index 0000000000..8d5636a667 Binary files /dev/null and b/app/assets/images/pappardelle.jpg differ diff --git a/app/assets/images/pastina.jpg b/app/assets/images/pastina.jpg new file mode 100644 index 0000000000..289d9174c2 Binary files /dev/null and b/app/assets/images/pastina.jpg differ diff --git a/app/assets/images/penne.jpg b/app/assets/images/penne.jpg new file mode 100644 index 0000000000..76018e6c8e Binary files /dev/null and b/app/assets/images/penne.jpg differ diff --git a/app/assets/images/pg3.jpg b/app/assets/images/pg3.jpg new file mode 100644 index 0000000000..398e809eff Binary files /dev/null and b/app/assets/images/pg3.jpg differ diff --git a/app/assets/images/pg4.jpeg b/app/assets/images/pg4.jpeg new file mode 100644 index 0000000000..50d01dc89d Binary files /dev/null and b/app/assets/images/pg4.jpeg differ diff --git a/app/assets/images/pg7.jpg b/app/assets/images/pg7.jpg new file mode 100644 index 0000000000..6806de48e8 Binary files /dev/null and b/app/assets/images/pg7.jpg differ diff --git a/app/assets/images/ravioli.jpg b/app/assets/images/ravioli.jpg new file mode 100644 index 0000000000..2f4778488d Binary files /dev/null and b/app/assets/images/ravioli.jpg differ diff --git a/app/assets/images/rotini.jpg b/app/assets/images/rotini.jpg new file mode 100644 index 0000000000..5c53f3b9ee Binary files /dev/null and b/app/assets/images/rotini.jpg differ diff --git a/app/assets/images/spaghetti.jpg b/app/assets/images/spaghetti.jpg new file mode 100644 index 0000000000..38e14b9a3b Binary files /dev/null and b/app/assets/images/spaghetti.jpg differ diff --git a/app/assets/images/spaghettsi-logo.png b/app/assets/images/spaghettsi-logo.png new file mode 100644 index 0000000000..259b032846 Binary files /dev/null and b/app/assets/images/spaghettsi-logo.png differ diff --git a/app/assets/images/tortellini.jpg b/app/assets/images/tortellini.jpg new file mode 100644 index 0000000000..b79c81eae6 Binary files /dev/null and b/app/assets/images/tortellini.jpg differ diff --git a/app/assets/javascripts/addresses.js b/app/assets/javascripts/addresses.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/addresses.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/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..4f73c21a7d --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,20 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. + //= require jquery3 + //= require popper + //= require bootstrap-sprockets + +// +//= require rails-ujs +//= require activestorage +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000000..739aa5f022 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/order_products.js b/app/assets/javascripts/order_products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order_products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/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/payments.js b/app/assets/javascripts/payments.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/payments.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..4e690ad07d --- /dev/null +++ b/app/assets/javascripts/products.js @@ -0,0 +1,84 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. +filterSelection("all") +function filterSelection(c) { + var x, i; + x = document.getElementsByClassName("filterDiv"); + if (c == "all") c = ""; + // Add the "show" class (display:block) to the filtered elements, and remove the "show" class from the elements that are not selected + for (i = 0; i < x.length; i++) { + w3RemoveClass(x[i], "show"); + if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show"); + } +} + +// Show filtered elements +function w3AddClass(element, name) { + var i, arr1, arr2; + arr1 = element.className.split(" "); + arr2 = name.split(" "); + for (i = 0; i < arr2.length; i++) { + if (arr1.indexOf(arr2[i]) == -1) { + element.className += " " + arr2[i]; + } + } +} + +// Hide elements that are not selected +function w3RemoveClass(element, name) { + var i, arr1, arr2; + arr1 = element.className.split(" "); + arr2 = name.split(" "); + for (i = 0; i < arr2.length; i++) { + while (arr1.indexOf(arr2[i]) > -1) { + arr1.splice(arr1.indexOf(arr2[i]), 1); + } + } + element.className = arr1.join(" "); +} + +// Add active class to the current control button (highlight it) +var btnContainer = document.getElementById("myBtnContainer"); +var btns = btnContainer.getElementsByClassName("btn"); +for (var i = 0; i < btns.length; i++) { + btns[i].addEventListener("click", function() { + var current = document.getElementsByClassName("active"); + current[0].className = current[0].className.replace(" active", ""); + this.className += " active"; + }); +} + +// product show page +$(document).ready(function(){ + //-- Click on detail + $("ul.menu-items > li").on("click",function(){ + $("ul.menu-items > li").removeClass("active"); + $(this).addClass("active"); + }) + + $(".attr,.attr2").on("click",function(){ + var clase = $(this).attr("class"); + + $("." + clase).removeClass("active"); + $(this).addClass("active"); + }) + + //-- Click on QUANTITY + $(".btn-minus").on("click",function(){ + var now = $(".section > div > input").val(); + if ($.isNumeric(now)){ + if (parseInt(now) -1 > 0){ now--;} + $(".section > div > input").val(now); + }else{ + $(".section > div > input").val("1"); + } + }) + $(".btn-plus").on("click",function(){ + var now = $(".section > div > input").val(); + if ($.isNumeric(now)){ + $(".section > div > input").val(parseInt(now)+1); + }else{ + $(".section > div > input").val("1"); + } + }) + }) 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/addresses.scss b/app/assets/stylesheets/addresses.scss new file mode 100644 index 0000000000..0c30f1ebda --- /dev/null +++ b/app/assets/stylesheets/addresses.scss @@ -0,0 +1,13 @@ +// Place all the styles related to the Addresses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.address-container { + margin-bottom: 5rem; + margin-top: 5rem; + box-shadow: 0 0 30px black; +} + +.top-row { + margin-top: 2rem; +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..fc48929935 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,145 @@ + +/* Custom bootstrap variables must be set or imported *before* bootstrap. */ +@import "bootstrap"; +/* Import scss content */ +@import "**/*"; +// Need to fix when screen gets smaller +// Need to fix dropdown menu location to align even when screen size changes + +body { + font-family: 'Montserrat', sans-serif; + max-width: 100%; + overflow-x: hidden; + min-height: 500px ; +} +// navbar +#spaghettsi-logo { + width: 150px; + height: 150px; + border-radius: 50%; + border: 5px double firebrick; +} + +.error-list { + list-style: none; +} + +.nav-word { + margin-top: 50px; +} + +.nav-item { + font-size: 20px; +} + +.navbar { + border-bottom: 10px double firebrick; +} + +// homepage +/************* GENERIC *****************/ +a {color:#696969;} +// img {width:100%;} +.img-icon { + width: 50px; +} +.card { + background-color: white; + +} + +.product-card { + width: 20rem; + height: 32rem; +} + +.card-footer { + background-color: #006400; + color: white; +} + +.fa { + padding: 10px; + font-size: 30px; + width: 50px; + text-align: center; + text-decoration: none; + margin: 5px 2px; +} + +.fa:hover { + opacity: 0.7; +} + +.fa-facebook { + background: #3B5998; + color: white; +} + +.fa-twitter { + background: #55ACEE; + color: white; +} +.fa-google { + background: #dd4b39; + color: white; +} + +.fa-linkedin { + background: #007bb5; + color: white; +} +.fa-instagram { + background: #125688; + color: white; +} + +.fa-pinterest { + background: #cb2027; + color: white; +} + +.container { + background-color: white; +} + +.btn-user { + color: white; +} + +.top-info { + margin-top: 2rem; +} + +// .index-container { +// height: 150vh; +// } + +/************* TOP-HEAD *****************/ +.top-head ul li {padding-right:8px;} +/****************** Navigation **************/ +.navbar-toggler {border-color: #dd0000;} +.navbar-toggler-icon { + background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgb(221, 0, 0, 0.7)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E"); +} +/**************** Banner Slider Carousel **************/ +.carousel-inner img {width: 100%;} +.carousel-caption {color:#000;top:110px; bottom: auto; text-align:left;} +.carousel-caption h1 { color:#dd0000; } +/************ Services **************/ +.most-car-box:hover {box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);} +/*********** TABS *******/ +.nav-tabs { border-bottom: 1px solid #ccc; } +.nav-tabs .nav-link.active { + border-bottom: 1px solid #dd0000; + border-radius:0px; +} +/**************** Social ICONS ***************/ +/* Social Icons */ + +.social-icons{margin: 0;padding: 0; font-size : 10px;} +.social {margin:7px 7px 7px 0px;} +#social-fb:hover {color: #3B5998;transition:all .25s;} + #social-tw:hover {color: #4099FF;transition:all .25s;} + #social-gp:hover {color: #d34836;transition:all .25s;} + #social-em:hover {color: #f39c12;transition:all .25s;} diff --git a/app/assets/stylesheets/contact_us.scss b/app/assets/stylesheets/contact_us.scss new file mode 100644 index 0000000000..70a5a6d2d6 --- /dev/null +++ b/app/assets/stylesheets/contact_us.scss @@ -0,0 +1,46 @@ +.margin-top-x8{ + display: flex; + flex-direction:column; + padding: 10px; + +} + +.col-sm-4{ + display: inline-grid; +} +input[type=text], select, textarea { + width: 100%; /* Full width */ + padding: 12px; /* Some padding */ + border: 1px solid #ccc; /* Gray border */ + border-radius: 4px; /* Rounded borders */ + box-sizing: border-box; /* Make sure that padding and width stays in place */ + margin-top: 6px; /* Add a top margin */ + margin-bottom: 16px; /* Bottom margin */ + resize: vertical /* Allow the user to vertically resize the textarea (not horizontally) */ +} + +/* Style the submit button with a specific background color etc */ +input[type=submit] { + color: white; + width: 12rem; + border: none; + border-radius: 4px; + cursor: pointer; +} + +/* When moving the mouse over the submit button, add a darker green color */ +input[type=submit]:hover { + background-color: brickred; +} + +/* Add a background color and some padding around the form */ +.container { + border-radius: 5px; + background-color: #f2f2f2; + padding: 20px; +} + +.rounded-circle { + width: 200px; + height: 200px; +} diff --git a/app/assets/stylesheets/order_products.scss b/app/assets/stylesheets/order_products.scss new file mode 100644 index 0000000000..d7da5d6766 --- /dev/null +++ b/app/assets/stylesheets/order_products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the order_products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..62712b899a --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,130 @@ +// 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/ +.param { + margin-bottom: 7px; + line-height: 1.4; +} +.param-inline dt { + display: inline-block; +} +.param dt { + margin: 0; + margin-right: 7px; + font-weight: 600; +} +.param-inline dd { + vertical-align: baseline; + display: inline-block; +} + +.param dd { + margin: 0; + vertical-align: baseline; +} + +.shopping-cart-wrap .price { + color: #007bff; + font-size: 18px; + font-weight: bold; + margin-right: 5px; + display: block; +} +var { + font-style: normal; +} + +.media img { + margin-right: 1rem; +} +.img-sm { + width: 90px; + max-height: 75px; + object-fit: cover; +} + +.shopping-cart-container { + margin: 4rem; + border: none; +} + +// ========================== +// CHECKOUT +// ========================== + +.table>tbody>tr>td, .table>tfoot>tr>td{ + vertical-align: middle; +} + +.checkout-table { + margin-top: 3rem; + margin-left: 3rem; + margin-right: 3rem; +} +.guest-checkout-1 { + margin-left: 4rem; +} +.guest-checkout { + margin-left: 6rem; +} + +.btn-space { + margin-right: 5px; +} + +.btn-group { + margin-left: 3rem; + margin-right: 2rem; + margin-bottom: 3rem; +} + +@media screen and (max-width: 600px) { + table#cart tbody td .form-control{ + width:20%; + display: inline !important; + } + .actions .btn{ + width:36%; + margin:1.5em 0; + } + + .actions .btn-info{ + float:left; + } + .actions .btn-danger{ + float:right; + } + + table#cart thead { display: none; } + table#cart tbody td { display: block; padding: .6rem; min-width:320px;} + table#cart tbody tr td:first-child { background: #333; color: #fff; } + table#cart tbody td:before { + content: attr(data-th); font-weight: bold; + display: inline-block; width: 8rem; + } + + table#cart tfoot td{display:block; } + table#cart tfoot td .btn{display:block;} + +} + +.order-total { + height: 10px; +} +// ===================================== +// SHOW PAGE +// ===================================== + +.order-details { + border-top: 5px solid black; + border-bottom: 5px solid black; + margin: 3rem; +} + +.order-confirmation { + margin-top: 8rem; + margin-left: 2rem; +} +.order-number { + padding: 2rem; +} diff --git a/app/assets/stylesheets/payments.scss b/app/assets/stylesheets/payments.scss new file mode 100644 index 0000000000..ab0d7f0e1a --- /dev/null +++ b/app/assets/stylesheets/payments.scss @@ -0,0 +1,10 @@ +/* Padding - just for asthetics on Bootsnipp.com */ +.payment-container { + margin-bottom: 5rem; + margin-top: 5rem; + box-shadow: 0 0 30px black; +} + +.top-info { + margin: 3rem; +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..6a68b1d5cf --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,307 @@ +// 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/ + +.container { + overflow: hidden; +} + +.filterDiv { + float: left; + width: 18rem; + height: 28rem; + text-align: center; + margin: 20px; + margin-left: 4rem; + display: none; /* Hidden by default */ +} + +/* The "show" class is added to the filtered elements */ +.show { + display: block; +} + +.quantity-field { + margin: 1rem; +} + +/* Style the buttons */ +.btn { + border: none; + outline: none; + padding: 12px 16px; + // background-color: #green; + cursor: pointer; +} + +a .btn-primary { + color: white; +} + +#review-modal { + margin-bottom: 3rem; + width: 15rem; +} + +#exampleModalLong { + margin-top: 10rem; +} +/* Add a light grey background on mouse-over */ +.btn:hover { + background-color: #B22222; + color: white; +} + +/* Add a dark background to the active button */ +.btn.active { + background-color: darkgreen; + color: white; +} +// +// product view trial + +.add-to-cart .btn-qty { + width: 52px; + height: 46px; +} + +.add-to-cart .btn { border-radius: 0; } + +.btn-products { + background-color: darkgreen; + color: white; +} + +.index-btn { + width: 100%; + margin: 0rem; +} + +// product page + +body { + font-family: 'open sans'; + overflow-x: hidden; } + +.preview { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; } + @media screen and (max-width: 996px) { + .preview { + margin-bottom: 20px; } } + +.preview-pic { + -webkit-box-flex: 1; + -webkit-flex-grow: 1; + -ms-flex-positive: 1; + flex-grow: 1; } + +.preview-thumbnail.nav-tabs { + border: none; + margin-top: 15px; } + .preview-thumbnail.nav-tabs li { + width: 18%; + margin-right: 2.5%; } + .preview-thumbnail.nav-tabs li img { + max-width: 100%; + display: block; } + .preview-thumbnail.nav-tabs li a { + padding: 0; + margin: 0; } + .preview-thumbnail.nav-tabs li:last-of-type { + margin-right: 0; } + +.tab-content { + overflow: hidden; } + .tab-content img { + width: 100%; + -webkit-animation-name: opacity; + animation-name: opacity; + -webkit-animation-duration: .3s; + animation-duration: .3s; } + +.card { + margin-top: 50px; + background: #eee; + line-height: 1.5em; } + +.show-card { + padding: 3rem; +} + +#pic-1 { + width: 25rem; + +} + +@media screen and (min-width: 997px) { + .wrapper { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; } } + +.details { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; } + +.colors { + -webkit-box-flex: 1; + -webkit-flex-grow: 1; + -ms-flex-positive: 1; + flex-grow: 1; } + +.product-title, .price, .sizes, .colors { + text-transform: UPPERCASE; + font-weight: bold; } + +.checked, .price span { + color: #ff9f1a; } + +.product-title, .rating, .product-description, .price, .vote, .sizes { + margin-bottom: 15px; } + +.product-title { + margin-top: 0; } + +.size { + margin-right: 10px; } + .size:first-of-type { + margin-left: 40px; } + +.color { + display: inline-block; + vertical-align: middle; + margin-right: 10px; + height: 2em; + width: 2em; + border-radius: 2px; } + .color:first-of-type { + margin-left: 20px; } + + + +.add-to-cart { + background: darkgreen; + padding: 1.2em 1.5em; + border: none; + text-transform: UPPERCASE; + font-weight: bold; + color: #fff; + -webkit-transition: background .3s ease; + transition: background .3s ease; } + .add-to-cart:hover, .like:hover { + background: darkgreen; + color: #fff; } + +.not-available { + text-align: center; + line-height: 2em; } + .not-available:before { + font-family: fontawesome; + content: "\f00d"; + color: #fff; } + +.tooltip-inner { + padding: 1.3em; +} + +@-webkit-keyframes opacity { + 0% { + opacity: 0; + -webkit-transform: scale(3); + transform: scale(3); } + 100% { + opacity: 1; + -webkit-transform: scale(1); + transform: scale(1); } } + +@keyframes opacity { + 0% { + opacity: 0; + -webkit-transform: scale(3); + transform: scale(3); } + 100% { + opacity: 1; + -webkit-transform: scale(1); + transform: scale(1); } } +// ============================================= +// sell a product form +.top-row { + margin-top: 2rem; +} +.send-button{ + background: #54C7C3; + width:100%; + font-weight: 600; + color:#fff; + padding: 8px 25px; +} + +.my-input{ + box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + cursor: text; + padding: 8px 10px; + transition: border .1s linear; +} +.header-title{ + margin: 5rem 0; +} +h1{ + font-size: 31px; + line-height: 40px; + font-weight: 600; + color:#4c5357; +} +h2{ + color: #5e8396; + font-size: 21px; + line-height: 32px; + font-weight: 400; +} +.login-or { + position: relative; + color: #aaa; + margin-top: 10px; + margin-bottom: 10px; + padding-top: 10px; + padding-bottom: 10px; +} +.span-or { + display: block; + position: absolute; + left: 50%; + top: -2px; + margin-left: -25px; + background-color: #fff; + width: 50px; + text-align: center; +} + +.hr-or { +height: 1px; +} + +@media screen and (max-width:480px){ + h1 { + font-size: 26px; + } + + h2 { + font-size: 20px; + } +} diff --git a/app/assets/stylesheets/review_form.scss b/app/assets/stylesheets/review_form.scss new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/app/assets/stylesheets/review_form.scss @@ -0,0 +1 @@ + diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..11bbb12cd5 --- /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/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..c8364b7e02 --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,95 @@ +// 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/ +.user-card { + margin: 3rem; + background-color: #B22222; +} + +.table { + margin-bottom: 5rem; +} + +.card-footer { + height: 4rem; +} + +.card-footer a { + color: white; + text-decoration: none; +} + +.card-footer a:hover { + color: #064579; +} + + +// ======================================== +// DASHBOARD +// ======================================== + +.sidenav { + width: 200px; + position: fixed; + z-index: 1; + top: 20px; + left: 10px; + background-color: firebrick; + overflow-x: hidden; + padding: 15px 10px; + margin-top: 9rem; + +} + +.sidenav a { + padding: 10px 8px 10px 16px; + text-decoration: none; + font-size: 20px; + color: white; + display: block; + + +} + +.sidenav a:hover { + color: #064579; +} + +.main { + margin-left: 140px; /* Same width as the sidebar + left position in px */ + font-size: 28px; /* Increased text to enable scrolling */ + padding: 0px 10px; +} + +@media screen and (max-height: 450px) { + .sidenav {padding-top: 15px;} + .sidenav a {font-size: 18px;} +} + +.card-deck { + margin-right: 3rem; +} + +.card-dashboard { + border: 3px solid black; +} + +.large-print { + font-size: 40px; +} + +#btn-seller { + width: 20rem; +} +// =========================== +// SHOW +// =========================== +.merchant-order-details { + margin-left: 15rem; + margin-top: 10rem; + padding: 2rem; +} + +.shipped { + text-decoration: underline; +} 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/addresses_controller.rb b/app/controllers/addresses_controller.rb new file mode 100644 index 0000000000..ba876de06e --- /dev/null +++ b/app/controllers/addresses_controller.rb @@ -0,0 +1,60 @@ +class AddressesController < ApplicationController + # + # def index + # @addresses = Address.all + # end + # + # def show + # end + + def new + if @login_user + @address = Address.new() + else + render 'layouts/not_found', status: :bad_request + end + end + + def create + @address = Address.new(address_params) + + if @address.user != @login_user + flash[:warning] = "You must be logged in to add an address" + render 'layouts/not_found', status: :bad_request + else + if @address.save + flash[:success] = "Successfully created address." + redirect_to checkout_path + else + flash.now[:warning] = "A problem occurred: Could not create address." + flash.now[:validation_errors] = @address.errors.full_messages + + render :new, status: :bad_request + end + end + end + + # def edit + # end + # + # def update + # end + # + # def destroy + # end + + private + def address_params + params.require(:address).permit(:user_id, :first_name, :last_name, + :street, :street_2, :city, :state, :zip) + end + + # def find_address + # @address = Address.find_by(id: params[:id].to_i) + # + # if @address.nil? + # render 'layouts/not_found', status: :not_found + # end + # end + +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000000..8ea161e1c7 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,15 @@ +class ApplicationController < ActionController::Base + + before_action :find_login_user, :find_shopping_cart + + def find_login_user + @login_user = User.find_by(id: session[:user_id]) + end + + def find_shopping_cart + if @login_user + @shopping_cart = Order.find_by(user_id: @login_user.id, status: :pending) + end + 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_products_controller.rb b/app/controllers/order_products_controller.rb new file mode 100644 index 0000000000..e0a01bf97a --- /dev/null +++ b/app/controllers/order_products_controller.rb @@ -0,0 +1,126 @@ +class OrderProductsController < ApplicationController + + def create + + check_login + + check_shopping_cart + + + product = Product.find_by(id: params[:order_product][:product_id]) + + + quantity = params[:order_product][:quantity] + if product.user_id == session[:user_id] + redirect_back(fallback_location: products_path) + flash[:warning] = "Mamma Mia! You can't purchase your own products. Just steal some from the supply closet!" + else + + existing_row = OrderProduct.find_by(product_id: product.id, order_id: session[:shopping_cart_id]) + + if existing_row + + if decrease_inventory(product, quantity) + existing_row.quantity += quantity.to_i + if existing_row.save + flash[:success] = "Cart has been updated!" + redirect_to shopping_cart_path + else + product_not_added + end + else + product_not_added + end + + + else + new_row = OrderProduct.new(product_id: product.id, order_id: session[:shopping_cart_id], quantity: quantity) + + if decrease_inventory(product, quantity) + if new_row.save + flash[:success] = "Cart has been updated!" + redirect_to shopping_cart_path + else + product_not_added + end + else + product_not_added + end + end + end + + end + + def update + if order_product = OrderProduct.find_by(id: params[:order_product][:id]) + old_quantity = order_product.quantity + + order_product.update(quantity: params[:order_product][:quantity]) + new_quantity = order_product.quantity + + change_inventory = new_quantity - old_quantity + + order_product.product.quantity -= change_inventory + + order_product.product.save + + if order_product.quantity == 0 + order_product.destroy + flash[:success] = "#{order_product.product.name} removed from cart." + else + flash[:success] = "#{order_product.product.name} quantity updated." + end + + redirect_to shopping_cart_path + else + flash[:warning] = "Could not find product to update. Please try again." + redirect_to root_path + end + + end + + def check_login + + if !@login_user + flash[:warning] = "You are not logged in, continuing as guest." + user = User.create( + full_name: 'Guest user', + email: 'example@example.com', + is_a_seller: false, + uid: rand(11111111..99999999), + provider: 'guest_login' + ) + + session[:user_id] = user.id + end + end + + def check_shopping_cart + + if !@shopping_cart + @shopping_cart = Order.create( + user_id: session[:user_id], + status: :pending, + payment_id: nil, + address_id: nil + ) + + end + + session[:shopping_cart_id] = @shopping_cart.id + end + + def decrease_inventory(product, quantity) + product.quantity -= quantity.to_i + product.save + end + + def product_not_added + flash[:warning] = "Sorry, that quantity is not available. Please try again." + redirect_to root_path + end + + + + +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..5b7c08601a --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,103 @@ +class OrdersController < ApplicationController +before_action :find_order, only: [:show, :edit, :mark_as_shipped, :dashboard] +before_action :check_login_user, except: [:shopping_cart] # repeated in ApplicationController?? + # def index + # end + + def show + + if !@order || @order.status == 'pending' || @order.user != @login_user + render 'layouts/not_found', status: :not_found + end + + if @login_user.provider == 'guest_login' + session[:user_id] = nil + end + end + + # def new; end + + # def create + # # @shopping_cart = Order.new + # # if !@shopping_cart.save + # # flash[:warning] = "There was an error. Could not create shopping cart." + # # end + # end + + def edit + + if !@shopping_cart || @shopping_cart.user != @login_user + render 'layouts/not_found', status: :not_found + + # elsif @order.user !=@login_user + # render 'layouts/not_found', status: :not_found + else + render :checkout + end + end + + def mark_as_shipped + if @order.status != 'complete' + @order.status = 'complete' + if @order.save + redirect_back(fallback_location: merchant_orders_path) + end + end + end + + def update + + if @shopping_cart.products == [] + + redirect_to products_path + flash[:warning] = "Error: Cannot checkout, cart is empty." + + elsif !@login_user.update(user_params) + flash[:warning] = "An error occurred. Please try again." + flash[:validation_errors] = @login_user.errors.full_messages + redirect_back(fallback_location: checkout_path) + + else + if @shopping_cart.update(order_params) + flash[:success] = "Your order has been placed!" + order_id = session[:shopping_cart_id] + session[:shopping_cart_id] = nil + + redirect_to order_path(@shopping_cart.id) + + else + flash[:warning] = "Unable to place order" + flash[:validation_errors] = @shopping_cart.errors.full_messages + redirect_back(fallback_location: checkout_path) + end + end + + end + + # def dashboard + # end + + def shopping_cart; end + +private + + def find_order + @order = Order.find_by(id: params[:id].to_i) + end + + def order_params + params.permit(:payment_id, :address_id, :status) + end + + def user_params + params.permit(:full_name, :email) + end + + def check_login_user + if !@login_user + flash[:warning] = "You must be logged in to see an order." + redirect_to root_path + end + end + +end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000000..4d704c87d3 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,6 @@ +class PagesController < ApplicationController + def home + end + def contact_us + end +end diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb new file mode 100644 index 0000000000..f47f94ca68 --- /dev/null +++ b/app/controllers/payments_controller.rb @@ -0,0 +1,47 @@ +class PaymentsController < ApplicationController +before_action :find_card_types, only: [:new, :edit, :update, :create] + def index + end + + def show + end + + def new + @payment = Payment.new() + end + + def create + @payment = Payment.new(payment_params) + @card_types = Payment.card_types + + + if @payment.save + flash[:success] = "Successfully created payment." + redirect_to checkout_path + else + flash.now[:warning] = "A problem occurred: Could not create payment." + flash.now[:validation_errors] = @payment.errors.full_messages + render :new, status: :bad_request + end + end + + def edit + end + + def update + end + + def destroy + end + + private + + def find_card_types + @card_types = Payment.card_types + end + + def payment_params + params.require(:payment).permit(:user_id, :address_id, :card_number, :expiration_date, :cvv, :card_type) + + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..5205c1a617 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,130 @@ +class ProductsController < ApplicationController + before_action :find_product, only: [:show, :edit, :update, :deactivate] + before_action :find_categories, only: [:new, :edit, :update, :create] + before_action :find_products_index, only: [:index, :index_by_merchant] + + + + def index + # @products = Product.active_products + # @order_product = OrderProduct.new() + end + + def index_by_merchant + # @products = Product.active_products + # @order_product = OrderProduct.new() + @merchants = User.merchants + end + + def show + @order_product = OrderProduct.new() + end + + def new + if @login_user.nil? + flash[:warning] = "You must be a merchant to sell a product. Sign up as a merchant to continue!" + redirect_to root_path + elsif !@login_user.is_a_seller? + flash[:warning] = "You must be a merchant to sell a product. Sign up as a merchant to continue!" + redirect_to user_path(@login_user.id) + end + @product = Product.new() + end + + def create + + @product = Product.new(product_params) + if @product.save + flash[:success] = "Successfully created #{@product.name}" + redirect_to product_path(@product.id) + + else + flash.now[:warning] = "A problem occurred: Could not create #{@product.name}" + flash.now[:validation_errors] = @product.errors.full_messages + + render :new, status: :bad_request + end + end + + def edit + if !@login_user.nil? && @login_user.is_a_seller? + if @login_user.id != @product.user_id + redirect_to root_path + flash[:warning] = "You can only edit your own products." + end + else + redirect_to root_path + flash[:warning] = "You don't have permission to see that." + end + end + + def update + if @product.update(product_params) + flash[:success] = "Successfully updated #{@product.name}" + redirect_to product_path(@product.id) + else + flash.now[:warning] = "A problem occurred: Could not update #{@product.name}" + flash.now[:validation_errors] = @product.errors.full_messages + render :edit + end + end + + + def deactivate + if @login_user && @login_user.is_a_seller? + if @login_user.id != @product.user_id + flash[:warning] = "You can only remove your own products." + redirect_to root_path + else + + if @product.is_active + @product.is_active = false + elsif !@product.is_active + @product.is_active = true + end + + if @product.save + if !@product.is_active + flash[:warning] = "Product: #{@product.name.capitalize} was discontinued." + else + flash[:warning] = "Product: #{@product.name.capitalize} is available again for purchase." + end + redirect_to merchant_my_products_path + + end + end + else + redirect_to root_path + flash[:warning] = "You don't have permission to see that." + end + end + + + + private + + + def find_product + @product = Product.find_by(id: params[:id].to_i) + + if @product.nil? + render 'layouts/not_found', status: :not_found + end + end + + def find_categories + @product_categories = Product.categories + end + + def product_params + product_params = params.require(:product).permit(:name, :user_id, :price_in_cents, :category, :quantity, :description, :image_url) + product_params[:price_in_cents] = product_params[:price_in_cents].to_f * 100 + return product_params + end + + def find_products_index + @products = Product.active_products + @order_product = OrderProduct.new() + end + +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..c42180aade --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,67 @@ + +class ReviewsController < ApplicationController + before_action :find_product, only: [:new, :create] + + def index + @reviews = Review.all + end + + def new + if item_ownership? + redirect_to product_path(@product.id) + flash[:warning] = "You cannot review your own products." + else + @review = @product.reviews.new + end + end + + def create + if item_ownership? + + redirect_to product_path(@product.id) + flash[:warning] = "You cannot review your own products." + else + + @review = Review.new(review_params) + @review.user = @login_user + if @review.save + flash[:success] = "Thanks for creating a review!" + + redirect_to product_path(@product.id) + else + + flash[:warning] = "An error occurred, could not create the review" + flash[:validation_errors] = @review.errors.full_messages + + redirect_to product_path(@product.id), status: :bad_request + end + end + end + + def edit + end + + def update + end + + def destroy + end + + private + + def review_params + params.require(:review).permit(:review, :rating, :product_id) + end + + def item_ownership? + return @product.user_id == session[:user_id] + end + + def find_product + @product = Product.find_by(id: params[:id].to_i) + + if @product.nil? + render 'layouts/not_found', status: :not_found + end + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..1effb4c4cc --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,44 @@ + +class SessionsController < ApplicationController + + 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] = "Logged in as returning user #{user.full_name}" + + else + user = User.build_from_github(auth_hash) + + if user.save + + flash[:success] = "Logged in as new user #{user.full_name}" + else + flash[:warning] = "Could not create new user account: #{user.errors.messages}" + flash[:validation_errors] = user.errors.messages + + redirect_to root_path + return + end + end + session[:user_id] = user.id + redirect_to root_path + end + + def destroy + session[:user_id] = nil + flash[:success] = "Logged out. Pasta la Vista, baby!" + + redirect_to root_path + end + + protected + + def auth_hash + request.env['omniauth.auth'] + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..2983ac7e03 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,116 @@ +class UsersController < ApplicationController + before_action :find_orders_info, only: [:dashboard, :orders_index] + before_action :find_products, only: [:dashboard, :products_index] + + + def show + if @login_user.nil? || @login_user.provider == 'guest_login' + redirect_to root_path + flash[:warning] = "Oops, you must create an account to view this page!" + else + @login_user_orders = Order.where(user_id: @login_user.id).where().not(status: :pending) + render :account + end + end + + def update + + # if params[:commit] == "Update Personal Info" + # @login_user.full_name = params[:user][:full_name] + # @login_user.email = params[:user][:email] + # if @login_user.save + # flash[:success] = "User updated." + # else + # flash[:warning] = "There was an error." + # flash[:validation_errors] = @login_user.errors.full_messages + # end + # redirect_to checkout_path + # else + @login_user.is_a_seller = params[:user][:is_a_seller] + if @login_user.save + + if @login_user.products.any? + if @login_user.is_a_seller + activate_user_products + else + deactivate_user_products + end + end + + flash[:success] = "Account settings updated!" + redirect_to account_path + end + # end + + end + + def dashboard + if @login_user.nil? || !@login_user.is_a_seller? + redirect_to root_path + flash[:warning] = "You don't have permission to view that page" + else + @total_active_products = @active_products.count + @total_inactive_products = @inactive_products.count + @total_products = @login_user.products.count + + end + end + + def orders_index; end + + def order_show + @order = Order.find_by(id: params[:id]) + + if !@order || @order.status == "pending" + render 'layouts/not_found', status: :not_found + else + @order_products = @order.order_products_by_merchant(@login_user) + @order_subtotal = @order.order_subtotal_by_merchant(@login_user) + end + end + + def products_index + @products = @login_user.products + end + + + + + + def deactivate_user_products + @login_user.products.each do |product| + product.is_active = false + product.save + end + end + + def activate_user_products + @login_user.products.each do |product| + product.is_active = true + product.save + end + end + + private + + def find_orders_info + if @login_user + @orders = @login_user.all_orders_for_merchant + @total_orders = @orders.count + @paid_orders = @login_user.sort_orders_by_status('paid') + @total_paid_orders = @paid_orders.count + @completed_orders = @login_user.sort_orders_by_status('complete') + @total_completed_orders = @completed_orders.count + end + end + + def find_products + if @login_user + @active_products = @login_user.product_status(true) + @inactive_products = @login_user.product_status(false) + end + end + + + +end diff --git a/app/helpers/addresses_helper.rb b/app/helpers/addresses_helper.rb new file mode 100644 index 0000000000..5f4dc1384e --- /dev/null +++ b/app/helpers/addresses_helper.rb @@ -0,0 +1,2 @@ +module AddressesHelper +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..6c78a43d17 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,19 @@ +module ApplicationHelper + def readable_date(date) + ("" + date.strftime("%B %d, %Y") + "").html_safe + end + + def cc_date(date) + ("" + date.strftime("%b %Y") + "").html_safe + end + + def readable_price(price_in_cents) + dollars = price_in_cents.to_f / 100 + return ("" + "$" + ("%.2f" % dollars) + "").html_safe + end + + def form_price(price_in_cents) + dollars = price_in_cents.to_f / 100 + return '%.2f' % dollars + end +end diff --git a/app/helpers/order_products_helper.rb b/app/helpers/order_products_helper.rb new file mode 100644 index 0000000000..fb2828b523 --- /dev/null +++ b/app/helpers/order_products_helper.rb @@ -0,0 +1,2 @@ +module OrderProductsHelper +end diff --git a/app/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/payments_helper.rb b/app/helpers/payments_helper.rb new file mode 100644 index 0000000000..c1b884f80f --- /dev/null +++ b/app/helpers/payments_helper.rb @@ -0,0 +1,2 @@ +module PaymentsHelper +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/address.rb b/app/models/address.rb new file mode 100644 index 0000000000..318537ef7f --- /dev/null +++ b/app/models/address.rb @@ -0,0 +1,14 @@ +class Address < ApplicationRecord + belongs_to :user + has_one :payment + has_many :orders + + validates :user_id, presence: true + validates :first_name, presence: true + validates :last_name, presence: true + validates :street, presence: true + validates :city, presence: true + validates :state, presence: true + validates :zip, presence: true , numericality: true,length: { in: 5..10 } + +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..10a4cba84d --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..e572e8d93c --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,47 @@ +class Order < ApplicationRecord + has_many :order_products, dependent: :destroy + has_many :products, through: :order_products + belongs_to :payment, optional: true + belongs_to :address, optional: true + belongs_to :user + + validates :user_id, presence: true + validates :address_id, presence: true, if: :order_placed? + validates :payment_id, presence: true, if: :order_placed? + validates :status, presence: true + + def order_placed? + return self.status == "paid" + end + + def order_subtotal + return self.order_products.sum{|row| row.item_subtotal} + end + + def seattle_sales_tax + return (0.101 * self.order_subtotal).round(0) + end + + def flat_rate_shipping + return 1000 + end + + def order_total + return self.order_subtotal + self.flat_rate_shipping + self.seattle_sales_tax + end + + def order_products_by_merchant(seller) + rows = [] + self.order_products.each do |op| + if op.product.user_id == seller.id + rows << op + end + end + + return rows + end + + def order_subtotal_by_merchant(seller) + self.order_products_by_merchant(seller).sum{|row| row.item_subtotal} + end +end diff --git a/app/models/order_product.rb b/app/models/order_product.rb new file mode 100644 index 0000000000..afdaae1074 --- /dev/null +++ b/app/models/order_product.rb @@ -0,0 +1,13 @@ +class OrderProduct < ApplicationRecord + belongs_to :order + belongs_to :product + + validates :order, presence: true + validates :product, presence: true + validates :quantity, presence: true, numericality: { greater_than: 0, message: "Must add atleast a quantity of one."} + validates :quantity, numericality: { less_than: 10000, message: "Can't order that quantity."} + + def item_subtotal + self.product.price_in_cents * self.quantity + end +end diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 0000000000..a6ab6b68dc --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,20 @@ +class Payment < ApplicationRecord + belongs_to :user + has_many :orders + belongs_to :address + + validates :user_id, presence: true + validates :address_id, presence: true + validates :card_number, presence: true, numericality: true, length: { in: 14..17 } + validates :expiration_date, presence: true + validates :cvv, presence: true, numericality: true, length: { in: 3..6 } + validates :card_type, presence: true + + def self.card_types + return ['AMEX', 'Visa', 'MasterCard', 'Discover', 'Spagh-Ettsi Gift Card'] + end + + def last_four_digits + self.card_number.to_s.last(4) + end +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..b2d0f09d12 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,39 @@ +class Product < ApplicationRecord + has_many :reviews + belongs_to :user + has_many :order_products + has_many :orders, through: :order_products + + #validates :user_id, presence: true + validates :name, presence: true, uniqueness: true + validates :price_in_cents, presence: true, numericality: { greater_than: 0, message: "Price must be greater than 0"} + validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, message: "Stock cannot go below 0"} + validates :category, presence: true + validates :description, presence: true + # validates_format_of :image_url,:with => /\A[http]/ + + def self.categories + return ['long', 'short', 'shell', 'sheet', 'filled', 'soup'] + end + + def self.active_products + return Product.where(is_active: true) + end + + def average_rating + ratings = 0 + self.reviews.each do |review| + ratings += review.rating if review.rating + end + if ratings == 0 + return "Not yet rated" + else + return (ratings.to_i / self.reviews.length).round(2) + end + end + + # def self.merchant_owners + # return + # end + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..be8cfd4b21 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,13 @@ + +class Review < ApplicationRecord + belongs_to :product + belongs_to :user, required: false + + + validates :product_id, presence: true + validates :rating, presence: true, numericality: { greater_than: 0, message: "Rating must be greater than 0"} + validates :rating, numericality: { less_than_or_equal_to: 5, message: "We're flattered but this product can only be rated out of 5."} + # def item_ownership? + # return self.product.user_id == session[:user_id] + # end +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..318b49eeeb --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,91 @@ +class User < ApplicationRecord + has_many :orders + has_many :products + has_many :addresses + has_many :payments + has_many :reviews + + validates :is_a_seller, inclusion: {in: [false], message: "Must be a registered user to become a seller"}, if: :guest? + validates :full_name, presence: true + validates :email, presence: true + validates_format_of :email,:with => /.+@.+\..+/ + validates :uid, presence: true + validates :provider, presence: true + + def self.build_from_github(auth_hash) + user = User.new + user.uid = auth_hash[:uid] + user.provider = 'github' + user.full_name = auth_hash[:info][:name] + user.email = auth_hash[:info][:email] + return user + end + + def guest? + return self.provider == 'guest_login' + end + + def total_revenue + all_orders = all_orders_for_merchant + all_merchant_order_products = [] + specific_merchant_ops = [] + total_revenue = 0 + all_orders.each do |order| + all_merchant_order_products << order.order_products + end + all_merchant_order_products.flatten! + all_merchant_order_products.each do |order_product| + if order_product.product.user_id == self.id + specific_merchant_ops << order_product + end + end + + specific_merchant_ops.each do |op| + item_total = op.item_subtotal + + total_revenue += item_total + end + return total_revenue + end + + def total_revenue_by_status(status) + orders_by_status = sort_orders_by_status(status) + all_merchant_order_products = [] + specific_merchant_ops = [] + total_revenue = 0 + orders_by_status.each do |order| + all_merchant_order_products << order.order_products + end + all_merchant_order_products.flatten! + all_merchant_order_products.each do |order_product| + if order_product.product.user_id == self.id + specific_merchant_ops << order_product + end + end + + specific_merchant_ops.each do |op| + item_total = op.item_subtotal + + total_revenue += item_total + end + return total_revenue + end + + def all_orders_for_merchant + orders = Order.joins(:products).where({products: {user: self}}).where().not(status: :pending) + return orders.uniq + end + + def sort_orders_by_status(status) + return all_orders_for_merchant.select{|o| o.status == status} + end + + def product_status(boolean) + self.products.where(is_active: boolean) + end + + def self.merchants + User.where(is_a_seller: true) + end + +end diff --git a/app/views/addresses/_form.html.erb b/app/views/addresses/_form.html.erb new file mode 100644 index 0000000000..c5debdf8b8 --- /dev/null +++ b/app/views/addresses/_form.html.erb @@ -0,0 +1,59 @@ +
+
+

Address

+

Please fill out all appropriate fields

+
+ <%= form_with model: @address, local: true do |f| %> + <%= f.hidden_field :user_id, value: @login_user.id %> +
+
+ <%= f.label :first_name, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :first_name, class: 'form-control', id:"name" %> +
+
+
+ <%= f.label :last_name, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :last_name, class: 'form-control', id:"name" %> +
+
+
+ <%= f.label :street, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :street, class: 'form-control'%> +
+
+
+ <%= f.label :street_2, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :street_2, class: 'form-control'%> +
+
+
+ <%= f.label :city, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :city, class: 'form-control'%> +
+
+
+ <%= f.label :state, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :state, class: 'form-control'%> +
+
+
+ <%= f.label :zip, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :zip, class: 'form-control'%> +
+
+
+
+ <%= f.submit "Save Address", class: 'btn btn-products'%> +
+
+
+ +
diff --git a/app/views/addresses/new.html.erb b/app/views/addresses/new.html.erb new file mode 100644 index 0000000000..23997ae13a --- /dev/null +++ b/app/views/addresses/new.html.erb @@ -0,0 +1 @@ +<%= render partial: 'form' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..986ec01ce6 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,151 @@ + + + + + + SpaghEttsi + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + + + + + + + + <% if flash.any? %> +
+ <% flash.each do |name, message| %> + <% if name == 'warning' || name == 'success' %> +
+ <%= message %> + <% if flash[:validation_errors] %> + + <% end %> +
+ <% end %> + <%end%> +
+ <% end%> + + + <%= 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/layouts/not_found.html.erb b/app/views/layouts/not_found.html.erb new file mode 100644 index 0000000000..84ac2b7a01 --- /dev/null +++ b/app/views/layouts/not_found.html.erb @@ -0,0 +1,5 @@ +
+

Sorry, we can't find the noodle you're looking for.

+

It must be an impasta!

+ <%= link_to "Go back to prdoucts", products_path, class: "btn btn-dark" %> +

diff --git a/app/views/orders/checkout.html.erb b/app/views/orders/checkout.html.erb new file mode 100644 index 0000000000..ab00fce303 --- /dev/null +++ b/app/views/orders/checkout.html.erb @@ -0,0 +1,154 @@ +<%= form_tag checkout_path, remote: false, id: 'checkout_form' %> +<%= hidden_field_tag 'status', 'paid', form: 'checkout_form' %> + +

Checkout

+ + + + + + + + + + + + + + + + <% if @login_user.full_name == 'Guest user' || @login_user.email == 'example@example.com' %> + + + + + + <% else %> + + + + + + <% end %> + +
1 + Review Items +
+ + + + + + + + + + <% @shopping_cart.order_products.each do |order_product| %> + + + + + + + + <% end %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProductQuantityPriceItem Subtotal
+
+
<%= image_tag(order_product.product.image_url, alt: "small product icon", class: "img-thumbnail img-sm") %>
+
+

<%= order_product.product.name %>

+
+
+
+ <%= order_product.quantity %> + +
+ <%= readable_price(order_product.product.price_in_cents)%> +
+
+
+ <%= readable_price(order_product.item_subtotal)%> +
+
+ Subtotal + + <%= readable_price(@shopping_cart.order_subtotal) %> +
+ Seattle Sales Tax (10.1%) + + <%= readable_price(@shopping_cart.seattle_sales_tax) %> +
+ Flat Rate Shipping + + <%= readable_price(@shopping_cart.flat_rate_shipping) %> +
+ Order Total + + <%= readable_price(@shopping_cart.order_total) %> +
+
+
2 + Shipping Address +
+ <% if @login_user.addresses.any? %> +
+ <%= select_tag 'address_id', options_from_collection_for_select(@login_user.addresses, "id", "street"), form: 'checkout_form' %> +
+ <% end %> + <%= link_to "Add an address", new_address_path %> +
+
3 + Payment Method +
+ <% if @login_user.payments.any? %> +
+ <%= select_tag 'payment_id', options_from_collection_for_select(@login_user.payments, "id", "card_type"), form: 'checkout_form' %> + +
+ <% end %> + <%= link_to "Add a payment method", new_payment_path %> +
+
4 + <%= label_tag 'full_name', 'Full Name', form: 'checkout_form' %> + <%= text_field_tag 'full_name', @login_user.full_name, form: 'checkout_form' %> + <%= label_tag 'email', 'Email Address', form: 'checkout_form' %> + <%= text_field_tag 'email', @login_user.email, form: 'checkout_form' %> +
4 +
Name: <%= @login_user.full_name %>
+
Email: <%= @login_user.email %>
+
+
+ <%= link_to "Back to Shopping Cart", shopping_cart_path, class: "btn btn-products btn-space"%> + <%= link_to "Keep Shopping", products_path, class: "btn btn-products btn-space" %> + <%= submit_tag "Submit Order", form: 'checkout_form', class: 'btn btn-products'%> +
diff --git a/app/views/orders/shopping_cart.html.erb b/app/views/orders/shopping_cart.html.erb new file mode 100644 index 0000000000..544ce3a512 --- /dev/null +++ b/app/views/orders/shopping_cart.html.erb @@ -0,0 +1,81 @@ +
+<% if @shopping_cart.nil? || @shopping_cart.products ==[] %> +
+

Your shopping cart is empty! Add some fusilli, silly!

+
+<% else @shopping_cart %> +

<%= @shopping_cart.user.full_name %>

+

You have <%= @shopping_cart.order_products.count %> item(s) in your cart.

+
+ + +
+ + + + + + + + + + + + <% @shopping_cart.order_products.each do |order_product| %> + + + + + + + + + <% end %> + + + + + + + + +
ProductQuantityPriceItem Subtotal
+
+
<%= image_tag(order_product.product.image_url, alt:"product icon", class: "img-thumbnail img-sm") %>
+
+

<%= order_product.product.name %>

+
+
+
+ <%= form_with model: order_product, id: "update_inventory_#{order_product.id}", local: true do |f| %> + <%= f.number_field :quantity, min: 0, max: (order_product.product.quantity + order_product.quantity), class: 'form-control'%> + <%= f.hidden_field :id %> + + + <%= f.submit "Update Quantity", class: "btn btn-products", form: "update_inventory_#{order_product.id}" %> + <% end %> + +
+ <%= readable_price(order_product.product.price_in_cents)%> + +
+
+
+ <%= readable_price(order_product.item_subtotal)%> + +
+
+ Order Subtotal + + <%= readable_price(@shopping_cart.order_subtotal) %> +
+
+ + + +
+ <%= link_to "Keep Shopping", products_path, class: "btn btn-products btn-space" %> + <%= link_to "Continue to Checkout", checkout_path, class: "btn btn-products" %> +
+<% end %> + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..986baa7f1b --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,118 @@ + +
+

Order Confirmation

+

Order # <%= @order.id %>

+
+ +
+

Your order is complete!

+

Thank you for your order!

+

Let us know if you encounter any issues - your satisfaction is our priority.

+

+
+ +
+

Date Placed: <%= readable_date(@order.updated_at) %>

+

Name: <%= @login_user.full_name %>

+

Email: <%= @login_user.email %>

+

Shipped to: +

<%= @order.address.first_name %> <%= @order.address.last_name %>

+

<%= @order.address.street %>

+

<%= @order.address.city %> <%= @order.address.state %> <%= @order.address.zip %>

+

+

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

+

Payment: <%= @order.payment.card_type %> ending in <%= @order.payment.last_four_digits %>, expiring <%= cc_date(@order.payment.expiration_date) %>

+
+ +
+ + + + + + + + + + + <% @order.order_products.each do |op| %> + + + + + + + + + <% end %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProductQuantityPriceBack to ProductProduct Subtotal
+
+
<%= image_tag(op.product.image_url, alt: "product image icon", class: "img-thumbnail img-sm") %>
+
+

<%= op.product.name %>

+
+
+
+ <%=op.quantity %> + +
+ <%= readable_price(op.product.price_in_cents)%> +
+
+ <%= link_to "Back to Product", product_path(op.product.id), class: "btn btn-products" %> + +
+ <%= readable_price(op.item_subtotal)%> +
+
+ Subtotal + + <%= readable_price(@order.order_subtotal) %> +
+ Seattle Sales Tax (10.1%) + + <%= readable_price(@order.seattle_sales_tax) %> +
+ Flat Rate Shipping + + <%= readable_price(@order.flat_rate_shipping) %> +
+ Order Total + + <%= readable_price(@order.order_total) %> +
+
diff --git a/app/views/pages/contact_us.html.erb b/app/views/pages/contact_us.html.erb new file mode 100644 index 0000000000..6a1e90b6aa --- /dev/null +++ b/app/views/pages/contact_us.html.erb @@ -0,0 +1,64 @@ +
+

About us

+

Our Mission

+
+
+
+

We are serious about pasta.

+

At Spagh-ettsi, we care deeply about the health, well-being and culinary delight of our customers. We share a passion for – and commitment to – a philosophy of wholesome nutrition.

+

We carefully pick the best products that we can find based on a few important criteria: wholesome and pure, fresh and full-flavored. Wherever feasible, we seek out organic products, however, we do not limit ourselves to a strict, “organic only” platform. In addition, we are dedicated to educating our customers about the benefits of foods free of artificial, industrial additives

+

We are zealous in our search for and creation of full-flavored foods. And, we get great satisfaction out of sharing our new finds and creations with others.

+
+
+
+
+

Our Team

+
+
+ photo of Amanda +

Amanda

+
Chief Pasta Officer
+
+
+
+
+ photo of Daniela +

Daniela

+
Founder & Pasta Innovator
+
+
+
+
+ photo of Hannah +

Hannah

+
Director of Pasta Development
+
+
+
+
+ photo of Christina +

Christina

+
Chief Gluten-Free Officer
+
+
+
+
+ + +


+
+

Talk pasta to us!

+
+ + + + + + + + + + + +
+
diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb new file mode 100644 index 0000000000..4fb6683cfc --- /dev/null +++ b/app/views/pages/home.html.erb @@ -0,0 +1,165 @@ + + +
+
+
+
+

Featured Pastas

+

"Eat pasta to run fasta."

+
+
+ +
+
+ <% product = Product.all.find_by(id: 1) %> + <%= link_to image_tag(product.image_url, alt: "Card image cap", class: "card-img-top"), product_path(product.id) %> +
+
<%= product.name %>
+

<%= product.description.capitalize %>

+
+ +
+
+ <% product2 = Product.all.find_by(id: 4) %> + <%= link_to image_tag(product2.image_url, alt: "Card image cap", class: "card-img-top"), product_path(product2.id) %> +
+
<%= product2.name %>
+

<%= product2.description.capitalize %>

+
+ +
+
+ <% product3 = Product.all.find_by(id: 10) %> + <%= link_to image_tag(product3.image_url, alt: "Card image cap", class: "card-img-top"), product_path(product3.id) %> + +
+
<%= product3.name %>
+

<%= product3.description.capitalize %>

+
+ +
+
+
+
+ <%=link_to "View All Pasta", products_path, class: "btn btn-danger"%> +
+
+
+
+ +
+
+
+
+ +

How can we help you?

+

+ The pastabilities are endless! We want to hear from you so we can make + all your pasta dreams come true. +

+ <%=link_to "Ask a Question", contact_us_path, class: "btn btn-danger" %> +
+
+
+
+
+
+
+
+
+
+ tablet clipart +
+
+
Shop with ease
+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure aspernatur

+
+
+
+
+
+
+ online shopping cart clipart +
+
+
Makes Great Gifts
+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure aspernatur

+
+
+
+
+
+
+ money clipart +
+
+
Save Money
+

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure aspernatur

+
+
+
+
+
+
diff --git a/app/views/payments/_form.html.erb b/app/views/payments/_form.html.erb new file mode 100644 index 0000000000..2342ca7ce8 --- /dev/null +++ b/app/views/payments/_form.html.erb @@ -0,0 +1,70 @@ +
+
+

Payment

+

Please fill out all fields

+
+
+
+
+ cards accepted +
+
+
+
+
+ + <%= form_with model: @payment, local: true do |f| %> + <%= f.hidden_field :user_id, value: @login_user.id %> +
+
+ <%= f.label "Billing Address", class: "col-sm-3 offset-sm-1 col-form-label" %> + + <% if @login_user.addresses.any? %> +
+ <%= f.select(:address_id, [], {}, class: "form-control") do %> + <% @login_user.addresses.each do |address| -%> + <%= content_tag(:option, address.street, value: address.id) %> + <% end %> + <% end %> + <% end %> +
+
+ <%= link_to "Add an address", new_address_path %> +
+
+ +
+ <%= f.label :card_number, class:"col-sm-3 offset-sm-1 col-form-label"%> +
+ <%= f.text_field :card_number, maxlength: 19, class: 'form-control'%> +
+
+ +
+ <%= f.label :expiration_date, class: "col-sm-3 offset-sm-1 col-form-label"%> +
+ <%= f.date_field :expiration_date, min: Date.today, class: 'form-control' %> +
+
+ +
+ <%= f.label :cvv, class: "col-sm-3 offset-sm-1 col-form-label"%> +
+ <%= f.text_field :cvv, maxlength: 4, class: 'form-control' %> +
+
+ +
+ <%= f.label :card_type, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.select :card_type, @card_types, {}, class: 'form-control' %> +
+
+ +
+ <%= f.submit "Save Payment", class: 'btn btn-products'%> +
+ + <% end %> +
+
diff --git a/app/views/payments/new.html.erb b/app/views/payments/new.html.erb new file mode 100644 index 0000000000..e8812896e1 --- /dev/null +++ b/app/views/payments/new.html.erb @@ -0,0 +1,5 @@ +<% if @login_user %> + <%= render partial: 'form' %> +<% else %> +

Please log in to add a payment

+<% end %> diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..665dfe11be --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,82 @@ +
+
+

+ <%= form_intro %> +

+

+

<%= quote %>

+
<%= quoteauthor %>
+
+ + <%= form_with model: @product, local: true do |f| %> + <%= f.hidden_field :user_id, value: session[:user_id] %> +
+
+ <%= f.label "Product Name", class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_field :name, class: 'form-control', id:"name" %> +
+
+
+ <%= f.label "Unit Price ($)", class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.number_field :price_in_cents, step: 0.01, min: 0, value: form_price(@product.price_in_cents), class: 'form-control', id: 'form_price' %> +
+
+
+ <%= f.label "Quantity in Stock", class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.number_field :quantity, min: 1, class: 'form-control'%> +
+
+
+ <%= f.label :category, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.select :category, @product_categories, {}, class: "form-control"%> +
+
+
+ <%= f.label "Product Description", class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_area :description, class: 'form-control'%> +
+
+
+ <%= f.label "Paste the web address of this product's photo", class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <% if origin == 'new' %> + <%= f.text_field :image_url, class: 'form-control', value: 'https://png.pngtree.com/element_origin_min_pic/17/02/28/7597f1929358e13efe92f4a20a212c94.jpg' %> + <% else %> + <%= f.text_field :image_url, class: 'form-control' %> + <% end %> +
+
+
+
+ <%= f.submit "Submit Product", class: 'btn btn-products'%> +
+
+
+ +
+
+ <%=link_to "Return to Products", products_path, class: 'btn btn-products'%> +
+

By adding a product and becoming a merchant, you are indicating that you have read and agree to the Terms of Use and Privacy Policy. +

+
+ <% end %> + +
+
+
Welcome
+
<%= @login_user.full_name %>
+
+ <%= link_to "Dashboard", dashboard_path %> + <%= link_to "Add a Product", new_product_path %> + <%= link_to "My Products", merchant_my_products_path %> + <%= link_to "My Orders", merchant_orders_path %> +
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..216e0f2f6a --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,4 @@ +<%= render partial: "form", locals: {origin: 'edit', form_intro: 'Edit an Existing Product!', + quote: "Spaghetti is good with ranch, and spaghetti is good with sugar. + You put all of that together and make a sandwich out of it, and you get greatness. + People shouldn't judge unless they try it", quoteauthor: "--- Terry Rozier" } %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..10e41965e1 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,59 @@ +
+ + + + +
+ + + + + + + +
+ + +
+ <% @products.each do |product| %> +
+ <%= link_to image_tag(product.image_url, alt: "Card image cap", class: "card-img-top "), product_path(product.id) %> +
+
<%= product.name %>
+
+

<%= readable_price(product.price_in_cents)%>

+ <%if product.quantity == 0 %> +

Out of Stock

+ <%else%> + +
+
+ <%end%> +
+ +
diff --git a/app/views/products/index_by_merchant.html.erb b/app/views/products/index_by_merchant.html.erb new file mode 100644 index 0000000000..49747a726d --- /dev/null +++ b/app/views/products/index_by_merchant.html.erb @@ -0,0 +1,55 @@ +
+ + + + +
+ + <% @merchants.each do |merchant| %> + + <% end %> +
+ + +
+ <% i = 1 %> + <% @products.each do |product| %> +
+ <%= link_to image_tag("#{product.image_url}", alt: "Card image cap", class: "card-img-top"), product_path(product.id) %> +
+
<%= product.name %>
+
+

<%= readable_price(product.price_in_cents)%>

+ + +
+
+
+ <% i += 1 %> + <%end%> +
+ diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..6f3b8478f2 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,4 @@ + + +<%= render partial: "form", locals: {origin: 'new', form_intro: 'Add a New Product!', quote: "Spaghetti can be eaten most successfully if you inhale it like a vacuum cleaner.", quoteauthor: " --- Sophia Loren"} %> diff --git a/app/views/products/notfound.html.erb b/app/views/products/notfound.html.erb new file mode 100644 index 0000000000..84ac2b7a01 --- /dev/null +++ b/app/views/products/notfound.html.erb @@ -0,0 +1,5 @@ +
+

Sorry, we can't find the noodle you're looking for.

+

It must be an impasta!

+ <%= link_to "Go back to prdoucts", products_path, class: "btn btn-dark" %> +

diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..1defa03a03 --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,71 @@ +
+
+
+
+
+
+
<%= image_tag(@product.image_url, alt: "large picture of pasta") %>
+
+

<%= @product.reviews.count %> Product Reviews

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

Date: <%= readable_date(review.created_at) %>

+

Rating: <%= review.rating %>

+

<%= review.review.capitalize %>

+
+ <%end%> +

<%= link_to "Add a Review", new_product_review_path, class: "btn btn-products" %>

+ +
+
+
+

<%= @product.name %>

+
+
+ <% if @product.average_rating == 'Not yet rated' %> +

Not yet rated

+ <% else %> + <% @product.average_rating.times do %> + + <% end %> + <% (5 - @product.average_rating).times do %> + + <% end %> + <% end %> +
+ +
+

current price: <%= readable_price(@product.price_in_cents) %>

+

Category: <%= (@product.category).capitalize %>

+

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

+ <%if @product.quantity == 0 %> +

Out of Stock

+ <%else%> +

Stock: <%= @product.quantity %>

+ + <%= form_with model: @order_product do |f| %> +
+
+ <%= f.label :quantity %> + <%= f.number_field :quantity, value: 1, class: 'form-control'%> +
+ + + <%= f.hidden_field :product_id, value: params[:id] %> + <%= f.hidden_field :order_id, value: session[:order_id] %> + +
+ <%= f.submit "Add to Cart", class: 'add-to-cart btn btn-products'%> +
+ <%end%> + + <% end %> +
+ <%=link_to "Back to Products", products_path, class: 'btn btn-products' %> + +
+
+
+
+
diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb new file mode 100644 index 0000000000..cdf8c68712 --- /dev/null +++ b/app/views/reviews/index.html.erb @@ -0,0 +1,13 @@ +
+

Reviews:

+ +
+ <% @reviews.each do |review| %> + <%= "Product: #{review.product.name}:\n" %> + + <%= "#{review.review.capitalize}\n" %>
+

Date: <%= review.created_at %>

+

Rating: <%= review.rating %>

+
+ +<% end %> diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..62c86f22b5 --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,27 @@ +
+ <%= form_with model: @review, url: create_review_path(@product.id), method: :post, class: "review-form" do |f|%> +
+

New <%= @product.name %> Review

+

A penne for your thoughts:

+
+ <%= f.hidden_field :product_id, value: @product.id %> +
+
+ <%= f.label :rating, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.select :rating, [1,2,3,4,5], {}, class: 'form-control' %> +
+
+
+ <%= f.label :review, class: "col-sm-3 offset-sm-1 col-form-label" %> +
+ <%= f.text_area :review, class: 'form-control' %> +
+
+
+ <%= f.submit "Save review", class: "review-button btn btn-products" %> +
+ <% end %> +
+
+ diff --git a/app/views/users/account.html.erb b/app/views/users/account.html.erb new file mode 100644 index 0000000000..10f850af08 --- /dev/null +++ b/app/views/users/account.html.erb @@ -0,0 +1,78 @@ +
+
+
+

User:

+
<%= @login_user.full_name %>
+

Email:

+
<%= @login_user.email %>
+
+
+ +
+
+
+ <% if @login_user.is_a_seller %> +

You are currently a Spagh-ettsi merchant. To change your status, click the button below.

+ <%= form_with model: @login_user, local: true do |f| %> + <%= f.hidden_field :is_a_seller, value: false %> + <%= f.submit "Stop selling artisanal pasta", class: "btn bg-dark text-center", style: "margin-bottom:4px;white-space: normal;" %> + <% end %> + <% else %> +

You are currently a Spagh-ettsi customer. To become a merchant, click the button below.

+ <%= form_with model: @login_user, local: true do |f| %> + <%= f.hidden_field :is_a_seller, value: true %> + <%= f.submit "Open my own handcrafted pasta shop", class: "btn bg-dark ", style: "margin-bottom:4px;white-space: normal;" %> + <% end %> + <% end %> +

+
+
+
+
+ <%= link_to "Visit your Shop >", dashboard_path, class: "btn btn-user bg-dark card-title"%> +

Find all your seller info here!

+
+
+
+ +
+

Buyer Orders:

+ + + + + + + + + + + <% @login_user_orders.each do |order| %> + + + + + + + + + <%end %> + +
Order #Date PlacedOrdered ItemsSubtotalTotal Price
+ <%=order.id %> + + <%=readable_date(order.updated_at) %> + + <% order.order_products.each do |op| %> +
    +
  • + <%= op.quantity %> <%= op.product.name %> +
  • +
+ <%end %> +
+

<%=readable_price(order.order_subtotal) %>

+
+

<%=readable_price(order.order_total) %>

+
+
diff --git a/app/views/users/dashboard.html.erb b/app/views/users/dashboard.html.erb new file mode 100644 index 0000000000..56e30dd328 --- /dev/null +++ b/app/views/users/dashboard.html.erb @@ -0,0 +1,93 @@ + +
+
Welcome
+
<%= @login_user.full_name %>
+
+ <%= link_to "Dashboard", dashboard_path %> + <%= link_to "Add a Product", new_product_path %> + <%= link_to "My Products", merchant_my_products_path %> + <%= link_to "My Orders", merchant_orders_path %> +
+ +
+

Merchant Dashboard

+
+
+
+
Total Orders
+
<%= @total_orders %>
+
+
+
+
+
Total Revenue
+
<%= readable_price(@login_user.total_revenue) %>
+

Unfulfilled: <%= readable_price(@login_user.total_revenue_by_status('paid')) %>

+

Fulfilled: <%= readable_price(@login_user.total_revenue_by_status('complete')) %>

+
+
+
+
+
Products
+

Active: <%= @total_active_products %>

+

Inactive: <%= @total_inactive_products %>

+
+
+
+
+
Order Status
+

Unfulfilled: <%= @total_paid_orders %>

+

Fulfilled: <%= @total_completed_orders %>

+
+
+
+ +
+

Orders to Complete:

+ + + + + + + + + + + + <% @paid_orders.each do |order| %> + + + + + + + + <% end %> + +
Order #Date PlacedProductsOrder TotalShipping Status
+

<%= link_to "#{order.id}", merchant_order_path(order.id) %>

+
+

<%= readable_date(order.updated_at) %>

+
+ <% order.order_products_by_merchant(@login_user).each do |product| %> +
    +
  • + <%= product.quantity %> <%= product.product.name %> +
  • +
+ <% end %> +
+

<%=readable_price(order.order_subtotal) %>

+
+
+ <% if order.status != 'complete' %> + <%= link_to "Not Yet Shipped - View Order", merchant_order_path(order.id), class: "btn btn-products" %> + <%else%> +

*Items have been shipped

+ <% end %> +
+
+
+ +
diff --git a/app/views/users/order_show.html.erb b/app/views/users/order_show.html.erb new file mode 100644 index 0000000000..eb1e7eb2aa --- /dev/null +++ b/app/views/users/order_show.html.erb @@ -0,0 +1,95 @@ + + +
+

Merchant Order View Page

+

Order # <%= @order.id %>

+
+ +
+

Date Placed:<%= readable_date(@order.updated_at) %>

+

Name: <%= @order.user.full_name %>

+

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

+

Shipped to: +

<%= @order.address.first_name %> <%= @order.address.last_name %>

+

<%= @order.address.street %>

+

<%= @order.address.city %> <%= @order.address.state %> <%= @order.address.zip %>

+

+

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

+

Payment: <%= @order.payment.card_type %> ending in <%= @order.payment.last_four_digits %>

+
+ <% if @order.status != 'complete' %> + <%= link_to "Ship these items!", mark_as_shipped_path, method: :patch, class: "btn btn-products" %> + <%else%> +

*Items have been shipped

+ <% end %> +
+
+ +
+ + + + + + + + + + + <% @order_products.each do |op| %> + + + + + + + + + <% end %> + + + + + + + + + + + + +
ProductQuantityPriceBack to ProductProduct Subtotal
+
+
+
+

<%= op.product.name %>

+
+
+
+ <%=op.quantity %> + +
+ <%= readable_price(op.product.price_in_cents)%> +
+
+ <%= link_to "Back to Product", product_path(op.product.id), class: "btn btn-products" %> + +
+ <%= readable_price(op.item_subtotal)%> +
+
+ Subtotal + + <%= readable_price(@order_subtotal) %> +
+
+ +
+
Welcome
+
<%= @login_user.full_name %>
+
+ <%= link_to "Dashboard", dashboard_path %> + <%= link_to "Add a Product", new_product_path %> + <%= link_to "My Products", merchant_my_products_path %> + <%= link_to "My Orders", merchant_orders_path %> +
diff --git a/app/views/users/orders_index.html.erb b/app/views/users/orders_index.html.erb new file mode 100644 index 0000000000..e10fb054d7 --- /dev/null +++ b/app/views/users/orders_index.html.erb @@ -0,0 +1,100 @@ +
+

Orders

+

Total Orders: <%= @total_orders %>

+
+ +
+

Orders to Complete:

+ + + + + + + + + + + + <% @paid_orders.each do |order| %> + + + + + + + + <% end %> + +
Order #Date PlacedProductsOrder TotalShipping Status
+

<%= link_to "#{order.id}", merchant_order_path(order.id) %>

+
+

<%= readable_date(order.updated_at) %>

+
+ <% order.order_products_by_merchant(@login_user).each do |product| %> +
    +
  • + <%= product.quantity %> <%= product.product.name %> +
  • +
+ <% end %> +
+

<%=readable_price(order.order_subtotal_by_merchant(@login_user)) %>

+
+
+ <% if order.status != 'complete' %> + <%= link_to "View Order to Complete", merchant_order_path(order.id), class: "btn btn-products" %> + <%else%> +

*Items have been shipped

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

Completed Orders:

+ + + + + + + + + + + <% @completed_orders.each do |order| %> + + + + + + + <% end %> + +
Order #Date PlacedProductsTotal Revenue
+

<%= link_to "#{order.id}", merchant_order_path(order.id) %>

+
+

<%= readable_date(order.updated_at) %>

+
+ <% order.order_products_by_merchant(@login_user).each do |product| %> +
    +
  • + <%= product.quantity %> <%= product.product.name %> +
  • +
+ <% end %> +
+

<%=readable_price(order.order_subtotal_by_merchant(@login_user)) %>

+
+
+ +
+
Welcome
+
<%= @login_user.full_name %>
+
+ <%= link_to "Dashboard", dashboard_path %> + <%= link_to "Add a Product", new_product_path %> + <%= link_to "My Products", merchant_my_products_path %> + <%= link_to "My Orders", merchant_orders_path %> +
diff --git a/app/views/users/products_index.html.erb b/app/views/users/products_index.html.erb new file mode 100644 index 0000000000..23399716d8 --- /dev/null +++ b/app/views/users/products_index.html.erb @@ -0,0 +1,45 @@ +
+ + + + +
+ + + +
+ + +
+ <% i = 1 %> + <% @products.each do |product| %> +
+ <%= link_to image_tag("#{product.image_url}", alt: "Card image cap", class: "card-img-top"), product_path(product.id) %> +
+
<%= product.name %>
+
+

<%= readable_price(product.price_in_cents)%>

+ + +
+
+ <% i += 1 %> + <%end%> +
+
+ +
+
Welcome
+
<%= @login_user.full_name %>
+
+ <%= link_to "Dashboard", dashboard_path %> + <%= link_to "Add a Product", new_product_path %> + <%= link_to "My Products", merchant_my_products_path %> + <%= link_to "My Orders", merchant_orders_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..fa35ab4973 --- /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 SpaghEttsi + 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..04767e4e87 --- /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: spagh-ettsi_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000000..3a47d52bd1 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +k1kFfWDmq2biOGljgYWVRsffw/KAyg2RTIi1R99w1mqgCuXwJ8CJFW7u0xc72VJh+bTrtIIpRLjyfVQskqXbrktT0MMsPBqniMUCfnH9aCdweih6i7jllcThmVoyYJKxvz9d/MZ0cYfcfDp4unNY5bs87cR8F8e39M1gvALWwj6gtoUHUN5VqYSdU3ZvB/lzCdTkAgQsyVWzRoTn4p2m/sQpH8LIye84W+SpC0BtM8tCWcBJjvqPAkgsNoQYnIEdgvsfMxOgopqBX+AWScUocncpYp/Y7ppoglnsGmknSYFXZ/B9+GZ17JQteYIAW4xpB6R9iaguePYeY/4EGbVSLmYu/ra0ZTWYHy6q93bo8mP058RrLLZrQJssNfTGjME8oK0ZQeMurT7eff9GAEZ5lF5EpeWRBKOErEAh--kZj56Dq2i1xOuoXB--+WEEl+0JSyi7DckTdqAZCg== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..a20237c4f0 --- /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: spagh-ettsi_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: spagh-ettsi + + # 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: spagh-ettsi_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: spagh-ettsi_production + username: spagh-ettsi + password: <%= ENV['SPAGH-ETTSI_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..a1ca265dbe --- /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 = "spagh-ettsi_#{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..bb776f6750 --- /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", callback_path:'/auth/github/callback' +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..2dad4c29ca --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,46 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root 'pages#home' + get "/auth/:provider/callback", to: "sessions#create", as: 'auth_callback' + get '/dashboard', to: "users#dashboard", as: 'dashboard' + get '/pages/contact_us', to: 'pages#contact_us', as: 'contact_us' + delete "/logout", to: "sessions#destroy", as: "logout" + get '/shopping_cart', to: 'orders#shopping_cart', as: 'shopping_cart' + patch '/shopping_cart', to: 'order_products#update', as: 'order_product' + get '/checkout', to: 'orders#edit', as: 'checkout' + post '/checkout', to: 'orders#update' + + get '/account', to: 'users#show', as: 'account' + patch '/product/:id', to: 'products#deactivate', as: 'deactivate_product' + patch '/users/:id', to: 'users#update', as: 'update_user' + post '/users/:id', to: 'users#update' + get '/merchant/orders', to: 'users#orders_index', as: 'merchant_orders' + get '/merchant/orders/:id', to: 'users#order_show', as: 'merchant_order' + patch '/merchant/orders/:id', to: 'orders#mark_as_shipped', as: 'mark_as_shipped' + get '/products_by_merchant', to: 'products#index_by_merchant', as: 'products_by_merchant' #should change this to products_index_by_merchant + get '/merchant/my_products', to: 'users#products_index', as: 'merchant_my_products' + + get '/product/:id/reviews/new', to: 'reviews#new', as: 'new_product_review' + post '/product/:id/reviews/', to: 'reviews#create', as: 'create_review' + resources :products do + resources :reviews, only: [:index, :create] + end + + + resources :reviews, only: [:index, :new, :create] + + + + resources :users, only: [:create, :show] #do + # resources :products, only: [:show, :edit] + # end + resources :addresses + resources :payments + + resources :orders + resources :sessions, only: [:create, :destroy] + resources :order_products, only: [:create] + # resources :orders do + # resources :products, only: [:create] + # end +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/address_seeds.csv b/db/address_seeds.csv new file mode 100644 index 0000000000..16b589324a --- /dev/null +++ b/db/address_seeds.csv @@ -0,0 +1,21 @@ +user_id,first_name,last_name,street,street_2,city,state,zip +6,Malinda,Smith,73094 Keira Shores,Apt. 320,Bartonfort,OK,79875 +9,Sean,Murazik,748 Bartell Mountains,Apt. 959,Windlerhaven,AZ,16790 +2,Kelly,Cormier,79946 Anna Stream,Apt. 237,Lloydstad,IL,96189 +15,Solomon,Balistreri,41093 Bailey Creek,Suite 129,Lake Feliceview,OK,24238 +9,Emory,Shields,4890 Kovacek Views,Apt. 775,Port Sadehaven,NV,23438 +19,Maximo,Schimmel,26934 Rolande Knoll,Suite 565,New Lizamouth,OH,14311 +1,Jude,Satterfield,4040 Maryam Motorway,Suite 513,New Kraigmouth,LA,93230 +18,Stephen,Jacobs,78156 Deonna Courts,Suite 233,Lake Regena,NH,13366 +20,Matt,Medhurst,1500 Cathie Terrace,Apt. 420,Lake Harrison,MD,36730 +10,Ira,Bahringer,66856 Leigh Fords,Apt. 869,South Lavon,SC,46067 +20,Mohamed,Herzog,763 Mosciski Cove,Apt. 784,South Yulanda,OH,89261 +17,Wilburn,Padberg,2971 Nicky Wells,Suite 282,Jodytown,WY,99912 +20,Cory,Gleichner,67856 Howell Valleys,Suite 596,Roryville,ID,14195 +7,Lin,Sporer,610 Rory Trafficway,Apt. 627,North Calandraborough,ME,78945 +16,Angel,Lubowitz,88326 Hildegarde Green,Apt. 188,South Janee,GA,53829 +20,Jimmy,Runte,19077 Borer Islands,Suite 127,South Margyville,MS,45979 +19,Owen,Legros,995 Hammes Causeway,Apt. 752,Raymondberg,TX,83075 +16,Deandre,Bartell,188 Stehr Parks,Suite 816,West Claretta,VT,53136 +1,Tristan,Mraz,937 Yee Fort,Apt. 652,North Mahalia,IL,51076 +3,Dusty,Moen,87314 Clifton Glen,Apt. 949,East See,SD,76376 diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb new file mode 100644 index 0000000000..6db3b8b7d8 --- /dev/null +++ b/db/generate_seeds.rb @@ -0,0 +1,140 @@ +require 'faker' +require 'date' +require 'csv' + +CSV.open('db/user_seeds.csv', "w", :write_headers=> true, + :headers => ["full_name", "email", "is_a_seller", "uid", "provider"]) do |csv| + + 20.times do + full_name = Faker::Name.name + email = Faker::Internet.email("#{full_name.split}") + is_a_seller = true + uid = rand(11111111..99999999) + provider = %w(github twitter facebook google).sample + + csv << [full_name, email, is_a_seller, uid, provider] + end +end + +CSV.open('db/address_seeds.csv', "w", :write_headers=> true, + :headers => ["user_id", "first_name", "last_name", "street", "street_2", "city","state", "zip"]) do |csv| + + 20.times do + user_id = rand(1..20) + first_name = Faker::Name.first_name + last_name = Faker::Name.last_name + street = Faker::Address.street_address + street_2 = Faker::Address.secondary_address + city = Faker::Address.city + state = Faker::Address.state_abbr + zip = rand(11111..99999) + + + csv << [user_id, first_name, last_name, street, street_2, city, state, zip] + end +end + +CSV.open('db/payment_seeds.csv', "w", :write_headers=> true, + :headers => ["user_id", "address_id", "card_number", "expiration_date", "cvv", "card_type"]) do |csv| + + 20.times do + + user_id = rand(1..20) + address_id = rand(1..20) + card_number = rand(111111111111111..999999999999999) + expiration_date = Faker::Date.forward(600) + cvv = rand(111..9999) + card_type = %w(AMEX VISA MASTERCARD DISCOVER).sample + + + csv << [user_id, address_id, card_number, expiration_date, cvv, card_type] + end +end + + +CSV.open("db/product_seeds.csv", "w", :write_headers=> true, + :headers => ["category", "name", "user_id", "price_in_cents", "description", "quantity", "image_url"]) do |csv| + pasta = ["Callentani", "Capellini", "Ditalini", "Elbow", "Farfalle", + "Fettuccine", "Gemelli", "Gluten-free Shells", "Jumbo Shells", "Lasagna", + "Manicotti", "Medium Shells", "Orzo", "Pappardelle", "Pastina", + "Penne", "Ravioli", "Rotini", "Spaghetti", "Tortellini"] + images = ["callentani.jpg", "capellini.jpg", "ditalini.jpg", "elbow.jpg", + "farfalle.jpg", "fettuccine.jpg", "gemelli.jpg", "gluten-free.jpg", + "large-shell.jpg", "lasagna.jpg", "manicotti.jpg", "medium-shell.jpg", + "orzo.jpg", "pappardelle.jpg", "pastina.jpg", "penne.jpg", "ravioli.jpg", + "rotini.jpg", "spaghetti.jpg", "tortellini.jpg"] + categories = ["short", "long", "soup", "short", "short", "long", "short", "shell", + "shell", "sheet", "filled", "shell", "soup", "long", "soup", "short", "filled", + "short", "long", "filled"] + + 20.times do |i| + + category = categories[i] + name = pasta[i] + user_id = rand(1..20) + price_in_cents = rand(100..699) + description = Faker::Cannabis.health_benefit + quantity = rand(1..20) + image_url = images[i] + + csv << [category, name, user_id, price_in_cents, description, quantity, image_url] + + end + + CSV.open('db/order_seeds.csv', "w", :write_headers=> true, + :headers => ["user_id", "status", "payment_id", "address_id"]) do |csv| + + 20.times do + user_id = rand(1..20) + status = "paid" + payment_id = rand(1..20) + address_id = rand(1..20) + + csv << [user_id, status, payment_id, address_id] + end + + end + + CSV.open('db/order_products_seeds.csv', "w", :write_headers=> true, + :headers => ["order_id", "product_id", "quantity"]) do |csv| + + 20.times do + order_id = rand(1..20) + product_id = rand(1..20) + quantity = rand(1..20) + + csv << [order_id, product_id, quantity] + end + + end + + CSV.open('db/review_seeds.csv', "w", :write_headers=> true, + :headers => ["user_id", "product_id", "review", "rating"]) do |csv| + + 20.times do + + user_id = rand(1..20) + product_id = rand(1..20) + review = Faker::Lorem.paragraph(3) + rating = rand(1..5) + + csv << [user_id, product_id, review, rating] + end + + end + +end + +# CSV.open("db/order_products_seeds.csv", "w", :write_headers=> true, +# :headers => ["user_id", "status","payment_id", "address_id"]) do |csv| +# +# 20.times do +# user_id = rand(1..25) +# status = %w(pending paid complete cancelled).sample +# payment_id = rand(1..2000) +# address_id = rand(1..200) +# +# +# csv << [user_id, status, payment_id, address_id] +# end +# end diff --git a/db/migrate/20181017210518_create_users.rb b/db/migrate/20181017210518_create_users.rb new file mode 100644 index 0000000000..084bce50cc --- /dev/null +++ b/db/migrate/20181017210518_create_users.rb @@ -0,0 +1,14 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.string :first_name + t.string :last_name + t.string :email + t.boolean :is_a_seller + t.integer :uid + t.string :provider + + t.timestamps + end + end +end diff --git a/db/migrate/20181017210746_create_addresses.rb b/db/migrate/20181017210746_create_addresses.rb new file mode 100644 index 0000000000..84f10c0ff9 --- /dev/null +++ b/db/migrate/20181017210746_create_addresses.rb @@ -0,0 +1,16 @@ +class CreateAddresses < ActiveRecord::Migration[5.2] + def change + create_table :addresses do |t| + t.references :user, foreign_key: true + t.string :first_name + t.string :last_name + t.string :street + t.string :street_2 + t.string :city + t.string :state + t.integer :zip + + t.timestamps + end + end +end diff --git a/db/migrate/20181017211246_create_payments.rb b/db/migrate/20181017211246_create_payments.rb new file mode 100644 index 0000000000..9ff68e335e --- /dev/null +++ b/db/migrate/20181017211246_create_payments.rb @@ -0,0 +1,14 @@ +class CreatePayments < ActiveRecord::Migration[5.2] + def change + create_table :payments do |t| + t.references :user, foreign_key: true + t.references :address, foreign_key: true + t.integer :card_number + t.date :expiration_date + t.integer :cvv + t.string :card_type + + t.timestamps + end + end +end diff --git a/db/migrate/20181017211745_create_products.rb b/db/migrate/20181017211745_create_products.rb new file mode 100644 index 0000000000..e57bc8fecd --- /dev/null +++ b/db/migrate/20181017211745_create_products.rb @@ -0,0 +1,14 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.string :name + t.references :user, foreign_key: true + t.integer :price_in_cents + t.integer :quantity + t.string :category + t.text :description + + t.timestamps + end + end +end diff --git a/db/migrate/20181017212150_create_orders.rb b/db/migrate/20181017212150_create_orders.rb new file mode 100644 index 0000000000..6033b78ac1 --- /dev/null +++ b/db/migrate/20181017212150_create_orders.rb @@ -0,0 +1,12 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.references :user, foreign_key: true + t.string :status + t.references :payment, foreign_key: true + t.references :address, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20181017212433_create_reviews.rb b/db/migrate/20181017212433_create_reviews.rb new file mode 100644 index 0000000000..cee8a6a07b --- /dev/null +++ b/db/migrate/20181017212433_create_reviews.rb @@ -0,0 +1,12 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.references :user, foreign_key: true + t.references :product, foreign_key: true + t.text :review + t.integer :rating + + t.timestamps + end + end +end diff --git a/db/migrate/20181017212647_create_order_products.rb b/db/migrate/20181017212647_create_order_products.rb new file mode 100644 index 0000000000..552bae0591 --- /dev/null +++ b/db/migrate/20181017212647_create_order_products.rb @@ -0,0 +1,10 @@ +class CreateOrderProducts < ActiveRecord::Migration[5.2] + def change + create_table :order_products do |t| + t.references :order, foreign_key: true + t.references :product, foreign_key: true + t.integer :quantity + t.timestamps + end + end +end diff --git a/db/migrate/20181018031441_change_cc_to_big_int.rb b/db/migrate/20181018031441_change_cc_to_big_int.rb new file mode 100644 index 0000000000..10c6bcee6d --- /dev/null +++ b/db/migrate/20181018031441_change_cc_to_big_int.rb @@ -0,0 +1,5 @@ +class ChangeCcToBigInt < ActiveRecord::Migration[5.2] + def change + change_column :payments, :card_number, :bigint + end +end diff --git a/db/migrate/20181019205406_add_image_attribute_to_products.rb b/db/migrate/20181019205406_add_image_attribute_to_products.rb new file mode 100644 index 0000000000..d558b3ce92 --- /dev/null +++ b/db/migrate/20181019205406_add_image_attribute_to_products.rb @@ -0,0 +1,5 @@ +class AddImageAttributeToProducts < ActiveRecord::Migration[5.2] + def change + add_column :products, :image_url, :string + end +end diff --git a/db/migrate/20181020192042_change_user_name_field.rb b/db/migrate/20181020192042_change_user_name_field.rb new file mode 100644 index 0000000000..572d77259d --- /dev/null +++ b/db/migrate/20181020192042_change_user_name_field.rb @@ -0,0 +1,7 @@ +class ChangeUserNameField < ActiveRecord::Migration[5.2] + def change + remove_column :users, :first_name + remove_column :users, :last_name + add_column :users, :full_name, :string + end +end diff --git a/db/migrate/20181022180831_add_default_value_users.rb b/db/migrate/20181022180831_add_default_value_users.rb new file mode 100644 index 0000000000..e6de3a9cc3 --- /dev/null +++ b/db/migrate/20181022180831_add_default_value_users.rb @@ -0,0 +1,5 @@ +class AddDefaultValueUsers < ActiveRecord::Migration[5.2] + def change + change_column :users, :is_a_seller, :boolean, :default => false + end +end diff --git a/db/migrate/20181023010956_add_column_to_products.rb b/db/migrate/20181023010956_add_column_to_products.rb new file mode 100644 index 0000000000..11bffe3445 --- /dev/null +++ b/db/migrate/20181023010956_add_column_to_products.rb @@ -0,0 +1,5 @@ +class AddColumnToProducts < ActiveRecord::Migration[5.2] + def change + add_column :products, :is_active, :boolean, :default => true + end +end diff --git a/db/order_products_seeds.csv b/db/order_products_seeds.csv new file mode 100644 index 0000000000..3eb1bc4f3e --- /dev/null +++ b/db/order_products_seeds.csv @@ -0,0 +1,21 @@ +order_id,product_id,quantity +17,9,6 +10,2,4 +10,17,3 +5,2,5 +9,9,12 +7,17,18 +17,9,17 +14,2,10 +8,10,14 +8,5,17 +2,14,11 +2,4,16 +7,13,3 +10,8,17 +8,13,12 +13,17,19 +1,11,7 +15,2,9 +18,9,6 +4,7,5 diff --git a/db/order_seeds.csv b/db/order_seeds.csv new file mode 100644 index 0000000000..877757a5c4 --- /dev/null +++ b/db/order_seeds.csv @@ -0,0 +1,21 @@ +user_id,status,payment_id,address_id +4,paid,14,9 +1,paid,19,11 +17,paid,2,5 +5,paid,9,4 +18,paid,16,13 +16,paid,5,2 +14,paid,5,12 +9,paid,17,7 +1,paid,5,17 +15,paid,9,15 +17,paid,20,8 +20,paid,13,11 +9,paid,18,15 +19,paid,18,12 +9,paid,4,16 +8,paid,13,9 +1,paid,2,18 +17,paid,13,8 +13,paid,16,16 +15,paid,18,13 diff --git a/db/payment_seeds.csv b/db/payment_seeds.csv new file mode 100644 index 0000000000..a14d0c0def --- /dev/null +++ b/db/payment_seeds.csv @@ -0,0 +1,21 @@ +user_id,address_id,card_number,expiration_date,cvv,card_type +5,19,648310350969462,2019-03-21,1699,VISA +4,2,864580070827161,2020-06-02,6811,VISA +15,20,808172804817563,2019-08-20,5901,AMEX +15,16,259211036110080,2019-07-20,2343,DISCOVER +17,19,592593981154352,2020-05-20,8690,MASTERCARD +13,7,465144674086463,2019-09-28,6260,MASTERCARD +14,2,323889356816708,2019-07-18,9237,VISA +11,9,994190517085571,2019-04-17,7309,VISA +8,13,890096716811943,2019-01-11,9899,MASTERCARD +5,15,319477663022404,2019-10-25,5624,AMEX +16,17,265566687666886,2019-08-05,2975,MASTERCARD +13,1,760737854449123,2019-05-20,8339,AMEX +20,6,280982471294632,2019-07-29,3359,MASTERCARD +2,20,566404910252770,2019-04-30,6907,AMEX +18,16,868738353152065,2020-04-04,3414,VISA +5,18,931999412440854,2019-01-13,2496,DISCOVER +12,17,362093968991114,2019-12-03,9312,AMEX +18,16,885111029073865,2018-10-30,7087,AMEX +15,17,631079298655678,2019-01-14,5120,AMEX +7,3,985811364391153,2018-11-10,8037,MASTERCARD diff --git a/db/product_seeds.csv b/db/product_seeds.csv new file mode 100644 index 0000000000..629d4d0ba6 --- /dev/null +++ b/db/product_seeds.csv @@ -0,0 +1,21 @@ +category,name,user_id,price_in_cents,description,quantity,image_url +short,Callentani,17,170,tranquilizing,18,callentani.jpg +long,Capellini,17,236,reduces blood sugar levels,8,capellini.jpg +soup,Ditalini,11,106,treats fungal infection,1,ditalini.jpg +short,Elbow,4,576,relieves pain,14,elbow.jpg +short,Farfalle,9,640,inhibits cell growth in tumors/cancer cells,19,farfalle.jpg +long,Fettuccine,16,472,treats fungal infection,11,fettuccine.jpg +short,Gemelli,2,644,relieves congestion,1,gemelli.jpg +shell,Gluten-free Shells,6,341,reduces inflammation,13,gluten-free.jpg +shell,Jumbo Shells,7,160,stimulates function in the immune system,4,large-shell.jpg +sheet,Lasagna,11,159,protects against nervous system degeneration,10,lasagna.jpg +filled,Manicotti,8,376,aids sleep,2,manicotti.jpg +shell,Medium Shells,11,518,relieves pain,3,medium-shell.jpg +soup,Orzo,15,532,treats depression,15,orzo.jpg +long,Pappardelle,5,416,reduces blood sugar levels,3,pappardelle.jpg +soup,Pastina,14,591,improves airflow to lungs,9,pastina.jpg +short,Penne,4,439,tranquilizing,14,penne.jpg +filled,Ravioli,8,641,treats fungal infection,17,ravioli.jpg +short,Rotini,14,439,stimulates function in the immune system,20,rotini.jpg +long,Spaghetti,8,699,kills or slows bacteria growth,13,spaghetti.jpg +filled,Tortellini,5,381,treats allergy symptoms,20,tortellini.jpg diff --git a/db/review_seeds.csv b/db/review_seeds.csv new file mode 100644 index 0000000000..d4f5a89b9a --- /dev/null +++ b/db/review_seeds.csv @@ -0,0 +1,21 @@ +user_id,product_id,review,rating +20,3,Necessitatibus nostrum ullam. Qui est eos. Debitis quia alias.,4 +1,16,Laudantium et nemo. Id consequatur non. Ut amet ea.,3 +15,19,Sit possimus modi. Omnis velit ullam. Laboriosam non totam.,3 +7,8,Impedit est ut. Quae laudantium aliquam. Autem dolor iure.,4 +10,10,Autem quia quam. Animi fuga nihil. Qui aut est.,4 +3,17,Fuga id dicta. Sint fugit cupiditate. Voluptatum qui laudantium.,1 +8,12,Praesentium repellat tempore. Facere deleniti eos. In inventore et.,2 +9,12,Eius qui sed. Est iusto eum. Maxime facilis commodi.,4 +18,6,Illo minima commodi. Aut tenetur earum. Saepe consequuntur dolor.,5 +17,8,Deleniti corrupti reiciendis. Velit nulla repudiandae. Eum voluptatibus vero.,5 +20,11,Consectetur praesentium quisquam. Dolores et totam. Qui impedit quo.,5 +2,6,Eligendi voluptas voluptatem. Officia sed qui. Qui iste deleniti.,1 +9,6,Modi magnam qui. Nesciunt fugiat non. Rerum sit eaque.,2 +6,19,Repellendus consequuntur officiis. Sunt dolores reiciendis. Ratione voluptatem et.,3 +18,3,Eum quas non. Eius eos sit. Pariatur sequi enim.,1 +7,14,Dignissimos accusantium enim. Nesciunt non voluptatibus. Consequuntur aut eaque.,3 +4,2,Porro architecto facere. Voluptatem sequi natus. Ut natus provident.,3 +18,14,Et at vitae. Quo et ea. Ratione quos commodi.,2 +1,5,Quae suscipit fugit. Amet sequi qui. Sit aut expedita.,3 +1,8,Et dolor magnam. Et molestias quo. Optio iste voluptatem.,2 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..0254079dc5 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,113 @@ +# 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_23_010956) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "addresses", force: :cascade do |t| + t.bigint "user_id" + t.string "first_name" + t.string "last_name" + t.string "street" + t.string "street_2" + t.string "city" + t.string "state" + t.integer "zip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_addresses_on_user_id" + end + + create_table "order_products", force: :cascade do |t| + t.bigint "order_id" + t.bigint "product_id" + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["order_id"], name: "index_order_products_on_order_id" + t.index ["product_id"], name: "index_order_products_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.bigint "user_id" + t.string "status" + t.bigint "payment_id" + t.bigint "address_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["address_id"], name: "index_orders_on_address_id" + t.index ["payment_id"], name: "index_orders_on_payment_id" + t.index ["user_id"], name: "index_orders_on_user_id" + end + + create_table "payments", force: :cascade do |t| + t.bigint "user_id" + t.bigint "address_id" + t.bigint "card_number" + t.date "expiration_date" + t.integer "cvv" + t.string "card_type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["address_id"], name: "index_payments_on_address_id" + t.index ["user_id"], name: "index_payments_on_user_id" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.bigint "user_id" + t.integer "price_in_cents" + t.integer "quantity" + t.string "category" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "image_url" + t.boolean "is_active", default: true + t.index ["user_id"], name: "index_products_on_user_id" + end + + create_table "reviews", force: :cascade do |t| + t.bigint "user_id" + t.bigint "product_id" + t.text "review" + t.integer "rating" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["product_id"], name: "index_reviews_on_product_id" + t.index ["user_id"], name: "index_reviews_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "email" + t.boolean "is_a_seller", default: false + t.integer "uid" + t.string "provider" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "full_name" + end + + add_foreign_key "addresses", "users" + add_foreign_key "order_products", "orders" + add_foreign_key "order_products", "products" + add_foreign_key "orders", "addresses" + add_foreign_key "orders", "payments" + add_foreign_key "orders", "users" + add_foreign_key "payments", "addresses" + add_foreign_key "payments", "users" + add_foreign_key "products", "users" + add_foreign_key "reviews", "products" + add_foreign_key "reviews", "users" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..83078d48b1 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,217 @@ +# 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 user data from #{USER_FILE}" + +user_failures = [] +CSV.foreach(USER_FILE, :headers => true) do |row| + + user = User.new( + full_name: row['full_name'], + email: row['email'], + is_a_seller: row['is_a_seller'], + uid: row['uid'], + provider: row['provider'] + ) + + + successful = user.save + + if !successful + user_failures << user + puts "Failed to save user: #{user.inspect}" + puts "#{user.errors.full_messages}" + else + puts "Created user: #{user.inspect}" + end +end + + +ADDRESSES_FILE = Rails.root.join('db', 'address_seeds.csv') +puts "Loading raw user data from #{ADDRESSES_FILE}" + +address_failures = [] +CSV.foreach(ADDRESSES_FILE, :headers => true) do |row| + address = Address.new( + user_id: row['user_id'], + first_name: row['first_name'], + last_name: row['last_name'], + street: row['street'], + street_2: row['street_2'], + city: row['city'], + state: row['state'], + zip: row['zip'], + ) + + successful = address.save + + if !successful + address_failures << address + puts "Failed to save address: #{address.inspect}" + puts "#{address.errors.full_messages}" + else + puts "Created address: #{address.inspect}" + end +end + + +PAYMENTS_FILE = Rails.root.join('db', 'payment_seeds.csv') +puts "Loading raw user data from #{PAYMENTS_FILE}" + +payment_failures = [] +CSV.foreach(PAYMENTS_FILE, :headers => true) do |row| + payment = Payment.new( + user_id: row['user_id'], + address_id: row['address_id'], + card_number: row['card_number'], + expiration_date: row['expiration_date'], + cvv: row['cvv'], + card_type: row['card_type'] + ) + + successful = payment.save + + if !successful + payment_failures << payment + puts "Failed to save payment: #{payment.inspect}" + puts "#{payment.errors.full_messages}" + else + puts "Created payment: #{payment.inspect}" + end +end + + + + +PRODUCT_FILE = Rails.root.join('db', 'product_seeds.csv') +puts "Loading raw product data from #{PRODUCT_FILE}" + +product_failures = [] +CSV.foreach(PRODUCT_FILE, :headers => true) do |row| + product = Product.new( + + category: row['category'], + name: row['name'], + user_id: row['user_id'], + price_in_cents: row['price_in_cents'], + description: row['description'], + quantity: row['quantity'], + image_url: row['image_url'] + ) + + successful = product.save + + if !successful + product_failures << product + puts "Failed to save product: #{product.inspect}" + puts "#{product.errors.full_messages}" + else + puts "Created product: #{product.inspect}" + end +end + +ORDER_FILE = Rails.root.join('db', 'order_seeds.csv') +puts "Loading raw user data from #{ORDER_FILE}" + +order_failures = [] +CSV.foreach(ORDER_FILE, :headers => true) do |row| + order = Order.new( + user_id: row['user_id'], + status: row['status'], + payment_id: row['payment_id'], + address_id: row['address_id'], + ) + + successful = order.save + + + if !successful + order_failures << user + puts "Failed to save order: #{order.inspect}" + puts "#{order.errors.full_messages}" + else + puts "Created order: #{order.inspect}" + end +end + +ORDER_PRODUCTS_FILE = Rails.root.join('db', 'order_products_seeds.csv') +puts "Loading raw user data from #{ORDER_PRODUCTS_FILE}" + +order_product_failures = [] +CSV.foreach(ORDER_PRODUCTS_FILE, :headers => true) do |row| + order_product = OrderProduct.new( + order_id: row['order_id'], + product_id: row['product_id'], + quantity: row['quantity'] + ) + + successful = order_product.save + + if !successful + order_product_failures << order_product + puts "Failed to save order_products: #{order_product.inspect}" + puts "#{order_product.errors.full_messages}" + else + puts "Created order_products: #{order_product.inspect}" + end +end + +REVIEWS_FILE = Rails.root.join('db', 'review_seeds.csv') +puts "Loading raw user data from #{REVIEWS_FILE}" + +review_failures = [] +CSV.foreach(REVIEWS_FILE, :headers => true) do |row| + review = Review.new( + user_id: row['user_id'], + product_id: row['product_id'], + review: row['review'], + rating: row['rating'] + ) + + successful = review.save + + if !successful + review_failures << review + + puts "Failed to save review: #{review.inspect}" + puts "#{review.errors.full_messages}" + else + puts "Created reviews: #{review.inspect}" + end +end + +puts "Added #{User.count} user records" +puts "#{user_failures.length} users failed to save." + +puts "Added #{Product.count} product records" +puts "#{product_failures.length} products failed to save." + +puts "Added #{OrderProduct.count} order_product records" +puts "#{order_product_failures.length} order_products failed to save." + +puts "Added #{Order.count} order records" +puts "#{order_failures.length} orders failed to save." + +puts "Added #{Address.count} address records" +puts "#{address_failures.length} address failed to save." + +puts "Added #{Payment.count} payment records" +puts "#{payment_failures.length} payments failed to save." + +puts "Added #{Review.count} review records" +puts "#{review_failures.length} reviews failed to save." + + +puts "Manually resetting PK sequence on each table" +ActiveRecord::Base.connection.tables.each do |t| + ActiveRecord::Base.connection.reset_pk_sequence!(t) + + +end diff --git a/db/user_seeds.csv b/db/user_seeds.csv new file mode 100644 index 0000000000..eb5fecf754 --- /dev/null +++ b/db/user_seeds.csv @@ -0,0 +1,21 @@ +full_name,email,is_a_seller,uid,provider +Mrs. Branden Yost,mrsbrandenyost@emardbatz.io,true,82675057,github +Mae Will,maewill@lemke.org,true,22266046,twitter +Myles Goldner,mylesgoldner@cormierkrajcik.io,true,75295767,github +Margarete Gleichner IV,ivmargaretegleichner@schimmelshanahan.io,true,45989803,google +Emerson Smitham DDS,ddsemersonsmitham@zemlakwintheiser.com,true,98811369,facebook +Lovella Swaniawski,lovellaswaniawski@franecki.biz,true,65227756,github +Nicki Mohr,mohrnicki@feil.com,true,50455725,github +Valorie Grant,valoriegrant@hirthe.info,true,20968976,google +Lizette Kerluke,lizettekerluke@gislason.info,true,82410707,twitter +Frederick Upton,frederickupton@schmeler.name,true,85416006,twitter +Rodolfo Kris,krisrodolfo@crist.io,true,68733380,twitter +Ms. Dwayne Klocko,klockomsdwayne@hintzgibson.biz,true,92676257,facebook +Kyle Legros,legroskyle@bradtkeschulist.info,true,22305621,twitter +Tracy Auer,auertracy@mcdermott.name,true,21183803,facebook +Donny Goldner,goldnerdonny@west.biz,true,19867062,google +Danna Romaguera,romagueradanna@kilbackgottlieb.com,true,32144852,google +Dominique Pfannerstill,dominiquepfannerstill@ledner.biz,true,67623444,twitter +Casey Bauch DVM,caseybauchdvm@pagaclindgren.info,true,61658205,google +Dr. Isabella Rosenbaum,isabelladrrosenbaum@dibbert.biz,true,98480819,github +Eddie Herzog,herzogeddie@batz.io,true,40224299,google 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..190fd20420 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "spagh-ettsi", + "private": true, + "dependencies": {} +} diff --git a/public/.DS_Store b/public/.DS_Store new file mode 100644 index 0000000000..95962d0909 Binary files /dev/null and b/public/.DS_Store differ 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/images/.DS_Store b/public/images/.DS_Store new file mode 100644 index 0000000000..5008ddfcf5 Binary files /dev/null and b/public/images/.DS_Store differ diff --git a/public/images/welcome.scss b/public/images/welcome.scss new file mode 100644 index 0000000000..0e3aa7915f --- /dev/null +++ b/public/images/welcome.scss @@ -0,0 +1,184 @@ +@import url('https://fonts.googleapis.com/css?family=K2D'); + +.homepage { + font-family: 'K2D'; + height: 100%; + width: 100%; + display: grid; + grid-template-columns: repeat(6, 1fr); + grid-template-rows: repeat(10, 1fr); + grid-template-areas: + "h h h h h h" + "k k k k k k" + "d d d p p p" + "d d d p p p" + "d d d p p p" + "d d d p p p" + "d d d p p p" + "i i i i i i" + "i i i i i i" + "i i i i i i" + "f f f f f f" +} + +.welcome-header { + height: 80px; + grid-area: h; + font-family: 'K2D'; + background-color: black; + color: white; + display: flex; + align-items: center; + // text-align: center; + border-bottom: 10px solid white; +} +.welcome-header h1, h2 { + text-align: center; +} + +.tagline { + grid-area: k; + text-align: center; +} + +.smurf { + width: 50px; + height: 50px; +} + +.home-button { + margin-left: auto; +} + +.home-button img{ + width: 35px; + height: 35px; + padding-right: 50px; + padding-top: 20px; +} + +.main-part { + height: 500px; + display: flex; + align-items: center; + justify-content: center; +} + +.driver { + grid-area: d; + background-image: url('driver.jpg'); + // margin: 10px; +} + +.passenger { + grid-area: p; + background-image: url('passenger.jpg'); + // margin: 10px; +} + +.info { + grid-area: i; + text-align: center; + padding: 2em; +} + +footer { + grid-area: f; + background-color: black; + color: white; + text-align: center; + border-top: 10px solid white; +} + + .welcome-button{ + font-family: 'K2D'; + background:white; + color: black; + border: 2px solid black; + border-radius: 8px; + position:relative; + height:60px; + font-size:1.6em; + padding:2em; + vertical-align: center; + margin-top: 30%; + cursor:pointer; + transition:800ms ease all; + outline:none; + background-image: linear-gradient(white,#F0FFFF); + text-decoration: none; + + } + .welcome-button:hover{ + background:#fff; + color:#1AAB8A; + } + .welcome-button:before,button:after{ + content:''; + position:absolute; + top:0; + right:0; + height:5px; + width:0; + background: black; + transition:400ms ease all; + } + .welcome-button:after{ + right:inherit; + top:inherit; + left:0; + bottom:0; + } + .welcome-button:hover:before,button:hover:after{ + width:100%; + transition:800ms ease all; + } + + /* Dropdown Button */ +.dropbtn { + background-color: black; + color: white; + padding: 15px; + font-size: 16px; + border: none; + border-bottom: 3px solid white; + margin: 10px; +} + +/* The container
- needed to position the dropdown content */ +.dropdown { + position: relative; + display: inline-block; + font-family: 'K2D'; +} + +.driver-dropdown { + margin-left: 50%; +} + +/* Dropdown Content (Hidden by Default) */ +.dropdown-content { + display: none; + position: absolute; + background-color: #f1f1f1; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1; +} + +/* Links inside the dropdown */ +.dropdown-content a { + color: black; + padding: 12px 16px; + text-decoration: none; + display: block; +} + +/* Change color of dropdown links on hover */ +.dropdown-content a:hover {background-color: #DEB887;} + +/* Show the dropdown menu on hover */ +.dropdown:hover .dropdown-content {display: block;} + +/* Change the background color of the dropdown button when the dropdown content is shown */ +.dropdown:hover .dropbtn {background-color: #5F9EA0;} diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000000..37b576a4a0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/controllers/addresses_controller_test.rb b/test/controllers/addresses_controller_test.rb new file mode 100644 index 0000000000..41db21eee1 --- /dev/null +++ b/test/controllers/addresses_controller_test.rb @@ -0,0 +1,102 @@ +require "test_helper" + +describe AddressesController do + let(:buyer) {users(:buyer)} + let(:seller) {users(:seller)} + let(:mock_params) { + { + address: { + user_id: buyer.id, + first_name: "Gunther", + last_name: "Centralperk", + street: "Central Perk", + street_2: nil, + city: "New York", + state: "NY", + zip: 10001 + } + } + } + + + describe "new" do + + it "succeeds when user is logged in" do + perform_login(buyer) + get new_address_path + must_respond_with :success + end + + it 'responds with bad request with no user logged in' do + get new_address_path + + must_respond_with :bad_request + + end + end + + describe "create" do + + it "creates an address with valid data with a logged in user" do + perform_login(buyer) + + expect { + post addresses_path, params: mock_params + }.must_change 'Address.count', 1 + + address = Address.last + + expect(address.user_id).must_equal mock_params[:address][:user_id] + expect(address.first_name).must_equal mock_params[:address][:first_name] + expect(address.last_name).must_equal mock_params[:address][:last_name] + expect(address.street).must_equal mock_params[:address][:street] + expect(address.street_2).must_equal mock_params[:address][:street_2] + expect(address.city).must_equal mock_params[:address][:city] + expect(address.state).must_equal mock_params[:address][:state] + expect(address.zip).must_equal mock_params[:address][:zip] + + must_redirect_to checkout_path + + end + + it "responds with bad request and won't change DB if address user is not logged in user" do + perform_login(seller) + + expect { + post addresses_path, params: mock_params + }.wont_change 'Address.count' + + + must_respond_with :bad_request + + end + + it "responds with bad request and won't change DB if no user logged in" do + + + expect { + post addresses_path, params: mock_params + }.wont_change 'Address.count' + + + must_respond_with :bad_request + + end + + it "renders bad_request and does not update the DB for bogus data" do + perform_login(buyer) + + mock_params[:address][:street] = nil + + expect { + post addresses_path, params: mock_params + }.wont_change 'Address.count' + + must_respond_with :bad_request + end + + + end + + +end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb new file mode 100644 index 0000000000..2eb4b98ff5 --- /dev/null +++ b/test/controllers/order_products_controller_test.rb @@ -0,0 +1,372 @@ +require "test_helper" + +describe OrderProductsController do + let(:order_one) {orders(:order_one)} + let(:fusilli) {products(:fusilli)} + let(:spaghetti) {products(:spaghetti)} + let(:buyer) {users(:buyer)} + let(:seller) {users(:seller)} + let(:order_one_spaghetti) {order_products(:order_one_spaghetti)} + let(:mock_params) { + { + order_product: { + product_id: fusilli.id, + quantity: 5 + } + } + } + + + + describe 'create' do + it 'creates a row in the OrderProducts table with valid unique data and logged in user' do + + perform_login(buyer) + + expect { + post order_products_path, params: mock_params + }.must_change 'OrderProduct.count', 1 + + must_redirect_to shopping_cart_path + + end + + it 'adds the product to the shopping cart of the logged-in user' do + perform_login(buyer) + + expect { + post order_products_path, params: mock_params + }.must_change 'OrderProduct.count', 1 + + new_entry = OrderProduct.last + + #the order_one fixture has the status of pending and user = buyer + expect(new_entry.order).must_equal order_one + expect(new_entry.product).must_equal fusilli + expect(new_entry.quantity).must_equal 5 + + must_redirect_to shopping_cart_path + end + + it 'modifies an existing row if the product/order combo is already in the table' do + + perform_login(buyer) + + mock_params[:order_product][:product_id] = spaghetti.id + + expect(order_one_spaghetti.quantity).must_equal 5 + + expect { + post order_products_path, params: mock_params + }.wont_change 'OrderProduct.count' + + order_one_spaghetti.reload + + expect(order_one_spaghetti.quantity).must_equal 10 + + must_redirect_to shopping_cart_path + + end + + it 'will not add to cart if there is not enough stock' do + perform_login(buyer) + + expect(fusilli.quantity).must_equal 20 + + mock_params[:order_product][:quantity] = 21 + + expect { + post order_products_path, params: mock_params + }.wont_change 'OrderProduct.count' + + fusilli.reload + + expect(fusilli.quantity).must_equal 20 + + must_redirect_to root_path + + + end + + it 'does not change db with invalid data' do + perform_login(buyer) + + mock_params[:order_product][:quantity] = nil + + expect { + post order_products_path, params: mock_params + }.wont_change 'OrderProduct.count' + + must_redirect_to root_path + + + end + + it 'decrements the quantity in the product model appropriately' do + perform_login(buyer) + + # fusilli wasn't already in cart + old_quantity = fusilli.quantity + + expect { + post order_products_path, params: mock_params + }.must_change 'OrderProduct.count', 1 + + fusilli.reload + + new_quantity = fusilli.quantity + + expect(old_quantity - new_quantity).must_equal 5 + + #spaghetti was already in cart + + mock_params[:order_product][:product_id] = spaghetti.id + + old_quantity = spaghetti.quantity + + expect { + post order_products_path, params: mock_params + }.wont_change 'OrderProduct.count' + + spaghetti.reload + + new_quantity = spaghetti.quantity + + expect(old_quantity - new_quantity).must_equal 5 + + end + + it 'prevents a seller from buying their own products' do + perform_login(seller) + + expect { + post order_products_path, params: mock_params + }.wont_change 'OrderProduct.count' + + must_respond_with :redirect + expect(flash[:warning]).must_equal "Mamma Mia! You can't purchase your own products. Just steal some from the supply closet!" + end + + it 'redirects to root path with a warning if invalid data is given' do + perform_login(buyer) + mock_params[:order_product][:product_id] = nil + + expect { + post order_products_path, params: mock_params + }.wont_change 'OrderProduct.count' + + must_redirect_to root_path + end + end + + + describe 'check_login' do + it 'does nothing if a user is already logged in' do + perform_login(buyer) + + expect(session[:user_id]).must_equal buyer.id + + #call create which uses check_login as a helper method + expect{ + post order_products_path, params: mock_params + }.wont_change 'User.count' + + expect(session[:user_id]).must_equal buyer.id + + end + + it 'with no user logged in, creates a new guest user instance and logs the guest user in' do + + expect{ + post order_products_path, params: mock_params + }.must_change 'User.count', 1 + + new_user = User.last + + expect(new_user.full_name).must_equal 'Guest user' + expect(new_user.email).must_equal 'example@example.com' + expect(new_user.is_a_seller).must_equal false + expect(new_user.provider).must_equal 'guest_login' + + expect(session[:user_id]).must_equal new_user.id + end + end + + describe 'check_shopping_cart' do + it 'sets the session shopping cart id if the user has an order with pending status' do + perform_login(buyer) + + #call create which uses check_shopping_cart as a helper method + expect{ + post order_products_path, params: mock_params + }.wont_change 'Order.count' + + #buyer has an open order called order_one + expect(session[:user_id]).must_equal buyer.id + expect(session[:shopping_cart_id]).must_equal order_one.id + + end + + it 'creates a new shopping cart attached to the logged-in user if the user does not have one and sets the session shopping cart id' do + perform_login(seller) + + #call create which uses check_shopping_cart as a helper method + #seller has no orders yet + expect{ + post order_products_path, params: mock_params + }.must_change 'Order.count', 1 + + new_order = Order.last + + expect(new_order.user).must_equal seller + + expect(session[:user_id]).must_equal seller.id + expect(session[:shopping_cart_id]).must_equal new_order.id + + end + + it 'creates a new shopping cart for the guest user' do + + #nobody logged in, no orders yet + old_order_count = Order.count + + expect{ + post order_products_path, params: mock_params + }.must_change 'User.count', 1 + + new_order_count = Order.count + + expect(new_order_count - old_order_count).must_equal 1 + + guest_user = User.last + guest_order = Order.last + + expect(guest_order.user).must_equal guest_user + expect(session[:user_id]).must_equal guest_user.id + expect(session[:shopping_cart_id]).must_equal guest_order.id + end + end + + describe 'update' do + let(:mock_update_params) { + { + order_product: + { + quantity: 3, + id: order_one_spaghetti.id + } + } + } + + it 'modifies an existing row given a valid id' do + #order_one_spaghetti = 5 in cart + + perform_login(buyer) + + expect(order_one_spaghetti.quantity).must_equal 5 + + expect{ + patch shopping_cart_path, params: mock_update_params + }.wont_change 'OrderProduct.count' + + order_one_spaghetti.reload + expect(order_one_spaghetti.quantity).must_equal 3 + + must_redirect_to shopping_cart_path + + end + + it 'fails with invalid id' do + perform_login(buyer) + + mock_update_params[:order_product][:id] = -1 + + expect{ + patch shopping_cart_path, params: mock_update_params + }.wont_change 'OrderProduct.count' + + must_redirect_to root_path + + end + + it 'deletes row if quantity is set to zero' do + perform_login(buyer) + + #no more spaghetti in order one + mock_update_params[:order_product][:quantity] = 0 + + expect{ + patch shopping_cart_path, params: mock_update_params + }.must_change 'OrderProduct.count', -1 + + expect(OrderProduct.find_by(order: order_one, product: spaghetti)).must_equal nil + + end + + it 'updates the product inventory appropriately when buying more' do + # ----- increase order quantity by 10 + + perform_login(buyer) + + #in cart + expect(order_one_spaghetti.quantity).must_equal 5 + + #inventory + expect(spaghetti.quantity).must_equal 50 + + mock_update_params[:order_product][:quantity] = 15 + + expect{ + patch shopping_cart_path, params: mock_update_params + }.wont_change 'OrderProduct.count' + + #in cart plus 10 + order_one_spaghetti.reload + expect(order_one_spaghetti.quantity).must_equal 15 + + #inventory minus 10 + spaghetti.reload + expect(spaghetti.quantity).must_equal 40 + end + + it 'updates the product inventory appropriately when buying fewer' do + # ------ decrease order quantity by 3 + + expect(order_one_spaghetti.quantity).must_equal 5 + + mock_update_params[:order_product][:quantity] = 2 + + expect{ + patch shopping_cart_path, params: mock_update_params + }.wont_change 'OrderProduct.count' + + #in cart minus 3 + order_one_spaghetti.reload + expect(order_one_spaghetti.quantity).must_equal 2 + + #inventory plus 3 + spaghetti.reload + expect(spaghetti.quantity).must_equal 53 + end + + it 'updates the product inventory appropriately when buying zero' do + # ------ decrease order quantity by 5 + + expect(order_one_spaghetti.quantity).must_equal 5 + + mock_update_params[:order_product][:quantity] = 0 + + #deletes row from order_products table + expect{ + patch shopping_cart_path, params: mock_update_params + }.must_change 'OrderProduct.count', -1 + + + #inventory plus 5 + spaghetti.reload + expect(spaghetti.quantity).must_equal 55 + 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..76556aeb7f --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,184 @@ +require "test_helper" + +describe OrdersController do + let(:order_one) {orders(:order_one)} + let(:order_two) {orders(:order_two)} + let(:order_three) {orders(:order_three)} + let(:buyer) {users(:buyer)} + let(:seller) {users(:seller)} + + let(:order_params) { + { + full_name: 'Ron Howard', + email: 'happy@days.com', + payment_id: payments(:amex).id, + address_id: addresses(:school).id, + status: :paid + + } + } + + let(:op_params) { + { + order_product: { + product_id: products(:fusilli).id, + quantity: 5 + } + } + } + + describe 'show' do + it 'succeeds with a logged-in user viewing their own non-pending order given a valid ID' do + perform_login(buyer) + get order_path(order_two.id) + + must_respond_with :success + end + + it 'responds with not found with a logged-in user trying to view a pending order given a valid ID' do + perform_login(buyer) + get order_path(order_one.id) + + must_respond_with :not_found + end + + it 'responds with not found with a logged-in user trying to view someone elses order with valid ID' do + perform_login(buyer) + get order_path(order_three.id) + + must_respond_with :not_found + end + + it 'responds with not found with a logged-in user given an invalid ID' do + perform_login(buyer) + get order_path(-1) + + must_respond_with :not_found + end + + it 'redirects to root if a user is not logged in given a valid ID' do + get order_path(order_two.id) + + must_redirect_to root_path + end + + it 'clears the session to remove a guest login after displaying order summary' do + post order_products_path, params: op_params #start a shopping cart to create guest login + new_order = Order.last + expect(new_order.user.provider).must_equal 'guest_login' + + patch order_path(new_order.id), params: order_params #complete the order + + get order_path(new_order.id) + + expect(session[:user_id]).must_equal nil + end + end + + describe 'edit, which is actually checkout form' do + it 'succeeds with a logged-in user given a pending order with valid ID' do + perform_login(buyer) + get edit_order_path(order_one.id) + + must_respond_with :success + end + + it 'succeeds as checkout_path when a user has a pending order' do + perform_login(buyer) + get checkout_path + + must_respond_with :success + end + + it 'responds with not found if a user has no pending order' do + perform_login(seller) + get checkout_path + must_respond_with :not_found + end + + + # it 'responds with not found with a logged-in user given a non-pending order with valid ID' do + # perform_login(buyer) + # get edit_order_path(order_two.id) + # + # must_respond_with :not_found + # end + #changed edit path to checkout so overrides this capability + # + # it 'responds with not found with a logged-in user with someone elses valid order ID' do + # perform_login(buyer) + # get edit_order_path(order_three.id) + # + # must_respond_with :not_found + # end + + it 'redirects to root with no user logged in (guest user is technically a login)' do + get edit_order_path(order_three.id) + + must_redirect_to root_path + end + + end + + describe 'mark_as_shipped' do + it 'changes order status from paid to shipped with logged in user and valid ID' do + perform_login(seller) + + expect(order_two.status).must_equal 'paid' + + patch mark_as_shipped_path(order_two.id) + + order_two.reload + expect(order_two.status).must_equal 'complete' + end + + end + + describe 'update' do + it 'updates the order with a logged-in user given valid data and redirects to order show page' do + perform_login(buyer) + patch order_path(order_one.id), params: order_params + + must_redirect_to order_path(order_one.id) + end + + it 'redirects back with a flash warning with logged-in user given invalid data' do + perform_login(buyer) + order_params[:payment_id] = nil + + patch order_path(order_one.id), params: order_params + + must_respond_with :redirect + expect(flash[:warning]).must_equal "Unable to place order" + end + + it 'redirects back with a flash warning with logged-in user (guest mock login) using invalid name or email' do + perform_login(buyer) + order_params[:full_name] = nil + + patch order_path(order_one.id), params: order_params + + must_respond_with :redirect + expect(flash[:warning]).must_equal "An error occurred. Please try again." + end + + it 'redirects to root path with no login user' do + patch order_path(order_one.id), params: order_params + + must_redirect_to root_path + end + + it 'prevents checkout with an empty cart' do + perform_login(buyer) + order_one.order_products.each do |op| + op.delete + end + post checkout_path, params: order_params + + must_redirect_to products_path + end + + end + + +end diff --git a/test/controllers/payments_controller_test.rb b/test/controllers/payments_controller_test.rb new file mode 100644 index 0000000000..ebfe62170f --- /dev/null +++ b/test/controllers/payments_controller_test.rb @@ -0,0 +1,65 @@ +require "test_helper" + +describe PaymentsController do + let(:buyer) {users(:buyer)} + let(:home) {addresses(:home)} + let(:mock_payment_params) { + { + payment: { + user_id: buyer.id, + address_id: home.id, + card_number: 123456789012334, + expiration_date: Date.today, + cvv: 123, + card_type: 'AMEX' + } + } + } + + describe 'new' do + it "succeeds when a user is logged in" do + @login_user = buyer + get new_payment_path + must_respond_with :success + end + + it "succeeds if a user is not logged in" do + @login_user = nil + get new_payment_path + must_respond_with :success + end + end + + describe 'create' do + it "creates a payment with valid data" do + expect { + post payments_path, params: mock_payment_params + }.must_change 'Payment.count', 1 + + payment = Payment.find_by(card_number: mock_payment_params[:payment][:card_number]) + + expect(payment.user.id).must_equal mock_payment_params[:payment][:user_id] + expect(payment.address.id).must_equal mock_payment_params[:payment][:address_id] + expect(payment.card_number).must_equal mock_payment_params[:payment][:card_number] + expect(payment.expiration_date).must_equal mock_payment_params[:payment][:expiration_date] + expect(payment.cvv).must_equal mock_payment_params[:payment][:cvv] + expect(payment.card_type).must_equal mock_payment_params[:payment][:card_type] + + must_redirect_to checkout_path + + end + + it "renders bad_request and does not update the DB for missing data" do + mock_payment_params[:payment][:card_number] = nil + + expect { + post payments_path, params: mock_payment_params + }.wont_change 'Payment.count' + + must_respond_with :bad_request + 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..12b56f735b --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,282 @@ +require "test_helper" + +describe ProductsController do + let(:spaghetti) {products(:spaghetti)} + let(:lasagne) {products(:lasagne)} + let(:seller) {users(:seller)} + let(:buyer) {users(:buyer)} + + let(:mock_params) { + { + product: + { + name: 'ziti', + user_id: seller.id, + price_in_cents: 3.49, + category: 'short', + quantity: 100, + description: 'these ones are ziti', + image_url: http + } + } + } + + describe 'guest users' do + describe 'index' do + it 'succeeds' do + get products_path + + must_respond_with :success + end + + end + + describe 'show' do + it 'succeeds given a valid ID' do + get product_path(spaghetti.id) + + must_respond_with :success + end + + it 'responds with not found given an invalid ID' do + get product_path(-1) + + must_respond_with :not_found + end + + end + + + describe 'guest restrictions' do + + it "cannot access new" do + get new_product_path + must_redirect_to root_path + expect(flash[:warning]).must_equal "You must be a merchant to sell a product. Sign up as a merchant to continue!" + end + end + end + + + describe 'authorized and logged in user functionality' do + let(:seller) {users(:seller)} + let(:buyer) {users(:buyer)} + + describe 'logged in user that is not a seller' do + + it 'does not allow a non-seller user to create a new product' do + perform_login(buyer) + get new_product_path + must_redirect_to user_path(buyer.id) + expect(flash[:warning]).must_equal "You must be a merchant to sell a product. Sign up as a merchant to continue!" + end + end + + describe "logged in user that is a seller" do + + describe 'new and create' do + it 'allows a seller user to create a new product' do + perform_login(seller) + get new_product_path + assert_response :success + + expect { + post products_path, params: mock_params + }.must_change 'Product.count', 1 + + product = Product.last + + expect(product.name).must_equal mock_params[:product][:name] + expect(product.user_id).must_equal seller.id + expect(product.price_in_cents).must_equal 349 + expect(product.category).must_equal mock_params[:product][:category] + expect(product.quantity).must_equal mock_params[:product][:quantity] + expect(product.description).must_equal mock_params[:product][:description] + + must_redirect_to product_path(product.id) + + end + + it "renders bad_request and does not update the DB for bogus data" do + mock_params[:product][:price_in_cents] = 'words' + perform_login(seller) + + + expect { + post products_path, params: mock_params + }.wont_change 'Product.count' + + must_respond_with :bad_request + end + end + + end + + + + describe "edit for product created by user" do + #login user as seller + #user product that belongs to the seller + + it "succeeds with valid id that belongs to them" do + perform_login(seller) + get edit_product_path(spaghetti.id) + + must_respond_with :success + + end + + it "renders 404 not_found for an invalid id" do + #create a product is theirs + #delete products, run this test + perform_login(seller) + get edit_product_path(-1) + + must_respond_with :not_found + end + + it "doesn't allow a user that is not a seller to edit a valid item" do + #try editing a product that is not theirs and gives error messages + perform_login(buyer) + get edit_product_path(spaghetti.id) + must_redirect_to root_path + expect(flash[:warning]).must_equal "You don't have permission to see that." + end + + it "fails with valid id that does not belong to them" do + ada = users(:ada)#try editing a product that is not theirs and gives error messages + perform_login(ada) + get edit_product_path(spaghetti.id) + must_redirect_to root_path + expect(flash[:warning]).must_equal "You can only edit your own products." + end + end + + describe "update product" do + it 'can update a product' do + mock_product_params = { + product: { + quantity: 30, + price_in_cents: 5.99 + } + } + + lasagne = products(:lasagne) + expect(lasagne.quantity).must_equal 25 + perform_login(seller) + + expect{ + patch product_path(lasagne.id), params: mock_product_params + #binding.pry + }.must_change 'lasagne.reload.quantity', 5 + + must_redirect_to product_path(lasagne.id) + expect(flash[:success]).must_equal "Successfully updated lasagne" + expect(lasagne.quantity).must_equal 30 + expect(lasagne.price_in_cents).must_equal 599 + end + + it 'can flashes an error for invalid params for updating a product' do + mock_product_params = { + product: { + quantity: -2, + price_in_cents: 5.99 + } + } + + lasagne = products(:lasagne) + expect(lasagne.quantity).must_equal 25 + perform_login(seller) + + expect{ + patch product_path(lasagne.id), params: mock_product_params + }.wont_change 'lasagne.reload.quantity' + + expect(flash[:warning]).must_equal "A problem occurred: Could not update lasagne" + expect(lasagne.quantity).must_equal 25 + expect(lasagne.price_in_cents).must_equal 499 + end + end + + describe 'deactivate products' do + it 'prevents a guest user from deactivating a product' do + + patch deactivate_product_path(lasagne.id) + + must_redirect_to root_path + expect(flash[:warning]).must_equal "You don't have permission to see that." + end + + it 'allows a logged-in user to deactivate their own product' do + perform_login(seller) + + expect(lasagne.is_active).must_equal true + + patch deactivate_product_path(lasagne.id) + + lasagne.reload + + expect(lasagne.is_active).must_equal false + + must_redirect_to merchant_my_products_path + + end + + it 'allows a logged-in user to activate their own product' do + perform_login(seller) + + lasagne.is_active = false + lasagne.save + + patch deactivate_product_path(lasagne.id) + + lasagne.reload + + expect(lasagne.is_active).must_equal true + + must_redirect_to merchant_my_products_path + + end + + it 'redirects to root if someone tries to deactivate someone elses product' do + buyer.is_a_seller = true + + buyer.save + + perform_login(buyer) + + expect(lasagne.is_active).must_equal true + + patch deactivate_product_path(lasagne.id) + + lasagne.reload + + expect(lasagne.is_active).must_equal true + + must_redirect_to root_path + end + + it 'redirects to root if a non-seller tries to deactivate' do + perform_login(buyer) + + expect(lasagne.is_active).must_equal true + + patch deactivate_product_path(lasagne.id) + + lasagne.reload + + expect(lasagne.is_active).must_equal true + + must_redirect_to root_path + end + end + + describe 'index by merchant' do + it 'successfully renders the index by merchant view' do + get products_by_merchant_path + + must_respond_with :success + end + 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..fc7901923d --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,96 @@ +require "test_helper" + +describe ReviewsController do + let(:spaghetti) {products(:spaghetti)} + let(:seller) {users(:seller)} + let(:review_hash) do + { + review: { + review: 'relieves anxiety', + rating: 5, + + product_id: spaghetti.id + } + } + end + it 'succeeds' do + get reviews_path + + must_respond_with :success + end + + describe "index" do + it "index action should show all the reviews" do + @reviews = Review.all + + get reviews_url + value(response).must_be :successful? + end + + it "should display no reviews when there are no reviews" do + Review.destroy_all + + get reviews_path + must_respond_with :success + expect(Review.all.count).must_equal 0 + end + end + + + describe "new" do + + it "succeeds" do + + get new_product_review_path(spaghetti.id) + + must_respond_with :success + end + + it "checks the owner cannot review their own product" do + perform_login(seller) + get new_product_review_path(spaghetti.id) + + must_redirect_to product_path(spaghetti.id) + end + + it "responds with not_found with a bad id" do + get new_product_review_path(-1) + + must_respond_with :not_found + end + end + + describe "create" do + it "creates a review if valid data is provided" do + expect { + post create_review_path(spaghetti.id), params: review_hash + }.must_change 'Review.count', 1 + + must_redirect_to product_path(spaghetti.id) + end + + it "renders not_found when invalid data is provided" do + + # Arranges + review_hash[:review][:rating] = nil + + # Act-Assert + expect { + post create_review_path(spaghetti.id), params: review_hash + }.wont_change 'Review.count' + + get product_path(-1) + + must_respond_with :not_found + end + it "checks the owner cannot review their own product" do + perform_login(seller) + expect { + post create_review_path(spaghetti.id), params: review_hash + }.wont_change 'Review.count' + + must_redirect_to product_path(spaghetti.id) + 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..a8b44cfa4c --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,50 @@ + require "test_helper" + +describe SessionsController do + describe "auth_callback" do + let(:grace) {users(:grace)} + it "logs in an existing user and redirects to the root route" do + expect{perform_login(grace)}.wont_change('User.count') + # start_count = User.count + # user = users(:grace) + # + # perform_login(user) + must_redirect_to root_path + expect(session[:user_id]).must_equal grace.id + # + # # Should *not* have created a new user + # User.count.must_equal start_count + end + end + + it "creates an account for a new user and redirects to the root route" do + start_count = User.count + user = User.new(provider: "github", uid: 99999, full_name: "test_user", email: "test@user.com") + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + + must_redirect_to root_path + + # Should have created a new user + User.count.must_equal start_count + 1 + + # The new user's ID should be set in the session + session[:user_id].must_equal User.last.id + end + + it "redirects to the login route if given invalid user data" do + + user = User.new(provider: "github", uid: 99999 , full_name: "test_user", email: "") + + expect{ perform_login(user)}.wont_change('User.count') + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + + must_redirect_to root_path + + end + + +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..c5dfff6f37 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,206 @@ +require "test_helper" + +describe UsersController do + + describe "creating users" do + + it "creates an account for a new user and redirects to the root route" do + start_count = User.count + #i think this is a session test + end + + it "creates a new user" do + start_count = User.count + user = User.new(provider: "github", uid: 99999, full_name: "test_user", email: "test@user.com") + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + + must_redirect_to root_path + + # Should have created a new user + User.count.must_equal start_count + 1 + + # The new user's ID should be set in the session + session[:user_id].must_equal User.last.id + end + + end + + describe 'logging in' do + it "logs in an existing user" do + start_count = User.count + grace = users(:grace) + perform_login(grace) + must_redirect_to root_path + session[:user_id].must_equal grace.id + + User.count.must_equal start_count + end + + it "logs out a user, clearing the session user id" do + grace = users(:grace) + perform_login(grace) + + expect(session[:user_id]).must_equal grace.id + + delete logout_path + + expect(session[:user_id]).must_equal nil + end + + end + + describe 'user account page' do + + it 'redirects a guest from trying to access the account page' do + @login_user = nil + id = 1 + get user_path(id) + must_redirect_to root_path + expect(flash[:warning]).must_equal "Oops, you must create an account to view this page!" + + end + + it 'shows an account page for a user' do + seller = users(:seller) + perform_login(seller) + get user_path(seller.id) + must_respond_with :success + end + + it 'allows a user to become a seller/merchant' do + buyer = users(:buyer) + perform_login(buyer) + patch update_user_path(buyer.id), params: { + user: { + is_a_seller: true + } + } + must_redirect_to account_path + expect(flash[:success]).must_equal"Account settings updated!" + + end + + end + + describe 'merchant user settings' do + + it 'shows a dashbboard of a merchants store' do + seller = users(:seller) + perform_login(seller) + get dashboard_path + must_respond_with :success + end + + it 'redirects a guest user from seeing a dashboard' do + get dashboard_path + must_redirect_to root_path + expect(flash[:warning]).must_equal"You don't have permission to view that page" + + end + + it 'redirects a non-seller user from seeing a dashboard' do + buyer = users(:buyer) + perform_login(buyer) + get dashboard_path + must_redirect_to root_path + expect(flash[:warning]).must_equal"You don't have permission to view that page" + end + + end + + describe 'merchant dashboard' do + it 'shows all the merchants products' do + seller = users(:seller) + perform_login(seller) + get merchant_my_products_path + must_respond_with :success + end + end + # it 'shows all the merchants products by status' do + # # active. count + # # instance of + # # produt .name + # # + # # inactive + # # instance of + # # product.name + # end + # + it 'renders not found for orders that havent been placed/are in shopping cart' do + perform_login(users(:buyer)) + get merchant_order_path(orders(:order_one).id) + + must_respond_with :not_found + end + + it 'renders not found for orders that do not exist' do + perform_login(users(:buyer)) + + get merchant_order_path(-1) + + must_respond_with :not_found + end + # + # it 'shows the order_product row specific to the merhcnat for an order' do + # + # end + # + # it 'shows their subtotal for the row of their order for an order' do + # + # end + # + # end + + describe "it can update user status as seller" do + + it 'can turn off seller status and deactive their products accordingly' do + seller = users(:seller) + perform_login(seller) + patch update_user_path(seller.id), params: { + user: { + is_a_seller: false + } + } + expect(seller.products[1].is_active).must_equal false + + must_redirect_to account_path + expect(flash[:success]).must_equal "Account settings updated!" + end + + it 'can turn on a users selling status and reactivate products' do + seller = users(:seller) + perform_login(seller) + patch update_user_path(seller.id), params: { + user: { + is_a_seller: true + } + } + expect(seller.products[0].is_active).must_equal true + + must_redirect_to account_path + expect(flash[:success]).must_equal "Account settings updated!" + end + + end + + describe "it shows orders that merchants need to fulfill" do + + it 'finds an order a merchant needs to fulfill' do + seller = users(:seller) + order = orders(:order_two) + perform_login(seller) + get merchant_order_path(order.id) + must_respond_with :success + end + + # it 'renders not found for a merchants products that are still in the shopping ' do + # seller = users(:seller) + # order = orders(:order_one) + # perform_login(seller) + # get merchant_order_path(order.id) + # must_respond_with :not_found + # end + end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/addresses.yml b/test/fixtures/addresses.yml new file mode 100644 index 0000000000..7eef91c862 --- /dev/null +++ b/test/fixtures/addresses.yml @@ -0,0 +1,35 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +home: + user: buyer + first_name: Pasta + last_name: Eater + street: 123 Macaroni Lane + street_2: Apt 4A + city: Bellevue + state: WA + zip: 98004 + +school: + user: buyer + first_name: Ada + last_name: Lovelace + street: 1215 4th Ave + street_2: Suite 1050 + city: Seattle + state: WA + zip: 98161 + +work: + user: seller + first_name: Francesco + last_name: Rinaldi + street: 1215 4th Ave + street_2: Suite 1050 + city: Seattle + state: WA + zip: 98161 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_products.yml b/test/fixtures/order_products.yml new file mode 100644 index 0000000000..232d8a7654 --- /dev/null +++ b/test/fixtures/order_products.yml @@ -0,0 +1,29 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +order_one_spaghetti: + order: order_one + product: spaghetti + quantity: 5 + +# column: value +# +order_one_lasagne: + order: order_one + product: lasagne + quantity: 2 + + +order_two_spaghetti: + order: order_two + product: spaghetti + quantity: 1 + +order_four_fusili: + order: order_four + product: fusilli + quantity: 1 +# column: value diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..5431ff0f47 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,32 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +order_one: + user: buyer + status: pending + payment: amex + address: school + +# column: value +# +order_two: + user: buyer + status: paid + payment: visa + address: home +# column: value + +order_three: + user: seller + status: paid + payment: discover + address: work + +order_four: + user: buyer + status: complete + payment: discover + address: work diff --git a/test/fixtures/payments.yml b/test/fixtures/payments.yml new file mode 100644 index 0000000000..400959ceb9 --- /dev/null +++ b/test/fixtures/payments.yml @@ -0,0 +1,31 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +amex: + user: buyer + address: home + card_number: 378282246310005 + expiration_date: Date.parse(January 2, 2050) + cvv: 1234 + card_type: AMEX +# column: value +# +visa: + user: buyer + address: home + card_number: 4012888888881881 + expiration_date: Date.parse(January 2, 2050) + cvv: 123 + card_type: VISA +# column: value + +discover: + user: seller + address: work + card_number: 378282246310005 + expiration_date: Date.parse(January 2, 2050) + cvv: 1234 + card_type: Discover diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..5e19eab832 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,44 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +spaghetti: + name: spaghetti + user: seller + price_in_cents: 299 + quantity: 50 + category: long + description: this is a box of spaghetti + is_active: true + image_url: http + +lasagne: + name: lasagne + user: seller + price_in_cents: 499 + quantity: 25 + category: sheet + description: these are lasagne noodles + image_url: http + + +fusilli: + name: fusilli + user: seller + price_in_cents: 400 + quantity: 20 + category: short + description: fusilli jerry, because you're silly + image_url: http + +inactive_ravioli: + name: ravioli + user: seller + price_in_cents: 399 + quantity: 34 + category: filled + description: roly poly ravioli + is_active: false + image_url: http diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..7087fbf793 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,35 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: + user: buyer + product: spaghetti + review: This spaghetti was not as long as I expected. + rating: 3 + +two: + user: buyer + product: lasagne + review: It was pretty sheety lasagne. + rating: 5 + +three: + user: buyer + product: spaghetti + review: It was pretty sheety lasagne. + rating: 4 + +four: + user: buyer + product: spaghetti + review: It was pretty sheety lasagne. + rating: 3 + +five: + user: buyer + product: spaghetti + review: It was pretty sheety lasagne. + rating: 2 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..d69582d531 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,35 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +seller: + full_name: Francesco Rinaldi + email: francesco@rinaldi.com + is_a_seller: true + uid: 12345678 + provider: github + +buyer: + full_name: Pasta Eater + email: pasta@eater.com + is_a_seller: false + uid: 23456789 + provider: github + +ada: + provider: github + uid: 12345 + email: ada@adadevelopersacademy.org + full_name: countess_ada + is_a_seller: true + +grace: + provider: github + uid: 13371337 + email: grace@hooper.net + full_name: graceful_hopps + +guest: + is_a_seller: false + provider: guest_login + uid: 98765432 + email: example@example.com + full_name: Guest user diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/helpers/test_helper.rb b/test/helpers/test_helper.rb 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/address_test.rb b/test/models/address_test.rb new file mode 100644 index 0000000000..c1f7c8b262 --- /dev/null +++ b/test/models/address_test.rb @@ -0,0 +1,123 @@ +require "test_helper" + +describe Address do + let(:address) { addresses(:home) } + + it "must be valid" do + value(address).must_be :valid? + end + + it 'has required fields' do + fields = [:user_id, :first_name, :last_name, :street, :city, :state, :zip] + + fields.each do |field| + expect(address).must_respond_to field + end + end + + + describe 'Relationships' do + + it 'belongs to a user' do + user = address.user + expect(user).must_be_instance_of User + expect(user.id).must_equal address.user_id + end + + + it 'has one user' do + user = address.user + expect(user).must_be_instance_of User + end + + + end + + describe 'validations' do + it 'must have a user' do + address = addresses(:home) + address.user = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:user]).must_equal ["must exist"] + end + + it 'must have a first_name' do + address = addresses(:home) + address.first_name = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:first_name]).must_equal ["can't be blank"] + end + + it 'must have a last_name' do + address = addresses(:home) + address.last_name = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:last_name]).must_equal ["can't be blank"] + end + it 'must have a street' do + address = addresses(:home) + address.street = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:street]).must_equal ["can't be blank"] + end + it 'must have a city' do + address = addresses(:home) + address.city = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:city]).must_equal ["can't be blank"] + end + + it 'must have a state' do + address = addresses(:home) + address.state = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:state]).must_equal ["can't be blank"] + end + + it 'must have a zip' do + address = addresses(:home) + address.zip = nil + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:zip]).must_equal ["can't be blank", "is not a number", "is too short (minimum is 5 characters)"] + end + + it 'must have a zip that is numerical' do + address = addresses(:home) + address.zip = 'abced' + address.save + + valid = address.valid? + + expect(valid).must_equal false + expect(address.errors.messages[:zip]).must_equal ["is not a number", "is too short (minimum is 5 characters)"] + end + end +end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb new file mode 100644 index 0000000000..b114826fcd --- /dev/null +++ b/test/models/order_product_test.rb @@ -0,0 +1,63 @@ +require "test_helper" + +describe OrderProduct do + let(:order_product) { order_products(:order_one_spaghetti) } + it "must be valid" do + value(order_product).must_be :valid? + end + it 'has required fields' do + fields = [:order, :product, :quantity] + fields.each do |field| + expect(order_product).must_respond_to field + end + end + describe 'Relationships' do + it 'belongs to an order' do + order = order_product.order + expect(order).must_be_instance_of Order + expect(order.id).must_equal order_product.order_id + end + it 'belongs to a product' do + product = order_product.product + expect(product).must_be_instance_of Product + expect(product.id).must_equal order_product.product_id + end + end + describe 'validations' do + it 'must have an order' do + order_product = order_products(:order_one_spaghetti) + order_product.order = nil + order_product.save + valid = order_product.valid? + expect(valid).must_equal false + expect(order_product.errors.messages[:order]).must_equal ["must exist", "can't be blank"] + end + it 'must have aa product' do + order_product = order_products(:order_one_spaghetti) + order_product.product = nil + order_product.save + valid = order_product.valid? + expect(valid).must_equal false + expect(order_product.errors.messages[:product]).must_equal ["must exist", "can't be blank"] + end + it 'must have an quantity' do + order_product = order_products(:order_one_spaghetti) + order_product.quantity = nil + order_product.save + valid = order_product.valid? + expect(valid).must_equal false + expect(order_product.errors.messages[:quantity]).must_equal ["can't be blank", "Must add atleast a quantity of one.", "Can't order that quantity."] + end + end + + describe 'item_subtotal method' do + it 'returns the price of the item times the quantity in the cart' do + order_product = order_products(:order_one_spaghetti) + item = products(:spaghetti) + + expect(order_product.item_subtotal).must_equal (5 * 299) + + end + + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..4d31a753a4 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,123 @@ +require "test_helper" + +describe Order do + let(:order) { orders(:order_one) } + + describe 'validates' do + + it "must be valid" do + value(order).must_be :valid? + end + + it 'has required fields' do + fields = [:user_id, :status] + fields.each do |field| + expect(order).must_respond_to field + end + end + + end + + + describe 'Relationships' do + it 'can have many products' do + + products = order.products + expect(products.length).must_be :>=, 1 + products.each do |product| + expect(product).must_be_instance_of Product + end + end + + it 'can have many order_products' do + OrderProduct.create(order: order, product: products(:lasagne), quantity: 5) + + order_products = order.order_products + expect(order_products.length).must_be :>=, 2 + order_products.each do |order_product| + expect(order_product).must_be_instance_of OrderProduct + end + end + + it 'can have one payment' do + payment = order.payment + expect(payment).must_be_instance_of Payment + end + + it 'can have one address' do + address = order.address + expect(address).must_be_instance_of Address + end + + it 'belongs to a user' do + user = order.user + expect(user).must_be_instance_of User + expect(user.id).must_equal order.user_id + end + + end + + + describe 'validations' do + + it 'must have a user' do + order = orders(:order_one) + order.user = nil + order.save + + valid = order.valid? + + expect(valid).must_equal false + expect(order.errors.messages[:user]).must_equal ["must exist"] + end + + + it 'must have a status' do + order = orders(:order_one) + order.status = nil + order.save + + valid = order.valid? + + expect(valid).must_equal false + expect(order.errors.messages[:status]).must_equal ["can't be blank"] + end + + end + + + describe "custom validations" do + let(:placed_order) { orders(:order_two) } + + describe "validations for a :placed_order" do + it "placed_order will work if it has a payment and address'" do + + placed_order.save + + valid = placed_order.valid? + + expect(valid).must_equal true + end + + it 'will not work if it does not have a payment' do + placed_order.payment = nil + placed_order.save + + valid = placed_order.valid? + expect(valid).must_equal false + + end + + it 'will not work if it does not have an address' do + placed_order.address = nil + placed_order.save + + valid = placed_order.valid? + expect(valid).must_equal false + end + + end + + end + +end diff --git a/test/models/payment_test.rb b/test/models/payment_test.rb new file mode 100644 index 0000000000..6041806316 --- /dev/null +++ b/test/models/payment_test.rb @@ -0,0 +1,156 @@ +require "test_helper" + +describe Payment do + let(:payment) { payments(:visa) } + + it "must be valid" do + value(payment).must_be :valid? + end + + it 'has required fields' do + fields = [:user_id, :address_id, :card_type, :card_number, :expiration_date, :cvv] + + fields.each do |field| + expect(payment).must_respond_to field + end + end + + + describe 'Relationships' do + + it 'belongs to a user' do + user = payment.user + expect(user).must_be_instance_of User + expect(user.id).must_equal payment.user_id + end + + # it 'belongs to an order' do + # order = payment.order + # expect(order).must_be_instance_of Order + # expect(order.id).must_equal payment.order_id + # end + + it 'belongs to an address' do + address = payment.address + expect(address).must_be_instance_of Address + expect(address.id).must_equal payment.address_id + end + + + end + + describe 'validations' do + it 'must have a user' do + payment = payments(:amex) + payment.user = nil + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:user]).must_equal ["must exist"] + end + + it 'must have an address' do + payment = payments(:amex) + payment.address = nil + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:address]).must_equal ["must exist"] + end + + it 'must have a card_number' do + payment = payments(:amex) + payment.card_number = nil + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:card_number]).must_equal ["can't be blank", "is not a number", "is too short (minimum is 14 characters)"] + end + + it 'must have a card_number that is between 14 and 17 integers' do + payment = payments(:amex) + payment.card_number = 12309845 + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:card_number]).must_equal ["is too short (minimum is 14 characters)"] + + payment.card_number = 12309845123454321233 + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:card_number]).must_equal ["is too long (maximum is 17 characters)"] + end + + it 'must have an expiration date' do + payment = payments(:amex) + payment.expiration_date = nil + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:expiration_date]).must_equal ["can't be blank"] + end + + it 'must have a cvv' do + payment = payments(:amex) + payment.cvv = nil + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:cvv]).must_equal ["can't be blank", "is not a number","is too short (minimum is 3 characters)"] + end + + it 'must have a cvv between 3-6 numbers long' do + payment = payments(:amex) + payment.cvv = 12 + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:cvv]).must_equal ["is too short (minimum is 3 characters)"] + + payment.cvv = 1234567 + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:cvv]).must_equal ["is too long (maximum is 6 characters)"] + + payment.cvv = 'abc' + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:cvv]).must_equal ["is not a number","is too short (minimum is 3 characters)"] + + end + + it 'must have a card_type' do + payment = payments(:amex) + payment.card_type = nil + payment.save + + valid = payment.valid? + + expect(valid).must_equal false + expect(payment.errors.messages[:card_type]).must_equal ["can't be blank"] + end + end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..24d9188bd7 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,151 @@ +require "test_helper" + +describe Product do + let(:product) { products(:spaghetti) } + + it "knows its own categories" do + expect(Product.categories).must_equal ['long', 'short', 'shell', 'sheet', 'filled', 'soup'] + end + + it "can filter only active products" do + expect(Product.active_products.count).must_equal 3 + expect(Product.active_products).wont_include products(:inactive_ravioli) + end + + it "returns an empty set with no active products" do + Product.all.each do |product| + product.is_active = false + product.save + end + + expect(Product.active_products.count).must_equal 0 + end + + it "knows its average_rating " do + expect(product.average_rating).must_equal 3 + end + + it "returns not yet rated if there are no ratings" do + expect(products(:fusilli).average_rating).must_equal 'Not yet rated' + end + + it "must be valid" do + value(product).must_be :valid? + end + + it 'has required fields' do + fields = [:user_id, :name, :price_in_cents, :quantity, :category, :description] + + fields.each do |field| + expect(product).must_respond_to field + end + end + + + describe 'Relationships' do + + it 'can have many reviews' do + reviews = product.reviews + + + expect(reviews.length).must_be :>=, 1 + reviews.each do |review| + expect(review).must_be_instance_of Review + end + end + + it 'can have many orders' do + orders = product.orders + + expect(orders.length).must_be :>=, 1 + orders.each do |order| + expect(order).must_be_instance_of Order + end + end + + it 'can have many order_products' do + OrderProduct.create(order: orders(:order_one), product: products(:spaghetti), quantity: 5) + order_products = product.order_products + + expect(order_products.length).must_be :>=, 2 + order_products.each do |order_product| + expect(order_product).must_be_instance_of OrderProduct + end + end + + it 'belongs to a user' do + user = product.user + expect(user).must_be_instance_of User + expect(user.id).must_equal product.user_id + end + + end + + describe 'validations' do + it 'must have a user' do + product = products(:lasagne) + product.user = nil + product.save + + valid = product.valid? + + expect(valid).must_equal false + expect(product.errors.messages[:user]).must_equal ["must exist"] + end + + it 'must have a name' do + product = products(:lasagne) + product.name = nil + product.save + + valid = product.valid? + + expect(valid).must_equal false + expect(product.errors.messages[:name]).must_equal ["can't be blank"] + end + + it 'must have an price_in_cents' do + product = products(:lasagne) + product.price_in_cents = nil + product.save + + valid = product.valid? + + expect(valid).must_equal false + expect(product.errors.messages[:price_in_cents]).must_equal ["can't be blank", "Price must be greater than 0"] + end + + it 'must have a quantity' do + product = products(:lasagne) + product.quantity = nil + product.save + + valid = product.valid? + + expect(valid).must_equal false + expect(product.errors.messages[:quantity]).must_equal ["can't be blank", "Stock cannot go below 0"] + end + + it 'must have a category' do + product = products(:lasagne) + product.category = nil + product.save + + valid = product.valid? + + expect(valid).must_equal false + expect(product.errors.messages[:category]).must_equal ["can't be blank"] + end + + it 'must have an description' do + product = products(:lasagne) + product.description = nil + product.save + + valid = product.valid? + + expect(valid).must_equal false + expect(product.errors.messages[:description]).must_equal ["can't be blank"] + end + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..98849e24b4 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,71 @@ +require "test_helper" + +describe Review do + let(:review) { reviews(:one) } + + describe "validates" do + + it "must be valid" do + value(review).must_be :valid? + end + + it 'has required fields' do + fields = [:user_id, :product_id, :rating] + + fields.each do |field| + expect(review).must_respond_to field + end + end + end + + describe 'Relationships' do + + it 'can have one product' do + product = review.product + expect(product).must_be_instance_of Product + end + + + it 'can have one user' do + user = review.user + expect(user).must_be_instance_of User + end + end + + describe 'validations' do + it 'does not reqire a user' do + review = reviews(:one) + review.user = nil + review.save + + valid = review.valid? + + expect(valid).must_equal true + + end + + it 'must have a product' do + review = reviews(:one) + review.product = nil + review.save + + valid = review.valid? + + expect(valid).must_equal false + expect(review.errors.messages[:product]).must_equal ["must exist"] + + end + + it 'must have an rating' do + review = reviews(:one) + review.rating = nil + review.save + + valid = review.valid? + + expect(valid).must_equal false + expect(review.errors.messages[:rating]).must_equal "can't be blank", "Rating must be greater than 0", "We're flattered but this product can + only be rated out of 5." + end + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..3cf17f5e69 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,204 @@ +require "test_helper" + +class UserTest < ActiveSupport::TestCase + describe User do + let(:user) { User.new(full_name: 'Chris McNally', email: 'chris@ada.com', uid:'12345', provider: 'github') } + + it "must be valid" do + value(user).must_be :valid? + end + + it 'has required fields' do + fields = [:full_name, :email, :uid, :provider] + + fields.each do |field| + expect(user).must_respond_to field + end + end + end + + describe 'Relationships' do + let(:user) { users(:buyer)} + + it 'can have many products' do + + user.products << Product.first + products = user.products + + expect(products.length).must_be :>=, 1 + products.each do |product| + expect(product).must_be_instance_of Product + end + end + + it 'can have many orders' do + + user.orders << Order.first + orders = user.orders + + expect(orders.length).must_be :>=, 1 + orders.each do |order| + expect(order).must_be_instance_of Order + end + end + + it 'can have many addresses' do + + user.addresses << Address.first + addresses = user.addresses + + expect(addresses.length).must_be :>=, 1 + addresses.each do |address| + expect(address).must_be_instance_of Address + end + end + + it 'can have many payments' do + + user.payments << Payment.first + payments = user.payments + + expect(payments.length).must_be :>=, 1 + payments.each do |payment| + expect(payment).must_be_instance_of Payment + end + end + + it 'can have many reviews' do + + user.reviews << Review.first + reviews = user.reviews + + expect(reviews.length).must_be :>=, 1 + reviews.each do |review| + expect(review).must_be_instance_of Review + end + end + end + + describe 'validations' do + it 'must have a full_name' do + user = users(:seller) + user.full_name = nil + user.save + + valid = user.valid? + + expect(valid).must_equal false + expect(user.errors.messages).must_include :full_name + end + + it 'must have an email' do + user = users(:seller) + user.email = nil + user.save + + valid = user.valid? + + expect(valid).must_equal false + expect(user.errors.messages).must_include :email + end + + it 'must have a uid' do + user = users(:seller) + user.uid = nil + user.save + + valid = user.valid? + + expect(valid).must_equal false + expect(user.errors.messages).must_include :uid + end + + it 'must have a provider' do + user = users(:seller) + user.provider = nil + user.save + + valid = user.valid? + + expect(valid).must_equal false + expect(user.errors.messages).must_include :provider + end + end + + describe 'becoming a seller' do + let(:guest) {users(:guest)} + let(:buyer) {users(:buyer)} + + it 'allows a user with an account to become a seller' do + expect(buyer.is_a_seller).must_equal false + + buyer.is_a_seller = true + buyer.save + expect(buyer.is_a_seller).must_equal true + end + + it 'does not allow a guest user to become a seller' do + expect(guest.is_a_seller).must_equal false + guest.is_a_seller = true + guest.save + + valid = guest.valid? + + expect(valid).must_equal false + expect(guest.errors.messages).must_include :is_a_seller + expect(guest.errors.messages[:is_a_seller]).must_equal ["Must be a registered user to become a seller"] + end + + end + + describe "custom methods" do + let(:seller) {users(:seller)} + let(:buyer) {users(:buyer)} + + describe 'self.merchants' do + it 'returns a list of all active merchants' do + merchant_list = User.merchants + + expect(merchant_list).must_include seller + expect(merchant_list).wont_include buyer + end + end + + describe ' total_revenue' do + it 'should return the total revenue for all products sold by a given merchant' do + expect(seller.total_revenue).must_equal 699 + end + + it 'should return the total revenue by order status for all products sold by a given merchant' do + expect(seller.total_revenue_by_status('paid')).must_equal 299 + + expect(seller.total_revenue_by_status('complete')).must_equal 400 + end + end + + describe 'product status' do + it 'sorts a merchants prodcuts by their status'do + + expect(seller.product_status(true)[0]).must_be_instance_of Product + expect(seller.product_status(true)[0].name).must_equal 'spaghetti' + + end + end + + describe "Create user using oauth" do + it 'creates an instance of a user using github auth_hash' do + mock_hash = { + provider: 'github', + uid: 12345, + info: { + email: 'test@test.com', + name: 'Please pass this test' + } + } + + expect(User.build_from_github(mock_hash)).must_be_instance_of User + + end + + 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..1c94547e3e --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,53 @@ +ENV["RAILS_ENV"] = "test" +require 'simplecov' +SimpleCov.start +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" + +# for Colorized output +# For colorful output! +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + +# To add Capybara feature tests add `gem "minitest-rails-capybara"` +# to the test group in the Gemfile and uncomment the following: +# require "minitest/rails/capybara" + +# Uncomment for awesome colorful output +require "minitest/pride" +require 'active_support/testing/assertions' +include ActiveSupport::Testing::Assertions + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + def setup + # Once you have enabled test mode, all requests + # to OmniAuth will be short circuited to use the mock authentication hash. + # A request to /auth/provider will redirect immediately to /auth/provider/callback. + OmniAuth.config.test_mode = true + end + + def mock_auth_hash(user) + return { + provider: user.provider, + uid: user.uid, + info: { + email: user.email, + name: user.full_name + } + } + end + + 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