diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..ee91c2309d --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# 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 + +/node_modules +/yarn-error.log + +.byebug_history +.env +.DS_Store +.env + +# Ignore coverage +coverage diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..658789f98b --- /dev/null +++ b/Gemfile @@ -0,0 +1,77 @@ +source 'https://rubygems.org' + +git_source(:github) do |repo_name| + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" +end + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.1.6' +# Use postgresql as the database for Active Record +gem 'pg', '>= 0.18', '< 2.0' +# Use Puma as the app server +gem 'puma', '~> 3.7' +# 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 'therubyracer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +gem 'simplecov', require: false, group: :test +gem "omniauth" +gem "omniauth-github" + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '~> 2.13' + gem 'selenium-webdriver' +end + +group :development do + # Access an IRB console on exception pages or by using <%= 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 + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-turbolinks' +gem 'jquery-rails' +gem 'foundation-rails' +gem 'normalize-rails' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..8330f49f9f --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,272 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.1.6) + actionpack (= 5.1.6) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.6) + actionpack (= 5.1.6) + actionview (= 5.1.6) + activejob (= 5.1.6) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.1.6) + actionview (= 5.1.6) + activesupport (= 5.1.6) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.6) + activesupport (= 5.1.6) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.1.6) + activesupport (= 5.1.6) + globalid (>= 0.3.6) + activemodel (5.1.6) + activesupport (= 5.1.6) + activerecord (5.1.6) + activemodel (= 5.1.6) + activesupport (= 5.1.6) + arel (~> 8.0) + activesupport (5.1.6) + 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) + arel (8.0.0) + babel-source (5.8.35) + babel-transpiler (0.7.0) + babel-source (>= 4.0, < 6) + execjs (~> 2.0) + better_errors (2.4.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) + builder (3.2.3) + byebug (10.0.2) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (>= 2.0, < 4.0) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + debug_inspector (0.0.3) + docile (1.1.5) + dotenv (2.2.2) + dotenv-rails (2.2.2) + dotenv (= 2.2.2) + railties (>= 3.2, < 6.0) + erubi (1.7.1) + execjs (2.7.0) + faraday (0.12.2) + multipart-post (>= 1.2, < 3) + ffi (1.9.23) + foundation-rails (6.4.3.0) + railties (>= 3.1.0) + sass (>= 3.3.0, < 3.5) + sprockets-es6 (>= 0.9.0) + globalid (0.4.1) + activesupport (>= 4.2.0) + hashie (3.5.7) + i18n (1.0.1) + concurrent-ruby (~> 1.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 (1.5.6) + 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) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.2.0) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + multi_json (1.13.1) + multi_xml (0.6.0) + multipart-post (2.0.0) + nio4r (2.3.0) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + normalize-rails (4.1.1) + oauth2 (1.4.0) + faraday (>= 0.8, < 0.13) + jwt (~> 1.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.0.0) + 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.2) + puma (3.11.4) + rack (2.0.4) + rack-test (1.0.0) + rack (>= 1.0, < 3) + rails (5.1.6) + actioncable (= 5.1.6) + actionmailer (= 5.1.6) + actionpack (= 5.1.6) + actionview (= 5.1.6) + activejob (= 5.1.6) + activemodel (= 5.1.6) + activerecord (= 5.1.6) + activesupport (= 5.1.6) + bundler (>= 1.3.0) + railties (= 5.1.6) + 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.1.6) + actionpack (= 5.1.6) + activesupport (= 5.1.6) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + ruby-progressbar (1.9.0) + ruby_dep (1.5.0) + rubyzip (1.2.1) + sass (3.4.25) + 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.11.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) + simplecov (0.15.1) + docile (~> 1.1.0) + 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.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-es6 (0.9.2) + babel-source (>= 5.8.11) + babel-transpiler + sprockets (>= 3.0.0) + 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.1.1) + turbolinks-source (~> 5.1) + turbolinks-source (5.1.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.9) + execjs (>= 0.3.0, < 3) + web-console (3.6.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.0.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + byebug + capybara (~> 2.13) + dotenv-rails + foundation-rails + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + normalize-rails + omniauth + omniauth-github + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.7) + rails (~> 5.1.6) + sass-rails (~> 5.0) + selenium-webdriver + simplecov + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +BUNDLED WITH + 1.16.1 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/images/Red_Sweater.png b/app/assets/images/Red_Sweater.png new file mode 100644 index 0000000000..7dc1ce62bc Binary files /dev/null and b/app/assets/images/Red_Sweater.png differ diff --git a/app/assets/images/favicon.png b/app/assets/images/favicon.png new file mode 100644 index 0000000000..1d3d64bada Binary files /dev/null and b/app/assets/images/favicon.png differ diff --git a/app/assets/images/home_img.jpg b/app/assets/images/home_img.jpg new file mode 100644 index 0000000000..dd5ad0c796 Binary files /dev/null and b/app/assets/images/home_img.jpg differ diff --git a/app/assets/images/placeimg_200_250_any (1).jpg b/app/assets/images/placeimg_200_250_any (1).jpg new file mode 100644 index 0000000000..fba2897f30 Binary files /dev/null and b/app/assets/images/placeimg_200_250_any (1).jpg differ diff --git a/app/assets/images/placeimg_200_250_any.jpg b/app/assets/images/placeimg_200_250_any.jpg new file mode 100644 index 0000000000..bde2e4e13c Binary files /dev/null and b/app/assets/images/placeimg_200_250_any.jpg differ diff --git a/app/assets/images/placeimg_200_250_nature (1).jpg b/app/assets/images/placeimg_200_250_nature (1).jpg new file mode 100644 index 0000000000..0045ccb545 Binary files /dev/null and b/app/assets/images/placeimg_200_250_nature (1).jpg differ diff --git a/app/assets/images/placeimg_200_250_nature.jpg b/app/assets/images/placeimg_200_250_nature.jpg new file mode 100644 index 0000000000..5841232510 Binary files /dev/null and b/app/assets/images/placeimg_200_250_nature.jpg differ diff --git a/app/assets/images/sweatsy.png b/app/assets/images/sweatsy.png new file mode 100644 index 0000000000..e3ec06cec4 Binary files /dev/null and b/app/assets/images/sweatsy.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..bbeccf9c77 --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,19 @@ +// 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 jquery + +// +//= require rails-ujs +//= require foundation +//= require_tree . + +$(function(){ $(document).foundation(); }); diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000000..739aa5f022 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/carts.js b/app/assets/javascripts/carts.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/carts.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/categories.js b/app/assets/javascripts/categories.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/categories.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/merchants.js b/app/assets/javascripts/merchants.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/merchants.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/order_products.js b/app/assets/javascripts/order_products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/order_products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/products.js b/app/assets/javascripts/products.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/products.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/sessions.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss new file mode 100644 index 0000000000..b751de052d --- /dev/null +++ b/app/assets/stylesheets/_settings.scss @@ -0,0 +1,868 @@ +// Foundation for Sites Settings +// ----------------------------- +// +// Table of Contents: +// +// 1. Global +// 2. Breakpoints +// 3. The Grid +// 4. Base Typography +// 5. Typography Helpers +// 6. Abide +// 7. Accordion +// 8. Accordion Menu +// 9. Badge +// 10. Breadcrumbs +// 11. Button +// 12. Button Group +// 13. Callout +// 14. Card +// 15. Close Button +// 16. Drilldown +// 17. Dropdown +// 18. Dropdown Menu +// 19. Flexbox Utilities +// 20. Forms +// 21. Label +// 22. Media Object +// 23. Menu +// 24. Meter +// 25. Off-canvas +// 26. Orbit +// 27. Pagination +// 28. Progress Bar +// 29. Prototype Arrow +// 30. Prototype Border-Box +// 31. Prototype Border-None +// 32. Prototype Bordered +// 33. Prototype Display +// 34. Prototype Font-Styling +// 35. Prototype List-Style-Type +// 36. Prototype Overflow +// 37. Prototype Position +// 38. Prototype Rounded +// 39. Prototype Separator +// 40. Prototype Shadow +// 41. Prototype Sizing +// 42. Prototype Spacing +// 43. Prototype Text-Decoration +// 44. Prototype Text-Transformation +// 45. Prototype Text-Utilities +// 46. Responsive Embed +// 47. Reveal +// 48. Slider +// 49. Switch +// 50. Table +// 51. Tabs +// 52. Thumbnail +// 53. Title Bar +// 54. Tooltip +// 55. Top Bar +// 56. Xy Grid + +@import 'util/util'; + +// 1. Global +// --------- + +$global-font-size: 100%; +$global-width: rem-calc(1200); +$global-lineheight: 1.5; +$foundation-palette: ( + primary: #C36891, + secondary: #66fcf1, + success: #f384aa, + warning: #f384aa, + alert: #f384aa, +); +$light-gray: #e6e6e6; +$medium-gray: #cacaca; +$dark-gray: #8a8a8a; +$black: #0a0a0a; +$white: #fefefe; +$body-background: $white; +$body-font-color: $black; +$body-font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; +$body-antialiased: true; +$global-margin: 1rem; +$global-padding: 1rem; +$global-position: 1rem; +$global-weight-normal: normal; +$global-weight-bold: bold; +$global-radius: 0; +$global-menu-padding: 0.7rem 1rem; +$global-menu-nested-margin: 1rem; +$global-text-direction: ltr; +$global-flexbox: true; +$global-prototype-breakpoints: false; +$global-button-cursor: auto; +$global-color-pick-contrast-tolerance: 0; +$print-transparent-backgrounds: true; + +@include add-foundation-colors; + +// 2. Breakpoints +// -------------- + +$breakpoints: ( + small: 0, + medium: 640px, + large: 1024px, + xlarge: 1200px, + xxlarge: 1440px, +); +$print-breakpoint: large; +$breakpoint-classes: (small medium large); + +// 3. The Grid +// ----------- + +$grid-row-width: $global-width; +$grid-column-count: 12; +$grid-column-gutter: ( + small: 20px, + medium: 30px, +); +$grid-column-align-edge: true; +$grid-column-alias: 'columns'; +$block-grid-max: 8; + +// 4. Base Typography +// ------------------ + +$header-font-family: $body-font-family; +$header-font-weight: $global-weight-normal; +$header-font-style: normal; +$font-family-monospace: Consolas, 'Liberation Mono', Courier, monospace; +$header-color: inherit; +$header-lineheight: 1.4; +$header-margin-bottom: 0.5rem; +$header-styles: ( + small: ( + 'h1': ('font-size': 24), + 'h2': ('font-size': 20), + 'h3': ('font-size': 19), + 'h4': ('font-size': 18), + 'h5': ('font-size': 17), + 'h6': ('font-size': 16), + ), + medium: ( + 'h1': ('font-size': 48), + 'h2': ('font-size': 40), + 'h3': ('font-size': 31), + 'h4': ('font-size': 25), + 'h5': ('font-size': 20), + 'h6': ('font-size': 16), + ), +); +$header-text-rendering: optimizeLegibility; +$small-font-size: 80%; +$header-small-font-color: $medium-gray; +$paragraph-lineheight: 1.6; +$paragraph-margin-bottom: 1rem; +$paragraph-text-rendering: optimizeLegibility; +$code-color: $black; +$code-font-family: $font-family-monospace; +$code-font-weight: $global-weight-normal; +$code-background: $light-gray; +$code-border: 1px solid $medium-gray; +$code-padding: rem-calc(2 5 1); +$anchor-color: $primary-color; +$anchor-color-hover: scale-color($anchor-color, $lightness: -14%); +$anchor-text-decoration: none; +$anchor-text-decoration-hover: none; +$hr-width: $global-width; +$hr-border: 1px solid $medium-gray; +$hr-margin: rem-calc(20) auto; +$list-lineheight: $paragraph-lineheight; +$list-margin-bottom: $paragraph-margin-bottom; +$list-style-type: disc; +$list-style-position: outside; +$list-side-margin: 1.25rem; +$list-nested-side-margin: 1.25rem; +$defnlist-margin-bottom: 1rem; +$defnlist-term-weight: $global-weight-bold; +$defnlist-term-margin-bottom: 0.3rem; +$blockquote-color: $dark-gray; +$blockquote-padding: rem-calc(9 20 0 19); +$blockquote-border: 1px solid $medium-gray; +$cite-font-size: rem-calc(13); +$cite-color: $dark-gray; +$cite-pseudo-content: '\2014 \0020'; +$keystroke-font: $font-family-monospace; +$keystroke-color: $black; +$keystroke-background: $light-gray; +$keystroke-padding: rem-calc(2 4 0); +$keystroke-radius: $global-radius; +$abbr-underline: 1px dotted $black; + +// 5. Typography Helpers +// --------------------- + +$lead-font-size: $global-font-size * 1.25; +$lead-lineheight: 1.6; +$subheader-lineheight: 1.4; +$subheader-color: $dark-gray; +$subheader-font-weight: $global-weight-normal; +$subheader-margin-top: 0.2rem; +$subheader-margin-bottom: 0.5rem; +$stat-font-size: 2.5rem; + +// 6. Abide +// -------- + +$abide-inputs: true; +$abide-labels: true; +$input-background-invalid: get-color(alert); +$form-label-color-invalid: get-color(alert); +$input-error-color: get-color(alert); +$input-error-font-size: rem-calc(12); +$input-error-font-weight: $global-weight-bold; + +// 7. Accordion +// ------------ + +$accordion-background: $white; +$accordion-plusminus: true; +$accordion-title-font-size: rem-calc(12); +$accordion-item-color: $primary-color; +$accordion-item-background-hover: $light-gray; +$accordion-item-padding: 1.25rem 1rem; +$accordion-content-background: $white; +$accordion-content-border: 1px solid $light-gray; +$accordion-content-color: $body-font-color; +$accordion-content-padding: 1rem; + +// 8. Accordion Menu +// ----------------- + +$accordionmenu-padding: $global-menu-padding; +$accordionmenu-nested-margin: $global-menu-nested-margin; +$accordionmenu-submenu-padding: $accordionmenu-padding; +$accordionmenu-arrows: true; +$accordionmenu-arrow-color: $primary-color; +$accordionmenu-item-background: null; +$accordionmenu-border: null; +$accordionmenu-submenu-toggle-background: null; +$accordion-submenu-toggle-border: $accordionmenu-border; +$accordionmenu-submenu-toggle-width: 40px; +$accordionmenu-submenu-toggle-height: $accordionmenu-submenu-toggle-width; +$accordionmenu-arrow-size: 6px; + +// 9. Badge +// -------- + +$badge-background: $primary-color; +$badge-color: $white; +$badge-color-alt: $black; +$badge-palette: $foundation-palette; +$badge-padding: 0.3em; +$badge-minwidth: 2.1em; +$badge-font-size: 0.6rem; + +// 10. Breadcrumbs +// --------------- + +$breadcrumbs-margin: 0 0 $global-margin 0; +$breadcrumbs-item-font-size: rem-calc(11); +$breadcrumbs-item-color: $primary-color; +$breadcrumbs-item-color-current: $black; +$breadcrumbs-item-color-disabled: $medium-gray; +$breadcrumbs-item-margin: 0.75rem; +$breadcrumbs-item-uppercase: true; +$breadcrumbs-item-separator: true; +$breadcrumbs-item-separator-item: '/'; +$breadcrumbs-item-separator-item-rtl: '\\'; +$breadcrumbs-item-separator-color: $medium-gray; + +// 11. Button +// ---------- + +$button-font-family: inherit; +$button-padding: 0.85em 1em; +$button-margin: 0.5em; +$button-fill: solid; +$button-background: $primary-color; +$button-background-hover: scale-color($button-background, $lightness: -15%); +$button-color: $white; +$button-color-alt: $black; +$button-radius: $global-radius; +$button-hollow-border-width: 1px; +$button-sizes: ( + tiny: 0.6rem, + small: 0.75rem, + default: 0.9rem, + large: 1.25rem, +); +$button-palette: $foundation-palette; +$button-opacity-disabled: 0.25; +$button-background-hover-lightness: -20%; +$button-hollow-hover-lightness: -50%; +$button-transition: background-color 0.25s ease-out, color 0.25s ease-out; + +// 12. Button Group +// ---------------- + +$buttongroup-margin: 1rem; +$buttongroup-spacing: 1px; +$buttongroup-child-selector: '.button'; +$buttongroup-expand-max: 6; +$buttongroup-radius-on-each: true; + +// 13. Callout +// ----------- + +$callout-background: $light-gray; +$callout-background-fade: 85%; +$callout-border: 1px solid rgba($black, 0.25); +$callout-margin: 1rem; +$callout-padding: 2rem; +$callout-font-color: $body-font-color; +$callout-font-color-alt: $body-background; +$callout-radius: $global-radius; +$callout-link-tint: 30%; + +// 14. Card +// -------- + +$card-background: $white; +$card-font-color: $body-font-color; +$card-divider-background: $light-gray; +$card-border: 1px solid $light-gray; +$card-shadow: none; +$card-border-radius: $global-radius; +$card-padding: $global-padding; +$card-margin-bottom: $global-margin; + +// 15. Close Button +// ---------------- + +$closebutton-position: right top; +$closebutton-offset-horizontal: ( + small: 0.66rem, + medium: 1rem, +); +$closebutton-offset-vertical: ( + small: 0.33em, + medium: 0.5rem, +); +$closebutton-size: ( + small: 1.5em, + medium: 2em, +); +$closebutton-lineheight: 1; +$closebutton-color: $dark-gray; +$closebutton-color-hover: $black; + +// 16. Drilldown +// ------------- + +$drilldown-transition: transform 0.15s linear; +$drilldown-arrows: true; +$drilldown-padding: $global-menu-padding; +$drilldown-nested-margin: 0; +$drilldown-background: $white; +$drilldown-submenu-padding: $drilldown-padding; +$drilldown-submenu-background: $white; +$drilldown-arrow-color: $primary-color; +$drilldown-arrow-size: 6px; + +// 17. Dropdown +// ------------ + +$dropdown-padding: 1rem; +$dropdown-background: $body-background; +$dropdown-border: 1px solid $medium-gray; +$dropdown-font-size: 1rem; +$dropdown-width: 300px; +$dropdown-radius: $global-radius; +$dropdown-sizes: ( + tiny: 100px, + small: 200px, + large: 400px, +); + +// 18. Dropdown Menu +// ----------------- + +$dropdownmenu-arrows: true; +$dropdownmenu-arrow-color: $anchor-color; +$dropdownmenu-arrow-size: 6px; +$dropdownmenu-arrow-padding: 1.5rem; +$dropdownmenu-min-width: 200px; +$dropdownmenu-background: $white; +$dropdownmenu-submenu-background: $dropdownmenu-background; +$dropdownmenu-padding: $global-menu-padding; +$dropdownmenu-nested-margin: 0; +$dropdownmenu-submenu-padding: $dropdownmenu-padding; +$dropdownmenu-border: 1px solid $medium-gray; +$dropdown-menu-item-color-active: get-color(primary); +$dropdown-menu-item-background-active: transparent; + +// 19. Flexbox Utilities +// --------------------- + +$flex-source-ordering-count: 6; +$flexbox-responsive-breakpoints: true; + +// 20. Forms +// --------- + +$fieldset-border: 1px solid $medium-gray; +$fieldset-padding: rem-calc(20); +$fieldset-margin: rem-calc(18 0); +$legend-padding: rem-calc(0 3); +$form-spacing: rem-calc(16); +$helptext-color: $black; +$helptext-font-size: rem-calc(13); +$helptext-font-style: italic; +$input-prefix-color: $black; +$input-prefix-background: $light-gray; +$input-prefix-border: 1px solid $medium-gray; +$input-prefix-padding: 1rem; +$form-label-color: $black; +$form-label-font-size: rem-calc(14); +$form-label-font-weight: $global-weight-normal; +$form-label-line-height: 1.8; +$select-background: $white; +$select-triangle-color: $dark-gray; +$select-radius: $global-radius; +$input-color: $black; +$input-placeholder-color: $medium-gray; +$input-font-family: inherit; +$input-font-size: rem-calc(16); +$input-font-weight: $global-weight-normal; +$input-line-height: $global-lineheight; +$input-background: $white; +$input-background-focus: $white; +$input-background-disabled: $light-gray; +$input-border: 1px solid $medium-gray; +$input-border-focus: 1px solid $dark-gray; +$input-padding: $form-spacing / 2; +$input-shadow: inset 0 1px 2px rgba($black, 0.1); +$input-shadow-focus: 0 0 5px $medium-gray; +$input-cursor-disabled: not-allowed; +$input-transition: box-shadow 0.5s, border-color 0.25s ease-in-out; +$input-number-spinners: true; +$input-radius: $global-radius; +$form-button-radius: $global-radius; + +// 21. Label +// --------- + +$label-background: $primary-color; +$label-color: $white; +$label-color-alt: $black; +$label-palette: $foundation-palette; +$label-font-size: 0.8rem; +$label-padding: 0.33333rem 0.5rem; +$label-radius: $global-radius; + +// 22. Media Object +// ---------------- + +$mediaobject-margin-bottom: $global-margin; +$mediaobject-section-padding: $global-padding; +$mediaobject-image-width-stacked: 100%; + +// 23. Menu +// -------- + +$menu-margin: 0; +$menu-nested-margin: $global-menu-nested-margin; +$menu-items-padding: $global-menu-padding; +$menu-simple-margin: 1rem; +$menu-item-color-active: $white; +$menu-item-background-active: get-color(primary); +$menu-icon-spacing: 0.25rem; +$menu-item-background-hover: $light-gray; +$menu-state-back-compat: true; +$menu-centered-back-compat: true; +$menu-icons-back-compat: true; + +// 24. Meter +// --------- + +$meter-height: 1rem; +$meter-radius: $global-radius; +$meter-background: $medium-gray; +$meter-fill-good: $success-color; +$meter-fill-medium: $warning-color; +$meter-fill-bad: $alert-color; + +// 25. Off-canvas +// -------------- + +$offcanvas-sizes: ( + small: 250px, +); +$offcanvas-vertical-sizes: ( + small: 250px, +); +$offcanvas-background: $light-gray; +$offcanvas-shadow: 0 0 10px rgba($black, 0.7); +$offcanvas-inner-shadow-size: 20px; +$offcanvas-inner-shadow-color: rgba($black, 0.25); +$offcanvas-overlay-zindex: 11; +$offcanvas-push-zindex: 12; +$offcanvas-overlap-zindex: 13; +$offcanvas-reveal-zindex: 12; +$offcanvas-transition-length: 0.5s; +$offcanvas-transition-timing: ease; +$offcanvas-fixed-reveal: true; +$offcanvas-exit-background: rgba($white, 0.25); +$maincontent-class: 'off-canvas-content'; + +// 26. Orbit +// --------- + +$orbit-bullet-background: $medium-gray; +$orbit-bullet-background-active: $dark-gray; +$orbit-bullet-diameter: 1.2rem; +$orbit-bullet-margin: 0.1rem; +$orbit-bullet-margin-top: 0.8rem; +$orbit-bullet-margin-bottom: 0.8rem; +$orbit-caption-background: rgba($black, 0.5); +$orbit-caption-padding: 1rem; +$orbit-control-background-hover: rgba($black, 0.5); +$orbit-control-padding: 1rem; +$orbit-control-zindex: 10; + +// 27. Pagination +// -------------- + +$pagination-font-size: rem-calc(14); +$pagination-margin-bottom: $global-margin; +$pagination-item-color: $black; +$pagination-item-padding: rem-calc(3 10); +$pagination-item-spacing: rem-calc(1); +$pagination-radius: $global-radius; +$pagination-item-background-hover: $light-gray; +$pagination-item-background-current: $primary-color; +$pagination-item-color-current: $white; +$pagination-item-color-disabled: $medium-gray; +$pagination-ellipsis-color: $black; +$pagination-mobile-items: false; +$pagination-mobile-current-item: false; +$pagination-arrows: true; + +// 28. Progress Bar +// ---------------- + +$progress-height: 1rem; +$progress-background: $medium-gray; +$progress-margin-bottom: $global-margin; +$progress-meter-background: $primary-color; +$progress-radius: $global-radius; + +// 29. Prototype Arrow +// ------------------- + +$prototype-arrow-directions: ( + down, + up, + right, + left +); +$prototype-arrow-size: 0.4375rem; +$prototype-arrow-color: $black; + +// 30. Prototype Border-Box +// ------------------------ + +$prototype-border-box-breakpoints: $global-prototype-breakpoints; + +// 31. Prototype Border-None +// ------------------------- + +$prototype-border-none-breakpoints: $global-prototype-breakpoints; + +// 32. Prototype Bordered +// ---------------------- + +$prototype-bordered-breakpoints: $global-prototype-breakpoints; +$prototype-border-width: rem-calc(1); +$prototype-border-type: solid; +$prototype-border-color: $medium-gray; + +// 33. Prototype Display +// --------------------- + +$prototype-display-breakpoints: $global-prototype-breakpoints; +$prototype-display: ( + inline, + inline-block, + block, + table, + table-cell +); + +// 34. Prototype Font-Styling +// -------------------------- + +$prototype-font-breakpoints: $global-prototype-breakpoints; +$prototype-wide-letter-spacing: rem-calc(4); +$prototype-font-normal: $global-weight-normal; +$prototype-font-bold: $global-weight-bold; + +// 35. Prototype List-Style-Type +// ----------------------------- + +$prototype-list-breakpoints: $global-prototype-breakpoints; +$prototype-style-type-unordered: ( + disc, + circle, + square +); +$prototype-style-type-ordered: ( + decimal, + lower-alpha, + lower-latin, + lower-roman, + upper-alpha, + upper-latin, + upper-roman +); + +// 36. Prototype Overflow +// ---------------------- + +$prototype-overflow-breakpoints: $global-prototype-breakpoints; +$prototype-overflow: ( + visible, + hidden, + scroll +); + +// 37. Prototype Position +// ---------------------- + +$prototype-position-breakpoints: $global-prototype-breakpoints; +$prototype-position: ( + static, + relative, + absolute, + fixed +); +$prototype-position-z-index: 975; + +// 38. Prototype Rounded +// --------------------- + +$prototype-rounded-breakpoints: $global-prototype-breakpoints; +$prototype-border-radius: rem-calc(3); + +// 39. Prototype Separator +// ----------------------- + +$prototype-separator-breakpoints: $global-prototype-breakpoints; +$prototype-separator-align: center; +$prototype-separator-height: rem-calc(2); +$prototype-separator-width: 3rem; +$prototype-separator-background: $primary-color; +$prototype-separator-margin-top: $global-margin; + +// 40. Prototype Shadow +// -------------------- + +$prototype-shadow-breakpoints: $global-prototype-breakpoints; +$prototype-box-shadow: 0 2px 5px 0 rgba(0,0,0,.16), + 0 2px 10px 0 rgba(0,0,0,.12); + +// 41. Prototype Sizing +// -------------------- + +$prototype-sizing-breakpoints: $global-prototype-breakpoints; +$prototype-sizing: ( + width, + height +); +$prototype-sizes: ( + 25: 25%, + 50: 50%, + 75: 75%, + 100: 100% +); + +// 42. Prototype Spacing +// --------------------- + +$prototype-spacing-breakpoints: $global-prototype-breakpoints; +$prototype-spacers-count: 3; + +// 43. Prototype Text-Decoration +// ----------------------------- + +$prototype-decoration-breakpoints: $global-prototype-breakpoints; +$prototype-text-decoration: ( + overline, + underline, + line-through, +); + +// 44. Prototype Text-Transformation +// --------------------------------- + +$prototype-transformation-breakpoints: $global-prototype-breakpoints; +$prototype-text-transformation: ( + lowercase, + uppercase, + capitalize +); + +// 45. Prototype Text-Utilities +// ---------------------------- + +$prototype-utilities-breakpoints: $global-prototype-breakpoints; +$prototype-text-overflow: ellipsis; + +// 46. Responsive Embed +// -------------------- + +$responsive-embed-margin-bottom: rem-calc(16); +$responsive-embed-ratios: ( + default: 4 by 3, + widescreen: 16 by 9, +); + +// 47. Reveal +// ---------- + +$reveal-background: $white; +$reveal-width: 600px; +$reveal-max-width: $global-width; +$reveal-padding: $global-padding; +$reveal-border: 1px solid $medium-gray; +$reveal-radius: $global-radius; +$reveal-zindex: 1005; +$reveal-overlay-background: rgba($black, 0.45); + +// 48. Slider +// ---------- + +$slider-width-vertical: 0.5rem; +$slider-transition: all 0.2s ease-in-out; +$slider-height: 0.5rem; +$slider-background: $light-gray; +$slider-fill-background: $medium-gray; +$slider-handle-height: 1.4rem; +$slider-handle-width: 1.4rem; +$slider-handle-background: $primary-color; +$slider-opacity-disabled: 0.25; +$slider-radius: $global-radius; + +// 49. Switch +// ---------- + +$switch-background: $medium-gray; +$switch-background-active: $primary-color; +$switch-height: 2rem; +$switch-height-tiny: 1.5rem; +$switch-height-small: 1.75rem; +$switch-height-large: 2.5rem; +$switch-radius: $global-radius; +$switch-margin: $global-margin; +$switch-paddle-background: $white; +$switch-paddle-offset: 0.25rem; +$switch-paddle-radius: $global-radius; +$switch-paddle-transition: all 0.25s ease-out; + +// 50. Table +// --------- + +$table-background: $white; +$table-color-scale: 5%; +$table-border: 1px solid smart-scale($table-background, $table-color-scale); +$table-padding: rem-calc(8 10 10); +$table-hover-scale: 2%; +$table-row-hover: darken($table-background, $table-hover-scale); +$table-row-stripe-hover: darken($table-background, $table-color-scale + $table-hover-scale); +$table-is-striped: true; +$table-striped-background: smart-scale($table-background, $table-color-scale); +$table-stripe: even; +$table-head-background: smart-scale($table-background, $table-color-scale / 2); +$table-head-row-hover: darken($table-head-background, $table-hover-scale); +$table-foot-background: smart-scale($table-background, $table-color-scale); +$table-foot-row-hover: darken($table-foot-background, $table-hover-scale); +$table-head-font-color: $body-font-color; +$table-foot-font-color: $body-font-color; +$show-header-for-stacked: false; +$table-stack-breakpoint: medium; + +// 51. Tabs +// -------- + +$tab-margin: 0; +$tab-background: $white; +$tab-color: $primary-color; +$tab-background-active: $light-gray; +$tab-active-color: $primary-color; +$tab-item-font-size: rem-calc(12); +$tab-item-background-hover: $white; +$tab-item-padding: 1.25rem 1.5rem; +$tab-expand-max: 6; +$tab-content-background: $white; +$tab-content-border: $light-gray; +$tab-content-color: $body-font-color; +$tab-content-padding: 1rem; + +// 52. Thumbnail +// ------------- + +$thumbnail-border: solid 4px $white; +$thumbnail-margin-bottom: $global-margin; +$thumbnail-shadow: 0 0 0 1px rgba($black, 0.2); +$thumbnail-shadow-hover: 0 0 6px 1px rgba($primary-color, 0.5); +$thumbnail-transition: box-shadow 200ms ease-out; +$thumbnail-radius: $global-radius; + +// 53. Title Bar +// ------------- + +$titlebar-background: $black; +$titlebar-color: $white; +$titlebar-padding: 0.5rem; +$titlebar-text-font-weight: bold; +$titlebar-icon-color: $white; +$titlebar-icon-color-hover: $medium-gray; +$titlebar-icon-spacing: 0.25rem; + +// 54. Tooltip +// ----------- + +$has-tip-cursor: help; +$has-tip-font-weight: $global-weight-bold; +$has-tip-border-bottom: dotted 1px $dark-gray; +$tooltip-background-color: $black; +$tooltip-color: $white; +$tooltip-padding: 0.75rem; +$tooltip-max-width: 10rem; +$tooltip-font-size: $small-font-size; +$tooltip-pip-width: 0.75rem; +$tooltip-pip-height: $tooltip-pip-width * 0.866; +$tooltip-radius: $global-radius; + +// 55. Top Bar +// ----------- + +$topbar-padding: 0.5rem; +$topbar-background: $light-gray; +$topbar-submenu-background: $topbar-background; +$topbar-title-spacing: 0.5rem 1rem 0.5rem 0; +$topbar-input-width: 200px; +$topbar-unstack-breakpoint: medium; + +// 56. Xy Grid +// ----------- + +$xy-grid: true; +$grid-container: $global-width; +$grid-columns: 12; +$grid-margin-gutters: ( + small: 20px, + medium: 30px +); +$grid-padding-gutters: $grid-margin-gutters; +$grid-container-padding: $grid-padding-gutters; +$grid-container-max: $global-width; +$xy-block-grid-max: 8; diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..f2807ab5bd --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,285 @@ +/* +* 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. +*= require normalize-rails + +* +*= require_tree . +*= require_self +*= require foundation_and_overrides + +*/ + +/*all page body styling*/ +body,html { + height: 100%; +} + +body { + /*font-family: 'Raleway', sans-serif;*/ + /*font-family: 'Dosis', sans-serif;*/ + font-family: 'Shadows Into Light', cursive; + /*font-family: 'Handlee', cursive;*/ + /*font-family: 'Arsenal', sans-serif;*/ + /*font-family: 'Neucha', cursive;*/ +} + +h2, h3, h4, h5 { + font-family: 'Shadows Into Light', cursive; + font-weight: bold; +} + +/*Navbar styling*/ +.nav { + width: 100%; + position: fixed; +} +.top-bar-left { + list-style-type: none; + font-size: 40px; +} + + + +/*form styling*/ +form { + padding: 2em; +} + +/*Home page styling*/ +#home-background-img { + background-image: url('home_img.jpg'); + background-repeat: no-repeat; + background-size: cover; + background-position: center; + background-attachment: fixed; + padding-top: 2em; + height: 30em; +} + +.home-container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + margin-top: 7em; +} + + +.homepage-title { + color: #fff; + font-weight: bold; + font-size: 2.75em; + text-shadow: 0px 4px 3px rgba(64,224,208,0.4), + 0px 8px 13px rgba(64,224,208,0.4), + 0px 18px 23px rgba(64,224,208,0.4); +} + +.home-header { + text-align: center; + padding: 1em; +} + +hr { + width: 20%; + padding: 0; + margin-top: 0; + border: 1px solid rgb(64,224,208); +} + +.homepage p { + padding: 3em; + text-align: justify; +} + +.homepage h4 { + line-height: 1em; + margin: 0 auto; +} + +.home-image-expand { + max-width: 100%; + + -moz-transition: all 0.3s; + -webkit-transition: all 0.3s; + transition: all 0.3s; +} + +.home-image-expand:hover { + -moz-transform: scale(1.1); + -webkit-transform: scale(1.1); + transform: scale(1.1); +} + +ul { + list-style-type: none; +} + +ul.merchants li { + padding: 1.5em; + margin: 0 auto; +} + +.size1, .size2, .size3, .size4 { + font-size: 2em; +} +.size1 :hover { + color: purple; + font-weight: bold; + font-size: 2em; +} + +.size2 :hover { + color: #cc3500; + font-weight: bold; + font-size: 2em; +} + +.size3 :hover { + color: #d8c100; + font-weight: bold; + font-size: 2em; +} + +.size4 :hover { + color: #2daf00; + font-weight: bold; + font-size: 2em; +} + +i { + color: #C36891; + cursor: pointer; +} +/*product grid styling*/ +.grid-x { + display: flex; +} + +.thumbnail .description { + display:flex; + flex-direction: column; + word-wrap: break-word; +} +/*merchant grid*/ +.merchant-grid-x { + display: flex; + /*grid-template-rows: 1fr 1fr 1fr 1fr;*/ +} +.merchant-grid-x ul{ + list-style-type: none; +} + +.image { + padding: 30px; +} +/*cart item styling*/ +.quantity { + width: 3em; + display: inline; +} + +/*.cart-items { + display:grid; + grid-template-columns: 1fr 5em repeat(2, 1fr) repeat(2, 100px); + font-size: 1.25em; +}*/ + +.prod_table { + padding: 2em 4em; + font-size: 1.25em; +} + +input[type=number]::-webkit-inner-spin-button, +input[type=number]::-webkit-outer-spin-button { + + opacity: 1; + +} + +/** FOOTER **/ + +.site-footer { + background: linear-gradient(to top, rgba(180,195,203,0.2), rgba(64,224,208,0.8)); + color: #8aa0ae; + padding: 2rem; +} + +.site-footer .column-block { + margin-bottom: 30px; +} + +.site-footer > .row { + margin-bottom: 1rem; +} + +.site-footer-name { + color: #fefefe; + margin-bottom: 1rem; + font-size: 2rem; +} + +.site-footer-title { + color: #fefefe; + margin-bottom: 1rem; + font-size: 1.25rem; +} + +.site-footer-block { + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + margin-bottom: 1rem; +} + +.site-footer-block .fa { + font-size: 2rem; + color: #020304; +} + +div.column.medium-3 img { + padding: .5em; +} + +.contact { + padding-left: 3em; +} + +div.site-footer-block i.fa { + color: #fff; +} + +.y-grid p { + margin: 0; +} + +.site-footer-block p { + margin-left: 1rem; + line-height: 1.125rem; +} + +.site-footer-bottom { + background: #020304; + padding: 1rem 0; +} + +.site-footer-bottom p, +.site-footer-bottom .menu { + margin-bottom: 0; +} + +.site-footer-bottom .site-footer-bottom-links { + float: right; +} + +.site-footer-bottom .site-footer-bottom-links a { + color: #8aa0ae; +} diff --git a/app/assets/stylesheets/browserslist b/app/assets/stylesheets/browserslist new file mode 100644 index 0000000000..6019618a9a --- /dev/null +++ b/app/assets/stylesheets/browserslist @@ -0,0 +1,4 @@ +last 2 versions +ie >= 9 +Android >= 2.3 +ios >= 7 diff --git a/app/assets/stylesheets/carts.scss b/app/assets/stylesheets/carts.scss new file mode 100644 index 0000000000..2fe1b9e710 --- /dev/null +++ b/app/assets/stylesheets/carts.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Carts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..ef1657f8c9 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/foundation_and_overrides.scss b/app/assets/stylesheets/foundation_and_overrides.scss new file mode 100644 index 0000000000..ed4c5a0ecf --- /dev/null +++ b/app/assets/stylesheets/foundation_and_overrides.scss @@ -0,0 +1,61 @@ +@charset 'utf-8'; + +@import 'settings'; +@import 'foundation'; + +// If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package. +// +// @import 'motion-ui/motion-ui'; + +// We include everything by default. To slim your CSS, remove components you don't use. + +@include foundation-global-styles; +@include foundation-xy-grid-classes; +//@include foundation-grid; +//@include foundation-flex-grid; +@include foundation-flex-classes; +@include foundation-typography; +@include foundation-forms; +@include foundation-button; +@include foundation-accordion; +@include foundation-accordion-menu; +@include foundation-badge; +@include foundation-breadcrumbs; +@include foundation-button-group; +@include foundation-callout; +@include foundation-card; +@include foundation-close-button; +@include foundation-menu; +@include foundation-menu-icon; +@include foundation-drilldown-menu; +@include foundation-dropdown; +@include foundation-dropdown-menu; +@include foundation-responsive-embed; +@include foundation-label; +@include foundation-media-object; +@include foundation-off-canvas; +@include foundation-orbit; +@include foundation-pagination; +@include foundation-progress-bar; +@include foundation-slider; +@include foundation-sticky; +@include foundation-reveal; +@include foundation-switch; +@include foundation-table; +@include foundation-tabs; +@include foundation-thumbnail; +@include foundation-title-bar; +@include foundation-tooltip; +@include foundation-top-bar; +@include foundation-visibility-classes; +@include foundation-float-classes; + +// If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package. +// +// @include motion-ui-transitions; +// @include motion-ui-animations; +@import 'motion-ui/motion-ui'; +@include motion-ui-transitions; +@include motion-ui-animations; + + diff --git a/app/assets/stylesheets/merchants.scss b/app/assets/stylesheets/merchants.scss new file mode 100644 index 0000000000..2327c00afe --- /dev/null +++ b/app/assets/stylesheets/merchants.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the merchants controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/order_products.scss b/app/assets/stylesheets/order_products.scss new file mode 100644 index 0000000000..4e38cdae9b --- /dev/null +++ b/app/assets/stylesheets/order_products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderProducts 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..9b6c6cd422 --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,15 @@ +// 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/ + +.order-summary { + padding: 2em 4em; +} + +.small-summary { + width: auto; +} + +.confirm-info { + margin-top: 3em; +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..89e2e8db07 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ 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/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..c27719daf3 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,31 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception + helper_method :current_order, :previous_order + + before_action :current_user + before_action :current_order + before_action :require_login + + def current_user + @current_user ||= Merchant.find(session[:merchant_id]) if session[:merchant_id] + end + +# flashes message if current_user can't find a logged-in merchant + def require_login + unless current_user + flash[:error] = "You must be logged in to do that." + redirect_back fallback_location: root_path + end + end + + def current_order + if session[:order_id] + @current_order = Order.find(session[:order_id]) + else + @current_order = Order.create(status: 'pending') + session[:order_id] = @current_order.id + end + return @current_order + end + +end diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb new file mode 100644 index 0000000000..189197ef84 --- /dev/null +++ b/app/controllers/carts_controller.rb @@ -0,0 +1,43 @@ +class CartsController < ApplicationController + before_action :find_order_products + skip_before_action :require_login + before_action :previous_order, only: [:confirmation] + + def show; end + + def edit; end + + def confirmation; end + + def update + @current_order.assign_attributes(cart_params) + @current_order.get_expiry(params) + @current_order.status = "in progress" + if @current_order.save + @current_order.status = "paid" + if @current_order.save + # empty cart by setting session[:order_id] to nil + session[:order_id] = nil + session[:prev_order_id] = @current_order.id # here + redirect_to confirmation_path + end + else + render :edit, status: :bad_request + end + end + + private + def find_order_products + @order_products = @current_order.order_products + head :not_found unless @order_products + end + + def cart_params + params.require(:order).permit(:name, :email, :cc_num, :cc_cvv, :zip, :address, expiry_date: {}) + end + + def previous_order + @previous_order ||= Order.find_by(id: session[:prev_order_id]) + end + +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..0dfa186ba4 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,25 @@ +class CategoriesController < ApplicationController +skip_before_action :require_login, only: [:index, :show] + + def index + @products_by_category = Category.products_by_category + end + + def new; end + + def create + @category = Category.new(name: params[:category][:name]) + + if @category.save + flash[:success] = "Category added successfully" + redirect_to merchant_path(id: @current_user.id) + else + flash.now[:failure] = "Validations Failed" + render :new, status: :bad_request + end + end + + def show + @category = Category.find_by(id: params[: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/merchants_controller.rb b/app/controllers/merchants_controller.rb new file mode 100644 index 0000000000..9fe9a00d4f --- /dev/null +++ b/app/controllers/merchants_controller.rb @@ -0,0 +1,24 @@ +class MerchantsController < ApplicationController + before_action :require_login, only: [:show, :new] + + def index + @merchants = Merchant.all + end + + def new + @merchant = @current_user + redirect_to merchant_path(@merchant) + end + + def show + @merchant = @current_user + redirect_to root_path unless @merchant + end + + private + + def merchant_params + params.require(:merchant).permit(:username, :email) + end + +end diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb new file mode 100644 index 0000000000..146a4789a7 --- /dev/null +++ b/app/controllers/order_products_controller.rb @@ -0,0 +1,64 @@ +class OrderProductsController < ApplicationController + skip_before_action :require_login + before_action :find_order_product, only: [:show, :update, :destroy] + + def create + @order = current_order + product = Product.find_by(id: params[:order_product][:product_id]) + + # Maybe: make an instance method on Order to do this work and return the item + @item = @order.order_products.find_by(product: product) + if @item + @item.quantity += (params[:order_product][:quantity]).to_i + else + @item = @order.order_products.new(item_params) + end + + if @item.quantity > product.available + flash[:error] = "Only #{product.available} currently available." + redirect_to products_path + return + end + + if @item.save + @current_order.total = @current_order.order_total + @current_order.save + name = Product.find_by(id: @item.product_id).name.titleize + session[:order_id] = @order.id + flash[:success] = "You added #{@item.quantity} #{@item.quantity > 1 ? name.pluralize : name}!" + redirect_to products_path + else + # FLASH MESSAGE + @order.errors.messages + end + end + + def update + # FLASH MESSAGE + @item.assign_attributes({quantity: item_params[:quantity]}) + @item.save + redirect_to cart_path + end + + def destroy + @item.destroy + if @order.save + flash[:success] = "#{Product.find_by(id: @item.product_id).name.titleize} has been deleted from your cart." + else + flash[:failure] = "Something went wrong, but don't sweat it! Here's your cart." + end + redirect_to cart_path + end + + + private + def item_params + params.require(:order_product).permit(:quantity, :product_id) + end + + def find_order_product + @order = current_order + @item = @order.order_products.find(params[:id]) + end + +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..9c544c12d9 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,81 @@ +class OrdersController < ApplicationController + before_action :require_login, only: [:show, :index] + before_action :find_order, only: [:show, :ship_order] + + def index + @merchant = Merchant.find(session[:merchant_id]) + + orders = [] + OrderProduct.all.each do |order_product| + product = Product.find(order_product.product_id) + if product.merchant_id == @merchant.id + orders << order_product + end + end + @orders = orders + + products = [] + orders.each do |order| + product = Product.find(order.product_id) + products << product + end + @products = products + + unshipped_orders = [] + @orders.each do |order_product| + if order_product.order.status == 'paid' + unshipped_orders << order_product.product.price + end + end + + shipped_orders = [] + @orders.each do |order_product| + if order_product.order.status == 'shipped' + shipped_orders << order_product.product.price + end + end + + @unshipped_orders = unshipped_orders.sum + @shipped_orders = shipped_orders.sum + + @total = @unshipped_orders + @shipped_orders + end + + def ship_order + if @order.status == "paid" + @order.ship_order + flash[:success] = "Order Shipped!" + redirect_to merchant_orders_path(merchant_id: @current_user.id) + elsif @order.status == "shipped" + flash[:error] = "You already shipped this order" + else + flash[:error] = "Cannot ship an unpaid order" + redirect_to merchant_orders_path(merchant_id: @current_user.id) + end + end + + def show; end + + def create + @order = Order.new(order_params) + @order.status = 'pending' + if @order.save + redirect_to order_path(@order.id) + else + render :new, status: :bad_request + end + end + + private + + # does this need to be edited since we have a cart params?? + def order_params + params.require(:order).permit(:status, :name, :email, :address, :cc_num, :expiry_date, :cc_cvv, :zip) + end + + def find_order + @order = Order.find_by_id(params[:id]) + head :not_found unless @order + end + +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..dd165bd568 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,99 @@ +class ProductsController < ApplicationController + before_action :find_product, only: [:show, :edit, :update, :retire, :destroy] + before_action :correct_merchant, only: [:edit, :update, :destroy] + skip_before_action :require_login, only: [:index, :root, :show] + + def root + @products = Product.all + @categories = Category.all + @merchants = Merchant.all + end + + def index + merch_id = params[:merchant_id] + if merch_id.nil? + @products = Product.all + @order_product = current_order.order_products.new + else + @products = Merchant.find(merch_id).products + end + end + + def new + @product = Product.new(merchant: @current_user) + end + + def create + @product = Product.new(product_params) + @product.merchant = @current_user + + if @product.save + flash[:success] = "Product added successfully" + + redirect_to merchant_products_path(@current_user.id) + + else + flash.now[:failure] = "Validations Failed" + render :new, status: :bad_request + end + end + + + def show + end + + def edit + + # Check that the current_user matches the user associated with the product + end + + def update + @product.assign_attributes(product_params) + + if @product.save + redirect_to product_path + else render :edit, status: :bad_request + end + end + + def destroy + @product.destroy + + redirect_to products_path + end + + def retire + if @product.merchant = @current_user + @product.available = 0 + if @product.save + flash[:success] = "Successfully retired." + else + flash[:failure] = "Could not Retire, Try Again" + end + end + redirect_to products_path + end + + private + def find_product + @product = Product.find_by(id: params[:id]) + head :not_found unless @product + end + + def correct_merchant + # find_product + unless session[:merchant_id] == @product.merchant.id + flash[:error] = "Merchant and product do not match" + redirect_to root_path + end + end + + def product_params + return params.require(:product).permit(:name, :price, :available, :photo, :description) + end + + def review_params + return params.require(:review).permit(:rating, :description) + end + +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..57228290e9 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,25 @@ +class ReviewsController < ApplicationController + skip_before_action :require_login + + def create + @review = Review.new(review_params) + @review.product_id = params[:product_id] + + if @current_user && @current_user.products.include?(@review.product) + flash[:error] = "You can't review your own products" + redirect_to product_path(@review.product) + + elsif @review.save + redirect_to product_path(@review.product_id) + else + flash[:error] = "You must submit a rating of 1-5 and a description." + @product = Product.find_by(id: params[:product_id]) + render 'products/show', status: :bad_request + end + end +end + +private +def review_params + return params.require(:review).permit(:rating, :description) +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..b6ac11544b --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,40 @@ +class SessionsController < ApplicationController + + skip_before_action :require_login + + def create + auth_hash = request.env['omniauth.auth'] + + if auth_hash['uid'] + @merchant = Merchant.find_by(uid: auth_hash['uid'], provider: 'github') + + if @merchant.nil? + @merchant = Merchant.build_from_github(auth_hash) + if @merchant.save + session[:merchant_id] = @merchant.id + flash[:success] = "Successfully created new user #{@merchant.username.capitalize} with ID #{@merchant.id}" + redirect_to merchant_path(@merchant.id) + else + flash[:error] = "Could not log in" + flash[:messages] = @merchant.errors.messages + redirect_to root_path + end + else + session[:merchant_id] = @merchant.id + flash[:success] = "Welcome back #{@merchant.username.capitalize}!" + redirect_to merchant_path(@merchant.id) + end + + else + flash[:error] = "Could not authenticate user via Github" + redirect_to root_path + end + end + + + def destroy + session[:merchant_id] = nil + flash[:success] = "You have been logged out" + redirect_to root_path + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/carts_helper.rb b/app/helpers/carts_helper.rb new file mode 100644 index 0000000000..d99c380cb5 --- /dev/null +++ b/app/helpers/carts_helper.rb @@ -0,0 +1,2 @@ +module CartsHelper +end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/helpers/merchants_helper.rb b/app/helpers/merchants_helper.rb new file mode 100644 index 0000000000..5337747b0f --- /dev/null +++ b/app/helpers/merchants_helper.rb @@ -0,0 +1,2 @@ +module MerchantsHelper +end diff --git a/app/helpers/order_products_helper.rb b/app/helpers/order_products_helper.rb new file mode 100644 index 0000000000..fb2828b523 --- /dev/null +++ b/app/helpers/order_products_helper.rb @@ -0,0 +1,2 @@ +module OrderProductsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..3622e17dbf --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,11 @@ +module OrdersHelper + + def last_four(order) + order.cc_num.last(4) + end + + def date_placed(order) + order.updated_at.strftime("%B %-d, %Y at %l:%M%P") + end + +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..569b255219 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,13 @@ +module ProductsHelper + def average_rating(product) + reviews = product.reviews + + review_count = reviews.count + + ratings = reviews.map { |review| review.rating} + ratings_sum = ratings.inject { |sum, rating| sum + rating } + + + return (ratings_sum.to_f / review_count.to_f).round(2) if !ratings_sum.nil? + end +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000..a009ace51c --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..286b2239d1 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..10a4cba84d --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..6c04ea00fe --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,14 @@ +class Category < ApplicationRecord + has_and_belongs_to_many :products + validates :name, presence: true + validates :name, uniqueness: true + + def self.products_by_category + cat_prod = {} + all.each do |c| + cat_prod[c] = c.products + end + return cat_prod + end + +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/merchant.rb b/app/models/merchant.rb new file mode 100644 index 0000000000..94d7a532d2 --- /dev/null +++ b/app/models/merchant.rb @@ -0,0 +1,15 @@ +class Merchant < ApplicationRecord + has_many :products + has_many :orders + # has_many :reviews + has_many :product_categories, through: :products, source: :categories + + validates :username, presence: true, uniqueness: true + validates :email, presence: true, uniqueness: true + + def self.build_from_github(auth_hash) + @merchant = Merchant.new(username: auth_hash['info']['nickname'], email: auth_hash['info']['email'], uid: auth_hash['uid'], provider: auth_hash['provider']) + + end + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..ea4205c48e --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,69 @@ +class Order < ApplicationRecord + has_many :order_products, dependent: :destroy + has_many :products, through: :order_products + has_many :merchants, through: :products + before_save :update_status + before_save :order_total + + validates :name, presence: true, if: :ready_to_process? + + validates :email, presence: true, if: :ready_to_process?, format: { with: /@/, message: "must include @" } + + validates :address, presence: true, if: :ready_to_process?, format: { with: /\A[\d]+/, message: "must start with digits" } + + validates :cc_num, presence: true, if: :ready_to_process?, format: { with: /\A[\d]{16}\z/, message: "16 digits only" } + + validates :cc_cvv, presence: true, if: :ready_to_process?, format: { with: /\A[\d]{3}\z/, message: "3 digits only" } + + validates :zip, presence: true, if: :ready_to_process?, format: { with: /\A[\d]+\z/, message: "digits only" } + + def ready_to_process? + self.status == "in progress" + end + + def order_total + total = 0 + self.order_products.each do |order_product| + total += order_product.subtotal + end + return total + end + + # reduce the total num of products available when user pays for an order + def decrement(order) + order.order_products.each do |order_product| + order_product.product.available -= order_product.quantity + end + end + + def update_status + if self.status == nil + self.status = "pending" + end + end + + def ship_order + if self.status == "paid" + self.status = "shipped" + self.save + end + end + + def get_expiry(params) + date = Date.new(params[:order]["expiry_date(1i)"].to_i, + params[:order]["expiry_date(2i)"].to_i, + params[:order]["expiry_date(3i)"].to_i) + self.expiry_date = "#{date.month}/#{date.year}" + end + + + def find_order_merchants + merchants = [] + self.order_products.each do |product| + merchant = Merchant.find_by(product.merchant_id) + merchants << merchant + end + return merchants + end + +end diff --git a/app/models/order_product.rb b/app/models/order_product.rb new file mode 100644 index 0000000000..c808f81087 --- /dev/null +++ b/app/models/order_product.rb @@ -0,0 +1,13 @@ +class OrderProduct < ApplicationRecord + belongs_to :product + belongs_to :order + + def subtotal + subtotal = (self.product.price * self.quantity) + end + + def find_order_product(merchant_id) + product = Product.find(self.product_id) + end + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..bb2187b2a2 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,13 @@ +class Product < ApplicationRecord + has_many :order_products + has_many :reviews, dependent: :destroy + has_many :orders, through: :order_products + has_and_belongs_to_many :categories + belongs_to :merchant + + validates :name, presence: true + validates :name, uniqueness: true + validates :price, presence: true + validates :price, numericality: { only_integer: true, greater_than: 0} + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..8fb94200d3 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,6 @@ +class Review < ApplicationRecord + validates :rating, presence: true + validates_numericality_of :rating, only_integer: true, :greater_than_or_equal_to => 1, :less_than_or_equal_to => 5 + validates :description, presence: true + belongs_to :product +end diff --git a/app/views/carts/confirmation.html.erb b/app/views/carts/confirmation.html.erb new file mode 100644 index 0000000000..06d5481dc5 --- /dev/null +++ b/app/views/carts/confirmation.html.erb @@ -0,0 +1,100 @@ +
+ +

