From f02be6473357f4fefdcf304e8dd837a8997bf2ba Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Tue, 17 Oct 2017 14:09:36 -0700 Subject: [PATCH 001/269] create rails project --- .gitignore | 19 + Gemfile | 72 ++ Gemfile.lock | 234 +++++ Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 18 + app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 app/assets/stylesheets/_settings.scss | 863 ++++++++++++++++++ app/assets/stylesheets/application.css | 17 + .../stylesheets/foundation_and_overrides.scss | 53 ++ app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 3 + app/controllers/concerns/.keep | 0 app/helpers/application_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 19 + app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 38 + bin/spring | 17 + bin/update | 29 + bin/yarn | 11 + config.ru | 5 + config/application.rb | 25 + config/boot.rb | 3 + config/cable.yml | 10 + config/database.yml | 85 ++ config/environment.rb | 5 + config/environments/development.rb | 54 ++ config/environments/production.rb | 91 ++ config/environments/test.rb | 42 + .../application_controller_renderer.rb | 8 + config/initializers/assets.rb | 14 + config/initializers/backtrace_silencers.rb | 7 + config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 + config/initializers/mime_types.rb | 4 + config/initializers/wrap_parameters.rb | 14 + config/locales/en.yml | 33 + config/puma.rb | 56 ++ config/routes.rb | 3 + config/secrets.yml | 32 + config/spring.rb | 6 + db/seeds.rb | 7 + lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 package.json | 5 + public/404.html | 67 ++ public/422.html | 67 ++ public/500.html | 66 ++ public/apple-touch-icon-precomposed.png | 0 public/apple-touch-icon.png | 0 public/favicon.ico | 0 public/robots.txt | 1 + test/application_system_test_case.rb | 5 + test/controllers/.keep | 0 test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/system/.keep | 0 test/test_helper.rb | 26 + tmp/.keep | 0 vendor/.keep | 0 77 files changed, 2235 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/stylesheets/_settings.scss create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/assets/stylesheets/foundation_and_overrides.scss create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/helpers/application_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100755 bin/yarn create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/secrets.yml create mode 100644 config/spring.rb create mode 100644 db/seeds.rb create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 package.json create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/apple-touch-icon-precomposed.png create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 test/application_system_test_case.rb create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/system/.keep create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..82701fedc8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# 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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..35b1f4c9c0 --- /dev/null +++ b/Gemfile @@ -0,0 +1,72 @@ +source 'https://rubygems.org' + +git_source(:github) do |repo_name| + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" +end + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.1.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 + +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' +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' +end + +gem 'awesome_print' +gem 'foundation-rails', '6.4.1.2' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..40ed35cd56 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,234 @@ +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) + erubi (1.7.0) + execjs (2.7.0) + 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) + i18n (0.9.0) + concurrent-ruby (~> 1.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-turbolinks (2.1.0) + railties (>= 3.1.0) + turbolinks + 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) + nio4r (2.1.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + 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) + 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) + foundation-rails (= 6.4.1.2) + jbuilder (~> 2.5) + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + pg (~> 0.18) + pry-rails + puma (~> 3.7) + rails (~> 5.1.4) + sass-rails (~> 5.0) + selenium-webdriver + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +BUNDLED WITH + 1.15.4 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..4f2cc0f55a --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,18 @@ +// 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 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/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss new file mode 100644 index 0000000000..b67ff00cdc --- /dev/null +++ b/app/assets/stylesheets/_settings.scss @@ -0,0 +1,863 @@ +// 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..a152282fce --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,17 @@ +/* + * 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 + + */ 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/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..1c07694e9d --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/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/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..cd60004891 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,19 @@ + + + + + + + <%= content_for?(:title) ? yield(:title) : "Untitled" %> + + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + + + <%= 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/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/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..787824f888 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +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/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..1beea2accd --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# 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) 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/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 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/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..10594a3248 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,26 @@ +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... +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 From 752766f839082fd439fb3fb7705d9e04a89c4007 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 15:56:01 -0700 Subject: [PATCH 002/269] Initial commit on anders-merchant branch. Generate Merchants controller --- app/assets/javascripts/merchants.js | 2 ++ app/assets/stylesheets/merchants.scss | 3 +++ app/controllers/merchants_controller.rb | 2 ++ app/helpers/merchants_helper.rb | 2 ++ test/controllers/merchants_controller_test.rb | 7 +++++++ 5 files changed, 16 insertions(+) create mode 100644 app/assets/javascripts/merchants.js create mode 100644 app/assets/stylesheets/merchants.scss create mode 100644 app/controllers/merchants_controller.rb create mode 100644 app/helpers/merchants_helper.rb create mode 100644 test/controllers/merchants_controller_test.rb 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/stylesheets/merchants.scss b/app/assets/stylesheets/merchants.scss new file mode 100644 index 0000000000..f4c164d600 --- /dev/null +++ b/app/assets/stylesheets/merchants.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Merchants controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb new file mode 100644 index 0000000000..ae95f7677b --- /dev/null +++ b/app/controllers/merchants_controller.rb @@ -0,0 +1,2 @@ +class MerchantsController < ApplicationController +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/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb new file mode 100644 index 0000000000..6eb57f7baa --- /dev/null +++ b/test/controllers/merchants_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe MerchantsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From d2dbdc6c98094f9769a3e858fe2fae89e7b33cb6 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 16:00:05 -0700 Subject: [PATCH 003/269] Add basic CRUD routes for Merchants --- config/routes.rb | 1 + test/controllers/merchants_controller_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 787824f888..a68873db16 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + resources :merchants end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 6eb57f7baa..16b643c9ac 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe MerchantsController do - # it "must be a real test" do - # flunk "Need real tests" - # end + describe "index" do + + end end From 7b4471f5903c6b125baa62065a26526c0c854331 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Tue, 17 Oct 2017 16:05:32 -0700 Subject: [PATCH 004/269] create Orders model and controller --- app/assets/javascripts/orders.js | 2 + app/assets/stylesheets/orders.scss | 3 ++ app/controllers/orders_controller.rb | 54 ++++++++++++++++++++++ app/helpers/orders_helper.rb | 2 + app/models/order.rb | 2 + db/migrate/20171017225858_create_orders.rb | 16 +++++++ db/schema.rb | 31 +++++++++++++ test/controllers/orders_controller_test.rb | 7 +++ test/fixtures/orders.yml | 21 +++++++++ test/models/order_test.rb | 9 ++++ 10 files changed, 147 insertions(+) create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/models/order.rb create mode 100644 db/migrate/20171017225858_create_orders.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/orders_controller_test.rb create mode 100644 test/fixtures/orders.yml create mode 100644 test/models/order_test.rb 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/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/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..012dd86d4e --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,54 @@ +class OrdersController < ApplicationController + before_action :find_work_by_params_id, only: [:show, :edit, :update, :destroy] + + def index + @books = Work.sort_by_category("book") + @albums = Work.sort_by_category("album") + @movies = Work.sort_by_category("movie") + end + + def create + @work = Work.new(work_params) + + if save_and_flash(@work) + redirect_to work_path(@work) + else + render :new, status: :bad_request + end + + end + + def new + @work = Work.new + end + + def edit + end + + def show + end + + def update + @work.update_attributes(work_params) + if save_and_flash(@work, edit:"updated") + redirect_to(work_path(@work)) + else + render :edit, status: :bad_request + end + end + + def destroy + save_and_flash(@work, edit: "destroyed", save: @work.destroy) + redirect_to root_path + end + + private + def work_params + return params.require(:work).permit(:category, :title, :creator, :publication_year, :description) + end + + def find_work_by_params_id + @work = Work.find_by(id: params[:id]) + head :not_found unless @work + end +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/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..10281b3450 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,2 @@ +class Order < ApplicationRecord +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/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..f0472bc635 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,31 @@ +# 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: 20171017225858) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "orders", force: :cascade 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.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..68784595f3 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrdersController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..5f8e4e4c7e --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,21 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + status: MyString + email: MyString + mailing_address: MyString + buyer_name: MyString + card_number: MyString + expiration: MyString + cvv: MyString + zipcode: MyString + +two: + status: MyString + email: MyString + mailing_address: MyString + buyer_name: MyString + card_number: MyString + expiration: MyString + cvv: MyString + zipcode: MyString diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..df80f10fb6 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + + it "must be valid" do + value(order).must_be :valid? + end +end From e0115402f46ae69b097b43954db8863c06efd67e Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 16:10:30 -0700 Subject: [PATCH 005/269] Add tests for MerchantsController@index. Generate Merchant Model. Add test data for Merchants --- app/controllers/merchants_controller.rb | 4 +++ app/models/merchant.rb | 2 ++ app/views/merchants/index.html.erb | 1 + db/migrate/20171017230617_create_merchants.rb | 10 ++++++++ db/schema.rb | 25 +++++++++++++++++++ test/controllers/merchants_controller_test.rb | 12 ++++++++- test/fixtures/merchants.yml | 13 ++++++++++ test/models/merchant_test.rb | 9 +++++++ 8 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 app/models/merchant.rb create mode 100644 app/views/merchants/index.html.erb create mode 100644 db/migrate/20171017230617_create_merchants.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/merchants.yml create mode 100644 test/models/merchant_test.rb diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index ae95f7677b..8794500c77 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,2 +1,6 @@ class MerchantsController < ApplicationController + + def index + end + end diff --git a/app/models/merchant.rb b/app/models/merchant.rb new file mode 100644 index 0000000000..0440407160 --- /dev/null +++ b/app/models/merchant.rb @@ -0,0 +1,2 @@ +class Merchant < ApplicationRecord +end diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb new file mode 100644 index 0000000000..8dd90ea430 --- /dev/null +++ b/app/views/merchants/index.html.erb @@ -0,0 +1 @@ +

All Merchants

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/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..49f1ba60c4 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,25 @@ +# 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: 20171017230617) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + 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 + end + +end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 16b643c9ac..4efbc57e4b 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -2,6 +2,16 @@ describe MerchantsController do 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 end diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml new file mode 100644 index 0000000000..09b8d77881 --- /dev/null +++ b/test/fixtures/merchants.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +anders: + username: anders + email: anders@tricycle.com + +lauren: + username: lauren + email: lauren@tricycle.com + +bennett: + username: bennett + email: bennett@tricycle.com diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb new file mode 100644 index 0000000000..1cc99d985f --- /dev/null +++ b/test/models/merchant_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Merchant do + let(:merchant) { Merchant.new } + + it "must be valid" do + value(merchant).must_be :valid? + end +end From eb32d6eebf73e506b718ff06786d2b80ee1d4217 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 16:19:07 -0700 Subject: [PATCH 006/269] Add db seeds. Add link to show page on index page. --- app/controllers/merchants_controller.rb | 4 ++++ app/views/merchants/index.html.erb | 4 ++++ db/seeds.rb | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 8794500c77..2c881f67de 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,6 +1,10 @@ class MerchantsController < ApplicationController def index + @merchants = Merchant.all + end + + def show end end diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb index 8dd90ea430..2d85bfbbbc 100644 --- a/app/views/merchants/index.html.erb +++ b/app/views/merchants/index.html.erb @@ -1 +1,5 @@

All Merchants

+ +<% @merchants.each do |m| %> + <%= link_to m.username, merchant_path(m.id) %> +<% end %> diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2accd..440764dc6d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,9 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) + +Merchant.create(username: "anders", email: "anders@tricycle.com") + +Merchant.create(username: "lauren", email: "lauren@tricycle.com") + +Merchant.create(username: "bennett", email: "bennett@tricycle.com") From 4fd45a822e5a90b33e614ae4afdf4598ca908f53 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 16:34:14 -0700 Subject: [PATCH 007/269] Add MerchantsController#show, corresponding tests, and template. Add private method to find specific merchant by merchant id --- app/controllers/merchants_controller.rb | 14 ++++++++- app/views/merchants/show.html.erb | 6 ++++ test/controllers/merchants_controller_test.rb | 29 ++++++++++++++----- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 app/views/merchants/show.html.erb diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 2c881f67de..be511bde07 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,10 +1,22 @@ class MerchantsController < ApplicationController +before_action :find_id_by_params, except: [:index, :new, :create] + def index @merchants = Merchant.all end def show + @merchant = Merchant.find_by(id: params[:id]) end - + + private + + def find_id_by_params + @merchant = Merchant.find_by(id: params[:id]) + unless @merchant + head :not_found + end + end + end diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb new file mode 100644 index 0000000000..09c74a5cc0 --- /dev/null +++ b/app/views/merchants/show.html.erb @@ -0,0 +1,6 @@ +

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

+ +<%# TODO %> +<%# all money %> +<%# all products sold %> +<%# all customers who have bought products %> diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 4efbc57e4b..f04f825fec 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -3,15 +3,28 @@ describe MerchantsController do 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 + 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 + 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 an extant merchant ID" do + get merchant_path(Merchant.first) + 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 end end From c5bcc885c378582bedae6863e64930b661aef797 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Tue, 17 Oct 2017 16:34:29 -0700 Subject: [PATCH 008/269] create CRUD controller actions and tests and view pages --- app/controllers/orders_controller.rb | 47 +++++--- app/views/orders/edit.html.erb | 0 app/views/orders/index.html.erb | 0 app/views/orders/new.html.erb | 0 app/views/orders/show.html.erb | 0 config/routes.rb | 2 + test/controllers/orders_controller_test.rb | 129 ++++++++++++++++++++- test/fixtures/orders.yml | 36 +++--- 8 files changed, 175 insertions(+), 39 deletions(-) create mode 100644 app/views/orders/edit.html.erb create mode 100644 app/views/orders/index.html.erb create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/show.html.erb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 012dd86d4e..fae03489b2 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,17 +1,15 @@ class OrdersController < ApplicationController - before_action :find_work_by_params_id, only: [:show, :edit, :update, :destroy] + before_action :find_order_by_params_id, only: [:show, :edit, :update, :destroy] def index - @books = Work.sort_by_category("book") - @albums = Work.sort_by_category("album") - @movies = Work.sort_by_category("movie") + @orders = Order.all end def create - @work = Work.new(work_params) + @order = Order.new(order_params) - if save_and_flash(@work) - redirect_to work_path(@work) + if save_and_flash(@order) + redirect_to order_path(@order) else render :new, status: :bad_request end @@ -19,7 +17,7 @@ def create end def new - @work = Work.new + @order = Order.new end def edit @@ -29,26 +27,39 @@ def show end def update - @work.update_attributes(work_params) - if save_and_flash(@work, edit:"updated") - redirect_to(work_path(@work)) + @order.update_attributes(order_params) + if save_and_flash(@order, edit:"updated") + redirect_to(order_path(@order)) else render :edit, status: :bad_request end end def destroy - save_and_flash(@work, edit: "destroyed", save: @work.destroy) - redirect_to root_path + save_and_flash(@order, edit: "destroyed", save: @order.destroy) + redirect_to orders_path end private - def work_params - return params.require(:work).permit(:category, :title, :creator, :publication_year, :description) + def order_params + return params.require(:order).permit(:status, :email, :mailing_address, :buyer_name, :card_number, :expiration, :cvv, :zipcode) end - def find_work_by_params_id - @work = Work.find_by(id: params[:id]) - head :not_found unless @work + def find_order_by_params_id + @order = Order.find_by(id: params[:id]) + head :not_found unless @order + end + + def save_and_flash(model, edit: "created", save: model.save) + result = save + if result + flash[:status] = :success + flash[:message] = "Successfully #{edit} #{model.class} #{model.id}" + else + flash.now[:status] = :failure + flash.now[:message] = "A problem occurred: Could not create #{model.class}" + flash.now[:details] = model.errors.messages + return false + end end end diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/config/routes.rb b/config/routes.rb index 787824f888..3d5d7e388d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + resources :orders end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 68784595f3..3960289514 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -1,7 +1,130 @@ require "test_helper" describe OrdersController do - # it "must be a real test" do - # flunk "Need real tests" - # end + let :order_data { + order_data = { + order: { + status: "pending", + buyer_name: "Zachary" + } + } + } + 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 + + #------- test nested routes + # it "returns a success status when given a valid author id" do + # get author_books_path(Author.first) + # must_respond_with :success + # end + + # opposite: + # get author_books_path(Author.last.id + 1) + # must_respond_with :not_found + end + + describe "new" do + it "returns a success status for new form" do + get new_order_path + must_respond_with :success + end + end + + describe "create" do + it "redirects to order page when the order data is valid" do + + Order.new(order_data[:order]).must_be :valid? + start_order_count = Order.count + post orders_path, params: order_data + must_respond_with :redirect + # must_redirect_to order_path() + + Order.count.must_equal start_order_count + 1 + end + + # it "sends bad_request when the order data is invalid" do + # + # Order.new(invalid_order_data[:order]).wont_be :valid? + # start_order_count = Order.count + # post orders_path, params: invalid_order_data + # must_respond_with :bad_request + # # assert_template :new + # + # Order.count.must_equal start_order_count + # + # end + end + + describe "show" do + it "returns success when given a vaild id" do + get order_path(order_id) + 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 + + end + + describe "edit" do + it "returns success when given a vaild id" do + get edit_order_path(order_id) + must_respond_with :success + end + it "returns not_found when given an invaild id" do + get edit_order_path(order_id + 1) + must_respond_with :not_found + 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 + + it "returns succes if the order exists and the change is valid" do + + orders(:order1).must_be :valid? + put order_path(orders(:order1)), params: order_data + must_respond_with :redirect + must_redirect_to order_path(orders(:order1)) + end + + + # it "returns bad_request if the change is invalid" do + # # don't quite know how to check invalidity here.... + # put order_path(orders(:order1)), params: invalid_order_data + # must_respond_with :bad_request + # 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 orders_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/fixtures/orders.yml b/test/fixtures/orders.yml index 5f8e4e4c7e..239a227f26 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -1,21 +1,21 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - status: MyString - email: MyString - mailing_address: MyString - buyer_name: MyString - card_number: MyString - expiration: MyString - cvv: MyString - zipcode: MyString +order1: + status: "pending" + 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" -two: - status: MyString - email: MyString - mailing_address: MyString - buyer_name: MyString - card_number: MyString - expiration: MyString - cvv: MyString - zipcode: MyString +order2: + status: "pending" + 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" From 242a0c0914d2983e589f5ffba7ba7e9e67b54811 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 17 Oct 2017 16:52:34 -0700 Subject: [PATCH 009/269] CRUD for products --- app/assets/javascripts/products.js | 2 + app/assets/stylesheets/products.scss | 3 + app/controllers/products_controller.rb | 59 ++++++++++++++++++++ app/helpers/products_helper.rb | 2 + app/models/product.rb | 3 + app/views/products/_form.html.erb | 19 +++++++ app/views/products/edit.html.erb | 3 + app/views/products/index.html.erb | 11 ++++ app/views/products/new.html.erb | 3 + app/views/products/show.html.erb | 7 +++ config/routes.rb | 2 + db/migrate/20171017225535_create_products.rb | 15 +++++ db/schema.rb | 29 ++++++++++ test/controllers/products_controller_test.rb | 7 +++ test/fixtures/products.yml | 11 ++++ test/models/product_test.rb | 9 +++ 16 files changed, 185 insertions(+) create mode 100644 app/assets/javascripts/products.js create mode 100644 app/assets/stylesheets/products.scss create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/models/product.rb create mode 100644 app/views/products/_form.html.erb create mode 100644 app/views/products/edit.html.erb create mode 100644 app/views/products/index.html.erb create mode 100644 app/views/products/new.html.erb create mode 100644 app/views/products/show.html.erb create mode 100644 db/migrate/20171017225535_create_products.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/products_controller_test.rb create mode 100644 test/fixtures/products.yml create mode 100644 test/models/product_test.rb 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/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..bff386e55a --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..37cc18766b --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,59 @@ +class ProductsController < ApplicationController + before_action :find_product, only: [:show, :edit, :update, :destroy] + + def index + @products = Product.all + end + + def show ; end + + def new + @product = Product.new + end + + def create + @product = Product.new( + product_params + ) + @product.merchant_id = session[:user_id] + # this could be a hidden field view, or it could be in the strong params, or it could be here + if @product.save + redirect_to products_path + else + render :new + end + end + + def edit ; end + + def update + @product.update_attributes(product_params) + if + redirect_to products_path(@product.id) + else + render :edit + end + end + + def destroy + @product.destroy + flash[:status] = :success + flash[:message] = "Successfully deleted!" + redirect_to products_path + end + + + private + + def product_params + return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url) + end + + def find_product + @product = Product.find_by(id: params[:id]) + unless @product + head :not_found + end + end + +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/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..3b3457c82f --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,3 @@ +class Product < ApplicationRecord + +end diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 0000000000..f89463396a --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,19 @@ + +<%= form_for @product do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :description %> + <%= f.text_area :description %> + + <%= f.label :price %> + <%= f.text_field :price %> + + <%= f.label :inventory %> + <%= f.text_field :inventory %> + + <%= 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..b77612ee9b --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,11 @@ +

Index page for Products! ALL OF the 3's!

+ +<% @products.each do |product| %> +
+ <%= link_to product.name, product_path(product.id) %> + <%= product.price %> + <%= product.description %> +
+<% end %> + +<%= link_to "Add a Product", new_product_path %> diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000000..2de3d736bf --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,3 @@ +

Add a NEW product:

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

Show page for Individual Product!

+<%= @product.name %> +<%= @product.description %> +<% @product.price %> + + +<%= link_to "Back to All Products", products_path %> diff --git a/config/routes.rb b/config/routes.rb index 787824f888..fa5b1ce77d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + resources :products end 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/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..89da75aeb9 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,29 @@ +# 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: 20171017225535) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "products", force: :cascade do |t| + t.string "name" + t.text "description" + t.integer "price" + t.integer "merchant_id" + t.string "inventory" + t.string "photo_url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..392a20e292 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ProductsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,11 @@ +# 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 diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..a618b0a156 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Product do + let(:product) { Product.new } + + it "must be valid" do + value(product).must_be :valid? + end +end From 4c489a66a67e319758784c8e79fe7ff411402a76 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 19:21:46 -0700 Subject: [PATCH 010/269] Add MerchantsController#edit, template, and corresponding tests. Add link_to edit page to show page. --- app/controllers/merchants_controller.rb | 4 +++- app/views/merchants/edit.html.erb | 12 ++++++++++++ app/views/merchants/show.html.erb | 2 ++ test/controllers/merchants_controller_test.rb | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/views/merchants/edit.html.erb diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index be511bde07..3371d4a7ed 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -10,6 +10,9 @@ def show @merchant = Merchant.find_by(id: params[:id]) end + def edit + end + private def find_id_by_params @@ -18,5 +21,4 @@ def find_id_by_params head :not_found end end - end diff --git a/app/views/merchants/edit.html.erb b/app/views/merchants/edit.html.erb new file mode 100644 index 0000000000..3e28040efe --- /dev/null +++ b/app/views/merchants/edit.html.erb @@ -0,0 +1,12 @@ +
+ <%= form_for @merchant do |f| %> + + <%= f.label :username %> + <%= f.text_field :username %> + + <%= f.label :email %> + <%= f.text_field :email %> + + <%= f.submit class: "button" %> + <% end %> +
diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index 09c74a5cc0..5d33572a02 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -1,5 +1,7 @@

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

+<%= link_to "Edit", edit_merchant_path(@merchant.id) %> + <%# TODO %> <%# all money %> <%# all products sold %> diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index f04f825fec..e1c907a9ff 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -27,4 +27,17 @@ must_respond_with :not_found end end + + describe "edit" do + it "succeeds for an extant merchant ID" do + get edit_merchant_path(Merchant.first) + must_respond_with :success + end + + it "renders 404 not_found for an invalid merchant ID" do + invalid_merchant_id = Merchant.last.id + 1 + get edit_merchant_path(invalid_merchant_id) + must_respond_with :not_found + end +end end From 5d39d69e3b8428bd48e2a3a29575cf1564b42d57 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 17 Oct 2017 19:51:05 -0700 Subject: [PATCH 011/269] playing with price --- app/models/product.rb | 5 ++++- app/views/products/index.html.erb | 6 +++--- app/views/products/show.html.erb | 9 +++++---- ...18023503_change_product_price_from_intege_to_float.rb | 6 ++++++ db/schema.rb | 4 ++-- 5 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20171018023503_change_product_price_from_intege_to_float.rb diff --git a/app/models/product.rb b/app/models/product.rb index 3b3457c82f..1161f027c9 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,3 +1,6 @@ class Product < ApplicationRecord - +validates :price, presence: true, numericality:{greater_than: 0} + +validates :name, presence: true, uniqueness: true + end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index b77612ee9b..ace3a2ae1d 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -2,9 +2,9 @@ <% @products.each do |product| %>
- <%= link_to product.name, product_path(product.id) %> - <%= product.price %> - <%= product.description %> +

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

