From 3ac66882338fa1c3f6d73ba68093b7fcfb399574 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 4 Mar 2009 21:25:17 +0000 Subject: [PATCH] Moved to Netbeans 6.5. Started order creation --- app/controllers/line_items_controller.rb | 85 +++++++++++++++++++ app/controllers/orders_controller.rb | 85 +++++++++++++++++++ app/helpers/line_items_helper.rb | 2 + app/helpers/orders_helper.rb | 2 + app/models/line_item.rb | 2 + app/models/order.rb | 2 + app/views/line_items/edit.html.erb | 28 ++++++ app/views/line_items/index.html.erb | 26 ++++++ app/views/line_items/new.html.erb | 27 ++++++ app/views/line_items/show.html.erb | 23 +++++ app/views/orders/edit.html.erb | 28 ++++++ app/views/orders/index.html.erb | 26 ++++++ app/views/orders/new.html.erb | 27 ++++++ app/views/orders/show.html.erb | 23 +++++ db/migrate/20090304153209_create_orders.rb | 16 ++++ .../20090304153613_create_line_items.rb | 16 ++++ nbproject/project.properties | 1 + test/fixtures/line_items.yml | 13 +++ test/fixtures/orders.yml | 13 +++ test/functional/line_items_controller_test.rb | 45 ++++++++++ test/functional/orders_controller_test.rb | 45 ++++++++++ test/unit/line_item_test.rb | 8 ++ test/unit/order_test.rb | 8 ++ 23 files changed, 551 insertions(+) create mode 100644 app/controllers/line_items_controller.rb create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/helpers/line_items_helper.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/models/line_item.rb create mode 100644 app/models/order.rb create mode 100644 app/views/line_items/edit.html.erb create mode 100644 app/views/line_items/index.html.erb create mode 100644 app/views/line_items/new.html.erb create mode 100644 app/views/line_items/show.html.erb create mode 100644 app/views/orders/edit.html.erb create mode 100644 app/views/orders/index.html.erb create mode 100644 app/views/orders/new.html.erb create mode 100644 app/views/orders/show.html.erb create mode 100644 db/migrate/20090304153209_create_orders.rb create mode 100644 db/migrate/20090304153613_create_line_items.rb create mode 100644 test/fixtures/line_items.yml create mode 100644 test/fixtures/orders.yml create mode 100644 test/functional/line_items_controller_test.rb create mode 100644 test/functional/orders_controller_test.rb create mode 100644 test/unit/line_item_test.rb create mode 100644 test/unit/order_test.rb diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb new file mode 100644 index 0000000..1b17372 --- /dev/null +++ b/app/controllers/line_items_controller.rb @@ -0,0 +1,85 @@ +class LineItemsController < ApplicationController + # GET /line_items + # GET /line_items.xml + def index + @line_items = LineItem.find(:all) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @line_items } + end + end + + # GET /line_items/1 + # GET /line_items/1.xml + def show + @line_item = LineItem.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @line_item } + end + end + + # GET /line_items/new + # GET /line_items/new.xml + def new + @line_item = LineItem.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @line_item } + end + end + + # GET /line_items/1/edit + def edit + @line_item = LineItem.find(params[:id]) + end + + # POST /line_items + # POST /line_items.xml + def create + @line_item = LineItem.new(params[:line_item]) + + respond_to do |format| + if @line_item.save + flash[:notice] = 'LineItem was successfully created.' + format.html { redirect_to(@line_item) } + format.xml { render :xml => @line_item, :status => :created, :location => @line_item } + else + format.html { render :action => "new" } + format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /line_items/1 + # PUT /line_items/1.xml + def update + @line_item = LineItem.find(params[:id]) + + respond_to do |format| + if @line_item.update_attributes(params[:line_item]) + flash[:notice] = 'LineItem was successfully updated.' + format.html { redirect_to(@line_item) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /line_items/1 + # DELETE /line_items/1.xml + def destroy + @line_item = LineItem.find(params[:id]) + @line_item.destroy + + respond_to do |format| + format.html { redirect_to(line_items_url) } + format.xml { head :ok } + end + end +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000..eba6175 --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,85 @@ +class OrdersController < ApplicationController + # GET /orders + # GET /orders.xml + def index + @orders = Order.find(:all) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @orders } + end + end + + # GET /orders/1 + # GET /orders/1.xml + def show + @order = Order.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @order } + end + end + + # GET /orders/new + # GET /orders/new.xml + def new + @order = Order.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @order } + end + end + + # GET /orders/1/edit + def edit + @order = Order.find(params[:id]) + end + + # POST /orders + # POST /orders.xml + def create + @order = Order.new(params[:order]) + + respond_to do |format| + if @order.save + flash[:notice] = 'Order was successfully created.' + format.html { redirect_to(@order) } + format.xml { render :xml => @order, :status => :created, :location => @order } + else + format.html { render :action => "new" } + format.xml { render :xml => @order.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /orders/1 + # PUT /orders/1.xml + def update + @order = Order.find(params[:id]) + + respond_to do |format| + if @order.update_attributes(params[:order]) + flash[:notice] = 'Order was successfully updated.' + format.html { redirect_to(@order) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @order.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /orders/1 + # DELETE /orders/1.xml + def destroy + @order = Order.find(params[:id]) + @order.destroy + + respond_to do |format| + format.html { redirect_to(orders_url) } + format.xml { head :ok } + end + end +end diff --git a/app/helpers/line_items_helper.rb b/app/helpers/line_items_helper.rb new file mode 100644 index 0000000..8f607da --- /dev/null +++ b/app/helpers/line_items_helper.rb @@ -0,0 +1,2 @@ +module LineItemsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000..443227f --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/models/line_item.rb b/app/models/line_item.rb new file mode 100644 index 0000000..988324c --- /dev/null +++ b/app/models/line_item.rb @@ -0,0 +1,2 @@ +class LineItem < ActiveRecord::Base +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000..0bcb158 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,2 @@ +class Order < ActiveRecord::Base +end diff --git a/app/views/line_items/edit.html.erb b/app/views/line_items/edit.html.erb new file mode 100644 index 0000000..1e1298a --- /dev/null +++ b/app/views/line_items/edit.html.erb @@ -0,0 +1,28 @@ +

