Created
August 29, 2017 22:14
-
-
Save abinoam/d7029f02052b8a05407d4d4c5b1403f3 to your computer and use it in GitHub Desktop.
Bug at paranoia 2.3.1 / rails 5.1.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rails" | |
gem "arel" | |
gem "sqlite3" | |
gem "paranoia" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :posts, force: true do |t| | |
end | |
create_table :post_with_ons, force: true do |t| | |
end | |
create_table :paranoia_posts, force: true do |t| | |
t.timestamp :deleted_at | |
end | |
create_table :paranoia_post_with_ons, force: true do |t| | |
t.timestamp :deleted_at | |
end | |
create_table :comments, force: true do |t| | |
t.integer :post_id | |
end | |
end | |
class CallCounter < ActiveRecord::Base | |
self.abstract_class = true | |
attr_accessor :call_count | |
def increment_call_count | |
@call_count = 0 unless @call_count | |
@call_count += 1 | |
end | |
end | |
class Post < CallCounter | |
after_commit :increment_call_count | |
end | |
class PostWithOn < CallCounter | |
after_commit :increment_call_count, on: [ :create, :update, :destroy ] | |
end | |
class ParanoiaPost < CallCounter | |
acts_as_paranoid | |
after_commit :increment_call_count | |
end | |
class ParanoiaPostWithOn < CallCounter | |
acts_as_paranoid | |
after_commit :increment_call_count, on: [ :create, :update, :destroy ] | |
end | |
class PlainRailsTest < Minitest::Test | |
def setup | |
post.call_count = 0 | |
post.save! | |
assert_equal 1, post.call_count | |
end | |
def teardown | |
assert_equal 2, post.call_count | |
end | |
def post | |
@post ||= post_class.new | |
end | |
def test_after_commit_on_save_callback | |
post.save! | |
end | |
def test_after_commit_on_destroy_callback | |
post.destroy! | |
end | |
def post_class | |
Post | |
end | |
end | |
class PlainRailsTestWithOn < PlainRailsTest | |
def post_class | |
PostWithOn | |
end | |
end | |
class ParanoiaTest < PlainRailsTest | |
def post_class | |
ParanoiaPost | |
end | |
end | |
class ParanoiaTestWithOn < PlainRailsTest | |
def post_class | |
ParanoiaPostWithOn | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment