<commit_before>RSpec::Matchers.define :owned_payload_eq do |expected|
  match do |actual|
    actual['name'] == expected.name &&
    actual['payload'] == expected.payload &&
    actual['owners'].size == ids(expected).size
  end

  def ids (expected)
    @names ||= expected.users.collect do |user|
      user.id
    end
  end
end

RSpec::Matchers.define :appliance_set_eq do |expected|
  match do |actual|
    actual['name'] == expected.name &&
    actual['id'] == expected.id &&
    actual['priority'] == expected.priority &&
    actual['appliance_set_type'] == expected.appliance_set_type.to_s
  end
end

RSpec::Matchers.define :appliance_type_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['name'] == expected.name &&
    actual['description'] == expected.description &&
    actual['shared'] == expected.shared &&
    actual['scalable'] == expected.scalable &&
    actual['visible_for'] == expected.visible_for &&

    actual['preference_cpu'] == expected.preference_cpu &&
    actual['preference_memory'] == expected.preference_memory &&
    actual['preference_disk'] == expected.preference_disk &&

    #links
    actual['author'] == expected.user_id &&
    actual['security_proxy'] == expected.security_proxy_id
  end
end

RSpec::Matchers.define :http_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
        actual['url'] == expected.url &&
        actual['application_protocol'] == expected.application_protocol &&
        actual['appliance_id'] == expected.appliance_id &&
        actual['port_mapping_template_id'] == expected.port_mapping_template_id
  end
end

RSpec::Matchers.define :port_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
        actual['public_ip'] == expected.public_ip &&
        actual['source_port'] == expected.source_port &&
        actual['port_mapping_template_id'] == expected.port_mapping_template.id &&
        actual['virtual_machine_id'] == expected.virtual_machine.id
  end
end

RSpec::Matchers.define :http_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['url'] == expected.url &&
    actual['application_protocol'] == expected.application_protocol &&
    actual['appliance_id'] == expected.appliance_id &&
    actual['port_mapping_template_id'] == expected.port_mapping_template_id
  end
end

RSpec::Matchers.define :port_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['public_ip'] == expected.public_ip &&
    actual['source_port'] == expected.source_port &&
    actual['port_mapping_template_id'] == expected.port_mapping_template.id &&
    actual['virtual_machine_id'] == expected.virtual_machine.id
  end
end

RSpec::Matchers.define :config_template_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['name'] == expected.name &&
    actual['payload'] == expected.payload &&
    actual['appliance_type_id'] == expected.appliance_type.id
  end
end

RSpec::Matchers.define :config_instance_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
        actual['payload'] == expected.payload &&
        actual['appliance_configuration_template_id'] == expected.appliance_configuration_template.id
  end
end

RSpec::Matchers.define :config_instance_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['payload'] == expected.payload &&
    actual['appliance_configuration_template_id'] == expected.appliance_configuration_template.id
  end
end

RSpec::Matchers.define :port_mapping_template_eq do |expected|
  match do |actual|
    (actual['id'] == expected.id) &&
    (actual['transport_protocol'] == expected.transport_protocol) &&
    (actual['application_protocol'] == expected.application_protocol) &&
    (actual['service_name'] == expected.service_name) &&
    (actual['target_port'] == expected.target_port) &&
    ((actual['appliance_type_id'] = expected.appliance_type.id) or (actual['dev_mode_property_set_id'] = expected.dev_mode_property_set.id))
  end<commit_msg>another PMT matchers fix :(<commit_after>RSpec::Matchers.define :owned_payload_eq do |expected|
  match do |actual|
    actual['name'] == expected.name &&
    actual['payload'] == expected.payload &&
    actual['owners'].size == ids(expected).size
  end

  def ids (expected)
    @names ||= expected.users.collect do |user|
      user.id
    end
  end
end

RSpec::Matchers.define :appliance_set_eq do |expected|
  match do |actual|
    actual['name'] == expected.name &&
    actual['id'] == expected.id &&
    actual['priority'] == expected.priority &&
    actual['appliance_set_type'] == expected.appliance_set_type.to_s
  end
end

RSpec::Matchers.define :appliance_type_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['name'] == expected.name &&
    actual['description'] == expected.description &&
    actual['shared'] == expected.shared &&
    actual['scalable'] == expected.scalable &&
    actual['visible_for'] == expected.visible_for &&

    actual['preference_cpu'] == expected.preference_cpu &&
    actual['preference_memory'] == expected.preference_memory &&
    actual['preference_disk'] == expected.preference_disk &&

    #links
    actual['author'] == expected.user_id &&
    actual['security_proxy'] == expected.security_proxy_id
  end
end

RSpec::Matchers.define :http_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
        actual['url'] == expected.url &&
        actual['application_protocol'] == expected.application_protocol &&
        actual['appliance_id'] == expected.appliance_id &&
        actual['port_mapping_template_id'] == expected.port_mapping_template_id
  end
end

RSpec::Matchers.define :port_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
        actual['public_ip'] == expected.public_ip &&
        actual['source_port'] == expected.source_port &&
        actual['port_mapping_template_id'] == expected.port_mapping_template.id &&
        actual['virtual_machine_id'] == expected.virtual_machine.id
  end
end

RSpec::Matchers.define :http_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['url'] == expected.url &&
    actual['application_protocol'] == expected.application_protocol &&
    actual['appliance_id'] == expected.appliance_id &&
    actual['port_mapping_template_id'] == expected.port_mapping_template_id
  end
end

RSpec::Matchers.define :port_mapping_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['public_ip'] == expected.public_ip &&
    actual['source_port'] == expected.source_port &&
    actual['port_mapping_template_id'] == expected.port_mapping_template.id &&
    actual['virtual_machine_id'] == expected.virtual_machine.id
  end
end

RSpec::Matchers.define :config_template_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['name'] == expected.name &&
    actual['payload'] == expected.payload &&
    actual['appliance_type_id'] == expected.appliance_type.id
  end
end

RSpec::Matchers.define :config_instance_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
        actual['payload'] == expected.payload &&
        actual['appliance_configuration_template_id'] == expected.appliance_configuration_template.id
  end
end

RSpec::Matchers.define :config_instance_eq do |expected|
  match do |actual|
    actual['id'] == expected.id &&
    actual['payload'] == expected.payload &&
    actual['appliance_configuration_template_id'] == expected.appliance_configuration_template.id
  end
end

RSpec::Matchers.define :port_mapping_template_eq do |expected|
  match do |actual|
    (actual['id'] == expected.id) &&
    (actual['transport_protocol'] == expected.transport_protocol) &&
    (actual['application_protocol'] == expected.application_protocol) &&
    (actual['service_name'] == expected.service_name) &&
    (actual['target_port'] == expected.target_port) &&
    ((expected.appliance_type && (actual['appliance_type_id'] == expected.appliance_type_id)) or
     (expected.dev_mode_property_set && (actual['dev_mode_property_set_id'] == expected.dev_mode_property_set.id)))
  end
end

RSpec::Matchers.define :be_updated_by_port_mapping_template do |expected|
  match do |actual|
    (actual['transport_protocol'] == expected[:transport_protocol] || expected[:transport_protocol].blank?) &&
    (actual['application_protocol'] == expected[:application_protocol] || expected[:application_protocol].blank?) &&
    (actual['service_name'] == expected[:service_name] || expected[:service_name].blank?) &&
    (actual['target_port'] == expected[:target_port] || expected[:target_port].blank?) &&
    ((actual['appliance_type_id'] == expected[:appliance_type_id]) or (actual['dev_mode_property_set_id'] == expected[:dev_mode_property_set_id]) or
     (expected[:appliance_type_id].blank? && expected[:dev_mode_property_set_id].blank?))
  end
{'fraction_non_alphanumeric': 0.1487850882059248, 'fraction_numerical': 0.0, 'mean_word_length': 4.770806658130602, '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': '7453383', 'n_tokens_mistral': 2735, 'n_tokens_neox': 2690, 'n_words': 474}