From 9145563a8d27360910c3de21b088f68283f33ba3 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Fri, 23 Nov 2007 17:54:50 -0800 Subject: [PATCH] Remove Bitem It was no longer necessary. We added purchases using STI which totally blew the COItem and BItem approach out of the water. Signed-off-by: Ira W. Snyder --- app/controllers/bitem_controller.rb | 51 ------------- app/helpers/bitem_helper.rb | 2 - app/models/bitem.rb | 18 ----- app/models/customer.rb | 1 - app/views/bitem/_form.rhtml | 13 ---- app/views/bitem/edit.rhtml | 9 --- app/views/bitem/list.rhtml | 31 -------- app/views/bitem/new.rhtml | 8 -- app/views/bitem/show.rhtml | 8 -- app/views/layouts/bitem.rhtml | 17 ----- db/development.sqlite3 | Bin 24576 -> 24576 bytes db/migrate/026_drop_bitems.rb | 13 ++++ db/schema.rb | 8 +- test/fixtures/bitems.yml | 5 -- test/functional/bitem_controller_test.rb | 92 ----------------------- test/unit/bitem_test.rb | 10 --- 16 files changed, 14 insertions(+), 272 deletions(-) delete mode 100644 app/controllers/bitem_controller.rb delete mode 100644 app/helpers/bitem_helper.rb delete mode 100644 app/models/bitem.rb delete mode 100644 app/views/bitem/_form.rhtml delete mode 100644 app/views/bitem/edit.rhtml delete mode 100644 app/views/bitem/list.rhtml delete mode 100644 app/views/bitem/new.rhtml delete mode 100644 app/views/bitem/show.rhtml delete mode 100644 app/views/layouts/bitem.rhtml create mode 100644 db/migrate/026_drop_bitems.rb delete mode 100644 test/fixtures/bitems.yml delete mode 100644 test/functional/bitem_controller_test.rb delete mode 100644 test/unit/bitem_test.rb diff --git a/app/controllers/bitem_controller.rb b/app/controllers/bitem_controller.rb deleted file mode 100644 index 4cae2e6..0000000 --- a/app/controllers/bitem_controller.rb +++ /dev/null @@ -1,51 +0,0 @@ -class BitemController < ApplicationController - def index - list - render :action => 'list' - end - - # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) - verify :method => :post, :only => [ :destroy, :create, :update ], - :redirect_to => { :action => :list } - - def list - @bitem_pages, @bitems = paginate :bitems, :per_page => 10 - end - - def show - @bitem = Bitem.find(params[:id]) - end - - def new - @bitem = Bitem.new - end - - def create - @bitem = Bitem.new(params[:bitem]) - if @bitem.save - flash[:notice] = 'Bitem was successfully created.' - redirect_to :action => 'list' - else - render :action => 'new' - end - end - - def edit - @bitem = Bitem.find(params[:id]) - end - - def update - @bitem = Bitem.find(params[:id]) - if @bitem.update_attributes(params[:bitem]) - flash[:notice] = 'Bitem was successfully updated.' - redirect_to :action => 'show', :id => @bitem - else - render :action => 'edit' - end - end - - def destroy - Bitem.find(params[:id]).destroy - redirect_to :action => 'list' - end -end diff --git a/app/helpers/bitem_helper.rb b/app/helpers/bitem_helper.rb deleted file mode 100644 index 5678936..0000000 --- a/app/helpers/bitem_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module BitemHelper -end diff --git a/app/models/bitem.rb b/app/models/bitem.rb deleted file mode 100644 index 8dfaf81..0000000 --- a/app/models/bitem.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Bitem < ActiveRecord::Base - belongs_to :customer - belongs_to :merchandise - - validates_presence_of :date - validates_presence_of :customer_id - validates_presence_of :merchandise_id - validates_numericality_of :customer_id - validates_numericality_of :merchandise_id - validates_associated :customer - validates_associated :merchandise - - protected - def validate - errors.add(:customer_id, "does not exist is the database") if customer.nil? - errors.add(:merchandise_id, "does not exist in the database") if merchandise.nil? - end -end diff --git a/app/models/customer.rb b/app/models/customer.rb index 673cffd..5509439 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,5 @@ class Customer < ActiveRecord::Base has_many :coitems - has_many :bitems has_many :merchandise_purchases has_many :rentable_purchases diff --git a/app/views/bitem/_form.rhtml b/app/views/bitem/_form.rhtml deleted file mode 100644 index a3db253..0000000 --- a/app/views/bitem/_form.rhtml +++ /dev/null @@ -1,13 +0,0 @@ -<%= error_messages_for 'bitem' %> - - -


