diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..07d8cf3f7c --- /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 + +# Keep secrets secret +.env +coverage + +coverage/index.html diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..c690e770f6 --- /dev/null +++ b/Gemfile @@ -0,0 +1,79 @@ +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 + +gem 'jquery-rails' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.1.4' +# Use postgresql as the database for Active Record +gem 'pg', '~> 0.18' +# 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', '~> 3.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +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' +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' + gem 'simplecov', :require => false +end + +gem 'awesome_print' +gem 'foundation-rails', '6.4.1.2' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..edf47d0b2e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,275 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.1.4) + actionpack (= 5.1.4) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.4) + activesupport (= 5.1.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.1.4) + activesupport (= 5.1.4) + globalid (>= 0.3.6) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) + arel (~> 8.0) + activesupport (5.1.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + 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) + awesome_print (1.8.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.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.3) + byebug (9.1.0) + capybara (2.15.4) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + childprocess (0.8.0) + ffi (~> 1.0, >= 1.0.11) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.2) + debug_inspector (0.0.3) + docile (1.1.5) + dotenv (2.2.1) + dotenv-rails (2.2.1) + dotenv (= 2.2.1) + railties (>= 3.2, < 5.2) + erubi (1.7.0) + execjs (2.7.0) + faraday (0.12.2) + multipart-post (>= 1.2, < 3) + ffi (1.9.18) + foundation-rails (6.4.1.2) + railties (>= 3.1.0) + sass (>= 3.3.0, < 3.5) + sprockets-es6 (>= 0.9.0) + globalid (0.4.0) + activesupport (>= 4.2.0) + hashie (3.5.6) + i18n (0.9.0) + concurrent-ruby (~> 1.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.1) + 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.0.2) + 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.1.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.6.6) + mime-types (>= 1.16, < 4) + method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_mime (0.1.4) + mini_portile2 (2.3.0) + minitest (5.10.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.1.18) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + multi_json (1.12.2) + multi_xml (0.6.0) + multipart-post (2.0.0) + nio4r (2.1.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + 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.7.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.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + pg (0.21.0) + pry (0.11.1) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.0) + puma (3.10.0) + rack (2.0.3) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) + bundler (>= 1.3.0) + railties (= 5.1.4) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.1.0) + rb-fsevent (0.10.2) + 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.6) + 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.6.0) + childprocess (~> 0.5) + rubyzip (~> 1.0) + simplecov (0.15.0) + 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.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.3) + tzinfo (1.2.3) + thread_safe (~> 0.1) + uglifier (3.2.0) + execjs (>= 0.3.0, < 3) + web-console (3.5.1) + 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.2) + xpath (2.1.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + awesome_print + better_errors + binding_of_caller + byebug + capybara (~> 2.13) + dotenv-rails + foundation-rails (= 6.4.1.2) + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + omniauth + omniauth-github + pg (~> 0.18) + pry-rails + puma (~> 3.7) + rails (~> 5.1.4) + 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.0.pre.3 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000..84f56612f1 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/images/33.jpeg b/app/assets/images/33.jpeg new file mode 100644 index 0000000000..1124d91775 Binary files /dev/null and b/app/assets/images/33.jpeg differ diff --git a/app/assets/images/3friends.jpg b/app/assets/images/3friends.jpg new file mode 100644 index 0000000000..80262b83f3 Binary files /dev/null and b/app/assets/images/3friends.jpg differ diff --git a/app/assets/images/address-icon.png b/app/assets/images/address-icon.png new file mode 100644 index 0000000000..90f8c8bae3 Binary files /dev/null and b/app/assets/images/address-icon.png differ diff --git a/app/assets/images/banana.jpg b/app/assets/images/banana.jpg new file mode 100644 index 0000000000..18396797cb Binary files /dev/null and b/app/assets/images/banana.jpg differ diff --git a/app/assets/images/blue_cart.png b/app/assets/images/blue_cart.png new file mode 100644 index 0000000000..99c5967456 Binary files /dev/null and b/app/assets/images/blue_cart.png differ diff --git a/app/assets/images/boo2.jpg b/app/assets/images/boo2.jpg new file mode 100644 index 0000000000..f9d6edb5b0 Binary files /dev/null and b/app/assets/images/boo2.jpg differ diff --git a/app/assets/images/cart.png b/app/assets/images/cart.png new file mode 100644 index 0000000000..a905cf707d Binary files /dev/null and b/app/assets/images/cart.png differ diff --git a/app/assets/images/cart_circle.png b/app/assets/images/cart_circle.png new file mode 100644 index 0000000000..533c445da8 Binary files /dev/null and b/app/assets/images/cart_circle.png differ diff --git a/app/assets/images/circle_cart.jpg b/app/assets/images/circle_cart.jpg new file mode 100644 index 0000000000..37e2243e28 Binary files /dev/null and b/app/assets/images/circle_cart.jpg differ diff --git a/app/assets/images/icecream.jpeg b/app/assets/images/icecream.jpeg new file mode 100644 index 0000000000..3243ef6b47 Binary files /dev/null and b/app/assets/images/icecream.jpeg differ diff --git a/app/assets/images/lock-open-blue.png b/app/assets/images/lock-open-blue.png new file mode 100644 index 0000000000..77e81d3f76 Binary files /dev/null and b/app/assets/images/lock-open-blue.png differ diff --git a/app/assets/images/login.png b/app/assets/images/login.png new file mode 100644 index 0000000000..8868550ae7 Binary files /dev/null and b/app/assets/images/login.png differ diff --git a/app/assets/images/login_key.png b/app/assets/images/login_key.png new file mode 100644 index 0000000000..cddd05af4a Binary files /dev/null and b/app/assets/images/login_key.png differ diff --git a/app/assets/images/logout.png b/app/assets/images/logout.png new file mode 100644 index 0000000000..b7975800ad Binary files /dev/null and b/app/assets/images/logout.png differ diff --git a/app/assets/images/pine.jpg b/app/assets/images/pine.jpg new file mode 100644 index 0000000000..be02a4cf58 Binary files /dev/null and b/app/assets/images/pine.jpg differ diff --git a/app/assets/images/pineapple1.jpg b/app/assets/images/pineapple1.jpg new file mode 100644 index 0000000000..3325577fb4 Binary files /dev/null and b/app/assets/images/pineapple1.jpg differ diff --git a/app/assets/images/unlock.png b/app/assets/images/unlock.png new file mode 100644 index 0000000000..2d199c0922 Binary files /dev/null and b/app/assets/images/unlock.png differ diff --git a/app/assets/images/you.png b/app/assets/images/you.png new file mode 100644 index 0000000000..1ed1ea8752 Binary files /dev/null and b/app/assets/images/you.png differ diff --git a/app/assets/images/your_page.png b/app/assets/images/your_page.png new file mode 100644 index 0000000000..58fa2203f1 Binary files /dev/null and b/app/assets/images/your_page.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..48f33b7b53 --- /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 turbolinks +//= 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/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/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss new file mode 100644 index 0000000000..0ef2ccf1a5 --- /dev/null +++ b/app/assets/stylesheets/_settings.scss @@ -0,0 +1,862 @@ +// 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: #1779ba, + secondary: #767676, + success: #3adb76, + warning: #ffae00, + alert: #cc4b37, +); +$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-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 0 $global-margin 0; +$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: $white; +$callout-background-fade: 85%; +$callout-border: 1px solid rgba($black, 0.25); +$callout-margin: 0 0 1rem 0; +$callout-padding: 1rem; +$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; + +// 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-size: 250px; +$offcanvas-vertical-size: 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; +$block-grid-max: 8; diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..1fa3589a2a --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,308 @@ +/* +* 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_tree . +*= require_self +*= require foundation_and_overrides + +*/ + +.hidden { + visibility: hidden; +} + +li { + list-style-type: none; +} +.total-revenue { + width: 300px; + text-align: center; + margin-left: 200px; +} + +html, main, h1, h2, h3, a { + font-family: 'Quicksand', sans-serif; + color: black; +} +h1 { + text-align: center; +} +.background { + background-image: url("https://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDth6y8WgTWVLeNdwFmkRem83MYqd15T1urJrxlOybhaRlelBZSKTnNAYF80MQD7Vbk51LyVtj6nQLCMeIm7D7xp0_QUdQI4FMzSGxc4DBUyxWDrIqCg2o5oV92lluS60U6e6siDzZr9HPI-LXK9TnvJgAKUYetUwlpv_Jc1COHr/"); + /*height: 100vh;*/ + /*background-position: top; + background-repeat: repeat; + height: 700px;*/ +} + +.menu { + border-top: 1px solid white; + border-bottom: 1px solid white; +} + +.top-nav { + text-align: right; + padding-right: 30px; +} + +.dropdown .dropdown-content { + background: rgb(255,255,255); + color: grey; +} + +div .dropdown { + padding: 2% 0; +} + +.dropdown span { + color: white; + font-size: 20px; +} + +h2 a:hover { + color: grey; +} + +nav div span { + text-align: center; +} + +.rand { + margin-top: 10px; + padding-bottom: 10px; + background-color: rgba(219, 238, 241, 0.85); + padding-left: 10px; +} +.randpad { + background-color: rgba(219, 238, 241, 0.85); + margin-left: 5px; + margin-bottom: 10px; + height: 200px; + width: 200px; +} +.randpad-home { + background-color: rgba(219, 238, 241, 0.85); + margin-left: 5px; + margin-bottom: 10px; + height: 200px; + width: 200px; +} +.columns:last-child:not(:first-child) { + float: left; +} +.heading:hover a { + color:rgb(53, 163, 187); +} +.heading a { + font-size: 1.6em; + color: white; +} +.emptycart { + text-align: center; + font-weight: bold; +} + +/***********/ +/* MAIN */ +/***********/ +.button { + background-color: rgba(245, 193, 151, 0.92); +} +.button:hover { + background-color: rgba(245, 151, 230, 0.92); +} + +/*.button-link{ +color: rgb(17, 185, 190); +font-size: 20px; +}*/ + +/* +.button-link:hover{ +color:rgb(43, 80, 82); +}*/ + +.button-link { + color: white; + /*font-weight: bold;*/ + font-size: 20px; +} + +.button-link:hover{ + color: rgb(43, 80, 82); +} + +.button-link a{ + color: rgb(43, 80, 82); + font-size: 20px; +} + +/*.button-link a{ +color: rgb(17, 185, 190); +font-size: 20px; +}*/ +/*.button-link a:hover{ +color:rgb(43, 80, 82); +}*/ +.good { + color: rgb(20, 17, 83); +} +p { + margin-bottom: 1px; + padding-top: 10px; + text-align: center +} +p a:hover{ + color:rgb(17, 185, 190); +} + + +.welcome h1 { + /*font-family: Brush Script MT, Brush Script Std, cursive;*/ + color: rgb(21, 101, 175); + /*font-style: italic;*/ + text-align: center; + padding-top: 20px; +} + +h3 { + text-align: center; +} + + +a { + font-size: 20px; + color: rgb(17, 26, 88); +} + +body { + color: rgb(17, 26, 88); + font-family: 'Quicksand', sans-serif; +} + +.wrappy { + width: 90%; + margin: 0 auto; + max-width: 900px; + padding-bottom: 100px; +} + +/***********/ +/* FOOTER */ +/***********/ + +/***********/ +/* STARS */ +/***********/ + +.zero-stars, .zero-stars a{ + color: lightgrey; +} + +.one-star, .one-star a{ + color: #cc0000; +} + +.two-stars, .two-stars a{ + color: #ff8533; +} + +.three-stars, .three-stars a{ + color: #ffcc00; +} + +.four-stars, .four-stars a{ + color: #99db70; +} + +.five-stars, .five-stars a{ + color: #33AC33; +} +.float-right { + padding-top: 10px; +} +/***********/ +/* DROPDOWN */ +/***********/ +.button a { + color: white; +} +.dropdown { + position: relative; + display: inline-block; + /*width: 100px;*/ + padding: 3% 6%; + font-size: 20px; +} +.dropdown-content { + display: none; + position: absolute; + background-color: #f9f9f9; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + padding: 12px 16px; + z-index: 1; + font-size: 15px; +} +.dropdown-content a { + display: block; +} +.dropdown:hover .dropdown-content { + display: block; +} + +.category { + border-bottom: solid; +} + +.add { + margin-left: 40%; +} + +.buy { + background-color: rgb(231, 178, 220); +} + +.product { + font-weight: bold; + padding-top: 30px; + /*width: 800px;*/ + border-style: solid; + background-image: url(33.jpeg); + background-size: cover; + /*background-repeat: no-repeat;*/ + padding-bottom: 100px; + padding-left: 30px; +} +.product-index { + font-weight: bold; + padding-top: 30px; + /*width: 800px;*/ + border-style: solid; + background-image: url(33.jpeg); + background-size: cover; + /*background-repeat: no-repeat;*/ + padding-bottom: 100px; + padding-left: 30px; +} +.product-index a { + color: rgb(213, 38, 148); +} + +.first-item a{ + font-size: 1.5em; +} +.playing { + border-style: solid; + max-width: 200px; + height: 300px; +} diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..6bd81093cd --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,11 @@ +// 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/ +.cat-image img { + height: 200px; + width: 200px + // max-height: 200px; +} +.category { + margin-top: 20px; +} diff --git a/app/assets/stylesheets/foundation_and_overrides.scss b/app/assets/stylesheets/foundation_and_overrides.scss new file mode 100644 index 0000000000..2066155081 --- /dev/null +++ b/app/assets/stylesheets/foundation_and_overrides.scss @@ -0,0 +1,53 @@ +@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-grid; +@include foundation-typography; +@include foundation-button; +@include foundation-forms; +@include foundation-visibility-classes; +@include foundation-float-classes; +@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-drilldown-menu; +@include foundation-dropdown; +@include foundation-dropdown-menu; +@include foundation-responsive-embed; +@include foundation-label; +@include foundation-media-object; +@include foundation-menu; +@include foundation-menu-icon; +@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; + +// 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; diff --git a/app/assets/stylesheets/merchants.scss b/app/assets/stylesheets/merchants.scss new file mode 100644 index 0000000000..3ee03197e5 --- /dev/null +++ b/app/assets/stylesheets/merchants.scss @@ -0,0 +1,82 @@ +// 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/ +h3.merchant-heading { + color: white; + font-weight: bold; + text-align: center; + padding: 5px; + background-color: rgba(255, 255, 255, 0.3); + margin: 5% 0%; +} + +.order_list { + color: rgb(63, 92, 153); +} + +table tbody tr td { + color: black +} +table tbody tr td a { + color: black +} + +.name-wrap { + width: 90%; + margin: 0 auto; + max-width: 900px; +} + +.order_info_table { + margin-bottom: 0rem; +} + +.order_info_table thead, .products_info_table thead{ + background: transparent; + border: 0px; + border-bottom: black 2px solid; + +} +.order_info_table tbody, .products_info_table tbody { + background: rgba(255, 255, 255, 0.25); + border: 0px; +} + +.products_info_table { + margin-left: 5%; + width: 95%; +} + +.align_right { + text-align: right; + background: rgba(255, 255, 255, 0.25); +} +.order_info_table .align_right { + width: 23.75%; +} +.products_info_table .align_right { + width: 25%; +} +#total_boxes { + margin: 0; + display: flex; + justify-content: space-around; +} +.total_box { + background-color: #629286; + color: white; + text-align: center; + padding: 0; + width: 22%; + display: flex; + flex-direction: column; + justify-content: space-between; + margin-bottom: 20px; +} + +.total_box h6 { + padding-top: 1rem; +} +.total_box p { + padding-bottom: 1rem; +} 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..741506954d --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..d41198e068 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,133 @@ +// 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/ +.motto { + margin-top: 30px; +} +.all-products h2 { + margin-top: 20px; + text-align: center; + font-weight: bold; +} + +.category-name { + text-align: center; + padding: 30px; + + background-image: url("https://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDth6y8WgTWVLeNdwFmkRem83MYqd15T1urJrxlOybhaRlelBZSKTnNAYF80MQD7Vbk51LyVtj6nQLCMeIm7D7xp0_QUdQI4FMzSGxc4DBUyxWDrIqCg2o5oV92lluS60U6e6siDzZr9HPI-LXK9TnvJgAKUYetUwlpv_Jc1COHr/"); + background-size: cover; +} + +.category-name a { + font-size: 50px; + color: white; + font-weight: bold; +} +.large-5 { + width: 13%; + margin-left: 150px; +} +.crop-image { + height: 200px; + width: 200px; + overflow: hidden; + margin-left: 70px; + margin-bottom: 10px; + margin-top: 20px; +} +.crop-image img { + height: 200px; + width: 200px; +} +.prod-name a { + padding-right: 10px; +} + + +// #product-name { +// text-align: center; +// } + +a.head-button.columns.large-3 { + float: right; + margin-top: 1rem; +} + +section.details.columns.small-12 { + float: right; +} + +#product-image.large-5 { + width: 40%; + // max-width: 40%; + margin: 3rem; +} + +.details { + margin-top: 5rem; +} + +.input-button input.field { + width: 20%; + float: left; + margin: 0 1rem; + clear: both; +} +.dashboard p { + text-align: left; + margin: 0 1rem; +} +.head-w-button { + width: 80%; + margin: auto; + margin-top: 20px; +} + +#edit-button { + margin: 0 1rem; +} +.reviews { + display: inline-block; + text-align: left; + margin: 0 2rem; +} + +.rating { + padding-left: 10px; + font-weight: bold; + font-size: 30px; +} +// .rating-star { +// padding-left: 10px; +// } + +.individual { + border-style: groove; + padding-bottom: 20px; + // border-bottom: lightgrey 1pt solid; + width: 500px; +} +#reviews { + margin-bottom: 3rem; + border-top: lightgrey 1pt solid; +} +.description { + margin-bottom: 1px; + padding-top: 10px; +} + +.wrap-city { + width: 90%; + margin: 0 auto; + max-width: 900px; + padding-bottom: 100px; +} +// #add-to-cart { +// width: 25% +// } + +// .category-products { +// width: 100%; +// height: 100%; +// overflow: hidden; +// } diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..11bbb12cd5 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/root.scss b/app/assets/stylesheets/root.scss new file mode 100644 index 0000000000..4619f1ac20 --- /dev/null +++ b/app/assets/stylesheets/root.scss @@ -0,0 +1,89 @@ +section.root { + margin-top: 5%; +} + +.homepage { + background-image: url("https://yourshot.nationalgeographic.com/u/fQYSUbVfts-T7odkrFJckdiFeHvab0GWOfzhj7tYdC0uglagsDth6y8WgTWVLeNdwFmkRem83MYqd15T1urJrxlOybhaRlelBZSKTnNAYF80MQD7Vbk51LyVtj6nQLCMeIm7D7xp0_QUdQI4FMzSGxc4DBUyxWDrIqCg2o5oV92lluS60U6e6siDzZr9HPI-LXK9TnvJgAKUYetUwlpv_Jc1COHr/"); + height: 700px; +} +.bae { + padding-top: 15%; +} +.bae a { + color: white; + font-size: 100px; +} +.welcome { + padding-top: 30%; +} +section .space{ + padding: 0%; +} +.hey-bae a { + font-size: 70px; +} +.spotlight { + max-height: 500px; + margin: auto; + color: black; + text-align: center; + padding: 5px; + background-color: rgba(255,255,255,0.3); + margin: 0%; +} +.spooky { + text-align: center; + margin-top: 150px; + +} +.spooky-row { + // margin-left: 100px; +} +.spooky-spot { + text-align: center; + margin-top: 20px; +} +.spotlight-image img { + width: 300px; + display: block; + margin: auto; + width: 40%; + max-height: 400px; +} + +.seasonal { + height: 100%; + overflow: hidden; + +} +.seasonal img { + height: 100px; + padding-left: 40px; +} + +section h5 { + color: grey; + // font-weight: bold; + text-align: center; + padding: 5px; + background-color: rgba(255,255,255,0.3); + margin: 5% 0%; +} + +.seasonal-home { + margin-top: 20px; + font-size: 3em; +} + +.product-image { + padding-bottom: 10px; + padding-left: 10px; + max-width: 200px; + height: 100px; +} +.product-image img { + max-height: 100px; +} +.bottom { + height: 100px; +} 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..ea7fc30e89 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,34 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception + + protected + + def must_be_logged_in + if session[:merchant_id] == nil + flash[:status] = :failure + flash[:message] = "You must be logged in to do that!" + redirect_to products_path + end + end + + def must_be_merchant_of_product + if session[:merchant_id] != @product.merchant_id + flash[:status] = :failure + flash[:message] = "You must be the owner of this product to do that!" + redirect_to products_path + end + end + + def save_and_flash(model, edit: "create", save: model.save, name: model.name) + result = save + if result + flash[:status] = :success + flash[:message] = "Successfully #{edit}d #{model.class} #{name}" + else + flash.now[:status] = :failure + flash.now[:message] = "Could not #{edit} #{model.class}" + flash.now[:details] = model.errors.messages + return false + end + end +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..0972acde59 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,40 @@ +class CategoriesController < ApplicationController + before_action :must_be_logged_in, only: [:new, :create] + before_action :find_id_by_params, only: [:show] + + def index + @categories = Category.all + @spot = Category.spot + # @by_cat = Category.view_by_category + end + + def show ; end + + def new + @category = Category.new + end + + def create + @category = Category.new(category_params) + + if save_and_flash(@category) + redirect_to products_path + return + else + render :new, status: :bad_request + end + end + + private + + def category_params + return params.require(:category).permit(:name) + end + + def find_id_by_params + @category = Category.find_by(id: params[:id]) + unless @category + head :not_found + end + end +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb new file mode 100644 index 0000000000..242f659783 --- /dev/null +++ b/app/controllers/merchants_controller.rb @@ -0,0 +1,93 @@ +class MerchantsController < ApplicationController + + before_action :find_id_by_params, except: [:index, :create, :logout] + before_action :must_be_logged_in, only: [:destroy] + + def index + @merchants = Merchant.all + end + + def create + auth_hash = request.env['omniauth.auth'] + session[:cart] = nil + if auth_hash['uid'] + merchant = Merchant.find_by(provider: params[:provider], uid: auth_hash[:uid]) + if merchant.nil? #merchant hasn't logged in before + merchant = Merchant.from_auth_hash(params[:provider], auth_hash) + save_and_flash(merchant) + else #merchant has logged in before + flash[:status] = :success + flash[:message] = "Successfully logged in as returning merchant #{merchant.name}" + end + + if session[:merchant_id] == merchant.id + flash[:status] = :failure + flash[:message] = "You're already logged in, Bae!" + else + session[:merchant_id] = merchant.id + end + + else + flash[:status] = :failure + flash[:message] = "Could not create merchant from OAuth data" + # this might be redundant, because save_and_flash might do this anyway? + end + + redirect_to products_path + end + + def logout + session[:merchant_id] = nil + session[:cart] = nil + flash[:status] = :success + flash[:message] = "You have been logged out." + redirect_to products_path + end + + def show(status: nil) + @paid_orders = @merchant.sort_orders_by_status("paid") + @complete_orders = @merchant.sort_orders_by_status("complete") + if params[:status] == "paid" || params[:status] == nil + @filtered_orders = @paid_orders + @title = "Waiting to be fulfilled:" + elsif params[:status] == "complete" + @filtered_orders = @complete_orders + @title = "Completed orders:" + end + end + + def destroy + if @merchant.id != session[:merchant_id] + flash[:status] = :failure + flash[:message] = "Only the merchant has permission to delete" + redirect_to root_path + else + @merchant.destroy + flash[:status] = :success + flash[:message] = "Successfully deleted" + redirect_to merchants_path + end + end + + private + + def check_this_merchant + if @merchant.id != session[:merchant_id] + flash[:status] = :failure + flash[:message] = "Only the merchant has permission to do this." + return false + end + return true + end + + def merchant_params + params.require(:merchant).permit(:username, :email) + end + + def find_id_by_params + @merchant = Merchant.find_by(id: params[:id]) + unless @merchant + head :not_found + end + end +end diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb new file mode 100644 index 0000000000..1c0a5ac851 --- /dev/null +++ b/app/controllers/order_products_controller.rb @@ -0,0 +1,129 @@ +class OrderProductsController < ApplicationController + # before_action :find_op_by_params_id, only: [:edit, :update] + def update_status + @op = OrderProduct.find_by(id: params[:id]) + @op.status = "complete" + @op.save + if @op.order.order_complete? + @op.order.status = "complete" + @op.order.save + flash[:status] = :success + flash[:message] = "Order has been completed and shipped to buyer" + redirect_to merchant_path(@op.product.merchant) + return + end + flash[:status] = :success + flash[:message] = "Product has been added to order, Order is waiting on other products before shipping." + redirect_to merchant_path(@op.product.merchant) + end + + def update + @op = OrderProduct.find_by(id: params[:id]) + # @product = @op.product + + @product = Product.find_by(id: params[:product_id]) + new_quantity = params[:quantity].to_i + + #find instance of order + order_id = session[:cart] + @order = Order.find_by(id: order_id) + + if @product.check_inventory(new_quantity) + @op.quantity = new_quantity + if save_and_flash_cart + redirect_to order_path(@order.id) + else + render "orders/show", status: :bad_request + end + else #not enough inventory + not_enough_inventory + render "orders/show", status: :bad_request + end + end + + def create + assign_order + @product = Product.find_by(id: params[:product_id]) + + quantity = params[:quantity].to_i + + if @product.check_inventory(quantity) + #find order object + order = Order.find_by(id: @order) + + #check if this order already has this product + result = order.order_products.select {|op| op.product_id == @product.id} + + if result.empty? #no current products with this id + @op = OrderProduct.new(quantity: quantity, product_id: params[:product_id], order_id: @order) + else #there is an op in result(should be just one) + @op = result[0] + + new_quantity = @op.quantity + quantity + @op.quantity = new_quantity + end + + if save_and_flash_cart + redirect_to order_path(@order) + else + render "products/show", status: :bad_request + end + + else + not_enough_inventory + render "products/show", status: :bad_request + end + end + + def destroy + @op = OrderProduct.find_by(id: params[:id]) + @order = Order.find_by(id: @op.order.id) + # if there is still content in the cart, show + + save_and_flash(@op, edit: "delete", save: @op.destroy, name: "item") + + if @order.order_products.empty? + session[:cart] = nil + redirect_to order_empty_cart_path(:cart) + else + redirect_to order_path(@order) + end + end + + private + def assign_order + if session[:cart] + @order = session[:cart] + else + order = Order.create(status:"pending") + @order = order.id + session[:cart] = order.id + end + end + + # def order_params + # return params.require(:order_product).permit(:quantity, :product_id) + # end + def not_enough_inventory + flash.now[:status] = :failure + flash.now[:message] = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." + end + + def find_op_by_params_id + @op = OrderProduct.find_by(id: params[:id]) + head :not_found unless @op + end + + def save_and_flash_cart + if @op.save + flash[:status] = :success + flash[:message] = "Successfully updated cart" + else + flash.now[:status] = :failure + flash.now[:message] = "Could not update cart." + flash.now[:details] = @op.errors.messages + return false + end + end + +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..bda24b485c --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,96 @@ +class OrdersController < ApplicationController + before_action :find_order_by_params_id, only: [:show, :update, :destroy, :checkout, :receipt, :check_merchant_is_prod_owner] + before_action :check_order_session, only: [:receipt] + before_action :check_cart, only:[:show] + + def index + @orders = Order.all + end + + def show ; end + + + def checkout + @payment_info = PaymentInfo.new + end + + def receipt + @payment_info = @order.payment_info + @last_four_cc = @payment_info.last_four_cc + end + + def update + @payment_info = PaymentInfo.new + @payment_info.update_attributes(payment_params) + @payment_info.order = @order + if save_and_flash(@payment_info, name: @payment_info.buyer_name) + else + render :checkout, status: :bad_request + return + end + flash[:receipt] = payment_params[:buyer_name] + @order.status = "paid" + update_order_items_status + session[:cart] = nil + + if save_and_flash(@order, edit:"submitte", name: @order.id) + @order.order_products.each do |op| + op.product.decrease_inventory(op.quantity) + end + redirect_to order_receipt_path(@order.id) + else + render :checkout, status: :bad_request + redirect_to(order_path(@order)) + end + end + + def destroy + save_and_flash(@order, edit: "destroye", save: @order.destroy, name: @order.id) + session[:cart] = nil + redirect_to root_path + end + +private + def payment_params + return params.require(:payment_info).permit(:email, :mailing_address, :buyer_name, :card_number, :expiration, :cvv, :zipcode) + end + + def find_order_by_params_id + @order = Order.find_by(id: params[:id] || params[:order_id]) + head :not_found unless @order + end + + def check_order_session + if (flash[:receipt] != @order.payment_info.buyer_name) && check_merchant_is_prod_owner != true + flash[:status] = :failure + flash[:message] = "Sorry, you cannot view that receipt." + redirect_to root_path + end + end + + def update_order_items_status + @order.order_products.each do |op| + op.status = "paid" + op.save + end + end + + def check_merchant_is_prod_owner + @order.products.each do |prod| + if prod.merchant_id == session[:merchant_id] + return true + end + end + return false + end + + def check_cart + if session[:cart] != params[:id].to_i + flash[:status] = :failure + flash[:message] = "Sorry, you cannot view that order." + redirect_to root_path + end + + end + +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..316f2fcb96 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,75 @@ +class ProductsController < ApplicationController + before_action :find_product, only: [:show, :edit, :update, :destroy, :retire] + before_action :must_be_logged_in, only: [:new, :destroy, :edit] + before_action :must_be_merchant_of_product, only: [:destroy, :edit] + + def root + @all_products_for_season_cat = Category.root_page_seasonal_pick + end + + def index + @products = Product.not_retired + # @categories = Category.all + end + + def show ; end + + def new + @product = Product.new + end + + def create + @product = Product.new( + product_params + ) + @product.merchant_id = session[:merchant_id] + if save_and_flash(@product) + redirect_to products_path + return + else + render :edit, status: :bad_request + end + end + + def edit ; end + + def update + @product.merchant_id = session[:merchant_id] + @product.update_attributes(product_params) + if save_and_flash(@product, edit: "update") + redirect_back(fallback_location: product_path(@product)) + return + else + render :edit, status: :bad_request + end + end + + def destroy + @product.destroy + flash[:status] = :success + flash[:message] = "Successfully deleted!" + redirect_to products_path + end + + def retire + @product.retired = !@product.retired + save_and_flash(@product, edit: 'retire') + # flash unretire? + redirect_back(fallback_location: product_path(@product)) + end + + +private + + def product_params + return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url, :category_ids => []) + end + + def find_product + @product = Product.find_by(id: params[:id]) + unless @product + head :not_found + end + end + +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..1f18d4c4eb --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,52 @@ +class ReviewsController < ApplicationController + +before_action :find_product, only: [:new] + + def new + if session[:merchant_id] == @product.merchant_id + flash[:status] = :failure + flash[:message] = "You cannot review your own product!" + redirect_to products_path + return + else + @review = Review.new + end + end + + def create + # @product = Product.find_by(id: params[:product_id]) + # cant_be_merchant + @review = Review.new( + review_params + ) + @product = Product.find_by(id: review_params[:product_id]) + if save_and_flash(@review, name: "") + redirect_to product_path(review_params[:product_id]) + return + else + render :new, status: :bad_request + end + end +end + +private + +def find_product + @product = Product.find_by(id: params[:product_id]) + unless @product + head :not_found + end +end + +def review_params + return params.require(:review).permit(:rating, :text, :product_id) +end + +# def cant_be_merchant +# if session[:merchant_id] == @product.merchant_id +# flash[:status] = :failure +# flash[:message] = "You cannot review your own product!" +# redirect_to products_path +# return +# end +# end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..888ddfa91e --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,26 @@ +module ApplicationHelper + def set_class(rating) + case rating + when 0 + "zero-stars" + when 1 + "one-star" + when 2 + "two-stars" + when 3 + "three-stars" + when 4 + "four-stars" + when 5 + "five-stars" + end + end + + def readable_date(date) + date.strftime("%A, %b %d").html_safe + end + + def readable_price(price) + '$' + '%.2f' % price + end +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..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/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..cfcf88b47a --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,34 @@ +class Category < ApplicationRecord + has_and_belongs_to_many :products + + validates :name, presence: {message: "Please enter a category name"}, uniqueness: true + + def self.spot + spot = Product.all.sample + return spot + end + + def self.root_page_seasonal_pick + category = "halloween" + all_products_for_season_cat = [] + + Category.all.where(name: category).each do |c| + + c.products.not_retired.each do |prod| + all_products_for_season_cat << prod + end + end + + return all_products_for_season_cat + + end + + # def self.view_by_category + # Category.all.each do |category| + # category.products.each do |product| + # return product + # end + # end + # 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..d8aa22135a --- /dev/null +++ b/app/models/merchant.rb @@ -0,0 +1,56 @@ +class Merchant < ApplicationRecord + + has_many :products + + validates :username, presence: {message: "Please enter a username"}, uniqueness: true + + validates :email, presence: {message: "Please enter an email"}, uniqueness: true + + validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/, message: "Please enter your email in this format: example@example.com" + def self.from_auth_hash(provider, auth_hash) + merchant = new + merchant.provider = provider + merchant.uid = auth_hash['uid'] + merchant.name = auth_hash['info']['name'] + merchant.email = auth_hash['info']['email'] + merchant.username = auth_hash['info']['nickname'] + + return merchant + end + + + # def merchant_orders + # Order.joins(:products).where(products: {merchant: merchant}) + # end + + def relevant_orders + relevant_orders = [] + Order.all.each do |order| + relevant_order_products = order.order_products.select { |op| + op.product.merchant == self + } + if relevant_order_products.length > 0 + relevant_orders << { + order: order, + order_products: relevant_order_products + } + end + end + return relevant_orders + end + + def sort_orders_by_status(status) + merchants_orders = self.relevant_orders + return merchants_orders.select { |order| order[:order].status == status} + end + + def total_revenue(status) + orders = sort_orders_by_status(status) + sum = 0 + orders.each do |order| + sum += order[:order].order_total(merchant: self) + end + return sum + end + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..d55f4ae3ff --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,36 @@ +class Order < ApplicationRecord + has_many :order_products + has_many :products, through: :order_products + has_one :payment_info + + scope :not_retired, -> { where(retired: false) } + + + def order_complete? + incomplete = 0 + + self.order_products.each do |op| + if op.status != "complete" + incomplete += 1 + end + end + return incomplete == 0 ? true : false + end + + def order_total(merchant: nil) + total = 0 + ops = nil + if merchant + ops = self.order_products.select { |op| + op.merchant == merchant + } + else + ops = self.order_products + end + ops.each do |order_product| + total += order_product.subtotal + end + return total + end + +end diff --git a/app/models/order_product.rb b/app/models/order_product.rb new file mode 100644 index 0000000000..746930c1e6 --- /dev/null +++ b/app/models/order_product.rb @@ -0,0 +1,11 @@ +class OrderProduct < ApplicationRecord + belongs_to :order + belongs_to :product + has_one :merchant, through: :product + + validates :quantity, numericality: {greater_than_or_equal_to: 1} + + def subtotal + return product.price * quantity + end +end diff --git a/app/models/payment_info.rb b/app/models/payment_info.rb new file mode 100644 index 0000000000..bfebadc1ea --- /dev/null +++ b/app/models/payment_info.rb @@ -0,0 +1,18 @@ +class PaymentInfo < ApplicationRecord + has_one :order + + validates :buyer_name, presence: true + validates :email, presence: true + validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/, message: "Please enter your email in this format: example@example.com" + validates :card_number, presence: true, length: {minimum: 4} #numericality + validates :expiration, presence: true + # could be cool to format it like a date? + validates :mailing_address, presence: true + validates :cvv, presence: true #numericality + validates :zipcode, presence: true #numericality + + def last_four_cc + last_four_cc = self.card_number.slice(-4..-1) + return last_four_cc + end +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..67123c8d53 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,48 @@ +class Product < ApplicationRecord + + has_many :order_products + has_many :orders, through: :order_products + has_many :reviews + has_and_belongs_to_many :categories + belongs_to :merchant + + scope :not_retired, -> { where(retired: false) } + + validates :name, presence: true, uniqueness: true + + validates :price, presence: true, numericality:{greater_than: 0} + + validates :inventory, presence: true, numericality:{greater_than_or_equal_to: 0} + + validates :category_ids, presence: {message: "Please select at least one category"} + + def check_inventory(quantity) + if self.inventory >= quantity + return true + end + return false + end + + def decrease_inventory(quantity) + self.inventory -= quantity + self.save + end + + + def average_rating + avg = 0 + count = 0 + + reviews.each do |review| + if review.rating > 0 + count += 1 + avg += review.rating + end + end + if count == 0 + return 0 + end + return avg / count + end + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..81f5d186eb --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,5 @@ +class Review < ApplicationRecord + belongs_to :product + + validates :rating, presence: true, numericality:{greater_than: 0, less_than_or_equal_to: 5} +end diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 0000000000..61e664990c --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,17 @@ +
+
+

All Categories

+ <% @categories.each do |cat| %> +
+

<%= cat.name.capitalize %>

+ <% cat.products.not_retired.each do |prod| %> +

<%= link_to prod.name, product_path(prod.id) %>

+

<%= readable_price(prod.price) %>

+

<%= image_tag "#{prod.photo_url}", alt:"image", size: "100x100"%>

+ <% end %> + <%# can we have an associated image for a category or that would be too much because then you'd have to include that in the form when creating a new category? %> + <%# Instead of an image, we could just have some nice text in a clickable box? %> + <% end %> +
+
+
diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..2aae82104d --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,13 @@ +
+ +
+

New Category:

+ <%= form_for @category do |f| %> + + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.submit class: "button" %> + <% end %> +
+
diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000000..c34b80cdfa --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,19 @@ +
+

<%= @category.name %>

+ +
+<% @category.products.not_retired.each do |prod| %> +
+

<%= link_to prod.name.capitalize, product_path(prod.id) %>

+ +

<%= readable_price(prod.price) %>

+ + +

<%= link_to product_path(prod.id) do %> +<%= image_tag prod.photo_url %>

+<% end %> + +
+<% end %> +
+
diff --git a/app/views/layouts/_stars.html.erb b/app/views/layouts/_stars.html.erb new file mode 100644 index 0000000000..22fedefdbe --- /dev/null +++ b/app/views/layouts/_stars.html.erb @@ -0,0 +1,3 @@ + + <%= 'â–²' * rating %><%= 'â–³' * (5 - rating) %> + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..711f061087 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,118 @@ + + + + + + + <%= content_for?(:title) ? yield(:title) : "3Bae" %> + + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> + + <%= csrf_meta_tags %> + + + +
+ + + +<% unless current_page?(root_path) %> + + <% end %> +
+
+ + <% if flash[:message] %> +
+

