diff --git a/.gitignore b/.gitignore index 6db3c9a5bc..ca77b76fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,11 +5,19 @@ # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. + + +.DS_Store + +coverage + /.bundle +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + # Ignore all logfiles and tempfiles. /log/* !/log/.keep -/tmp - -.DS_Store +/tmp \ No newline at end of file diff --git a/Gemfile b/Gemfile index fc06e5713d..8cea3c1192 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,8 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' + +gem 'bootstrap-sass' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby @@ -24,7 +26,7 @@ gem 'jbuilder', '~> 2.0' gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' +gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server # gem 'unicorn' @@ -35,6 +37,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'simplecov' + gem 'rails-erd' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index a9da33c60c..487de96f64 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,10 +37,17 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + autoprefixer-rails (6.3.6) + execjs + bcrypt (3.1.11) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-sass (3.3.6) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.2) byebug (8.2.5) + choice (0.2.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -50,6 +57,7 @@ GEM coffee-script-source (1.10.0) concurrent-ruby (1.0.1) debug_inspector (0.0.2) + docile (1.1.5) erubis (2.7.0) execjs (2.6.0) globalid (0.3.6) @@ -96,6 +104,11 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-erd (1.4.7) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) railties (4.2.6) @@ -106,6 +119,7 @@ GEM rake (11.1.2) rdoc (4.2.2) json (~> 1.4) + ruby-graphviz (1.2.2) sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -116,6 +130,11 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simplecov (0.11.2) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) spring (1.7.1) sprockets (3.6.0) concurrent-ruby (~> 1.0) @@ -143,18 +162,25 @@ PLATFORMS ruby DEPENDENCIES + bcrypt (~> 3.1.7) + bootstrap-sass byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails pg (~> 0.15) rails (= 4.2.6) + rails-erd sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov spring turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) +RUBY VERSION + ruby 2.3.0p0 + BUNDLED WITH 1.12.1 diff --git a/app/assets/images/ditzy_icon.png b/app/assets/images/ditzy_icon.png new file mode 100644 index 0000000000..12a61fae5e Binary files /dev/null and b/app/assets/images/ditzy_icon.png differ diff --git a/app/assets/images/ditzy_logo_final.png b/app/assets/images/ditzy_logo_final.png new file mode 100644 index 0000000000..162453d152 Binary files /dev/null and b/app/assets/images/ditzy_logo_final.png differ diff --git a/app/assets/images/products/1.png b/app/assets/images/products/1.png new file mode 100644 index 0000000000..3260b1df39 Binary files /dev/null and b/app/assets/images/products/1.png differ diff --git a/app/assets/images/products/2.jpg b/app/assets/images/products/2.jpg new file mode 100644 index 0000000000..101b27f9c4 Binary files /dev/null and b/app/assets/images/products/2.jpg differ diff --git a/app/assets/javascripts/categories.coffee b/app/assets/javascripts/categories.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/categories.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/order_item.coffee b/app/assets/javascripts/order_item.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/order_item.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/orders.coffee b/app/assets/javascripts/orders.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/orders.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/products.coffee b/app/assets/javascripts/products.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/products.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/reviews.coffee b/app/assets/javascripts/reviews.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/reviews.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/users.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css deleted file mode 100644 index f9cd5b3483..0000000000 --- a/app/assets/stylesheets/application.css +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any styles - * defined in the other CSS/SCSS files in this directory. It is generally better to create a new - * file per style scope. - * - *= require_tree . - *= require_self - */ diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss new file mode 100644 index 0000000000..dd4376369a --- /dev/null +++ b/app/assets/stylesheets/application.css.scss @@ -0,0 +1,106 @@ +/** MAIN STYLING **/ + +@import "bootstrap-sprockets"; +@import "bootstrap"; + +* { + box-sizing: border-box; +} + +html { + font-family: 'Palanquin', sans-serif; + font-size: 1rem; +} + +main { + padding: 1rem; +} + +h1 { + color: #42bad3; /* ditzy bright blue */ + font-weight: lighter; + font-size: 2.5rem; + padding: 1rem; + margin: 0rem; +} + +h2 { + color: #d8563d; /* ditzy red */ + font-size: 1.5rem; + padding: 1rem; +} + +h3 { + color: #42bad3; /* ditzy bright blue */ + font-size: 1.5rem; + padding: 1rem; +} + +h4 { + + color: #3f52b8; /* ditzy dark blue */ + font-size: 1.5rem; + padding: 1rem; + +} + +span { + color: #3f52b8; /* ditzy dark blue */ +} + +a { + color: #3f52b8; /* ditzy dark blue */ +} + +p { + color: #3f52b8; /* ditzy dark blue */ + font-size: 1rem; + padding: 1rem; +} + +li { + color: #42bad3; /* ditzy bright blue */ + list-style-type: circle; + } + + +hr.dark-blue { + border: 0.1rem solid #3f52b8; + padding: 0rem; + margin: 0rem; +} + +hr.bright-blue { + border: 0.1rem solid #42bad3; + padding: 0rem; + margin: 0rem; +} + +.thumnbnail { + display: inline-block; + margin-left: auto; + margin-right: auto; +} + +.caption { + display: inline-block; + margin-left: auto; + margin-right: auto; +} + +.caption p { + font-size: 0.8rem; + margin: 0; +} + +.btn { + margin-left: 0.5rem; +} + +/** FONT AWESOME **/ + +.fa { + color: #3f52b8; /* ditzy dark blue */ + font-size: 3rem !important; +} + diff --git a/app/assets/stylesheets/categories.scss b/app/assets/stylesheets/categories.scss new file mode 100644 index 0000000000..ef1657f8c9 --- /dev/null +++ b/app/assets/stylesheets/categories.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the categories controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/order_item.scss b/app/assets/stylesheets/order_item.scss new file mode 100644 index 0000000000..0f35cbeb67 --- /dev/null +++ b/app/assets/stylesheets/order_item.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrderItem controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..3b0428a94e --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..89e2e8db07 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..7bef9cf826 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..1efc835ccd --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1b9..a769690606 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,18 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception -end + helper_method :current_user + + def current_user + @user ||= User.find_by(id: session[:user_id]) + end + + def index + redirect_to products_path + end + + # def logged_in? + # current_user != nil + # end + +end \ No newline at end of file diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..9b9dc8dfae --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,50 @@ +class CategoriesController < ApplicationController + + # we could use this to run a clickable list of categories that will enable folks to see what all the categories are. + def index + end + + def show_by_category + @merchant = User.find(params[:id]) + @products = Product.where(user_id: @merchant.id) + + render :categories_products + end + # if merchant && merchant.authenticate(params[:password]) + # merchant_session[:merchant_id] = merchant.id + # redirect_to root_url, :notice => "Merchanthas been logged in" + # else + # flash.now[:error] = "Invalid username or password." + # @title = "Merchant Signin" + # render "new" + # end + def new + @category = Category.new + end + + def create + # if category_create_params[:category][:name] == "" + # flash.now[:error] = "Please Enter a Catagory Name" + # raise + # end + @category = Category.new(category_create_params[:category]) + if @category.save + redirect_to dashboard_path(current_user.id) + else + # this sucks - place holder for the moment + render :bad_route + + # redirect_to dashboard_path(current_user.id) + end + end + + private + def category_create_params + # if category_create_params[:category][:name] == "" + # flash.now[:error] = "Please Enter a Catagory Name" + # raise + # end + params.permit(category: [:name]) + end +end + diff --git a/app/controllers/order_item_controller.rb b/app/controllers/order_item_controller.rb new file mode 100644 index 0000000000..69bf391454 --- /dev/null +++ b/app/controllers/order_item_controller.rb @@ -0,0 +1,39 @@ + +class OrderItemController < ApplicationController + + # route for /cart + def index + @order = Order.find(session[:order_id]) + @order_items = OrderItem.where(order_id: session[:order_id]).order("created_at asc") + + end + + def create + # quantity 1 is default, params[:format] is where the product id comes from + @order_item = OrderItem.new(order_id: session[:order_id], quantity: 1, product_id: params[:format]) + if @order_item.save + redirect_to cart_path + else + redirect_to products_path + end + end + + def update + @order_item = OrderItem.find(params[:id]) + @order_item.update(quantity: params[:order_item][:quantity]) + + redirect_to cart_path + end + + def destroy + @order_item = OrderItem.find(params[:id]) + @order_item.destroy + redirect_to cart_path + end + + def show + @order_item = OrderItem.find(params[:id]) + @order_product = Product.find(@order_item.product_id) + end + +end \ No newline at end of file diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..e0918d4edb --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,62 @@ +class OrdersController < ApplicationController + # confirmation page + def show + @order = Order.find(session[:order_id]) + @order_items = OrderItem.where(order_id: session[:order_id]).order("created_at asc") + render :show + end + + def create + @order = Order.find(session[:order_id]) + @order.expiration_on_cc = "#{params[:orders][:month]}-#{params[:orders][:year]}" + # @order.expiration_on_cc = params[:orders][:month] + + @order.status = "complete" + @order.name_on_cc = params[:orders][:name_on_cc] + @order.address = params[:orders][:address] + @order.security_on_cc = params[:orders][:security_on_cc] + # @order.expiration_on_cc = Date.strptime(params[:orders][:expiration_on_cc], '%m-%y') + @order.email = params[:orders][:email] + @order.zip = params[:orders][:zip] + @order.updated_at = Time.now + + # Send to the confirmation page aka orders#show + check_inventory(@order) + if @order.save + reduce_inventory(@order) + redirect_to complete_order_path + else + render :new + end + end + + def check_inventory(order) + order.order_items.each do |item| + if item.product.quantity < 0 + flash[:error] = "Sorry, this is out of stock!" + redirect_to product_path(params[:product_id]) + end + end + end + + def reduce_inventory(order) + order.order_items.each do |item| + item.product.quantity -= item.quantity + item.product.save + end + end + + # def complete_order + # # locate the order and "complete it" + # @order_details = OrderItem.where(session[:order_id]) + # clear_cart + + # #this is the confirmation page + # redirect_to :show + # end + + # def clear_cart + # OrderItem.destroy(@order_details) + # end +end + diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..477d5e9bb9 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,75 @@ +class ProductsController < ApplicationController + def index + @new_products = Product.where(visible: true).last(3) + @products = Product.where(visible: true).order(id: :asc) + @categories = Category.all + render :index + end + + def show + # controller action: if @user_id (show "list" view for user)/if category (show "list" view by category) + @product = Product.where(visible: true).find(params[:id]) + @reviews = Review.where(product_id: @product.id) + @merchant = User.joins(:products).where("products.id": params[:id]) + render :product_details + end + + def show_by_merchant + @merchant = User.find(params[:user_id]) + @products = Product.where(visible: true).where(user_id: @merchant.id) + + render :users_products + end + + def show_by_category + @category = Category.find(params[:category_id]) + @products = Category.find(params[:category_id]).products.where(visible: true) + render :categories_products + end + + def new + # user = curent user here. + @user = User.find(params[:id]) + @product = Product.new + render :create_product + end + + def create + @product = Product.create(product_create_params[:product]) + redirect_to dashboard_path(current_user.id) + end + + def edit + @product = Product.find(params[:product_id]) + # @categories = Product.find(params[:product_id]).categories + @categories = Category.all + render :edit + end + + def update + @product = Product.find(params[:id]) + @product.update(product_update_params[:product]) + redirect_to dashboard_path(current_user.id) + end + + def destroy + killed_record = Product.destroy(params[:id]) + if params[:id] = true + redirect_to products_show_path(@current_user.id) + end + end + + def show_merchant_store + @merchant = User.find(params[:id]) + @merchant_products = Product.where(user_id: @merchant.id) + end + + private + def product_create_params + params.permit(product: [:name, :user_id, :price_in_dollars, :visible, :quantity, :description, :image_url, :category_ids => []]) + end + + def product_update_params + params.permit(product: [:name, :user_id, :price_in_dollars, :visible, :quantity, :description, :image_url, :category_ids => []]) + end +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..78af4305f2 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,49 @@ +class ReviewsController < ApplicationController + #might only need index show delete + def index #show all + #@review = Review.where(product_id: params[:product_id]).first + + end + + def show # show one all display a view that has already been created + @review = Review.all.where(params[:product_id]) + render :new + end + + def new + @review = Review.new + @product = Product.find(params[:product_id]) + render :new + end + + def create + @reviewparams = review_params + @review = Review.new(review_params) + if @review.save + redirect_to product_path(@review.product_id) + else + @review = Review.new + @product = Product.find(params[:product_id]) + render :new + end + + end + + def edit + @review = Reviews.find(params[:id]) + render :new + end + + def update + end + + def delete + end +end + + +private + + def review_params + params.require(:review).permit(:review_text, :rating, :product_id) + end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..32fad17edb --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,32 @@ +class SessionsController < ApplicationController + + + # login for registered users + def create + current_user = User.log_in(params[:session_data][:email], params[:session_data][:password]) + if current_user + session[:user_id] = current_user.id + @order = Order.create + @order.status = "pending" + session[:order_id] = @order.id + redirect_to products_path + else + redirect_to products_path + end + end + + #login for guest users + def create_order + # brand new cart object + @order = Order.create + # this is the cart object + session[:order_id] = @order.id + redirect_to products_path + end + + def destroy + session.delete(:user_id) + redirect_to products_path + end + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..90b25c0068 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,64 @@ +class UsersController < ApplicationController + # commenting this out because it breaks things and Rowan is not here to explain it + # before_action :require_login, except: [:new, :create, :bad_route] + + def new + @new_user = User.new + end + + def create + @new_user = User.new(user_create_params[:user]) + + if @new_user.save + redirect_to new_session_path + else + render :new + end + end + + def show_merchant + @merchant_order_items = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).order(order_id: :asc) + @total_revenue = OrderItem.joins(:product).where("products.user_id": params[:id]).sum("products.price_in_dollars") + @completed_orders = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "complete").count() + @pending_orders = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "pending").count() + @completed_orders_subtotal = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "complete").sum("products.price_in_dollars") + @pending_orders_subtotal = OrderItem.joins(:product, :order).where("products.user_id": params[:id]).where("orders.status": "pending").sum("products.price_in_dollars") + end + + def show + @merchant = User.find(params[:id]) + @products = Product.where(user_id: @merchant.id) + @category ||= Category.new + @categories = Category.all + @product = Product.new + + render "users/merchant" + end + + def update_order_item + @item = OrderItem.find(params[:id]) + @item.update(update_order_item_params[:order_item]) + redirect_to orders_dashboard_path(current_user.id) + end + + + def show_merchant_order + @order = Order.find(params[:id]) + end + + private + + def require_login + unless current_user && current_user.id == params[:id].to_i + render :bad_route + end + end + + def user_create_params + params.permit(user: [:user_name, :email, :password, :password_confirmation]) + end + + def update_order_item_params + params.permit(order_item: [:shipped]) + end +end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000000..e06f31554c --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/helpers/order_item_helper.rb b/app/helpers/order_item_helper.rb new file mode 100644 index 0000000000..1b37f3b1bb --- /dev/null +++ b/app/helpers/order_item_helper.rb @@ -0,0 +1,2 @@ +module OrderItemHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000000..ab5c42b325 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..74ebfdff08 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,8 @@ +class Category < ActiveRecord::Base + + has_and_belongs_to_many :products + + validates :name, presence: true + validates :name, uniqueness: true + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..606ceaa9e5 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,3 @@ +class Order < ActiveRecord::Base + has_many :order_items +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..d9ab6b790c --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,5 @@ +class OrderItem < ActiveRecord::Base + belongs_to :order + belongs_to :product + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..7d9951a831 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,10 @@ +class Product < ActiveRecord::Base + belongs_to :user + has_many :reviews + has_and_belongs_to_many :categories + + validates :name, presence: true + validates_numericality_of :quantity, :only_integer => true, :greater_than_or_equal_to => 1 + validates_numericality_of :price_in_dollars, :greater_than_or_equal_to => 1 + +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..05a8803e65 --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,6 @@ +class Review < ActiveRecord::Base + belongs_to :product + + validates :review_text, presence: true + validates :rating, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..d04ffd9c8d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,18 @@ +class User < ActiveRecord::Base + + # attr_accessor :user_name, :password, :password_confirmation + has_many :products + has_many :orders + has_many :reviews , :through => :product + has_many :order_items , :through => :order + + validates :user_name, presence: true + validates :email, presence: true, uniqueness: true + + has_secure_password + + def self.log_in(email, password) + somebody = find_by(email: email) + somebody && somebody.authenticate(password) + end +end diff --git a/app/views/categories/bad_route.html.erb b/app/views/categories/bad_route.html.erb new file mode 100644 index 0000000000..3bf412e37e --- /dev/null +++ b/app/views/categories/bad_route.html.erb @@ -0,0 +1,9 @@ +<% if @category.errors.any? %> + +<% end %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9b70e01c2e..452caef455 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,48 @@ - Betsy + dITzy* <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> + + + + + + + + + + + +
+ <%=link_to image_tag("ditzy_logo_final.png"), products_path%> +<% if current_user %> + + Welcome, <%= current_user.user_name.capitalize %>! + + <%= link_to "Logout", logout_path, method: "delete", :class => "btn btn-primary btn-sm" %> + <%= link_to "Dashboard", dashboard_path(current_user.id), method: "get", :class => "btn btn-primary btn-sm" %> + <%= link_to "Your Cart", cart_path(current_user.id), method: "get", :class => "btn btn-primary btn-sm" %> +<% else %> + <%= link_to "Login", new_session_path, :class => "btn btn-primary btn-sm" %> + <%= link_to "Create An Account", new_user_path, :class => "btn btn-primary btn-sm" %> + <%= link_to "Your Cart", cart_path, method: "get", :class => "btn btn-primary btn-sm" %> +<% end %> + +

+ gr8 stuff 4 good lady*z +

-<%= yield %> +
+
+
+
+ <%= yield %> +
diff --git a/app/views/order_item/index.html.erb b/app/views/order_item/index.html.erb new file mode 100644 index 0000000000..d666d12204 --- /dev/null +++ b/app/views/order_item/index.html.erb @@ -0,0 +1,37 @@ +

+ Your Cart of Awesome +

+ +<% @total = 0 %> +<% @order_items.each do |item| %> + <% product = Product.find(item.product_id) %> + + <% @total += (product.price_in_dollars * item.quantity) %> +<% end %> + +

Total: <%= number_to_currency(@total) %>

+ +<%= link_to"Give Us Money!", checkout_path, :class => "btn btn-primary btn-md" %>

+ + +<%= link_to "Shop Some More", products_path, :class => "btn btn-primary btn-md" %> diff --git a/app/views/order_item/show.html.erb b/app/views/order_item/show.html.erb new file mode 100644 index 0000000000..c2973b1880 --- /dev/null +++ b/app/views/order_item/show.html.erb @@ -0,0 +1,17 @@ +

Deets on your order item

+<%= params %> + + + + + + + + + + + + + + +
Order IDProductQuantityShipping Status
<%= @order_item.order_id %><%= @order_product.name %><%= @order_item.quantity %><%= @order_item.shipped %>
\ No newline at end of file diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000000..6f7b680b9f --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,25 @@ +

