Skip to content

Commit

Permalink
Tests: Use new requests syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
YtvwlD committed Aug 13, 2016
1 parent abaa047 commit 8017344
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/functional/audits_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AuditsControllerTest < ActionController::TestCase
"month" => 1,
"day" => 1
}
get :index, start_date: @date, end_date: @date, :format => "json"
get :index, params: { start_date: @date, end_date: @date}, :format => "json"
assert_response :success
resp = JSON.parse(response.body)
assert_equal [], resp["audits"]
Expand Down
10 changes: 5 additions & 5 deletions test/functional/drinks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ class DrinksControllerTest < ActionController::TestCase

test "should create drink" do
assert_difference('Drink.count') do
post :create, drink: { bottle_size: @drink.bottle_size, caffeine: @drink.caffeine, price: @drink.price, logo_file_name: @drink.logo_file_name, name: @drink.name }
post :create, params: {drink: { bottle_size: @drink.bottle_size, caffeine: @drink.caffeine, price: @drink.price, logo_file_name: @drink.logo_file_name, name: @drink.name }}
end

assert_redirected_to drink_path(assigns(:drink))
end

test "should show drink" do
get :show, id: @drink
get :show, params: {id: @drink}
assert_response :success
end

test "should get edit" do
get :edit, id: @drink
get :edit, params: {id: @drink}
assert_response :success
end

test "should update drink" do
put :update, id: @drink, drink: { bottle_size: @drink.bottle_size, caffeine: @drink.caffeine, price: @drink.price, logo_file_name: @drink.logo_file_name, name: @drink.name }
put :update, params: {id: @drink, drink: { bottle_size: @drink.bottle_size, caffeine: @drink.caffeine, price: @drink.price, logo_file_name: @drink.logo_file_name, name: @drink.name }}
assert_redirected_to drink_path(assigns(:drink))
end

test "should destroy drink" do
assert_difference('Drink.count', -1) do
delete :destroy, id: @drink
delete :destroy, params: {id: @drink}
end

assert_redirected_to drinks_path
Expand Down
24 changes: 12 additions & 12 deletions test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,60 @@ class UsersControllerTest < ActionController::TestCase

test "should create user" do
assert_difference('User.count') do
post :create, user: { balance: @user.balance, name: @user.name }
post :create, params: {user: { balance: @user.balance, name: @user.name }}
end
assert_redirected_to user_path(assigns(:user))
end

test "should show user with email" do
get :show, id: @user
get :show, params: {id: @user}
assert_response :success
end

test "should show user without email" do
get :show, id: users(:two)
get :show, params: {id: users(:two)}
assert_response :success
end

test "should get edit" do
get :edit, id: @user
get :edit, params: {id: @user}
assert_response :success
end

test "deposit" do
get :deposit, id: @user, amount: 100
get :deposit, params: {id: @user, amount: 100}
assert_equal 200, User.find(@user.id).balance
assert_equal 100, Audit.first.difference
end

test "payment" do
get :payment, id: @user, amount: 100
get :payment, params: {id: @user, amount: 100}
assert_equal 0, User.find(@user.id).balance
assert_equal -100, Audit.first.difference
end

test "payment resulting in a negative balance" do
get :payment, id: users(:two), amount: 100
get :payment, params: {id: users(:two), amount: 100}
assert_equal -100, User.find(users(:two).id).balance
assert_equal -100, Audit.first.difference
end

test "buy" do
get :buy, id: @user, drink: @drink
get :buy, params: {id: @user, drink: @drink}
assert_equal -@drink.price, Audit.first.difference
assert_redirected_to users_path
end

test "buy resulting in a negative balance" do
get :buy, id: users(:two), drink: @drink
get :buy, params: {id: users(:two), drink: @drink}
assert_equal -@drink.price, User.find(users(:two).id).balance
assert_equal -@drink.price, Audit.first.difference
assert_redirected_to users_path
end

test "buy unavailable drink" do
assert_equal Drink.find(drinks(:two).id).active, false
get :buy, id: @user, drink: drinks(:two)
get :buy, params: {id: @user, drink: drinks(:two)}
assert_equal Drink.find(drinks(:two).id).active, true
assert_equal -drinks(:two).price, Audit.first.difference
assert_redirected_to users_path
Expand All @@ -86,13 +86,13 @@ class UsersControllerTest < ActionController::TestCase
end

test "should update user" do
put :update, id: @user, user: { balance: @user.balance, name: @user.name }
put :update, params: {id: @user, user: { balance: @user.balance, name: @user.name }}
assert_redirected_to user_path(assigns(:user))
end

test "should destroy user" do
assert_difference('User.count', -1) do
delete :destroy, id: @user
delete :destroy, params: {id: @user}
end
assert_redirected_to users_path
end
Expand Down

0 comments on commit 8017344

Please sign in to comment.