Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
add destroy test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhkonkov committed Mar 16, 2017
1 parent f32d081 commit 43489ea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
root to: 'welcome#index'
resources :dishes, only: [:index, :edit, :new, :create, :update, :destroy]
resources :user_menus, only: [:index]
resources :users, only: [:index, :new, :create, :edit, :update, :destroy]
resources :users, except: :show
resources :menus, param: :date, only: [:edit, :update] do
member do
put :approve
Expand Down
18 changes: 13 additions & 5 deletions test/controllers/web/admin/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Web::Admin::UsersControllerTest < ActionController::TestCase
setup do
@user = create :user, neem: false
@user = create :user_with_user_menus, neem: false
@user_attrs = attributes_for :user
admin_http_login
end
Expand All @@ -18,10 +18,10 @@ class Web::Admin::UsersControllerTest < ActionController::TestCase
end

test 'create' do
user_count = User.count
post :create, params: { user: @user_attrs }
assert_response :redirect
assert { User.count == user_count + 1 }
assert_difference('User.count', +1) do
post :create, params: { user: @user_attrs }
end
assert_redirected_to admin_users_path
end

test 'edit' do
Expand All @@ -36,4 +36,12 @@ class Web::Admin::UsersControllerTest < ActionController::TestCase
assert { @user.reload.email = new_email }
end

test 'destroy' do
assert_difference('User.count', -1) do
delete :destroy, params: { id: @user.id }
end

assert_redirected_to admin_users_path
end

end
10 changes: 10 additions & 0 deletions test/factories/user_menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,15 @@
create_list :user_menu_dish, 3, user_menu: user_menu
end
end

factory :user_menu_with_user_menu_dishes do
transient do
posts_count 5
end
after(:create) do |user_menu, evaluator|
create_list(:user_menu_dish, evaluator.posts_count, user_menu: user_menu)
end
end

end
end
10 changes: 10 additions & 0 deletions test/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
name
email '[email protected]'
description

factory :user_with_user_menus do
transient do
posts_count 5
end
after(:create) do |user, evaluator|
create_list(:user_menu_with_user_menu_dishes, evaluator.posts_count, user: user)
end
end

end
end

0 comments on commit 43489ea

Please sign in to comment.