Editing line_item

+ +<% form_for(@line_item) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :product_id %>
+ <%= f.text_field :product_id %> +

+

+ <%= f.label :order_id %>
+ <%= f.text_field :order_id %> +

+

+ <%= f.label :quantity %>
+ <%= f.text_field :quantity %> +

+

+ <%= f.label :total_price %>
+ <%= f.text_field :total_price %> +

+

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @line_item %> | +<%= link_to 'Back', line_items_path %> diff --git a/app/views/line_items/index.html.erb b/app/views/line_items/index.html.erb new file mode 100644 index 0000000..7b07453 --- /dev/null +++ b/app/views/line_items/index.html.erb @@ -0,0 +1,26 @@ +

Listing line_items

+ + + + + + + + + +<% for line_item in @line_items %> + + + + + + + + + +<% end %> +
ProductOrderQuantityTotal price
<%=h line_item.product_id %><%=h line_item.order_id %><%=h line_item.quantity %><%=h line_item.total_price %><%= link_to 'Show', line_item %><%= link_to 'Edit', edit_line_item_path(line_item) %><%= link_to 'Destroy', line_item, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New line_item', new_line_item_path %> diff --git a/app/views/line_items/new.html.erb b/app/views/line_items/new.html.erb new file mode 100644 index 0000000..7927008 --- /dev/null +++ b/app/views/line_items/new.html.erb @@ -0,0 +1,27 @@ +

New line_item

+ +<% form_for(@line_item) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :product_id %>
+ <%= f.text_field :product_id %> +

+

+ <%= f.label :order_id %>
+ <%= f.text_field :order_id %> +

+

+ <%= f.label :quantity %>
+ <%= f.text_field :quantity %> +

+

+ <%= f.label :total_price %>
+ <%= f.text_field :total_price %> +

+

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', line_items_path %> diff --git a/app/views/line_items/show.html.erb b/app/views/line_items/show.html.erb new file mode 100644 index 0000000..aa6f3c0 --- /dev/null +++ b/app/views/line_items/show.html.erb @@ -0,0 +1,23 @@ +

+ Product: + <%=h @line_item.product_id %> +

+ +

+ Order: + <%=h @line_item.order_id %> +

+ +

+ Quantity: + <%=h @line_item.quantity %> +

+ +

+ Total price: + <%=h @line_item.total_price %> +

+ + +<%= link_to 'Edit', edit_line_item_path(@line_item) %> | +<%= link_to 'Back', line_items_path %> diff --git a/app/views/orders/edit.html.erb b/app/views/orders/edit.html.erb new file mode 100644 index 0000000..73f8414 --- /dev/null +++ b/app/views/orders/edit.html.erb @@ -0,0 +1,28 @@ +

Editing order

+ +<% form_for(@order) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

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

+

+ <%= f.label :email %>
+ <%= f.text_field :email %> +

+

+ <%= f.label :pay_type %>
+ <%= f.text_field :pay_type %> +

+

+ <%= f.submit "Update" %> +

+<% end %> + +<%= link_to 'Show', @order %> | +<%= link_to 'Back', orders_path %> diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb new file mode 100644 index 0000000..39e117e --- /dev/null +++ b/app/views/orders/index.html.erb @@ -0,0 +1,26 @@ +

Listing orders

+ + + + + + + + + +<% for order in @orders %> + + + + + + + + + +<% end %> +
NameAddressEmailPay type
<%=h order.name %><%=h order.address %><%=h order.email %><%=h order.pay_type %><%= link_to 'Show', order %><%= link_to 'Edit', edit_order_path(order) %><%= link_to 'Destroy', order, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New order', new_order_path %> diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb new file mode 100644 index 0000000..606e44c --- /dev/null +++ b/app/views/orders/new.html.erb @@ -0,0 +1,27 @@ +

