diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..62455dce1e Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..0e8ebbbf4f --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# 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 + +coverage/* + +# Ignore master key for decrypting credentials and more. +/config/master.key + + +#Ignore OAuth info +.env 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..01056bc225 --- /dev/null +++ b/Gemfile @@ -0,0 +1,88 @@ +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/ragit ils/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' + 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 'simplecov', require: false + gem 'chromedriver-helper' + +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end + +# Setting up for OAuth +gem "omniauth" +gem "omniauth-github" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..d3dafbbe07 --- /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.3.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.10.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.2) + xpath (~> 3.2) + 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) + regexp_parser (1.2.0) + ruby-progressbar (1.10.0) + ruby_dep (1.5.0) + rubyzip (1.2.2) + sass (3.6.0) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.14.1) + childprocess (~> 0.5) + rubyzip (~> 1.2, >= 1.2.2) + shellany (0.0.1) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.19) + execjs (>= 0.3.0, < 3) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.2.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + bootsnap (>= 1.1.0) + bootstrap (~> 4.1.3) + byebug + capybara (>= 2.15) + chromedriver-helper + dotenv-rails + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + omniauth + omniauth-github + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.1) + sass-rails (~> 5.0) + selenium-webdriver + simplecov + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +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/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000..d856c4d19c Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store new file mode 100644 index 0000000000..f77cae5023 Binary files /dev/null and b/app/assets/.DS_Store differ diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000000..957b5e2ac3 Binary files /dev/null and b/app/assets/images/.DS_Store differ diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/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/category.js b/app/assets/javascripts/category.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/category.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/homepage.js b/app/assets/javascripts/homepage.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/homepage.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/items.js b/app/assets/javascripts/items.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/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/orderitems.js b/app/assets/javascripts/orderitems.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orderitems.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/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/sessions.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/status.js b/app/assets/javascripts/status.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/status.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..fcdc12c7fd --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,110 @@ +/* + * 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{ + font-family: 'Quicksand', sans-serif; +} + +.top_of_page{ + padding-right: 100px; +} + +.top_of_page > ul >li{ + list-style-type: none; + float: right; + padding-right: 30px; +} + +.fas, .header_links, #home_link{ + color: grey; +} + +.header_links:hover, .fas:hover, #home_link:hover{ + color: #ffa791; + text-decoration: none; +} + +header > h1{ + color: grey; + text-align: center; + font-family: 'Mali', cursive; + padding-top: 60px; + padding-bottom: 60px; + font-size: 3em; +} + +.navbar{ + background-color: none; + border-top: .25px solid lightgrey; + border-bottom: .25px solid lightgrey; + padding-left: 100px; +} + +.dropdown-menu-right { + padding-left: 10px; +} + +footer{ + border-top: .25px solid lightgrey; + padding-left: 70px; + padding-right: 70px; + padding-top: 110px; + padding-bottom: 110px; + display: flex; + flex-direction: row; +} + +.footer_left, .footer_right{ + display: block; +} + +.footer_left{ + margin-right: 5vw; +} + +li{ + list-style-type: none; +} + +section .success, section .form_errors, section .error { + text-align: center; + padding: 0.75rem 1.25rem; + margin: 1em; + border: 1px solid transparent; + border-radius: 0.25rem; +} + +section .success { + color: #155724; + background-color: #d4edda; + border-color: #c3e6cb; +} + +section .error, section .form_errors{ + color: #856404; + background-color: #fff3cd; + border-color: #ffeeba; +} + +.body_main{ + padding-left: 110px; + padding-right: 110px; + padding-top: 50px; + padding-bottom: 50px; +} diff --git a/app/assets/stylesheets/category.scss b/app/assets/stylesheets/category.scss new file mode 100644 index 0000000000..75f552a05e --- /dev/null +++ b/app/assets/stylesheets/category.scss @@ -0,0 +1,88 @@ +// Place all the styles related to the category controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + + +.item-by-category{ + display: flex; + flex-direction: row; + justify-content: space-around; + flex-wrap: wrap; +} + +.item-block { + width: 20em; + height: 20em; + position: relative; + margin-top: 50px; +} + +.item-block:hover .overlay { + display: block; + background: #fb8d96 ;opacity:0.8; +} + +.item-block:hover .button { + opacity: 1; +} + +.item-block:hover .title { + top: 10px; +} + +.category-images { + width: 20em; + height: 20em; + position: absolute; +} + +.title { + position: absolute; + left: 0; + top: 80px; + font-weight: 700; + font-size: 30px; + text-align: center; + text-transform: uppercase; + color: white; + text-decoration: none; + z-index: 1; + transition: top .5s ease; + padding: 1em; + width: 100% +} + +.overlay { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0); + transition: background 0.5s ease; +} + +.button { + position: relative; + left:0; + top: 200px; + text-align: center; + opacity: 0; + transition: opacity .35s ease; +} + +.button a { + width: 200px; + padding: 12px 48px; + text-align: center; + background-color: #94dbd7; + border-radius: 120px; + text-decoration: none; + color: #ffffff; + font-weight: bold; + z-index: 1; +} + +.button a:hover { + background-color: #429a95; +} diff --git a/app/assets/stylesheets/homepage.scss b/app/assets/stylesheets/homepage.scss new file mode 100644 index 0000000000..be430e4cfe --- /dev/null +++ b/app/assets/stylesheets/homepage.scss @@ -0,0 +1,45 @@ +// Place all the styles related to the homepage controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +// .landing_page{ +// padding: 110px; +// // display: flex; +// // flex-direction: column; +// } + +img{ + width: 350px; + height: 350px; + margin-right: 5vw; +} + +.homepage_products{ + display: flex; + flex-direction: row; + flex-wrap: nowrap; + // justify-content: space-between; + overflow-x: auto; + + img{ + flex: 0 0 auto; + } +} + +.scroll{ + display: flex; + flex-direction: row; +} + +.scroll_indicator{ + text-align: center; + line-height: 350px; + color: grey; +} + +.fa{ + font-size:30px +} + +article:nth-of-type(1), article:nth-of-type(2){ + padding-bottom: 70px; +} diff --git a/app/assets/stylesheets/items.scss b/app/assets/stylesheets/items.scss new file mode 100644 index 0000000000..1ddc17c1d8 --- /dev/null +++ b/app/assets/stylesheets/items.scss @@ -0,0 +1,136 @@ +// Place all the styles related to the items controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + + + + // [converter] extracted a&:hover, a&:focus, a&.active to a.thumbnail:hover, a.thumbnail:focus, a.thumbnail.active + + // Image captions + +.container { + display: grid; + grid-template-columns: .2fr 8fr; + grid-template-rows: 1fr 1fr 1fr 1fr 1fr; +} + +.item-image { + grid-row-start: 1; + grid-row-end: 7; + grid-column-start: 1; + grid-column-end: 2; + margin-right: 1em; + padding: 0; + text-align: center; + display: flex; + justify-content: center; + flex-direction: row; + align-items: center; +} + + +.item-info { + grid-row-start: 1; + grid-row-end: 6; + grid-column-start: 2; + grid-column-end: 3; + background-color: #ffd2d5; + margin: 0; + padding: 2em; + border-radius: 2em; +} + +.category-tag { + grid-row-start: 1; + grid-row-end: 2; + grid-column-start: 2; + grid-column-end: 3; + width: 10em; + padding: 5px 20px; + text-align: center; + background-color: #94dbd7; + border-radius: 120px; + text-decoration: none; + color: #ffffff; + font-weight: bold; + z-index: 1; +} + +.item-name { + grid-row-start: 2; + grid-row-end: 3; + grid-column-start: 2; + grid-column-end: 3; + margin-top: .5em; + color: #772f33; +} + +.item-name h2 { + font-weight: bold; + font-size: 3em; +} + +.price h3 { + color: #2a58a3; + font-size: .7em; + font-weight: bold; +} + +.description p { + font-size: 1.5em; + line-height: 1.5em; +} + +.price { + grid-row-start: 3; + grid-row-end: 4; + grid-column-start: 2; + grid-column-end: 3; + color: white; + font-weight: bold; + font-size: 2em; + font-style: italic; + margin-top: .5em; + margin-bottom: .5em; +} + +.description { + grid-row-start: 4; + grid-row-end: 5; + grid-column-start: 2; + grid-column-end: 3; +} + +.quantities { + grid-row-start: 5; + grid-row-end: 6; + grid-column-start: 2; + grid-column-end: 3; + width: 100%; + margin-top: 1.5em; + margin-bottom: 1.5em; +} + +.availability { + color: red; +} + + +.form-group .btn { + background-color: #fb8d96; + width: 100%; + grid-row-start: 6; + grid-row-end: 7; + grid-column-start: 2; + grid-column-end: 3; + padding: .7em; + border-radius: 2em; + border: none; + margin-top: 1em; + color: white; + font-weight: bold; +} + +.form-group .btn:hover { + background-color: #ab4652; +} diff --git a/app/assets/stylesheets/merchant_pending_orders.scss b/app/assets/stylesheets/merchant_pending_orders.scss new file mode 100644 index 0000000000..c4e3153605 --- /dev/null +++ b/app/assets/stylesheets/merchant_pending_orders.scss @@ -0,0 +1,18 @@ +.pending_order{ + border: .5px solid lightgrey; + margin-bottom: 15px; +} + +.pending_order{ + display: flex; + flex-direction: row; +} + +.item_info{ + margin-right: 30px; + width: 30vw; +} + +.customer_info{ + width: 30vw; +} diff --git a/app/assets/stylesheets/orderitems.scss b/app/assets/stylesheets/orderitems.scss new file mode 100644 index 0000000000..3ae284dd37 --- /dev/null +++ b/app/assets/stylesheets/orderitems.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..fbc876350c --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,60 @@ +// 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/ +h1{ + color: black; + padding-bottom: 30px; + padding-top: 30px; +} +.cart_thumbnail{ + height: 100px; + width: 100px; +} + +#cart{ + display: flex; + flex-direction: column; + // padding-left: 110px; +} + +.item_display{ + display: flex; + flex-direction: row; + height: 200px; + width: 800px; + border: .5px solid lightgray; + padding: 30px; +} + +.item_details{ + // padding-right: 60px; + width: 250px; +} + +input[type=text]{ + width: 60px; +} + +input[type=submit]{ + font-size: 12px; + background-color: grey; + color: black; +} + +.item_subtotal{ + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.column{ + margin-right: 60px; + +} + +.subtotal{ + width: 800px; + text-align: right; + padding-top: 20px; + padding-right: 40px; +} diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..7bef9cf826 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/status.scss b/app/assets/stylesheets/status.scss new file mode 100644 index 0000000000..afa26e37d7 --- /dev/null +++ b/app/assets/stylesheets/status.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the status controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..478ad55b78 --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,9 @@ +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +section .user-profile { + display: grid; + grid-template-areas: + "user-pic user-pic" + "user-product user-product"; +} 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..ebdc820c01 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,57 @@ + +class ApplicationController < ActionController::Base + + + before_action :find_current_user + before_action :find_all_merchants + before_action :current_order + # before_action :require_login, except: :index + + private + + def find_current_user + @current_user = User.find_by(id: session[:user_id]) + # else + # @guest_user = #allocated guest or User.find_by() + # end + end + + #find all merchants + # @merchants = User.where(products: []) + #find all merchants + def find_all_merchants + active_products = Item.where(active: true) + + distinct_merchant_objects = active_products.select(:user_id).distinct + @merchant_ids = distinct_merchant_objects.map do |merchant| + merchant.user_id + end + + return @merchant_ids + + end + + def require_login + unless @current_user + flash[:error] = "You must be logged in to do that." + redirect_to root_path + end + end + + def current_order + + if session[:order_id] + + # Order.find_by(id: session[:order_id]) + @current_shopper_order_id = session[:order_id] + + else + new_order = Order.create + + session[:order_id] = new_order.id + @current_shopper_order_id = session[:order_id] + # raise + end + end + +end diff --git a/app/controllers/category_controller.rb b/app/controllers/category_controller.rb new file mode 100644 index 0000000000..58cd7a1d87 --- /dev/null +++ b/app/controllers/category_controller.rb @@ -0,0 +1,8 @@ +class CategoryController < ApplicationController + def show + category_id = params[:id] + @category = Category.find_by(id: category_id) + @items_in_category = Item.where(active: true, category_id: category_id) + + 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/homepage_controller.rb b/app/controllers/homepage_controller.rb new file mode 100644 index 0000000000..ad19d5f208 --- /dev/null +++ b/app/controllers/homepage_controller.rb @@ -0,0 +1,5 @@ +class HomepageController < ApplicationController + def index + @newest = Item.order(created_at: :desc).take(5) + end +end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb new file mode 100644 index 0000000000..cbedd70960 --- /dev/null +++ b/app/controllers/items_controller.rb @@ -0,0 +1,89 @@ +class ItemsController < ApplicationController + before_action :find_searched_item, only: [:show, :edit, :update, :destroy, :find_item_category] + before_action :find_item_category, only: [:show] + + def index + @items = Item.all + end + + def edit + end + + def new + @item = Item.new() + end + + def create + # @item = Item.new(user_id: @current_user.id) + @item = Item.new(item_params) + + if @current_user + @item.user_id = @current_user.id + end + + save_success = @item.save + + if save_success + flash[:success] = "Item #{@item.name} successfully saved." + redirect_to shop_path + else + flash.now[:error] = "Item was not saved." + render :new, status: :bad_request + end + end + + def destroy + in_order = OrderItem.find_by(item_id: @item.id) + + + if in_order + flash[:error] = "Item cannot be deleted. There is a pending order with this item" + # redirect_back (fallback_location: root_path) + redirect_back(fallback_location: root_path) + else + success = @item.destroy + flash[:success] = "Item successfully deleted." + redirect_back(fallback_location: root_path) + end + end + + + def show + head :not_found unless @item + @order = Order.find_by(id: session[:order_id]) + end + + def update + success_save = @item.update(item_params) + + if success_save + flash[:success] = "Item successfully updated." + redirect_to shop_path + else + flash.now[:error] = "Error in updating product" + render :edit, status: 400 + end + end + + private + + def item_params + return params.require(:item).permit( + :name, + :category_id, + :price, + :quantity_available, + :description, + :image, + :active + ) + end + + def find_searched_item + @item = Item.find_by(id: params[:id]) + end + + def find_item_category + @item_category = Category.find(@item.category_id).category_type + end +end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb new file mode 100644 index 0000000000..8adaab2eda --- /dev/null +++ b/app/controllers/order_items_controller.rb @@ -0,0 +1,79 @@ +class OrderItemsController < ApplicationController + + def create + + order_id = session[:order_id].to_i + item_id = params[:item_id].to_i + + @order_item = OrderItem.new(status: "pending", quantity_per_item: params[:quantity_per_item].to_i, order_id: order_id, item_id: item_id) + + if @order_item.save + + # session[:order_id] = @order.id + flash[:success] = "Item successfully added to your cart!" + redirect_to order_path(order_id) + + else + flash.now[:error] = "Order item contains bad data." + redirect_to item_path(item_id), status: :bad_request + end + + end + + + def update + @order = Order.find_by(id: session[:order_id]) + @order_item = @order.order_items.find_by(id: params[:id]) + + success = @order_item.update(quantity_per_item: params[:quantity_per_item]) + + if success + flash[:success] = "Item successfully updated." + redirect_to order_path(@order) + else + flash.now[:error] = "Invalid order item data" + redirect_to order_path(@order) + end + end + + + def increment_quantity + @order = Order.find_by(id: session[:order_id]) + @order_item = @order.order_items.find_by(item_id: params[:item_id]) + @item = Item.find_by(id: @order_item.item_id) + + additional_quantity = params[:quantity_per_item].to_i + + new_quantity = @order_item.quantity_per_item + additional_quantity + + if new_quantity > @item.quantity_available + flash[:error] = "Whoops! You already have a few of these babies in your cart and we only have #{@item.quantity_available} available. Please check your quantity and try again." + redirect_to order_path(@order) + else + success = @order_item.update(quantity_per_item: new_quantity) + if success + flash[:success] = "Item quantity updated." + redirect_to order_path(@order) + end + end + + end + + + def destroy + + @order = Order.find_by(id: session[:order_id]) + @order_item = @order.order_items.find(params[:id]) + + + success = @order_item.destroy + + if success + flash[:success] = "Item successfully deleted." + redirect_to order_path(@order) + end + end + + + +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..f839ed115e --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,62 @@ +class OrdersController < ApplicationController + + def show + current_order = Order.find_by(id: params[:id]) + # @order_items = @current_order.order_items + + @order_items = OrderItem.where(order_id: current_order.id) + # @order_items = current_order.order_items + end + + #fill out order details + def edit + @order = Order.find_by(id: params[:id]) + end + + #submit order button + def update + + @order = Order.find_by(id: params[:id]) + + successful = @order.update(parsed_order_data(order_params)) + + #to do --> MOVE logic into instance method in Order + # @order.order_items.each do |order_item| + # order_item.submit_order_item + # end + @order.submit_order + + if successful + #clear session data + temp_id = session[:order_id] + session[:order_id] = nil + flash[:success] = "Thank you for your order. Order confirmation number: #{@order.id}. Please save this number to view your order status. Disclaimer: This site is for demonstration purposes only." + redirect_to status_path(temp_id) + else + + flash.now[:error] = "Error in submitting order." + render :edit, status: 400 + end + end + + private + + def order_params + return params.require(:order).permit( + :name, + :email, + :mailing_address, + :name_on_card, + :credit_card_num, + :credit_card_exp_year, + :credit_card_exp_month, + :cvv_num, + :zipcode + ) + end + + def parsed_order_data(order_params) + return { name: order_params[:name], email: order_params[:email], mailing_address: order_params[:mailing_address], name_on_card: order_params[:name_on_card], credit_card_num: order_params[:credit_card_num], credit_card_exp_year: order_params[:credit_card_exp_year], credit_card_exp_month: order_params[:credit_card_exp_month], status: "paid" + } + end +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..8e580cedff --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,62 @@ + +class ReviewsController < ApplicationController +# +# +# def new +# @review = Review.new +# end +# +# def create +# +# # session[:user_id] != @current_user ? can_review = true : can_review = false +# # if can_review +# @review = Review.new( +# description: params[:review][:description], +# rating:params[:review][:rating], +# item_id: params[:item_id], +# user_id: 3 +# ) +# +# +# @review.save +# +# flash[:sucess] = "Thank you for your review!" +# redirect_to items_path(@item) +# +# +# end +# +# def edit +# end +# +# def show +# head :not_found unless @review +# end +# +# def update +# +# success_save = @review.update( +# description: params[:review][:description], +# rating:params[:review][:rating], +# item_id: params[:id], +# user_id: session[:user_id] +# ) +# +# if success_save +# flash[:success] = "Review of #{@item.name} successfully reviewed." +# redirect_to shop_path +# else +# flash.now[:error] = "Error in reviewing product" +# render :edit, status: 400 +# end +# end +# +# def filtered_params +# +# return params.require(:review).permit( +# :description, +# :rating, +# :item_id sessions[:item_id] +# :user_id session[:user_id] +# ) +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..f0df2d1920 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,38 @@ +class SessionsController < ApplicationController + def create + auth_hash = request.env['omniauth.auth'] + # raise + user = User.find_by(uid: auth_hash[:uid], provider: auth_hash[:provider]) + + + if user + session[:user_id] = user.id + else + new_user = User.new( + name: auth_hash['info']['name'], + nickname: auth_hash['info']['nickname'], + email: auth_hash['info']['email'], + image_url: auth_hash['info']['image'], + uid: auth_hash['uid'], + provider: auth_hash['provider'], + created_at: Time.now + ) + + if new_user.save + session[:user_id] = new_user.id + flash[:success] = "Successfully logged in" + else + flash[:error] = "Unable to log in" + redirect_to root_path + return + end + end + redirect_to root_path + + end + + def logout + session[:user_id] = nil + redirect_to root_path + end +end diff --git a/app/controllers/status_controller.rb b/app/controllers/status_controller.rb new file mode 100644 index 0000000000..dcb761d024 --- /dev/null +++ b/app/controllers/status_controller.rb @@ -0,0 +1,61 @@ +class StatusController < ApplicationController + def findform + end + + # post route + def detail + @order = Order.find_by(id: params[:id]) + orderitems = OrderItem.where(order_id: params[:id]) + ids_items_purchased = orderitems.map do |item| + item.item_id + end + + quantity_per_item = orderitems.map do |item| + item.quantity_per_item + end + + items_purchased = [] + ids_items_purchased.each do |id| + item = Item.find_by(id: id) + items_purchased << item + end + + @order_info = {} + + index = 0 + while index < items_purchased.length do + @order_info[items_purchased[index]] = quantity_per_item[index] + index += 1 + end + + end + + # get route + def show + @order = Order.find_by(id: params[:id]) + orderitems = OrderItem.where(order_id: params[:id]) + + ids_items_purchased = orderitems.map do |item| + item.item_id + end + + quantity_per_item = orderitems.map do |item| + item.quantity_per_item + end + + items_purchased = [] + ids_items_purchased.each do |id| + item = Item.find_by(id: id) + items_purchased << item + end + + @order_info = {} + + index = 0 + while index < items_purchased.length do + @order_info[items_purchased[index]] = quantity_per_item[index] + index += 1 + end + + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..9f42061d9d --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,93 @@ +class UsersController < ApplicationController + #remove shop from below filter once conenct user_login + before_action :find_searched_user, only: [:show] + before_action :find_current_user_unfulfilled_items, only: [:shop] + + #user profile / merchant page that is visible to all + def show + head :not_found unless @user + # render 'layouts/invalid_page', status: :not_found + end + + #merchant view that is visible to just merchants + def shop + unless @current_user + flash[:error] = "You need to sign up to create a shop." + redirect_to root_path + return + end + end + + def merchant_pending_orders + # @testing = "Shoe" + current_merchant = session[:user_id] +# raise + items_sold_by_merchant = find_items_sold_by_merchant(current_merchant) + item_ids = items_sold_by_merchant.map do |item| + item.id + end + + @pending_order_items = [] + item_ids.each do |x| + order_items = OrderItem.where(item_id: x) + + order_items.each do |order_item| + @pending_order_items << order_item + end + end + + end + + def paid + order_item_id = params[:item_id] + order_item = OrderItem.find_by(id: order_item_id) + order_item.status = "shipped" + order_item.save + redirect_back(fallback_location: root_path) + end + + private + + #strong params + def user_params + return params.require(:user).permit( + :name, + :nickname, + :email, + :image_url, + :uid, + :provider + ) + end + + def find_searched_user + @user = User.find_by(id: params[:id]) + end + + #helper method to find items this user sells + def find_current_user_items + if @current_user + return @current_user.items + end + end + + def find_current_user_unfulfilled_items + + @current_user_items = find_current_user_items + + if @current_user_items.nil? || @current_user_items.empty? + return + end + + @current_merchant_unfulfilled_order_items = @current_user_items.map do |item| + OrderItem.where(item_id: item.id) && OrderItem.where(status: "ordered") + end + @current_merchant_unfulfilled_order_items.flatten! + end + + + def find_items_sold_by_merchant(merchant_id) + items = Item.where(user_id: merchant_id) + return items + 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/category_helper.rb b/app/helpers/category_helper.rb new file mode 100644 index 0000000000..ac5cb5bf58 --- /dev/null +++ b/app/helpers/category_helper.rb @@ -0,0 +1,2 @@ +module CategoryHelper +end diff --git a/app/helpers/homepage_helper.rb b/app/helpers/homepage_helper.rb new file mode 100644 index 0000000000..c5bbfe518f --- /dev/null +++ b/app/helpers/homepage_helper.rb @@ -0,0 +1,2 @@ +module HomepageHelper +end diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb new file mode 100644 index 0000000000..67107a0554 --- /dev/null +++ b/app/helpers/items_helper.rb @@ -0,0 +1,3 @@ +module ItemsHelper + +end diff --git a/app/helpers/orderitems_helper.rb b/app/helpers/orderitems_helper.rb new file mode 100644 index 0000000000..c74e407d1c --- /dev/null +++ b/app/helpers/orderitems_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..e0be9c1b9b --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,4 @@ +module OrdersHelper + + +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/status_helper.rb b/app/helpers/status_helper.rb new file mode 100644 index 0000000000..fc2a6e1cc7 --- /dev/null +++ b/app/helpers/status_helper.rb @@ -0,0 +1,2 @@ +module StatusHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000..a009ace51c --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..286b2239d1 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..10a4cba84d --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..7d27fd493c --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,3 @@ +class Category < ApplicationRecord + has_many :items +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/item.rb b/app/models/item.rb new file mode 100644 index 0000000000..ea964c9a5d --- /dev/null +++ b/app/models/item.rb @@ -0,0 +1,61 @@ +class Item < ApplicationRecord + belongs_to :user + has_many :reviews + belongs_to :category + has_many :order_items + + VALID_CATEGORIES = ["accessories", "books", "clothing", "seasonal", "luggage", "shoes", "tech", "miscellaneous"] + + validates :name, presence: true, uniqueness: { + scope: [:user, :category], message: "User: has already added this item in this category. Please change item inventory." + } + + validates :price, presence: true + validates :quantity_available, presence: true + + + def decrement_quantity_available(num) + if num + self.quantity_available -= num + self.save + end + end + + + # guest login is set to 0 + # def is_authenticated_user? + # session[:user_id] != 0 ? true: false + # return + # end + + # user created the product + # def user_created_product? + # if session[:user_id] == @self.user_id ? user_created = true: false + # return user_created + # end + # end + + + + def return_quantity_selection + + iterations = self.quantity_available + + quantity_options = [] + + iterations.times do |number| + quantity_options << number + 1 + end + + return quantity_options + end + + + def item_subtotal(price,qty) + item_subtotal = price * qty + + return item_subtotal + end + + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..fcb7c06db1 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,38 @@ +class Order < ApplicationRecord + # belongs_to :user + has_many :order_items + + VALID_MONTHS = (01..12).to_a + + attr_reader :valid_years + + validate :validate_years, on: :update + + validates_inclusion_of :credit_card_exp_month, :in => VALID_MONTHS, message: "Please enter a valid month.", on: :update + + validates :credit_card_exp_year, :in => @valid_years, on: :update + + validates :order_items, length: { minimum: 1 }, on: :update + + def submit_order + if !self.order_items.empty? + self.status = "paid" + self.order_items.each do |order_item| + order_item.submit_order_item + end + end + end + + private + + def self.valid_years + two_digit_date = Date.today.year % 1000 + @valid_years = (two_digit_date .. two_digit_date + 8).to_a + return @valid_years + end + + def validate_years + valid_years = Order.valid_years + errors.add("Credit cared exp year", "is invalid.") unless valid_years.include?(self.credit_card_exp_year) + end +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..ca0562a305 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,30 @@ +class OrderItem < ApplicationRecord + belongs_to :order + belongs_to :item + validates :item_id, presence: true + validates :order_id, presence: true + + validates :quantity_per_item, presence: true, numericality: { only_integer: true, greater_than: 0 } + + + def submit_order_item + + item = Item.find_by(id: self.item_id) + if item + item.decrement_quantity_available(self.quantity_per_item) + #change order item status + self.status = "paid" + self.save + end + end + + def find_item_name(num) + item = Item.find_by(id: num) + if item + item_name = item.name + return item_name + end + end + + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..92f0e762ce --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,7 @@ +class Review < ApplicationRecord + belongs_to :item + belongs_to :user + # + # validates :rating, presence: true + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..eaaca43e4a --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,22 @@ +class User < ApplicationRecord + has_many :items + # has_many :orders + has_many :reviews + + validates :nickname, presence: true, uniqueness: { + scope: :provider, message: "User: username already exists for this provider. Please login or reset password." + } + + validates :email, presence: true, uniqueness: true + + # def self.build_from_github(auth_hash) + # user = User.new(provider: auth_hash['provider'], uid: auth_hash['uid'], nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], email: auth_hash['info']['email'], image_url: auto_hash['info']['image']) + # end + +#accepts user_ids from applicationcontroller @merchant_ids +#returns true if this instance of a user has a product/ is a merchant +# @current_user.is_a_merchant?(@merchant_ids) + def is_a_merchant?(given_ids) + return given_ids.include?(self.id) + end +end diff --git a/app/views/category/show.html.erb b/app/views/category/show.html.erb new file mode 100644 index 0000000000..2b92e21f0f --- /dev/null +++ b/app/views/category/show.html.erb @@ -0,0 +1,26 @@ +
+ +

+ <%= @category.category_type.capitalize %> +

+ +
+ <% @items_in_category.each do |item| %> + +
+ <%= item.name %> + +

<%= item.name %>

+ +
+ +
+ <%= link_to "Details", item_path(item.id) %> +
+ +
+ + <% end %> +
+ +
diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb new file mode 100644 index 0000000000..7aea2641cf --- /dev/null +++ b/app/views/homepage/index.html.erb @@ -0,0 +1,47 @@ +
+
+

Newest Arrivals

+
+
+ suitcase + suitcase + suitcase + suitcase +
+
+ +
+
+ +
+ +
+

Featured Products

+
+
+ book + book + book + book +
+
+ +
+
+
+ +
+

Staff Favorites

+
+
+ phone_case + phone_case + phone_case + phone_case +
+
+ +
+
+
+
diff --git a/app/views/items/_item_form.html.erb b/app/views/items/_item_form.html.erb new file mode 100644 index 0000000000..9b1592ad38 --- /dev/null +++ b/app/views/items/_item_form.html.erb @@ -0,0 +1,24 @@ +<%= render partial: 'layouts/form_errors', +locals: { + model: @item +} +%> + +<%= form_with model: @item, method: verb, :url => pathway do |f| %> + +<%= f.label :Name %>
+<%= f.text_field :name %>
+<%= f.label :price %>
+<%= f.text_field :price %>
+<%= f.label :quantity_available %>
+<%= f.text_field :quantity_available %>
+<%= f.label :image_url %>
+<%= f.text_field :image %>
+<%= f.label :active %>
+<%= f.text_field :active %>
+<%= f.label :category_id %>
+<%= collection_select :item, :category_id, Category.all, :id, :category_type, {}, {:multiple => false} %>
+<%= f.label :description %>
+<%= f.text_area :description %> +<%= f.submit action_type, class: "item-form-submit-button" %> +<% end %> diff --git a/app/views/items/edit.html.erb b/app/views/items/edit.html.erb new file mode 100644 index 0000000000..3e89c84ac5 --- /dev/null +++ b/app/views/items/edit.html.erb @@ -0,0 +1,11 @@ +

