<commit_before>Given /^a draft (publication|policy|news article|consultation|speech) "([^"]*)" exists$/ do |document_type, title|
  create("draft_#{document_class(document_type).name.underscore}".to_sym, title: title)
end

Given /^a draft (publication|policy|news article|consultation) "([^"]*)" exists in the "([^"]*)" topic$/ do |document_type, title, topic_name|
  topic = Topic.find_by_name(topic_name)
  create("draft_#{document_class(document_type).name.underscore}".to_sym, title: title, topics: [topic])
end

Given /^a submitted (publication|policy|news article|consultation|speech) "([^"]*)" exists$/ do |document_type, title|
  create("submitted_#{document_class(document_type).name.underscore}".to_sym, title: title)
end

Given /^another user edits the (publication|policy|news article|consultation|speech) "([^"]*)" changing the title to "([^"]*)"$/ do |document_type, original_title, new_title|
  document = document_class(document_type).find_by_title(original_title)
  document.update_attributes!(title: new_title)
end

Given /^a published (publication|policy|news article|consultation|speech) "([^"]*)" that's the responsibility of:$/ do |document_type, title, table|
  document = create(:"published_#{document_type}", title: title)
  table.hashes.each do |row|
    person = Person.find_or_create_by_name(row["Person"])
    ministerial_role = MinisterialRole.find_or_create_by_name(row["Ministerial Role"])
    person.ministerial_roles << ministerial_role
    document.ministerial_roles << ministerial_role
  end
end

When /^I view the (publication|policy|news article|consultation|speech) "([^"]*)"$/ do |document_type, title|
  click_link title
end

When /^I visit the list of draft documents$/ do
  visit admin_documents_path
end

When /^I visit the list of documents awaiting review$/ do
  visit submitted_admin_documents_path
end

When /^I visit the (publication|policy|news article|consultation) "([^"]*)"$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit public_document_path(document)
end

When /^I draft a new (policy|news article) "([^"]*)"$/ do |document_type, title|
  begin_drafting_document type: document_type, title: title
  click_button "Save"
end

When /^I submit the (publication|policy|news article|consultation|speech) "([^"]*)"$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit_document_preview title
  click_button "Submit to 2nd pair of eyes"
end

When /^I publish the (publication|policy|news article|consultation|speech) "([^"]*)"$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit_document_preview title
  click_button "Publish"
end

When /^I force publish the (publication|policy|news article|consultation|speech) "([^"]*)"$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit_document_preview title
  click_button "Force Publish"
end

When /^I save my changes to the (publication|policy|news article|consultation|speech)$/ do |document_type|
  click_button "Save"
end

When /^I edit the (publication|policy|news article|consultation) changing the title to "([^"]*)"$/ do |document_type, new_title|
  fill_in "Title", with: new_title
  click_button "Save"
end

Then /^I should see the (publication|policy|news article|consultation|speech) "([^"]*)" in the list of draft documents$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit admin_documents_path
  assert has_css?(record_css_selector(document))
end

Then /^I should see the (publication|policy|news article|consultation|speech) "([^"]*)" in the list of submitted documents$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit submitted_admin_documents_path
  assert has_css?(record_css_selector(document))
end

Then /^I should see the (publication|policy|news article|consultation|speech) "([^"]*)" in the list of published documents$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit published_admin_documents_path
  assert has_css?(record_css_selector(document))
end

Then /^I should not see the policy "([^"]*)" in the list of draft documents$/ do |title|
  visit admin_documents_path
  assert has_no_css?(".policy a", text: title)
end

Then /^the (publication|policy|news article|consultation|speech) "([^"]*)" should be visible to the public$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit documents_path
  assert page.has_css?(record_css_selector(document), text: title)
end

Then /^I should see in the preview that "([^"]*)" should be in the "([^"]*)" and "([^"]*)" topics$/ do |title, first_topic, second_topic|
  visit_document_preview title
  assert has_css?(".topic", text: first_topic)
  assert has_css?(".topic", text: second_topic)
end

Then /^I should see in the preview that "([^"]*)" should be in the "([^"]*)" and "([^"]*)" organisations$/ do |title, first_org, second_org|
  visit_document_preview title
  assert has_css?(".organisation", text: first_org)
  assert has_css?(".organisation", text: second_org)
end<commit_msg>Use a Transform to reduce duplication in cucumber steps<commit_after>THE_DOCUMENT = Transform(/the (publication|policy|news article|consultation|speech) "([^"]*)"/) do |document_type, title|
  document = document_class(document_type).find_by_title(title)
end

