diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..5008ddfcf5 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..70c99c9403 --- /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 + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key + +.env +coverage diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..f7a91deda4 --- /dev/null +++ b/Gemfile @@ -0,0 +1,90 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +# ruby '2.5.1' +# ruby '2.4.1' + +gem 'simplecov', require: false, group: :test + + + +# 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 + +gem "omniauth" +gem "omniauth-github" + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +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' + + gem 'dotenv-rails' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..0db682d77e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,310 @@ +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) + 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 + 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) + +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/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..e6f2e2e779 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/americat1.jpg b/app/assets/images/americat1.jpg new file mode 100644 index 0000000000..f7fb9e53aa Binary files /dev/null and b/app/assets/images/americat1.jpg differ diff --git a/app/assets/images/americat2.jpg b/app/assets/images/americat2.jpg new file mode 100644 index 0000000000..9380cdc6ab Binary files /dev/null and b/app/assets/images/americat2.jpg differ diff --git a/app/assets/images/bed.jpg b/app/assets/images/bed.jpg new file mode 100644 index 0000000000..b79b976463 Binary files /dev/null and b/app/assets/images/bed.jpg differ diff --git a/app/assets/images/car.jpg b/app/assets/images/car.jpg new file mode 100644 index 0000000000..e575ab02c2 Binary files /dev/null and b/app/assets/images/car.jpg differ diff --git a/app/assets/images/dust-transparent-red.gif b/app/assets/images/dust-transparent-red.gif new file mode 100644 index 0000000000..e0b8cfcc71 Binary files /dev/null and b/app/assets/images/dust-transparent-red.gif differ diff --git a/app/assets/images/firework.gif b/app/assets/images/firework.gif new file mode 100644 index 0000000000..0e22a39d8a Binary files /dev/null and b/app/assets/images/firework.gif differ diff --git a/app/assets/images/flower.jpg b/app/assets/images/flower.jpg new file mode 100644 index 0000000000..fcaad08333 Binary files /dev/null and b/app/assets/images/flower.jpg differ diff --git a/app/assets/images/red-falling.gif b/app/assets/images/red-falling.gif new file mode 100644 index 0000000000..72c0db0572 Binary files /dev/null and b/app/assets/images/red-falling.gif differ diff --git a/app/assets/images/smallfirework.gif b/app/assets/images/smallfirework.gif new file mode 100644 index 0000000000..f3819c94c4 Binary files /dev/null and b/app/assets/images/smallfirework.gif differ diff --git a/app/assets/images/sparkle.gif b/app/assets/images/sparkle.gif new file mode 100644 index 0000000000..782c5b4153 Binary files /dev/null and b/app/assets/images/sparkle.gif differ diff --git a/app/assets/images/supreme.png b/app/assets/images/supreme.png new file mode 100644 index 0000000000..c288aae4c7 Binary files /dev/null and b/app/assets/images/supreme.png differ 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/categories.js b/app/assets/javascripts/categories.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/categories.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/merchants.js b/app/assets/javascripts/merchants.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/merchants.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/order.js b/app/assets/javascripts/order.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order.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/order_items.js b/app/assets/javascripts/order_items.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order_items.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/products.js b/app/assets/javascripts/products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/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/welcome.js b/app/assets/javascripts/welcome.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/welcome.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..e5854e2c2a --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,253 @@ +@import url('https://fonts.googleapis.com/css?family=Love+Ya+Like+A+Sister'); +@import url('https://fonts.googleapis.com/css?family=Quicksand'); +@import url('https://fonts.googleapis.com/css?family=Paytone+One'); + +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + */ + +/* Custom bootstrap variables must be set or imported *before* bootstrap. */ +@import "bootstrap"; +/* Import scss content */ +@import "**/*"; + +body { + width: 100wh; + height: 90vh; + color: #fff; + background: linear-gradient(-45deg, #E54B4B, #E54B4B, #F7EBE8, #F72F26); + background-size: 400% 400%; + -webkit-animation: Gradient 15s ease infinite; + -moz-animation: Gradient 15s ease infinite; + animation: Gradient 15s ease infinite; +} + +@-webkit-keyframes Gradient { + 0% { + background-position: 0% 50% + } + 50% { + background-position: 100% 50% + } + 100% { + background-position: 0% 50% + } +} + +@-moz-keyframes Gradient { + 0% { + background-position: 0% 50% + } + 50% { + background-position: 100% 50% + } + 100% { + background-position: 0% 50% + } +} + +@keyframes Gradient { + 0% { + background-position: 0% 50% + } + 50% { + background-position: 100% 50% + } + 100% { + background-position: 0% 50% + } +} + + + +.welcome { + text-transform: uppercase; + letter-spacing: .2em; + text-shadow: 2px 2px grey; +} + + +h2 { + color: #292F36; + text-transform:uppercase; + letter-spacing: 1em; + text-shadow: 2px 2px #B1B3B5; +} + +body { +text-transform:capitalize; +background-color: #fff; +font-family: 'Quicksand', sans-serif; + +} + +strong { + color: #EA1300; + font-weight: bold; +} + +footer { + color: #923030; + text-align: center; + +} +main { + padding: 4rem; +} + +li { + list-style: none; +} + +.homepage-title { + text-align: center; +} + +.header { + color: #EA1300; + background-color: #FFFFFF; + font-family: 'Paytone One', sans-serif; + padding: 2rem 2rem .1rem 2rem; + +} + +#logo-hover a:visited { + color:#EA1300; +} + +#logo-hover a:link { + color:#EA1300; +} + +.logo { + text-align: left; + font-weight: 600; + font-size: 7em; + letter-spacing: .2em; + margin-bottom: .25em; +} + +.little-header { + font-size: 20px; + color: #292F36; + letter-spacing: .2em; + font-family: 'Quicksand', sans-serif; +} + +.nav-app-header { + display: flex; + justify-content: flex-end; + flex-direction: row; + font-family: 'Quicksand', sans-serif; + +} + +.app-header__nav_item { + padding-left: 20px; +} + +a:visited { + color: #292F36; + +} +a:link { + color: #292F36; +} + +a:hover { + color: #E54B4B; + transition: .6s; + text-decoration: none; +} + +#logo-hover a:hover { + color: #B4231C; + background-image:image-url("smallfirework.gif"); +} + +#session { + background-color: #FFFFFF; +} + +#session:hover { + color: #E54B4B; + border: #E54B4B solid 1px; +} + +.btn-primary { + background-color: #E54B4B; + border: 1px #292F36 solid; +} + +.btn-primary:hover { + color: #E54B4B; + background-color: #E54B4B; + border: 1px #E54B4B solid; +} + +.btn-primary:visited { + background-color: #E54B4B; + border: 1px #292F36 solid; +} + +.dropdown { + position: relative; + display: inline-block; +} + +.dropdown-content { + display: none; + position: absolute; + background-color: #FFF; + background-image:image-url("red-falling.gif"); + + min-width: 130px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + padding: 12px 36px; + z-index: 1; + font-weight: bold; + white-space: nowrap; +} + +.dropdown:hover .dropdown-content { + display: block; +} + + +.carousel { + overflow: hidden; + height: 320px; + width: 95%; + background-color: white; + margin: 0 auto ; + border: 1px solid #E54B4B ; + +} + +.carousel img { + margin-top: -22%; + margin-bottom: auto; + height: auto; + width: 100%; +} + + + +.mini-body { + color: black; + background-color: white; + width: 80%; + border: 10px solid white; + padding: 25px; + margin: auto; +} diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..0bb756559b --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,18 @@ +// Place all the styles related to the Categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +.category-title { + text-align: center; +} + +/*---------------------- PRODUCT LIST ----------------------------*/ + +.grid-container { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + text-align: center; + justify-content: center; + grid-column-gap: 50px; + grid-row-gap: 25px; + align-self: auto; +} diff --git a/app/assets/stylesheets/merchants.scss b/app/assets/stylesheets/merchants.scss new file mode 100644 index 0000000000..626b3f0060 --- /dev/null +++ b/app/assets/stylesheets/merchants.scss @@ -0,0 +1,101 @@ +// Place all the styles related to the merchants controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.merchant-title { + text-align: center; +} + + +.mini-body{ + color: black; + background-color: white; + width: 80%; + border: 10px solid white; + padding: 15px; + margin: auto; +} + +.merchant-show-title { + text-align: center; + color: #292F36; + text-transform:uppercase; + letter-spacing: .5em; + text-shadow: 2px 2px #B1B3B5; +} + +/*---------------------- PRODUCT LIST ----------------------------*/ + +.grid-container { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + text-align: center; + justify-content: center; + grid-column-gap: 50px; + grid-row-gap: 25px; + align-self: auto; +} + +.order-items { + margin-bottom: 0; + padding: 0; +} +.order-items li { + list-style: disc; +} + +.order-row td { + padding: 10px 20px; + vertical-align: top; +} + +.order-header th { + padding: 10px 20px; +} + + +/*---------------------- MERCHANT SHOW ----------------------*/ + + +.add-category { + background-color: #F97A74 !important; + border: 1px #292F36 solid; +} + +.add-product { + background-color: #F97A74 !important; + border: 1px #292F36 solid; +} + +.order-summary { + background-color: #FFE5E7 !important; + border: 1px #292F36 solid; +} + + + + +.mini-body-about{ +justify-content: center; + color: black; + background-color: white; + width: 80%; + border: 10px solid white; + padding: 15px; + margin: auto; +} + +.about-grid-container { + display: grid; + grid-template-columns: 1fr 1fr; + text-align: center; + justify-content: center; + grid-column-gap: 50px; + grid-row-gap: 20px; + align-self: auto; +} + +.grid-item { + padding: 20px + +} diff --git a/app/assets/stylesheets/order.scss b/app/assets/stylesheets/order.scss new file mode 100644 index 0000000000..3ee74f9f68 --- /dev/null +++ b/app/assets/stylesheets/order.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the order controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/order_items.scss b/app/assets/stylesheets/order_items.scss new file mode 100644 index 0000000000..c02e2068ea --- /dev/null +++ b/app/assets/stylesheets/order_items.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the order_items 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..46d16d2504 --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,66 @@ +// 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/ + +table, th, td { + border: 0px solid black; + text-align: center !important; +} + +table { + border-collapse: collapse; + width: 100%; +} + +th, td { + text-align: left; + padding: 8px; + border-bottom: 1px solid #ddd; + +} + +// tr:nth-child(even){background-color: #f2f2f2} +// th, td { +// padding: 12px; +// text-align: left; +// height: 50px; +// vertical-align: bottom; +// } +// +// tr:hover {background-color: #F7EBE8;} +// tr:nth-child(even) {background-color: #F7EBE8;} + + +.update-order { + color: black; + background-color: #FFE5E7 !important; + border: 1px #292F36 solid; +} + + +.remove-item { + color: #fff !important; + background-color: #F72F26 !important; + border: 1px #292F36 solid; +} + +.order-image img{ + width: 75px; + height: 75px; + position: relative; + overflow: hidden; + border-radius: 50%; +} + + +.checkout { + color: white !important; + background-color: #23D552 !important; + border: 1px #292F36 solid; +} + +.table-head { + align-items: center; + font-weight: bold; + background-color: #EBECEC; +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..4ca71985a2 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,100 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.product-title { + text-align: center; +} + +/*---------------------- PRODUCT LIST ----------------------------*/ + +.grid-container { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + text-align: center; + justify-content: center; + grid-column-gap: 50px; + grid-row-gap: 25px; + align-self: auto; + margin: 4em +} + +.grid-item img { + max-width: 100%; + height: 250px; + border-radius: 50; + padding: 2px; + border: 1px solid #EC7C7C ; + outline: 3px solid #FFE5E7; + outline-offset: 1px; + + margin: 0 auto ; +} + + + + +.image { + opacity: 1; + display: block; + width: 100%; + height: auto; + transition: .5s ease; + backface-visibility: hidden; + margin: 0; +} + +.middle { + transition: .5s ease; + opacity: 0; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + -ms-transform: translate(-50%, -50%); + text-align: center; +} + +.container:hover .image { + opacity: 0.6; +} + +/*---------------------- PRODUCT DETAILS ----------------------------*/ + +.show-grid-container { + display: flex; + grid-template-columns: 1fr 1fr; + justify-content: center; + grid-column-gap: 5px; + align-self: auto; +} + +.show-grid-image { + display: flex; + align-items: center; + justify-content: center; + width: 30%; + padding: 1px; +} + +.show-grid-image img { + width: 90%; + padding: 1px; + border: 1px solid black ; + +} + +.review-container { + display: grid; + text-align: left; + width: 70%; + margin: -10px auto; + padding: 30px; + +} + + +.add-cart { + background-color: #F97A74 !important; + border: 1px #292F36 solid; +} diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..7bef9cf826 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/welcome.scss b/app/assets/stylesheets/welcome.scss new file mode 100644 index 0000000000..77ce11a740 --- /dev/null +++ b/app/assets/stylesheets/welcome.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the welcome controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000..d672697283 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000000..0ff5442f47 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000000..61c2018d73 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,65 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception + before_action :find_merchant + + def render_404 + # DPR: this will actually render a 404 page in production + raise ActionController::RoutingError.new('Not Found') + end + + # return the current order or create a new order if none exists + def current_order + if !session[:order_id] + new_order = Order.new() + session[:order_id] = new_order.id + result = new_order.save + if result + # flash[:status] = :success + # flash[:result_text] = "Added item to your cart" + # redirect_to root_path + return new_order.id + else + # flash[:status] = :failure + # flash[:result_text] = "Could not add to order" + # redirect_to root_path + end + + elsif + ongoing_order = Order.find_by(id: session[:order_id]) + flash[:status] = :failure + flash[:result_text] = "You already have a cart in progress." + # redirect_to root_path + return ongoing_order.id + else + puts "oh no" + flash[:status] = :failure + flash[:result_text] = "Your order does not exist." + redirect_to root_path + end + + end + + private + + # NOTE: can dry the code above private with this + def find_order + if session[:order_id] + @ongoing_order = Order.find_by(id: session[:order_id]) + end + end + + def find_merchant + if session[:merchant_id] + @login_user = Merchant.find_by(id: session[:merchant_id]) + end + end + + def require_login + if find_merchant.nil? + flash[:status] = :failure + flash[:result_text] = "You must be a logged in merchant to view this page." + redirect_to root_path + end + end + +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..f1d91e2fdb --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,43 @@ +class CategoriesController < ApplicationController + + before_action :require_login, only: [:new, :create] + + def index + @categories = Category.all + end + + def new + if @login_user.nil? + render_404 + else + @category = Category.new + end + end + + def create + if @login_user.nil? + flash[:status] = :failure + flash[:result_text] = "You must be logged in to add a new category." + redirect_to root_path + else + @category = Category.new(category_params) + if @category.save + flash[:status] = :success + flash[:result_text] = "Successfully created category: + #{@category.category_name}." + redirect_to root_path + else + flash[:status] = :failure + flash[:result_text] = "Could not create category: #{@category.category_name}." + flash[:messages] = @category.errors.messages + render :new, status: :bad_request + end + end + end + + private + + def category_params + params.require(:category).permit(:category_name) + 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/merchants_controller.rb b/app/controllers/merchants_controller.rb new file mode 100644 index 0000000000..a1f14e191b --- /dev/null +++ b/app/controllers/merchants_controller.rb @@ -0,0 +1,50 @@ +class MerchantsController < ApplicationController + # QUESTION: WHY ISN'T THIS WORKING????!?!?! + # skip_before_action :matching_merchant, only: [:index] + before_action :matching_merchant, only: [:show, :order_summary] + + def index + @merchant = Merchant.all + end + + def show + # QUESTION: add if/else so only login_user can view merchant account page?? + @merchant = Merchant.find(params[:id]) + render_404 unless @merchant + end + + def order_summary + # show orders that belong only to merchant + @orders = Order.joins(:products).where(products: {merchant_id: params[:merchant_id]}) + + # show order_items that belong only to merchant + @order_items = @orders.map { |order| order.order_items }.flatten + end + + private + + def matching_merchant + # like, if you're not even logged in, don't try to view such things + require_login() + + merchant_viewing = Merchant.find_by(id: params[:id]) + + # this allows the order summary page to work + if merchant_viewing.nil? + merchant_viewing = Merchant.find_by(id: params[:merchant_id]) + end + + if find_merchant != merchant_viewing + flash[:status] = :failure + flash[:result_text] = "Only merchant #{merchant_viewing.username} may view this page." + + redirect_to root_path + end + end + + + def about_us + end + + +end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb new file mode 100644 index 0000000000..d10331a1de --- /dev/null +++ b/app/controllers/order_items_controller.rb @@ -0,0 +1,110 @@ +class OrderItemsController < ApplicationController + + + + def create + #TODO: translate into strong params + + @order_item = OrderItem.new(product_id: params[:product_id].to_i, quantity: params[:quantity].to_i, order_id: current_order) + session[:order_id] = @order_item.order.id + # order_id = OrderItem.add_order_item_to_order(@order_item) + # @order_item.order_id = order_id + + # TODO: add if/else or model method to check against + edit product inventory + + result = @order_item.save + + if result + flash[:status] = :success + flash[:result_text] = "Successfully created + order item #{@order_item.product.name}." + + else + flash[:status] = :failure + flash[:result_text] = "DID NOT create order item #{order_id}" + flash[:messages] = @order_item.errors.messages + end + + redirect_back(fallback_location: root_path) + end + + def update + @order_item = OrderItem.find_by(id: params[:order_item_id]) + + @order_item.update(quantity: params[:quantity]) + + if @order_item.save + flash[:status] = :success + flash[:result_text] = "Successfully updated order item: #{@order_item.product.name}" + flash[:messages] = @order_item.errors.messages + else + flash[:status] = :failure + flash[:result_text] = "Did not update order item: #{@order_item.product.name}" + flash[:messages] = @order_item.errors.messages + end + redirect_to orders_path + + end + + def change_shipping_status + @order_item = OrderItem.find_by(id: params[:order_item_id]) + + @order_item.update(shipped: params[:shipped]) + + if @order_item.save + flash[:status] = :success + flash[:result_text] = "Successfully changed shipping status for item #{@order_item.product.name}" + flash[:messages] = @order_item.errors.messages + else + flash[:status] = :failure + flash[:result_text] = "Could not change shipping status for order item #{@order_item.product.name}" + flash[:messages] = @order_item.errors.messages + end + + redirect_back(fallback_location: root_path) + end + + + # NOTE: actions below are for order... should instead be for order_item? + + # def update + # @order = current_order + # @order_item = @order.order_items.find(params[:id]) + # @order_item.update_attributes(order_item_params) + # @order_items = @order.order_items + # end + + # def destroy + # @order = current_order + # @order_item = @order.order_items.find(params[:id]) + # @order_item.destroy + # @order_items = @order.order_items + # end + + def destroy + @order_item = OrderItem.find_by(id: params[:id]) + + result = @order_item.destroy + + if result + flash[:status] = :success + flash[:result_text] = "Successfully destroyed item: #{@order_item.product.name}" + redirect_to orders_path + else + flash[:status] = :failure + flash[:result_text] = "Did not delete #{@order_item.product.name}" + flash[:messages] = @order_item.errors.messages + end + end + + # private + # + # def order_item_params + # params.require(:order_items).permit(:product_id, :quantity) + # end + + # end + + + +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..ba23a53fb9 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,191 @@ +class OrdersController < ApplicationController + before_action :find_order, only: [:show, :edit, :update, :destroy] + before_action :matching_guest, only: [:show] + + + def index + + @orders = Order.find_by(id: session[:order_id]) + # commented out because it's confusong? + # if session[:merchant] + # merchant_id = session[:merchant]['id'] + # @orders = Merchant.find(merchant_id).orders + # end + + end + + def new + @order = Order.new + end + # add @order_items + def show + # if @order.nil? || !@order.order_items + # head :not_found + # else @order_items = current_order.order_items + # end + + # @order = Order.find_by(id: params[:id]) + # unless @order + # render_404 + # else + # merchants = @order.products.map { |p| p.merchant } + # if !merchants.include?(matching_guest) + # flash[:status] = :failure + # flash[:result_text] = "Access denied." + # redirect_to root_path + # end + # end + end + + def create + + + + # #TODO: translate into strong params + # @order_item = OrderItem.new(product_id: params[:product_id].to_i, quantity: params[:quantity].to_i, order_id: params[:order_id]) + # # order_id = OrderItem.add_order_item_to_order(@order_item) + # # @order_item.order_id = order_id + # + # # TODO: add if/else or model method to check against + edit product inventory + # + # result = @order_item.save + # + # if result + # flash[:status] = :success + # flash[:result_text] = "Successfully created + # order item" + # else + # flash[:status] = :failure + # flash[:result_text] = "DID NOT create order item #{order_id}" + # flash[:messages] = @order_item.errors.messages + # end + # redirect_back(fallback_location: root_path) + + + # if session[:order_id] == + # @order = Order.new #(params) + # @order_category = @order.category + # if @order.save + # flash[:status] = :success + # # flash[:result_text] = "Successfully created order" + # # redirect_to + # else + # flash[:status] = :failure + # # flash[:result_text] = "Could not create order" + # # flash[:messages] = @order.errors.messages + # # render :new, status: :bad_request + # end + + # NOTE: I commented the code below out b/c it threw errors + # if sessions[:order_id] == + # @order = Order.new #(params) + # @order_category = @order.category + # if @order.save + # flash[:status] = :success + # # flash[:result_text] = "Successfully created order" + # # redirect_to + # else + # flash[:status] = :failure + # # flash[:result_text] = "Could not create order" + # # flash[:messages] = @order.errors.messages + # # render :new, status: :bad_request + # end + # end + + @order = Order.find_by(id: session[:order_id]) + + if @order.nil? + flash[:status] = :failure + flash[:result_text] = "No order found" + flash[:messages] = @order_item.errors.messages + redirect_to root_path + return + end + + @order.update(order_params) + + @order.payment_status = "paid" + + result = @order.save + + if result + @order.decrement_inventory_via_order() + set_new_session_order_id() + + flash[:status] = :success + flash[:result_text] = "Order #{@order.id} successfully paid!" + render :show + else + flash[:status] = :failure + flash[:result_text] = "Experiencing an issue with order #{@order.id}." + flash[:messages] = @order.errors.messages + render :new + end + end + + def edit + if @order.nil? + head :not_found + end + end + + def update + # if @order.nil? + # head :not_found + # end + @order.update(order_params) + if + @order.update(status: "paid") + flash.now[:status] = :failure + flash.now[:result_text] = "Boo!" + flash.now[:messages] = humanize(@order.errors.messages) + render :new, status: :bad_request + end + end + + def destroy + if @order.nil? + head :not_found + end + #if @order.destroy + #redirect_to orders_path + #else + #render :show + #end + end + + private + + def find_order + @order = Order.find_by(id: params[:id]) + end + + def order_params + params.require(:order).permit(:guest_email, :guest_mailing, :guest_cc_name, :guest_cc_num, :guest_cc_exp_date, :guest_cc_cvv_code, :guest_cc_zip) + end + + + # QUESTION: should these be moved to the model? + + # if guest has submitted an order, then we start a new cart tied to a new session id + def create_new_cart_upon_submit() + new_order = Order.create() + return new_order + end + + def set_new_session_order_id() + new_order = create_new_cart_upon_submit() + session[:order_id] = new_order.id + end + + def matching_guest + order_viewing = Order.find_by(id: params[:id]) + + if find_order.nil? || find_order.id != order_viewing.id + flash[:status] = :failure + flash[:result_text] = "Only owner of order #{order_viewing.id} may view this page." + + redirect_to root_path + end + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..21a304bbad --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,165 @@ +class ProductsController < ApplicationController + before_action :require_login, only: [:new, :create] + before_action :find_product, only: [:show, :edit, :update] + + def index + if params[:merchant_id] + merchant = Merchant.find_by(id: params[:merchant_id]) + @products = merchant.products + + elsif params[:category_id] + category = Category.find_by(id: params[:category_id]) + @products = category.products + else + @products = Product.all + end + end + + def new + @product = Product.new + @product.photo_url = "" + end + + def create + if @login_user + # merchant_id = @login_user.id + # @login_user = @merchant.product.id + params = product_params + + params[:price] = params[:price].to_f * 100 + params[:merchant_id] = @login_user.id + params[:photo_url] = "https://i.imgur.com/lbztpnF.jpg" if params[:photo_url].empty? + + @product = Product.new(params) + # @product.price = @product.price_float_to_int + # @product.merchant_id = @login_user.id + # @product.photo_url = "https://i.imgur.com/lbztpnF.jpg" if @product.photo_url.empty? + + + if @product.save + flash[:status] = :success + flash[:result_text] = "Successfully created + #{@product.name}" + redirect_to product_path(@product) + # debugger + else + flash[:status] = :failure + flash[:result_text] = "Experiencing an issue with order #{@product.id}." + flash[:messages] = @product.errors.messages + render :new + end + end + + + if !@login_user + flash[:status] = :failure + flash[:result_text] = "Could not create #{@product}" + # flash[:messages] = @product.errors.messages + redirect_to root_path + end + # debugger + end + + def show; + @avg_rating = self.get_average_rating() + end + + def edit + @product = Product.find_by(id: params[:id]) + + end + + def update + if @login_user + + params = product_params + + params[:price] = params[:price].to_f * 100 + + @product.update(params) + + result = @product.save + + if result + flash[:status] = :success + flash[:result_text] = "Successfully updated product #{@product.name}" + redirect_to product_path(@product.id) + else + flash[:status] = :failure + flash[:result_text] = "Failed to update" + flash[:messages] = @product.errors.messages + render :edit, status: :bad_request + end + else + redirect_back fallback_location: root_path, status: :bad_request + + end + end + + # shipped toggle method - onced checked, the status should chacnge from true to false ship to shipped + + # def toggle_enable_status + # + # end + + def destroy + if @login_user + + product = Product.find_by(id: params[:id]) + + product.destroy + + flash[:status] = :success + flash[:result_text] = "Successfully deleted product #{product.name}" + redirect_to merchant_path(@login_user) + end + end + + + def add_to_order + @order_item = OrderItem.new + #(order_id: @current_cart.id, product_id: product.id, quantity: params[:order_items][:inventory], status: 'pending') + if @order_item.save + # product.inventory -= params[:order_products][:inventory].to_i + # product.save + flash[:status] = :success + flash[:result_text] = "Successfully added product to cart" + redirect_to product_path(@product.id) + else + flash[:status] = :failure + flash[:result_text] = "Failed to add to cart" + # render :show + end + end + + def get_average_rating + reviews = Review.where(product_id: @product.id) + sum = 0 + + reviews.each do |review| + unless review.star_rating == nil + sum = sum + review.star_rating + end + end + + length = reviews.length + + if length == 0 + return 0 + end + + average = sum / length + return average + end + + private + + def product_params + params.require(:product).permit(:name, :price, :description, :photo_url, :status, :inventory, category_ids: []) + end + + def find_product + @product = Product.find_by(id: params[:id]) + head :not_found unless @product + end +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..6804d260f9 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,50 @@ +class ReviewsController < ApplicationController + before_action :find_review, only: [:show, :edit, :update] + + def new + @review = Review.new + @review.product = Product.find(params[:product_id]) + end + + def create + @review = Review.new(review_params) + @review.product = Product.find(params[:product_id]) + + if !@login_user + if @review.save + flash[:status] = :success + flash[:result_text] = "Successfully created review." + redirect_to product_path(@review.product) + else + render :new + end + end + + + + if @login_user + # && session.id == @product.login_user.id + flash[:status] = :failure + flash[:result_text] = "You cannot review your own product." + # flash[:messages] = @product.errors.messages + redirect_to product_path(@review.product) + end + end + + # if find_user && @user.id == @product.user.id + # flash[:status] = :failure + # flash[:result_text] = "Oops..You can't review your own product!" + # redirect_to product_path(@product.id) + + + private + + def review_params + params.require(:review).permit(:star_rating, :text, :product_id) + end + + def find_review + @review = Review.find_by(id: params[:id]) + head :not_found unless @review + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..6de1d9bef2 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,49 @@ +class SessionsController < ApplicationController + + def create + auth_hash = request.env['omniauth.auth'] + merchant = Merchant.find_by(uid: auth_hash[:uid], provider: 'github') + + if merchant + # User was found in the database + flash[:status] = "success" + flash[:result_text] = "Logged in as returning merchant #{merchant.username}" + + else + # User doesn't match anything in the DB + # Attempt to create a new user + merchant = Merchant.build_from_github(auth_hash) + + if merchant.save + flash[:status] = "success" + flash[:result_text] = "Logged in as new merchant #{merchant.username}" + # flash[:messages] = merchant.errors.messages + + else + # Couldn't save the user for some reason. If we + # hit this it probably means there's a bug with the + # way we've configured GitHub. Our strategy will + # be to display error messages to make future + # debugging easier. + flash[:status] = "failure" + flash[:result_text] = "Could not create new merchant account: #{merchant.errors.messages}" + flash[:messages] = merchant.errors.messages + + redirect_to root_path + return + end + end + + # If we get here, we have a valid user instance + session[:merchant_id] = merchant.id + redirect_to root_path + end + + def destroy + session.delete(:merchant_id) + flash[:status] = "success" + flash[:result_text] = "Successfully logged out!" + + redirect_to root_path + end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..d8c85ab84b --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,2 @@ +class WelcomeController < ApplicationController +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/helpers/merchants_helper.rb b/app/helpers/merchants_helper.rb new file mode 100644 index 0000000000..5337747b0f --- /dev/null +++ b/app/helpers/merchants_helper.rb @@ -0,0 +1,2 @@ +module MerchantsHelper +end diff --git a/app/helpers/order_helper.rb b/app/helpers/order_helper.rb new file mode 100644 index 0000000000..05d197a0c1 --- /dev/null +++ b/app/helpers/order_helper.rb @@ -0,0 +1,2 @@ +module OrderHelper +end diff --git a/app/helpers/order_items_helper.rb b/app/helpers/order_items_helper.rb new file mode 100644 index 0000000000..e197528ae1 --- /dev/null +++ b/app/helpers/order_items_helper.rb @@ -0,0 +1,2 @@ +module OrderItemsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/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/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000000..eeead45fc9 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000..a009ace51c --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..286b2239d1 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..477d4720ce --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,13 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true + + # QUESTION: overall --> protect from forgery?? how to secure user input? + + + # QUESTION: should this instead be in a view helper? + def convert_int_to_f(num) + if num.class == Integer || num.class == Float + return num.to_f/100.to_f + end + end +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..ab08728787 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,4 @@ +class Category < ApplicationRecord + has_and_belongs_to_many :products + validates :category_name, presence: true, uniqueness: 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/merchant.rb b/app/models/merchant.rb new file mode 100644 index 0000000000..33d0abf4f9 --- /dev/null +++ b/app/models/merchant.rb @@ -0,0 +1,17 @@ +class Merchant < ApplicationRecord + has_many :products + + validates :username, presence: true, uniqueness: true + validates :email, presence: true, uniqueness: true + + # TODO: maybe check for valid email form xxx@xxx.xxx + + def self.build_from_github(auth_hash) + merchant = Merchant.new + merchant.uid = auth_hash[:uid] + merchant.provider = 'github' + merchant.email = auth_hash['info']['email'] + merchant.username = auth_hash['info']['nickname'] + return merchant + end +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..e28d70f4e6 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,85 @@ +class Order < ApplicationRecord + # TODO: decide/add more validations+testing (cc info, mailing address, etc) + has_many :order_items + # for joining products though o_i + has_many :products, through: :order_items + + scope :filter_status, -> (filterstatus) { where filter_status: status } + + + # QUESTION: fulfillment_status --> check to make sure that statuses are one of the allowed ones (ex: pending, completed, paid, etc.) + + + def empty_cart?() + return self.order_items.nil? || self.order_items.empty? + end + + def order_total() + total_as_float = self.order_items.sum do |order_item| + order_item.order_item_subtotal() + end + + return total_as_float + end + +# TODO: reduce all these dependencies; sro! + def decrement_inventory_via_order() + self.order_items.each do |order_item| + order_item.decrement_inventory_via_order_item() + end + end + + # def show_only_merchant_order_items() + # all_items_in_order = self.order_items + # + # all_products_in_order = all_items_in_order.map {|product| product.where(id: item.product_id)} + # + # return all_products_in_order + # end + +def self.find_orders_by_status(status_string) + specified_orders = self.where(payment_status: status_string) +end + +def self.total_orders_by_status(status_string) + specified_orders = self.find_orders_by_status(status_string) + + orders_count = specified_orders.length + + return orders_count +end + +def self.revenue_by_status(status_string) + specified_orders = self.find_orders_by_status(status_string) + + specified_orders.total_revenue +end + +def self.total_revenue() + order_items = self.all.map {|order| order.order_items}.flatten + + order_items.sum {|item| item.order_item_subtotal} +end + +def filter_status + @orders = Order.status("pending").starts_with("Paid") +end + +# def self.total_revenue() +# self.merchant_revenue_by_order_items +# +# +# end + + + private + # QUESTION: what does this do? is this old? + # def set_fullfillment_status + # self.order_status_id = 1 + # end + def confirm_payment? + self.payment_status == "paid" + end + + +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..c460b15db4 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,54 @@ +class OrderItem < ApplicationRecord + belongs_to :order + belongs_to :product + + validates :quantity, presence: true, numericality: { greater_than: 0, only_integer: true } + + + # TODO: change from true/false to pending etc. [this will cause errors i think until we can coordinate it] + validates :shipped, inclusion: { in: [true, false] } + + def order_item_subtotal() + price = convert_int_to_f(self.product.price) + quantity = self.quantity + + return price * quantity + end + + def decrement_inventory_via_order_item() + product = self.product + inventory = product.inventory + + quantity = self.quantity + + difference = inventory - quantity + + if difference < 0 + raise ArguementError, "Guest cannot purchase more inventory than is available" + # QUESTION: add flash messages? rescue? + end + + product[:inventory] = difference + result = product.save + + if result + p "great" + # QUESTION: add flash messages? + else + raise ArguementError, "Unable to alter product inventory" + # QUESTION: add flash messages? rescue? + end + + end + def double_check_availability() + if self.product.inventory < 1 + flash[:status] = :failure + flash[:result_text] = "Sorry - product #{self.product.name} is no longer available!" + + redirect_to order_item_path(order_item.id), method: :delete + end + end + + + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..215a51eff7 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,34 @@ +class Product < ApplicationRecord + has_many :reviews + has_many :order_items + # for join table + has_many :orders, through: :order_items + belongs_to :merchant + has_and_belongs_to_many :categories + + validates :name, presence: true, uniqueness: true + # TODO: maybe product name must be unique to category??? + validates :price, presence: true, numericality: { greater_than: 0 } + + # Deleted/inactive products aren't shown + default_scope { where(status: true) } + + validates :inventory, presence: true, numericality: { greater_than: -1 } + + + + # QUESTION: how to handle invalid photo URLS since that will 'show up' ?? + # QUESTION: status default --> true?? to show it's automatically active? + + + # QUESTION: should these be view helpers instead? + def price_int_to_float() + return convert_int_to_f(self.price) + end + + def price_float_to_int() + return self.price * 100 + end + + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..651c889ec5 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,5 @@ +class Review < ApplicationRecord + belongs_to :product + + validates :star_rating, presence: true, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 5, only_integer: true } +end diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb new file mode 100644 index 0000000000..322a8d5c67 --- /dev/null +++ b/app/views/categories/_form.html.erb @@ -0,0 +1,15 @@ +
+ <%= form_with model: @category, local: true do |f| %> + + +
+ <%= f.label :category_name %> + <%= f.text_field :category_name, class: "form-control" %> +
+ + +
+ <%= f.submit class: "btn btn-primary" %> +
+ <% end %> +
diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 0000000000..32f590c555 --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,22 @@ +
+ +
+