+ <%= "Confirmation for order #{@previous_order.id}" %> +

+ + + + + + + + + + + <% @previous_order.order_products.each do |i| %> + + + + + + + + + + + + <% end %> + +
ProductQuantitySubtotal
<%= link_to i.product.name, product_path(i.product.id) %><%= "x #{i.quantity}" %><%= "#{number_to_currency(i.subtotal)}" %>
+ +

Order Total: <%= number_to_currency(@previous_order.order_total) %>

+ +
+ +

Summary

+ + + + + + + + + + + +
Placed: <%= date_placed(@previous_order) %>
Status: <%= @previous_order.status.titleize %>
+ +
+ +
+ +

Contact

+ + + + + + + + + + + + + + + +
Name: <%= @previous_order.name %>
Email: <%= @previous_order.email %>
Address: <%= @previous_order.address %>
+ +
+ +
+ +

Billing

+ + + + + + + + + + + + + + + + + + + + +
Credit Cart: <%= last_four(@previous_order) %>
Expiration: <%= @previous_order.expiry_date %>
CCV Number: <%= @previous_order.cc_cvv %>
Billing Zip: <%= @previous_order.zip %>
+ +
+
diff --git a/app/views/carts/edit.html.erb b/app/views/carts/edit.html.erb new file mode 100644 index 0000000000..79cb9fecb7 --- /dev/null +++ b/app/views/carts/edit.html.erb @@ -0,0 +1,70 @@ +
+