Given /^a draft (publication|policy|news article|consultation|speech) "([^"]*)" exists$/ do |document_type, title|
  create("draft_#{document_class(document_type).name.underscore}".to_sym, title: title)
end

Given /^a draft (publication|policy|news article|consultation) "([^"]*)" exists in the "([^"]*)" topic$/ do |document_type, title, topic_name|
  topic = Topic.find_by_name(topic_name)
  create("draft_#{document_class(document_type).name.underscore}".to_sym, title: title, topics: [topic])
end

Given /^a submitted (publication|policy|news article|consultation|speech) "([^"]*)" exists$/ do |document_type, title|
  create("submitted_#{document_class(document_type).name.underscore}".to_sym, title: title)
end

Given /^another user edits the (publication|policy|news article|consultation|speech) "([^"]*)" changing the title to "([^"]*)"$/ do |document_type, original_title, new_title|
  document = document_class(document_type).find_by_title(original_title)
  document.update_attributes!(title: new_title)
end

Given /^a published (publication|policy|news article|consultation|speech) "([^"]*)" that's the responsibility of:$/ do |document_type, title, table|
  document = create(:"published_#{document_type}", title: title)
  table.hashes.each do |row|
    person = Person.find_or_create_by_name(row["Person"])
    ministerial_role = MinisterialRole.find_or_create_by_name(row["Ministerial Role"])
    person.ministerial_roles << ministerial_role
    document.ministerial_roles << ministerial_role
  end
end

When /^I view the (publication|policy|news article|consultation|speech) "([^"]*)"$/ do |document_type, title|
  click_link title
end

When /^I visit the list of draft documents$/ do
  visit admin_documents_path
end

When /^I visit the list of documents awaiting review$/ do
  visit submitted_admin_documents_path
end

When /^I visit the (publication|policy|news article|consultation) "([^"]*)"$/ do |document_type, title|
  document = document_class(document_type).find_by_title(title)
  visit public_document_path(document)
end

When /^I draft a new (policy|news article) "([^"]*)"$/ do |document_type, title|
  begin_drafting_document type: document_type, title: title
  click_button "Save"
end

When /^I submit (#{THE_DOCUMENT})$/ do |document|
  visit_document_preview document.title
  click_button "Submit to 2nd pair of eyes"
end

When /^I publish (#{THE_DOCUMENT})$/ do |document|
  visit_document_preview document.title
  click_button "Publish"
end

When /^I force publish (#{THE_DOCUMENT})$/ do |document|
  visit_document_preview document.title
  click_button "Force Publish"
end

When /^I save my changes to the (publication|policy|news article|consultation|speech)$/ do |document_type|
  click_button "Save"
end

When /^I edit the (publication|policy|news article|consultation) changing the title to "([^"]*)"$/ do |document_type, new_title|
  fill_in "Title", with: new_title
  click_button "Save"
end

Then /^I should see (#{THE_DOCUMENT}) in the list of draft documents$/ do |document|
  visit admin_documents_path
  assert has_css?(record_css_selector(document))
end

Then /^I should see (#{THE_DOCUMENT}) in the list of submitted documents$/ do |document|
  visit submitted_admin_documents_path
  assert has_css?(record_css_selector(document))
end

Then /^I should see (#{THE_DOCUMENT}) in the list of published documents$/ do |document|
  visit published_admin_documents_path
  assert has_css?(record_css_selector(document))
end

Then /^I should not see the policy "([^"]*)" in the list of draft documents$/ do |title|
  visit admin_documents_path
  assert has_no_css?(".policy a", text: title)
end

Then /^(#{THE_DOCUMENT}) should be visible to the public$/ do |document|
  visit documents_path
  assert page.has_css?(record_css_selector(document), text: document.title)
end

Then /^I should see in the preview that "([^"]*)" should be in the "([^"]*)" and "([^"]*)" topics$/ do |title, first_topic, second_topic|
  visit_document_preview title
  assert has_css?(".topic", text: first_topic)
  assert has_css?(".topic", text: second_topic)
end

Then /^I should see in the preview that "([^"]*)" should be in the "([^"]*)" and "([^"]*)" organisations$/ do |title, first_org, second_org|
  visit_document_preview title
  assert has_css?(".organisation", text: first_org)
  assert has_css?(".organisation", text: second_org)
end
{'fraction_non_alphanumeric': 0.13472659024043826, 'fraction_numerical': 0.00020290149132596124, 'mean_word_length': 6.502283105022831, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3422971', 'n_tokens_mistral': 3252, 'n_tokens_neox': 3124, 'n_words': 838}