<commit_before>module ProjectFactoryMethods
  def set_project_defaults(attributes)
    attributes[:user_id] ||= @me.id if @me && !attributes[:user_id]
    attributes[:product_id] ||= @product.id if @product && !attributes[:product_id]
    attributes[:area_ids] ||= [Area.last.id] if Area.any? && !attributes[:area_ids]
  end
end

World(ProjectFactoryMethods)

Given /^a project named "([^\"]*)"$/ do |name|
  attributes = {name: name}
  set_project_defaults(attributes)
  @project = Factory(:project, attributes)
  
  @project.reload
end

Given /^a text creation project named "([^\"]*)"$/ do |name|
  attributes = {name: name}
  set_project_defaults(attributes)
  @project = Factory(:text_creation_project, attributes)
  
  @project.reload
end

Then /^I should see the following projects:$/ do |expected_table|
  rows = find('table').all('tr')
  table = rows.map { |r| r.all('th,td').map { |c| c.text.strip } }
  expected_table.diff!(table)
end<commit_msg>Improves product_id attribute of first text creation project<commit_after>module ProjectFactoryMethods
  def set_project_defaults(attributes)
    attributes[:user_id] ||= @me.id if @me && !attributes[:user_id]
    attributes[:product_id] ||= @product.id if @product && !attributes[:product_id]
    attributes[:area_ids] ||= [Area.last.id] if Area.any? && !attributes[:area_ids]
  end
end

World(ProjectFactoryMethods)

Given /^a project named "([^\"]*)"$/ do |name|
  attributes = {name: name}
  set_project_defaults(attributes)
  @project = Factory(:project, attributes)
  
  @project.reload
end

Given /^a text creation project named "([^\"]*)"$/ do |name|
  product = Product.first || Factory(:product)
  attributes = {name: name, product_id: product.id}
  set_project_defaults(attributes)
  @project = Factory(:project, attributes)
  
  @project.reload
end

Then /^I should see the following projects:$/ do |expected_table|
  rows = find('table').all('tr')
  table = rows.map { |r| r.all('th,td').map { |c| c.text.strip } }
  expected_table.diff!(table)
end
{'fraction_non_alphanumeric': 0.15857284440039643, 'fraction_numerical': 0.0, 'mean_word_length': 4.95575221238938, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6876815', 'n_tokens_mistral': 667, 'n_tokens_neox': 655, 'n_words': 157}