Sha256: 86199fd0075da43aefac37a0d77e6e9f3bdc4653820cde040546624c386fc79c

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require_relative "spec_helper"
require "active_record"

ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"

ActiveRecord::Schema.define do
  self.verbose = false

  create_table :products, force: true do |t|
    t.string :name
    t.string :slug
    t.integer :category_id
    t.integer :price

    t.timestamps null: true
  end

  create_table :categories, force: true do |t|
    t.string :title
    t.string :slug

    t.timestamps null: true
  end
end

class Product < ActiveRecord::Base
  belongs_to :category
end

class Category < ActiveRecord::Base
end

module ActiveRecord
  class Base
    def self.reset_pk_sequence
      case ActiveRecord::Base.connection.adapter_name
        when "SQLite"
          new_max = maximum(primary_key) || 0
          update_seq_sql = "update sqlite_sequence set seq = #{new_max} where name = '#{table_name}';"
          ActiveRecord::Base.connection.execute(update_seq_sql)
        else
          exit(1)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
trailblazer-finder-0.70.0 spec/spec_helper_active_record.rb
trailblazer-finder-0.50.0 spec/spec_helper_active_record.rb
trailblazer-finder-0.10.3 spec/spec_helper_active_record.rb
trailblazer-finder-0.10.2 spec/spec_helper_active_record.rb
trailblazer-finder-0.10.1 spec/spec_helper_active_record.rb
trailblazer-finder-0.10.0 spec/spec_helper_active_record.rb
trailblazer-finder-0.3.0 spec/spec_helper_active_record.rb
trailblazer-finder-0.2.7 spec/spec_helper_active_record.rb
trailblazer-finder-0.2.6 spec/spec_helper_active_record.rb
trailblazer-finder-0.2.5 spec/spec_helper_active_record.rb