Edit Your Product

+ + +<%= render partial: "item_form", +locals: { + action_type: "Submit Changes", + form_title: "Submit Changes", + verb: :patch, + pathway: item_path + } +%> diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb new file mode 100644 index 0000000000..cb113aad07 --- /dev/null +++ b/app/views/items/index.html.erb @@ -0,0 +1,20 @@ +
+

All Items

+
+ + +<% @items.each do |item| %> + + + class="img-thumbnail, item_show" > +<%= item.name %> +<%= item.price %> +<%= item.quantity_available %> +<%= item.avg_rating %> +<%= item.description %> +
+
+<% end %> + + + diff --git a/app/views/items/new.html.erb b/app/views/items/new.html.erb new file mode 100644 index 0000000000..42b6fe0ba2 --- /dev/null +++ b/app/views/items/new.html.erb @@ -0,0 +1,10 @@ +

Add a New Product

+ +<%= render partial: 'item_form', +locals: { + action_type: "Submit", + form_title: "New!", + verb: :post, + pathway: items_path + } +%> diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb new file mode 100644 index 0000000000..7bf6e2f149 --- /dev/null +++ b/app/views/items/show.html.erb @@ -0,0 +1,75 @@ +
+ +
> +
+ +
+ +
+ <%= @item_category %> +
+ +
+

<%= @item.name %>

+
+ +
+

$<%= '%.2f' % @item.price %>

+

+ +
+

<%= @item.description %>

+
+ +
+ + <% if @order.order_items.find_by(item_id: @item.id).nil? %> + + <%= form_with model: @order_item, method: :post, :url => item_order_items_path(@item.id) do |f| %> + + +
+ <%= f.label "Quantity:" %> + + (<%= @item.quantity_available %> available) + + + <%= f.select :quantity_per_item, @item.return_quantity_selection, {}, class: "form-control" %> +
+ +
+ <%= f.submit "Add to Cart", class: "btn btn-light" %> +
+ + <% end %> + <% else %> + + <%= form_with model: @order_item, method: :patch, :url => item_increment_quantity_path(@item.id) do |f| %> + +
+ <%= f.label "Quantity:" %> + + (<%= @item.quantity_available %> available) + + <%= f.select :quantity_per_item, @item.return_quantity_selection, {}, class: "form-control" %> +
+ +
+ <%= f.submit "Add to Cart", class: "btn btn-light" %> +
+ + + <% end %> + + + <% end %> + + + + +
+ + +
+ +
diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb new file mode 100644 index 0000000000..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..595788435c --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,131 @@ + + + + + Betsy + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + + + +
+
+ +
+ +

Kawaii Travel Shop

+ + +
+ +
+
+ <% flash.each do |key_word, message| %> +
<%=message%>
+ <% 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/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000000..a64d4d13e3 --- /dev/null +++ b/app/views/orders/edit.html.erb @@ -0,0 +1,38 @@ +

Checkout

+ +<%= render partial: 'layouts/form_errors', +locals: { + model: @order +} +%> + +<%= form_with model: @order, class: 'item-form' do |f| %> + + + + <%= f.label :Name %> + <%= f.text_field :name %> + <%= f.label :email %> + <%= f.text_field :email %> + <%= f.label :mailing_address %> + <%= f.text_field :mailing_address %> + +

Billing Information:

+ + <%= f.label :name_on_card %> + <%= f.text_field :name_on_card %> + <%= f.label :credit_card_num %> + <%= f.text_field :credit_card_num %> + <%= f.label :credit_card_exp_month%> + <%= f.select :credit_card_exp_month, selections: Order::VALID_MONTHS %> + <%= f.label :credit_card_exp_year %> + <%= f.select :credit_card_exp_year, selections: Order.valid_years %> + <%= f.label :cvv_num %> + <%= f.text_area :cvv_num %> + <%= f.label :zipcode %> + <%= f.text_area :zipcode %> + + <%= f.submit "Submit", class: "btn btn-success" %> + + +<% end %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..f80f2f87e8 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,46 @@ + + +
+ + <% cart_subtotal = [] %> + +

Shopping Cart