Product Categories

+
+ +
+ + +

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

Add a New Category

+<%= render partial: "form" %> + +
diff --git a/app/views/layouts/_merchant_account_products.html.erb b/app/views/layouts/_merchant_account_products.html.erb new file mode 100644 index 0000000000..62307f979a --- /dev/null +++ b/app/views/layouts/_merchant_account_products.html.erb @@ -0,0 +1,54 @@ +

Available Products

+ + + + + + + + + + + + +<% @merchant.products.each do |product| %> + + + + + + + + + + <% end %> + + + +
+ Name + + Inventory + + Price + + Status + + + + +
+ <%= link_to product.name, product_path(product) %> + + <%= product.inventory %> + + <%= number_to_currency(product.price_int_to_float, precision: 2) %> + + + <%= product.status %> + + <%= link_to "Edit", edit_product_path(product.id) %> + + <%= link_to "Delete", product_path(product.id), method: :delete, data: { + confirm: "Are you sure you want to delete this entry #{product.name}?" }, class: "btn btn-danger" %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..d16635f00f --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,93 @@ + + + + Betsy + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + +
+

+ <%= link_to "REDSY", root_path %>All Red, All The Time +

+ + + +
+ + <% if flash[:result_text] or flash[:messages] %> +
+
+ <%= flash[:status].to_s == "failure" ? "A problem occurred: " : "" %><%= flash[:result_text] %> + <% if flash[:messages] %> + + <% 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/merchants/about_us.html.erb b/app/views/merchants/about_us.html.erb new file mode 100644 index 0000000000..e0633fe336 --- /dev/null +++ b/app/views/merchants/about_us.html.erb @@ -0,0 +1,37 @@ +
+
+