+

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

+

<%= product.description %>

<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 9f4af0ea7f..6693265406 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,7 +1,8 @@

Show page for Individual Product!

-<%= @product.name %> -<%= @product.description %> -<% @product.price %> +

<%= @product.name %>

+

<%= @product.description %>

+

Price: $<%= '%.2f' % @product.price %>

-<%= link_to "Back to All Products", products_path %> +

<%= link_to "Back to All Products", products_path %>

+

<%= link_to "Edit", edit_product_path(@product) %>

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/schema.rb b/db/schema.rb index 89da75aeb9..8dcb44eeaf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171017225535) do +ActiveRecord::Schema.define(version: 20171018023503) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -18,12 +18,12 @@ create_table "products", force: :cascade do |t| t.string "name" t.text "description" - t.integer "price" t.integer "merchant_id" t.string "inventory" t.string "photo_url" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.float "price" end end From 4547e7be4c5f7ee0910d329bc104678638a8b0b3 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 20:10:31 -0700 Subject: [PATCH 012/269] Add MerchantsController#update and corresponding test. Add validation to Merchant model. --- app/controllers/merchants_controller.rb | 24 ++++++++ app/models/merchant.rb | 3 + test/controllers/merchants_controller_test.rb | 56 ++++++++++++++++--- test/models/merchant_test.rb | 6 +- 4 files changed, 79 insertions(+), 10 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 3371d4a7ed..c6be0612cf 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -13,8 +13,32 @@ def show def edit end + def update + # if @merchant.user_id != session[:user_id] + # flash[:status] = :failure + # flash[:result_text] = "Only the merchant has permission to do this" + # redirect_to root_path + # else + @merchant.update_attributes(merchant_params) + if @merchant.save + flash[:status] = :success + flash[:result_text] = "Successfully updated" + redirect_to merchant_path(@merchant) + else + flash.now[:status] = :failure + flash.now[:result_text] = "Could not update" + flash.now[:messages] = @merchant.errors.messages + render :edit, status: :not_found + end + # end + end + private + def merchant_params + params.require(:merchant).permit(:username, :email) + end + def find_id_by_params @merchant = Merchant.find_by(id: params[:id]) unless @merchant diff --git a/app/models/merchant.rb b/app/models/merchant.rb index 0440407160..fa13e329d7 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,2 +1,5 @@ class Merchant < ApplicationRecord + + validates :username, presence: {message: "The username must be present"} + end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index e1c907a9ff..021f4874ff 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -29,15 +29,55 @@ end describe "edit" do - it "succeeds for an extant merchant ID" do - get edit_merchant_path(Merchant.first) - must_respond_with :success + it "succeeds for an extant merchant ID" do + get edit_merchant_path(Merchant.first) + must_respond_with :success + end + + it "renders 404 not_found for an invalid merchant ID" do + invalid_merchant_id = Merchant.last.id + 1 + get edit_merchant_path(invalid_merchant_id) + must_respond_with :not_found + end end - it "renders 404 not_found for an invalid merchant ID" do - invalid_merchant_id = Merchant.last.id + 1 - get edit_merchant_path(invalid_merchant_id) - must_respond_with :not_found + describe "update" do + it "succeeds for valid data and an extant merchant ID" do + merchant = Merchant.first + merchant_data = { + merchant: { + username: merchant.username + "new", + email: merchant.email + } + } + + patch merchant_path(merchant.id), params: merchant_data + must_redirect_to merchant_path(merchant.id) + + # Verify the DB was really modified + Merchant.find(merchant.id).username.must_equal merchant_data[:merchant][:username] + end + + it "renders bad_request for invalid data" do + merchant = Merchant.first + merchant_data = { + merchant: { + username: "", + email: merchant.email + } + } + + patch merchant_path(merchant), params: merchant_data + must_respond_with :not_found + + # Verify the DB was not modified + Merchant.find(merchant.id).username.must_equal merchant.username + 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 end end -end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index 1cc99d985f..3c99f5ca70 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -1,9 +1,11 @@ require "test_helper" describe Merchant do - let(:merchant) { Merchant.new } + before do + @valid_test_m = Merchant.new(username: "tricycle", email: "tricycle@tricycle.com" ) + end it "must be valid" do - value(merchant).must_be :valid? + @valid_test_m.must_be :valid? end end From 20d5436c8ba0f4c26742b1b4fd50f8ee83657caf Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 20:24:45 -0700 Subject: [PATCH 013/269] Add MerchantsController#destroy and corresponding tests. Add links to show page. --- app/controllers/merchants_controller.rb | 16 ++++++++++++-- app/views/merchants/show.html.erb | 4 +++- test/controllers/merchants_controller_test.rb | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index c6be0612cf..5ea492106a 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -30,8 +30,20 @@ def update flash.now[:messages] = @merchant.errors.messages render :edit, status: :not_found end - # end - end + end + + def destroy + # if @merchant.user_id != session[:user_id] + # flash[:status] = :failure + # flash[:result_text] = "Only the merchant has permission to delete" + # redirect_to root_path + # else + @merchant.destroy + flash[:status] = :success + flash[:result_text] = "Successfully deleted" + # redirect_to root_path + redirect_to merchants_path + end private diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index 5d33572a02..34ff806ea6 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -1,6 +1,8 @@

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

-<%= link_to "Edit", edit_merchant_path(@merchant.id) %> +<%= link_to "Back to Merchants List", merchants_path, class: "button" %> +<%= link_to "Edit", edit_merchant_path(@merchant.id), class: "button" %> +<%= link_to "Delete", merchant_path(@merchant.id), method: :delete, data: { confirm: "Are you sure?" }, class: "alert button" %> <%# TODO %> <%# all money %> diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 021f4874ff..5283d07545 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -80,4 +80,26 @@ must_respond_with :not_found end end + + describe "destroy" do + it "succeeds for an extant work ID" do + merchant_id = Merchant.first.id + + 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 + end end From 0ad22b34fb29e0f218de948a36f077c37f9009b2 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 17 Oct 2017 20:32:01 -0700 Subject: [PATCH 014/269] tests test tests for product controller and model --- app/controllers/products_controller.rb | 17 ++- app/views/products/index.html.erb | 3 +- app/views/products/show.html.erb | 5 +- test/controllers/products_controller_test.rb | 147 +++++++++++++++++++ test/fixtures/products.yml | 17 ++- test/models/product_test.rb | 46 +++++- 6 files changed, 220 insertions(+), 15 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 37cc18766b..2a5563ac58 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -8,6 +8,7 @@ def index def show ; end def new + # if @product.merchant_id != session[:merchant_id] @product = Product.new end @@ -15,12 +16,13 @@ def create @product = Product.new( product_params ) - @product.merchant_id = session[:user_id] # this could be a hidden field view, or it could be in the strong params, or it could be here + @product.merchant_id = session[:merchant_id] + if @product.save redirect_to products_path else - render :new + render :new, status: :bad_request end end @@ -28,14 +30,18 @@ def edit ; end def update @product.update_attributes(product_params) - if - redirect_to products_path(@product.id) + if @product.save + #change once add flash and save + redirect_to product_path(@product) + return else - render :edit + render :edit, status: :bad_request + return end end def destroy + # if @product.merchant_id != session[:merchant_id] @product.destroy flash[:status] = :success flash[:message] = "Successfully deleted!" @@ -46,6 +52,7 @@ def destroy private def product_params + # should merchant_id be here? return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url) end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index ace3a2ae1d..b98643cc40 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,5 +1,6 @@

Index page for Products! ALL OF the 3's!

+

Categories:

<% @products.each do |product| %>

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

@@ -8,4 +9,4 @@
<% end %> -<%= link_to "Add a Product", new_product_path %> +<%= link_to "Add a Product", new_product_path, class: "button" %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 6693265406..d8108a4631 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -4,5 +4,6 @@

Price: $<%= '%.2f' % @product.price %>

-

<%= link_to "Back to All Products", products_path %>

-

<%= link_to "Edit", edit_product_path(@product) %>

+

<%= link_to "Back to All Products", products_path, class: "button" %>

+

<%= link_to "Edit", edit_product_path(@product), class: "button" %>

+

<%= link_to "Delete", product_path(@product), class: "alert button", method: "delete", data: { confirm: "Are you sure?" } %>

diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 392a20e292..4e44d6ff8e 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -4,4 +4,151 @@ # it "must be a real test" do # flunk "Need real tests" # 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 + # need to write test for when new is not allowed (not merchant_id) + end + + describe "create" do + it "saves and redirects to products_path when the product data is valid" do + product_data = { + product: { + name: "book", + price: 1, + } + } + Product.new(product_data[: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.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 + # need to write test for when create is not allowed (not merchant_id) + 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 + # need to write test for when edit is not allowed (not merchant_id) + end + + describe "update" do + it "returns success when change is valid" do + product = Product.first + product_data = { + product: { + name: "book", + price: 4.32 + } + } + 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 + + # need to write test for when update is not allowed (not merchant_id) + end + + describe "destroy" do + it "success when product is deleted" do + product_count = Product.count + delete product_path(Product.first) + must_respond_with :redirect + must_redirect_to products_path + product_count.must_equal Product.count + 1 + end + + # need to write test for when destroy is not allowed (not merchant_id) + end end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index dc3ee79b5d..a7b83f7cc9 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -4,8 +4,17 @@ # 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: {} +# one: {} +# # column: value +# # +# two: {} # column: value + + +tricycle: + name: tricycle + description: "A fun toy!" + merchant_id: 1 + inventory: 2 + photo_url: www.fillmurray.com + price: 2.40 diff --git a/test/models/product_test.rb b/test/models/product_test.rb index a618b0a156..1676e3deb9 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,9 +1,49 @@ require "test_helper" describe Product do - let(:product) { Product.new } + # let(:product) { Product.new } + # + # it "must be valid" do + # value(product).must_be :valid? + + describe 'validations' do + it 'is valid' do + b = Product.new(name: "book", price: 2) + b.must_be :valid? + end + + it 'requires a name' do + b = Product.new + is_valid = b.valid? + is_valid.must_equal false + b.errors.messages.must_include :name + end + + it 'requires a unique name' do + name = "test book" + b1 = Product.create!(name: name, price: 1) + b2 = Product.new(name: name, price: 2) + b2.wont_be :valid? + end + + it 'requires a price' do + b = Product.new + is_valid = b.valid? + is_valid.must_equal false + b.errors.messages.must_include :price + end + + it 'requires a price greater than 0' do + b = Product.new(name: name, price: -1) + is_valid = b.valid? + is_valid.must_equal false + b.errors.messages.must_include :price + end - it "must be valid" do - value(product).must_be :valid? end + + describe "relations" do + + end + end From e912b8ed6af6e88a89ca449097066ab7bdd71f7f Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 20:36:39 -0700 Subject: [PATCH 015/269] Add validations to Merchant model and corresponding tests --- app/models/merchant.rb | 5 ++++- test/models/merchant_test.rb | 37 ++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/models/merchant.rb b/app/models/merchant.rb index fa13e329d7..428e0aac8b 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,5 +1,8 @@ class Merchant < ApplicationRecord - validates :username, presence: {message: "The username must be present"} + validates :username, presence: {message: "Please enter a username"} + validates :email, presence: {message: "Please enter an email"} + + validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/, message: "Please enter your email in this format: example@example.com" end diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index 3c99f5ca70..7439643478 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -5,7 +5,40 @@ @valid_test_m = Merchant.new(username: "tricycle", email: "tricycle@tricycle.com" ) end - it "must be valid" do - @valid_test_m.must_be :valid? + 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 an email" do + merchant = Merchant.new(username: "username", email: "") + merchant.valid?.must_equal false + merchant.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@") + merchant.valid?.must_equal false + merchant.errors.messages.must_include :email + + merchant2 = Merchant.new(username: "username", email: "tricycle@tricycle") + merchant.valid?.must_equal false + merchant.errors.messages.must_include :email + + merchant2 = Merchant.new(username: "username", email: "tricycle@tricycle.") + merchant.valid?.must_equal false + merchant.errors.messages.must_include :email + + end end end From d885004c0e6a5b7a3a18b8b05072b0a53bb8ae61 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Tue, 17 Oct 2017 20:57:19 -0700 Subject: [PATCH 016/269] Add MerchantsController#new and MerchantsController#create, and corresponding tests. Add form partial to DRY up edit and new templates. --- app/controllers/merchants_controller.rb | 20 +++++ app/models/merchant.rb | 1 + app/views/merchants/_form.html.erb | 12 +++ app/views/merchants/edit.html.erb | 13 +--- app/views/merchants/index.html.erb | 10 ++- app/views/merchants/new.html.erb | 1 + test/controllers/merchants_controller_test.rb | 78 +++++++++++++++++++ test/models/merchant_test.rb | 9 +-- 8 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 app/views/merchants/_form.html.erb create mode 100644 app/views/merchants/new.html.erb diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 5ea492106a..57eb4a90fb 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -6,6 +6,26 @@ def index @merchants = Merchant.all end + def new + @merchant = Merchant.new + end + + def create + @merchant = Merchant.new(merchant_params) + # @merchant.user_id = session[:user_id] + if @merchant.save + # @merchant = session[:user_id] + flash[:status] = :success + flash[:result_text] = "Successfully created: #{@merchant.username}" + redirect_to merchant_path(@merchant.id) + else + flash[:status] = :failure + flash[:result_text] = "Could not create new merchant" + flash[:messages] = @merchant.errors.messages + render :new, status: :bad_request + end + end + def show @merchant = Merchant.find_by(id: params[:id]) end diff --git a/app/models/merchant.rb b/app/models/merchant.rb index 428e0aac8b..e702f92692 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -5,4 +5,5 @@ class Merchant < ApplicationRecord validates :email, presence: {message: "Please enter an email"} validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/, message: "Please enter your email in this format: example@example.com" + #https://stackoverflow.com/questions/4776907/what-is-the-best-easy-way-to-validate-an-email-address-in-ruby end diff --git a/app/views/merchants/_form.html.erb b/app/views/merchants/_form.html.erb new file mode 100644 index 0000000000..3e28040efe --- /dev/null +++ b/app/views/merchants/_form.html.erb @@ -0,0 +1,12 @@ +
+ <%= form_for @merchant do |f| %> + + <%= f.label :username %> + <%= f.text_field :username %> + + <%= f.label :email %> + <%= f.text_field :email %> + + <%= f.submit class: "button" %> + <% end %> +
diff --git a/app/views/merchants/edit.html.erb b/app/views/merchants/edit.html.erb index 3e28040efe..d44c608b6a 100644 --- a/app/views/merchants/edit.html.erb +++ b/app/views/merchants/edit.html.erb @@ -1,12 +1 @@ -
- <%= form_for @merchant do |f| %> - - <%= f.label :username %> - <%= f.text_field :username %> - - <%= f.label :email %> - <%= f.text_field :email %> - - <%= f.submit class: "button" %> - <% end %> -
+<%= render partial: "form" %> diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb index 2d85bfbbbc..f8d6c0fc21 100644 --- a/app/views/merchants/index.html.erb +++ b/app/views/merchants/index.html.erb @@ -1,5 +1,9 @@

All Merchants

-<% @merchants.each do |m| %> - <%= link_to m.username, merchant_path(m.id) %> -<% end %> +<%= link_to "Become a Merchant", new_merchant_path, class: "button" %> + +
+ <% @merchants.each do |m| %> + <%= link_to m.username, merchant_path(m.id) %> + <% end %> +
diff --git a/app/views/merchants/new.html.erb b/app/views/merchants/new.html.erb new file mode 100644 index 0000000000..d44c608b6a --- /dev/null +++ b/app/views/merchants/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 5283d07545..13ec19cccf 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -15,6 +15,84 @@ end end + describe "new" do + it "works" do + get new_merchant_path + must_respond_with :success + end + end + + describe "create" do + it "creates a merchant with valid data" do + merchant_data = { + merchant: { + username: "test test", + email: "test@test.com" + } + } + + start_count = Merchant.count + + post merchants_path, params: merchant_data + must_redirect_to merchant_path(Merchant.last) + + Merchant.count.must_equal start_count + 1 + end + + it "renders bad_request and does not update the DB for invalid merchant data" do + invalid_merchant_data = { + merchant: { + username: "", + email: "" + } + } + + start_count = Merchant.count + + post merchants_path, params: invalid_merchant_data + must_respond_with :bad_request + + Merchant.count.must_equal start_count + end + + + it "renders 400 bad_request for invalid email entries" do + invalid_email = { + merchant: { + username: "namename", + email: "name" + } + } + + invalid_email_2 = { + merchant: { + username: "namename", + email: "name@" + } + } + + invalid_email_3 = { + merchant: { + username: "namename", + email: "name@name." + } + } + + start_count = Merchant.count + + post merchants_path, params: invalid_email + must_respond_with :bad_request + + post merchants_path, params: invalid_email_2 + must_respond_with :bad_request + + post merchants_path, params: invalid_email_3 + must_respond_with :bad_request + + Merchant.count.must_equal start_count + end + end + describe "show" do it "succeeds for an extant merchant ID" do get merchant_path(Merchant.first) diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index 7439643478..4e69dcacd0 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -28,17 +28,16 @@ merchant.errors.messages.must_include :email merchant1 = Merchant.new(username: "username", email: "tricycle@") - merchant.valid?.must_equal false + merchant1.valid?.must_equal false merchant.errors.messages.must_include :email merchant2 = Merchant.new(username: "username", email: "tricycle@tricycle") - merchant.valid?.must_equal false + merchant2.valid?.must_equal false merchant.errors.messages.must_include :email - merchant2 = Merchant.new(username: "username", email: "tricycle@tricycle.") - merchant.valid?.must_equal false + merchant3 = Merchant.new(username: "username", email: "tricycle@tricycle.") + merchant3.valid?.must_equal false merchant.errors.messages.must_include :email - end end end From 0f31fb541ee930d4ece55170ccc81783cd72c459 Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 18 Oct 2017 10:53:59 -0700 Subject: [PATCH 017/269] playing with form for new/edit --- app/models/product.rb | 1 + app/views/products/_form.html.erb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/models/product.rb b/app/models/product.rb index 1161f027c9..b2c0e8a5c6 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,4 +1,5 @@ class Product < ApplicationRecord + validates :price, presence: true, numericality:{greater_than: 0} validates :name, presence: true, uniqueness: true diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index f89463396a..88ae48a6ee 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -3,6 +3,8 @@ <%= f.label :name %> <%= f.text_field :name %> + + <%= f.label :description %> <%= f.text_area :description %> From c6cb8ac561e92834efb2f36460352c292d0be5c6 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 10:55:21 -0700 Subject: [PATCH 018/269] play with views for order --- app/views/layouts/application.html.erb | 2 +- app/views/orders/edit.html.erb | 44 ++++++++++++++++++++++++++ app/views/orders/index.html.erb | 20 ++++++++++++ app/views/orders/new.html.erb | 4 +++ app/views/orders/show.html.erb | 14 ++++++++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cd60004891..a039136e1b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,7 +4,7 @@ - <%= content_for?(:title) ? yield(:title) : "Untitled" %> + <%= content_for?(:title) ? yield(:title) : "3Bae" %> <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb index e69de29bb2..45097d7a04 100644 --- a/app/views/orders/edit.html.erb +++ b/app/views/orders/edit.html.erb @@ -0,0 +1,44 @@ +

Enter Billing Information

+ +
    + <%= form_for @order do |f| %> +
  • + <%= f.label :email%> + <%= f.text_field :email%> +
  • + +
  • + <%= f.label :buyer_name %> + <%= f.text_field :buyer_name %> +
  • + +
  • + <%= f.label :mailing_address %> + <%= f.text_field :mailing_address %> +
  • + +
  • + <%= f.label :card_number %> + <%= f.text_field :card_number %> +
  • + +
  • + <%= f.label :expiration %> + <%= f.text_field :expiration %> +
  • + +
  • + <%= f.label :cvv %> + <%= f.text_field :cvv %> +
  • + +
  • + <%= f.label :zipcode %> + <%= f.text_field :zipcode %> +
  • + +
  • + <%= f.submit "Buy", class:'button' %> +
  • + <% end %> +
diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb index e69de29bb2..ae40117161 100644 --- a/app/views/orders/index.html.erb +++ b/app/views/orders/index.html.erb @@ -0,0 +1,20 @@ +<%= link_to 'New Order', new_order_path, class:'button' %> + +

All Orders

+
    + <% @orders.each do |order| %> +
  • +

    + Order <%= order.id %> +

    +

    + Status: <%= order.status %> +

    + + <%= link_to 'Edit', edit_order_path(order), class:'button' %> + + <%= link_to 'Delete', order_path(order), method: :delete, data: { confirm: "Are you sure?" }, class:'alert button' %> + +
  • + <% end %> +
diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb index e69de29bb2..6f4e3b3ceb 100644 --- a/app/views/orders/new.html.erb +++ 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/show.html.erb b/app/views/orders/show.html.erb index e69de29bb2..f8bc7dabdc 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -0,0 +1,14 @@ +

Your Cart

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

+ Order <%= @order.id %> +

+

+ Status: <%= @order.status %> +

+ + +<%= link_to "Back to All Orders", orders_path, class:'button'%> From d1b1ac24182fae4ad274f2a39e7c8e75c7756774 Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 18 Oct 2017 12:26:41 -0700 Subject: [PATCH 019/269] review controller and model --- app/assets/javascripts/reviews.js | 2 ++ app/assets/stylesheets/reviews.scss | 3 +++ app/controllers/reviews_controller.rb | 21 +++++++++++++++++++++ app/helpers/reviews_helper.rb | 2 ++ app/models/product.rb | 1 + app/models/review.rb | 5 +++++ app/views/products/index.html.erb | 5 +++-- app/views/products/show.html.erb | 7 +++++-- app/views/reviews/new.html.erb | 13 +++++++++++++ config/routes.rb | 2 ++ db/migrate/20171018185635_create_reviews.rb | 11 +++++++++++ db/schema.rb | 10 +++++++++- test/controllers/reviews_controller_test.rb | 7 +++++++ test/fixtures/reviews.yml | 11 +++++++++++ test/models/review_test.rb | 9 +++++++++ 15 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/reviews.js create mode 100644 app/assets/stylesheets/reviews.scss create mode 100644 app/controllers/reviews_controller.rb create mode 100644 app/helpers/reviews_helper.rb create mode 100644 app/models/review.rb create mode 100644 app/views/reviews/new.html.erb create mode 100644 db/migrate/20171018185635_create_reviews.rb create mode 100644 test/controllers/reviews_controller_test.rb create mode 100644 test/fixtures/reviews.yml create mode 100644 test/models/review_test.rb 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/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/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..6b96f85093 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,21 @@ +class ReviewsController < ApplicationController + def new + @review = Review.new + end + def create + @review = Review.new( + review_params + ) + + if @review.save + redirect_to products_path + else + render :new, status: :bad_request + end + end +end + +private +def review_params + return params.require(:review).permit(:rating, :text, :product_id) +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/models/product.rb b/app/models/product.rb index b2c0e8a5c6..959f6084a2 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,4 +1,5 @@ class Product < ApplicationRecord +has_many :reviews validates :price, presence: true, numericality:{greater_than: 0} diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..1db03c3eee --- /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/products/index.html.erb b/app/views/products/index.html.erb index b98643cc40..efbf4f578a 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -3,9 +3,10 @@

Categories:

<% @products.each do |product| %>
-

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

+

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

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

-

<%= product.description %>

+

Description: <%= product.description %>

+
<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index d8108a4631..35296451e6 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,9 +1,12 @@

Show page for Individual Product!

-

<%= @product.name %>

-

<%= @product.description %>

+

Name: <%= @product.name %>

+

Description: <%= @product.description %>

Price: $<%= '%.2f' % @product.price %>

+

Reviews: <%= @product.reviews %>

+

<%= link_to "Back to All Products", products_path, class: "button" %>

+

<%= link_to "Write a Review", new_review_path, class: "button" %>

<%= link_to "Edit", edit_product_path(@product), class: "button" %>

<%= 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..11c4e0fae1 --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,13 @@ +

Write a new Review:

+<%= form_for @review do |f| %> + +<%= f.label :rating, "Rating 1-5" %> +<%= f.number_field :rating %> + +<%= f.label :text, "Write a review!" %> +<%= f.text_area :text %> + +<%= f.hidden_field :product_id, :value => @product.id %> + + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index eb2422f0b4..bc7339bb43 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,4 +4,6 @@ resources :orders resources :products resources :merchants + resources :reviews, only: [:new, :create] + # nested route /product/:id/review 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/schema.rb b/db/schema.rb index 40b4d1b790..c273e48c88 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171018023503) do +ActiveRecord::Schema.define(version: 20171018185635) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -46,4 +46,12 @@ t.float "price" 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/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..386065239a --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ReviewsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,11 @@ +# 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 diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..ce8378a033 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Review do + let(:review) { Review.new } + + it "must be valid" do + value(review).must_be :valid? + end +end From 8caf1963b7601da581ab450d80aa259371d30642 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Wed, 18 Oct 2017 15:03:17 -0700 Subject: [PATCH 020/269] Add relationship between Merchant and Product, tests passing. Commented out one test for #update of Products, for now --- app/controllers/products_controller.rb | 2 +- app/models/merchant.rb | 2 ++ app/models/product.rb | 6 ++-- test/controllers/products_controller_test.rb | 38 ++++++++++---------- test/fixtures/products.yml | 4 +-- test/models/merchant_test.rb | 7 ++++ test/models/product_test.rb | 35 +++++++++--------- 7 files changed, 52 insertions(+), 42 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 2a5563ac58..583468b9e9 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -17,7 +17,7 @@ def create product_params ) # this could be a hidden field view, or it could be in the strong params, or it could be here - @product.merchant_id = session[:merchant_id] + # @product.merchant_id = session[:merchant_id] if @product.save redirect_to products_path diff --git a/app/models/merchant.rb b/app/models/merchant.rb index e702f92692..19eb23e28d 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -1,5 +1,7 @@ class Merchant < ApplicationRecord + has_many :products + validates :username, presence: {message: "Please enter a username"} validates :email, presence: {message: "Please enter an email"} diff --git a/app/models/product.rb b/app/models/product.rb index b2c0e8a5c6..d886c6eda5 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,7 +1,9 @@ class Product < ApplicationRecord -validates :price, presence: true, numericality:{greater_than: 0} + belongs_to :merchant -validates :name, presence: true, uniqueness: true + validates :price, presence: true, numericality:{greater_than: 0} + + validates :name, presence: true, uniqueness: true end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 4e44d6ff8e..dbbe1cc7ff 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -1,9 +1,6 @@ require "test_helper" describe ProductsController do - # it "must be a real test" do - # flunk "Need real tests" - # end describe "index" do it "shows all products" do @@ -42,21 +39,23 @@ end describe "create" do - it "saves and redirects to products_path when the product data is valid" do - product_data = { - product: { - name: "book", - price: 1, - } - } - Product.new(product_data[: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.count.must_equal start_product_count + 1 - end + # it "saves and redirects to products_path when the product data is valid" do + # product_data = { + # product: { + # name: "book", + # price: 1, + # merchant: merchants(:anders) + # } + # } + # + # Product.new(product_data[: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.count.must_equal start_product_count + 1 + # end it "renders a bad_request when the product data is invalid" do bad_product = { @@ -96,7 +95,8 @@ product_data = { product: { name: "book", - price: 4.32 + price: 4.32, + merchant: merchants(:anders) } } product.update_attributes(product_data[:product]) diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index a7b83f7cc9..e6a8b1493e 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -14,7 +14,7 @@ tricycle: name: tricycle description: "A fun toy!" - merchant_id: 1 + merchant: anders inventory: 2 photo_url: www.fillmurray.com - price: 2.40 + price: 2.40 diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index 4e69dcacd0..9be0c1181a 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -2,9 +2,16 @@ 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 + end + describe "validations" do it "is valid when given valid merchant data" do @valid_test_m.must_be :valid? diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 1676e3deb9..a961cc5241 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,36 +1,40 @@ require "test_helper" describe Product do - # let(:product) { Product.new } - # - # it "must be valid" do - # value(product).must_be :valid? + + before do + @p = Product.new + end + + describe "relations" do + it "must respond to merchant" do + @p.must_respond_to :merchant + end + end describe 'validations' do it 'is valid' do - b = Product.new(name: "book", price: 2) + b = Product.new(name: "book", price: 2, merchant_id: Product.first.merchant_id) b.must_be :valid? end it 'requires a name' do - b = Product.new - is_valid = b.valid? + is_valid = @p.valid? is_valid.must_equal false - b.errors.messages.must_include :name + @p.errors.messages.must_include :name end it 'requires a unique name' do name = "test book" - b1 = Product.create!(name: name, price: 1) - b2 = Product.new(name: name, price: 2) + b1 = Product.create!(name: name, price: 1, merchant_id: Product.first.merchant_id) + b2 = Product.new(name: name, price: 2, merchant_id: Product.first.merchant_id) b2.wont_be :valid? end it 'requires a price' do - b = Product.new - is_valid = b.valid? + is_valid = @p.valid? is_valid.must_equal false - b.errors.messages.must_include :price + @p.errors.messages.must_include :price end it 'requires a price greater than 0' do @@ -39,11 +43,6 @@ is_valid.must_equal false b.errors.messages.must_include :price end - - end - - describe "relations" do - end end From 11b4e4438b038ed0c7db8c80752645005cc3bc38 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 15:18:18 -0700 Subject: [PATCH 021/269] create order_products model and controller --- app/assets/javascripts/order_products.js | 2 ++ app/assets/stylesheets/order_products.scss | 3 +++ app/controllers/order_products_controller.rb | 11 +++++++++++ app/helpers/order_products_helper.rb | 2 ++ app/models/order.rb | 1 + app/models/order_product.rb | 4 ++++ app/models/product.rb | 5 +++-- app/views/orders/show.html.erb | 10 +++++++--- app/views/products/show.html.erb | 2 ++ config/routes.rb | 1 + .../20171018192530_create_order_products.rb | 11 +++++++++++ db/schema.rb | 18 +++++++++++++++++- .../order_products_controller_test.rb | 7 +++++++ test/fixtures/order_products.yml | 11 +++++++++++ test/models/order_product_test.rb | 9 +++++++++ 15 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 app/assets/javascripts/order_products.js create mode 100644 app/assets/stylesheets/order_products.scss create mode 100644 app/controllers/order_products_controller.rb create mode 100644 app/helpers/order_products_helper.rb create mode 100644 app/models/order_product.rb create mode 100644 db/migrate/20171018192530_create_order_products.rb create mode 100644 test/controllers/order_products_controller_test.rb create mode 100644 test/fixtures/order_products.yml create mode 100644 test/models/order_product_test.rb 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/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/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb new file mode 100644 index 0000000000..a059c7b015 --- /dev/null +++ b/app/controllers/order_products_controller.rb @@ -0,0 +1,11 @@ +class OrderProductsController < ApplicationController + def create + order = Order.create(status:"this is a test") + @order_product = OrderProduct.new(product_id: params[:product_id], order_id: order.id) + + @order_product.save + + redirect_to order_path(order) + end + +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/models/order.rb b/app/models/order.rb index 10281b3450..732f18c63e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,3 @@ class Order < ApplicationRecord + has_many :order_products end diff --git a/app/models/order_product.rb b/app/models/order_product.rb new file mode 100644 index 0000000000..85b356ece1 --- /dev/null +++ b/app/models/order_product.rb @@ -0,0 +1,4 @@ +class OrderProduct < ApplicationRecord + belongs_to :order + belongs_to :product +end diff --git a/app/models/product.rb b/app/models/product.rb index b2c0e8a5c6..3a2c64324b 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,7 +1,8 @@ class Product < ApplicationRecord + has_many :order_products -validates :price, presence: true, numericality:{greater_than: 0} + validates :price, presence: true, numericality:{greater_than: 0} -validates :name, presence: true, uniqueness: true + validates :name, presence: true, uniqueness: true end diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index f8bc7dabdc..b76ae3d31b 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,8 +1,12 @@

Your Cart

-<%# @order.products.each do |product| %> - -<%# end %> +
    + <% @order.order_products.each do |order_product| %> +
  • + <%= order_product.product.name %> +
  • + <% end %> +

Order <%= @order.id %>

diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index d8108a4631..a270e11dcf 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -3,6 +3,8 @@

<%= @product.description %>

Price: $<%= '%.2f' % @product.price %>

+

<%= link_to "Add to Order", create_order_product_path(product_id: @product.id), method:'post', class: "button" %>

+

<%= link_to "Back to All Products", products_path, class: "button" %>

<%= link_to "Edit", edit_product_path(@product), class: "button" %>

diff --git a/config/routes.rb b/config/routes.rb index eb2422f0b4..43d8edde8d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,4 +4,5 @@ resources :orders resources :products resources :merchants + post '/order_products', to: 'order_products#create', as: 'create_order_product' 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/schema.rb b/db/schema.rb index 40b4d1b790..5772ec98c8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171018023503) do +ActiveRecord::Schema.define(version: 20171018192530) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -22,6 +22,22 @@ t.datetime "updated_at", null: false end + create_table "order_items", 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 + 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 + end + create_table "orders", force: :cascade do |t| t.string "status" t.string "email" diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb new file mode 100644 index 0000000000..868bc2929c --- /dev/null +++ b/test/controllers/order_products_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrderProductsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/order_products.yml b/test/fixtures/order_products.yml new file mode 100644 index 0000000000..1cb6079d5a --- /dev/null +++ b/test/fixtures/order_products.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + quantity: 1 + product_id: 1 + order_id: 1 + +two: + quantity: 1 + product_id: 1 + order_id: 1 diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb new file mode 100644 index 0000000000..47c6ee2a98 --- /dev/null +++ b/test/models/order_product_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderProduct do + let(:order_product) { OrderProduct.new } + + it "must be valid" do + value(order_product).must_be :valid? + end +end From 5dbdbccb38ca41647271076d1081a299374dcf14 Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 18 Oct 2017 15:33:49 -0700 Subject: [PATCH 022/269] reviews --- app/controllers/reviews_controller.rb | 10 ++++++++-- app/views/products/show.html.erb | 7 +++++-- app/views/reviews/new.html.erb | 2 +- config/routes.rb | 8 +++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 6b96f85093..31d0745683 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -1,18 +1,24 @@ class ReviewsController < ApplicationController def new @review = Review.new + @product = Product.find_by(id: params[:product_id]) end + def create + @product = Product.find_by(id: params[:product_id]) @review = Review.new( review_params ) - if @review.save - redirect_to products_path + redirect_to product_path(@product) else render :new, status: :bad_request end end + + def show + @review = Review.find_by[id: params[:id]] + end end private diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 35296451e6..bb52f32d5a 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -3,10 +3,13 @@

Description: <%= @product.description %>

Price: $<%= '%.2f' % @product.price %>

-

Reviews: <%= @product.reviews %>

+

Reviews: <% @product.reviews.each do |review| %>

+<%= review.text %> +<%= review.rating %> +<% end %>

<%= link_to "Back to All Products", products_path, class: "button" %>

-

<%= link_to "Write a Review", new_review_path, class: "button" %>

+

<%= link_to "Write a Review", new_product_review_path(@product), class: "button" %>

<%= link_to "Edit", edit_product_path(@product), class: "button" %>

<%= 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 index 11c4e0fae1..3c3c9ebb9f 100644 --- a/app/views/reviews/new.html.erb +++ b/app/views/reviews/new.html.erb @@ -1,5 +1,5 @@

Write a new Review:

-<%= form_for @review do |f| %> +<%= form_for [@product, @review] do |f| %> <%= f.label :rating, "Rating 1-5" %> <%= f.number_field :rating %> diff --git a/config/routes.rb b/config/routes.rb index bc7339bb43..7428c19ea2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,8 +2,10 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :orders - resources :products + resources :products do + resources :reviews, only: [:new, :create, :show] + end resources :merchants - resources :reviews, only: [:new, :create] - # nested route /product/:id/review + + end From 49175ce9a04bf0e89e305e0adbdc6caea6d513a5 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 15:36:49 -0700 Subject: [PATCH 023/269] start and fail with tests --- app/controllers/order_products_controller.rb | 3 +- .../order_products_controller_test.rb | 72 ++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index a059c7b015..8c774a2514 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -5,7 +5,8 @@ def create @order_product.save - redirect_to order_path(order) + # redirect_to order_path(order) + redirect_to orders_path end end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index 868bc2929c..52790413ff 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -1,7 +1,73 @@ require "test_helper" describe OrderProductsController do - # it "must be a real test" do - # flunk "Need real tests" - # end + describe "create" do + it "creates an OrderProduct with a product and an order" do + product_params = { + params: { + product_id: products(:tricycle) + } + } + + start_count = OrderProduct.count + + post create_order_product_path, params: product_params + must_redirect_to orders_path + + OrderProduct.count.must_equal start_count + 1 + end + + # it "renders bad_request and does not update the DB for invalid merchant data" do + # invalid_merchant_data = { + # merchant: { + # username: "", + # email: "" + # } + # } + # + # start_count = Merchant.count + # + # post merchants_path, params: invalid_merchant_data + # must_respond_with :bad_request + # + # Merchant.count.must_equal start_count + # end + # + # + # it "renders 400 bad_request for invalid email entries" do + # invalid_email = { + # merchant: { + # username: "namename", + # email: "name" + # } + # } + # + # invalid_email_2 = { + # merchant: { + # username: "namename", + # email: "name@" + # } + # } + # + # invalid_email_3 = { + # merchant: { + # username: "namename", + # email: "name@name." + # } + # } + # + # start_count = Merchant.count + # + # post merchants_path, params: invalid_email + # must_respond_with :bad_request + # + # post merchants_path, params: invalid_email_2 + # must_respond_with :bad_request + # + # post merchants_path, params: invalid_email_3 + # must_respond_with :bad_request + # + # Merchant.count.must_equal start_count + # end + end end From ec92ceccd0e7a2ba747fba672d6c345cb147ba8d Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 15:52:10 -0700 Subject: [PATCH 024/269] fix merge error --- app/models/product.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index f1184cc4cd..002cb685c6 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,9 +1,7 @@ class Product < ApplicationRecord -<<<<<<< HEAD + has_many :order_products -======= -has_many :reviews ->>>>>>> lauren-reviews + has_many :reviews belongs_to :merchant From e658912352f50b960c93a35c544cbb2132f90f6e Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 18 Oct 2017 19:07:22 -0700 Subject: [PATCH 025/269] reviews controller tests --- test/controllers/reviews_controller_test.rb | 37 +++++++++++++++++++++ test/models/review_test.rb | 11 +++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index 386065239a..e13f675743 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -4,4 +4,41 @@ # it "must be a real test" do # flunk "Need real tests" # end + + before do + @review = Review.new + end + + describe "relations" do + it "must respond to product" do + @review.must_respond_to :product + 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 + 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/models/review_test.rb b/test/models/review_test.rb index ce8378a033..925966a6c9 100644 --- a/test/models/review_test.rb +++ b/test/models/review_test.rb @@ -1,9 +1,10 @@ require "test_helper" describe Review do - let(:review) { Review.new } - - it "must be valid" do - value(review).must_be :valid? - end + # let(:review) { Review.new } + # + # it "must be valid" do + # value(review).must_be :valid? + # end + end From e0094af68b6ad7c4eaf7e0a9ea3ace52281a87b1 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Wed, 18 Oct 2017 19:35:29 -0700 Subject: [PATCH 026/269] Add OAuth gems and did basic set up until I tried to db:migrate, and am stuck on this error: PG::NotNullViolation: ERROR: column provider contains null values. Add login functionality to #create, commented out until migration is resolved. --- .gitignore | 3 ++ Gemfile | 7 +++- Gemfile.lock | 30 +++++++++++++- app/controllers/application_controller.rb | 12 ++++++ app/controllers/merchants_controller.rb | 39 +++++++++++++++++++ app/controllers/products_controller.rb | 2 +- app/models/merchant.rb | 11 ++++++ app/models/product.rb | 6 +-- config/initializers/omniauth.rb | 3 ++ config/routes.rb | 1 + ...20171019005522_add_columns_to_merchants.rb | 7 ++++ 11 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 config/initializers/omniauth.rb create mode 100644 db/migrate/20171019005522_add_columns_to_merchants.rb diff --git a/.gitignore b/.gitignore index 82701fedc8..93fc4c22fa 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ /yarn-error.log .byebug_history + +# Keep secrets secret +.env diff --git a/Gemfile b/Gemfile index 35b1f4c9c0..c68cf7f8b4 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,10 @@ gem 'jbuilder', '~> 2.5' # 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] @@ -48,6 +52,7 @@ group :development do # 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 @@ -69,4 +74,4 @@ group :test do end gem 'awesome_print' -gem 'foundation-rails', '6.4.1.2' \ No newline at end of file +gem 'foundation-rails', '6.4.1.2' diff --git a/Gemfile.lock b/Gemfile.lock index 40ed35cd56..200a6d7157 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,8 +69,14 @@ GEM concurrent-ruby (1.0.5) crass (1.0.2) debug_inspector (0.0.3) + 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) @@ -78,6 +84,7 @@ GEM 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) @@ -86,6 +93,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks + jwt (1.5.6) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -111,9 +119,26 @@ GEM 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) @@ -211,12 +236,15 @@ DEPENDENCIES binding_of_caller byebug capybara (~> 2.13) + dotenv-rails foundation-rails (= 6.4.1.2) jbuilder (~> 2.5) jquery-turbolinks listen (>= 3.0.5, < 3.2) minitest-rails minitest-reporters + omniauth + omniauth-github pg (~> 0.18) pry-rails puma (~> 3.7) @@ -231,4 +259,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.15.4 + 1.16.0.pre.3 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e9d..bbe2c6f5f8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,15 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + protected + + # def require_login + # @merchant = Merchant.find_by(id: session[:user_id]) + # unless @merchant + # flash[:status] = :failure + # flash[:message] = "You must be logged in to do that!" + # redirect_to products_path + # end + # end + end diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 57eb4a90fb..2ccff02f18 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -11,6 +11,28 @@ def new end def create + # auth_hash = request.env['omniauth.auth'] + # + # 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]) + # save_and_flash(merchant) + # else #merchant has logged in before + # flash[:status] = :success + # flash[:message] = "Successfully logged in as returning merchant #{merchant.name}" + # end + # + # session[:merchant_id] = merchant.id + # + # else + # flash[:status] = :failure + # flash[:message] = "Could not create merchant from OAuth data" + # end + # + # redirect_to root_path + # end + @merchant = Merchant.new(merchant_params) # @merchant.user_id = session[:user_id] if @merchant.save @@ -77,4 +99,21 @@ def find_id_by_params head :not_found end end + + def save_and_flash(model) + result = model.save + + if result + flash[:status] = :success + flash[:message] = "Successfully saved #{model.class} #{model.name}" + else + flash.now[:status] = :failure + flash.now[:message] = "Failed to save #{model.class}" + flash.now[:details] = model.errors.messages + end + + puts "In save_and_flash: Result: #{result}" + + return result + end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 583468b9e9..2a5563ac58 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -17,7 +17,7 @@ def create product_params ) # this could be a hidden field view, or it could be in the strong params, or it could be here - # @product.merchant_id = session[:merchant_id] + @product.merchant_id = session[:merchant_id] if @product.save redirect_to products_path diff --git a/app/models/merchant.rb b/app/models/merchant.rb index 19eb23e28d..223a05cfe2 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -8,4 +8,15 @@ class Merchant < ApplicationRecord validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/, message: "Please enter your email in this format: example@example.com" #https://stackoverflow.com/questions/4776907/what-is-the-best-easy-way-to-validate-an-email-address-in-ruby + + 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 end diff --git a/app/models/product.rb b/app/models/product.rb index f1184cc4cd..002cb685c6 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,9 +1,7 @@ class Product < ApplicationRecord -<<<<<<< HEAD + has_many :order_products -======= -has_many :reviews ->>>>>>> lauren-reviews + has_many :reviews belongs_to :merchant 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/routes.rb b/config/routes.rb index 3b2bf073ba..362976fbf1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,4 +8,5 @@ resources :merchants post '/order_products', to: 'order_products#create', as: 'create_order_product' + get "/auth/:provider/callback", to: "merchants#create" 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 From 6b7b64872d497eb427f89542cf6a1a16686a947c Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 20:13:56 -0700 Subject: [PATCH 027/269] moving on to model testing because controller is killing me. --- app/controllers/order_products_controller.rb | 4 ++-- test/controllers/order_products_controller_test.rb | 4 ++-- test/models/product_test.rb | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 8c774a2514..481f706de6 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -5,8 +5,8 @@ def create @order_product.save - # redirect_to order_path(order) - redirect_to orders_path + redirect_to order_path(order) + # redirect_to orders_path end end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index 52790413ff..b03469fc03 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -4,8 +4,8 @@ describe "create" do it "creates an OrderProduct with a product and an order" do product_params = { - params: { - product_id: products(:tricycle) + order_product: { + product_id: products(:tricycle).id } } diff --git a/test/models/product_test.rb b/test/models/product_test.rb index a961cc5241..ee122e471c 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -10,6 +10,11 @@ it "must respond to merchant" do @p.must_respond_to :merchant end + + it "can have order_products" do + @p.must_respond_to :order_products + end + end describe 'validations' do From 1b83c9190fe456788fe8856b34222d2f713cddc6 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 20:35:25 -0700 Subject: [PATCH 028/269] add model testing --- app/models/order.rb | 9 +++++++++ test/fixtures/order_products.yml | 8 ++++---- test/fixtures/products.yml | 8 ++++++++ test/models/order_product_test.rb | 13 ++++++++++--- test/models/order_test.rb | 25 ++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 732f18c63e..ed5362d3ce 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,3 +1,12 @@ class Order < ApplicationRecord has_many :order_products + + + def products + products = [] + order_products.each do |op| + products << op.product + end + return products + end end diff --git a/test/fixtures/order_products.yml b/test/fixtures/order_products.yml index 1cb6079d5a..05a029fd4d 100644 --- a/test/fixtures/order_products.yml +++ b/test/fixtures/order_products.yml @@ -2,10 +2,10 @@ one: quantity: 1 - product_id: 1 - order_id: 1 + product: tricycle + order: order1 two: quantity: 1 - product_id: 1 - order_id: 1 + product: tripod + order: order1 diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index e6a8b1493e..9238abfe61 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -18,3 +18,11 @@ tricycle: inventory: 2 photo_url: www.fillmurray.com price: 2.40 + +tripod: + name: tripod + description: "Good for cameras" + merchant: lauren + inventory: 4 + photo_url: www.fillmurray.com + price: 12.56 diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index 47c6ee2a98..b6ae7fd8a2 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -1,9 +1,16 @@ require "test_helper" describe OrderProduct do - let(:order_product) { OrderProduct.new } + let (:op) { order_products(:one) } + describe "relationships" do + it "has an order" do + op.must_respond_to :order + op.order.must_be_kind_of Order + end - it "must be valid" do - value(order_product).must_be :valid? + it "has a product" do + op.must_respond_to :product + op.product.must_be_kind_of Product + end end end diff --git a/test/models/order_test.rb b/test/models/order_test.rb index df80f10fb6..915e09cc97 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -1,9 +1,28 @@ require "test_helper" describe Order do - let(:order) { Order.new } + 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.order_products.each do |op| + op.product.must_be_kind_of Product + end + 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 "must be valid" do - value(order).must_be :valid? + 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 end From b7cf61509051c3294de3ddbd0625e2f4f914dc8c Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Wed, 18 Oct 2017 21:13:35 -0700 Subject: [PATCH 029/269] make a new order-product take a quantity --- app/controllers/order_products_controller.rb | 12 ++++++-- app/controllers/orders_controller.rb | 29 ++++++++++---------- app/views/layouts/application.html.erb | 3 ++ app/views/orders/index.html.erb | 2 +- app/views/orders/show.html.erb | 27 +++++++++++++----- app/views/products/show.html.erb | 10 ++++++- db/schema.rb | 8 ++++++ 7 files changed, 65 insertions(+), 26 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 481f706de6..11e5db37eb 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -1,11 +1,17 @@ class OrderProductsController < ApplicationController def create - order = Order.create(status:"this is a test") - @order_product = OrderProduct.new(product_id: params[:product_id], order_id: order.id) + if session[:cart] + @order = session[:cart] + else + order = Order.create(status:"pending") + @order = order.id + session[:cart] = order.id + end + @order_product = OrderProduct.new(quantity: params[:quantity], product_id: params[:product_id], order_id: @order) @order_product.save - redirect_to order_path(order) + redirect_to order_path(@order) # redirect_to orders_path end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index fae03489b2..bdfbbd946a 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -5,22 +5,23 @@ def index @orders = Order.all end - def create - @order = Order.new(order_params) - - if save_and_flash(@order) - redirect_to order_path(@order) - else - render :new, status: :bad_request - end - - end - - def new - @order = Order.new - end + # def create + # @order = Order.new(order_params) + # + # if save_and_flash(@order) + # redirect_to order_path(@order) + # else + # render :new, status: :bad_request + # end + # + # end + # + # def new + # @order = Order.new + # end def edit + # edit is actually more like check_out end def show diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a039136e1b..d3d3a77748 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,6 +12,9 @@ +
+ <%= link_to "Home", products_path %> +
<%= yield %> diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb index ae40117161..7f7ecb5b17 100644 --- a/app/views/orders/index.html.erb +++ b/app/views/orders/index.html.erb @@ -1,4 +1,4 @@ -<%= link_to 'New Order', new_order_path, class:'button' %> +<%# link_to 'New Order', new_order_path, class:'button' %>

