Added tests for Credentials
Removed routes from credentials that aren't used along with controller actions
This commit is contained in:
parent
5885620d50
commit
ae7846e46e
@ -1,7 +1,7 @@
|
||||
Rails.application.routes.draw do
|
||||
|
||||
resources :domains do
|
||||
resources :credentials
|
||||
resources :credentials, only: [ :new, :create, :edit, :update, :destroy]
|
||||
resources :virtuals
|
||||
end
|
||||
|
||||
|
||||
@ -1,49 +1,78 @@
|
||||
require "test_helper"
|
||||
|
||||
class CredentialsControllerTest < ActionDispatch::IntegrationTest
|
||||
include Devise::Test::IntegrationHelpers
|
||||
|
||||
setup do
|
||||
@credential = credentials(:one)
|
||||
@domain = domains(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get credentials_url
|
||||
assert_response :success
|
||||
test "should not get new" do
|
||||
get new_domain_credential_url(@domain.id)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_credential_url
|
||||
sign_in users(:bob)
|
||||
get new_domain_credential_url(@domain.id)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create credential" do
|
||||
test "should not create credential because we are not logged in" do
|
||||
assert_no_difference("Credential.count") do
|
||||
post domain_credentials_url(@domain.id), params: { credential: { email: "steve", password: "ThePassword12345%" } }
|
||||
end
|
||||
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should create credential because we are logged in" do
|
||||
sign_in users(:bob)
|
||||
assert_difference("Credential.count") do
|
||||
post credentials_url, params: { credential: { email: @credential.email, password: @credential.password } }
|
||||
post domain_credentials_url(@domain.id), params: { credential: { email: "steve", password: "ThePassword12345%" } }
|
||||
end
|
||||
|
||||
assert_redirected_to credential_url(Credential.last)
|
||||
assert_redirected_to domain_path(@domain.id)
|
||||
end
|
||||
|
||||
test "should show credential" do
|
||||
get credential_url(@credential)
|
||||
test "should get edit not get edit because we are not logged in" do
|
||||
get edit_domain_credential_url(@domain,@credential)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should get edit because we are logged in" do
|
||||
sign_in users(:bob)
|
||||
get edit_domain_credential_url(@domain,@credential)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_credential_url(@credential)
|
||||
assert_response :success
|
||||
test "should not update credential because we are not logged in" do
|
||||
patch domain_credential_url(@domain,@credential), params: { credential: { email: @credential.email, password: @credential.password } }
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should update credential" do
|
||||
patch credential_url(@credential), params: { credential: { email: @credential.email, password: @credential.password } }
|
||||
assert_redirected_to credential_url(@credential)
|
||||
test "should update credential because we are logged in" do
|
||||
sign_in users(:bob)
|
||||
patch domain_credential_url(@domain,@credential), params: { credential: { email: @credential.email, password: @credential.password } }
|
||||
assert_redirected_to domain_url(@domain)
|
||||
end
|
||||
|
||||
test "should destroy credential" do
|
||||
test "should not destroy credential because we are not logged in" do
|
||||
assert_no_difference("Credential.count") do
|
||||
delete domain_credential_url(@domain,@credential)
|
||||
end
|
||||
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "should destroy credential because we are logged in" do
|
||||
sign_in users(:bob)
|
||||
assert_difference("Credential.count", -1) do
|
||||
delete credential_url(@credential)
|
||||
delete domain_credential_url(@domain,@credential)
|
||||
end
|
||||
|
||||
assert_redirected_to credentials_url
|
||||
assert_redirected_to domain_url(@domain)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -6,7 +6,7 @@ class DomainsControllerTest < ActionDispatch::IntegrationTest
|
||||
@domain = domains(:one)
|
||||
end
|
||||
|
||||
test "not should get index because we are not logged in" do
|
||||
test "not should get index because user not logged in" do
|
||||
get domains_url
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
2
test/fixtures/credentials.yml
vendored
2
test/fixtures/credentials.yml
vendored
@ -3,7 +3,9 @@
|
||||
one:
|
||||
email: bob@example.net
|
||||
password: MyString
|
||||
domain: one
|
||||
|
||||
two:
|
||||
email: alice@example.org
|
||||
password: MyString
|
||||
domain: two
|
||||
|
||||
@ -19,7 +19,7 @@ class CredentialTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "domain added to name" do
|
||||
@c = Credential.new(email: "jez", password: "1234567&ab", domain_id: domains(:one).id)
|
||||
@c = Credential.new(email: "jez@#{domains(:one).domain}", password: "1234567&ab", domain_id: domains(:one).id)
|
||||
assert @c.save
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user