+<% end %>
\ No newline at end of file
diff --git a/app/views/categories/create.html.erb b/app/views/categories/create.html.erb
new file mode 100644
index 0000000000..19d08fb435
--- /dev/null
+++ b/app/views/categories/create.html.erb
@@ -0,0 +1,4 @@
+
+
We have a myriad of baked goods for any occassion. Choose from intricate cakes to classic cookies. Our talented Bakesy partners will satisfy any sweet tooth.
+ <% end %>
+ <% ord = Order.find_by(id: item.order.id) %>
+ <% if ord.status.nil? %>
+
PENDING PAYMENT
+ <% else %>
+
<%= ord.status.upcase %>
+ <% end %>
+
+ <% end %>
+ <% end %>
+
+
+
+
+
+
REVENUE
+
+
+
+
PENDING
+
PAID
+
COMPLETE
+
CANCELLED
+
TOTAL
+
+
+
+ <% sold = @user.find_ordered_items %>
+ <% if sold.empty? %>
+ <%= "No Products Have Sold" %>
+ <% else %>
+
+
<%= format_price(@user.revenue("Pending")) %>
+
<%= format_price(@user.revenue("Paid")) %>
+
<%= format_price(@user.revenue("Complete"))%>
+
<%= format_price(@user.revenue("Cancelled")) %>
+
<%= format_price(@user.revenue("Total")) %>
+
+ <% end %>
+
+
+
+
+
+ <%= link_to 'Back', root_path %>
diff --git a/bin/bundle b/bin/bundle
new file mode 100755
index 0000000000..f19acf5b5c
--- /dev/null
+++ b/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rails b/bin/rails
new file mode 100755
index 0000000000..5badb2fde0
--- /dev/null
+++ b/bin/rails
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 0000000000..d87d5f5781
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/bin/setup b/bin/setup
new file mode 100755
index 0000000000..94fd4d7977
--- /dev/null
+++ b/bin/setup
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = File.expand_path('..', __dir__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:setup'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/spring b/bin/spring
new file mode 100755
index 0000000000..fb2ec2ebb4
--- /dev/null
+++ b/bin/spring
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+ require 'rubygems'
+ require 'bundler'
+
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
+ if spring
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
+ gem 'spring', spring.version
+ require 'spring/binstub'
+ end
+end
diff --git a/bin/update b/bin/update
new file mode 100755
index 0000000000..58bfaed518
--- /dev/null
+++ b/bin/update
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = File.expand_path('..', __dir__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/yarn b/bin/yarn
new file mode 100755
index 0000000000..460dd565b4
--- /dev/null
+++ b/bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path('..', __dir__)
+Dir.chdir(APP_ROOT) do
+ begin
+ exec "yarnpkg", *ARGV
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000000..f7ba0b527b
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/config/application.rb b/config/application.rb
new file mode 100644
index 0000000000..5c09a3eefc
--- /dev/null
+++ b/config/application.rb
@@ -0,0 +1,25 @@
+require_relative 'boot'
+
+require 'rails/all'
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module Betsy
+ class Application < Rails::Application
+ config.generators do |g|
+ # Force new test files to be generated in the minitest-spec style
+ g.test_framework :minitest, spec: true
+ # Always use .js files, never .coffee
+ g.javascript_engine :js
+ end
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.2
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration can go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded after loading
+ # the framework and any gems in your application.
+ end
+end
diff --git a/config/boot.rb b/config/boot.rb
new file mode 100644
index 0000000000..b9e460cef3
--- /dev/null
+++ b/config/boot.rb
@@ -0,0 +1,4 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
+require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
diff --git a/config/cable.yml b/config/cable.yml
new file mode 100644
index 0000000000..dd2a324c68
--- /dev/null
+++ b/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
+ channel_prefix: betsy_production
diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc
new file mode 100644
index 0000000000..2170aafac5
--- /dev/null
+++ b/config/credentials.yml.enc
@@ -0,0 +1 @@
+6qMkHjG2FcVe8v2LPgI4ogyQYaCK5bMWmEkSKjF4CJMmfhWKZ2OeTv/ePiXOcz3w/Kn5GX0h21i4dHUPl9MQinnI3QepErVUXUR4rFZZbqBI39sAu1MqSmu3OMlKPnunn7jcwgcol3H3akRkdhgL/GapeGVNzu+oR4NSDKmvsBpNHDKLxu6P3aSFBzRHiHcNXi0EO8JIK/XVa2ZiKu8v+Y03hbieJhmXwLqCUJE7YSJ47SlKYw4YYl4Ed0fYmaFtTKfq8c6MI+ziyepXL4X9AHBwFlgs95nKRYHeAscruwXZ1GfLrkzqdnppGq+W+VxmMXdxa7sWi7v06UlXsGfZxd9HemBiib3pFZxDyVU6SqA0XFxmFCblO7rNsiuT5LrOMZZ2PXDwybPkYF8M/wOrAxuHH/uW30R36X5D--N0APY7pCr5Quvg0+--jT6K103BvIqvpfllNATnjg==
\ No newline at end of file
diff --git a/config/database.yml b/config/database.yml
new file mode 100644
index 0000000000..6903bb6083
--- /dev/null
+++ b/config/database.yml
@@ -0,0 +1,85 @@
+# PostgreSQL. Versions 9.1 and up are supported.
+#
+# Install the pg driver:
+# gem install pg
+# On OS X with Homebrew:
+# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
+# On OS X with MacPorts:
+# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
+# On Windows:
+# gem install pg
+# Choose the win32 build.
+# Install PostgreSQL and put its /bin directory on your path.
+#
+# Configure Using Gemfile
+# gem 'pg'
+#
+default: &default
+ adapter: postgresql
+ encoding: unicode
+ # For details on connection pooling, see Rails configuration guide
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+
+development:
+ <<: *default
+ database: betsy_development
+
+ # The specified database role being used to connect to postgres.
+ # To create additional roles in postgres see `$ createuser --help`.
+ # When left blank, postgres will use the default role. This is
+ # the same name as the operating system user that initialized the database.
+ #username: betsy
+
+ # The password associated with the postgres role (username).
+ #password:
+
+ # Connect on a TCP socket. Omitted by default since the client uses a
+ # domain socket that doesn't need configuration. Windows does not have
+ # domain sockets, so uncomment these lines.
+ #host: localhost
+
+ # The TCP port the server listens on. Defaults to 5432.
+ # If your server runs on a different port number, change accordingly.
+ #port: 5432
+
+ # Schema search path. The server defaults to $user,public
+ #schema_search_path: myapp,sharedapp,public
+
+ # Minimum log levels, in increasing order:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, notice, warning, error, fatal, and panic
+ # Defaults to warning.
+ #min_messages: notice
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: betsy_test
+
+# As with config/secrets.yml, you never want to store sensitive information,
+# like your database password, in your source code. If your source code is
+# ever seen by anyone, they now have access to your database.
+#
+# Instead, provide the password as a unix environment variable when you boot
+# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
+# for a full rundown on how to provide these environment variables in a
+# production deployment.
+#
+# On Heroku and other platform providers, you may have a full connection URL
+# available as an environment variable. For example:
+#
+# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
+#
+# You can use this database configuration with:
+#
+# production:
+# url: <%= ENV['DATABASE_URL'] %>
+#
+production:
+ <<: *default
+ database: betsy_production
+ username: betsy
+ password: <%= ENV['BETSY_DATABASE_PASSWORD'] %>
diff --git a/config/environment.rb b/config/environment.rb
new file mode 100644
index 0000000000..426333bb46
--- /dev/null
+++ b/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
new file mode 100644
index 0000000000..1311e3e4ef
--- /dev/null
+++ b/config/environments/development.rb
@@ -0,0 +1,61 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ # Run rails dev:cache to toggle caching.
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Store uploaded files on the local file system (see config/storage.yml for options)
+ config.active_storage.service = :local
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Highlight code that triggered database queries in logs.
+ config.active_record.verbose_query_logs = true
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/config/environments/production.rb b/config/environments/production.rb
new file mode 100644
index 0000000000..5f6f3058c6
--- /dev/null
+++ b/config/environments/production.rb
@@ -0,0 +1,94 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
+ # config.require_master_key = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Store uploaded files on the local file system (see config/storage.yml for options)
+ config.active_storage.service = :local
+
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "betsy_#{Rails.env}"
+
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/config/environments/test.rb b/config/environments/test.rb
new file mode 100644
index 0000000000..0a38fd3ce9
--- /dev/null
+++ b/config/environments/test.rb
@@ -0,0 +1,46 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Store uploaded files on the local file system in a temporary directory
+ config.active_storage.service = :test
+
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb
new file mode 100644
index 0000000000..142d382f87
--- /dev/null
+++ b/config/initializers/action_view.rb
@@ -0,0 +1 @@
+Rails.application.config.action_view.form_with_generates_remote_forms = false
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000000..89d2efab2b
--- /dev/null
+++ b/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
new file mode 100644
index 0000000000..4b828e80cb
--- /dev/null
+++ b/config/initializers/assets.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000..59385cdf37
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb
new file mode 100644
index 0000000000..d3bcaa5ec8
--- /dev/null
+++ b/config/initializers/content_security_policy.rb
@@ -0,0 +1,25 @@
+# Be sure to restart your server when you modify this file.
+
+# Define an application-wide content security policy
+# For further information see the following documentation
+# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
+
+# Rails.application.config.content_security_policy do |policy|
+# policy.default_src :self, :https
+# policy.font_src :self, :https, :data
+# policy.img_src :self, :https, :data
+# policy.object_src :none
+# policy.script_src :self, :https
+# policy.style_src :self, :https
+
+# # Specify URI for violation reports
+# # policy.report_uri "/csp-violation-report-endpoint"
+# end
+
+# If you are using UJS then enable automatic nonce generation
+# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
+
+# Report CSP violations to a specified URI
+# For further information see the following documentation:
+# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
+# Rails.application.config.content_security_policy_report_only = true
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000000..5a6a32d371
--- /dev/null
+++ b/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000000..4a994e1e7b
--- /dev/null
+++ b/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000000..ac033bf9dc
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000000..dc1899682b
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 0000000000..fd4416122a
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,3 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email"
+end
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000000..bbfc3961bf
--- /dev/null
+++ b/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/config/locales/en.yml b/config/locales/en.yml
new file mode 100644
index 0000000000..decc5a8573
--- /dev/null
+++ b/config/locales/en.yml
@@ -0,0 +1,33 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/config/puma.rb b/config/puma.rb
new file mode 100644
index 0000000000..a5eccf816b
--- /dev/null
+++ b/config/puma.rb
@@ -0,0 +1,34 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory.
+#
+# preload_app!
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000000..dcffbb0cd5
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,40 @@
+Rails.application.routes.draw do
+ root 'products#home'
+
+ get "/auth/:provider/callback", to: "sessions#create", as: "login"
+
+ resources :products do
+ resources :reviews, only: [:new, :create]
+ end
+
+ get "/auth/:provider/callback", to: "sessions#create", as: "auth_callback"
+ delete "/logout", to: "sessions#destroy", as: "logout"
+
+ resources :reviews, :except => [:show]
+
+ resources :carts, only: [:show, :new]
+
+ patch 'order_items/:id/ship', to: "order_items#ship", as: "ship_item"
+ post "order_items/cart_direct/:id", to: "order_items#cart_direct", as: "quick_shop"
+ resources :order_items, only: [:create, :update, :destroy]
+
+ resources :orders
+ patch 'order/confirm_order/:id', to: "order#confirm_order", as: "confirm_order"
+
+ get 'products/category/:id', to: "products#category", as: "category"
+ patch 'products/:id/retire', to: "products#status", as: "product_status"
+ get 'products/merchant/:id', to: "products#merchant", as: "merchant"
+ resources :products, :except => [:destroy]
+
+ resources :users, :except => [:destroy, :index]
+
+ resources :users do
+ resources :products, only: [:index, :show, :new]
+ # resources :orders, only: [:index, :show]
+ end
+
+
+
+ resources :categories, :except => [:destroy]
+
+end
diff --git a/config/spring.rb b/config/spring.rb
new file mode 100644
index 0000000000..9fa7863f99
--- /dev/null
+++ b/config/spring.rb
@@ -0,0 +1,6 @@
+%w[
+ .ruby-version
+ .rbenv-vars
+ tmp/restart.txt
+ tmp/caching-dev.txt
+].each { |path| Spring.watch(path) }
diff --git a/config/storage.yml b/config/storage.yml
new file mode 100644
index 0000000000..d32f76e8fb
--- /dev/null
+++ b/config/storage.yml
@@ -0,0 +1,34 @@
+test:
+ service: Disk
+ root: <%= Rails.root.join("tmp/storage") %>
+
+local:
+ service: Disk
+ root: <%= Rails.root.join("storage") %>
+
+# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
+# amazon:
+# service: S3
+# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
+# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
+# region: us-east-1
+# bucket: your_own_bucket
+
+# Remember not to checkin your GCS keyfile to a repository
+# google:
+# service: GCS
+# project: your_project
+# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
+# bucket: your_own_bucket
+
+# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
+# microsoft:
+# service: AzureStorage
+# storage_account_name: your_account_name
+# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
+# container: your_container_name
+
+# mirror:
+# service: Mirror
+# primary: local
+# mirrors: [ amazon, google, microsoft ]
diff --git a/db/category_seeds.csv b/db/category_seeds.csv
new file mode 100644
index 0000000000..b418136fd9
--- /dev/null
+++ b/db/category_seeds.csv
@@ -0,0 +1,4 @@
+id,category
+1,Cupcake
+2,Pie
+3,Cake
diff --git a/db/generate_seeds.rb b/db/generate_seeds.rb
new file mode 100644
index 0000000000..510c564dcb
--- /dev/null
+++ b/db/generate_seeds.rb
@@ -0,0 +1,75 @@
+
+require 'faker'
+require 'date'
+require 'csv'
+
+# feel free to
+# run this script in order to replace it and generate a new one
+# run using the command:
+# $ ruby db/generate_seeds.rb
+# if satisfied with this new media_seeds.csv file, recreate the db with:
+# $ rails db:reset
+# doesn't currently check for if titles are unique against each other
+
+CSV.open('db/user_seeds.csv', "w", :write_headers=> true,
+ :headers => ["uid", "username", "email"]) do |csv|
+
+ 5.times do
+ uid = Faker::Number.between(1, 5)
+ username = Faker::Internet.username
+ email= Faker::Internet.safe_email
+ csv << [uid, username, email]
+ end
+end
+
+
+
+CSV.open('db/product_seeds.csv', "w", :write_headers=> true,
+ :headers => ["prod_name", "user_id", "description", "price", "inv_qty", "active", "image"]) do |csv|
+
+ 30.times do
+ # category = %w(birthday wedding chocolate vanilla buttercream).sample
+ prod_name = Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor
+ user_id = Faker::Number.between(1, 4)
+ description = Faker::Coffee.notes
+ price = Faker::Number.decimal(2, 2)
+ inv_qty = Faker::Number.between(0, 30)
+ active = Faker::Boolean.boolean
+ image = Faker::LoremPixel.image("200x300", false, 'food')
+
+ csv << [prod_name, user_id, description, price, inv_qty, active, image]
+ end
+end
+
+
+CSV.open('db/review_seeds.csv', "w", :write_headers=> true,
+ :headers => ["rating", "description", "product_id"]) do |csv|
+
+ 10.times do
+ rating = Faker::Number.between(1, 5)
+ description = ["Tasted like ", "Deliciously flavored ", "Oddly it smelled like "].sample + Faker::Coffee.notes
+ product_id = Faker::Number.between(1, 15)
+ csv << [rating, description, product_id]
+ end
+end
+
+
+CSV.open('db/order_seeds.csv', "w", :write_headers=> true,
+ :headers => ["status", "cust_name", "cust_email", "mailing_address",
+ "cc_name", "cc_digit", "cc_expiration", "cc_cvv",
+ "cc_zip"]) do |csv|
+
+ 10.times do
+ status = %w(pending paid complete cancelled).sample
+ cust_name = Faker::RuPaul.queen
+ cust_email = Faker::Internet.safe_email
+ mailing_address = Faker::Address.full_address
+ cc_name = Faker::FunnyName.two_word_name
+ cc_digit = Faker::Number.number(16)
+ cc_expiration = Faker::Business.credit_card_expiry_date
+ cc_cvv = Faker::Number.number(3)
+ cc_zip = Faker::Number.number(5)
+
+ csv << [status, cust_name, cust_email, mailing_address, cc_name, cc_digit, cc_expiration, cc_cvv, cc_zip]
+ end
+end
diff --git a/db/migrate/20181017233257_create_users.rb b/db/migrate/20181017233257_create_users.rb
new file mode 100644
index 0000000000..ce7f9b7096
--- /dev/null
+++ b/db/migrate/20181017233257_create_users.rb
@@ -0,0 +1,11 @@
+class CreateUsers < ActiveRecord::Migration[5.2]
+ def change
+ create_table :users do |t|
+ t.integer :uid
+ t.string :username
+ t.string :email
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181017233513_create_products.rb b/db/migrate/20181017233513_create_products.rb
new file mode 100644
index 0000000000..47529e527d
--- /dev/null
+++ b/db/migrate/20181017233513_create_products.rb
@@ -0,0 +1,13 @@
+class CreateProducts < ActiveRecord::Migration[5.2]
+ def change
+ create_table :products do |t|
+ t.string :category
+ t.string :prod_name
+ t.string :description
+ t.float :price
+ t.integer :inv_qty
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181017233535_create_orders.rb b/db/migrate/20181017233535_create_orders.rb
new file mode 100644
index 0000000000..71335debcf
--- /dev/null
+++ b/db/migrate/20181017233535_create_orders.rb
@@ -0,0 +1,17 @@
+class CreateOrders < ActiveRecord::Migration[5.2]
+ def change
+ create_table :orders do |t|
+ t.string :status
+ t.string :cust_name
+ t.string :cust_email
+ t.integer :mailing_address
+ t.string :cc_name
+ t.integer :cc_digit
+ t.date :cc_expiration
+ t.integer :cc_cvv
+ t.integer :cc_zip
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181017233629_create_reviews.rb b/db/migrate/20181017233629_create_reviews.rb
new file mode 100644
index 0000000000..b3b1f0c445
--- /dev/null
+++ b/db/migrate/20181017233629_create_reviews.rb
@@ -0,0 +1,10 @@
+class CreateReviews < ActiveRecord::Migration[5.2]
+ def change
+ create_table :reviews do |t|
+ t.integer :rating
+ t.string :description
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181017233954_create_categories.rb b/db/migrate/20181017233954_create_categories.rb
new file mode 100644
index 0000000000..6cfb9a0962
--- /dev/null
+++ b/db/migrate/20181017233954_create_categories.rb
@@ -0,0 +1,9 @@
+class CreateCategories < ActiveRecord::Migration[5.2]
+ def change
+ create_table :categories do |t|
+ t.string :category
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181017234540_create_categories_products_join.rb b/db/migrate/20181017234540_create_categories_products_join.rb
new file mode 100644
index 0000000000..09fe47a944
--- /dev/null
+++ b/db/migrate/20181017234540_create_categories_products_join.rb
@@ -0,0 +1,8 @@
+class CreateCategoriesProductsJoin < ActiveRecord::Migration[5.2]
+ def change
+ create_table :categories_products do |t|
+ t.belongs_to :category, index: true
+ t.belongs_to :product, index: true
+ end
+ end
+end
diff --git a/db/migrate/20181018174629_add_active_image_fields_to_product.rb b/db/migrate/20181018174629_add_active_image_fields_to_product.rb
new file mode 100644
index 0000000000..d40a6b8492
--- /dev/null
+++ b/db/migrate/20181018174629_add_active_image_fields_to_product.rb
@@ -0,0 +1,6 @@
+class AddActiveImageFieldsToProduct < ActiveRecord::Migration[5.2]
+ def change
+ add_column :products, :image, :string
+ add_column :products, :active, :boolean, default: true
+ end
+end
diff --git a/db/migrate/20181018181858_create_order_items.rb b/db/migrate/20181018181858_create_order_items.rb
new file mode 100644
index 0000000000..c2c48ba42f
--- /dev/null
+++ b/db/migrate/20181018181858_create_order_items.rb
@@ -0,0 +1,12 @@
+class CreateOrderItems < ActiveRecord::Migration[5.2]
+ def change
+ create_table :order_items do |t|
+ t.integer :order_id
+ t.integer :product_id
+ t.integer :qty
+ t.boolean :shipped
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181019014144_add_foreign_key_associations.rb b/db/migrate/20181019014144_add_foreign_key_associations.rb
new file mode 100644
index 0000000000..7a0e41e91f
--- /dev/null
+++ b/db/migrate/20181019014144_add_foreign_key_associations.rb
@@ -0,0 +1,6 @@
+class AddForeignKeyAssociations < ActiveRecord::Migration[5.2]
+ def change
+ add_reference :products, :user, foreign_key: true
+ add_reference :reviews, :product, foreign_key: true
+ end
+end
diff --git a/db/migrate/20181019035503_remove_category_from_products.rb b/db/migrate/20181019035503_remove_category_from_products.rb
new file mode 100644
index 0000000000..4a5939d3d9
--- /dev/null
+++ b/db/migrate/20181019035503_remove_category_from_products.rb
@@ -0,0 +1,5 @@
+class RemoveCategoryFromProducts < ActiveRecord::Migration[5.2]
+ def change
+ remove_column :products, :category
+ end
+end
diff --git a/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb b/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb
new file mode 100644
index 0000000000..757f155371
--- /dev/null
+++ b/db/migrate/20181019041122_change_cc_digit_int_to_bigint.rb
@@ -0,0 +1,5 @@
+class ChangeCcDigitIntToBigint < ActiveRecord::Migration[5.2]
+ def change
+ change_column :orders, :cc_digit, :bigint
+ end
+end
diff --git a/db/migrate/20181019041908_change_order_mail_address_to_text.rb b/db/migrate/20181019041908_change_order_mail_address_to_text.rb
new file mode 100644
index 0000000000..1e95d824b2
--- /dev/null
+++ b/db/migrate/20181019041908_change_order_mail_address_to_text.rb
@@ -0,0 +1,5 @@
+class ChangeOrderMailAddressToText < ActiveRecord::Migration[5.2]
+ def change
+ change_column :orders, :mailing_address, :text
+ end
+end
diff --git a/db/migrate/20181019042145_change_reviews_description_to_text.rb b/db/migrate/20181019042145_change_reviews_description_to_text.rb
new file mode 100644
index 0000000000..5dfb97e329
--- /dev/null
+++ b/db/migrate/20181019042145_change_reviews_description_to_text.rb
@@ -0,0 +1,5 @@
+class ChangeReviewsDescriptionToText < ActiveRecord::Migration[5.2]
+ def change
+ change_column :reviews, :description, :text
+ end
+end
diff --git a/db/migrate/20181019042229_change_products_description_to_text.rb b/db/migrate/20181019042229_change_products_description_to_text.rb
new file mode 100644
index 0000000000..5ea37ef928
--- /dev/null
+++ b/db/migrate/20181019042229_change_products_description_to_text.rb
@@ -0,0 +1,5 @@
+class ChangeProductsDescriptionToText < ActiveRecord::Migration[5.2]
+ def change
+ change_column :products, :description, :text
+ end
+end
diff --git a/db/migrate/20181019064613_add_provider_col_user.rb b/db/migrate/20181019064613_add_provider_col_user.rb
new file mode 100644
index 0000000000..b2fff32f05
--- /dev/null
+++ b/db/migrate/20181019064613_add_provider_col_user.rb
@@ -0,0 +1,16 @@
+class AddProviderColUser < ActiveRecord::Migration[5.2]
+ def change
+ add_column :users, :provider, :string
+ change_column :users, :uid, :integer, null: false
+ change_column :users, :username, :string, null: false
+
+ # reset column info to prevent strange things
+ User.reset_column_information
+
+ # update vote count values in db
+ User.all.each do |user|
+ user.update_attribute :provider, 'github'
+ end
+
+ end
+end
diff --git a/db/migrate/20181019070105_provider_not_nullable_user.rb b/db/migrate/20181019070105_provider_not_nullable_user.rb
new file mode 100644
index 0000000000..54079f4dcf
--- /dev/null
+++ b/db/migrate/20181019070105_provider_not_nullable_user.rb
@@ -0,0 +1,5 @@
+class ProviderNotNullableUser < ActiveRecord::Migration[5.2]
+ def change
+ change_column :users, :provider, :string, null: false
+ end
+end
diff --git a/db/migrate/20181019214941_changeprovidernill.rb b/db/migrate/20181019214941_changeprovidernill.rb
new file mode 100644
index 0000000000..38e7272eb0
--- /dev/null
+++ b/db/migrate/20181019214941_changeprovidernill.rb
@@ -0,0 +1,5 @@
+class Changeprovidernill < ActiveRecord::Migration[5.2]
+ def change
+ change_column :users, :provider, :string
+ end
+end
diff --git a/db/migrate/20181019215248_providernil.rb b/db/migrate/20181019215248_providernil.rb
new file mode 100644
index 0000000000..ce89d9e851
--- /dev/null
+++ b/db/migrate/20181019215248_providernil.rb
@@ -0,0 +1,5 @@
+class Providernil < ActiveRecord::Migration[5.2]
+ def change
+ change_column :users, :provider, :string, null: true
+ end
+end
diff --git a/db/migrate/20181019215535_change_null_user_provider.rb b/db/migrate/20181019215535_change_null_user_provider.rb
new file mode 100644
index 0000000000..39203a422a
--- /dev/null
+++ b/db/migrate/20181019215535_change_null_user_provider.rb
@@ -0,0 +1,5 @@
+class ChangeNullUserProvider < ActiveRecord::Migration[5.2]
+ def change
+ change_column :users, :provider, :string, null: true
+ end
+end
diff --git a/db/migrate/20181019215725_change_provider_in_users.rb b/db/migrate/20181019215725_change_provider_in_users.rb
new file mode 100644
index 0000000000..b3dd455255
--- /dev/null
+++ b/db/migrate/20181019215725_change_provider_in_users.rb
@@ -0,0 +1,5 @@
+class ChangeProviderInUsers < ActiveRecord::Migration[5.2]
+ def change
+ change_column :users, :provider, :string, null: true
+ end
+end
diff --git a/db/migrate/20181021220825_create_order_statuses.rb b/db/migrate/20181021220825_create_order_statuses.rb
new file mode 100644
index 0000000000..4b19173f11
--- /dev/null
+++ b/db/migrate/20181021220825_create_order_statuses.rb
@@ -0,0 +1,10 @@
+class CreateOrderStatuses < ActiveRecord::Migration[5.2]
+ def change
+ # drop_table :order_statuses, force: :cascade
+ create_table :order_statuses do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20181022054705_add_references_products_orders.rb b/db/migrate/20181022054705_add_references_products_orders.rb
new file mode 100644
index 0000000000..b3be5f55d5
--- /dev/null
+++ b/db/migrate/20181022054705_add_references_products_orders.rb
@@ -0,0 +1,8 @@
+class AddReferencesProductsOrders < ActiveRecord::Migration[5.2]
+ def change
+ remove_column :order_items, :product_id
+ remove_column :order_items, :order_id
+ add_reference :order_items, :product, foreign_key: true
+ add_reference :order_items, :order, foreign_key: true
+ end
+end
diff --git a/db/migrate/20181022070614_add_reference_order_status_to_order_items.rb b/db/migrate/20181022070614_add_reference_order_status_to_order_items.rb
new file mode 100644
index 0000000000..7e11969ad8
--- /dev/null
+++ b/db/migrate/20181022070614_add_reference_order_status_to_order_items.rb
@@ -0,0 +1,5 @@
+class AddReferenceOrderStatusToOrderItems < ActiveRecord::Migration[5.2]
+ def change
+ add_reference :order_items, :order_status, foreign_key: true
+ end
+end
diff --git a/db/migrate/20181022232304_remove_reference_order_item_status.rb b/db/migrate/20181022232304_remove_reference_order_item_status.rb
new file mode 100644
index 0000000000..12e5e00540
--- /dev/null
+++ b/db/migrate/20181022232304_remove_reference_order_item_status.rb
@@ -0,0 +1,6 @@
+class RemoveReferenceOrderItemStatus < ActiveRecord::Migration[5.2]
+ def change
+ remove_reference(:order_items, :order_status, index: true)
+
+ end
+end
diff --git a/db/migrate/20181025035101_add_default_item_shipped_false.rb b/db/migrate/20181025035101_add_default_item_shipped_false.rb
new file mode 100644
index 0000000000..1a0ae7d566
--- /dev/null
+++ b/db/migrate/20181025035101_add_default_item_shipped_false.rb
@@ -0,0 +1,5 @@
+class AddDefaultItemShippedFalse < ActiveRecord::Migration[5.2]
+ def change
+ change_column_default :order_items, :shipped, false
+ end
+end
diff --git a/db/migrate/20181025223530_remove_order_status_table.rb b/db/migrate/20181025223530_remove_order_status_table.rb
new file mode 100644
index 0000000000..d2966097bf
--- /dev/null
+++ b/db/migrate/20181025223530_remove_order_status_table.rb
@@ -0,0 +1,5 @@
+class RemoveOrderStatusTable < ActiveRecord::Migration[5.2]
+ def change
+
+ end
+end
diff --git a/db/order_seeds.csv b/db/order_seeds.csv
new file mode 100644
index 0000000000..dac1543e7b
--- /dev/null
+++ b/db/order_seeds.csv
@@ -0,0 +1,2 @@
+status,cust_name,cust_email,mailing_address,cc_name,cc_digit,cc_expiration,cc_cvv,cc_zip
+paid,Darienne Lake,rico.ryan@example.net,"Suite 960 578 Marvin Park, West Astridstad, MT 01415",Lisa Ford,6035639394729400,2019-10-19,389,14426
diff --git a/db/product_seeds.csv b/db/product_seeds.csv
new file mode 100644
index 0000000000..21d72bba9b
--- /dev/null
+++ b/db/product_seeds.csv
@@ -0,0 +1,4 @@
+prod_name,user_id,description,price,inv_qty,active,image
+I Vote Cupcake,1,Vanilla cake topped with vanilla buttercream and “I Vote Cupcake” edible image,2.50,10,active,https://www.cupcakeroyale.com/wp-content/uploads/2018/08/20180827-I-Vote-Cupcake-003-620x620.jpg
+Pumpkin Cardamom,1,Pumpkin spice cake with cardamom cream cheese frosting and spiced pumpkin seeds!,2.75,8,active,https://www.cupcakeroyale.com/wp-content/uploads/2016/02/20170925-Pumpkin-Cardamom-011-sq-620x620.jpg
+Fig and Honey,1,Brown butter vanilla cake filled with a rich and citrusy fig compote,2.25,10,active,https://www.cupcakeroyale.com/wp-content/uploads/2017/08/20170817-Fig-and-Honey-120-620x413.jpg
diff --git a/db/review_seeds.csv b/db/review_seeds.csv
new file mode 100644
index 0000000000..d6681f8d81
--- /dev/null
+++ b/db/review_seeds.csv
@@ -0,0 +1,5 @@
+rating,description,product_id
+3,"It was delicious, like a party in my mouth",1
+5,"Pleasantly spiced and full of pumpkin flavor",2
+4,"Tasted like Fall, the fig compote was super yum!",3
+3,"So so good, like nothing I've ever tasted",2
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000000..4602181ee8
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,97 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 2018_10_25_223530) 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 "category"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "categories_products", force: :cascade do |t|
+ t.bigint "category_id"
+ t.bigint "product_id"
+ t.index ["category_id"], name: "index_categories_products_on_category_id"
+ t.index ["product_id"], name: "index_categories_products_on_product_id"
+ end
+
+ create_table "order_items", force: :cascade do |t|
+ t.integer "qty"
+ t.boolean "shipped", default: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "product_id"
+ t.bigint "order_id"
+ t.index ["order_id"], name: "index_order_items_on_order_id"
+ t.index ["product_id"], name: "index_order_items_on_product_id"
+ end
+
+ create_table "order_statuses", force: :cascade do |t|
+ t.string "name"
+ 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 "cust_name"
+ t.string "cust_email"
+ t.text "mailing_address"
+ t.string "cc_name"
+ t.bigint "cc_digit"
+ t.date "cc_expiration"
+ t.integer "cc_cvv"
+ t.integer "cc_zip"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "products", force: :cascade do |t|
+ t.string "prod_name"
+ t.text "description"
+ t.float "price"
+ t.integer "inv_qty"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "image"
+ t.boolean "active", default: true
+ t.bigint "user_id"
+ t.index ["user_id"], name: "index_products_on_user_id"
+ end
+
+ create_table "reviews", force: :cascade do |t|
+ t.integer "rating"
+ t.text "description"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "product_id"
+ t.index ["product_id"], name: "index_reviews_on_product_id"
+ end
+
+ create_table "users", force: :cascade do |t|
+ t.integer "uid", null: false
+ t.string "username", null: false
+ t.string "email"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "provider"
+ end
+
+ add_foreign_key "order_items", "orders"
+ add_foreign_key "order_items", "products"
+ add_foreign_key "products", "users"
+ add_foreign_key "reviews", "products"
+end
diff --git a/db/seeds.rb b/db/seeds.rb
new file mode 100644
index 0000000000..7562e82309
--- /dev/null
+++ b/db/seeds.rb
@@ -0,0 +1,155 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
+#
+# Examples:
+#
+# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
+# Character.create(name: 'Luke', movie: movies.first)
+require 'csv'
+USER_FILE = Rails.root.join('db', 'user_seeds.csv')
+puts "Loading raw review data from #{USER_FILE}"
+
+user_failures = []
+CSV.foreach(USER_FILE, :headers => true) do |row|
+ user = User.new
+ user.uid = row['uid']
+ user.username = row['username']
+ user.email = row['email']
+ successful = user.save
+ if !successful
+ user_failures << user
+ puts "Failed to save user: #{user.inspect}"
+ puts "Error: #{user.errors}"
+ else
+ puts "Created user: #{user.inspect}"
+ end
+end
+
+puts "Added #{User.count} user records"
+puts "#{user_failures.length} user failed to save"
+
+
+
+PRODUCT_FILE = Rails.root.join('db', 'product_seeds.csv')
+puts "Loading raw review data from #{PRODUCT_FILE}"
+
+product_failures = []
+CSV.foreach(PRODUCT_FILE, :headers => true) do |row|
+ product = Product.new
+ product.prod_name = row['prod_name']
+ product.user_id = row['user_id']
+ product.description = row['description']
+ product.price = row['price']
+ product.inv_qty = row['inv_qty']
+ product.active = row['active']
+ product.image = row['image']
+ successful = product.save
+ if !successful
+ product_failures << product
+ puts "Failed to save product: #{product.inspect}"
+ puts "Error: #{product.errors}"
+ else
+ puts "Created product: #{product.inspect}"
+ end
+end
+
+puts "Added #{Product.count} product records"
+puts "#{product_failures.length} product failed to save"
+
+ORDER_FILE = Rails.root.join('db', 'order_seeds.csv')
+puts "Loading raw order data from #{ORDER_FILE}"
+
+order_failures = []
+CSV.foreach(ORDER_FILE, :headers => true) do |row|
+ order = Order.new
+ order.status = row['status']
+ order.cust_name = row['cust_name']
+ order.cust_email = row['cust_email']
+ order.mailing_address = row['mailing_address']
+ order.cc_name = row['cc_name']
+ order.cc_digit = row['cc_digit']
+ order.cc_expiration = row['cc_expiration']
+ order.cc_cvv = row['cc_cvv']
+ order.cc_zip = row['cc_zip']
+ successful = order.save
+ if !successful
+ order_failures << order
+ puts "Failed to save order: #{order.inspect}"
+ puts "Error: #{order.errors}"
+ else
+ puts "Created order: #{order.inspect}"
+ end
+end
+
+puts "Added #{Order.count} order records"
+puts "#{order_failures.length} order failed to save"
+
+
+
+
+
+REVIEW_FILE = Rails.root.join('db', 'review_seeds.csv')
+puts "Loading raw review data from #{REVIEW_FILE}"
+
+review_failures = []
+CSV.foreach(REVIEW_FILE, :headers => true) do |row|
+ review = Review.new
+ review.rating = row['rating']
+ review.description = row['description']
+ review.product_id = row['product_id']
+ successful = review.save
+ if !successful
+ review_failures << review
+ puts "Failed to save review: #{review.inspect}"
+ puts "Error: #{review.errors}"
+ else
+ puts "Created review: #{review.inspect}"
+ end
+end
+
+puts "Added #{Review.count} review records"
+puts "#{review_failures.length} review failed to save"
+
+
+
+
+#Populate order_items table
+
+# OrderItem.create(order_id: 2, product_id: 1, qty: 1, shipped: false)
+# add 3 items to first order
+# Order.first.order_items << Product.sample(3)
+# #
+
+
+CATEGORY_FILE = Rails.root.join('db', 'category_seeds.csv')
+puts "Loading raw review data from #{REVIEW_FILE}"
+
+category_failures = []
+CSV.foreach(CATEGORY_FILE, :headers => true) do |row|
+ category = Category.new
+ category.category = row['category']
+
+ successful = category.save
+ if !successful
+ category_failures << category
+ puts "Failed to save category: #{category.inspect}"
+ puts "Error: #{category.errors}"
+ else
+ puts "Created category: #{category.inspect}"
+ end
+end
+
+puts "Added #{Category.count} category records"
+puts "#{category_failures.length} category failed to save"
+
+
+Product.all.each do |product|
+ product.categories << Category.first
+end
+
+
+OrderStatus.delete_all
+OrderStatus.create! id: 1, name: "In Progress"
+OrderStatus.create! id: 2, name: "Placed"
+OrderStatus.create! id: 3, name: "Shipped"
+OrderStatus.create! id: 4, name: "Cancelled"
diff --git a/db/user_seeds.csv b/db/user_seeds.csv
new file mode 100644
index 0000000000..ccc1f078c7
--- /dev/null
+++ b/db/user_seeds.csv
@@ -0,0 +1,2 @@
+uid,username,email
+1,cupcakeroyale,cupcakes@cupcakes.com
diff --git a/lib/assets/.keep b/lib/assets/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/lib/tasks/.keep b/lib/tasks/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/log/.keep b/log/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/package.json b/package.json
new file mode 100644
index 0000000000..f874acf437
--- /dev/null
+++ b/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "betsy",
+ "private": true,
+ "dependencies": {}
+}
diff --git a/public/404.html b/public/404.html
new file mode 100644
index 0000000000..2be3af26fc
--- /dev/null
+++ b/public/404.html
@@ -0,0 +1,67 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/422.html b/public/422.html
new file mode 100644
index 0000000000..c08eac0d1d
--- /dev/null
+++ b/public/422.html
@@ -0,0 +1,67 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/500.html b/public/500.html
new file mode 100644
index 0000000000..78a030af22
--- /dev/null
+++ b/public/500.html
@@ -0,0 +1,66 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000000..37b576a4a0
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1 @@
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
diff --git a/storage/.keep b/storage/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/temp.txt b/temp.txt
new file mode 100644
index 0000000000..40ae76a92d
--- /dev/null
+++ b/temp.txt
@@ -0,0 +1,12 @@
+rails generate scaffold user uid:integer username:string email:string
+
+rails generate scaffold product category:string prod_name:string description:string price:float inv_qty:integer
+
+rails generate scaffold order status:string cust_name:string cust_email:string mailing_address:integer cc_name:string cc_digit:integer cc_expiration:date cc_cvv:integer cc_zip:integer
+
+rails generate scaffold review rating:integer description:string
+
+
+rails g migration CreateCategoriesProductsJoin
+
+rails db:migrate
\ No newline at end of file
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
new file mode 100644
index 0000000000..d19212abd5
--- /dev/null
+++ b/test/application_system_test_case.rb
@@ -0,0 +1,5 @@
+require "test_helper"
+
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
+end
diff --git a/test/controllers/.keep b/test/controllers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb
new file mode 100644
index 0000000000..4eae0b05ab
--- /dev/null
+++ b/test/controllers/carts_controller_test.rb
@@ -0,0 +1,36 @@
+require "test_helper"
+
+describe CartsController do
+
+ let (:product1) { products(:cake1) }
+
+ let (:order_item_hash1) {
+ {
+ order_item: {
+ product_id: product1.id,
+ qty: 5
+ }
+ }
+ }
+
+
+ it "should get a cart's show if order exists" do
+ post order_items_path, params: order_item_hash1
+ order_id = Order.last.id
+
+ get cart_path(order_id)
+
+ must_respond_with :success
+
+ end
+
+ it "should respond with not_found given an invalid order_id" do
+ order_id = -1
+
+ get cart_path(order_id)
+
+ must_respond_with :not_found
+
+ end
+
+end
diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb
new file mode 100644
index 0000000000..1ae548a028
--- /dev/null
+++ b/test/controllers/categories_controller_test.rb
@@ -0,0 +1,19 @@
+require "test_helper"
+
+describe CategoriesController do
+ it "should get index" do
+ get categories_index_url
+ value(response).must_be :success?
+ end
+
+ it "should get new" do
+ get categories_new_url
+ value(response).must_be :success?
+ end
+
+ it "should get create" do
+ get categories_create_url
+ value(response).must_be :success?
+ end
+
+end
diff --git a/test/controllers/order_items_controller_test.rb b/test/controllers/order_items_controller_test.rb
new file mode 100644
index 0000000000..10f938e3fe
--- /dev/null
+++ b/test/controllers/order_items_controller_test.rb
@@ -0,0 +1,241 @@
+require "test_helper"
+
+describe OrderItemsController do
+
+ let (:product1) { products(:cake1) }
+ let (:product2) { products(:cake3) }
+
+ let (:order_item_hash1) {
+ {
+ order_item: {
+ product_id: product1.id,
+ qty: 5
+ }
+ }
+ }
+
+ let (:order_item_hash2) {
+ {
+ order_item: {
+ product_id: product2.id,
+ qty: 3
+ }
+ }
+ }
+
+ let (:exceeds_inventory) {
+ {
+ order_item: {
+ product_id: product1.id,
+ qty: 8
+ }
+ }
+ }
+
+ let (:update_order_item1) {
+ {
+ order_item: {
+ product_id: product1.id,
+ qty: 3
+ }
+ }
+ }
+
+ let (:invalid_data) {
+ {
+ order_item: {
+ product_id: product1.id,
+ qty: nil
+ }
+ }
+ }
+
+ describe 'create' do
+
+ it 'can create a new order line item when order does not already exist' do
+
+ orders_before = Order.count
+
+ expect {
+ post order_items_path, params: order_item_hash1
+ }.must_change 'OrderItem.count', 1
+
+ orders_after = Order.count
+ order_id = Order.last.id
+
+ must_respond_with :redirect
+ must_redirect_to cart_path(order_id)
+
+ expect(orders_after).must_equal orders_before + 1
+ expect(OrderItem.last.product_id).must_equal product1.id
+ expect(OrderItem.last.order_id).must_equal order_id
+ end
+
+ it 'can create a new order line item to existing order' do
+
+ post order_items_path, params: order_item_hash1
+ order_id = Order.last.id
+
+ expect {
+ post order_items_path, params: order_item_hash2
+ }.must_change 'OrderItem.count', 1
+
+ must_respond_with :redirect
+ must_redirect_to cart_path(order_id)
+ expect(OrderItem.last.product_id).must_equal product2.id
+ expect(OrderItem.last.order_id).must_equal order_id
+ end
+
+ it 'can not add a line order item if quantity exceeds inventory' do
+
+ expect {
+ post order_items_path, params: exceeds_inventory
+ }.wont_change 'OrderItem.count'
+
+ must_respond_with :redirect
+ must_redirect_to product_path(product1.id)
+
+ end
+
+ end
+
+ describe 'update' do
+
+ before do
+ post order_items_path, params: order_item_hash1
+ @order_id = Order.last.id
+ @order_item_id = OrderItem.last.id
+ @before_qty = OrderItem.find_by(id: @order_item_id).qty
+ end
+
+ it 'can update an existing order line item with valid data' do
+
+ expect {
+ patch order_item_path(@order_item_id), params: update_order_item1
+ }.wont_change 'OrderItem.count'
+
+ after_qty = OrderItem.find_by(id: @order_item_id).qty
+
+ expect(after_qty).must_equal update_order_item1[:order_item][:qty]
+ must_respond_with :redirect
+ must_redirect_to cart_path(@order_id)
+
+ end
+
+ it 'will not update an existing order line item with invalid data' do
+
+ expect {
+ patch order_item_path(@order_item_id), params: invalid_data
+ }.wont_change 'OrderItem.count'
+
+ after_qty = OrderItem.find_by(id: @order_item_id).qty
+
+ expect(after_qty).must_equal @before_qty
+
+ must_respond_with :redirect
+ must_redirect_to root_path
+ end
+
+ it 'will redirect when a line order item does not exist to update' do
+
+ expect {
+ patch order_item_path(-1), params: update_order_item1
+ }.wont_change 'OrderItem.count'
+
+ must_respond_with :redirect
+ must_redirect_to root_path
+
+ end
+
+ it 'will will not update existing order line item when qty exceeds inventory count' do
+
+ expect {
+ patch order_item_path(@order_item_id), params: exceeds_inventory
+ }.wont_change 'OrderItem.count'
+
+ after_qty = OrderItem.find_by(id: @order_item_id).qty
+
+ expect(after_qty).must_equal @before_qty
+
+ must_respond_with :redirect
+ must_redirect_to product_path(product1.id)
+ end
+ end
+
+ describe 'destroy' do
+
+ before do
+ post order_items_path, params: order_item_hash1
+ @order_id = Order.last.id
+ @order_item_id = OrderItem.last.id
+ @before_qty = OrderItem.find_by(id: @order_item_id).qty
+ end
+
+ it 'can delete an existing order line item' do
+
+ expect{
+ delete order_item_path(@order_item_id)
+ }.must_change 'OrderItem.count', -1
+
+ must_respond_with :redirect
+ must_redirect_to cart_path(@order_id)
+ expect(OrderItem.find_by(id: @order_item_id)).must_be_nil
+ end
+
+ it 'will render not_found when a line order item does not exist to delete' do
+ end
+
+ end
+
+ describe 'cart_direct' do
+
+ it 'can add a line order item with a qty of 1 when existing order exists' do
+ post order_items_path, params: order_item_hash1
+ order_id = Order.last.id
+
+ new_item = products(:cake3)
+
+ expect {
+ post quick_shop_path(new_item.id)
+ }.must_change 'OrderItem.count', 1
+
+ must_respond_with :redirect
+ must_redirect_to cart_path(order_id)
+ expect(OrderItem.last.product_id).must_equal new_item.id
+ expect(OrderItem.last.order_id).must_equal order_id
+
+ end
+
+ it 'can add a line order item with a qty of 1 when existing order does not exist' do
+
+ orders_before = Order.count
+ new_item = products(:cake3)
+
+ expect {
+ post quick_shop_path(new_item.id)
+ }.must_change 'OrderItem.count', 1
+
+ orders_after = Order.count
+ order_id = Order.last.id
+
+ must_respond_with :redirect
+ must_redirect_to cart_path(order_id)
+
+ expect(orders_after).must_equal orders_before + 1
+ expect(OrderItem.last.product_id).must_equal new_item.id
+ expect(OrderItem.last.order_id).must_equal order_id
+ end
+
+ it 'can not add a line order item if item is out of stock' do
+ product = products(:brownie)
+
+ expect {
+ post quick_shop_path(product.id)
+ }.wont_change 'OrderItem.count'
+
+ must_respond_with :redirect
+ must_redirect_to products_path
+ end
+ end
+
+end
diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb
new file mode 100644
index 0000000000..8bb3a58a44
--- /dev/null
+++ b/test/controllers/orders_controller_test.rb
@@ -0,0 +1,158 @@
+require "test_helper"
+
+describe OrdersController do
+ let(:order) { orders :one }
+
+ it "gets index" do
+ get orders_url
+
+ value(response).must_be :successful?
+ end
+
+ describe "show" do
+
+ it "it shows an order for that merchant" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = orders(:one).id
+
+ get orders_path(id)
+
+ value(response).must_be :successful?
+ end
+
+ it "will not allow another merchant to view an order without their product" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = orders(:two).id
+
+ get orders_path(id)
+
+ value(response).must_be :successful?
+ end
+ end
+
+ describe "update" do
+ # placing the order we use update
+ let (:product) { products(:cake1) }
+
+ let (:order_item_hash) {
+ {
+ order_item: {
+ product_id: product.id,
+ qty: 5
+ }
+ }
+ }
+
+ let (:confirm_hash) do
+ {
+ order: {
+ cc_cvv: order.cc_cvv,
+ cc_digit: order.cc_digit,
+ cc_expiration: order.cc_expiration,
+ cc_name: order.cc_name,
+ cc_zip: order.cc_zip,
+ cust_email: order.cust_email,
+ cust_name: order.cust_name,
+ mailing_address: order.mailing_address,
+ status: order.status
+ }
+ }
+ end
+ #PATCH /orders/:id
+ it "will allow merchant confirm a purchase with valid params" do
+ user = users(:laura)
+ perform_login(user)
+
+ expect {
+ post order_items_path, params: order_item_hash
+ }.must_change 'OrderItem.count', 1
+
+ id = Order.last.id
+
+ expect {
+ patch order_path(id), params: confirm_hash
+ }.wont_change "Order.count"
+
+ expect(flash.now[:success]).must_equal "Order was accepted"
+ expect(order.cc_name).must_equal confirm_hash[:order][:cc_name]
+ expect(order.cust_email).must_equal confirm_hash[:order][:cust_email]
+ end
+
+ it "does not confirm a order with zero items in the cart" do
+ user = users(:laura)
+ perform_login(user)
+
+ expect {
+ post order_items_path, params: order_item_hash
+ }.must_change 'OrderItem.count', 1
+
+ order = Order.last
+ order.order_items.destroy_all
+
+ expect {
+ patch order_path(order.id), params: confirm_hash
+ }.wont_change "Order.count"
+
+ must_redirect_to products_path
+ expect(flash[:warning]).must_equal "You have zero items in your cart"
+ end
+
+ it "allow a guest user add items to cart" do
+ expect {
+ post order_items_path, params: order_item_hash
+ }.must_change 'OrderItem.count', 1
+
+ id = Order.last.id
+
+ expect {
+ patch order_path(id), params: confirm_hash
+ }.wont_change "Order.count"
+
+ expect(flash.now[:success]).must_equal "Order was accepted"
+ end
+
+ it "does not complete an order with invalid params" do
+ confirm_hash[:order][:cust_name] = nil
+
+ expect {
+ post order_items_path, params: order_item_hash
+ }.must_change 'OrderItem.count', 1
+
+ id = Order.last.id
+
+ expect {
+ patch order_path(id), params: confirm_hash
+ }.wont_change "Order.count"
+
+ must_respond_with :success
+ expect(flash.now[:warning]).must_equal 'Order was not not created'
+ end
+
+ it "does not load an invalid order" do
+ id = -1
+
+ expect {
+ patch order_path(id)
+ }.wont_change 'Order.count'
+
+ must_redirect_to order_path
+ expect(flash[:now]).must_equal "Order does not exsist"
+ end
+
+ end
+
+ # describe "destroy" do
+ # it "destroys order" do
+ # expect {
+ # delete order_url(order)
+ # }.must_change "Order.count", -1
+ #
+ # must_redirect_to orders_path
+ # end
+ # end
+
+end
diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb
new file mode 100644
index 0000000000..228f527a2a
--- /dev/null
+++ b/test/controllers/products_controller_test.rb
@@ -0,0 +1,283 @@
+require "test_helper"
+
+describe ProductsController do
+ let(:product) { build(:product) }
+
+ it "gets index" do
+ get products_url
+ value(response).must_be :successful?
+ end
+
+ describe "new" do
+
+ it "gets new form for a logged in user" do
+ user = users(:laura)
+ perform_login(user)
+
+ get new_product_path
+ value(response).must_be :successful?
+ end
+
+ it "is an invalid request if merchant is not logged in" do
+ get new_product_path
+
+ must_redirect_to root_path
+ value(response).must_be :redirection?
+ expect(flash[:danger]).must_equal "You must log in to access this feature"
+ end
+ end
+
+ describe "create" do
+
+ it "creates product" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = users(:laura).id
+ product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: id } }
+
+ expect {
+ post products_path, params: product_hash
+ }.must_change "Product.count"
+
+ must_redirect_to user_path(session[:user_id])
+ expect(flash[:notice]).must_equal "#{product.prod_name} was added to your inventory."
+ end
+
+ it "is an forbidden request if user is not logged in" do
+ product_hash = { product: { prod_name: product.prod_name, description: product.description, price: product.price, inv_qty: product.inv_qty, user: nil } }
+
+ expect {
+ post products_path, params: product_hash
+ }.wont_change "Product.count"
+
+ must_redirect_to root_path
+ expect(response.response_code).must_equal 302
+ end
+ end
+
+ describe "show" do
+
+ it "show a single product detail page" do
+ id = Product.first.id
+
+ get product_path(id)
+ value(response).must_be :successful?
+ end
+
+ it "should repond with not_found if given an invalid id" do
+ id = -1
+
+ get product_path(id)
+
+ must_respond_with :not_found
+ end
+
+ end
+
+ describe "edit" do
+
+ it "gets edit form page for a logged in merchant" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = products(:cake1).id
+
+ get edit_product_path(id)
+ value(response).must_be :successful?
+ end
+
+ it "should respond with not_found if an invalid product id is entered" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = products(:cake2).id
+
+ get edit_product_path(id)
+
+ must_redirect_to product_path(id)
+ expect(flash[:danger]).must_equal "You don't have access to edit this product."
+ end
+
+ it "does not give a logged out user access to a product edit page" do
+ id = products(:cake2).id
+
+ get edit_product_path(id)
+
+ must_redirect_to root_path
+ end
+
+ it "should respond with not_found if given an invalid id" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = -1
+
+ get edit_product_path(id)
+
+ must_respond_with :not_found
+ end
+ end
+
+ describe "update" do
+ let(:laura) {users(:laura)}
+ let (:product_hash) do
+ {
+ product: {
+ prod_name: product.prod_name,
+ description: product.description,
+ price: product.price,
+ inv_qty: product.inv_qty,
+ user: laura.id
+ }
+ }
+ end
+
+ it "a merchant can update their product" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = products(:cake1).id
+
+ expect {
+ patch product_path(id), params: product_hash
+ }.wont_change "Product.count"
+
+ must_redirect_to product_path
+ expect(flash[:notice]).must_equal "#{product.prod_name} was successfully updated."
+
+ new_product = Product.find_by(id: id)
+
+ expect(new_product.prod_name).must_equal product_hash[:product][:prod_name]
+ expect(new_product.description).must_equal product_hash[:product][:description]
+ end
+
+ it "a user not logged in cant update a product" do
+ id = products(:cake1).id
+
+ expect {
+ patch product_path(id), params: product_hash
+ }.wont_change "Product.count"
+
+ must_redirect_to root_path(id)
+ end
+
+ it "a gives an error if the product params are invalid" do
+ user = users(:laura)
+ perform_login(user)
+
+ cake1 = products(:cake1)
+ product_hash[:product][:prod_name] = cake1.prod_name
+
+ id = products(:cake2).id
+ old_product = products(:cake2)
+
+ expect {
+ patch product_path(id), params: product_hash
+ }.wont_change "Product.count"
+
+ new_product = Product.find(id)
+
+ must_respond_with :success
+ expect(old_product.prod_name).must_equal new_product.prod_name
+ expect(old_product.description).must_equal new_product.description
+ expect(flash[:warning]).must_equal "Edit was unsuccessful"
+ end
+
+ it "gives not_found for a product that doesnt exist" do
+ id = -1
+
+ expect {
+ patch product_path(id)
+ }.wont_change 'Product.count'
+
+ must_respond_with :not_found
+ end
+ end
+
+ describe "category" do
+
+ it "finds a category for product" do
+ id = Category.first.id
+
+ get category_path(id)
+
+ value(response).must_be :successful?
+ end
+
+ it "redirects to root_path for invalid category" do
+ id = 56
+
+ get category_path(id)
+
+ # value(response).must_be :successful?
+ must_redirect_to root_path
+ expect(flash[:warning]).must_equal "Category is invalid"
+ end
+ end
+
+
+ describe "merchant" do
+
+ it "finds a merchant for a product" do
+ id = User.first.id
+
+ get merchant_path(id)
+
+ value(response).must_be :successful?
+ end
+
+ it "redirects to root_path for invalid category" do
+ id = -56
+
+ get merchant_path(id)
+
+ # value(response).must_be :successful?
+ must_redirect_to root_path
+ expect(flash[:warning]).must_equal "User is invalid"
+ end
+
+ end
+
+ describe "status" do
+
+ it "changes an inactive product to active" do
+ user = users(:laura)
+ perform_login(user)
+
+ product = Product.find_by(prod_name: "a wedding cake")
+
+ patch product_status_path(product)
+
+ # must_respond_with :redirect
+ expect(product.active).must_equal true
+ end
+
+ it "changes an active product to inactive" do
+ user = users(:laura)
+ perform_login(user)
+
+ product = Product.find_by(prod_name: "a wedding cake")
+ product.active = true
+ product.save
+
+ patch product_status_path(product)
+ product_new = Product.find_by(prod_name: "a wedding cake")
+
+ # must_respond_with :redirect
+ expect(product_new.active).must_equal false
+ expect(flash[:notice]).must_equal "#{product.prod_name} status successfully retired."
+ end
+
+ it "reponds with not found for invalid product" do
+ id = -56
+
+ patch product_status_path(id)
+
+ # value(response).must_be :successful?
+ must_respond_with :not_found
+ end
+
+ end
+
+end
diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb
new file mode 100644
index 0000000000..a8e29675d5
--- /dev/null
+++ b/test/controllers/reviews_controller_test.rb
@@ -0,0 +1,67 @@
+require "test_helper"
+
+describe ReviewsController do
+ let(:review) { reviews :one }
+
+ it "gets index" do
+ get reviews_url
+ value(response).must_be :successful?
+ end
+
+ describe "new" do
+
+ it "gets the form with the new review page" do
+ id = products(:cake1).id
+
+ get new_product_review_path(id)
+ value(response).must_be :successful?
+ end
+
+ end
+
+ describe "create" do
+
+ it "creates a new review given valid params" do
+ id = products(:cake1).id
+ review_hash = { review: { description: review.description, rating: review.rating} }
+
+ expect {
+ post product_reviews_path(id), params: review_hash
+ }.must_change "Review.count", 1
+
+ must_redirect_to product_path(id)
+
+ expect(Review.last.description).must_equal review_hash[:review][:description]
+ expect(Review.last.rating).must_equal review_hash[:review][:rating]
+ end
+
+ it "respond with an redirect for invalid params" do
+ id = products(:cake1).id
+ review_hash = { review: { description: review.description } }
+
+ expect {
+ post product_reviews_path(id), params: review_hash
+ }.wont_change "Review.count"
+
+ must_respond_with :success
+ expect(flash[:warning]).must_equal "Please enter all fields"
+ end
+
+ it "respond with an error if merchant reviews their own product" do
+ user = users(:laura)
+ perform_login(user)
+
+ id = products(:cake1).id
+ review_hash = { review: { description: review.description, rating: review.rating} }
+
+ expect {
+ post product_reviews_path(id), params: review_hash
+ }.wont_change "Review.count"
+
+ must_redirect_to products_path
+ expect(flash[:warning]).must_equal "You can't review your own Product"
+ end
+ end
+
+
+end
diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb
new file mode 100644
index 0000000000..8663792f55
--- /dev/null
+++ b/test/controllers/sessions_controller_test.rb
@@ -0,0 +1,86 @@
+require "test_helper"
+
+describe SessionsController do
+ # it "should get login" do
+ # get login_path
+ # value(response).must_be :success?
+ # end
+ #
+ # it "should get new" do
+ # get sessions_new_url
+ # value(response).must_be :success?
+ # end
+ #
+ # it "should get destroy" do
+ # get sessions_destroy_url
+ # value(response).must_be :success?
+ # end
+
+ describe "auth_callback" do
+
+ it "logs in an existing user" do
+ start_count = User.count
+ user = users(:grace)
+
+ perform_login(user)
+
+ must_redirect_to root_path
+ expect(flash[:result_text]).must_match /Successfully logged*/
+ session[:user_id].must_equal user.id
+
+ # Should *not* have created a new user
+ User.count.must_equal start_count
+ end
+
+ it "can login in a new user with good data" do
+ user = users(:ada)
+ # remove ada test user from test db
+ user.destroy
+ # login ada as new user to test db
+ perform_login(user)
+ # user count should increase by 1
+ expect do
+ get auth_callback_path(:github).must_change('User.count' +1)
+ end
+ # redirect to root_path
+ must_redirect_to root_path
+ expect(flash[:result_text]).must_match /Successfully created*/
+ expect(session[:user_id]).wont_be_nil
+ end
+
+ it "rejects an invalid user login with bad data" do
+ user = users(:ada)
+ user.uid = nil
+
+ perform_login(user)
+
+ expect do
+ get auth_callback_path(:github).wont_change 'User.count'
+ end
+
+ must_respond_with :bad_request
+ expect(session[:user_id]).must_be_nil
+
+ end
+
+ describe "logout" do
+ it 'can log out' do
+ user = users(:grace)
+
+ perform_login(user)
+
+ delete logout_path
+
+ expect do
+ get auth_callback_path(:github).wont_change 'User.count'
+ end
+
+ must_redirect_to root_path
+ expect(session[:user_id]).must_be_nil
+
+ end
+
+
+ end
+ end
+end
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
new file mode 100644
index 0000000000..7609157f04
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,66 @@
+require "test_helper"
+
+describe UsersController do
+ let(:user) { users :ada }
+
+ it "gets new" do
+ get new_user_url
+ value(response).must_be :successful?
+ end
+
+ it "creates user" do
+ user_hash= {
+ user: {
+ email: 'user3@gmail.com',
+ uid: 2,
+ username: 'newuser'
+ }
+ }
+ expect {
+ post users_path, params: user_hash
+ }.must_change "User.count", 1
+
+ must_redirect_to root_path
+ end
+
+
+ # User test are create and and show order fulfillment if logged in
+ describe "Logged in users" do
+ before do
+ perform_login(users(:grace))
+ end
+
+ describe "show" do
+ # Just the standard show tests
+ it "succeeds for logged in user" do
+ get user_path(session[:user_id])
+ must_respond_with :success
+
+ end
+
+ it "returns 404 a user who is not the logged in user" do
+ a = users(:ada)
+ a_id = a.id
+ get user_path(a_id)
+ must_redirect
+ end
+ end
+
+ # can change an items status to shipped
+ # can add new products
+ # can retire a product
+
+ end
+
+ describe "Guest users" do
+ # it "returns 404 a user who is not the logged in user" do
+ # get user_path(session[:user_id] - 1)
+ # must_respond_with :forbidden
+ # end
+
+
+
+ end
+end
+
+
diff --git a/test/factories/category.rb b/test/factories/category.rb
new file mode 100644
index 0000000000..53208610a8
--- /dev/null
+++ b/test/factories/category.rb
@@ -0,0 +1,5 @@
+FactoryBot.define do
+ factory :category do
+ category { Faker::Name.first_name }
+ end
+end
diff --git a/test/factories/order.rb b/test/factories/order.rb
new file mode 100644
index 0000000000..5aa68a6d8d
--- /dev/null
+++ b/test/factories/order.rb
@@ -0,0 +1,13 @@
+FactoryBot.define do
+ factory :order do
+ status { %w(pending paid complete cancelled).sample}
+ cust_name { Faker::RuPaul.queen}
+ cust_email { Faker::Internet.safe_email}
+ mailing_address { Faker::Address.full_address}
+ cc_name { Faker::FunnyName.two_word_name}
+ cc_digit { "1" * 16}
+ cc_expiration { Faker::Business.credit_card_expiry_date}
+ cc_cvv { Faker::Number.number(3) }
+ cc_zip { Faker::Number.number(5) }
+ end
+end
diff --git a/test/factories/product.rb b/test/factories/product.rb
new file mode 100644
index 0000000000..7055e310d7
--- /dev/null
+++ b/test/factories/product.rb
@@ -0,0 +1,12 @@
+FactoryBot.define do
+ factory :product do
+ # category { %w(birthday wedding chocolate vanilla buttercream).sample}
+ prod_name { Faker::Dessert.variety + ' ' + Faker::Dessert.topping + ' ' + Faker::Dessert.flavor}
+ description { Faker::Coffee.notes}
+ price { Faker::Number.decimal(2, 2)}
+ inv_qty { Faker::Number.between(0, 30)}
+ active { Faker::Boolean.boolean}
+ image { "image test"}
+ user
+ end
+end
diff --git a/test/factories/user.rb b/test/factories/user.rb
new file mode 100644
index 0000000000..eef4244669
--- /dev/null
+++ b/test/factories/user.rb
@@ -0,0 +1,8 @@
+FactoryBot.define do
+ factory :user do
+ uid { rand(1..(2**31)).to_s}
+ provider { "github" }
+ username { Faker::Name.first_name }
+ email { Faker::Internet.email }
+ end
+end
diff --git a/test/fixtures/.keep b/test/fixtures/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml
new file mode 100644
index 0000000000..8492e33dc5
--- /dev/null
+++ b/test/fixtures/categories.yml
@@ -0,0 +1,10 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ category: birthday
+
+two:
+ category: wedding
+
+three:
+ category: chocolate
diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml
new file mode 100644
index 0000000000..d78a92642c
--- /dev/null
+++ b/test/fixtures/order_items.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+line1:
+ order: one
+ product: cake1
+ qty: 2
+ shipped: false
+
+line2:
+ order: two
+ product: cake2
+ qty: 2
+ shipped: false
diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml
new file mode 100644
index 0000000000..5e5b0dce24
--- /dev/null
+++ b/test/fixtures/orders.yml
@@ -0,0 +1,45 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ status: Paid
+ cust_name: Laura
+ cust_email: laura@gmail.com
+ mailing_address: 123 Front St.
+ cc_name: Laura Liz
+ cc_digit: 1111111111111111
+ cc_expiration: 2018-10-17
+ cc_cvv: 123
+ cc_zip: 98765
+
+two:
+ status: pending
+ cust_name: Grace
+ cust_email: grace@gmail.com
+ mailing_address: 123 Front St.
+ cc_name: Laura Liz
+ cc_digit: 1111111111111111
+ cc_expiration: 2018-10-17
+ cc_cvv: 1
+ cc_zip: 1
+
+three:
+ status: pending
+ cust_name: ada
+ cust_email: ada@gmail.com
+ mailing_address: 1
+ cc_name: MyString
+ cc_digit: 1111111111111111
+ cc_expiration: 2018-10-17
+ cc_cvv: 123
+ cc_zip: 98765
+
+three:
+ status: pending
+ cust_name: ada
+ cust_email: grace@gmail.com
+ mailing_address: 123 Front St.
+ cc_name: Laura Liz
+ cc_digit: 1111111111111111
+ cc_expiration: 2018-10-17
+ cc_cvv: 123
+ cc_zip: 98765
diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml
new file mode 100644
index 0000000000..88a704fa9a
--- /dev/null
+++ b/test/fixtures/products.yml
@@ -0,0 +1,32 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+cake1:
+
+ prod_name: a wedding cake
+ description: yum
+ price: 15.5
+ inv_qty: 5
+ user: laura
+
+cake2:
+
+ prod_name: chocolate goodness
+ description: the best
+ price: 19.5
+ inv_qty: 5
+ user: grace
+
+
+cake3:
+ prod_name: vanilla plains
+ description: real vanilla
+ price: 20.5
+ inv_qty: 3
+ user: grace
+
+brownie:
+ prod_name: chocolate brownie
+ description: decadent
+ price: 19.5
+ inv_qty: 0
+ user: ada
diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml
new file mode 100644
index 0000000000..27fde1e798
--- /dev/null
+++ b/test/fixtures/reviews.yml
@@ -0,0 +1,10 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ rating: 1
+ description: MyString
+ product: cake1
+
+two:
+ rating: 1
+ description: MyString
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
new file mode 100644
index 0000000000..97b51aa1d9
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,22 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+
+laura:
+ provider: github
+ uid: 13371338
+ email: lbird@ada.com
+ username: Lady Bird
+
+
+ada:
+ provider: github
+ uid: 2354234
+ email: ada@lovelace.com
+ username: countess_ada
+
+
+grace:
+ provider: github
+ uid: 13371337
+ email: grace@hopper.com
+ username: graceful_hopps
diff --git a/test/helpers/.keep b/test/helpers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/integration/.keep b/test/integration/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/mailers/.keep b/test/mailers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/models/.keep b/test/models/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/models/category_test.rb b/test/models/category_test.rb
new file mode 100644
index 0000000000..9a2ad9c30b
--- /dev/null
+++ b/test/models/category_test.rb
@@ -0,0 +1,29 @@
+require "test_helper"
+
+describe Category do
+ let(:category) { Category.new }
+
+ it "must be valid" do
+ value(category).must_be :valid?
+ end
+
+ describe 'validations' do
+ it 'has required fields' do
+ fields = [:category]
+
+ fields.each do |field|
+ expect(book).must_respond_to field
+ end
+ end
+ end
+
+ describe 'relationship' do
+ let(:product) { products(:cake1) }
+ it 'belongs to product' do
+ cat = product.category
+
+ expect(cat).must_be_instance_of Product
+ expect(cat.id).must_equal product.category_id
+ end
+ end
+end
diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb
new file mode 100644
index 0000000000..3f69f96891
--- /dev/null
+++ b/test/models/order_item_test.rb
@@ -0,0 +1,81 @@
+require "test_helper"
+
+describe OrderItem do
+ let(:order_item) { order_items(:line1) }
+
+ describe 'relationships' do
+ it 'must belong to a product' do
+ product = order_item.product
+
+ expect(product).must_be_instance_of Product
+ expect(product.id).must_equal order_item.product.id
+
+ end
+
+ it 'must belong to an order' do
+ order = order_item.order
+
+ expect(order).must_be_instance_of Order
+ expect(order.id).must_equal order_item.order.id
+ end
+ end
+
+ describe 'validations' do
+ it 'must be valid with all fields' do
+ another_order_item = order_items(:line2)
+
+ expect(order_item).must_be :valid?
+
+ expect(another_order_item).must_be :valid?
+ end
+
+ it 'must have qty' do
+ order_item.qty = nil
+
+ valid = order_item.save
+
+ expect(valid).must_equal false
+ expect(order_item.errors.messages).must_include :qty
+ end
+
+ it 'must have a quantity greater than 0' do
+ order_item.qty = 0
+
+ valid = order_item.save
+
+ expect(valid).must_equal false
+ expect(order_item.errors.messages).must_include :qty
+ end
+
+ it 'must have a quantity that is an integer' do
+ order_item.qty = 1.5
+
+ valid = order_item.save
+
+ expect(valid).must_equal false
+ expect(order_item.errors.messages).must_include :qty
+ end
+
+ end
+
+ describe 'subtotal' do
+ it 'must be able to calculate subtotal for order_item' do
+ subtotal = order_item.subtotal
+
+ expect(subtotal).must_equal order_item.product.price * order_item.qty
+ end
+
+ it 'must be able to calculate subtotal for order_item with qty of 0' do
+ order_item.qty = 0
+ order_item.save
+
+ subtotal = order_item.subtotal
+
+ expect(subtotal).must_equal 0
+ end
+
+ end
+
+
+
+end
diff --git a/test/models/order_status_test.rb b/test/models/order_status_test.rb
new file mode 100644
index 0000000000..ab042fbd3e
--- /dev/null
+++ b/test/models/order_status_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+describe OrderStatus do
+ let(:order_status) { OrderStatus.new }
+
+ it "must be valid" do
+ value(order_status).must_be :valid?
+ end
+end
diff --git a/test/models/order_test.rb b/test/models/order_test.rb
new file mode 100644
index 0000000000..7290b3298f
--- /dev/null
+++ b/test/models/order_test.rb
@@ -0,0 +1,227 @@
+require "test_helper"
+
+describe Order do
+
+ describe "items_in_cart" do
+
+ it "returns the total quantity of items in cart" do
+ order = orders(:one)
+ number = order.items_in_cart
+
+ expect(number).must_equal 4
+ end
+
+ it "returns 0 when no items in cart" do
+ order = orders(:three)
+ number = order.items_in_cart
+
+ expect(number).must_equal 0
+ end
+ end
+
+ describe "place order" do
+
+ it "reduces inventory quantity by order item quantity" do
+ order = orders(:one)
+ inv_qty_before = order.order_items.first.product.inv_qty
+ order_qty = order.order_items.first.qty
+
+ order.place_order
+ order = orders(:one)
+
+ inv_qty_after = order.order_items.first.product.inv_qty
+ expect(order.order_items.first.product.inv_qty).must_equal inv_qty_after
+ expect(inv_qty_after).must_equal inv_qty_before - order_qty
+ end
+ end
+
+ describe "total_price" do
+
+ it "gets the correct total price when the order has items" do
+ order = orders(:one)
+ price_first_item = order.order_items.first.product.price * order.order_items.first.qty
+ price_last_item = order.order_items.last.product.price * order.order_items.last.qty
+ total_price = price_first_item + price_last_item
+
+ order.total_price
+
+ expect(order.total_price).must_equal total_price
+ end
+ end
+
+describe "validation" do
+ let(:user) { user(:one) }
+ before do
+ 1.times do
+ order = create(:order)
+ describe "validation" do
+ let(:order) { build(:order) }
+
+ it "must be valid with all parameters" do
+ expect(order.valid?).must_equal true
+ end
+
+ it "must be invalid without a customer name " do
+ order.cust_name = nil
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cust_name
+ end
+ end
+
+ # it "must be a valid order" do
+ #
+ # expect(order.valid?).must_equal true
+ # end
+
+ it "must be invalid without a customer name " do
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cust_email
+ end
+
+ order.cust_name = nil
+
+ expect(order.cust_name.valid?).must_equal false
+ expect(order.errors.messages).must_include :cust_name
+ end
+
+ it "must be invalid without an email address or correct data type " do
+ order.cust_email = nil
+ order.cust_email = 123
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :mailing_address
+ end
+
+ expect(order.cust_email.valid?).must_equal false
+ expect(order.errors.messages).must_include :cust_email
+ end
+
+
+ it "must be invalid without a mailing address" do
+ order.mailing_address = nil
+
+ expect(order.mailing_address.valid?).must_equal false
+ expect(order.errors.messages).must_include :mailing_address
+ end
+
+
+ it "must be invalid without a customer name" do
+ order.cc_name = nil
+
+ expect(order.cc_name.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_name
+ end
+
+ # it "must be invalid if date has expired" do
+ # order.cc_expiration = 2018/08/21
+ #
+ # expect(order.cc_name.valid?).must_equal false
+ # expect(order.errors.messages).must_include :cc_expiration
+ # end
+
+ it "must be invalid with more than 16 digits for credit card" do
+ order.cc_digit = 123
+ order2.cc_digit = "hi"
+
+ expect(order.cc_digit.valid?).must_equal false
+ expect(order2.cc_digit.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_digit
+ expect(order2.errors.messages).must_include :cc_digit
+ end
+
+ it "must have only 3 digits for CVV" do
+ order.cc_cvv = 12
+ order2.cc_cvv = "hi"
+
+ expect(order.cc_cvv.valid?).must_equal false
+ expect(order2.cc_cvv.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_cvv
+ expect(order2.errors.messages).must_include :cc_cvv
+ end
+
+ it "must be 5 digits in length for zip code" do
+ order.cc_zip = 12
+ order2.cc_zip = "hi"
+
+ expect(order.cc_zip.valid?).must_equal false
+ expect(order2.cc_zip.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_zip
+ expect(order2.errors.messages).must_include :cc_zip
+ end
+ it "must be invalid without a customer name" do
+ order.cust_name = nil
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cust_name
+ end
+
+ # it "must be invalid if date has expired" do
+ # order.cc_expiration = 2018/08/21
+ #
+ # expect(order.cc_name.valid?).must_equal false
+ # expect(order.errors.messages).must_include :cc_expiration
+ # end
+
+ it "must be invalid with less than 16 digits for credit card" do
+ order.cc_digit = 123
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_digit
+
+ order.cc_digit = "hi"
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_digit
+ end
+
+ it "must have only 3 digits for CVV" do
+ order.cc_cvv = 12
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_cvv
+
+ order.cc_cvv = "hi"
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_cvv
+ end
+
+ it "must have only 16 digits for Credit Card number" do
+ order.cc_digit = 1234123412341234
+
+ expect(order.valid?).must_equal true
+ end
+
+ it "must be 5 digits in length for zip code" do
+ order.cc_zip = 1255
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_zip
+
+ order.cc_zip = "hi"
+
+ expect(order.valid?).must_equal false
+ expect(order.errors.messages).must_include :cc_zip
+ end
+
+
+ # describe "relations" do
+ #
+ # it "belong to a product" do
+ # expect(order.user).must_be_instance_of User
+ # expect(order.user.orders).must_include Order
+ # end
+ # end
+
+end
+describe "relations" do
+
+ it "belong to a product" do
+ order = product.order
+ #add the yml file
+ expect(order).must_be_instance_of Product
+ expect(order.id).must_equal product.order_id
+ end
+end
+
+end
diff --git a/test/models/product_test.rb b/test/models/product_test.rb
new file mode 100644
index 0000000000..c2115fbe04
--- /dev/null
+++ b/test/models/product_test.rb
@@ -0,0 +1,61 @@
+require "test_helper"
+
+describe Product do
+ let(:product) { build(:product) }
+ let(:product2) { create(:product)}
+
+ describe "validation" do
+
+ it "must be valid" do
+ expect(product.valid?).must_equal true
+ end
+
+ it "must be invalid without a product name " do
+ product.prod_name = nil
+
+ expect(product.valid?).must_equal false
+ expect(product.errors.messages).must_include :prod_name
+ end
+
+ it "must be invalid without a description" do
+ product.description = nil
+
+ expect(product.valid?).must_equal false
+ expect(product.errors.messages).must_include :description
+ end
+
+
+ it "must be invalid without a price" do
+ product.price = nil
+
+ expect(product.valid?).must_equal false
+ expect(product.errors.messages).must_include :price
+ end
+
+
+ it "must have a unique product name" do
+ product.prod_name = product2.prod_name
+ expect(product.valid?).must_equal false
+ end
+
+
+ end
+
+
+ describe "relations" do
+
+ # it "belong to a user" do
+ # expect(product.user).must_be_instance_of User
+ # expect(product.user.products).must_include product
+ # end
+
+ it "must respond to reviews" do
+ expect(product).must_respond_to :reviews
+ end
+
+ it "responds to categories" do
+ expect(product).must_respond_to :categories
+ end
+
+ end
+end
diff --git a/test/models/review_test.rb b/test/models/review_test.rb
new file mode 100644
index 0000000000..507bfc4621
--- /dev/null
+++ b/test/models/review_test.rb
@@ -0,0 +1,27 @@
+require "test_helper"
+
+describe Review do
+ let(:review) { Review.new(rating: "1", description: "this is great", product: Product.new) }
+
+ it "must be valid" do
+ expect(review.valid?).must_equal true
+ end
+
+ describe "relations" do
+
+ it "must respond to product" do
+ expect(review).must_respond_to :product
+ end
+
+ end
+
+ describe "validations" do
+
+ it "invalid without a rating" do
+ review.rating = nil
+ expect(review.valid?).must_equal false
+ expect(review.errors.messages).must_include :rating
+ end
+
+ end
+end
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 0000000000..cd9152db7b
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,49 @@
+require "test_helper"
+
+describe User do
+ # let(:user) { User.new }
+ #
+ # it "must be valid" do
+ # value(user).must_be :valid?
+ # end
+
+ describe "relations" do
+ before do
+ user = User.new
+ end
+
+ it "has a list of products" do
+
+ user = product(:create)
+
+ user.must_respond_to :product
+ user.products.each do |product|
+ product.must_be_kind_of Product
+ end
+ end
+
+ end
+
+ describe "validations" do
+ it "requires a username" do
+ user = User.new
+ user.valid?.must_equal false
+ user.errors.messages.must_include :username
+ end
+
+ it "requires a unique username" do
+ username = "test username"
+ user1 = User.new(username: username)
+
+ # This must go through, so we use create!
+ user1.save!
+
+ user2 = User.new(username: username)
+ result = user2.save
+ result.must_equal false
+ user2.errors.messages.must_include :username
+ end
+
+
+ end
+end
diff --git a/test/system/.keep b/test/system/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000000..9e687b9149
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,59 @@
+require 'simplecov'
+SimpleCov.start
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path("../../config/environment", __FILE__)
+require "rails/test_help"
+require "minitest/rails"
+require "minitest/reporters" # for Colorized output
+require 'faker'
+
+
+# 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...
+ class ActiveSupport::TestCase
+ include FactoryBot::Syntax::Methods
+ end
+
+ #oauth testing setup
+ def setup
+ OmniAuth.config.test_mode = true
+ end
+ # Test helper method to generate a mock auth hash
+ # for fixture data
+ def mock_auth_hash(user)
+ return {
+ provider: user.provider,
+ uid: user.uid,
+ info: {
+ email: user.email,
+ nickname: user.username
+ }
+ }
+ end
+
+ # oauth mock login
+ def perform_login(user)
+ OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user))
+ get auth_callback_path(:github)
+ end
+
+end
diff --git a/tmp/.keep b/tmp/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/vendor/.keep b/vendor/.keep
new file mode 100644
index 0000000000..e69de29bb2