All Orders

    diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index b76ae3d31b..fdfcfb7cde 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,12 +1,25 @@

    Your Cart

    -
      - <% @order.order_products.each do |order_product| %> -
    • - <%= order_product.product.name %> -
    • - <% end %> -
    + + + + + + + + + + <% @order.order_products.each do |op| %> + + + + + + <% end %> + +
    ProductQuantityCost
    <%= link_to op.product.name, product_path(op.product) %><%= op.quantity %><%= op.product.price %>
    + +

    Order <%= @order.id %>

    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index cc78bcaed7..dcd12f141c 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -3,7 +3,15 @@

    Description: <%= @product.description %>

    Price: $<%= '%.2f' % @product.price %>

    -

    <%= link_to "Add to Order", create_order_product_path(product_id: @product.id), method:'post', class: "button" %>

    +
    + <%= form_tag create_order_product_path(product_id: @product.id), method: :post do %> + + <%= text_field_tag "quantity", 1 %> + + <%= submit_tag "Add to Order", class: "button" %> + <% end %> +
    +

    Reviews: <% @product.reviews.each do |review| %>

    <%= review.text %> diff --git a/db/schema.rb b/db/schema.rb index 1dd220e069..882d7c0453 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -22,6 +22,14 @@ t.datetime "updated_at", null: false end + create_table "order_items", 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 + end + create_table "order_products", force: :cascade do |t| t.integer "quantity" t.integer "product_id" From 1ad557cdb4c850b3214fa35817cb0aef47c6604f Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Wed, 18 Oct 2017 21:24:49 -0700 Subject: [PATCH 030/269] Add basic html to application.html.erb. Sign in and sign out functionality now working. Still need to test. --- app/controllers/merchants_controller.rb | 74 ++++++++++++++----------- app/views/layouts/application.html.erb | 40 +++++++++++++ config/routes.rb | 1 + db/schema.rb | 5 +- 4 files changed, 86 insertions(+), 34 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 2ccff02f18..ce4b4d4a8e 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,6 +1,6 @@ class MerchantsController < ApplicationController -before_action :find_id_by_params, except: [:index, :new, :create] +before_action :find_id_by_params, except: [:index, :new, :create, :logout] def index @merchants = Merchant.all @@ -11,41 +11,49 @@ def new end def create - # auth_hash = request.env['omniauth.auth'] - # - # 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]) - # save_and_flash(merchant) - # else #merchant has logged in before - # flash[:status] = :success - # flash[:message] = "Successfully logged in as returning merchant #{merchant.name}" - # end - # - # session[:merchant_id] = merchant.id - # + auth_hash = request.env['omniauth.auth'] + + 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 + + session[:merchant_id] = merchant.id + + else + flash[:status] = :failure + flash[:message] = "Could not create merchant from OAuth data" + end + + redirect_to products_path + end + + # def create + # @merchant = Merchant.new(merchant_params) + # # @merchant.id = session[:merchant_id] + # if @merchant.save + # # @merchant = session[:merchant_id] + # flash[:status] = :success + # flash[:result_text] = "Successfully created: #{@merchant.username}" + # redirect_to merchant_path(@merchant.id) # else # flash[:status] = :failure - # flash[:message] = "Could not create merchant from OAuth data" + # flash[:result_text] = "Could not create new merchant" + # flash[:messages] = @merchant.errors.messages + # render :new, status: :bad_request # end - # - # redirect_to root_path # end - @merchant = Merchant.new(merchant_params) - # @merchant.user_id = session[:user_id] - if @merchant.save - # @merchant = session[:user_id] - flash[:status] = :success - flash[:result_text] = "Successfully created: #{@merchant.username}" - redirect_to merchant_path(@merchant.id) - else - flash[:status] = :failure - flash[:result_text] = "Could not create new merchant" - flash[:messages] = @merchant.errors.messages - render :new, status: :bad_request - end + def logout + session[:merchant_id] = nil + flash[:status] = :success + flash[:message] = "You have been logged out" + redirect_to products_path end def show @@ -56,7 +64,7 @@ def edit end def update - # if @merchant.user_id != session[:user_id] + # if @merchant.id != session[:merchant_id] # flash[:status] = :failure # flash[:result_text] = "Only the merchant has permission to do this" # redirect_to root_path @@ -75,7 +83,7 @@ def update end def destroy - # if @merchant.user_id != session[:user_id] + # if @merchant.id != session[:merchant_id] # flash[:status] = :failure # flash[:result_text] = "Only the merchant has permission to delete" # redirect_to root_path diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a039136e1b..d495d910d0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,6 +13,46 @@ + + + <% if flash[:message] %> +
    + <%= flash[:message] %> +
    + <% end %> + + <% if flash[:result_text] or flash[:messages] %> +
    +

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

    + <% if flash[:messages] %> +
      + <% flash[:messages].each do |name, problems| %> + <% problems.each do |problem| %> +
    • <%= name %>: <%= problem %>
    • + <% end %> + <% end %> +
    + <% end %> +
    + <% end %> + <%= yield %> diff --git a/config/routes.rb b/config/routes.rb index 362976fbf1..a1f0f08e06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,4 +9,5 @@ post '/order_products', to: 'order_products#create', as: 'create_order_product' get "/auth/:provider/callback", to: "merchants#create" + get '/logout', to: 'merchants#logout', as: 'logout' end diff --git a/db/schema.rb b/db/schema.rb index 1dd220e069..c2e3eb01a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171018192530) do +ActiveRecord::Schema.define(version: 20171019005522) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,9 @@ 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| From a9e61ed52659dcef77b25d07880f053bd5414bf4 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Wed, 18 Oct 2017 21:34:14 -0700 Subject: [PATCH 031/269] Add set up to start oauth testing. All tests now erroring --- test/fixtures/merchants.yml | 6 ++++++ test/test_helper.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml index 09b8d77881..9acb1e778b 100644 --- a/test/fixtures/merchants.yml +++ b/test/fixtures/merchants.yml @@ -1,13 +1,19 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html anders: + provider: github + uid: 12345 username: anders email: anders@tricycle.com lauren: + provider: github + uid: 67896789 username: lauren email: lauren@tricycle.com bennett: + provider: github + uid: 123123123 username: bennett email: bennett@tricycle.com diff --git a/test/test_helper.rb b/test/test_helper.rb index 10594a3248..dc9867096e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,4 +23,19 @@ 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: { + email: merchant.email, + nickname: merchant.username + } + } + end end From 19dad1db8cf2546f4d03c8d922d1144ab863b7ca Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 18 Oct 2017 21:46:48 -0700 Subject: [PATCH 032/269] review tests --- test/controllers/reviews_controller_test.rb | 71 ++++++++++++--------- test/fixtures/reviews.yml | 13 ++-- test/models/review_test.rb | 38 ++++++++++- 3 files changed, 88 insertions(+), 34 deletions(-) diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index e13f675743..d2e6d94f14 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -4,41 +4,54 @@ # it "must be a real test" do # flunk "Need real tests" # end + let (:review) {reviews(:review1)} - before do - @review = Review.new - end - - describe "relations" do - it "must respond to product" do - @review.must_respond_to :product + describe "new" do + it "creates a new review successfully" do + @product = Product.first.id + get new_product_review_path(@product) + must_respond_with :success 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 - is_valid = @review.valid? - is_valid.must_equal false - @review.errors.messages.must_include :rating - end + describe "create" do + # BOTH create tests need :product_id! HOW DO WE PASS IN? - 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 "saves and redirects to product show page when the review data is valid" do + # review_data = { + # review: { + # rating: 3, + # text: "I loved it!", + # } + # } + # @product = Product.first.id + # Review.new(review_data[:review]).must_be :valid? + # start_review_count = Review.count + # + # post new_product_review_path, params: product_data + # must_respond_with :redirect + # must_redirect_to product_path(@product) + # Review.count.must_equal start_review_count + 1 + # 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 + + # it "renders a bad_request when the review data is invalid" do + # bad_review = { + # review: { + # rating: "", + # # no rating given!! + # } + # } + # Review.new(bad_review[:review]).wont_be :valid? + # start_review_count = Review.count + # post new_product_review_path, params: bad_review + # + # must_respond_with :bad_request + # Review.count.must_equal start_review_count + # end + # # need to write test for when create is not allowed (not merchant_id) end + + end diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml index dc3ee79b5d..b3c5dd49b7 100644 --- a/test/fixtures/reviews.yml +++ b/test/fixtures/reviews.yml @@ -4,8 +4,13 @@ # 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: {} +# one: {} +# # column: value +# # +# two: {} # column: value + +review1: + rating: 1 + text: "A hit!" + product_id: 1 diff --git a/test/models/review_test.rb b/test/models/review_test.rb index 925966a6c9..672ff3bf62 100644 --- a/test/models/review_test.rb +++ b/test/models/review_test.rb @@ -6,5 +6,41 @@ # 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 + review.must_respond_to :product + 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 From 365678e8f6dbf821dafcfa4a16796b68175c31eb Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 10:13:44 -0700 Subject: [PATCH 033/269] working controller test --- app/controllers/reviews_controller.rb | 4 +-- app/views/reviews/new.html.erb | 2 +- config/routes.rb | 3 +- test/controllers/reviews_controller_test.rb | 39 ++++++++++----------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 31d0745683..8231e012e7 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -5,12 +5,12 @@ def new end def create - @product = Product.find_by(id: params[:product_id]) + # @product = Product.find_by(id: params[:product_id]) @review = Review.new( review_params ) if @review.save - redirect_to product_path(@product) + redirect_to product_path(review_params[:product_id]) else render :new, status: :bad_request end diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb index 3c3c9ebb9f..11c4e0fae1 100644 --- a/app/views/reviews/new.html.erb +++ b/app/views/reviews/new.html.erb @@ -1,5 +1,5 @@

    Write a new Review:

    -<%= form_for [@product, @review] do |f| %> +<%= form_for @review do |f| %> <%= f.label :rating, "Rating 1-5" %> <%= f.number_field :rating %> diff --git a/config/routes.rb b/config/routes.rb index 3b2bf073ba..e4debc7175 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,8 +3,9 @@ resources :orders resources :products do - resources :reviews, only: [:new, :create, :show] + resources :reviews, only: [:new] end + resources :reviews, only: [:create] resources :merchants post '/order_products', to: 'order_products#create', as: 'create_order_product' diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index d2e6d94f14..71439465ec 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -1,10 +1,7 @@ require "test_helper" describe ReviewsController do - # it "must be a real test" do - # flunk "Need real tests" - # end - let (:review) {reviews(:review1)} + # let (:review) {reviews(:review1)} describe "new" do it "creates a new review successfully" do @@ -17,22 +14,24 @@ describe "create" do # BOTH create tests need :product_id! HOW DO WE PASS IN? - # it "saves and redirects to product show page when the review data is valid" do - # review_data = { - # review: { - # rating: 3, - # text: "I loved it!", - # } - # } - # @product = Product.first.id - # Review.new(review_data[:review]).must_be :valid? - # start_review_count = Review.count - # - # post new_product_review_path, params: product_data - # must_respond_with :redirect - # must_redirect_to product_path(@product) - # Review.count.must_equal start_review_count + 1 - # end + 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 + } + } + 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 "renders a bad_request when the review data is invalid" do From 949ace115e1778c85cb38c22492f5e7ed72c2291 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Thu, 19 Oct 2017 12:44:18 -0700 Subject: [PATCH 034/269] Add tests for OAuth functionality. --- config/routes.rb | 2 +- test/controllers/merchants_controller_test.rb | 204 ++++++++++++------ test/test_helper.rb | 6 + 3 files changed, 142 insertions(+), 70 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index a1f0f08e06..c252cf9dd2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,6 @@ resources :merchants post '/order_products', to: 'order_products#create', as: 'create_order_product' - get "/auth/:provider/callback", to: "merchants#create" + get "/auth/:provider/callback", to: "merchants#create", as: 'auth_callback' get '/logout', to: 'merchants#logout', as: 'logout' end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 13ec19cccf..e82df5419e 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -1,98 +1,164 @@ require "test_helper" describe MerchantsController do - 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 "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 - describe "new" do - it "works" do - get new_merchant_path - must_respond_with :success - end - end + # Get a merchant from the fixtures + merchant = merchants(:anders) - describe "create" do - it "creates a merchant with valid data" do - merchant_data = { - merchant: { - username: "test test", - email: "test@test.com" - } - } + # 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)) - start_count = Merchant.count + # 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) - post merchants_path, params: merchant_data - must_redirect_to merchant_path(Merchant.last) + must_redirect_to products_path - Merchant.count.must_equal start_count + 1 - end + # Since we can read the session, check that the user ID was set as expected + session[:merchant_id].must_equal merchant.id - it "renders bad_request and does not update the DB for invalid merchant data" do - invalid_merchant_data = { - merchant: { - username: "", - email: "" - } - } + # 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 + # Merchant.destroy_all start_count = Merchant.count - post merchants_path, params: invalid_merchant_data - must_respond_with :bad_request + # merchant = merchants(:anders) - Merchant.count.must_equal start_count - end + merchant = Merchant.new(provider: "github", uid: 123124564, username: "test_merchant", email: "test@merchant.com", name: "trio") + puts "merchant: provider: #{merchant.provider}, uid: #{merchant.uid}" - it "renders 400 bad_request for invalid email entries" do - invalid_email = { - merchant: { - username: "namename", - email: "name" - } - } + login(merchant) - invalid_email_2 = { - merchant: { - username: "namename", - email: "name@" - } - } + puts "merchant: provider: #{merchant.provider}, uid: #{merchant.uid}" - invalid_email_3 = { - merchant: { - username: "namename", - email: "name@name." - } - } - start_count = Merchant.count + must_redirect_to products_path + flash[:status].must_equal :success - post merchants_path, params: invalid_email - must_respond_with :bad_request + # Should have created a new user + Merchant.count.must_equal start_count + 1 - post merchants_path, params: invalid_email_2 - must_respond_with :bad_request + # 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 - post merchants_path, params: invalid_email_3 - must_respond_with :bad_request + it "redirects to the products route if given invalid user data" do + invalid_merchant = Merchant.first + invalid_merchant.uid = "" - Merchant.count.must_equal start_count + login(invalid_merchant) + + must_redirect_to products_path + flash[:status].must_equal :success end 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 "new" do + it "works" do + get new_merchant_path + must_respond_with :success + end + end + + # describe "create" do + # it "creates a merchant with valid data" do + # merchant_data = { + # merchant: { + # username: "test test", + # email: "test@test.com" + # } + # } + # + # start_count = Merchant.count + # + # post merchants_path, params: merchant_data + # must_redirect_to merchant_path(Merchant.last) + # + # Merchant.count.must_equal start_count + 1 + # end + # + # it "renders bad_request and does not update the DB for invalid merchant data" do + # invalid_merchant_data = { + # merchant: { + # username: "", + # email: "" + # } + # } + # + # start_count = Merchant.count + # + # post merchants_path, params: invalid_merchant_data + # must_respond_with :bad_request + # + # Merchant.count.must_equal start_count + # end + # + # + # it "renders 400 bad_request for invalid email entries" do + # invalid_email = { + # merchant: { + # username: "namename", + # email: "name" + # } + # } + # + # invalid_email_2 = { + # merchant: { + # username: "namename", + # email: "name@" + # } + # } + # + # invalid_email_3 = { + # merchant: { + # username: "namename", + # email: "name@name." + # } + # } + # + # start_count = Merchant.count + # + # post merchants_path, params: invalid_email + # must_respond_with :bad_request + # + # post merchants_path, params: invalid_email_2 + # must_respond_with :bad_request + # + # post merchants_path, params: invalid_email_3 + # must_respond_with :bad_request + # + # Merchant.count.must_equal start_count + # end + # end + describe "show" do it "succeeds for an extant merchant ID" do get merchant_path(Merchant.first) diff --git a/test/test_helper.rb b/test/test_helper.rb index dc9867096e..31997c0569 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -38,4 +38,10 @@ def mock_auth_hash(merchant) } } end + + def login(merchant) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant)) + get auth_callback_path(:github) + end + end From ed97b9c80ecae4003f8847bcb655f41b7dbd1bb6 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 12:49:34 -0700 Subject: [PATCH 035/269] reviews controller --- test/controllers/reviews_controller_test.rb | 34 ++++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index 71439465ec..8f873321a1 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -34,21 +34,25 @@ end - # it "renders a bad_request when the review data is invalid" do - # bad_review = { - # review: { - # rating: "", - # # no rating given!! - # } - # } - # Review.new(bad_review[:review]).wont_be :valid? - # start_review_count = Review.count - # post new_product_review_path, params: bad_review - # - # must_respond_with :bad_request - # Review.count.must_equal start_review_count - # end - # # need to write test for when create is not allowed (not merchant_id) + # it "renders a bad_request when the review data is invalid" do + # product = Product.first + # bad_review = { + # review: { + # rating: "", + # product_id: product.id + # # no rating given!! + # } + # } + # product.reviews.new(bad_review[:review]).wont_be :valid? + # + # start_review_count = Review.count + # post reviews_path, params: bad_review + # + # must_respond_with :bad_request + # + # Review.count.must_equal start_review_count + # end + # need to write test for when create is not allowed (not merchant_id) end From d2edbd4ba010f2001b6fee0e473c207d0356b05b Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 12:51:24 -0700 Subject: [PATCH 036/269] fix one controller test --- test/controllers/order_products_controller_test.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index b03469fc03..d0d2dadda0 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -2,17 +2,16 @@ describe OrderProductsController do describe "create" do - it "creates an OrderProduct with a product and an order" do + it "creates an OrderProduct with a product and an order, creates a new order if no session[:cart] exists" do product_params = { - order_product: { - product_id: products(:tricycle).id - } + product_id: products(:tricycle).id, + quantity: 1 } start_count = OrderProduct.count post create_order_product_path, params: product_params - must_redirect_to orders_path + must_redirect_to order_path(session[:cart]) OrderProduct.count.must_equal start_count + 1 end From 9e4c98a0f00044709f4c3f119c0031c3d22af022 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 13:01:54 -0700 Subject: [PATCH 037/269] comment out broken tests --- test/controllers/orders_controller_test.rb | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 3960289514..bd06ea9d35 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -36,23 +36,23 @@ end describe "new" do - it "returns a success status for new form" do - get new_order_path - must_respond_with :success - end + # it "returns a success status for new form" do + # get new_order_path + # must_respond_with :success + # end end describe "create" do - it "redirects to order page when the order data is valid" do - - Order.new(order_data[:order]).must_be :valid? - start_order_count = Order.count - post orders_path, params: order_data - must_respond_with :redirect - # must_redirect_to order_path() - - Order.count.must_equal start_order_count + 1 - end + # it "redirects to order page when the order data is valid" do + # + # Order.new(order_data[:order]).must_be :valid? + # start_order_count = Order.count + # post orders_path, params: order_data + # must_respond_with :redirect + # # must_redirect_to order_path() + # + # Order.count.must_equal start_order_count + 1 + # end # it "sends bad_request when the order data is invalid" do # From f9c04bac01de7488d8f3bd2e1b2e9b5ce76f081a Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 13:26:27 -0700 Subject: [PATCH 038/269] home page! --- app/controllers/products_controller.rb | 3 ++- app/views/layouts/application.html.erb | 4 ++-- app/views/products/index.html.erb | 2 +- app/views/products/root.html.erb | 8 ++++++++ config/routes.rb | 2 +- db/schema.rb | 8 -------- 6 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 app/views/products/root.html.erb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 2a5563ac58..e20c57223d 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,6 +1,7 @@ class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :destroy] - + def root + end def index @products = Product.all end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4b677de666..01f874d695 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,12 +13,12 @@
    - <%= link_to "Home", products_path %> + <%= link_to "Home", root_path %>
+ <% end %> + <% end %> - <%= yield %> + <%= yield %> - + From 810ea3dc9bfcf83b7d409d47e38fe9bedff94d80 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 16:02:15 -0700 Subject: [PATCH 047/269] working on authorized viewing --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/merchants_controller.rb | 10 ++++++++-- app/controllers/products_controller.rb | 5 +---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 15855d2f5f..82d29d987d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,6 +24,13 @@ class ApplicationController < ActionController::Base # end # return result # end + 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 save_and_flash(model, edit: "", save: model.save) result = save diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index b858493cb2..2e93a5b8be 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -3,7 +3,13 @@ class MerchantsController < ApplicationController before_action :find_id_by_params, except: [:index, :new, :create, :logout] def index - @merchants = Merchant.all + if session[:merchant_id] == nil + flash[:status] = :failure + flash[:message] = "You must be logged in to do that!" + redirect_to products_path + else + @merchants = Merchant.all + end end def new @@ -32,7 +38,7 @@ def create redirect_to products_path end - + def logout session[:merchant_id] = nil flash[:status] = :success diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 932d72bf70..ac423de785 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,5 +1,6 @@ class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :destroy] + before_action :must_be_logged_in, only: [:show, :new] def root end def index @@ -9,13 +10,9 @@ def index def show ; end def new - if session[:merchant_id] == nil - flash[:status] = :failure - flash[:message] = "You must be logged in to do that!" redirect_to products_path else @product = Product.new - end end def create From 81f1a46c7621fdfc896f2150888f6d55295d906b Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 16:07:33 -0700 Subject: [PATCH 048/269] DRY up helper method --- app/controllers/merchants_controller.rb | 11 +++-------- app/controllers/products_controller.rb | 4 +--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 2e93a5b8be..24535109c5 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,15 +1,10 @@ class MerchantsController < ApplicationController before_action :find_id_by_params, except: [:index, :new, :create, :logout] - + before_action :must_be_logged_in, only: [:index] + def index - if session[:merchant_id] == nil - flash[:status] = :failure - flash[:message] = "You must be logged in to do that!" - redirect_to products_path - else - @merchants = Merchant.all - end + @merchants = Merchant.all end def new diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index ac423de785..8d7eeb0cd8 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -10,9 +10,7 @@ def index def show ; end def new - redirect_to products_path - else - @product = Product.new + @product = Product.new end def create From a6ae86854e6a39c42111215e90f2bb36feea204e Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 16:15:21 -0700 Subject: [PATCH 049/269] owner of product cannot review their product --- app/controllers/reviews_controller.rb | 8 +++++++- app/views/merchants/show.html.erb | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 0b1a200cb8..7b77fd48d0 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -1,7 +1,13 @@ class ReviewsController < ApplicationController + def new - @review = Review.new @product = Product.find_by(id: params[:product_id]) + if session[:merchant_id] == @product.merchant_id + flash[:status] = :failure + flash[:message] = "You cannot review your own product!" + redirect_to products_path + end + @review = Review.new end def create diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index 34ff806ea6..f49195f85c 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -4,6 +4,10 @@ <%= link_to "Edit", edit_merchant_path(@merchant.id), class: "button" %> <%= link_to "Delete", merchant_path(@merchant.id), method: :delete, data: { confirm: "Are you sure?" }, class: "alert button" %> +<% @merchant.products.each do |product| %> +

