diff --git a/app/assets/javascripts/boxes.js b/app/assets/javascripts/boxes.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/boxes.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/purchases.js b/app/assets/javascripts/purchases.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/purchases.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/boxes.css b/app/assets/stylesheets/boxes.css new file mode 100644 index 00000000..afad32db --- /dev/null +++ b/app/assets/stylesheets/boxes.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/purchases.css b/app/assets/stylesheets/purchases.css new file mode 100644 index 00000000..afad32db --- /dev/null +++ b/app/assets/stylesheets/purchases.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/boxes_controller.rb b/app/controllers/boxes_controller.rb new file mode 100644 index 00000000..ada2b541 --- /dev/null +++ b/app/controllers/boxes_controller.rb @@ -0,0 +1,74 @@ +class BoxesController < ApplicationController + before_action :set_box, only: [:show, :edit, :update, :destroy] + + # GET /boxes + # GET /boxes.json + def index + @boxes = Box.all + end + + # GET /boxes/1 + # GET /boxes/1.json + def show + end + + # GET /boxes/new + def new + @box = Box.new + end + + # GET /boxes/1/edit + def edit + end + + # POST /boxes + # POST /boxes.json + def create + @box = Box.new(box_params) + + respond_to do |format| + if @box.save + format.html { redirect_to @box, notice: 'Box was successfully created.' } + format.json { render :show, status: :created, location: @box } + else + format.html { render :new } + format.json { render json: @box.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /boxes/1 + # PATCH/PUT /boxes/1.json + def update + respond_to do |format| + if @box.update(box_params) + format.html { redirect_to @box, notice: 'Box was successfully updated.' } + format.json { render :show, status: :ok, location: @box } + else + format.html { render :edit } + format.json { render json: @box.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /boxes/1 + # DELETE /boxes/1.json + def destroy + @box.destroy + respond_to do |format| + format.html { redirect_to boxes_url, notice: 'Box was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_box + @box = Box.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def box_params + params.require(:box).permit(:box_request_id, :designed_by_id, :design_reviewed_by_id, :assembled_by_id, :shipped_by_id, :shipping_payment_id, :shipped_at, :shipment_tracking_number) + end +end diff --git a/app/controllers/purchases_controller.rb b/app/controllers/purchases_controller.rb new file mode 100644 index 00000000..562917ba --- /dev/null +++ b/app/controllers/purchases_controller.rb @@ -0,0 +1,74 @@ +class PurchasesController < ApplicationController + before_action :set_purchase, only: [:show, :edit, :update, :destroy] + + # GET /purchases + # GET /purchases.json + def index + @purchases = Purchase.all + end + + # GET /purchases/1 + # GET /purchases/1.json + def show + end + + # GET /purchases/new + def new + @purchase = Purchase.new + end + + # GET /purchases/1/edit + def edit + end + + # POST /purchases + # POST /purchases.json + def create + @purchase = Purchase.new(purchase_params) + + respond_to do |format| + if @purchase.save + format.html { redirect_to @purchase, notice: 'Purchase was successfully created.' } + format.json { render :show, status: :created, location: @purchase } + else + format.html { render :new } + format.json { render json: @purchase.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /purchases/1 + # PATCH/PUT /purchases/1.json + def update + respond_to do |format| + if @purchase.update(purchase_params) + format.html { redirect_to @purchase, notice: 'Purchase was successfully updated.' } + format.json { render :show, status: :ok, location: @purchase } + else + format.html { render :edit } + format.json { render json: @purchase.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /purchases/1 + # DELETE /purchases/1.json + def destroy + @purchase.destroy + respond_to do |format| + format.html { redirect_to purchases_url, notice: 'Purchase was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_purchase + @purchase = Purchase.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def purchase_params + params.require(:purchase).permit(:location_id, :total_price, :purchased_by_id, :reimbursed_by_id, :reimbursement_check_number, :reimbursement_status) + end +end diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb new file mode 100644 index 00000000..17fa1bf2 --- /dev/null +++ b/app/helpers/boxes_helper.rb @@ -0,0 +1,2 @@ +module BoxesHelper +end diff --git a/app/helpers/purchases_helper.rb b/app/helpers/purchases_helper.rb new file mode 100644 index 00000000..f3c416f5 --- /dev/null +++ b/app/helpers/purchases_helper.rb @@ -0,0 +1,2 @@ +module PurchasesHelper +end diff --git a/app/models/box.rb b/app/models/box.rb new file mode 100644 index 00000000..3f6aed7b --- /dev/null +++ b/app/models/box.rb @@ -0,0 +1,8 @@ +class Box < ApplicationRecord + belongs_to :box_request + belongs_to :designed_by, optional: true, class_name: "User", foreign_key: :designed_by_id, inverse_of: :boxes_as_designer + belongs_to :design_reviewed_by, optional: true, class_name: "User", foreign_key: :design_reviewed_by_id, inverse_of: :boxes_as_design_reviewer + belongs_to :assembled_by, optional: true, class_name: "User", foreign_key: :assembled_by_id, inverse_of: :boxes_as_assembler + belongs_to :shipped_by, optional: true, class_name: "User", foreign_key: :shipped_by_id, inverse_of: :boxes_as_shipper + belongs_to :shipping_payment, optional: true, class_name: "Purchase", foreign_key: :shipping_payment_id, inverse_of: :payment_for_shipment +end diff --git a/app/models/purchase.rb b/app/models/purchase.rb new file mode 100644 index 00000000..47fad3b0 --- /dev/null +++ b/app/models/purchase.rb @@ -0,0 +1,5 @@ +class Purchase < ApplicationRecord + belongs_to :location + belongs_to :purchased_by, optional: true, class_name: "User", foreign_key: :purchased_by_id, inverse_of: :purchases + belongs_to :reimbursed_by, optional: true, class_name: "User", foreign_key: :reimbursed_by_id, inverse_of: :reimbursed_purchases +end diff --git a/app/models/user.rb b/app/models/user.rb index 47567994..c092b727 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,9 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable + + has_many :boxes_as_designer, class_name: "Box", foreign_key: :designed_by_id, inverse_of: :designed_by, dependent: :nullify + has_many :boxes_as_design_reviewer, class_name: "Box", foreign_key: :design_reviewed_by_id, inverse_of: :designed_reviewed_by, dependent: :nullify + has_many :boxes_as_assembler, class_name: "Box", foreign_key: :assembled_by_id, inverse_of: :assembled_by, dependent: :nullify + has_many :boxes_as_shipper, class_name: "Box", foreign_key: :shipped_by_id, inverse_of: :shipped_by, dependent: :nullify end diff --git a/app/views/boxes/_box.json.jbuilder b/app/views/boxes/_box.json.jbuilder new file mode 100644 index 00000000..b1ed9df4 --- /dev/null +++ b/app/views/boxes/_box.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! box, :id, :box_request_id, :designed_by_id, :design_reviewed_by_id, :assembled_by_id, :shipped_by_id, :shipping_payment_id, :shipped_at, :shipment_tracking_number, :created_at, :updated_at +json.url box_url(box, format: :json) diff --git a/app/views/boxes/_form.html.erb b/app/views/boxes/_form.html.erb new file mode 100644 index 00000000..17757707 --- /dev/null +++ b/app/views/boxes/_form.html.erb @@ -0,0 +1,57 @@ +<%= form_with(model: box, local: true) do |form| %> + <% if box.errors.any? %> +
+

