diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..55262d309a --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# 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 + +#Ignore env file for Github Auth +.env + +#Ignore Mac finder related files +.DS_Store + +coverage diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..25c81fe399 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.5.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..7a1d852b64 --- /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' + +# 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 + +# OAuth +gem 'omniauth' +gem 'omniauth-github' + +# Gem to show multiple pages +gem 'will_paginate', '~> 3.1.0' + +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' + gem 'simplecov', require: false +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' +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..6238c581a6 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,315 @@ +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) + will_paginate (3.1.6) + 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) + will_paginate (~> 3.1.0) + +RUBY VERSION + ruby 2.5.1p57 + +BUNDLED WITH + 1.16.4 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000000..e34f706f4a --- /dev/null +++ b/Guardfile @@ -0,0 +1,9 @@ +guard :minitest, autorun: false, spring: true do + watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/.+_test.rb$}) + watch(%r{^test/test_helper.rb$}) { 'test' } +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/images/cat-sweater.jpg b/app/assets/images/cat-sweater.jpg new file mode 100644 index 0000000000..20930693d0 Binary files /dev/null and b/app/assets/images/cat-sweater.jpg differ diff --git a/app/assets/images/home/penguin-sweaters.jpg b/app/assets/images/home/penguin-sweaters.jpg new file mode 100644 index 0000000000..401de8b065 Binary files /dev/null and b/app/assets/images/home/penguin-sweaters.jpg differ diff --git a/app/assets/images/home/petstogether.jpeg b/app/assets/images/home/petstogether.jpeg new file mode 100644 index 0000000000..1f41b75a6b Binary files /dev/null and b/app/assets/images/home/petstogether.jpeg differ diff --git a/app/assets/images/home/tiger-eyes.jpg b/app/assets/images/home/tiger-eyes.jpg new file mode 100644 index 0000000000..82a62eda01 Binary files /dev/null and b/app/assets/images/home/tiger-eyes.jpg differ diff --git a/app/assets/images/home/white-puppy-running.jpg b/app/assets/images/home/white-puppy-running.jpg new file mode 100644 index 0000000000..dfa36576d5 Binary files /dev/null and b/app/assets/images/home/white-puppy-running.jpg differ diff --git a/app/assets/images/puppies-sweaters.jpg b/app/assets/images/puppies-sweaters.jpg new file mode 100644 index 0000000000..90c48fe26c Binary files /dev/null and b/app/assets/images/puppies-sweaters.jpg differ diff --git a/app/assets/images/puppy-wearing-socks-and-booties.jpg b/app/assets/images/puppy-wearing-socks-and-booties.jpg new file mode 100644 index 0000000000..ed288ca130 Binary files /dev/null and b/app/assets/images/puppy-wearing-socks-and-booties.jpg differ diff --git a/app/assets/images/westie-puppy-in-a-coat.jpg b/app/assets/images/westie-puppy-in-a-coat.jpg new file mode 100644 index 0000000000..482d6be6dc Binary files /dev/null and b/app/assets/images/westie-puppy-in-a-coat.jpg 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_items.js b/app/assets/javascripts/order_items.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order_items.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/products.js b/app/assets/javascripts/products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/sessions.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..e832d52b70 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,90 @@ +/* + * 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 { + background-color: #191970; + margin: 2em; +} + +header { + display: grid; + grid-template-rows: 3fr 1fr; + grid-template-columns: 1fr 4fr; + color: #191970; + margin-top : 15px; + padding: 10px; +} + +.header-text { + display: flex; + flex-direction: column; + text-align: center; + justify-content: center; + grid-column: 2; + grid-row: 1; +} + +.header-heading { + font-family: 'Rammetto One', cursive; +} + +.header-img { + background-image: image-url("home/petstogether.jpeg"); + background-repeat: no-repeat; + background-position: left top; + width: 400px; + height: 350px; +} + +nav { + grid-row: 2; + grid-column: 1 / 3; + // background-color: #191970; + border-top: solid #c6d9ec .1rem; + border-bottom: solid #c6d9ec .1rem; +} + +.user-nav-list, .shopping-nav-list { + display: flex; + flex-direction: row; +} + +header a:hover, header a:link, header a:visited, footer { + color: #191970; + text-decoration: none; + margin: 1em; +} + +header a:hover { + text-decoration: underline; +} + +.header-subheading { + margin-bottom: 2em; +} + +h1, h2, h3 { + color: #191970 +} + + +main, header { + background-color: white; + padding: 2em; +} diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..42976cbc11 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/merchants.scss b/app/assets/stylesheets/merchants.scss new file mode 100644 index 0000000000..1191d05306 --- /dev/null +++ b/app/assets/stylesheets/merchants.scss @@ -0,0 +1,12 @@ +// 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/ + +ul { + list-style: none; +} + +.merchant-details img { + border-radius: 50%; + height: 60px; +} diff --git a/app/assets/stylesheets/order_items.scss b/app/assets/stylesheets/order_items.scss new file mode 100644 index 0000000000..584862de9b --- /dev/null +++ b/app/assets/stylesheets/order_items.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderItems controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..741506954d --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..75ad1355f4 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,89 @@ +// 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/ + +.banner { + color: white; + padding: 5rem; + border: 3rem; + margin: 2rem; + background-attachment: fixed; + background-position: center; + background-repeat: no-repeat; + background-size: cover; +} + +a:link { + text-decoration: none; +} + +#puppy-banner { + background-image: image-url("home/white-puppy-running.jpg"); +} + +#tiger-banner { + background-image: image-url("home/tiger-eyes.jpg"); +} + +#sweater-banner { + background-image: image-url("home/penguin-sweaters.jpg"); +} + +.overlay { + padding: 10rem; + position: relative; + bottom: 0; + background: rgb(0, 0, 0); + background: rgba(0, 0, 0, 0.5); /* Black see-through */ + color: #f1f1f1; + width: 100%; + height: 200%; + transition: .5s ease; + opacity:0; + color: white; + font-size: 20px; + padding: 20px; + text-align: center; +} + +.banner:hover .overlay { + opacity: 1; +} + +.text { + color: white; + font-size: 2rem; + position: relative; + text-align: center; +} + +.product-gallery { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: space-between; +} + +.card { + margin: .5em; + width: 15rem; +} + +.pagination { + .previous_page { background:#191970; color:white; } + .previous_page.disabled { background: white; color: #777; } + .current { border: .15em solid;} + .next_page { background: #191970; color: white; } + .next_page.disabled { background: white; color: #777; } +} + +a, em, span { + color: #191970; + padding: .25em; + margin-left: 1em; + margin-right: 1em; +} + +.product-gallery img { + height: 250px; +} diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..11bbb12cd5 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..ccb1ed25b2 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/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..eb476adf61 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,9 @@ +class ApplicationController < ActionController::Base + # protect_from_forgery with: :exception + protect_from_forgery with: :exception + + + def render_404 + raise ActionController::RoutingError.new('Not Found') + end +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..e448b763fc --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,29 @@ +class CategoriesController < ApplicationController + + def new + @category = Category.new + end + + def create + @category = Category.new(category_params) + + if @category.save + flash[:status] = :success + flash[:result_text] = "Category #{@category.name} successfully created." + redirect_to dashboard_path(session[:user_id]) + else + flash.now[:status] = :failure + flash.now[:result_text] = "Invalid category name. Please try again." + render :new, status: :bad_request + end + end + + private + + def category_params + return params.require(:category).permit( + :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..90028e071b --- /dev/null +++ b/app/controllers/merchants_controller.rb @@ -0,0 +1,31 @@ +class MerchantsController < ApplicationController + + before_action :find_merchant, only: [:show, :dashboard] + + def index + @merchants = Merchant.all + end + + def show + end + + def dashboard + end + +private + + def merchant_params + return params.require(:merchant).permit( + :username, + :email, + :uid, + :provider + ) + end + + def find_merchant + @merchant = Merchant.find_by(id: params[:id]) + render_404 unless @merchant + end + +end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb new file mode 100644 index 0000000000..fe5eae80a4 --- /dev/null +++ b/app/controllers/order_items_controller.rb @@ -0,0 +1,147 @@ +require 'pry' +class OrderItemsController < ApplicationController + + before_action :find_order_item, only: [:show, :edit, :update, :destroy, :status] + + def index + @order_items = OrderItem.where(status: 'pending', order_id: session[:order_id]) + end + + # order item is created when added to cart + def create + @order_item = OrderItem.new(order_item_params) + + unless session[:order_id] + order = Order.create(status: 'pending') + session[:order_id] = order.id + end + + order = Order.find_by(id: session[:order_id]) + + if order + # Search for existing OrderItem in cart to update + duplicate_item = OrderItem.find_by(product_id: @order_item.product_id, order: order, status: 'pending') + + if duplicate_item + + quantity = @order_item.quantity + duplicate_item.quantity + + if quantity < duplicate_item.product.stock + + duplicate_item.update(quantity: quantity) + @order_item.reduce_stock(duplicate_item) + # end + # remaining_stock = duplicate_item.product.stock - order_item_params[:quantity].to_i + # + # if duplicate_item.product.update(stock: remaining_stock) + # + # quantity = duplicate_item.quantity + @order_item.quantity + # duplicate_item.update(quantity: quantity) + + flash[:status] = :success + flash[:result_text] = "Cart successfully updated - added #{@order_item.quantity} of #{@order_item.product.name}." + # end + else + + flash[:status] = :failure + flash[:result_text] = "Quantity requested exceeds stock. Please try again." + end + # end + else + + @order_item.order_id = session[:order_id] + # order item is created when added to cart + if @order_item.save + + @order_item.reduce_stock + # product = @order_item.product + # remaining_stock = product.stock - @order_item.quantity + # + # if product.update(stock: remaining_stock) + + flash[:status] = :success + flash[:result_text] = "Item successfully added to cart. " + # else + # flash[:status] = :failure + # flash[:result_text] = "Quantity requested exceeds stock. Please try again." + # end + + else + + flash[:status] = :failure + flash[:result_text] = "Error adding item to cart" + end + end + # + # else + # flash[:status] = :failure + # flash[:result_text] = "Order for cart is invalid. Please restart browser and try again." + # session[:order_id] = nil + end + + redirect_back fallback_location: products_path + end + + def show; + end + + def edit; + end + + def update + old_quantity = @order_item.quantity + new_quantity = order_item_params[:quantity].to_i + + + diff_quantity = new_quantity - old_quantity + curr_stock = @order_item.product.stock + new_stock = curr_stock - diff_quantity + + if @order_item.product.update(stock: new_stock) + + if @order_item.update(order_item_params) + + flash[:status] = :success + flash[:result_text] = "Update was successful." + + else + flash[:status] = :failure + flash[:result_text] = "Update was not successful. Invalid input." + end + else + flash[:status] = :failure + flash[:result_text] = "Quantity requested exceeds stock. Please try again." + end + + redirect_back fallback_location: order_items_path + end + + def destroy + @order_item.destroy + @order_item.restock_product + flash[:status] = :success + flash[:result_text] = "#{@order_item.product.name} successfully removed from cart." + redirect_to order_items_path + end + + def status + if @order_item.update(status: 'complete') + flash[:status] = :success + flash[:result_text] = "Order item number #{@order_item.id} has been completed." + else + flash[:status] = :failure + flash[:result_text] = "There was a problem. Order #{@order_item.id} has not been updated." + end + redirect_to dashboard_path(session[:user_id]) + end + + private + def order_item_params + params.require(:order_item).permit(:quantity, :status, :product_id, :order_id) + end + + def find_order_item + @order_item = OrderItem.find_by(id: params[:id]) + render_404 unless @order_item + end +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..4fba6f7a20 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,71 @@ +class OrdersController < ApplicationController + + before_action :find_order, except: [:index, :create] + + def index + @orders = Order.all + end + + # is this necessary? + def create + @order = Order.new(order_params) + if @order.save + redirect_to order_path(@order.id) + else + render :edit, status: :bad_request + end + end + + def show + end + + def edit + end + + def update + + @order.update(order_params) + @order.set_paid + + if @order.save + session[:order_id] = nil + + flash[:status] = :success + flash[:result_text] = "Order successfully finalized. Please save your order number - ##{@order.id}." + redirect_to order_path(@order.id) + else + flash.now[:status] = :failure + flash.now[:result_text] = "Order information is invalid. Please try again." + render :edit, status: :bad_request + end + end + + def destroy + @order.destroy + flash[:status] = :success + flash[:result_text] = "Your order has been cancelled." + redirect_to root_path + end + + def customerinfo + end + + private + + def order_params + params.require(:order).permit( + :status, + :name, + :email, + :address, + :cc_num, + :cc_cvv, + :cc_expiration + ) + end + + def find_order + @order = Order.find_by(id: params[:id]) + render_404 unless @order + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..421cb858e1 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,87 @@ +class ProductsController < ApplicationController + + before_action :find_product, only: [:show, :edit, :update, :destroy] + + def index + @products = Product.where(active: true).paginate(page: params[:page], per_page: 16) + end + + def show + @reviews = @product.reviews + @order_item = OrderItem.new(quantity: 1, status: 'pending') + end + + def new + @product = Product.new + end + + def create + if session[:user_id] + @product = Product.new(product_params) + @product.merchant_id = session[:user_id] + + if @product.save + flash[:status] = :success + flash[:result_text] = "Product successfully created." + redirect_to products_path + else + flash.now[:status] = :failure + flash.now[:result_text] = "Product info invalid. Please try again." + render :new, status: :bad_request + end + else + flash.now[:status] = :failure + flash.now[:result_text] = "Only logged in merchants can create products" + render :new, status: :bad_request + end + end + + def edit + end + + def update + if session[:user_id] && (session[:user_id] == @product.merchant_id) + if @product.update(product_params) + flash[:status] = :success + flash[:result_text] = "Product successfully edited." + redirect_to product_path(@product) + else + flash.now[:status] = :failure + flash.now[:result_text] = "Product info invalid. Please try again." + render :edit + end + else + flash.now[:status] = :failure + flash.now[:result_text] = "Only a logged in merchant may update their product." + render :edit + end + end + + def destroy + @product.destroy + flash[:status] = :success + flash[:result_text] = "Product successfully deleted." + redirect_to products_path + end + +private + + def product_params + params.require(:product).permit( + :name, + :price, + :description, + :photo, + :stock, + :active, + :rating, + :merchant_id, + category_ids: []) + end + + def find_product + @product = Product.find_by(id: params[:id]) + render_404 unless @product + end + +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..a83e94642c --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,38 @@ +class ReviewsController < ApplicationController + + before_action :find_product + + def new + @review = Review.new + end + + def create + @review = Review.new(review_params) + + if @review.save + flash[:status] = :success + flash[:result_text] = "Review successfully saved." + redirect_to product_path(@product.id) + else + flash.now[:status] = :failure + flash.now[:result_text] = "Invalid review. Please try again." + render :new + end + end + + private + + def review_params + params.require(:review) + .permit( + :name, + :rating, + :description, + :product_id + ) + end + + def find_product + @product = Product.find_by(id: params[:product_id]) + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..fffcaea037 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,34 @@ +class SessionsController < ApplicationController + def create + auth_hash = request.env['omniauth.auth'] + + merchant = Merchant.find_by(uid: auth_hash[:uid], provider: auth_hash[:provider]) + + if merchant + flash[:status] = :success + flash[:result_text] = "Welcome #{merchant.username}" + else + merchant = Merchant.create_from_github(auth_hash) + + if merchant.save + flash[:status] = :success + flash[:result_text] = "Logged in as merchant #{merchant.username}" + else + flash[:status] = :failure + flash[:result_text] = "Could not create new account: #{merchant.errors.messages}" + redirect_to root_path + return + end + end + + session[:user_id] = merchant.id + redirect_to root_path + end + + def destroy + session[:user_id] = nil + flash[:status] = :success + flash[:result_text] = "Successfully logged out" + redirect_to root_path + end +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..ce780a3e07 --- /dev/null +++ b/app/helpers/merchants_helper.rb @@ -0,0 +1,5 @@ +module MerchantsHelper + def render_date(date) + date.strftime("%b %e, %Y") + end +end diff --git a/app/helpers/order_items_helper.rb b/app/helpers/order_items_helper.rb new file mode 100644 index 0000000000..e197528ae1 --- /dev/null +++ b/app/helpers/order_items_helper.rb @@ -0,0 +1,2 @@ +module OrderItemsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000..a009ace51c --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..286b2239d1 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..10a4cba84d --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..c150d34a77 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,5 @@ +class Category < ApplicationRecord + has_and_belongs_to_many :products + + validates :name, uniqueness: true, presence: 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..37c039e5e2 --- /dev/null +++ b/app/models/merchant.rb @@ -0,0 +1,50 @@ +class Merchant < ApplicationRecord + has_many :products + has_many :order_items, through: :products + + validates :username, uniqueness: true, presence: true + validates :email, uniqueness: true, presence: true + + def self.create_from_github(auth_hash) + merchant = Merchant.new + merchant.username = auth_hash['info']['nickname'] + merchant.email = auth_hash['info']['email'] + merchant.uid = auth_hash['uid'] + merchant.provider = 'github' + + return merchant + end + + def all_order_items_subtotal + return self.order_items.sum { |item| item.price } + end + + def paid_order_items + return self.order_items.where(status: 'paid') + end + + def paid_orders_subtotal + return self.paid_order_items.sum { |item| item.price } + end + + def complete_order_items + return self.order_items.where(status: 'complete') + end + + def completed_orders_subtotal + return self.complete_order_items.sum { |item| item.price } + end + + def rating + + + products_with_reviews = self.products.find_all{ |product| product.rating } + + if products_with_reviews.empty? + return nil + else + return 1.0 * products_with_reviews.sum{ |product| product.rating } / products_with_reviews.length + end + + end +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..b862c720e2 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,53 @@ +class Order < ApplicationRecord + STATUS = %w(pending paid complete cancelled) + has_many :order_items, dependent: :destroy + + validates :status, presence: true, + inclusion: { in: STATUS } + + validates :name, presence: true, if: :is_not_pending + validates :email, presence: true, if: :is_not_pending + validates :address, presence: true, if: :is_not_pending + validates :cc_num, presence: true, if: :is_not_pending + validates :cc_cvv, presence: true, if: :is_not_pending + validates :cc_expiration, presence: true, if: :is_not_pending + + def is_not_pending + return self.status != 'pending' + end + + def total + return self.order_items.sum { |item| item.price} + end + + def CC_num_last_four + + if self.cc_num + cc_str = self.cc_num.to_s + + if cc_str.length < 4 + return cc_str + else + return cc_str.to_s[-4..-1] + end + end + end + + def total_quantity + return self.order_items.sum {|item| item.quantity } + end + + def set_paid + self.update(status: 'paid') + + self.order_items.each do |item| + item.update(status: 'paid') + end + end + + + def self.search(search) + where("id = ?", "#{search}") + end + +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..9681174637 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,27 @@ +class OrderItem < ApplicationRecord + STATUS = %w(pending paid complete cancelled) + belongs_to :product + belongs_to :order + + validates :quantity, presence: true, numericality: { greater_than: 0 } + + validates :status, presence: true, + inclusion: { in: STATUS } + + def price + return self.product.price * self.quantity + end + + def restock_product + product = Product.find_by(id: self.product) + new_stock = product.stock + self.quantity + product.update(stock: new_stock) + return new_stock + end + + def reduce_stock(duplicate = self) + remaining_stock = duplicate.product.stock - self.quantity + return duplicate.product.update(stock: remaining_stock) + end + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..594dad3530 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,20 @@ +class Product < ApplicationRecord + belongs_to :merchant + + has_many :reviews + has_many :order_items + + has_and_belongs_to_many :categories + + validates :name, presence: true + validates :price, presence: true, numericality: { greater_than: 0 } + validates :stock, presence: true, numericality: { greater_than_or_equal_to: 0 } + + + def rating + unless self.reviews.empty? + return 1.0 * self.reviews.sum{ |review| review.rating } / self.reviews.length + end + return "No ratings" + end +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..e3bf0ce39c --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,7 @@ +class Review < ApplicationRecord + RATINGS = [*1..5] + belongs_to :product + + validates :name, presence: true + validates :rating, presence: true, inclusion: { in: RATINGS } +end diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..d3c18151e1 --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,8 @@ +<%= form_with model: @category do |f| %> + + <%= f.label :name %> + <%= f.text_field :name , class: 'form-control'%> + + <%= f.submit class: "btn btn-primary" %> + +<% end %> diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb new file mode 100644 index 0000000000..4f9c141b70 --- /dev/null +++ b/app/views/layouts/_form_errors.html.erb @@ -0,0 +1,15 @@ +<% if model.errors.messages.any? %> +
+