About Us

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

Merchant Edit Page

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

Our Merchants

+
+
+ +

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

New Merchant Page

diff --git a/app/views/merchants/order_summary.html.erb b/app/views/merchants/order_summary.html.erb new file mode 100644 index 0000000000..0362d24176 --- /dev/null +++ b/app/views/merchants/order_summary.html.erb @@ -0,0 +1,103 @@ +
+
+

Orders Summary

+
+
+ <% if @login_user != nil %> + + + + + + +
+ Total Revenue: <%= number_to_currency(@orders.total_revenue, precision: 2) %> + By status Paid: <%= number_to_currency(@orders.revenue_by_status("paid"), precision: 2)%> + + By status Complete: <%= number_to_currency(@orders.revenue_by_status("complete"), precision: 2)%> +
+ +
+ + + + + + +
+ Total Orders: <%= @orders.length %> + Orders Paid: <%= @orders.total_orders_by_status("paid") %> + + Orders Complete: <%= @orders.total_orders_by_status("complete") %> +
+ + + + <% end %> + +
+

Orders

+ + + + + + + + + + + + + + + + + + + <% @order_items.each do |item| %> + + + + + + + + + + + + + + + <% end %> + +
Order IDPurchase DateItem NameItem QuantityItem PriceItem SubtotalCurrent StatusShip Status
+ <%= link_to item.order.id, order_path(item.order) %> + + + <%= item.order.created_at.strftime("%m/%d/%Y") %> + + <%= item.product.name %> + + + <%= item.quantity %> + + + <%= number_to_currency(item.product.price_int_to_float, precision: 2) %> + + <%= number_to_currency(item.order_item_subtotal, precision: 2) %> + + + <%= item.order.payment_status %> + + <%= item.shipped %> + + + <% if item.shipped == false %> + <%= link_to "Mark as shipped", ship_item_path({order_item_id: item.id, shipped: true}), method: :put, class: "btn btn-danger"%> + <% else %> + <%= link_to "Unship", ship_item_path({order_item_id: item.id, shipped: false}), method: :put, class: "btn btn-danger"%> + <% end %> +
+
diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb new file mode 100644 index 0000000000..63c45990ca --- /dev/null +++ b/app/views/merchants/show.html.erb @@ -0,0 +1,16 @@ +
+