New order

+ +<% form_for(@order) do |f| %> + <%= f.error_messages %> + +

+ <%= f.label :name %>
+ <%= f.text_field :name %> +

+

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

+

+ <%= f.label :email %>
+ <%= f.text_field :email %> +

+

+ <%= f.label :pay_type %>
+ <%= f.text_field :pay_type %> +

+

+ <%= f.submit "Create" %> +

+<% end %> + +<%= link_to 'Back', orders_path %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000..221c5c5 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,23 @@ +

+ Name: + <%=h @order.name %> +

+ +

+ Address: + <%=h @order.address %> +

+ +

+ Email: + <%=h @order.email %> +

+ +

+ Pay type: + <%=h @order.pay_type %> +

+ + +<%= link_to 'Edit', edit_order_path(@order) %> | +<%= link_to 'Back', orders_path %> diff --git a/db/migrate/20090304153209_create_orders.rb b/db/migrate/20090304153209_create_orders.rb new file mode 100644 index 0000000..a0a1598 --- /dev/null +++ b/db/migrate/20090304153209_create_orders.rb @@ -0,0 +1,16 @@ +class CreateOrders < ActiveRecord::Migration + def self.up + create_table :orders do |t| + t.string :name + t.text :address + t.string :email + t.string :pay_type + + t.timestamps + end + end + + def self.down + drop_table :orders + end +end diff --git a/db/migrate/20090304153613_create_line_items.rb b/db/migrate/20090304153613_create_line_items.rb new file mode 100644 index 0000000..6870a05 --- /dev/null +++ b/db/migrate/20090304153613_create_line_items.rb @@ -0,0 +1,16 @@ +class CreateLineItems < ActiveRecord::Migration + def self.up + create_table :line_items do |t| + t.integer :product_id + t.integer :order_id + t.integer :quantity + t.decimal :total_price + + t.timestamps + end + end + + def self.down + drop_table :line_items + end +end diff --git a/nbproject/project.properties b/nbproject/project.properties index 0b610ac..9522eb9 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,2 +1,3 @@ +javac.classpath= rails.port=3000 source.encoding=UTF-8 diff --git a/test/fixtures/line_items.yml b/test/fixtures/line_items.yml new file mode 100644 index 0000000..ab7fc85 --- /dev/null +++ b/test/fixtures/line_items.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + product_id: 1 + order_id: 1 + quantity: 1 + total_price: 9.99 + +two: + product_id: 1 + order_id: 1 + quantity: 1 + total_price: 9.99 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000..e4a667a --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + address: MyText + email: MyString + pay_type: MyString + +two: + name: MyString + address: MyText + email: MyString + pay_type: MyString diff --git a/test/functional/line_items_controller_test.rb b/test/functional/line_items_controller_test.rb new file mode 100644 index 0000000..305a261 --- /dev/null +++ b/test/functional/line_items_controller_test.rb @@ -0,0 +1,45 @@ +require 'test_helper' + +class LineItemsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:line_items) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create line_item" do + assert_difference('LineItem.count') do + post :create, :line_item => { } + end + + assert_redirected_to line_item_path(assigns(:line_item)) + end + + test "should show line_item" do + get :show, :id => line_items(:one).id + assert_response :success + end + + test "should get edit" do + get :edit, :id => line_items(:one).id + assert_response :success + end + + test "should update line_item" do + put :update, :id => line_items(:one).id, :line_item => { } + assert_redirected_to line_item_path(assigns(:line_item)) + end + + test "should destroy line_item" do + assert_difference('LineItem.count', -1) do + delete :destroy, :id => line_items(:one).id + end + + assert_redirected_to line_items_path + end +end diff --git a/test/functional/orders_controller_test.rb b/test/functional/orders_controller_test.rb new file mode 100644 index 0000000..ec6232f --- /dev/null +++ b/test/functional/orders_controller_test.rb @@ -0,0 +1,45 @@ +require 'test_helper' + +class OrdersControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:orders) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create order" do + assert_difference('Order.count') do + post :create, :order => { } + end + + assert_redirected_to order_path(assigns(:order)) + end + + test "should show order" do + get :show, :id => orders(:one).id + assert_response :success + end + + test "should get edit" do + get :edit, :id => orders(:one).id + assert_response :success + end + + test "should update order" do + put :update, :id => orders(:one).id, :order => { } + assert_redirected_to order_path(assigns(:order)) + end + + test "should destroy order" do + assert_difference('Order.count', -1) do + delete :destroy, :id => orders(:one).id + end + + assert_redirected_to orders_path + end +end diff --git a/test/unit/line_item_test.rb b/test/unit/line_item_test.rb new file mode 100644 index 0000000..cad6eed --- /dev/null +++ b/test/unit/line_item_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class LineItemTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/order_test.rb b/test/unit/order_test.rb new file mode 100644 index 0000000..6556fe0 --- /dev/null +++ b/test/unit/order_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class OrderTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end -- 2.34.1