Skip to content

Commit

Permalink
Fix expenses tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Mar 20, 2019
1 parent ef896db commit 11b6492
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
33 changes: 1 addition & 32 deletions test/controllers/expenses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,6 @@ class ExpensesControllerTest < ActionController::TestCase

setup :login

test 'GET#index management may list all expenses' do
login_as(:mark)
get :index
assert_equal 5, assigns(:expenses).count
end

test 'GET#index management may filter by status' do
login_as(:mark)
get :index, params: { status: :pending }
assert_equal 1, assigns(:expenses).count
end

test 'GET#index management may filter by employee_id' do
login_as(:mark)
get :index, params: { employee_id: employees(:pascal).id }
assert_equal 4, assigns(:expenses).count
end

test 'GET#index management may filter by department_id' do
login_as(:mark)
employees(:pascal).update(department: departments(:devone))
get :index, params: { department_id: departments(:devone).id }
assert_equal 4, assigns(:expenses).count
end

test 'GET#index management may filter by reimbursement_date' do
login_as(:mark)
get :index, params: { reimbursement_date: '2019_02' }
assert_equal 1, assigns(:expenses).count
end

test 'GET#index employee may not list top level expenses' do
login_as(:pascal)
assert_raise { get :index }
Expand Down Expand Up @@ -77,7 +46,7 @@ class ExpensesControllerTest < ActionController::TestCase
login_as(:mark)
put :update, params: { employee_id: expense.employee_id, id: expense.id, review: 1, expense: { amount: 1 } }
assert_equal 1, expense.reload.amount
assert_redirected_to expense_review_path(expense)
assert_redirected_to expenses_review_path(expense)
end

%w(pending deferred rejected).each do |status|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@ class ExpensesReviewsControllerTest < ActionController::TestCase

setup :login

test 'GET#index management may list all expenses' do
login_as(:mark)
get :index
assert_equal 5, assigns(:expenses).count
end

test 'GET#index management may filter by status' do
login_as(:mark)
get :index, params: { status: :pending }
assert_equal 1, assigns(:expenses).count
end

test 'GET#index management may filter by employee_id' do
login_as(:mark)
get :index, params: { employee_id: employees(:pascal).id }
assert_equal 4, assigns(:expenses).count
end

test 'GET#index management may filter by department_id' do
login_as(:mark)
employees(:pascal).update(department: departments(:devone))
get :index, params: { department_id: departments(:devone).id }
assert_equal 4, assigns(:expenses).count
end

test 'GET#index management may filter by reimbursement_date' do
login_as(:mark)
get :index, params: { reimbursement_date: '2019_02' }
assert_equal 1, assigns(:expenses).count
end

test 'GET#show employee may not work with expense reviews' do
login_as(:pascal)
assert_raise do
Expand Down Expand Up @@ -53,4 +84,5 @@ class ExpensesReviewsControllerTest < ActionController::TestCase
assert_redirected_to expenses_review_path(other)
end


end

0 comments on commit 11b6492

Please sign in to comment.