Merchant Summary: <%= @merchant.username %>

+

+

+ <% if @login_user != nil %> + <%= link_to "Add Product", new_product_path, class: "btn btn-primary add-product" %> + <%= link_to "Add Category", new_category_path, class: "btn btn-primary add-category" %> + <%= link_to "Order Summary", merchant_order_summary_path(@merchant), class: "btn btn-primary order-summary" %> + <% end %> +
+

+ +

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

+
diff --git a/app/views/orders/_order_form.html.erb b/app/views/orders/_order_form.html.erb new file mode 100644 index 0000000000..3341a3d00e --- /dev/null +++ b/app/views/orders/_order_form.html.erb @@ -0,0 +1,44 @@ +
+ <%= form_with model: @order, local: true do |f| %> + + +
+ <%= f.label :name %> + <%= f.text_field :guest_cc_name, class: "form-control" %> +
+ +
+ <%= f.label :address%> + <%= f.text_field :guest_mailing, class: "form-control" %> +
+ +
+ <%= f.label :email %> + <%= f.text_field :guest_email, class: "form-control" %> +
+ +
+ <%= f.label :credit_card_number %> + <%= f.text_field :guest_cc_num, class: "form-control" %> +
+ +
+ <%= f.label :expiration_date %> + <%= f.text_field :guest_cc_exp_date, class: "form-control" %> +
+ +
+ <%= f.label :cvv %> + <%= f.text_field :guest_cc_cvv_code, class: "form-control" %> +
+ +
+ <%= f.label :billing_zip_code %> + <%= f.text_field :guest_cc_zip, class: "form-control" %> +
+ +
+ <%= f.submit action_type, class: "btn btn-primary" %> +
+ <% end %> +
diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000000..803ef8c329 --- /dev/null +++ b/app/views/orders/edit.html.erb @@ -0,0 +1 @@ +

Edit Order Page

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

Your Cart

+
+ +<% if !@orders || @orders.empty_cart? %> +

Cart is empty!

+ +<% else %> + +

Products

+
+ + + + + + + + + + + + + + +<% @orders.order_items.each do |order_item| %> +<% order_item.double_check_availability %> + + + + + + + + + + + + <% end %> + + + + + + + + + + + +
+ Image + + Item Name + + Unit Price + + Current Quantity + + Update Quantity + + Remove + + Subtotal +
+ <%= link_to image_tag("#{order_item.product.photo_url}"), product_path(order_item.product.id), class: "order-image"%> + + <%= link_to order_item.product.name, product_path(order_item.product.id) %> + + + <%= number_to_currency((order_item.product.price_int_to_float), precision: 2) %> + + <%= order_item.quantity %> + + <%= form_with model: @order_item, url: order_items_update_path(:order_item_id => order_item), method: :put do |f|%> + + <%= f.label :quantity%> + <%= f.select :quantity, (1..order_item.product.inventory) %> + <%= f.submit "Update", class: "btn btn-primary update-order" %> + + <% end %> + + + + <%= link_to 'Remove from Cart', order_item_path(order_item.id), method: :delete, data: { confirm: "Are you sure you want to delete item: #{order_item.product.name}?" }, class: "btn btn-primary remove-item" %> + + <%= number_to_currency(order_item.order_item_subtotal, precision: 2) %> +
+ + + + + + + TOTAL: <%= number_to_currency(@orders.order_total, precision: 2) %> +
+
+

+

+ <%= link_to 'Proceed to Checkout', new_order_path, class: "btn btn-success" %> +
+ + +<% end %> +
diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..0d98e4ace6 --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,7 @@ +
+ +

New Order Page

+ +<%= render partial: "order_form", locals: { action_type: "Submit Payment Info" } %> + +
diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..494d43edb1 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,41 @@ +
+ <% if session[:merchant_id].nil? %> +
+

Thanks for shopping with us!

+
+

+ <% end %> + +

Order Details

+

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

+

Purchased on: <%=@order.created_at.strftime("%m/%d/%Y") %>

+

Purchase status: <%=@order.payment_status %>

+

Name: <%=@order.guest_cc_name %>

+

Shipping address: <%=@order.guest_mailing %>

+

Email: <%=@order.guest_email %>

+
+ + + +

Products Purchased

+ + + + + + + + + <% @order.order_items.each do |item| %> + + + + + + <% end %> +
Product: Price: Quantity:
<%= link_to item.product.name, product_path(item.product.id) %><%=number_to_currency(item.product.price_int_to_float, precision: 2) %> <%= item.quantity %>
+ +
+

+ Purchase Total: <%= number_to_currency(@order.order_total, precision: 2) %> +