+ + Billing Information +

+ +<%= form_for :orders do |f| %> +
+

+ Name on credit card: <%= f.text_field :name_on_cc %>
+ Credit Card Number: <%= f.text_field :credit_card_number %>
+ Address: <%= f.text_field :address %>
+ Zip: <%= f.text_field :zip %>
+ Security Code: <%= f.text_field :security_on_cc %>
+ Expiration: + <%= f.select :month, 1..12 %> + <%= f.select :year, Date.today.year.. 8.years.from_now.year %>
+ Email: <%= f.text_field :email %>
+ <% status = "pending" %> + <% f.hidden_field :status => status %>
+ <%= button_tag(type: 'submit', class: "btn btn-primary btn-md", action: "create") do %> + Submit + <% end %> +

+
+<%end%> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..b7a8697f6d --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,30 @@ + +

+ + Order Complete! +

+
+
+ <% @total = 0 %> + <% @order_items.each do |item| %> + <% @product = Product.find(item.product_id) %> + + Item Ordered: <%= link_to @product.name, product_path(@product.id) %>
+ Quantity Ordered: <%= item.quantity %>
+ Price per Item: <%= number_to_currency(@product.price_in_dollars) %>
+ Placed on: <%= @order.updated_at.strftime("%B %d, %Y") %>
+ Status: <%= @order.status.capitalize %>
+ <% if item.shipped == true %> + Shipped: It's on the way, brah! + <% else %> + Shipped: Pending + <% end %> + <% @total += (@product.price_in_dollars * item.quantity) %> +

+ + <% end %> +
+
+

+ Total Charges: <%= number_to_currency(@total) %> +

\ No newline at end of file diff --git a/app/views/products/categories_products.html.erb b/app/views/products/categories_products.html.erb new file mode 100644 index 0000000000..1b926375ca --- /dev/null +++ b/app/views/products/categories_products.html.erb @@ -0,0 +1,12 @@ +

<%= @category.name %>

+

Products

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

+ <%=image_tag("#{product.image_url}")%> + Product ID: <%= product.id %>
+ <%= link_to product.name, product_path(product.id) %>
+ <%= product.price_in_dollars %> +

+<%end%> \ No newline at end of file diff --git a/app/views/products/create_product.html.erb b/app/views/products/create_product.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000000..397f17c9b8 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,36 @@ +

+ + Hi buddy, edit your product +

+
+ <%= form_for @product do |f| %> + + <%= f.label :name %> + <%= f.text_field :name %>
+ <%= f.label :price_in_dollars %> + <%= f.text_field :price_in_dollars %>
+ <%= f.label :quantity %> + <%= f.text_field :quantity %>
+ <%= f.label :visibility %> + <%= f.label :true %> + <%= f.radio_button :visible, :true, :checked => :true %> + <%= f.label :false %> + <%= f.radio_button :visible, :false, :checked => :false %>
+ <%= f.label :image_url %> + <%= f.text_field :image_url %>
+ <%= f.label :description %> + <%= f.text_field :description %>
+ + Categories: + + <% @categories.each do |category| %> + <%= f.label :category_ids, "#{category.name}", :value => category.name %> + <%= f.check_box :category_ids, {:multiple => true}, category.id, nil %> + <% end %> +
+
+ <%= button_tag(type: 'submit', class: "btn btn-primary btn-md", action: "edit") do %> + Submit Changes + <% end %> + <% end %> +
\ No newline at end of file diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..c3f37afb2c --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,65 @@ +

+ NEW PRODUCTS +

+ +
+
+ <% @new_products.each do |product| %> +
+
+
+ <%= link_to(image_tag(product.image_url),product_path(product.id)) %> +
+
+ <%= link_to product.name, product_path(product.id) %> +
+
+
+
+
+ <% end %> +
+
+ +

+ + +

+ ALL PRODUCTS +

+
+
+ <% @products.each do |product| %> +
+
+
+ <%= link_to(image_tag(product.image_url),product_path(product.id)) %> +
+
+

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

+
+
+ <%=link_to "BUY NOW", cart_path(product.id), method: :post, :class => "btn btn-primary btn-sm" %> +
+