<%= "Checkout for order #{@current_order.id}" %>

+ + <%= render partial: "layouts/error_messages", locals: { model: @current_order } %> + + + + + + + + + + + <% @order_products.each do |i| %> + + + + + + + + + + + + <% end %> + +
ProductQuantitySubtotal
<%= link_to i.product.name, product_path(i.product.id) %><%= "x #{i.quantity}" %><%= "#{number_to_currency(i.subtotal)}" %>
+

Order Total: <%= number_to_currency current_order.order_total %>

+
+ +
+ +
+ + <% @current_order.expiry_date = nil %> + + <%= form_for @current_order, url: cart_path do |f| %> + + <%= f.label :name, "Name: " %> + <%= f.text_field :name, placeholder: "Dwayne Johnson" %> + + <%= f.label :email, "Email: " %> + <%= f.email_field :email, placeholder: "dwayne.johnson@sweatsy.com" %> + + <%= f.label :address, "Address: " %> + <%= f.text_field :address, placeholder: "1234 Main Street Los Angeles, CA 90001" %> + + <%= f.label :cc_num, "Credit Card: " %> + <%= f.number_field :cc_num, placeholder: "XXXXXXXXXXXX" %> + + <%= f.label :cc_cvv, "CVV: " %> + <%= f.number_field :cc_cvv, placeholder: "XXX" %> + + <%= f.label :expiry_date, "Expiration: " %> + + <%= f.date_select :expiry_date, {order: [:month, :year], prompt: { month: 'Select month', year: 'Select year' }, start_year: Date.today.year, end_year: Date.today.year + 10}, {required: true} %> + + <%= f.label :zip, "Billing Zip: " %> + <%= f.number_field :zip, placeholder: "XXXXX" %> + + <%= f.submit "Place Order", class: 'button' %> + + <%= link_to "Back to Cart", cart_path, class: "button" %> + + <% end %> +
+ +
diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb new file mode 100644 index 0000000000..ebdaa31151 --- /dev/null +++ b/app/views/carts/show.html.erb @@ -0,0 +1,63 @@ +
+ +<% if @order_products.any? %> + +