There were some problems. Please fix them.

+ +
+<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..05254ff104 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,89 @@ + + + + Petsy + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + + + + +
+
+ +
+ +
+

PETSY

+

Purring, Leaping, Wagging, and Swimming into Hearts Around the Globe

+
+ + +
+ + <% 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/_complete_orders.html.erb b/app/views/merchants/_complete_orders.html.erb new file mode 100644 index 0000000000..4f6bc3db9b --- /dev/null +++ b/app/views/merchants/_complete_orders.html.erb @@ -0,0 +1,29 @@ +
+

Complete Order Items    Count: <%= "#{@merchant.complete_order_items.length}" %>     Total Revenue for Completed Order Items: $<%= "#{@merchant.completed_orders_subtotal}" %>

+ + + + + + + + + + + + + + <% @merchant.complete_order_items.each do |item| %> + + + + + + + + + + <% end %> + +
Order IDProduct IDDescriptionQuantitySubtotalOrdered OnStatus
<%= link_to item.order.id, customer_info_path(item.order.id) %><%= link_to item.product_id, product_path(item.product_id) %><%= item.product.description %><%= item.quantity %><%= item.price %><%= render_date(item.created_at) %><%= item.status %>
+
diff --git a/app/views/merchants/_header.html.erb b/app/views/merchants/_header.html.erb new file mode 100644 index 0000000000..fec0afa64a --- /dev/null +++ b/app/views/merchants/_header.html.erb @@ -0,0 +1,4 @@ +
+