diff --git a/app/views/products/_product_form.html.erb b/app/views/products/_product_form.html.erb new file mode 100644 index 0000000000..ad4a60b71f --- /dev/null +++ b/app/views/products/_product_form.html.erb @@ -0,0 +1,39 @@ +
+ <%= form_with model: @product do |f| %> + + +
+ <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
+ +
+ <%= f.label :price%> + <%= f.text_field :price, class: "form-control", :value => number_with_precision(f.object.price_int_to_float, :precision => 2) %> +
+ +
+ <%= f.label :description %> + <%= f.text_area :description, class: "form-control" %> +
+ +
+ <%= f.label :inventory %> + <%= f.text_field :inventory, class: "form-control" %> +
+ +
+ <%= f.label :category_ids, "Select all categories that apply" %> + <%= f.select(:category_ids, Category.all.map { |c| [c.category_name, c.id] }, {}, :multiple => true, class: "form-control") %> +
+ +
+ <%= f.label :link_photo_url %> + <%= f.text_field :photo_url, class: "form-control" %> +
+ +
+ <%= f.submit action_type, class: "btn btn-primary" %> +
+ <% end %> +
diff --git a/app/views/products/by_category.html.erb b/app/views/products/by_category.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..7c3946c02f --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,3 @@ +

Product Edit Page

+ +<%= render partial: "product_form", locals: { action_type: "Edit Product", form_title: "Edit Product" } %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..f03b1bd8a7 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,31 @@ +
+
+<% if params[:category_id] %> +

List of Products: <%= Category.find(params[:category_id]).category_name.capitalize %> + <% elsif params[:merchant_id] %> +

<%= Merchant.find(params[:merchant_id]).username %>'s shop

+ <% else %> +

All Products

+ <% end %> +
+
+ +

+
    + <% @products.each do |p| %> +
  • + +
    + <%= link_to image_tag("#{p.photo_url}"), product_path(p.id), class: "image"%> +
    +
    + <%= link_to "#{p.name}", product_path(p.id) %> +
    + <%= number_to_currency(p.price_int_to_float, precision: 2) %> +
    +
  • + <% end %> +
+
+ +
diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..5799258644 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,6 @@ +
+ +

Add a New Product Page

+<%= render partial: "product_form", locals: { action_type: "Create Product" } %> + +
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..e2c564ab89 --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,76 @@ +
+ +
+

Product Details

+
+

+
+
+ <%= image_tag "#{@product.photo_url}", class: "show-image" %> +
+ +
+

+ <%= @product.name %> +

+

+

+ Price: + <%= number_to_currency(@product.price_int_to_float, precision: 2) %> +
+ +
Seller: + <%= link_to @product.merchant.username, merchant_products_path(@product.merchant.id) %> +
+

+

+ <% if @product.inventory < 1 %> + Out of Stock + <% else %> + Available Stock: <%= @product.inventory %> +
+
+ <%= form_with model: @order, url: product_order_items_create_path(@product.id), method: :post do |f|%> + <%= f.label :quantity%> + <%= f.select :quantity, (1..@product.inventory) %>
+ <%= f.submit "Add Item to Cart", class: "btn btn-primary add-cart" %> + <% end %> + <% end %> +
+
+
Description: + <%= @product.description %> +
+ +
Categories: + <% @product.categories.each do |c| %> + <%= link_to c.category_name, category_products_path(c.id) %> + <% end %> +
+
+
+ +
+
+

Rating Summary

