Convert specs to tests

This commit is contained in:
Artur Beljajev 2017-11-22 04:35:06 +02:00
parent 61b6df197e
commit 93b0037c39
6 changed files with 48 additions and 60 deletions

View file

@ -1,18 +0,0 @@
require 'test_helper'
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_creates_new_registrar
assert_difference -> { Registrar.count } do
post admin_registrars_path, registrar: attributes_for(:registrar)
end
end
def test_redirects_to_newly_created_registrar
post admin_registrars_path, registrar: attributes_for(:registrar)
assert_redirected_to admin_registrar_path(Registrar.first)
end
end

View file

@ -1,13 +0,0 @@
require 'test_helper'
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_accounting_customer_code
registrar = create(:registrar, accounting_customer_code: 'test accounting customer code')
visit admin_registrar_path(registrar)
assert_text 'test accounting customer code'
end
end

View file

@ -2,39 +2,29 @@ require 'test_helper'
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
login_as users(:admin)
@registrar = registrars(:valid)
end
def test_updates_website
registrar = create(:registrar, website: 'test')
patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(website: 'new.example.com')
@registrar.reload
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, website: 'new-website')
registrar.reload
assert_equal 'new-website', registrar.website
assert_equal 'new.example.com', @registrar.website
end
def test_updates_email
registrar = create(:registrar, email: 'test@test.com')
patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(email: 'new@example.com')
@registrar.reload
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, email: 'new-test@test.com')
registrar.reload
assert_equal 'new-test@test.com', registrar.email
assert_equal 'new@example.com', @registrar.email
end
def test_updates_billing_email
registrar = create(:registrar, billing_email: 'test@test.com')
patch admin_registrar_path(@registrar),
registrar: @registrar.attributes.merge(billing_email: 'new-billing@example.com')
@registrar.reload
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, billing_email: 'new-test@test.com')
registrar.reload
assert_equal 'new-test@test.com', registrar.billing_email
end
def test_redirects_to_registrar
registrar = create(:registrar)
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar)
assert_redirected_to admin_registrar_path(registrar)
assert_equal 'new-billing@example.com', @registrar.billing_email
end
end

View file

@ -2,16 +2,16 @@ require 'test_helper'
class EditRegistrarTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
login_as users(:admin)
@registrar = registrars(:valid)
end
def test_updates_registrar
registrar = create(:registrar)
visit admin_registrar_path(registrar)
visit admin_registrar_path(@registrar)
click_link_or_button 'Edit'
click_link_or_button 'Update registrar'
assert_current_path admin_registrar_path(@registrar)
assert_text 'Registrar has been successfully updated'
end
end

View file

@ -0,0 +1,15 @@
require 'test_helper'
class ShowRegistrarTest < ActionDispatch::IntegrationTest
include ActionView::Helpers::NumberHelper
def setup
login_as users(:admin)
@registrar = registrars(:complete)
visit admin_registrar_path(@registrar)
end
def test_accounting_customer_code
assert_text 'ACCOUNT001'
end
end

View file

@ -1,9 +1,23 @@
require 'test_helper'
class RegistrarTest < ActiveSupport::TestCase
def setup
@registrar = registrars(:valid)
end
def test_valid
assert @registrar.valid?
end
def test_rejects_absent_accounting_customer_code
registrar = Registrar.new(accounting_customer_code: nil)
registrar.validate
assert registrar.errors.added?(:accounting_customer_code, :blank)
@registrar.accounting_customer_code = nil
@registrar.validate
assert @registrar.invalid?
end
def test_requires_country_code
@registrar.country_code = nil
@registrar.validate
assert @registrar.invalid?
end
end