From f8b18455c7731417c65731f3dff05a9bd8a78c39 Mon Sep 17 00:00:00 2001 From: Oscar Wyatt Date: Thu, 16 Aug 2018 13:07:28 +0100 Subject: [PATCH 1/5] Extend wait time for failing test --- test/integration/links_out_config_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/links_out_config_test.rb b/test/integration/links_out_config_test.rb index c25fb86c1..baa3b2034 100644 --- a/test/integration/links_out_config_test.rb +++ b/test/integration/links_out_config_test.rb @@ -51,7 +51,7 @@ def assert_has_supergroup_navigation(expected_supergroups) test "links out configuration causes no errors and correct supergroups are displayed for each ruleset" do stub_rummager setup_variant_b - using_wait_time 10 do + using_wait_time 30 do taxon_config.each_key do |taxonomy_rule_level| taxon_config[taxonomy_rule_level].each_key do |rules_for_taxon| setup_and_visit_content_item_with_taxonomy_grouping("guide", taxonomy_rule_level => rules_for_taxon) From 9cf2dbd3d76e0652939620c98e7246c10d6572ed Mon Sep 17 00:00:00 2001 From: Oscar Wyatt Date: Thu, 16 Aug 2018 13:48:12 +0100 Subject: [PATCH 2/5] Move configuration to before_initialize block --- config/application.rb | 4 +++- test/integration/links_out_config_test.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/application.rb b/config/application.rb index 08773ca4a..ae1e224f1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,6 +50,8 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. # config.active_record.raise_in_transactional_callbacks = true - config.taxonomy_navigation_links_out = config_for(:taxonomy_navigation_links_out) + config.before_initialize do + config.taxonomy_navigation_links_out = config_for(:taxonomy_navigation_links_out) + end end end diff --git a/test/integration/links_out_config_test.rb b/test/integration/links_out_config_test.rb index baa3b2034..e21e5f0ce 100644 --- a/test/integration/links_out_config_test.rb +++ b/test/integration/links_out_config_test.rb @@ -33,7 +33,7 @@ def default_taxonomy_grouping end def taxon_config - Rails.configuration.taxonomy_navigation_links_out || YAML.safe_load(File.read("config/taxonomy_navigation_links_out.yml"))["default"] + Rails.configuration.taxonomy_navigation_links_out end def expected_supergroups(rule_level) @@ -59,7 +59,7 @@ def assert_has_supergroup_navigation(expected_supergroups) if expected_supergroups.any? assert_has_supergroup_navigation(expected_supergroups) else - refute page.has_css?('taxonomy-navigation') + refute page.has_css?('.taxonomy-navigation') end end end From 9256af353828584e8d73d85cf57e3b54eda7a87c Mon Sep 17 00:00:00 2001 From: Andrew Garner Date: Fri, 17 Aug 2018 11:24:57 +0100 Subject: [PATCH 3/5] Stub taxonomy navigation links out correctly --- test/presenters/content_item/links_out_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/presenters/content_item/links_out_test.rb b/test/presenters/content_item/links_out_test.rb index 651ef3d71..8902f2fd2 100644 --- a/test/presenters/content_item/links_out_test.rb +++ b/test/presenters/content_item/links_out_test.rb @@ -80,7 +80,7 @@ def other_rules end def stub_load_rules(rules) - Rails.configuration.taxonomy_navigation_links_out = rules + Rails.configuration.stubs(:taxonomy_navigation_links_out).returns(rules) end def assert_has_supergroup_rule(rule_set) From fbe2aa87cfc76dc07cb6953a7f2c8802927e30d1 Mon Sep 17 00:00:00 2001 From: Andrew Garner Date: Fri, 17 Aug 2018 13:39:33 +0100 Subject: [PATCH 4/5] Refactor LinksOutConfigTest test Dynamically generate the tests, not the assertions based on the links out config. This will allow us to see which test is failing and decreases the chance of a test timing out. --- test/integration/links_out_config_test.rb | 79 ++++++++--------------- 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/test/integration/links_out_config_test.rb b/test/integration/links_out_config_test.rb index e21e5f0ce..7f6da48e9 100644 --- a/test/integration/links_out_config_test.rb +++ b/test/integration/links_out_config_test.rb @@ -3,66 +3,41 @@ class LinksOutConfigTest < ActionDispatch::IntegrationTest include ContentPagesNavTestHelper include GdsApi::TestHelpers::Rummager + include Capybara::Minitest::Assertions - def schema_type - "guide" - end + Rails.configuration.taxonomy_navigation_links_out.each do |name, group| + group.each do |level, rules| + test "links out configuration for #{name} #{level}" do + stub_rummager + setup_variant_b - def setup_variant_b - ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(true) - end + content_example = get_example_guide_with_single_taxon + content_example[name] = level - def setup_and_visit_content_item_with_taxonomy_grouping(name, taxonomy_grouping) - taxonomy_grouping = default_taxonomy_grouping.merge(taxonomy_grouping) - @content_item = get_content_example(name).tap do |item| - item["links"]["taxons"] = SINGLE_TAXON - item["content_purpose_supergroup"] = taxonomy_grouping["content_purpose_supergroup"] - item["content_purpose_subgroup"] = taxonomy_grouping["content_purpose_subgroup"] - item["document_type"] = taxonomy_grouping["document_type"] - content_store_has_item(item["base_path"], item.to_json) - visit_with_cachebust(item["base_path"]) - end - end + content_store_has_item content_example['base_path'], content_example.to_json + visit_with_cachebust content_example['base_path'] - def default_taxonomy_grouping - { - "content_purpose_supergroup" => "guidance_and_regulation", - "content_purpose_subgroup" => "guidance", - "document_type" => "guide" - } - end - - def taxon_config - Rails.configuration.taxonomy_navigation_links_out - end - - def expected_supergroups(rule_level) - rule_level.map { |rules| rules["supergroup"].humanize } - end - - def assert_has_supergroup_navigation(expected_supergroups) - within('.taxonomy-navigation') do - expected_supergroups.each do |supergroup| - assert page.has_css?('.gem-c-heading', text: supergroup) + if rules.empty? + refute_css '.taxonomy-navigation' + else + rules.each do |rule| + assert_css '.taxonomy-navigation .gem-c-heading', text: rule['supergroup'].humanize + end + end end end end - test "links out configuration causes no errors and correct supergroups are displayed for each ruleset" do - stub_rummager - setup_variant_b - using_wait_time 30 do - taxon_config.each_key do |taxonomy_rule_level| - taxon_config[taxonomy_rule_level].each_key do |rules_for_taxon| - setup_and_visit_content_item_with_taxonomy_grouping("guide", taxonomy_rule_level => rules_for_taxon) - expected_supergroups = expected_supergroups(taxon_config[taxonomy_rule_level][rules_for_taxon]) - if expected_supergroups.any? - assert_has_supergroup_navigation(expected_supergroups) - else - refute page.has_css?('.taxonomy-navigation') - end - end - end + def get_example_guide_with_single_taxon + get_content_example_by_schema_and_name('guide', 'guide').tap do |item| + item['content_purpose_subgroup'] = 'guidance' + item['content_purpose_supergroup'] = 'guidance_and_regulation' + item['document_type'] = 'guide' + item['links']['taxons'] = SINGLE_TAXON end end + + def setup_variant_b + ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(true) + end end From 1d735b7ea3cdfb3463de68fcffc9c38a0a042dc6 Mon Sep 17 00:00:00 2001 From: Andrew Garner Date: Fri, 17 Aug 2018 13:46:03 +0100 Subject: [PATCH 5/5] Load custom configuration as documented Let's see if the approach set out in the Rails documentation works now that we have refactored related tests. --- config/application.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config/application.rb b/config/application.rb index ae1e224f1..127410522 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,8 +50,7 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. # config.active_record.raise_in_transactional_callbacks = true - config.before_initialize do - config.taxonomy_navigation_links_out = config_for(:taxonomy_navigation_links_out) - end + # Load links out configuration for taxonomy navigation + config.taxonomy_navigation_links_out = config_for(:taxonomy_navigation_links_out) end end