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
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :domains do
|
resources :domains do
|
||||||
resources :credentials
|
resources :credentials, only: [ :new, :create, :edit, :update, :destroy]
|
||||||
resources :virtuals
|
resources :virtuals
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,49 +1,78 @@
|
|||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class CredentialsControllerTest < ActionDispatch::IntegrationTest
|
class CredentialsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
include Devise::Test::IntegrationHelpers
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@credential = credentials(:one)
|
@credential = credentials(:one)
|
||||||
|
@domain = domains(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should not get new" do
|
||||||
get credentials_url
|
get new_domain_credential_url(@domain.id)
|
||||||
assert_response :success
|
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get new" do
|
test "should get new" do
|
||||||
get new_credential_url
|
sign_in users(:bob)
|
||||||
|
get new_domain_credential_url(@domain.id)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
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
|
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
|
end
|
||||||
|
|
||||||
assert_redirected_to credential_url(Credential.last)
|
assert_redirected_to domain_path(@domain.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show credential" do
|
test "should get edit not get edit because we are not logged in" do
|
||||||
get credential_url(@credential)
|
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
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get edit" do
|
test "should not update credential because we are not logged in" do
|
||||||
get edit_credential_url(@credential)
|
patch domain_credential_url(@domain,@credential), params: { credential: { email: @credential.email, password: @credential.password } }
|
||||||
assert_response :success
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update credential" do
|
test "should update credential because we are logged in" do
|
||||||
patch credential_url(@credential), params: { credential: { email: @credential.email, password: @credential.password } }
|
sign_in users(:bob)
|
||||||
assert_redirected_to credential_url(@credential)
|
patch domain_credential_url(@domain,@credential), params: { credential: { email: @credential.email, password: @credential.password } }
|
||||||
|
assert_redirected_to domain_url(@domain)
|
||||||
end
|
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
|
assert_difference("Credential.count", -1) do
|
||||||
delete credential_url(@credential)
|
delete domain_credential_url(@domain,@credential)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to credentials_url
|
assert_redirected_to domain_url(@domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,7 +6,7 @@ class DomainsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
@domain = domains(:one)
|
@domain = domains(:one)
|
||||||
end
|
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
|
get domains_url
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|||||||
2
test/fixtures/credentials.yml
vendored
2
test/fixtures/credentials.yml
vendored
@ -3,7 +3,9 @@
|
|||||||
one:
|
one:
|
||||||
email: bob@example.net
|
email: bob@example.net
|
||||||
password: MyString
|
password: MyString
|
||||||
|
domain: one
|
||||||
|
|
||||||
two:
|
two:
|
||||||
email: alice@example.org
|
email: alice@example.org
|
||||||
password: MyString
|
password: MyString
|
||||||
|
domain: two
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class CredentialTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "domain added to name" do
|
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
|
assert @c.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user