Permalink
Browse files

adds item transaction goo. not sure about this

  • Loading branch information...
1 parent d881254 commit 7d1c6b4e01bd3d5f5e5e61a81b56531a275c6b27 @chaserx chaserx committed Jul 9, 2012
@@ -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://jashkenas.github.com/coffee-script/
@@ -0,0 +1,32 @@
+class ItemTransactionsController < ApplicationController
+ # GET /item_transactions
+ # GET /item_transactions.json
+ def index
+ @item_transactions = ItemTransaction.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @item_transactions }
+ end
+ end
+
+ # GET /item_transactions/1
+ # GET /item_transactions/1.json
+ def show
+ @item_transaction = ItemTransaction.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @item_transaction }
+ end
+ end
+
+ # POST /item_transactions
+ # POST /item_transactions.json
+ def create
+ @item_transaction = ItemTransaction.new(params[:item_transaction])
+ @item_transaction.save
+ end
+
+
+end
@@ -0,0 +1,2 @@
+module ItemTransactionsHelper
+end
View
@@ -5,6 +5,7 @@ class Item < ActiveRecord::Base
before_create :set_defaults
before_create :assign_tag_number
+ after_save :log_transaction
# TODO(chase): should set some defaults before create.
# time_checked_out should default to nil on create not Time.now
@@ -30,4 +31,9 @@ def lookup_by_tag_number(tag)
where(tag_number: tag).first
end
+ def log_transaction
+ # not sure if this is the way to do this...
+ # want to have a historical log of check-ins/out on x item
+ end
+
end
@@ -0,0 +1,3 @@
+class ItemTransaction < ActiveRecord::Base
+ attr_accessible :item_checkin_time, :item_checkout_time, :item_creation_time, :item_deletion_time, :item_id, :user_id
+end
@@ -0,0 +1,33 @@
+<h1>Listing item_transactions</h1>
+
+<table>
+ <tr>
+ <th>Item</th>
+ <th>Item creation time</th>
+ <th>Item checkin time</th>
+ <th>Item checkout time</th>
+ <th>Item deletion time</th>
+ <th>User</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @item_transactions.each do |item_transaction| %>
+ <tr>
+ <td><%= item_transaction.item_id %></td>
+ <td><%= item_transaction.item_creation_time %></td>
+ <td><%= item_transaction.item_checkin_time %></td>
+ <td><%= item_transaction.item_checkout_time %></td>
+ <td><%= item_transaction.item_deletion_time %></td>
+ <td><%= item_transaction.user_id %></td>
+ <td><%= link_to 'Show', item_transaction %></td>
+ <td><%= link_to 'Edit', edit_item_transaction_path(item_transaction) %></td>
+ <td><%= link_to 'Destroy', item_transaction, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Item transaction', new_item_transaction_path %>
@@ -0,0 +1,35 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Item:</b>
+ <%= @item_transaction.item_id %>
+</p>
+
+<p>
+ <b>Item creation time:</b>
+ <%= @item_transaction.item_creation_time %>
+</p>
+
+<p>
+ <b>Item checkin time:</b>
+ <%= @item_transaction.item_checkin_time %>
+</p>
+
+<p>
+ <b>Item checkout time:</b>
+ <%= @item_transaction.item_checkout_time %>
+</p>
+
+<p>
+ <b>Item deletion time:</b>
+ <%= @item_transaction.item_deletion_time %>
+</p>
+
+<p>
+ <b>User:</b>
+ <%= @item_transaction.user_id %>
+</p>
+
+
+<%= link_to 'Edit', edit_item_transaction_path(@item_transaction) %> |
+<%= link_to 'Back', item_transactions_path %>
View
@@ -1,4 +1,6 @@
Collector::Application.routes.draw do
+ resources :item_transactions, only: [:create, :index, :show]
+
resources :items do
member do
put :check_in
@@ -0,0 +1,14 @@
+class CreateItemTransactions < ActiveRecord::Migration
+ def change
+ create_table :item_transactions do |t|
+ t.integer :item_id
+ t.datetime :item_creation_time
+ t.datetime :item_checkin_time
+ t.datetime :item_checkout_time
+ t.datetime :item_deletion_time
+ t.integer :user_id
+
+ t.timestamps
+ end
+ end
+end
View
@@ -0,0 +1,64 @@
+# 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 to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120708224101) do
+
+ create_table "item_transactions", :force => true do |t|
+ t.integer "item_id"
+ t.datetime "item_creation_time"
+ t.datetime "item_checkin_time"
+ t.datetime "item_checkout_time"
+ t.datetime "item_deletion_time"
+ t.integer "user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "items", :force => true do |t|
+ t.string "name"
+ t.datetime "date_collected"
+ t.datetime "time_checked_in"
+ t.datetime "time_checked_out"
+ t.integer "checked_out_by"
+ t.string "tag_number"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "type"
+ t.text "desc"
+ t.boolean "checkedin", :default => true
+ t.boolean "checkedout", :default => false
+ t.string "donated_by"
+ t.string "maintained_by"
+ end
+
+ create_table "users", :force => true do |t|
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :default => "", :null => false
+ t.string "reset_password_token"
+ t.datetime "reset_password_sent_at"
+ t.datetime "remember_created_at"
+ t.integer "sign_in_count", :default => 0
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "username"
+ t.boolean "admin", :default => false
+ end
+
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
+ add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
+
+end
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ item_id: 1
+ item_creation_time: 2012-07-08 18:41:01
+ item_checkin_time: 2012-07-08 18:41:01
+ item_checkout_time: 2012-07-08 18:41:01
+ item_deletion_time: 2012-07-08 18:41:01
+ user_id: 1
+
+two:
+ item_id: 1
+ item_creation_time: 2012-07-08 18:41:01
+ item_checkin_time: 2012-07-08 18:41:01
+ item_checkout_time: 2012-07-08 18:41:01
+ item_deletion_time: 2012-07-08 18:41:01
+ user_id: 1
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ItemTransactionsControllerTest < ActionController::TestCase
+ setup do
+ @item_transaction = item_transactions(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:item_transactions)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create item_transaction" do
+ assert_difference('ItemTransaction.count') do
+ post :create, item_transaction: { item_checkin_time: @item_transaction.item_checkin_time, item_checkout_time: @item_transaction.item_checkout_time, item_creation_time: @item_transaction.item_creation_time, item_deletion_time: @item_transaction.item_deletion_time, item_id: @item_transaction.item_id, user_id: @item_transaction.user_id }
+ end
+
+ assert_redirected_to item_transaction_path(assigns(:item_transaction))
+ end
+
+ test "should show item_transaction" do
+ get :show, id: @item_transaction
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @item_transaction
+ assert_response :success
+ end
+
+ test "should update item_transaction" do
+ put :update, id: @item_transaction, item_transaction: { item_checkin_time: @item_transaction.item_checkin_time, item_checkout_time: @item_transaction.item_checkout_time, item_creation_time: @item_transaction.item_creation_time, item_deletion_time: @item_transaction.item_deletion_time, item_id: @item_transaction.item_id, user_id: @item_transaction.user_id }
+ assert_redirected_to item_transaction_path(assigns(:item_transaction))
+ end
+
+ test "should destroy item_transaction" do
+ assert_difference('ItemTransaction.count', -1) do
+ delete :destroy, id: @item_transaction
+ end
+
+ assert_redirected_to item_transactions_path
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ItemTransactionsHelperTest < ActionView::TestCase
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ItemTransactionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 7d1c6b4

Please sign in to comment.