+ + <% @order_items.order('created_at').each do |item| %> +
+ +
+ <% x = Item.find_by(id: item.item_id) %> + <%= x.name%>
+ <%= x.description %>
+ <%= link_to "Remove", order_item_path(item.id), method: :delete, data: { confirm: "are you sure you want to delete this item?" } %> +
+ +
+
+ Qty: <%= item.quantity_per_item %> + + <%= form_with model: @order_item, method: :patch, :url => order_item_path(item.id) do |f| %> + <%= f.select :quantity_per_item, x.return_quantity_selection %>
+ <%= f.submit "update quantity" %> + <% end %> +
+
+ Item Price: $<%= '%.2f' % x.price %> +
+
+ <% item_sub = x.item_subtotal(x.price, item.quantity_per_item) %> + <% cart_subtotal << item_sub %> + Total: $<%= '%.2f' % item_sub %> +
+ +
+ +
+ <% end %> +
+

Subtotal: $<%= '%.2f' % cart_subtotal.sum %>


+ +
+ +
diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..4553af61ef --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,9 @@ +<%= form_with model: @review do |f| %> + <%= f.label :rating %> + <%= f.select :rating, [1,2,3,4,5] %> + <%= f.label :description %> + <%= f.text_area :description %> + + <%= f.submit %> +<% end %> + diff --git a/app/views/status/detail.html.erb b/app/views/status/detail.html.erb new file mode 100644 index 0000000000..bc7f9a3c29 --- /dev/null +++ b/app/views/status/detail.html.erb @@ -0,0 +1,14 @@ +

Order Details

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

The order number you entered does not exist

+ +<% else %> + +

Order Date: <%= @order.created_at.strftime("%B %d, %Y") %>

+ + <% @order_info.each do |item, qty| %> + Qty: <%= qty %>, <%= item.name %>
+ <% end %> + +<% end %> diff --git a/app/views/status/findform.html.erb b/app/views/status/findform.html.erb new file mode 100644 index 0000000000..9ec331b31a --- /dev/null +++ b/app/views/status/findform.html.erb @@ -0,0 +1,8 @@ +

View Previous Order

+ +

Please enter Order Confirmation Number:

+ +<%= form_with url: detail_path do |form| %> + <%= form.text_field :id %> + <%= form.submit "Submit" %> +<% end %> diff --git a/app/views/status/show.html.erb b/app/views/status/show.html.erb new file mode 100644 index 0000000000..802bdbdbe1 --- /dev/null +++ b/app/views/status/show.html.erb @@ -0,0 +1,11 @@ +

Order Details

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

The order number you entered does not exist

+<% else %> +

Order Date: <%= @order.created_at.strftime("%B %d, %Y") %>

+ + <% @order_info.each do |item, qty| %> + Qty: <%= qty %>, <%= item.name %>
+ <% end %> +<% end %> diff --git a/app/views/users/merchant_pending_orders.html.erb b/app/views/users/merchant_pending_orders.html.erb new file mode 100644 index 0000000000..9198c1af7b --- /dev/null +++ b/app/views/users/merchant_pending_orders.html.erb @@ -0,0 +1,34 @@ + +
+

Manage Orders

+ + <% count = 1 %> + <% @pending_order_items.each do |order_item|%> + + <%= count %> + +
+
+
Item Information
+ Order Date: <%= order_item.created_at.strftime("%B %d, %Y") %>
+ Item Name: <%= order_item.find_item_name(order_item.item_id) %>
+ Qty Ordered: <%= order_item.quantity_per_item %>
+ Status: <%= order_item.status %>
+ + <%= link_to "Mark as Shipped", paid_path(order_item.id), method: :post %> + +
+ + +
+
Customer Information:
+ <% order = Order.find_by(id: order_item.order_id) %> + Name: <%= order.name %>
+ Email: <%= order.email %>
+ Address: <%= order.mailing_address %>
+ +
+
+ <% count += 1 %> + <% end %> +
diff --git a/app/views/users/shop.html.erb b/app/views/users/shop.html.erb new file mode 100644 index 0000000000..e70b7cbff8 --- /dev/null +++ b/app/views/users/shop.html.erb @@ -0,0 +1,66 @@ +
+ +
+ <%= image_tag "#{@current_user.image_url}", alt: "user image", title: "#{@current_user.name}'s profile pic", style: 'float:right;'%> + + +
+ + <%if @current_user.is_a_merchant?(@merchant_ids)%> +
+

<%=@current_user.name%>'s Shop

+
+
    +
  • <%=link_to "Add New Product", new_item_path%>
  • +
  • <%= link_to "Manage Orders", pending_path %>
  • +
+ <% count = 1 %> +
    + <%@current_user_items.each do |item| %> +
  • <%= count %>. For sale: <%=item.name%><%= link_to "(details)", item_path(item)%><%= link_to "(edit)", edit_item_path(item)%><%= link_to "(delete)", item_path(item), method: :delete, data: { confirm: "Are you sure you want to delete this product: #{item.name}? You have #{item.quantity_available} of them"} %>
  • +
  • Stock: <%=item.quantity_available%>
  • +
  • Price: $<%= '%.2f' % item.price%>
  • +
  • Category: <%=item.category_id%>
  • +

    ---------------------------------------

    + <% count +=1 %> + <% end %> +
+
+
+ + +
+ + + +
+
    + +
  • <% @current_merchant_unfulfilled_order_items.each do |order_item| %> +
  • Item Name<%=Item.find_by(id: order_item.item_id).name%>
  • +
  • Num Ordered: <%=order_item.quantity_per_item %>
  • +
  • Customer Name: <%=Order.find_by(id: order_item.order_id).name%>
  • +
  • Customer Address: <%=Order.find_by(id: order_item.order_id).mailing_address%>
  • + <% end %> + + +
+
+ + +
+ + + <%else%> +
+

Create your first product in your shop!

+

<%= link_to "Add Product", new_item_path %>

+
+ <%end%> + +
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000000..8fdae0cba4 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,16 @@ +
+
+
+ <%= image_tag "#{@user.image_url}", alt: "user image", title: "#{@user.name}'s profile'" %> +
+
+

<%=@user.name%>'s Shop

+

Product List