<%= "Cart for order #{@current_order.id}" %>

+ + + + + + + + + + + + + + + <% @order_products.each do |i| %> + + <%= form_for i do |f| %> + + + + + + + + + + + <% end %> + + <% end %> +
ProductsQuantityUnit PriceSubtotal:UpdateDelete
+ <%= link_to i.product.name, product_path(i.product.id) %> + + <% max = i.product.available %> + <%= f.hidden_field :product_id, value: i.product.id %> + <%= f.number_field :quantity, value: i.quantity, min: 1, max: max, class: "quantity" %> + + <%= number_to_currency(i.product.price) %> + + <%= number_to_currency(i.subtotal) %> + + <%= f.submit "Update", class: "button" %> + + <%= link_to "Delete", order_product_path(i), :data => {:confirm => "You sure you want to remove #{i.product.name} from your cart?", :method => "delete"}, class: "button" %> +
+ +

Order Total: <%= number_to_currency(current_order.order_total) %>

+ + <%= link_to "Proceed to Checkout", checkout_path, class: "button" %> + + <%= link_to "Contine Shopping", products_path, class: "button" %> + + <% else %> +

Your shopping cart is empty.

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

All products by category

+ +
+ + <% @products_by_category.each do | c, prods | %> + +

<%= link_to c.name.capitalize, category_path(c) %>