-<%= text_field 'bitem', 'customer_id' %>

- -


-<%= text_field 'bitem', 'merchandise_id' %>

- -


-<%= date_select 'bitem', 'date' %>

- - diff --git a/app/views/bitem/edit.rhtml b/app/views/bitem/edit.rhtml deleted file mode 100644 index bb2d7ed..0000000 --- a/app/views/bitem/edit.rhtml +++ /dev/null @@ -1,9 +0,0 @@ -

Editing bitem

- -<% form_tag :action => 'update', :id => @bitem do %> - <%= render :partial => 'form' %> - <%= submit_tag 'Edit' %> -<% end %> - -<%= link_to 'Show', :action => 'show', :id => @bitem %> | -<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/bitem/list.rhtml b/app/views/bitem/list.rhtml deleted file mode 100644 index 81a7d7c..0000000 --- a/app/views/bitem/list.rhtml +++ /dev/null @@ -1,31 +0,0 @@ -

Listing bitems

- - - - - - <% for column in Bitem.content_columns %> - - <% end %> - - -<% for bitem in @bitems %> - - - - <% for column in Bitem.content_columns %> - - <% end %> - - - - -<% end %> -
Customer NameMerchandise Name<%= column.human_name %>
<%=h bitem.customer.name %><%=h bitem.merchandise.title %><%=h bitem.send(column.name) %><%= link_to 'Show', :action => 'show', :id => bitem %><%= link_to 'Edit', :action => 'edit', :id => bitem %><%= link_to 'Destroy', { :action => 'destroy', :id => bitem }, :confirm => 'Are you sure?', :method => :post %>
- -<%= link_to 'Previous page', { :page => @bitem_pages.current.previous } if @bitem_pages.current.previous %> -<%= link_to 'Next page', { :page => @bitem_pages.current.next } if @bitem_pages.current.next %> - -
- -<%= link_to 'New bitem', :action => 'new' %> diff --git a/app/views/bitem/new.rhtml b/app/views/bitem/new.rhtml deleted file mode 100644 index d2556da..0000000 --- a/app/views/bitem/new.rhtml +++ /dev/null @@ -1,8 +0,0 @@ -

New bitem

- -<% form_tag :action => 'create' do %> - <%= render :partial => 'form' %> - <%= submit_tag "Create" %> -<% end %> - -<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/bitem/show.rhtml b/app/views/bitem/show.rhtml deleted file mode 100644 index fd2d14b..0000000 --- a/app/views/bitem/show.rhtml +++ /dev/null @@ -1,8 +0,0 @@ -<% for column in Bitem.content_columns %> -

- <%= column.human_name %>: <%=h @bitem.send(column.name) %> -

-<% end %> - -<%= link_to 'Edit', :action => 'edit', :id => @bitem %> | -<%= link_to 'Back', :action => 'list' %> diff --git a/app/views/layouts/bitem.rhtml b/app/views/layouts/bitem.rhtml deleted file mode 100644 index fc00ace..0000000 --- a/app/views/layouts/bitem.rhtml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Bitem: <%= controller.action_name %> - <%= stylesheet_link_tag 'scaffold' %> - - - -

<%= flash[:notice] %>