+
+
+
  • Average rating: <%= @avg_rating %>
  • +
    +
    +
    + Reviews + <% @product.reviews.each do |r| %> +
  • Rating: <%= r.star_rating %>
  • +

    +

  • Review: <%= r.text %>
  • +
    + <% end %> +
    +

    +

    + <%= link_to "Add review", new_product_review_path(@product), class: "btn btn-primary add-cart"%> +
    +
    + +
    diff --git a/app/views/reviews/_review_form.html.erb b/app/views/reviews/_review_form.html.erb new file mode 100644 index 0000000000..81d0035d77 --- /dev/null +++ b/app/views/reviews/_review_form.html.erb @@ -0,0 +1,21 @@ +
    + +
    + <%= form_with(model: @review, url: [@review.product, @review]) do |f| %> + +
    + <%= f.label :rating %>: + <%= f.select(:star_rating, ['1', '2', '3', '4', '5']) %> +
    + +
    + <%= f.label :review %> + <%= f.text_field :text, class: "form-control" %> +
    + +
    + <%= f.submit action_type, class: "btn btn-primary" %> +
    + <% end %> +
    +
    diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..a3b924b79f --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,22 @@ +
    + +
    +

    Add a New Review

    +
    +

    + +
    +
    + <%= image_tag "#{@review.product.photo_url}", class: "show-image" %> +
    + +
    +

    + <%= @review.product.name %> +

    +

    +

    + + <%= render partial: "review_form", locals: { action_type: "Create Review" } %> + +
    diff --git a/app/views/reviews/show.html.erb b/app/views/reviews/show.html.erb new file mode 100644 index 0000000000..8a075282eb --- /dev/null +++ b/app/views/reviews/show.html.erb @@ -0,0 +1 @@ +<%= render partial: "review_form", locals: { action_type: "Edit Review", form_title: "Edit Product" } %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 0000000000..1d14121b75 --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,29 @@ +
    +

    Welcome to Redsy

    +
    + +
    + diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000000..f19acf5b5c --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000000..5badb2fde0 --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000000..d87d5f5781 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000000..94fd4d7977 --- /dev/null +++ b/bin/setup @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000000..fb2ec2ebb4 --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000000..58bfaed518 --- /dev/null +++ b/bin/update @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 0000000000..460dd565b4 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..f7ba0b527b --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000000..5c09a3eefc --- /dev/null +++ b/config/application.rb @@ -0,0 +1,25 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Betsy + class Application < Rails::Application + config.generators do |g| + # Force new test files to be generated in the minitest-spec style + g.test_framework :minitest, spec: true + # Always use .js files, never .coffee + g.javascript_engine :js + end + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000000..b9e460cef3 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000000..dd2a324c68 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: betsy_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000000..cecdfdddf5 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +zDmXME5PLAQz8KijnopkvXYe3hAI5G+KXo9UvsFwL11Yu0KQZ2VFiwC/yxlhVy1V0znpsecIF+irUZSUNGP1riwVJIsF4mdnshlX3s8l+LPS9hX3yMpS93g7WMPbqMqv4RjCpv8D7mTQ1VwQ1Co78mcWAxZ02Jrne7tXwvBfoJ01/VHBomDoEkBE7kH0aoZRQDQ0NnAt5Y7woRz1jgu6e9VL3E9aGkJodw1EJKcGmiTZc6ZRcSt2L5eJAQJEGoJpSO1VkU0aOEJWOnGiwSuN69IbqZkAk8AOn4QKR+LjVg+vRyY+CnnSNGAdRN1R+jJcb8F3mP94UJGnL6RHwiDLgaZiozbt0AsZjCqh65TG9IumD95L1GBTFBU8KgAtrX0bVf3UueoaqAMNv3Nbs0zYHgDg8IxhZfJtWIDF--JPJCCoWagE1xuE9a--nIGqQ408gtXwbNOT+BlyoA== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..6903bb6083 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: betsy_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: betsy + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: betsy_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: betsy_production + username: betsy + password: <%= ENV['BETSY_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000..426333bb46 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000000..1311e3e4ef --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,61 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000000..5f6f3058c6 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,94 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "betsy_#{Rails.env}" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000000..0a38fd3ce9 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,46 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb new file mode 100644 index 0000000000..142d382f87 --- /dev/null +++ b/config/initializers/action_view.rb @@ -0,0 +1 @@ +Rails.application.config.action_view.form_with_generates_remote_forms = false diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000000..89d2efab2b --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..4b828e80cb --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000..59385cdf37 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000000..d3bcaa5ec8 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000000..5a6a32d371 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..4a994e1e7b --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000000..ac033bf9dc --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000000..dc1899682b --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..ef8c60c371 --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,4 @@ +# config/initializers/omniauth.rb +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/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..10ec60facc --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,48 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root 'welcome#index' + + get '/merchant/about_us', to: 'merchants#about_us', as: 'about_us' + + get '/product/:id/add_to_order', to: 'products#add_to_order', as: 'add_to_order' + + get "/auth/:provider/callback", to: "sessions#create", as: 'auth_callback' + + delete "/logout", to: "sessions#destroy", as: "logout" + + + resources :orders do + #put '/filter_status', to: 'orders#filter_status', as: 'filter_order' + end + + resources :order_items, include: [:show, :delete] + + put '/update_order_item', to: 'order_items#update', as: 'order_items_update' + + put '/ship_me/', to: 'order_items#change_shipping_status', as: + 'ship_item' + + + + resources :categories do + resources :products, include: [:index, :show, :create] + end + + resources :merchants do + resources :products, include: [:index, :show, :create] + get '/order_summary', to: 'merchants#order_summary', as: 'order_summary' + end + + + resources :products, only: [:index, :new, :create, :edit, :update, :show, :destroy] do + post '/add_order_item', to: 'order_items#create', as: 'order_items_create' + resources :reviews, shallow: true + end + + + + + + # NOTE: nested route ideas: merchants/id#/products and categories/id#/products ??? + +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/migrate/20181018173542_create_merchants.rb b/db/migrate/20181018173542_create_merchants.rb new file mode 100644 index 0000000000..6fbed1393c --- /dev/null +++ b/db/migrate/20181018173542_create_merchants.rb @@ -0,0 +1,10 @@ +class CreateMerchants < ActiveRecord::Migration[5.2] + def change + create_table :merchants do |t| + t.string :username + t.string :email + + t.timestamps + end + end +end diff --git a/db/migrate/20181018173747_create_products.rb b/db/migrate/20181018173747_create_products.rb new file mode 100644 index 0000000000..806b7e381a --- /dev/null +++ b/db/migrate/20181018173747_create_products.rb @@ -0,0 +1,14 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.string :name + t.integer :price + t.string :description + t.string :photo_url + t.boolean :status + t.integer :inventory + + t.timestamps + end + end +end diff --git a/db/migrate/20181018173816_create_categories.rb b/db/migrate/20181018173816_create_categories.rb new file mode 100644 index 0000000000..92db7eb4be --- /dev/null +++ b/db/migrate/20181018173816_create_categories.rb @@ -0,0 +1,8 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20181018174434_create_orders.rb b/db/migrate/20181018174434_create_orders.rb new file mode 100644 index 0000000000..ee826ff6a8 --- /dev/null +++ b/db/migrate/20181018174434_create_orders.rb @@ -0,0 +1,14 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :payment_status + t.boolean :clear_cart + t.integer :total_price + t.datetime :date_time_placed + t.string :fulfillment_status + t.string :guest_user_info + + t.timestamps + end + end +end diff --git a/db/migrate/20181018174517_create_order_items.rb b/db/migrate/20181018174517_create_order_items.rb new file mode 100644 index 0000000000..cd9db5ef0d --- /dev/null +++ b/db/migrate/20181018174517_create_order_items.rb @@ -0,0 +1,9 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/migrate/20181018174609_create_reviews.rb b/db/migrate/20181018174609_create_reviews.rb new file mode 100644 index 0000000000..e1d038f2f5 --- /dev/null +++ b/db/migrate/20181018174609_create_reviews.rb @@ -0,0 +1,10 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.integer :star_rating + t.string :text + + t.timestamps + end + end +end diff --git a/db/migrate/20181018181528_add_reference_in_product_to_merch.rb b/db/migrate/20181018181528_add_reference_in_product_to_merch.rb new file mode 100644 index 0000000000..07d1716c44 --- /dev/null +++ b/db/migrate/20181018181528_add_reference_in_product_to_merch.rb @@ -0,0 +1,5 @@ +class AddReferenceInProductToMerch < ActiveRecord::Migration[5.2] + def change + add_reference :products, :merchant, foreign_key: true + end +end diff --git a/db/migrate/20181018181755_add_reference_in_review_to_prod.rb b/db/migrate/20181018181755_add_reference_in_review_to_prod.rb new file mode 100644 index 0000000000..db9fd6236b --- /dev/null +++ b/db/migrate/20181018181755_add_reference_in_review_to_prod.rb @@ -0,0 +1,5 @@ +class AddReferenceInReviewToProd < ActiveRecord::Migration[5.2] + def change + add_reference :reviews, :product, foreign_key: true + end +end diff --git a/db/migrate/20181018181934_add_reference_in_order_item_to_prod_and_order.rb b/db/migrate/20181018181934_add_reference_in_order_item_to_prod_and_order.rb new file mode 100644 index 0000000000..b174aa0126 --- /dev/null +++ b/db/migrate/20181018181934_add_reference_in_order_item_to_prod_and_order.rb @@ -0,0 +1,6 @@ +class AddReferenceInOrderItemToProdAndOrder < ActiveRecord::Migration[5.2] + def change + add_reference :order_items, :product, foreign_key: true + add_reference :order_items, :order, foreign_key: true + end +end diff --git a/db/migrate/20181018182126_add_reference_in_order_to_orditem.rb b/db/migrate/20181018182126_add_reference_in_order_to_orditem.rb new file mode 100644 index 0000000000..ebbd8d76a9 --- /dev/null +++ b/db/migrate/20181018182126_add_reference_in_order_to_orditem.rb @@ -0,0 +1,5 @@ +class AddReferenceInOrderToOrditem < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :order_item, foreign_key: true + end +end diff --git a/db/migrate/20181018182425_create_join_table_category_products.rb b/db/migrate/20181018182425_create_join_table_category_products.rb new file mode 100644 index 0000000000..a67c560e5a --- /dev/null +++ b/db/migrate/20181018182425_create_join_table_category_products.rb @@ -0,0 +1,8 @@ +class CreateJoinTableCategoryProducts < ActiveRecord::Migration[5.2] + def change + create_join_table :categories, :products do |t| + # t.index [:category_id, :product_id] + # t.index [:product_id, :category_id] + end + end +end diff --git a/db/migrate/20181018190251_add_category_name_to_category.rb b/db/migrate/20181018190251_add_category_name_to_category.rb new file mode 100644 index 0000000000..cda6b5c5e6 --- /dev/null +++ b/db/migrate/20181018190251_add_category_name_to_category.rb @@ -0,0 +1,5 @@ +class AddCategoryNameToCategory < ActiveRecord::Migration[5.2] + def change + add_column :categories, :category_name, :string + end +end diff --git a/db/migrate/20181018211820_add_uid_to_merchants.rb b/db/migrate/20181018211820_add_uid_to_merchants.rb new file mode 100644 index 0000000000..a3230fab34 --- /dev/null +++ b/db/migrate/20181018211820_add_uid_to_merchants.rb @@ -0,0 +1,5 @@ +class AddUidToMerchants < ActiveRecord::Migration[5.2] + def change + add_column :merchants, :uid, :integer, null: false + end +end diff --git a/db/migrate/20181018212016_add_provider_to_merchants.rb b/db/migrate/20181018212016_add_provider_to_merchants.rb new file mode 100644 index 0000000000..91a549f132 --- /dev/null +++ b/db/migrate/20181018212016_add_provider_to_merchants.rb @@ -0,0 +1,5 @@ +class AddProviderToMerchants < ActiveRecord::Migration[5.2] + def change + add_column :merchants, :provider, :string, null: false + end +end diff --git a/db/migrate/20181019215520_edit_order_columns_cost_guest_info_etc.rb b/db/migrate/20181019215520_edit_order_columns_cost_guest_info_etc.rb new file mode 100644 index 0000000000..6d8c54cee1 --- /dev/null +++ b/db/migrate/20181019215520_edit_order_columns_cost_guest_info_etc.rb @@ -0,0 +1,17 @@ +class EditOrderColumnsCostGuestInfoEtc < ActiveRecord::Migration[5.2] + def change + add_column :orders, :guest_email, :string + add_column :orders, :guest_mailing, :string + add_column :orders, :guest_cc_name, :string + add_column :orders, :guest_cc_num, :string + add_column :orders, :guest_cc_exp_date, :string + add_column :orders, :guest_cc_cvv_code, :string + add_column :orders, :guest_cc_zip, :string + + remove_column :orders, :guest_user_info, :string + remove_column :orders, :date_time_placed, :datetime + remove_column :orders, :total_price, :integer + + remove_reference(:orders, :order_item, index: true, foreign_key: true) + end +end diff --git a/db/migrate/20181019222757_add_default_status_to_products.rb b/db/migrate/20181019222757_add_default_status_to_products.rb new file mode 100644 index 0000000000..acb5e6d2ea --- /dev/null +++ b/db/migrate/20181019222757_add_default_status_to_products.rb @@ -0,0 +1,5 @@ +class AddDefaultStatusToProducts < ActiveRecord::Migration[5.2] + def change + change_column :products, :status, :boolean, default: true + end +end diff --git a/db/migrate/20181019222914_add_shipped_status_to_orderitems.rb b/db/migrate/20181019222914_add_shipped_status_to_orderitems.rb new file mode 100644 index 0000000000..8d9ce18e00 --- /dev/null +++ b/db/migrate/20181019222914_add_shipped_status_to_orderitems.rb @@ -0,0 +1,5 @@ +class AddShippedStatusToOrderitems < ActiveRecord::Migration[5.2] + def change + add_column :order_items, :shipped, :boolean, default: false + end +end diff --git a/db/migrate/20181024170254_orders_change_status_default_drop_clear_cart.rb b/db/migrate/20181024170254_orders_change_status_default_drop_clear_cart.rb new file mode 100644 index 0000000000..0bb91a2a8c --- /dev/null +++ b/db/migrate/20181024170254_orders_change_status_default_drop_clear_cart.rb @@ -0,0 +1,6 @@ +class OrdersChangeStatusDefaultDropClearCart < ActiveRecord::Migration[5.2] + def change + change_column_default :orders, :payment_status, "pending" + remove_column :orders, :clear_cart, :boolean + end +end diff --git a/db/migrate/20181025015735_add_category_product_index.rb b/db/migrate/20181025015735_add_category_product_index.rb new file mode 100644 index 0000000000..ecfcabbd56 --- /dev/null +++ b/db/migrate/20181025015735_add_category_product_index.rb @@ -0,0 +1,5 @@ +class AddCategoryProductIndex < ActiveRecord::Migration[5.2] + def change + add_index :categories_products, [:category_id, :product_id], unique: true + end +end diff --git a/db/migrate/20181026173653_add_default_image.rb b/db/migrate/20181026173653_add_default_image.rb new file mode 100644 index 0000000000..e0f50e813f --- /dev/null +++ b/db/migrate/20181026173653_add_default_image.rb @@ -0,0 +1,5 @@ +class AddDefaultImage < ActiveRecord::Migration[5.2] + def change + change_column_default :products, :photo_url, "https://i.imgur.com/lbztpnF.jpg" + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..52c29d845e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,90 @@ +# 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_26_173653) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "category_name" + end + + create_table "categories_products", id: false, force: :cascade do |t| + t.bigint "category_id", null: false + t.bigint "product_id", null: false + t.index ["category_id", "product_id"], name: "index_categories_products_on_category_id_and_product_id", unique: true + end + + create_table "merchants", force: :cascade do |t| + t.string "username" + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "uid", null: false + t.string "provider", null: false + end + + create_table "order_items", force: :cascade do |t| + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.bigint "order_id" + t.boolean "shipped", default: false + t.index ["order_id"], name: "index_order_items_on_order_id" + t.index ["product_id"], name: "index_order_items_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.string "payment_status", default: "pending" + t.string "fulfillment_status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "guest_email" + t.string "guest_mailing" + t.string "guest_cc_name" + t.string "guest_cc_num" + t.string "guest_cc_exp_date" + t.string "guest_cc_cvv_code" + t.string "guest_cc_zip" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.integer "price" + t.string "description" + t.string "photo_url", default: "https://i.imgur.com/lbztpnF.jpg" + t.boolean "status", default: true + t.integer "inventory" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "merchant_id" + t.index ["merchant_id"], name: "index_products_on_merchant_id" + end + + create_table "reviews", force: :cascade do |t| + t.integer "star_rating" + t.string "text" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.index ["product_id"], name: "index_reviews_on_product_id" + end + + add_foreign_key "order_items", "orders" + add_foreign_key "order_items", "products" + add_foreign_key "products", "merchants" + add_foreign_key "reviews", "products" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..e7f27e68af --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,24 @@ +# 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) + +# Product.delete_all +# Product.create! id: 10, name: "Cherry", price: 22.49, status: true, merchant_id: 1 +# Product.create! id: 11, name: "Apple", price: 0.29, status: true, merchant_id: 1 +# Product.create! id: 12, name: "Strawberries", price: 1.99, status: true, merchant_id: 1 +# +# Order.delete_all +# Order.create! id: 1, fulfillment_status: "In Progress" +# Order.create! id: 2, fulfillment_status: "Placed" +# Order.create! id: 3, fulfillment_status: "Shipped" +# Order.create! id: 4, fulfillment_status: "Cancelled" +# +# # Merchant.delete_all +# Merchant.create! id: 20, username: "Small Fry", email: "fry@gmail.com", uid: 33, provider: "github" +# Merchant.create! id: 21, username: "Momma", email: "momma@gmail.com", uid: 44, provider: "github" +# Merchant.create! id: 22, username: "Big Papa", email: "big_papa@gmail.com", uid: 55, provider: "github" +# Merchant.create! id: 23, username: "Disco", email: "disco@gmail.com", uid: 66, provider: "github" diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json new file mode 100644 index 0000000000..f874acf437 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "betsy", + "private": true, + "dependencies": {} +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000000..2be3af26fc --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
    +
    +

    The page you were looking for doesn't exist.

    +

    You may have mistyped the address or the page may have moved.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000000..c08eac0d1d --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
    +
    +

    The change you wanted was rejected.

    +

    Maybe you tried to change something you didn't have access to.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000000..78a030af22 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
    +
    +

    We're sorry, but something went wrong.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000000..37b576a4a0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..a2c990ee49 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,50 @@ +require "test_helper" + +describe CategoriesController do + # it "must be a real test" do + # flunk "Need real tests" + # end + let(:wearables) { categories(:wearables) } + let(:mercury) { merchants(:mercury) } + + describe 'add new category' do + it 'lets a merchant add a new category' do + merchants(:mercury) + # binding.pry + expect { post categories_path, params: {category: {category_name: "drinkables"}}}.must_change 'Category.count', 1 + must_respond_with :redirect + end + + it 'doesnt let a guest access new category page' do + get new_category_path + must_respond_with :bad_request + end + + it 'doesnt let a guest add a new category' do + expect { post categories_path, params: {category: {category_name: "drinkables"}}}.must_change 'Category.count', 0 + must_respond_with :redirect + end + + it 'must be a unique category' do + merchants(:mercury) + wearables.category_name.must_equal "wearables" + expect { post categories_path, params: {category: {category_name: "wearables"}}}.must_change 'Category.count', 0 + end + + it 'does not allow a blank name' do + merchants(:mercury) + expect { post categories_path, params: {category: {category_name: " "}}}.must_change 'Category.count', 0 + + post categories_path, params: {category: {name: ""}} + must_respond_with :bad_request + + end + end + + describe 'categories view routes' do + it 'should get index' do + get categories_path + must_respond_with :success + end + end +end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb new file mode 100644 index 0000000000..6eb57f7baa --- /dev/null +++ b/test/controllers/merchants_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe MerchantsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/order_items_controller_test.rb b/test/controllers/order_items_controller_test.rb new file mode 100644 index 0000000000..96e3063c9c --- /dev/null +++ b/test/controllers/order_items_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrderItemsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..56f1603911 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,42 @@ +require "test_helper" + +describe OrdersController do + + # it "must be a real test" do + # flunk "Need real tests" + # end + describe "index" do + + it "shows order belonging to merchant" do + merchant = :mercury + login_test_user + + get merchant_orders_path(merchant) + must_respond_with :success + end + + it "only merchant can view orders" do + merchant = :mercury + + get merchant_orders_path(merchant) + must_redirect_to root_path + end + + end + + + describe "show" do + + it "returns success with valid id when logged in" do + login_test_user + + order_id = Order.first.id + + get order_path(order_id) + must_respond_with :success + 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..ffeccbc7e8 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,247 @@ +require "test_helper" +require 'pry' + +describe ProductsController do + # it "must be a real test" do + # flunk "Need real tests" + # end + let(:products) { Product.where( status: true) } + let(:poodr) { products(:poodr) } + + describe "authenticated user is logged in merchant" do + before do + login(Merchant.first) + end + end + + it "must be valid" do + product = Product.first + result = product.valid? + result.must_equal true + end + + describe "index" do + + it 'can display all products' do + get products_path + must_respond_with :success + end + end + + describe "create" do + + it "can create a product" do + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + get auth_callback_path(:github) + + product_hash = { + product: { + name: 'Practical Object Oriented Programming in Ruby', + price: 20, + description: 'A look at how to design object-oriented systems', + photo_url: 'test url', + status: true, + inventory: 1 + } + } + + expect { + post products_path, params: product_hash + }.must_change 'Product.count', 1 + + must_respond_with :redirect + + expect(Product.last.name).must_equal product_hash[:product][:name] + expect(Product.last.price).must_equal product_hash[:product][:price] + expect(Product.last.description).must_equal product_hash[:product][:description] + end + + + it "will not create a product with invalid params" do + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + get auth_callback_path(:github) + + product_hash = { + product: { + price: 20, + description: 'A look at how to design object-oriented systems', + photo_url: 'test url', + status: "test string not boolean", + inventory: 1 + } + } + + expect { + post products_path, params: product_hash + }.wont_change 'Product.count' + + must_respond_with :success + + end + end + + describe 'update' do + + it 'can update a product if logged in' do + + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + get auth_callback_path(:github) + + + @login_user = Merchant.first + product = Product.first + + product_hash = { + product: { + name: 'Practical Object Oriented Programming in Ruby', + price: 20, + description: 'A look at how to design object-oriented systems', + photo_url: 'test url', + status: true, + inventory: 1 + } + } + + patch product_path(product.id), params: product_hash + must_respond_with :found + + + end + + it 'will not update a product if not logged in' do + product = Product.first + product_hash = { + product: { + name: 'Practical Object Oriented Programming in Ruby', + price: 20, + description: 'A look at how to design object-oriented systems', + photo_url: 'test url', + status: true, + inventory: 1 + } + } + + patch product_path(product.id), params: product_hash + must_respond_with :bad_request + + + end + end + + describe 'show' do + + it 'can display a product details page' do + product = Product.first + + get product_path(product.id) + must_respond_with :success + end + + it 'returns not found if invalid id' do + + get product_path(0) + must_respond_with :not_found + end + + end + + describe 'update' do + + it 'a logged in user can update a product' do + + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + get auth_callback_path(:github) + + @login_user = Merchant.first + + product = Product.find_by(name: 'Poodr') + + put merchant_product_path(mercury.id, product.id), params { + product_hash = { + product: { + name: 'top poodr', + price: 20, + description: 'A look at how to design object-oriented systems', + photo_url: 'test url', + status: true, + inventory: 1 + } + } + } + + product_update = Product.find_by(name: 'top poodr') + + product_update.name.must_equal 'top poodr' + must_respond_with :redirect + must_redirect_to product_path(@product.id) + + end + + it 'it falls back to root path and sends bad request if not logged in' do + product = Product.first + product_hash = { + product: { + name: 'Practical Object Oriented Programming in Ruby', + price: 20, + description: 'A look at how to design object-oriented systems', + photo_url: 'test url', + status: true, + inventory: 1 + } + } + + patch product_path(product.id), params: product_hash + must_respond_with :bad_request + + end + end + + describe 'destroy' do + + it "a merchant can destroy their own product" do + product = Product.find_by(name: 'houseplant') + @login_user = Merchant.find(product.merchant.id) + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( @login_user ) ) + get auth_callback_path(:github) + + expect { + delete product_path(product.id) + }.must_change('Product.count', -1) + + must_respond_with :redirect + must_redirect_to merchant_path(@login_user.id) + + + end + end + + describe 'add_to_order' do + + it 'a product can be successfully added to the cart' do + product = Product.first + product_data = { + name: 'test', + product_id: product.id, + merchant_id: Merchant.first.id + } + + current_count = Product.count + + get add_to_order_path(product.id) + + must_respond_with :redirect + must_redirect_to product_path(product.id) + end + + + + it 'a product can have an average rating' do + + 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..48ea9ab49f --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,76 @@ +require "test_helper" + +describe SessionsController do + # it "must be a real test" do + # flunk "Need real tests" + # end + describe 'create' do + + it "can successfully log in with github as an existing merchant" do + # Arrange + # make sure that for some existing merchant, everything is configured! + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + + # Act + # Simulating logging in with github being successful (given the OmniAuth hash made above) + get auth_callback_path(:github) + + # Assert + must_redirect_to root_path + expect(session[:merchant_id]).must_equal mercury.id + expect(flash[:status]).must_equal "success" + + end + + it "creates a new user successfully when logging in with a new valid merchant" do + + start_count = Merchant.count + new_merchant = Merchant.new(username: "new user", email: "some email", uid: 3, provider: :github) + + # if new_merchant is not valid, then this test isn't testing the right thing + expect(new_merchant.valid?).must_equal true + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( new_merchant ) ) + get auth_callback_path(:github) + + must_redirect_to root_path + expect( Merchant.count ).must_equal start_count + 1 + expect( session[:merchant_id] ).must_equal Merchant.last.id + end + + it "does not create a new user when logging in with a new invalid merchant" do + start_count = Merchant.count + + invalid_new_merchant = Merchant.new(username: nil, email: nil) + + # if invalid_new_user is valid, then this test isn't testing the right thing + expect(invalid_new_merchant.valid?).must_equal false + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( invalid_new_merchant ) ) + + get auth_callback_path(:github) + + must_redirect_to root_path + expect( session[:merchant_id] ).must_equal nil + expect( Merchant.count ).must_equal start_count + end + end + + describe 'logout' do + + it "can logout a user" do + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + get auth_callback_path(:github) + + expect ( session[:merchant_id] ).must_equal merchants(:mercury).id + + delete logout_path + + must_respond_with :redirect + must_redirect_to root_path + end + end + +end diff --git a/test/controllers/welcome_controller_test.rb b/test/controllers/welcome_controller_test.rb new file mode 100644 index 0000000000..877b7e7456 --- /dev/null +++ b/test/controllers/welcome_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe WelcomeController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..e81a6947ca --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,37 @@ +# 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 +# +readables: + category_name: readables + products: poodr + +wearables: + category_name: wearables + products: onesie1, snuggie + +cozyables: + category_name: cozyables + products: snuggie + +snackables: + category_name: snackables + products: koolaid + +hairables: + category_name: hairables + products: wig1 + +plantables: + category_name: plantables + products: houseplant1 + +houseables: + category_name: houseables + products: lamp + +beautifiables: + category_name: beautifiables + products: nailpolish1 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml new file mode 100644 index 0000000000..3adb41b549 --- /dev/null +++ b/test/fixtures/merchants.yml @@ -0,0 +1,31 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +mercury: + username: mercury + email: m@1mercury.com + uid: 12345678 + provider: github + +jupiter: + username: jupiter + email: jup@jup.net + uid: 87654321 + provider: github + +neptune: + username: neptune + email: neptune123@nep.com + uid: 23456789 + provider: github + +saturn: + username: saturn + email: 123saturn@sat.org + uid: 98765432 + provider: github + +mars: + username: mars + email: marsmars@mars1.com + uid: 01234567 + provider: github diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..c254b4553b --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,31 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +orderitem1: + quantity: 1 + product: poodr + order: order1 + +orderitem2: + quantity: 2 + product: wig1 + order: order2 + +orderitem3: + quantity: 1 + product: nailpolish1 + order: order2 + +orderitem4: + quantity: 1 + product: koolaid + order: order3 + +orderitem5: + quantity: 1 + product: onesie1 + order: order3 + +orderitem6: + quantity: 1 + product: snuggie + order: order4 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..94975a9805 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,46 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +order1: + payment_status: pending + fulfillment_status: pending + guest_email: person@person.com + guest_mailing: 123 somewhere st. + guest_cc_name: Person A. Person + guest_cc_num: 1234567890123456 + guest_cc_exp_date: 01/2020 + guest_cc_cvv_code: 123 + guest_cc_zip: 07747 + +order2: + payment_status: paid + fulfillment_status: complete + guest_email: me@wnbc.net + guest_mailing: 321 somewhere sq. + guest_cc_name: Person Moo + guest_cc_num: 0987654321098765 + guest_cc_exp_date: 02/2021 + guest_cc_cvv_code: 321 + guest_cc_zip: 11238 + +order3: + payment_status: pending + fulfillment_status: pending + guest_email: herc@hercules.org + guest_mailing: 1 highline st. + guest_cc_name: Hercules Hercules + guest_cc_num: 1234567890123456 + guest_cc_exp_date: 11/2020 + guest_cc_cvv_code: 999 + guest_cc_zip: 98121 + + +order4: + payment_status: pending + fulfillment_status: pending + guest_email: person@person.com + guest_mailing: 123 somewhere st. + guest_cc_name: Person A. Person + guest_cc_num: 1234567890123456 + guest_cc_exp_date: 01/2020 + guest_cc_cvv_code: 123 + guest_cc_zip: 07747 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..1034c6e905 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,73 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +poodr: + name: Poodr + price: 2000 + description: ruby is practical and full of bicycles and flexible + photo_url: https://i.imgur.com/WnNdern.jpg + status: true + inventory: 1 + merchant: jupiter + +koolaid: + name: koolaid + price: 100 + description: a sugary drink that breaks through a wall + photo_url: https://images-na.ssl-images-amazon.com/images/I/91BG%2BhDfwuL._SY550_.jpg + status: true + inventory: 100 + merchant: mercury + +wig1: + name: wig + price: 4444 + description: not just for halloween + photo_url: https://images.halloweencostumes.com/products/22842/1-1/long-wavy-red-wig.jpg + status: true + inventory: 100 + merchant: saturn + +houseplant1: + name: houseplant + price: 1500 + description: Cyclamen + photo_url: https://www.educationquizzes.com/library/Gardening/Houseplants/Cyclamen-C.jpg + status: true + inventory: 0 + merchant: saturn + +lamp: + name: lamp + price: 6600 + description: let there be light + photo_url: https://images.homedepot-static.com/productImages/d5b0dbea-d25f-49c5-824d-7c894e5d14ab/svn/chrome-table-lamps-tl8082-64_400_compressed.jpg + status: true + inventory: 50 + merchant: mars + +nailpolish1: + name: nailpolish + price: 1000 + description: spirit fingers + photo_url: https://i.imgur.com/Yczg2oF.jpg + status: true + inventory: 2 + merchant: saturn + +onesie1: + name: onesie + price: 900 + description: not your grandma's jammies + photo_url: https://images-na.ssl-images-amazon.com/images/I/51tRFrfnuPL._UX342_.jpg + status: true + inventory: 5 + merchant: mars + +snuggie: + name: snuggie + price: 500 + description: hygge time + photo_url: http://4.bp.blogspot.com/_AGXlKNxtdl8/SwDf52G-CTI/AAAAAAAAA1E/hFHKLRpGwvs/s1600/snuggie.jpg + status: true + inventory: 44 + merchant: jupiter diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..d040b37025 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,26 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +review1: + star_rating: 1 + text: SO BAD. IT BROKE!!!!!! + product: lamp + +review2: + star_rating: 2 + text: It wiggles. Not stable. + product: lamp + +review3: + star_rating: 3 + text: Average in every way. + product: snuggie + +review4: + star_rating: 4 + text: Happy with this purchase, but you know -- it's not perfect... + product: nailpolish1 + +review5: + star_rating: 5 + text: SO HAPPY VERY WOW TWO THUMBS WAY UP THXXXXXX + product: poodr diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..ab616ce171 --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,55 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new } + let(:readables) { categories(:readables) } + +# describe 'relations' do +# it 'responds to products' do +# expect(readables).must_respond_to :products +# +# readables.products.each do |product| +# expect(product).must_be_kind_of Product +# end +# end +# +# it 'can have products' do +# expect(readables).must_include products(:poodr) +# end +# +# it 'can have zero products' do +# expect(readables).must_include products(:poodr) +# end +# end +# +# describe 'validations' do +# it "must be valid" do +# value(category).must_be :valid? +# end +# +# it 'requires a category name present' do +# expect(readables.valid?).must_equal true +# +# readables.category_name = nil +# +# expect(category.valid?).must_equal false +# expect(category.errors.messages).must_include :category_name +# end +# +# it 'requires a unique name' do +# cozyables = categories(:cozyables) +# wearables = categories(:wearables) +# cozyables.username = wearables.username +# +# expect(cozyables.valid?).must_equal false +# expect(cozyables.errors.messages).must_include :category_name +# +# cozyables.username = "cozyables" +# expect(cozyables.valid?).must_equal true +# end +# end + +describe 'model logic' do + # TODO: add tests for business logic below +end +end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..277384946d --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,69 @@ +require "test_helper" + +describe Merchant do + let(:merchant) { Merchant.new } + let(:mercury) { merchants(:mercury) } + + describe 'relations' do + it 'has a list of products' do + expect(mercury).must_respond_to :products + + mercury.products.each do |product| + expect(product).must_be_kind_of Product + end + end + end + + describe 'validations' do + it "must be valid" do + value(mercury).must_be :valid? + end + + it 'requires a username present' do + expect(mercury.valid?).must_equal true + + mercury.username = nil + + expect(mercury.valid?).must_equal false + expect(mercury.errors.messages).must_include :username + end + + it 'requires a unique username' do + mars = merchants(:mars) + saturn = merchants(:saturn) + saturn.username = mars.username + + expect(saturn.valid?).must_equal false + expect(saturn.errors.messages).must_include :username + + saturn.username = "saturn" + expect(saturn.valid?).must_equal true + end + + it 'requires an email address present' do + expect(mercury.valid?).must_equal true + + mercury.email = nil + + expect(mercury.valid?).must_equal false + expect(mercury.errors.messages).must_include :email + end + + it 'requires a unique email address' do + mars = merchants(:mars) + saturn = merchants(:saturn) + + saturn.email = mars.email + + expect(saturn.valid?).must_equal false + expect(saturn.errors.messages).must_include :email + + saturn.email = "unique@email.org" + expect(saturn.valid?).must_equal true + end + end + + describe 'model logic' do + # TODO: add tests for business logic below + end +end diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..4c3fa932dd --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,79 @@ +require "test_helper" + + +describe OrderItem do + let(:order_item) { OrderItem.new } + let(:orderitem1) { order_items(:orderitem1) } + + describe 'relations' do + it 'belongs to a product' do + expect(orderitem1).must_respond_to :product + expect(orderitem1.product).must_be_kind_of Product + # expect(orderitem1.product).must_equal products(:poodr) + end + + it 'belongs to an order' do + expect(orderitem1).must_respond_to :order + expect(orderitem1.order).must_be_kind_of Order + expect(orderitem1.order).must_equal orders(:order1) + end + end + + describe 'validations' do + it "must be valid" do + value(orderitem1).must_be :valid? + end + + it 'must have a quantity present' do + expect(orderitem1.valid?).must_equal true + p orderitem1.quantity + + orderitem1.quantity = nil + + expect(orderitem1.valid?).must_equal false + expect(orderitem1.errors.messages).must_include :quantity + end + + it 'must have a quantity greater than zero present' do + orderitem1.quantity = 0 + + expect(orderitem1.valid?).must_equal false + expect(orderitem1.errors.messages).must_include :quantity + + orderitem1.quantity = -1 + + expect(orderitem1.valid?).must_equal false + expect(orderitem1.errors.messages).must_include :quantity + end + + it 'must have an integer present' do + orderitem1.quantity = 1.5 + + expect(orderitem1.valid?).must_equal false + expect(orderitem1.errors.messages).must_include :quantity + + orderitem1.quantity = "number" + + expect(orderitem1.valid?).must_equal false + expect(orderitem1.errors.messages).must_include :quantity + end + + it 'must have a shipping status present' do + orderitem1.shipped = nil + + expect(orderitem1.valid?).must_equal false + expect(orderitem1.errors.messages).must_include :shipped + end + + # it 'must have a valid shipping status' do + # orderitem1.shipped = "string" + # + # expect(orderitem1.valid?).must_equal false + # expect(orderitem1.errors.messages).must_include :shipped + # end + end + + describe 'model logic' do + # TODO: add tests for business logic below + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..751ce1342a --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,61 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + let(:order1) { orders(:order1) } + let(:order2) { orders(:order2) } + + describe 'relations' do + it 'has many order items' do + expect(order1).must_respond_to :order_items + + order1.order_items.each do |order_item| + expect(order_item).must_be_kind_of OrderItem + end + + order1.order_items.each do |order_item| + expect(order_item).must_equal order_items(:orderitem1) + end + end + end + + # TODO: decide/add more validations+testing (cc info, mailing address, etc) + describe 'validations' do + it "must be valid" do + expect(order2).must_be :valid? + end + + it 'must have an email address' do + expect(order2.guest_email).must_equal 'me@wnbc.net' + # test passes as long as it matches what's in the fixtures. Is this a good test? + expect(order2).must_respond_to :guest_email + + end + + it 'has a name corresponding with the credit card' do + expect(order2.guest_cc_name).must_equal 'Person Moo' + end + + it 'has a credit card number with 16 digits' do + expect(order2.guest_cc_num).must_equal "0987654321098765" + + expect(order2.guest_cc_num.length).must_equal 16 + end + + it 'has a three-digit CVV number' do + expect(order2.guest_cc_cvv_code).must_equal "321" + + expect(order2.guest_cc_cvv_code.length).must_equal 3 + end + + it 'must have a 5 digit zip code' do + expect(order2.guest_cc_zip).must_equal "11238" + + expect(order2.guest_cc_zip.length).must_equal 5 + end + + # it 'rejects an invalid order' do + # invalid_order = Order.new + # end + end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..42461991dc --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,63 @@ +require "test_helper" +# has_many :reviews +# has_many :order_items +# belongs_to :merchant +# has_and_belongs_to_many :categories + +# validates :name, presence: true, uniqueness: true +# # TODO: maybe product name must be unique to category??? +# validates :price, presence: true, numericality: { greater_than: 0 } + +describe Product do + let(:product) { Product.new } + let(:product1) { products(:poodr) } + let(:product2) { products(:koolaid) } + + # before do + # @product = Product.new(name: 'test title', price: 20, description: 'test description', merchant: 'jupiter') + # end + + it "must be valid" do + expect(product.valid?).must_equal false + end + + it 'must have a name' do + expect(product1.valid?).must_equal true + product1.name = '' + expect(product1.valid?).must_equal false + end + + it 'has a unique name' do + product2.name = product1.name + expect(product2.valid?).must_equal false + end + + it 'has a valid price' do + test_product = products(:koolaid) + expect(test_product.price).must_equal 100 + expect(test_product.valid?).must_equal true + + ['', 'not a price', '1dollar'].each do |invalid| + test_product.price = invalid + end + expect(test_product.valid?).must_equal false + end + + it 'has a price greater than 0' do + product1.price = -2 + expect(product1.valid?).must_equal false + end + + it 'has valid stock' do + test_product = products(:koolaid) + ['', -1, 'cow'].each do |invalid| + test_product.inventory = invalid + end + expect(product2.valid?).must_equal false + end + + it 'can have 0 stock' do + product2.inventory = 0 + expect(product2.valid?).must_equal true + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..fbe2b1460b --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,10 @@ +require "test_helper" + +describe Review do + let(:review) { Review.new } + + it "must be valid" do + skip + value(review).must_be :valid? + 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..7ff86c148c --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,60 @@ +require 'simplecov' +SimpleCov.start + +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" +# for Colorized output +# For colorful output! +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + +# To add Capybara feature tests add `gem "minitest-rails-capybara"` +# to the test group in the Gemfile and uncomment the following: +# require "minitest/rails/capybara" + +# Uncomment for awesome colorful output +# require "minitest/pride" + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + # Add more helper methods to be used by all tests here... + + + 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(merchant) + return { + uid: merchant.uid, + provider: merchant.provider, + info: { + nickname: merchant.username, + email: merchant.email + } + } + end + + def login_test_user + mercury = merchants(:mercury) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_auth_hash( mercury ) ) + get auth_callback_path(:github) + end + + def logout_test_user + OmniAuth.config.mock_auth[:github] = nil + get logout_path + 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