Moved to Netbeans 6.5. Started order creation
authorNeil Smith <neil.git@njae.me.uk>
Wed, 4 Mar 2009 21:25:17 +0000 (21:25 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Wed, 4 Mar 2009 21:25:17 +0000 (21:25 +0000)
23 files changed:
app/controllers/line_items_controller.rb [new file with mode: 0644]
app/controllers/orders_controller.rb [new file with mode: 0644]
app/helpers/line_items_helper.rb [new file with mode: 0644]
app/helpers/orders_helper.rb [new file with mode: 0644]
app/models/line_item.rb [new file with mode: 0644]
app/models/order.rb [new file with mode: 0644]
app/views/line_items/edit.html.erb [new file with mode: 0644]
app/views/line_items/index.html.erb [new file with mode: 0644]
app/views/line_items/new.html.erb [new file with mode: 0644]
app/views/line_items/show.html.erb [new file with mode: 0644]
app/views/orders/edit.html.erb [new file with mode: 0644]
app/views/orders/index.html.erb [new file with mode: 0644]
app/views/orders/new.html.erb [new file with mode: 0644]
app/views/orders/show.html.erb [new file with mode: 0644]
db/migrate/20090304153209_create_orders.rb [new file with mode: 0644]
db/migrate/20090304153613_create_line_items.rb [new file with mode: 0644]
nbproject/project.properties
test/fixtures/line_items.yml [new file with mode: 0644]
test/fixtures/orders.yml [new file with mode: 0644]
test/functional/line_items_controller_test.rb [new file with mode: 0644]
test/functional/orders_controller_test.rb [new file with mode: 0644]
test/unit/line_item_test.rb [new file with mode: 0644]
test/unit/order_test.rb [new file with mode: 0644]

diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb
new file mode 100644 (file)
index 0000000..1b17372
--- /dev/null
@@ -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 (file)
index 0000000..eba6175
--- /dev/null
@@ -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 (file)
index 0000000..8f607da
--- /dev/null
@@ -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 (file)
index 0000000..443227f
--- /dev/null
@@ -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 (file)
index 0000000..988324c
--- /dev/null
@@ -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 (file)
index 0000000..0bcb158
--- /dev/null
@@ -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 (file)
index 0000000..1e1298a
--- /dev/null
@@ -0,0 +1,28 @@
+<h1>Editing line_item</h1>
+
+<% form_for(@line_item) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :product_id %><br />
+    <%= f.text_field :product_id %>
+  </p>
+  <p>
+    <%= f.label :order_id %><br />
+    <%= f.text_field :order_id %>
+  </p>
+  <p>
+    <%= f.label :quantity %><br />
+    <%= f.text_field :quantity %>
+  </p>
+  <p>
+    <%= f.label :total_price %><br />
+    <%= f.text_field :total_price %>
+  </p>
+  <p>
+    <%= f.submit "Update" %>
+  </p>
+<% 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 (file)
index 0000000..7b07453
--- /dev/null
@@ -0,0 +1,26 @@
+<h1>Listing line_items</h1>
+
+<table>
+  <tr>
+    <th>Product</th>
+    <th>Order</th>
+    <th>Quantity</th>
+    <th>Total price</th>
+  </tr>
+
+<% for line_item in @line_items %>
+  <tr>
+    <td><%=h line_item.product_id %></td>
+    <td><%=h line_item.order_id %></td>
+    <td><%=h line_item.quantity %></td>
+    <td><%=h line_item.total_price %></td>
+    <td><%= link_to 'Show', line_item %></td>
+    <td><%= link_to 'Edit', edit_line_item_path(line_item) %></td>
+    <td><%= link_to 'Destroy', line_item, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= 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 (file)
index 0000000..7927008
--- /dev/null
@@ -0,0 +1,27 @@
+<h1>New line_item</h1>
+
+<% form_for(@line_item) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :product_id %><br />
+    <%= f.text_field :product_id %>
+  </p>
+  <p>
+    <%= f.label :order_id %><br />
+    <%= f.text_field :order_id %>
+  </p>
+  <p>
+    <%= f.label :quantity %><br />
+    <%= f.text_field :quantity %>
+  </p>
+  <p>
+    <%= f.label :total_price %><br />
+    <%= f.text_field :total_price %>
+  </p>
+  <p>
+    <%= f.submit "Create" %>
+  </p>
+<% 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 (file)
index 0000000..aa6f3c0
--- /dev/null
@@ -0,0 +1,23 @@
+<p>
+  <b>Product:</b>
+  <%=h @line_item.product_id %>
+</p>
+
+<p>
+  <b>Order:</b>
+  <%=h @line_item.order_id %>
+</p>
+
+<p>
+  <b>Quantity:</b>
+  <%=h @line_item.quantity %>
+</p>
+
+<p>
+  <b>Total price:</b>
+  <%=h @line_item.total_price %>
+</p>
+
+
+<%= 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 (file)
index 0000000..73f8414
--- /dev/null
@@ -0,0 +1,28 @@
+<h1>Editing order</h1>
+
+<% form_for(@order) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :name %><br />
+    <%= f.text_field :name %>
+  </p>
+  <p>
+    <%= f.label :address %><br />
+    <%= f.text_area :address %>
+  </p>
+  <p>
+    <%= f.label :email %><br />
+    <%= f.text_field :email %>
+  </p>
+  <p>
+    <%= f.label :pay_type %><br />
+    <%= f.text_field :pay_type %>
+  </p>
+  <p>
+    <%= f.submit "Update" %>
+  </p>
+<% 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 (file)
index 0000000..39e117e
--- /dev/null
@@ -0,0 +1,26 @@
+<h1>Listing orders</h1>
+
+<table>
+  <tr>
+    <th>Name</th>
+    <th>Address</th>
+    <th>Email</th>
+    <th>Pay type</th>
+  </tr>
+
+<% for order in @orders %>
+  <tr>
+    <td><%=h order.name %></td>
+    <td><%=h order.address %></td>
+    <td><%=h order.email %></td>
+    <td><%=h order.pay_type %></td>
+    <td><%= link_to 'Show', order %></td>
+    <td><%= link_to 'Edit', edit_order_path(order) %></td>
+    <td><%= link_to 'Destroy', order, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= 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 (file)
index 0000000..606e44c
--- /dev/null
@@ -0,0 +1,27 @@
+<h1>New order</h1>
+
+<% form_for(@order) do |f| %>
+  <%= f.error_messages %>
+
+  <p>
+    <%= f.label :name %><br />
+    <%= f.text_field :name %>
+  </p>
+  <p>
+    <%= f.label :address %><br />
+    <%= f.text_area :address %>
+  </p>
+  <p>
+    <%= f.label :email %><br />
+    <%= f.text_field :email %>
+  </p>
+  <p>
+    <%= f.label :pay_type %><br />
+    <%= f.text_field :pay_type %>
+  </p>
+  <p>
+    <%= f.submit "Create" %>
+  </p>
+<% 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 (file)
index 0000000..221c5c5
--- /dev/null
@@ -0,0 +1,23 @@
+<p>
+  <b>Name:</b>
+  <%=h @order.name %>
+</p>
+
+<p>
+  <b>Address:</b>
+  <%=h @order.address %>
+</p>
+
+<p>
+  <b>Email:</b>
+  <%=h @order.email %>
+</p>
+
+<p>
+  <b>Pay type:</b>
+  <%=h @order.pay_type %>
+</p>
+
+
+<%= 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 (file)
index 0000000..a0a1598
--- /dev/null
@@ -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 (file)
index 0000000..6870a05
--- /dev/null
@@ -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
index 0b610acb37e8fb8641f9cfb58832edb7d99fe3bc..9522eb9676a6ff99873bd5d1d689befdeedfb2f7 100644 (file)
@@ -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 (file)
index 0000000..ab7fc85
--- /dev/null
@@ -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 (file)
index 0000000..e4a667a
--- /dev/null
@@ -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 (file)
index 0000000..305a261
--- /dev/null
@@ -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 (file)
index 0000000..ec6232f
--- /dev/null
@@ -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 (file)
index 0000000..cad6eed
--- /dev/null
@@ -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 (file)
index 0000000..6556fe0
--- /dev/null
@@ -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