<%= product.name %>

+<% end %> + <%# TODO %> <%# all money %> <%# all products sold %> From 6dabcd6dab79674a8931fa4c2c28fa3073a45c58 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 16:30:38 -0700 Subject: [PATCH 050/269] cart button --- app/views/layouts/application.html.erb | 1 + app/views/merchants/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bba40514bb..9e07285d9b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,6 +28,7 @@ <%= link_to "View all merchants", merchants_path, class: "button" %> <% end %>
+ <%= link_to "My Cart", products_path, class: "button" %> <% if session[:merchant_id] %> <%= link_to "Log out", logout_path, class: "button" %> <% else %> diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index f49195f85c..70926952fb 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -5,7 +5,7 @@ <%= link_to "Delete", merchant_path(@merchant.id), method: :delete, data: { confirm: "Are you sure?" }, class: "alert button" %> <% @merchant.products.each do |product| %> -

<%= product.name %>

+

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

<% end %> <%# TODO %> From 78007323ea1208318fee2bb51c1cee0fdba04de6 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 17:05:46 -0700 Subject: [PATCH 051/269] cart icon but not a link to order page --- app/assets/images/cart.png | Bin 0 -> 3666 bytes app/controllers/application_controller.rb | 8 ++++++++ app/controllers/merchants_controller.rb | 3 ++- app/controllers/products_controller.rb | 3 ++- app/views/layouts/application.html.erb | 6 +++++- 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 app/assets/images/cart.png diff --git a/app/assets/images/cart.png b/app/assets/images/cart.png new file mode 100644 index 0000000000000000000000000000000000000000..a905cf707da908039f5548f2264f74ec02b4666e GIT binary patch literal 3666 zcma)9`8N~{7oIU=OJo0%Y(qjwmL{@mkTJ%RZDd|1Yr-^kS;|uOWs)T(WQ~k1j3LXE zHH0Kf21AyRtp;WNy#K-bob%j!?!D)p`@?hZ4>#W2^cLjIg);yE0D>^mzkTX^|0NsC zsjWm;<()dP-%W%S+bP1>T;fh+cD#|D9{|9?_b-8foR{ZMn;8gwJ*(iC>(ibjQ3H{l z?ah^fVU7BFqi4`KC0*v|GwGq1%$v$0pvI$7WnliIc%_^&_I=}UXQrIEELqh{7=8{J z?qUxlkE}omxwlex<>^Q!dH5!B$}dbw(^u_f_@K&3Zf>^w-X3BX73!9MvY~zA?iS?c zuB-oFalh=f%inma6?Pm@dzQ?H26~lYXC*RLfNsE4z!4AGfcnrP#iY1ci7GrV*-c+p z$7Zc^S#)l&j7Z+{JTTaam2pyeUjOm)x0JGdT?2WXc(^YEG;S0AO5$7vB47B3>PdZ) zkZKK%;1PYS(ezg4Fo|W*Oyo%~*3-x_w4Tf=t8K$Wt!A+^x8pxfVd6xHJQ;PY?wPG( zRw$F@j;^Fmmq&98-n+g+w5{}ptg59C{5*p(+h4fn?QRoFk+|*-{2j4gj3TsKg})l{ za=rC?gXQPb+13H`UDl-wed~bTE?A@feQzG}orS5(QU8ly=k;QLd(EImqINw+$j}Lq zw!%K2!6Fm7$vtwNj-@NYCm+$tHFI$b%aUHOUMX5XMxtR1B;S!KS;yNc2g|bLt8nGQ z#uU)>>8mvbaSQG`v?QrEn334l40zi(c@Z7$#gx)>(mw-gNvQ0wa4~A)+$BO@ddUQd zZ-q^m7borjD(r*IqV~60ka({7GVxA5@0Bbxk(m#8B>QB;f}m_BJ4QQ0Qw;{rj$tbV2%T?xD{hI}=Xr zsJuLy@GTpF`SMY0iPp)a`gPd&O}3UpjweX5{JGA+j#R6w$b}~|a{-#Tt9xMJxU>ZC zNP_7}jS%mG0wzDsNJb=;{38ZDiHKFTk`P%9ew#`=oi@Xz`AnUy{OKnuKgOL=(_Fv; z4CY0@_&4?LhvE(B?E3_GcJdmq0WGFX(CxN7{G%Sw5_<0N;5zLpo>K~N5weJbh!`n! z&&AZ)&s=}WqeHv<56Y*-nXenxgu>{Uogc>zeLvBfNLdC<;5?in4;Gt0qIVO;LF_L7 z5KoXz=aBD)Z~}fNVjo)3%bwbK{Ru&qQ4y_X3mD9EDQRQwcXdgNEkxVtOz7SmZX!Gx zs4b+H`8FLII0oL%>u;Lk1=EANeFd143tIvm$%Vv)^S)*TPy`&ZD9W69aBj65+?2!F z^NUMaL`?=S?^+*vJHr$5_WB+Eu0mM#D-Avu82)vwmuZ7h6^eA(`}k_?1%37r;M%8s zf!^1f(&ONdP4O^6d&dc7x>7%Dpl1{RPmIqsimLznh-`CSoOm~tXaR*?7V4@wEv$RtC_NYQt6T|bcnx` zG4wBrGYP!AWTFf_$0F; zL&edyCC%p>@%PTGi|Xa+9R_`w%54`jFYNeKCZI+$-%z4YQfvKNEvWqy`}*}?JrBeq zM@!mzcuXs2%YmmM;&t&dUg=sE6ZEm1hcA>$VHmh%#fo!O0}WI;x^a4gY+F-B${Kd84ue{jDsKR@+!V_FqBKGBis@_23T(ni zji!OmL?mB-8Z?~3s`CEpjZ+oN;R9|q8?ate&GAv0IVde8z3mv-!moDj)iJxT3eH;A zaT8>E+WQPeiQkGzgGbe~M06AU?;V)0=0WWvgpysIO(9l{C3{X3iAJ;?-YO68Q)ihX ztbFPuhPeCaomI+edsGXJ`TI=!vFwJ!hduQx<;rEv<50jJ=meH7#1STimp4cdE$Y7S zv}2C3?+WQWKzPCPWh=FE2vEYw8!LlPFSO$Pl6PNGq_u4L$pA>2>+dr;8PG?-wA_-DFu;E7;^PFSYoOCGmfm^O#L&fb9(a%I*$p<#ke5@7U{?2(}USw^_yAj;t6PJ?1$t{=Mof#yMbxb2!?P&qZ`28NQ-z5ldEu z>Fw868(;D;KoO+0m%Jwhg7cP+jr@zG<5YqfCpm|U=t!chVe_r@!S|6lFQI^Tlt@JI zU-&8@$IX_8E*cea{1!8dlcmIDtfICH1SjL)3Dlm|dKR1sSO!$T<}8laHrjW*ETgSj>&NoF`PwFGDR%Ci_)m!Too+=JWODGC*;&?K`^GYuTQ&v{6lGg zSU&d1p?HHHAsXt?#_R&~II`tqi<~xZK-=i?ZG=ftgeT&pYj}5eJp}7dT$AE40h}Wo z_rLP~;SI#at0A!0aJN@S9htn>8=sa*A?6K79K*bGy;TJ;@bX?;#N*Emf4#FH4=>4$ zj;4G#!mr_yP$F@`lT5;ATe#OiMD?pE=;@!>rWGq(A#ejmfFT;;c> z(++~csxm%WID=_H%HLkn7|1fdrqBD!0QDH`dPA`e+uj2-%beJ|Ar`>#7yFN| za`^=-4_8hobbl7vIN_!pK-&%+(fhq`oCRa*K!0>&4|Mu!P9D*Ijq*-79bWC6)zaxu zwmRr`{^fXznT zyAze9oNl-BcQ4an#sOPgfcYBYV|E%6TG`==x9@ zRMkE&OGA@j6vsZkNF;vq1zH54X@!!kk1L+}i z<3jyNA-|fF`_{G7w(D~&O8Jas4|-r|L+n9j>2!2N1DKHHL@83&0=cRs~||(04RlE|5=We7o9CFBTmL){`}?~$*U83 zqoePU9YM6#?0V{e3NjtmWL6!N?Ydzf<873Xt_TUvrU-;^9K)4-eZe??y#YTmPoqhr zB>vh4QzvD(8u+^V2FW-#3CTFW?8Vnry>2WS3zRF{y;%)PNevmXK>k`Q~y3_tH8ye`*gPFc&lPM9p0;a>zi7 zX`3vBzr1T_oX6B=P*t5Xg*cI8;a)BR~L@5IiJDGGau;CLe+ zQjU{ZotU%AFGhaBFMC~pt7bTSI0Ag?%B_oaW?qJ~&p*(_b)BBz8bunL*|?G8!nE-+ o`MuW1skj+7exCn`Xa2{mY>=U!DnF;BPoF{n!oXC&>Lxbo|BN-x4FCWD literal 0 HcmV?d00001 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 82d29d987d..b9b022e3d2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -32,6 +32,14 @@ def must_be_logged_in end end + def must_be_merchant_of_product + if session[:merchant_id] != @product.merchant_id + lash[: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: "", save: model.save) result = save if result diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 24535109c5..3191bd2f6b 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -2,7 +2,7 @@ class MerchantsController < ApplicationController before_action :find_id_by_params, except: [:index, :new, :create, :logout] before_action :must_be_logged_in, only: [:index] - + def index @merchants = Merchant.all end @@ -38,6 +38,7 @@ def logout session[:merchant_id] = nil flash[:status] = :success flash[:message] = "You have been logged out" + session[:cart] = nil redirect_to products_path end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 8d7eeb0cd8..421abd1bfb 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,6 +1,7 @@ class ProductsController < ApplicationController before_action :find_product, only: [:show, :edit, :update, :destroy] - before_action :must_be_logged_in, only: [:show, :new] + before_action :must_be_logged_in, only: [:new, :destroy, :edit] + before_action :must_be_merchant_of_product, only: [:destroy, :edit] def root end def index diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9e07285d9b..1de3b9fa58 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,7 +28,11 @@ <%= link_to "View all merchants", merchants_path, class: "button" %> <% end %>
- <%= link_to "My Cart", products_path, class: "button" %> + <%= link_to products_path do %> + <%= image_tag 'cart.png', size: "40x40" %> + <% end %> + + <% if session[:merchant_id] %> <%= link_to "Log out", logout_path, class: "button" %> <% else %> From 82a09ce3b5377cf0e7e752b0eca4f2feccfe36a9 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 17:09:09 -0700 Subject: [PATCH 052/269] try to get .env to work again. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 82701fedc8..bb8ab389e3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ /yarn-error.log .byebug_history + +.env From fee85d1176de2ff5e410e9505ebf81f5927ba6b5 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 18:20:36 -0700 Subject: [PATCH 053/269] finish basic controller and model testing for order_products. --- app/controllers/merchants_controller.rb | 2 +- app/controllers/order_products_controller.rb | 9 +- app/models/order_product.rb | 3 + .../order_products_controller_test.rb | 84 +++++++------------ test/fixtures/products.yml | 6 +- test/models/order_product_test.rb | 21 +++++ 6 files changed, 67 insertions(+), 58 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 24535109c5..707cec0804 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -2,7 +2,7 @@ class MerchantsController < ApplicationController before_action :find_id_by_params, except: [:index, :new, :create, :logout] before_action :must_be_logged_in, only: [:index] - + def index @merchants = Merchant.all end diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 11e5db37eb..f267a1d3e5 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -7,11 +7,16 @@ def create @order = order.id session[:cart] = order.id end + @product = Product.find_by(id: params[:product_id]) @order_product = OrderProduct.new(quantity: params[:quantity], product_id: params[:product_id], order_id: @order) - @order_product.save + if save_and_flash(@order_product, edit:"created") + #I don't think these flash messages are what we want, but I can't test it, so its staying like this for awhile - redirect_to order_path(@order) + redirect_to order_path(@order) + else + render "products/show", status: :bad_request + end # redirect_to orders_path end diff --git a/app/models/order_product.rb b/app/models/order_product.rb index 85b356ece1..b4ab831257 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -1,4 +1,7 @@ class OrderProduct < ApplicationRecord belongs_to :order belongs_to :product + + validates :quantity, numericality: { less_than_or_equal_to: 5, greater_than_or_equal_to: 1} + end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index d0d2dadda0..2c2aa0f036 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -7,66 +7,46 @@ product_id: products(:tricycle).id, quantity: 1 } + 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 an OrderProduct with a product and an order, adds to existin cart if it has already been initiated" do + product_params = { + product_id: products(:tricycle).id, + quantity: 1 + } + 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 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 + end + + it "wont create if input is invalid" do + product_params = { + product_id: products(:tricycle).id, + quantity: 0 + } + start_count = OrderProduct.count + + post create_order_product_path, params: product_params + must_respond_with :bad_request + + OrderProduct.count.must_equal start_count end - # it "renders bad_request and does not update the DB for invalid merchant data" do - # invalid_merchant_data = { - # merchant: { - # username: "", - # email: "" - # } - # } - # - # start_count = Merchant.count - # - # post merchants_path, params: invalid_merchant_data - # must_respond_with :bad_request - # - # Merchant.count.must_equal start_count - # end - # - # - # it "renders 400 bad_request for invalid email entries" do - # invalid_email = { - # merchant: { - # username: "namename", - # email: "name" - # } - # } - # - # invalid_email_2 = { - # merchant: { - # username: "namename", - # email: "name@" - # } - # } - # - # invalid_email_3 = { - # merchant: { - # username: "namename", - # email: "name@name." - # } - # } - # - # start_count = Merchant.count - # - # post merchants_path, params: invalid_email - # must_respond_with :bad_request - # - # post merchants_path, params: invalid_email_2 - # must_respond_with :bad_request - # - # post merchants_path, params: invalid_email_3 - # must_respond_with :bad_request - # - # Merchant.count.must_equal start_count - # end end end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 9238abfe61..592a9384fe 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -15,8 +15,8 @@ tricycle: name: tricycle description: "A fun toy!" merchant: anders - inventory: 2 - photo_url: www.fillmurray.com + inventory: 3 + # photo_url: "www.fillmurray.com" price: 2.40 tripod: @@ -24,5 +24,5 @@ tripod: description: "Good for cameras" merchant: lauren inventory: 4 - photo_url: www.fillmurray.com + # photo_url: www.fillmurray.com price: 12.56 diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index b6ae7fd8a2..b9d81b9e38 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -2,6 +2,9 @@ describe OrderProduct do let (:op) { order_products(:one) } + let (:order) { orders(:order1) } + let (:product) { products(:tricycle)} + describe "relationships" do it "has an order" do op.must_respond_to :order @@ -13,4 +16,22 @@ op.product.must_be_kind_of Product end end + + describe "vaildations" do + it "works with a number between 1-5" do + (1..5).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 From 700f2d44fe8afddb4f0f8141a93d736e70ba01d6 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 18:38:24 -0700 Subject: [PATCH 054/269] change inventory from string to integer for math reasons --- app/controllers/order_products_controller.rb | 2 +- app/models/order_product.rb | 1 + app/models/product.rb | 3 +++ .../20171020013202_change_product_inventory_to_integer.rb | 6 ++++++ db/schema.rb | 4 ++-- test/controllers/order_products_controller_test.rb | 2 ++ 6 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20171020013202_change_product_inventory_to_integer.rb diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index f267a1d3e5..0e2923bb16 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -9,9 +9,9 @@ def create end @product = Product.find_by(id: params[:product_id]) @order_product = OrderProduct.new(quantity: params[:quantity], product_id: params[:product_id], order_id: @order) - if save_and_flash(@order_product, edit:"created") #I don't think these flash messages are what we want, but I can't test it, so its staying like this for awhile + @product.decrease_inventory(params[:quantity]) redirect_to order_path(@order) else diff --git a/app/models/order_product.rb b/app/models/order_product.rb index b4ab831257..fcc6a30b2c 100644 --- a/app/models/order_product.rb +++ b/app/models/order_product.rb @@ -4,4 +4,5 @@ class OrderProduct < ApplicationRecord validates :quantity, numericality: { less_than_or_equal_to: 5, greater_than_or_equal_to: 1} + end diff --git a/app/models/product.rb b/app/models/product.rb index 002cb685c6..009416efae 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -9,4 +9,7 @@ class Product < ApplicationRecord validates :name, presence: true, uniqueness: true + def decrease_inventory(quantity) + self.inventory -= quantity + 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/schema.rb b/db/schema.rb index c2e3eb01a6..ebf444d0c9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171019005522) do +ActiveRecord::Schema.define(version: 20171020013202) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -50,7 +50,7 @@ t.string "name" t.text "description" t.integer "merchant_id" - t.string "inventory" + t.integer "inventory" t.string "photo_url" t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index 2c2aa0f036..242fd94f92 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -9,12 +9,14 @@ } orders_start = Order.count start_count = OrderProduct.count + inventory = products(:tricycle).inventory 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 + products(:tricycle).inventory.must_equal inventory - 1 end it "creates an OrderProduct with a product and an order, adds to existin cart if it has already been initiated" do From da35a0ea17eda8e3bda42f9f85ad1555271b3797 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Thu, 19 Oct 2017 18:57:28 -0700 Subject: [PATCH 055/269] Add stars styling to reviews. Add average_rating method to Products model --- app/assets/stylesheets/application.css | 28 ++++++++++ app/controllers/merchants_controller.rb | 73 ++++++++++++++++++------- app/helpers/application_helper.rb | 16 ++++++ app/models/product.rb | 16 ++++++ app/views/layouts/_stars.html.erb | 5 ++ app/views/products/show.html.erb | 30 ++++++++-- app/views/reviews/new.html.erb | 13 ++++- 7 files changed, 152 insertions(+), 29 deletions(-) create mode 100644 app/views/layouts/_stars.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a152282fce..0ec84dc4c9 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,3 +15,31 @@ *= require foundation_and_overrides */ + + /***********/ + /* 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; + } diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 3191bd2f6b..4fd50d7a9f 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,7 +1,6 @@ class MerchantsController < ApplicationController - before_action :find_id_by_params, except: [:index, :new, :create, :logout] - before_action :must_be_logged_in, only: [:index] +before_action :find_id_by_params, except: [:index, :new, :create, :logout] def index @merchants = Merchant.all @@ -34,11 +33,26 @@ def create redirect_to products_path end + # def create + # @merchant = Merchant.new(merchant_params) + # # @merchant.id = session[:merchant_id] + # if @merchant.save + # # @merchant = session[:merchant_id] + # flash[:status] = :success + # flash[:result_text] = "Successfully created: #{@merchant.username}" + # redirect_to merchant_path(@merchant.id) + # else + # flash[:status] = :failure + # flash[:result_text] = "Could not create new merchant" + # flash[:messages] = @merchant.errors.messages + # render :new, status: :bad_request + # end + # end + def logout session[:merchant_id] = nil flash[:status] = :success flash[:message] = "You have been logged out" - session[:cart] = nil redirect_to products_path end @@ -55,31 +69,31 @@ def update # flash[:result_text] = "Only the merchant has permission to do this" # redirect_to root_path # else - @merchant.update_attributes(merchant_params) - if @merchant.save - flash[:status] = :success - flash[:result_text] = "Successfully updated" - redirect_to merchant_path(@merchant) - else - flash.now[:status] = :failure - flash.now[:result_text] = "Could not update" - flash.now[:messages] = @merchant.errors.messages - render :edit, status: :not_found + @merchant.update_attributes(merchant_params) + if @merchant.save + flash[:status] = :success + flash[:result_text] = "Successfully updated" + redirect_to merchant_path(@merchant) + else + flash.now[:status] = :failure + flash.now[:result_text] = "Could not update" + flash.now[:messages] = @merchant.errors.messages + render :edit, status: :not_found + end end - end - def destroy + def destroy # if @merchant.id != session[:merchant_id] # flash[:status] = :failure # flash[:result_text] = "Only the merchant has permission to delete" # redirect_to root_path # else - @merchant.destroy - flash[:status] = :success - flash[:result_text] = "Successfully deleted" - # redirect_to root_path - redirect_to merchants_path - end + @merchant.destroy + flash[:status] = :success + flash[:result_text] = "Successfully deleted" + # redirect_to root_path + redirect_to merchants_path + end private @@ -94,4 +108,21 @@ def find_id_by_params end end + def save_and_flash(model) + result = model.save + + if result + puts "result: #{result}" + flash[:status] = :success + flash[:message] = "Successfully saved #{model.class} #{model.name}" + else + flash.now[:status] = :failure + flash.now[:message] = "Failed to save #{model.class}" + flash.now[:details] = model.errors.messages + end + + puts "In save_and_flash: Result: #{result}" + + return result + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945c..396689e00f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,18 @@ 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 end diff --git a/app/models/product.rb b/app/models/product.rb index 002cb685c6..688928e82c 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -9,4 +9,20 @@ class Product < ApplicationRecord validates :name, presence: true, uniqueness: true + 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/views/layouts/_stars.html.erb b/app/views/layouts/_stars.html.erb new file mode 100644 index 0000000000..83b8ba4247 --- /dev/null +++ b/app/views/layouts/_stars.html.erb @@ -0,0 +1,5 @@ + + <%= '★' * rating %><%= '☆' * (5 - rating) %> + diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index e53326e6fe..0bef9f8821 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,7 +1,23 @@ -

Show page for Individual Product!

-

Name: <%= @product.name %>

-

Description: <%= @product.description %>

-

Price: $<%= '%.2f' % @product.price %>

+

Show page for Individual Product!

+ +
+

+ Name: + <%= @product.name %> +

+

+ Description: + <%= @product.description %> +

+

+ Price: $ + <%= '%.2f' % @product.price %> +

+

+ Average rating: + <%= render partial:"/layouts/stars", locals: {rating: @product.average_rating} %> +

+

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

@@ -14,9 +30,11 @@
-

Reviews: <% @product.reviews.each do |review| %>

+

Reviews: + <% @product.reviews.each do |review| %> +

<%= review.text %> -<%= review.rating %> +<%= render partial:"/layouts/stars", locals: {rating: review.rating} %> <% end %> diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb index 9edfb6eafd..a6f915118c 100644 --- a/app/views/reviews/new.html.erb +++ b/app/views/reviews/new.html.erb @@ -1,8 +1,17 @@

Write a new Review:

<%= form_for @review do |f| %> -<%= f.label :rating, "Rating 1-5" %> -<%= f.select :rating, [1,2,3,4,5] %> +<% 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 %> From 6496f35028cd40d0980abf3c7929844e2a9ed7b2 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Thu, 19 Oct 2017 19:21:01 -0700 Subject: [PATCH 056/269] Add test for #average_rating in Product Model, and test for #logout in MerchantsController --- app/controllers/merchants_controller.rb | 16 ---------- test/controllers/merchants_controller_test.rb | 21 ++++++------ test/fixtures/reviews.yml | 10 ++++++ test/models/product_test.rb | 32 +++++++++++++++++++ 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 4fd50d7a9f..750c8fcab8 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -33,22 +33,6 @@ def create redirect_to products_path end - # def create - # @merchant = Merchant.new(merchant_params) - # # @merchant.id = session[:merchant_id] - # if @merchant.save - # # @merchant = session[:merchant_id] - # flash[:status] = :success - # flash[:result_text] = "Successfully created: #{@merchant.username}" - # redirect_to merchant_path(@merchant.id) - # else - # flash[:status] = :failure - # flash[:result_text] = "Could not create new merchant" - # flash[:messages] = @merchant.errors.messages - # render :new, status: :bad_request - # end - # end - def logout session[:merchant_id] = nil flash[:status] = :success diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index e82df5419e..16fe6fb166 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -31,20 +31,11 @@ end it "creates an account for a new merchant and redirects to the products route" do - # Merchant.destroy_all start_count = Merchant.count - - # merchant = merchants(:anders) - - merchant = Merchant.new(provider: "github", uid: 123124564, username: "test_merchant", email: "test@merchant.com", name: "trio") - - puts "merchant: provider: #{merchant.provider}, uid: #{merchant.uid}" + merchant = Merchant.new(provider: "github", uid: 123124564, username: "test_merchant", email: "test@merchant.com", name: "trio") login(merchant) - puts "merchant: provider: #{merchant.provider}, uid: #{merchant.uid}" - - must_redirect_to products_path flash[:status].must_equal :success @@ -67,6 +58,16 @@ end end + describe "logout" do + it "succeeds, redirects to products_path, sets flash[:status] to success and session[:merchant_id] 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 + end + end + describe "index" do it "succeeds when there are merchants" do Merchant.count.must_be :>, 0, "No merchants in the test fixtures" diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml index b3c5dd49b7..77e1535d6b 100644 --- a/test/fixtures/reviews.yml +++ b/test/fixtures/reviews.yml @@ -12,5 +12,15 @@ review1: rating: 1 + text: "Terrible" + product_id: 1 + +review2: + rating: 4 + text: "Great" + product_id: 1 + +review3: + rating: 5 text: "A hit!" product_id: 1 diff --git a/test/models/product_test.rb b/test/models/product_test.rb index ee122e471c..6591ac9406 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -50,4 +50,36 @@ end 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 + product = Product.first + + product.average_rating.must_equal 0 + end + end + end From 0db5d48618163d1c66d0a40024e1797f3c3339ad Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Thu, 19 Oct 2017 20:39:59 -0700 Subject: [PATCH 057/269] Clean up some comments --- app/controllers/application_controller.rb | 2 +- app/views/layouts/_stars.html.erb | 4 +- test/controllers/products_controller_test.rb | 253 ++++++++++--------- test/fixtures/products.yml | 4 +- 4 files changed, 135 insertions(+), 128 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b9b022e3d2..8dbe2fe339 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -34,7 +34,7 @@ def must_be_logged_in def must_be_merchant_of_product if session[:merchant_id] != @product.merchant_id - lash[:status] = :failure + flash[:status] = :failure flash[:message] = "You must be the owner of this product to do that!" redirect_to products_path end diff --git a/app/views/layouts/_stars.html.erb b/app/views/layouts/_stars.html.erb index 83b8ba4247..23d58bfa19 100644 --- a/app/views/layouts/_stars.html.erb +++ b/app/views/layouts/_stars.html.erb @@ -1,5 +1,3 @@ - + <%= '★' * rating %><%= '☆' * (5 - rating) %> diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 58bb7023a9..d1ce936851 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -30,146 +30,155 @@ end end - describe "new" do - it "creates a new product successfully" do - get new_product_path - must_respond_with :success - end - # need to write test for when new is not allowed (not merchant_id) - end - - describe "create" do - it "saves and redirects to products_path when the product data is valid" do + describe "logged in merchants" do + before do merchant = Merchant.first login(merchant) - product_data = { - product: { - name: "book", - price: 4.32, - merchant_id: merchant.id - } - } - product = Product.new(product_data[:product]) - 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 - # product_data = { - # product: { - # name: "book", - # price: 1, - # merchant: merchants(:anders) - # } - # } - # - # Product.new(product_data[: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.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 - # need to write test for when create is not allowed (not merchant_id) - 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 + describe "new" do + it "creates a new product successfully" do + get new_product_path + must_respond_with :success + end end - # need to write test for when edit is not allowed (not merchant_id) - end - describe "update" do - it "returns success when change is valid" do - # charles says we need to log in to make this test pass - merchant = Merchant.first - login(merchant) - product = Product.first - product_data = { - product: { - name: "book", - price: 4.32, + 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, + merchant: merchants(:anders) + } } - } - 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 = Product.new(product_data[:product]) + 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 - product.reload - product.name.must_equal product_data[:product][:name] + must_respond_with :bad_request + Product.count.must_equal start_product_count + end 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 + 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 - it "returns bad_request when change is invalid" do - product = Product.first - bad_product_data = { - product: { - name: "" + describe "update" do + it "returns success when change is valid" do + product = Product.first + product_data = { + product: { + name: "book", + price: 4.32, + } + } + 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 + 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 - # need to write test for when update is not allowed (not merchant_id) + 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 + end end - describe "destroy" do - it "success when product is deleted" do - product_count = Product.count - delete product_path(Product.first) - must_respond_with :redirect - must_redirect_to products_path - product_count.must_equal Product.count + 1 + describe "not logged in users" do + 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 + must_respond_with :redirect + must_redirect_to products_path + end end - # need to write test for when destroy is not allowed (not merchant_id) + 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 end end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 9238abfe61..85a01c53cb 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -16,7 +16,7 @@ tricycle: description: "A fun toy!" merchant: anders inventory: 2 - photo_url: www.fillmurray.com + 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 tripod: @@ -24,5 +24,5 @@ tripod: description: "Good for cameras" merchant: lauren inventory: 4 - photo_url: www.fillmurray.com + 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 From adea105f3da83bfea5c0e79903ff7664bae6e140 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 20:41:19 -0700 Subject: [PATCH 058/269] fixed tests --- app/controllers/application_controller.rb | 2 +- test/controllers/merchants_controller_test.rb | 9 ++++- test/controllers/products_controller_test.rb | 12 ++++-- test/controllers/reviews_controller_test.rb | 38 +++++++++---------- test/fixtures/products.yml | 4 +- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b9b022e3d2..8dbe2fe339 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -34,7 +34,7 @@ def must_be_logged_in def must_be_merchant_of_product if session[:merchant_id] != @product.merchant_id - lash[:status] = :failure + flash[:status] = :failure flash[:message] = "You must be the owner of this product to do that!" redirect_to products_path end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index e82df5419e..83302fca1f 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -36,9 +36,9 @@ # merchant = merchants(:anders) - merchant = Merchant.new(provider: "github", uid: 123124564, username: "test_merchant", email: "test@merchant.com", name: "trio") + merchant = Merchant.new(provider: "github", uid: 123124564, username: "test_merchant", email: "test@merchant.com", name: "trio") - puts "merchant: provider: #{merchant.provider}, uid: #{merchant.uid}" + puts "merchant: provider: #{merchant.provider}, uid: #{merchant.uid}" login(merchant) @@ -69,12 +69,17 @@ describe "index" do it "succeeds when there are merchants" do + merchant = merchants(:anders) + login(merchant) + 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 = merchants(:anders) + login(merchant) Merchant.destroy_all get merchants_path must_respond_with :success diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index 58bb7023a9..46516aded6 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -32,6 +32,8 @@ describe "new" do it "creates a new product successfully" do + merchant = merchants(:anders) + login(merchant) get new_product_path must_respond_with :success end @@ -163,11 +165,15 @@ describe "destroy" do it "success when product is deleted" do - product_count = Product.count - delete product_path(Product.first) + merchant = merchants(:anders) + login(merchant) + product = Product.first + # product_count = Product.count + delete product_path(product) must_respond_with :redirect must_redirect_to products_path - product_count.must_equal Product.count + 1 + Product.find_by(id: product.id).must_be_nil + # product_count.must_equal Product.count + 1 end # need to write test for when destroy is not allowed (not merchant_id) diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index 8f873321a1..79538f960c 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -15,7 +15,7 @@ # BOTH create tests need :product_id! HOW DO WE PASS IN? it "saves and redirects to product show page when the review data is valid" do - product = Product.first + product = Product.first review_data = { review: { rating: 3, @@ -34,24 +34,24 @@ end - # it "renders a bad_request when the review data is invalid" do - # product = Product.first - # bad_review = { - # review: { - # rating: "", - # product_id: product.id - # # no rating given!! - # } - # } - # product.reviews.new(bad_review[:review]).wont_be :valid? - # - # start_review_count = Review.count - # post reviews_path, params: bad_review - # - # must_respond_with :bad_request - # - # Review.count.must_equal start_review_count - # end + it "renders a bad_request when the review data is invalid" do + # don't know how to simulate an invalid review now that the 1-5 rating is a dropdown and there is no way the data could be bad anymore... + + # product = Product.first + # bad_review = { + # review: { + # rating: 1, + # product_id: product.id + # } + # } + # product.reviews.new(bad_review[:review]).wont_be :valid? + # + # start_review_count = Review.count + # post reviews_path, params: bad_review + # + # must_respond_with :bad_request + # Review.count.must_equal start_review_count + end # need to write test for when create is not allowed (not merchant_id) end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 9238abfe61..01e4e6725d 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -16,7 +16,7 @@ tricycle: description: "A fun toy!" merchant: anders inventory: 2 - photo_url: www.fillmurray.com + photo_url: http://www.fillmurray.com/g/200/300 price: 2.40 tripod: @@ -24,5 +24,5 @@ tripod: description: "Good for cameras" merchant: lauren inventory: 4 - photo_url: www.fillmurray.com + photo_url: http://www.fillmurray.com/200/300 price: 12.56 From 12ab298d893cab18781bfac5abbabdd483109ffd Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 19 Oct 2017 20:51:54 -0700 Subject: [PATCH 059/269] reviews controller tests --- test/controllers/reviews_controller_test.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index 79538f960c..f63dae6d8b 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -34,22 +34,25 @@ end - it "renders a bad_request when the review data is invalid" do + # it "renders a bad_request when the review data is invalid" do # don't know how to simulate an invalid review now that the 1-5 rating is a dropdown and there is no way the data could be bad anymore... - + it "doesn't allow a merchant to review their own product" do + # Except for if the user trying to review it is the merchant of the product. + # merchant = merchants(:anders) + # login(merchant) # product = Product.first - # bad_review = { + # anders_review = { # review: { # rating: 1, # product_id: product.id # } # } - # product.reviews.new(bad_review[:review]).wont_be :valid? + # product.reviews.new(anders_review[:review]).wont_be :valid? # # start_review_count = Review.count - # post reviews_path, params: bad_review + # post reviews_path, params: anders_review # - # must_respond_with :bad_request + # must_redirect_to products_path # Review.count.must_equal start_review_count end # need to write test for when create is not allowed (not merchant_id) From 48db96927c680a3a8dfc55923b0d4a9dad366a1a Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 21:13:09 -0700 Subject: [PATCH 060/269] add some quantity and inventory relationships and test for create order_product --- app/controllers/order_products_controller.rb | 32 ++++++++++----- app/controllers/orders_controller.rb | 2 + app/models/product.rb | 10 +++++ .../order_products_controller_test.rb | 40 +++++++++++++------ test/models/product_test.rb | 31 ++++++++++++++ 5 files changed, 91 insertions(+), 24 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 0e2923bb16..78ad0a5306 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -1,5 +1,26 @@ class OrderProductsController < ApplicationController def create + assign_order + @product = Product.find_by(id: params[:product_id]) + + quantity = params[:quantity].to_i + + if @product.check_inventory(quantity) + @order_product = OrderProduct.new(quantity: quantity, product_id: params[:product_id], order_id: @order) + if save_and_flash(@order_product, edit:"created") + redirect_to order_path(@order) + else + render "products/show", status: :bad_request + end + else + flash[:status] = :failure + flash[:message] = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." + render "products/show", status: :bad_request + end + end + +private + def assign_order if session[:cart] @order = session[:cart] else @@ -7,17 +28,6 @@ def create @order = order.id session[:cart] = order.id end - @product = Product.find_by(id: params[:product_id]) - @order_product = OrderProduct.new(quantity: params[:quantity], product_id: params[:product_id], order_id: @order) - if save_and_flash(@order_product, edit:"created") - #I don't think these flash messages are what we want, but I can't test it, so its staying like this for awhile - @product.decrease_inventory(params[:quantity]) - - redirect_to order_path(@order) - else - render "products/show", status: :bad_request - end - # redirect_to orders_path end end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index bdcb05da3f..9de1d5daba 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -22,6 +22,8 @@ def index def edit # edit is actually more like check_out + # @product.decrease_inventory(params[:quantity].to_i) + #when they check_out, test end def show diff --git a/app/models/product.rb b/app/models/product.rb index 009416efae..d1b1614762 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -9,6 +9,16 @@ class Product < ApplicationRecord validates :name, presence: true, uniqueness: true + + + def check_inventory(quantity) + if self.inventory >= quantity + return true + end + return false + end + + def decrease_inventory(quantity) self.inventory -= quantity end diff --git a/test/controllers/order_products_controller_test.rb b/test/controllers/order_products_controller_test.rb index 242fd94f92..a25d24f9bc 100644 --- a/test/controllers/order_products_controller_test.rb +++ b/test/controllers/order_products_controller_test.rb @@ -2,35 +2,35 @@ describe OrderProductsController do describe "create" do - it "creates an OrderProduct with a product and an order, creates a new order if no session[:cart] exists" do - product_params = { + before do + @product_params = { product_id: products(:tricycle).id, quantity: 1 } + end + + 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 - inventory = products(:tricycle).inventory - post create_order_product_path, params: product_params + 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 - products(:tricycle).inventory.must_equal inventory - 1 + end it "creates an OrderProduct with a product and an order, adds to existin cart if it has already been initiated" do - product_params = { - product_id: products(:tricycle).id, - quantity: 1 - } - post create_order_product_path, params: product_params + + 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 - post create_order_product_path, params: product_params + post create_order_product_path, params: @product_params must_redirect_to order_path(session[:cart]) OrderProduct.count.must_equal start_count + 1 @@ -38,17 +38,31 @@ end it "wont create if input is invalid" do - product_params = { + bad_product_params = { product_id: products(:tricycle).id, quantity: 0 } start_count = OrderProduct.count - post create_order_product_path, params: product_params + post create_order_product_path, params: bad_product_params must_respond_with :bad_request + flash[:message].must_equal "A problem occurred: Could not created OrderProduct" 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 end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index ee122e471c..1bcde94b74 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -50,4 +50,35 @@ end 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 "decrease_inventory" do + let(:tripod) { products(:tripod) } + it "decreases the inventory by the given quantity" 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 + end From 95f6f28644194008ee42f9d4b8d13861dfa8a3e1 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 19 Oct 2017 21:50:23 -0700 Subject: [PATCH 061/269] started some functionality for checkout, not finished --- app/controllers/order_products_controller.rb | 37 +++++++++++++++- app/controllers/orders_controller.rb | 15 +++++-- app/views/order_products/edit.html.erb | 14 +++++++ app/views/orders/checkout.html.erb | 44 ++++++++++++++++++++ app/views/orders/show.html.erb | 2 + config/routes.rb | 7 +++- 6 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 app/views/order_products/edit.html.erb create mode 100644 app/views/orders/checkout.html.erb diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 78ad0a5306..67ac82b098 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -1,4 +1,28 @@ class OrderProductsController < ApplicationController + before_action :find_op_by_params_id, only: [:edit, :update] + def edit + + end + + def update + @op.update_attributes(order_params) + + @product = Product.find_by(id: params[:product_id]) + quantity = params[:quantity].to_i + + if @product.check_inventory(quantity) + if save_and_flash(@order, edit:"updated") + redirect_to(order_path(@order)) + else + render :edit, status: :bad_request + end + else + flash.now[:status] = :failure + flash.now[:message] = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." + render "products/show", status: :bad_request + end + end + def create assign_order @product = Product.find_by(id: params[:product_id]) @@ -13,8 +37,8 @@ def create render "products/show", status: :bad_request end else - flash[:status] = :failure - flash[:message] = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." + flash[:status].now = :failure + flash[:message].now = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." render "products/show", status: :bad_request end end @@ -30,4 +54,13 @@ def assign_order end end + def order_params + return params.require(:order_product).permit(:quantity, :product_id) + end + + def find_op_by_params_id + @op = OrderProduct.find_by(id: params[:id]) + head :not_found unless @op + end + end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 9de1d5daba..8ec83c8fef 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,5 +1,5 @@ class OrdersController < ApplicationController - before_action :find_order_by_params_id, only: [:show, :edit, :update, :destroy] + before_action :find_order_by_params_id, only: [:show, :edit, :update, :destroy, :checkout] def index @orders = Order.all @@ -23,7 +23,7 @@ def index def edit # edit is actually more like check_out # @product.decrease_inventory(params[:quantity].to_i) - #when they check_out, test + #when they check_out, test end def show @@ -31,10 +31,13 @@ def show def update @order.update_attributes(order_params) - if save_and_flash(@order, edit:"updated") + if save_and_flash(@order, edit:"submitted") + @order.status = "paid" + session[:cart] = nil redirect_to(order_path(@order)) + # at some point this should be a reciept page of some kind else - render :edit, status: :bad_request + render :checkout, status: :bad_request end end @@ -43,6 +46,10 @@ def destroy redirect_to orders_path end + def checkout + + end + private def order_params return params.require(:order).permit(:status, :email, :mailing_address, :buyer_name, :card_number, :expiration, :cvv, :zipcode) 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 @@ +
    + <%= form_for @op do |f| %> +
  • + <%= f.label :quantity%> + <%= f.text_field :quantity%> +
  • +
  • + <%= f.hidden_field :product_id, value: params[:product_id] %> +
  • +
  • + <%= f.submit "Update", class:'button' %> +
  • + <% end %> +
diff --git a/app/views/orders/checkout.html.erb b/app/views/orders/checkout.html.erb new file mode 100644 index 0000000000..45097d7a04 --- /dev/null +++ b/app/views/orders/checkout.html.erb @@ -0,0 +1,44 @@ +

Enter Billing Information

+ +
    + <%= form_for @order do |f| %> +
  • + <%= f.label :email%> + <%= f.text_field :email%> +
  • + +
  • + <%= f.label :buyer_name %> + <%= f.text_field :buyer_name %> +
  • + +
  • + <%= f.label :mailing_address %> + <%= f.text_field :mailing_address %> +
  • + +
  • + <%= f.label :card_number %> + <%= f.text_field :card_number %> +
  • + +
  • + <%= f.label :expiration %> + <%= f.text_field :expiration %> +
  • + +
  • + <%= f.label :cvv %> + <%= f.text_field :cvv %> +
  • + +
  • + <%= f.label :zipcode %> + <%= f.text_field :zipcode %> +
  • + +
  • + <%= f.submit "Buy", class:'button' %> +
  • + <% end %> +
diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index fdfcfb7cde..ed40d67a0b 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -6,6 +6,7 @@ Product Quantity Cost + Edit @@ -14,6 +15,7 @@ <%= link_to op.product.name, product_path(op.product) %> <%= op.quantity %> <%= op.product.price %> + <%= link_to "Edit Quantity", edit_order_product_path(product_id: op.product_id), class:'button' %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 869bd05032..eaf5cc98a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,17 @@ 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 + resources :orders, only: [:index, :show, :edit, :update, :destroy] + + get 'order/:id/checkout', to: 'order#checkout', as: 'checkout' + resources :products do resources :reviews, only: [:new] end resources :reviews, only: [:create] resources :merchants + + resources :order_products, only: [:edit, :update] post '/order_products', to: 'order_products#create', as: 'create_order_product' get "/auth/:provider/callback", to: "merchants#create", as: 'auth_callback' From 935de813081fb0d721013ea5495adc262bb06507 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Fri, 20 Oct 2017 10:28:00 -0700 Subject: [PATCH 062/269] Fix end bug --- test/models/product_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 77d1e54fb5..d173689530 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -80,6 +80,8 @@ 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 From 7ba4a585c9124c0d4ebb783c46b8ab8773aed85e Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Fri, 20 Oct 2017 10:31:21 -0700 Subject: [PATCH 063/269] fix flash .now error --- app/controllers/order_products_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index 67ac82b098..f225138830 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -37,8 +37,8 @@ def create render "products/show", status: :bad_request end else - flash[:status].now = :failure - flash[:message].now = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." + flash.now[:status] = :failure + flash.now[:message] = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." render "products/show", status: :bad_request end end From 70169d37e9dfbfee4dba3de886ebcef2f1835791 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 20 Oct 2017 11:06:17 -0700 Subject: [PATCH 064/269] interesting path developments --- app/controllers/reviews_controller.rb | 14 +++++++- config/routes.rb | 2 +- test/controllers/reviews_controller_test.rb | 39 ++++++++++----------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 7b77fd48d0..77ef12d679 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -6,12 +6,15 @@ def new flash[:status] = :failure flash[:message] = "You cannot review your own product!" redirect_to products_path + return + else + @review = Review.new end - @review = Review.new end def create # @product = Product.find_by(id: params[:product_id]) + # cant_be_merchant @review = Review.new( review_params ) @@ -28,3 +31,12 @@ def create 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/config/routes.rb b/config/routes.rb index eaf5cc98a1..3039ce1e89 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ resources :products do resources :reviews, only: [:new] end - resources :reviews, only: [:create] + resources :reviews, only: [:new, :create] resources :merchants resources :order_products, only: [:edit, :update] diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index f63dae6d8b..8dd2394b0c 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -12,8 +12,6 @@ end describe "create" do - # BOTH create tests need :product_id! HOW DO WE PASS IN? - it "saves and redirects to product show page when the review data is valid" do product = Product.first review_data = { @@ -23,6 +21,7 @@ product_id: product.id } } + puts review_data[:review][:product_id] product.reviews.new(review_data[:review]).must_be :valid? start_review_count = Review.count @@ -35,25 +34,25 @@ # it "renders a bad_request when the review data is invalid" do - # don't know how to simulate an invalid review now that the 1-5 rating is a dropdown and there is no way the data could be bad anymore... + # what if the star is left blank... it "doesn't allow a merchant to review their own product" do - # Except for if the user trying to review it is the merchant of the product. - # merchant = merchants(:anders) - # login(merchant) - # product = Product.first - # anders_review = { - # review: { - # rating: 1, - # product_id: product.id - # } - # } - # product.reviews.new(anders_review[:review]).wont_be :valid? - # - # start_review_count = Review.count - # post reviews_path, params: anders_review - # - # must_redirect_to products_path - # Review.count.must_equal start_review_count + merchant = merchants(:anders) + login(merchant) + product = Product.find_by(merchant: merchant) + anders_review = { + review: { + rating: 1, + product_id: product.id + } + } + # Review.new(anders_review[:review]).wont_be :valid? + + 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 # need to write test for when create is not allowed (not merchant_id) end From 79ba1b9769e976df3048b0b5422543803b893ee2 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Fri, 20 Oct 2017 12:04:14 -0700 Subject: [PATCH 065/269] mess with quantity --- app/controllers/order_products_controller.rb | 29 ++++++++++---------- app/views/orders/show.html.erb | 9 +++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/controllers/order_products_controller.rb b/app/controllers/order_products_controller.rb index f225138830..2b0191384c 100644 --- a/app/controllers/order_products_controller.rb +++ b/app/controllers/order_products_controller.rb @@ -1,25 +1,24 @@ class OrderProductsController < ApplicationController - before_action :find_op_by_params_id, only: [:edit, :update] - def edit - - end - + # before_action :find_op_by_params_id, only: [:edit, :update] def update - @op.update_attributes(order_params) + @op = OrderProduct.find_by(id: params[:id]) @product = Product.find_by(id: params[:product_id]) quantity = params[:quantity].to_i + @op.quantity = quantity if @product.check_inventory(quantity) - if save_and_flash(@order, edit:"updated") - redirect_to(order_path(@order)) - else - render :edit, status: :bad_request - end + @op.save + # if save_and_flash(@op, edit:"updated") + # # redirect_to(order_path(@op.order)) + redirect_to root_path + # else + # render :edit, status: :bad_request + # end else flash.now[:status] = :failure flash.now[:message] = "Not enough #{@product.name.pluralize} in stock, please revise the quantity selected." - render "products/show", status: :bad_request + render "orders/show", status: :bad_request end end @@ -54,9 +53,9 @@ def assign_order end end - def order_params - return params.require(:order_product).permit(:quantity, :product_id) - end + # def order_params + # return params.require(:order_product).permit(:quantity, :product_id) + # end def find_op_by_params_id @op = OrderProduct.find_by(id: params[:id]) diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index ed40d67a0b..15d71e2077 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -15,7 +15,14 @@ <%= link_to op.product.name, product_path(op.product) %> <%= op.quantity %> <%= op.product.price %> - <%= link_to "Edit Quantity", edit_order_product_path(product_id: op.product_id), class:'button' %> + + <%= form_tag order_product_path(product_id: op.product_id), method: :patch do %> + + <%= text_field_tag "quantity" %> + + <%= submit_tag "Update Quantity", class: "button" %> + <% end %> + <% end %> From 62ea02d51e0e3dcf87838b3ef9cfcc2c99cb384d Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 20 Oct 2017 12:12:44 -0700 Subject: [PATCH 066/269] logout reset --- app/controllers/merchants_controller.rb | 1 + test/controllers/reviews_controller_test.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 8603e4b3c7..9d014313ea 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -36,6 +36,7 @@ def create def logout session[:merchant_id] = nil + session[:cart] = nil flash[:status] = :success flash[:message] = "You have been logged out" redirect_to products_path diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb index 8dd2394b0c..6072f8175d 100644 --- a/test/controllers/reviews_controller_test.rb +++ b/test/controllers/reviews_controller_test.rb @@ -39,12 +39,12 @@ merchant = merchants(:anders) login(merchant) product = Product.find_by(merchant: merchant) - anders_review = { - review: { - rating: 1, - product_id: product.id - } - } + # anders_review = { + # review: { + # rating: 1, + # product_id: product.id + # } + # } # Review.new(anders_review[:review]).wont_be :valid? start_review_count = Review.count From e2cff49582e5ee065b7ae50af16d6765074fb9ed Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 20 Oct 2017 12:31:00 -0700 Subject: [PATCH 067/269] join table --- app/models/category.rb | 3 +++ app/models/product.rb | 2 ++ db/migrate/20171020192401_create_categories.rb | 9 +++++++++ db/schema.rb | 13 ++++++++++++- test/fixtures/categories.yml | 11 +++++++++++ test/models/category_test.rb | 9 +++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/models/category.rb create mode 100644 db/migrate/20171020192401_create_categories.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..f3218758f1 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,3 @@ +class Category < ApplicationRecord + has_and_belongs_to_many :products +end diff --git a/app/models/product.rb b/app/models/product.rb index 4d985ecfee..7d6895f1f4 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -2,6 +2,8 @@ class Product < ApplicationRecord has_many :order_products has_many :reviews + has_and_belongs_to_many :categories + belongs_to :merchant 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/schema.rb b/db/schema.rb index ebf444d0c9..add5810568 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,22 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171020013202) do +ActiveRecord::Schema.define(version: 20171020192401) 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" diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,11 @@ +# 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 diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..781320ad8e --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Category do + let(:category) { Category.new } + + it "must be valid" do + value(category).must_be :valid? + end +end From 0c8b34c1d6c746f271421746813ca35a0a843207 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Fri, 20 Oct 2017 13:58:16 -0700 Subject: [PATCH 068/269] get the cart to take you to the current order --- app/views/layouts/application.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1de3b9fa58..10adeadc08 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,7 +28,7 @@ <%= link_to "View all merchants", merchants_path, class: "button" %> <% end %>
- <%= link_to products_path do %> + <%= link_to session[:cart] ? order_path(session[:cart]) : products_path do %> <%= image_tag 'cart.png', size: "40x40" %> <% end %> From 6e26aaecb2d9c863a52a0bbd6f0ae039bf9d48b8 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 20 Oct 2017 14:01:16 -0700 Subject: [PATCH 069/269] categories --- app/assets/javascripts/categories.js | 2 ++ app/assets/stylesheets/categories.scss | 3 ++ app/controllers/categories_controller.rb | 12 ++++++++ app/controllers/products_controller.rb | 2 +- app/helpers/categories_helper.rb | 2 ++ app/models/category.rb | 1 + app/views/products/_form.html.erb | 28 +++++++++---------- config/routes.rb | 5 ++++ .../controllers/categories_controller_test.rb | 7 +++++ 9 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 app/assets/javascripts/categories.js create mode 100644 app/assets/stylesheets/categories.scss create mode 100644 app/controllers/categories_controller.rb create mode 100644 app/helpers/categories_helper.rb create mode 100644 test/controllers/categories_controller_test.rb 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/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..42976cbc11 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..6be7d6bea1 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,12 @@ +class CategoriesController < ApplicationController + def index + @categories = Category.all + end + + def new + + end + + def create + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 421abd1bfb..360636a2a6 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -52,7 +52,7 @@ def destroy private def product_params - return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url) + return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url, :category) end def find_product 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/models/category.rb b/app/models/category.rb index f3218758f1..68960db28e 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,4 @@ class Category < ApplicationRecord has_and_belongs_to_many :products + end diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index 88ae48a6ee..fce55b31c0 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -1,21 +1,21 @@ - <%= form_for @product do |f| %> - <%= f.label :name %> - <%= f.text_field :name %> +<%= 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 :description %> +<%= f.text_area :description %> - <%= f.label :price %> - <%= f.text_field :price %> +<%= f.label :price %> +<%= f.text_field :price %> - <%= f.label :inventory %> - <%= f.text_field :inventory %> +<%= f.label :inventory %> +<%= f.text_field :inventory %> - <%= f.label :photo_url %> - <%= f.text_field :photo_url %> +<%= f.label :photo_url %> +<%= f.text_field :photo_url %> - - <% end %> + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 3039ce1e89..2e23d4e916 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,4 +16,9 @@ get "/auth/:provider/callback", to: "merchants#create", as: 'auth_callback' get '/logout', to: 'merchants#logout', as: 'logout' + + resources :categories do + # get '/products', to: 'products#index' + resources :products, only: [:index, :new, :create] + end end diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000000..125dd4c91d --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe CategoriesController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From 4593a4b4cd14666853693ddfbe8b74d0fa23bcb5 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Fri, 20 Oct 2017 14:36:02 -0700 Subject: [PATCH 070/269] add must-be-logged-in to merchant show, and tests for index and show about being logged in. --- app/controllers/merchants_controller.rb | 17 ++-- test/controllers/merchants_controller_test.rb | 87 ++++++++++++------- 2 files changed, 66 insertions(+), 38 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 9d014313ea..aef8ee3554 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,7 +1,7 @@ class MerchantsController < ApplicationController before_action :find_id_by_params, except: [:index, :new, :create, :logout] - before_action :must_be_logged_in, only: [:index] + before_action :must_be_logged_in, only: [:index, :show] def index @merchants = Merchant.all @@ -43,7 +43,12 @@ def logout end def show - @merchant = Merchant.find_by(id: params[:id]) + if @merchant.id != session[:merchant_id] + flash[:status] = :success + flash[:message] = "You can only see your own details" + redirect_to merchant_path(session[:merchant_id]) + end + end def edit @@ -58,12 +63,12 @@ def update @merchant.update_attributes(merchant_params) if @merchant.save flash[:status] = :success - flash[:result_text] = "Successfully updated" + flash[:message] = "Successfully updated" redirect_to merchant_path(@merchant) else flash.now[:status] = :failure - flash.now[:result_text] = "Could not update" - flash.now[:messages] = @merchant.errors.messages + flash.now[:message] = "Could not update" + flash.now[:details] = @merchant.errors.messages render :edit, status: :not_found end end @@ -76,7 +81,7 @@ def destroy # else @merchant.destroy flash[:status] = :success - flash[:result_text] = "Successfully deleted" + flash[:message] = "Successfully deleted" # redirect_to root_path redirect_to merchants_path end diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 99ab51855e..b232890c9e 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -1,8 +1,60 @@ require "test_helper" describe MerchantsController do + describe "for logged in user" 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 "only shows merchant their own page" do + get merchant_path(merchants(:lauren)) + must_redirect_to merchant_path(@merchant) + flash[:message].must_equal "You can only see your own details" + 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 + end + end + + describe "non logged in user" do + it "show fails for a non-logged in user" do + get merchant_path(merchants(:anders)) + must_redirect_to products_path + flash[:message].must_equal "You must be logged in to do that!" + end + + it "index fails for a non-logged in user" do + get merchants_path + must_redirect_to products_path + flash[:message].must_equal "You must be logged in to do that!" + end + end - describe "auth_callback" do + 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 @@ -61,33 +113,17 @@ end describe "logout" do - it "succeeds, redirects to products_path, sets flash[:status] to success and session[:merchant_id] to nil" 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 - describe "index" do - it "succeeds when there are merchants" do - merchant = merchants(:anders) - login(merchant) - - 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 = merchants(:anders) - login(merchant) - Merchant.destroy_all - get merchants_path - must_respond_with :success - end - end describe "new" do it "works" do @@ -167,19 +203,6 @@ # end # end - describe "show" do - it "succeeds for an extant merchant ID" do - get merchant_path(Merchant.first) - 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 - end - describe "edit" do it "succeeds for an extant merchant ID" do get edit_merchant_path(Merchant.first) From e055ab2a8da0d13380bea622b40ea3504007dbb4 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Fri, 20 Oct 2017 14:37:35 -0700 Subject: [PATCH 071/269] categories --- app/controllers/categories_controller.rb | 16 +++++++++++++++- app/models/category.rb | 4 +++- app/views/categories/new.html.erb | 9 +++++++++ app/views/layouts/application.html.erb | 1 + app/views/products/index.html.erb | 16 +++++++++++----- db/seeds.rb | 6 ------ 6 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 app/views/categories/new.html.erb diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 6be7d6bea1..d5f10f298d 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -4,9 +4,23 @@ def index end def new - + @category = Category.new end def create + @category = Category.new(category_params) + + if save_and_flash(@category, edit: "created", save: @category.save ) + redirect_to products_path + return + else + render :new, status: :bad_request + end + end + + private + + def category_params + return params.require(:category).permit(:name) end end diff --git a/app/models/category.rb b/app/models/category.rb index 68960db28e..c2cddda7a3 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,6 @@ class Category < ApplicationRecord has_and_belongs_to_many :products - + + validates :name, presence: {message: "Please enter a category name"} + end diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000000..3c23b1b827 --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,9 @@ +
+ <%= form_for @category do |f| %> + + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.submit class: "button" %> + <% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1de3b9fa58..24f4675284 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -27,6 +27,7 @@ <% unless session[:merchant_id] == nil %> <%= link_to "View all merchants", merchants_path, class: "button" %> <% end %> + <%= link_to "Create new category", new_category_path, class: "button "%>
<%= link_to products_path do %> <%= image_tag 'cart.png', size: "40x40" %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 770582eee4..3884c00d5d 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,15 +1,21 @@

All Products

+

Categories:

-<% @products.each do |product| %> +<% Category.all.each do |category| %> + <%= category.name %> + +<%= category.product_ids %> +<% category.product_ids.each do |prod| %>
-

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

-

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

-

Description: <%= product.description %>

-

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

+

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

+

Price: $<%= '%.2f' % prod.price %>

+

Description: <%= prod.description %>

+

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


<% end %> +<% end %> <%= link_to "Add a Product", new_product_path, class: "button" %> diff --git a/db/seeds.rb b/db/seeds.rb index 440764dc6d..1beea2accd 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,9 +5,3 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) - -Merchant.create(username: "anders", email: "anders@tricycle.com") - -Merchant.create(username: "lauren", email: "lauren@tricycle.com") - -Merchant.create(username: "bennett", email: "bennett@tricycle.com") From 253d0ea15bfcf722c0e0598aea1a940d0ebbbea8 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Fri, 20 Oct 2017 15:06:17 -0700 Subject: [PATCH 072/269] display categories on product show page --- app/controllers/products_controller.rb | 2 +- app/models/product.rb | 2 ++ app/views/products/_form.html.erb | 2 +- app/views/products/index.html.erb | 36 ++++++++++++++------------ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 360636a2a6..1b65d6e3ac 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -52,7 +52,7 @@ def destroy private def product_params - return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url, :category) + return params.require(:product).permit(:name, :description, :price, :inventory, :photo_url, :category_ids => []) end def find_product diff --git a/app/models/product.rb b/app/models/product.rb index 7d6895f1f4..c7871e70a8 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,6 +11,8 @@ class Product < ApplicationRecord validates :name, presence: true, uniqueness: true + validates :inventory, presence: true, numericality:{greater_than_or_equal_to: 0} + def check_inventory(quantity) if self.inventory >= quantity return true diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb index fce55b31c0..ccc9202f80 100644 --- a/app/views/products/_form.html.erb +++ b/app/views/products/_form.html.erb @@ -12,7 +12,7 @@ <%= f.text_field :price %> <%= f.label :inventory %> -<%= f.text_field :inventory %> +<%= f.text_field :inventory, :value => 1 %> <%= f.label :photo_url %> <%= f.text_field :photo_url %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index 3884c00d5d..c4e6e11089 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,21 +1,25 @@

All Products

-

Categories:

-<% Category.all.each do |category| %> - <%= category.name %> - -<%= category.product_ids %> -<% category.product_ids.each do |prod| %> -
-

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

-

Price: $<%= '%.2f' % prod.price %>

-

Description: <%= prod.description %>

-

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

- -
-
-<% end %> -<% end %> + <% Category.all.each do |category| %> +

<%= category.name %>

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

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

+

Price: $ + <%= '%.2f' % prod.price %> +

+

Description: + <%= prod.description %> +

+

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

+
+
+ <% end %> + <% end %> <%= link_to "Add a Product", new_product_path, class: "button" %> From 939472a361c1104b11c8f928c9bb302177cbd1a3 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 20 Oct 2017 15:12:00 -0700 Subject: [PATCH 073/269] unique category validate --- app/models/category.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/category.rb b/app/models/category.rb index c2cddda7a3..57bc714b93 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,6 +1,6 @@ class Category < ApplicationRecord has_and_belongs_to_many :products - validates :name, presence: {message: "Please enter a category name"} + validates :name, presence: {message: "Please enter a category name"}, uniqueness: true end From 8e7735a66f911affa716f659806ec533afe8a48f Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 20 Oct 2017 16:00:26 -0700 Subject: [PATCH 074/269] tests --- app/controllers/products_controller.rb | 13 ++++++------- app/models/product.rb | 2 ++ test/controllers/categories_controller_test.rb | 2 ++ test/controllers/products_controller_test.rb | 3 ++- test/fixtures/categories.yml | 16 +++++++++++----- test/models/category_test.rb | 16 +++++++++++++--- test/models/product_test.rb | 3 ++- 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 1b65d6e3ac..b6e6c5c340 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -19,13 +19,12 @@ def create product_params ) @product.merchant_id = session[:merchant_id] - - if save_and_flash(@product, edit: "created", save: @product.save ) - redirect_to products_path - return - else - render :edit, status: :bad_request - end + if save_and_flash(@product, edit: "created", save: @product.save ) + redirect_to products_path + return + else + render :edit, status: :bad_request + end end def edit ; end diff --git a/app/models/product.rb b/app/models/product.rb index c7871e70a8..dbb91c7475 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -13,6 +13,8 @@ class Product < ApplicationRecord 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 diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb index 125dd4c91d..54523ba271 100644 --- a/test/controllers/categories_controller_test.rb +++ b/test/controllers/categories_controller_test.rb @@ -4,4 +4,6 @@ # it "must be a real test" do # flunk "Need real tests" # end + + # describe all methods index new create end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb index e7d4026db8..89d6824668 100644 --- a/test/controllers/products_controller_test.rb +++ b/test/controllers/products_controller_test.rb @@ -100,6 +100,7 @@ product: { name: "book", price: 4.32, + category_ids: Category.first.id } } product.update_attributes(product_data[:product]) @@ -184,7 +185,7 @@ # must_redirect_to products_path # Product.find_by(id: product.id).must_be_nil # # product_count.must_equal Product.count + 1 - + describe "destroy" do it "will set flash[:status] to failure and redirect to products_path" do delete product_path(Product.first) diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml index dc3ee79b5d..6678e967a8 100644 --- a/test/fixtures/categories.yml +++ b/test/fixtures/categories.yml @@ -3,9 +3,15 @@ # 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: {} +# # +# one: {} +# # column: value +# # +# two: {} # column: value + +book: + name: book + +movie: + name: movie diff --git a/test/models/category_test.rb b/test/models/category_test.rb index 781320ad8e..f6c3e68f1b 100644 --- a/test/models/category_test.rb +++ b/test/models/category_test.rb @@ -1,9 +1,19 @@ require "test_helper" describe Category do - let(:category) { Category.new } + # let(:category) { Category.new } + # + # it "must be valid" do + # value(category).must_be :valid? + # end + let (:category) {categories(:book)} - it "must be valid" do - value(category).must_be :valid? + describe "relations" do + it "must be connected to products" do + category.must_respond_to :products + end end end + + +# unqiqueness and presence diff --git a/test/models/product_test.rb b/test/models/product_test.rb index d173689530..432b5ac39e 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -20,6 +20,7 @@ describe 'validations' do it 'is valid' do b = Product.new(name: "book", price: 2, merchant_id: Product.first.merchant_id) + b.category_ids = Category.first.id b.must_be :valid? end @@ -81,7 +82,7 @@ #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 From b5081536e94c01ab30480989cd8eab934d9da011 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Fri, 20 Oct 2017 16:32:06 -0700 Subject: [PATCH 075/269] add merchant relevant products started, not done. --- app/controllers/merchants_controller.rb | 14 +++++----- app/models/merchant.rb | 16 +++++++++++ app/models/order.rb | 1 + app/models/product.rb | 1 + app/views/merchants/show.html.erb | 24 ++++++++++++++-- test/controllers/merchants_controller_test.rb | 28 +++++++++---------- 6 files changed, 61 insertions(+), 23 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index aef8ee3554..66254fdb30 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -1,7 +1,7 @@ class MerchantsController < ApplicationController before_action :find_id_by_params, except: [:index, :new, :create, :logout] - before_action :must_be_logged_in, only: [:index, :show] + # before_action :must_be_logged_in, only: [:index, :show] def index @merchants = Merchant.all @@ -43,12 +43,12 @@ def logout end def show - if @merchant.id != session[:merchant_id] - flash[:status] = :success - flash[:message] = "You can only see your own details" - redirect_to merchant_path(session[:merchant_id]) - end - + # if @merchant.id != session[:merchant_id] + # flash[:status] = :success + # flash[:message] = "You can only see your own details" + # redirect_to merchants_path + # end + @orders = @merchant.relevant_orders end def edit diff --git a/app/models/merchant.rb b/app/models/merchant.rb index 223a05cfe2..5c7b94fd2f 100644 --- a/app/models/merchant.rb +++ b/app/models/merchant.rb @@ -19,4 +19,20 @@ def self.from_auth_hash(provider, auth_hash) return merchant end + + def relevant_orders + relevant_orders = [] + Order.all.each do |order| + relevant_products = order.products.select { |product| + product.merchant == self + } + if relevant_products.length > 0 + relevant_orders << { + order: order, + products: relevant_products + } + end + end + return relevant_orders + end end diff --git a/app/models/order.rb b/app/models/order.rb index ed5362d3ce..b32af7692f 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,5 +1,6 @@ class Order < ApplicationRecord has_many :order_products + has_many :products, through: :order_products def products diff --git a/app/models/product.rb b/app/models/product.rb index 7d6895f1f4..d4cb718f8d 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,6 +1,7 @@ class Product < ApplicationRecord has_many :order_products + has_many :orders, through: :order_products has_many :reviews has_and_belongs_to_many :categories diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index 70926952fb..529c4f4374 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -1,13 +1,33 @@

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

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

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

<% end %> +<% if @merchant.id == session[:merchant_id] %> +
    + <% @orders.each do |order| %> +
  • +

    <%= link_to "#{order[:order].id}", order_path(order[:order]) %> - status: <%= order[:order].status %>

    + +
      + <% order[:products].each do |product| %> +
    • + <%= product.name %> +
    • + <% end %> +
    +
  • + <% end %> +
+<% end %> + <%# TODO %> <%# all money %> <%# all products sold %> diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index b232890c9e..e40fc75876 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -28,7 +28,7 @@ it "only shows merchant their own page" do get merchant_path(merchants(:lauren)) - must_redirect_to merchant_path(@merchant) + must_redirect_to merchants_path flash[:message].must_equal "You can only see your own details" end @@ -40,19 +40,19 @@ end end - describe "non logged in user" do - it "show fails for a non-logged in user" do - get merchant_path(merchants(:anders)) - must_redirect_to products_path - flash[:message].must_equal "You must be logged in to do that!" - end - - it "index fails for a non-logged in user" do - get merchants_path - must_redirect_to products_path - flash[:message].must_equal "You must be logged in to do that!" - end - end + # describe "non logged in user" do + # it "show fails for a non-logged in user" do + # get merchant_path(merchants(:anders)) + # must_redirect_to products_path + # flash[:message].must_equal "You must be logged in to do that!" + # end + # + # it "index fails for a non-logged in user" do + # get merchants_path + # must_redirect_to products_path + # flash[:message].must_equal "You must be logged in to do that!" + # end + # end describe "create and login with auth_callback" do it "logs in an existing user and redirects to the products route" do From d81823c7f7b21145b5fbdbcd6675b9e8e069dd2a Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Fri, 20 Oct 2017 20:26:20 -0700 Subject: [PATCH 076/269] Add tests for Category Model. All index page for Categories. --- app/models/category.rb | 1 - app/views/categories/index.html.erb | 11 +++++++++++ app/views/layouts/application.html.erb | 3 +++ test/models/category_test.rb | 26 +++++++++++++++++++------- 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 app/views/categories/index.html.erb diff --git a/app/models/category.rb b/app/models/category.rb index 57bc714b93..b0d4a3edff 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -2,5 +2,4 @@ class Category < ApplicationRecord has_and_belongs_to_many :products validates :name, presence: {message: "Please enter a category name"}, uniqueness: true - end diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 0000000000..87b17da9da --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,11 @@ +
+

All Categories

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

<%= cat.name.capitalize %>

+ <%# 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/layouts/application.html.erb b/app/views/layouts/application.html.erb index a13c39304a..5df042fdd6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,6 +28,9 @@ <%= link_to "View all merchants", merchants_path, class: "button" %> <% end %> <%= link_to "Create new category", new_category_path, class: "button "%> + <%= link_to "All categories", categories_path, class: "button" %> + +
<%= link_to session[:cart] ? order_path(session[:cart]) : products_path do %> <%= image_tag 'cart.png', size: "40x40" %> diff --git a/test/models/category_test.rb b/test/models/category_test.rb index f6c3e68f1b..0784d078ea 100644 --- a/test/models/category_test.rb +++ b/test/models/category_test.rb @@ -1,11 +1,7 @@ require "test_helper" describe Category do - # let(:category) { Category.new } - # - # it "must be valid" do - # value(category).must_be :valid? - # end + let (:category) {categories(:book)} describe "relations" do @@ -13,7 +9,23 @@ category.must_respond_to :products end 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 -# unqiqueness and presence + 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 +end From 80db69ff55831228880889cbd8737366a5f31b96 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Fri, 20 Oct 2017 21:21:56 -0700 Subject: [PATCH 077/269] Add tests for CatgoriesController --- app/controllers/categories_controller.rb | 2 + app/views/layouts/application.html.erb | 7 +- config/routes.rb | 9 +++ .../controllers/categories_controller_test.rb | 73 ++++++++++++++++++- 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index d5f10f298d..1de9946681 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,4 +1,6 @@ class CategoriesController < ApplicationController + before_action :must_be_logged_in, only: [:new, :create] + def index @categories = Category.all end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5df042fdd6..b3a152c637 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -25,11 +25,14 @@
+ +
+ <%= image_tag "#{@product.photo_url}", alt:"image", class:'columns small-12 large-5', id:'product-image' %> + +
+

+ <%= @product.description %> +

+

+ <%= '%.2f' % @product.price %> +

+ +
+ <% if @product.retired != true %> +

+ Currently in stock: <%= @product.inventory %> +

+
+ <%= form_tag create_order_product_path(product_id: @product.id), method: :post do %> + + <%= text_field_tag "quantity", 1, class:'field' %> + + <%= submit_tag "Add to Cart", class: "buy button" %> + <% end %> +
+ <% if session[:merchant_id] == @product.merchant_id %> +
+ <%= form_for @product do |f| %> + + <%= f.text_field :inventory, class:'field'%> + + <%= submit_tag "Update inventory", class: "button" %> + <% end %> +
+ <% end %> + <% else %> +

+ This product has been retired. +

