diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb
new file mode 100644
index 0000000000..04266021cb
--- /dev/null
+++ b/app/views/merchants/show.html.erb
@@ -0,0 +1,27 @@
+<%# should this be an edited products#index? %>
+
+
Created at: <%= readable_date(review.created_at) %>
+
<%= review.description %>
+
+
+ <% end %>
+
+
+
+
+
diff --git a/bin/bundle b/bin/bundle
new file mode 100755
index 0000000000..66e9889e8b
--- /dev/null
+++ b/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rails b/bin/rails
new file mode 100755
index 0000000000..5badb2fde0
--- /dev/null
+++ b/bin/rails
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 0000000000..d87d5f5781
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/bin/setup b/bin/setup
new file mode 100755
index 0000000000..78c4e861dc
--- /dev/null
+++ b/bin/setup
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:setup'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/spring b/bin/spring
new file mode 100755
index 0000000000..fb2ec2ebb4
--- /dev/null
+++ b/bin/spring
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+ require 'rubygems'
+ require 'bundler'
+
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
+ if spring
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
+ gem 'spring', spring.version
+ require 'spring/binstub'
+ end
+end
diff --git a/bin/update b/bin/update
new file mode 100755
index 0000000000..a8e4462f20
--- /dev/null
+++ b/bin/update
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/yarn b/bin/yarn
new file mode 100755
index 0000000000..c2bacef836
--- /dev/null
+++ b/bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+VENDOR_PATH = File.expand_path('..', __dir__)
+Dir.chdir(VENDOR_PATH) do
+ begin
+ exec "yarnpkg #{ARGV.join(" ")}"
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000000..f7ba0b527b
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/config/application.rb b/config/application.rb
new file mode 100644
index 0000000000..5f6ca0f9b2
--- /dev/null
+++ b/config/application.rb
@@ -0,0 +1,25 @@
+require_relative 'boot'
+
+require 'rails/all'
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module Betsy
+ class Application < Rails::Application
+ config.generators do |g|
+ # Force new test files to be generated in the minitest-spec style
+ g.test_framework :minitest, spec: true
+
+ # Always use .js files, never .coffee
+ g.javascript_engine :js
+ end
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.1
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ end
+end
diff --git a/config/boot.rb b/config/boot.rb
new file mode 100644
index 0000000000..30f5120df6
--- /dev/null
+++ b/config/boot.rb
@@ -0,0 +1,3 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/config/cable.yml b/config/cable.yml
new file mode 100644
index 0000000000..3cba994bb2
--- /dev/null
+++ b/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: redis://localhost:6379/1
+ channel_prefix: betsy_production
diff --git a/config/database.yml b/config/database.yml
new file mode 100644
index 0000000000..6903bb6083
--- /dev/null
+++ b/config/database.yml
@@ -0,0 +1,85 @@
+# PostgreSQL. Versions 9.1 and up are supported.
+#
+# Install the pg driver:
+# gem install pg
+# On OS X with Homebrew:
+# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
+# On OS X with MacPorts:
+# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
+# On Windows:
+# gem install pg
+# Choose the win32 build.
+# Install PostgreSQL and put its /bin directory on your path.
+#
+# Configure Using Gemfile
+# gem 'pg'
+#
+default: &default
+ adapter: postgresql
+ encoding: unicode
+ # For details on connection pooling, see Rails configuration guide
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+
+development:
+ <<: *default
+ database: betsy_development
+
+ # The specified database role being used to connect to postgres.
+ # To create additional roles in postgres see `$ createuser --help`.
+ # When left blank, postgres will use the default role. This is
+ # the same name as the operating system user that initialized the database.
+ #username: betsy
+
+ # The password associated with the postgres role (username).
+ #password:
+
+ # Connect on a TCP socket. Omitted by default since the client uses a
+ # domain socket that doesn't need configuration. Windows does not have
+ # domain sockets, so uncomment these lines.
+ #host: localhost
+
+ # The TCP port the server listens on. Defaults to 5432.
+ # If your server runs on a different port number, change accordingly.
+ #port: 5432
+
+ # Schema search path. The server defaults to $user,public
+ #schema_search_path: myapp,sharedapp,public
+
+ # Minimum log levels, in increasing order:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, notice, warning, error, fatal, and panic
+ # Defaults to warning.
+ #min_messages: notice
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: betsy_test
+
+# As with config/secrets.yml, you never want to store sensitive information,
+# like your database password, in your source code. If your source code is
+# ever seen by anyone, they now have access to your database.
+#
+# Instead, provide the password as a unix environment variable when you boot
+# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
+# for a full rundown on how to provide these environment variables in a
+# production deployment.
+#
+# On Heroku and other platform providers, you may have a full connection URL
+# available as an environment variable. For example:
+#
+# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
+#
+# You can use this database configuration with:
+#
+# production:
+# url: <%= ENV['DATABASE_URL'] %>
+#
+production:
+ <<: *default
+ database: betsy_production
+ username: betsy
+ password: <%= ENV['BETSY_DATABASE_PASSWORD'] %>
diff --git a/config/environment.rb b/config/environment.rb
new file mode 100644
index 0000000000..426333bb46
--- /dev/null
+++ b/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
new file mode 100644
index 0000000000..5187e22186
--- /dev/null
+++ b/config/environments/development.rb
@@ -0,0 +1,54 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ if Rails.root.join('tmp/caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/config/environments/production.rb b/config/environments/production.rb
new file mode 100644
index 0000000000..9284f84839
--- /dev/null
+++ b/config/environments/production.rb
@@ -0,0 +1,91 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
+ # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
+ # `config/secrets.yml.key`.
+ config.read_encrypted_secrets = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "betsy_#{Rails.env}"
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/config/environments/test.rb b/config/environments/test.rb
new file mode 100644
index 0000000000..8e5cbde533
--- /dev/null
+++ b/config/environments/test.rb
@@ -0,0 +1,42 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000000..89d2efab2b
--- /dev/null
+++ b/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
new file mode 100644
index 0000000000..4b828e80cb
--- /dev/null
+++ b/config/initializers/assets.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000..59385cdf37
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000000..5a6a32d371
--- /dev/null
+++ b/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000000..4a994e1e7b
--- /dev/null
+++ b/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000000..ac033bf9dc
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000000..dc1899682b
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 0000000000..03e7984f03
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,3 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], scope: "email, profile"
+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..b0fe5f3ce1
--- /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#home'
+
+ resources :orders
+
+ resources :merchants, except: [:new, :create] do
+ resources :orders, only: [:index]
+ resources :products, except: [:show]
+ get '/manage_products', to: 'merchants#manage_products', as: 'manage_products'
+ end
+
+ resources :orderitems, only: [:create, :update, :destroy]
+
+ resources :reviews, only: [:create]
+
+ resources :categories, only: [:create]
+
+ resources :products, only: [:index, :show]
+
+
+ get '/:category', to: 'products#index', as: 'category'
+
+ post '/products/categories/new', to: 'products#new_category', as: 'new_category'
+
+ get '/:id/viewcart', to: 'orders#viewcart', as: 'viewcart'
+
+ get "/auth/:provider/callback", to: "sessions#create", as: 'auth_callback'
+
+ delete "/logout", to: "sessions#destroy", as: "logout"
+
+ patch '/order_items/:id/cancel', to: 'orderitems#cancel', as: 'cancel'
+ patch '/order_items/:id/ship', to: 'orderitems#ship', as: 'ship'
+
+ get '/search', to: 'products#index', as: 'search'
+end
diff --git a/config/secrets.yml b/config/secrets.yml
new file mode 100644
index 0000000000..eb6904ad4b
--- /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: 34fb4a95a4674d0975fcd131a3f269c2b709575c4bb992502aaa40db62f58292965df4b9433ae4126e12c20dca1fdaa481ba2c7fdebb919d62cd0d983f2741b5
+
+test:
+ secret_key_base: 1d4ffcfb3ee3e78cae04116f4cc76df3eb789be342ea4bb3e321d58145dbc5eb1b508a0f89254b9009063d62b86e856f67214970c6899af60792928ccd69223f
+
+# 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/20180419033356_create_merchants.rb b/db/migrate/20180419033356_create_merchants.rb
new file mode 100644
index 0000000000..64a57c904c
--- /dev/null
+++ b/db/migrate/20180419033356_create_merchants.rb
@@ -0,0 +1,10 @@
+class CreateMerchants < ActiveRecord::Migration[5.1]
+ def change
+ create_table :merchants do |t|
+ t.string :username
+ t.string :email
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419034041_create_reviews.rb b/db/migrate/20180419034041_create_reviews.rb
new file mode 100644
index 0000000000..f369d1c988
--- /dev/null
+++ b/db/migrate/20180419034041_create_reviews.rb
@@ -0,0 +1,9 @@
+class CreateReviews < ActiveRecord::Migration[5.1]
+ def change
+ create_table :reviews do |t|
+ t.integer :rating
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419044712_create_products.rb b/db/migrate/20180419044712_create_products.rb
new file mode 100644
index 0000000000..94e1798ebf
--- /dev/null
+++ b/db/migrate/20180419044712_create_products.rb
@@ -0,0 +1,12 @@
+class CreateProducts < ActiveRecord::Migration[5.1]
+ def change
+ create_table :products do |t|
+ t.string :name
+ t.string :stock
+ t.float :price
+ t.text :description
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419045117_create_categories.rb b/db/migrate/20180419045117_create_categories.rb
new file mode 100644
index 0000000000..5bef4913b8
--- /dev/null
+++ b/db/migrate/20180419045117_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/20180419045927_create_products_categories.rb b/db/migrate/20180419045927_create_products_categories.rb
new file mode 100644
index 0000000000..cb0a2423f0
--- /dev/null
+++ b/db/migrate/20180419045927_create_products_categories.rb
@@ -0,0 +1,8 @@
+class CreateProductsCategories < 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/20180419050820_create_orders.rb b/db/migrate/20180419050820_create_orders.rb
new file mode 100644
index 0000000000..dbe01c2067
--- /dev/null
+++ b/db/migrate/20180419050820_create_orders.rb
@@ -0,0 +1,16 @@
+class CreateOrders < ActiveRecord::Migration[5.1]
+ def change
+ create_table :orders do |t|
+ t.string :customer_name
+ t.string :customer_email
+ t.string :credit_card
+ t.string :CVV
+ t.string :CC_expiration
+ t.string :status
+ t.string :shipping_address
+ t.string :billing_address
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419053635_create_order_items.rb b/db/migrate/20180419053635_create_order_items.rb
new file mode 100644
index 0000000000..1b14bf865b
--- /dev/null
+++ b/db/migrate/20180419053635_create_order_items.rb
@@ -0,0 +1,11 @@
+class CreateOrderItems < ActiveRecord::Migration[5.1]
+ def change
+ create_table :order_items do |t|
+ t.integer :quantity
+ t.integer :product_id
+ t.integer :order_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20180419171654_add_merchant_id_to_products.rb b/db/migrate/20180419171654_add_merchant_id_to_products.rb
new file mode 100644
index 0000000000..45930fd0d9
--- /dev/null
+++ b/db/migrate/20180419171654_add_merchant_id_to_products.rb
@@ -0,0 +1,5 @@
+class AddMerchantIdToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :products, :merchant, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180419171936_product_id_to_reviews.rb b/db/migrate/20180419171936_product_id_to_reviews.rb
new file mode 100644
index 0000000000..58e4c7b6dd
--- /dev/null
+++ b/db/migrate/20180419171936_product_id_to_reviews.rb
@@ -0,0 +1,5 @@
+class ProductIdToReviews < ActiveRecord::Migration[5.1]
+ def change
+ add_reference :reviews, :product, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180419172655_add_product_to_order_item.rb b/db/migrate/20180419172655_add_product_to_order_item.rb
new file mode 100644
index 0000000000..3672da38ca
--- /dev/null
+++ b/db/migrate/20180419172655_add_product_to_order_item.rb
@@ -0,0 +1,6 @@
+class AddProductToOrderItem < ActiveRecord::Migration[5.1]
+ def change
+ remove_column :order_items, :product_id, :integer
+ add_reference :order_items, :product, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180419210206_add_orderto_order_items.rb b/db/migrate/20180419210206_add_orderto_order_items.rb
new file mode 100644
index 0000000000..e85143d2bf
--- /dev/null
+++ b/db/migrate/20180419210206_add_orderto_order_items.rb
@@ -0,0 +1,7 @@
+class AddOrdertoOrderItems < ActiveRecord::Migration[5.1]
+ def change
+ remove_column :order_items, :order_id, :integer
+
+ add_reference :order_items, :order, foreign_key: true
+ end
+end
diff --git a/db/migrate/20180419213238_add_description_to_review.rb b/db/migrate/20180419213238_add_description_to_review.rb
new file mode 100644
index 0000000000..4c7de16c49
--- /dev/null
+++ b/db/migrate/20180419213238_add_description_to_review.rb
@@ -0,0 +1,5 @@
+class AddDescriptionToReview < ActiveRecord::Migration[5.1]
+ def change
+ add_column :reviews, :description, :text
+ end
+end
diff --git a/db/migrate/20180420062814_add_status_to_products.rb b/db/migrate/20180420062814_add_status_to_products.rb
new file mode 100644
index 0000000000..a12aa899ef
--- /dev/null
+++ b/db/migrate/20180420062814_add_status_to_products.rb
@@ -0,0 +1,5 @@
+class AddStatusToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_column :products, :retired, :boolean, default: false
+ end
+end
diff --git a/db/migrate/20180420175356_change_credit_card_columns_to_lower_case.rb b/db/migrate/20180420175356_change_credit_card_columns_to_lower_case.rb
new file mode 100644
index 0000000000..beff288d0b
--- /dev/null
+++ b/db/migrate/20180420175356_change_credit_card_columns_to_lower_case.rb
@@ -0,0 +1,6 @@
+class ChangeCreditCardColumnsToLowerCase < ActiveRecord::Migration[5.1]
+ def change
+ rename_column :orders, :CVV, :cvv
+ rename_column :orders, :CC_expiration, :cc_expiration
+ end
+end
diff --git a/db/migrate/20180421173034_change_product_stock_to_integer.rb b/db/migrate/20180421173034_change_product_stock_to_integer.rb
new file mode 100644
index 0000000000..f375900ea4
--- /dev/null
+++ b/db/migrate/20180421173034_change_product_stock_to_integer.rb
@@ -0,0 +1,5 @@
+class ChangeProductStockToInteger < ActiveRecord::Migration[5.1]
+ def change
+ change_column :products, :stock, :integer, using: 'stock::integer'
+ end
+end
diff --git a/db/migrate/20180421225111_modify_merchant_for_authentication.rb b/db/migrate/20180421225111_modify_merchant_for_authentication.rb
new file mode 100644
index 0000000000..67523944db
--- /dev/null
+++ b/db/migrate/20180421225111_modify_merchant_for_authentication.rb
@@ -0,0 +1,6 @@
+class ModifyMerchantForAuthentication < ActiveRecord::Migration[5.1]
+ def change
+ add_column :merchants, :uid, :integer, options: { null: false }
+ add_column :merchants, :provider, :string, options: { null: false }
+ end
+end
diff --git a/db/migrate/20180421234834_make_merchant_uid_big_int.rb b/db/migrate/20180421234834_make_merchant_uid_big_int.rb
new file mode 100644
index 0000000000..5eff310fab
--- /dev/null
+++ b/db/migrate/20180421234834_make_merchant_uid_big_int.rb
@@ -0,0 +1,5 @@
+class MakeMerchantUidBigInt < ActiveRecord::Migration[5.1]
+ def change
+ change_column :merchants, :uid, :integer, limit: 8
+ end
+end
diff --git a/db/migrate/20180421235138_make_merchant_uid_bigger.rb b/db/migrate/20180421235138_make_merchant_uid_bigger.rb
new file mode 100644
index 0000000000..32e2ef0a16
--- /dev/null
+++ b/db/migrate/20180421235138_make_merchant_uid_bigger.rb
@@ -0,0 +1,5 @@
+class MakeMerchantUidBigger < ActiveRecord::Migration[5.1]
+ def change
+ change_column :merchants, :uid, :bigint
+ end
+end
diff --git a/db/migrate/20180421235852_change_uid_to_string.rb b/db/migrate/20180421235852_change_uid_to_string.rb
new file mode 100644
index 0000000000..4697ea6efc
--- /dev/null
+++ b/db/migrate/20180421235852_change_uid_to_string.rb
@@ -0,0 +1,5 @@
+class ChangeUidToString < ActiveRecord::Migration[5.1]
+ def change
+ change_column :merchants, :uid, :string
+ end
+end
diff --git a/db/migrate/20180423172432_add_photo_url_to_products.rb b/db/migrate/20180423172432_add_photo_url_to_products.rb
new file mode 100644
index 0000000000..4521172bc9
--- /dev/null
+++ b/db/migrate/20180423172432_add_photo_url_to_products.rb
@@ -0,0 +1,5 @@
+class AddPhotoUrlToProducts < ActiveRecord::Migration[5.1]
+ def change
+ add_column :products, :photo_url, :string
+ end
+end
diff --git a/db/migrate/20180424190055_add_status_to_order_item.rb b/db/migrate/20180424190055_add_status_to_order_item.rb
new file mode 100644
index 0000000000..93cf2bd147
--- /dev/null
+++ b/db/migrate/20180424190055_add_status_to_order_item.rb
@@ -0,0 +1,5 @@
+class AddStatusToOrderItem < ActiveRecord::Migration[5.1]
+ def change
+ add_column :order_items, :status, :string
+ end
+end
diff --git a/db/migrate/20180425060326_add_default_pending_status_to_order_item.rb b/db/migrate/20180425060326_add_default_pending_status_to_order_item.rb
new file mode 100644
index 0000000000..6d22b9a3d3
--- /dev/null
+++ b/db/migrate/20180425060326_add_default_pending_status_to_order_item.rb
@@ -0,0 +1,5 @@
+class AddDefaultPendingStatusToOrderItem < ActiveRecord::Migration[5.1]
+ def change
+ change_column :order_items, :status, :string, default: "pending"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000000..d742a37f9a
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,90 @@
+# 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: 20180425060326) 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 "merchants", force: :cascade do |t|
+ t.string "username"
+ t.string "email"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "uid"
+ t.string "provider"
+ 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 "product_id"
+ t.bigint "order_id"
+ t.string "status", default: "pending"
+ 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 "customer_name"
+ t.string "customer_email"
+ t.string "credit_card"
+ t.string "cvv"
+ t.string "cc_expiration"
+ t.string "status"
+ t.string "shipping_address"
+ t.string "billing_address"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "products", force: :cascade do |t|
+ t.string "name"
+ t.integer "stock"
+ t.float "price"
+ t.text "description"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "merchant_id"
+ t.boolean "retired", default: false
+ t.string "photo_url"
+ t.index ["merchant_id"], name: "index_products_on_merchant_id"
+ end
+
+ create_table "products_categories", force: :cascade do |t|
+ t.bigint "product_id"
+ t.bigint "category_id"
+ t.index ["category_id"], name: "index_products_categories_on_category_id"
+ t.index ["product_id"], name: "index_products_categories_on_product_id"
+ end
+
+ create_table "reviews", force: :cascade do |t|
+ t.integer "rating"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.bigint "product_id"
+ t.text "description"
+ t.index ["product_id"], name: "index_reviews_on_product_id"
+ end
+
+ add_foreign_key "order_items", "orders"
+ add_foreign_key "order_items", "products"
+ add_foreign_key "products", "merchants"
+ add_foreign_key "reviews", "products"
+end
diff --git a/db/seeds.rb b/db/seeds.rb
new file mode 100644
index 0000000000..c5cc3df5ee
--- /dev/null
+++ b/db/seeds.rb
@@ -0,0 +1,86 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
+#
+# Examples:
+#
+# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
+# Character.create(name: 'Luke', movie: movies.first)
+
+category_names = ['accessories', 'capes', 'stickers', 'utility', 'media']
+
+unsaved_categories = []
+category_names.each do |category|
+ category = Category.new(name: category)
+ successful = category.save
+
+ if !successful
+ unsaved_categories << category.name
+ end
+end
+puts "#{unsaved_categories.count} categories not saved"
+
+
+merchants = ['wonder pig', 'captain dog', 'professor heggie', 'batcat']
+unsaved_merchants = []
+merchants.each do |name|
+ merchant = Merchant.new
+ merchant.username = name
+ merchant.email = name.gsub(' ', '_').concat('@superpet.com')
+ merchant.uid = rand(10000..99999).to_s
+ merchant.provider = 'google_oauth2'
+
+ successful = merchant.save
+
+ if !successful
+ unsaved_merchants << merchant.name
+ end
+end
+
+puts "#{unsaved_merchants.count} merchants not saved"
+category_hash = {}
+Category.all.map {|category| category_hash[category.name] = category}
+
+product_names = [
+ ['Green Lantern', 'https://images-na.ssl-images-amazon.com/images/I/51ByMhmwMWL._SY879_.jpg', [category_hash['utility'],] ],
+ ['Ms Marvel Stickers', 'https://i.pinimg.com/236x/36/dc/70/36dc7094fef7a1db3596db10eee68a07--ms-marvel-sticker.jpg', [ category_hash['stickers'], category_hash['accessories']] ],
+ ['Batarang', 'https://www.thinkgeek.com/images/products/zoom/httq_batman_batarang_letter_opener.jpg', [category_hash['utility'], category_hash['accessories']] ],
+ ['Black Eye Mask', 'http://www.5050factoryoutlet.com/istarimages/mp/395936-10!02-30648_d.jpg', [category_hash['accessories']]],
+ ['Yellow Cape', 'https://i.pinimg.com/736x/b1/c6/d1/b1c6d16f5d0cc1ea35ff4344f1aaa386--halloween-costumes-for-dogs-pet-costumes.jpg', [category_hash['accessories'], category_hash['capes']]],
+ ['Entire Captain Planet Series on VHS', 'https://img1.etsystatic.com/142/0/5844803/il_570xN.1130347923_5jxi.jpg', [category_hash['media']]],
+ ['Storm Wig', 'https://ssli.ebayimg.com/images/g/Mv8AAOSwLN5WiOXY/s-l640.jpg', [category_hash['accessories']]],
+ ['Black Widdow Utility Cuffs', 'https://img.etsystatic.com/il/42fa43/1103666807/il_340x270.1103666807_fn4o.jpg?version=0', [category_hash['accessories'], category_hash['utility']] ],
+ ['Red Hair Dye', 'https://www.softsheen-carson.com/~/media/Images/SoftsheenUS/Dark%20and%20Lovely/ALL_GO%20INTENSE%20SPICY%20RED_1000x1000.jpg', [category_hash['accessories']]]
+]
+
+unsaved_products = []
+product_names.each do |product|
+ prod = Product.new
+ prod.merchant_id = Merchant.all.sample.id
+ prod.name = product[0]
+ prod.stock = rand(1..10)
+ prod.price = rand(1..100)
+ prod.photo_url = product[1]
+ prod.categories = product[2]
+
+ successful = prod.save!
+ if !successful
+ unsaved_products << prod.name
+ end
+end
+puts "#{unsaved_products.count} products not saved"
+
+unsaved_orderitems = []
+5.times do
+ orderitem = OrderItem.new
+ product = Product.all.sample
+ orderitem.product_id = product.id
+ orderitem.quantity = rand(1..product.stock)
+ orderitem.order_id = Order.create!.id
+
+ successful = orderitem.save!
+ if !successful
+ unsaved_orderitems << orderitem
+ end
+end
+
+puts "#{unsaved_orderitems.count} orderitems not saved"
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..e926788b71
--- /dev/null
+++ b/test/controllers/categories_controller_test.rb
@@ -0,0 +1,29 @@
+require "test_helper"
+
+describe CategoriesController do
+ describe'create' do
+ let(:merchant) { Merchant.first }
+ before do
+ login(merchant)
+ end
+
+ it 'creates a category with valid data' do
+ old_category_count = Category.count
+
+ post categories_path, params: {name: 'test'}
+
+ must_redirect_to merchant_products_path(merchant.id)
+ Category.count.must_equal old_category_count + 1
+ end
+
+ it 'returns bad_request for bad data' do
+ old_category_count = Category.count
+
+ post categories_path, params: {name: nil}
+
+ must_respond_with :redirect
+ Category.count.must_equal old_category_count
+ end
+
+ end
+end
diff --git a/test/controllers/merchants_controller_test.rb b/test/controllers/merchants_controller_test.rb
new file mode 100644
index 0000000000..2a917e7399
--- /dev/null
+++ b/test/controllers/merchants_controller_test.rb
@@ -0,0 +1,61 @@
+require "test_helper"
+
+describe MerchantsController do
+ describe 'authenticated user' do
+ before do
+ @merchant = Merchant.first
+ login(@merchant)
+ end
+ describe 'index' do
+ it 'returns success with many mearchants' do
+ get merchants_path
+
+ must_respond_with :success
+ end
+
+ it 'returns success with no merchants' do
+ Merchant.destroy_all
+
+ get merchants_path
+
+ must_respond_with :success
+ end
+ end
+
+ describe 'show' do
+ it 'returns success' do
+ merchant2 = Merchant.last
+ get merchant_path(merchant2.id)
+
+ must_respond_with :success
+ end
+ end
+ end
+
+ describe 'guest user' do
+ describe 'index' do
+ it 'returns success with many mearchants' do
+ get merchants_path
+
+ must_respond_with :success
+ end
+
+ it 'returns success with no merchants' do
+ Merchant.destroy_all
+
+ get merchants_path
+
+ must_respond_with :success
+ end
+ end
+
+ describe 'show' do
+ it 'returns success' do
+ merchant2 = Merchant.last
+ get merchant_path(merchant2.id)
+
+ must_respond_with :success
+ end
+ end
+ end
+end
diff --git a/test/controllers/orderitems_controller_test.rb b/test/controllers/orderitems_controller_test.rb
new file mode 100644
index 0000000000..be13cd7b2b
--- /dev/null
+++ b/test/controllers/orderitems_controller_test.rb
@@ -0,0 +1,178 @@
+require "test_helper"
+
+describe OrderitemsController do
+
+ describe 'create' do
+ it 'can add a valid orderitem' do
+ oi_data = {
+ product_id: Product.first.id,
+ order_id: Order.first.id,
+ quantity: 1
+ }
+
+ old_oi_count = OrderItem.count
+
+ OrderItem.new(oi_data).must_be :valid?
+
+ post orderitems_path, params: {order_item: oi_data}
+
+ must_respond_with :redirect
+
+ OrderItem.count.must_equal old_oi_count + 1
+
+ end
+
+ it "won't create an invalid orderitem" do
+ oi_data = {
+ product_id: Product.last.id,
+ quantity: Product.last.stock + 1
+ }
+
+ old_oi_count = OrderItem.count
+
+ OrderItem.new(oi_data).wont_be :valid?
+
+ post orderitems_path, params: {order_item: oi_data}
+
+ must_respond_with :redirect
+ OrderItem.count.must_equal old_oi_count
+ end
+
+ it 'will update a current order item quantity if adding more items of the same product to the cart' do
+ product1 = Product.first
+ orderitem_data = {
+ product_id: product1.id,
+ quantity: 1
+ }
+ old_oi_count = OrderItem.count
+
+ post orderitems_path, params: { order_item: orderitem_data }
+ OrderItem.count.must_equal old_oi_count + 1
+
+ orderitem = OrderItem.last
+ post orderitems_path, params: { order_item: orderitem_data }
+
+ orderitem.reload
+ orderitem.quantity.must_equal 2
+
+ order = Order.find(orderitem.order_id)
+ product_ones = order.products.select { |product| product.id == product1.id }
+
+ product_ones.length.must_equal 1
+ end
+ end
+
+ describe 'update' do
+ it 'updates an existing orderitem with valid data' do
+ orderitem = {
+ product_id: Product.first.id,
+ order_id: Order.first.id,
+ quantity: 1
+ }
+ post orderitems_path, params: {order_item: orderitem}
+
+ test_io = OrderItem.last
+
+ test_io.assign_attributes(quantity: 2)
+ test_io.must_be :valid?
+
+ patch orderitem_path(test_io.id), params: { order_item: {quantity: 2} }
+
+ must_redirect_to viewcart_path(session[:cart_id])
+ test_io.reload
+ test_io.quantity.must_equal 2
+
+ end
+
+ it 'sends does not update a product for invalid data' do
+ orderitem = {
+ product_id: Product.first.id,
+ order_id: Order.first.id,
+ quantity: 1
+ }
+ post orderitems_path, params: {order_item: orderitem}
+
+ test_io = OrderItem.last
+
+ test_io.assign_attributes(quantity: 0)
+ test_io.wont_be :valid?
+
+ patch orderitem_path(test_io.id), params: { order_item: {quantity: 0} }
+
+ must_redirect_to viewcart_path(session[:cart_id])
+ test_io.reload
+ test_io.quantity.must_equal 1
+ end
+
+ it 'redirects to root for orderitem that dne' do
+ io_id = OrderItem.last.id + 1
+ patch orderitem_path(io_id)
+
+ must_respond_with :redirect
+ must_redirect_to root_path
+ end
+ end
+
+ describe 'destroy' do
+ it 'responds with success if an orderitem is deleted' do
+ io_id = OrderItem.first.id
+ old_oi_count = OrderItem.count
+
+ delete orderitem_path(io_id)
+
+ must_respond_with :redirect
+
+ OrderItem.count.must_equal old_oi_count - 1
+ OrderItem.find_by(id: io_id).must_be_nil
+ end
+
+ it 'redirects to root if orderitem dne' do
+ io_id = OrderItem.last.id + 1
+ old_oi_count = OrderItem.count
+
+ delete orderitem_path(io_id)
+
+ must_redirect_to root_path
+ OrderItem.count.must_equal old_oi_count
+ end
+ end
+
+ describe 'ship' do
+ it "allows you to ship an item that exists" do
+ order_item = OrderItem.create(order_id: Order.first.id, product_id: Product.first.id, quantity: 1, status: "pending")
+ order_item.status.must_equal "pending"
+
+ patch ship_path(order_item)
+
+ OrderItem.last.status.must_equal "shipped"
+ end
+
+ it "redirects to root for an item that doesn't exist" do
+ order_item_id = OrderItem.last.id + 1
+ order_item = OrderItem.find_by(id: order_item_id)
+ order_item.must_be :nil?
+ patch ship_path(order_item_id)
+ must_redirect_to root_path
+ end
+ end # ship
+
+ describe 'cancel' do
+ it "allows you to cancel an item that exists" do
+ order_item = OrderItem.create(order_id: Order.first.id, product_id: Product.first.id, quantity: 1, status: "pending")
+ order_item.status.must_equal "pending"
+
+ patch cancel_path(order_item.id)
+
+ OrderItem.last.status.must_equal "cancelled"
+ end
+
+ it "responds with not found for an item that doesn't exist" do
+ order_item_id = OrderItem.last.id + 1
+ order_item = OrderItem.find_by(id: order_item_id)
+ order_item.must_be :nil?
+ patch cancel_path(order_item_id)
+ must_redirect_to root_path
+ end
+ end # cancel
+
+end
diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb
new file mode 100644
index 0000000000..575473c47c
--- /dev/null
+++ b/test/controllers/orders_controller_test.rb
@@ -0,0 +1,196 @@
+require "test_helper"
+
+describe OrdersController do
+ describe "logged in merchant" do
+
+ before do
+ login(Merchant.first)
+ @orders = Merchant.first.orders
+ 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 # index
+ end # logged in merchant
+
+ describe "show" do
+
+ it "sends success if there is an order and status is paid" do
+ orderitem = {product_id: Product.first.id, quantity: Product.first.stock}
+
+ post orderitems_path, params: {order_item: orderitem}
+
+ order = Order.find(session[:cart_id])
+ order.update_attributes(
+ cc_expiration: '234',
+ cvv: '2',
+ customer_name: '23',
+ customer_email: 'sf',
+ credit_card: 'asdf',
+ shipping_address: 'asdf',
+ billing_address: '234'
+ )
+ order.status = "paid"
+ order.save!
+ get order_path(order)
+ must_respond_with :success
+ end
+
+ it "redirects to root if the order does not exist" do
+ order_id = Order.last.id + 1
+ get order_path(order_id)
+ must_redirect_to root_path
+ end
+
+ it "redirects to edit_path if order status != paid" do
+ orderitem = {product_id: Product.first.id, quantity: Product.first.stock}
+
+ post orderitems_path, params: {order_item: orderitem}
+
+ order = Order.find(session[:cart_id])
+ order.update_attributes(
+ cc_expiration: '234',
+ cvv: '2',
+ customer_name: '23',
+ customer_email: 'sf',
+ credit_card: 'asdf',
+ shipping_address: 'asdf',
+ billing_address: '234'
+ )
+ order.status = "pending"
+ order.save!
+
+ get order_path(order)
+ must_redirect_to edit_order_path(order.id)
+
+ end
+
+ end # show
+
+ describe "create" do
+
+ it 'adds a valid order' do
+ old_order_count = Order.count
+
+ post orders_path
+
+ must_respond_with :redirect
+ # must redirect to same path as before
+
+ Order.count.must_equal old_order_count + 1
+ Order.last.status.must_equal "pending"
+ end
+
+ end # create
+
+ describe "update" do
+
+ it "incorporates complete customer information and changes status to paid" do
+ product = Product.first
+ orderitem = {product_id: product.id, quantity: product.stock}
+ post orderitems_path, params: {order_item: orderitem}
+
+ order_id = Order.last.id
+
+ order_data = {
+ customer_name: "Barry Allen",
+ customer_email: "run@nike.com",
+ credit_card: "1123581321345589",
+ cvv: "890",
+ cc_expiration: "09/20",
+ shipping_address: "200 Washington St., Central City, NJ, 23456",
+ billing_address: "23456"
+ }
+ patch order_path(order_id), params: {order: order_data}
+
+ must_redirect_to order_path(order_id)
+
+ Order.last.status.must_equal "paid"
+ end
+
+ it "does not allow the transaction to go through if there are no items in the cart" do
+ # create an order item
+ orderitem = {product_id: Product.first.id, quantity: Product.first.stock}
+ post orderitems_path, params: {order_item: orderitem}
+
+ # delete the order item
+ order_id = OrderItem.last.order.id
+ delete orderitem_path(OrderItem.last.id)
+
+ # send to update the order w customer info
+ order_data = {
+ customer_name: "Barry Allen",
+ customer_email: "run@nike.com",
+ credit_card: "1123581321345589",
+ cvv: "890",
+ cc_expiration: "09/20",
+ shipping_address: "200 Washington St., Central City, NJ, 23456",
+ billing_address: "23456"
+ }
+ patch order_path(order_id), params: {order: order_data}
+
+ must_respond_with :redirect
+ Order.last.status.must_equal "pending"
+ end
+
+ it "does not allow the transaction to go through if the customer data is incomplete" do
+ # create a new order item
+ orderitem = {product_id: Product.first.id, quantity: Product.first.stock}
+ post orderitems_path, params: {order_item: orderitem}
+
+ # update the order with missing fields
+ order_data = {
+ customer_name: "Barry Allen",
+ credit_card: "1123581321345589",
+ cvv: "890",
+ shipping_address: "200 Washington St., Central City, NJ, 23456",
+ billing_address: "23456"
+ }
+ patch order_path(session[:cart_id]), params: {order: order_data}
+
+ must_respond_with :bad_request
+ Order.last.status.must_equal "pending"
+ # relating the cart/order to the order item
+ session[:cart_id].must_equal OrderItem.last.order_id
+ end
+
+ end # update
+
+ describe 'viewcart' 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 orderitems_path, params: {order_item: orderitem_data}
+
+ get viewcart_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 viewcart_path(order_id)
+ must_respond_with :redirect
+ must_redirect_to root_path
+ end
+
+
+
+ end # viewcart
+
+
+end
diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb
new file mode 100644
index 0000000000..75b8c45100
--- /dev/null
+++ b/test/controllers/products_controller_test.rb
@@ -0,0 +1,228 @@
+require "test_helper"
+
+describe ProductsController do
+ describe 'guest user' do
+ describe 'index' do
+ it 'succeeds with multiple products for a guest user' do
+ Product.count.must_be :>, 0
+
+ get products_path
+ must_respond_with :success
+ end
+
+ it 'succeeds with no products for a guest user' do
+ Product.destroy_all
+
+ Product.count.must_equal 0
+ get products_path
+ must_respond_with :success
+ end
+
+ it 'succeeds for a specific category' do
+ category = Category.first
+
+ get category_path(category.name)
+ must_respond_with :success
+ end
+
+ it 'succeeds with no categories' do
+ Category.destroy_all
+
+ get products_path
+ must_respond_with :success
+ end
+ end
+
+ describe 'show' do
+ it 'succeeds for an existing product' do
+ product_id = Product.first.id
+
+ get product_path(product_id)
+
+ must_respond_with :success
+ end
+
+ it 'redirects to root path for a non-existing id' do
+ product_id = Product.last.id + 1
+
+ get product_path(product_id)
+
+ must_redirect_to root_path
+ end
+ end
+ end
+
+ describe 'authenticated user' do
+ let (:product_data) {
+ {
+ name: 'Product',
+ stock: 3,
+ price: 3.00,
+ merchant_id: Merchant.first.id
+ }
+ }
+ let(:merchant) { Merchant.first }
+
+ before do
+ login(merchant)
+ end
+
+ describe 'index' do
+ it 'works with no products' do
+ Product.where(merchant_id: merchant.id).destroy_all
+
+ get merchant_path(merchant.id)
+
+ must_respond_with :success
+ end
+
+ it 'works with many products' do
+ products = Product.where(merchant_id: merchant.id)
+
+ products.count.must_be :>, 0
+
+ get merchant_path(merchant.id)
+
+ must_respond_with :success
+ end
+ end
+
+ describe 'new' do
+ it 'succeeds for an authenticated user' do
+ get new_merchant_product_path(merchant.id)
+
+ must_respond_with :success
+ end
+ end
+
+ describe 'create' do
+
+ it "creates a work with valid data" do
+ old_product_count = Product.count
+
+ post merchant_products_path(merchant.id), params: { product: product_data }
+
+ must_redirect_to merchant_manage_products_path(session[:merchant_id])
+ Product.count.must_equal old_product_count + 1
+ end
+
+ it "renders bad_request and does not update the DB for bogus data for an authenticated user" do
+ product_data[:name] = nil
+
+ old_product_count = Product.count
+
+ post merchant_products_path(merchant.id), params: { product: product_data }
+
+ must_respond_with :bad_request
+ Product.count.must_equal old_product_count
+ end
+
+ it 'adds a default photo if none is given' do
+ post merchant_products_path(merchant.id), params: { product: product_data }
+
+ must_respond_with :redirect
+ Product.last.photo_url.must_equal "http://www.equistaff.com/Images/noimageavailable.gif"
+ end
+ end
+
+ describe 'edit' do
+ it 'succeeds for an authenticated user' do
+ product = merchant.products.first
+ get edit_merchant_product_path(merchant.id, product.id)
+
+ must_respond_with :success
+ end
+ end
+
+ describe 'update' do
+ let (:old_product_count) { Product.count }
+
+ it 'succeeds with good data' do
+ product = merchant.products.first
+ old_product_stock = product.stock
+
+ product_data = {
+ name: product.name,
+ stock: product.stock - 1,
+ price: product.price,
+ merchant_id: product.merchant_id
+ }
+
+ patch merchant_product_path(merchant.id, product.id), params: { product: product_data }
+ product.reload
+
+ must_redirect_to merchant_manage_products_path(session[:merchant_id])
+ Product.count.must_equal old_product_count
+
+ product.stock.must_equal (old_product_stock - 1)
+ end
+
+ it 'returns bad_request for bad data' do
+ product = merchant.products.first
+ old_product_stock = product.stock
+
+ product_data = {
+ name: product.name,
+ stock: nil,
+ price: product.price,
+ merchant_id: product.merchant_id
+ }
+
+ patch merchant_product_path(merchant.id, product.id), params: { product: product_data }
+ product.reload
+
+ must_respond_with :bad_request
+ Product.count.must_equal old_product_count
+
+ product.stock.must_equal old_product_stock
+ end
+
+ it 'adds a default photo if none is given' do
+ product = merchant.products.first
+ product_data = {
+ product_id: product.id,
+ photo_url: nil,
+ merchant_id: product.merchant_id,
+ stock: 2,
+ price: 2.99
+ }
+
+ patch merchant_product_path(merchant.id, product.id), params: { product: product_data }
+
+ must_respond_with :redirect
+ product.reload
+ product.photo_url.must_equal "http://www.equistaff.com/Images/noimageavailable.gif"
+ end
+ end
+
+ describe 'destroy' do
+ let (:product) { merchant.products.first }
+
+ it 'retires an existing product' do
+ delete merchant_product_path(merchant.id, product.id)
+
+ product.reload
+ product.retired.must_equal true
+ must_redirect_to merchant_manage_products_path(session[:merchant_id])
+ end
+
+ it 'must redirect to root for a non-existing product' do
+ non_existing_id = Product.last.id + 1
+ delete merchant_product_path(merchant.id, non_existing_id)
+
+ must_redirect_to root_path
+ end
+
+ it 'will not retire a product that is not associated with the merchant' do
+ product = Merchant.where.not(id: merchant.id).first.products.first
+
+ delete merchant_product_path(merchant.id, product.id)
+
+ product.reload
+ product.retired.must_equal false
+ must_redirect_to merchant_manage_products_path(session[:merchant_id])
+ end
+ 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..e48347f596
--- /dev/null
+++ b/test/controllers/reviews_controller_test.rb
@@ -0,0 +1,53 @@
+require "test_helper"
+
+describe ReviewsController do
+ describe 'create' do
+ before do
+ @old_review_count = Review.count
+ end
+
+ it 'is successful with valid data' do
+ review_data = {
+ rating: 5,
+ product_id: Product.first.id
+ }
+
+ post reviews_path, params: {review: review_data}
+
+ must_respond_with :redirect
+ Review.count.must_equal @old_review_count + 1
+ end
+
+ it 'is unsuccessful with invalid data' do
+ review_data = {
+ rating: 7,
+ product_id: Product.first.id
+ }
+
+ post reviews_path, params: {review: review_data}
+
+ must_respond_with :redirect
+ Review.count.must_equal @old_review_count
+ end
+
+ it "wont' let you review if it's your own product" do
+ merchant = Merchant.first
+ merchant.products.length.must_be :>, 0
+ login(merchant)
+
+ product = merchant.products.first
+
+ review_data = {
+ rating: 3,
+ product_id: product.id
+ }
+ post reviews_path, params: {review: review_data}
+
+ must_respond_with :redirect
+
+ Review.count.must_equal @old_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..12ab1f1bbb
--- /dev/null
+++ b/test/controllers/sessions_controller_test.rb
@@ -0,0 +1,34 @@
+require "test_helper"
+
+describe SessionsController do
+ describe 'auth_callback' do
+ it 'logs in an existing user' do
+ merchant = Merchant.first
+
+ login(merchant)
+
+ must_redirect_to orders_path
+ session[:merchant_id].must_equal merchant.id
+ end
+
+ it 'creates a new merchant if one does not already exist' do
+ merchant_data = {
+ username: 'Test User',
+ email: 'test@email.com',
+ uid: '9999999999999',
+ provider: 'google_oauth2'
+ }
+
+ merchant = Merchant.new(merchant_data)
+ merchant.valid?.must_equal true
+
+ old_merchant_count = Merchant.count
+
+ login(merchant)
+ must_redirect_to orders_path
+
+ Merchant.count.must_equal old_merchant_count + 1
+ session[:merchant_id].must_equal Merchant.last.id
+ 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..814a8eaf3d
--- /dev/null
+++ b/test/fixtures/categories.yml
@@ -0,0 +1,12 @@
+# 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
+#
+
+memorabilia:
+ name: memorabilia
+
+awesome:
+ name: awesome
diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/merchants.yml b/test/fixtures/merchants.yml
new file mode 100644
index 0000000000..3090fa08bd
--- /dev/null
+++ b/test/fixtures/merchants.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+merchant_one:
+ username: merchant_one
+ email: merchant_one@example.com
+ uid: 1
+ provider: :google_oauth2
+
+batambaman:
+ username: batambaman
+ email: thebatambaman@gmail.com
+ uid: 12345
+ provider: google_oauth2
diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml
new file mode 100644
index 0000000000..3a6fc88df6
--- /dev/null
+++ b/test/fixtures/order_items.yml
@@ -0,0 +1,20 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ quantity: 1
+ product: batarang
+ order: one
+ status: pending
+
+two:
+ quantity: 2
+ product: lasso
+ order: two
+ status: pending
+
+
+three:
+ quantity: 1
+ product: utility_belt
+ order: one
+ status: pending
diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml
new file mode 100644
index 0000000000..51a016ce8f
--- /dev/null
+++ b/test/fixtures/orders.yml
@@ -0,0 +1,21 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ customer_name: Peter Parker
+ customer_email: iluvheros@fan.net
+ credit_card: 1234567891011121
+ cvv: 987
+ cc_expiration: 09/35
+ status: paid
+ shipping_address: 1234 Lovelace Ave Seattle WA 98103
+ billing_address: 98103
+
+two:
+ customer_name: Jane Foster
+ customer_email: desertphenom@smartypants.com
+ credit_card: 9876543210111213
+ cvv: 786
+ cc_expiration: 03/23
+ status: paid
+ shipping_address: 109 Desert Road Nowhere AZ 29843
+ billing_address: 29843
diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml
new file mode 100644
index 0000000000..457b2f1d12
--- /dev/null
+++ b/test/fixtures/products.yml
@@ -0,0 +1,37 @@
+# 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
+#
+
+batarang:
+ name: Batarang
+ stock: 10
+ price: 40.00
+ description: The only weapon you'll ever need.
+ merchant: merchant_one
+ # categories:
+ # - memorabilia
+ # - awesome
+ photo_url: http://www.equistaff.com/Images/noimageavailable.gif
+
+lasso:
+ name: Lasso of Truth
+ stock: 10
+ price: 234.99
+ description: Lasso
+ merchant: merchant_one
+ # categories:
+ # - memorabilia
+ # - awesome
+ photo_url: http://www.equistaff.com/Images/noimageavailable.gif
+
+
+utility_belt:
+ name: Utility Belt
+ stock: 20
+ price: 59.99
+ description: A fanny pack, but better
+ merchant: batambaman
+ photo_url: http://www.equistaff.com/Images/noimageavailable.gif
diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml
new file mode 100644
index 0000000000..194299143a
--- /dev/null
+++ b/test/fixtures/reviews.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ rating: 1
+ product: batarang
+
+two:
+ rating: 1
+ product: lasso
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..68b8f31e67
--- /dev/null
+++ b/test/models/category_test.rb
@@ -0,0 +1,80 @@
+require "test_helper"
+
+describe Category do
+ describe 'relations' do
+ it 'connects category and products' do
+ product = Product.first
+
+ category = Category.new(name: 'Accessories')
+ category.products.push(product)
+
+ category.valid?.must_equal true
+ category.products.must_include product
+ end
+ end
+
+ describe 'validations' do
+ it 'cannot be created without a name' do
+ old_category_count = Category.count
+
+ category = Category.new(name: nil)
+
+ category.valid?.must_equal false
+ Category.count.must_equal old_category_count
+ category.errors.must_include :name
+ end
+
+ it 'can only be created with a unique name' do
+ old_category_count = Category.count
+
+ category = Category.new(name: Category.first.name)
+
+ category.valid?.must_equal false
+ Category.count.must_equal old_category_count
+ category.errors.must_include :name
+ end
+ end
+
+ describe 'logic' do
+
+ describe 'categories_with_works' do
+ it 'only returns categories that have products associated with it' do
+ categories_with_works = Category.categories_with_works
+
+ categories_with_works.each do |category|
+ category.products.must_be :>, 0
+ end
+ end
+
+ it 'returns an empty array if there are no categories with products' do
+ Category.destroy_all
+
+ categories_with_works = Category.categories_with_works
+
+ categories_with_works.must_be_empty
+
+ end
+ end
+
+ describe 'fix_category' do
+ it 'downcases and pluralizes the category' do
+ category1 = 'weapon'
+ category2 = 'mouse'
+
+ result1 = Category.fix_category(category1)
+ result2 = Category.fix_category(category2)
+
+ result1.must_equal 'weapons'
+ result2.must_equal 'mice'
+ end
+
+ it 'works for an already plural category' do
+ category1 = 'Toys'
+
+ result1 = Category.fix_category(category1)
+
+ result1.must_equal 'toys'
+ end
+ end
+ end
+end
diff --git a/test/models/merchant_test.rb b/test/models/merchant_test.rb
new file mode 100644
index 0000000000..7b18378e05
--- /dev/null
+++ b/test/models/merchant_test.rb
@@ -0,0 +1,219 @@
+require "test_helper"
+
+describe Merchant do
+ describe "validations" do
+
+ it "must have a unique username" do
+ # arrange
+ merchant = Merchant.first
+ old_merchant_count = Merchant.count
+
+ new_merchant = Merchant.new(username: merchant.username, email: "address@example.com")
+
+ # assumptions
+ new_merchant.wont_be :valid?
+
+ # act
+ new_merchant.save
+
+ # assert
+ Merchant.count.must_equal old_merchant_count
+ end
+
+ it "must have a unique email" do
+ # arrange
+ merchant = Merchant.first
+ old_merchant_count = Merchant.count
+
+ new_merchant = Merchant.new(username: "example_username", email: merchant.email)
+
+ # assumptions
+ new_merchant.wont_be :valid?
+
+ # act
+ new_merchant.save
+
+ # assert
+ Merchant.count.must_equal old_merchant_count
+ end
+
+ end # validations
+
+ describe "relations" do
+
+ it "connects product and product_id" do
+ merchant = Merchant.first
+
+ product = Product.new(name: "Green Lantern Ring", stock: 1, price: 57.00)
+
+ # act
+ product.merchant = merchant
+ product.must_be :valid?
+
+ product.save
+
+ merchant.products.must_include product
+ end
+
+ end # relations
+
+ describe "business logic" do
+
+ describe "#merchant_order_items" do
+
+ before do
+ @merchant = Merchant.first
+ @result = @merchant.merchant_order_items("all")
+ end
+
+ it "must return a hash" do
+ @result.must_be_kind_of Hash
+ end
+
+ it "must have keys corresponding to order id" do
+ orders = @merchant.orders
+ orders_ids = orders.map { |order| order.id }
+ @result.keys.must_equal orders_ids
+ end
+
+ it "must have values of type order_item only for products that belong to the merchant" do
+ merchant = merchants(:merchant_one)
+
+ result = merchant.merchant_order_items("all").values
+ result.each do |order_items|
+ order_items.each do |order_item|
+ order_item.product.merchant_id.must_equal merchant.id
+ end
+ end
+
+ end
+
+ it "must return an empty hash for a merchant with no orders" do
+ @merchant = Merchant.create(username: "Barry Allen", email: "b@rryfast.com")
+ @result = @merchant.merchant_order_items("all")
+ @result.must_be :empty?
+ end
+
+ end # merchant_order_items
+
+ describe "#total_revenue_by" do
+ before do
+ @merchant = Merchant.first
+ @order = Order.create(status: "completed")
+ product = Product.create(name: "eye mask", merchant_id: @merchant.id, stock: "20", price: 22.50)
+ @order_item = OrderItem.create(product_id: product.id, order_id: @order.id, quantity: 1)
+ end
+
+ it "returns the total revenue for all of a merchant's orders" do
+ merchant_orders = @merchant.orders
+ all_orders_total = 0.00
+ merchant_orders.each do |order|
+ order.order_items.each do |order_item|
+ if order_item.product.merchant_id == @merchant.id
+ all_orders_total += order_item.subtotal
+ end
+ end
+ end
+
+ result = @merchant.total_revenue_by("all")
+ result.must_equal all_orders_total
+ end
+
+ it "returns the total revenue for all of a merchant's orders with status paid" do
+ merchant_orders = @merchant.orders
+ paid_orders_total = 0.00
+ merchant_orders.each do |order|
+ order.order_items.each do |order_item|
+ if order_item.product.merchant_id == @merchant.id && Order.find(order.id).status == "paid"
+ paid_orders_total += order_item.subtotal
+ end
+ end
+ end
+
+ result = @merchant.total_revenue_by("paid")
+ result.must_equal paid_orders_total
+
+ end
+
+ it "returns the total revenue for all of a merchant's orders with status completed" do
+ merchant_orders = @merchant.orders
+ completed_orders_total = 0.00
+ merchant_orders.each do |order|
+ order.order_items.each do |order_item|
+ # binding.pry
+ if order_item.product.merchant_id == @merchant.id && Order.find(order.id).status == "completed"
+ completed_orders_total += order_item.subtotal
+ end
+ end
+ end
+
+ result = @merchant.total_revenue_by("completed")
+ result.must_equal completed_orders_total
+
+ end
+
+
+ it "returns 0.0 for the total revenue of a merchant with zero orders" do
+ merchant = Merchant.new
+ result = merchant.total_revenue_by("all")
+ result.must_equal 0.0
+ end
+
+ end # merchant total_revenue_by
+
+ describe "#count_orders_by" do
+ before do
+ @merchant = Merchant.first
+ end
+
+ it "returns the total number of orders for a merchant" do
+ num_orders = @merchant.orders.count
+ result = @merchant.count_orders_by("all")
+ result.must_equal num_orders
+ end
+
+ it "returns the total number of pending orders for a merchant" do
+ pending_orders = @merchant.orders.select do |order|
+ order.status == "pending"
+ end
+ result = @merchant.count_orders_by("pending")
+ result.must_equal pending_orders.count
+ end
+
+ it "returns the total number of paid orders for a merchant" do
+ paid_orders = @merchant.orders.select do |order|
+ order.status == "paid"
+ end
+ result = @merchant.count_orders_by("paid")
+ result.must_equal paid_orders.count
+ end
+
+ it "returns the total number of completed orders for a merchant" do
+ completed_orders = @merchant.orders.select do |order|
+ order.status == "completed"
+ end
+ result = @merchant.count_orders_by("completed")
+ result.must_equal completed_orders.count
+ end
+
+ it "returns the total number of cancelled orders for a merchant" do
+ cancelled_orders = @merchant.orders.select do |order|
+ order.status == "cancelled"
+ end
+ result = @merchant.count_orders_by("cancelled")
+ result.must_equal cancelled_orders.count
+ end
+
+ it "returns 0 for a merchant with zero orders" do
+ merchant = Merchant.new
+ num_orders = merchant.orders.count
+ num_orders.must_equal 0
+ result = merchant.count_orders_by("all")
+ result.must_equal num_orders
+ end
+
+ end # num_orders_by
+
+ end # business logic
+
+end
diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb
new file mode 100644
index 0000000000..8495048f84
--- /dev/null
+++ b/test/models/order_item_test.rb
@@ -0,0 +1,165 @@
+require "test_helper"
+require 'pry'
+
+describe OrderItem do
+
+ describe 'validations' do
+ before do
+ @product = Product.first
+ @order = Order.first
+ @order_item = OrderItem.new(product_id: @product.id, order_id: @order.id, quantity: 1, status: "pending")
+ end
+
+ it 'is valid with a index_reviews_on_product_id' do
+
+ @order_item.valid?.must_equal true
+
+ end
+
+ it 'is invalid without a product_id' do
+
+ order_item = OrderItem.new(order_id: @order_id, quantity: 1)
+
+ order_item.wont_be :valid?
+
+ end
+
+ it 'is valid with an order_id' do
+
+ @order_item.valid?.must_equal true
+
+ end
+
+ it 'is invalid without an order_id' do
+ @order_item.valid?.must_equal true
+
+ @order_item.order_id = nil
+
+ @order_item.valid?.must_equal false
+ end
+
+ it 'is valid with a quantity greater than zero' do
+ @order_item.quantity = 3
+ @order_item.quantity.must_equal 3
+ @order_item.valid?.must_equal true
+ end
+
+ it 'is invalid when the quantity is not an integer' do
+ @order_item.valid?.must_equal true
+
+ @order_item.quantity = "potatoes"
+
+ @order_item.valid?.must_equal false
+
+ end
+
+ it 'is invalid when the quantity is zero' do
+ @order_item.valid?.must_equal true
+
+ @order_item.quantity = 0
+
+ @order_item.valid?.must_equal false
+ end
+
+ it 'is invalid with a quantity greater than the product stock' do
+ stock = @product.stock
+ @order_item.quantity = stock + 1
+ @order_item.wont_be :valid?
+ end
+
+ it 'is invalid without a status' do
+ @order_item.must_be :valid?
+ @order_item.status = nil
+ @order_item.wont_be :valid?
+ end
+
+ end # validations
+
+ describe "relations" do
+ before do
+ @order_item = OrderItem.new
+ end
+
+
+ it "connects product and product id" do
+ product = Product.first
+ @order_item.product = product
+ @order_item.product_id.must_equal product.id
+ end
+
+ it "connects order and order id" do
+ order = Order.first
+ @order_item.order = order
+ @order_item.order_id.must_equal order.id
+ end
+
+ end # relations
+
+ describe "business logic" do
+
+ describe "subtotal" do
+
+ it "returns the price of the product times the quantity of the order item" do
+ product = Product.first
+ quantity = 2
+ order = Order.create
+ order_item = OrderItem.new(quantity: quantity, product_id: product.id, order_id: order.id, status: "pending")
+ order_item.must_be :valid?
+ subtotal = product.price * quantity
+ result = order_item.subtotal
+ result.must_equal subtotal
+ end
+
+ end # subtotal
+
+ describe 'orderitem aggregation' do
+ it 'will update an order item quantity' do
+ product1 = Product.first
+ order = Order.create!
+
+ orderitem1 = OrderItem.create!(product_id: product1.id, quantity: 1, order_id: order.id)
+
+ orderitem2 = OrderItem.new(product_id: orderitem1.product_id, quantity: 1, order_id: order.id)
+
+ # return orderitem2
+ orderitem_test = OrderItem.aggregate_orderitem(orderitem2, orderitem1)
+
+ orderitem_test.save
+
+ orderitem1.quantity.must_equal 2
+ orderitem_test.id.must_equal orderitem1.id
+
+ product_ones = order.products.select { |product| product.id == product1.id }
+
+ product_ones.length.must_equal 1
+ end
+ end
+
+ describe 'existing_oi?' do
+ it "will return true if order item's product is already associated with the order" do
+ product1 = Product.first
+ order = Order.create!
+
+ orderitem1 = OrderItem.create!(product_id: product1.id, quantity: 1, order_id: order.id)
+
+ orderitem2 = OrderItem.new(product_id: product1.id, quantity: 1, order_id: order.id)
+ result = OrderItem.existing_oi?(orderitem2)
+
+ result.must_equal orderitem1
+ end
+
+ it 'will return nil if that product is not associated with the order' do
+ product1 = Product.first
+ order = Order.create!
+
+ OrderItem.create!(product_id: product1.id, quantity: 1, order_id: order.id)
+
+ orderitem2 = OrderItem.new(product_id: Product.last.id, quantity: 1, order_id: order.id)
+
+ result = OrderItem.existing_oi?(orderitem2)
+ result.must_equal nil
+ end
+ end
+ end # business logic
+
+end
diff --git a/test/models/order_test.rb b/test/models/order_test.rb
new file mode 100644
index 0000000000..897fae30a1
--- /dev/null
+++ b/test/models/order_test.rb
@@ -0,0 +1,140 @@
+require "test_helper"
+
+describe Order do
+ describe 'validations' do
+
+ describe 'validations before changing status from pending to paid' do
+ it 'is valid with one order item' do
+ order = Order.first
+ order.order_items.count.must_equal 1
+ order.valid?.must_equal true
+ end
+
+ it 'is can be associated with multiple order items' do
+ order = Order.create!
+ OrderItem.create!(quantity: 1, product: Product.last, order: order, status: 'pending')
+ OrderItem.create!(quantity: 1, product: Product.first, order: order, status: 'pending')
+
+ order.order_items.count.must_be :>, 1
+ OrderItem.last.order_id.must_equal order.id
+ item1 = OrderItem.find(OrderItem.last.id - 1)
+ item1.order_id.must_equal order.id
+ end
+
+ it 'is valid with 0 order items' do
+ order = Order.new
+ order.order_items.count.must_equal 0
+ order.valid?.must_equal true
+ end
+
+ end # validations before changing status
+
+ end # validations
+
+ describe 'business logic' do
+ describe 'order_total' do
+ before do
+ @order = Order.new
+ @order.order_items << OrderItem.first
+ @order.valid?.must_equal true
+ @order.save
+ end
+ it 'returns the correct total when there is one orderitem' do
+ @order.order_items.length.must_equal 1
+ total = @order.order_total
+
+ total.must_equal OrderItem.first.product.price
+
+ end
+ it 'returns the correct total when there are multiple orderitems' do
+ @order.order_items << OrderItem.last
+
+ @order.order_items.length.must_equal 2
+
+ total = @order.order_total
+
+ total.must_equal OrderItem.first.product.price + OrderItem.last.product.price
+ end
+ end # order_total
+
+ describe 'order_status' do
+
+ describe 'determines the status of an order based on the status of its order items' do
+ before do
+ @order = Order.create
+ @order_item_one = OrderItem.create(product_id: Product.first.id, order_id: @order.id, quantity: 1, status: "pending")
+ @order_item_two = OrderItem.create(product_id: Product.last.id, order_id: @order.id, quantity: 1, status: "pending")
+ @order.assign_attributes(customer_name: "Bob Belcher", customer_email: "burgers_rule@gmail.com", credit_card: "123456789abcdef0", cvv: "789", cc_expiration: "11/18", shipping_address: "345 Main St., Seattle, WA 54321", billing_address: "54321", status: "paid")
+ @order.save
+ @order.status.must_equal "paid"
+
+ @order_item_one.update(status: "shipped")
+ @order.status.must_equal "paid"
+ @order_item_two.update(status: "cancelled")
+
+ end
+
+ it "has a paid status until none of the order items have a pending status" do
+ @order.reload
+ @order.order_status
+ @order.status.must_equal "completed"
+ end
+
+ it "has a cancelled status only if all order_items are cancelled" do
+ @order.reload
+ @order.order_status
+ @order.status.must_equal "completed"
+
+ @order_item_one.update(status: "cancelled")
+
+ @order.reload
+
+ @order.order_status
+ @order.status.must_equal "cancelled"
+
+ end
+
+ end
+
+ end # order_status
+
+
+ describe 'reduce_stock' do
+ it 'reduces the stock for all items by expected amount' do
+ order = Order.new
+ order.valid?
+ order.save
+ item1 = OrderItem.first
+ item1.quantity = 5
+ item1.save
+ order.order_items << item1
+ item2 = OrderItem.last
+ item2.quantity = 8
+ item2.save
+ order.order_items << item2
+
+ order.order_items.length.must_equal 2
+
+ product1 = item1.product
+ product1.stock = 12
+
+ product2 = item2.product
+ product2.stock = 9
+
+ order.reduce_stock
+
+ order.reload
+
+ product1.reload
+ product2.reload
+
+ product1.stock.must_equal 7
+ product2.stock.must_equal 1
+
+ end
+ end
+
+
+ end # business logic
+
+end # Order
diff --git a/test/models/product_test.rb b/test/models/product_test.rb
new file mode 100644
index 0000000000..146c88e4e2
--- /dev/null
+++ b/test/models/product_test.rb
@@ -0,0 +1,190 @@
+require "test_helper"
+
+describe Product do
+ describe 'relations' do
+ let (:product) { Product.new(name: 'Action Figure', stock: 3, price: 2.99, merchant: merchants(:merchant_one)) }
+ let (:merchant) { Merchant.first }
+
+ it 'has a list of categories' do
+ product = products(:batarang)
+
+ product.must_respond_to :categories
+
+ product.categories.each do |category|
+ category.must_be_kind_of Category
+ end
+ end
+
+ it 'connects categories and products' do
+ category = Category.first
+
+ product.categories.push(category)
+
+ product.valid?.must_equal true
+
+ product.categories.must_include category
+ end
+
+
+ it 'connects products and merchants' do
+ product = Product.new(name: 'Green Hair Dye', stock: 24, price: 8.99, merchant_id: merchant.id)
+
+ product.merchant_id.must_equal merchant.id
+ end
+
+ it 'connects products and order_items' do
+ order_item = order_items(:one)
+
+ product = Product.create!(name: 'Green Hair Dye', stock: 24, price: 8.99, merchant_id: merchant.id)
+
+ product.order_items << order_item
+ product.valid?.must_equal true
+ product.order_item_ids.must_include order_item.id
+ end
+
+ it 'connects products and orders' do
+ product1 = Product.create!(name: 'Green Hair Dye', stock: 24, price: 8.99, merchant_id: merchant.id)
+
+ order = Order.create!
+ OrderItem.create!(product_id: product1.id, order_id: order.id, quantity: 2, status: 'pending')
+
+ product1.valid?.must_equal true
+ product1.order_ids.must_include order.id
+ end
+ end
+
+ describe 'validations' do
+ let (:merchant) { Merchant.first }
+ let (:categories) { [Category.first] }
+
+ it 'cannot be created without a name' do
+ product_data = {
+ stock: 1,
+ price: 1.99,
+ merchant_id: merchant.id,
+ categories: categories
+ }
+
+ product = Product.new(product_data)
+
+ product.valid?.must_equal false
+ product.errors.messages.must_include :name
+ end
+
+ it 'must have a unique name' do
+ product1_name = Product.first.name
+
+ product2_data = {
+ name: product1_name,
+ stock: 1,
+ price: 1.99,
+ merchant_id: merchant.id,
+ categories: categories
+ }
+
+ product = Product.new(product2_data)
+
+ product.valid?.must_equal false
+ product.errors.messages.must_include :name
+ end
+
+ it 'cannot be created without a price' do
+ product_data = {
+ name: 'product',
+ stock: 1,
+ merchant_id: merchant.id,
+ categories: categories
+ }
+
+ product = Product.new(product_data)
+
+ product.valid?.must_equal false
+ product.errors.messages.must_include :price
+ end
+
+ it 'cannot be created with a price below 0' do
+ product_data = {
+ name: 'product',
+ stock: 1,
+ price: -2.4,
+ merchant_id: merchant.id,
+ categories: categories
+ }
+
+ product = Product.new(product_data)
+ product.valid?.must_equal false
+ product.errors.messages.must_include :price
+ end
+
+ it 'cannot be created without a stock' do
+ product_data = {
+ name: 'product',
+ price: 2.99,
+ stock: nil,
+ merchant_id: merchant.id,
+ categories: categories
+ }
+
+ product = Product.new(product_data)
+
+ product.valid?.must_equal false
+ product.errors.messages.must_include :stock
+ end
+
+ it 'cannot be created without a merchant ID' do
+ product_data = {
+ name: 'product',
+ stock: 1,
+ price: 2.4,
+ categories: categories
+ }
+
+ product = Product.new(product_data)
+ product.valid?.must_equal false
+ product.errors.messages.must_include :merchant
+ end
+
+ it 'can be created with appropriate data' do
+ product_data = {
+ name: 'product',
+ stock: 1,
+ price: 2.4,
+ merchant_id: merchant.id,
+ categories: categories
+ }
+ old_product_count = Product.count
+
+ product = Product.create(product_data)
+ product.valid?.must_equal true
+ Product.count.must_equal old_product_count + 1
+ end
+ end
+
+ describe 'scopes' do
+ describe 'by_category' do
+ it 'returns only the products of a specific category' do
+ category = Category.first
+
+ products = Product.by_category(category.name)
+
+ products.each do |product|
+ product.categories.must_include category
+ end
+ end
+ end
+ end
+
+ describe 'stock_decrement' do
+ it 'decreases product stock by the amount ordered' do
+ product = Product.first
+ product.stock = 5
+ product.save
+
+ product.stock_decrement(3)
+ product.reload
+
+ product.stock.must_equal 2
+ end
+ end
+
+end
diff --git a/test/models/review_test.rb b/test/models/review_test.rb
new file mode 100644
index 0000000000..bbd22e4052
--- /dev/null
+++ b/test/models/review_test.rb
@@ -0,0 +1,60 @@
+require "test_helper"
+
+describe Review do
+ describe "validations" do
+ before do
+ @old_review_count = Review.count
+ @review = Review.new()
+ @review.product = Product.first
+ end
+
+ it "must have a rating" do
+ @review.wont_be :valid?
+ @review.save
+ Review.count.must_equal @old_review_count
+ end
+
+ it "must have a rating that's an integer" do
+ @review.rating = "a"
+ @review.wont_be :valid?
+ @review.save
+ Review.count.must_equal @old_review_count
+ end
+
+ it "must have a rating that is greater than 0" do
+ @review.rating = 0
+ @review.wont_be :valid?
+ @review.save
+ Review.count.must_equal @old_review_count
+ end
+
+ it "must have a rating that is less than 6" do
+ @review.rating = 6
+ @review.wont_be :valid?
+ @review.save
+ Review.count.must_equal @old_review_count
+ end
+
+ it "a valid rating can be created" do
+ @review.rating = 3
+ @review.must_be :valid?
+ @review.save
+ Review.count.must_equal @old_review_count + 1
+ end
+
+ end # validations
+
+ describe "relations" do
+
+ it "connects product and product id" do
+ review = Review.new(rating: 3)
+ review.product = Product.first
+
+ review.must_be :valid?
+ review.save
+
+ review.product_id.must_equal Product.first.id
+ end
+
+ end # relations
+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..2c394b186a
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,61 @@
+require 'simplecov'
+SimpleCov.start 'rails' do
+ add_filter '/bin/'
+ add_filter '/db/'
+ add_filter '/spec/' # for rspec
+ add_filter '/test/' # for minitest
+ add_filter '/app/channels'
+ add_filter '/app/jobs'
+ add_filter '/app/mailer'
+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
+ # 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,
+ name: user.username
+ }
+ }
+ end
+
+ def login(user)
+ OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new(mock_auth_hash(user))
+ get auth_callback_path(:google_oauth2)
+
+ 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