- -<%= yield %> - - - diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 92a8e4bc4bfcf1a9b6ae618b060cd56ebc3a303e..11394f606e13396c816a7459f7a375e391ab5d17 100644 GIT binary patch delta 194 zcmZoTz}Rqrae}m;NM5lJj#7buA1GbTf+*b&K;VQy3=mbI)Wno4k_S zNL87Yok3h#RGQJ)#K_n*xS%LAFFh?YH7CW`#MrnbBQ>)qwU}`e52FY_Q#}Idg`Gj( zU4QZ^E)ChtqC^KEF3zh=NiEV#&d)W}wJ5v6yXQDg_U6e1H%F)ex`b6?acxT`AjU0nq2Ig zo0V!=c|eY3V!p+|{FeFFW|fZ E0CV^^E&u=k diff --git a/db/migrate/026_drop_bitems.rb b/db/migrate/026_drop_bitems.rb new file mode 100644 index 0000000..049297a --- /dev/null +++ b/db/migrate/026_drop_bitems.rb @@ -0,0 +1,13 @@ +class DropBitems < ActiveRecord::Migration + def self.up + drop_table :bitems + end + + def self.down + create_table :bitems do |t| + t.column :customer_id, :integer, :null => false + t.column :merchandise_id, :integer, :null => false + t.column :date, :date, :null => false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ef94c3e..192232a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,13 +2,7 @@ # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition. -ActiveRecord::Schema.define(:version => 25) do - - create_table "bitems", :force => true do |t| - t.column "customer_id", :integer, :null => false - t.column "merchandise_id", :integer, :null => false - t.column "date", :date, :null => false - end +ActiveRecord::Schema.define(:version => 26) do create_table "coitems", :force => true do |t| t.column "customer_id", :integer diff --git a/test/fixtures/bitems.yml b/test/fixtures/bitems.yml deleted file mode 100644 index b49c4eb..0000000 --- a/test/fixtures/bitems.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -one: - id: 1 -two: - id: 2 diff --git a/test/functional/bitem_controller_test.rb b/test/functional/bitem_controller_test.rb deleted file mode 100644 index 72063e0..0000000 --- a/test/functional/bitem_controller_test.rb +++ /dev/null @@ -1,92 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' -require 'bitem_controller' - -# Re-raise errors caught by the controller. -class BitemController; def rescue_action(e) raise e end; end - -class BitemControllerTest < Test::Unit::TestCase - fixtures :bitems - - def setup - @controller = BitemController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - @first_id = bitems(:first).id - end - - def test_index - get :index - assert_response :success - assert_template 'list' - end - - def test_list - get :list - - assert_response :success - assert_template 'list' - - assert_not_nil assigns(:bitems) - end - - def test_show - get :show, :id => @first_id - - assert_response :success - assert_template 'show' - - assert_not_nil assigns(:bitem) - assert assigns(:bitem).valid? - end - - def test_new - get :new - - assert_response :success - assert_template 'new' - - assert_not_nil assigns(:bitem) - end - - def test_create - num_bitems = Bitem.count - - post :create, :bitem => {} - - assert_response :redirect - assert_redirected_to :action => 'list' - - assert_equal num_bitems + 1, Bitem.count - end - - def test_edit - get :edit, :id => @first_id - - assert_response :success - assert_template 'edit' - - assert_not_nil assigns(:bitem) - assert assigns(:bitem).valid? - end - - def test_update - post :update, :id => @first_id - assert_response :redirect - assert_redirected_to :action => 'show', :id => @first_id - end - - def test_destroy - assert_nothing_raised { - Bitem.find(@first_id) - } - - post :destroy, :id => @first_id - assert_response :redirect - assert_redirected_to :action => 'list' - - assert_raise(ActiveRecord::RecordNotFound) { - Bitem.find(@first_id) - } - end -end diff --git a/test/unit/bitem_test.rb b/test/unit/bitem_test.rb deleted file mode 100644 index 966a42b..0000000 --- a/test/unit/bitem_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class BitemTest < Test::Unit::TestCase - fixtures :bitems - - # Replace this with your real tests. - def test_truth - assert true - end -end -- 2.25.1