<%= pluralize(box.errors.count, "error") %> prohibited this box from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :box_request_id %> + <%= form.text_field :box_request_id %> +
+ +
+ <%= form.label :designed_by_id %> + <%= form.text_field :designed_by_id %> +
+ +
+ <%= form.label :design_reviewed_by_id %> + <%= form.text_field :design_reviewed_by_id %> +
+ +
+ <%= form.label :assembled_by_id %> + <%= form.text_field :assembled_by_id %> +
+ +
+ <%= form.label :shipped_by_id %> + <%= form.text_field :shipped_by_id %> +
+ +
+ <%= form.label :shipping_payment_id %> + <%= form.text_field :shipping_payment_id %> +
+ +
+ <%= form.label :shipped_at %> + <%= form.datetime_select :shipped_at %> +
+ +
+ <%= form.label :shipment_tracking_number %> + <%= form.text_field :shipment_tracking_number %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/boxes/edit.html.erb b/app/views/boxes/edit.html.erb new file mode 100644 index 00000000..d7e85ab3 --- /dev/null +++ b/app/views/boxes/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Box

+ +<%= render 'form', box: @box %> + +<%= link_to 'Show', @box %> | +<%= link_to 'Back', boxes_path %> diff --git a/app/views/boxes/index.html.erb b/app/views/boxes/index.html.erb new file mode 100644 index 00000000..3813b008 --- /dev/null +++ b/app/views/boxes/index.html.erb @@ -0,0 +1,41 @@ +