+
+ +
+
+ +<% end %> diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..e693f843e7 --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1 @@ +
new category route
diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000000..cb3a97dcdd --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,24 @@ +

<%= @category.name.capitalize %>

+ + diff --git a/app/views/layouts/_error_messages.html.erb b/app/views/layouts/_error_messages.html.erb new file mode 100644 index 0000000000..75a24cfb85 --- /dev/null +++ b/app/views/layouts/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if model.errors.messages.any? %> +
+

There were some problems

+ +
+<% end %> diff --git a/app/views/layouts/_form.html.erb b/app/views/layouts/_form.html.erb new file mode 100644 index 0000000000..9d52a4a233 --- /dev/null +++ b/app/views/layouts/_form.html.erb @@ -0,0 +1,33 @@ + +

Add a new product

+ +<%= render partial: "layouts/error_messages", locals: { model: @product } %> + +<%= form_for @product do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :price %> + <%= f.number_field :price %> + + <%= f.label :photo, 'Photo URL' %> + <%= f.text_field :photo %> + + <%= f.label :description %> + <%= f.text_area :description %> + + <%= f.label :available %> + <%= f.number_field :available %> + +<%= f.hidden_field :merchant_id %> + + + +
+ <%= f.label :categories %> + <%= collection_check_boxes(:product, :category_ids, Category.all, :id, :name) %> +
+ + + <%= f.submit %> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..fd6f1d4c43 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,117 @@ + + + + + + + + <%= "Sweatsy" %> + + + + + <%= favicon_link_tag asset_path('favicon.png'), :rel => 'icon', :type => 'image/png' %> + + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + + + + +
+
+ <% flash.each do |name, 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/merchants/_form.html.erb b/app/views/merchants/_form.html.erb new file mode 100644 index 0000000000..5f22510707 --- /dev/null +++ b/app/views/merchants/_form.html.erb @@ -0,0 +1,11 @@ +<%= form_for @merchant do |f| %> + + <%= f.label :username, "User Name" %> + <%= f.text_field :username %> + + <%= f.label :email, "Email Address" %> + <%= f.text_field :email %> + + <%= f.submit "Sign up!" %> + +<% end %> diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb new file mode 100644 index 0000000000..69b4fed15f --- /dev/null +++ b/app/views/merchants/index.html.erb @@ -0,0 +1,61 @@ +
+
+

Browse by Merchant:

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

Get Ready to Sweat!!!

+ +<%= render partial: "form" %> diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb new file mode 100644 index 0000000000..04e8a742d6 --- /dev/null +++ b/app/views/merchants/show.html.erb @@ -0,0 +1,24 @@ + +
+ +

Welcome, <%= @merchant.username.capitalize %>!

+ +
<%= link_to "Manage your products", merchant_products_path(@merchant) %>
+ +
<%= link_to "Add a new product", new_product_path %>
+ +
<%= link_to "Manage your orders", merchant_orders_path(@merchant.id) %>
+ +
+ +
+ + <%= form_for :category, url: categories_path do |f|%> + + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.submit "Add a new category" %> + + <% end %> +
diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000000..d9f7194f96 --- /dev/null +++ b/app/views/orders/index.html.erb @@ -0,0 +1,53 @@ +

<%= @merchant.username.capitalize %>'s Order Summary Page

+ +
+

Order Details

+ + + + + + + + + + + + + + + + <% @orders.each do |order| %> + + + + + + + + + + + + <% end %> + +
ProductQuantitySubtotalStatusDateBuyerEmailAddressShip
<%= link_to Product.find(order.product_id).name, product_path(Product.find(order.product_id)) %><%= order.quantity %><%= number_to_currency(order.subtotal) %><%= order.order.status %><%= order.order.created_at.strftime("%B %d, %Y") %><%= order.order.name %><%= order.order.email %><%= order.order.address %><%= link_to "Ship Order", :controller => "orders", :action => "ship_order", :id => order.order.id%>
+ +

Revenue

+ + + + + + + + + + + + + + + +
Revenue from Paid Orders (not shipped)Revenue from Shipped OrdersTotal Revenue
<%= number_to_currency(@unshipped_orders) %><%= number_to_currency(@shipped_orders) %><%= number_to_currency(@total) %>
+
diff --git a/app/views/orders/ship_order.html.erb b/app/views/orders/ship_order.html.erb new file mode 100644 index 0000000000..31eead0d1b --- /dev/null +++ b/app/views/orders/ship_order.html.erb @@ -0,0 +1 @@ +

Order Shipped!

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

+ <%= "Placeholder" %> +

diff --git a/app/views/products/_shop_by.html.erb b/app/views/products/_shop_by.html.erb new file mode 100644 index 0000000000..81f5ec4421 --- /dev/null +++ b/app/views/products/_shop_by.html.erb @@ -0,0 +1,15 @@ +
+

Top <%= shop_by.pluralize.capitalize %>

+ + +
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..b517ba1404 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,2 @@ +
Edit Page
+<%= render partial: "layouts/form", locals: { page_title: "Edit a product"} %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..9aef3d9473 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,64 @@ +
+
+

+ Browse all products +

+
+
+ +
+
+ <% @products.each do |product| %> + + <% end%> +
+
+ +
+
diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..036f093135 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,3 @@ + + +<%= render partial: "layouts/form", locals: { page_title: "Add a new product"} %> diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb new file mode 100644 index 0000000000..e4aa29ffe9 --- /dev/null +++ b/app/views/products/root.html.erb @@ -0,0 +1,120 @@ +
+
+
+

SWEATSY

+
+

Get ready to get sweaty!

+
+
+
+

Our Story

+
+ +
+
Sweatsy, adj.: being both sweaty and sexy.
+
+ +

Are you ready to get sweaty? Sweatsy is the brainchild of Ludwig Von Swetson and Lucretia Sweatovsky, two exercise enterpreneur enthusiasts. Their vision was to start business to offer people of all walks of life high-end couture active wear. From leggings to spandex, to leotards and scrunchies, our apparel is guaranteed to make you sweat in as fabulous a way possible. We source from the most elite factories of the Lithuanian countryside and use the most sweatastic and semipermeable textiles. We hope you enjoy perusing our stock of sweaty accessories and consider buying something to help you reach sweat success! Don't sweat the small stuff! Start your day with sweatsy and love your life bigly. Hashtag live life to the sweatiest. Hashtag life is sweet and sweaty. Don't forget to follow us on Instagram puh-lease! Thank you for visiting our beautiful website! It is the best website, trust us no bugs just sweat. +

+
+ +
+
+

Browse Top Products

+
+
    +
  • +
    +
    Red Leotard
    +
    +
    + placeholder photo +
    +
  • + +
  • +
    +
    Jazz Legs
    +
    +
    + placeholder photo +
    +
  • + + +
  • +
    +
    Dry-Fit Shirt
    +
    +
    + placeholder photo +
    +
  • + +
+ <%= link_to "See More", products_path, class:'button' %> +
+
+ + +
+
+

Browse by Category

+
+
    +
  • +
    +
    <%= link_to 'Shirts', categories_path %>
    +
    +
    + placeholder photo +
    +
  • + +
  • +
    +
    <%= link_to 'Shoes', categories_path %>
    +
    +
    + placeholder photo +
    +
  • + +
  • +
    +
    <%= link_to 'Accessories', categories_path %>
    +
    +
    + placeholder photo +
    +
  • + +
  • +
    +
    <%= link_to 'Tights', categories_path %>
    +
    +
    + placeholder photo +
    +
  • + +
+ <%= link_to "See More", categories_path, class:'button' %> +
+
+ +
+
+ +

See Top Sellers

+
+
    +
  • <%= link_to Merchant.find(1).username, merchants_path %>
  • +
  • <%= link_to Merchant.find(2).username, merchants_path %>
  • +
  • <%= link_to Merchant.find(3).username, merchants_path %>
  • +
  • <%= link_to Merchant.find(4).username, merchants_path %>
  • +
+ <%= link_to "See More", merchants_path, class:'button' %> +
+
+
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..f5081fc0aa --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,81 @@ +
+

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

+ +

+ Categories: + <% @product.categories.each do |category|%> + <%= link_to category.name, category_path(category) %> + <% end %> +

+
+ +
+

<%= @product.name.titleize %>

+
+ placeholder image +
+ <%=number_to_currency(@product.price)%> +

+ <%= @product.description %> +

+

+ <%= @product.available %> Available +

+ +
+ <% if session[:merchant_id] == @product.merchant_id%> +

+ <%= link_to 'Edit', edit_product_path(@product)%> + <%= link_to 'Retire', retire_path(@product), method: :patch %> +

+ <%end%> +
+ + +
+ <%= form_for :order_product, url: order_products_path do |f| %> + <% max = @product.available %> + <%= f.hidden_field :product_id, value: @product.id %> + <%= f.number_field :quantity, value: 1, min: 1, max: max, class: "quantity" %> + <%= f.submit "Add to cart", class: "button" %> + <% end %> +
+ +
+ +
+
Average Review: <%= average_rating(@product) %>
+ +

All Reviews

+ + + + + + + <% @product.reviews.each do |review| %> + + + + + <% end %> + +
RatingDescription
<%= review.rating %><%= review.description %>
+
+ +
+

Enjoyed this product? Write a review