<%=@merchant.username%>

+

<%=@merchant.created_at.strftime("Joined Petsy in %B %Y")%>

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

All Order Items    Count: <%= "#{@merchant.order_items.size}" %>     Total Revenue for All Order Items: $<%= "#{@merchant.all_order_items_subtotal}" %>

+ + + + + + + + + + + + + + <% @merchant.order_items.each do |item| %> + + + + + + + + + + <% end %> + +
Order IDProduct IDDescriptionQuantitySubtotalOrdered OnStatus
<%= link_to item.order.id, customer_info_path(item.order.id) %><%= link_to item.product_id, product_path(item.product_id) %><%= item.product.description %><%= item.quantity %><%= item.price %><%= render_date(item.created_at) %><%= item.status %>
+
diff --git a/app/views/merchants/_paid_orders.html.erb b/app/views/merchants/_paid_orders.html.erb new file mode 100644 index 0000000000..d8b696e180 --- /dev/null +++ b/app/views/merchants/_paid_orders.html.erb @@ -0,0 +1,31 @@ +
+

Paid Order Items   Count: <%= "#{@merchant.paid_order_items.length}" %>    Total Revenue for Paid Order Items: $<%= "#{@merchant.paid_orders_subtotal}" %>

+ + + + + + + + + + + + + + + <% @merchant.paid_order_items.each do |item| %> + + + + + + + + + + + <% end %> + +
Order IDProduct IDDescriptionQuantitySubtotalOrdered OnStatus
<%= link_to item.order.id, customer_info_path(item.order.id) %><%= link_to item.product_id, product_path(item.product_id) %><%= item.product.description %><%= item.quantity %><%= item.price %><%= render_date(item.created_at) %><%= item.status %><%= link_to "Fulfill order", order_items_status_path(item.id), method: :post, class: 'btn btn-primary' %>
+
diff --git a/app/views/merchants/_products.html.erb b/app/views/merchants/_products.html.erb new file mode 100644 index 0000000000..2eb582331b --- /dev/null +++ b/app/views/merchants/_products.html.erb @@ -0,0 +1,33 @@ +
+

Products + + <%= link_to "Add New Product", new_product_path %> + <%= link_to "Add New Category", new_category_path %> + +

+ + + + + + + + + + + + + <% @merchant.products.each do |product| %> + + + + + + + + + + <% end %> + +
NameDescriptionPriceStockRating
<%= link_to product.name, product_path(product.id)%><%= product.description%>$ <%= product.price%><%= product.stock%><%= product.rating%><%= link_to "Edit", edit_product_path(product.id), class: 'btn btn-primary'%>
+
diff --git a/app/views/merchants/dashboard.html.erb b/app/views/merchants/dashboard.html.erb new file mode 100644 index 0000000000..756746655b --- /dev/null +++ b/app/views/merchants/dashboard.html.erb @@ -0,0 +1,39 @@ +<%= render partial: "header" %> +<% if @merchant.id == session[:user_id] %> + + + +
+
+ <%= render partial: "products" %> +
+
+ <%= render partial: "orders" %> +
+
+ <%= render partial: "paid_orders" %> +
+
+ <%= render partial: "complete_orders" %> +
+
+<% else %> +

+ You may only view your own dashboard. +

+<% end %> diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb new file mode 100644 index 0000000000..19e0263a84 --- /dev/null +++ b/app/views/merchants/index.html.erb @@ -0,0 +1,10 @@ +
+

All Merchants

+ + <% @merchants.each do |merchant| %> + + <% end %> +
diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb new file mode 100644 index 0000000000..220e197eb2 --- /dev/null +++ b/app/views/merchants/show.html.erb @@ -0,0 +1,31 @@ +
+

<%=@merchant.username%>

+

<%=@merchant.created_at.strftime("Joined Petsy in %B %Y")%>

+
+

Products

+ + + + + + + + + + + + + <% @merchant.products.each do |product| %> + + + + + + + + + <% end %> + +
NameDescriptionPriceStockRating
Image of <%=product.name%><%= link_to product.name, product_path(product.id) %><%= product.description %><%= product.price %><%= product.stock %><%= product.rating %>
+
+
diff --git a/app/views/order_items/index.html.erb b/app/views/order_items/index.html.erb new file mode 100644 index 0000000000..ca718c822e --- /dev/null +++ b/app/views/order_items/index.html.erb @@ -0,0 +1,34 @@ +

Cart

+ +<% if @order_items.empty? %> + +

Cart is currently empty.

+ +<% else %> + + + +<%= link_to 'Finalize Order', edit_order_path(session[:order_id]), class: "btn btn-primary" %> +<% end %> diff --git a/app/views/order_items/new.html.erb b/app/views/order_items/new.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/orders/_order_form.html.erb b/app/views/orders/_order_form.html.erb new file mode 100644 index 0000000000..fbb35fc6d9 --- /dev/null +++ b/app/views/orders/_order_form.html.erb @@ -0,0 +1,31 @@ +<%= render partial: 'layouts/form_errors', +locals: { + model: @order +} +%> + +<%= form_with model: @order, class: 'order-form' do |f| %> + +

<%= form_title %>

+ + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> + + <%= f.label :email %> + <%= f.text_field :email, class: "form-control" %> + + <%= f.label :address %> + <%= f.text_field :address, class: "form-control" %> + + <%= f.label :cc_num %> + <%= f.text_field :cc_num, class: "form-control" %> + + <%= f.label :cc_cvv %> + <%= f.text_field :cc_cvv, class: "form-control" %> + + <%= f.label :cc_expiration, 'Expiration date' %> + <%= f.date_select :cc_expiration, :discard_day => true, :start_year => Date.today.year, :end_year => (Date.today.year+10), :use_month_numbers => true, :order => [:month, :year], class: "form-control" %> + + <%= f.submit 'Finalize Order', class: "order-form-submit-button btn btn-primary" %> + +<% end %> diff --git a/app/views/orders/customerinfo.html.erb b/app/views/orders/customerinfo.html.erb new file mode 100644 index 0000000000..5b913f5f66 --- /dev/null +++ b/app/views/orders/customerinfo.html.erb @@ -0,0 +1,47 @@ +

Customer Order Detail

+ +
+ +
+ + +
+

Order Items

+ + + + + + + + + + + + <% @order.order_items.each do |item| %> + <% if session[:user_id] == item.product.merchant_id %> + + + + + + + <% end %> + <% end %> + + + + + +
Name Quantity Status Price
<%= item.product.name %> <%= item.quantity %> <%= item.status %> <%= item.price %>
Total <%= @order.total %>
+
diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000000..159af9a8c7 --- /dev/null +++ b/app/views/orders/edit.html.erb @@ -0,0 +1,6 @@ +<%= render partial: "order_form", + locals: { + form_title: "Customer Payment Information", + action_type: "Submit Order" + } +%> diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000000..af3be9e6c9 --- /dev/null +++ b/app/views/orders/index.html.erb @@ -0,0 +1,15 @@ + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..bbadf117d6 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,47 @@ +

Order Confirmation

+ +
+ +
+ + +
+

Order Items

+ + + + + + + + + + + + <% @order.order_items.each do |item| %> + + + + + + <% end %> + + + + + +
Name Quantity Status Price
<%= item.product.name %> <%= item.quantity %> <%= item.status %> <%= item.price %> +
Total <%= @order.total %>
+
+ +<%= link_to "Cancel Order", order_path(@order), class: "btn btn-danger", method: :delete %> diff --git a/app/views/products/_product_form.html.erb b/app/views/products/_product_form.html.erb new file mode 100644 index 0000000000..a7d338dc70 --- /dev/null +++ b/app/views/products/_product_form.html.erb @@ -0,0 +1,26 @@ +
+ <%= 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' %> + + <%= f.label :photo %> + <%= f.text_field :photo, class: 'form-control' %> + + <%= f.label :stock %> + <%= f.text_field :stock, class: 'form-control' %> + + <%= f.label :active %> + <%= f.check_box :active %> + + <%= f.label :description %> + <%= f.text_area :description, class: 'form-control' %> + + <%= f.label :category %> + <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> + + <%= f.submit class: "btn btn-primary form-control" %> + <% end %> +
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..4b80c9787f --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,3 @@ +

Edit Product

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

All Products

+ + + +<%= will_paginate @products %> +
diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..81ac5f1d3b --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,4 @@ +