+
+
+
+
+ <%end%> +
+
+ + \ No newline at end of file diff --git a/app/views/products/list_view.html.erb b/app/views/products/list_view.html.erb new file mode 100644 index 0000000000..d45859ca4b --- /dev/null +++ b/app/views/products/list_view.html.erb @@ -0,0 +1,11 @@ +

<%= @user.name %>

+

Products

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

+ Product ID: <%= product.id %>
+ <%= link_to product.name, user_product_path(product.user_id, product.id) %>
+ <%= product.price %> +

+<%end%> \ No newline at end of file diff --git a/app/views/products/product_details.html.erb b/app/views/products/product_details.html.erb new file mode 100644 index 0000000000..b386a00e8a --- /dev/null +++ b/app/views/products/product_details.html.erb @@ -0,0 +1,32 @@ +
+

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

+ <%=image_tag(("#{@product.image_url}"), :class => 'img-responsive') %> +

+ Price: <%= number_to_currency(@product.price_in_dollars) %>
+ Quantity In Stock: <%= @product.quantity %>
+ Description: <%= @product.description %>
+ Sold by: <%= link_to @merchant.first.user_name, merchant_store_path(@merchant.first.id) %> +

+ + <%=link_to "BUY NOW", cart_path(@product.id), method: :post, :class => "btn btn-primary btn-md" %> + +
+ +
+

+ Product Reviews +

+ <% @reviews.each do |review| %> +

+ Rating: <%= review.rating %>
+ Review: <%= review.review_text %> +

+ <%end%> + + <% if !current_user || current_user.id != @product.user_id %> + <%=link_to "Review this product", new_product_review_path(@product.id), :class => "btn btn-primary btn-md"%> + <% end %> +
\ No newline at end of file diff --git a/app/views/products/show_merchant_store.html.erb b/app/views/products/show_merchant_store.html.erb new file mode 100644 index 0000000000..6f24c3261b --- /dev/null +++ b/app/views/products/show_merchant_store.html.erb @@ -0,0 +1,17 @@ +

+ + Welcome to <%= @merchant.user_name.capitalize%>'s Store! +

+

+ Products +

+

+<% @merchant_products.each do |product| %> + <%=image_tag(("#{product.image_url}"), :class => 'img-responsive')%>
+ Product: <%=product.name%>
+ Price: <%=product.price_in_dollars%>
+ Description: <%=product.description%>

+<% end %> +

+ +<%= link_to "Shop Some More", products_path, :class => "btn btn-primary btn-md" %> diff --git a/app/views/products/users_products.html.erb b/app/views/products/users_products.html.erb new file mode 100644 index 0000000000..4798472d15 --- /dev/null +++ b/app/views/products/users_products.html.erb @@ -0,0 +1,17 @@ +

+ + <%= @merchant.user_name %> +

+

+ Products +

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

+ <%=image_tag("#{product.image_url}")%> + Product ID: <%= product.id %>
+ <%= link_to product.name, product_path(product.id) %>
+ <%= product.price_in_dollars %> +

+ <%end%> +
\ No newline at end of file diff --git a/app/views/reviews/index.html.erb b/app/views/reviews/index.html.erb new file mode 100644 index 0000000000..33a7b31bfb --- /dev/null +++ b/app/views/reviews/index.html.erb @@ -0,0 +1,17 @@ +

+ + Add a comment: +

+
+<%= form_for([@product,@review]) do |f| %> + + <%= f.label :commenter %>
+ <%= f.text_field :commenter %> + <%= f.label :body %>
+ <%= f.text_area :body %> + <%= button_tag(type: 'submit', class: "btn btn-primary btn-md", action: "create") do %> + Add comment + <% end %> +
+<% end %> +
\ No newline at end of file diff --git a/app/views/reviews/new.html.erb b/app/views/reviews/new.html.erb new file mode 100644 index 0000000000..1cd1f8bb47 --- /dev/null +++ b/app/views/reviews/new.html.erb @@ -0,0 +1,28 @@ +

+ Review This Product +

+ +<% if !current_user || current_user.id != @product.user_id %> + <%= form_for([@product, @review])do |f| %> +
+

+ <%= f.label :review_text %>
+ <%= f.text_area :review_text %> +

+
+
+

+ <%=f.label :rating%> + <%=f.select :rating, [1,2,3,4,5] %> + <%= f.hidden_field :product_id, :value => params[:product_id] %>
+

+
+ <%= button_tag(type: 'submit', class: "btn btn-primary btn-sm", action: "create") do %> + Save + <% end %> + <% end %> +<% else %> +

+ This is your product! You can't leave a review on it. +

+<% end %> diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000000..f3ae4cef27 --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,19 @@ +

+ + Login +

+
+
+ + <%= form_for(:session_data, url: sessions_path) do |f| %> + <%= f.label :email, 'Email Address:' %> + <%= f.text_field :email%> + <%= f.label :email, 'Password:' %> + <%= f.password_field :password %> + <%= button_tag(type: 'submit', class: "btn btn-primary btn-sm", action: "create") do %> + Sign-in + <% end %> + <% end %> + +
+
\ No newline at end of file diff --git a/app/views/users/bad_route.html.erb b/app/views/users/bad_route.html.erb new file mode 100644 index 0000000000..c9e27f8793 --- /dev/null +++ b/app/views/users/bad_route.html.erb @@ -0,0 +1,17 @@ +

YOU CAN'T VIEW THIS!

+ +

Please use your back button and try again.

+ +<% if @category.errors.any? %> +