<%= notice %>

+ +

Boxes

+ + + + + + + + + + + + + + + + + + <% @boxes.each do |box| %> + + + + + + + + + + + + + + <% end %> + +
Box requestDesigned byDesign reviewed byAssembled byShipped byShipping paymentShipped atShipment tracking number
<%= box.box_request %><%= box.designed_by %><%= box.design_reviewed_by %><%= box.assembled_by %><%= box.shipped_by %><%= box.shipping_payment %><%= box.shipped_at %><%= box.shipment_tracking_number %><%= link_to 'Show', box %><%= link_to 'Edit', edit_box_path(box) %><%= link_to 'Destroy', box, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Box', new_box_path %> diff --git a/app/views/boxes/index.json.jbuilder b/app/views/boxes/index.json.jbuilder new file mode 100644 index 00000000..7b1d4c21 --- /dev/null +++ b/app/views/boxes/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @boxes, partial: "boxes/box", as: :box diff --git a/app/views/boxes/new.html.erb b/app/views/boxes/new.html.erb new file mode 100644 index 00000000..0aeb5e7d --- /dev/null +++ b/app/views/boxes/new.html.erb @@ -0,0 +1,5 @@ +

New Box

+ +<%= render 'form', box: @box %> + +<%= link_to 'Back', boxes_path %> diff --git a/app/views/boxes/show.html.erb b/app/views/boxes/show.html.erb new file mode 100644 index 00000000..ae7d5120 --- /dev/null +++ b/app/views/boxes/show.html.erb @@ -0,0 +1,44 @@ +

<%= notice %>

+ +

+ Box request: + <%= @box.box_request %> +

+ +

+ Designed by: + <%= @box.designed_by %> +

+ +

+ Design reviewed by: + <%= @box.design_reviewed_by %> +

+ +

+ Assembled by: + <%= @box.assembled_by %> +

+ +

+ Shipped by: + <%= @box.shipped_by %> +

+ +

+ Shipping payment: + <%= @box.shipping_payment %> +

+ +

+ Shipped at: + <%= @box.shipped_at %> +

+ +

+ Shipment tracking number: + <%= @box.shipment_tracking_number %> +

+ +<%= link_to 'Edit', edit_box_path(@box) %> | +<%= link_to 'Back', boxes_path %> diff --git a/app/views/boxes/show.json.jbuilder b/app/views/boxes/show.json.jbuilder new file mode 100644 index 00000000..70fea382 --- /dev/null +++ b/app/views/boxes/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "boxes/box", box: @box diff --git a/app/views/purchases/_form.html.erb b/app/views/purchases/_form.html.erb new file mode 100644 index 00000000..cc682192 --- /dev/null +++ b/app/views/purchases/_form.html.erb @@ -0,0 +1,47 @@ +<%= form_with(model: purchase, local: true) do |form| %> + <% if purchase.errors.any? %> +
+

