<commit_before>require "spec_helper"

describe BazaModels::Query do
  include DatabaseHelper

  let!(:user) { User.create!(id: 1, email: "<EMAIL>") }
  let!(:another_user) { User.create!(id: 2, email: "<EMAIL>") }

  it "eq" do
    expect(User.ransack(id_eq: 1).result.to_a).to eq [user]
  end

  it "cont" do
    expect(User.ransack(email_cont: "test").result.to_a).to eq [user]
  end

  it "s" do
    query = User.ransack(s: "email asc")

    expect(query.result.to_a).to eq [another_user, user]
    expect(query.result.to_sql).to eq "SELECT `users`.* FROM `users` ORDER BY `email` asc"
  end
end<commit_msg>Wrote spec to reproduce the problem<commit_after>require "spec_helper"

describe BazaModels::Query do
  include DatabaseHelper

  let!(:organization) { Organization.create!(id: 1, name: "Test organization") }
  let!(:user) { User.create!(id: 1, organization: organization, email: "<EMAIL>") }
  let!(:another_user) { User.create!(id: 2, organization: nil, email: "<EMAIL>") }

  it "eq" do
    expect(User.ransack(id_eq: 1).result.to_a).to eq [user]
  end

  it "cont" do
    expect(User.ransack(email_cont: "test").result.to_a).to eq [user]
  end

  it "s" do
    query = User.ransack(s: "email asc")

    expect(query.result.to_a).to eq [another_user, user]
    expect(query.result.to_sql).to eq "SELECT `users`.* FROM `users` ORDER BY `email` asc"
  end

  it "works with sub models" do
    query = User.ransack(organization_name_cont: "Test")

    expect(query.result.to_a).to eq [user]
  end
end
{'fraction_non_alphanumeric': 0.15695364238410597, 'fraction_numerical': 0.004635761589403974, 'mean_word_length': 4.087542087542087, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6940779', 'n_tokens_mistral': 578, 'n_tokens_neox': 545, 'n_words': 139}