New Product

+ + +<%= render partial: "product_form" %> diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb new file mode 100644 index 0000000000..28dda638ea --- /dev/null +++ b/app/views/products/root.html.erb @@ -0,0 +1,27 @@ +<%= link_to products_path do %> + +<% end %> +<%= link_to products_path do %> + +<% end %> +<%= link_to products_path do %> + +<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..256f1ff2a8 --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,74 @@ +

Product Detail

+ + + +<% if @product.merchant.id == session[:user_id] %> +
+ <%= link_to "Edit", edit_product_path(@product), class: "btn btn-primary" %> +
+<% end %> + +
+ + <%= form_with model: @order_item, class: 'add-cart-form' do |f| %> + + <%= f.label :quantity %> + <%= f.text_field :quantity %> + + <%= f.hidden_field :status, value: 'pending' %> + + <%= f.hidden_field :product_id, value: @product.id %> + + <% if @product.stock == 0 %> + <%= f.submit "Add to cart", class: 'pending' "add-cart-form-submit-button btn btn-primary", disabled: true %> + + <% else %> + <%= f.submit "Add to cart", class: 'pending' "add-cart-form-submit-button btn btn-primary" %> + <% end %> + + <% end %> +
+ +
+ <% if @reviews.empty? %> +

No Reviews Available.

+ <% else %> + + <% end %> + + +<%= link_to "Add Review", new_product_review_path(@product.id), class: "btn btn-primary" %> + +
diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb new file mode 100644 index 0000000000..3ab914c805 --- /dev/null +++ b/app/views/reviews/index.html.erb @@ -0,0 +1,63 @@ +

Product Detail

+ + + +
+ <%= link_to "Edit", edit_product_path(@product), class: "btn btn-primary" %> +
+ +
+ + <%= form_with model: @order_item, class: 'add-cart-form' do |f| %> + + <%= f.label :quantity %> + <%= f.text_field :quantity %> + + <%= f.hidden_field :status, value: 'pending' %> + + <%= f.hidden_field :product_id, value: @product.id %> + + <% if @product.stock == 0 %> + <%= f.submit "Add to cart", class: 'pending' "add-cart-form-submit-button btn btn-primary", disabled: true %> + + <% else %> + <%= f.submit "Add to cart", class: 'pending' "add-cart-form-submit-button btn btn-primary" %> + <% end %> + + <% end %> +
+ +
+ <% if @reviews.empty? %> +

No Reviews Available.