<%= flash[:status] == :failure ? "A problem occurred: " : "" %><%= flash[:message] %>

+ + <% if flash[:details] %> + + <% end %> +
+ <% end %> + + <%= yield %> + +
+ + + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000..cbd34d2e9d --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/app/views/merchants/_show_orders.html.erb b/app/views/merchants/_show_orders.html.erb new file mode 100644 index 0000000000..8177ad047e --- /dev/null +++ b/app/views/merchants/_show_orders.html.erb @@ -0,0 +1,57 @@ + + diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb new file mode 100644 index 0000000000..dc2ea0e80a --- /dev/null +++ b/app/views/merchants/index.html.erb @@ -0,0 +1,12 @@ +
+ +

All Merchants

+ + + +
+ <% @merchants.each do |m| %> +

<%= link_to m.username, merchant_path(m.id) %>

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

<%= @merchant.username %>'s Page

+ +
+ <%= link_to "Back to Merchants List", merchants_path, class: "button" %> + <% if @merchant.id == session[:merchant_id] %> + <%# link_to "Edit", edit_merchant_path(@merchant.id), class: "button" %> + <%= link_to "Add Product", new_product_path, class: "button" %> + <%# link_to "Delete", merchant_path(@merchant.id), method: :delete, data: { confirm: "Are you sure?" }, class: "alert button" %> + <%end %> +
+
+ +<% if @merchant.id == session[:merchant_id] %> + +<%end%> + + +

Products