<%= pluralize(purchase.errors.count, "error") %> prohibited this purchase from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :location_id %> + <%= form.text_field :location_id %> +
+ +
+ <%= form.label :total_price %> + <%= form.text_field :total_price %> +
+ +
+ <%= form.label :purchased_by_id %> + <%= form.text_field :purchased_by_id %> +
+ +
+ <%= form.label :reimbursed_by_id %> + <%= form.text_field :reimbursed_by_id %> +
+ +
+ <%= form.label :reimbursement_check_number %> + <%= form.text_field :reimbursement_check_number %> +
+ +
+ <%= form.label :reimbursement_status %> + <%= form.text_field :reimbursement_status %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/purchases/_purchase.json.jbuilder b/app/views/purchases/_purchase.json.jbuilder new file mode 100644 index 00000000..2234f292 --- /dev/null +++ b/app/views/purchases/_purchase.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! purchase, :id, :location_id, :total_price, :purchased_by_id, :reimbursed_by_id, :reimbursement_check_number, :reimbursement_status, :created_at, :updated_at +json.url purchase_url(purchase, format: :json) diff --git a/app/views/purchases/edit.html.erb b/app/views/purchases/edit.html.erb new file mode 100644 index 00000000..3ab655cb --- /dev/null +++ b/app/views/purchases/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Purchase

+ +<%= render 'form', purchase: @purchase %> + +<%= link_to 'Show', @purchase %> | +<%= link_to 'Back', purchases_path %> diff --git a/app/views/purchases/index.html.erb b/app/views/purchases/index.html.erb new file mode 100644 index 00000000..9841e3e7 --- /dev/null +++ b/app/views/purchases/index.html.erb @@ -0,0 +1,37 @@ +

<%= notice %>

+ +

Purchases

+ + + + + + + + + + + + + + + + <% @purchases.each do |purchase| %> + + + + + + + + + + + + <% end %> + +
LocationTotal pricePurchased byReimbursed byReimbursement check numberReimbursement status
<%= purchase.location %><%= purchase.total_price %><%= purchase.purchased_by %><%= purchase.reimbursed_by %><%= purchase.reimbursement_check_number %><%= purchase.reimbursement_status %><%= link_to 'Show', purchase %><%= link_to 'Edit', edit_purchase_path(purchase) %><%= link_to 'Destroy', purchase, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Purchase', new_purchase_path %> diff --git a/app/views/purchases/index.json.jbuilder b/app/views/purchases/index.json.jbuilder new file mode 100644 index 00000000..90e1a957 --- /dev/null +++ b/app/views/purchases/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @purchases, partial: "purchases/purchase", as: :purchase diff --git a/app/views/purchases/new.html.erb b/app/views/purchases/new.html.erb new file mode 100644 index 00000000..71afba2e --- /dev/null +++ b/app/views/purchases/new.html.erb @@ -0,0 +1,5 @@ +

New Purchase

+ +<%= render 'form', purchase: @purchase %> + +<%= link_to 'Back', purchases_path %> diff --git a/app/views/purchases/show.html.erb b/app/views/purchases/show.html.erb new file mode 100644 index 00000000..e6e8245e --- /dev/null +++ b/app/views/purchases/show.html.erb @@ -0,0 +1,34 @@ +

<%= notice %>

+ +

+ Location: + <%= @purchase.location %> +

+ +

+ Total price: + <%= @purchase.total_price %> +

+ +

+ Purchased by: + <%= @purchase.purchased_by %> +

+ +

+ Reimbursed by: + <%= @purchase.reimbursed_by %> +

+ +

+ Reimbursement check number: + <%= @purchase.reimbursement_check_number %> +

+ +

+ Reimbursement status: + <%= @purchase.reimbursement_status %> +

