<commit_before>RSpec.describe MiqAeMethod do
  let(:user) { FactoryBot.create(:user_with_group) }
  it "should return editable as false if the parent namespace/class is not editable" do
    n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                            :class_id => c1.id,
                            :name     => "foo_method",
                            :scope    => "instance",
                            :language => "ruby",
                            :location => "inline")
    expect(f1.editable?(user)).to be_falsey
  end

  it "should return editable as true if the parent namespace/class is editable" do
    n1 = FactoryBot.create(:miq_ae_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                            :class_id => c1.id,
                            :name     => "foo_method",
                            :scope    => "instance",
                            :language => "ruby",
                            :location => "inline")
    expect(f1.editable?(user)).to be_truthy
  end

  it "should lookup method" do
    n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                           :class_id => c1.id,
                           :name     => "foo_method",
                           :scope    => "instance",
                           :language => "ruby",
                           :location => "inline")
    expect(f1.editable?(user)).to be_falsey

    expect(MiqAeMethod.lookup_by_class_id_and_name(c1.id, "foo_method")).to eq(f1)
  end

  context "#copy" do
    let(:d2) { FactoryBot.create(:miq_ae_domain, :name => "domain2", :priority => 2) }
    let(:ns1) { FactoryBot.create(:miq_ae_namespace, :name => "ns1", :parent => @d1) }
    let(:m1) { FactoryBot.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method1", :scope => "instance", :language => "ruby", :location => "inline") }
    let(:m2) { FactoryBot.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method2", :scope => "instance", :language => "ruby", :location => "inline") }
    before do
      @d1 = FactoryBot.create(:miq_ae_domain, :name => "domain1", :parent => nil, :priority => 1)
      @cls1 = FactoryBot.create(:miq_ae_class, :name => "cls1", :namespace_id => ns1.id)
      @ns2 = FactoryBot.create(:miq_ae_namespace, :name => "ns2", :parent => d2)
    end

    it "copies instances under specified namespace" do<commit_msg>add spec showing current valid? query count<commit_after>RSpec.describe MiqAeMethod do
  let(:user) { FactoryBot.create(:user_with_group) }
  it "should return editable as false if the parent namespace/class is not editable" do
    n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                            :class_id => c1.id,
                            :name     => "foo_method",
                            :scope    => "instance",
                            :language => "ruby",
                            :location => "inline")
    expect(f1.editable?(user)).to be_falsey
  end

  it "should return editable as true if the parent namespace/class is editable" do
    n1 = FactoryBot.create(:miq_ae_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                            :class_id => c1.id,
                            :name     => "foo_method",
                            :scope    => "instance",
                            :language => "ruby",
                            :location => "inline")
    expect(f1.editable?(user)).to be_truthy
  end

  it "should lookup method" do
    n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                           :class_id => c1.id,
                           :name     => "foo_method",
                           :scope    => "instance",
                           :language => "ruby",
                           :location => "inline")
    expect(f1.editable?(user)).to be_falsey

    expect(MiqAeMethod.lookup_by_class_id_and_name(c1.id, "foo_method")).to eq(f1)
  end

  it "doesn’t access database when unchanged model is saved" do
    n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => user.current_tenant)
    c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo")
    f1 = FactoryBot.create(:miq_ae_method,
                           :class_id => c1.id,
                           :name     => "foo_method",
                           :scope    => "instance",
                           :language => "ruby",
                           :location => "inline")
    expect { f1.valid? }.to make_database_queries(:count => 1)
  end

  context "#copy" do
    let(:d2) { FactoryBot.create(:miq_ae_domain, :name => "domain2", :priority => 2) }
    let(:ns1) { FactoryBot.create(:miq_ae_namespace, :name => "ns1", :parent => @d1) }
    let(:m1) { FactoryBot.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method1", :scope => "instance", :language => "ruby", :location => "inline") }
    let(:m2) { FactoryBot.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method2", :scope => "instance", :language => "ruby", :location => "inline") }
    before do
      @d1 = FactoryBot.create(:miq_ae_domain, :name => "domain1", :parent => nil, :priority => 1)
      @cls1 = FactoryBot.create(:miq_ae_class, :name => "cls1", :namespace_id => ns1.id)
      @ns2 = FactoryBot.create(:miq_ae_namespace, :name => "ns2", :parent => d2)
    end

    it "copies instances under specified namespace" do
{'fraction_non_alphanumeric': 0.14363929146537843, 'fraction_numerical': 0.014331723027375202, 'mean_word_length': 2.233211868818324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 102, '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': '1666129', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1986, 'n_words': 411}