+
diff --git a/bin/bundle b/bin/bundle
new file mode 100755
index 0000000000..66e9889e8b
--- /dev/null
+++ b/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rails b/bin/rails
new file mode 100755
index 0000000000..5badb2fde0
--- /dev/null
+++ b/bin/rails
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 0000000000..d87d5f5781
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/bin/setup b/bin/setup
new file mode 100755
index 0000000000..78c4e861dc
--- /dev/null
+++ b/bin/setup
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:setup'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/spring b/bin/spring
new file mode 100755
index 0000000000..fb2ec2ebb4
--- /dev/null
+++ b/bin/spring
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+ require 'rubygems'
+ require 'bundler'
+
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
+ if spring
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
+ gem 'spring', spring.version
+ require 'spring/binstub'
+ end
+end
diff --git a/bin/update b/bin/update
new file mode 100755
index 0000000000..a8e4462f20
--- /dev/null
+++ b/bin/update
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/yarn b/bin/yarn
new file mode 100755
index 0000000000..c2bacef836
--- /dev/null
+++ b/bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+VENDOR_PATH = File.expand_path('..', __dir__)
+Dir.chdir(VENDOR_PATH) do
+ begin
+ exec "yarnpkg #{ARGV.join(" ")}"
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000000..f7ba0b527b
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/config/application.rb b/config/application.rb
new file mode 100644
index 0000000000..5f6ca0f9b2
--- /dev/null
+++ b/config/application.rb
@@ -0,0 +1,25 @@
+require_relative 'boot'
+
+require 'rails/all'
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module Betsy
+ class Application < Rails::Application
+ config.generators do |g|
+ # Force new test files to be generated in the minitest-spec style
+ g.test_framework :minitest, spec: true
+
+ # Always use .js files, never .coffee
+ g.javascript_engine :js
+ end
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.1
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ end
+end
diff --git a/config/boot.rb b/config/boot.rb
new file mode 100644
index 0000000000..30f5120df6
--- /dev/null
+++ b/config/boot.rb
@@ -0,0 +1,3 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/config/cable.yml b/config/cable.yml
new file mode 100644
index 0000000000..3cba994bb2
--- /dev/null
+++ b/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: redis://localhost:6379/1
+ channel_prefix: betsy_production
diff --git a/config/database.yml b/config/database.yml
new file mode 100644
index 0000000000..6903bb6083
--- /dev/null
+++ b/config/database.yml
@@ -0,0 +1,85 @@
+# PostgreSQL. Versions 9.1 and up are supported.
+#
+# Install the pg driver:
+# gem install pg
+# On OS X with Homebrew:
+# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
+# On OS X with MacPorts:
+# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
+# On Windows:
+# gem install pg
+# Choose the win32 build.
+# Install PostgreSQL and put its /bin directory on your path.
+#
+# Configure Using Gemfile
+# gem 'pg'
+#
+default: &default
+ adapter: postgresql
+ encoding: unicode
+ # For details on connection pooling, see Rails configuration guide
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+
+development:
+ <<: *default
+ database: betsy_development
+
+ # The specified database role being used to connect to postgres.
+ # To create additional roles in postgres see `$ createuser --help`.
+ # When left blank, postgres will use the default role. This is
+ # the same name as the operating system user that initialized the database.
+ #username: betsy
+
+ # The password associated with the postgres role (username).
+ #password:
+
+ # Connect on a TCP socket. Omitted by default since the client uses a
+ # domain socket that doesn't need configuration. Windows does not have
+ # domain sockets, so uncomment these lines.
+ #host: localhost
+
+ # The TCP port the server listens on. Defaults to 5432.
+ # If your server runs on a different port number, change accordingly.
+ #port: 5432
+
+ # Schema search path. The server defaults to $user,public
+ #schema_search_path: myapp,sharedapp,public
+
+ # Minimum log levels, in increasing order:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, notice, warning, error, fatal, and panic
+ # Defaults to warning.
+ #min_messages: notice
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: betsy_test
+
+# As with config/secrets.yml, you never want to store sensitive information,
+# like your database password, in your source code. If your source code is
+# ever seen by anyone, they now have access to your database.
+#
+# Instead, provide the password as a unix environment variable when you boot
+# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
+# for a full rundown on how to provide these environment variables in a
+# production deployment.
+#
+# On Heroku and other platform providers, you may have a full connection URL
+# available as an environment variable. For example:
+#
+# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
+#
+# You can use this database configuration with:
+#
+# production:
+# url: <%= ENV['DATABASE_URL'] %>
+#
+production:
+ <<: *default
+ database: betsy_production
+ username: betsy
+ password: <%= ENV['BETSY_DATABASE_PASSWORD'] %>
diff --git a/config/environment.rb b/config/environment.rb
new file mode 100644
index 0000000000..426333bb46
--- /dev/null
+++ b/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
new file mode 100644
index 0000000000..5187e22186
--- /dev/null
+++ b/config/environments/development.rb
@@ -0,0 +1,54 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ if Rails.root.join('tmp/caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/config/environments/production.rb b/config/environments/production.rb
new file mode 100644
index 0000000000..9284f84839
--- /dev/null
+++ b/config/environments/production.rb
@@ -0,0 +1,91 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
+ # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
+ # `config/secrets.yml.key`.
+ config.read_encrypted_secrets = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "betsy_#{Rails.env}"
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/config/environments/test.rb b/config/environments/test.rb
new file mode 100644
index 0000000000..8e5cbde533
--- /dev/null
+++ b/config/environments/test.rb
@@ -0,0 +1,42 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000000..89d2efab2b
--- /dev/null
+++ b/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
new file mode 100644
index 0000000000..4b828e80cb
--- /dev/null
+++ b/config/initializers/assets.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000..59385cdf37
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000000..5a6a32d371
--- /dev/null
+++ b/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000000..4a994e1e7b
--- /dev/null
+++ b/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000000..ac033bf9dc
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000000..dc1899682b
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 0000000000..fd4416122a
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,3 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email"
+end
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000000..bbfc3961bf
--- /dev/null
+++ b/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/config/locales/en.yml b/config/locales/en.yml
new file mode 100644
index 0000000000..decc5a8573
--- /dev/null
+++ b/config/locales/en.yml
@@ -0,0 +1,33 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/config/puma.rb b/config/puma.rb
new file mode 100644
index 0000000000..1e19380dcb
--- /dev/null
+++ b/config/puma.rb
@@ -0,0 +1,56 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory. If you use this option
+# you need to make sure to reconnect any threads in the `on_worker_boot`
+# block.
+#
+# preload_app!
+
+# If you are preloading your application and using Active Record, it's
+# recommended that you close any connections to the database before workers
+# are forked to prevent connection leakage.
+#
+# before_fork do
+# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
+# end
+
+# The code in the `on_worker_boot` will be called if you are using
+# clustered mode by specifying a number of `workers`. After each worker
+# process is booted, this block will be run. If you are using the `preload_app!`
+# option, you will want to use this block to reconnect to any threads
+# or connections that may have been created at application boot, as Ruby
+# cannot share connections between processes.
+#
+# on_worker_boot do
+# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
+# end
+#
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000000..3461e7137f
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,31 @@
+Rails.application.routes.draw do
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+
+
+ root 'mains#index'
+
+ get '/user/:id', to: 'sessions#index', as: 'user_profile'
+
+ delete '/logout', to: 'sessions#logout', as: 'logout'
+ resources :order_items
+
+ resources :mains, only: [:index]
+
+ resources :categories, only: [:index, :new, :create] do
+ resources :products, only: [:index]
+ end
+
+ resources :users do
+ resources :products, only: [:index]
+ end
+
+ resources :orders
+
+ resources :products do
+ resources :reviews, only: [:new, :create]
+ end
+
+
+ get "/auth/:provider/callback", to: "sessions#create", as: "auth_callback"
+
+end
diff --git a/config/secrets.yml b/config/secrets.yml
new file mode 100644
index 0000000000..dc42500d6f
--- /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: 5bc0d441f84843b1e1630c3069776c5c7df8ec601c28040ae4a3f60bf1bdcb2ff4855d063d580ff664b6eea6257c43adf195579cc9a299e739871c54b3ee5c97
+
+test:
+ secret_key_base: 3b5eb0c26371d457be0fba27ec9e928322d5a00c9c778ca18bc39a509196ed0f6e2e649b57a587faf5b630ec663aeec5c587411fc1ab76e418e43b155b930d60
+
+# 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/categories.csv b/db/categories.csv
new file mode 100644
index 0000000000..28553da410
--- /dev/null
+++ b/db/categories.csv
@@ -0,0 +1,9 @@
+name
+Home
+Bedding
+Health
+Grooming
+Toys
+Training
+Accessories
+Food
diff --git a/db/migrate/20180419210951_create_products.rb b/db/migrate/20180419210951_create_products.rb
new file mode 100644
index 0000000000..d4682f63bd
--- /dev/null
+++ b/db/migrate/20180419210951_create_products.rb
@@ -0,0 +1,8 @@
+class CreateProducts < ActiveRecord::Migration[5.1]
+ def change
+ create_table :products do |t|
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419211453_add_columns_to_products.rb b/db/migrate/20180419211453_add_columns_to_products.rb
new file mode 100644
index 0000000000..0d5095bdcd
--- /dev/null
+++ b/db/migrate/20180419211453_add_columns_to_products.rb
@@ -0,0 +1,8 @@
+class AddColumnsToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_column :products, :name, :string
+ add_column :products, :stock, :integer
+ add_column :products, :price, :integer
+ add_column :products, :description, :string
+ end
+end
diff --git a/db/migrate/20180419212536_create_users.rb b/db/migrate/20180419212536_create_users.rb
new file mode 100644
index 0000000000..a588bf5a68
--- /dev/null
+++ b/db/migrate/20180419212536_create_users.rb
@@ -0,0 +1,8 @@
+class CreateUsers < ActiveRecord::Migration[5.1]
+ def change
+ create_table :users do |t|
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419214144_create_orders.rb b/db/migrate/20180419214144_create_orders.rb
new file mode 100644
index 0000000000..8d3698575f
--- /dev/null
+++ b/db/migrate/20180419214144_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/20180419214714_create_order_items.rb b/db/migrate/20180419214714_create_order_items.rb
new file mode 100644
index 0000000000..db8b5cfa57
--- /dev/null
+++ b/db/migrate/20180419214714_create_order_items.rb
@@ -0,0 +1,9 @@
+class CreateOrderItems < ActiveRecord::Migration[5.1]
+ def change
+ create_table :order_items do |t|
+ t.integer :quantity
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419215007_create_reviews.rb b/db/migrate/20180419215007_create_reviews.rb
new file mode 100644
index 0000000000..4556d11346
--- /dev/null
+++ b/db/migrate/20180419215007_create_reviews.rb
@@ -0,0 +1,10 @@
+class CreateReviews < ActiveRecord::Migration[5.1]
+ def change
+ create_table :reviews do |t|
+ t.integer :rating
+ t.string :comments
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419215339_create_categories.rb b/db/migrate/20180419215339_create_categories.rb
new file mode 100644
index 0000000000..5bef4913b8
--- /dev/null
+++ b/db/migrate/20180419215339_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/20180419220346_create_shopping_carts.rb b/db/migrate/20180419220346_create_shopping_carts.rb
new file mode 100644
index 0000000000..9aa3ec7ff1
--- /dev/null
+++ b/db/migrate/20180419220346_create_shopping_carts.rb
@@ -0,0 +1,8 @@
+class CreateShoppingCarts < ActiveRecord::Migration[5.1]
+ def change
+ create_table :shopping_carts do |t|
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180420214215_add_pet_type_and_photo_to_products.rb b/db/migrate/20180420214215_add_pet_type_and_photo_to_products.rb
new file mode 100644
index 0000000000..1aebb1b1c8
--- /dev/null
+++ b/db/migrate/20180420214215_add_pet_type_and_photo_to_products.rb
@@ -0,0 +1,6 @@
+class AddPetTypeAndPhotoToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_column :products, :pet_type, :string
+ add_column :products, :photo_url, :string
+ end
+end
diff --git a/db/migrate/20180420215210_create_products_categories_join.rb b/db/migrate/20180420215210_create_products_categories_join.rb
new file mode 100644
index 0000000000..3af322f986
--- /dev/null
+++ b/db/migrate/20180420215210_create_products_categories_join.rb
@@ -0,0 +1,8 @@
+class CreateProductsCategoriesJoin < ActiveRecord::Migration[5.1]
+ def change
+ create_table :products_categories do |t|
+ t.belongs_to :product, index: true
+ t.belongs_to :category, index: true
+ end
+ end
+end
diff --git a/db/migrate/20180421184241_add_username_and_email.rb b/db/migrate/20180421184241_add_username_and_email.rb
new file mode 100644
index 0000000000..20fd9e17b7
--- /dev/null
+++ b/db/migrate/20180421184241_add_username_and_email.rb
@@ -0,0 +1,6 @@
+class AddUsernameAndEmail < ActiveRecord::Migration[5.1]
+ def change
+ add_column :users, :username, :string
+ add_column :users, :email, :string
+ end
+end
diff --git a/db/migrate/20180421184734_add_uid_and_provider.rb b/db/migrate/20180421184734_add_uid_and_provider.rb
new file mode 100644
index 0000000000..f76794f8b3
--- /dev/null
+++ b/db/migrate/20180421184734_add_uid_and_provider.rb
@@ -0,0 +1,7 @@
+class AddUidAndProvider < ActiveRecord::Migration[5.1]
+ def change
+ add_column :users, :uid, :integer, :null => false
+ add_column :users, :provider, :string, :null => false
+
+ end
+end
diff --git a/db/migrate/20180421200355_add_user_foreign_key_to_product.rb b/db/migrate/20180421200355_add_user_foreign_key_to_product.rb
new file mode 100644
index 0000000000..07e5feb713
--- /dev/null
+++ b/db/migrate/20180421200355_add_user_foreign_key_to_product.rb
@@ -0,0 +1,5 @@
+class AddUserForeignKeyToProduct < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :products, :users, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180421204232_add_product_to_reviews.rb b/db/migrate/20180421204232_add_product_to_reviews.rb
new file mode 100644
index 0000000000..c0f1aed214
--- /dev/null
+++ b/db/migrate/20180421204232_add_product_to_reviews.rb
@@ -0,0 +1,5 @@
+class AddProductToReviews < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :reviews, :product, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180423050846_change_foreign_key_user_for_products.rb b/db/migrate/20180423050846_change_foreign_key_user_for_products.rb
new file mode 100644
index 0000000000..f45fde418e
--- /dev/null
+++ b/db/migrate/20180423050846_change_foreign_key_user_for_products.rb
@@ -0,0 +1,5 @@
+class ChangeForeignKeyUserForProducts < ActiveRecord::Migration[5.1]
+ def change
+ rename_column :products, :users_id, :user_id
+ end
+end
diff --git a/db/migrate/20180423195434_add_foreign_key_orders.rb b/db/migrate/20180423195434_add_foreign_key_orders.rb
new file mode 100644
index 0000000000..1cfb584e7e
--- /dev/null
+++ b/db/migrate/20180423195434_add_foreign_key_orders.rb
@@ -0,0 +1,6 @@
+class AddForeignKeyOrders < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :order_items, :order, foreign_key:true
+ add_reference :order_items, :product, foreign_key:true
+ end
+end
diff --git a/db/migrate/20180423200648_change_default_column_orders.rb b/db/migrate/20180423200648_change_default_column_orders.rb
new file mode 100644
index 0000000000..ee60925a10
--- /dev/null
+++ b/db/migrate/20180423200648_change_default_column_orders.rb
@@ -0,0 +1,5 @@
+class ChangeDefaultColumnOrders < ActiveRecord::Migration[5.1]
+ def change
+ change_column_default :orders, :status, "pending"
+ end
+end
diff --git a/db/migrate/20180423221528_change_products_categories.rb b/db/migrate/20180423221528_change_products_categories.rb
new file mode 100644
index 0000000000..d7ac93465a
--- /dev/null
+++ b/db/migrate/20180423221528_change_products_categories.rb
@@ -0,0 +1,5 @@
+class ChangeProductsCategories < ActiveRecord::Migration[5.1]
+ def change
+ rename_table :products_categories, :categories_products
+ end
+end
diff --git a/db/migrate/20180423221943_change_order_items.rb b/db/migrate/20180423221943_change_order_items.rb
new file mode 100644
index 0000000000..2c535d08ae
--- /dev/null
+++ b/db/migrate/20180423221943_change_order_items.rb
@@ -0,0 +1,5 @@
+class ChangeOrderItems < ActiveRecord::Migration[5.1]
+ def change
+ rename_table :order_items, :items_order
+ end
+end
diff --git a/db/migrate/20180423223729_change_name_back_to_order_items.rb b/db/migrate/20180423223729_change_name_back_to_order_items.rb
new file mode 100644
index 0000000000..d8b8585b69
--- /dev/null
+++ b/db/migrate/20180423223729_change_name_back_to_order_items.rb
@@ -0,0 +1,5 @@
+class ChangeNameBackToOrderItems < ActiveRecord::Migration[5.1]
+ def change
+ rename_table :items_order, :order_items
+ end
+end
diff --git a/db/migrate/20180424180040_add_columns_to_orders.rb b/db/migrate/20180424180040_add_columns_to_orders.rb
new file mode 100644
index 0000000000..6928635870
--- /dev/null
+++ b/db/migrate/20180424180040_add_columns_to_orders.rb
@@ -0,0 +1,11 @@
+class AddColumnsToOrders < ActiveRecord::Migration[5.1]
+ def change
+ add_column :orders, :email, :string
+ add_column :orders, :mail_adr, :string
+ add_column :orders, :cc_name, :string
+ add_column :orders, :cc_num, :string
+ add_column :orders, :cc_exp, :string
+ add_column :orders, :cc_cvv, :string
+ add_column :orders, :bill_zip, :string
+ end
+end
diff --git a/db/order_seeds.csv b/db/order_seeds.csv
new file mode 100644
index 0000000000..2ab8a14894
--- /dev/null
+++ b/db/order_seeds.csv
@@ -0,0 +1,6 @@
+email,mail_adr,cc_name,cc_num,cc_exp,cc_cvv,bill_zip
+NinaHsr@gmail.org,405 N Smart St Seattle WA,Nina Hintz Sr.,4567-7654-3456-9876,09/20,253,98373
+KaiaKlocko@hotmail.org,Apt 3 6th Ave Kent WA,Kaia Klocko,1234-5678-9101-1121,11/24,678,98378
+MarcHoeger@gmail.org,253 North Shore Beach Seattle WA,Marcellus Hoeger,9876-4453-1123-3214,04/21,456,98075
+ErvinW76@msn.org,567432 College Way Mount Vernon WA,Ervin Wiza,1203-4521-4765-9876,02/28,123,98273
+eeheller@ada.org,Apt 5B 14th St Seattle WA,Elmore Heller MD,5643-2231-4321-6754,12/22,543,98075
diff --git a/db/product_seeds.csv b/db/product_seeds.csv
new file mode 100644
index 0000000000..f268684b6c
--- /dev/null
+++ b/db/product_seeds.csv
@@ -0,0 +1,46 @@
+name,stock,price,description,pet_type,photo_url,user_id
+The Indestructible Petsy KONG,14,2000,Our most popular toy for dogs of all sizes.,dog,KONG.jpg,1
+The Chewsen One,12,300,The most powerful chew toy ever.,dog,Chewsen.jpg,1
+Plush Vader,2,500,The cuteness of this toy will really choke you up.,dog,Plush-Vader.jpg,4
+Tug Rope,10,1000,Get some arm muscles while playing tug of war with your BFF.,dog,Tug-Rope.jpg,5
+Pickles In A Jar,6,1400,Set of 4 funny pickle plush toys.,dog,Pickles.jpg,2
+C-3PO & R2-D2 Mice,9,300,Pack of 2 full of surprises your cat will love.,cat,Mices.jpg
+Petsy Cat Teaser,15,300,This toy is the cat's meow.,cat,Teaser.jpg,3
+Crinkly Cat Tunnel,4,1500,Your pet will play with this like it is an endless tunnel.,cat,Tunnel.jpg,5
+Laser Toy,11,250,This toy is on point.,cat,Laser.jpg,6
+The Mega Terrarium,3,50000,High glass terrarium with lots of room for your reptile friend.,reptile,Terrarium.jpg,5
+Petsy Halogen Reptile Dome Heat Lamp,7,1500,Bulb not included a radiant heat source for your pet reptile.,reptile,Heat-Lamp.jpg,3
+Coconut Husk Brick Reptile Bedding,12,500,It does not smell like coconut but good for the environment.,reptile,Rep-Bedding.jpg,2
+Reptile Hideaway,3,700,Spacious log made out of full cork for your reptile friend to hide in.,reptile,Hideaway.jpg,1
+Jungle Plant,5,300,We recommend getting 2 to create the full jungle feel.,reptile,Jungle-Plant.jpg,4
+Skull Hideaway,2,1300,Our most popular hideaway for reptiles.,reptile,Skull-Hideaway.jpg,3
+Petsy Clips for Reptiles,5,500,Reptiles have nails too that need to be regularly trimmed.,reptile,Rep-Clip.jpg,1
+Reptile Leash,4,800,Take your pet reptile out for a walk when the weather is nice outside.,reptile,Rep-Leash.jpg,5
+Petsy Clips for Pets,10,1000,Soft grip to help cut nails easily.,cat,Nail-Clipper.jpg,2
+Petsy Scented Litter,4,900,35lbs litter you won't even notice the litter box.,cat,Cat-Litter.jpg,2
+Cat Leash,3,1300,We are not kitten you right meow,cat,Cat-Harness.jpg,3
+Cat Bow Tie,11,1100,For the hipster cat.,cat,Cat-Bow-Tie.jpg,4
+Fishbone Bow Tie,2,200,So good looking your cat might eat it.,cat,Fishbone-Bow-Tie.jpg,4
+Dog Leash,5,3500,Easy to use on puppies and dogs of all sizes.,dog,Dog-Leash.jpg,5
+Petsy Harness for dogs,10,2000,Gentle and easy to use on dogs of all sizes.,dog,Dog-Harness.jpg,6
+Camo Skull Bandana Dog Collar,1,1000,Dog not included.,dog,Bandana.jpg,4
+Cat Brush,7,2500,Eliminates cat fur.,cat,Cat-Brush.jpg,2
+Cat Shampoo,9,1200,Fragrance Free Oatmeal & Aloe Totally Natural Pet Shampoo.,cat,Cat-Shampoo.jpg,1
+Cat Dry Shampoo,3,700,Dander Reducing Waterless Shampoo for Cats.,cat,Cat-Dry-Shampoo.jpg,5
+Dog Brush,9,3000,Eliminates dog hair.,dog,Dog-Brush.jpg,1
+Dog Shampoo,20,550,Nourishing Avocado & Olive Oil Dog Shampoo.,dog,Dog-Shampoo.jpg,3
+Petsy Pads,30,1500,Gigantic Puppy Housebreaking Pads.,dog,Pads.jpg,5
+Doggie Bag Dispenser,14,600,Refillable Bag Dispenser.,dog,Bag-Dispenser.jpg,6
+Doggie Bags,10,599,100% Compostable Dog Waste Bags.,dog,Dog-Waste-Bags.jpg,6
+Petsy Luxurious Dog Bed,1,20000,Only the best for your BFF sharing is of optional.,dog,Dog-Bed.jpg,1
+Petsy Teepee,1,8000,Perfect for the pet
+ who loves to stargaze.,dog,Teepee.jpg,1
+Petsy Luxurious Cat Purch,1,10000,Only the best for your BFF.,cat,Cat-Bed.jpg,4
+Petsy Cat Tree Playground,1,15000,Can fit up to 6 cats.,cat,Cattree.jpg,4
+Reptile Food,15,320,Gourmet Style Mealworms Reptile Food.,reptile,Rep-Food.jpg,4
+Vegetable Reptile Munchies,8,850,For a healthy pet reptile.,reptile,Rep-Veg-Food.jpg,5
+Cat Wet Food Pouch,9,1130,Case of 12 Tuna Ocean Whitefish & Pumpkin Wet Cat Food Pouch.,cat,Cat-Wet-Food.jpg,4
+Cat Wet Food Can,8,1200,Case of 8 Grill Mackerel Sardine Calamari Wet Cat Food.,cat,Cat-Can-Food.jpg,1
+Cat Dry Food,12,3000,Dry Cat Food.,cat,Cat-Dry-Food.jpg,1
+Dog Wet Food Can,13,3500,Case of 12 Chicken & Mackerel Poke.,dog,Dog-Dry-Food.jpg,4
+Dog Dry Food,5,3000,Dry Dog Food.,dog,Dog-Wet-Food.jpg,2
diff --git a/db/review_seeds.csv b/db/review_seeds.csv
new file mode 100644
index 0000000000..3f27a7a2b2
--- /dev/null
+++ b/db/review_seeds.csv
@@ -0,0 +1,5 @@
+rating, comments, product_id
+4,delectable,1
+5,incredible flexibility,10
+1,garbage,3
+2,This changed my pets life,24
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000000..731de955c5
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,94 @@
+# 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: 20180424180040) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "categories", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "categories_products", force: :cascade do |t|
+ t.bigint "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 "order_items", force: :cascade do |t|
+ t.integer "quantity"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "order_id"
+ t.bigint "product_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 "orders", force: :cascade do |t|
+ t.string "status", default: "pending"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "email"
+ t.string "mail_adr"
+ t.string "cc_name"
+ t.string "cc_num"
+ t.string "cc_exp"
+ t.string "cc_cvv"
+ t.string "bill_zip"
+ end
+
+ create_table "products", force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "name"
+ t.integer "stock"
+ t.integer "price"
+ t.string "description"
+ t.string "pet_type"
+ t.string "photo_url"
+ 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.string "comments"
+ 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 "shopping_carts", 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.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "username"
+ t.string "email"
+ t.integer "uid", null: false
+ t.string "provider", null: false
+ 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..9b4c82b64e
--- /dev/null
+++ b/db/seeds.rb
@@ -0,0 +1,46 @@
+# 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')
+
+# might have to change to .open, and
+CSV.foreach(user_file, headers: true, header_converters: :symbol, converters: :all) do |row|
+ # data is in a Hash, create a product ising the row data?
+ data = Hash[row.headers.zip(row.fields)]
+ puts data
+ User.create!(data)
+ # we never do anything with the new data structure
+end
+
+product_file = Rails.root.join('db', 'product_seeds.csv')
+
+# might have to change to .open, and
+CSV.foreach(product_file, headers: true, header_converters: :symbol, converters: :all) do |row|
+ # data is in a Hash, create a product ising the row data?
+ data = Hash[row.headers.zip(row.fields)]
+ puts data
+ Product.create!(data)
+ # we never do anything with the new data structure
+end
+
+
+category_file = Rails.root.join('db', 'categories.csv')
+
+# might have to change to .open, and
+CSV.foreach(category_file, headers: true, header_converters: :symbol, converters: :all) do |row|
+ # data is in a Hash, create a product ising the row data?
+ data = Hash[row.headers.zip(row.fields)]
+ puts data
+ Category.create!(data)
+ # we never do anything with the new data structure
+end
+
+review_file = Rails.root.join('db', 'review_seeds.csv')
+
+CSV.foreach(review_file, headers: true, header_converters: :symbol, converters: :all) do |row|
+ data = Hash[row.headers.zip(row.fields)]
+ Review.create!(data)
+end
diff --git a/db/user_seeds.csv b/db/user_seeds.csv
new file mode 100644
index 0000000000..fc34c93a68
--- /dev/null
+++ b/db/user_seeds.csv
@@ -0,0 +1,7 @@
+username, email, uid, provider
+rufo, puppy@petsy.com, 123, github
+kitty, kitty@petsy.com, 345, github
+max, max@petsy.com, 567, github
+rhino, rhino@petsy.com, 899, github
+kerry, kerry@petsy.com, 124, github
+sally, sally@petsy.com, 125, github
diff --git a/lib/assets/.keep b/lib/assets/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/lib/tasks/.keep b/lib/tasks/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/log/.keep b/log/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/package.json b/package.json
new file mode 100644
index 0000000000..f874acf437
--- /dev/null
+++ b/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "betsy",
+ "private": true,
+ "dependencies": {}
+}
diff --git a/public/404.html b/public/404.html
new file mode 100644
index 0000000000..2be3af26fc
--- /dev/null
+++ b/public/404.html
@@ -0,0 +1,67 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/422.html b/public/422.html
new file mode 100644
index 0000000000..c08eac0d1d
--- /dev/null
+++ b/public/422.html
@@ -0,0 +1,67 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/500.html b/public/500.html
new file mode 100644
index 0000000000..78a030af22
--- /dev/null
+++ b/public/500.html
@@ -0,0 +1,66 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000000..37b576a4a0
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1 @@
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
new file mode 100644
index 0000000000..d19212abd5
--- /dev/null
+++ b/test/application_system_test_case.rb
@@ -0,0 +1,5 @@
+require "test_helper"
+
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
+end
diff --git a/test/controllers/.keep b/test/controllers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb
new file mode 100644
index 0000000000..bd6c935d4f
--- /dev/null
+++ b/test/controllers/categories_controller_test.rb
@@ -0,0 +1,89 @@
+require "test_helper"
+
+
+describe CategoriesController do
+ let(:user) { users(:one) }
+ describe 'index' do
+ it 'sends a success response when there are many categories' do
+ Category.count.must_be :>, 0
+
+ # Act
+ get categories_path
+
+ # Assert
+ must_respond_with :success
+ end
+
+ end
+
+ describe 'new' do
+ it 'responds with success with a logged user' do
+ # category = Category.first
+ login(user)
+
+ get new_category_path
+
+ must_respond_with :success
+ end
+
+
+ end
+
+ describe "create" do
+ it "lets a logged user to create a category" do
+ category_data = {name: 'new category'}
+ user = User.first
+ old_category_count = Category.count
+
+ Category.new(category_data).must_be :valid?
+ login(user)
+
+ post categories_path, params: {category: category_data}
+
+ must_respond_with :redirect
+ must_redirect_to users_path
+ Category.count.must_equal old_category_count + 1
+ end
+
+ it "can add a valid category" do
+ # Arrange
+ category_data = {
+ name: 'test category name'
+ }
+ old_category_count = Category.count
+
+ # Assumption
+ Category.new(category_data).must_be :valid?
+
+ # Act
+ post categories_path, params: { category: category_data }
+
+ # # Assert
+ # # ***The HTTP response below
+ # must_respond_with :redirect
+ # must_redirect_to categorys_path
+
+ Category.count.must_equal old_category_count + 1
+ Category.last.name.must_equal category_data[:name]
+ end
+
+ it "won't add an invalid category" do
+ # Arrange
+ category_data = {
+ name: nil
+ }
+ old_category_count = Category.count
+
+ # Assumption
+ Category.new(category_data).wont_be :valid?
+
+ # Act
+ post categories_path, params: { category: category_data }
+
+ # Assert
+ # must_respond_with :bad_request
+ Category.count.must_equal old_category_count
+ end
+ end
+
+end
diff --git a/test/controllers/mains_controller_test.rb b/test/controllers/mains_controller_test.rb
new file mode 100644
index 0000000000..e61c5eed75
--- /dev/null
+++ b/test/controllers/mains_controller_test.rb
@@ -0,0 +1,13 @@
+require "test_helper"
+
+describe MainsController do
+ describe "index" do
+ it "sends a success response" do
+
+ get root_path
+
+ must_respond_with :success
+ end
+ 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..a4b496f4cf
--- /dev/null
+++ b/test/controllers/order_items_controller_test.rb
@@ -0,0 +1,81 @@
+require "test_helper"
+
+describe OrderItemsController do
+ describe "index" do
+ it "sends a success response when there are many order items" do
+ get order_items_path
+
+ must_respond_with :success
+ end
+
+ it "sends a success response when there are no orders" do
+ OrderItem.destroy_all
+ get order_items_path
+ must_respond_with :success
+ end
+ end
+ describe "show" do
+ it "should get show" do
+ get order_item_path(OrderItem.first.id)
+
+ must_respond_with :success
+ end
+
+ end
+
+ describe "create" do
+
+ it "sends success if the order exists" do
+ order = Order.first
+ orderitem_data = { product_id: Product.first.id, quantity: Product.first.stock, order_id: order.id }
+
+ post order_items_path, params: {order_item: orderitem_data}
+
+ get order_item_path(order)
+ must_respond_with :success
+ end
+ it "sends not_found if the order does not exist" do
+ order_id = Order.last.id + 1
+ get order_item_path(order_id)
+ must_respond_with :bad_request
+ must_redirect_to root_path
+ end
+
+ end
+
+ describe "update" do
+ it 'updates the quantity of a same product added to the cart' do
+
+ updated_quantity = 3
+
+ patch order_item_path(OrderItem.first.id),
+ params: {
+ order_item: {
+ quantity: updated_quantity,
+ }
+ }
+
+ updated_op = OrderItem.find(OrderItem.first.id)
+ updated_op.quantity.must_equal updated_quantity
+
+ end
+ end
+
+ describe "destroy" do
+ it "deletes a order item" do
+ delete order_item_path(OrderItem.first.id)
+
+ must_respond_with :redirect
+ end
+
+ it "reduces order item count" do
+ initial = OrderItem.count
+
+ delete order_item_path(OrderItem.first.id)
+
+ OrderItem.count.must_equal initial - 1
+
+ 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..3ab6ea4c98
--- /dev/null
+++ b/test/controllers/orders_controller_test.rb
@@ -0,0 +1,77 @@
+require "test_helper"
+
+describe OrdersController do
+ before do
+ @orders = Order.all
+ end
+ describe "index" do
+
+ it "sends a success response when there are many orders" do
+ @orders.count.must_be :>, 0
+ get orders_path
+ must_respond_with :success
+ end
+
+ it "sends a success response when there are no orders" do
+ Order.destroy_all
+ @orders.count.must_equal 0
+ get orders_path
+ must_respond_with :success
+ end
+
+ end
+
+ describe "update" do
+
+ it "takes customer information and changes status to paid" do
+ product = Product.first
+
+ order_item = {product_id: product.id, quantity: product.stock}
+ post order_items_path, params: {order_item: order_item}
+
+ order_id = Order.last.id
+
+ order_data = {
+ cc_name: "Sarah Parker",
+ email: "jackson@petsy.com",
+ cc_num: "12345678901234567",
+ cc_cvv: "980",
+ cc_exp: "01/22",
+ mail_adr: "2615 233rd Ave SE, Sammamish",
+ bill_zip: "98075",
+ status: "pending"
+ }
+ patch order_path(order_id), params: {order: order_data}
+
+ must_redirect_to order_path
+
+
+ Order.last.status.must_equal "paid"
+ end
+
+ it "does not procees the order if the customer data is incomplete" do
+ orderitem = {product_id: Product.first.id, quantity: Product.first.stock}
+ post order_items_path, params: {order_item: orderitem}
+
+ order_data = {
+ email: "jackson@petsy.com",
+ cc_num: "12345678901234567",
+ cc_cvv: "980",
+ cc_exp: "01/22",
+ mail_adr: "2615 233rd Ave SE, Sammamish",
+ bill_zip: "98075",
+ status: "pending"
+ }
+ patch order_path(session[:order_id]), params: {order: order_data}
+
+ must_respond_with :found
+
+ Order.last.status.must_equal "pending"
+
+ session[:order_id].must_equal OrderItem.last.order_id
+ 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..5ca1b3faf8
--- /dev/null
+++ b/test/controllers/products_controller_test.rb
@@ -0,0 +1,118 @@
+require "test_helper"
+
+describe ProductsController do
+ describe "index" do
+ it "succeeds when there are products" do
+ # Arrange
+ Product.count.must_be :>, 0
+ # Act
+ get products_path
+ # Assert
+ must_respond_with :success
+
+ end
+
+ it "succeeds when there are no products" do
+ # Arrange
+ Product.destroy_all
+ Product.all.length.must_equal 0
+ # Act
+ get products_path
+ # Assert
+ must_respond_with :success
+ end
+
+ end
+
+ describe "new" do
+ it "does not succeed when guest user" do
+ # Arrange & Act
+ get new_product_path
+ # Assert
+ must_redirect_to users_path
+ end
+
+ it "succeeds when login user" do
+ # Arrange & Act
+ existing_user = users(:one)
+ login(existing_user)
+ get new_product_path
+ # Assert
+ must_respond_with :success
+ end
+ end
+
+ describe "create" do
+ it 'can add a valid product' do
+ # Arrange
+ existing_user = users(:one)
+ login(existing_user)
+ product_data = {
+ name: 'TestToy',
+ stock: 5,
+ price: 500,
+ description: "A dogs dream",
+ pet_type: "dog",
+ photo_url: "Pickles.jpg",
+ user_id: existing_user.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 'cannot add a product with bogus data' do
+ # Arrange
+ existing_user = users(:two)
+ login(existing_user)
+ product_data = {
+ stock: 5,
+ price: 500,
+ description: "A dogs dream",
+ pet_type: "dog",
+ photo_url: "Pickles.jpg",
+ user_id: existing_user.id,
+ }
+ old_product_count = Product.count
+
+ # Act
+ post products_path, params: { product: product_data }
+
+ # Assert
+ must_respond_with :bad_request
+
+ Product.count.must_equal old_product_count
+ # Product.last.name.must_equal product_data[:name]
+ end
+
+
+ end
+
+ describe "show" do
+ it 'sends success if the product exists' do
+ get product_path(Product.first)
+ must_respond_with :success
+ end
+
+ it "sends not_found if the product doesn't exist" do
+ product_id = Product.last.id + 1
+
+ get product_path(product_id)
+
+ 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..242771ca89
--- /dev/null
+++ b/test/controllers/reviews_controller_test.rb
@@ -0,0 +1,54 @@
+require "test_helper"
+
+describe ReviewsController do
+ describe 'new' do
+ it 'responds with success with a logged out user' do
+ product = Product.first
+ get new_product_review_path(product)
+
+ must_respond_with :success
+ end
+
+ it "renders 404 not_found " do
+ get new_product_review_path(-1)
+ must_respond_with :not_found
+ end
+
+ it "won't let the product's owner to review product" do
+ product_id = Product.first.id
+ login(users(:one))
+ get new_product_review_path(products(:product1))
+ must_respond_with :redirect
+
+ post product_reviews_path(products(:product1)), params: {rating: 5, comments: "la la la", product_id: product_id}
+ must_respond_with :redirect
+ end
+ end
+
+ describe "create" do
+
+ it "it won't create a review with bogus data" do
+ product = Product.create(name:"cat rug",price: 10, user: users(:one), stock: 15)
+ start = product.reviews.count
+ post product_reviews_path(product.id), params: {review:{rating: 15, comments: "beautiful"}}
+ product.reviews.count.must_equal start
+ must_respond_with :bad_request
+ end
+
+ it "creates a review with valid data" do
+ product_id = Product.first.id
+ review_data = { rating: 5, comments: 'comments', product_id: product_id }
+
+ old_review_count = Review.count
+
+ Review.new(review_data).must_be :valid?
+ post product_reviews_path(product_id), params: { review: review_data}
+
+ must_respond_with :redirect
+ must_redirect_to product_path(product_id)
+ Review.count.must_equal old_review_count + 1
+ Review.last.comments.must_equal 'comments'
+ 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..aab84e4fe2
--- /dev/null
+++ b/test/controllers/sessions_controller_test.rb
@@ -0,0 +1,72 @@
+require "test_helper"
+
+describe SessionsController do
+ describe 'auth_callback' do
+ it "should create a new user and redirect to root page" do
+ user = User.new(provider: 'github', uid: 76621, email: 'mail4@me.org', username: 'Lemuel Larsky')
+
+ user.must_be :valid?
+ original_count = User.count
+ user.save
+ # act
+ login(user)
+
+ # assert
+
+ must_redirect_to root_path
+ User.count.must_equal original_count + 1
+ session[:user_id].must_equal User.last.id
+
+ end
+
+
+ it "logs in existing user and redirect to root page" do
+ # arrange
+ user = User.first
+ original_count = User.count
+
+ # act
+ login(user)
+
+ # assert
+
+ must_redirect_to root_path
+ User.count.must_equal original_count
+ session[:user_id].must_equal user.id
+
+ end
+
+ it "does not log in with invalid data" do
+ user = User.new(provider: 'github', uid: nil , email: 'mail@me.org', username: 'Milkah Lamb')
+
+ user.wont_be :valid?
+
+ original_count = User.count
+
+ # act
+ login(user)
+
+ # assert
+
+ must_redirect_to root_path
+ User.count.must_equal original_count
+
+
+ end
+
+ describe 'logout' do
+ it "can logout" do
+ # Arrange
+ login(User.first)
+
+ # Act
+ delete logout_path
+
+ assert_nil 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..53f45f2c93
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,59 @@
+require "test_helper"
+
+describe UsersController do
+
+ describe 'index' do
+ it 'succeeds when there are users' do
+ User.count.must_be :>,0
+ get users_path
+ must_respond_with :success
+ end
+ end
+
+ describe 'show' do
+ it 'succeeds for an extant user ID' do
+ user_id = User.first.id
+
+ get user_path(user_id)
+
+ must_respond_with :success
+ end
+
+ it 'renders 404 not_found for a bogus user ID' do
+ user_id = User.last.id + 1
+
+ get user_path(user_id)
+
+ must_respond_with :not_found
+ end
+ end
+
+ describe "new" do
+ it "succeeds" do
+ get new_user_path
+
+ must_respond_with :success
+ end
+ end
+
+
+ describe "edit" do
+ it "should get edit for valid id" do
+ user_id = User.first.id
+ get edit_user_path(user_id)
+
+ must_respond_with :success
+
+ end
+
+ it "renders 404 and does not update DB for bad ID" do
+ user_id = User.last.id + 1
+
+ get edit_user_path(user_id)
+
+ must_respond_with :not_found
+
+ end
+ end
+
+end
diff --git a/test/fixtures/.keep b/test/fixtures/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml
new file mode 100644
index 0000000000..a7b3d721c8
--- /dev/null
+++ b/test/fixtures/categories.yml
@@ -0,0 +1,10 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+decor:
+ name: decor
+
+food:
+ name: food
+
+accessory:
+ name: accessory
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..59254433c3
--- /dev/null
+++ b/test/fixtures/order_items.yml
@@ -0,0 +1,18 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+orderitem1:
+ order: order1
+ product: product1
+ quantity: 10
+
+
+orderitem2:
+ order: order2
+ product: product2
+ quantity: 5
+
+
+orderitem3:
+ order: order3
+ product: product3
+ quantity: 3
diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml
new file mode 100644
index 0000000000..628a8c0a17
--- /dev/null
+++ b/test/fixtures/orders.yml
@@ -0,0 +1,21 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+order1:
+ status: pending
+ email: email1
+ mail_adr: mail_adr1
+ cc_name: cc_name1
+ cc_num: 123456789123456
+ cc_exp: 11/22
+ cc_cvv: 123
+ bill_zip: 98075
+
+order2:
+ status: pending
+ email: email1
+ mail_adr: mail_adr1
+ cc_name: cc_name1
+ cc_num: 123456789123456
+ cc_exp: 11/22
+ cc_cvv: 123
+ bill_zip: 98075
diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml
new file mode 100644
index 0000000000..093648dd58
--- /dev/null
+++ b/test/fixtures/products.yml
@@ -0,0 +1,34 @@
+# 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
+#
+product1:
+ name: tank
+ stock: 7
+ price: 2100
+ description: A bullet proof tank for the most wanted of reptiles
+ pet_type: reptile
+ photo_url: Pickles.jpg
+ user: one
+
+
+product2:
+ name: collar
+ stock: 25
+ price: 1000
+ description: A stylish collar for your most tamed canines
+ pet_type: dog
+ photo_url: Pickles.jpg
+ user: one
+
+
+product3:
+ name: Dog Scarf
+ stock: 15
+ price: 1000
+ description: A fabulous scarf for your fabulous pooch
+ pet_type: dog
+ photo_url: Pickles.jpg
+ user: two
diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml
new file mode 100644
index 0000000000..b05a92f064
--- /dev/null
+++ b/test/fixtures/reviews.yml
@@ -0,0 +1,16 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ rating: 4
+ comments: Great product
+ product: product2
+
+two:
+ rating: 3
+ comments: Love this so much
+ product: product1
+
+three:
+ rating: 4
+ comments:
+ product: product1
diff --git a/test/fixtures/shopping_carts.yml b/test/fixtures/shopping_carts.yml
new file mode 100644
index 0000000000..dc3ee79b5d
--- /dev/null
+++ b/test/fixtures/shopping_carts.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..edde366c54
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,29 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the "{}" from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one:
+ username: puppy
+ email: puppy@petsy.com
+ uid: 1
+ provider: github
+
+two:
+ username: lizard
+ email: lizard@petsy.com
+ uid: 2
+ provider: github
+
+three:
+ username: cat
+ email: neko@petsy.com
+ uid: 3
+ provider: github
+
+four:
+ username: Milkah Lamb
+ email: mail@me.org
+ uid: 77621
+ 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/category_test.rb b/test/models/category_test.rb
new file mode 100644
index 0000000000..c4ee452022
--- /dev/null
+++ b/test/models/category_test.rb
@@ -0,0 +1,50 @@
+require "test_helper"
+
+describe Category do
+ describe "relations" do
+ it "connects product and product_id" do
+ product = Product.first
+ category = Category.first
+
+ product.categories << category
+
+ product.category_ids.must_include category.id
+ end
+ end
+
+ describe "validations" do
+ it "must be valid with all required fields" do
+ category = Category.new(name: "test category")
+ category.save
+ category.valid?.must_equal true
+ end
+
+ it "requires a name" do
+ category = Category.new(name: nil)
+ category.save
+ category.valid?.must_equal false
+ category.errors.messages.must_include :name
+ end
+
+ it "allows products to have multiple categoriess" do
+ category1 = categories(:decor)
+ category2 = categories(:food)
+ category1.valid?.must_equal true
+ category1.valid?.must_equal true
+ end
+
+ it "must have a unique name" do
+ category_name = "test category"
+ new_category = Category.new(name: category_name)
+
+ new_category.save!
+
+ new_category2 = Category.new(name: category_name)
+ result = new_category2.save
+ result.must_equal false
+ new_category2.errors.messages.must_include :name
+ 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..76b734b18f
--- /dev/null
+++ b/test/models/order_item_test.rb
@@ -0,0 +1,56 @@
+require "test_helper"
+
+describe OrderItem do
+ let(:order_item) { OrderItem.new(order: orders(:order1), product: products(:product1), quantity: 7) }
+
+ describe "relations" do
+ it "has an associated product" do
+ orderitem = order_items(:orderitem1)
+ orderitem.product.must_equal products(:product1)
+ orderitem.product_id = products(:product2).id
+ orderitem.product.must_equal products(:product2)
+ end
+
+ it "has associated order" do
+ orderitem = order_items(:orderitem1)
+ orderitem.order.must_equal orders(:order1)
+ orderitem.order_id = orders(:order2).id
+ orderitem.order.must_equal orders(:order2)
+ end
+ end
+
+ describe "validations" do
+
+ it "must have a positive integer quantity" do
+ [-3, 0].each do |num|
+ order_item.quantity = num
+ order_item.valid?.must_equal false
+ end
+ (1..5).each do |num|
+ order_item.quantity = num
+ order_item.valid?.must_equal true
+ end
+ end
+ it "must be in stock" do
+ order_item.quantity = 100
+ order_item.valid?.must_equal false
+ end
+ it "can't make an order product from out of stock product" do
+ product = products(:product1)
+ product.stock = 0
+ product.save
+ orderitem = OrderItem.new(order: orders(:order1), product: products(:product1), quantity: 7)
+ orderitem.valid?.must_equal false
+ end
+ end
+
+ describe "custom methods" do
+ it "returns the subtotal of an orderitem" do
+ orderitem = OrderItem.new(order: orders(:order1), product: products(:product1), quantity: 7)
+ result_sub_total = 14700
+ orderitem.sub_total.must_equal result_sub_total
+ end
+ end
+
+
+end
diff --git a/test/models/order_test.rb b/test/models/order_test.rb
new file mode 100644
index 0000000000..d0d4ebd2ad
--- /dev/null
+++ b/test/models/order_test.rb
@@ -0,0 +1,151 @@
+require "test_helper"
+
+describe Order do
+ let(:order) { Order.new }
+ let(:order1) { orders(:order1) }
+
+ describe "relations" do
+
+ it "has a list of order_items" do
+ order1.order_items.each do |item|
+ item.must_be_instance_of OrderItem
+ item.order.must_be_instance_of Order
+ item.order.must_equal order1
+ end
+ end
+ end
+
+ describe "validations" do
+ before do
+ @order = Order.new(email: "rufo@petsy.com", mail_adr: "2615 233rd SE, Sammamish, WA",cc_name: "Rufino Woof", cc_num: "9875632147652345", cc_exp: "09/22", cc_cvv: "987",bill_zip: "98075", status: "paid")
+ end
+
+
+ it "must have a mailing address" do
+ @order.mail_adr = nil
+ @order.valid?.must_equal false
+ end
+
+ it "must have a name in the credit card information" do
+ @order.cc_name = nil
+ @order.valid?.must_equal false
+ @order.cc_name = "Rufino Woof"
+ @order.valid?.must_equal true
+ end
+
+ it "must have an email address" do
+ @order.email.must_equal "rufo@petsy.com"
+ @order.valid?.must_equal true
+ @order.email = nil
+ @order.valid?.must_equal false
+ end
+
+ it "must have a billing zip code number" do
+ @order.bill_zip.must_equal "98075"
+ @order.valid?.must_equal true
+
+ [nil,"","wooof"].each do |num|
+ @order.bill_zip = num
+ @order.valid?.must_equal false
+ end
+ end
+
+
+ it "must have a credit card number of 16 digits" do
+ @order.cc_num.must_equal "9875632147652345"
+ @order.valid?.must_equal true
+
+ [nil,"45638","raaaa",""].each do |num|
+ @order.cc_num = num
+ @order.valid?.must_equal false
+ end
+ end
+
+ it "must have an expiration date" do
+ @order.cc_exp.must_equal "09/22"
+ @order.valid?.must_equal true
+
+ @order.cc_exp = nil
+ @order.valid?.must_equal false
+ end
+
+ it "must include a CVV number of 3 digits" do
+ [nil,"18294673","fuw"].each do |num|
+ @order.cc_cvv = num
+ @order.valid?.must_equal false
+ end
+
+ ["345","182","666"].each do |num|
+ @order.cc_cvv = num
+ @order.valid?.must_equal true
+ end
+ end
+
+
+ end
+ describe "custom methods" do
+ describe "total_sum" do
+ before do
+ @order = Order.new
+ @order.order_items << OrderItem.first
+ @order.valid?.must_equal true
+ @order.save
+ end
+ it "returns the total of an order of only one order item " do
+ order.save
+
+ OrderItem.create(quantity: 1, product_id: products(:product1).id, order_id: order.id)
+
+ order.total_sum.must_be_kind_of Integer
+ order.total_sum.must_equal (products(:product1).price)
+ order.total_sum.must_equal 2100
+
+ end
+
+ it "returns the total of an order of multiple order items " do
+ order.save
+
+ OrderItem.create(quantity: 1, product_id: products(:product1).id, order_id: order.id)
+ OrderItem.create(quantity: 1, product_id: products(:product2).id, order_id: order.id)
+ OrderItem.create(quantity: 1, product_id: products(:product3).id, order_id: order.id)
+
+ order.total_sum.must_be_kind_of Integer
+ order.total_sum.must_equal (products(:product1).price + products(:product2).price + products(:product3).price)
+ order.total_sum.must_equal 4100
+ end
+
+ it "returns the total of an order of multiple order items " do
+ order.save
+
+ OrderItem.create(quantity: 0, product_id: products(:product1).id, order_id: order.id)
+
+ order.total_sum.must_be_kind_of Integer
+ order.total_sum.must_equal 0
+
+ end
+
+ end
+
+ describe "reduce_inventory" do
+ it "reduces the inventory of the items purchased" do
+ order = Order.new
+ order.save
+ order_item = order_items(:orderitem1)
+ order_item.quantity.must_equal 10
+ order_item.save
+ order.order_items << order_item
+
+
+ product = order_item.product
+ product.stock = products(:product2).stock
+ product.stock.must_equal 25
+ order.reduce_inventory
+
+ order.reload
+ product.reload
+
+ product.stock.must_equal 15
+ end
+ end
+ end
+end
diff --git a/test/models/product_test.rb b/test/models/product_test.rb
new file mode 100644
index 0000000000..7686cb7eff
--- /dev/null
+++ b/test/models/product_test.rb
@@ -0,0 +1,145 @@
+require "test_helper"
+
+describe Product do
+ let(:product) { Product.new }
+ let(:product1) {products(:product1)}
+ let(:product2) {users(:product2)}
+
+ describe 'relations' do
+ it "must belong to a user" do
+ product = products(:product1)
+ product.must_respond_to :user
+ product.must_be_kind_of Product
+ product.user.must_be_kind_of User
+ end
+
+ it "must belong to a category" do
+ product = products(:product1)
+ product.must_respond_to :categories
+
+ end
+
+ it "has a list of categories" do
+ product1.categories.each do |category|
+ category.must_be_instance_of Category
+ category.products.must_be_instance_of Array
+ category.products.must_include product1
+ end
+ end
+
+ it "belongs to many categories" do
+ Product.first.categories << categories(:decor)
+ Product.first.categories << categories(:food)
+ Product.last.categories << categories(:decor)
+ Product.first.categories.must_equal [categories(:decor),categories(:food)]
+ Product.last.categories.must_equal [categories(:decor)]
+ end
+
+ it "has reviews" do
+ product = products(:product1)
+ product.must_respond_to :reviews
+ end
+
+ it "has a list of orderitems " do
+ product1.order_items.each do |order_item|
+ order_item.must_be_instance_of OrderItem
+ order_item.product.must_be_instance_of Product
+ order_item.product.must_equal product1
+ end
+ end
+
+ end
+ describe 'validations' do
+ it "must have a name to be valid" do
+ product1.valid?.must_equal true
+ product1.name = ""
+ product1.valid?.must_equal false
+ product1.errors.messages.must_include :name
+ end
+
+ it "must have a unique name" do
+ product_name = "test productname"
+ new_product = Product.new(name: product_name, price: 50, stock: 10)
+
+ new_product.save!
+
+ new_product2 = Product.new(name: product_name, price: 30, stock: 5)
+ result = new_product2.save
+ result.must_equal false
+ new_product2.errors.messages.must_include :name
+ end
+
+ it "must have a price to be valid" do
+ product1.valid?.must_equal true
+ product1.price = ""
+ product1.valid?.must_equal false
+ end
+
+ it "must have a price greater than 0" do
+ product1.valid?.must_equal true
+ product1.price = 0
+ product1.valid?.must_equal false
+ product1.price = -5
+ product1.valid?.must_equal false
+ end
+
+ it "must have a stock to be valid" do
+ product1.valid?.must_equal true
+ product1.stock = ""
+ product1.valid?.must_equal false
+ end
+
+ it "must have an integer as stock" do
+ product1.valid?.must_equal true
+ product1.stock = 0.4
+ product1.valid?.must_equal false
+ end
+
+ it "must have as stock a number greater than or equal to 0" do
+ product1.valid?.must_equal true
+ product1.stock = 0
+ product1.valid?.must_equal true
+ end
+
+ it "cannot have a negative number as stock" do
+ product1.valid?.must_equal true
+ product1.stock = -10
+ product1.valid?.must_equal false
+ end
+
+ end
+
+ describe 'custom methods' do
+
+ it "returns correct average rating" do
+ product = products(:product1)
+ product.show_rating.must_equal 3
+
+ product = products(:product2)
+ product.show_rating.must_equal 4
+ end
+
+ it "returns no reviews when the product does not have reviews" do
+ product.show_rating.must_equal "No reviews"
+ end
+
+
+ it "returns a collection of products" do
+
+ Product.by_pet_type.must_be_kind_of Hash
+ end
+
+
+ it 'reduces the stock of the product' do
+ product = Product.first
+ product.stock = 10
+ product.save
+
+ product.stock_reduction(3)
+ product.reload
+
+ product.stock.must_equal 7
+ end
+ end
+
+end
diff --git a/test/models/review_test.rb b/test/models/review_test.rb
new file mode 100644
index 0000000000..4c682168b7
--- /dev/null
+++ b/test/models/review_test.rb
@@ -0,0 +1,59 @@
+require "test_helper"
+
+describe Review do
+ describe "relations" do
+ it "has a product" do
+ r = reviews(:one)
+ r.must_respond_to :product
+ r.product.must_be_kind_of Product
+ end
+ end
+
+ describe "validations" do
+ it "must be valid with all required fields" do
+ review = Review.last
+ review.valid?.must_equal true
+ end
+
+ it "allows users to review for multiple products" do
+ review1 = reviews(:one)
+ review2 = reviews(:two)
+ review1.valid?.must_equal true
+ review2.valid?.must_equal true
+ end
+
+ it "requires a rating" do
+ review = Review.new(comments: "great product")
+ review.save
+ review.valid?.must_equal false
+ review.errors.messages.must_include :rating
+ end
+
+ it "requires a rating to be integer" do
+ review = Review.new(rating: "what")
+ review.save
+ review.valid?.must_equal false
+ review.errors.messages.must_include :rating
+ end
+
+ it "requires a rating between 1 and 5" do
+ review = Review.new(rating: 0)
+ review.save
+ review.valid?.must_equal false
+ end
+
+ it "rating cannot be greater than 5" do
+ review = Review.new(rating: 7)
+ review.save
+ review.valid?.must_equal false
+ review.errors.messages.must_include :rating
+ end
+
+ it "rating cannot be less than 0" do
+ review = Review.new(rating: -3)
+ review.save
+ review.valid?.must_equal false
+ review.errors.messages.must_include :rating
+ end
+ end
+end
diff --git a/test/models/shopping_cart_test.rb b/test/models/shopping_cart_test.rb
new file mode 100644
index 0000000000..125ee42256
--- /dev/null
+++ b/test/models/shopping_cart_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+describe ShoppingCart do
+ let(:shopping_cart) { ShoppingCart.new }
+
+ it "must be valid" do
+ value(shopping_cart).must_be :valid?
+ end
+end
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 0000000000..4d79d06ce7
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,84 @@
+require "test_helper"
+
+describe User do
+ let(:user) { User.new }
+ let(:one) { users(:one) }
+
+ describe "relations" do
+ it "has a list of products" do
+ dan = users(:one)
+ dan.must_respond_to :products
+ dan.products.each do |product|
+ product.must_be_kind_of Product
+ end
+ dan.products.count.must_equal 2
+ end
+
+ it "returns an empty array if user does not have products" do
+ dan = users(:three)
+ dan.must_respond_to :products
+ dan.products.each do |product|
+ product.must_be_kind_of Product
+ end
+ dan.products.must_equal []
+ end
+ end
+
+ describe "validations" do
+ it "must be valid" do
+ one.must_be :valid?
+ end
+
+ it "must have a username" do
+ user.email = "email"
+ user.username = " "
+ user.valid?.must_equal false
+ user.errors.messages.must_include :username
+
+ user.username = "test username"
+ user.valid?.must_equal true
+ end
+
+ it "username must be unique" do
+ one.username.must_equal "puppy"
+ user.email = "email2"
+ user.username = "puppy"
+ user.valid?.must_equal false
+ user.errors.messages.must_include :username
+ end
+
+ it "must have an email" do
+ user.username = "username"
+ user.email = " "
+ user.valid?.must_equal false
+ user.errors.messages.must_include :email
+
+ user.email = "email3"
+ user.valid?.must_equal true
+ end
+
+ it "email must be unique" do
+ one.email.must_equal "puppy@petsy.com"
+ user.username = "name2"
+ user.username = "puppy@petsy.com"
+ user.valid?.must_equal false
+ user.errors.messages.must_include :email
+ end
+ end
+
+ describe 'custom methods' do
+ it "builds user from auth_hash" do
+ auth_hash = {
+ info: { nickname: "test", email: "test@petsy.com" },
+ uid: "124",
+ provider: "github"
+ }
+ user = User.info_from_github(auth_hash)
+
+ user.username.must_equal "test"
+ user.email.must_equal "test@petsy.com"
+ user.uid.must_equal 124
+ user.provider.must_equal "github"
+ 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..9b7a21cfe4
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,67 @@
+require 'simplecov'
+SimpleCov.start 'rails' do
+ add_filter '/bin/'
+ add_filter '/db/'
+ add_filter '/spec/' # for rspec
+ add_filter '/test/' # for minitest
+end
+
+
+ENV["RAILS_ENV"] = "test"
+SimpleCov.start 'rails' do
+ add_filter '/bin/'
+ add_filter '/db/'
+ add_filter '/spec/' # for rspec
+ add_filter '/test/' # for minitest
+end
+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...
+ # group :test do
+ # gem 'simplecov', require: false
+ # end
+ def setup
+ # Once you have enabled test mode, all requests
+ # to OmniAuth will be short circuited to use the mock authentication hash.
+ # A request to /auth/provider will redirect immediately to /auth/provider/callback.
+ OmniAuth.config.test_mode = true
+ end
+
+ def mock_auth_hash(user)
+ return {
+ provider: user.provider,
+ uid: user.uid,
+ info: {
+ email: user.email,
+ username: user.username
+ }
+ }
+ end
+
+ def 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