+ <% else %> + + <% end %> + + +<%= link_to "Add Review", new_product_review_path, class: "btn btn-primary" %> + +
diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..92aaec50aa --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,17 @@ +
+ <%= form_with model: [@product, @review] do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :rating %> + <%= f.select :rating, Review::RATINGS %> + + <%= f.label :description %> + <%= f.text_area :description %> + + <%= f.hidden_field :product_id, value: @product.id %> + + <%= f.submit class: "btn btn-primary" %> + + <% end %> +
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..6b169e821b --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +/MzRPeazUWZZIFKyxQGagt5ecLbxDZpO19R7uanF8E5sHrUE/6ypZKnH/ZDleWcewYZ65pIg/cc8ADMys5Drt8Ea59PDo9r9QLOzj4L4nwByhMVHyyLcezx6SGJ+CdDbq2JB0bt+kUa1De/niqg5dF4hOVqRubMCLPGuif1Z13/qSNZC9hC8lAtHifUNB1ugQY0v0HkH9O79NFVrfAh8mv05J4xa6sQlNjjCiREpTlAX6QPVF7QGZpRvPqjtDOoIujPgeuZ1aXTEpzEHOWNo9PZiZbVKGLY0aoYNN8G6kWii7kRzGOpu/RhcYCsm+XbEoarvvZVUguTtTiPg8FfOurTNODxiJ+qWPhrMiVANED9irE4c2wOZQkkT7OUWFaEF7dRItChlF5BGCTYDigN7GJIyeTMwTEL/0lvr--eZLILJm0c6kkzYLF--8Rc6/Fzq3tv12+01/IGNlw== \ 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..dcf129464e --- /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 = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "betsy_#{Rails.env}" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000000..0a38fd3ce9 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,46 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb new file mode 100644 index 0000000000..142d382f87 --- /dev/null +++ b/config/initializers/action_view.rb @@ -0,0 +1 @@ +Rails.application.config.action_view.form_with_generates_remote_forms = false diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000000..89d2efab2b --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..4b828e80cb --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000..59385cdf37 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000000..d3bcaa5ec8 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000000..5a6a32d371 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..4a994e1e7b --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000000..ac033bf9dc --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000000..dc1899682b --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..fd4416122a --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000..bbfc3961bf --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000000..decc5a8573 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000000..a5eccf816b --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000000..9ebe3f90f9 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,26 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root 'products#root' + + resources :merchants, except: [:new, :create] + resources :products do + resources :reviews, only: [:new, :create] + end + + resources :order_items, except: [:new] + resources :orders, except: [:new] + + resources :sessions, only: [:new, :create] + + resources :categories, only: [:new, :create] + + get '/auth/:provider/callback', to: "sessions#create", as: 'auth_callback' + delete '/logout', to: 'sessions#destroy', as: 'logout' + + get '/merchants/:id/dashboard', to: 'merchants#dashboard', as: 'dashboard' + + post '/order_items/:id/status', to: 'order_items#status', as: 'order_items_status' + + get '/orders/:id/customerinfo', to: 'orders#customerinfo', as: 'customer_info' + +end diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 0000000000..9fa7863f99 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000000..d32f76e8fb --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/category_seeds.csv b/db/category_seeds.csv new file mode 100644 index 0000000000..a41458ed36 --- /dev/null +++ b/db/category_seeds.csv @@ -0,0 +1,13 @@ +name +Sussex Spaniel +Keeshond +Bull Mastiff +English Hound +Coonhound +Clumber +English Setter +Chesapeake Retriever +Curly Retriever +Stbernard +Kuvasz +Pomeranian diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb new file mode 100644 index 0000000000..9329ed2dbb --- /dev/null +++ b/db/generate_seeds.rb @@ -0,0 +1,74 @@ +require 'faker' +require 'date' +require 'csv' + +# Merchant seed script +CSV.open('db/merchant_seeds.csv', "w", :write_headers=> true, + :headers => ["username", "email", "uid", "provider"]) do |csv| + + 5.times do + username = Faker::HarryPotter.character + email = Faker::Internet.email + uid = Faker::Number.number(3) + provider = "github" + + csv << [username, email, uid, provider] + end +end + +# Product seed script +CSV.open('db/product_seeds.csv', "w", :write_headers=> true, + :headers => ["name", "price", "photo", "stock", "active", "description"]) do |csv| + + 50.times do + name = Faker::Cat.name + price = Faker::Commerce.price + photo = 'http://placekitten.com/200/300' + stock = Faker::Number.number(2) + active = Faker::Boolean.boolean(0.8) + description = Faker::Lorem.sentence + + csv << [name, price, photo, stock, active, description] + end +end + +# Order item seed script +CSV.open('db/order_item_seeds.csv', "w", :write_headers=> true, + :headers => ["quantity", "status"]) do |csv| + + 50.times do + quantity = Faker::Number.number(2) + status = %w(pending paid complete cancelled).sample + + csv << [quantity, status] + end +end + +# Order seed screipt +CSV.open('db/order_seeds.csv', "w", :write_headers=> true, + :headers => ["status", "name", "email", "address", "cc_num", "cc_cvv", "cc_expiration"]) do |csv| + + 20.times do + status = %w(paid complete cancelled).sample + name = Faker::RickAndMorty.character + email = Faker::Internet.email + address = Faker::Address.full_address + cc_num = Faker::Number.number(16) + cc_cvv = Faker::Number.number(3) + cc_expiration = Faker::Date.backward(21) + + + csv << [status, name, email, address, cc_num, cc_cvv, cc_expiration] + end +end + +# Category seed script +CSV.open('db/category_seeds.csv', "w", :write_headers=> true, + :headers => ["name"]) do |csv| + + 12.times do + name = Faker::Dog.breed + + csv << [name] + end +end diff --git a/db/merchant_seeds.csv b/db/merchant_seeds.csv new file mode 100644 index 0000000000..49e4c63695 --- /dev/null +++ b/db/merchant_seeds.csv @@ -0,0 +1,6 @@ +username,email,uid,provider +Magorian,glenn@dare.name,820,github +Tom Marvolo Riddle,macknader@steuber.net,364,github +Mr. Roberts,ezequiel@ernser.co,232,github +Rolf Scamander,antoniocorkery@shanahanernser.io,353,github +Winky,dirk@murphy.name,145,github diff --git a/db/migrate/20181017222943_create_merchants.rb b/db/migrate/20181017222943_create_merchants.rb new file mode 100644 index 0000000000..846cedd125 --- /dev/null +++ b/db/migrate/20181017222943_create_merchants.rb @@ -0,0 +1,11 @@ +class CreateMerchants < ActiveRecord::Migration[5.2] + def change + create_table :merchants do |t| + t.string :username + t.string :email + t.integer :uid + t.string :provider + t.timestamps + end + end +end diff --git a/db/migrate/20181017222948_create_products.rb b/db/migrate/20181017222948_create_products.rb new file mode 100644 index 0000000000..f5ece18922 --- /dev/null +++ b/db/migrate/20181017222948_create_products.rb @@ -0,0 +1,15 @@ +class CreateProducts < ActiveRecord::Migration[5.2] + def change + create_table :products do |t| + t.string :name + t.decimal :price + t.string :photo + t.integer :stock + t.boolean :active + t.string :category + t.decimal :rating + t.belongs_to :merchant, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20181017222952_create_orders.rb b/db/migrate/20181017222952_create_orders.rb new file mode 100644 index 0000000000..5396ce84dd --- /dev/null +++ b/db/migrate/20181017222952_create_orders.rb @@ -0,0 +1,14 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :status + t.string :name + t.string :email + t.string :address + t.integer :cc_num + t.integer :cc_cvv + t.date :cc_expiration + t.timestamps + end + end +end diff --git a/db/migrate/20181017222957_create_order_items.rb b/db/migrate/20181017222957_create_order_items.rb new file mode 100644 index 0000000000..55800924ca --- /dev/null +++ b/db/migrate/20181017222957_create_order_items.rb @@ -0,0 +1,11 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + t.integer :quantity + t.string :status + t.belongs_to :product, index: true + t.belongs_to :order, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20181017223000_create_reviews.rb b/db/migrate/20181017223000_create_reviews.rb new file mode 100644 index 0000000000..b3151c6ac6 --- /dev/null +++ b/db/migrate/20181017223000_create_reviews.rb @@ -0,0 +1,11 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.string :name + t.integer :rating + t.string :description + t.belongs_to :product, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20181018180824_reformat_order_cc_num.rb b/db/migrate/20181018180824_reformat_order_cc_num.rb new file mode 100644 index 0000000000..fc0dc77270 --- /dev/null +++ b/db/migrate/20181018180824_reformat_order_cc_num.rb @@ -0,0 +1,5 @@ +class ReformatOrderCcNum < ActiveRecord::Migration[5.2] + def change + change_column :orders, :cc_num, :bigint + end +end diff --git a/db/migrate/20181021171911_add_description_column_to_products.rb b/db/migrate/20181021171911_add_description_column_to_products.rb new file mode 100644 index 0000000000..11ec697c03 --- /dev/null +++ b/db/migrate/20181021171911_add_description_column_to_products.rb @@ -0,0 +1,5 @@ +class AddDescriptionColumnToProducts < ActiveRecord::Migration[5.2] + def change + add_column :products, :description, :string + end +end diff --git a/db/migrate/20181024173739_remove_rating_products.rb b/db/migrate/20181024173739_remove_rating_products.rb new file mode 100644 index 0000000000..d545688c56 --- /dev/null +++ b/db/migrate/20181024173739_remove_rating_products.rb @@ -0,0 +1,5 @@ +class RemoveRatingProducts < ActiveRecord::Migration[5.2] + def change + remove_column :products, :rating + end +end diff --git a/db/migrate/20181024224302_create_categories.rb b/db/migrate/20181024224302_create_categories.rb new file mode 100644 index 0000000000..6ccc3914a0 --- /dev/null +++ b/db/migrate/20181024224302_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20181024224430_create_categories_products_join.rb b/db/migrate/20181024224430_create_categories_products_join.rb new file mode 100644 index 0000000000..7bcfaadab5 --- /dev/null +++ b/db/migrate/20181024224430_create_categories_products_join.rb @@ -0,0 +1,8 @@ +class CreateCategoriesProductsJoin < ActiveRecord::Migration[5.2] + def change + create_table :categories_products do |t| + t.belongs_to :category, index: true + t.belongs_to :product, index: true + end + end +end diff --git a/db/migrate/20181024224809_remove_category_from_products.rb b/db/migrate/20181024224809_remove_category_from_products.rb new file mode 100644 index 0000000000..4a5939d3d9 --- /dev/null +++ b/db/migrate/20181024224809_remove_category_from_products.rb @@ -0,0 +1,5 @@ +class RemoveCategoryFromProducts < ActiveRecord::Migration[5.2] + def change + remove_column :products, :category + end +end diff --git a/db/order_item_seeds.csv b/db/order_item_seeds.csv new file mode 100644 index 0000000000..e41351f041 --- /dev/null +++ b/db/order_item_seeds.csv @@ -0,0 +1,51 @@ +quantity,status +85,paid +80,pending +28,paid +10,cancelled +75,complete +14,complete +95,pending +18,paid +35,paid +62,pending +33,cancelled +87,cancelled +50,complete +78,complete +46,paid +65,complete +90,paid +21,paid +97,complete +19,pending +59,cancelled +59,paid +25,paid +91,pending +76,cancelled +65,complete +34,complete +49,paid +49,cancelled +79,cancelled +74,cancelled +83,paid +81,complete +43,complete +49,paid +18,pending +21,paid +35,paid +80,paid +85,complete +16,paid +32,pending +38,paid +66,paid +46,pending +82,cancelled +40,pending +26,cancelled +19,cancelled +74,complete diff --git a/db/order_seeds.csv b/db/order_seeds.csv new file mode 100644 index 0000000000..6008f2fcd1 --- /dev/null +++ b/db/order_seeds.csv @@ -0,0 +1,21 @@ +status,name,email,address,cc_num,cc_cvv,cc_expiration +complete,Unity,joanesatterfield@abernathy.net,"Suite 409 845 Mills Green, Lake Genaroshire, MS 44970",4486883872396845,555,2018-10-23 +paid,Beth's Mytholog,berryfeil@dibbertlang.co,"Apt. 365 7230 Natosha Freeway, Farrellshire, ID 50567-5016",2176389478716835,154,2018-10-04 +cancelled,Unity,catarinaschroeder@steubermitchell.name,"Suite 769 7678 Von Tunnel, Port Reginald, OH 72355",9407052645553807,906,2018-10-13 +complete,Abradolf Lincler,lanellturcotte@haag.biz,"Apt. 890 26637 Rosalina Hill, Paucekhaven, MN 50199-3481",8083496813074413,712,2018-10-04 +paid,Snowball,nigelstokes@bergeheathcote.biz,"Apt. 279 91179 Petrina Plaza, Johnsonmouth, FL 37419-0453",1425929142216586,775,2018-10-04 +complete,Cousin Nicky,irinahoeger@kuhlmansawayn.co,"590 Alva Union, Kozeyfurt, ID 02820-7540",8616399893664530,651,2018-10-21 +complete,"Revolio 'Gearhead' Clockberg, Jr.",marckilback@nolan.name,"4009 Little Motorway, East Denis, MI 46736",6341894708669961,706,2018-10-22 +paid,Jessica,fideliaryan@pfannerstill.biz,"Suite 128 2597 Miquel Street, Lake Danita, NJ 46521",8584190810966913,957,2018-10-16 +cancelled,Fart,donnelltromp@westzulauf.name,"Suite 997 4165 Katina Rapid, Brendanmouth, ND 47070",3966391398253288,335,2018-10-14 +paid,Mr. Poopybutthole,demetrice@johns.com,"749 Pedro Freeway, Honeymouth, WY 93386-2460",8813010477919242,565,2018-10-18 +cancelled,Krombopulos Michael,cleolehner@joneswatsica.biz,"53369 Santiago Divide, Damionfurt, WY 25181-3050",2169398197736081,191,2018-10-06 +paid,Arthricia,melanienikolaus@prohaska.info,"Suite 519 90840 Stacey Lock, East Maynard, MS 63672",6070400071834991,125,2018-10-24 +cancelled,"Revolio 'Gearhead' Clockberg, Jr.",carrielemke@reichel.name,"43426 Luke Rue, Abrahamhaven, CA 14404-4088",1846236753265187,767,2018-10-15 +complete,Beth Smith,alvinjohnston@oreilly.net,"Apt. 934 8303 Adams Mall, South Felicia, WA 45786",5322792478635279,659,2018-10-11 +cancelled,Jerry's Mytholog,averyrice@berge.co,"Suite 657 85544 Noe Ports, South Precious, HI 72983-4991",2664550272640410,366,2018-10-16 +complete,Krombopulos Michael,jasminrau@macejkovicpaucek.name,"Apt. 234 21632 Schroeder Garden, New Tobiasville, IA 02526",1483700269514539,222,2018-10-24 +cancelled,King Jellybean,tisa@towne.org,"Apt. 272 2038 Conroy Radial, Dedraview, NH 55849",5964637614914130,722,2018-10-04 +complete,Scary Terry,mitch@blickstamm.io,"Apt. 234 4164 Emmerich Via, Port Isaias, IL 77152",8101522667209264,920,2018-10-19 +paid,Baby Legs,bunny@blanda.org,"Apt. 524 322 Argentina Road, Greenholtmouth, HI 55167-6284",5058172511519348,332,2018-10-07 +paid,Arthricia,markusmante@towne.co,"749 Osinski Bridge, Klingburgh, MO 35098",5446813160763276,406,2018-10-04 diff --git a/db/product_seeds.csv b/db/product_seeds.csv new file mode 100644 index 0000000000..cca0e2654b --- /dev/null +++ b/db/product_seeds.csv @@ -0,0 +1,51 @@ +name,price,photo,stock,active,description +Millie,29.37,http://placekitten.com/200/300,37,false,Eius praesentium aperiam placeat. +Lily,1.76,http://placekitten.com/200/300,94,true,Sed aut et magni. +Misty,72.65,http://placekitten.com/200/300,48,true,Excepturi quia quaerat placeat. +Bella,88.16,http://placekitten.com/200/300,60,true,Et et a id. +Lily,25.69,http://placekitten.com/200/300,50,true,Autem qui provident vel. +Max,3.1,http://placekitten.com/200/300,26,true,Ad saepe earum at. +Millie,29.65,http://placekitten.com/200/300,10,true,Quidem sequi quis nihil. +Daisy,49.14,http://placekitten.com/200/300,35,true,Voluptatem laboriosam dolore placeat. +Shadow,99.86,http://placekitten.com/200/300,22,true,Blanditiis dolorem vel omnis. +Smudge,29.28,http://placekitten.com/200/300,84,true,Et mollitia quam quia. +Max,89.38,http://placekitten.com/200/300,27,true,Nihil non repellendus error. +Lily,29.96,http://placekitten.com/200/300,76,false,Distinctio et quaerat quod. +Tiger,49.06,http://placekitten.com/200/300,14,true,Quam quaerat tempora eveniet. +Lucy,37.0,http://placekitten.com/200/300,20,false,Odit alias dolores perferendis. +Milo,10.86,http://placekitten.com/200/300,90,false,Amet quia et corrupti. +Simba,46.65,http://placekitten.com/200/300,43,true,Ab corrupti aut inventore. +Sam,54.46,http://placekitten.com/200/300,47,false,Rerum quia qui vitae. +Max,68.73,http://placekitten.com/200/300,14,true,Asperiores eum ea cum. +Sooty,80.0,http://placekitten.com/200/300,86,true,At ut est iste. +Bella,76.75,http://placekitten.com/200/300,36,true,Dolorem et enim sint. +Lucky,40.63,http://placekitten.com/200/300,15,false,Ut aut omnis quidem. +Felix,68.86,http://placekitten.com/200/300,38,false,Qui quas quis illum. +Felix,57.72,http://placekitten.com/200/300,76,false,Aut vel minus ipsum. +Simba,51.79,http://placekitten.com/200/300,12,true,Nihil blanditiis asperiores perspiciatis. +Charlie,59.53,http://placekitten.com/200/300,35,true,Reiciendis fugit eum et. +Tiger,32.61,http://placekitten.com/200/300,18,false,Aut repudiandae quidem molestiae. +Chloe,44.84,http://placekitten.com/200/300,63,true,Eaque error saepe voluptatem. +Max,84.36,http://placekitten.com/200/300,24,true,Quaerat ut quo voluptatem. +Angel,0.73,http://placekitten.com/200/300,70,true,Explicabo neque quidem autem. +Misty,23.02,http://placekitten.com/200/300,48,true,Sapiente ut non eos. +Jasper,33.39,http://placekitten.com/200/300,28,true,Consectetur quos porro fugit. +Coco,35.39,http://placekitten.com/200/300,62,true,Hic odit cum soluta. +Molly,53.18,http://placekitten.com/200/300,54,true,Quae et et autem. +Smokey,36.76,http://placekitten.com/200/300,25,true,Harum exercitationem ex ipsa. +Simba,72.53,http://placekitten.com/200/300,41,true,Laborum blanditiis iusto velit. +Lucy,78.55,http://placekitten.com/200/300,22,true,In eos et vero. +Alfie,48.35,http://placekitten.com/200/300,49,true,Accusantium voluptas similique quia. +Oliver,40.33,http://placekitten.com/200/300,54,true,At repellat error sint. +Simba,95.27,http://placekitten.com/200/300,51,true,Esse amet assumenda et. +Coco,80.22,http://placekitten.com/200/300,24,false,Alias perspiciatis iusto molestias. +Coco,64.54,http://placekitten.com/200/300,96,false,Voluptas vitae nihil quidem. +Alfie,60.28,http://placekitten.com/200/300,69,true,Totam quaerat consequuntur quia. +Millie,68.28,http://placekitten.com/200/300,72,true,Et perferendis quia expedita. +Smokey,90.27,http://placekitten.com/200/300,49,true,Laudantium optio temporibus qui. +Misty,56.26,http://placekitten.com/200/300,76,true,Accusantium sapiente et non. +Coco,5.06,http://placekitten.com/200/300,95,true,Natus quae perspiciatis in. +Smudge,31.64,http://placekitten.com/200/300,77,false,Iusto ipsam repellat expedita. +Sam,35.53,http://placekitten.com/200/300,24,true,Incidunt ratione aut repellendus. +Bella,75.51,http://placekitten.com/200/300,37,true,Quis placeat cum architecto. +Jasper,68.77,http://placekitten.com/200/300,46,false,Sed voluptatibus voluptate minus. diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..f81eb80593 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,86 @@ +# 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_24_224809) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "categories_products", force: :cascade do |t| + t.bigint "category_id" + t.bigint "product_id" + t.index ["category_id"], name: "index_categories_products_on_category_id" + t.index ["product_id"], name: "index_categories_products_on_product_id" + end + + create_table "merchants", force: :cascade do |t| + t.string "username" + t.string "email" + t.integer "uid" + t.string "provider" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "order_items", force: :cascade do |t| + t.integer "quantity" + t.string "status" + t.bigint "product_id" + t.bigint "order_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: 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 "status" + t.string "name" + t.string "email" + t.string "address" + t.bigint "cc_num" + t.integer "cc_cvv" + t.date "cc_expiration" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.decimal "price" + t.string "photo" + t.integer "stock" + t.boolean "active" + t.bigint "merchant_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "description" + t.index ["merchant_id"], name: "index_products_on_merchant_id" + end + + create_table "reviews", force: :cascade do |t| + t.string "name" + t.integer "rating" + t.string "description" + t.bigint "product_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["product_id"], name: "index_reviews_on_product_id" + end + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..506c7b50cd --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,55 @@ +require 'csv' + + +merchant_file = Rails.root.join('db', 'merchant_seeds.csv') +order_item_file = Rails.root.join('db', 'order_item_seeds.csv') +order_file = Rails.root.join('db', 'order_seeds.csv') +product_file = Rails.root.join('db', 'product_seeds.csv') +category_file = Rails.root.join('db', 'category_seeds.csv') + +CSV.foreach(merchant_file, headers: true, header_converters: :symbol, converters: :all) do |row| + data = Hash[row.headers.zip(row.fields)] + puts data + Merchant.create!(data) +end + +CSV.foreach(order_file, headers: true, header_converters: :symbol, converters: :all) do |row| + data = Hash[row.headers.zip(row.fields)] + puts data + Order.create!(data) +end + +CSV.foreach(category_file, headers: true, header_converters: :symbol, converters: :all) do |row| + data = Hash[row.headers.zip(row.fields)] + puts data + category = Category.new(data) + category.save! +end + +CSV.foreach(product_file, headers: true, header_converters: :symbol, converters: :all) do |row| + data = Hash[row.headers.zip(row.fields)] + puts data + merchant = Merchant.all.shuffle.first + product = Product.new(data) + product.update_attributes(merchant: merchant) + + num_categories = rand(4) + 1 + list_categories = Category.all.shuffle[0..num_categories] + + list_categories.each do |category| + product.categories << category + end + + + product.save! +end + +CSV.foreach(order_item_file, headers: true, header_converters: :symbol, converters: :all) do |row| + data = Hash[row.headers.zip(row.fields)] + puts data + product = Product.all.shuffle.first + order = Order.all.shuffle.first + orderitem = OrderItem.new(data) + orderitem.update_attributes(order: order, product: product) + orderitem.save! +end 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/petsy-emporium b/petsy-emporium new file mode 160000 index 0000000000..f9eb18aad2 --- /dev/null +++ b/petsy-emporium @@ -0,0 +1 @@ +Subproject commit f9eb18aad20d87c5711a75004a9a278dfe8b1b61 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..9c423b7eda --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,54 @@ +require "test_helper" + +describe CategoriesController do + + before do + @merchant = merchants(:dogdays) + perform_login(@merchant) + end + + describe "new" do + it 'should get new' do + get new_category_path + + must_respond_with :success + end + end + + describe "create" do + before do + @category_data = { + category: { + name: 'test category' + } + } + end + it 'can create a new category with valid data' do + + test_category = Category.new(@category_data[:category]) + test_category.must_be :valid?, "Category is invalid. Please fix." + + expect{ + post categories_path, params: @category_data + }.must_change('Category.count', +1) + + must_redirect_to dashboard_path(@merchant.id) + + end + + it 'does not create a new category with invalid data' do + + @category_data[:category][:name] = Category.first.name + + test_category = Category.new(@category_data[:category]) + test_category.wont_be :valid?, "Category is not invalid. Please fix." + + expect{ + post categories_path, params: @category_data + }.wont_change('Category.count') + + must_respond_with :bad_request + + 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..e44b09ed41 --- /dev/null +++ b/test/controllers/merchants_controller_test.rb @@ -0,0 +1,81 @@ +require "test_helper" +require 'pry' +describe MerchantsController do + + let(:merchant_data) { + { + merchant: + { + username: 'testername', + email: 'testername@gmail.com', + uid: 7, + provider: 'github' + } + } + } + + let (:merchant) { + merchants(:dogdays) + } + + describe "index" do + it "should get index" do + + get merchants_path + + must_respond_with :success + end + end + + describe "show" do + + + it "should respond with success for showing an existing merchant" do + + get merchant_path(merchant.id) + must_respond_with :success + end + + it "should respond with not found for showing a non-existant merchant" do + + merchant.destroy + + expect{ + get merchant_path(merchant.id) + }.must_raise(ActionController::RoutingError) + + end + end + + describe "dashboard" do + it "should respond with success for showing an existing merchant" do + + get dashboard_path(merchant) + + must_respond_with :success + end + + it "raise error for showing a non existant merchant" do + merchant.destroy + + expect{ + get merchant_path(merchant.id) + }.must_raise(ActionController::RoutingError) + + end + end + + describe "dashboard" do + it "should respond with success for connecting to an existing merchant" do + existing_merchant = merchants(:dogdays) + get dashboard_path(existing_merchant.id) + must_respond_with :success + end + + it "should respond with not found when trying to link to a non-existant merchant" do + get dashboard_path(bad_merchant_id) + must_respond_with :not_found + end + 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..a287e6bd31 --- /dev/null +++ b/test/controllers/order_items_controller_test.rb @@ -0,0 +1,112 @@ +require "test_helper" +require 'pry' +describe OrderItemsController do + + describe "guest user" do + describe "index" do + + + it "can access cart" do + + get order_items_path + + must_respond_with :success + end + end + + + describe 'create' do + it "creates new order for first item added to cart" do + + order_item_data = { + order_item: { + quantity: 1, + status: 'pending', + product_id: Product.first.id + } + } + + before = OrderItem.count + + expect { + post order_items_path, params: order_item_data + }.must_change('Order.count', +1) + + expect(OrderItem.count).must_equal before + 1 + + expect(flash[:status]).must_equal :success + expect(flash[:result_text]).must_equal "Item successfully added to cart. " + + expect(session[:order_id]).must_equal OrderItem.last.order_id + + must_respond_with :redirect + end + + it "successfully adds order item to existing order" do + + merchant = merchants(:dogdays) + perform_login(merchant) + + order_item_data = { + order_item: { + quantity: 3, + status: 'pending', + product_id: products(:product_two).id, + order_id: orders(:merchant).id + } + } + + test_item = OrderItem.new(order_item_data[:order_item]) + test_item.must_be :valid?, "OrderItem data was invalid. Please fix this test." + + session[:order_id] = orders(:merchant).id + + before = OrderItem.count + + post order_items_path(order_item_data) + + expect { + post order_items_path, params: order_item_data + }.wont_change('Order.count') + + expect(OrderItem.count).must_equal before + 1 + + expect(flash[:status]).must_equal :success + expect(flash[:result_text]).must_include "Cart successfully updated" + + must_respond_with :redirect + + end + + it "shows an error if the quantity is greater than the product's stock" do + + order_item_data = { + order_item: { + quantity: 20, + status: 'pending', + product_id: products(:product_two).id, + order_id: orders(:merchant).id + } + } + + test_item = OrderItem.new(order_item_data[:order_item]) + before_stock = test_item.product.stock + # before_order = test_item.quantity + test_item.must_be :valid?, "OrderItem data was invalid. Please fix this test." + + post order_items_path(order_item_data) + + expect { + post order_items_path, params: order_item_data + }.wont_change('Order.count') + + expect(test_item.product.stock).must_equal before_stock + order_item = OrderItem.find_by( + product_id: products(:product_two).id, + order_id: orders(:merchant).id + ) + expect(order_item.quantity).must_equal 15 + end + end + end +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..80c1f8c623 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,124 @@ +require "test_helper" + +describe OrdersController do + + let (:delete_all) { + Order.all.each do |order| + order.destroy + end + } + + let (:order_data) { + { + order: { + status: 'paid', + name: 'Ada', + email: 'ada@adacademy.com', + address: '123 Street Dr. Seattle, WA', + cc_num: 1123384229389283, + cc_cvv: 280, + cc_expiration: '2020-09-01' + } + } + } + + let (:existing_order) { + orders(:bob) + } + + describe "index" do + it "succeeds with orders present" do + get orders_path + + must_respond_with :success + end + + it "succeeds with no orders present" do + delete_all + + get orders_path + + must_respond_with :success + end + end + + describe "create" do + it "can create an order" do + test_order = Order.new(order_data[:order]) + expect(test_order).must_be :valid?, "Order data was invalid. Please fix." + + expect{ + post orders_path, params: order_data + }.must_change('Order.count', +1 ) + + must_redirect_to order_path(Order.last) + must_respond_with :redirect + end + end + + describe "edit" do + it "succeeds with an extant order ID" do + get edit_order_path(existing_order.id) + + must_respond_with :success + end + + it "renders 404 not_found for a bogus order ID" do + existing_order.destroy + + expect{ + get edit_order_path(existing_order.id) + }.must_raise(ActionController::RoutingError) + + end + end + + describe "update" do + it "succeeds for valid data and an extant work ID" do + test_order = Order.new(order_data[:order]) + expect(test_order).must_be :valid?, "Order data was invalid. Please fix." + + expect { + patch order_path(existing_order.id), params: order_data + }.wont_change('Order.count') + + existing_order.reload + (existing_order.email).must_equal test_order.email + (existing_order.name).must_equal test_order.name + (existing_order.address).must_equal test_order.address + + must_redirect_to order_path(existing_order.id) + end + + it "renders 404 not_found for a bogus order ID" do + existing_order.destroy + + expect{ + patch order_path(existing_order.id), params: order_data + }.must_raise(ActionController::RoutingError) + + end + end + + describe "destroy" do + it "succeeds for an extant order ID with status not cancelled" do + expect { + delete order_path(existing_order.id) + }.must_change('Order.count', -1) + + must_respond_with :redirect + must_redirect_to root_path + end + + it "renders 404 not_found and does not update the DB for a bogus order ID" do + existing_order.destroy + + expect{ + delete order_path(existing_order.id) + }.must_raise(ActionController::RoutingError) + + 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..e1afbb818b --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,151 @@ +require "test_helper" +require 'pry' + +describe ProductsController do + let (:product_data) { + { + product: { + name: "Test product", + price: 3.50, + merchant: merchants(:dogdays), + stock: 5, + active: true + } + } + } + + let (:product) { + products(:product_one) + } + + describe "guest user" do + describe "index" do + it "successfully gets index" do + get products_path + + must_respond_with :success + end + end + + describe "show" do + it "should respond with success for showing an existing product" do + + get product_path(product.id) + + must_respond_with :success + end + + it "should respond with not found for showing a non-existing product" do + + product.destroy + + expect{ + get product_path(product.id) + }.must_raise(ActionController::RoutingError) + + end + end + + describe "create" do + it 'should not allow guest user to create a new product' do + test_product = Product.new(product_data[:product]) + test_product.must_be :valid?, "Product data was invalid. Please come fix this test." + + expect { + post products_path, params: product_data + }.wont_change('Product.count') + + must_respond_with :bad_request + end + end + + describe "update" do + it "should not allow guest user to update a new product" do + + end + end + end + + describe "merchant user" do + before do + perform_login(merchants(:dogdays)) + end + + describe "new" do + it "successfully retrieves new page" do + + get new_product_path + + must_respond_with :success + + end + end + + describe "create" do + it "creates new product when logged in and given valid data" do + + + test_product = Product.new(product_data[:product]) + test_product.must_be :valid?, "Product data was invalid. Please come fix this test." + + expect { + post products_path, params: product_data + }.must_change('Product.count', 1) + + must_redirect_to products_path + + expect(Product.last.name).must_equal product_data[:product][:name] + end + end + + describe "edit" do + it "responds with success for an existing product" do + get edit_product_path(product) + + must_respond_with :success + end + + it "responds with not_found for a product that doesn't exist" do + product.destroy + + expect{ + get edit_product_path(product) + + }.must_raise(ActionController::RoutingError) + + end + end + + describe "update" do + it "should show success when showing an existing product" do + + get product_path(product.id) + + must_respond_with :success + end + + it "should return error message if product doesn't exist" do + + product.destroy + + expect{ + get product_path(product.id) + }.must_raise(ActionController::RoutingError) + + end + end + + describe "destroy" do + it "can destroy an existing product" do + + + expect { + delete product_path(product) + }.must_change('Product.count', -1) + + + must_redirect_to products_path + end + end + end +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..be9c6fbd45 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,35 @@ +require "test_helper" + +describe ReviewsController do + let (:product) {Product.first} + describe "new" do + it "can get new page" do + get new_product_review_path(product) + must_respond_with :success + end + end + describe "create" do + it "can create a review with valid data" do + review_data = { + review: { + name: "Aurea", + rating: 5, + product: product + } + } + test_review = Review.new(review_data[:review]) + test_review.must_be :valid?, "Review data was invalid. Please come fix this test." + + # expect { + # post product_reviews_path(product), params: review_data + # }.must_change('Review.count', +1) + # VNG: In the console, Review.count returns 0, so I think there's a problem with our yml files/test database. + post product_reviews_path(product), params: review_data + must_respond_with :success + # must_redirect_to product_path(product) + # VNG: Redirect causes error - response is 200 ok, not redirect. + end + it "doesn't create a review with invalid data" 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..8be9258f12 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,60 @@ +require "test_helper" + +describe SessionsController do + describe 'create' do + it 'can sucessfully log in with github as an existing user' do + merchant = merchants(:dogdays) + + perform_login(merchant) + + must_redirect_to root_path + + expect(session[:user_id]).must_equal merchant.id + # expect(flash[:success]).must_equal "Logged in as merchant #{merchant.username}" + # VNG - We need to fix flash. + end + + it 'creates a new user sucessfully when logging in with a new valid user' do + + start_count = Merchant.count + + new_user = Merchant.new(username: "new user", email: "email@email.com", uid: 10, provider: "github") + + expect(new_user.valid?).must_equal true + + perform_login(new_user) + + must_redirect_to root_path + + expect(Merchant.count).must_equal start_count + 1 + + expect( session[:user_id] ).must_equal Merchant.last.id + + end + + it 'does not create a new user when logging in with a new invalid user' do + start_count = Merchant.count + + invalid_new_user = Merchant.new(username: nil, email: nil) + + expect(invalid_new_user.valid?).must_equal false + + perform_login(invalid_new_user) + + must_redirect_to root_path + expect( session[:user_id] ).must_equal nil + expect( Merchant.count ).must_equal start_count + end + end + + describe 'destroy' do + it 'can log out a logged in user' do + merchant = merchants(:dogdays) + + perform_login(merchant) + + delete logout_path(merchant) + must_redirect_to root_path + end + end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..ea917c3146 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +dog: + name: dogs + products: [product_one, product_two] +cat: + name: cats + products: [product_three] +val: + name: silly val + products: [product_one, product_two, product_six] 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..443c5d08dc --- /dev/null +++ b/test/fixtures/merchants.yml @@ -0,0 +1,26 @@ +# 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 +# +dogdays: + username: dogsdays + email: dogsdays@over.com + uid: 12345 + provider: github +palomino: + username: palomino + email: horsesgalore@some.com + uid: 31234 + provider: github +larry: + username: lizardlarry + email: larry54@over.com + uid: 7124 + provider: github +cuteclothes: + username: cuteclothes + email: cuteclothes@shop.com + uid: 1123 + provider: github diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..7daf33b778 --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,36 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: + quantity: 1 + status: paid + product: product_one + order: bob +two: + quantity: 1 + status: paid + product: product_two + order: bob +three: + quantity: 1 + status: paid + product: product_three + order: bob +four: + quantity: 1 + status: paid + product: product_four + order: bob +five: + quantity: 3 + status: pending + product: product_one + order: bob +six: + quantity: 2 + status: pending + product: product_one + order: merchant diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..500051f840 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,24 @@ +# 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 +# +bob: + status: paid + name: Bob Li + email: bobli@adacademy.com + address: 100 6th Avenue, Seattle WA + cc_num: 1232837292749182 + cc_cvv: 293 + cc_expiration: '01-09-2018' +incomplete_order: + status: pending +merchant: + status: pending + name: Dog Days + email: dog@days.com + address: 100 10th Avenue, Seattle WA + cc_num: 1232837292749182 + cc_cvv: 293 + cc_expiration: 01-09-2018 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..3832b58675 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,46 @@ +product_one: + name: test product 1 + price: 1.99 + photo: http://placekitten.com/200/300 + stock: 10 + active: true + merchant: dogdays + description: blah blah blah cats +product_two: + name: test product 2 + price: 10.99 + photo: http://placekitten.com/200/300 + stock: 15 + active: true + merchant: palomino + description: blah blah blah cats +product_three: + name: test product 3 + price: 18.99 + photo: http://placekitten.com/200/300 + stock: 5 + active: true + merchant: larry + description: blah blah blah cats +product_four: + name: test product 4 + price: 1.99 + photo: http://placekitten.com/200/300 + stock: 8 + active: true + merchant: cuteclothes + description: blah blah blah cats +product_five: + name: test product 5 + price: 11.99 + photo: http://placekitten.com/200/300 + stock: 10 + active: true + merchant: dogdays + description: blah blah blah cats +product_six: + name: test product 6 + price: 11.99 + stock: 10 + active: true + merchant: dogdays diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..7c758d2f62 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,22 @@ +# 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 +# +review_one: + name: Val + rating: 2 + product: product_one +review_two: + name: Ada + rating: 5 + product: product_one +review_three: + name: Val + rating: 4 + product: product_five +review_four: + name: Val + rating: 5 + product: product_six diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/helpers/merchants_helper.rb b/test/helpers/merchants_helper.rb new file mode 100644 index 0000000000..1b3433be36 --- /dev/null +++ b/test/helpers/merchants_helper.rb @@ -0,0 +1,17 @@ +require "test_helper" +require 'pry' + +describe MerchantsHelper do + +describe "render_date" do + it "should correctly format dates to string format" do + order = order_items.first + expect(order.valid?).must_equal true + + date = order.created_at + + expect(render_date(order.created_at)).must_be_kind_of String + end + end + +end 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..a4bfe01b0d --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,38 @@ +require "test_helper" + +describe Category do + before do + @c = categories(:dog) + end + + describe 'relations' do + it 'has some products' do + + expect( @c.products ).must_respond_to :each + + @c.products.each do |product| + expect( product ).must_be_instance_of Product + end + end + end + + describe 'validations' do + it 'is valid with a unique name' do + + expect( @c ).must_be :valid? + end + it 'is invalid without a name' do + + @c.name = nil + + expect( @c ).wont_be :valid? + end + + it 'is invalid with a duplicate name' do + + dup_category = Category.new(name: @c.name ) + + expect( dup_category ).wont_be :valid? + end + end +end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..de13a18fee --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,82 @@ +require "test_helper" + +describe Merchant do + before do + @m = merchants(:dogdays) + end + describe 'relations' do + it 'has some products' do + + expect( @m.products ).must_respond_to :each + + @m.products.each do |product| + + expect( product ).must_be_instance_of Product + end + end + end + + describe 'validations' do + let (:new_merchant) { + Merchant.new( + username: 'testusername', + email: 'testemail@ada.com', + uid: 9999, + provider: 'github' + ) + } + + + it 'is valid when username and email is unique and present' do + + expect( @m ).must_be :valid? + + end + + it 'is invalid without a username' do + @m.username = nil + + expect ( @m ).wont_be :valid? + end + + it 'is invalid when username is non unique' do + + expect( new_merchant ).must_be :valid? + + new_merchant.username = @m.username + + expect( new_merchant ).wont_be :valid? + end + + it 'is invalid without an email' do + @m.email = nil + + expect( @m ).wont_be :valid? + end + + it 'is invalid when email is non unique' do + expect( new_merchant).must_be :valid? + + new_merchant.email = @m.email + + expect( new_merchant ).wont_be :valid? + end + + end + + describe 'rating' do + it 'returns average of all product ratings' do + expect( @m.rating ).must_be_close_to 4.17, 0.01 + end + + it 'returns nil if no products' do + @m.products.each do |product| + product.destroy + end + + @m.reload + + expect( @m.rating ).must_be_nil + end + end +end diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..1af6126d11 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,73 @@ +require "test_helper" + +describe OrderItem do + before do + @o = order_items(:one) + end + describe 'relations' do + it 'has a product' do + + expect( @o.product ).must_be_instance_of Product + + end + + it 'has an order' do + + expect( @o.order ).must_be_instance_of Order + + end + end + + describe 'validations' do + it 'is valid when quantity and status are present with valid values' do + + expect( @o ).must_be :valid? + + end + + it 'is invalid without a quantity' do + + @o.quantity = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid with a quantity of 0 or less' do + + @o.quantity = 0 + + expect( @o ).wont_be :valid? + + @o.quantity = -1 + + expect( @o ).wont_be :valid? + end + + it 'is invalid without a status' do + + @o.status = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid when the status is not one of the valid status values' do + + @o.status = 'foo' + + expect( @o ).wont_be :valid? + + end + + end + + describe 'price' do + it 'correctly calculates price based on product price and quantity' do + o = order_items(:five) + + expect( o.price).must_be_close_to 5.97, 0.01 + end + end + +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..cf05ced97b --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,192 @@ +require "test_helper" + +describe Order do + before do + @o = orders(:bob) + end + describe 'relations' do + + + it 'has some order items' do + expect( @o.order_items ).must_respond_to :each + + @o.order_items.each do |order_item| + expect(order_item).must_be_instance_of OrderItem + end + end + + + end + + describe 'validations' do + describe 'conditional validation: order is not pending' do + + it 'is valid when all required fields are present' do + expect( @o ).must_be :valid? + + end + + it 'is invalid without a name' do + + @o.name = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid without an email' do + + @o.email = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid without an address' do + + @o.address = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid without a cc_num' do + + @o.cc_num = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid without a cc_cvv' do + + @o.cc_cvv = nil + + expect( @o ).wont_be :valid? + + end + + it 'is invalid without a cc_expiration' do + + @o.cc_expiration = nil + + expect( @o ).wont_be :valid? + + end + end + + describe 'unconditional validation' do + + before do + @o = orders(:incomplete_order) + end + + it 'is valid if status is present and true' do + expect( @o ).must_be :valid? + end + + it 'is invalid if status is not a valid status' do + @o.status = 'foo' + + expect( @o ).wont_be :valid? + end + end + + end + + describe 'is_not_pending' do + it 'returns false if pending' do + @o.status = 'pending' + + expect( @o.is_not_pending ).must_equal false + end + + it 'returns true if not pending' do + + Order::STATUS.each do |status| + if status != 'pending' + @o.status = status + + expect( @o.is_not_pending ).must_equal true + end + end + + end + end + + describe 'total' do + it 'returns total price of all order items' do + + expect( @o.total ).must_be_close_to 39.93, 0.01 + end + + it 'returns 0 if no order items' do + + @o.order_items.each do |order_item| + order_item.destroy + end + + @o.reload + + expect( @o.total ).must_equal 0 + + end + + end + describe 'CC_num_last_four' do + it 'correctly returns last four digits of cc_num' do + @o.cc_num = '1239082378923' + + expect( @o.CC_num_last_four ).must_equal '8923' + end + + it 'returns total string if cc_num length is less than 4' do + @o.cc_num = '13' + + expect( @o.CC_num_last_four ).must_equal '13' + end + + it 'returns nil if cc_num is nil' do + @o.cc_num = nil + + expect( @o.CC_num_last_four ).must_be_nil + end + end + + describe 'total_quantity' do + it 'returns total quantity of all order items' do + + expect( @o.total_quantity ).must_equal 7 + end + + it 'returns 0 if no order items' do + + @o.order_items.each do |order_item| + order_item.destroy + end + + @o.reload + + expect( @o.total_quantity ).must_equal 0 + + end + end + + describe 'paid' do + it 'successfully sets own status and all order items status to paid' do + @o.status = 'pending' + + @o.order_items.each do |order_item| + order_item.status = 'pending' + end + + @o.set_paid + + expect( @o.status ).must_equal 'paid' + + @o.order_items.each do |order_item| + expect( order_item.status ).must_equal 'paid' + end + end + end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..53f5992923 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,98 @@ +require "test_helper" + +describe Product do + + before do + @p = Product.first + end + + describe 'relations' do + + it 'has a merchant' do + + expect( @p.merchant ).must_be_instance_of Merchant + + end + it 'has some reviews' do + + expect( @p.reviews ).must_respond_to :each + expect( @p.reviews.first ).must_be_instance_of Review + + end + + it 'has some order items' do + + expect( @p.order_items ).must_respond_to :each + expect( @p.order_items.first ).must_be_instance_of OrderItem + + end + + it 'has some categories' do + expect( @p.categories).must_respond_to :each + expect( @p.categories.first ).must_be_instance_of Category + end + end + + describe 'validations' do + it 'is valid when required fields are present and price and stock are valid inputs' do + + expect( @p ).must_be :valid? + + end + + it 'is invalid without a name' do + + @p.name = nil + + expect( @p ).wont_be :valid? + end + + it 'is invalid without a price' do + + @p.price = nil + + expect( @p ).wont_be :valid? + + end + + it 'is invalid with a price less than or equal to zero' do + + @p.price = 0 + + expect( @p ).wont_be :valid? + + @p.price = -1 + + expect( @p ).wont_be :valid? + end + + it 'is invalid without a stock' do + + @p.stock = nil + + expect( @p ).wont_be :valid? + end + + it 'is invalid with a negative stock' do + + @p.stock = -1 + + expect( @p ).wont_be :valid? + + end + + end + + describe 'rating' do + it 'returns average of the reviews rating' do + + expect( @p.rating ).must_be_close_to 3.5, 0.01 + end + + it 'returns nil for a product with no reviews' do + no_reviews = products(:product_two) + + expect( no_reviews.rating ).must_be_nil + end + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..91a642b40d --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,41 @@ +require "test_helper" + +describe Review do + before do + @r = reviews(:review_one) + end + describe 'relations' do + it 'has a product' do + expect ( @r.product ).must_be_instance_of Product + end + end + + describe 'validations' do + it 'is valid when name and rating is present, and rating is int between 1 and 5' do + + expect( @r ).must_be :valid? + + end + + it 'is invalid when name is missing' do + + @r.name = nil + expect ( @r ).wont_be :valid? + end + + it 'is invalid when rating is missing' do + @r.rating = nil + expect ( @r ).wont_be :valid? + end + + it 'is invalid when rating is not an int between 1 through 5' do + invalid_rating = 0 + + expect( Review::RATINGS.include?(invalid_rating)).must_equal false + + @r.rating = invalid_rating + + expect( @r ).wont_be :valid? + end + end +end diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000000..728b40e6af --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,48 @@ +require 'simplecov' +SimpleCov.start 'rails' +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" # for Colorized output +require "pry" +# 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 + OmniAuth.config.test_mode = true + end + + def mock_merchant_hash(user) + return { + uid: user.uid, + provider: user.provider, + info: { + nickname: user.username, + email: user.email + } + } + end + + def perform_login(user) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( mock_merchant_hash( user ) ) + + get auth_callback_path(:github) + end +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2