-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module LineItemsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class LineItem < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
<title>LineItems: <%= controller.action_name %></title> | ||
<%= stylesheet_link_tag 'scaffold' %> | ||
</head> | ||
<body> | ||
|
||
<p style="color: green"><%= flash[:notice] %></p> | ||
|
||
<%= yield %> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |