product_id: 1
order_id: 1
quantity: 1
- total_price: 9.99
+ total_price: 19.99
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
- name: MyString
- address: MyText
- email: MyString
- pay_type: MyString
+ name: First Order Person
+ address: First Address
+ email: first@email.com
+ pay_type: cc
two:
- name: MyString
- address: MyText
- email: MyString
- pay_type: MyString
+ name: Second Order Person
+ address: Second address
+ email: second@email.com
+ pay_type: po
description: Dummy description
price: 1234
image_url: ruby.png
+ date_available: 2009-01-01
rails_book:
title: Agile Web Development with Rails
description: Dummy description
price: 2345
image_url: rails.png
-
\ No newline at end of file
+ date_available: 2009-01-01
+
require 'test_helper'
class LineItemsControllerTest < ActionController::TestCase
+
+ fixtures :orders, :products, :line_items, :users
+
test "should get index" do
- get :index
+ get :index, {}, { :user_id => users(:dave).id }
assert_response :success
assert_not_nil assigns(:line_items)
end
test "should get new" do
- get :new
+ get :new, {}, { :user_id => users(:dave).id }
assert_response :success
end
test "should create line_item" do
assert_difference('LineItem.count') do
- post :create, :line_item => { }
+ post :create, {:line_item => { :order_id => 1, :product_id => 1, :quantity => 5, :total_price => 9.99 }},
+ { :user_id => users(:dave).id }
end
assert_redirected_to line_item_path(assigns(:line_item))
end
test "should show line_item" do
- get :show, :id => line_items(:one).id
+ get :show, {:id => line_items(:one).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should get edit" do
- get :edit, :id => line_items(:one).id
+ get :edit, {:id => line_items(:one).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should update line_item" do
- put :update, :id => line_items(:one).id, :line_item => { }
+ put :update, {:id => line_items(:one).id, :line_item => { } }, { :user_id => users(:dave).id }
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
+ delete :destroy, {:id => line_items(:one).id}, { :user_id => users(:dave).id }
end
assert_redirected_to line_items_path
end
+
+
+
+
+ test "index without user" do
+ get :index
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "new without user" do
+ get :new
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "create line_item without user" do
+ post :create, :line_item => { :order_id => 1, :product_id => 1, :quantity => 5, :total_price => 9.99 }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "show line_item without user" do
+ get :show, :id => line_items(:one).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get edit without user" do
+ get :edit, :id => line_items(:one).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "update line_item without user" do
+ put :update, :id => line_items(:one).id, :line_item => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "destroy line_item without user" do
+ delete :destroy, :id => line_items(:one).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
end
require 'test_helper'
class OrdersControllerTest < ActionController::TestCase
+
+ fixtures :orders, :users
+
test "should get index" do
- get :index
+ get :index, {}, { :user_id => users(:dave).id }
assert_response :success
assert_not_nil assigns(:orders)
end
test "should get new" do
- get :new
+ get :new, {}, { :user_id => users(:dave).id }
assert_response :success
end
test "should create order" do
assert_difference('Order.count') do
- post :create, :order => { }
+ post :create, {:order => { :name => "a name", :address => "an address",
+ :email => "name@nowhere.com",
+ :pay_type => "po"}},
+ { :user_id => users(:dave).id }
end
assert_redirected_to order_path(assigns(:order))
end
test "should show order" do
- get :show, :id => orders(:one).id
+ get :show, {:id => orders(:one).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should get edit" do
- get :edit, :id => orders(:one).id
+ get :edit, {:id => orders(:one).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should update order" do
- put :update, :id => orders(:one).id, :order => { }
+ put :update, {:id => orders(:one).id, :order => { }}, { :user_id => users(:dave).id }
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
+ delete :destroy, {:id => orders(:one).id}, { :user_id => users(:dave).id }
end
assert_redirected_to orders_path
end
+
+
+
+ test "get index without user" do
+ get :index
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get new without user" do
+ get :new
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "create order without user" do
+ post :create, :order => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "show order without user" do
+ get :show, :id => orders(:one).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get edit without user" do
+ get :edit, :id => orders(:one).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "update order without user" do
+ put :update, :id => orders(:one).id, :order => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "destroy order without user" do
+ delete :destroy, :id => orders(:one).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+
end
require 'test_helper'
class ProductsControllerTest < ActionController::TestCase
+
+ fixtures :products, :users
+
test "should get index" do
- get :index
+ get :index, {}, { :user_id => users(:dave).id }
assert_response :success
assert_not_nil assigns(:products)
end
test "should get new" do
- get :new
+ get :new, {}, { :user_id => users(:dave).id }
assert_response :success
end
test "should create product" do
assert_difference('Product.count') do
- post :create, :product => { }
+ post :create, {:product => {:title => "test product", :description => "test description",
+ :image_url => "/images/test.jpg", :price => 9.99, :date_available => Time.now}},
+ { :user_id => users(:dave).id }
end
assert_redirected_to product_path(assigns(:product))
end
test "should show product" do
- get :show, :id => products(:one).id
+ get :show, {:id => products(:ruby_book).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should get edit" do
- get :edit, :id => products(:one).id
+ get :edit, {:id => products(:ruby_book).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should update product" do
- put :update, :id => products(:one).id, :product => { }
+ put :update, {:id => products(:ruby_book).id, :product => { }}, { :user_id => users(:dave).id }
assert_redirected_to product_path(assigns(:product))
end
test "should destroy product" do
assert_difference('Product.count', -1) do
- delete :destroy, :id => products(:one).id
+ delete :destroy, {:id => products(:ruby_book).id}, { :user_id => users(:dave).id }
end
assert_redirected_to products_path
end
+
+
+ test "get index without user" do
+ get :index
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get new without user" do
+ get :new
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "create product without user" do
+ post :create, :product => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "show product without user" do
+ get :show, :id => products(:ruby_book).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get edit without user" do
+ get :edit, :id => products(:ruby_book).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "update product without user" do
+ put :update, :id => products(:ruby_book).id, :product => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "destroy product without user" do
+ delete :destroy, :id => products(:ruby_book).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
end
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
+
+ fixtures :users
+
+
test "should get index" do
- get :index
+ get :index, {}, { :user_id => users(:dave).id }
assert_response :success
assert_not_nil assigns(:users)
end
test "should get new" do
- get :new
+ get :new, {}, { :user_id => users(:dave).id }
assert_response :success
end
test "should create user" do
assert_difference('User.count') do
- post :create, :user => { }
+ post :create, {:user => {:name => "noone", :password => "password" }}, { :user_id => users(:dave).id }
end
- assert_redirected_to user_path(assigns(:user))
+ # redirect to index, not user show page
+ assert_redirected_to users_path
end
test "should show user" do
- get :show, :id => users(:one).id
+ get :show, {:id => users(:dave).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should get edit" do
- get :edit, :id => users(:one).id
+ get :edit, {:id => users(:dave).id}, { :user_id => users(:dave).id }
assert_response :success
end
test "should update user" do
- put :update, :id => users(:one).id, :user => { }
- assert_redirected_to user_path(assigns(:user))
+ put :update, {:id => users(:dave).id, :user => { }}, { :user_id => users(:dave).id }
+ # redirect to index, not user show page
+ assert_redirected_to users_path
end
test "should destroy user" do
assert_difference('User.count', -1) do
- delete :destroy, :id => users(:one).id
+ delete :destroy, {:id => users(:dave).id}, { :user_id => users(:dave).id }
end
assert_redirected_to users_path
end
+
+
+
+
+ test "get index without logged-in user" do
+ get :index
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get new without logged-in user" do
+ get :new
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "create user without logged-in user" do
+ post :create, :user => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "show user without logged-in user" do
+ get :show, :id => users(:dave).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "get edit without logged-in user" do
+ get :edit, :id => users(:dave).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "update user without logged-in user" do
+ put :update, :id => users(:dave).id, :user => { }
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+ test "destroy user without logged-in user" do
+ delete :destroy, :id => users(:dave).id
+ assert_redirected_to :controller => "admin", :action => "login"
+ assert_equal "Please log in", flash[:notice]
+ end
+
+
end