Sha256: 63e8b3fca8187c54e0f23b4e634f1bf9f6f4311a73d4e616ae189e4a938b32d0

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

require 'active_record'
require 'machinist/active_record'

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: ':memory:',
  timeout: 500
)

ActiveRecord::Schema.define(version: 0) do
  create_table :users, force: true do |t|
    t.column :username, :string
  end

  create_table :posts, force: true do |t|
    t.column :title, :string
    t.column :author_id, :integer
    t.column :body, :text
  end

  create_table :comments, force: true do |t|
    t.column :post_id, :integer
    t.column :body, :text
  end

  create_table :tags, force: true do |t|
    t.column :name, :string
  end

  create_table :posts_tags, id: false, force: true do |t|
    t.column :post_id, :integer
    t.column :tag_id, :integer
  end
end

class User < ActiveRecord::Base
  validates_presence_of :username
  validates_uniqueness_of :username
end

class Post < ActiveRecord::Base
  has_many :comments
  belongs_to :author, class_name: 'User'
  has_and_belongs_to_many :tags
end

class Comment < ActiveRecord::Base
  belongs_to :post
end

class Tag < ActiveRecord::Base
  has_and_belongs_to_many :posts
end

module ActiveRecordEnvironment
  def empty_database!
    [User, Post, Comment].each do |klass|
      klass.delete_all
      klass.clear_blueprints!
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
machinist_redux-3.0.4 spec/support/active_record_environment.rb
machinist_redux-3.0.3 spec/support/active_record_environment.rb
machinist_redux-3.0.2 spec/support/active_record_environment.rb
machinist_redux-3.0.0 spec/support/active_record_environment.rb