<commit_before>require "test_helper"

class CountriesControllerTest < ActionController::TestCase
  test "index should display a list of countries" do
    bat = create(:country, name: "British Antarctic Territory")
    png = create(:country, name: "Papua New Guinea")

    get :index

    assert_select ".countries" do
      assert_select_object bat
      assert_select_object png
    end
  end

  test "shows only published news articles" do
    published_document = create(:published_news_article)
    draft_document = create(:draft_news_article)
    country = create(:country, documents: [published_document, draft_document])

    get :show, id: country

    assert_select "#news_articles" do
      assert_select_object(published_document)
      assert_select_object(draft_document, count: 0)
    end
  end

  test "shows only news articles associated with country" do
    published_document = create(:published_news_article)
    another_published_document = create(:published_news_article)
    country = create(:country, documents: [published_document])

    get :show, id: country

    assert_select "#news_articles" do
      assert_select_object(published_document)
      assert_select_object(another_published_document, count: 0)
    end
  end

  test "shows most recent news articles at the top" do
    later_document = create(:published_news_article, published_at: 1.hour.ago)
    earlier_document = create(:published_news_article, published_at: 2.hours.ago)
    country = create(:country, documents: [earlier_document, later_document])

    get :show, id: country

    expected_ids = [later_document, earlier_document].map { |d| dom_id(d) }
    assert_select "#news_articles .news_article" do |news_articles|
      assert_equal expected_ids, news_articles.map { |a| a["id"] }
    end
  end

  test "should not display an empty published news articles section" do
    country = create(:country, documents: [])

    get :show, id: country

    assert_select "#news_articles", count: 0
  end

  test "shows only published policies" do
    published_document = create(:published_policy)
    draft_document = create(:draft_policy)
    country = create(:country, documents: [published_document, draft_document])

    get :show, id: country

    assert_select "#policies" do
      assert_select_object(published_document)
      assert_select_object(draft_document, count: 0)
    end
  end

  test "shows only policies associated with country" do
    published_document = create(:published_policy)
    another_published_document = create(:published_policy)
    country = create(:country, documents: [published_document])

    get :show, id: country

    assert_select "#policies" do
      assert_select_object(published_document)
      assert_select_object(another_published_document, count: 0)
    end
  end

  test "shows most recent policies at the top" do
    later_document = create(:published_policy, published_at: 1.hour.ago)
    earlier_document = create(:published_policy, published_at: 2.hours.ago)
    country = create(:country, documents: [earlier_document, later_document])

    get :show, id: country

    expected_ids = [later_document, earlier_document].map { |d| dom_id(d) }
    assert_select "#policies .policy" do |policies|
      assert_equal expected_ids, policies.map { |a| a["id"] }
    end
  end

  test "should not display an empty published policies section" do
    country = create(:country, documents: [])

    get :show, id: country

    assert_select "#policies", count: 0
  end
end<commit_msg>Simplify tests checking the order of countries.<commit_after>require "test_helper"

class CountriesControllerTest < ActionController::TestCase
  test "index should display a list of countries" do
    bat = create(:country, name: "British Antarctic Territory")
    png = create(:country, name: "Papua New Guinea")

    get :index

    assert_select ".countries" do
      assert_select_object bat
      assert_select_object png
    end
  end

  test "shows only published news articles" do
    published_document = create(:published_news_article)
    draft_document = create(:draft_news_article)
    country = create(:country, documents: [published_document, draft_document])

    get :show, id: country

    assert_select "#news_articles" do
      assert_select_object(published_document)
      assert_select_object(draft_document, count: 0)
    end
  end

  test "shows only news articles associated with country" do
    published_document = create(:published_news_article)
    another_published_document = create(:published_news_article)
    country = create(:country, documents: [published_document])

    get :show, id: country

    assert_select "#news_articles" do
      assert_select_object(published_document)
      assert_select_object(another_published_document, count: 0)
    end
  end

  test "shows most recent news articles at the top" do
    later_document = create(:published_news_article, published_at: 1.hour.ago)
    earlier_document = create(:published_news_article, published_at: 2.hours.ago)
    country = create(:country, documents: [earlier_document, later_document])

    get :show, id: country

    assert_equal [later_document, earlier_document], assigns[:news_articles]
  end

  test "should not display an empty published news articles section" do
    country = create(:country, documents: [])

    get :show, id: country

    assert_select "#news_articles", count: 0
  end

  test "shows only published policies" do
    published_document = create(:published_policy)
    draft_document = create(:draft_policy)
    country = create(:country, documents: [published_document, draft_document])

    get :show, id: country

    assert_select "#policies" do
      assert_select_object(published_document)
      assert_select_object(draft_document, count: 0)
    end
  end

  test "shows only policies associated with country" do
    published_document = create(:published_policy)
    another_published_document = create(:published_policy)
    country = create(:country, documents: [published_document])

    get :show, id: country

    assert_select "#policies" do
      assert_select_object(published_document)
      assert_select_object(another_published_document, count: 0)
    end
  end

  test "shows most recent policies at the top" do
    later_document = create(:published_policy, published_at: 1.hour.ago)
    earlier_document = create(:published_policy, published_at: 2.hours.ago)
    country = create(:country, documents: [earlier_document, later_document])

    get :show, id: country

    assert_equal [later_document, earlier_document], assigns[:policies]
  end

  test "should not display an empty published policies section" do
    country = create(:country, documents: [])

    get :show, id: country

    assert_select "#policies", count: 0
  end
end
{'fraction_non_alphanumeric': 0.0828931924882629, 'fraction_numerical': 0.0029342723004694834, 'mean_word_length': 4.359276729559748, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2393217', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1880, 'n_words': 553}