+
    + <%@user.items.each do |item| %> +
  • For sale: <%=item.name%><%= link_to "(view)", item_path(item)%>
  • + <% 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..f5c513e0a3 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +EZewcexkKXzfxCJnxJ42QJHtPtFIr6ttF3k/Dn2tBxMuhH+11uugdWZi45l18hSXqJEi6Xx5d8+kB1OlQbUf8+jetufAO6tZge5jQalqgZAqsgaL4YEvrKV/bSD/EOplqq//m9IIjPceD3BR7j43Vts8T90lyMpQohM9LowJ+dfAwYg3zpTodYisKLz1NwWYYC8X3Vuc3MV+WVQqRAYV9mfXE9X/+oomu9svAq0Zx66+GGMqXnfS+WbJA+z9yLZQyZ7vW+eRNOcdW92rQaSEqvTkx1O5akTYXWEdzAmE75QmbvrqUGBM3brOAsZMzlZy3VTLoeXJQBGhw3RGWORq/0Fp3p/CAX7WPUwCzmUp3X2bFzDgembJaopXobAFNgYpm2IET68pazL53U2eC2KYf8IQaV2mLGJ2G6rT--5Nz0OdRHNlc7y/Pw--H65G7tvuiWtt3wbZkM0Rzg== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..6903bb6083 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: betsy_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: betsy + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: betsy_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: betsy_production + username: betsy + password: <%= ENV['BETSY_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000..426333bb46 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000000..1311e3e4ef --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,61 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000000..5f6f3058c6 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,94 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "betsy_#{Rails.env}" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000000..0a38fd3ce9 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,46 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb new file mode 100644 index 0000000000..142d382f87 --- /dev/null +++ b/config/initializers/action_view.rb @@ -0,0 +1 @@ +Rails.application.config.action_view.form_with_generates_remote_forms = false diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000000..89d2efab2b --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..4b828e80cb --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000..59385cdf37 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000000..d3bcaa5ec8 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000000..5a6a32d371 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..4a994e1e7b --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000000..ac033bf9dc --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000000..dc1899682b --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..fd4416122a --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000..bbfc3961bf --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000000..decc5a8573 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000000..a5eccf816b --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000000..9802be21c4 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,29 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root 'homepage#index' + get "/status/findform", to: 'status#findform' + get "/status/:id", to: 'status#show', as: 'status' + post "/status/detail", to: 'status#detail', as: 'detail' + + get "users/pending", to: 'users#merchant_pending_orders', as: 'pending' + post "/users/:item_id/paid", to: 'users#paid', as: 'paid' + + # resources :status + resources :users, only: [:show, :shop, :orders] + resources :orders, :items, :reviews, :category + + resources :order_items, only: [:update, :destroy] + + + resources :items do + post '/order_items', to: 'order_items#create' + patch 'order_items', to: 'order_items#increment_quantity', as: 'increment_quantity' + + resources :reviews + end + +get "/auth/:provider/callback", to: "sessions#create", as: 'auth_callback' +post '/logout', to: 'sessions#logout', as: 'logout' + +get '/shop', to: 'users#shop', as: 'shop' +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/item_seeds.csv b/db/item_seeds.csv new file mode 100644 index 0000000000..d7d2f42bda --- /dev/null +++ b/db/item_seeds.csv @@ -0,0 +1,20 @@ +price,image,quantity_available,name,description,avg_rating,user_id,active,category_id +70,https://i.pinimg.com/236x/c3/62/9b/c3629b93a61797063ac2372ac7e63f29--liz-lisa-carry-bag.jpg,3,Sakura,20-inch hardside spinner luggage for weekend getaways or as international carry-on,4,2,true,5 +140,http://inhonorofdesign.com/wp-content/uploads/2015/01/Mint-Steamline-Luggage1.jpg,5,Steamline,Fully lined interior with divider; compression pad helps free up space; 150D-polyester interior organizer with 3 zippered pockets for securing smaller items,3,2,true,5 +100,https://rlv.zcache.com/custom_kawaii_cute_summer_tropical_pineapples_luggage-r086ff13689a94b06807ab730fe879e7e_64fbv_540.jpg?rlvnet=1,2,Globe Trotter,SMOOTH-ROLLING airflow multi-directional spinner wheels for easy movement,4,2,true,5 +30,https://i.ebayimg.com/images/g/wD0AAOSw5UVbaZD0/s-l640.jpg,5,Lets Go Pikachu Suitcase Cover,Now any boring suitcase can look amazing and bright thanks to this suitcase cover. The cover is stretchy so that it fits snug around your suitcase and it will keep your handles and wheels available for use so it just makes you suitcase look so much more fun,4,2,true,5 +40,https://i.etsystatic.com/14018434/r/il/874991/1231114367/il_570xN.1231114367_rn04.jpg,2,Travel Buddy Babadook,Cause if it's in a word or if it's in a book you can't get rid of the Babadook...Never travel alone,4,2,true,4 +25,https://www.icing.com/dw/image/v2/BBTK_PRD/on/demandware.static/-/Sites-master-catalog/default/dwbffc1c23/images/icing/hi-res/72623_1.jpg?sw=734&sh=734&sm=fit,3,Black Cat Sleep Mask,Get some rest while you travel,3,2,true,4 +60,https://cdn.shopify.com/s/files/1/0758/2735/products/TB1slR3JVXXXXbsXVXXXXXXXXXX__0-item_pic.jpg?v=1534937389,10,Bowsii MJ,Delightfully dressy Mary Janes for your next tea paaarrrtte,0,1,true,6 +50,https://d1nr5wevwcuzuv.cloudfront.net/product_photos/32510889/T2Gs20XaFaXXXXXXXX_!!12789126_original.jpg,10,Playful Rabbit,Cute and retro for your next kawaii adventure,0,1,true,6 +45,https://cdn.shopify.com/s/files/1/2420/5055/products/product-image-240638197_800x.jpg?v=1530833053,10,Mint Ice Dreamy,Carry summer with you everywhere you go with these ice cream cone patterned casual sneaks,0,1,true,6 +60,http://a2.fanbread.com/uploads/image/file/15212/extra_large_shoes_9.jpg?5a2ae58d6f9a919141d9ab57cc9d7de8,10,Pony Chops,Chantal over at Pony-Chops hand painted these cosplay shoes for a kawaii obsessed friend,0,2,true,6 +40,https://d3u67r7pp2lrq5.cloudfront.net/product_photos/25592829/181_original.jpg,10,Lolita Lace,Time to play dress up with your besties,0,2,true,6 +15,https://d2h1pu99sxkfvn.cloudfront.net/b0/4472065/369738546_TKOLSyoflE/P0.jpg,20,Little Twin Stars lanyard,Let the Twin Stars keep your travel pass safe,0,2,true,8 +20,https://www.picclickimg.com/d/l400/pict/271995172532_/JETOY-Choo-Choo-Cat-Petit-Transparent-Passport-Cover.jpg,20,Choo Choo Cat Passport,Let Choo Choo Cat lead your next adventure and keep your passport,0,3,true,8 +15,https://images-na.ssl-images-amazon.com/images/I/51FEWy6IpeL.jpg,10,Critter Luggage Tag,Kawaii Critter Tags to identify your luggage,0,4,true,8 +20,http://g01.a.alicdn.com/kf/HTB1hMJRMXXXXXXFXXXXq6xXFXXXC/Creative-kawaii-rhinestone-monchichi-keychain-doll-pendant-car-key-ring-women-handbag-bag-charm-key-chains.jpg,10,Monchichi ChiChain,Monchichi is sweet to hold in your hands with your keys,0,4,true,8 +40,https://78.media.tumblr.com/d003d0b62268bc4007d25eb14836c6f2/tumblr_mr529nSuCQ1s9dgawo1_500.jpg,10,Sparkly Pepper,Protect yourself during your travels with this stylin pepper spray,0,4,true,8 +20,http://poesprints.com/wp-content/uploads/2018/08/raven_blanket.jpg,4,Raven Travel Blanket,Quoth the raven...sleep some more!,4,3,true,4 +15,https://encrypted-tbn0.gstatic.com/shopping?q=tbn:ANd9GcT5ifb7wyonvmIXNSB1uoX5kzP1py_LPgP-hbDqVHilZ5JD52Tj1CyplU00aKiv6-NZ7FSpv3MJfuCNwNihuokXFtGM9_SVFIcefJmf2lHzo1v6z9L9A4G4&usqp=CAE,2,Home For the Holidays Krampus Luggage Tag,Kick off the holiday season early with this festive luggage tag.,4,2,true,4 +5,https://images-na.ssl-images-amazon.com/images/I/41LZf3WrtBL.jpg,2,Spooky Ghosty Stress Relief Squishy,This friendly little ghost is super soft and squeezeable. The perfect fiddle toy for easing some take off and landing jitters.,4,2,true,4 diff --git a/db/migrate/20181018212109_create_users.rb b/db/migrate/20181018212109_create_users.rb new file mode 100644 index 0000000000..3a8f4217f1 --- /dev/null +++ b/db/migrate/20181018212109_create_users.rb @@ -0,0 +1,14 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.integer :uid + t.string :name + t.string :nickname + t.string :email + t.string :image_url + t.string :provider + + t.timestamps + end + end +end diff --git a/db/migrate/20181018212627_create_orders.rb b/db/migrate/20181018212627_create_orders.rb new file mode 100644 index 0000000000..d273f0c0fa --- /dev/null +++ b/db/migrate/20181018212627_create_orders.rb @@ -0,0 +1,18 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :name + t.string :email + t.string :mailing_address + t.string :name_on_card + t.integer :credit_card_num + t.integer :credit_card_exp_month + t.integer :credit_card_exp_year + t.integer :cvv_num + t.integer :zipcode + + + t.timestamps + end + end +end diff --git a/db/migrate/20181018213306_create_items.rb b/db/migrate/20181018213306_create_items.rb new file mode 100644 index 0000000000..c729acf1c4 --- /dev/null +++ b/db/migrate/20181018213306_create_items.rb @@ -0,0 +1,15 @@ +class CreateItems < ActiveRecord::Migration[5.2] + def change + create_table :items do |t| + t.string :category + t.integer :price + t.string :image + t.integer :quantity_available + t.string :name + t.string :description + t.integer :avg_rating + + t.timestamps + end + end +end diff --git a/db/migrate/20181018213354_create_reviews.rb b/db/migrate/20181018213354_create_reviews.rb new file mode 100644 index 0000000000..4c50e6ab91 --- /dev/null +++ b/db/migrate/20181018213354_create_reviews.rb @@ -0,0 +1,10 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.string :description + t.integer :rating + + t.timestamps + end + end +end diff --git a/db/migrate/20181018214111_delete_uid.rb b/db/migrate/20181018214111_delete_uid.rb new file mode 100644 index 0000000000..d52b82ecf6 --- /dev/null +++ b/db/migrate/20181018214111_delete_uid.rb @@ -0,0 +1,5 @@ +class DeleteUid < ActiveRecord::Migration[5.2] + def change + remove_column :users, :uid + end +end diff --git a/db/migrate/20181018214131_add_uid_to_users.rb b/db/migrate/20181018214131_add_uid_to_users.rb new file mode 100644 index 0000000000..f36704e564 --- /dev/null +++ b/db/migrate/20181018214131_add_uid_to_users.rb @@ -0,0 +1,5 @@ +class AddUidToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :uid, :integer, null:false + end +end diff --git a/db/migrate/20181018214412_delete_provider_from_users.rb b/db/migrate/20181018214412_delete_provider_from_users.rb new file mode 100644 index 0000000000..875862d5de --- /dev/null +++ b/db/migrate/20181018214412_delete_provider_from_users.rb @@ -0,0 +1,5 @@ +class DeleteProviderFromUsers < ActiveRecord::Migration[5.2] + def change + remove_column :users, :provider + end +end diff --git a/db/migrate/20181018214431_add_provider_to_users.rb b/db/migrate/20181018214431_add_provider_to_users.rb new file mode 100644 index 0000000000..3f58d0f1a1 --- /dev/null +++ b/db/migrate/20181018214431_add_provider_to_users.rb @@ -0,0 +1,5 @@ +class AddProviderToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :provider, :string, null:false + end +end diff --git a/db/migrate/20181018214642_add_status_shipped_to_order.rb b/db/migrate/20181018214642_add_status_shipped_to_order.rb new file mode 100644 index 0000000000..22b11c61ff --- /dev/null +++ b/db/migrate/20181018214642_add_status_shipped_to_order.rb @@ -0,0 +1,6 @@ +class AddStatusShippedToOrder < ActiveRecord::Migration[5.2] + def change + add_column :orders, :status, :string, default: "pending" + add_column :orders, :shipped, :boolean, default: false + end +end diff --git a/db/migrate/20181018215000_create_order_items.rb b/db/migrate/20181018215000_create_order_items.rb new file mode 100644 index 0000000000..0e744b51f7 --- /dev/null +++ b/db/migrate/20181018215000_create_order_items.rb @@ -0,0 +1,8 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20181018215031_delete_shipped_orders.rb b/db/migrate/20181018215031_delete_shipped_orders.rb new file mode 100644 index 0000000000..fc818b7024 --- /dev/null +++ b/db/migrate/20181018215031_delete_shipped_orders.rb @@ -0,0 +1,5 @@ +class DeleteShippedOrders < ActiveRecord::Migration[5.2] + def change + remove_column :orders, :shipped + end +end diff --git a/db/migrate/20181018215159_add_customer_to_order.rb b/db/migrate/20181018215159_add_customer_to_order.rb new file mode 100644 index 0000000000..833fdfe640 --- /dev/null +++ b/db/migrate/20181018215159_add_customer_to_order.rb @@ -0,0 +1,5 @@ +class AddCustomerToOrder < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :user, foreign_key: true + end +end diff --git a/db/migrate/20181018215421_add_shipped_to_orderitem.rb b/db/migrate/20181018215421_add_shipped_to_orderitem.rb new file mode 100644 index 0000000000..8493fb60fa --- /dev/null +++ b/db/migrate/20181018215421_add_shipped_to_orderitem.rb @@ -0,0 +1,5 @@ +class AddShippedToOrderitem < ActiveRecord::Migration[5.2] + def change + add_column :order_items, :shipped, :boolean, default:false + end +end diff --git a/db/migrate/20181018215601_add_order_and_item_orderitem.rb b/db/migrate/20181018215601_add_order_and_item_orderitem.rb new file mode 100644 index 0000000000..a6f2fa1b05 --- /dev/null +++ b/db/migrate/20181018215601_add_order_and_item_orderitem.rb @@ -0,0 +1,6 @@ +class AddOrderAndItemOrderitem < ActiveRecord::Migration[5.2] + def change + add_reference :order_items, :order, foreign_key: true + add_reference :order_items, :item, foreign_key: true + end +end diff --git a/db/migrate/20181018215915_add_user_to_item.rb b/db/migrate/20181018215915_add_user_to_item.rb new file mode 100644 index 0000000000..fb8251f1dd --- /dev/null +++ b/db/migrate/20181018215915_add_user_to_item.rb @@ -0,0 +1,5 @@ +class AddUserToItem < ActiveRecord::Migration[5.2] + def change + add_reference :items, :user, foreign_key: true + end +end diff --git a/db/migrate/20181018220049_add_active_to_item.rb b/db/migrate/20181018220049_add_active_to_item.rb new file mode 100644 index 0000000000..24f53330ee --- /dev/null +++ b/db/migrate/20181018220049_add_active_to_item.rb @@ -0,0 +1,5 @@ +class AddActiveToItem < ActiveRecord::Migration[5.2] + def change + add_column :items, :active, :boolean, default: true + end +end diff --git a/db/migrate/20181018220256_add_user_and_item_to_reviews.rb b/db/migrate/20181018220256_add_user_and_item_to_reviews.rb new file mode 100644 index 0000000000..e126811966 --- /dev/null +++ b/db/migrate/20181018220256_add_user_and_item_to_reviews.rb @@ -0,0 +1,6 @@ +class AddUserAndItemToReviews < ActiveRecord::Migration[5.2] + def change + add_reference :reviews, :user, foreign_key: true + add_reference :reviews, :item, foreign_key: true + end +end diff --git a/db/migrate/20181019232117_add_quantity_to_orderitems.rb b/db/migrate/20181019232117_add_quantity_to_orderitems.rb new file mode 100644 index 0000000000..76dce75ade --- /dev/null +++ b/db/migrate/20181019232117_add_quantity_to_orderitems.rb @@ -0,0 +1,5 @@ +class AddQuantityToOrderitems < ActiveRecord::Migration[5.2] + def change + add_column :order_items, :quantity_per_item, :integer + end +end diff --git a/db/migrate/20181020154501_create_categories.rb b/db/migrate/20181020154501_create_categories.rb new file mode 100644 index 0000000000..c489422c78 --- /dev/null +++ b/db/migrate/20181020154501_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.2] + def change + create_table :categories do |t| + t.string :type + + t.timestamps + end + end +end diff --git a/db/migrate/20181020155307_change_type_column_for_category.rb b/db/migrate/20181020155307_change_type_column_for_category.rb new file mode 100644 index 0000000000..a86b3bfb26 --- /dev/null +++ b/db/migrate/20181020155307_change_type_column_for_category.rb @@ -0,0 +1,5 @@ +class ChangeTypeColumnForCategory < ActiveRecord::Migration[5.2] + def change + remove_column :categories, :type + end +end diff --git a/db/migrate/20181020155504_add_item_type_to_category.rb b/db/migrate/20181020155504_add_item_type_to_category.rb new file mode 100644 index 0000000000..872a551bbe --- /dev/null +++ b/db/migrate/20181020155504_add_item_type_to_category.rb @@ -0,0 +1,5 @@ +class AddItemTypeToCategory < ActiveRecord::Migration[5.2] + def change + add_column :categories, :category_type, :string + end +end diff --git a/db/migrate/20181020161333_delete_category_from_items.rb b/db/migrate/20181020161333_delete_category_from_items.rb new file mode 100644 index 0000000000..8399d40182 --- /dev/null +++ b/db/migrate/20181020161333_delete_category_from_items.rb @@ -0,0 +1,5 @@ +class DeleteCategoryFromItems < ActiveRecord::Migration[5.2] + def change + remove_column :items, :category + end +end diff --git a/db/migrate/20181020161500_add_category_foreign_key_items.rb b/db/migrate/20181020161500_add_category_foreign_key_items.rb new file mode 100644 index 0000000000..ae4ff19456 --- /dev/null +++ b/db/migrate/20181020161500_add_category_foreign_key_items.rb @@ -0,0 +1,5 @@ +class AddCategoryForeignKeyItems < ActiveRecord::Migration[5.2] + def change + add_reference :items, :category, foreign_key: true + end +end diff --git a/db/migrate/20181021014223_delete_user_id_from_order.rb b/db/migrate/20181021014223_delete_user_id_from_order.rb new file mode 100644 index 0000000000..6b9fd6ba96 --- /dev/null +++ b/db/migrate/20181021014223_delete_user_id_from_order.rb @@ -0,0 +1,5 @@ +class DeleteUserIdFromOrder < ActiveRecord::Migration[5.2] + def change + remove_column :orders, :user_id + end +end diff --git a/db/migrate/20181023214234_delete_shipped_from_order_item.rb b/db/migrate/20181023214234_delete_shipped_from_order_item.rb new file mode 100644 index 0000000000..b30190b92f --- /dev/null +++ b/db/migrate/20181023214234_delete_shipped_from_order_item.rb @@ -0,0 +1,5 @@ +class DeleteShippedFromOrderItem < ActiveRecord::Migration[5.2] + def change + remove_column :order_items, :shipped + end +end diff --git a/db/migrate/20181023214436_add_status_to_orderitem.rb b/db/migrate/20181023214436_add_status_to_orderitem.rb new file mode 100644 index 0000000000..cf640c41ae --- /dev/null +++ b/db/migrate/20181023214436_add_status_to_orderitem.rb @@ -0,0 +1,5 @@ +class AddStatusToOrderitem < ActiveRecord::Migration[5.2] + def change + add_column :order_items, :status, :string, default: "pending" + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..014836aaeb --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,94 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2018_10_23_214436) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "category_type" + end + + create_table "items", force: :cascade do |t| + t.integer "price" + t.string "image" + t.integer "quantity_available" + t.string "name" + t.string "description" + t.integer "avg_rating" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.boolean "active", default: true + t.bigint "category_id" + t.index ["category_id"], name: "index_items_on_category_id" + t.index ["user_id"], name: "index_items_on_user_id" + end + + create_table "order_items", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "order_id" + t.bigint "item_id" + t.integer "quantity_per_item" + t.string "status", default: "pending" + t.index ["item_id"], name: "index_order_items_on_item_id" + t.index ["order_id"], name: "index_order_items_on_order_id" + end + + create_table "orders", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "mailing_address" + t.string "name_on_card" + t.integer "credit_card_num" + t.integer "credit_card_exp_month" + t.integer "credit_card_exp_year" + t.integer "cvv_num" + t.integer "zipcode" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "status", default: "pending" + end + + create_table "reviews", force: :cascade do |t| + t.string "description" + t.integer "rating" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.bigint "item_id" + t.index ["item_id"], name: "index_reviews_on_item_id" + t.index ["user_id"], name: "index_reviews_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "nickname" + t.string "email" + t.string "image_url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "uid", null: false + t.string "provider", null: false + end + + add_foreign_key "items", "categories" + add_foreign_key "items", "users" + add_foreign_key "order_items", "items" + add_foreign_key "order_items", "orders" + add_foreign_key "reviews", "items" + add_foreign_key "reviews", "users" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..a2821178ab --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,79 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create( +#[ +# { name: 'Star Wars' }, +# { name: 'Lord of the Rings' } +# ] +#) +# Character.create(name: 'Luke', movie: movies.first) + +require 'csv' + +#loading constants +USER_FILE = Rails.root.join('db', 'user_seeds.csv') +puts "Loading raw data from #{USER_FILE}" + + +ITEM_FILE = Rails.root.join('db', 'item_seeds.csv') +puts "Loading raw data from #{ITEM_FILE}" + + +############################################################# +#seeding categories +x = ["accessories", "books", "clothing", "seasonal", "luggage", "shoes", "tech", "miscellaneous"] +x.each do |category| + Category.create(category_type: category) +end +############################################################## + +############################################################## +#seeding users +user_failures = [] +CSV.foreach(USER_FILE, :headers => true) do |row| + + user = User.new + user.name = row['name'] + user.nickname = row['nickname'] + user.email = row['email'] + user.image_url = row['image_url'] + user.uid = row['uid'] + user.provider = row['provider'] + successful = user.save + if !successful + user_failures << user + puts "Failed to save user: #{user.inspect}" + else + puts "Created user: #{user.inspect}" + end +end +############################################################## + + +#Seeding items + +item_failures = [] +CSV.foreach(ITEM_FILE, :headers => true) do |row| + + item = Item.new + item.price = row['price'] + item.image = row['image'] + item.quantity_available = row['quantity_available'] + item.name = row['name'] + item.description = row['description'] + item.avg_rating = row['provider'] + item.user_id = row['user_id'] + item.active = row['active'] + item.category_id = row['category_id'] + + successful = item.save + if !successful + item_failures << item + puts "Failed to save item: #{item.inspect}" + else + puts "Created item: #{item.inspect}" + end +end diff --git a/db/user_seeds.csv b/db/user_seeds.csv new file mode 100644 index 0000000000..d127654ae7 --- /dev/null +++ b/db/user_seeds.csv @@ -0,0 +1,5 @@ +name,nickname,email,image_url,uid,provider +jen,jen_is_cool,jen@gmail.com,https://goo.gl/4usQGd,991,aim +doug,doug-donut,doug@gmail.com,https://goo.gl/DBLsc9,992,aim +jazz,jazzed,jazz@gmail.com,https://bit.ly/2R5zhBa,993,aim +layla,layayala,laya@gmail.com,https://plbz.it/2pZTSeB,994,aim diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json new file mode 100644 index 0000000000..f874acf437 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "betsy", + "private": true, + "dependencies": {} +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000000..2be3af26fc --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

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

