+ <% if item.average_rating == 0 %>
+ Be the first to rate this product!
+ <% else %>
+ averate rating
+ <% item.average_rating.times do %>
+ <%= "💧" %>
+ <% end %>
+
+
+
+
+ e
+ raise unless e.message.include?('spring')
+end
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 0000000000..d87d5f5781
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/bin/setup b/bin/setup
new file mode 100755
index 0000000000..78c4e861dc
--- /dev/null
+++ b/bin/setup
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:setup'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/spring b/bin/spring
new file mode 100755
index 0000000000..fb2ec2ebb4
--- /dev/null
+++ b/bin/spring
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+ require 'rubygems'
+ require 'bundler'
+
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
+ if spring
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
+ gem 'spring', spring.version
+ require 'spring/binstub'
+ end
+end
diff --git a/bin/update b/bin/update
new file mode 100755
index 0000000000..a8e4462f20
--- /dev/null
+++ b/bin/update
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/yarn b/bin/yarn
new file mode 100755
index 0000000000..c2bacef836
--- /dev/null
+++ b/bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+VENDOR_PATH = File.expand_path('..', __dir__)
+Dir.chdir(VENDOR_PATH) do
+ begin
+ exec "yarnpkg #{ARGV.join(" ")}"
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000000..f7ba0b527b
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/config/application.rb b/config/application.rb
new file mode 100644
index 0000000000..4014030a94
--- /dev/null
+++ b/config/application.rb
@@ -0,0 +1,27 @@
+
+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 RegrEtsy
+ class Application < Rails::Application
+ config.generators do |g|
+ # Force new test files to be generated in the minitest-spec style
+ g.test_framework :minitest, spec: true
+
+ # Always use .js files, never .coffee
+ g.javascript_engine :js
+ end
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.1
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ end
+end
diff --git a/config/boot.rb b/config/boot.rb
new file mode 100644
index 0000000000..30f5120df6
--- /dev/null
+++ b/config/boot.rb
@@ -0,0 +1,3 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/config/cable.yml b/config/cable.yml
new file mode 100644
index 0000000000..7e2633a867
--- /dev/null
+++ b/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: redis://localhost:6379/1
+ channel_prefix: regrEtsy_production
diff --git a/config/database.yml b/config/database.yml
new file mode 100644
index 0000000000..c3067539a0
--- /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: regrEtsy_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: regrEtsy
+
+ # 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: regrEtsy_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: regrEtsy_production
+ username: regrEtsy
+ password: <%= ENV['REGRETSY_DATABASE_PASSWORD'] %>
diff --git a/config/environment.rb b/config/environment.rb
new file mode 100644
index 0000000000..426333bb46
--- /dev/null
+++ b/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
new file mode 100644
index 0000000000..5187e22186
--- /dev/null
+++ b/config/environments/development.rb
@@ -0,0 +1,54 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ if Rails.root.join('tmp/caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/config/environments/production.rb b/config/environments/production.rb
new file mode 100644
index 0000000000..b27bc8d300
--- /dev/null
+++ b/config/environments/production.rb
@@ -0,0 +1,91 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
+ # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
+ # `config/secrets.yml.key`.
+ config.read_encrypted_secrets = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "regrEtsy_#{Rails.env}"
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/config/environments/test.rb b/config/environments/test.rb
new file mode 100644
index 0000000000..8e5cbde533
--- /dev/null
+++ b/config/environments/test.rb
@@ -0,0 +1,42 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000000..89d2efab2b
--- /dev/null
+++ b/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
new file mode 100644
index 0000000000..4b828e80cb
--- /dev/null
+++ b/config/initializers/assets.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000..59385cdf37
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000000..5a6a32d371
--- /dev/null
+++ b/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000000..4a994e1e7b
--- /dev/null
+++ b/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000000..ac033bf9dc
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000000..dc1899682b
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 0000000000..fd4416122a
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,3 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email"
+end
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000000..bbfc3961bf
--- /dev/null
+++ b/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/config/locales/en.yml b/config/locales/en.yml
new file mode 100644
index 0000000000..decc5a8573
--- /dev/null
+++ b/config/locales/en.yml
@@ -0,0 +1,33 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/config/puma.rb b/config/puma.rb
new file mode 100644
index 0000000000..1e19380dcb
--- /dev/null
+++ b/config/puma.rb
@@ -0,0 +1,56 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory. If you use this option
+# you need to make sure to reconnect any threads in the `on_worker_boot`
+# block.
+#
+# preload_app!
+
+# If you are preloading your application and using Active Record, it's
+# recommended that you close any connections to the database before workers
+# are forked to prevent connection leakage.
+#
+# before_fork do
+# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
+# end
+
+# The code in the `on_worker_boot` will be called if you are using
+# clustered mode by specifying a number of `workers`. After each worker
+# process is booted, this block will be run. If you are using the `preload_app!`
+# option, you will want to use this block to reconnect to any threads
+# or connections that may have been created at application boot, as Ruby
+# cannot share connections between processes.
+#
+# on_worker_boot do
+# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
+# end
+#
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000000..0404cfcf8a
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,37 @@
+Rails.application.routes.draw do
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+ root 'products#root'
+
+ # TODO changed using nested routes instead - leaving these here so you can see what we had previously
+ # get '/products/:id/reviews/new', to: 'reviews#new', as: 'new_product_review'
+
+ resources :products do
+ resources :reviews, only: [:new, :create]
+ end
+
+ resources :users do
+ resources :products, only: [:index]
+ end
+
+ resources :categories do
+ resources :products, only: [:index]
+ end
+
+ get '/login', to: 'sessions#new', as: 'login'
+ # used get for action on logout because we could not resolve an issue, per
+ # instructor's suggestion
+ get '/logout', to: 'sessions#logout', as: 'logout'
+ get "/auth/:provider/callback", to: "sessions#create", as: 'auth_callback'
+
+ resources :carts, only: [:show, :edit, :update]
+ post '/carts', to: 'carts#add_to_cart', as: :add_to_cart
+ post '/add', to: 'sessions#add_cart_product', as: :add_product
+
+ get 'carts/:id/checkout', to: 'carts#checkout', as: :checkout
+ post 'carts/:id/checkout', to: 'carts#finalize'
+
+ get 'order/:id', to: 'carts#order_details', as: :order
+ patch 'order/:id', to: 'carts#order_status'
+
+
+end
diff --git a/config/secrets.yml b/config/secrets.yml
new file mode 100644
index 0000000000..ca46a1fe0c
--- /dev/null
+++ b/config/secrets.yml
@@ -0,0 +1,32 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key is used for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+# You can use `rails secret` to generate a secure secret key.
+
+# Make sure the secrets in this file are kept private
+# if you're sharing your code publicly.
+
+# Shared secrets are available across all environments.
+
+# shared:
+# api_key: a1B2c3D4e5F6
+
+# Environmental secrets are only available for that specific environment.
+
+development:
+ secret_key_base: e70b5b97b719ff4c5621f3f04831ae6f17aab6e140e8cc73bd9958f1a3836e2d13b17918c8d2dc5afa19573e31df541bd602cbe9a5724b1887489aad09b8bbfd
+
+test:
+ secret_key_base: 2572e7dea09f924a6e0d706ab4aaa71030ead74a02fed23c5e1df8c4cda1bcb51f8c34fd5265fab3ce5db3d093fc7e5cebce634971eac76e30cc2eb80a9ece8e
+
+# Do not keep production secrets in the unencrypted secrets file.
+# Instead, either read values from the environment.
+# Or, use `bin/rails secrets:setup` to configure encrypted secrets
+# and move the `production:` environment over there.
+
+production:
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
diff --git a/config/spring.rb b/config/spring.rb
new file mode 100644
index 0000000000..c9119b40c0
--- /dev/null
+++ b/config/spring.rb
@@ -0,0 +1,6 @@
+%w(
+ .ruby-version
+ .rbenv-vars
+ tmp/restart.txt
+ tmp/caching-dev.txt
+).each { |path| Spring.watch(path) }
diff --git a/db/migrate/20180419062938_create_products.rb b/db/migrate/20180419062938_create_products.rb
new file mode 100644
index 0000000000..1223f7beb1
--- /dev/null
+++ b/db/migrate/20180419062938_create_products.rb
@@ -0,0 +1,13 @@
+class CreateProducts < ActiveRecord::Migration[5.1]
+ def change
+ create_table :products do |t|
+ t.string :name
+ t.text :description
+ t.float :price
+ t.integer :stock
+ t.text :url
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419065400_create_users.rb b/db/migrate/20180419065400_create_users.rb
new file mode 100644
index 0000000000..4bfb682e18
--- /dev/null
+++ b/db/migrate/20180419065400_create_users.rb
@@ -0,0 +1,14 @@
+class CreateUsers < ActiveRecord::Migration[5.1]
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.string :username
+ t.string :email
+ t.string :password
+ t.string :uid
+ t.string :provider
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419065639_create_categories.rb b/db/migrate/20180419065639_create_categories.rb
new file mode 100644
index 0000000000..5bef4913b8
--- /dev/null
+++ b/db/migrate/20180419065639_create_categories.rb
@@ -0,0 +1,9 @@
+class CreateCategories < ActiveRecord::Migration[5.1]
+ def change
+ create_table :categories do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419065737_create_reviews.rb b/db/migrate/20180419065737_create_reviews.rb
new file mode 100644
index 0000000000..68c0586d7c
--- /dev/null
+++ b/db/migrate/20180419065737_create_reviews.rb
@@ -0,0 +1,10 @@
+class CreateReviews < ActiveRecord::Migration[5.1]
+ def change
+ create_table :reviews do |t|
+ t.integer :rating
+ t.text :review
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419065814_create_orders.rb b/db/migrate/20180419065814_create_orders.rb
new file mode 100644
index 0000000000..8d3698575f
--- /dev/null
+++ b/db/migrate/20180419065814_create_orders.rb
@@ -0,0 +1,9 @@
+class CreateOrders < ActiveRecord::Migration[5.1]
+ def change
+ create_table :orders do |t|
+ t.string :status
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419070148_create_product_category_join.rb b/db/migrate/20180419070148_create_product_category_join.rb
new file mode 100644
index 0000000000..b22d35a60f
--- /dev/null
+++ b/db/migrate/20180419070148_create_product_category_join.rb
@@ -0,0 +1,8 @@
+class CreateProductCategoryJoin < ActiveRecord::Migration[5.1]
+ def change
+ create_table :product_category do |t|
+ t.belongs_to :product, index: true
+ t.belongs_to :category, index: true
+ end
+ end
+end
diff --git a/db/migrate/20180419070336_create_order_item_join.rb b/db/migrate/20180419070336_create_order_item_join.rb
new file mode 100644
index 0000000000..85ef9733cf
--- /dev/null
+++ b/db/migrate/20180419070336_create_order_item_join.rb
@@ -0,0 +1,10 @@
+class CreateOrderItemJoin < ActiveRecord::Migration[5.1]
+ def change
+ create_table :order_item do |t|
+ t.belongs_to :product, index: true
+ t.belongs_to :order, index: true
+
+ t.integer :quantity
+ end
+ end
+end
diff --git a/db/migrate/20180419070656_add_reference_to_products.rb b/db/migrate/20180419070656_add_reference_to_products.rb
new file mode 100644
index 0000000000..68bd29e6b3
--- /dev/null
+++ b/db/migrate/20180419070656_add_reference_to_products.rb
@@ -0,0 +1,5 @@
+class AddReferenceToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :products, :user, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180419145514_add_product_id_to_reviews.rb b/db/migrate/20180419145514_add_product_id_to_reviews.rb
new file mode 100644
index 0000000000..b817023ad2
--- /dev/null
+++ b/db/migrate/20180419145514_add_product_id_to_reviews.rb
@@ -0,0 +1,5 @@
+class AddProductIdToReviews < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :reviews, :product, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180419213849_add_retire_column_to_products.rb b/db/migrate/20180419213849_add_retire_column_to_products.rb
new file mode 100644
index 0000000000..883c322bce
--- /dev/null
+++ b/db/migrate/20180419213849_add_retire_column_to_products.rb
@@ -0,0 +1,5 @@
+class AddRetireColumnToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_column :products, :retired, :boolean
+ end
+end
diff --git a/db/migrate/20180419214224_change_column_add_default_to_retired.rb b/db/migrate/20180419214224_change_column_add_default_to_retired.rb
new file mode 100644
index 0000000000..9c1353a852
--- /dev/null
+++ b/db/migrate/20180419214224_change_column_add_default_to_retired.rb
@@ -0,0 +1,5 @@
+class ChangeColumnAddDefaultToRetired < ActiveRecord::Migration[5.1]
+ def change
+ change_column :products, :retired, :boolean, default: false
+ end
+end
diff --git a/db/migrate/20180420022301_fixing_join_table_name.rb b/db/migrate/20180420022301_fixing_join_table_name.rb
new file mode 100644
index 0000000000..945b5b6cf5
--- /dev/null
+++ b/db/migrate/20180420022301_fixing_join_table_name.rb
@@ -0,0 +1,5 @@
+class FixingJoinTableName < ActiveRecord::Migration[5.1]
+ def change
+ rename_table :product_category, :products_categories
+ end
+end
diff --git a/db/migrate/20180420023228_make_join_table_match_rails_expectation.rb b/db/migrate/20180420023228_make_join_table_match_rails_expectation.rb
new file mode 100644
index 0000000000..4bd39d5e0f
--- /dev/null
+++ b/db/migrate/20180420023228_make_join_table_match_rails_expectation.rb
@@ -0,0 +1,5 @@
+class MakeJoinTableMatchRailsExpectation < ActiveRecord::Migration[5.1]
+ def change
+ rename_table :products_categories, :categories_products
+ end
+end
diff --git a/db/migrate/20180420200525_create_join_table_cart_product.rb b/db/migrate/20180420200525_create_join_table_cart_product.rb
new file mode 100644
index 0000000000..29468fc0af
--- /dev/null
+++ b/db/migrate/20180420200525_create_join_table_cart_product.rb
@@ -0,0 +1,8 @@
+class CreateJoinTableCartProduct < ActiveRecord::Migration[5.1]
+ def change
+ create_join_table :carts, :products do |t|
+ t.index [:cart_id, :product_id]
+ # t.index [:product_id, :cart_id]
+ end
+ end
+end
diff --git a/db/migrate/20180420211402_create_sessions.rb b/db/migrate/20180420211402_create_sessions.rb
new file mode 100644
index 0000000000..9810f66651
--- /dev/null
+++ b/db/migrate/20180420211402_create_sessions.rb
@@ -0,0 +1,8 @@
+class CreateSessions < ActiveRecord::Migration[5.1]
+ def change
+ create_table :sessions do |t|
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180420221041_change_column_null_users.rb b/db/migrate/20180420221041_change_column_null_users.rb
new file mode 100644
index 0000000000..b81adbfb62
--- /dev/null
+++ b/db/migrate/20180420221041_change_column_null_users.rb
@@ -0,0 +1,6 @@
+class ChangeColumnNullUsers < ActiveRecord::Migration[5.1]
+ def change
+ change_column_null :users, :uid, :string, false
+ change_column_null :users, :provider, :string, false
+ end
+end
diff --git a/db/migrate/20180420222909_remove_add_columns_to_user.rb b/db/migrate/20180420222909_remove_add_columns_to_user.rb
new file mode 100644
index 0000000000..9b603c118d
--- /dev/null
+++ b/db/migrate/20180420222909_remove_add_columns_to_user.rb
@@ -0,0 +1,9 @@
+class RemoveAddColumnsToUser < ActiveRecord::Migration[5.1]
+ def change
+ remove_column :users, :uid
+ remove_column :users, :provider
+
+ add_column :users, :uid, :string, null: false
+ add_column :users, :provider, :string, null: false
+ end
+end
diff --git a/db/migrate/20180423131221_create_buyerdetails.rb b/db/migrate/20180423131221_create_buyerdetails.rb
new file mode 100644
index 0000000000..c5502ecc18
--- /dev/null
+++ b/db/migrate/20180423131221_create_buyerdetails.rb
@@ -0,0 +1,16 @@
+class CreateBuyerdetails < ActiveRecord::Migration[5.1]
+ def change
+ create_table :buyerdetails do |t|
+ t.string :email
+ t.string :mailing_address
+ t.string :buyer_name
+ t.string :card_number
+ t.string :expiration
+ t.string :cvv
+ t.string :zipcode
+ t.bigint :order_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180423131605_add_payment_info_to_order.rb b/db/migrate/20180423131605_add_payment_info_to_order.rb
new file mode 100644
index 0000000000..281d47101c
--- /dev/null
+++ b/db/migrate/20180423131605_add_payment_info_to_order.rb
@@ -0,0 +1,5 @@
+class AddPaymentInfoToOrder < ActiveRecord::Migration[5.1]
+ def change
+ add_column :orders, :buyerdetails_id, :bigint
+ end
+end
diff --git a/db/migrate/20180423191116_change_order_item_to_orders_items.rb b/db/migrate/20180423191116_change_order_item_to_orders_items.rb
new file mode 100644
index 0000000000..0c9b94f052
--- /dev/null
+++ b/db/migrate/20180423191116_change_order_item_to_orders_items.rb
@@ -0,0 +1,5 @@
+class ChangeOrderItemToOrdersItems < ActiveRecord::Migration[5.1]
+ def change
+ rename_table :order_item, :items_orders
+ end
+end
diff --git a/db/migrate/20180423191458_add_quantity_to_carts_products.rb b/db/migrate/20180423191458_add_quantity_to_carts_products.rb
new file mode 100644
index 0000000000..fb394ff6d0
--- /dev/null
+++ b/db/migrate/20180423191458_add_quantity_to_carts_products.rb
@@ -0,0 +1,5 @@
+class AddQuantityToCartsProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_column :carts_products, :quantity, :integer
+ end
+end
diff --git a/db/migrate/20180423193052_create_orderitems.rb b/db/migrate/20180423193052_create_orderitems.rb
new file mode 100644
index 0000000000..e6341e198a
--- /dev/null
+++ b/db/migrate/20180423193052_create_orderitems.rb
@@ -0,0 +1,10 @@
+class CreateOrderitems < ActiveRecord::Migration[5.1]
+ def change
+ create_table :orderitems do |t|
+ t.bigint "product_id", null: false
+ t.bigint "order_id", null: false
+ t.integer "quantity"
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180426022929_change_key_on_order_to_buyerdetail.rb b/db/migrate/20180426022929_change_key_on_order_to_buyerdetail.rb
new file mode 100644
index 0000000000..4304a39784
--- /dev/null
+++ b/db/migrate/20180426022929_change_key_on_order_to_buyerdetail.rb
@@ -0,0 +1,5 @@
+class ChangeKeyOnOrderToBuyerdetail < ActiveRecord::Migration[5.1]
+ def change
+ remove_column :orders, :buyerdetails_id
+ end
+end
diff --git a/db/migrate/20180426024204_add_reference_to_orders.rb b/db/migrate/20180426024204_add_reference_to_orders.rb
new file mode 100644
index 0000000000..8182848105
--- /dev/null
+++ b/db/migrate/20180426024204_add_reference_to_orders.rb
@@ -0,0 +1,5 @@
+class AddReferenceToOrders < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :orders, :buyerdetail, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180427020251_buyerdetail_add_reference.rb b/db/migrate/20180427020251_buyerdetail_add_reference.rb
new file mode 100644
index 0000000000..07004f2de4
--- /dev/null
+++ b/db/migrate/20180427020251_buyerdetail_add_reference.rb
@@ -0,0 +1,6 @@
+class BuyerdetailAddReference < ActiveRecord::Migration[5.1]
+ def change
+ remove_column :buyerdetails, :order_id
+ add_reference :buyerdetails, :order, foreign_key: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000000..5d7ac04acc
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,123 @@
+# 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: 20180427020251) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "buyerdetails", force: :cascade do |t|
+ t.string "email"
+ t.string "mailing_address"
+ t.string "buyer_name"
+ t.string "card_number"
+ t.string "expiration"
+ t.string "cvv"
+ t.string "zipcode"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "order_id"
+ t.index ["order_id"], name: "index_buyerdetails_on_order_id"
+ end
+
+ create_table "carts", force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "carts_products", id: false, force: :cascade do |t|
+ t.bigint "cart_id", null: false
+ t.bigint "product_id", null: false
+ t.integer "quantity"
+ t.index ["cart_id", "product_id"], name: "index_carts_products_on_cart_id_and_product_id"
+ end
+
+ create_table "categories", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "categories_products", force: :cascade do |t|
+ t.bigint "product_id"
+ t.bigint "category_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 "items_orders", force: :cascade do |t|
+ t.bigint "product_id"
+ t.bigint "order_id"
+ t.integer "quantity"
+ t.index ["order_id"], name: "index_items_orders_on_order_id"
+ t.index ["product_id"], name: "index_items_orders_on_product_id"
+ end
+
+ create_table "orderitems", force: :cascade do |t|
+ t.bigint "product_id", null: false
+ t.bigint "order_id", null: false
+ t.integer "quantity"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "orders", force: :cascade do |t|
+ t.string "status"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "buyerdetail_id"
+ t.index ["buyerdetail_id"], name: "index_orders_on_buyerdetail_id"
+ end
+
+ create_table "products", force: :cascade do |t|
+ t.string "name"
+ t.text "description"
+ t.float "price"
+ t.integer "stock"
+ t.text "url"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "user_id"
+ t.boolean "retired", default: false
+ t.index ["user_id"], name: "index_products_on_user_id"
+ end
+
+ create_table "reviews", force: :cascade do |t|
+ t.integer "rating"
+ t.text "review"
+ 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 "sessions", force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "users", force: :cascade do |t|
+ t.string "name"
+ t.string "username"
+ t.string "email"
+ t.string "password"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "uid", null: false
+ t.string "provider", null: false
+ end
+
+ add_foreign_key "buyerdetails", "orders"
+ add_foreign_key "orders", "buyerdetails"
+ 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..df94419c86
--- /dev/null
+++ b/db/seeds.rb
@@ -0,0 +1,123 @@
+User.create!([
+ {
+ name: "Rick Astley",
+ username: "Rickrolls",
+ email: "rick@astley.com",
+ password: "neverGiveUP1",
+ uid: "12345",
+ provider: "github"
+ },
+ {
+ name: "Nickel Back",
+ username: "We Want our Nickelback",
+ email: "nickel@back.com",
+ password: "photograPH1",
+ uid: "23456",
+ provider: "github"
+ },
+ {
+ name: "Smash Mouth",
+ username: "You're an Allstar",
+ email: "smash@mouthy.com",
+ password: "getyourGameOn1",
+ uid: "34567",
+ provider: "github"
+ },
+ {
+ name: "Nic Cage",
+ username: "A National Treasure",
+ email: "nic@cage.com",
+ password: "imnicCage1",
+ uid: "45678",
+ provider: "github"
+ },
+ {
+ name: "Ada Lovelace",
+ username: "Ada Develops It",
+ email: "ada@lovelace.com",
+ password: "dalove1",
+ uid: "56789",
+ provider: "github"
+ }
+])
+
+Category.create!([
+ {name: "Time Machines"},
+ {name: "Pharmaceuticals"},
+ {name: "Personal Care"},
+ {name: "Lifestyle"}
+])
+Product.create!([
+ {name: "Kat Von D Tattoo Concealer ", description: "A highly-pigmented, full-coverage, transfer- and water-resistant concealer. ", price: 25.0, stock: 3, url: "kat_von_d_tattoo_cover_up.jpg", user_id: 1, retired: false, categories: Category.where(name: "Personal Care")},
+ {name: "Aspirin", description: "Essential medicine for your hangover", price: 14.99, stock: 5, url: "aspirin.jpg", user_id: 3, retired: false, categories: Category.where(name: "Pharmaceuticals")},
+ {
+ name: "Plan B",
+ description: "Whoops! Now you can press reset on that one-night stand!", price: 27.49,
+ stock: 5,
+ url: "plan_b.jpg",
+ user_id: 2,
+ retired: false,
+ categories: Category.where(name: "Pharmaceuticals")
+ },
+ {name: "White Out", description: "", price: 3.99, stock: 6, url: "white_out.jpg", user_id: 5, retired: false},
+ {name: "Tardis Dr. Who Time Machine", description: "Time machine capable of traveling any direction through space and time — so it can visit any planet at any point in history", price: 2300000000.0, stock: 1, url: "tardis_time_machine.jpg", user_id: 5, retired: false, categories: Category.where(name: "Time Machines")},
+ {name: "Attorney Services for an Unfortunate Injury", description: "Financial peril after your terrible decisions? Call our fine attorney-at-law to sue those guilty parties", price: 2399.0, stock: 1, url: "attorney_service_injury.jpg", user_id: 1, retired: false, categories: Category.where(name: "Lifestyle")},
+ {name: "Bad Credit Repair Service", description: "Fix your bad credit with our credit recovery service", price: 199.0, stock: 2, url: "credit_repair_service.jpg", user_id: 4, retired: false, categories: Category.where(name: "Lifestyle")},
+ {name: "Magic Erasers", description: "When your kid decided to go crazy with the crayons on the wall, this will get it off", price: 6.99, stock: 10, url: "magic_eraser_sponges.jpg", user_id: 3, retired: false, categories: Category.where(name: "Lifestyle")},
+ {name: "Mattress Pad", description: "Don't ruin co-sleeping", price: 23.99, stock: 4, url: "mattress_pad.jpg", user_id: 2, retired: false, categories: Category.where(name: "Personal Care")},
+ {name: "After Burn Sunburn Cream", description: "Trying to forget your troubles and fell asleep in the sun? Try this to calm your blistering skin", price: 13.49, stock: 20, url: "sunburn_cream.jpg", user_id: 1, retired: false, categories: Category.where(name: "Personal Care")},
+ {name: "Unbranded Tissue", description: "Do you need to dry your stress tears from dealing with Betsy git issues (did you know that you can't spell 'guilt' without 'git'?!). Did you git init but now you want to git tfo? Did you type git curse instead of git clone? Use these 1 ply, generic tissues to wipe the git blame away", price: 0.75, stock: 1000, url: "tissue.jpg", user_id: 1, retired: false, categories: Category.where(name: "Personal Care")}
+])
+
+Review.create!([
+ {
+ product_id: 1,
+ rating: 5,
+ review: "Hides my dry, crepey eye circles from Betsy"
+ },
+ {
+ product_id: 2,
+ rating: 3,
+ review: "I prefer naproxen, but this worked okay for my post-retro hangover"
+ },
+ {
+ product_id: 5,
+ rating: 5,
+ review: "This worked better than expected when I turned my Betsy group's git file directory structure into a dumpster fire. Could do without the Doctor, but whatevs"
+ },
+ {
+ product_id: 4,
+ rating: 1,
+ review: "Would give this a 0 rating if I could. This totally messed up my computer screen and didn't persist my deletions when I pushed to git"
+ },
+ {
+ product_id: 8,
+ rating: 4,
+ review: "I've been sleep-whiteboarding recently, but missing the whiteboard. This really helped clean my apartment walls"
+ },
+ {
+ product_id: 11,
+ rating: 5,
+ review: "I liked these because they were functional in drying my many, many tears and cheap so I could buy in volume"
+ },
+ {
+ product_id: 9,
+ rating: 4,
+ review: "I feel like this has helped my mattress stay fresh and clean clean when I don't have time to shower because I'm in the matrix. I wish it had more padding"
+ },
+ {
+ product_id: 10,
+ rating: 4,
+ review: "I passed out on the roof of Purple at lunch time because I hadn't slept for 48 hours because Ada. It was Seattle's annual day of sun and I look like an angry strawberry but this has helped take the heat off"
+ },
+ {
+ product_id: 3,
+ rating: 5,
+ review: "Priceless. Better than Rails magic."
+ },
+ {
+ product_id: 6,
+ rating: 1,
+ review: "This schmuck wasn't able to get a good outcome for my very compelling case wherein I was stuck in the deli elevator at Ada for hours and it was super traumatizing. Find someone else."
+ }
+])
diff --git a/feedback.md b/feedback.md
deleted file mode 100644
index 5950f49c8e..0000000000
--- a/feedback.md
+++ /dev/null
@@ -1,41 +0,0 @@
-# bEtsy
-## What We're Looking For
-
-Feature | Feedback
-:------------- | :-------------
-**Baseline** |
-Appropriate Git Usage with all members contributing |
-Answered comprehension questions |
-Trello board is created and utilized in project management |
-Heroku instance is online |
-**General** |
-Nested routes follow RESTful conventions |
-oAuth used for User authentication |
-Functionality restricted based on user roles |
-Products can be added and removed from cart |
-Users can view past orders |
-Merchants can add, edit and view their products |
-Errors are reported to the user |
-**Order Functionality** |
-Reduces products' inventory |
-Cannot order products that are out of stock |
-Changes order state |
-Clears current cart |
-**Database** |
-ERD includes all necessary tables and relationships |
-Table relationships |
-**Models** |
-Validation rules for Models |
-Business logic is in the models |
-**Controllers** |
-Controller Filters used to DRY up controller code |
-**Testing** |
-Model Testing |
-Controller Testing |
-Session Testing |
-SimpleCov at 90% for controller and model tests |
-**Front-end** |
-The app is styled to create an attractive user interface |
-Content is organized with HTML5 semantic tags |
-CSS is DRY |
-**Overall** |
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/package.json b/package.json
new file mode 100644
index 0000000000..4284c5f3b0
--- /dev/null
+++ b/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "regrEtsy",
+ "private": true,
+ "dependencies": {}
+}
diff --git a/public/404.html b/public/404.html
new file mode 100644
index 0000000000..2be3af26fc
--- /dev/null
+++ b/public/404.html
@@ -0,0 +1,67 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/422.html b/public/422.html
new file mode 100644
index 0000000000..c08eac0d1d
--- /dev/null
+++ b/public/422.html
@@ -0,0 +1,67 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/500.html b/public/500.html
new file mode 100644
index 0000000000..78a030af22
--- /dev/null
+++ b/public/500.html
@@ -0,0 +1,66 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000000..37b576a4a0
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1 @@
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
new file mode 100644
index 0000000000..d19212abd5
--- /dev/null
+++ b/test/application_system_test_case.rb
@@ -0,0 +1,5 @@
+require "test_helper"
+
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
+end
diff --git a/test/controllers/.keep b/test/controllers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb
new file mode 100644
index 0000000000..f804c6d1c7
--- /dev/null
+++ b/test/controllers/carts_controller_test.rb
@@ -0,0 +1,178 @@
+require "test_helper"
+
+describe CartsController do
+ describe "show" do
+ it "sends success if the order exists" do
+ order = Order.first
+ get order_path(order)
+ must_respond_with :success
+ end
+
+ it "sends success if the orders products exist" do
+ order = Order.first
+ product = Product.first
+ orderitem = Orderitem.create!(product: product, order_id: order.id, quantity: 1)
+ order.products.must_respond_with :success
+ end
+
+ it "sends success if the orderitems exist" do
+ order = Order.first
+ product = Product.first
+ end
+ end
+
+ describe "update" do
+ #kat will poke this
+ it "updates an existing order with valid data" do
+ get root_path
+ order = Order.find(session[:order_id])
+
+ order.must_be :valid?
+ order_item = order.orderitems.first
+ order_item.must_be :valid?
+
+ order_item.product.id.must_equal 6
+
+
+ old_order_item_quantity = order_item.quantity
+ old_order_item_quantity.must_equal 3
+
+ new_quantity = 6
+
+ patch cart_path(order), params: { product_id: order_item.product.id, quantity: new_quantity, order_id: order.id }
+ order.reload
+ result = order_item.quantity
+ result.must_equal new_quantity
+
+ end
+
+ # it "sends failure for invalid data" do
+ # order = Order.first
+ # order_item = order.orderitems.first
+ # old_order_item_quantity = order_item.quantity
+ # new_quantity = "three"
+ #
+ # patch cart_path(order), params: { quantity: new_quantity }
+ # order.reload
+ # result = order_item.quantity
+ # result.wont_equal new_quantity
+ # end
+ #
+ # it "removes a product from the cart" do
+ # order = Order.first
+ # order_item_id = order.orderitems.first.id
+ # new_quantity = 0
+ #
+ # patch cart_path(order), params: { quantity: new_quantity }
+ # order.reload
+ # result = order.orderitems
+ # result.wont_include order_item_id
+ # end
+ #
+ # it "changes the quantity of an existing product in the cart" do
+ # order = Order.first
+ # order_item = order.orderitems.first
+ # old_order_item_quantity = order_item.quantity
+ # new_quantity = 1
+ #
+ # patch cart_path(order), params: { quantity: new_quantity }
+ # order.reload
+ # result = order_item.quantity
+ # result.must_equal new_quantity
+ # end
+ #
+ # it "sends not_found for an order that does not exist" do
+ # skip
+ # end
+ # end
+ #
+ # describe "add_to_cart" do
+ # it "successfully adds in-stock products to the cart" do
+ # order = orders(:order_two)
+ # puts "#{order.id} order id"
+ # product = products(:regret)
+ # puts "#{product.id} product id"
+ # old_order_item_count = order.products.count
+ # new_quantity = 1
+ # product.stock.must_be :>, 1
+ # post add_to_cart_path, params: { id: order.id, product_id: product.id, quantity: new_quantity }
+ #
+ # result = order.products
+ # must_respond_with :redirect
+ # result.must_include product
+ #
+ # end
+ #
+ # it "does not add products to the cart that are out of stock" do
+ # skip
+ # end
+ #
+ #
+ # end
+ #
+ # describe "checkout" do
+ # it "renders the shipping and payment info form" do
+ # get checkout_path(Order.first)
+ # must_respond_with :success
+ # end
+ # end
+ #
+ # describe "finalize" do
+ # it "reduces the number of inventory for each product purchased" do
+ # order = Order.first
+ # product = Product.first
+ # old_stock_count = product.stock
+ #
+ #
+ # end
+ #
+ # it "changes the order status from 'pending' to paid" do
+ # skip #what is order status initialized as?
+ # end
+
+ it "creates a Buyer Detail record" do
+ get root_path
+ order_id = session[:order_id]
+ order = Order.find(session[:order_id])
+
+ order.must_be :valid?
+
+ payment_info = {
+ email: "test@test.com",
+ mailing_address: "123 Street",
+ buyer_name: "Buyer Person",
+ card_number: "1234567890",
+ expiration: "01/01",
+ cvv: "1234",
+ zipcode: "12345",
+ order_id: order_id
+ }
+ buyer = Buyerdetail.new(payment_info)
+ buyer.must_be :valid?
+ buyer.save
+ post checkout_path(order), params: { buyerdetail: payment_info }
+
+ result = Buyerdetail.find_by(order_id: order_id).id
+
+ result.must_equal buyer.id
+ end
+
+ it "responds with bad_request if the order has errors" do
+ skip
+ end
+ end
+
+ describe "order_details" do
+ it "successfully renders the order details" do
+ order = Order.first
+ get order_path(order)
+ must_respond_with :success
+ end
+ end
+
+ describe "clear_cart" do
+ it "clears the current cart" do
+ #TODO where is this executed?
+ end
+ end
+end
diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb
new file mode 100644
index 0000000000..1b2248fea2
--- /dev/null
+++ b/test/controllers/categories_controller_test.rb
@@ -0,0 +1,241 @@
+require "test_helper"
+
+describe CategoriesController do
+ describe "authenticated user" do
+ before do
+ @user = User.first
+ login(@user)
+ end
+
+ describe "new" do
+ it "responds with success" do
+ puts "User Name: #{@user.name} User ID: #{@user.id}"
+ get new_category_path
+
+ must_respond_with :success
+ end
+ end
+
+ describe "create" do
+ it "can add a valid category" do
+ category_data = {
+ name: "Category Test"
+ }
+
+ old_category_count = Category.count
+
+ Category.new(category_data).must_be :valid?
+
+ post categories_path, params: { category: category_data }
+
+ must_respond_with :redirect
+ must_redirect_to categories_path
+
+ Category.count.must_equal old_category_count + 1
+ Category.last.name.must_equal category_data[:name]
+ end
+
+ it "won't add a duplicate category" do
+ category_data = {
+ name: Category.first.name
+ }
+
+ old_category_count = Category.count
+
+ Category.new(category_data).wont_be :valid?
+
+ post categories_path, params: { category: category_data }
+
+ must_respond_with :bad_request
+ Category.count.must_equal old_category_count
+ end
+ end
+
+ describe "show" do
+ it "sends success if the category exists" do
+ get category_path(Category.first)
+ must_respond_with :success
+ end
+
+ it "sends not_found if the category does not exist" do
+ category_id = Category.last.id + 1
+
+ get category_path(category_id)
+
+ must_respond_with :not_found
+ end
+ end
+
+ describe "edit" do
+ it "sends success if the category exists" do
+ get edit_category_path(Category.first)
+ must_respond_with :success
+ end
+
+ it "sends not_found if the category does not exist" do
+ category_id = Category.last.id + 1
+
+ get edit_category_path(category_id)
+
+ must_respond_with :not_found
+ end
+ end
+
+ describe "update" do
+ it "updates an existing book with valid data" do
+ category = Category.first
+ category_data = category.attributes
+ category_data[:name] = "Updated Category Name"
+
+ category.assign_attributes(category_data)
+ category.must_be :valid?
+
+ patch category_path(category), params: { category: category_data }
+
+ must_redirect_to category_path(category)
+
+ category.reload
+ category.name.must_equal category_data[:name]
+ end
+
+ it "sends bad_request for invalid data" do
+ category = Category.first
+ category_data = category.attributes
+ category_data[:name] = ""
+
+ category.assign_attributes(category_data)
+ category.wont_be :valid?
+
+ patch category_path(category), params: { category: category_data }
+
+ must_respond_with :bad_request
+
+ category.reload
+ category.name.wont_equal category_data[:name]
+ end
+
+ it "sends not_found for a category that does not exist" do
+ category_id = Category.last.id + 1
+
+ patch category_path(category_id)
+
+ must_respond_with :not_found
+ end
+ end
+
+ describe "destroy" do
+ it "destroys a real category" do
+ category_id = Category.first.id
+ old_category_count = Category.count
+
+ delete category_path(category_id)
+
+ must_respond_with :redirect
+ must_redirect_to categories_path
+
+ Category.count.must_equal old_category_count - 1
+ Category.find_by(id: category_id).must_be_nil
+ end
+
+ it "sends not_found when the category does not exist" do
+ category_id = Category.last.id + 1
+ old_category_count = Category.count
+
+ delete category_path(category_id)
+
+ must_respond_with :not_found
+ Category.count.must_equal old_category_count
+ end
+ end
+
+ end
+
+ describe "guest user" do
+ describe "index" do
+ before do
+ @category = Category.first
+ @product = Product.first
+ @product.categories << @category
+ end
+
+ it "should get a category's products index" do
+ get category_products_path(@category.id)
+ must_respond_with :success
+ end
+
+ it "sends a success respond when there are many categories" do
+ Category.count.must_be :>, 0
+
+ get categories_path
+
+ must_respond_with :success
+ end
+
+ it "sends a success respond when there are no categories" do
+ Category.destroy_all
+
+ get categories_path
+
+ must_respond_with :success
+ end
+ end
+ it "should get a category's products index" do
+ get category_products_path, params: {category_id: Category.first.id}
+ must_respond_with :success
+
+ end
+
+ it "rejects requests for new category form" do
+ get new_category_path
+
+ result = flash[:status]
+ must_redirect_to :root
+ result.must_equal :failure
+ end
+
+ it "rejects requests to create a category" do
+ category_data = {
+ name: "Test Category"
+ }
+
+ old_category_count = Category.count
+ Category.new(category_data).must_be :valid?
+
+ post categories_path, params: { category: category_data }
+
+ must_redirect_to :root
+ result.must_equal :failure
+ Category.count.must_equal old_category_count
+ end
+
+ it "rejects requests for edit category form" do
+ get edit_category_path(Category.first)
+ must_respond_with :unauthorized
+ end
+
+ it "rejects requests to update a category" do
+ category = Category.first
+ category_data = category.attributes
+ category_data[:name] = "updated category name"
+
+ category.assign_attributes(category_data)
+ category.must_be :valid?
+
+ patch category_path(category), params: { category: category_data }
+
+ must_redirect_to :root
+ result.must_equal :failure
+ end
+
+ it "rejects requests to delete a category" do
+ category_id = Category.first.id
+ old_category_count = Category.count
+
+ delete category_path(category_id)
+
+ must_redirect_to :root
+ result.must_equal :failure
+ Category.count.must_equal old_category_count
+ 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..c9de21db57
--- /dev/null
+++ b/test/controllers/products_controller_test.rb
@@ -0,0 +1,127 @@
+require "test_helper"
+
+describe ProductsController do
+ describe "authenticated user" do
+ before do
+ login(User.first)
+ end
+
+ describe 'root' do
+ it 'should get root path' do
+ get root_path
+ must_respond_with :success
+ end
+ end # ends 'describe 'root' do'
+
+ describe 'products index' do
+ it 'should get the products index' do
+ get products_path
+ must_respond_with :success
+ end
+
+ it 'sends a success response when there is more than one product' do
+ # Assumptions
+ Product.count.must_be :>, 0
+
+ # Act
+ get products_path
+
+ # Assert
+ must_respond_with :success
+ end
+
+ it 'sends a success response when there are no products' do
+ # Arrange
+ Product.destroy_all
+
+ # Act
+ get products_path
+
+ # Assert
+ must_respond_with :success
+ end
+
+ it "should get a user's product index" do
+ get user_products_path()
+ must_respond_with :success
+ end
+
+ it 'should render 404 if user_id does not exist' do
+ get user_products_path()
+ must_respond_with :success
+ end
+
+ it 'should get search results' do
+ get products_path, params: {search: "aspirin"}
+ must_respond_with :success
+ end
+ end # ends 'describe 'index' do'
+
+ describe 'new' do
+ it 'responds with success' do
+ get new_product_path
+ must_respond_with :success
+ end
+ end # ends describe 'new' do
+
+ describe 'create' do
+ it 'can add a valid product' do
+ # Arrange
+ product_data = {
+ name: 'controller test product',
+ user_id: User.first.id
+ }
+ old_product_count = Product.count
+
+ # Assumptions
+ Product.new(product_data).must_be :valid?
+
+ # Act
+ post products_path, params: { product: product_data }
+
+ # Assert
+ must_respond_with :redirect
+ must_redirect_to products_path
+
+ Product.count.must_equal old_product_count + 1
+ Product.last.name.must_equal product_data[:name]
+ end
+
+ it "won't add an invalid product" do
+ # Arrange
+ product_data = {
+ name: '',
+ }
+ old_product_count = Product.count
+
+ # Assumptions
+ Product.new(product_data).wont_be :valid?
+
+ # Act
+ post products_path, params: { product: product_data }
+ # Assert
+ must_respond_with :bad_request
+ Product.count.must_equal old_product_count
+ end
+
+ end # ends describe 'create' do
+
+ describe 'guest user' do
+ describe 'root' do
+ it 'should get root path' do
+ get root_path
+ must_respond_with :success
+ end
+ end # ends 'describe 'root' do'
+
+ describe 'products index' do
+ it 'should get the products index' do
+ get products_path
+ must_respond_with :success
+ end
+ end
+ end
+
+
+ end # ends 'describe "authenticated user" do'
+end # ends 'describe ProductsController do'
diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb
new file mode 100644
index 0000000000..9faeab2e69
--- /dev/null
+++ b/test/controllers/reviews_controller_test.rb
@@ -0,0 +1,57 @@
+require "test_helper"
+
+describe ReviewsController do
+ before do
+ @product = {
+ id: 3,
+ name: 'controller test product',
+ user_id: User.first.id
+ }
+ end
+ describe 'new' do
+ it 'succeeds with new review' do
+ get new_product_review_path
+ must_respond_with :success
+ end
+ end
+
+ describe 'create' do
+ it 'can add a valid review' do
+
+ # Arrange
+ review_data = {
+ rating: 5,
+ review: 'This was a great product',
+ product_id: 3
+ }
+
+ review_count = Review.count
+ #Assumptions
+ result = Review.new(review_data)
+ result.must_be :valid?
+ # Act
+ post product_reviews_path, params: { review: review_data }
+ # Assert
+ must_respond_with :redirect
+ must_redirect_to product_path(@product)
+
+ Review.count.must_equal review_count + 1
+ end
+
+ it "won't add an invalid review" do
+ review_data = {
+ rating: 5,
+ review: 'This was a great product',
+ product_id: 3
+ }
+ review_count = Review.count
+
+ Review.new(review_data).wont_be :valid?
+
+ post product_reviews_path, params: { review: review_data }
+
+ must_respond_with :bad_request
+ Review.count.must_equal review_count
+ end
+ end
+ end
diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb
new file mode 100644
index 0000000000..662a896c90
--- /dev/null
+++ b/test/controllers/sessions_controller_test.rb
@@ -0,0 +1,115 @@
+require "test_helper"
+
+describe SessionsController do
+
+ describe 'new' do
+ it 'succeeds with a new user' do
+ get new_user_path
+ must_respond_with :success
+ end
+ end
+
+ describe "auth_callback" do
+ it "should log in an existing user and redirects them back to the homepage" do
+ start_count = User.count
+ user = users(:anne)
+
+ #Action
+ login(user)
+ #Assert
+ must_respond_with :redirect
+ must_redirect_to root_path
+ User.count.must_equal start_count
+ session[:user_id].must_equal user.id
+ end
+
+ it "can login a new user" do
+ start_count = User.count
+ user = User.new(
+ username: "Greg",
+ provider: 'github',
+ email: 'Greg@naver.com',
+ uid: 901 )
+
+ login(user)
+
+ #Assert
+ must_respond_with :redirect
+ must_redirect_to root_path
+ User.count.must_equal (start_count + 1)
+ session[:user_id].must_equal User.last.id
+ end
+
+ it 'logs in an existing user' do
+ # Arrange
+ start_count = User.count
+ user = User.first
+
+ # Act
+ login(user)
+
+ # Assert
+ User.count.must_equal start_count
+ session[:user_id].must_equal user.id
+ end
+
+ it 'does not login if the user data is invalid' do
+ # Validations fails
+ user = User.new(
+ uid: 99999,
+ provider: "github",
+ email: nil,
+ name: nil)
+
+ OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user))
+ get auth_callback_path(:github)
+
+ must_respond_with :redirect
+ must_redirect_to root_path
+ # session[:user_id].must_equal nil
+ end
+
+ it 'does not log in with insufficient data' do
+ start_count = User.count
+
+ user = User.new(
+ provider: "github",
+ name: 'something',
+ uid: 99999)
+
+ login(user)
+
+ User.count.must_equal start_count
+ # Auth hash doesn not include a uid
+ end
+ end
+
+ describe 'logout' do
+ it "can logout a user" do
+ login(users(:anne))
+ session[:user_id].must_equal users(:anne).id
+
+ delete logout_path
+ must_respond_with :redirect
+ must_redirect_to root_path
+ end
+ end
+
+ describe 'user_email' do
+ it "splits email into username" do
+ user = {name: 'name',
+ username: nil,
+ email: 'ada@developers.org',
+ uid: "9999",
+ provider: 'github'
+ }
+
+ user_count = User.count
+ User.new(user).must_be :valid?
+ post users_path, params: { user: user }
+ must_respond_with :success
+ User.count.must_equal user_count + 1
+ User.last.username.must_equal "ada"
+ 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..2425d5e5a3
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,24 @@
+require 'test_helper'
+
+describe UsersController do
+
+ describe 'show' do
+ it 'sends success if the user extant' do
+ get user_path(User.first)
+ must_respond_with :success
+ end
+
+ it 'it sends a 404 if the user is not found' do
+ user_id = User.last.id + 1
+ get user_path(user_id)
+ must_respond_with :not_found
+ end
+ end
+
+ describe 'new' do
+ it 'succeeds with new user' do
+ get new_user_path
+ must_respond_with :success
+ end
+ end
+end
diff --git a/test/fixtures/.keep b/test/fixtures/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/buyerdetails.yml b/test/fixtures/buyerdetails.yml
new file mode 100644
index 0000000000..3b0ab4f069
--- /dev/null
+++ b/test/fixtures/buyerdetails.yml
@@ -0,0 +1,21 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+ada:
+ email: ada@adadevelopersacademy.
+ mailing_address: 112 Somewhere else
+ buyer_name: Ada
+ card_number: 1234123412341234
+ expiration: 04-02-1985
+ cvv: 213
+ zipcode: 35209
+ order: 1
+
+# two:
+# email:
+# mailing_address:
+# buyer_name:
+# card_number:
+# expiration:
+# cvv:
+# zipcode:
+# order_id:
diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml
new file mode 100644
index 0000000000..7f4c97152c
--- /dev/null
+++ b/test/fixtures/categories.yml
@@ -0,0 +1,4 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+cleaning:
+ name: Cleaning
diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/orderitems.yml b/test/fixtures/orderitems.yml
new file mode 100644
index 0000000000..6ea5553342
--- /dev/null
+++ b/test/fixtures/orderitems.yml
@@ -0,0 +1,20 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the "{}" from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+oi_one:
+ product: regret
+ quantity: 6
+ order: order_one
+
+oi_two:
+ product: product_one
+ quantity: 6
+ order: order_one
+
+oi_three:
+ product: product_one
+ quantity: 3
+ order: order_two
diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml
new file mode 100644
index 0000000000..87c82d3e55
--- /dev/null
+++ b/test/fixtures/orders.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+order_one:
+ status: pending
+ buyerdetail_id: ada
+
+order_two:
+ status: paid
+ buyerdetail_id: ada
diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml
new file mode 100644
index 0000000000..190a23784f
--- /dev/null
+++ b/test/fixtures/products.yml
@@ -0,0 +1,46 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+odor:
+ name: Odor Eaters
+ price: 12.95
+ user: anne
+ stock: 20
+ url: http://placekitten.com/200/300
+ retired: false
+
+regret:
+ name: Pure Unadulterated Regret
+ price: 10
+ user: anne
+ stock: 200000
+ url: http://placekitten.com/200/300
+ retired: false
+
+product_one:
+ name: White Out
+ description: A description
+ price: 1.00
+ stock: 5
+ url: http://placekitten.com/200/300
+ user: anne
+ retired: false
+
+# shampoo:
+# name: dry shampoo
+# description: best non-shampoo you'll ever have
+# price: 11.99
+# stock: 5
+# url: shampoo.jpg
+# user_id: 1
+# category: personal care
+# shoes:
+# name: vans
+# price: 10
+# description: some black vans
+# user: anne
+#
+# toy:
+# name: figit spinner
+# price: 9
+# description: revolving toy
+# user: anne
diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml
new file mode 100644
index 0000000000..f4a664e076
--- /dev/null
+++ b/test/fixtures/reviews.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+# one:
+# text:
+# rating: 4
+# product_id: shoes
+#
+# two:
+# text: A good product
+# rating: 5
+# product_id: toy
diff --git a/test/fixtures/sessions.yml b/test/fixtures/sessions.yml
new file mode 100644
index 0000000000..a784dcd1d6
--- /dev/null
+++ b/test/fixtures/sessions.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the "{}" from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+# one: {}
+# # column: value
+# #
+# two: {}
+# # column: value
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
new file mode 100644
index 0000000000..fa552fb0f0
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+anne:
+ name: Anne
+ username: annehwatson1
+ email: anne1@email.com
+ password: helloworld
+ uid: 123
+ provider: github
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/buyerdetail_test.rb b/test/models/buyerdetail_test.rb
new file mode 100644
index 0000000000..f2f4f147c4
--- /dev/null
+++ b/test/models/buyerdetail_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+describe Buyerdetail do
+ let(:buyerdetail) { Buyerdetail.new }
+
+ it "must be valid" do
+ value(buyerdetail).must_be :valid?
+ end
+end
diff --git a/test/models/category_test.rb b/test/models/category_test.rb
new file mode 100644
index 0000000000..781320ad8e
--- /dev/null
+++ b/test/models/category_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+describe Category do
+ let(:category) { Category.new }
+
+ it "must be valid" do
+ value(category).must_be :valid?
+ end
+end
diff --git a/test/models/order_test.rb b/test/models/order_test.rb
new file mode 100644
index 0000000000..a5a7d1ba84
--- /dev/null
+++ b/test/models/order_test.rb
@@ -0,0 +1,36 @@
+require "test_helper"
+
+describe Order do
+ it 'can be created with valid data' do
+ old_order_count = Order.count
+ order = Order.new(status: :pending)
+
+ order.must_be :valid?
+
+ order = order.save
+ result = order.valid?
+
+ result.must_be true
+ end
+
+ describe "subtotal" do
+ it "calculates the line-item cost of an item" do
+ orderitem = orderitems(:oi_one)
+ orderitem.quantity.must_equal 6
+
+ price = orderitem.product.price
+ total = (price * orderitem.quantity)
+ expected_result = 72.86
+
+ order = orderitem.order
+
+ order.must_be :valid?
+
+ result = order.total
+
+ result.must_equal expected_result
+
+ end
+ end
+
+end
diff --git a/test/models/orderitem_test.rb b/test/models/orderitem_test.rb
new file mode 100644
index 0000000000..68b5b14cf4
--- /dev/null
+++ b/test/models/orderitem_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+describe Orderitem do
+
+ it "must be valid" do
+ orderitem = Orderitem.first
+ orderitem.must_be :valid?
+ end
+end
diff --git a/test/models/product_test.rb b/test/models/product_test.rb
new file mode 100644
index 0000000000..bf691089e6
--- /dev/null
+++ b/test/models/product_test.rb
@@ -0,0 +1,52 @@
+require "test_helper"
+
+describe Product do
+
+ it "must be valid" do
+ product = Product.first
+ result = product.valid?
+ result.must_equal true
+ end
+
+ describe 'retire logic' do
+ describe 'product#retire' do
+ it "toggles product.retired boolean to true" do
+ product = Product.find_by(retired: false)
+ product_id = product.id
+
+ product.retire
+
+ result = Product.find(product_id)
+
+ result.retired.must_equal true
+ end
+ end
+
+ describe 'product#retired?' do
+ it "returns true for retired" do
+ product = Product.find_by(retired: false)
+ product_id = product.id
+
+ result = product.retired?
+ result.must_equal false
+
+ product.retire
+
+ result = Product.find(product_id)
+
+ result.retired?.must_equal true
+ end
+
+ it "returns false if not retired" do
+ product = Product.find_by(retired: false)
+ product_id = product.id
+
+ result = product.retired?
+
+ result.must_equal false
+ end
+ end
+ end
+
+
+end
diff --git a/test/models/review_test.rb b/test/models/review_test.rb
new file mode 100644
index 0000000000..ce8378a033
--- /dev/null
+++ b/test/models/review_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+describe Review do
+ let(:review) { Review.new }
+
+ it "must be valid" do
+ value(review).must_be :valid?
+ end
+end
diff --git a/test/models/session_test.rb b/test/models/session_test.rb
new file mode 100644
index 0000000000..17f1617bc1
--- /dev/null
+++ b/test/models/session_test.rb
@@ -0,0 +1,15 @@
+require "test_helper"
+
+describe Session do
+ let(:session) { Session.new }
+
+ it "must be valid" do
+ value(session).must_be :valid?
+ end
+
+ describe 'self.sweep method' do
+ it 'returns a time object for string' do
+
+ end
+ end
+end
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 0000000000..0384c7081d
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,71 @@
+require "test_helper"
+
+describe User do
+ let(:user) { User.new(
+ username: "Greg",
+ provider: 'github',
+ email: 'Greg@naver.com',
+ uid: 901 ) }
+
+ it "must be valid" do
+ value(user).must_be :valid?
+ end
+
+ describe 'relations' do
+ it 'has a list of products' do
+ user = users(:anne)
+ user.must_respond_to :products
+
+ 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
+ user = User.new(
+ username: 'username',
+ password: 'helloworld',
+ uid: 123,
+ provider: 'github')
+
+ user.save!
+
+ user2 = User.new(username: 'username')
+ result = user2.save
+ result.must_equal false
+ user2.errors.messages.must_include :username
+ end
+ end
+
+ # describe 'calculate revenue' do
+ # it "figures out total revenue for user" do
+ # user = User.first
+ # user.products.wont_be_nil
+ # user.orders.wont_be_nil
+ #
+ # expected_result = 0.0
+ # user.orders.each do |order|
+ # products = order.products.where(user_id: user.id)
+ # products.each do |product|
+ # orderitems = order.orderitems.where(product_id: product.id)
+ # orderitems.each do |orderitem|
+ # order.subtotal()
+ # expected_result += order.
+ # end
+ # end
+ # end
+ # expected_result.must_equal nil
+ # user.total_revenue.must_equal expected_result
+ # end
+ # end
+ # 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..e77553dbfd
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,90 @@
+require 'simplecov'
+# require 'simplecov-console'
+# SimpleCov.formatter = SimpleCov.formatter = SimpleCov::Formatter::Console
+# SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
+# SimpleCov::Formatter::HTMLFormatter,
+# SimpleCov::Formatter::Console,
+# ])
+
+SimpleCov.start 'rails' do
+ add_filter '/app/jobs/application_job.rb'
+ add_filter '/app/mailers/application_mailer.rb'
+ add_filter '/app/channels/application_cable/channel.rb'
+ add_filter '/app/channels/application_cable/connection.rb'
+ add_filter '/app/helpers/'
+end
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path("../../config/environment", __FILE__)
+
+require "rails/test_help"
+require "minitest/rails"
+require "minitest/reporters" # for Colorized output
+
+# For colorful output!
+Minitest::Reporters.use!(
+ Minitest::Reporters::SpecReporter.new,
+ ENV,
+ Minitest.backtrace_filter
+)
+
+
+# To add Capybara feature tests add `gem "minitest-rails-capybara"`
+# to the test group in the Gemfile and uncomment the following:
+# require "minitest/rails/capybara"
+
+# Uncomment for awesome colorful output
+# require "minitest/pride"
+
+class ActiveSupport::TestCase
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
+ fixtures :all
+ # Add more helper methods to be used by all tests here...
+ def setup
+ OmniAuth.config.test_mode = true
+ end
+
+ def mock_auth_hash(user)
+ return {
+ provider: user.provider,
+ uid: user.uid,
+ info: {
+ email: user.email,
+ name: user.name
+ }
+ }
+ end
+
+ def login(user)
+ OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user))
+ get auth_callback_path(:github)
+ must_redirect_to root_path
+ end
+
+ def new_buyer(order)
+ payment_info = {
+ email: "test@test.com",
+ mailing_address: "123 Street",
+ buyer_name: "Buyer Person",
+ card_number: "1234567890",
+ expiration: "01/01",
+ cvv: "1234",
+ zipcode: "12345",
+ order_id: order.id
+ }
+ post checkout_path(order.id), params: { buyerdetail: payment_info }
+ must_redirect_to order_path(order)
+ end
+
+
+ def retire_product(product_id)
+ product = Product.find(product_id)
+
+ product.retire
+
+ result = Product.find(product_id)
+
+ result.retired.must_be true
+ end
+
+end
diff --git a/vendor/.gitignore b/vendor/.gitignore
new file mode 100644
index 0000000000..a102292231
--- /dev/null
+++ b/vendor/.gitignore
@@ -0,0 +1,24 @@
+# See https://help.github.com/articles/ignoring-files for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile '~/.gitignore_global'
+
+# Ignore bundler config.
+/.bundle
+
+# Ignore all logfiles and tempfiles.
+/log/*
+/tmp/*
+!/log/.keep
+!/tmp/.keep
+
+/node_modules
+/yarn-error.log
+
+.byebug_history
+
+
+.env
+
+/coverage/*
diff --git a/vendor/.keep b/vendor/.keep
new file mode 100644
index 0000000000..e69de29bb2