+ +<%= link_to 'Edit', edit_purchase_path(@purchase) %> | +<%= link_to 'Back', purchases_path %> diff --git a/app/views/purchases/show.json.jbuilder b/app/views/purchases/show.json.jbuilder new file mode 100644 index 00000000..50fb1c2a --- /dev/null +++ b/app/views/purchases/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "purchases/purchase", purchase: @purchase diff --git a/config/routes.rb b/config/routes.rb index be3ce257..d943f93c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,12 @@ Rails.application.routes.draw do + resources :purchases devise_for :users, controllers: { passwords: 'users/passwords', sessions: "users/sessions" } resources :locations resources :meetings + resources :boxes resources :volunteers resources :box_requests resources :requesters diff --git a/db/migrate/20190726200525_create_boxes.rb b/db/migrate/20190726200525_create_boxes.rb new file mode 100644 index 00000000..b2b44134 --- /dev/null +++ b/db/migrate/20190726200525_create_boxes.rb @@ -0,0 +1,16 @@ +class CreateBoxes < ActiveRecord::Migration[5.2] + def change + create_table :boxes do |t| + t.references :box_request, foreign_key: true, null: false, index: true + t.references :designed_by, foreign_table_name: :user, null: true, index: true + t.references :design_reviewed_by, foreign_table_name: :user, null: true, index: true + t.references :assembled_by, foreign_table_name: :user, null: true, index: true + t.references :shipped_by, foreign_table_name: :user, null: true, index: true + t.references :shipping_payment, foreign_table_name: :purchase, null: true, index: true + t.datetime :shipped_at + t.string :shipment_tracking_number + + t.timestamps + end + end +end diff --git a/db/migrate/20190726205736_create_purchases.rb b/db/migrate/20190726205736_create_purchases.rb new file mode 100644 index 00000000..0f236bb8 --- /dev/null +++ b/db/migrate/20190726205736_create_purchases.rb @@ -0,0 +1,14 @@ +class CreatePurchases < ActiveRecord::Migration[5.2] + def change + create_table :purchases do |t| + t.references :location, foreign_key: true, null: true, index: true + t.float :total_price + t.references :purchased_by + t.references :reimbursed_by + t.string :reimbursement_check_number + t.string :reimbursement_status + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 088f05f4..bea65ee3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -70,6 +70,25 @@ t.index ["requester_id"], name: "index_box_requests_on_requester_id" end + create_table "boxes", force: :cascade do |t| + t.bigint "box_request_id", null: false + t.bigint "designed_by_id" + t.bigint "design_reviewed_by_id" + t.bigint "assembled_by_id" + t.bigint "shipped_by_id" + t.bigint "shipping_payment_id" + t.datetime "shipped_at" + t.string "shipment_tracking_number" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["assembled_by_id"], name: "index_boxes_on_assembled_by_id" + t.index ["box_request_id"], name: "index_boxes_on_box_request_id" + t.index ["design_reviewed_by_id"], name: "index_boxes_on_design_reviewed_by_id" + t.index ["designed_by_id"], name: "index_boxes_on_designed_by_id" + t.index ["shipped_by_id"], name: "index_boxes_on_shipped_by_id" + t.index ["shipping_payment_id"], name: "index_boxes_on_shipping_payment_id" + end + create_table "core_box_items", force: :cascade do |t| t.bigint "abuse_type_id", null: false t.bigint "inventory_type_id", null: false @@ -129,6 +148,20 @@ t.index ["meeting_type_id"], name: "index_meetings_on_meeting_type_id" end + create_table "purchases", force: :cascade do |t| + t.bigint "location_id" + t.float "total_price" + t.bigint "purchased_by_id" + t.bigint "reimbursed_by_id" + t.string "reimbursement_check_number" + t.string "reimbursement_status" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["location_id"], name: "index_purchases_on_location_id" + t.index ["purchased_by_id"], name: "index_purchases_on_purchased_by_id" + t.index ["reimbursed_by_id"], name: "index_purchases_on_reimbursed_by_id" + end + create_table "requesters", force: :cascade do |t| t.string "first_name" t.string "last_name" @@ -208,9 +241,11 @@ end add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "boxes", "box_requests" add_foreign_key "core_box_items", "abuse_types" add_foreign_key "core_box_items", "inventory_types" add_foreign_key "inventory_tallies", "locations", column: "storage_location_id" add_foreign_key "meetings", "locations" add_foreign_key "meetings", "meeting_types" + add_foreign_key "purchases", "locations" end diff --git a/spec/controllers/purchases_controller_spec.rb b/spec/controllers/purchases_controller_spec.rb new file mode 100644 index 00000000..abe33b5e --- /dev/null +++ b/spec/controllers/purchases_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe PurchasesController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Purchase. As you add validations to Purchase, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # PurchasesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Purchase.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + purchase = Purchase.create! valid_attributes + get :show, params: {id: purchase.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + purchase = Purchase.create! valid_attributes + get :edit, params: {id: purchase.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Purchase" do + expect { + post :create, params: {purchase: valid_attributes}, session: valid_session + }.to change(Purchase, :count).by(1) + end + + it "redirects to the created purchase" do + post :create, params: {purchase: valid_attributes}, session: valid_session + expect(response).to redirect_to(Purchase.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {purchase: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested purchase" do + purchase = Purchase.create! valid_attributes + put :update, params: {id: purchase.to_param, purchase: new_attributes}, session: valid_session + purchase.reload + skip("Add assertions for updated state") + end + + it "redirects to the purchase" do + purchase = Purchase.create! valid_attributes + put :update, params: {id: purchase.to_param, purchase: valid_attributes}, session: valid_session + expect(response).to redirect_to(purchase) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + purchase = Purchase.create! valid_attributes + put :update, params: {id: purchase.to_param, purchase: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested purchase" do + purchase = Purchase.create! valid_attributes + expect { + delete :destroy, params: {id: purchase.to_param}, session: valid_session + }.to change(Purchase, :count).by(-1) + end + + it "redirects to the purchases list" do + purchase = Purchase.create! valid_attributes + delete :destroy, params: {id: purchase.to_param}, session: valid_session + expect(response).to redirect_to(purchases_url) + end + end + +end diff --git a/spec/helpers/purchases_helper_spec.rb b/spec/helpers/purchases_helper_spec.rb new file mode 100644 index 00000000..2cd5a8fa --- /dev/null +++ b/spec/helpers/purchases_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the PurchasesHelper. For example: +# +# describe PurchasesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe PurchasesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/purchase_spec.rb b/spec/models/purchase_spec.rb new file mode 100644 index 00000000..40736092 --- /dev/null +++ b/spec/models/purchase_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Purchase, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/purchases_spec.rb b/spec/requests/purchases_spec.rb new file mode 100644 index 00000000..15a6f311 --- /dev/null +++ b/spec/requests/purchases_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Purchases", type: :request do + describe "GET /purchases" do + it "works! (now write some real specs)" do + get purchases_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/purchases_routing_spec.rb b/spec/routing/purchases_routing_spec.rb new file mode 100644 index 00000000..5ca59a5d --- /dev/null +++ b/spec/routing/purchases_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe PurchasesController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/purchases").to route_to("purchases#index") + end + + it "routes to #new" do + expect(:get => "/purchases/new").to route_to("purchases#new") + end + + it "routes to #show" do + expect(:get => "/purchases/1").to route_to("purchases#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/purchases/1/edit").to route_to("purchases#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/purchases").to route_to("purchases#create") + end + + it "routes to #update via PUT" do + expect(:put => "/purchases/1").to route_to("purchases#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/purchases/1").to route_to("purchases#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/purchases/1").to route_to("purchases#destroy", :id => "1") + end + end +end diff --git a/spec/views/purchases/edit.html.erb_spec.rb b/spec/views/purchases/edit.html.erb_spec.rb new file mode 100644 index 00000000..3d0139f3 --- /dev/null +++ b/spec/views/purchases/edit.html.erb_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe "purchases/edit", type: :view do + before(:each) do + @purchase = assign(:purchase, Purchase.create!( + :location => nil, + :total_price => 1.5, + :purchased_by => nil, + :reimbursed_by => nil, + :reimbursement_check_number => "MyString", + :reimbursement_status => "MyString" + )) + end + + it "renders the edit purchase form" do + render + + assert_select "form[action=?][method=?]", purchase_path(@purchase), "post" do + + assert_select "input[name=?]", "purchase[location_id]" + + assert_select "input[name=?]", "purchase[total_price]" + + assert_select "input[name=?]", "purchase[purchased_by_id]" + + assert_select "input[name=?]", "purchase[reimbursed_by_id]" + + assert_select "input[name=?]", "purchase[reimbursement_check_number]" + + assert_select "input[name=?]", "purchase[reimbursement_status]" + end + end +end diff --git a/spec/views/purchases/index.html.erb_spec.rb b/spec/views/purchases/index.html.erb_spec.rb new file mode 100644 index 00000000..c250c8dd --- /dev/null +++ b/spec/views/purchases/index.html.erb_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe "purchases/index", type: :view do + before(:each) do + assign(:purchases, [ + Purchase.create!( + :location => nil, + :total_price => 2.5, + :purchased_by => nil, + :reimbursed_by => nil, + :reimbursement_check_number => "Reimbursement Check Number", + :reimbursement_status => "Reimbursement Status" + ), + Purchase.create!( + :location => nil, + :total_price => 2.5, + :purchased_by => nil, + :reimbursed_by => nil, + :reimbursement_check_number => "Reimbursement Check Number", + :reimbursement_status => "Reimbursement Status" + ) + ]) + end + + it "renders a list of purchases" do + render + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => 2.5.to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => "Reimbursement Check Number".to_s, :count => 2 + assert_select "tr>td", :text => "Reimbursement Status".to_s, :count => 2 + end +end diff --git a/spec/views/purchases/new.html.erb_spec.rb b/spec/views/purchases/new.html.erb_spec.rb new file mode 100644 index 00000000..6fcbb9df --- /dev/null +++ b/spec/views/purchases/new.html.erb_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe "purchases/new", type: :view do + before(:each) do + assign(:purchase, Purchase.new( + :location => nil, + :total_price => 1.5, + :purchased_by => nil, + :reimbursed_by => nil, + :reimbursement_check_number => "MyString", + :reimbursement_status => "MyString" + )) + end + + it "renders new purchase form" do + render + + assert_select "form[action=?][method=?]", purchases_path, "post" do + + assert_select "input[name=?]", "purchase[location_id]" + + assert_select "input[name=?]", "purchase[total_price]" + + assert_select "input[name=?]", "purchase[purchased_by_id]" + + assert_select "input[name=?]", "purchase[reimbursed_by_id]" + + assert_select "input[name=?]", "purchase[reimbursement_check_number]" + + assert_select "input[name=?]", "purchase[reimbursement_status]" + end + end +end diff --git a/spec/views/purchases/show.html.erb_spec.rb b/spec/views/purchases/show.html.erb_spec.rb new file mode 100644 index 00000000..594e1adf --- /dev/null +++ b/spec/views/purchases/show.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "purchases/show", type: :view do + before(:each) do + @purchase = assign(:purchase, Purchase.create!( + :location => nil, + :total_price => 2.5, + :purchased_by => nil, + :reimbursed_by => nil, + :reimbursement_check_number => "Reimbursement Check Number", + :reimbursement_status => "Reimbursement Status" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(//) + expect(rendered).to match(/2.5/) + expect(rendered).to match(//) + expect(rendered).to match(//) + expect(rendered).to match(/Reimbursement Check Number/) + expect(rendered).to match(/Reimbursement Status/) + end +end diff --git a/test/controllers/boxes_controller_test.rb b/test/controllers/boxes_controller_test.rb new file mode 100644 index 00000000..f2550797 --- /dev/null +++ b/test/controllers/boxes_controller_test.rb @@ -0,0 +1,48 @@ +require 'test_helper' + +class BoxesControllerTest < ActionDispatch::IntegrationTest + setup do + @box = boxes(:one) + end + + test "should get index" do + get boxes_url + assert_response :success + end + + test "should get new" do + get new_box_url + assert_response :success + end + + test "should create box" do + assert_difference('Box.count') do + post boxes_url, params: { box: { assembled_by_id: @box.assembled_by_id, box_request_id: @box.box_request_id, design_reviewed_by_id: @box.design_reviewed_by_id, designed_by_id: @box.designed_by_id, shipment_tracking_number: @box.shipment_tracking_number, shipped_at: @box.shipped_at, shipped_by_id: @box.shipped_by_id, shipping_payment_id: @box.shipping_payment_id } } + end + + assert_redirected_to box_url(Box.last) + end + + test "should show box" do + get box_url(@box) + assert_response :success + end + + test "should get edit" do + get edit_box_url(@box) + assert_response :success + end + + test "should update box" do + patch box_url(@box), params: { box: { assembled_by_id: @box.assembled_by_id, box_request_id: @box.box_request_id, design_reviewed_by_id: @box.design_reviewed_by_id, designed_by_id: @box.designed_by_id, shipment_tracking_number: @box.shipment_tracking_number, shipped_at: @box.shipped_at, shipped_by_id: @box.shipped_by_id, shipping_payment_id: @box.shipping_payment_id } } + assert_redirected_to box_url(@box) + end + + test "should destroy box" do + assert_difference('Box.count', -1) do + delete box_url(@box) + end + + assert_redirected_to boxes_url + end +end diff --git a/test/fixtures/boxes.yml b/test/fixtures/boxes.yml new file mode 100644 index 00000000..38a5e93e --- /dev/null +++ b/test/fixtures/boxes.yml @@ -0,0 +1,21 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + box_request: one + designed_by: one + design_reviewed_by: one + assembled_by: one + shipped_by: one + shipping_payment: one + shipped_at: 2019-07-26 16:05:25 + shipment_tracking_number: MyString + +two: + box_request: two + designed_by: two + design_reviewed_by: two + assembled_by: two + shipped_by: two + shipping_payment: two + shipped_at: 2019-07-26 16:05:25 + shipment_tracking_number: MyString diff --git a/test/models/box_test.rb b/test/models/box_test.rb new file mode 100644 index 00000000..42107f56 --- /dev/null +++ b/test/models/box_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BoxTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/boxes_test.rb b/test/system/boxes_test.rb new file mode 100644 index 00000000..973378b3 --- /dev/null +++ b/test/system/boxes_test.rb @@ -0,0 +1,57 @@ +require "application_system_test_case" + +class BoxesTest < ApplicationSystemTestCase + setup do + @box = boxes(:one) + end + + test "visiting the index" do + visit boxes_url + assert_selector "h1", text: "Boxes" + end + + test "creating a Box" do + visit boxes_url + click_on "New Box" + + fill_in "Assembled by", with: @box.assembled_by_id + fill_in "Box request", with: @box.box_request_id + fill_in "Design reviewed by", with: @box.design_reviewed_by_id + fill_in "Designed by", with: @box.designed_by_id + fill_in "Shipment tracking number", with: @box.shipment_tracking_number + fill_in "Shipped at", with: @box.shipped_at + fill_in "Shipped by", with: @box.shipped_by_id + fill_in "Shipping payment", with: @box.shipping_payment_id + click_on "Create Box" + + assert_text "Box was successfully created" + click_on "Back" + end + + test "updating a Box" do + visit boxes_url + click_on "Edit", match: :first + + fill_in "Assembled by", with: @box.assembled_by_id + fill_in "Box request", with: @box.box_request_id + fill_in "Design reviewed by", with: @box.design_reviewed_by_id + fill_in "Designed by", with: @box.designed_by_id + fill_in "Shipment tracking number", with: @box.shipment_tracking_number + fill_in "Shipped at", with: @box.shipped_at + fill_in "Shipped by", with: @box.shipped_by_id + fill_in "Shipping payment", with: @box.shipping_payment_id + click_on "Update Box" + + assert_text "Box was successfully updated" + click_on "Back" + end + + test "destroying a Box" do + visit boxes_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Box was successfully destroyed" + end +end