<commit_before>class FixtureBuilder

  def self.build(&block)
    new.instance_eval(&block)
  end

  def covered
    @covered ||= new_covered
  end
  delegate :current_user, to: :covered

  def new_covered options={}
    Covered.new options.merge(
      host: defined?(Capybara) ? Capybara.server_host : 'example.com',
      port: defined?(Capybara) ? Capybara.server_port : 80,
    )
  end
  private :new_covered


  def get_user email_address
    @users_cache ||= {}
    @users_cache[email_address] ||= ::User.find_by_email_address!(email_address)
  end

  def as_an_admin
    @covered = new_covered(current_user_id: get_user('<EMAIL>').id)
    yield
  ensure
    @covered = nil
  end

  def as email_address
    @covered = new_covered(current_user_id: get_user(email_address).id)
    yield
  ensure
    @covered = nil
  end

  def create_organization attributes
    @organization.nil? or raise "you can only create one organization in a fixture builder"
    @organization = covered.organizations.create! attributes.merge(add_current_user_as_a_member: false)
  end

  def organization
    @organization or raise 'please create a organization first'
  end

  def add_member name, email_address
    organization.members.add(name: name, email_address: email_address)
  end

  def web_enable! email_address
    covered.users.find_by_email_address!(email_address).update!(
      password: 'password',
      password_confirmation: 'password'
    )
  end

  def require_current_user_be_web_enabled!
    current_user.web_enabled? or raise "the current user #{current_user.inspect} must be web enabled to do this action."
  end

  def confirm_email_address! email_address
    covered.users.find_by_email_address!(email_address).email_addresses.find_by_address!(email_address).confirm!
  end

  def create_conversation options
    subject = options.fetch(:subject)
    conversation = organization.conversations.create!(subject: subject, creator: current_user)
    create_message conversation, options
  end

  def create_message conversation, options
    message = conversation.messages.create!(options.merge(creator: current_user))
  end

  def reply_to message, options
    message.conversation.messages.create!(options.merge(parent_message: message, creator: current_user))
  end

  def mute_conversation conversation
    conversation.mute!
  end

  def create_task subject
    organization.tasks.create!(subject: subject, creator: current_user)
  end

  def add_doer_to_task task, email_address
    user_record = get_user(email_address)
    user = Covered::User.new(covered, user_record)
    task.doers.add user
  end

  def mark_task_as_done task
    task.done!
  end<commit_msg>fixture builder now uses covered as it was intended to be used :P<commit_after>class FixtureBuilder

  def self.build(&block)
    new.instance_eval(&block)
  end

  def covered
    @covered ||= Covered.new(
      host: defined?(Capybara) ? Capybara.server_host : 'example.com',
      port: defined?(Capybara) ? Capybara.server_port : 80,
    )
  end
  delegate :current_user, to: :covered


  def get_user email_address
    @users_cache ||= {}
    @users_cache[email_address] ||= ::User.find_by_email_address!(email_address)
  end

  def as_an_admin
    covered.current_user_id = get_user('<EMAIL>').id
    yield
  ensure
    covered.current_user_id = nil
  end

  def as email_address
    covered.current_user_id = get_user(email_address).id
    yield
  ensure
    covered.current_user_id = nil
  end

  def create_organization attributes
    @organization.nil? or raise "you can only create one organization in a fixture builder"
    @organization = covered.organizations.create! attributes.merge(add_current_user_as_a_member: false)
  end

  def organization
    @organization or raise 'please create a organization first'
  end

  def add_member name, email_address
    organization.members.add(name: name, email_address: email_address)
  end

  def web_enable! email_address
    covered.users.find_by_email_address!(email_address).update!(
      password: 'password',
      password_confirmation: 'password'
    )
  end

  def require_current_user_be_web_enabled!
    current_user.web_enabled? or raise "the current user #{current_user.inspect} must be web enabled to do this action."
  end

  def confirm_email_address! email_address
    covered.users.find_by_email_address!(email_address).email_addresses.find_by_address!(email_address).confirm!
  end

  def create_conversation options
    subject = options.fetch(:subject)
    conversation = organization.conversations.create!(subject: subject, creator: current_user)
    create_message conversation, options
  end

  def create_message conversation, options
    conversation.messages.create!(options.merge(creator: current_user))
  end

  def reply_to message, options
    message.conversation.messages.create!(options.merge(parent_message: message, creator: current_user))
  end

  def mute_conversation conversation
    conversation.mute!
  end

  def create_task subject
    organization.tasks.create!(subject: subject, creator: current_user)
  end

  def add_doer_to_task task, email_address
    user_record = get_user(email_address)
    user = Covered::User.new(covered, user_record)
    task.doers.add user
  end

  def mark_task_as_done task
    task.done!
  end
{'fraction_non_alphanumeric': 0.07973609802073515, 'fraction_numerical': 0.0007540056550424129, 'mean_word_length': 4.258671952428147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7282825', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1592, 'n_words': 386}