Skip to content

Instantly share code, notes, and snippets.

@doits
Created December 28, 2020 17:10
Show Gist options
  • Save doits/cb10afbcd907f9a3955c6465af0d090e to your computer and use it in GitHub Desktop.
Save doits/cb10afbcd907f9a3955c6465af0d090e to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
# Create postgres table `bug_report` before running this test
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", github: "rails/rails", branch: '6-1-stable'
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
require 'active_support/testing/assertions'
ActiveRecord::Base.has_many_inversing = true
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "bug_report")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :events, force: true, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
end
create_table :event_applications, force: true, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
t.references :event, type: :uuid, null: false
end
end
class Event < ActiveRecord::Base
has_many :applications, class_name: 'EventApplication', inverse_of: :event, dependent: :destroy
end
class EventApplication < ActiveRecord::Base
belongs_to :event, inverse_of: :applications, touch: true
end
class BugTest < Minitest::Test
include ActiveSupport::Testing::Assertions
def test_association_stuff
event = Event.create!
event.applications.create!
assert_difference 'EventApplication.count', -1 do
EventApplication.last.destroy
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment