paper_trail_scrapbook 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +21 -0
- data/.rspec +5 -0
- data/.rubocop.yml +8 -0
- data/.ruby-gemset +1 -0
- data/Changelog.md +0 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +141 -0
- data/LICENSE.md +21 -0
- data/README.md +77 -0
- data/Rakefile +24 -0
- data/circle.yml +10 -0
- data/lib/paper_trail_scrapbook/changes.rb +89 -0
- data/lib/paper_trail_scrapbook/chapter.rb +49 -0
- data/lib/paper_trail_scrapbook/config.rb +13 -0
- data/lib/paper_trail_scrapbook/life_history.rb +17 -0
- data/lib/paper_trail_scrapbook/version.rb +4 -0
- data/lib/paper_trail_scrapbook.rb +51 -0
- data/paper_trail_scrapbook.gemspec +38 -0
- data/spec/dummy_app/Rakefile +7 -0
- data/spec/dummy_app/app/models/animal.rb +4 -0
- data/spec/dummy_app/app/models/article.rb +24 -0
- data/spec/dummy_app/app/models/authorship.rb +5 -0
- data/spec/dummy_app/app/models/bar_habtm.rb +4 -0
- data/spec/dummy_app/app/models/book.rb +9 -0
- data/spec/dummy_app/app/models/boolit.rb +4 -0
- data/spec/dummy_app/app/models/callback_modifier.rb +45 -0
- data/spec/dummy_app/app/models/car.rb +3 -0
- data/spec/dummy_app/app/models/cat.rb +2 -0
- data/spec/dummy_app/app/models/chapter.rb +9 -0
- data/spec/dummy_app/app/models/citation.rb +5 -0
- data/spec/dummy_app/app/models/custom_primary_key_record.rb +15 -0
- data/spec/dummy_app/app/models/customer.rb +4 -0
- data/spec/dummy_app/app/models/document.rb +6 -0
- data/spec/dummy_app/app/models/dog.rb +2 -0
- data/spec/dummy_app/app/models/editor.rb +4 -0
- data/spec/dummy_app/app/models/editorship.rb +5 -0
- data/spec/dummy_app/app/models/elephant.rb +3 -0
- data/spec/dummy_app/app/models/fluxor.rb +3 -0
- data/spec/dummy_app/app/models/foo_habtm.rb +5 -0
- data/spec/dummy_app/app/models/foo_widget.rb +2 -0
- data/spec/dummy_app/app/models/fruit.rb +5 -0
- data/spec/dummy_app/app/models/gadget.rb +3 -0
- data/spec/dummy_app/app/models/kitchen/banana.rb +5 -0
- data/spec/dummy_app/app/models/legacy_widget.rb +3 -0
- data/spec/dummy_app/app/models/line_item.rb +4 -0
- data/spec/dummy_app/app/models/not_on_update.rb +4 -0
- data/spec/dummy_app/app/models/on/create.rb +6 -0
- data/spec/dummy_app/app/models/on/destroy.rb +6 -0
- data/spec/dummy_app/app/models/on/empty_array.rb +6 -0
- data/spec/dummy_app/app/models/on/update.rb +6 -0
- data/spec/dummy_app/app/models/order.rb +5 -0
- data/spec/dummy_app/app/models/paragraph.rb +5 -0
- data/spec/dummy_app/app/models/person.rb +39 -0
- data/spec/dummy_app/app/models/post.rb +3 -0
- data/spec/dummy_app/app/models/post_with_status.rb +7 -0
- data/spec/dummy_app/app/models/quotation.rb +5 -0
- data/spec/dummy_app/app/models/section.rb +6 -0
- data/spec/dummy_app/app/models/skipper.rb +3 -0
- data/spec/dummy_app/app/models/song.rb +37 -0
- data/spec/dummy_app/app/models/thing.rb +3 -0
- data/spec/dummy_app/app/models/translation.rb +6 -0
- data/spec/dummy_app/app/models/truck.rb +4 -0
- data/spec/dummy_app/app/models/vehicle.rb +4 -0
- data/spec/dummy_app/app/models/whatchamajigger.rb +4 -0
- data/spec/dummy_app/app/models/widget.rb +8 -0
- data/spec/dummy_app/app/models/wotsit.rb +8 -0
- data/spec/dummy_app/app/versions/custom_primary_key_record_version.rb +3 -0
- data/spec/dummy_app/app/versions/joined_version.rb +6 -0
- data/spec/dummy_app/app/versions/json_version.rb +3 -0
- data/spec/dummy_app/app/versions/kitchen/banana_version.rb +5 -0
- data/spec/dummy_app/app/versions/post_version.rb +3 -0
- data/spec/dummy_app/config/application.rb +37 -0
- data/spec/dummy_app/config/boot.rb +24 -0
- data/spec/dummy_app/config/database.sqlite.yml +15 -0
- data/spec/dummy_app/config/database.yml +15 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +36 -0
- data/spec/dummy_app/config/environments/production.rb +74 -0
- data/spec/dummy_app/config/environments/test.rb +46 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/dummy_app/config/initializers/inflections.rb +10 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/paper_trail.rb +1 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +9 -0
- data/spec/dummy_app/config/initializers/session_store.rb +8 -0
- data/spec/dummy_app/config/locales/en.yml +5 -0
- data/spec/dummy_app/config/routes.rb +4 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/db/migrate/20110208155312_set_up_test_tables.rb +344 -0
- data/spec/dummy_app/db/schema.rb +296 -0
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/paper_trail_scrapbook/changes_spec.rb +6 -0
- data/spec/paper_trail_scrapbook/chapter_spec.rb +6 -0
- data/spec/paper_trail_scrapbook/config_spec.rb +17 -0
- data/spec/paper_trail_scrapbook/life_history_spec.rb +6 -0
- data/spec/paper_trail_scrapbook/version_spec.rb +6 -0
- data/spec/paper_trail_scrapbook_spec.rb +4 -0
- data/spec/spec_helper.rb +73 -0
- metadata +363 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
class CallbackModifier < ActiveRecord::Base
|
2
|
+
has_paper_trail on: []
|
3
|
+
|
4
|
+
def test_destroy
|
5
|
+
transaction do
|
6
|
+
run_callbacks(:destroy) do
|
7
|
+
self.deleted = true
|
8
|
+
save!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def flagged_deleted?
|
14
|
+
deleted?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class BeforeDestroyModifier < CallbackModifier
|
19
|
+
has_paper_trail on: []
|
20
|
+
paper_trail.on_destroy :before
|
21
|
+
end
|
22
|
+
|
23
|
+
class AfterDestroyModifier < CallbackModifier
|
24
|
+
has_paper_trail on: []
|
25
|
+
paper_trail.on_destroy :after
|
26
|
+
end
|
27
|
+
|
28
|
+
class NoArgDestroyModifier < CallbackModifier
|
29
|
+
has_paper_trail on: []
|
30
|
+
paper_trail.on_destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
class UpdateModifier < CallbackModifier
|
34
|
+
has_paper_trail on: []
|
35
|
+
paper_trail.on_update
|
36
|
+
end
|
37
|
+
|
38
|
+
class CreateModifier < CallbackModifier
|
39
|
+
has_paper_trail on: []
|
40
|
+
paper_trail.on_create
|
41
|
+
end
|
42
|
+
|
43
|
+
class DefaultModifier < CallbackModifier
|
44
|
+
has_paper_trail
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
class CustomPrimaryKeyRecord < ActiveRecord::Base
|
4
|
+
self.primary_key = :uuid
|
5
|
+
|
6
|
+
has_paper_trail class_name: 'CustomPrimaryKeyRecordVersion'
|
7
|
+
|
8
|
+
# This default_scope is to test the case of the Version#item association
|
9
|
+
# not returning the item due to unmatched default_scope on the model.
|
10
|
+
default_scope { where(name: 'custom_primary_key_record') }
|
11
|
+
|
12
|
+
before_create do
|
13
|
+
self.uuid ||= SecureRandom.uuid
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Person < ActiveRecord::Base
|
2
|
+
has_many :authorships, foreign_key: :author_id, dependent: :destroy
|
3
|
+
has_many :books, through: :authorships
|
4
|
+
belongs_to :mentor, class_name: 'Person', foreign_key: :mentor_id
|
5
|
+
has_paper_trail
|
6
|
+
|
7
|
+
# Convert strings to TimeZone objects when assigned
|
8
|
+
def time_zone=(value)
|
9
|
+
if value.is_a? ActiveSupport::TimeZone
|
10
|
+
super
|
11
|
+
else
|
12
|
+
zone = ::Time.find_zone(value) # nil if can't find time zone
|
13
|
+
super zone
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Store TimeZone objects as strings when serialized to database
|
18
|
+
class TimeZoneSerializer
|
19
|
+
class << self
|
20
|
+
def dump(zone)
|
21
|
+
zone.try(:name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def load(value)
|
25
|
+
::Time.find_zone(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def dump(zone)
|
30
|
+
self.class.dump(zone)
|
31
|
+
end
|
32
|
+
|
33
|
+
def load(value)
|
34
|
+
self.class.load(value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
serialize :time_zone, TimeZoneSerializer.new
|
39
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This model tests ActiveRecord::Enum, which was added in AR 4.1
|
2
|
+
# http://edgeguides.rubyonrails.org/4_1_release_notes.html#active-record-enums
|
3
|
+
class PostWithStatus < ActiveRecord::Base
|
4
|
+
has_paper_trail
|
5
|
+
|
6
|
+
enum status: { draft: 0, published: 1, archived: 2 }
|
7
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module OverrideSongAttributesTheRails4Way
|
2
|
+
def attributes
|
3
|
+
if name
|
4
|
+
super.merge(name: name)
|
5
|
+
else
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def changed_attributes
|
11
|
+
if name
|
12
|
+
super.merge(name: name)
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Song < ActiveRecord::Base
|
20
|
+
has_paper_trail
|
21
|
+
|
22
|
+
# Uses an integer of seconds to hold the length of the song
|
23
|
+
def length=(minutes)
|
24
|
+
write_attribute(:length, minutes.to_i * 60)
|
25
|
+
end
|
26
|
+
|
27
|
+
def length
|
28
|
+
read_attribute(:length) / 60
|
29
|
+
end
|
30
|
+
|
31
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
32
|
+
attribute :name, :string
|
33
|
+
else
|
34
|
+
attr_accessor :name
|
35
|
+
prepend OverrideSongAttributesTheRails4Way
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# The purpose of this custom version class is to test the scope methods on the
|
2
|
+
# VersionConcern::ClassMethods module. See
|
3
|
+
# https://github.com/airblade/paper_trail/issues/295 for more details.
|
4
|
+
class JoinedVersion < PaperTrail::Version
|
5
|
+
default_scope { joins('INNER JOIN widgets ON widgets.id = versions.item_id') }
|
6
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require 'active_record/railtie'
|
5
|
+
require 'action_controller/railtie'
|
6
|
+
|
7
|
+
Bundler.require(:default, Rails.env)
|
8
|
+
require 'paper_trail'
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.encoding = 'utf-8'
|
13
|
+
config.filter_parameters += [:password]
|
14
|
+
config.active_support.escape_html_entities_in_json = true
|
15
|
+
config.active_support.test_order = :sorted
|
16
|
+
|
17
|
+
# Disable assets in rails 4.2. In rails 5, config does not respond to
|
18
|
+
# assets, probably because it was moved out of railties to some other gem,
|
19
|
+
# and we only have dev. dependencies on railties, not all of rails. When
|
20
|
+
# we drop support for rails 4.2, we can remove this whole conditional.
|
21
|
+
config.assets.enabled = false if config.respond_to?(:assets)
|
22
|
+
|
23
|
+
config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'
|
24
|
+
|
25
|
+
# `raise_in_transactional_callbacks` was added in rails 4, then deprecated
|
26
|
+
# in rails 5. Oh, how fickle are the gods.
|
27
|
+
if ActiveRecord.respond_to?(:gem_version)
|
28
|
+
v = ActiveRecord.gem_version
|
29
|
+
if v >= Gem::Version.new('4.2') && v < Gem::Version.new('5.0.0.beta1')
|
30
|
+
config.active_record.raise_in_transactional_callbacks = true
|
31
|
+
end
|
32
|
+
if v >= Gem::Version.new('5.0.0.beta1')
|
33
|
+
config.active_record.time_zone_aware_types = [:datetime]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# We normally use the root project Gemfile (and gemspec), but when we run rake
|
4
|
+
# locally (not on travis) in this dummy app, we set the BUNDLE_GEMFILE env.
|
5
|
+
# variable. The project Gemfile/gemspec allows AR 4.0, which is a problem
|
6
|
+
# because this dummy app uses `enum` in some of its models, and `enum` was
|
7
|
+
# introduced in AR 4.1. So, when we run rake here, we use:
|
8
|
+
#
|
9
|
+
# BUNDLE_GEMFILE=../../gemfiles/ar_4.2.gemfile bundle exec rake
|
10
|
+
#
|
11
|
+
# Once we drop support for AR 4.0 and 4.1 this will be less of a problem, but
|
12
|
+
# we should keep the ability to specify BUNDLE_GEMFILE because the same
|
13
|
+
# situation could come up in the future.
|
14
|
+
unless ENV.key?('BUNDLE_GEMFILE')
|
15
|
+
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
16
|
+
if File.exist?(gemfile)
|
17
|
+
puts "Booting PT test dummy app: Using gemfile: #{gemfile}"
|
18
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
19
|
+
end
|
20
|
+
end
|
21
|
+
require 'bundler'
|
22
|
+
Bundler.setup
|
23
|
+
|
24
|
+
$LOAD_PATH.unshift(File.expand_path('../../../../lib', __FILE__))
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
test: &test
|
4
|
+
adapter: sqlite3
|
5
|
+
pool: 5
|
6
|
+
timeout: 5000
|
7
|
+
database: db/test.sqlite3
|
8
|
+
|
9
|
+
foo:
|
10
|
+
<<: *test
|
11
|
+
database: db/test-foo.sqlite3
|
12
|
+
|
13
|
+
bar:
|
14
|
+
<<: *test
|
15
|
+
database: db/test-bar.sqlite3
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
test: &test
|
4
|
+
adapter: sqlite3
|
5
|
+
pool: 5
|
6
|
+
timeout: 5000
|
7
|
+
database: db/test.sqlite3
|
8
|
+
|
9
|
+
foo:
|
10
|
+
<<: *test
|
11
|
+
database: db/test-foo.sqlite3
|
12
|
+
|
13
|
+
bar:
|
14
|
+
<<: *test
|
15
|
+
database: db/test-bar.sqlite3
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
# config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Log the query plan for queries taking more than this (works
|
26
|
+
# with SQLite, MySQL, and PostgreSQL)
|
27
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
28
|
+
|
29
|
+
# Do not compress assets
|
30
|
+
config.assets.compress = false
|
31
|
+
|
32
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
33
|
+
# This option may cause significant delays in view rendering with a large
|
34
|
+
# number of complex assets.
|
35
|
+
config.assets.debug = true
|
36
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Eager load code on boot. This eager loads most of Rails and
|
8
|
+
# your application in memory, allowing both thread web servers
|
9
|
+
# and those relying on copy on write to perform better.
|
10
|
+
# Rake tasks automatically ignore this option for performance.
|
11
|
+
config.eager_load = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on
|
14
|
+
config.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
|
17
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
18
|
+
config.serve_static_assets = false
|
19
|
+
|
20
|
+
# Compress JavaScripts and CSS
|
21
|
+
config.assets.compress = true
|
22
|
+
|
23
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
24
|
+
config.assets.compile = false
|
25
|
+
|
26
|
+
# Generate digests for assets URLs
|
27
|
+
config.assets.digest = true
|
28
|
+
|
29
|
+
# Defaults to nil and saved in location specified by config.assets.prefix
|
30
|
+
# config.assets.manifest = YOUR_PATH
|
31
|
+
|
32
|
+
# Specifies the header that your server uses for sending files
|
33
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
34
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
35
|
+
|
36
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
37
|
+
# config.force_ssl = true
|
38
|
+
|
39
|
+
# See everything in the log (default is :info)
|
40
|
+
# config.log_level = :debug
|
41
|
+
|
42
|
+
# Prepend all log lines with the following tags
|
43
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
44
|
+
|
45
|
+
# Use a different logger for distributed setups
|
46
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
47
|
+
|
48
|
+
# Use a different cache store in production
|
49
|
+
# config.cache_store = :mem_cache_store
|
50
|
+
|
51
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
52
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
53
|
+
|
54
|
+
# Precompile additional assets (application.js, application.css, and all
|
55
|
+
# non-JS/CSS are already added)
|
56
|
+
# config.assets.precompile += %w( search.js )
|
57
|
+
|
58
|
+
# Disable delivery errors, bad email addresses will be ignored
|
59
|
+
# config.action_mailer.raise_delivery_errors = false
|
60
|
+
|
61
|
+
# Enable threaded mode
|
62
|
+
# config.threadsafe!
|
63
|
+
|
64
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
65
|
+
# the I18n.default_locale when a translation can not be found)
|
66
|
+
config.i18n.fallbacks = true
|
67
|
+
|
68
|
+
# Send deprecation notices to registered listeners
|
69
|
+
config.active_support.deprecation = :notify
|
70
|
+
|
71
|
+
# Log the query plan for queries taking more than this (works
|
72
|
+
# with SQLite, MySQL, and PostgreSQL)
|
73
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
74
|
+
end
|