Sha256: 26835056a9d2bdbf52edee978d960b3744e582be096cc01e8e7e27ccd1953e2c

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

describe "arel-mysql-index-hint" do
  describe "#all" do
    subject do
      User.
        all.
        hint(users: {index_users_on_email: hint_type}).
        to_sql
    end

    let(:sql) do
      "SELECT `users`.* " +
      "FROM `users` " +
      "#{hint_type} INDEX (index_users_on_email)"
    end

    let(:hint_type) { :force }

    it { is_expected.to eq sql }
  end

  describe "call nothing" do
    subject do
      User.
        hint(users: {index_users_on_email: hint_type}).
        to_sql
    end

    let(:sql) do
      "SELECT `users`.* " +
      "FROM `users` " +
      "#{hint_type} INDEX (index_users_on_email)"
    end

    let(:hint_type) { :force }

    it { is_expected.to eq sql }
  end

  describe "#limit" do
    subject do
      User.
        limit(1).
        hint(users: {index_users_on_email: hint_type}).
        to_sql
    end

    let(:sql) do
      "SELECT  `users`.* " +
      "FROM `users` " +
      "#{hint_type} INDEX (index_users_on_email)  " +
      "LIMIT 1"
    end

    let(:hint_type) { :force }

    it { is_expected.to eq sql }
  end

  describe "#first" do
    subject do
      User.
        hint(users: {index_users_on_email: hint_type}).
        first
    end

    let(:sql) do
      "SELECT  `users`.* FROM `users` " +
      "#{hint_type} INDEX (index_users_on_email)   " +
      "ORDER BY `users`.`id` ASC " +
      "LIMIT 1"
    end

    let(:hint_type) { :force }

    it do
      subject
      expect(sql_log).to include sql
    end
  end

  describe "#take" do
    subject do
      User.
        hint(users: {index_users_on_email: hint_type}).
        take
    end

    let(:sql) do
      "SELECT  `users`.* FROM `users` " +
      "#{hint_type} INDEX (index_users_on_email)  " +
      "LIMIT 1"
    end

    let(:hint_type) { :force }

    it do
      subject
      expect(sql_log).to include sql
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arel-mysql-index-hint-0.1.1 spec/arel-mysql-index-hint/without_join_spec.rb