From 738785fcb901bbd5a2536c19384be26e72ff09c6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 7 Aug 2018 16:41:11 +0300 Subject: [PATCH 1/4] Add contact tests --- test/models/contact_test.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/models/contact_test.rb diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb new file mode 100644 index 000000000..b4ea6ec38 --- /dev/null +++ b/test/models/contact_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +class ContactTest < ActiveSupport::TestCase + def setup + @contact = contacts(:john) + @original_address_processing_setting = Setting.address_processing + end + + def teardown + Setting.address_processing = @original_address_processing_setting + end + + def test_valid_fixture + assert @contact.valid? + end + + def test_email_validation + @contact.email = '' + assert @contact.invalid? + + @contact.email = 'test@bestmail.test' + assert @contact.valid? + end + + def test_phone_validation + @contact.phone = '' + assert @contact.invalid? + + @contact.phone = '+123.' + assert @contact.invalid? + + @contact.phone = '+123.4' + assert @contact.valid? + end +end \ No newline at end of file From f73a2551d3d61d542983be63ec7773999b57899a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 7 Aug 2018 22:53:02 +0300 Subject: [PATCH 2/4] Improve readability --- test/models/contact_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index b4ea6ec38..e63c0e589 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -14,18 +14,25 @@ class ContactTest < ActiveSupport::TestCase assert @contact.valid? end - def test_email_validation + def test_invalid_without_email @contact.email = '' assert @contact.invalid? + end + + def test_email_format_validation + @contact.email = 'invalid' + assert @contact.invalid? @contact.email = 'test@bestmail.test' assert @contact.valid? end - def test_phone_validation - @contact.phone = '' + def test_invalid_without_phone + @contact.email = '' assert @contact.invalid? + end + def test_phone_format_validation @contact.phone = '+123.' assert @contact.invalid? From 3fc55866b23ce77b550fd7aad1f2bce23cb1b718 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 8 Aug 2018 13:55:54 +0300 Subject: [PATCH 3/4] Use setup callback --- test/models/contact_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index e63c0e589..fc01388a3 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class ContactTest < ActiveSupport::TestCase - def setup + setup do @contact = contacts(:john) @original_address_processing_setting = Setting.address_processing end From 9225d30914364a122fdbb058d4ae1abbc575fc7f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 8 Aug 2018 13:56:14 +0300 Subject: [PATCH 4/4] Remove dead code --- test/models/contact_test.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index fc01388a3..5651cc883 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -3,11 +3,6 @@ require 'test_helper' class ContactTest < ActiveSupport::TestCase setup do @contact = contacts(:john) - @original_address_processing_setting = Setting.address_processing - end - - def teardown - Setting.address_processing = @original_address_processing_setting end def test_valid_fixture