<commit_before>class PageFragment
  include RSpec::Matchers

  delegate :select, to: :@element

  def initialize element = nil
    @element = element || page
  end

  def method_missing method, *args, &block
    if @element.respond_to? method
      @element.send method, *args, &block
    else
      super
    end
  end

  def class_names
    @element[:class].split(' ')
  end

  def has_class_name?(name)
    class_names.include?(name)
  end

  def session
    if Capybara::Session === @element
      @element
    else
      @element.session
    end
  end

  def view_card card_name, overlay_class=nil, &block
    find('.card-content', text: card_name).click
    overlay_class ||= begin
                      "#{card_name.gsub ' ', ''}Overlay".constantize
                    rescue NameError
                      CardOverlay
                    end
    overlay = overlay_class.new session.find(".overlay", visible: false)
    if block_given?
      block.call overlay
      overlay.dismiss
      expect(session).to have_no_css('.overlay.in')
    else
      overlay
    end
  end

  protected

  def select_from_chosen(item_text, options={})
    session.execute_script(%Q!$(".#{options[:class]}.chosen-container:first").mousedown()!)
    find(".#{options[:class]}.chosen-container input[type=text]").set(item_text)
    session.execute_script(%Q!$(".#{options[:class]}.chosen-container:first input").trigger(jQuery.Event("keyup", { keyCode: 13 }))!)
  end

  def wait_for_pjax
    sleep 0.1
  end

  def wait_for_turbolinks
    sleep 0.3
  end
end

class Page < PageFragment
  include Capybara::DSL

  class << self<commit_msg>changed capybara method to fix page.rb<commit_after>class PageFragment
  include RSpec::Matchers

  delegate :select, to: :@element

  def initialize element = nil
    @element = element || page
  end

  def method_missing method, *args, &block
    if @element.respond_to? method
      @element.send method, *args, &block
    else
      super
    end
  end

  def class_names
    @element[:class].split(' ')
  end

  def has_class_name?(name)
    class_names.include?(name)
  end

  def session
    if Capybara::Session === @element
      @element
    else
      @element.session
    end
  end

  def view_card card_name, overlay_class=nil, &block
    find('.card-content', text: card_name).click
    overlay_class ||= begin
                      "#{card_name.gsub ' ', ''}Overlay".constantize
                    rescue NameError
                      CardOverlay
                    end
    overlay = overlay_class.new session.find(".overlay", visible: false)
    if block_given?
      block.call overlay
      overlay.dismiss
      expect(session.has_css?('.overlay.in')).to eq false
    else
      overlay
    end
  end

  protected

  def select_from_chosen(item_text, options={})
    session.execute_script(%Q!$(".#{options[:class]}.chosen-container:first").mousedown()!)
    find(".#{options[:class]}.chosen-container input[type=text]").set(item_text)
    session.execute_script(%Q!$(".#{options[:class]}.chosen-container:first input").trigger(jQuery.Event("keyup", { keyCode: 13 }))!)
  end

  def wait_for_pjax
    sleep 0.1
  end

  def wait_for_turbolinks
    sleep 0.3
  end
end

class Page < PageFragment
  include Capybara::DSL

  class << self
{'fraction_non_alphanumeric': 0.1178082191780822, 'fraction_numerical': 0.0036529680365296802, 'mean_word_length': 2.7813578826237055, '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': '2457898', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1019, 'n_words': 229}