<commit_before># frozen_string_literal: true

require "test_helper"

class GobiertoPeople::PeopleeControllerTest < GobiertoControllerTest

  def setup
    %w(agendas gifts invitations trips).each do |submodule|
      enable_submodule(site, submodule)
    end
    super
  end

  def site
    @site_with_module_enabled ||= sites(:madrid)
  end

  def person
    @person ||= gobierto_people_people(:richard)
  end

  def set_default_dates(options = {})
    conf = site.configuration
    conf.raw_configuration_variables = <<-YAML
gobierto_people_default_filter_start_date: "#{options[:start_date]}"
gobierto_people_default_filter_end_date: "#{options[:end_date]}"
    YAML
    site.save
  end

  def wide_date_range_params
    @wide_date_range_params ||= { start_date: 10.years.ago.strftime("%Y-%m-%d"), end_date: 10.years.from_now.strftime("%Y-%m-%d") }
  end

  def test_redirect_without_default_dates
    with_current_site(site) do
      get gobierto_people_person_path(person.slug)
      assert_response :success

      person.events.destroy_all
      person.received_gifts.destroy_all
      person.invitations.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :success

      person.trips.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :success
    end
  end

  def test_redirect_with_default_dates
    with_current_site(site) do
      set_default_dates(wide_date_range_params)
      get gobierto_people_person_path(person.slug)
      assert_response :success

      person.events.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :success


      person.events.destroy_all
      person.invitations.destroy_all
      person.trips.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :redirect
      assert_redirected_to(gobierto_people_person_gifts_path(@person.slug))

      get gobierto_people_person_path(person.slug, start_date: "2012-01-01", end_date: "2019-01-01")
      assert_response :redirect
      assert_redirected_to(gobierto_people_person_gifts_path(@person.slug, start_date: "2012-01-01", end_date: "2019-01-01"))
    end
  end
end<commit_msg>Refactor test<commit_after># frozen_string_literal: true

require "test_helper"

class GobiertoPeople::PeopleeControllerTest < GobiertoControllerTest

  def setup
    %w(agendas gifts invitations trips).each do |submodule|
      enable_submodule(site, submodule)
    end
    super
  end

  def site
    @site_with_module_enabled ||= sites(:madrid)
  end

  def person
    @person ||= gobierto_people_people(:richard)
  end

  def set_default_dates(options = {})
    conf = site.configuration
    conf.raw_configuration_variables = <<-YAML
gobierto_people_default_filter_start_date: "#{options[:start_date]}"
gobierto_people_default_filter_end_date: "#{options[:end_date]}"
    YAML
    site.save
  end

  def wide_date_range_params
    @wide_date_range_params ||= { start_date: 10.years.ago.strftime("%Y-%m-%d"), end_date: 10.years.from_now.strftime("%Y-%m-%d") }
  end

  def test_redirect_without_default_dates
    with_current_site(site) do
      get gobierto_people_person_path(person.slug)
      assert_response :success

      person.events.destroy_all
      person.received_gifts.destroy_all
      person.invitations.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :success

      person.trips.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :success
    end
  end

  def test_redirect_with_default_dates
    with_current_site(site) do
      set_default_dates(wide_date_range_params)
      get gobierto_people_person_path(person.slug)
      assert_response :success
    end
  end

  def test_redirect_with_default_dates_and_person_path
    with_current_site(site) do
      set_default_dates(wide_date_range_params)

      person.events.destroy_all
      person.invitations.destroy_all
      person.trips.destroy_all

      get gobierto_people_person_path(person.slug)
      assert_response :redirect
      assert_redirected_to(gobierto_people_person_gifts_path(@person.slug))
    end
  end

  def test_redirect_with_default_dates_and_person_path_with_ranges
    with_current_site(site) do
      set_default_dates(wide_date_range_params)

      person.events.destroy_all
      person.invitations.destroy_all
      person.trips.destroy_all

      get gobierto_people_person_path(person.slug, start_date: "2012-01-01", end_date: "2019-01-01")
      assert_response :redirect
      assert_redirected_to(gobierto_people_person_gifts_path(@person.slug, start_date: "2012-01-01", end_date: "2019-01-01"))
    end
  end
end
{'fraction_non_alphanumeric': 0.07954062101233518, 'fraction_numerical': 0.015312632922160783, 'mean_word_length': 4.173817381738174, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6538681', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1548, 'n_words': 236}