+ + Something is Broken :( +

+ +<% end %> \ No newline at end of file diff --git a/app/views/users/merchant.html.erb b/app/views/users/merchant.html.erb new file mode 100644 index 0000000000..29847bd58d --- /dev/null +++ b/app/views/users/merchant.html.erb @@ -0,0 +1,118 @@ +

+ + Merchant Dashboard +

+

+ Welcome, m'sir <%=@merchant.user_name%>.
+ Please use this dashboard to manage your store. +

+ +<% if @category.errors.any? %> + +<% end %> + +

+ Create a Category, if you please. +

+ + <%= form_for @category, :url => categories_path do |f| %> +
+
+ + <%= f.label :category_name %> + + <%= f.text_field :name %> + <%= button_tag(type: 'submit', class: "btn btn-primary btn-sm", action: "create") do %> + Create Category + <% end %> +
+
+ <% end %> + + +

+ All Categories, m'sir <%=@merchant.user_name%>. +

+ + + + +

+ Create a Product, if you please. +

+ +<%= form_for @product do |f| %> +
+
+ + <%= f.label :name %> + <%= f.text_field :name %>
+ <%= f.label :price %> + <%= f.text_field :price_in_dollars %>
+ <%= f.label :quantity %> + <%= f.text_field :quantity %>
+ <%= f.label :description %> + <%= f.text_field :description %>
+ <%= f.label :image_url %> + <%= f.text_field :image_url %>
+
+
+
+ <% @categories.each do |category| %> + + <%= f.label :category_ids, "#{category.name}", :value => category.name %> + <%= f.check_box :category_ids, {:multiple => true}, category.id, nil %> + <%= f.hidden_field :user_id, :value => @merchant.id %> + <%= f.hidden_field :visible, :value => true %> + + <% end %> +
+ <%= button_tag(type: 'submit', class: "btn btn-primary btn-sm", action: "create") do %> + Create Product + <% end %> +<% end %> + + +

Your Products, m'sir

+ + + + + + <% @products.each do |product| %> + + + <% if product.visible == true %> + + <% else %> + + <% end %> + + + <% end %> +
+ Product + + Visibility + + Make Changes +
<%= link_to product.name, product_path(product.id) %><%= "Visible to buyers" %><%= "Not visible to buyers" %><%= button_to "Edit", edit_product_path, :method => :get, params: {product_id: product.id} %>
+ + +

+ Manage Your Orders, brah. +

+<%= link_to "Manage Your Orders", orders_dashboard_path(@merchant.id), :class => "btn btn-primary btn-sm" %> + diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000000..7a3ab59f4c --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,40 @@ +<% if @new_user.errors.any? %> +

+ + Something is Broken :( +

+ +<% end %> +

+ + Sign up for DITzy! +

+
+ + <%= form_for @new_user, :url => users_path do |f| %> + <%= f.label :user_name %> + <%= f.text_field :user_name %>
+ + <%= f.label :email %> + <%= f.email_field :email %>
+ + <%= f.label :password %> + <%= f.password_field :password %>
+ + <%= f.label :password_confirmation %> + <%= f.password_field :password_confirmation %>
+ + <%= button_tag(type: 'submit', class: "btn btn-primary btn-sm",action: "create") do %> + Create Account + <% end %> + <% end %> +
+
diff --git a/app/views/users/show_merchant.html.erb b/app/views/users/show_merchant.html.erb new file mode 100644 index 0000000000..8ee255e523 --- /dev/null +++ b/app/views/users/show_merchant.html.erb @@ -0,0 +1,144 @@ +

+ + Manage Your Orders +

+ +

+ Unshipped Orders +

+ +
+ + + + + + + + + + <% @merchant_order_items.each do |data| %> + + <% if data.shipped == false %> + + + + + + + <% end %> + + <% end %> +
+ Order Product + + Order Item Number + + Order Number + + Order Time + + Order Status + + Shipping Status +
+ <%= link_to data.product.name, order_item_path(data.order.id) %> + + <%= data.id %> + + <%= link_to data.order.id, merchant_order_path(data.order.id) %> + + <%= data.order.created_at %> + + <%= data.order.status %> + + <%= form_for data do |f| %> + <%= f.label :mark_as_shipped %> + <%= f.radio_button :shipped, :true, :checked => :true %> + <%= f.submit %> + <% end %> +
+
+ +

+ Shipped Orders +

+
+ + + + + + + + + + + <% @merchant_order_items.each do |data| %> + + <% if data.shipped == true %> + + + + + + + + <% end %> + + <% end %> +
+ Order Product + + Order Item Number + + Order Number + + Order Time + + Quantity + + Sale Total + + Order Status +
+ <%= link_to data.product.name, order_item_path(data.id) %> + + <%= data.order.id %> + + <%= data.id %> + + <%= data.order.created_at %> + + <%= data.quantity %> + + <%= data.product.price_in_dollars * (data.quantity) %> + + <%= data.order.status %> +
+
+ +

+ Total Revenue +

+

+ <%= number_to_currency(@total_revenue) %> +

+

+ Total Completed Orders +

+

+ Number of Orders: <%= @completed_orders %>
+ Subtotal: <%= number_to_currency(@completed_orders_subtotal) %> +

+

+ Total Pending Orders +

+

+ Number of Orders: <%= @pending_orders %>
+ Subtotal: <%= number_to_currency(@pending_orders_subtotal) %> +

+ + + + diff --git a/app/views/users/show_merchant_order.html.erb b/app/views/users/show_merchant_order.html.erb new file mode 100644 index 0000000000..4f0bb3c2f3 --- /dev/null +++ b/app/views/users/show_merchant_order.html.erb @@ -0,0 +1,16 @@ +
+
    +
  • + Name: <%= @order.name_on_cc %> +
  • +
  • + Address: <%= @order.address %> +
  • +
  • + Email: <%= @order.email %> +
  • +
  • + Credit Card Expiration: <%= @order.expiration_on_cc %> +
  • +
+
diff --git a/app/views/users/users_products.html.erb b/app/views/users/users_products.html.erb new file mode 100644 index 0000000000..df521d48e1 --- /dev/null +++ b/app/views/users/users_products.html.erb @@ -0,0 +1,21 @@ +

+ + <%= @merchant.user_name %> +

+

+ Products +

+ +
+ <% @products.each do |product| %> + <%=image_tag("#{product.image_url}")%> + + + Product ID: + + <%= product.id %>
+ <%= link_to product.name, product_path(product.id) %>
+ <%= product.price_in_dollars %>
+
+ <%end%> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3f66539d54..56d0a0dc95 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,38 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end + + # Creates an empty cart and an order id for guests from session id + root 'sessions#create_order' + + get '/complete' => 'orders#show', as: 'complete_order' + get '/checkout' => 'orders#new', as: 'checkout' + + post '/checkout' => 'orders#create' + + + get '/cart' => 'order_item#index', as: 'cart' + post '/cart' => 'order_item#create' + delete '/cart' => 'order_item#destroy' + patch '/cart/:id' => 'order_item#update', as: 'update_cart' + get 'dashboard/:id' => 'users#show', :as => 'dashboard' + get 'dashboard/orders/:id' => 'users#show_merchant', :as => 'orders_dashboard' + get 'dashboard/order_item/:id' => 'order_item#show', :as => 'order_item' + patch 'dashboard/order_item/:id' => 'users#update_order_item' + get 'dashboard/order/:id' => 'users#show_merchant_order', :as => 'merchant_order' + get 'store/:id' => 'products#show_merchant_store', :as => 'merchant_store' + + get '/categories/:category_id/products' => 'products#show_by_category', as: "category_products" + delete '/logout' => 'sessions#destroy' + + resources :sessions, :only => [:new, :create, :destroy] + + resources :users, :only => [:new, :create] do + + end + + resources :products do + resources :reviews, :only => [:new, :create] + end + + resources :categories, :only => [:new, :create] + end diff --git a/db/migrate/20160502230623_create_users.rb b/db/migrate/20160502230623_create_users.rb new file mode 100644 index 0000000000..cd9c3a2818 --- /dev/null +++ b/db/migrate/20160502230623_create_users.rb @@ -0,0 +1,12 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.text :user_name, null: false + t.text :email, null: false + t.text :password, null: false + t.text :password_confirmation, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160502230640_create_products.rb b/db/migrate/20160502230640_create_products.rb new file mode 100644 index 0000000000..85dc351ad3 --- /dev/null +++ b/db/migrate/20160502230640_create_products.rb @@ -0,0 +1,11 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.text :name, null: false + t.decimal :price_in_dollars, null: false + t.integer :user_id, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160502230649_create_orders.rb b/db/migrate/20160502230649_create_orders.rb new file mode 100644 index 0000000000..1a17cf5af8 --- /dev/null +++ b/db/migrate/20160502230649_create_orders.rb @@ -0,0 +1,10 @@ +class CreateOrders < ActiveRecord::Migration + def change + create_table :orders do |t| + t.text :order_item_collecton + t.integer :user_id, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160502230707_create_order_items.rb b/db/migrate/20160502230707_create_order_items.rb new file mode 100644 index 0000000000..b5e1f14fc4 --- /dev/null +++ b/db/migrate/20160502230707_create_order_items.rb @@ -0,0 +1,11 @@ +class CreateOrderItems < ActiveRecord::Migration + def change + create_table :order_items do |t| + t.integer :order_id, null: false + t.integer :product_id, null: false + t.integer :quantity, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160502230715_create_reviews.rb b/db/migrate/20160502230715_create_reviews.rb new file mode 100644 index 0000000000..ce2d57bdbb --- /dev/null +++ b/db/migrate/20160502230715_create_reviews.rb @@ -0,0 +1,12 @@ +class CreateReviews < ActiveRecord::Migration + def change + create_table :reviews do |t| + t.integer :rating, null: false + t.text :review_text + t.integer :user_id + t.integer :product_id, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160503163352_add_categories_column_to_products.rb b/db/migrate/20160503163352_add_categories_column_to_products.rb new file mode 100644 index 0000000000..eebe5168f2 --- /dev/null +++ b/db/migrate/20160503163352_add_categories_column_to_products.rb @@ -0,0 +1,7 @@ +class AddCategoriesColumnToProducts < ActiveRecord::Migration + def change + change_table :products do |t| + t.text :categories + end + end +end diff --git a/db/migrate/20160503212426_add_password_digest_to_users.rb b/db/migrate/20160503212426_add_password_digest_to_users.rb new file mode 100644 index 0000000000..fef0b8a730 --- /dev/null +++ b/db/migrate/20160503212426_add_password_digest_to_users.rb @@ -0,0 +1,8 @@ +class AddPasswordDigestToUsers < ActiveRecord::Migration + def change + change_table :users do |t| + t.string :password_digest + end + end +end + diff --git a/db/migrate/20160503221632_add_quantity_column_to_products.rb b/db/migrate/20160503221632_add_quantity_column_to_products.rb new file mode 100644 index 0000000000..ce2ee4993c --- /dev/null +++ b/db/migrate/20160503221632_add_quantity_column_to_products.rb @@ -0,0 +1,7 @@ +class AddQuantityColumnToProducts < ActiveRecord::Migration + def change + change_table :products do |t| + t.integer :quantity + end + end +end diff --git a/db/migrate/20160503222018_alter_users_to_remove_pass_conf.rb b/db/migrate/20160503222018_alter_users_to_remove_pass_conf.rb new file mode 100644 index 0000000000..750689d919 --- /dev/null +++ b/db/migrate/20160503222018_alter_users_to_remove_pass_conf.rb @@ -0,0 +1,5 @@ +class AlterUsersToRemovePassConf < ActiveRecord::Migration + def change + remove_column :users, :password_confirmation + end +end diff --git a/db/migrate/20160503222610_update_users_pass_digest_to_be_not_null.rb b/db/migrate/20160503222610_update_users_pass_digest_to_be_not_null.rb new file mode 100644 index 0000000000..1845e1ee6b --- /dev/null +++ b/db/migrate/20160503222610_update_users_pass_digest_to_be_not_null.rb @@ -0,0 +1,5 @@ +class UpdateUsersPassDigestToBeNotNull < ActiveRecord::Migration + def change + change_column :users, :password_digest, :string, null: false + end +end diff --git a/db/migrate/20160505024127_remove_password_from_users.rb b/db/migrate/20160505024127_remove_password_from_users.rb new file mode 100644 index 0000000000..b29c880869 --- /dev/null +++ b/db/migrate/20160505024127_remove_password_from_users.rb @@ -0,0 +1,5 @@ +class RemovePasswordFromUsers < ActiveRecord::Migration + def change + remove_column :users, :password + end +end diff --git a/db/migrate/20160505172421_add_visibility_tracking_and_categories_to_products.rb b/db/migrate/20160505172421_add_visibility_tracking_and_categories_to_products.rb new file mode 100644 index 0000000000..aa31fa67b1 --- /dev/null +++ b/db/migrate/20160505172421_add_visibility_tracking_and_categories_to_products.rb @@ -0,0 +1,7 @@ +class AddVisibilityTrackingAndCategoriesToProducts < ActiveRecord::Migration + def change + change_table :products do |t| + t.boolean :visible + end + end +end diff --git a/db/migrate/20160505173932_add_column_for_picture_url_to_products.rb b/db/migrate/20160505173932_add_column_for_picture_url_to_products.rb new file mode 100644 index 0000000000..861552d600 --- /dev/null +++ b/db/migrate/20160505173932_add_column_for_picture_url_to_products.rb @@ -0,0 +1,7 @@ +class AddColumnForPictureUrlToProducts < ActiveRecord::Migration + def change + change_table :products do |t| + t.text :image_url + end + end +end diff --git a/db/migrate/20160506054520_add_model_for_billing.rb b/db/migrate/20160506054520_add_model_for_billing.rb new file mode 100644 index 0000000000..bb2865f4cf --- /dev/null +++ b/db/migrate/20160506054520_add_model_for_billing.rb @@ -0,0 +1,15 @@ +class AddModelForBilling < ActiveRecord::Migration + def change + create_table :billings do |t| + t.text :email, null: false + t.text :address, null: false + t.text :name_on_cc, null: false + t.integer :number_on_cc, null: false + t.text :security_on_cc, null: false + t.datetime :expiration_on_cc, null: false + t.integer :zip, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160506154408_add_catagory_table.rb b/db/migrate/20160506154408_add_catagory_table.rb new file mode 100644 index 0000000000..e3eb2ffa9f --- /dev/null +++ b/db/migrate/20160506154408_add_catagory_table.rb @@ -0,0 +1,9 @@ +class AddCatagoryTable < ActiveRecord::Migration + def change + create_table :catagory do |t| + t.text :name, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160506154631_alter_products_table_change_catagory_to_array.rb b/db/migrate/20160506154631_alter_products_table_change_catagory_to_array.rb new file mode 100644 index 0000000000..c5d304ccd8 --- /dev/null +++ b/db/migrate/20160506154631_alter_products_table_change_catagory_to_array.rb @@ -0,0 +1,6 @@ +class AlterProductsTableChangeCatagoryToArray < ActiveRecord::Migration + def change + # change_column :products, :categories, :text, array: true, default: [] + change_column :products, :categories, :text, array: true, default: [], using: "(string_to_array(categories, ' '))" + end +end diff --git a/db/migrate/20160506174042_create_categories.rb b/db/migrate/20160506174042_create_categories.rb new file mode 100644 index 0000000000..20f6143c32 --- /dev/null +++ b/db/migrate/20160506174042_create_categories.rb @@ -0,0 +1,8 @@ +class CreateCategories < ActiveRecord::Migration + def change + create_table :categories do |t| + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160506175359_remove_misspelled_table.rb b/db/migrate/20160506175359_remove_misspelled_table.rb new file mode 100644 index 0000000000..2b40f7ee9c --- /dev/null +++ b/db/migrate/20160506175359_remove_misspelled_table.rb @@ -0,0 +1,5 @@ +class RemoveMisspelledTable < ActiveRecord::Migration + def change + drop_table :catagory + end +end diff --git a/db/migrate/20160506175411_add_name_column_to_categories.rb b/db/migrate/20160506175411_add_name_column_to_categories.rb new file mode 100644 index 0000000000..7f8dc9c147 --- /dev/null +++ b/db/migrate/20160506175411_add_name_column_to_categories.rb @@ -0,0 +1,8 @@ +class AddNameColumnToCategories < ActiveRecord::Migration + def change + change_table :categories do |t| + t.text :name + end + + end +end diff --git a/db/migrate/20160506175814_add_description_to_products.rb b/db/migrate/20160506175814_add_description_to_products.rb new file mode 100644 index 0000000000..ad61861b5f --- /dev/null +++ b/db/migrate/20160506175814_add_description_to_products.rb @@ -0,0 +1,7 @@ +class AddDescriptionToProducts < ActiveRecord::Migration + def change + change_table :categories do |t| + t.text :description, null: false + end + end +end diff --git a/db/migrate/20160506182211_remove_description_from_category.rb b/db/migrate/20160506182211_remove_description_from_category.rb new file mode 100644 index 0000000000..0d9529810c --- /dev/null +++ b/db/migrate/20160506182211_remove_description_from_category.rb @@ -0,0 +1,5 @@ +class RemoveDescriptionFromCategory < ActiveRecord::Migration + def change + remove_column :categories, :description + end +end diff --git a/db/migrate/20160506182233_add_desc_to_products.rb b/db/migrate/20160506182233_add_desc_to_products.rb new file mode 100644 index 0000000000..36d5ce18e1 --- /dev/null +++ b/db/migrate/20160506182233_add_desc_to_products.rb @@ -0,0 +1,6 @@ +class AddDescToProducts < ActiveRecord::Migration + def change + add_column :products, :description, :string + end +end + diff --git a/db/migrate/20160506202957_link_categories_with_products.rb b/db/migrate/20160506202957_link_categories_with_products.rb new file mode 100644 index 0000000000..9dd99af0d3 --- /dev/null +++ b/db/migrate/20160506202957_link_categories_with_products.rb @@ -0,0 +1,6 @@ +class LinkCategoriesWithProducts < ActiveRecord::Migration + create_table :categories_products, id: false do |t| + t.belongs_to :category, index: true + t.belongs_to :product, index: true + end +end diff --git a/db/migrate/20160506204129_remove_null_from_user_id_on_order_table.rb b/db/migrate/20160506204129_remove_null_from_user_id_on_order_table.rb new file mode 100644 index 0000000000..3c264e75fa --- /dev/null +++ b/db/migrate/20160506204129_remove_null_from_user_id_on_order_table.rb @@ -0,0 +1,5 @@ +class RemoveNullFromUserIdOnOrderTable < ActiveRecord::Migration + def change + change_column :orders, :user_id, :integer, null: true + end +end diff --git a/db/migrate/20160506224928_remove_catagories_from_products.rb b/db/migrate/20160506224928_remove_catagories_from_products.rb new file mode 100644 index 0000000000..9b7a9b88a5 --- /dev/null +++ b/db/migrate/20160506224928_remove_catagories_from_products.rb @@ -0,0 +1,5 @@ +class RemoveCatagoriesFromProducts < ActiveRecord::Migration + def change + remove_column :products, :categories + end +end diff --git a/db/migrate/20160510173158_add_billingto_orders.rb b/db/migrate/20160510173158_add_billingto_orders.rb new file mode 100644 index 0000000000..51eae467b3 --- /dev/null +++ b/db/migrate/20160510173158_add_billingto_orders.rb @@ -0,0 +1,10 @@ +class AddBillingtoOrders < ActiveRecord::Migration + def change + add_column :orders, :emails, :string + add_column :orders, :address, :string + add_column :orders, :name_on_cc, :string + add_column :orders, :security_on_cc, :integer + add_column :orders, :expiration_on_cc, :datetime + add_column :orders, :zip, :integer + end +end \ No newline at end of file diff --git a/db/migrate/20160510174418_remove_column_from_orders.rb b/db/migrate/20160510174418_remove_column_from_orders.rb new file mode 100644 index 0000000000..abf7b0ad90 --- /dev/null +++ b/db/migrate/20160510174418_remove_column_from_orders.rb @@ -0,0 +1,5 @@ +class RemoveColumnFromOrders < ActiveRecord::Migration + def change + remove_column :orders, :order_item_collecton, :string + end +end diff --git a/db/migrate/20160510174550_fix_typo_in_orders.rb b/db/migrate/20160510174550_fix_typo_in_orders.rb new file mode 100644 index 0000000000..bc439362e3 --- /dev/null +++ b/db/migrate/20160510174550_fix_typo_in_orders.rb @@ -0,0 +1,6 @@ +class FixTypoInOrders < ActiveRecord::Migration + def change + remove_column :orders, :emails, :string + add_column :orders, :email, :string + end +end diff --git a/db/migrate/20160510201323_add_status_column_to_orders.rb b/db/migrate/20160510201323_add_status_column_to_orders.rb new file mode 100644 index 0000000000..50dbfc1250 --- /dev/null +++ b/db/migrate/20160510201323_add_status_column_to_orders.rb @@ -0,0 +1,5 @@ +class AddStatusColumnToOrders < ActiveRecord::Migration + def change + add_column :orders, :status, :string + end +end diff --git a/db/migrate/20160510205409_add_order_id_column_to_orders.rb b/db/migrate/20160510205409_add_order_id_column_to_orders.rb new file mode 100644 index 0000000000..36a0bdff6f --- /dev/null +++ b/db/migrate/20160510205409_add_order_id_column_to_orders.rb @@ -0,0 +1,5 @@ +class AddOrderIdColumnToOrders < ActiveRecord::Migration + def change + add_column :orders, :order_id, :integer + end +end diff --git a/db/migrate/20160511040111_add_total_column_to_orders.rb b/db/migrate/20160511040111_add_total_column_to_orders.rb new file mode 100644 index 0000000000..84b0987966 --- /dev/null +++ b/db/migrate/20160511040111_add_total_column_to_orders.rb @@ -0,0 +1,5 @@ +class AddTotalColumnToOrders < ActiveRecord::Migration + def change + add_column :orders, :total, :float + end +end diff --git a/db/migrate/20160511050101_drop_table_billings.rb b/db/migrate/20160511050101_drop_table_billings.rb new file mode 100644 index 0000000000..459f93ad11 --- /dev/null +++ b/db/migrate/20160511050101_drop_table_billings.rb @@ -0,0 +1,5 @@ +class DropTableBillings < ActiveRecord::Migration + def change + drop_table :billings + end +end diff --git a/db/migrate/20160511223657_order_items_add_shipped_column.rb b/db/migrate/20160511223657_order_items_add_shipped_column.rb new file mode 100644 index 0000000000..c9ab0c88f4 --- /dev/null +++ b/db/migrate/20160511223657_order_items_add_shipped_column.rb @@ -0,0 +1,5 @@ +class OrderItemsAddShippedColumn < ActiveRecord::Migration + def change + add_column :order_items, :shipped, :boolean, :default => false + end +end diff --git a/db/migrate/20160512161143_add_credit_card_number_to_orders.rb b/db/migrate/20160512161143_add_credit_card_number_to_orders.rb new file mode 100644 index 0000000000..0c7402959f --- /dev/null +++ b/db/migrate/20160512161143_add_credit_card_number_to_orders.rb @@ -0,0 +1,6 @@ +class AddCreditCardNumberToOrders < ActiveRecord::Migration + def change + + add_column :orders, :credit_card_number, :integer + end +end diff --git a/db/migrate/20160512234333_remove_redundant_order_id_from_order_table.rb b/db/migrate/20160512234333_remove_redundant_order_id_from_order_table.rb new file mode 100644 index 0000000000..f6b8b7ef0e --- /dev/null +++ b/db/migrate/20160512234333_remove_redundant_order_id_from_order_table.rb @@ -0,0 +1,5 @@ +class RemoveRedundantOrderIdFromOrderTable < ActiveRecord::Migration + def change + remove_column :orders, :order_id, :integer + end +end diff --git a/db/migrate/20160513163658_change_expiration_to_string.rb b/db/migrate/20160513163658_change_expiration_to_string.rb new file mode 100644 index 0000000000..33bdd6efae --- /dev/null +++ b/db/migrate/20160513163658_change_expiration_to_string.rb @@ -0,0 +1,5 @@ +class ChangeExpirationToString < ActiveRecord::Migration + def change + change_column :orders, :expiration_on_cc, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..1579b54b66 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,86 @@ +# encoding: UTF-8 +# 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: 20160513163658) 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.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "name" + end + + create_table "categories_products", id: false, force: :cascade do |t| + t.integer "category_id" + t.integer "product_id" + end + + add_index "categories_products", ["category_id"], name: "index_categories_products_on_category_id", using: :btree + add_index "categories_products", ["product_id"], name: "index_categories_products_on_product_id", using: :btree + + create_table "order_items", force: :cascade do |t| + t.integer "order_id", null: false + t.integer "product_id", null: false + t.integer "quantity", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "shipped", default: false + end + + create_table "orders", force: :cascade do |t| + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "address" + t.string "name_on_cc" + t.integer "security_on_cc" + t.string "expiration_on_cc" + t.integer "zip" + t.string "email" + t.float "total" + t.string "status" + t.integer "credit_card_number" + end + + create_table "products", force: :cascade do |t| + t.text "name", null: false + t.decimal "price_in_dollars", null: false + t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "visible" + t.integer "quantity" + t.text "image_url" + t.text "description" + end + + create_table "reviews", force: :cascade do |t| + t.integer "rating", null: false + t.text "review_text" + t.integer "user_id" + t.integer "product_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.text "user_name", null: false + t.text "email", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "password_digest", null: false + end + +end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e857e..f2983b081e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,35 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +# 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 rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) +require 'csv' + +PRODUCTS = './seed_csvs/products.csv' + +CSV.foreach(PRODUCTS, headers: true) do |row| + Product.create(row.to_h) +end + +# ORDERS = './seed_csvs/orders.csv' + +# CSV.foreach(ORDERS, headers: true) do |row| +# Order.create(row.to_h) +# end + +# USERS = './seed_csvs/users.csv' + +# CSV.foreach(USERS, headers: true) do |row| +# User.create(row.to_h) +# end + +# ORDERITEMS = './seed_csvs/orderitems.csv' + +# CSV.foreach(ORDERITEMS, headers: true) do |row| +# OrderItem.create(row.to_h) +# end \ No newline at end of file diff --git a/erd.pdf b/erd.pdf new file mode 100644 index 0000000000..75cea2b720 Binary files /dev/null and b/erd.pdf differ diff --git a/seed_csvs/orderitems.csv b/seed_csvs/orderitems.csv new file mode 100644 index 0000000000..4817a6afb6 --- /dev/null +++ b/seed_csvs/orderitems.csv @@ -0,0 +1,11 @@ +order_id,product_id,quantity +1,1,3 +1,2,1 +1,3,1 +1,4,2 +2,2,2 +2,1,1 +3,1,1 +3,3,1 +4,4,5 +4,1,1 diff --git a/seed_csvs/orders.csv b/seed_csvs/orders.csv new file mode 100644 index 0000000000..75fb5e4abe --- /dev/null +++ b/seed_csvs/orders.csv @@ -0,0 +1,4 @@ +user_id,created_at,updated_at,address,name_on_cc,security_on_cc,expiration_on_cc,zip,email +1,2016-05-07 04:35:24,2016-05-07 04:35:24,1234 elmberry lane,Joe Doe,357,2019,89667 +2,2016-05-07 04:35:24,2016-05-07 04:35:24,1234 elmberry lane,Joe Doe,357,2019,89667 +3,2016-05-07 04:35:24,2016-05-07 04:35:24,1234 elmberry lane,Joe Doe,357,2019,89667 \ No newline at end of file diff --git a/seed_csvs/products.csv b/seed_csvs/products.csv new file mode 100644 index 0000000000..1419b464bf --- /dev/null +++ b/seed_csvs/products.csv @@ -0,0 +1,12 @@ +name,price_in_dollars,user_id,visible,quantity,image_url +Wedding Football,400.99,1,true,25,http://i.imgur.com/wQnqFYA.jpg +Lipstick Heart,25,1,true,20,http://i.imgur.com/YKuk4ew.jpg +High Heel Rain Boots,80,1,true,8,http://i.imgur.com/yJBBkPY.jpg +Hairspray Can Top,5.50,2,true,50,http://i.imgur.com/qb1FYlO.jpg +Women's Toothpaste,15,2,true,10,http://i.imgur.com/hTFtY2d.jpg +Women's Rogaine,42.99,2,true,15,http://i.imgur.com/vBetXEd.jpg +Women's Screwdriver,8.50,3,true,22,http://i.imgur.com/tt19AhA.jpg +Bic Crystal Pens For Her,12,3,true,10,http://i.imgur.com/H4qUDrT.jpg +Internet Ready Eggs,14,4,true,5,http://i.imgur.com/wQ4zT8m.jpg +Sleep Pretty in Pink Earplugs,8,4,true,30,http://i.imgur.com/mJzVzq4.jpg +Digital Fun Dip,3,5,true,35,http://i.imgur.com/qb8zym0.jpg \ No newline at end of file diff --git a/seed_csvs/users.csv b/seed_csvs/users.csv 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..12ca7c1c06 --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CategoriesControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/order_item_controller_test.rb b/test/controllers/order_item_controller_test.rb new file mode 100644 index 0000000000..b24dd58b29 --- /dev/null +++ b/test/controllers/order_item_controller_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class OrderItemControllerTest < ActionController::TestCase + + # test "should get index" do + # get :index + # assert_response :success + # end + +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..0afece19aa --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrdersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000000..c881fa681b --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..9ab3149763 --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ReviewsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..d30ebc380a --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SessionsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..d23f182948 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000000..937a0c002e --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..937a0c002e --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..937a0c002e --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000000..b263406494 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,20 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +wedding_football: +# column: value + name: "Wedding Football" + price_in_dollars: 240 + user_id: 1 + visible: true + quantity: 35 +orange_zest: +# column: value + name: "Candied Orange Zest" + price_in_dollars: 67 + user_id: 1 + visible: true + quantity: 18 \ No newline at end of file diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..ee2ed0c122 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,20 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +review: + rating: 1 + review_text: yes I love this product + user_id: 2 + product_id: 1 + created_at: 2016-05-11 22:26:45 + updated_at: 2016-05-11 22:26:45 + +order_items: + order_id: 1 + product_id: 1 + quantity: 1 + created_at: 2016-05-11 22:26:45 + updated_at: 2016-05-11 22:26:45 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..937a0c002e --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000000..8abfb97cb4 --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class CategoryTest < ActiveSupport::TestCase + # test "validations: user_name can't be blank" do + # category = Category.new + + # assert_not category.valid? + # assert category.errors.keys.include?(:user_name), "user_name is not in the errors hash" + # end +end + + + + # create_table "categories", force: :cascade do |t| + # t.datetime "created_at", null: false + # t.datetime "updated_at", null: false + # t.text "name" + # end \ No newline at end of file diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..e473b9e2e1 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrderItemTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..15b8ed1348 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrderTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000000..6a66faba71 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,62 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end + + test "products must have names" do + product = Product.new + + assert_not product.valid? + assert product.errors.keys.include?(:name), "can't be empty" + end + + test "products must have a whole number quantity" do + product = Product.new + product.name = "wedding football" + product.quantity = 0.3 + product.price_in_dollars = 10 + + assert_not product.valid? + assert product.errors.keys.include?(:quantity), "is not a number" + end + + test "products must have a quantity greater than 0" do + product = Product.new + product.name = "wedding football" + product.quantity = -3 + product.price_in_dollars = 10 + + assert_not product.valid? + assert product.errors.keys.include?(:quantity), "is not a number" + end + + test "products must have a price in dollars greater than or equal to 1" do + product = Product.new + product.name = "wedding football" + product.quantity = 3 + product.price_in_dollars = 0.5 + + product_two = Product.new + product.name = "wedding football" + product.quantity = 3 + product.price_in_dollars = -6 + + assert_not product.valid? + assert product.errors.keys.include?(:price_in_dollars), "is not a number" + + assert_not product_two.valid? + assert product.errors.keys.include?(:price_in_dollars), "is not a number" + end + + test "products may take a decimal price in dollars" do + product = Product.new + product.name = "wedding football" + product.quantity = 3 + product.price_in_dollars = 1.5 + + assert product.valid? + end + +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..cb34cc0204 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' + +class ReviewTest < ActiveSupport::TestCase + test "validations: review can't be blank" do + review = Review.new + + assert_not review.valid? + assert review.errors.keys.include?(:review_text), "title is not in the errors hash" + end + +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..b3f6dacdaa --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + test "validations: user_name can't be blank" do + user = User.new + + assert_not user.valid? + assert user.errors.keys.include?(:user_name), "user_name is not in the errors hash" + end + + test "validations: email can't be blank" do + user = User.new + + assert_not user.valid? + assert user.errors.keys.include?(:email), "email is not in the errors hash" + end + + test "user model has secure password" do + user = User.new + + assert_respond_to user, :password_digest + assert_respond_to user, :authenticate, "User requires has_secure_password" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 92e39b2d78..f2d5d2e5b8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,10 +1,16 @@ +require 'simplecov' +SimpleCov.start 'rails' + ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all + # fixtures :all + fixtures :products + # fixtures :users + # Add more helper methods to be used by all tests here... end