Sha256: 70adf94127cf609d5ee094f111e035bdfb117659ba9ebf9fd7883328a2442292

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'bundler'
Bundler.require

require 'active_record'
require 'minitest/autorun'
require 'logger'

$LOAD_PATH << File.join(__dir__, 'lib')

ActiveRecord::Base.establish_connection
ActiveRecord::Base.logger = Logger.new(STDOUT)

# DATABASE_URL=mysql2://mysql/database?pool=1 ruby test.rb

begin
  ActiveRecord::Tasks::DatabaseTasks.create_current('default_env')
rescue
end

ActiveRecord::Base.establish_connection

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
  end

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

class Post < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :post
end

class BugTest < Minitest::Test
  def setup
    Post.destroy_all
    Comment.destroy_all
  end

  def test_association_stuff
    post = Post.create!
    post.comments << Comment.create!

    assert_equal 1, post.comments.count
    assert_equal 1, Comment.count
    assert_equal post.id, Comment.first.post.id
  end

  def test_transaction
    assert_equal 0, Post.count

    Post.transaction do
      Post.create!
      Post.transaction(requires_new: true) do
        Post.create!

        raise ActiveRecord::Rollback
      end
    end

    assert_equal 1, Post.count
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-aws_data_service_mysql-adapter-0.1.0 test.rb