+ + <%= form_for :review, url: product_reviews_path(@product.id) do |f| %> + <%= f.label :rating %> + <%= f.select :rating, (1..5) %> + + <%= f.label :description %> + <%= f.text_field :description %> + + <%= f.submit %> + <% end %> + +
diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..84eb241e79 --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,10 @@ +
Add a Review For: *product name*
+<%= form_for @review do |f| %> + <%= f.label :rating %> + <%= f.number_field :rating %> + + <%= f.label :description %> + <%= f.text_field :description %> + + <%= f.submit %> +<% end %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000000..66e9889e8b --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +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..78c4e861dc --- /dev/null +++ b/bin/setup @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +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..a8e4462f20 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +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') + + 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..c2bacef836 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +VENDOR_PATH = File.expand_path('..', __dir__) +Dir.chdir(VENDOR_PATH) do + begin + exec "yarnpkg #{ARGV.join(" ")}" + 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..5f6ca0f9b2 --- /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.1 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000000..30f5120df6 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000000..3cba994bb2 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 + channel_prefix: betsy_production 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..5187e22186 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,54 @@ +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. + 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.seconds.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # 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 + + # 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..f97f2af958 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,93 @@ +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 + + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = 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 + + # 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') + config.serve_static_assets = true + config.assets.compile = true + + 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..8e5cbde533 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +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.seconds.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 + 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/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/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..1e19380dcb --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,56 @@ +# 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. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# If you are preloading your application and using Active Record, it's +# recommended that you close any connections to the database before workers +# are forked to prevent connection leakage. +# +# before_fork do +# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) +# end + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted, this block will be run. If you are using the `preload_app!` +# option, you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, as Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end +# + +# 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..6e20d5dada --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,40 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + root 'products#root' + + patch '/products/:id/retire', to: 'products#retire', as: 'retire' + + get '/:id/ship_order', to: 'orders#ship_order', as: 'ship_order' + + post '/products/:id/add_review', to: 'products#create_review', as: :create_review + + get '/auth/github', as: 'github_login' + + delete '/logout', to: 'sessions#destroy', as: 'logout' + + get "/auth/:provider/callback", to: "sessions#create", as: 'auth_callback' + + resources :products do + resources :reviews, only: [:new, :show, :create] + end + + resources :orders, only: [:show, :create, :update] + + get '/checkout', to: 'carts#edit', as: :checkout + get '/order_confirmation', to: 'carts#confirmation', as: :confirmation + + # may not need all routes for order_products + resources :order_products + resource :cart, only: [:show, :update] + + resources :categories, only: [:new, :create, :index, :show] do + resources :product, only: [:root] + end + + resources :merchants, except: [:edit, :update, :destroy] do + resources :products, only: [:index] + resources :orders, only: [:index] + end + +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000000..7f68fb3891 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,32 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +# Shared secrets are available across all environments. + +# shared: +# api_key: a1B2c3D4e5F6 + +# Environmental secrets are only available for that specific environment. + +development: + secret_key_base: 55a259c3241bf3d44e4e4b5b21aaefa1793e2ff067ae9a4dd34c9d9494c9d99f9f5aa16f311b45f1582027f9c5c360a61f2558b4671f57923c1db5344b0d6aaf + +test: + secret_key_base: 7fd84c0d006d6c01509c844e7b9e5ba1e7b3e18397001daf50b05eecc3e13ee272c34de9df91fa521a549d132193c937faf2235831adaf09217968432d55703a + +# Do not keep production secrets in the unencrypted secrets file. +# Instead, either read values from the environment. +# Or, use `bin/rails secrets:setup` to configure encrypted secrets +# and move the `production:` environment over there. + +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 0000000000..c9119b40c0 --- /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/db/migrate/20180419192941_create_merchants.rb b/db/migrate/20180419192941_create_merchants.rb new file mode 100644 index 0000000000..64a57c904c --- /dev/null +++ b/db/migrate/20180419192941_create_merchants.rb @@ -0,0 +1,10 @@ +class CreateMerchants < ActiveRecord::Migration[5.1] + def change + create_table :merchants do |t| + t.string :username + t.string :email + + t.timestamps + end + end +end diff --git a/db/migrate/20180419200734_create_reviews.rb b/db/migrate/20180419200734_create_reviews.rb new file mode 100644 index 0000000000..68962656fc --- /dev/null +++ b/db/migrate/20180419200734_create_reviews.rb @@ -0,0 +1,10 @@ +class CreateReviews < ActiveRecord::Migration[5.1] + def change + create_table :reviews do |t| + t.integer "rating" + t.string "description" + + t.timestamps + end + end +end diff --git a/db/migrate/20180419204902_create_orders.rb b/db/migrate/20180419204902_create_orders.rb new file mode 100644 index 0000000000..4c82956027 --- /dev/null +++ b/db/migrate/20180419204902_create_orders.rb @@ -0,0 +1,8 @@ +class CreateOrders < ActiveRecord::Migration[5.1] + def change + create_table :orders do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20180419204920_all_columns_to_order.rb b/db/migrate/20180419204920_all_columns_to_order.rb new file mode 100644 index 0000000000..b1127e0873 --- /dev/null +++ b/db/migrate/20180419204920_all_columns_to_order.rb @@ -0,0 +1,13 @@ +class AllColumnsToOrder < ActiveRecord::Migration[5.1] + def change + add_column :orders, :date, :date + add_column :orders, :status, :string + add_column :orders, :name, :string + add_column :orders, :email, :string + add_column :orders, :address, :string + add_column :orders, :cc_num, :string + add_column :orders, :expiry_date, :date + add_column :orders, :cc_cvv, :string + add_column :orders, :zip, :string + end +end diff --git a/db/migrate/20180419212035_create_products.rb b/db/migrate/20180419212035_create_products.rb new file mode 100644 index 0000000000..f7229bfe9a --- /dev/null +++ b/db/migrate/20180419212035_create_products.rb @@ -0,0 +1,11 @@ +class CreateProducts < ActiveRecord::Migration[5.1] + def change + create_table :products do |t| + t.string :name + t.integer :price + t.integer :available + + t.timestamps + end + end +end diff --git a/db/migrate/20180419214250_create_categories.rb b/db/migrate/20180419214250_create_categories.rb new file mode 100644 index 0000000000..9528428eb8 --- /dev/null +++ b/db/migrate/20180419214250_create_categories.rb @@ -0,0 +1,8 @@ +class CreateCategories < ActiveRecord::Migration[5.1] + def change + create_table :categories do |t| + t.string "name" + t.timestamps + end + end +end diff --git a/db/migrate/20180420002031_change_expiry_data_type.rb b/db/migrate/20180420002031_change_expiry_data_type.rb new file mode 100644 index 0000000000..40b193d8c0 --- /dev/null +++ b/db/migrate/20180420002031_change_expiry_data_type.rb @@ -0,0 +1,6 @@ +class ChangeExpiryDataType < ActiveRecord::Migration[5.1] + def change + change_column :orders, :date, :timestamp + change_column :orders, :expiry_date, :string + end +end diff --git a/db/migrate/20180420003356_delete_date_column_from_order.rb b/db/migrate/20180420003356_delete_date_column_from_order.rb new file mode 100644 index 0000000000..8a2ebf8920 --- /dev/null +++ b/db/migrate/20180420003356_delete_date_column_from_order.rb @@ -0,0 +1,5 @@ +class DeleteDateColumnFromOrder < ActiveRecord::Migration[5.1] + def change + remove_column :orders, :date + end +end diff --git a/db/migrate/20180420210859_createorderproductsjoin.rb b/db/migrate/20180420210859_createorderproductsjoin.rb new file mode 100644 index 0000000000..000d4417b4 --- /dev/null +++ b/db/migrate/20180420210859_createorderproductsjoin.rb @@ -0,0 +1,8 @@ +class Createorderproductsjoin < ActiveRecord::Migration[5.1] + def change + create_table :order_products do |t| + t.belongs_to :order, index: true + t.belongs_to :product, index: true + end + end +end diff --git a/db/migrate/20180420212840_add_quantity_field_to_order_products_table.rb b/db/migrate/20180420212840_add_quantity_field_to_order_products_table.rb new file mode 100644 index 0000000000..6105b5bcf8 --- /dev/null +++ b/db/migrate/20180420212840_add_quantity_field_to_order_products_table.rb @@ -0,0 +1,5 @@ +class AddQuantityFieldToOrderProductsTable < ActiveRecord::Migration[5.1] + def change + add_column :order_products, :quantity, :integer + end +end diff --git a/db/migrate/20180420213433_category_product_join_table.rb b/db/migrate/20180420213433_category_product_join_table.rb new file mode 100644 index 0000000000..9afdf35e6a --- /dev/null +++ b/db/migrate/20180420213433_category_product_join_table.rb @@ -0,0 +1,8 @@ +class CategoryProductJoinTable < ActiveRecord::Migration[5.1] + def change + create_table :categories_products do |t| + t.belongs_to :category, index: true + t.belongs_to :product, index: true + end + end +end diff --git a/db/migrate/20180420214528_add_merchant_id_to_products.rb b/db/migrate/20180420214528_add_merchant_id_to_products.rb new file mode 100644 index 0000000000..45930fd0d9 --- /dev/null +++ b/db/migrate/20180420214528_add_merchant_id_to_products.rb @@ -0,0 +1,5 @@ +class AddMerchantIdToProducts < ActiveRecord::Migration[5.1] + def change + add_reference :products, :merchant, foreign_key: true + end +end diff --git a/db/migrate/20180421042831_add_product_id_to_reviews.rb b/db/migrate/20180421042831_add_product_id_to_reviews.rb new file mode 100644 index 0000000000..aa157d4e07 --- /dev/null +++ b/db/migrate/20180421042831_add_product_id_to_reviews.rb @@ -0,0 +1,5 @@ +class AddProductIdToReviews < ActiveRecord::Migration[5.1] + def change + add_reference :reviews, :product, foreign_key: true + end +end diff --git a/db/migrate/20180422033227_add_description_and_image_to_new_product_form.rb b/db/migrate/20180422033227_add_description_and_image_to_new_product_form.rb new file mode 100644 index 0000000000..fe56fe3ab5 --- /dev/null +++ b/db/migrate/20180422033227_add_description_and_image_to_new_product_form.rb @@ -0,0 +1,6 @@ +class AddDescriptionAndImageToNewProductForm < ActiveRecord::Migration[5.1] + def change + add_column :products, :description, :string + add_column :products, :photo, :string + end +end diff --git a/db/migrate/20180422220445_add_product_id_to_review.rb b/db/migrate/20180422220445_add_product_id_to_review.rb new file mode 100644 index 0000000000..b1c7939a32 --- /dev/null +++ b/db/migrate/20180422220445_add_product_id_to_review.rb @@ -0,0 +1,4 @@ +class AddProductIdToReview < ActiveRecord::Migration[5.1] + def change + end +end diff --git a/db/migrate/20180422222854_fix_last_migration.rb b/db/migrate/20180422222854_fix_last_migration.rb new file mode 100644 index 0000000000..cd82375ebd --- /dev/null +++ b/db/migrate/20180422222854_fix_last_migration.rb @@ -0,0 +1,7 @@ +require_relative '20180422220445_add_product_id_to_review' + +class FixLastMigration < ActiveRecord::Migration[5.1] + def change + revert AddProductIdToReview + end +end diff --git a/db/migrate/20180424175628_add_uid_and_provider_to_merchants.rb b/db/migrate/20180424175628_add_uid_and_provider_to_merchants.rb new file mode 100644 index 0000000000..22e8a4f2a6 --- /dev/null +++ b/db/migrate/20180424175628_add_uid_and_provider_to_merchants.rb @@ -0,0 +1,6 @@ +class AddUidAndProviderToMerchants < ActiveRecord::Migration[5.1] + def change + add_column :merchants, :uid, :integer, null: false + add_column :merchants, :provider, :string, null: false + end +end diff --git a/db/migrate/20180426150803_add_total_to_orders_table.rb b/db/migrate/20180426150803_add_total_to_orders_table.rb new file mode 100644 index 0000000000..fec35a9dfc --- /dev/null +++ b/db/migrate/20180426150803_add_total_to_orders_table.rb @@ -0,0 +1,5 @@ +class AddTotalToOrdersTable < ActiveRecord::Migration[5.1] + def change + add_column :orders, :total, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..cb2585884a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,85 @@ +# 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: 20180426150803) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "categories_products", force: :cascade do |t| + t.bigint "category_id" + t.bigint "product_id" + t.index ["category_id"], name: "index_categories_products_on_category_id" + t.index ["product_id"], name: "index_categories_products_on_product_id" + end + + create_table "merchants", force: :cascade do |t| + t.string "username" + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "uid", null: false + t.string "provider", null: false + end + + create_table "order_products", force: :cascade do |t| + t.bigint "order_id" + t.bigint "product_id" + t.integer "quantity" + t.index ["order_id"], name: "index_order_products_on_order_id" + t.index ["product_id"], name: "index_order_products_on_product_id" + end + + create_table "orders", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "status" + t.string "name" + t.string "email" + t.string "address" + t.string "cc_num" + t.string "expiry_date" + t.string "cc_cvv" + t.string "zip" + t.integer "total" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.integer "price" + t.integer "available" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "merchant_id" + t.string "description" + t.string "photo" + t.index ["merchant_id"], name: "index_products_on_merchant_id" + end + + create_table "reviews", force: :cascade do |t| + t.integer "rating" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "product_id" + t.index ["product_id"], name: "index_reviews_on_product_id" + end + + add_foreign_key "products", "merchants" + add_foreign_key "reviews", "products" +end diff --git a/db/seed_data/categories-products.csv b/db/seed_data/categories-products.csv new file mode 100644 index 0000000000..97fc2a98ef --- /dev/null +++ b/db/seed_data/categories-products.csv @@ -0,0 +1,31 @@ +category_name,product_name +Pants,Track Pants +Accessories,Pink Head Band +Accessories,Orange Head Band +Accessories,Sweaty Accessory +Shirts,Rain Jacket +Outerwear,Rain Jacket +Shoes,White Sneakers +Outerwear,White Sneakers +Outerwear,Head Band +Accessories,Head Band +Accessories,Purple Leotard +Tights,Purple Leotard +Accessories,Red Leotard +Tights,Red Leotard +Tights,Black Tights +Accessories,Black Tights +Outerwear,Track Jacket +Shirts,Track Jacket +Tights,Spandex +Tights,Green Spandex +Accessories,Neon Head Band +Tights,Touquoise Tights +Shirts,Dry fit Shirt +Dry fit,Dry fit Shirt +Shoes,Purple Sneakers +Shoes,Neon Sneakers +Dry fit,Silk Leotard +Accessories,Silk Leotard +Accessories,Jazz legs +Legwarmers,Jazz legs diff --git a/db/seed_data/categories.csv b/db/seed_data/categories.csv new file mode 100644 index 0000000000..3dbb14fe35 --- /dev/null +++ b/db/seed_data/categories.csv @@ -0,0 +1,10 @@ +name +Shirts +Pants +Shoes +Outerwear +Accessories +Leotards +Legwarmers +Tights +Dry fit diff --git a/db/seed_data/merchants.csv b/db/seed_data/merchants.csv new file mode 100644 index 0000000000..868f373174 --- /dev/null +++ b/db/seed_data/merchants.csv @@ -0,0 +1,6 @@ +username,email,uid,provider +gregg,gregg.popovich@nba.com,1,github +tyronn,tyronn.lue@nba.com,2,github +steve,steve.kerr@nba.com,3,github +becky,becky.hammon@nba.com,4,github +mark,mark.jackson@nba.com,5,github diff --git a/db/seed_data/orders-products.csv b/db/seed_data/orders-products.csv new file mode 100644 index 0000000000..0d1deb9261 --- /dev/null +++ b/db/seed_data/orders-products.csv @@ -0,0 +1,9 @@ +order_id,product_name,quantity +1,Sweaty Accessory,1 +2,White Sneakers,3 +2,Rain Jacket,1 +3,Track Pants,2 +3,Rain Jacket,1 +3,White Sneakers,1 +3,Sweaty Accessory,1 +4,Head Band,4 diff --git a/db/seed_data/orders.csv b/db/seed_data/orders.csv new file mode 100644 index 0000000000..2f133e44d9 --- /dev/null +++ b/db/seed_data/orders.csv @@ -0,0 +1,5 @@ +status,name,email,address,cc_num,expiry_date,cc_cvv,zip, order +pending,Danny Green,danny@nba.com,"1234 5th Street Seattle, WA 98125",1234567888888888,1020,100,98312, +paid,Lebron James,lebron@nba.com,"6789 10th Street Seattle, WA 98125",1234512345123456,1118,200,98004, +complete,Harrison Barnes,harrison@nba.com,"1112 13th Street Seattle, WA 98125",3334445556667778,1119,300,98111, +cancelled,Kyrie Irving,kyrie@nba.com,"1415 16th Street Seattle, WA 98125",1010101111223345,1220,400,98332, diff --git a/db/seed_data/products.csv b/db/seed_data/products.csv new file mode 100644 index 0000000000..5aee46a96b --- /dev/null +++ b/db/seed_data/products.csv @@ -0,0 +1,2 @@ +name,price,available,description,photo,merchant +Track Pants,5000,20,Run faster sweat less,https://img.etsystatic.com/il/557be1/1397617100/il_570xN.1397617100_hbfj.jpg?version=2,1 diff --git a/db/seed_data/products2.csv b/db/seed_data/products2.csv new file mode 100644 index 0000000000..7a8ef418db --- /dev/null +++ b/db/seed_data/products2.csv @@ -0,0 +1,21 @@ +name,price,available,description,photo,merchant +Track Pants,5000,20,Run faster sweat less,https://img.etsystatic.com/il/557be1/1397617100/il_570xN.1397617100_hbfj.jpg?version=2,1 +Pink Head Band,699,20,No more sweat on your brows,https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ7hS4Q98DdAFHMLc0KiU70V1w9_-Vj63hfb4HAbSeAF7EhrMO4Og,1 +Orange Head Band,699,20,No more sweat on your brows,https://images-na.ssl-images-amazon.com/images/I/2105qPRuO3L.jpg,1 +Rain Jacket,3545,20,It will fight off the rain,https://img.etsystatic.com/il/bc058f/1469960898/il_570xN.1469960898_1l2g.jpg?version=0,2 +White Sneakers,6405,20,Protection for all the sweat, https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSi0uC5YCQw4wPrSqbF4f_Vy6bj7of4xU2UfcWaFgaBJENIGUSswg,4 +Sweaty Accessory,225,20, reduces sweat from everywhere you put it,http://d3eum8lucccgeh.cloudfront.net/designs/32518/DontSweat_grn.jpg,5 +Purple Leotard,100,20,Move around easier,https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR2pcWWgkfWtT9sCk7uJLoiSJXxVNZFZ-BUUGfSkIl75eHj0IFKfA,2 +Red Leotard,200,20,Let it shine,https://img.etsystatic.com/il/ba4e45/1088013044/il_570xN.1088013044_iqj2.jpg?version=1,2 +Black Tights,90,10,Release the sweat,https://rlv.zcache.co.uk/black_and_white_80s_style_leggings-rfc5f404502bc4d8e96e0024d6923df38_6ftq3_260.jpg?rlvnet=1,1 +Track Jacket,2700,20,Run faster sweat less,http://picture-cdn.wheretoget.it/yu7qzh-l.jpg,1 +Spandex,5000,20,Run faster sweat less, https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRjePGQzichk23U5SuvA3lfx6bs5Kk1gDIPd0uf_vNRmtrMUnjFvA,1 +Neon Head Band,699,20,No more sweat on your brows,https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTja6mFBrA_bETAZxt7VFuhLQJ6cxblasq5UZikxycFH6hdI3vp,3 +Green Spandex,5000,20,Run faster sweat less, https://images-na.ssl-images-amazon.com/images/I/41oVO%2BPcNuL.jpg,1 +Touquoise Tights,90,10,Release the sweat,https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQzwAoa1ivQNHyTTkcQpxAdx6kKfDwouri_Dhx9mIfhZdD77nkT,2 +Dry fit Shirt,90,10,Release the sweat,https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQEwKyPTI4qtkNvqj5V4i5fjDTTJ0WpErK6AFZp0Jf9MgBlRKwMg,1 +Neon Sneakers,6405,20,Protection for all the sweat, https://c2.staticflickr.com/4/3259/2786550775_62cc73ca14_z.jpg?zz=1,3 +Purple Sneakers,6405,20,Protection for all the sweat, https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQVlQpQlULhphplRcysE375sKUo8Z6mwCiCeFYYrZ-jmBbrA10QaA,4 +Silk Leotard,200,20,Let it shine,https://cdn-img-1.wanelo.com/p/d32/571/6b5/5e4564e57ff129f747ad555/x354-q80.jpg,2 +Head Band,699,20,No more sweat on your brows,https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQIO2Fgsx7PxowCtLuzPtRLIR7yIam8ayH97oBYStJBSBbsqNVs,3 +Jazz legs,200,20,Let it shine,https://i.pinimg.com/originals/23/de/e8/23dee8bb0263a8507325f0cdbd8b37f9.jpg,2 diff --git a/db/seed_data/reviews.csv b/db/seed_data/reviews.csv new file mode 100644 index 0000000000..0ab8fbed9b --- /dev/null +++ b/db/seed_data/reviews.csv @@ -0,0 +1,7 @@ +rating,description,product_name +1,Horrible product! Sweat everywhere!!,Sweaty Accessory +2,"Eh, I'm not impressed. Not so great and I wouldn't buy it again.",Track Pants +3,"This product is okay. Nothing to call home about, but it gets the job done.",Purple Leotard +4,I like it! Very nice...minimal sweat.,White Sneakers +5,This is a really fabulous product. It controlled my sweat!,Head Band +2,"Meh! Too tight.",Silk Leotard diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..03c559e07a --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,161 @@ +require 'csv' + +CATEGORIES_FILE = Rails.root.join('db', 'seed_data', 'categories.csv') +puts "Loading raw category data from #{CATEGORIES_FILE}" + +category_failures = [] +CSV.foreach(CATEGORIES_FILE, :headers => true) do |row| + category = Category.new + category.name = row['name'] + successful = category.save + if !successful + category_failures << category + puts "Failed to save category: #{category.inspect}" + else + puts "Created category: #{category.inspect}" + end +end + +puts "Added #{Category.count} category records" +puts "#{category_failures.count} categories failed to save" + + + +MERCHANTS_FILE = Rails.root.join('db', 'seed_data', 'merchants.csv') +puts "Loading raw merchant data from #{MERCHANTS_FILE}" + +merchant_failures = [] +CSV.foreach(MERCHANTS_FILE, :headers => true) do |row| + merchant = Merchant.new + merchant.username = row['username'] + merchant.email = row['email'] + merchant.uid = row['uid'] + merchant.provider = row['provider'] + successful = merchant.save + if !successful + merchant_failures << merchant + puts "Failed to save merchant: #{merchant.inspect}" + else + puts "Created merchant: #{merchant.inspect}" + end +end + +puts "Added #{Merchant.count} merchant records" +puts "#{merchant_failures.count} merchants failed to save" + + + +ORDERS_FILE = Rails.root.join('db', 'seed_data', 'orders.csv') +puts "Loading raw order data from #{ORDERS_FILE}" + +order_failures = [] +CSV.foreach(ORDERS_FILE, :headers => true) do |row| + order = Order.new + order.status = row['status'] + order.name = row['name'] + order.email = row['email'] + order.address = row['address'] + order.cc_num = row['cc_num'] + order.expiry_date = row['expiry_date'] + order.cc_cvv = row['cc_cvv'] + order.zip = row['zip'] + order.total = row['total'] + successful = order.save + if !successful + order_failures << order + puts "Failed to save order: #{order.inspect}" + else + puts "Created order: #{order.inspect}" + end +end + +puts "Added #{Order.count} order records" +puts "#{order_failures.count} orders failed to save" + + + +PRODUCTS_FILE = Rails.root.join('db', 'seed_data', 'products2.csv') +puts "Loading raw category data from #{PRODUCTS_FILE}" + +product_failures = [] +CSV.foreach(PRODUCTS_FILE, :headers => true) do |row| + product = Product.new + product.name = row['name'] + product.price = row['price'] + product.available = row['available'] + product.description = row['description'] + product.photo = row['photo'] + product.merchant_id = row['merchant'] + successful = product.save + if !successful + product_failures << product + puts "Failed to save product: #{product.inspect}" + else + puts "Created product: #{product.inspect}" + end +end + +puts "Added #{Product.count} product records" +puts "#{product_failures.count} products failed to save" + + + + +REVIEWS_FILE = Rails.root.join('db', 'seed_data', 'reviews.csv') +puts "Loading raw review data from #{REVIEWS_FILE}" + +review_failures = [] +CSV.foreach(REVIEWS_FILE, :headers => true) do |row| + review = Review.new + review.rating = row['rating'] + review.description = row['description'] + product = Product.find_by(name: row['product_name']) + review.product_id = product.id + successful = review.save + if !successful + review_failures << review + puts "Failed to save review: #{review.inspect}" + else + puts "Created review: #{review.inspect}" + end +end + +puts "Added #{Review.count} review records" +puts "#{review_failures.count} reviews failed to save" + + + +CATEGORIESPRODUCTS_FILE = Rails.root.join('db', 'seed_data', 'categories-products.csv') +puts "Loading raw categories_products data from #{CATEGORIESPRODUCTS_FILE}" + + +CSV.foreach(CATEGORIESPRODUCTS_FILE, :headers => true) do |row| + category = Category.find_by(name: row['category_name']) + product = Product.find_by(name: row['product_name']) + category.products << product +end + +puts "done with categories-products" + + + +ORDERSPRODUCTS_FILE = Rails.root.join('db', 'seed_data', 'orders-products.csv') +puts "Loading raw orders_products data from #{ORDERSPRODUCTS_FILE}" + +orderproduct_failures = [] +CSV.foreach(ORDERSPRODUCTS_FILE, :headers => true) do |row| + order_product = OrderProduct.new + order_product.order_id = Order.find(row['order_id']).id + order_product.product_id = Product.find_by(name: row['product_name']).id + order_product.quantity = row['quantity'] + successful = order_product.save + if !successful + orderproduct_failures << order_product + puts "Failed to save order_product: #{order_product.inspect}" + else + puts "Created order_product: #{order_product.inspect}" + end +end + +puts "Added #{OrderProduct.count} order_product records" +puts "#{orderproduct_failures.count} order_product records failed to save" 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/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb new file mode 100644 index 0000000000..f6b1fd8761 --- /dev/null +++ b/test/controllers/carts_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe CartsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..d57d338ee5 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,39 @@ +require "test_helper" + +describe CategoriesController do + + describe "index" do + it "sends a success reponse when there are many categories" do + Category.count.must_be :>, 0 + get categories_path + must_respond_with :success + end + + it "sends a success response when there are no categories" do + # destroy all products before destroying all categories + Product.destroy_all + Category.destroy_all + Category.count.must_equal 0 + get merchants_path + must_respond_with :success + end + end + + describe "create" do + it "saves a valid category" do + category_data = {name: 'new category'} + merchant = Merchant.first + old_category_count = Category.count + + Category.new(category_data).must_be :valid? + login(merchant) + + post categories_path, params: {category: category_data} + + must_respond_with :redirect + must_redirect_to merchant_path(id: merchant.id) + Category.count.must_equal old_category_count + 1 + end + end + +end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb new file mode 100644 index 0000000000..230f0c5710 --- /dev/null +++ b/test/controllers/merchants_controller_test.rb @@ -0,0 +1,50 @@ +require "test_helper" +require 'pry' +describe MerchantsController do + + describe "index" do + it "sends a success reponse when there are many merchants" do + Merchant.count.must_be :>, 0 + get merchants_path + must_respond_with :success + end + + it "sends a success response when there are no merchants" do + # destroy all products before destroying all merchants due to foreign key constraint + Product.destroy_all + Merchant.destroy_all + Merchant.count.must_equal 0 + get merchants_path + must_respond_with :success + end + + end + + describe "new" do + it "sends a success response" do + get new_merchant_path + must_respond_with :found + end + end + + describe "show" do + it "sends a success response if the merchant exists in the database" do + merchant = Merchant.first + + merchant.must_be :valid? + + get merchant_path(merchant) + + must_respond_with :found + end + + it "sends not_found if the merchant does not exist in the database" do + merchant = Merchant.last.id + 1 + + get merchant_path(merchant) + + must_redirect_to root_path + end + end + +end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb new file mode 100644 index 0000000000..b4e157b21c --- /dev/null +++ b/test/controllers/order_products_controller_test.rb @@ -0,0 +1,61 @@ +require "test_helper" +require 'pry' +describe OrderProductsController do + + describe 'create' do + + it "can create an OrderProduct with valid data" do + order = Order.first + + item_data = { + order_id: order.id, + quantity: 10, + product_id: Product.first.id + } + + # equals 0 + old_count = order.order_products.count + + post order_products_path, params: { order_product: item_data } + + must_respond_with :redirect + must_redirect_to products_path + + # still equals 0, not saving + order.order_products.count.must_equal old_count + 1 + end + + it "does not create an OrderProduct with incomplete data" do + order = Order.first + + item_data = { + quantity: 10, + } + old_count = order.order_products.count + + post order_products_path, params: { order_product: item_data } + + must_respond_with :bad_request + # still equals 0, not saving + order.order_products.count.must_equal old_count + end + + end + + describe 'update' do + + it "updates the quantity of an existing OrderProduct with a valid number" do + order = Order.first + + order_product = OrderProduct.create!(quantity: 1, order_id: order.id, product_id: Product.first.id) + + item_data = order_product.attributes + item_data[:quantity] = 2 + + patch order_product_path(order_product), params: { order_product: item_data } + + 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..eb3408d086 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,95 @@ +require "test_helper" + +describe OrdersController do + + describe 'show' do + + it "succeeds if order exists" do + get order_path(Order.first) + must_respond_with :found + end + + it "sends not_found if order doesn't exit" do + merchant = Merchant.first + login(merchant) + order_id = Order.last.id + 5 + + get order_path(order_id) + + must_respond_with :not_found + end + + end + + describe 'create' do + + it "can add a valid order" do + order_data = { + status: "in progress", + name: "Max", + email: "max@adaacademy.com", + # address zip + address: "2627 107th Ave NE Bellevue, WA 98004", + cc_num: "1234567891011121", + expiry_date: "1020", + cc_cvv: "123", + # billing zip + zip: "98004" + } + old_order_count = Order.count + + Order.new(order_data).must_be :valid? + + post orders_path, params: { order: order_data} + + must_respond_with :redirect + must_redirect_to order_path(Order.last.id) + + # 2 bc a new cart is created when order_path is run + # after it's complete there's an empty cart in addition to the order added + Order.count.must_equal old_order_count + 2 + Order.last.name.must_equal order_data[:name] + end + + # cart is created with only some of the payment validation errors + # this can't actually occur on the website bc validations are ran when payment details are processed + it "accepts invalid order bc it will hit validations at payment" do + order_data = { + name: "Max", + email: "max@adaacademy.com", + # address zip + address: "2627 107th Ave NE Bellevue, WA 98004", + cc_num: nil, + expiry_date: "1020", + cc_cvv: "123", + # billing zip + zip: "98004", + } + old_order_count = Order.count + + Order.new(order_data).must_be :valid? + + post orders_path, params: { order: order_data } + + must_respond_with :redirect + must_redirect_to order_path(Order.last.id) + + # 2 bc a new cart is created when order_path is run + # after it's complete there's an empty cart in addition to the order added + Order.count.must_equal old_order_count + 2 + end + + end + + describe "index" do + it "finds merchants orders" do + merchant = Merchant.first + login(merchant) + order_id = Order.last + + get merchant_orders_path(merchant) + must_respond_with :success + end + end + +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..8f4721d0ed --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,206 @@ +require "test_helper" + +describe ProductsController do + + describe 'index' do + it "sends a success response where there are products" do + + Product.count.must_be :>,0 + + get products_path + + must_respond_with :success + + end + + it "sends a success response when there are no products" do + Product.destroy_all + + get products_path + + Product.count.must_equal 0 + must_respond_with :success + end + end + + describe 'new' do + it "sends a success response when merchant adds a new product" do + login(Merchant.first) + get new_product_path + must_respond_with :success + end + + # it "sends bad request when a guest tries to add a new product" do + # get new_product_path + # must_respond_with :bad_request + # end + end + + describe 'create' do + + it "can add a product with valid data" do + merchant = Merchant.first + product_data = { + name: 'random', + price: 3, + available: 4, + merchant_id: merchant.id + } + old_product_count = Product.count + + product = Product.new(product_data) + + product.must_be :valid? + + post products_path, params: { product: product_data} + + must_respond_with :redirect + + must_redirect_to merchant_products_path(merchant.id) + + Product.count.must_equal old_product_count + 1 + + Product.last.name.must_equal product_data[:name] + end + + it "renders error for invalid data" do + + product_data = { + merchant_id: Merchant.first.id + } + old_product_count = Product.count + + product = Product.new(product_data) + + product.wont_be :valid? + + post products_path, params: { product: product_data} + + must_respond_with :bad_request + + Product.count.must_equal old_product_count + end + end + + describe 'edit' do + + it "send success if form loads" do + merchant = Merchant.first + login(merchant) + get edit_product_path(Product.find_by(merchant: merchant)) + must_respond_with :success + end + + it "sends not_found if product does not exist" do + + product_id = Product.last.id + 1 + + get edit_product_path(product_id) + must_respond_with :not_found + + end + end + + describe 'show' do + it "send success if the product exists" do + + get product_path(Product.first) + must_respond_with :success + end + + it "sends not_found if product does not exist" do + + product_id = Product.last.id + 1 + + get product_path(product_id) + must_respond_with :not_found + + end + end + + describe 'update' do + it "updates existing product with valid data" do + + # product = Product.first + # product_data = product.attributes + # + # product_data[:name] = "sweaty stuff" + # + # product.assign_attributes(product_data) + # + # product.must_be :valid? + # + # patch product_path(product), params: { product: product_data } + # + # must_redirect_to product_path(product) + # + # product.reload + # product.name.must_equal product_data[:name] + end + + it "sends bad_request when data is invalid" do + + merchant = Merchant.first + login(merchant) + + product = Product.find_by(merchant: merchant) + + product_data = product.attributes + + product_data[:name] = "" + + product.assign_attributes(product_data) + + product.wont_be :valid? + + patch product_path(product), params: { product: product_data } + + must_respond_with :bad_request + + product.reload + product.name.wont_equal product_data[:name] + end + + it "sends not_found for a product that does not exist" do + + product_id = Product.last.id + 1 + + patch product_path(product_id) + + must_respond_with :not_found + end + + end + + describe 'destroy' do + it "can destroy a product" do + + merchant = Merchant.first + login(merchant) + + product_id = Product.find_by(merchant: merchant).id + + old_product_count = Product.count + + delete product_path(product_id) + + must_respond_with :redirect + must_redirect_to products_path + + Product.count.must_equal old_product_count - 1 + end + + it "sends not_found when product does not exist" do + + product_id = Product.first.id + 1 + old_product_count = Product.count + + delete product_path(product_id) + + must_respond_with :not_found + + Product.count.must_equal old_product_count + + 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..f86912b9a2 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,34 @@ +require "test_helper" +require 'pry' + +describe ReviewsController do + describe 'create' do + it "creates a review with valid data" do + product_id = Product.first.id + review_data = { rating: 5, description: 'review description', product_id: product_id } + + old_review_count = Review.count + + Review.new(review_data).must_be :valid? + post product_reviews_path(product_id), params: { review: review_data} + + must_respond_with :redirect + must_redirect_to product_path(product_id) + Review.count.must_equal old_review_count + 1 + Review.last.description.must_equal 'review description' + end + + it "responds with bad request for missing input" do + product_id = Product.first.id + review_data = { description: 'review description', product_id: product_id } + + old_review_count = Review.count + + Review.new(review_data).wont_be :valid? + post product_reviews_path(product_id), params: { review: review_data} + + must_respond_with :bad_request + Review.count.must_equal old_review_count + end + end +end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..0a68cade44 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,71 @@ +require "test_helper" + +describe SessionsController do + describe 'create action via auth_callback_path' do + it "creates a new DB entry for a new user" do + merchant = Merchant.new( + provider: 'github', + uid: 0000, + email: 'test@test.org', + username: 'testuser' + ) + + merchant.must_be :valid? + old_merchant_count = Merchant.count + + login(merchant) + + Merchant.count.must_equal old_merchant_count + 1 + session[:merchant_id].must_equal Merchant.last.id + end + it "cannot create new user due to invalid data" do + merchant = Merchant.new( + provider: 'github', + uid: 0000, + username: 'testuser' + ) + + merchant.wont_be :valid? + old_merchant_count = Merchant.count + + login(merchant) + + Merchant.count.must_equal old_merchant_count + end + + it "logs in existing merchant" do + merchant = Merchant.first + old_merchant_count = Merchant.count + + login(merchant) + + session[:merchant_id].must_equal Merchant.first.id + must_redirect_to merchant_path(Merchant.first.id) + Merchant.count.must_equal old_merchant_count + end + + it "flashes error for invalid info in callback path" do + merchant = Merchant.new( + provider: 'github', + email: 'test@test.org', + username: 'testuser' + ) + + login(merchant) + + flash[:error].must_equal "Could not authenticate user via Github" + must_redirect_to root_path + end + end + + describe 'destroy action' do + it "logs user out" do + merchant = Merchant.first + + login(merchant) + logout(merchant) + + session[:merchant_id].must_be_nil + 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..e49dbb20b1 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below + + +shorts: + name: Shorts + +shirts: + name: Shirts + +pants: + name: Pants + +accessories: + name: Accessories + diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml new file mode 100644 index 0000000000..2739b20ae7 --- /dev/null +++ b/test/fixtures/merchants.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +merchant_one: + username: merchant_one + email: merchant_one@gmail.com + uid: 1 + provider: github + +merchant_two: + username: merchant_two + email: merchant_two@gmail.com + uid: 2 + provider: github diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..de6207ff56 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,25 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below + +basic_order: + status: in progress + name: Dan + email: dan@adaacademy.org + address: 1215 4th Ave, Seattle, WA 98161 + cc_num: 1234567891011121 + expiry_date: 1020 + cc_cvv: 111 + zip: 98161 + +paid_order: + status: in progress + name: Kari + email: kari@adaacademy.org + address: 3333 8th Ave, Seattle, WA 98161 + cc_num: 1234567892323232 + expiry_date: 0120 + cc_cvv: 101 + zip: 98111 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..5564084b12 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,22 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +hb: + name: headband + price: 10 + available: 6 + merchant: merchant_one + categories: accessories + +water: + name: bottled water + price: 1 + available: 100 + merchant: merchant_two + categories: accessories + +pants: + name: sweatpants + price: 20 + available: 10 + merchant: merchant_two + categories: pants diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..de9a25ae04 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: + rating: 1 + description: This review is for product 1 + product: hb + +two: + rating: 2 + description: This is review is for product 2 + product: water 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..04adf4721a --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new(name: "accessories") } + + it "must be valid" do + value(category).must_be :valid? + end + + it "must be invalid without a name" do + category = Category.new(name: nil) + category.wont_be :valid? + end + +end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..5854b7187a --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,81 @@ +require "test_helper" + +describe Merchant do + + describe "validations" do + + before do + @merchant = merchants(:merchant_one) + end + + it "is valid with all the required fields" do + result = @merchant.valid? + + value(result).must_equal true + end + + it "is invalid without a username" do + @merchant.username = nil + + result = @merchant.valid? + + value(result).must_equal false + end + + it "is invalid without an email" do + @merchant.email = nil + + result = @merchant.valid? + + value(result).must_equal false + end + + it "is invalid when there is a duplicate username" do + duplicate = merchants(:merchant_two) + duplicate.username = "merchant_one" + + result = duplicate.valid? + + value(result).must_equal false + end + + it "is invalid when there is a duplicate email" do + duplicate = merchants(:merchant_two) + duplicate.email = "merchant_one@gmail.com" + + result = duplicate.valid? + + value(result).must_equal false + end + + end + + describe 'relations' do + + before do + @merchant = merchants(:merchant_one) + end + + it "has a list of products to sell" do + @merchant.must_respond_to :products + @merchant.products.each do |product| + product.must_be_kind_of Product + end + end + + it "has many orders" do + @merchant.must_respond_to :orders + @merchant.orders.each do |order| + order.must_be_kind_of Order + end + end + + it "has many product categories" do + @merchant.product_categories.each do |category| + category.must_be_kind_of Category + end + end + + end + +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..c5b14b12cb --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,180 @@ +require "test_helper" + +describe Order do + + describe "validations" do + before do + @order = orders(:basic_order) + @progress_order = Order.new(status: "in progress") + end + + it 'can be created with all required fields' do + result = @order.valid? + result.must_equal true + end + + # WHEN IN PROGRESS IT.... + it "requires a name" do + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :name + end + + # email + it "requires an email" do + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :email + end + + it "requires an @ sign in the email when in progress" do + @progress_order.email = "emailnoatsign" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :email + end + + # address + it "requires an address" do + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :address + end + + it "requires a number at beginning of address" do + @progress_order.address = "not starting w/ numbers" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :address + end + + # cc_num + it "requires a cc_num" do + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_num + end + + it "requires 16 digits" do + @progress_order.cc_num = "111222" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_num + end + + it "requires digits only - test with letters only" do + @progress_order.cc_num = "no numbersssssss" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_num + end + + it "requires digits only - test with some letters" do + @progress_order.cc_num = "1letters23456789" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_num + end + + # cc_cvv + it "requires a cc_cvv" do + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_cvv + end + + it "requires 3 digits" do + @progress_order.cc_cvv = "1234" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_cvv + end + + it "requires digits only - test with letters only" do + @progress_order.cc_cvv = "xxx" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_cvv + end + + it "requires digits only - test with some letters" do + @progress_order.cc_cvv = "1x2" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :cc_cvv + end + + # zip + it "requires a zip" do + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :zip + end + + it "requires digits only - test with letters only" do + @progress_order.zip = "xxxxx" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :zip + end + + it "requires digits only - test with some letters" do + @progress_order.zip = "1x3x5" + @progress_order.valid?.must_equal false + @progress_order.errors.messages.must_include :zip + end + end + + # describe "relations" do + # it "has a merchant" do + # end + # + # it "has a list of products" do + # # order = orders(:order_one) + # # order.must_respond_to :products + # # order.products.each do |product| + # # product.must_be_kind_of Product + # end + # end + + describe 'order_total' do + before do + @paid_order = orders(:paid_order) + @p_one = products(:hb) + @p_two = products(:water) + @p_three = products(:pants) + end + + it "returns zero with no products" do + @paid_order.order_total.must_equal 0 + end + + it "calculates total with one of one product" do + OrderProduct.create(order: @paid_order, product: @p_one, quantity: 1) + @paid_order.order_total.must_equal 10 + end + + it "calculates total with many of one product" do + OrderProduct.create(order: @paid_order, product: @p_one, quantity: 4) + @paid_order.order_total.must_equal 40 + end + + it "calculates total with many products" do + OrderProduct.create(order: @paid_order, product: @p_one, quantity: 1) + OrderProduct.create(order: @paid_order, product: @p_two, quantity: 3) + OrderProduct.create(order: @paid_order, product: @p_three, quantity: 5) + + @paid_order.order_total.must_equal 113 + end + end + + describe 'update_status' do + + it "updates status when nil" do + new_order = Order.new() + new_order.save + + new_order.status == nil + + new_order.update_status + + new_order.status.must_equal "pending" + end + + it "doesn't update status when not nil" do + order = Order.create(status: 'notnil') + order.status.must_equal 'notnil' + + order.update_status + + order.status.must_equal 'notnil' + end + + end + +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..2fc6aaac3c --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,111 @@ +require "test_helper" + +describe Product do + describe 'validations' do + before do + + @product = Product.new( + name: 'headband', + price: 8, + available: 300) + end + + it "can be created with all required fields" do + # result = @product.valid? + # + # result.must_equal true + end + + it "is invalid without a name" do + @product.name = nil + + result = @product.valid? + result.must_equal false + @product.errors.messages.must_include :name + end + + it "is invalid with a duplicate name" do + dup_product = Product.first + + @product.name = dup_product.name + + result = @product.valid? + result.must_equal false + @product.errors.messages.must_include :name + end + + it "it is invalid without a price" do + @product.price = nil + + result = @product.valid? + result.must_equal false + @product.errors.messages.must_include :price + end + + it "it is invaild if price is 0 or less" do + @product.price = -2 + + result = @product.valid? + result.must_equal false + @product.errors.messages.must_include :price + end + + it "it is invalid if price is not an integer" do + @product.price = 'hi' + + result = @product.valid? + result.must_equal false + @product.errors.messages.must_include :price + + end + end + + describe 'relationships' do + before do + @product = Product.new( + name: 'headband', + price: 8, + available: 300, + merchant_id: Merchant.first.id) + end + + it "connects merchant and merchant_id" do + merchant = Merchant.first + + @product.merchant = merchant + + @product.must_respond_to :merchant + @product.merchant_id.must_equal merchant.id + @product.merchant.must_be_kind_of Merchant + end + + it "connects categories and category_ids" do + + category = Category.first + + @product.categories << category + + @product.must_respond_to :categories + @product.category_ids.must_include category.id + + end + + it "has a list of categories" do + @product.must_respond_to :categories + + @product.categories.each do |category| + category.must_be_kind_of Categories + end + end + + it "has a list of order_products" do + @product = Product.first + + @product.must_respond_to :order_products + + @product.order_products.each do |order_product| + order_product.must_be_kind_of Order_product + end + end + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..a94442361d --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,92 @@ +require "test_helper" + +describe Review do + describe 'validations' do + it "creates a review with complete form data" do + product_id = Product.first.id + old_review_count = Review.count + + review = Review.new(rating: 5, description: 'test review', product_id: product_id ) + review.save + + review.valid?.must_equal true + Review.count.must_equal old_review_count + 1 + Review.last.description.must_equal 'test review' + end + + it "rejects a review with non-numeric rating" do + product_id = Product.first.id + old_review_count = Review.count + + review = Review.new(rating: '10', description: 'test review', product_id: product_id ) + review.save + + review.valid?.must_equal false + Review.count.must_equal old_review_count + end + + it "rejects a review without description" do + product_id = Product.first.id + old_review_count = Review.count + + review = Review.new(rating: 1, product_id: product_id ) + review.save + + review.valid?.must_equal false + Review.count.must_equal old_review_count + end + + it "rejects a review without rating" do + product_id = Product.first.id + old_review_count = Review.count + + review = Review.new(description: 'test review', product_id: product_id ) + review.save + + review.valid?.must_equal false + Review.count.must_equal old_review_count + end + + it "rejects review with rating less than 1" do + product_id = Product.first.id + old_review_count = Review.count + + review = Review.new(rating: 0, description: 'test review', product_id: product_id ) + review.save + + review.valid?.must_equal false + Review.count.must_equal old_review_count + end + + it "rejects review with rating greater than 5" do + product_id = Product.first.id + old_review_count = Review.count + + review = Review.new(rating: 6, description: 'test review', product_id: product_id ) + review.save + + review.valid?.must_equal false + Review.count.must_equal old_review_count + end + end + + + it "connects merchant and merchant_id" do + merchant = Merchant.first + product = Product.find_by(merchant_id: Merchant.first.id) + + product.must_respond_to :merchant + product.merchant_id.must_equal merchant.id + product.merchant.must_be_kind_of Merchant + end + + + describe 'relations' do + it "must respond to product" do + review = Review.first + + review.must_respond_to :product + review.product.must_be_kind_of Product + 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..0bf1f053e3 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,57 @@ +require "simplecov" +SimpleCov.start :rails do + add_filter "/channels/" + add_filter "/jobs/" + add_filter "/mailers/" +end + +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" + +# For colorful output! +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + +# To add Capybara feature tests add `gem "minitest-rails-capybara"` +# to the test group in the Gemfile and uncomment the following: +# require "minitest/rails/capybara" + +# Uncomment for awesome colorful output +# require "minitest/pride" + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + # Add more helper methods to be used by all tests here... + def setup + OmniAuth.config.test_mode = true + end + + def mock_auth_hash(user) + return { + provider: user.provider, + uid: user.uid, + info: { + email: user.email, + nickname: user.username + } + } + end + + def login(user) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user)) + get auth_callback_path(:github) + end + + def logout(user) + OmniAuth.config.mock_auth[:github] = nil + delete logout_path + end +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2