+
+ + + + + + + + <%if session[:merchant_id] == @merchant.id %> + + + + <% end %> + + + + <% @merchant.products.each do |product| %> + + + + + <%if session[:merchant_id] == @merchant.id %> + + + + <% end %> + + <% end %> + +
ProductPriceInventoryUpdate InventoryEdit ProductRetire Product

<%= link_to product.name, product_path(product.id) %>

<%= readable_price(product.price) %><%= product.inventory %> + <% if product.retired %> + --Retired-- + <% else %> + + <%= form_for product do |f| %> + + <%= f.text_field :inventory, class:'field'%> + + <%= submit_tag "Update inventory", class: "button" %> + <% end %> + + <% end %> + <%= link_to "Edit Info", edit_product_path(product), class: "button" %><%= link_to product.retired ? "Unretire Product" : "Retire Product", retire_product_path(product), method: :patch, class: "button" %>
+ + + +<% if @merchant.id == session[:merchant_id] %> + +

Orders

+ + + + +<% if @filtered_orders %> +
+

<%= @title %>

+ <%= render partial: "show_orders", locals: {input_orders: @filtered_orders} %> +
+<% end %> + + + +<% end %> +
diff --git a/app/views/order_products/edit.html.erb b/app/views/order_products/edit.html.erb new file mode 100644 index 0000000000..d3fc35c9f5 --- /dev/null +++ b/app/views/order_products/edit.html.erb @@ -0,0 +1,14 @@ + diff --git a/app/views/orders/_buyerinfo.html.erb b/app/views/orders/_buyerinfo.html.erb new file mode 100644 index 0000000000..b5e1723760 --- /dev/null +++ b/app/views/orders/_buyerinfo.html.erb @@ -0,0 +1,11 @@ +

Receipt

+ +

<%= @payment_info.buyer_name %>'s Purchase Summary:

+ + diff --git a/app/views/orders/_table.html.erb b/app/views/orders/_table.html.erb new file mode 100644 index 0000000000..cf258c28a8 --- /dev/null +++ b/app/views/orders/_table.html.erb @@ -0,0 +1,61 @@ + diff --git a/app/views/orders/checkout.html.erb b/app/views/orders/checkout.html.erb new file mode 100644 index 0000000000..1066e8fa07 --- /dev/null +++ b/app/views/orders/checkout.html.erb @@ -0,0 +1,50 @@ +
+ +

Enter Billing Information

+ + +

+ Disclaimer: This is not a real commercial site. Please do not provide legitimate CC info. -2017- +

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

Oh no, your cart is empty!

+ +
+
Can we suggest? | Something, just for you
+ <% spot = Product.not_retired.sample %> +
+

<%= link_to spot.name, product_path(spot.id)%>

+

Price: <%= readable_price(spot.price) %>

+

<%= image_tag "#{spot.photo_url}", alt:"image", size: "300x300"%>

+

<%= link_to "More Info", product_path(spot.id), class: "button"%>

+

<%= form_tag create_order_product_path(product_id: spot.id), method: :post do %>

+ + <%= hidden_field_tag "quantity", 1 %> + +

<%= submit_tag "Add to Order", class: "buy button" %>

+ <% end %> +
+
diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000000..7f7ecb5b17 --- /dev/null +++ b/app/views/orders/index.html.erb @@ -0,0 +1,20 @@ +<%# link_to 'New Order', new_order_path, class:'button' %> + +

All Orders

+ diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..6f4e3b3ceb --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,4 @@ +<%= form_for @order do |f| %> + <%= f.hidden_field :status, value: "pending" %> + <%= f.submit "Create New Order", class:'button' %> +<% end %> diff --git a/app/views/orders/receipt.html.erb b/app/views/orders/receipt.html.erb new file mode 100644 index 0000000000..87c3793234 --- /dev/null +++ b/app/views/orders/receipt.html.erb @@ -0,0 +1,96 @@ +
+ <%= render partial: 'buyerinfo' %> + <% if flash[:receipt] == @order.payment_info.buyer_name %> + +

<%= "Check #{@payment_info.email} to track your shipping!" %>

+

<%= link_to "Get back to shopping!", root_path, class: "button"%>

+ <% else %> + +

<%= link_to "Back to your page", merchant_path(session[:merchant_id]), class: "button" %>

+ <% end %> + +
diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..49eaa8ea54 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,58 @@ + +

Your Cart

+
+ + + + + + + + + + + + + <% @order.order_products.each do |op| %> + + + + + + + + <% end %> + + + + + + + + +
ProductQuantityCostEditRemove
<%= link_to op.product.name, product_path(op.product) %><%= op.quantity %><%= readable_price(op.subtotal) %> +
+ <%= form_tag order_product_path(op.id, product_id: op.product_id), method: :patch do %> + + <%= text_field_tag :quantity, "", class:'field' %> + + <%= submit_tag "Update Quantity", class: "button" %> + <% end %> +
+
<%= link_to "Delete from cart", order_product_path(op.id), method: :delete, class:'button', + data: { confirm: 'Are you sure?' }%>
Total:<%= readable_price(@order.order_total) %>
+ +

Grand Total: <%= readable_price(@order.order_products.sum(&:subtotal)) %>

+ + +

<%= link_to "Proceed to Checkout", checkout_path(@order.id), class: "button buy" %>

+ +

Order <%= @order.id %>

+

Status: <%= @order.status %>

+ +

<%= link_to "Delete Order and start over!", order_path(@order.id), method: :delete, +data: { confirm: 'Are you sure?' }, class: "button" %>

+ + + +
diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..4a610c3e26 --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,25 @@ +
+ +<%= form_for @product do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> + +<%= f.label :category %> +<%= f.collection_check_boxes(:category_ids, Category.all, :id, :name) %> + +<%= f.label :description %> +<%= f.text_area :description %> + +<%= f.label :price %> +<%= f.text_field :price %> + +<%= f.label :inventory %> +<%= f.text_field :inventory, :value => 1 %> + +<%= f.label :photo_url %> +<%= f.text_field :photo_url %> + + +<% end %> + +
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..8bdd5cfa34 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,3 @@ +

Edit your product:

+ +<%= render partial: "form", locals: { action_name: "Edit" } %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..ae1b4212e5 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,47 @@ +
+

All things that come in 3s

+ + + <% Category.all.each do |category| %> +
+ <%= link_to category.name.capitalize, category_path(category.id) %> +
+ +
+ <% category.products.not_retired.each do |product| %> +
+
+ <%=link_to product_path(product.id) do %> + <%= image_tag product.photo_url %> + <% end %> +
+

<%= link_to product.name.capitalize, product_path(product.id) %> | + <%= readable_price(product.price)%>

+
+ <% end %> +
+ <% end %> +
+ + +<%#
+ <% category.products.each do |product| %> + + <%#
+

<%=link_to product.name.capitalize, product_path(product.id)%>

+ <%#

$<%='%.2f' % product.price%>

+ <%#

<%= image_tag "#{product.photo_url}" %>

+<%#
+ + + +<%# link_to "Delete", product_path(@product), class: "alert button", method: "delete", data: { confirm: "Are you sure?" } %> diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..9b3fa43838 --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,25 @@ +

Write a new Review:

+
+ +<%= form_for @review do |f| %> + + <% rating_array = [] %> + <% (1..5).each do |rating| + stars = render partial: "/layouts/stars", locals: {rating: rating} + rating_array << [stars, rating] + end %> + + <%= f.select :rating, rating_array, {include_blank: 'Select a rating'}, :selected => rating_array[:rating.to_s.to_i - 1] %> + + <%# f.label :rating, "Rating 1-5" %> + <%# f.select :rating, [1,2,3,4,5] %> + + <%= f.label :text, "Write a review!" %> + <%= f.text_area :text %> + + <%= f.hidden_field :product_id, value: @product.id %> + + <%= f.submit "Submit", class:'button' %> + +<% 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..9284f84839 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,91 @@ +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') + + 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..568b4d3a00 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,41 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root 'products#root' + + resources :orders, only: [:index, :show, :edit, :update, :destroy] do + get 'receipt' + get 'empty_cart' + end + + get 'orders/:id/checkout', to: 'orders#checkout', as: 'checkout' + + + resources :products do + resources :reviews, only: [:new] + end + patch '/products/:id/retire', to: 'products#retire', as: 'retire_product' + + resources :reviews, only: [:new, :create] + resources :merchants, only: [:index, :create, :show, :destroy] + + resources :order_products, only: [:edit, :update, :destroy] + post '/order_products', to: 'order_products#create', as: 'create_order_product' + patch '/order_products/:id/update_status', to: 'order_products#update_status', as: 'update_status' + + + get "/auth/:provider/callback", to: "merchants#create", as: 'auth_callback' + get '/logout', to: 'merchants#logout', as: 'logout' + + # get "/categories", to: 'categories#index', as: 'categories' + # get "/categories/new", to: 'categories#new', as: 'new_category' + # post "/categories", to: 'categories#create' + + # resources :categories, only: [:index, :new, :create] + + resources :categories do + # get '/products', to: 'products#index' + resources :products, only: [:index, :new, :create] + end + + +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000000..c576395ae6 --- /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: 6e5982597de3c024cbc2510aaf226317bcc2061b0ba06d6213d308163ee16096bfe32aec74458b2ad9f51d5746db85b5fead79571b817df7fb44f1ee0e71220b + +test: + secret_key_base: 2d7d0e75ee18088f964f7b2374257690106347fe802b712489be93b1dc4e9813e476117e1190dee17c6069ce8a8be86d3302b276b58388b7428c5846acf7333e + +# 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/20171017225535_create_products.rb b/db/migrate/20171017225535_create_products.rb new file mode 100644 index 0000000000..ba4a013b74 --- /dev/null +++ b/db/migrate/20171017225535_create_products.rb @@ -0,0 +1,15 @@ +class CreateProducts < ActiveRecord::Migration[5.1] + def change + create_table :products do |t| + t.string :name + t.text :description + t.integer :price + t.integer :merchant_id + t.string :inventory + t.string :photo_url + + + t.timestamps + end + end +end diff --git a/db/migrate/20171017225858_create_orders.rb b/db/migrate/20171017225858_create_orders.rb new file mode 100644 index 0000000000..7bbcee867c --- /dev/null +++ b/db/migrate/20171017225858_create_orders.rb @@ -0,0 +1,16 @@ +class CreateOrders < ActiveRecord::Migration[5.1] + def change + create_table :orders do |t| + t.string :status + t.string :email + t.string :mailing_address + t.string :buyer_name + t.string :card_number + t.string :expiration + t.string :cvv + t.string :zipcode + + t.timestamps + end + end +end diff --git a/db/migrate/20171017230617_create_merchants.rb b/db/migrate/20171017230617_create_merchants.rb new file mode 100644 index 0000000000..64a57c904c --- /dev/null +++ b/db/migrate/20171017230617_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/20171018023503_change_product_price_from_intege_to_float.rb b/db/migrate/20171018023503_change_product_price_from_intege_to_float.rb new file mode 100644 index 0000000000..246692c6c3 --- /dev/null +++ b/db/migrate/20171018023503_change_product_price_from_intege_to_float.rb @@ -0,0 +1,6 @@ +class ChangeProductPriceFromIntegeToFloat < ActiveRecord::Migration[5.1] + def change + remove_column :products, :price + add_column :products, :price, :float + end +end diff --git a/db/migrate/20171018185635_create_reviews.rb b/db/migrate/20171018185635_create_reviews.rb new file mode 100644 index 0000000000..4cfc2a3d29 --- /dev/null +++ b/db/migrate/20171018185635_create_reviews.rb @@ -0,0 +1,11 @@ +class CreateReviews < ActiveRecord::Migration[5.1] + def change + create_table :reviews do |t| + t.integer :rating + t.string :text + t.integer :product_id + + t.timestamps + end + end +end diff --git a/db/migrate/20171018192530_create_order_products.rb b/db/migrate/20171018192530_create_order_products.rb new file mode 100644 index 0000000000..61e3e5eae6 --- /dev/null +++ b/db/migrate/20171018192530_create_order_products.rb @@ -0,0 +1,11 @@ +class CreateOrderProducts < ActiveRecord::Migration[5.1] + def change + create_table :order_products do |t| + t.integer :quantity + t.integer :product_id + t.integer :order_id + + t.timestamps + end + end +end diff --git a/db/migrate/20171019005522_add_columns_to_merchants.rb b/db/migrate/20171019005522_add_columns_to_merchants.rb new file mode 100644 index 0000000000..0ca18f4ea4 --- /dev/null +++ b/db/migrate/20171019005522_add_columns_to_merchants.rb @@ -0,0 +1,7 @@ +class AddColumnsToMerchants < ActiveRecord::Migration[5.1] + def change + add_column :merchants, :name, :string + add_column :merchants, :provider, :string, null: false + add_column :merchants, :uid, :string, null: false + end +end diff --git a/db/migrate/20171020013202_change_product_inventory_to_integer.rb b/db/migrate/20171020013202_change_product_inventory_to_integer.rb new file mode 100644 index 0000000000..2edbcf0a4d --- /dev/null +++ b/db/migrate/20171020013202_change_product_inventory_to_integer.rb @@ -0,0 +1,6 @@ +class ChangeProductInventoryToInteger < ActiveRecord::Migration[5.1] + def change + change_column(:products, :inventory, 'integer USING CAST(inventory AS integer)') + + end +end diff --git a/db/migrate/20171020192401_create_categories.rb b/db/migrate/20171020192401_create_categories.rb new file mode 100644 index 0000000000..6a23464847 --- /dev/null +++ b/db/migrate/20171020192401_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[5.1] + def change + create_table :categories do |t| + t.string :name + t.timestamps + end + create_join_table :products, :categories + end +end diff --git a/db/migrate/20171024031744_create_payment_infos.rb b/db/migrate/20171024031744_create_payment_infos.rb new file mode 100644 index 0000000000..2ae19ae802 --- /dev/null +++ b/db/migrate/20171024031744_create_payment_infos.rb @@ -0,0 +1,15 @@ +class CreatePaymentInfos < ActiveRecord::Migration[5.1] + def change + create_table :payment_infos do |t| + t.string :email + t.string :mailing_address + t.string :buyer_name + t.string :card_number + t.string :expiration + t.string :cvv + t.string :zipcode + + t.timestamps + end + end +end diff --git a/db/migrate/20171024031934_remove_payment_info_from_order.rb b/db/migrate/20171024031934_remove_payment_info_from_order.rb new file mode 100644 index 0000000000..20f5dc0b7d --- /dev/null +++ b/db/migrate/20171024031934_remove_payment_info_from_order.rb @@ -0,0 +1,11 @@ +class RemovePaymentInfoFromOrder < ActiveRecord::Migration[5.1] + def change + remove_column :orders, :email + remove_column :orders, :mailing_address + remove_column :orders, :buyer_name + remove_column :orders, :card_number + remove_column :orders, :expiration + remove_column :orders, :cvv + remove_column :orders, :zipcode + end +end diff --git a/db/migrate/20171024032510_add_order_id_to_payment_info.rb b/db/migrate/20171024032510_add_order_id_to_payment_info.rb new file mode 100644 index 0000000000..c2774769af --- /dev/null +++ b/db/migrate/20171024032510_add_order_id_to_payment_info.rb @@ -0,0 +1,6 @@ +class AddOrderIdToPaymentInfo < ActiveRecord::Migration[5.1] + def change + add_column :payment_infos, :order_id, :integer + add_column :orders, :payment_info_id, :integer + end +end diff --git a/db/migrate/20171024175026_add_status_to_op.rb b/db/migrate/20171024175026_add_status_to_op.rb new file mode 100644 index 0000000000..f6c638450e --- /dev/null +++ b/db/migrate/20171024175026_add_status_to_op.rb @@ -0,0 +1,5 @@ +class AddStatusToOp < ActiveRecord::Migration[5.1] + def change + add_column :order_products, :status, :string + end +end diff --git a/db/migrate/20171024212310_add_retired_to.rb b/db/migrate/20171024212310_add_retired_to.rb new file mode 100644 index 0000000000..0dd686391b --- /dev/null +++ b/db/migrate/20171024212310_add_retired_to.rb @@ -0,0 +1,5 @@ +class AddRetiredTo < ActiveRecord::Migration[5.1] + def change + add_column :products, :retired, :boolean + end +end diff --git a/db/migrate/20171025181747_add_default_value_to_retired.rb b/db/migrate/20171025181747_add_default_value_to_retired.rb new file mode 100644 index 0000000000..bc371f865c --- /dev/null +++ b/db/migrate/20171025181747_add_default_value_to_retired.rb @@ -0,0 +1,5 @@ +class AddDefaultValueToRetired < ActiveRecord::Migration[5.1] + def change + change_column :products, :retired, :boolean, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..25444b4276 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,88 @@ +# 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: 20171025181747) 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", id: false, force: :cascade do |t| + t.bigint "product_id", null: false + t.bigint "category_id", null: false + 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.string "name" + t.string "provider", null: false + t.string "uid", null: false + end + + create_table "order_products", force: :cascade do |t| + t.integer "quantity" + t.integer "product_id" + t.integer "order_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "status" + end + + create_table "orders", force: :cascade do |t| + t.string "status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "payment_info_id" + end + + create_table "payment_infos", force: :cascade do |t| + t.string "email" + t.string "mailing_address" + t.string "buyer_name" + t.string "card_number" + t.string "expiration" + t.string "cvv" + t.string "zipcode" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "order_id" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.text "description" + t.integer "merchant_id" + t.integer "inventory" + t.string "photo_url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.float "price" + t.boolean "retired", default: false + end + + create_table "reviews", force: :cascade do |t| + t.integer "rating" + t.string "text" + t.integer "product_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/db/seed_data/categories.csv b/db/seed_data/categories.csv new file mode 100644 index 0000000000..f3c17e6c84 --- /dev/null +++ b/db/seed_data/categories.csv @@ -0,0 +1,7 @@ +name +halloween +music +food +animal +game +book diff --git a/db/seed_data/merchants.csv b/db/seed_data/merchants.csv new file mode 100644 index 0000000000..dfe9de5cfe --- /dev/null +++ b/db/seed_data/merchants.csv @@ -0,0 +1,5 @@ +name,username,email,provider,uid +Bennett Rahn,bennettrahn,rahnibennett@gmail.com,github,26212537 +Ben Merchant,benmerchant41,benmerchant41@gmail.com,github,32968600 +Lauren Lee,laurenelee,laurenelee88@gmail.com,github,24926734 +Anders Chen ,anderschenders,andreachen.ac@gmail.com,github,21146738 diff --git a/db/seed_data/products.csv b/db/seed_data/products.csv new file mode 100644 index 0000000000..16571b396b --- /dev/null +++ b/db/seed_data/products.csv @@ -0,0 +1,12 @@ +name,inventory,price,photo_url,description,merchant_id,category +Destiny's Child,3,10.5,http://cdn.playbuzz.com/cdn/e880452f-2f4e-44d5-8b62-5ad9ebcec66a/222b50e6-cb8a-4b3f-8293-b742778c04f9.jpg,A classic album!,1,2 +TLC ,10,11,http://www.kiss925.com/wp-content/uploads/sites/59/2015/03/tlc.jpg,A great debate between Destiny's Child and TLC... buy today to decide for yourself,2,2 +Hanson,5,11,https://cps-static.rovicorp.com/3/JPG_250/MI0002/296/MI0002296059.jpg?partner=allrovi.com,Three adorable young men,3,2 +BLT,10,5.5,http://hagerstownpizzabrothers.com/wp-content/uploads/2015/02/BLT-Sandwich.jpg,Delicious dinner or lunch!,4,3 +Neapolitan Ice Cream,3,3,http://www.articlesweb.org/blog/wp-content/uploads/2011/11/neapolitan-ice-cream-origin-and-recipe-sources-4.jpg,Scrumptious! ,1,3 +Kangaroo,1,100,http://www.australia.com/etc/designs/tourismaustralia/clientlibs/imgs/fallback/kangaroo_800_600.jpg,A hilarious and cute animal that sort of has three legs!,2,4 +Rock Paper Scissors,1,0.5,https://thenypost.files.wordpress.com/2014/06/rock-paper-4.jpg,A game that has 3 options!,3,5 +Movie,3,15,http://popcrush.com/files/2014/09/HocusPocus.jpg,A halloween classic,4,1 +Three Little Pigs,5,2,"https://images-na.ssl-images-amazon.com/images/I/51YKtd0IuZL._SX258_BO1,204,203,200_.jpg",A childhood hit,1,6 +Powerpuff Girls,3,30,https://img0.etsystatic.com/021/0/6191082/il_570xN.498434840_391z.jpg,A fun costume!,2,1 +Beetlejuice,3,12,https://i.pinimg.com/736x/2e/bc/65/2ebc65a661df3da311294af9b4e33ea7--beetlejuice-movie-beetlejuice-costume.jpg,A halloween fun and scary hit!,3,1 diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..02f457551c --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,182 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) +require 'csv' + +# MERCHANTS # + +MERCHANT_FILE = Rails.root.join('db','seed_data','merchants.csv') +puts "Loading raw media data from #{MERCHANT_FILE}" + +merchant_failures = [] +CSV.foreach(MERCHANT_FILE, :headers => true) do |row| + merchant = Merchant.new + merchant.name = row['name'] + merchant.username = row['username'] + merchant.email = row['email'] + merchant.provider = row['provider'] + merchant.uid = row['uid'] + puts "Created merchant: #{merchant.inspect}" + successful = merchant.save + if !successful + merchant_failures << merchant + end +end + +puts "Added #{Merchant.count} merchant records" +puts "#{merchant_failures.length} merchants failed to save" + +# CATEGORIES # + +CATEGORY_FILE = Rails.root.join('db','seed_data','categories.csv') +puts "Loading raw media data from #{CATEGORY_FILE}" + +category_failures = [] +CSV.foreach(CATEGORY_FILE, :headers => true) do |row| + category = Category.new + category.name = row['name'] + puts "Created category: #{category.inspect}" + successful = category.save + if !successful + category_failures << category + end +end + +puts "Added #{Category.count} category records" +puts "#{category_failures.length} categories failed to save" + +# PRODUCT CATEGORIES # + +# PC_FILE = Rails.root.join('db','seed_data','product_category.csv') +# puts "Loading raw media data from #{PC_FILE}" +# +# product_category_failures = [] +# CSV.foreach(PC_FILE, :headers => true) do |row| +# product_category = ProductCategory.new +# product_category.product_id = row['product_id'] +# product_category.category_id = row['category_id'] +# puts "Created merchant: #{product_category.inspect}" +# successful = product_category.save +# if !successful +# product_category_failures << product_category +# end +# end +# +# puts "Added #{ProductCategory.count} product_category records" +# puts "#{product_category_failures.length} product_category failed to save" + +# PRODUCTS # + +PRODUCT_FILE = Rails.root.join('db','seed_data','products.csv') +puts "Loading raw media data from #{PRODUCT_FILE}" + +product_failures = [] +CSV.foreach(PRODUCT_FILE, :headers => true) do |row| + product = Product.new + product.name = row['name'] + product.price = row['price'] + product.inventory = row['inventory'] + product.photo_url = row['photo_url'] + product.description = row['description'] + product.merchant_id = row['merchant_id'] + product.category_ids = [row['category']] + puts "Created product: #{product.inspect}" + successful = product.save + if !successful + product_failures << product + end +end + +puts "Added #{Product.count} product records" +puts "#{product_failures.length} productd failed to save" + +# REVIEWS # + +# REVIEW_FILE = Rails.root.join('db','seed_data','review.csv') +# puts "Loading raw media data from #{REVIEW_FILE}" +# +# review_failures = [] +# CSV.foreach(REVIEW_FILE, :headers => true) do |row| +# review = Review.new +# review.review = row['review'] +# review.rating = row['rating'] +# review.product_id = row['product'] +# puts "Created review: #{review.inspect}" +# successful = review.save +# if !successful +# review_failures << review +# end +# end +# +# puts "Added #{Review.count} review records" +# puts "#{review_failures.length} reviews failed to save" + + +# ORDER ITEMS # + +# order_failures = [] +# 10.times do +# order = Order.new +# successful = order.save +# if !successful +# order_failures << order_item +# end +# puts "Created order: #{order.inspect}" +# end +# puts "Added #{Order.count} order item records" +# puts "#{order_failures.length} orders failed to save" + +# ORDER ITEMS # + +# ORDER_ITEMS_FILE = Rails.root.join('db','seed_data','order_items.csv') +# puts "Loading raw media data from #{ORDER_ITEMS_FILE}" +# +# order_items_failures = [] +# CSV.foreach(ORDER_ITEMS_FILE, :headers => true) do |row| +# order_item = OrderItem.new +# order_item.product_id = row['product_id'] +# order_item.order_id = row['order_id'] +# order_item.quantity = row['quantity'] +# +# puts "Created order item: #{order_item.inspect}" +# successful = order_item.save +# if !successful +# order_items_failures << order_item +# end +# end +# +# puts "Added #{OrderItem.count} order item records" +# puts "#{order_items_failures.length} order items failed to save" + +# Payments # + +# PAYMENT_FILE = Rails.root.join('db','seed_data','payment.csv') +# puts "Loading raw payment data from #{PAYMENT_FILE}" +# +# d1 = Date.new(2017,5,8) +# +# payment_failures = [] +# CSV.foreach(PAYMENT_FILE, :headers => true) do |row| +# payment = Payment.new +# payment.email = row['email'] +# payment.mailing_address = row['mailing_address'] +# payment.cc_name = row['cc_name'] +# payment.cc_expiration = d1 +# payment.cc_number = row['cc_number'] +# payment.cc_ccv = row['cc_ccv'] +# payment.billing_zip = row['billing_zip'] +# payment.order_id = row['order_id'] +# +# puts "Created payment: #{payment.inspect}" +# successful = payment.save +# if !successful +# payment_failures << payment +# end +# end +# +# puts "Added #{Payment.count} order item records" +# puts "#{payment_failures.length} payments 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/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..77c0ebc8e9 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,88 @@ +require "test_helper" + +describe CategoriesController do + + #everyone can view all categories + describe "index" do + it "returns a success status when there are categories" do + Category.count.must_be :>, 0, "No categories in the test fixtures" + get categories_path + must_respond_with :success + end + + it "returns a success status when there are no categories" do + Category.destroy_all + get categories_path + must_respond_with :success + end + end + + describe "show" do + it "returns a success status if given a valid category id" do + cat = categories(:book) + get category_path(cat.id) + must_respond_with :success + end + + it "returns a not_found status if given an invalid category id" do + invalid_cat_id = Category.last.id + 1 + get category_path(invalid_cat_id) + must_respond_with :not_found + end + end + + describe "not logged in user" do + describe "new" do + it "returns a flash[:status] of failure, and redirects to products path" do + get new_category_path + flash[:status].must_equal :failure + must_respond_with :redirect + must_redirect_to products_path + end + end + + describe "create" do + it "returns a flash[:status] of failure, and redirects to products path" do + new_cat = { + category: { + name: "new cat" + } + } + + post categories_path, params: new_cat + flash[:status].must_equal :failure + must_respond_with :redirect + must_redirect_to products_path + end + end + end + + + describe "merchant logged in" do + + before do + merchant = Merchant.first + login(merchant) + end + + describe "new" do + it "returns a success status" do + get new_category_path + must_respond_with :success + end + end + + describe "create" do + it "creates a new category with valid data and redirects to products_path" do + new_cat = { + category: { + name: "new cat" + } + } + post categories_path, params: new_cat + must_respond_with :redirect + must_redirect_to products_path + end + 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..85b3aa5902 --- /dev/null +++ b/test/controllers/merchants_controller_test.rb @@ -0,0 +1,183 @@ +require "test_helper" + +describe MerchantsController do + describe "for logged in merchant" do + before do + @merchant = merchants(:anders) + login(@merchant) + end + + describe "index" do + it "succeeds when there are merchants" do + Merchant.count.must_be :>, 0, "No merchants in the test fixtures" + get merchants_path + must_respond_with :success + end + + it "succeeds when there are no merchants" do + Merchant.destroy_all + get merchants_path + must_respond_with :success + end + end + + describe "show" do + it "succeeds for a logged in merchant's own page" do + get merchant_path(@merchant) + must_respond_with :success + end + + it "renders 404 not_found for a invalid merchant ID" do + invalid_merchant_id = Merchant.last.id + 1 + get merchant_path(invalid_merchant_id) + must_respond_with :not_found + end + + it "returns a success status for a different merchant's page" do + merchant = merchants(:bennett) + get merchant_path(merchant) + must_respond_with :success + end + + # not sure how to test filters - since it is entirely a view thing? + it "returns a success status when parameters are passed in - for filtering orders" do + merchant = merchants(:bennett) + get merchant_path(merchant, status: "complete") + must_respond_with :success + end + end + + describe "destroy" do + it "succeeds for a logged in merchant who is deleting their own account" do + delete merchant_path(@merchant.id) + must_redirect_to merchants_path + + # The work should really be gone + Merchant.find_by(id: @merchant.id).must_be_nil + end + + it "renders 404 not_found and does not update the DB for a bogus work ID" do + start_count = Merchant.count + + bogus_work_id = Merchant.last.id + 1 + delete merchant_path(bogus_work_id) + must_respond_with :not_found + + Merchant.count.must_equal start_count + end + + it "sets flash[:status] to failiure and redirects to root_path if a logged in merchant is trying to delete another merchant's account" do + other_merchant = merchants(:bennett) + + delete merchant_path(other_merchant.id) + flash[:status].must_equal :failure + must_redirect_to root_path + end + end + end + + describe "non logged in user" do + describe "index" do + it "returns success for a non-logged in user" do + get merchants_path + must_respond_with :success + end + end + + describe "show" do + it "returns success for a non-logged in user" do + get merchant_path(merchants(:anders)) + must_respond_with :success + end + end + + describe "destroy" do + it "destroy fails for a non-logged in user" do + merchant = merchants(:bennett) + delete merchant_path(merchant.id) + must_redirect_to products_path + flash[:status].must_equal :failure + end + end + end + + describe "create and login with auth_callback" do + it "logs in an existing user and redirects to the products route" do + # Count the merchants, to make sure we're not (for example) creating + # a new merchant every time we get a login request + start_count = Merchant.count + + # Get a merchant from the fixtures + merchant = merchants(:anders) + + # Tell OmniAuth to use this merchant's info when it sees + # an auth callback from github + login(merchant) + # OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant)) + + # Send a login request for that merchant + # Note that we're using the named path for the callback, as defined + # in the `as:` clause in `config/routes.rb` + # get auth_callback_path(:github) + + must_redirect_to products_path + + # Since we can read the session, check that the user ID was set as expected + session[:merchant_id].must_equal merchant.id + + # Should *not* have created a new user + Merchant.count.must_equal start_count + end + + it "creates an account for a new merchant and redirects to the products route" do + start_count = Merchant.count + + merchant = Merchant.new(provider: "github", uid: 123124564, username: "test_merchant", email: "test@merchant.com", name: "trio") + + login(merchant) + + must_redirect_to products_path + flash[:status].must_equal :success + + # Should have created a new user + Merchant.count.must_equal start_count + 1 + + # The new user's ID should be set in the session + merchant_id = Merchant.find_by(username: merchant[:username]).id + session[:merchant_id].must_equal merchant_id + end + + it "redirects to the products route if given invalid user data" do + invalid_merchant = Merchant.first + invalid_merchant.uid = "" + + login(invalid_merchant) + + must_redirect_to products_path + flash[:status].must_equal :failure + end + + it "tells you you're already logged in if you're logged in." do + #log in again + merchant = merchants(:anders) + login(merchant) + login(merchant) + + flash[:status].must_equal :failure + flash[:message].must_equal "You're already logged in, Bae!" + end + + end + + describe "logout" do + it "succeeds, redirects to products_path, sets flash[:status] to success and session[:merchant_id], [:cart] to nil" do + get logout_path + must_respond_with :redirect + must_redirect_to products_path + flash[:status].must_equal :success + session[:merchant_id].must_equal nil + session[:cart].must_equal nil + 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..4669fab568 --- /dev/null +++ b/test/controllers/order_products_controller_test.rb @@ -0,0 +1,190 @@ +require "test_helper" + +describe OrderProductsController do + + before do + @product_params = { + product_id: products(:tricycle).id, + quantity: 1 + } + end + + describe "update_status" do + it "if entire order is complete, sets flash[:status] to success when order is saved with specific message, redirects merchant show page, and sets the orderproduct status and orders status to complete" do + #arrange + order_prod = order_products(:four) + + #assert + patch update_status_path(order_prod.id) + + #act + order_prod.reload + flash[:status].must_equal :success + order_prod.status.must_equal "complete" + order_prod.order.status.must_equal"complete" + flash[:message].must_equal "Order has been completed and shipped to buyer" + end + + it "if order status is not complete, it was set flash[:status] to success and message to 'order has been completed and shipped to buyer', and the order status will not be complete" do + #arrange + order_prod = order_products(:two) + + #assert + patch update_status_path(order_prod.id) + + #act + order_prod.reload + flash[:status].must_equal :success + order_prod.status.must_equal "complete" + order_prod.order.status.must_equal "pending" + flash[:message].must_equal "Product has been added to order, Order is waiting on other products before shipping." + end + end + + describe "destroy" do + it "deletes the orderproduct and redirects to order_path if there are still other orderproducts in the cart" do + order_prod = order_products(:two) + order_products(:three) + order = orders(:order4) + + order = order_prod.order + + delete order_product_path(order_prod.id) + + must_respond_with :redirect + must_redirect_to order_path(order) + end + + it "deletes the orderproduct and redirects to order_empty_cart_path if no more orderproducts in the order" do + order_prod = order_products(:four) + order_prod.order.id + + delete order_product_path(order_prod.id) + + must_respond_with :redirect + must_redirect_to order_empty_cart_path(:cart) + end + end + + describe "create" do + + it "creates an OrderProduct with a product and an order, creates a new order if no session[:cart] exists" do + orders_start = Order.count + start_count = OrderProduct.count + + post create_order_product_path, params: @product_params + must_redirect_to order_path(session[:cart]) + + OrderProduct.count.must_equal start_count + 1 + Order.count.must_equal orders_start + 1 + end + + it "creates a new OrderProduct with a product and an order if doesn't exist already, adds to existing cart if it has already been initiated" do + post create_order_product_path, params: @product_params + #I have to do this in order to set session. + + orders_start = Order.count + start_count = OrderProduct.count + + + new_product = { + product_id: products(:tripod).id, + quantity: 1 + } + + post create_order_product_path, params: new_product + must_redirect_to order_path(session[:cart]) + + OrderProduct.count.must_equal start_count + 1 + Order.count.must_equal orders_start + end + + it "if an OrderProduct with the same product already exists, it will not create a new OrderProduct object" do + post create_order_product_path, params: @product_params + + orders_start = Order.count + start_count = OrderProduct.count + + post create_order_product_path, params: @product_params + must_redirect_to order_path(session[:cart]) + + OrderProduct.count.must_equal start_count + Order.count.must_equal orders_start + end + + it "changes the quantity of an existing OrderProduct if trying to add more of the same product" do + post create_order_product_path, params: @product_params + + op = OrderProduct.find_by(order_id: session[:cart]) + quantity_start = op.quantity + + # binding.pry + post create_order_product_path, params: @product_params + + op.reload + op.quantity.must_equal quantity_start + 1 + end + + it "wont create if input is invalid" do + bad_product_params = { + product_id: products(:tricycle).id, + quantity: 0 + } + start_count = OrderProduct.count + + post create_order_product_path, params: bad_product_params + must_respond_with :bad_request + flash[:message].must_equal "Could not update cart." + + OrderProduct.count.must_equal start_count + end + + it "wont create if quantity is larger than inventory" do + bad_product_params = { + product_id: products(:tricycle).id, + quantity: (products(:tricycle).inventory + 1) + } + start_count = OrderProduct.count + + post create_order_product_path, params: bad_product_params + must_respond_with :bad_request + flash[:message].must_equal "Not enough tricycles in stock, please revise the quantity selected." + + OrderProduct.count.must_equal start_count + end + end + + describe "update" do + it "changes the quantity of an existing OrderProduct, if enough inventory" do + post create_order_product_path, params: @product_params + order_prod = OrderProduct.last + + update_order_prod = { + product_id: order_prod.product_id, + quantity: 2 + } + patch order_product_path(order_prod.id), params: update_order_prod + + must_respond_with :redirect + must_redirect_to order_path(order_prod.order) + flash[:status].must_equal :success + + order_prod.reload + order_prod.quantity.must_equal 2 + end + + it "sets flash[:status] to failure if there isn't enough inventory to update" do + post create_order_product_path, params: @product_params + order_prod = OrderProduct.last + + update_order_prod = { + product_id: order_prod.product_id, + quantity: 10 + } + patch order_product_path(order_prod.id), params: update_order_prod + + must_respond_with :bad_request + flash[:status].must_equal :failure + 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..c83c5d7140 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,175 @@ +require "test_helper" + +describe OrdersController do + let :order_data { + order_data = { + order: { + status: "pending", + payment_info: payment_infos(:payment1) + } + } + } + let :order_id { Order.last.id } + + + describe "index" do + it "returns a success status for all orders" do + get orders_path + must_respond_with :success + end + + it "returns a success status for no orders" do + Order.destroy_all + get orders_path + must_respond_with :success + end + end + + describe "show" do + it "returns success when given the current cart id." do + product_params = { + product_id: products(:tricycle).id, + quantity: 1 + } + post create_order_product_path, params: product_params + + get order_path(session[:cart]) + must_respond_with :success + end + it "returns not_found when given an invaild id" do + get order_path(order_id + 1) + must_respond_with :not_found + end + it "wont show past orders" do + get order_path(order_id) + must_redirect_to root_path + end + end + + describe "update" do + it "returns not_found when given an invaild id" do + put order_path(order_id + 1), params: order_data + must_respond_with :not_found + end + +# NEED TO FIX ############## + it "returns success if the order exists and the change is valid" do + payment_data = { + payment_info: { + email: "example@example.com", + buyer_name: "name", + cvv: "123", + card_number: "123456", + zipcode: "12345", + mailing_address: "12 34th st", + expiration: "12/34" + } + + } + + orders(:order1).must_be :valid? + get checkout_path(orders(:order1)) + put order_path(orders(:order1)), params: payment_data + session[:cart].must_be_nil + must_respond_with :redirect + must_redirect_to order_receipt_path(orders(:order1)) + end + end + + describe "checkout" do + it "sends the user to the checkout form" do + get checkout_path(order_id) + must_respond_with :success + end + it "not valid when order doesn't exist" do + get checkout_path(order_id + 1) + must_respond_with :not_found + end + end + + describe "receipt" do + it "shows the receipt after a successful update/checkout" do + merchant = merchants(:anders) + login(merchant) + payment_data = { + payment_info: { + email: "example@example.com", + buyer_name: "name", + cvv: "123", + card_number: "123456", + zipcode: "12345", + mailing_address: "12 34th st", + expiration: "12/34" + } + + } + patch order_path(orders(:order1)), params: payment_data + + get order_receipt_path(orders(:order1)) + must_respond_with :success + end + + it "cannot see a receipt twice; receipts will only show immediately after a purchase" do + + payment_data = { + payment_info: { + email: "example@example.com", + buyer_name: "name", + cvv: "123", + card_number: "123456", + zipcode: "12345", + mailing_address: "12 34th st", + expiration: "12/34" + } + } + patch order_path(orders(:order1)), params: payment_data + + get order_receipt_path(orders(:order1)) + must_respond_with :success + + get order_receipt_path(orders(:order1)) + must_respond_with :redirect + flash[:status].must_equal :failure + end + + it "shows the receipt to the merchant who is the owner of the orderproduct; so a merchant can see a receipt twice" do + merchant = merchants(:anders) + login(merchant) + + payment_data = { + payment_info: { + email: "example@example.com", + buyer_name: "name", + cvv: "123", + card_number: "123456", + zipcode: "12345", + mailing_address: "12 34th st", + expiration: "12/34" + } + } + patch order_path(orders(:order1)), params: payment_data + + get order_receipt_path(orders(:order1)) + must_respond_with :success + + get order_receipt_path(orders(:order1)) + must_respond_with :success + end + end + + describe "destroy" do + it "returns success if the order was destroyed" do + total = Order.count + delete order_path(orders(:order1)) + must_respond_with :redirect + must_redirect_to root_path + total.must_equal Order.count + 1 + end + + it "returns not_found when given an invaild id" do + put order_path(order_id + 1) + must_respond_with :not_found + 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..e56d1aa19b --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,241 @@ +require "test_helper" + +describe ProductsController do + +##########LOGGED IN MERCHANT################# + describe "logged in merchant" do + before do + merchant = Merchant.first + login(merchant) + end + + describe "root" do + it "returns a success status" do + get root_path + must_respond_with :success + end + end + + describe "index" do + it "shows all products" do + get products_path + must_respond_with :success + end + + it "returns success status when there are no products" do + Product.destroy_all + get products_path + must_respond_with :success + end + end + + describe "show" do + it "returns success when given a valid product id" do + product_id = Product.first.id + # user_id = session[:user_id] + get product_path(product_id) + must_respond_with :success + end + + it "returns not_found when given a bad work id" do + bad_product_id = Product.last.id + 1 + get product_path(bad_product_id) + must_respond_with :not_found + end + end + + describe "new" do + it "creates a new product successfully" do + get new_product_path + must_respond_with :success + end + end + + describe "create" do + it "saves and redirects to products_path when the product data is valid" do + product_data = { + product: { + name: "book", + price: 4.32, + inventory: 2, + category_ids: [categories(:book).id] + } + } + product = Product.new(product_data[:product]) + product.merchant_id = session[:merchant_id] + product.must_be :valid? + start_product_count = Product.count + + post products_path, params: product_data + must_respond_with :redirect + must_redirect_to products_path(product.id) + Product.count.must_equal start_product_count + 1 + end + + it "renders a bad_request when the product data is invalid" do + bad_product = { + product: { + name: "book", + # no price given!! + } + } + Product.new(bad_product[:product]).wont_be :valid? + start_product_count = Product.count + post products_path, params: bad_product + + must_respond_with :bad_request + Product.count.must_equal start_product_count + end + end + + describe "edit" do + it "returns success when given a valid product id" do + product_id = Product.first.id + get product_path(product_id) + must_respond_with :success + end + + it "returns not_found when given a bad work id" do + bad_product_id = Product.last.id + 1 + get product_path(bad_product_id) + must_respond_with :not_found + end + end + + describe "update" do + it "returns success when change is valid" do + product = Product.first + product_data = { + product: { + name: "book", + price: 4.32, + category_ids: Category.first.id + } + } + product.update_attributes(product_data[:product]) + product.must_be :valid? + + patch product_path(product), params: product_data + must_respond_with :redirect + must_redirect_to product_path(product) + + product.reload + product.name.must_equal product_data[:product][:name] + end + + it "returns not_found if product id is invalid" do + bad_product_id = Product.last.id + 1 + product_data = { + product: { + name: " title" + } + } + patch product_path(bad_product_id), params: product_data + must_respond_with :not_found + end + + it "returns bad_request when change is invalid" do + product = Product.first + bad_product_data = { + product: { + name: "" + } + } + product.update_attributes(bad_product_data[:product]) + product.wont_be :valid? + start_product_count = Product.count + + patch product_path(product), params: bad_product_data + must_respond_with :bad_request + Product.count.must_equal start_product_count + end + end + + describe "destroy" do + it "returns success when product is deleted" do + product_count = Product.count + product_id = Product.first + delete product_path(product_id) + must_respond_with :redirect + must_redirect_to products_path + Product.count.must_equal product_count - 1 + end + + it "returns not_found if given invalid product id" do + bad_product_id = Product.last.id + 1 + + delete product_path(bad_product_id) + must_respond_with :not_found + end + end + end + +##########NOT LOGGED IN USERS################# + describe "not logged in users" do + describe "root" do + it "returns a success status" do + get root_path + must_respond_with :success + end + end + + describe "index" do + it "shows all products" do + get products_path + must_respond_with :success + end + + it "returns success status when there are no products" do + Product.destroy_all + get products_path + must_respond_with :success + end + end + + describe "show" do + it "returns success when given a valid product id" do + product_id = Product.first.id + # user_id = session[:user_id] + get product_path(product_id) + must_respond_with :success + end + + it "returns not_found when given a bad work id" do + bad_product_id = Product.last.id + 1 + get product_path(bad_product_id) + must_respond_with :not_found + end + end + + describe "new" do + it "will set flash[:status] to failure and redirect to products_path" do + get new_product_path + flash[:status].must_equal :failure + must_respond_with :redirect + must_redirect_to products_path + end + end + + describe "edit" do + it "will set flash[:status] to failure and redirect to products_path" do + product_id = Product.first.id + get edit_product_path(product_id) + flash[:status].must_equal :failure + flash[:message].must_equal "You must be logged in to do that!" + must_respond_with :redirect + must_redirect_to products_path + end + end + + describe "destroy" do + it "will set flash[:status] to failure and redirect to products_path" do + delete product_path(Product.first) + flash[:status].must_equal :failure + must_respond_with :redirect + must_redirect_to products_path + end + end + + #Do we need tests for #create and #update here? + end +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..5c78d30571 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,136 @@ +require "test_helper" + +describe ReviewsController do + # let (:review) {reviews(:review1)} + + #######LOGGED IN MERCHANT########## + describe "logged in merchant" do + before do + merchant = merchants(:anders) + login(merchant) + end + + describe "new" do + it "merchants can go to a new review path for other products" do + product = products(:tripod) + get new_product_review_path(product) + must_respond_with :success + end + + it "doesn't allow a merchant to go to a new review on their own product" do + + product = products(:tricycle) + start_review_count = Review.count + get new_product_review_path(product) + + must_redirect_to products_path + flash[:message].must_equal "You cannot review your own product!" + Review.count.must_equal start_review_count + end + end + + describe "create" do + it "just in case, doesn't allow a merchant create a review on their own product" do + # TODO: come back to this test + # review_data = { + # review: { + # rating: 3, + # text: "I loved it!", + # product_id: product.id + # } + # } + # product = products(:tricycle) + # start_review_count = Review.count + # post reviews_path, params: review_data + # + # must_redirect_to products_path + # flash[:message].must_equal "You cannot review your own product!" + # Review.count.must_equal start_review_count + end + + it "does allow a merchant to review other products" do + product = products(:tripod) + review_data = { + review: { + rating: 3, + text: "I loved it!", + product_id: product.id + } + } + puts review_data[:review][:product_id] + product.reviews.new(review_data[:review]).must_be :valid? + start_review_count = Review.count + + post reviews_path, params: review_data + + must_respond_with :redirect + must_redirect_to product_path(product.id) + Review.count.must_equal start_review_count + 1 + + end + + end + end + + #######NOT LOGGED IN USER########## + describe "not logged in user" do + + describe "new" do + it "responds with success when directed to the new review path" do + product = Product.first.id + get new_product_review_path(product) + must_respond_with :success + end + + it "returns not_found if given invalid product id" do + invalid_prod_id = Product.last.id + 1 + get new_product_review_path(invalid_prod_id) + must_respond_with :not_found + end + end + + describe "create" do + it "saves and redirects to product show page when the review data is valid" do + + product = Product.first + review_data = { + review: { + rating: 3, + text: "I loved it!", + product_id: product.id + } + } + puts review_data[:review][:product_id] + product.reviews.new(review_data[:review]).must_be :valid? + start_review_count = Review.count + + post reviews_path, params: review_data + + must_respond_with :redirect + must_redirect_to product_path(product.id) + Review.count.must_equal start_review_count + 1 + end + + it "sends :bad_request if data is invalid" do + + product = Product.first + review_data = { + review: { + rating: 0, + text: "I loved it!", + product_id: product.id + } + } + puts review_data[:review][:product_id] + product.reviews.new(review_data[:review]).wont_be :valid? + start_review_count = Review.count + + post reviews_path, params: review_data + must_respond_with :bad_request + + Review.count.must_equal start_review_count + end + 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..6678e967a8 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,17 @@ +# 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: {} +# # column: value +# # +# two: {} +# column: value + +book: + name: book + +movie: + name: movie 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..216b466a63 --- /dev/null +++ b/test/fixtures/merchants.yml @@ -0,0 +1,22 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +anders: + provider: github + uid: 12345 + username: anders + email: anders@tricycle.com + name: "Anders" + +lauren: + provider: github + uid: 67896789 + username: lauren + email: lauren@tricycle.com + name: "Lauren" + +bennett: + provider: github + uid: 123123123 + username: bennett + email: bennett@tricycle.com + name: "Bennett" diff --git a/test/fixtures/order_products.yml b/test/fixtures/order_products.yml new file mode 100644 index 0000000000..ff20d7310a --- /dev/null +++ b/test/fixtures/order_products.yml @@ -0,0 +1,31 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + quantity: 1 + product: tricycle + order: order5 + status: "paid" + +two: + quantity: 1 + product: tripod + order: order4 + status: "" + +three: + quantity: 1 + product: tricycle + order: order4 + status: "" + +four: + quantity: 1 + product: tricycle + order: order1 + status: "" + +five: + quantity: 1 + product: tripod + order: order3 + status: "" diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..90b1328592 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +order1: + status: "pending" + +order2: + status: "pending" + +order3: + status: "complete" + +order4: + status: "pending" + +order5: + status: "paid" + +order6: + status: 'pending' diff --git a/test/fixtures/payment_infos.yml b/test/fixtures/payment_infos.yml new file mode 100644 index 0000000000..b69b7c6a42 --- /dev/null +++ b/test/fixtures/payment_infos.yml @@ -0,0 +1,24 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# + +payment1: + email: "bennett@email.com" + mailing_address: "123 S 1st Ave" + buyer_name: "Bennett" + card_number: "1234 5678 9101 1121" + expiration: "01/12" + cvv: "123" + zipcode: "98013" + +payment2: + email: "suzy@email.com" + mailing_address: "456 N 2nd Ave" + buyer_name: "Suzy" + card_number: "3141 5161 7181 9202" + expiration: "03/07" + cvv: "678" + zipcode: "73452" diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..1dd77c709d --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,29 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +# one: {} +# # column: value +# # +# two: {} +# column: value + + +tricycle: + name: tricycle + description: "A fun toy!" + merchant: anders + inventory: 4 + photo_url: https://i-d-images.vice.com/images/2016/09/16/bill-murray-has-a-couple-of-shifts-at-a-brooklyn-bar-this-weekend-body-image-1473999364.jpg + price: 2.40 + # category_ids + +tripod: + name: tripod + description: "Good for cameras" + merchant: lauren + inventory: 4 + photo_url: https://i-d-images.vice.com/images/2016/09/16/bill-murray-has-a-couple-of-shifts-at-a-brooklyn-bar-this-weekend-body-image-1473999364.jpg + price: 12.56 diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..dc3b5cd7f2 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,26 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +# one: {} +# # column: value +# # +# two: {} +# column: value + +review1: + rating: 1 + text: "Terrible" + product: tricycle + +review2: + rating: 4 + text: "Great" + product: tricycle + +review3: + rating: 5 + text: "A hit!" + product: tripod 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..96a9dc36dc --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,73 @@ +require "test_helper" + +describe Category do + + let (:category) {categories(:book)} + + describe "relations" do + it "must be connected to products" do + category.must_respond_to :products + end + end + + describe "validations" do + it "is valid when given valid category data" do + new_cat = Category.new(name: "record") + new_cat.must_be :valid? + end + + it "requires a name" do + invalid_cat = Category.new(name: "") + invalid_cat.wont_be :valid? + end + + it "requres a name that is unique" do + new_cat = Category.new(name: "record") + new_cat.save + new_cat_2 = Category.new(name: "record") + new_cat_2.wont_be :valid? + end + end + + describe "#self.spot" do + it "can be called" do + Category.must_respond_to :spot + end + + it "returns a Product object" do + Category.spot.must_be_instance_of Product + end + + it "returns nil if no products" do + Product.destroy_all + Category.spot.must_equal nil + end + end + + describe "#self.root_page_seasonal_pick" do + it "can be called" do + Category.must_respond_to :root_page_seasonal_pick + end + + it "returns an array of Product objects" do + halloween_category = Category.create!(name: "halloween") + product = products(:tricycle) + product.categories << halloween_category + + array_products = Category.root_page_seasonal_pick + array_products.must_be_instance_of Array + array_products[0].must_be_instance_of Product + end + + it "returns an empty array of if no products" do + Product.destroy_all + Category.root_page_seasonal_pick.must_be :empty? + end + + it "returns an empty array if no categories" do + Category.destroy_all + Category.root_page_seasonal_pick.must_be :empty? + end + end + +end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..3030334fc4 --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,135 @@ +require "test_helper" + +describe Merchant do + before do + @m = Merchant.new + @valid_test_m = Merchant.new(username: "tricycle", email: "tricycle@tricycle.com" ) + end + + describe "relations" do + it "responds to products" do + @m.must_respond_to :products + end + + it "has one or many products" do + @m.must_respond_to :products + @m.products.must_be :empty? + + product = products(:tricycle) + + @m.products << product + + @m.products.must_include product + end + end + + describe "validations" do + it "is valid when given valid merchant data" do + @valid_test_m.must_be :valid? + end + + it "requires a username" do + merchant = Merchant.new(username: "", email: "email@email.com") + merchant.valid?.must_equal false + merchant.errors.messages.must_include :username + end + + it "requires a unique username" do + merchant = merchants(:anders) + same_username = Merchant.new(username: merchant.username, email: merchant.username) + same_username.valid?.must_equal false + same_username.errors.messages.must_include :username + end + + it "requires an email" do + merchant = Merchant.new(username: "username", email: "") + merchant.valid?.must_equal false + merchant.errors.messages.must_include :email + end + + it "requires a unique email" do + merchant = merchants(:anders) + same_email = Merchant.new(username: merchant.username, email: merchant.username) + same_email.valid?.must_equal false + same_email.errors.messages.must_include :email + end + + it "requires an email in a certain format" do + merchant = Merchant.new(username: "username", email: "tricycle") + merchant.valid?.must_equal false + merchant.errors.messages.must_include :email + + merchant1 = Merchant.new(username: "username", email: "tricycle@") + merchant1.valid?.must_equal false + merchant.errors.messages.must_include :email + + merchant2 = Merchant.new(username: "username", email: "tricycle@tricycle") + merchant2.valid?.must_equal false + merchant.errors.messages.must_include :email + + merchant3 = Merchant.new(username: "username", email: "tricycle@tricycle.") + merchant3.valid?.must_equal false + merchant.errors.messages.must_include :email + end + end + + describe "custom methods" do + + #below test not passing - in merchant.rb, if I comment out all the auth_hash['info'] lines, then it passes. In test_helper.rb, #mock_auth_hash does not set an ['info']['name']... but that can't be all the problem (if it is even a problem), because ['info']['email'] and ['info']['nickname'] also aren't being recognized + describe "#self.from_auth_hash" do + it "returns an instance of Merchant" do + merchant = merchants(:lauren) + + merchant_instance = Merchant.from_auth_hash('github', mock_auth_hash(merchant)) + + merchant_instance.must_be_instance_of Merchant + end + end + + describe "relevant_orders" do + it "returns an Array of Hashes Order objects" do + merchant = merchants(:lauren) + should_return = merchant.relevant_orders + should_return.must_be_instance_of Array + should_return[0].must_be_instance_of Hash + end + + it "returns an empty Array if no orders" do + Order.destroy_all + merchant = merchants(:lauren) + should_return = merchant.relevant_orders + should_return.length.must_equal 0 + end + end + + describe "sort_orders_by_status" do + it "returns the order hashes like relevant_orders, but only for a certain status" do + merchant = merchants(:lauren) + merchant.sort_orders_by_status('paid').each do |order| + order[:order].status.must_equal "paid" + end + end + # the no orders edge case is tested above in relevant_orders + end + + describe "total_revenue" do + it "counts the completed orders total money" do + merchant = merchants(:lauren) + should_return = merchant.total_revenue('complete') + should_return.must_equal products(:tripod).price + end + it "does the same for paid (waiting to be completed) orders" do + merchant = merchants(:anders) + should_return = merchant.total_revenue('paid') + should_return.must_equal products(:tricycle).price + end + + it "returns 0 if no orders for that status" do + merchant = merchants(:bennett) + merchant.total_revenue('paid').must_equal 0 + end + end + + end + +end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb new file mode 100644 index 0000000000..36372b594c --- /dev/null +++ b/test/models/order_product_test.rb @@ -0,0 +1,42 @@ +require "test_helper" + +describe OrderProduct do + let (:op) { order_products(:five) } + let (:order) { orders(:order1) } + let (:product) { products(:tricycle)} + + describe "relationships" do + it "has an order" do + op.must_respond_to :order + op.order.must_be_kind_of Order + end + + it "has a product" do + op.must_respond_to :product + op.product.must_be_kind_of Product + end + + it "has a merchant" do + op.must_respond_to :merchant + op.merchant.must_be_kind_of Merchant + end + end + + describe "vaildations" do + it "works with a number greater than 0" do + [1, 3, 7, 10].each do |quantity| + op_valid = OrderProduct.new(order: order, product: product, quantity: quantity) + op_valid.valid?.must_equal true + end + end + + it "doesn't work with non-valid things." do + [0, -7, "nil"].each do |quantity| + op_invalid = OrderProduct.new(order: order, product: product, quantity: quantity) + op_invalid.valid?.must_equal false + op_invalid.errors.messages.must_include :quantity + end + + end + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..59bd9a7804 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,80 @@ +require "test_helper" + +describe Order do + let (:order) { orders(:order1) } + describe "relationships" do + it "has a list of order_products, which have products." do + order.must_respond_to :order_products + order.must_respond_to :products + order.order_products.each do |op| + op.product.must_be_kind_of Product + end + end + + it "has one payment_info" do + order.must_respond_to :payment_info + end + end + + describe "methods" do + describe "products" do + it "returns an array of products for that order" do + order.products.each do |product| + product.must_be_kind_of Product + end + end + + it "returns an empty array if the order has no products" do + empty_order = Order.new + empty_order.products.must_be_empty + end + end + end + + describe "order_complete?" do + it "can be called" do + order = orders(:order3) + order.must_respond_to :order_complete? + end + it "returns true if the all order product status is complete" do + op = order_products(:four) + order = orders(:order1) + op.status = "complete" + op.save + + order.order_complete?.must_equal true + end + + it "returns false if the order is not complete" do + order_products(:four) + order = orders(:order1) + + order.order_complete?.must_equal false + end + + #TODO: what if there are no orderproducts? + # it "sets flash[:status] to failure is there are no orderproducts" do + # OrderProducts.destroy_all + # order = orders(:order1) + # + # order.order_complete?. + # end + + end + + describe "order_total" do + it "returns the total of the whole order if no merchant is passed" do + orders(:order4).order_total.must_equal products(:tripod).price + products(:tricycle).price + end + + it "returns the total of the products belonging to a merchant if one is passed" do + orders(:order4).order_total(merchant: merchants(:lauren)).must_equal products(:tripod).price + end + + it "returns 0 when there are no products" do + orders(:order4).order_total(merchant: merchants(:bennett)).must_equal 0 + + orders(:order6).order_total.must_equal 0 + end + end +end diff --git a/test/models/payment_info_test.rb b/test/models/payment_info_test.rb new file mode 100644 index 0000000000..89c933926d --- /dev/null +++ b/test/models/payment_info_test.rb @@ -0,0 +1,90 @@ +require "test_helper" + +describe PaymentInfo do + let (:payment_info) { payment_infos(:payment1) } + describe "relationships" do + it "has one order" do + payment_info.must_respond_to :order + end + end + + describe "validations" do + before do + @invaild_payment = PaymentInfo.new(buyer_name: "", email: "") + end + + it "is valid when given valid merchant data" do + payment_info.must_be :valid? + end + + it "requires a buyer_name" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :buyer_name + end + + it "requires an email" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :email + end + + it "requires an email in a certain format" do + @invaild_payment.email = "tricycle" + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :email + + @invaild_payment.email = "tricycle@" + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :email + + @invaild_payment.email = "tricycle@tricycle" + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :email + + @invaild_payment.email = "tricycle@tricycle." + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :email + end + + it "requires a card_number" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :card_number + end + + it "requires a card_number that is equal to or greater than 4 characters" do + payment_info.card_number = "12" + payment_info.wont_be :valid? + end + + it "requires an expiration" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :expiration + end + + it "requires an mailing_address" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :mailing_address + end + + it "requires an cvv" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :cvv + end + + it "requires an zipcode" do + @invaild_payment.valid?.must_equal false + @invaild_payment.errors.messages.must_include :zipcode + end + end + + describe "#last_four_cc" do + it "can be called" do + payment_info.must_respond_to :last_four_cc + end + + it "returns a string of the last four characters of card_number" do + payment_info.card_number = "12345" + payment_info.last_four_cc.must_equal "2345" + end + end + +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..da89d5b6a6 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,200 @@ +require "test_helper" + +describe Product do + + before do + @p = Product.new + end + + describe "relations" do + it "must respond to merchant" do + @p.must_respond_to :merchant + end + + it "has a merchant" do + prod = products(:tricycle) + merch = merchants(:anders) + + prod.merchant.must_equal merch + prod.merchant_id.must_equal merch.id + end + + it "can have order_products" do + @p.must_respond_to :order_products + + prod = products(:tricycle) + order = orders(:order1) + order_prod = OrderProduct.create!(quantity: 1, product: prod, order: order) + + prod.order_products << order_prod + + prod.order_products.must_include order_prod + # prod = products(:tricycle) + # order_prod = order_products(:one) + # + # prod.order_products.must_equal order_prod + # prod.order_products_ids.must_equal order_prod.id + end + + #TODO: tried to work on this test. not understanding the through relationship well enough. Product doesn't have a direct relationship with Order, so how to connect them in tests? + it "can have orders through order_products" do + @p.must_respond_to :orders + # + # prod = products(:tricycle) + # order = orders(:order2) + # order_prod = OrderProduct.create!(quantity: 1, product: prod, order: order) + # + # prod.order_products.product_id.must_equal order.order_products.product_id + end + + it "can have reviews" do + @p.must_respond_to :reviews + + product = products(:tricycle) + + review = Review.create!(rating: 4, text: "great", product_id: product.id) + product.reviews << review + product.reviews.must_include review + end + + it "has at least one category, and can have multiple" do + @p.must_respond_to :categories + + @p.categories.must_be :empty? + + cat = Category.create!(name: "computers") + @p.categories << cat + @p.categories.must_include cat + + cat2 = Category.create!(name: "three-legged chairs") + @p.categories << cat2 + @p.categories.must_include cat2 + end + + end + + describe 'validations' do + it 'is valid' do + b = Product.new(name: "book", price: 2, merchant_id: Product.first.merchant_id, inventory: Product.first.inventory) + b.category_ids = Category.first.id + b.must_be :valid? + end + + it 'requires a name' do + is_valid = @p.valid? + is_valid.must_equal false + @p.errors.messages.must_include :name + end + + it 'requires a unique name' do + name = "test book" + Product.create!(name: name, price: 1, merchant_id: Product.first.merchant_id, inventory: Product.first.inventory, category_ids: Category.first.id) + b2 = Product.new(name: name, price: 2, merchant_id: Product.first.merchant_id, inventory: Product.first.inventory, category_ids: Category.first.id) + b2.wont_be :valid? + end + + it 'requires a price' do + is_valid = @p.valid? + is_valid.must_equal false + @p.errors.messages.must_include :price + end + + it 'requires a price greater than 0' do + b = Product.new(name: "tom petty video", price: -1) + is_valid = b.valid? + is_valid.must_equal false + b.errors.messages.must_include :price + end + + it "requires inventory that is greater or equal to 0" do + p = Product.new(name: "tom petty video", price: 1) + is_valid = p.valid? + is_valid.must_equal false + p.errors.messages.must_include :inventory + + p2 = Product.new(name: "tom petty video", price: 1, inventory: -1) + is_valid = p2.valid? + is_valid.must_equal false + p2.errors.messages.must_include :inventory + end + + it "requires the presence of a category" do + p = Product.new(name: "tom petty video", price: 1, inventory: 1) + is_valid = p.valid? + is_valid.must_equal false + p.errors.messages.must_include :category_ids + end + end + + #TODO: + describe "increase_inventory" do + + + end + + describe "decrease_inventory" do + let(:tricycle) { products(:tricycle) } + it "decreases the inventory by the given quantity" do + start = tricycle.inventory + + tricycle.decrease_inventory(1) + + tricycle.inventory.must_equal start - 1 + end + end + + describe "check_inventory" do + let(:tripod) { products(:tripod) } + it "returns true when there is inventory, and returns false when there isn't" do + max = tripod.inventory + + tripod.check_inventory(max).must_equal true + + tripod.check_inventory(max - 1).must_equal true + + tripod.check_inventory(max + 1).must_equal false + end + + it "returns false if the inventory is 0" do + tripod.inventory = 0 + + tripod.check_inventory(1).must_equal false + end + #since quantity has been validated to be always more than 0, do I still need to check other edge cases? + + end + + describe "#average_rating" do + it "returns an Integer that is the average of all ratings" do + #arrange + + product = Product.first + + review = Review.create!(rating: 5, product_id: product.id) + review_2 = Review.create!(rating: 3, product_id: product.id) + review_3 = Review.create!(rating: 1, product_id: product.id) + + all_reviews_product_1 = [review, review_2, review_3] + sum_rating = 0 + review_count = 0 + all_reviews_product_1.each do |review| + sum_rating += review.rating + review_count += 1 + end + + ave_rating = sum_rating / review_count + + #act + #assert + product.average_rating.must_equal ave_rating + end + + it "returns 0 if no reviews" do + Review.destroy_all + product = Product.first + + product.average_rating.must_equal 0 + end + end + +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..a924ec318b --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,51 @@ +require "test_helper" + +describe Review do + # let(:review) { Review.new } + # + # it "must be valid" do + # value(review).must_be :valid? + # end + let (:review) {reviews(:review1)} + # before do + # @review = Review.new + # end + + describe "relations" do + it "must respond to product" do + prod = products(:tricycle) + + review.must_respond_to :product + review.product_id.must_equal prod.id + review.product.must_equal prod + end + end + + describe 'validations' do + it 'is valid' do + review = Review.new(rating: 3, product_id: Product.first.id) + review.must_be :valid? + end + + it 'requires a rating' do + review.rating = nil + is_valid = review.valid? + is_valid.must_equal false + review.errors.messages.must_include :rating + end + + it 'requires a ranking greater than 0' do + review = Review.new(rating: 0, product_id: 1) + is_valid = review.valid? + is_valid.must_equal false + review.errors.messages.must_include :rating + end + + it 'requires a ranking less than 5' do + review = Review.new(rating: 6, product_id: 1) + is_valid = review.valid? + is_valid.must_equal false + review.errors.messages.must_include :rating + 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..3bccaa1199 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,50 @@ +require 'simplecov' +# SimpleCov.start 'rails' unless ENV['NO_COVERAGE'] +SimpleCov.start 'rails' +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" # for Colorized output + +# 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(merchant) + return { + provider: merchant.provider, + uid: merchant.uid, + :info.to_s => { + name: merchant.name, + email: merchant.email, + nickname: merchant.username + } + } + end + + def login(merchant) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant)) + get auth_callback_path(:github) + end + +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2