+ <% if session[:merchant_id] == @product.merchant_id %> + <%= link_to @product.retired ? "Unretire Product" : "Retire Product", retire_product_path(@product), method: :patch, class: "button" %> + <% end %> + <% end %> +
+
+ +
+ +
+
+

Reviews

+ <% if session[:merchant_id] != @product.merchant_id %> + <%= link_to "Write a Review", new_product_review_path(@product), class: "button columns small-6 large-3 head-button" %> + <% end %> +
+

Average rating: <%= render partial:"/layouts/stars", locals: {rating: @product.average_rating} %>

-
-
-

Categories:

- <% @product.categories.each do |cat| %> -

<%= cat.name%>

- <% end %> -
- -

<%= image_tag "#{@product.photo_url}", alt:"image"%>

- -<% if @product.retired != true %> -
- Currently in stock: <%= @product.inventory %> +
    + <% @product.reviews.each do |review| %> +
  • +

    <%= render partial:"/layouts/stars", locals: {rating: review.rating} %>

    +

    <%= review.created_at %>

    +

    <%= review.text %>

    +
  • + <% end %> +
-
- <%= form_tag create_order_product_path(product_id: @product.id), method: :post do %> - <%= text_field_tag "quantity", 1 %> - <%= submit_tag "Add to Cart", class: "buy button" %> - <% end %> -
-<% else %> -
- This product is retired. - <% if session[:merchant_id] == @product.merchant_id %> -

- <%= link_to @product.retired ? "Unretire Product" : "Retire Product", retire_product_path(@product), method: :patch, class: "button" %> -

- <% end %> -
-<% end %> -

Reviews: - <% @product.reviews.each do |review| %> -

- <%= review.text %> - <%= render partial:"/layouts/stars", locals: {rating: review.rating} %> - <% end %> + -

<%= link_to "Back to All Products", products_path, class: "button" %>

-

<%= link_to "Write a Review", new_product_review_path(@product), class: "button" %>

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

<%= link_to "Edit", edit_product_path(@product), class: "button" %>

- -<% end %> <%# link_to "Delete", product_path(@product), class: "alert button", method: "delete", data: { confirm: "Are you sure?" } %> - From 0c03f5c9f4a0ea3f02da1d2fe6547686cf92b070 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 17:21:21 -0700 Subject: [PATCH 251/269] fix a sizing error --- app/views/products/show.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 6b390e7dbe..c4542dc9da 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -1,8 +1,8 @@
-

+

<%= @product.name.capitalize %>

- <%= link_to "Back to All Products", products_path, class: "button columns small-6 large-3 head-button"%> + <%= link_to "Back to All Products", products_path, class: "button columns small-12 large-3 head-button"%>
@@ -54,9 +54,9 @@
-

Reviews

+

Reviews

<% if session[:merchant_id] != @product.merchant_id %> - <%= link_to "Write a Review", new_product_review_path(@product), class: "button columns small-6 large-3 head-button" %> + <%= link_to "Write a Review", new_product_review_path(@product), class: "button columns small-12 large-3 head-button" %> <% end %>

From 4e3dcc674f2b9d761926aaa13fe35834bd260944 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 17:34:16 -0700 Subject: [PATCH 252/269] fixed inline text fields on merchant and order show --- app/views/merchants/show.html.erb | 4 ++-- app/views/orders/show.html.erb | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index 7c60999118..8befe0e26d 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -39,10 +39,10 @@ <% if product.retired %> --Retired-- <% else %> - + <%= form_for product do |f| %> - <%= f.text_field :inventory%> + <%= f.text_field :inventory, class:'field'%> <%= submit_tag "Update inventory", class: "button" %> <% end %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index ac6d5f6d5f..f82a96db4b 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -19,12 +19,14 @@ <%= op.quantity %> $<%= '%.2f' % op.subtotal %> - <%= form_tag order_product_path(op.id, product_id: op.product_id), method: :patch do %> +

+ <%= form_tag order_product_path(op.id, product_id: op.product_id), method: :patch do %> - <%= text_field_tag "quantity" %> + <%= text_field_tag :quantity, "", class:'field' %> - <%= submit_tag "Update Quantity", class: "button" %> - <% end %> + <%= submit_tag "Update Quantity", class: "button" %> + <% end %> +
<%= link_to "Delete from cart", order_product_path(op.id), method: :delete, data: { confirm: 'Are you sure?' }%> From a94c81bf529a193e12eaa3e5bbfc0bfc2d624263 Mon Sep 17 00:00:00 2001 From: Lauren Date: Thu, 26 Oct 2017 17:39:19 -0700 Subject: [PATCH 253/269] clickable pics --- app/assets/stylesheets/products.scss | 1 + app/views/products/root.html.erb | 2 +- app/views/products/show.html.erb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 5b17253337..ec6eb0830d 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -80,6 +80,7 @@ section.details.columns.small-12 { .head-w-button { width: 80%; margin: auto; + margin-top: 20px; } .reviews { diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb index f5fd7cd839..0e7c7f0307 100644 --- a/app/views/products/root.html.erb +++ b/app/views/products/root.html.erb @@ -29,9 +29,9 @@ <%@all_products_for_season_cat.each do |product|%>
- <%= link_to product_path(product.id) do %> <%= link_to product.name.capitalize, product_path(product.id) %> | $<%='%.2f' % product.price%> + <%= link_to product_path(product.id) do %> <%= image_tag product.photo_url %> <% end %>
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index c4542dc9da..bd1a34a2b6 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -13,7 +13,7 @@ <%= @product.description %>

- <%= '%.2f' % @product.price %> + $<%= '%.2f' % @product.price %>

From 17d947b465b3a24bc159964b0c23a8a726d1ce9b Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 18:03:32 -0700 Subject: [PATCH 254/269] fix a couple broken tests, start working on missing ones --- test/fixtures/order_products.yml | 9 ++++++++- test/fixtures/orders.yml | 3 +++ test/models/merchant_test.rb | 21 ++++++++++++++++++++- test/models/order_product_test.rb | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/test/fixtures/order_products.yml b/test/fixtures/order_products.yml index 0e08b7a172..ff20d7310a 100644 --- a/test/fixtures/order_products.yml +++ b/test/fixtures/order_products.yml @@ -3,7 +3,8 @@ one: quantity: 1 product: tricycle - status: "" + order: order5 + status: "paid" two: quantity: 1 @@ -22,3 +23,9 @@ four: 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 index b51c6ea287..30c7e44183 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -12,3 +12,6 @@ order3: order4: status: "pending" + +order5: + status: "paid" diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index 32deb1e88f..a93b97ba63 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -102,12 +102,31 @@ 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 + 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 + + end end end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index 4ad7319902..c8d0a33bba 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe OrderProduct do - let (:op) { order_products(:one) } + let (:op) { order_products(:five) } let (:order) { orders(:order1) } let (:product) { products(:tricycle)} From a334d969cee59bfa3a1e427f57dd75eb88d27d23 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 18:06:03 -0700 Subject: [PATCH 255/269] add edit button back to show page whoops --- app/assets/stylesheets/products.scss | 3 +++ app/views/products/show.html.erb | 1 + 2 files changed, 4 insertions(+) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 5b17253337..e49b4c791d 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -82,6 +82,9 @@ section.details.columns.small-12 { margin: auto; } +#edit-button { + margin: 0 1rem; +} .reviews { text-align: left; margin: 0 2rem; diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index c4542dc9da..5a1e0fca4b 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -38,6 +38,7 @@ <%= submit_tag "Update inventory", class: "button" %> <% end %>
+ <%= link_to "Edit Info", edit_product_path(@product), class: "button", id:"edit-button" %> <% end %> <% else %>

From 7d7e3269d59390127fbed33e6403a968c394833c Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 18:33:07 -0700 Subject: [PATCH 256/269] add tests for some model methods/relationships --- test/controllers/merchants_controller_test.rb | 2 ++ test/fixtures/orders.yml | 3 +++ test/models/merchant_test.rb | 3 ++- test/models/order_product_test.rb | 5 +++++ test/models/order_test.rb | 17 +++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb index 1b92a2c530..52528d6584 100644 --- a/test/controllers/merchants_controller_test.rb +++ b/test/controllers/merchants_controller_test.rb @@ -38,6 +38,8 @@ get merchant_path(merchant) must_respond_with :success end + + # not sure how to test filters - since it is entirely a view thing? end describe "destroy" do diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index 30c7e44183..e85635030e 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -15,3 +15,6 @@ order4: order5: status: "paid" + +order6: + status: 'pending' diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb index a93b97ba63..3030334fc4 100644 --- a/test/models/merchant_test.rb +++ b/test/models/merchant_test.rb @@ -125,7 +125,8 @@ end it "returns 0 if no orders for that status" do - + merchant = merchants(:bennett) + merchant.total_revenue('paid').must_equal 0 end end diff --git a/test/models/order_product_test.rb b/test/models/order_product_test.rb index c8d0a33bba..36372b594c 100644 --- a/test/models/order_product_test.rb +++ b/test/models/order_product_test.rb @@ -15,6 +15,11 @@ 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 diff --git a/test/models/order_test.rb b/test/models/order_test.rb index c583d03196..59bd9a7804 100644 --- a/test/models/order_test.rb +++ b/test/models/order_test.rb @@ -59,5 +59,22 @@ # # 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 From ba3ba8453c9d4fb9049399119e77b621180890b1 Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 18:45:48 -0700 Subject: [PATCH 257/269] add total to cart --- app/views/orders/receipt.html.erb | 11 ++++++----- app/views/orders/show.html.erb | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/orders/receipt.html.erb b/app/views/orders/receipt.html.erb index e12be5ae21..9210315d17 100644 --- a/app/views/orders/receipt.html.erb +++ b/app/views/orders/receipt.html.erb @@ -26,7 +26,8 @@ Product Quantity - Subtotal + + Subtotal @@ -34,10 +35,10 @@ <%= link_to op.product.name, product_path(op.product_id) %> <%= op.quantity %> - <%= readable_price(op.subtotal) %> - + <%= link_to "Buy it again!", product_path(op.product_id), class: "button" %> + <%= readable_price(op.subtotal) %> <% end %> @@ -72,7 +73,7 @@ Product Quantity - Subtotal + Subtotal @@ -81,7 +82,7 @@ <%= link_to op.product.name, product_path(op.product_id) %> <%= op.quantity %> - <%= readable_price(op.subtotal) %> + <%= readable_price(op.subtotal) %> <% end %> <% end %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index f82a96db4b..dde1a172a0 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -28,10 +28,17 @@ <% end %>

- <%= link_to "Delete from cart", order_product_path(op.id), method: :delete, + <%= link_to "Delete from cart", order_product_path(op.id), method: :delete, class:'button', data: { confirm: 'Are you sure?' }%> <% end %> + + + Total: + <%= readable_price(@order.order_total) %> + + +

Grand Total: $<%= '%.2f' % @order.order_products.sum(&:subtotal) %>

From 3d04ad2b8c970ac486b3c65a8dac8e8b9b7ca35e Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Thu, 26 Oct 2017 18:49:48 -0700 Subject: [PATCH 258/269] add readable-date to review --- app/views/products/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 1769c8a6c9..d90440c55f 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -69,7 +69,7 @@ <% @product.reviews.each do |review| %>
  • <%= render partial:"/layouts/stars", locals: {rating: review.rating} %>

    -

    <%= review.created_at %>

    +

    <%= readable_date(review.created_at) %>

    <%= review.text %>

  • <% end %> From 6aee1627ce3d989151e9e1cde8008c379a56dfc2 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Thu, 26 Oct 2017 19:34:15 -0700 Subject: [PATCH 259/269] Add button to receipt show page for merchant. Some clean up --- app/controllers/categories_controller.rb | 4 +--- app/views/orders/receipt.html.erb | 1 + app/views/products/show.html.erb | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 22b44e7bed..0972acde59 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -8,9 +8,7 @@ def index # @by_cat = Category.view_by_category end - def show ; - # @category = Category.find(params[:id]) - end + def show ; end def new @category = Category.new diff --git a/app/views/orders/receipt.html.erb b/app/views/orders/receipt.html.erb index 9210315d17..4ce9d98834 100644 --- a/app/views/orders/receipt.html.erb +++ b/app/views/orders/receipt.html.erb @@ -91,4 +91,5 @@ <% end %> +

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

    diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 1769c8a6c9..43150d2cab 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -13,7 +13,7 @@ <%= @product.description %>

    - $<%= '%.2f' % @product.price %> + <%= readable_price(@product.price) %>

    From ba4c1d858b51b257c2a66c61eeb2de1ba111cd82 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Thu, 26 Oct 2017 20:42:19 -0700 Subject: [PATCH 260/269] Fix bug on receipt page. Add test for OrdersController#receipt --- app/views/orders/receipt.html.erb | 3 ++- test/controllers/orders_controller_test.rb | 26 ++++++++++++++++++++-- test/fixtures/orders.yml | 1 - 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/views/orders/receipt.html.erb b/app/views/orders/receipt.html.erb index 4ce9d98834..87c3793234 100644 --- a/app/views/orders/receipt.html.erb +++ b/app/views/orders/receipt.html.erb @@ -90,6 +90,7 @@ +

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

    <% end %> -

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

    + diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index 2c74835db3..c83c5d7140 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -89,7 +89,8 @@ 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", @@ -109,6 +110,7 @@ end it "cannot see a receipt twice; receipts will only show immediately after a purchase" do + payment_data = { payment_info: { email: "example@example.com", @@ -130,8 +132,28 @@ flash[:status].must_equal :failure end - it "shows the receipt to the merchant who is the owner of the orderproduct" do + 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 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index e85635030e..90b1328592 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -3,7 +3,6 @@ order1: status: "pending" - order2: status: "pending" From 56ec90a4532bd91c886a423bfb4325ef702804b4 Mon Sep 17 00:00:00 2001 From: Andrea Chen Date: Fri, 27 Oct 2017 07:31:17 -0700 Subject: [PATCH 261/269] Changing some price and date stuff --- app/views/categories/index.html.erb | 2 +- app/views/categories/show.html.erb | 2 +- app/views/merchants/show.html.erb | 2 +- app/views/orders/empty_cart.html.erb | 2 +- app/views/products/root.html.erb | 4 ++-- app/views/products/show.html.erb | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index cf9e1276b3..61e664990c 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -6,7 +6,7 @@

    <%= cat.name.capitalize %>

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

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

    -

    $<%= prod.price %>

    +

    <%= 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? %> diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb index 92218e0817..497962788e 100644 --- a/app/views/categories/show.html.erb +++ b/app/views/categories/show.html.erb @@ -5,7 +5,7 @@ <% @category.products.not_retired.each do |prod| %>

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

    -

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

    +

    <%= readable_price(prod.price) %>

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

    <% end %> diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index 8befe0e26d..ee7f265f67 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -32,7 +32,7 @@ <% @merchant.products.each do |product| %>

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

    - $<%= '%.2f' % product.price %> + <%= readable_price(product.price) %> <%= product.inventory %> <%if session[:merchant_id] == @merchant.id %> diff --git a/app/views/orders/empty_cart.html.erb b/app/views/orders/empty_cart.html.erb index affe1f7615..5589a806ad 100644 --- a/app/views/orders/empty_cart.html.erb +++ b/app/views/orders/empty_cart.html.erb @@ -5,7 +5,7 @@ <% spot = Product.not_retired.sample %>

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

    -

    Price: $<%= '%.2f' % spot.price %>

    +

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

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

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

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

    diff --git a/app/views/products/root.html.erb b/app/views/products/root.html.erb index 0e7c7f0307..44d3d9d649 100644 --- a/app/views/products/root.html.erb +++ b/app/views/products/root.html.erb @@ -17,7 +17,7 @@ <% @spot = Product.not_retired.sample %>

    <%= link_to @spot.name.capitalize, product_path(@spot.id) %> | - $<%='%.2f' % @spot.price%>

    + <%= readable_price(@spot.price) %>

    <%= link_to product_path(@spot.id) do %>

    <%= image_tag @spot.photo_url %>

    <% end %> @@ -30,7 +30,7 @@
    <%= link_to product.name.capitalize, product_path(product.id) %> | - $<%='%.2f' % product.price%> + <%= readable_price(product.price) %> <%= link_to product_path(product.id) do %> <%= image_tag product.photo_url %> <% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 43150d2cab..645da93686 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -69,7 +69,7 @@ <% @product.reviews.each do |review| %>
  • <%= render partial:"/layouts/stars", locals: {rating: review.rating} %>

    -

    <%= review.created_at %>

    +

    <%= readable_date(review.created_at) %>

    <%= review.text %>

  • <% end %> From c98f948771205e8608a7db7e10d2cb365c9ba35c Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 27 Oct 2017 10:19:17 -0700 Subject: [PATCH 262/269] clickable images --- app/views/categories/show.html.erb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb index 92218e0817..0d639c9044 100644 --- a/app/views/categories/show.html.erb +++ b/app/views/categories/show.html.erb @@ -6,7 +6,11 @@

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

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

    -

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

    + +

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

    +<% end %> +
    <% end %>
    From b4256fac3fcb09b33eecfe2f63c3d8645df4257e Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 27 Oct 2017 11:02:06 -0700 Subject: [PATCH 263/269] product page --- app/assets/stylesheets/products.scss | 46 ++++++++++---- app/views/products/show.html.erb | 92 +++++++++++++++------------- 2 files changed, 85 insertions(+), 53 deletions(-) diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss index 2c3c1a8e5e..d41198e068 100644 --- a/app/assets/stylesheets/products.scss +++ b/app/assets/stylesheets/products.scss @@ -28,16 +28,16 @@ margin-left: 150px; } .crop-image { - height: 200px; - width: 200px; - overflow: hidden; - margin-left: 70px; - margin-bottom: 10px; - margin-top: 20px; + height: 200px; + width: 200px; + overflow: hidden; + margin-left: 70px; + margin-bottom: 10px; + margin-top: 20px; } .crop-image img { - height: 200px; - width: 200px; + height: 200px; + width: 200px; } .prod-name a { padding-right: 10px; @@ -84,19 +84,43 @@ section.details.columns.small-12 { } #edit-button { - margin: 0 1rem; + margin: 0 1rem; } .reviews { + display: inline-block; text-align: left; margin: 0 2rem; } -.reviews li { - border-bottom: lightgrey 1pt solid; +.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% diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index 645da93686..81ddede89c 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -9,83 +9,91 @@ <%= image_tag "#{@product.photo_url}", alt:"image", class:'columns small-12 large-5', id:'product-image' %>
    -

    +

    + Description: <%= @product.description %> -

    -

    - <%= readable_price(@product.price) %> -

    +
    +
    + Price: <%= readable_price(@product.price) %> +
    <% if @product.retired != true %> -

    - Currently in stock: <%= @product.inventory %> -

    -
    - <%= form_tag create_order_product_path(product_id: @product.id), method: :post do %> - - <%= text_field_tag "quantity", 1, class:'field' %> - - <%= submit_tag "Add to Cart", class: "buy button" %> - <% end %> -
    - <% if session[:merchant_id] == @product.merchant_id %> -
    - <%= form_for @product do |f| %> - - <%= f.text_field :inventory, class:'field'%> - - <%= submit_tag "Update inventory", class: "button" %> - <% end %> -
    - <%= link_to "Edit Info", edit_product_path(@product), class: "button", id:"edit-button" %> +

    + Currently in stock: <%= @product.inventory %> +

    +
    + <%= form_tag create_order_product_path(product_id: @product.id), method: :post do %> + + <%= text_field_tag "quantity", 1, class:'field' %> + + <%= submit_tag "Add to Cart", class: "buy button" %> <% end %> - <% else %> -

    - This product has been retired. -

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

    + This product has been retired. +

    + <% if session[:merchant_id] == @product.merchant_id %> + <%= link_to @product.retired ? "Unretire Product" : "Retire Product", retire_product_path(@product), method: :patch, class: "button" %> + <% end %> <% end %>
    +
    -

    Reviews

    +

    Reviews:

    <% if session[:merchant_id] != @product.merchant_id %> - <%= link_to "Write a Review", new_product_review_path(@product), class: "button columns small-12 large-3 head-button" %> + <%= link_to "Write a Review", new_product_review_path(@product), class: "button columns small-12 large-3 head-button" %> <% end %>
    -

    - Average rating: +

    +

    Average rating:
    <%= render partial:"/layouts/stars", locals: {rating: @product.average_rating} %>

      + <% count = 0 %> <% @product.reviews.each do |review| %> -
    • +
    • +
      + <% count += 1 %> + <%= "Review #{count}:" %>

      <%= render partial:"/layouts/stars", locals: {rating: review.rating} %>

      <%= readable_date(review.created_at) %>

      <%= review.text %>

      -
    • +
    + <% end %>
    + <%# link_to "Delete", product_path(@product), class: "alert button", method: "delete", data: { confirm: "Are you sure?" } %> From 2e3e3da2b67dc88cf8de10a22fdfb942d4c36235 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 27 Oct 2017 11:16:02 -0700 Subject: [PATCH 264/269] empty cart image --- app/views/orders/empty_cart.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/orders/empty_cart.html.erb b/app/views/orders/empty_cart.html.erb index 5589a806ad..bb688bede7 100644 --- a/app/views/orders/empty_cart.html.erb +++ b/app/views/orders/empty_cart.html.erb @@ -6,7 +6,7 @@

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

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

    -

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

    +

    <%= 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 %>

    From dad35b84e449b5d68cec59a30ef52b95d233e70a Mon Sep 17 00:00:00 2001 From: Bennett Rahn Date: Fri, 27 Oct 2017 12:00:43 -0700 Subject: [PATCH 265/269] change the merchant show page to have #secret --- app/assets/stylesheets/merchants.scss | 2 +- app/views/merchants/show.html.erb | 86 ++++++++++++++------------- app/views/orders/show.html.erb | 1 - 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/app/assets/stylesheets/merchants.scss b/app/assets/stylesheets/merchants.scss index 158d6a0927..3ee03197e5 100644 --- a/app/assets/stylesheets/merchants.scss +++ b/app/assets/stylesheets/merchants.scss @@ -63,7 +63,7 @@ table tbody tr td a { justify-content: space-around; } .total_box { - background-color: rgb(21, 142, 116); + background-color: #629286; color: white; text-align: center; padding: 0; diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index ee7f265f67..a5ec2db17e 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -11,6 +11,50 @@
    +<% if @merchant.id == session[:merchant_id] %> +
      +
    • +
      Total Revenue
      +

      + <% if @complete_orders.empty? %> + No money made yet! + <% else %> + $<%='%.2f' % @merchant.total_revenue('complete')%> + <% end %> +

      +
    • + +
    • +
      Total Completed Orders
      +

      + <%=@complete_orders.count%> +

      + <%= link_to "See Completed Orders", merchant_path(@merchant, status: "complete") + "#secret", class:"button" %> +
    • + +
    • +
      Waiting Revenue
      +

      + <% if @paid_orders.empty? %> + No orders waiting! + <% else %> + $<%='%.2f' % @merchant.total_revenue('paid')%> + <% end %> +

      +
    • + +
    • +
      Waiting Orders
      +

      + <%=@paid_orders.count%> +

      + <%= link_to "See Orders Waiting Fulfillment", merchant_path(@merchant, status: "paid") + "#secret", class:"button"%> + + +
    • +
    +<%end%> +

    Products

    @@ -63,46 +107,6 @@

    Orders

    -
      -
    • -
      Total Revenue
      -

      - <% if @complete_orders.empty? %> - No money made yet! - <% else %> - $<%='%.2f' % @merchant.total_revenue('complete')%> - <% end %> -

      -
    • - -
    • -
      Total Completed Orders
      -

      - <%=@complete_orders.count%> -

      - <%= link_to "See Completed Orders", merchant_path(@merchant, status: "complete"), class:"button" %> -
    • - -
    • -
      Waiting Revenue
      -

      - <% if @paid_orders.empty? %> - No orders waiting! - <% else %> - $<%='%.2f' % @merchant.total_revenue('paid')%> - <% end %> -

      -
    • - -
    • -
      Waiting Orders
      -

      - <%=@paid_orders.count%> -

      - <%= link_to "See Orders Waiting Fulfillment", merchant_path(@merchant, status: "paid"), class:"button" %> -
    • -
    -