+
+

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

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

The change you wanted was rejected.

+

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

+
+

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

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

We're sorry, but something went wrong.

+
+

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

+
+ + diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000000..37b576a4a0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/controllers/category_controller_test.rb b/test/controllers/category_controller_test.rb new file mode 100644 index 0000000000..c93b7df14e --- /dev/null +++ b/test/controllers/category_controller_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +describe CategoryController do + # it "must be a real test" do + # flunk "Need real tests" + # end + it 'responds with success if the category exists' do + luggage_category = categories(:luggage) + + get category_path(luggage_category.id) + + must_respond_with :success + end +end diff --git a/test/controllers/homepage_controller_test.rb b/test/controllers/homepage_controller_test.rb new file mode 100644 index 0000000000..7f76c0fe4d --- /dev/null +++ b/test/controllers/homepage_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +describe HomepageController do + it 'should get index' do + get root_path + must_respond_with :success + end +end diff --git a/test/controllers/items_controller_test.rb b/test/controllers/items_controller_test.rb new file mode 100644 index 0000000000..5b071bd925 --- /dev/null +++ b/test/controllers/items_controller_test.rb @@ -0,0 +1,158 @@ +require "test_helper" + +describe ItemsController do + + before do + @linda = users(:one) + end + + describe 'index' do + + it "succeeds when there are items" do + get items_path + must_respond_with :success + end + + end + + describe "show" do + + it "responds with success for showing an existing product" do + + test_item = items.first + id = test_item.id + + get item_path(id) + + must_respond_with :success + end + + end + + describe "new" do + + it "successful new page" do + + get new_item_path + + must_respond_with :success + end + + end + + let (:logged_in_linda) { + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(@linda)) + + get auth_callback_path(:github) + } + + describe "create" do + + it "creates an item with valid data for a real logged in user and real category" do + + logged_in_linda + # @current_user = @linda + + item_data = { + item: + { + name: "A BRAND NEW THING", + category_id: Category.first.id, + price: 100, + quantity_available: 100 + } + } + test_item = Item.new(item_data[:item]) + + expect { + post items_path, params: item_data + + }.must_change('Item.count', +1) + + must_redirect_to shop_path + end + + it "renders bad_request and does not update the DB for bogus data" do + + logged_in_linda + # @current_user = @linda + + item_data = { + item: + { + name: "A BRAND NEW THING", + category_id: Category.first.id + } + } + + test_item = Item.new(item_data[:item]) + + expect { + post items_path, params: item_data + }.wont_change 'Item.count' + + must_respond_with :bad_request + assert_equal "Item was not saved.", flash[:error] + end + + end + + + describe "edit" do + + it "responds with success for an existing item" do + get edit_item_path(Item.first) + + must_respond_with :success + end + + + # Can't figure this one out :( + # describe "update" do + # + # it "successful update displays flash and redirects" do + # test_item = Item.create(name: "name", + # category: Category.first, + # user: User.first, + # price: 10, + # quantity_available: 10) + # + # expect {test_item.update(name: "changed name")}.must_route_to shop_path + # # expect flash[:success].must_equal "Item successfully updated." + # end + +end + +describe 'destroy' do + + it 'destroy an existing item' do + item = Item.create(name: "SOOO Unique", category: Category.first, user: User.first, price: 10, quantity_available: 10) + # testing the database change + expect { + delete item_path(item) + }.must_change('Item.count', -1) + # testing the flash message + expect flash[:success].must_equal "Item successfully deleted." + # testing the path + must_redirect_to root_path + end + + it 'will not destroy an item that is part of an OrderItem' do + @item = items(:shoes) + @order = orders(:one) + @new_order_item = OrderItem.create(order_id: @order.id, item_id: @item.id) + + item_count = Item.count + + delete item_path(@item) + # database not changed + expect(Item.count).must_equal item_count + # flash error appears + flash[:error].must_equal "Item cannot be deleted. There is a pending order with this item" + # redirect back + must_redirect_to root_path + 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..94a795a70a --- /dev/null +++ b/test/controllers/order_items_controller_test.rb @@ -0,0 +1,84 @@ +require "test_helper" +require "pry" + +describe OrderItemsController do + + describe "create" do + + it "can create an order item with good data" do + + order_item_data = { + item_id: Item.first.id, + order_id: Order.first.id, + quantity_per_item: 1 + } + + new_order_item = OrderItem.new(order_item_data) + + new_order_item.must_be :valid?, "Data was invalid. Please come fix this test." + + expect { + post item_order_items_path(Item.first.id), + params: order_item_data + }.must_change('OrderItem.count', +1) + + end + + it "does not create a new order item with bad data" do + + order_item_data = { + item_id: Item.first.id, + order_id: Order.first.id, + quantity_per_item: nil + } + + OrderItem.new(order_item_data).wont_be :valid?, "Data wasn't invalid. Please come fix this test." + + expect { + post item_order_items_path(Item.first.id), + params: order_item_data + }.wont_change('OrderItem.count') + + end + end + + # describe "update" do + # + # it "can update an item's quantity" do + # + # @order = Order.first + # @order_item = OrderItem.first + # + # start_count = @order_item.quantity_per_item + # + # order_item_data = { + # quantity_per_item: @order_item.quantity_per_item + 1 + # } + # + # expect { + # patch order_item_path(@order_item.id), + # params: order_item_data + # }.must_change('start_count') + # + # end + # end + + # describe "destroy" do + # + # it "can destroy an existing order item" do + # start_count = OrderItem.count + # + # orderitem = OrderItem.create( + # item_id: Item.first.id, + # order_id: Order.first.id, + # quantity_per_item: 1 + # ) + # + # delete order_item_path(orderitem.id) + # + # expect(OrderItem.count).must_equal start_count + # + # 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..21d162e99a --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,121 @@ +require "test_helper" + +describe OrdersController do + + before do + @pending = orders(:one) + @pending.credit_card_exp_month = Date.today.month + @pending.credit_card_exp_year = Date.today.year % 1000 + + @empty = Order.new + + @paid = orders(:two) + + @shipped = orders(:three) + @shipped.credit_card_exp_month = Date.today.month + @shipped.credit_card_exp_year = Date.today.year % 1000 + + @linda = users(:one) + end + + describe 'show' do + it "succeeds for an exisiting order" do + get order_path(@pending) + must_respond_with :success + end + end + + # def edit + # + # @order = Order.find_by(id: params[:id]) + # end + + let (:logged_in_linda) { + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(@linda)) + + get auth_callback_path(:github) + } + + describe 'edit' do + + it "will allow a guest user to access/edit their own order" do + current_order = Order.create + # controller.session[:order_id] = new_order.id + # session[:order_id] = new_order.id + # session.update + # binding.pry + # Session.new(order_id: 1) + + get order_path(current_order) + + expect(current_order.order_items.empty?).must_equal true + must_respond_with :success + end + + it "will allow a logged in user to access/edit their own order" do + logged_in_linda + + get order_path(session[:order_id]) + must_respond_with :success + end + end + + describe 'update' do + it 'will redirect to status_path and save valid order info' do + skip + logged_in_linda + + starting_session = session[:order_id] + order = Order.find_by(id: session[:order_id].to_i) + order.credit_card_exp_year = (Date.today.year % 1000) + 1 + order.credit_card_exp_month = Date.today.month + + order_item = order_items(:orderitem3) + order_item.order_id = order.id + order_item.save + + updated_year = (Date.today.year % 1000) + 7 + + order_data = { + order: { + credit_card_exp_year: updated_year + } + } + + put order_path(session[:order_id]), params: order_data + + ending_session = session[:order_id] + + updated_order = Order.find_by(id: order.id) + + # expect(starting_session).wont_equal ending_session + + # assert_equal flash[:success], "Thank you for your order. Order confirmation number: #{this_order.id}. Please save this number to view your order status. Disclaimer: This site is for demonstration purposes only." + + must_redirect_to status_path(order.id) + # + # assert_equal updated_year, order.credit_card_exp_year + # assert_equal updated_month, order.credit_card_exp_month + end + + it 'will render the page again status for bad request' do + skip + end + + it 'will change the status of the order to paid' do + skip + end + + it 'will change the status of all orderitems to paid' do + skip + end + + it 'will decrement the items according to quantity_per_item ' do + skip + end + + it 'will clear out session[:order_id]' do + skip + 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..386065239a --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ReviewsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..3dcf0dedb1 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,44 @@ +require 'test_helper' + +describe SessionsController do + describe 'auth_callback' do + it 'logs in an existing user and redirects to root route' do + start_count = User.count + + person = users(:june) + + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(person)) + + get auth_callback_path(:github) + + must_redirect_to root_path + session[:user_id].must_equal person.id + User.count.must_equal start_count + end + + it "creates an account for a new user and redirects to the root route" do + start_count = User.count + new_user = User.new(provider: "github", uid: 99999, name: "test_user", nickname: "test_user_nickname", email: "test@user.com") + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(new_user)) + + get auth_callback_path(:github) + + must_redirect_to root_path + User.count.must_equal start_count + 1 + session[:user_id].must_equal User.last.id + end + + # it 'invalid user data cannot log in' do + # start_count = User.count + # + # invalid_new_user = User.new(provider: "github", uid: 1, name: "test_user", nickname: "test_user_nickname", email: "test@user.com") + # + # OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(invalid_new_user)) + # + # get auth_callback_path(:github) + # + # User.count.must_equal start_count + # flash[:error].must_equal "Unable to log in" + # end + end +end diff --git a/test/controllers/status_controller_test.rb b/test/controllers/status_controller_test.rb new file mode 100644 index 0000000000..5b2f3a9bbe --- /dev/null +++ b/test/controllers/status_controller_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +describe StatusController do + before do + @item = items(:shoes) + @order = orders(:one) + @new_order_item = OrderItem.create(order_id: @order.id, item_id: @item.id) + end + + it 'will load a form to find an order' do + get status_findform_path + + must_respond_with :success + end + + it 'responds with success if the order exists' do + post detail_path + + must_respond_with :success + end + + it 'responds with success if the order exists' do + get status_path(@order.id) + + must_respond_with :success + end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..af6768ac0d --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,103 @@ +require "test_helper" + +describe UsersController do + # it "must be a real test" do + # flunk "Need real tests" + # end + + before do + @linda = users(:one) + @john = users(:two) + @june = users(:june) + end + + describe "show" do + it "succeeds for an exisiting user / merchant with items" do + + get user_path(@linda) + must_respond_with :success + end + + it "succeeds for an exisiting user / merchant without items" do + + get user_path(@june) + must_respond_with :success + end + + it "renders 404 not_found for a non exiting user" do + + get user_path(0) + must_respond_with :not_found + end + end + + let (:logged_in_merchant) { + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(@linda)) + + get auth_callback_path(:github) + } + + let (:logged_in_user) { + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(@june)) + + get auth_callback_path(:github) + } + + describe "shop" do + it "succeeds for a logged in user / merchant with items" do + # skip + + logged_in_merchant + + expect(session[:user_id]).must_equal @linda.id + + get shop_path(@linda) + must_respond_with :success + end + + it "succeeds for an exisiting user / merchant without items" do + + logged_in_user + + expect(session[:user_id]).must_equal @june.id + + get shop_path(@june) + must_respond_with :success + end + + it "redirects with flash error message for a non exiting user" do + + get shop_path(0) + must_redirect_to root_path + assert_equal 'You need to sign up to create a shop.', flash[:error] + end + end + + describe 'User#merchant pending orders and User#paid' do + + let (:logged_in_user) { + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(@linda)) + + get auth_callback_path(:github) + } + + it 'succeeds if a merchant has a pending order' do + logged_in_user + + get pending_path + must_respond_with :success + end + + it 'changes the status of an order to shipped'do + @item = items(:shoes) + @order = orders(:one) + @new_order_item = OrderItem.create(order_id: @order.id, item_id: @item.id, quantity_per_item: 3) + + post paid_path(@new_order_item.id) + find_shipped_order_item = OrderItem.find_by(status: "shipped") + + expect(find_shipped_order_item.id).must_equal @new_order_item.id + must_respond_with :redirect + 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..2164e77cdb --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +luggage: + category_type: luggage + +shoes: + category_type: shoes diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/items.yml b/test/fixtures/items.yml new file mode 100644 index 0000000000..cbe000492f --- /dev/null +++ b/test/fixtures/items.yml @@ -0,0 +1,22 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +suitcase: + category: luggage + price: 150 + image: https://i03.hsncdn.com/is/image/HomeShoppingNetwork/prodgrid230/joy-lightweight-nylon-tufftech-luxury-pinstripe-3-piece-d-20180208141055963~590535_2L0.jpg + quantity_available: 4 + name: Maroon Case + description: A bunch of suitcases + avg_rating: 3 + user: two + + +shoes: + category: shoes + price: 40 + image: https://cdn.shopify.com/s/files/1/0758/2735/products/TB2FjLqdmFmpuFjSZFrXXayOXXa__40028512_1024x1024_88870111-fda4-4eb0-9fef-963934c180e6.jpg?v=1510932598 + quantity_available: 2 + name: Bunny Shoes + description: Cute bunny shoes + avg_rating: 4 + user: one diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..5f3dc8dcd2 --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,24 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +orderitem1: + order: one + item: shoes + quantity_per_item: 1 + status: pending + +orderitem2: + order: one + item: suitcase + quantity_per_item: 1 + status: pending + +orderitem3: + order: two + item: suitcase + quantity_per_item: 2 + status: pending + +orderitem3: + order: one + item: suitcase + quantity_per_item: 3 + status: pending diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..f0fede9adc --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,37 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + email: MyString + mailing_address: MyString + name_on_card: MyString + credit_card_num: 1 + credit_card_exp_month: 0 + credit_card_exp_year: 0 + cvv_num: 1 + zipcode: 1 + status: pending + +two: + name: MyString + email: MyString + mailing_address: MyString + name_on_card: MyString + credit_card_num: 1 + credit_card_exp_month: 0 + credit_card_exp_year: 0 + cvv_num: 1 + zipcode: 1 + status: paid + +three: + name: MyString + email: MyString + mailing_address: MyString + name_on_card: MyString + credit_card_num: 1 + credit_card_exp_month: 0 + credit_card_exp_year: 0 + cvv_num: 1 + zipcode: 1 + status: shipped diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..cc113aebf0 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +good: + description: It's great + rating: 5 + user: one + item: luggage + +bad: + description: Terrible, just terrible + rating: 1 + user: two + item: shoes diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..b328aa8f96 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,25 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + uid: 1 + name: Linda + nickname: linda-lucy + email: linda-lucy@gmail.com + image_url: https://www.gstatic.com/webp/gallery3/2.sm.png + provider: github + +two: + uid: 2 + name: John + nickname: john-johnny + email: john-johnny@gmail.com + image_url: https://www.gstatic.com/webp/gallery/4.sm.jpg + provider: Gmail + +june: + uid: 3 + name: june + nickname: june-juny + email: june-juny@gmail.com + image_url: https://www.gstatic.com/webp/gallery3/1.sm.png + provider: Gmail diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..781320ad8e --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new } + + it "must be valid" do + value(category).must_be :valid? + end +end diff --git a/test/models/item_test.rb b/test/models/item_test.rb new file mode 100644 index 0000000000..4c3f639039 --- /dev/null +++ b/test/models/item_test.rb @@ -0,0 +1,159 @@ +require "test_helper" + +describe Item do + + + #relation tests: an order has many items, a category has many items + + describe 'relations' do + + it 'an item belongs to a category' do + + category = Item.first.category + + expect category.must_be_kind_of Category + end + + it 'an item belongs to a user' do + + user = Item.first.user + expect user.must_be_kind_of User + end + + end + + describe 'validations' do + + before do + @user_one = Item.first.user + @category_one = Category.first + @category_two = Category.first + + # no name + @nameless_item = Item.new( + name: nil, + category: @category_one, + price: 40, + quantity_available: 2, + user: @user_one + + ) + # no price + @priceless_item = Item.new( + name: 'no price', + category: @category_one, + price: nil, + quantity_available: 3, + user: @user_one + + ) + # no quantitiy + @quantityless_item = Item.new( + name: 'no quantitiy', + category: @category_one, + price: 30, + quantity_available: nil, + user: @user_one + ) + # same name, same qty, same category (duplicate) + + @thing_one = Item.new( + name: 'twin', + category: @category_one, + price: 30, + quantity_available: 2, + user: @user_one + ) + + @thing_two = Item.new( + name: 'twin', + category: @category_one, + price: 30, + quantity_available: 2, + user: @user_one + ) + + # same everything diff category is valid + + @same_name_diff_cat = Item.new( + name: 'cat', + category: Category.first, + price: 30, + quantity_available: 3, + user: @user_one + ) + + @diff_cat = Item.new( + name: 'cat', + category: Category.first, + price: 30, + quantity_available: 3, + user: @user_one + ) + end + + it 'is valid when title, category, and price is present' do + @valid_item = Item.first + is_valid = @valid_item.valid? + expect( is_valid ).must_equal true + + end + + it 'is not valid without a name' do + is_valid = @nameless_item.valid? + expect( is_valid ).must_equal false + + end + + it 'is not valid without a price' do + is_valid = @priceless_item.valid? + expect( is_valid ).must_equal false + end + + it 'is not valid without a quantitiy' do + is_valid = @quantityless_item.valid? + expect( is_valid ).must_equal false + end + + # it 'is not valid with same name, quantity, and price' do + # is_valid = @thing_two.valid? + # expect( is_valid ).must_equal false + # end + + it 'is valid with same name, diff category' do + is_valid = @same_name_diff_cat.valid? + expect ( is_valid ).must_equal true + + end + end + + describe 'decrement_quantity_available(num)' do + + it 'will decrement quantity in instance of item by num' do + valid_item = Item.first + + starting_quant = valid_item.quantity_available + num = 1 + + valid_item.decrement_quantity_available(num) + ending_quant = valid_item.quantity_available + + expect(ending_quant).must_equal starting_quant - num + end + + it 'will not decrement quantity in instance of item if num is nil' do + + valid_item = Item.first + + starting_quant = valid_item.quantity_available + num = nil + + valid_item.decrement_quantity_available(num) + ending_quant = valid_item.quantity_available + + expect(ending_quant).must_equal starting_quant + 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..574d8dcc50 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,148 @@ +require "test_helper" + +describe OrderItem do + + before do + @orderitem1 = order_items(:orderitem1) + @orderitem2 = order_items(:orderitem2) + @orderitem3 = order_items(:orderitem3) + end + + let(:order_item_missing_item) { + OrderItem.create(item: nil, + order: Order.first) + } + + let(:order_item_missing_order) { + OrderItem.create( item: Item.first, + order: nil) + } + + let(:submit_full_order_item) { + @orderitem2.submit_order_item + item = @orderitem2.item + item.decrement_quantity_available(@orderitem2.quantity_per_item) + @orderitem2 + } + + describe 'relations' do + it "has an item" do + expect(@orderitem1).must_respond_to :item + expect(@orderitem1.item).must_be_kind_of Item + end + + it "has an order" do + expect(@orderitem1).must_respond_to :order + expect(@orderitem1.order).must_be_kind_of Order + end + end + + describe 'validations' do + + it "will create a valid orderitem" do + value(@orderitem1).must_be :valid? + end + + it 'wont create a valid order_item if the item is missing' do + + starting_count = OrderItem.count + invalid_order_item = order_item_missing_item + ending_count = OrderItem.count + + expect(ending_count).must_equal starting_count + expect(invalid_order_item.valid?).must_equal false + expect(invalid_order_item.errors.messages).must_include :item, :item_id + end + + it 'wont create a valid order_item if the order is missing' do + + starting_count = OrderItem.count + invalid_order_item = order_item_missing_order + ending_count = OrderItem.count + + expect(ending_count).must_equal starting_count + + expect(invalid_order_item.valid?).must_equal false + expect(invalid_order_item.errors.messages).must_include :order, :order_id + end + end + + describe 'submit_order_item' do + + it 'will change the status to paid if order_item is not nil' do + + starting_item_quantity = @orderitem2.item.quantity_available + quant_to_be_subtracted = @orderitem2.quantity_per_item + expected_final_quant = starting_item_quantity - quant_to_be_subtracted + starting_status = @orderitem2.status + + submitted_order = submit_full_order_item + + ending_status = submitted_order.status + ending_quant = submitted_order.item.quantity_available + + expect(ending_quant).must_equal expected_final_quant + expect(starting_status).must_equal "pending" + expect(ending_status).must_equal "paid" + end + + it 'will not change status if order_items have no items' do + + empty_order = order_item_missing_item + start_stat = empty_order.status + + empty_order.submit_order_item + + end_stat = empty_order.status + + expect(end_stat).must_equal end_stat + end + + + it 'returns the name of an item given the OrderItem id' do + category = categories(:luggage) + user = users(:june) + new_order = Order.create() + + new_item = Item.create(name: "PotatoHead", price: 15, quantity_available: 15, category_id: category.id, user_id: user.id) + + new_orderitem = OrderItem.create(order_id: new_order.id, item_id: new_item.id, quantity_per_item: 1) + + new_orderitem_item_id = new_orderitem.item_id + + item_name = new_orderitem.find_item_name(new_orderitem_item_id) + + expect(item_name).must_equal "PotatoHead" + + end + end + + describe 'find_item_name' do + + it 'returns the name of an item given an item id' do + + @item = items(:shoes) + @order = orders(:one) + @new_order_item = OrderItem.create(order_id: @order.id, item_id: @item.id) + + + item_name = @item.name + find_item_name = @new_order_item.find_item_name(@new_order_item.item_id) + + expect(find_item_name).must_equal item_name + end + + it 'returns the order instance linked to an order_item' do + + @item = items(:shoes) + @order = orders(:one) + @new_order_item = OrderItem.create(order_id: @order.id, item_id: @item.id, quantity_per_item: 4) + + find_order = Order.find_by(id: @new_order_item.order_id) + + expect(find_order).must_equal @order + + end + end + # end + end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..735bb464af --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,101 @@ +require "test_helper" + +describe Order do + before do + @pending = orders(:one) + @pending.credit_card_exp_month = Date.today.month + @pending.credit_card_exp_year = Date.today.year % 1000 + + @empty = Order.new + end + + describe 'relations' do + it "has a list of order_items" do + expect(@pending).must_respond_to :order_items + @pending.order_items.each do |order_item| + expect(order_item).must_be_kind_of OrderItem + end + end + end + + describe 'validations' do + it "will be a valid pending order even if credit card info is missing" do + + expect(@empty.status).must_equal "pending" + expect(@empty.valid?).must_equal true + end + + it 'will not save a valid order when updating without valid month' do + + @pending.update(credit_card_exp_month: 0) + expect(@pending.valid?).must_equal false + end + + it 'will not save a valid order when updating without valid years' do + + @pending.update(credit_card_exp_year: 0) + expect(@pending.valid?).must_equal false + end + + it 'will create a valid order with any order_items' do + + expect(@empty.order_items.length).must_equal 0 + expect(@empty.valid?).must_equal true + end + + it 'will not update an order with any order_items' do + expect(@empty.order_items.length).must_equal 0 + + @empty.update(status: "paid") + expect(@empty.valid?).must_equal false + end + + it 'will update an order with one or more order_items' do + expect(@pending.order_items.length).must_be :>=, 1 + @pending.update(status: "paid") + expect(@pending.valid?).must_equal true + end + end + + describe 'submit_order' do + it 'will change order and order items to pending' do + expect(@pending.order_items.length).must_be :>=, 1 + expect(@pending.status).must_equal "pending" + + item_ids = @pending.order_items.map { |item| item.item_id } + statuses = @pending.order_items.map {|item| item.status}.uniq + expect(statuses.length).must_equal 1 + expect(statuses[0]).must_equal "pending" + + @pending.submit_order + + expect(@pending.status).must_equal "paid" + new_statuses = @pending.order_items.map {|item| item.status}.uniq + expect(new_statuses.length).must_equal 1 + expect(new_statuses[0]).must_equal "paid" + + end + end + + describe 'self.valid_years' do + it 'will an array of length 8 with years' do + valid_years = Order.valid_years + expect(valid_years.length).must_equal 9 + end + it 'will include today\'s date until 8 years from today' do + valid_years = Order.valid_years + first = Date.today.year % 1000 + last = first + 8 + range = (first..last).to_a + + expect(valid_years).must_equal range + end + end + + describe 'self.valid_years' do + it 'will an array of length 8 with years' do + valid_years = Order.valid_years + expect(valid_years.length).must_equal 9 + end + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..e5a3ff8385 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,18 @@ +require "test_helper" + + +# describe Review do +# let(:review) { Review.new } +# +# it "must be valid" do +# value(review).must_be :valid? +# end +# end + +describe Review do + # let(:review) { Review.new } + # + # it "must be valid" do + # value(review).must_be :valid? + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..e44b517f0c --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,139 @@ +require "test_helper" + +describe User do + + before do + @linda = users(:one) + @john = users(:two) + @june = users(:june) + end + + describe 'relations' do + it "has a list of items" do + expect(@linda).must_respond_to :items + @linda.items.each do |item| + expect(item).must_be_kind_of Item + end + end + + it "has a list of reviews" do + expect(@linda).must_respond_to :reviews + #NEED TO GIVE A YAML REVIEW + @linda.must_respond_to :reviews + @linda.reviews.each do |review| + expect(review).must_be_kind_of Review + end + end + end + + let(:dup_user_name_and_provider) { + dup_user = User.create(nickname: "#{@linda.nickname}", provider: "#{@linda.provider}", email: "lisa@yahoo.com", uid: "000" ) + dup_user + } + + let(:dup_user_name_only) { + dup_user = User.create(nickname: "Liam", email: "liam@yahoo.com", uid: "001", provider: "whatever") + dup_user.nickname = @john.nickname + dup_user.provider = "not a dup provider" + dup_user + } + + let(:dup_user_provider_only) { + dup_user = User.create(nickname: "Liam", email: "liam@yahoo.com", uid: "001", provider: "whatever") + dup_user.email = "not a dup email" + dup_user.provider = @john.provider + dup_user + } + + let(:dup_user_email_only) { + dup_user = User.create(nickname: "bad email", email: "#{@john.email}", uid: "002", provider: "whatever1") + dup_user + } + + describe 'validations' do + it 'will create a valid user' do + expect(@linda.valid?).must_equal true + end + + it 'wont create user with duplicate email' do + + starting_count = User.count + + dup_user = dup_user_email_only + + ending_count = User.count + + expect(ending_count).must_equal starting_count + + expect(@john.valid?).must_equal true + expect(dup_user.valid?).must_equal false + expect(dup_user.errors.messages).must_include :email + end + + it 'will not create a user who has a duplicate username for the same provider as existing user' do + + starting_count = User.count + + dup_user = dup_user_name_and_provider + + ending_count = User.count + + expect(ending_count).must_equal starting_count + + expect(@linda.valid?).must_equal true + expect(dup_user.valid?).must_equal false + expect(dup_user.errors.messages).must_include :nickname + end + + it 'will create a user who has a duplicate username but a different provider than existing user' do + + starting_count = User.count + + dup_user = dup_user_provider_only + + ending_count = User.count + + expect(ending_count).must_equal starting_count + 1 + + expect(@john.valid?).must_equal true + expect(dup_user.valid?).must_equal true + end + + it 'will create a user who has a duplicate provider but a different email than existing user' do + + starting_count = User.count + + dup_user = dup_user_provider_only + + ending_count = User.count + + expect(ending_count).must_equal starting_count + 1 + + expect(@john.valid?).must_equal true + expect(dup_user.valid?).must_equal true + end + end + + let(:item_ids){ + items = Item.all + item_ids = items.map { |item| item.user_id } + } + + describe 'is_a_merchant?(given_ids)' do + + it 'will return true if user has more than one or more items / is a merchant' do + + #greater than or equal to 1 + expect(@linda.items.length).must_be :>=, 1 + expect(@linda.is_a_merchant?(item_ids)).must_equal true + end + + it 'will return false if user has less than one item' do + + #less than 1 + expect(@june.items.length).must_be :<=, 1 + expect(@june.is_a_merchant?(item_ids)).must_equal false + 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..c04801df70 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,49 @@ +require 'simplecov' +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" # for Colorized output +# For colorful output! +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + +SimpleCov.start 'rails' do + add_filter '/bin/' + add_filter '/db/' + add_filter '/test/' # for minitest +end + +# 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_auth_hash(user) + return{ + uid: user.uid, + provider: user.provider, + info: { + name: user.name, + nickname: user.nickname, + email: user.email, + image_url: user.image_url + } + } + 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