Fix Style/StringLiterals: Use double quotes

This commit is contained in:
Jared Beck 2016-03-05 17:07:32 -05:00
parent 5672fd7d31
commit 8980f08d0e
93 changed files with 1096 additions and 1097 deletions

View File

@ -47,3 +47,9 @@ Style/DoubleNegation:
# concatenate multiline strings with `+` or use a HEREDOC.
Style/LineEndConcatenation:
Enabled: false
# The Ruby Style Guide does not prescribe a particular quote character, only
# that a project should pick one and be consistent. The decision has no
# performance implications. Double quotes are slightly easier to read.
Style/StringLiterals:
EnforcedStyle: double_quotes

View File

@ -343,13 +343,6 @@ Style/SpaceInsideParens:
Style/SpecialGlobalVars:
Enabled: false
# Offense count: 519
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.

View File

@ -1,2 +1,2 @@
source 'https://rubygems.org'
source "https://rubygems.org"
gemspec

View File

@ -1,30 +1,30 @@
require 'bundler'
require "bundler"
Bundler::GemHelper.install_tasks
desc 'Set a relevant database.yml for testing'
desc "Set a relevant database.yml for testing"
task :prepare do
ENV["DB"] ||= "sqlite"
FileUtils.cp "test/dummy/config/database.#{ENV["DB"]}.yml", "test/dummy/config/database.yml"
end
require 'rake/testtask'
desc 'Run tests on PaperTrail with Test::Unit.'
require "rake/testtask"
desc "Run tests on PaperTrail with Test::Unit."
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end
require 'rspec/core/rake_task'
desc 'Run tests on PaperTrail with RSpec'
require "rspec/core/rake_task"
desc "Run tests on PaperTrail with RSpec"
task(:spec).clear
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false # hide list of specs bit.ly/1nVq3Jn
end
require 'rubocop/rake_task'
require "rubocop/rake_task"
RuboCop::RakeTask.new
desc 'Default: run all available test suites'
desc "Default: run all available test suites"
task default: [:rubocop, :prepare, :test, :spec]

View File

@ -2,25 +2,25 @@
# It is based on the ActiveRecord template.
# https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
ruby '2.2.3'
source 'https://rubygems.org'
gem 'activerecord', '4.2.0'
gem 'minitest', '5.8.3'
gem 'paper_trail', '4.0.0', require: false
gem 'sqlite3'
ruby "2.2.3"
source "https://rubygems.org"
gem "activerecord", "4.2.0"
gem "minitest", "5.8.3"
gem "paper_trail", "4.0.0", require: false
gem "sqlite3"
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
require "active_record"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
@ -48,12 +48,12 @@ ActiveRecord::Schema.define do
end
add_index :version_associations, [:version_id]
add_index :version_associations, [:foreign_key_name, :foreign_key_id],
name: 'index_version_associations_on_foreign_key'
name: "index_version_associations_on_foreign_key"
end
# We must wait to require `paper_trail.rb` until after the
# `version_associations` table exists or else PT won't track associations.
require 'paper_trail'
require "paper_trail"
class User < ActiveRecord::Base
has_paper_trail

View File

@ -1,11 +1,11 @@
require 'rails/generators'
require 'rails/generators/active_record'
require "rails/generators"
require "rails/generators/active_record"
module PaperTrail
class InstallGenerator < ::Rails::Generators::Base
include ::Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)
class_option(
:with_changes,
type: :boolean,
@ -19,14 +19,14 @@ module PaperTrail
desc: "Store transactional IDs to support association restoration"
)
desc 'Generates (but does not run) a migration to add a versions table.'
desc "Generates (but does not run) a migration to add a versions table."
def create_migration_file
add_paper_trail_migration('create_versions')
add_paper_trail_migration('add_object_changes_to_versions') if options.with_changes?
add_paper_trail_migration("create_versions")
add_paper_trail_migration("add_object_changes_to_versions") if options.with_changes?
if options.with_associations?
add_paper_trail_migration('create_version_associations')
add_paper_trail_migration('add_transaction_id_column_to_versions')
add_paper_trail_migration("create_version_associations")
add_paper_trail_migration("add_transaction_id_column_to_versions")
end
end
@ -37,7 +37,7 @@ module PaperTrail
protected
def add_paper_trail_migration(template)
migration_dir = File.expand_path('db/migrate')
migration_dir = File.expand_path("db/migrate")
if self.class.migration_exists?(migration_dir, template)
warn "Migration already exists: #{template}"
else

View File

@ -8,13 +8,13 @@ class CreateVersionAssociations < ActiveRecord::Migration
add_index :version_associations, [:version_id]
add_index :version_associations,
[:foreign_key_name, :foreign_key_id],
name: 'index_version_associations_on_foreign_key'
name: "index_version_associations_on_foreign_key"
end
def self.down
remove_index :version_associations, [:version_id]
remove_index :version_associations,
name: 'index_version_associations_on_foreign_key'
name: "index_version_associations_on_foreign_key"
drop_table :version_associations
end
end

View File

@ -58,7 +58,7 @@ class CreateVersions < ActiveRecord::Migration
#
def versions_table_options
if MYSQL_ADAPTERS.include?(connection.class.name)
{ options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_col' }
{ options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_col" }
else
{}
end

View File

@ -1,13 +1,13 @@
require 'request_store'
require "request_store"
# Require files in lib/paper_trail, but not its subdirectories.
Dir[File.join(File.dirname(__FILE__), 'paper_trail', '*.rb')].each do |file|
require File.join('paper_trail', File.basename(file, '.rb'))
Dir[File.join(File.dirname(__FILE__), "paper_trail", "*.rb")].each do |file|
require File.join("paper_trail", File.basename(file, ".rb"))
end
# Require serializers
Dir[File.join(File.dirname(__FILE__), 'paper_trail', 'serializers', '*.rb')].each do |file|
require File.join('paper_trail', 'serializers', File.basename(file, '.rb'))
Dir[File.join(File.dirname(__FILE__), "paper_trail", "serializers", "*.rb")].each do |file|
require File.join("paper_trail", "serializers", File.basename(file, ".rb"))
end
module PaperTrail
@ -164,7 +164,7 @@ end
unless PaperTrail.active_record_protected_attributes?
PaperTrail.send(:remove_instance_variable, :@active_record_protected_attributes)
begin
require 'protected_attributes'
require "protected_attributes"
rescue LoadError # rubocop:disable Lint/HandleExceptions
# In case `protected_attributes` gem is not available.
end
@ -175,9 +175,9 @@ ActiveSupport.on_load(:active_record) do
end
# Require frameworks
require 'paper_trail/frameworks/sinatra'
if defined?(::Rails) && ActiveRecord::VERSION::STRING >= '3.2'
require 'paper_trail/frameworks/rails'
require "paper_trail/frameworks/sinatra"
if defined?(::Rails) && ActiveRecord::VERSION::STRING >= "3.2"
require "paper_trail/frameworks/rails"
else
require 'paper_trail/frameworks/active_record'
require "paper_trail/frameworks/active_record"
end

View File

@ -32,7 +32,7 @@ module PaperTrail
[:type_cast_for_database, :type_cast_from_database]
end
if ::ActiveRecord::VERSION::STRING < '4.2'
if ::ActiveRecord::VERSION::STRING < "4.2"
# Backport Rails 4.2 and later's `type_for_attribute` to build
# on a common interface.
def type_for_attribute(attr_name)

View File

@ -1,5 +1,5 @@
require 'singleton'
require 'paper_trail/serializers/yaml'
require "singleton"
require "paper_trail/serializers/yaml"
module PaperTrail
class Config

View File

@ -1,4 +1,4 @@
require 'paper_trail/version_concern'
require "paper_trail/version_concern"
module PaperTrail
class Version < ::ActiveRecord::Base

View File

@ -1,4 +1,4 @@
require 'paper_trail/version_association_concern'
require "paper_trail/version_association_concern"
module PaperTrail
class VersionAssociation < ::ActiveRecord::Base

View File

@ -1,5 +1,5 @@
require 'paper_trail/frameworks/rails/controller'
require 'paper_trail/frameworks/rails/engine'
require "paper_trail/frameworks/rails/controller"
require "paper_trail/frameworks/rails/engine"
module PaperTrail
module Rails

View File

@ -1,7 +1,7 @@
module PaperTrail
module Rails
class Engine < ::Rails::Engine
paths['app/models'] << 'lib/paper_trail/frameworks/active_record/models'
paths["app/models"] << "lib/paper_trail/frameworks/active_record/models"
end
end
end

View File

@ -1,6 +1,6 @@
require 'rspec/core'
require 'rspec/matchers'
require 'paper_trail/frameworks/rspec/helpers'
require "rspec/core"
require "rspec/matchers"
require "paper_trail/frameworks/rspec/helpers"
RSpec.configure do |config|
config.include ::PaperTrail::RSpec::Helpers::InstanceMethods

View File

@ -15,7 +15,7 @@ module PaperTrail
module ClassMethods
# enable versioning for specific blocks (at class-level)
def with_versioning(&block)
context 'with versioning', versioning: true do
context "with versioning", versioning: true do
class_exec(&block)
end
end

View File

@ -1,4 +1,4 @@
require 'active_support/core_ext/object' # provides the `try` method
require "active_support/core_ext/object" # provides the `try` method
module PaperTrail
module Sinatra

View File

@ -1,5 +1,5 @@
require 'active_support/core_ext/object' # provides the `try` method
require 'paper_trail/attributes_serialization'
require "active_support/core_ext/object" # provides the `try` method
require "paper_trail/attributes_serialization"
module PaperTrail
module Model
@ -70,7 +70,7 @@ module PaperTrail
attr_accessor self.version_association_name
class_attribute :version_class_name
self.version_class_name = options[:class_name] || 'PaperTrail::Version'
self.version_class_name = options[:class_name] || "PaperTrail::Version"
class_attribute :paper_trail_options
@ -115,12 +115,12 @@ module PaperTrail
end
# Record version before or after "destroy" event
def paper_trail_on_destroy(recording_order = 'before')
def paper_trail_on_destroy(recording_order = "before")
unless %w[after before].include?(recording_order.to_s)
fail ArgumentError, 'recording order can only be "after" or "before"'
end
if recording_order == 'after' &&
if recording_order == "after" &&
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("5")
if ::ActiveRecord::Base.belongs_to_required_by_default
::ActiveSupport::Deprecation.warn(
@ -262,7 +262,7 @@ module PaperTrail
# Temporarily overwrites the value of whodunnit and then executes the
# provided block.
def whodunnit(value)
raise ArgumentError, 'expected to receive a block' unless block_given?
raise ArgumentError, "expected to receive a block" unless block_given?
current_whodunnit = PaperTrail.whodunnit
PaperTrail.whodunnit = value
yield self
@ -307,7 +307,7 @@ module PaperTrail
def record_create
if paper_trail_switched_on?
data = {
event: paper_trail_event || 'create',
event: paper_trail_event || "create",
whodunnit: PaperTrail.whodunnit
}
if respond_to?(:updated_at)
@ -316,7 +316,7 @@ module PaperTrail
if pt_record_object_changes? && changed_notably?
data[:object_changes] = pt_recordable_object_changes
end
if self.class.paper_trail_version_class.column_names.include?('transaction_id')
if self.class.paper_trail_version_class.column_names.include?("transaction_id")
data[:transaction_id] = PaperTrail.transaction_id
end
version = send(self.class.versions_association_name).create! merge_metadata(data)
@ -328,7 +328,7 @@ module PaperTrail
def record_update(force = nil)
if paper_trail_switched_on? && (force || changed_notably?)
data = {
event: paper_trail_event || 'update',
event: paper_trail_event || "update",
object: pt_recordable_object,
whodunnit: PaperTrail.whodunnit
}
@ -338,7 +338,7 @@ module PaperTrail
if pt_record_object_changes?
data[:object_changes] = pt_recordable_object_changes
end
if self.class.paper_trail_version_class.column_names.include?('transaction_id')
if self.class.paper_trail_version_class.column_names.include?("transaction_id")
data[:transaction_id] = PaperTrail.transaction_id
end
version = send(self.class.versions_association_name).create merge_metadata(data)
@ -352,7 +352,7 @@ module PaperTrail
# @api private
def pt_record_object_changes?
paper_trail_options[:save_changes] &&
self.class.paper_trail_version_class.column_names.include?('object_changes')
self.class.paper_trail_version_class.column_names.include?("object_changes")
end
# Returns an object which can be assigned to the `object` attribute of a
@ -416,11 +416,11 @@ module PaperTrail
data = {
item_id: self.id,
item_type: self.class.base_class.name,
event: paper_trail_event || 'destroy',
event: paper_trail_event || "destroy",
object: pt_recordable_object,
whodunnit: PaperTrail.whodunnit
}
if self.class.paper_trail_version_class.column_names.include?('transaction_id')
if self.class.paper_trail_version_class.column_names.include?("transaction_id")
data[:transaction_id] = PaperTrail.transaction_id
end
version = self.class.paper_trail_version_class.create(merge_metadata(data))
@ -456,7 +456,7 @@ module PaperTrail
end
def set_transaction_id(version)
return unless self.class.paper_trail_version_class.column_names.include?('transaction_id')
return unless self.class.paper_trail_version_class.column_names.include?("transaction_id")
if PaperTrail.transaction? && PaperTrail.transaction_id.nil?
PaperTrail.transaction_id = version.id
version.transaction_id = version.id
@ -477,7 +477,7 @@ module PaperTrail
elsif v.is_a?(Symbol) && respond_to?(v)
# If it is an attribute that is changing in an existing object,
# be sure to grab the current version.
if has_attribute?(v) && send("#{v}_changed?".to_sym) && data[:event] != 'create'
if has_attribute?(v) && send("#{v}_changed?".to_sym) && data[:event] != "create"
send("#{v}_was".to_sym)
else
send(v)

View File

@ -105,7 +105,7 @@ module PaperTrail
array.map! do |record|
if (version = versions.delete(record.id)).nil?
record
elsif version.event == 'create'
elsif version.event == "create"
options[:mark_for_destruction] ? record.tap(&:mark_for_destruction) : nil
else
version.reify(options.merge(has_many: false, has_one: false))
@ -141,7 +141,7 @@ module PaperTrail
order("#{version_table_name}.id ASC").
first
if version
if version.event == 'create'
if version.event == "create"
if options[:mark_for_destruction]
model.send(assoc.name).mark_for_destruction if model.send(assoc.name, true)
else

View File

@ -1,4 +1,4 @@
require 'active_support/json'
require "active_support/json"
module PaperTrail
module Serializers

View File

@ -1,4 +1,4 @@
require 'yaml'
require "yaml"
module PaperTrail
module Serializers
@ -23,7 +23,7 @@ module PaperTrail
# in the serialized object_changes
def where_object_changes_condition(arel_field, field, value)
# Need to check first (before) and secondary (after) fields
if (defined?(::YAML::ENGINE) && ::YAML::ENGINE.yamler == 'psych') ||
if (defined?(::YAML::ENGINE) && ::YAML::ENGINE.yamler == "psych") ||
(defined?(::Psych) && ::YAML == ::Psych)
arel_field.matches("%\n#{field}:\n- #{value}\n%").
or(arel_field.matches("%\n#{field}:\n-%\n- #{value}\n%"))

View File

@ -1,4 +1,4 @@
require 'active_support/concern'
require "active_support/concern"
module PaperTrail
module VersionAssociationConcern

View File

@ -1,4 +1,4 @@
require 'active_support/concern'
require "active_support/concern"
module PaperTrail
module VersionConcern
@ -41,19 +41,19 @@ module PaperTrail
end
def creates
where event: 'create'
where event: "create"
end
def updates
where event: 'update'
where event: "update"
end
def destroys
where event: 'destroy'
where event: "destroy"
end
def not_creates
where 'event <> ?', 'create'
where "event <> ?", "create"
end
# Returns versions after `obj`.
@ -86,7 +86,7 @@ module PaperTrail
obj = obj.send(PaperTrail.timestamp_field) if obj.is_a?(self)
where(arel_table[PaperTrail.timestamp_field].lt(obj)).
order(self.timestamp_sort_order('desc'))
order(self.timestamp_sort_order("desc"))
end
def between(start_time, end_time)
@ -98,7 +98,7 @@ module PaperTrail
# Defaults to using the primary key as the secondary sort order if
# possible.
def timestamp_sort_order(direction = 'asc')
def timestamp_sort_order(direction = "asc")
[arel_table[PaperTrail.timestamp_field].send(direction.downcase)].tap do |array|
array << arel_table[primary_key].send(direction.downcase) if self.primary_key_is_int?
end
@ -107,11 +107,11 @@ module PaperTrail
# Performs an attribute search on the serialized object by invoking the
# identically-named method in the serializer being used.
def where_object(args = {})
raise ArgumentError, 'expected to receive a Hash' unless args.is_a?(Hash)
raise ArgumentError, "expected to receive a Hash" unless args.is_a?(Hash)
if columns_hash['object'].type == :jsonb
if columns_hash["object"].type == :jsonb
where("object @> ?", args.to_json)
elsif columns_hash['object'].type == :json
elsif columns_hash["object"].type == :json
predicates = []
values = []
args.each do |field, value|
@ -130,12 +130,12 @@ module PaperTrail
end
def where_object_changes(args = {})
raise ArgumentError, 'expected to receive a Hash' unless args.is_a?(Hash)
raise ArgumentError, "expected to receive a Hash" unless args.is_a?(Hash)
if columns_hash['object_changes'].type == :jsonb
if columns_hash["object_changes"].type == :jsonb
args.each { |field, value| args[field] = [value] }
where("object_changes @> ?", args.to_json)
elsif columns_hash['object'].type == :json
elsif columns_hash["object"].type == :json
predicates = []
values = []
args.each do |field, value|
@ -164,13 +164,13 @@ module PaperTrail
# Returns whether the `object` column is using the `json` type supported
# by PostgreSQL.
def object_col_is_json?
[:json, :jsonb].include?(columns_hash['object'].type)
[:json, :jsonb].include?(columns_hash["object"].type)
end
# Returns whether the `object_changes` column is using the `json` type
# supported by PostgreSQL.
def object_changes_col_is_json?
[:json, :jsonb].include?(columns_hash['object_changes'].try(:type))
[:json, :jsonb].include?(columns_hash["object_changes"].try(:type))
end
end
@ -212,7 +212,7 @@ module PaperTrail
# `ActiveModel::Dirty#changes`. returns `nil` if your `versions` table does
# not have an `object_changes` text column.
def changeset
return nil unless self.class.column_names.include? 'object_changes'
return nil unless self.class.column_names.include? "object_changes"
@changeset ||= load_changeset
end

View File

@ -3,9 +3,9 @@ module PaperTrail
MAJOR = 5
MINOR = 0
TINY = 0
PRE = 'pre'
PRE = "pre"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
def self.to_s
STRING

View File

@ -1,52 +1,52 @@
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'paper_trail/version_number'
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "paper_trail/version_number"
Gem::Specification.new do |s|
s.name = 'paper_trail'
s.name = "paper_trail"
s.version = PaperTrail.version
s.platform = Gem::Platform::RUBY
s.summary = "Track changes to your models' data. Good for auditing or versioning."
s.description = s.summary
s.homepage = 'https://github.com/airblade/paper_trail'
s.authors = ['Andy Stewart', 'Ben Atkins']
s.email = 'batkinz@gmail.com'
s.license = 'MIT'
s.homepage = "https://github.com/airblade/paper_trail"
s.authors = ["Andy Stewart", "Ben Atkins"]
s.email = "batkinz@gmail.com"
s.license = "MIT"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ['lib']
s.require_paths = ["lib"]
s.required_rubygems_version = '>= 1.3.6'
s.required_ruby_version = '>= 1.9.3'
s.required_rubygems_version = ">= 1.3.6"
s.required_ruby_version = ">= 1.9.3"
s.add_dependency 'activerecord', ['>= 3.0', '< 6.0']
s.add_dependency 'activesupport', ['>= 3.0', '< 6.0']
s.add_dependency 'request_store', '~> 1.1'
s.add_dependency "activerecord", [">= 3.0", "< 6.0"]
s.add_dependency "activesupport", [">= 3.0", "< 6.0"]
s.add_dependency "request_store", "~> 1.1"
s.add_development_dependency 'appraisal', '~> 2.1'
s.add_development_dependency 'rake', '~> 10.4.2'
s.add_development_dependency 'shoulda', '~> 3.5.0'
s.add_development_dependency 'ffaker', '~> 2.1.0'
s.add_development_dependency 'railties', ['>= 3.0', '< 6.0']
s.add_development_dependency 'sinatra', '~> 1.4.6'
s.add_development_dependency 'rack-test', '~> 0.6.3'
s.add_development_dependency 'rspec-rails', '~> 3.4.0'
s.add_development_dependency 'generator_spec', '~> 0.9.3'
s.add_development_dependency 'database_cleaner', '~> 1.2'
s.add_development_dependency 'pry-nav', '~> 0.2.4'
s.add_development_dependency 'rubocop', '~> 0.37.2'
s.add_development_dependency 'timecop', '~> 0.8.0'
s.add_development_dependency "appraisal", "~> 2.1"
s.add_development_dependency "rake", "~> 10.4.2"
s.add_development_dependency "shoulda", "~> 3.5.0"
s.add_development_dependency "ffaker", "~> 2.1.0"
s.add_development_dependency "railties", [">= 3.0", "< 6.0"]
s.add_development_dependency "sinatra", "~> 1.4.6"
s.add_development_dependency "rack-test", "~> 0.6.3"
s.add_development_dependency "rspec-rails", "~> 3.4.0"
s.add_development_dependency "generator_spec", "~> 0.9.3"
s.add_development_dependency "database_cleaner", "~> 1.2"
s.add_development_dependency "pry-nav", "~> 0.2.4"
s.add_development_dependency "rubocop", "~> 0.37.2"
s.add_development_dependency "timecop", "~> 0.8.0"
if defined?(JRUBY_VERSION)
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', '~> 1.3.15'
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter', '~> 1.3.15'
s.add_development_dependency 'activerecord-jdbcmysql-adapter', '~> 1.3.15'
s.add_development_dependency "activerecord-jdbcsqlite3-adapter", "~> 1.3.15"
s.add_development_dependency "activerecord-jdbcpostgresql-adapter", "~> 1.3.15"
s.add_development_dependency "activerecord-jdbcmysql-adapter", "~> 1.3.15"
else
s.add_development_dependency 'sqlite3', '~> 1.2'
s.add_development_dependency 'pg', '~> 0.17'
s.add_development_dependency "sqlite3", "~> 1.2"
s.add_development_dependency "pg", "~> 0.17"
# activerecord >= 4.2.5 may use mysql2 >= 0.4
s.add_development_dependency 'mysql2', '~> 0.4.2'
s.add_development_dependency "mysql2", "~> 0.4.2"
end
end

View File

@ -1,10 +1,10 @@
require 'rails_helper'
require 'generator_spec/test_case'
require File.expand_path('../../../lib/generators/paper_trail/install_generator', __FILE__)
require "rails_helper"
require "generator_spec/test_case"
require File.expand_path("../../../lib/generators/paper_trail/install_generator", __FILE__)
describe PaperTrail::InstallGenerator, type: :generator do
include GeneratorSpec::TestCase
destination File.expand_path('../tmp', __FILE__)
destination File.expand_path("../tmp", __FILE__)
after(:all) { prepare_destination } # cleanup the tmp directory
@ -16,12 +16,12 @@ describe PaperTrail::InstallGenerator, type: :generator do
it "generates a migration for creating the 'versions' table" do
expect(destination_root).to have_structure {
directory 'db' do
directory 'migrate' do
migration 'create_versions' do
contains 'class CreateVersions'
contains 'def change'
contains 'create_table :versions'
directory "db" do
directory "migrate" do
migration "create_versions" do
contains "class CreateVersions"
contains "def change"
contains "create_table :versions"
end
end
end
@ -37,12 +37,12 @@ describe PaperTrail::InstallGenerator, type: :generator do
it "generates a migration for creating the 'versions' table" do
expect(destination_root).to have_structure {
directory 'db' do
directory 'migrate' do
migration 'create_versions' do
contains 'class CreateVersions'
contains 'def change'
contains 'create_table :versions'
directory "db" do
directory "migrate" do
migration "create_versions" do
contains "class CreateVersions"
contains "def change"
contains "create_table :versions"
end
end
end
@ -51,12 +51,12 @@ describe PaperTrail::InstallGenerator, type: :generator do
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
expect(destination_root).to have_structure {
directory 'db' do
directory 'migrate' do
migration 'add_object_changes_to_versions' do
contains 'class AddObjectChangesToVersions'
contains 'def change'
contains 'add_column :versions, :object_changes, :text'
directory "db" do
directory "migrate" do
migration "add_object_changes_to_versions" do
contains "class AddObjectChangesToVersions"
contains "def change"
contains "add_column :versions, :object_changes, :text"
end
end
end

View File

@ -1,32 +1,32 @@
require 'rails_helper'
require "rails_helper"
describe Animal, type: :model do
it { is_expected.to be_versioned }
describe "STI", versioning: true do
it { expect(Animal.inheritance_column).to eq('species') }
it { expect(Animal.inheritance_column).to eq("species") }
describe "updates to the `inheritance_column`" do
subject { Cat.create!(name: 'Leo') }
subject { Cat.create!(name: "Leo") }
it "should be allowed" do
subject.update_attributes(name: 'Spike', species: 'Dog')
subject.update_attributes(name: "Spike", species: "Dog")
dog = Animal.find(subject.id)
expect(dog).to be_instance_of(Dog)
end
end
context 'with callback-methods' do
context 'when only has_paper_trail set in super class' do
let(:callback_cat) { Cat.create(name: 'Markus') }
context "with callback-methods" do
context "when only has_paper_trail set in super class" do
let(:callback_cat) { Cat.create(name: "Markus") }
it 'trails all events' do
callback_cat.update_attributes(name: 'Billie')
it "trails all events" do
callback_cat.update_attributes(name: "Billie")
callback_cat.destroy
expect(callback_cat.versions.collect(&:event)).to eq %w(create update destroy)
end
it 'does not break reify' do
it "does not break reify" do
callback_cat.destroy
expect { callback_cat.versions.last.reify }.not_to raise_error
end

View File

@ -1,5 +1,5 @@
require 'rails_helper'
require Rails.root.join('..', 'custom_json_serializer')
require "rails_helper"
require Rails.root.join("..", "custom_json_serializer")
describe Boolit, type: :model do
it { is_expected.to be_versioned }

View File

@ -1,32 +1,32 @@
require 'rails_helper'
require "rails_helper"
describe CallbackModifier, type: :model do
with_versioning do
describe 'callback-methods', versioning: true do
describe 'paper_trail_on_destroy' do
it 'should add :destroy to paper_trail_options[:on]' do
describe "callback-methods", versioning: true do
describe "paper_trail_on_destroy" do
it "should add :destroy to paper_trail_options[:on]" do
modifier = NoArgDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
expect(modifier.paper_trail_options[:on]).to eq [:destroy]
end
context 'when :before' do
it 'should create the version before destroy' do
context "when :before" do
it "should create the version before destroy" do
modifier = BeforeDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.test_destroy
expect(modifier.versions.last.reify).not_to be_flagged_deleted
end
end
context 'when :after' do
it 'should create the version after destroy' do
context "when :after" do
it "should create the version after destroy" do
modifier = AfterDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.test_destroy
expect(modifier.versions.last.reify).to be_flagged_deleted
end
end
context 'when no argument' do
it 'should default to before destroy' do
context "when no argument" do
it "should default to before destroy" do
modifier = NoArgDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.test_destroy
expect(modifier.versions.last.reify).not_to be_flagged_deleted
@ -34,61 +34,61 @@ describe CallbackModifier, type: :model do
end
end
describe 'paper_trail_on_update' do
it 'should add :update to paper_trail_options[:on]' do
describe "paper_trail_on_update" do
it "should add :update to paper_trail_options[:on]" do
modifier = UpdateModifier.create!(some_content: FFaker::Lorem.sentence)
expect(modifier.paper_trail_options[:on]).to eq [:update]
end
it 'should create a version' do
it "should create a version" do
modifier = UpdateModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.update_attributes! some_content: 'modified'
expect(modifier.versions.last.event).to eq 'update'
modifier.update_attributes! some_content: "modified"
expect(modifier.versions.last.event).to eq "update"
end
end
describe 'paper_trail_on_create' do
it 'should add :create to paper_trail_options[:on]' do
describe "paper_trail_on_create" do
it "should add :create to paper_trail_options[:on]" do
modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence)
expect(modifier.paper_trail_options[:on]).to eq [:create]
end
it 'should create a version' do
it "should create a version" do
modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence)
expect(modifier.versions.last.event).to eq 'create'
expect(modifier.versions.last.event).to eq "create"
end
end
context 'when no callback-method used' do
it 'should set paper_trail_options[:on] to [:create, :update, :destroy]' do
context "when no callback-method used" do
it "should set paper_trail_options[:on] to [:create, :update, :destroy]" do
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
expect(modifier.paper_trail_options[:on]).to eq [:create, :update, :destroy]
end
it 'should default to track destroy' do
it "should default to track destroy" do
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.destroy
expect(modifier.versions.last.event).to eq 'destroy'
expect(modifier.versions.last.event).to eq "destroy"
end
it 'should default to track update' do
it "should default to track update" do
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.update_attributes! some_content: 'modified'
expect(modifier.versions.last.event).to eq 'update'
modifier.update_attributes! some_content: "modified"
expect(modifier.versions.last.event).to eq "update"
end
it 'should default to track create' do
it "should default to track create" do
modifier = DefaultModifier.create!(some_content: FFaker::Lorem.sentence)
expect(modifier.versions.last.event).to eq 'create'
expect(modifier.versions.last.event).to eq "create"
end
end
context 'when only one callback-method' do
it 'does only track the corresponding event' do
context "when only one callback-method" do
it "does only track the corresponding event" do
modifier = CreateModifier.create!(some_content: FFaker::Lorem.sentence)
modifier.update_attributes!(some_content: 'modified')
modifier.update_attributes!(some_content: "modified")
modifier.test_destroy
expect(modifier.versions.collect(&:event)).to eq ['create']
expect(modifier.versions.collect(&:event)).to eq ["create"]
end
end
end

View File

@ -1,7 +1,7 @@
require 'rails_helper'
require "rails_helper"
describe Fluxor, type: :model do
describe '`be_versioned` matcher' do
describe "`be_versioned` matcher" do
it { is_expected.to_not be_versioned }
end

View File

@ -1,17 +1,17 @@
require 'rails_helper'
require "rails_helper"
describe Gadget, type: :model do
it { is_expected.to be_versioned }
let(:gadget) { Gadget.create!(name: 'Wrench', brand: 'Acme') }
let(:gadget) { Gadget.create!(name: "Wrench", brand: "Acme") }
describe "updates", versioning: true do
it "should generate a version for updates to `name` attribute" do
expect { gadget.update_attribute(:name, 'Hammer').to change{gadget.versions.size}.by(1) }
expect { gadget.update_attribute(:name, "Hammer").to change{gadget.versions.size}.by(1) }
end
it "should ignore for updates to `brand` attribute" do
expect { gadget.update_attribute(:brand, 'Stanley') }.to_not change{gadget.versions.size}
expect { gadget.update_attribute(:brand, "Stanley") }.to_not change{gadget.versions.size}
end
it "should still generate a version when only the `updated_at` attribute is updated" do
@ -39,24 +39,24 @@ describe Gadget, type: :model do
context "without update timestamps" do
it "should only acknowledge non-ignored attrs" do
subject.name = 'Wrench'
subject.name = "Wrench"
expect(subject.send(:changed_notably?)).to be true
end
it "should not acknowledge ignored attr (brand)" do
subject.brand = 'Acme'
subject.brand = "Acme"
expect(subject.send(:changed_notably?)).to be false
end
end
context "with update timestamps" do
it "should only acknowledge non-ignored attrs" do
subject.name, subject.updated_at = 'Wrench', Time.now
subject.name, subject.updated_at = "Wrench", Time.now
expect(subject.send(:changed_notably?)).to be true
end
it "should not acknowledge ignored attrs and timestamps only" do
subject.brand, subject.updated_at = 'Acme', Time.now
subject.brand, subject.updated_at = "Acme", Time.now
expect(subject.send(:changed_notably?)).to be false
end
end

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe JoinedVersion, type: :model, versioning: true do
it { expect(JoinedVersion.superclass).to be PaperTrail::Version }

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
# The `json_versions` table tests postgres' `json` data type. So, that
# table is only created when testing against postgres and ActiveRecord >= 4.
@ -15,7 +15,7 @@ if JsonVersion.table_exists?
it { expect(JsonVersion).to respond_to(:where_object) }
it "escapes values" do
f = Fruit.create(name: 'Bobby')
f = Fruit.create(name: "Bobby")
expect(
f.
versions.
@ -34,7 +34,7 @@ if JsonVersion.table_exists?
context "valid arguments", versioning: true do
let(:fruit_names) { %w(apple orange lemon banana lime coconut strawberry blueberry) }
let(:fruit) { Fruit.new }
let(:name) { 'pomegranate' }
let(:name) { "pomegranate" }
let(:color) { FFaker::Color.name }
before do
@ -54,7 +54,7 @@ if JsonVersion.table_exists?
it { expect(JsonVersion).to respond_to(:where_object_changes) }
it "escapes values" do
f = Fruit.create(name: 'Bobby')
f = Fruit.create(name: "Bobby")
expect(
f.
versions.

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
module Kitchen
describe Banana, type: :model do

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe NotOnUpdate, type: :model do
describe "#touch_with_version", versioning: true do

View File

@ -1,11 +1,11 @@
require 'rails_helper'
require "rails_helper"
# This model is in the test suite soley for the purpose of testing ActiveRecord::Enum,
# which is available in ActiveRecord4+ only
describe PostWithStatus, type: :model do
if defined?(ActiveRecord::Enum)
with_versioning do
let(:post) { PostWithStatus.create!(status: 'draft') }
let(:post) { PostWithStatus.create!(status: "draft") }
it "should stash the enum value properly in versions" do
post.published!

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe Skipper, type: :model do
with_versioning do

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe Thing, type: :model do
it { is_expected.to be_versioned }

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe PaperTrail::Version, type: :model do
it "should include the `VersionConcern` module to get base functionality" do
@ -14,7 +14,7 @@ describe PaperTrail::Version, type: :model do
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
describe "object_changes column", versioning: true do
let(:widget) { Widget.create!(name: 'Dashboard') }
let(:widget) { Widget.create!(name: "Dashboard") }
let(:value) { widget.versions.last.object_changes }
context "serializer is YAML" do
@ -76,13 +76,13 @@ describe PaperTrail::Version, type: :model do
describe "#originator" do
it { is_expected.to respond_to(:originator) }
it 'should set the invoke `paper_trail_originator`' do
it "should set the invoke `paper_trail_originator`" do
allow(ActiveSupport::Deprecation).to receive(:warn)
is_expected.to receive(:paper_trail_originator)
subject.originator
end
it 'should display a deprecation warning' do
it "should display a deprecation warning" do
expect(ActiveSupport::Deprecation).to receive(:warn).
with(/Use paper_trail_originator instead of originator/)
subject.originator
@ -110,10 +110,10 @@ describe PaperTrail::Version, type: :model do
describe "Class" do
column_overrides = [false]
if ENV['DB'] == 'postgres' && ::ActiveRecord::VERSION::MAJOR >= 4
column_overrides << 'json'
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 4
column_overrides << "json"
# 'jsonb' column types are only supported for ActiveRecord 4.2+
column_overrides << 'jsonb' if ::ActiveRecord::VERSION::STRING >= '4.2'
column_overrides << "jsonb" if ::ActiveRecord::VERSION::STRING >= "4.2"
end
column_overrides.shuffle.each do |override|
@ -160,7 +160,7 @@ describe PaperTrail::Version, type: :model do
before do
widget.update_attributes!(name: name, an_integer: int)
widget.update_attributes!(name: 'foobar', an_integer: 100)
widget.update_attributes!(name: "foobar", an_integer: 100)
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
end
@ -223,7 +223,7 @@ describe PaperTrail::Version, type: :model do
before do
widget.update_attributes!(name: name, an_integer: 0)
widget.update_attributes!(name: 'foobar', an_integer: 77)
widget.update_attributes!(name: "foobar", an_integer: 77)
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: int)
end
@ -244,7 +244,7 @@ describe PaperTrail::Version, type: :model do
it "handles queries for multiple attributes" do
expect(
widget.versions.where_object_changes(an_integer: 77, name: 'foobar')
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
).to eq(widget.versions[1..2])
end
end
@ -267,7 +267,7 @@ describe PaperTrail::Version, type: :model do
it "handles queries for multiple attributes" do
expect(
widget.versions.where_object_changes(an_integer: 77, name: 'foobar')
widget.versions.where_object_changes(an_integer: 77, name: "foobar")
).to eq(widget.versions[1..2])
end

View File

@ -1,23 +1,23 @@
require 'rails_helper'
require "rails_helper"
describe Widget, type: :model do
describe '`be_versioned` matcher' do
describe "`be_versioned` matcher" do
it { is_expected.to be_versioned }
end
let(:widget) { Widget.create! name: 'Bob', an_integer: 1 }
let(:widget) { Widget.create! name: "Bob", an_integer: 1 }
describe '`have_a_version_with` matcher', versioning: true do
describe "`have_a_version_with` matcher", versioning: true do
before do
widget.update_attributes!(name: 'Leonard', an_integer: 1 )
widget.update_attributes!(name: 'Tom')
widget.update_attributes!(name: 'Bob')
widget.update_attributes!(name: "Leonard", an_integer: 1 )
widget.update_attributes!(name: "Tom")
widget.update_attributes!(name: "Bob")
end
it "is possible to do assertions on versions" do
expect(widget).to have_a_version_with name: 'Leonard', an_integer: 1
expect(widget).to have_a_version_with name: "Leonard", an_integer: 1
expect(widget).to have_a_version_with an_integer: 1
expect(widget).to have_a_version_with name: 'Tom'
expect(widget).to have_a_version_with name: "Tom"
end
end
@ -37,8 +37,8 @@ describe Widget, type: :model do
describe "Callbacks", versioning: true do
describe :before_save do
context ':on => :update' do
before { widget.update_attributes!(name: 'Foobar') }
context ":on => :update" do
before { widget.update_attributes!(name: "Foobar") }
subject { widget.versions.last.reify }
@ -52,7 +52,7 @@ describe Widget, type: :model do
end
describe :after_create do
let(:widget) { Widget.create!(name: 'Foobar', created_at: Time.now - 1.week) }
let(:widget) { Widget.create!(name: "Foobar", created_at: Time.now - 1.week) }
it "corresponding version should use the widget's `updated_at`" do
expect(widget.versions.last.created_at.to_i).to eq(widget.updated_at.to_i)
@ -60,7 +60,7 @@ describe Widget, type: :model do
end
describe :after_update do
before { widget.update_attributes!(name: 'Foobar', updated_at: Time.now + 1.week) }
before { widget.update_attributes!(name: "Foobar", updated_at: Time.now + 1.week) }
subject { widget.versions.last.reify }
@ -90,7 +90,7 @@ describe Widget, type: :model do
end
describe :after_rollback do
let(:rolled_back_name) { 'Big Moo' }
let(:rolled_back_name) { "Big Moo" }
before do
begin
@ -105,9 +105,9 @@ describe Widget, type: :model do
end
end
it 'does not create an event for changes that did not happen' do
it "does not create an event for changes that did not happen" do
widget.versions.map(&:changeset).each do |changeset|
expect(changeset.fetch('name', [])).to_not include(rolled_back_name)
expect(changeset.fetch("name", [])).to_not include(rolled_back_name)
end
end
end
@ -137,16 +137,16 @@ describe Widget, type: :model do
it "should return the originator for the model at a given state" do
expect(widget.paper_trail_originator).to eq(orig_name)
widget.whodunnit(new_name) { |w| w.update_attributes(name: 'Elizabeth') }
widget.whodunnit(new_name) { |w| w.update_attributes(name: "Elizabeth") }
expect(widget.paper_trail_originator).to eq(new_name)
end
end
context "accessed from a reified model instance" do
before do
widget.update_attributes(name: 'Andy')
widget.update_attributes(name: "Andy")
PaperTrail.whodunnit = new_name
widget.update_attributes(name: 'Elizabeth')
widget.update_attributes(name: "Elizabeth")
end
context "default behavior (no `options[:dup]` option passed in)" do
@ -181,13 +181,13 @@ describe Widget, type: :model do
it { is_expected.to respond_to(:originator) }
it 'should set the invoke `paper_trail_originator`' do
it "should set the invoke `paper_trail_originator`" do
allow(::ActiveSupport::Deprecation).to receive(:warn)
is_expected.to receive(:paper_trail_originator)
subject.originator
end
it 'should display a deprecation warning' do
it "should display a deprecation warning" do
expect(::ActiveSupport::Deprecation).to receive(:warn).
with(/Use paper_trail_originator instead of originator/)
subject.originator
@ -199,7 +199,7 @@ describe Widget, type: :model do
context "Timestamp argument is AFTER object has been destroyed" do
before do
widget.update_attribute(:name, 'foobar')
widget.update_attribute(:name, "foobar")
widget.destroy
end
@ -215,8 +215,8 @@ describe Widget, type: :model do
context "no block given" do
it "should raise an error" do
expect {
widget.whodunnit('Ben')
}.to raise_error(ArgumentError, 'expected to receive a block')
widget.whodunnit("Ben")
}.to raise_error(ArgumentError, "expected to receive a block")
end
end
@ -232,14 +232,14 @@ describe Widget, type: :model do
it "should modify value of `PaperTrail.whodunnit` while executing the block" do
widget.whodunnit(new_name) do
expect(PaperTrail.whodunnit).to eq(new_name)
widget.update_attributes(name: 'Elizabeth')
widget.update_attributes(name: "Elizabeth")
end
expect(widget.versions.last.whodunnit).to eq(new_name)
end
context "after executing the block" do
it "reverts value of whodunnit to previous value" do
widget.whodunnit(new_name) { |w| w.update_attributes(name: 'Elizabeth') }
widget.whodunnit(new_name) { |w| w.update_attributes(name: "Elizabeth") }
expect(PaperTrail.whodunnit).to eq(orig_name)
end
end
@ -290,7 +290,7 @@ describe Widget, type: :model do
describe '#paper_trail_off!' do
it { is_expected.to respond_to(:paper_trail_off!) }
it 'should set the `paper_trail_enabled_for_model?` to `false`' do
it "should set the `paper_trail_enabled_for_model?` to `false`" do
expect(subject.paper_trail_enabled_for_model?).to be true
subject.paper_trail_off!
expect(subject.paper_trail_enabled_for_model?).to be false
@ -302,7 +302,7 @@ describe Widget, type: :model do
it { is_expected.to respond_to(:paper_trail_on!) }
it 'should set the `paper_trail_enabled_for_model?` to `true`' do
it "should set the `paper_trail_enabled_for_model?` to `true`" do
expect(subject.paper_trail_enabled_for_model?).to be false
subject.paper_trail_on!
expect(subject.paper_trail_enabled_for_model?).to be true

View File

@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe PaperTrail, type: :module, versioning: true do
describe '#config' do

View File

@ -1,29 +1,29 @@
require 'rails_helper'
require "rails_helper"
describe PaperTrail::VersionConcern do
before(:all) { require 'support/alt_db_init' }
before(:all) { require "support/alt_db_init" }
it 'allows included class to have different connections' do
it "allows included class to have different connections" do
expect(Foo::Version.connection).not_to eq(Bar::Version.connection)
end
it 'allows custom version class to share connection with superclass' do
it "allows custom version class to share connection with superclass" do
expect(Foo::Version.connection).to eq(Foo::Document.connection)
expect(Bar::Version.connection).to eq(Bar::Document.connection)
end
it 'can be used with class_name option' do
expect(Foo::Document.version_class_name).to eq('Foo::Version')
expect(Bar::Document.version_class_name).to eq('Bar::Version')
it "can be used with class_name option" do
expect(Foo::Document.version_class_name).to eq("Foo::Version")
expect(Bar::Document.version_class_name).to eq("Bar::Version")
end
describe 'persistence', versioning: true do
describe "persistence", versioning: true do
before do
@foo_doc = Foo::Document.create!(name: 'foobar')
@bar_doc = Bar::Document.create!(name: 'raboof')
@foo_doc = Foo::Document.create!(name: "foobar")
@bar_doc = Bar::Document.create!(name: "raboof")
end
it 'should store versions in the correct corresponding db location' do
it "should store versions in the correct corresponding db location" do
expect(@foo_doc.versions.first).to be_instance_of(Foo::Version)
expect(@bar_doc.versions.first).to be_instance_of(Bar::Version)
end

View File

@ -1,4 +1,4 @@
require 'spec_helper'
require "spec_helper"
describe PaperTrail::VERSION do
describe "Constants" do
@ -28,7 +28,7 @@ describe PaperTrail::VERSION do
it "should join the numbers into a period separated string" do
expect(subject::STRING).to eq(
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join('.'))
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join("."))
end
end
end

View File

@ -1,12 +1,12 @@
require 'rails_helper'
require "rails_helper"
describe PaperTrail do
context 'default' do
it 'should have versioning off by default' do
context "default" do
it "should have versioning off by default" do
expect(PaperTrail).not_to be_enabled
end
it 'should turn versioning on in a `with_versioning` block' do
it "should turn versioning on in a `with_versioning` block" do
expect(PaperTrail).not_to be_enabled
with_versioning do
expect(PaperTrail).to be_enabled
@ -23,12 +23,12 @@ describe PaperTrail do
end
end
context '`versioning: true`', versioning: true do
it 'should have versioning on by default' do
context "`versioning: true`", versioning: true do
it "should have versioning on by default" do
expect(PaperTrail).to be_enabled
end
it 'should keep versioning on after a with_versioning block' do
it "should keep versioning on after a with_versioning block" do
expect(PaperTrail).to be_enabled
with_versioning do
expect(PaperTrail).to be_enabled
@ -37,21 +37,21 @@ describe PaperTrail do
end
end
context '`with_versioning` block at class level' do
context "`with_versioning` block at class level" do
it { expect(PaperTrail).not_to be_enabled }
with_versioning do
it 'should have versioning on by default' do
it "should have versioning on by default" do
expect(PaperTrail).to be_enabled
end
end
it 'should not leak the `enabled?` state into successive tests' do
it "should not leak the `enabled?` state into successive tests" do
expect(PaperTrail).not_to be_enabled
end
end
describe :whodunnit do
before(:all) { PaperTrail.whodunnit = 'foobar' }
before(:all) { PaperTrail.whodunnit = "foobar" }
it "should get set to `nil` by default" do
expect(PaperTrail.whodunnit).to be_nil
@ -59,7 +59,7 @@ describe PaperTrail do
end
describe :controller_info do
before(:all) { ::PaperTrail.controller_info = {foo: 'bar'} }
before(:all) { ::PaperTrail.controller_info = {foo: "bar"} }
it "should get set to an empty hash before each test" do
expect(PaperTrail.controller_info).to eq({})

View File

@ -1,18 +1,18 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
ENV["DB"] ||= 'sqlite'
ENV["RAILS_ENV"] ||= "test"
ENV["DB"] ||= "sqlite"
unless File.exist?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
unless File.exist?(File.expand_path("../../test/dummy/config/database.yml", __FILE__))
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
end
require 'spec_helper'
require File.expand_path('../../test/dummy/config/environment', __FILE__)
require 'rspec/rails'
require 'paper_trail/frameworks/rspec'
require 'shoulda/matchers'
require 'ffaker'
require 'timecop'
require "spec_helper"
require File.expand_path("../../test/dummy/config/environment", __FILE__)
require "rspec/rails"
require "paper_trail/frameworks/rspec"
require "shoulda/matchers"
require "ffaker"
require "timecop"
# prevent Test::Unit's AutoRunner from executing during RSpec's rake task
Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)

View File

@ -1,7 +1,7 @@
require 'rails_helper'
require "rails_helper"
describe "Articles management", type: :request, order: :defined do
let(:valid_params) { { article: { title: 'Doh', content: FFaker::Lorem.sentence } } }
let(:valid_params) { { article: { title: "Doh", content: FFaker::Lorem.sentence } } }
context "versioning disabled" do
specify { expect(PaperTrail).not_to be_enabled }
@ -26,8 +26,8 @@ describe "Articles management", type: :request, order: :defined do
expect {
post articles_path, params_wrapper(valid_params)
}.to change(PaperTrail::Version, :count).by(1)
expect(article.title).to eq('Doh')
expect(article.versions.last.whodunnit).to eq('foobar')
expect(article.title).to eq("Doh")
expect(article.versions.last.whodunnit).to eq("foobar")
end
end
end

View File

@ -1,4 +1,4 @@
require 'pry-nav'
require "pry-nav"
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@ -106,7 +106,7 @@ end
# ActionDispatch::Integration HTTP request method switch to keyword args
# (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
def params_wrapper(args)
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new('5.0.0.beta1')
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
{ params: args }
else
args

View File

@ -24,7 +24,7 @@ module Foo
end
class Document < Base
has_paper_trail class_name: 'Foo::Version'
has_paper_trail class_name: "Foo::Version"
end
end
@ -43,7 +43,7 @@ module Bar
end
class Document < Base
has_paper_trail class_name: 'Bar::Version'
has_paper_trail class_name: "Bar::Version"
end
end

View File

@ -1,7 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
require File.expand_path("../config/application", __FILE__)
require "rake"
Dummy::Application.load_tasks

View File

@ -5,7 +5,7 @@ class ArticlesController < ApplicationController
end
def current_user
'foobar'
"foobar"
end
private

View File

@ -1,6 +1,6 @@
class WidgetsController < ApplicationController
def paper_trail_enabled_for_controller
request.user_agent != 'Disable User-Agent'
request.user_agent != "Disable User-Agent"
end
def create

View File

@ -1,6 +1,6 @@
class Animal < ActiveRecord::Base
has_paper_trail
self.inheritance_column = 'species'
self.inheritance_column = "species"
attr_accessible :species, :name if ::PaperTrail.active_record_protected_attributes?
end

View File

@ -3,7 +3,7 @@ class Article < ActiveRecord::Base
ignore: [
:title, {
abstract: Proc.new { |obj|
['ignore abstract', 'Other abstract'].include? obj.abstract
["ignore abstract", "Other abstract"].include? obj.abstract
}
}
],

View File

@ -1,5 +1,5 @@
class Fruit < ActiveRecord::Base
if ENV['DB'] == 'postgres' || JsonVersion.table_exists?
has_paper_trail class_name: 'JsonVersion'
if ENV["DB"] == "postgres" || JsonVersion.table_exists?
has_paper_trail class_name: "JsonVersion"
end
end

View File

@ -1,4 +1,4 @@
class LegacyWidget < ActiveRecord::Base
has_paper_trail ignore: :version,
version: 'custom_version'
version: "custom_version"
end

View File

@ -1,4 +1,4 @@
class Translation < ActiveRecord::Base
has_paper_trail if: Proc.new { |t| t.language_code == 'US' },
unless: Proc.new { |t| t.type == 'DRAFT' }
has_paper_trail if: Proc.new { |t| t.language_code == "US" },
unless: Proc.new { |t| t.type == "DRAFT" }
end

View File

@ -3,7 +3,7 @@ class Widget < ActiveRecord::Base
has_one :wotsit
has_many :whatchamajiggers, as: :owner
EXCLUDED_NAME = 'Biglet'
EXCLUDED_NAME = "Biglet"
validates :name, exclusion: { in: [EXCLUDED_NAME] }

View File

@ -2,5 +2,5 @@
# VersionConcern::ClassMethods module. See
# https://github.com/airblade/paper_trail/issues/295 for more details.
class JoinedVersion < PaperTrail::Version
default_scope { joins('INNER JOIN widgets ON widgets.id = versions.item_id') }
default_scope { joins("INNER JOIN widgets ON widgets.id = versions.item_id") }
end

View File

@ -1,3 +1,3 @@
class JsonVersion < PaperTrail::Version
self.table_name = 'json_versions'
self.table_name = "json_versions"
end

View File

@ -1,5 +1,5 @@
module Kitchen
class BananaVersion < PaperTrail::Version
self.table_name = 'banana_versions'
self.table_name = "banana_versions"
end
end

View File

@ -1,3 +1,3 @@
class PostVersion < PaperTrail::Version
self.table_name = 'post_versions'
self.table_name = "post_versions"
end

View File

@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path("../config/environment", __FILE__)
run Dummy::Application

View File

@ -1,11 +1,11 @@
require File.expand_path('../boot', __FILE__)
require File.expand_path("../boot", __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
Bundler.require(:default, Rails.env) if defined?(Bundler)
require 'paper_trail'
require "paper_trail"
module Dummy
class Application < Rails::Application
@ -62,7 +62,7 @@ module Dummy
# config.assets.version = '1.0'
# Rails 4 key for generating secret key
config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'
config.secret_key_base = "A fox regularly kicked the screaming pile of biscuits."
# `raise_in_transactional_callbacks` was added in rails 4, then deprecated
# in rails 5. Oh, how fickle are the gods.

View File

@ -1,10 +1,10 @@
require 'rubygems'
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
require "rubygems"
gemfile = File.expand_path("../../../../Gemfile", __FILE__)
if File.exist?(gemfile)
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
ENV["BUNDLE_GEMFILE"] = gemfile
require "bundler"
Bundler.setup
end
$:.unshift File.expand_path('../../../../lib', __FILE__)
$:.unshift File.expand_path("../../../../lib", __FILE__)

View File

@ -1,5 +1,5 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
require File.expand_path("../application", __FILE__)
# Initialize the rails application
Dummy::Application.initialize!

View File

@ -20,7 +20,7 @@ Dummy::Application.configure do
if config.respond_to?(:public_file_server)
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=3600'
"Cache-Control" => "public, max-age=3600"
}
else
config.static_cache_control = "public, max-age=3600"

View File

@ -1,5 +1,5 @@
# Turn on associations tracking when the test suite is run on Travis CI
PaperTrail.config.track_associations = true if ENV['TRAVIS']
PaperTrail.config.track_associations = true if ENV["TRAVIS"]
module PaperTrail
class Version < ActiveRecord::Base

View File

@ -4,6 +4,6 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Dummy::Application.config.secret_token = '99c0312cf416079a8c7ccc63acb1e9f4f' +
'17741398ec8022a2f4fb509c57f55b72486573e9816a026f507efbcd452a9e954d45c93c' +
'95d5bacd87e664ad6805d3f'
Dummy::Application.config.secret_token = "99c0312cf416079a8c7ccc63acb1e9f4f" +
"17741398ec8022a2f4fb509c57f55b72486573e9816a026f507efbcd452a9e954d45c93c" +
"95d5bacd87e664ad6805d3f"

View File

@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
Dummy::Application.config.session_store :cookie_store, key: "_dummy_session"
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information

View File

@ -52,7 +52,7 @@ class SetUpTestTables < ActiveRecord::Migration
add_index :version_associations, [:version_id]
add_index :version_associations,
[:foreign_key_name, :foreign_key_id],
name: 'index_version_associations_on_foreign_key'
name: "index_version_associations_on_foreign_key"
create_table :post_versions, force: true do |t|
t.string :item_type, null: false
@ -68,7 +68,7 @@ class SetUpTestTables < ActiveRecord::Migration
end
add_index :post_versions, [:item_type, :item_id]
if ENV['DB'] == 'postgres' && ::ActiveRecord::VERSION::MAJOR >= 4
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 4
create_table :json_versions, force: true do |t|
t.string :item_type, null: false
t.integer :item_id, null: false
@ -282,7 +282,7 @@ class SetUpTestTables < ActiveRecord::Migration
drop_table :sections
drop_table :paragraphs
remove_index :version_associations, column: [:version_id]
remove_index :version_associations, name: 'index_version_associations_on_foreign_key'
remove_index :version_associations, name: "index_version_associations_on_foreign_key"
drop_table :version_associations
drop_table :callback_modifiers
end

View File

@ -3,6 +3,6 @@
# This command will automatically be run when you run "rails" with Rails 3 gems
# installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
APP_PATH = File.expand_path("../../config/application", __FILE__)
require File.expand_path("../../config/boot", __FILE__)
require "rails/commands"

View File

@ -1,10 +1,10 @@
require 'test_helper'
require "test_helper"
class ControllerTest < ActionController::TestCase
tests WidgetsController
setup do
@request.env['REMOTE_ADDR'] = '127.0.0.1'
@request.env["REMOTE_ADDR"] = "127.0.0.1"
end
# Mimick what RequestStore will do outside of the test env, since it is
@ -13,65 +13,65 @@ class ControllerTest < ActionController::TestCase
RequestStore.store[:paper_trail] = nil
end
test 'disable on create' do
@request.env['HTTP_USER_AGENT'] = 'Disable User-Agent'
post :create, params_wrapper(widget: { name: 'Flugel' })
test "disable on create" do
@request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
post :create, params_wrapper(widget: { name: "Flugel" })
assert_equal 0, assigns(:widget).versions.length
end
test 'disable on update' do
@request.env['HTTP_USER_AGENT'] = 'Disable User-Agent'
post :create, params_wrapper(widget: { name: 'Flugel' })
test "disable on update" do
@request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
post :create, params_wrapper(widget: { name: "Flugel" })
w = assigns(:widget)
assert_equal 0, w.versions.length
put :update, params_wrapper(id: w.id, widget: { name: 'Bugle' })
put :update, params_wrapper(id: w.id, widget: { name: "Bugle" })
widget = assigns(:widget)
assert_equal 0, widget.versions.length
end
test 'disable on destroy' do
@request.env['HTTP_USER_AGENT'] = 'Disable User-Agent'
post :create, params_wrapper(widget: { name: 'Flugel' })
test "disable on destroy" do
@request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
post :create, params_wrapper(widget: { name: "Flugel" })
w = assigns(:widget)
assert_equal 0, w.versions.length
delete :destroy, params_wrapper(id: w.id)
assert_equal 0, PaperTrail::Version.with_item_keys('Widget', w.id).size
assert_equal 0, PaperTrail::Version.with_item_keys("Widget", w.id).size
end
test 'create' do
post :create, params_wrapper(widget: { name: 'Flugel' })
test "create" do
post :create, params_wrapper(widget: { name: "Flugel" })
widget = assigns(:widget)
assert_equal 1, widget.versions.length
assert_equal 153, widget.versions.last.whodunnit.to_i
assert_equal '127.0.0.1', widget.versions.last.ip
assert_equal 'Rails Testing', widget.versions.last.user_agent
assert_equal "127.0.0.1", widget.versions.last.ip
assert_equal "Rails Testing", widget.versions.last.user_agent
end
test 'update' do
w = Widget.create name: 'Duvel'
test "update" do
w = Widget.create name: "Duvel"
assert_equal 1, w.versions.length
put :update, params_wrapper(id: w.id, widget: { name: 'Bugle' })
put :update, params_wrapper(id: w.id, widget: { name: "Bugle" })
widget = assigns(:widget)
assert_equal 2, widget.versions.length
assert_equal 153, widget.versions.last.whodunnit.to_i
assert_equal '127.0.0.1', widget.versions.last.ip
assert_equal 'Rails Testing', widget.versions.last.user_agent
assert_equal "127.0.0.1", widget.versions.last.ip
assert_equal "Rails Testing", widget.versions.last.user_agent
end
test 'destroy' do
w = Widget.create name: 'Roundel'
test "destroy" do
w = Widget.create name: "Roundel"
assert_equal 1, w.versions.length
delete :destroy, params_wrapper(id: w.id)
widget = assigns(:widget)
assert_equal 2, widget.versions.length
assert_equal '127.0.0.1', widget.versions.last.ip
assert_equal 'Rails Testing', widget.versions.last.user_agent
assert_equal "127.0.0.1", widget.versions.last.ip
assert_equal "Rails Testing", widget.versions.last.user_agent
assert_equal 153, widget.versions.last.whodunnit.to_i
end
test "controller metadata methods should get evaluated if PT enabled for controller" do
@request.env['HTTP_USER_AGENT'] = 'User-Agent'
post :create, params_wrapper(widget: { name: 'Flugel' })
@request.env["HTTP_USER_AGENT"] = "User-Agent"
post :create, params_wrapper(widget: { name: "Flugel" })
assert PaperTrail.enabled_for_controller?
assert_equal 153, PaperTrail.whodunnit
assert PaperTrail.controller_info.present?
@ -80,8 +80,8 @@ class ControllerTest < ActionController::TestCase
end
test "controller metadata methods should not get evaluated if PT disabled for controller" do
@request.env['HTTP_USER_AGENT'] = 'Disable User-Agent'
post :create, params_wrapper(widget: { name: 'Flugel' })
@request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
post :create, params_wrapper(widget: { name: "Flugel" })
assert_equal 0, assigns(:widget).versions.length
assert !PaperTrail.enabled_for_controller?
assert PaperTrail.whodunnit.nil?

View File

@ -1,12 +1,12 @@
require 'test_helper'
require "test_helper"
class EnabledForControllerTest < ActionController::TestCase
tests ArticlesController
context "`PaperTrail.enabled? == true`" do
should 'enabled_for_controller?.should == true' do
should "enabled_for_controller?.should == true" do
assert PaperTrail.enabled?
post :create, params_wrapper(article: { title: 'Doh', content: FFaker::Lorem.sentence })
post :create, params_wrapper(article: { title: "Doh", content: FFaker::Lorem.sentence })
assert_not_nil assigns(:article)
assert PaperTrail.enabled_for_controller?
assert_equal 1, assigns(:article).versions.length
@ -16,9 +16,9 @@ class EnabledForControllerTest < ActionController::TestCase
context "`PaperTrail.enabled? == false`" do
setup { PaperTrail.enabled = false }
should 'enabled_for_controller?.should == false' do
should "enabled_for_controller?.should == false" do
assert !PaperTrail.enabled?
post :create, params_wrapper(article: { title: 'Doh', content: FFaker::Lorem.sentence })
post :create, params_wrapper(article: { title: "Doh", content: FFaker::Lorem.sentence })
assert !PaperTrail.enabled_for_controller?
assert_equal 0, assigns(:article).versions.length
end

View File

@ -7,23 +7,23 @@
# - test/functional/modular_sinatra_test.rb
#
if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
require 'test_helper'
require 'sinatra/base'
require "test_helper"
require "sinatra/base"
# --- Tests for modular `Sinatra::Base` style ----
class BaseApp < Sinatra::Base
configs = YAML.load_file(File.expand_path('../../dummy/config/database.yml', __FILE__))
configs = YAML.load_file(File.expand_path("../../dummy/config/database.yml", __FILE__))
ActiveRecord::Base.configurations = configs
ActiveRecord::Base.establish_connection(:test)
register PaperTrail::Sinatra
get '/test' do
Widget.create!(name: 'foo')
'Hello'
get "/test" do
Widget.create!(name: "foo")
"Hello"
end
def current_user
@current_user ||= OpenStruct.new(id: 'foobar')
@current_user ||= OpenStruct.new(id: "foobar")
end
end
@ -34,19 +34,19 @@ if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
@app ||= BaseApp
end
test 'baseline' do
test "baseline" do
assert_nil Widget.create.versions.first.whodunnit
end
context "`PaperTrail::Sinatra` in a `Sinatra::Base` application" do
should "sets the `user_for_paper_trail` from the `current_user` method" do
get '/test'
assert_equal 'Hello', last_response.body
get "/test"
assert_equal "Hello", last_response.body
widget = Widget.last
assert_not_nil widget
assert_equal 'foo', widget.name
assert_equal "foo", widget.name
assert_equal 1, widget.versions.size
assert_equal 'foobar', widget.versions.first.whodunnit
assert_equal "foobar", widget.versions.first.whodunnit
end
end
end

View File

@ -7,13 +7,13 @@
# - test/functional/modular_sinatra_test.rb
#
if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
require 'test_helper'
require "test_helper"
# require 'sinatra/main'
# --- Tests for non-modular `Sinatra::Application` style ----
module Sinatra
class Application
configs = YAML.load_file(File.expand_path('../../dummy/config/database.yml', __FILE__))
configs = YAML.load_file(File.expand_path("../../dummy/config/database.yml", __FILE__))
ActiveRecord::Base.configurations = configs
ActiveRecord::Base.establish_connection(:test)
@ -21,13 +21,13 @@ if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
# seem to fail without it ATM
register PaperTrail::Sinatra
get '/test' do
Widget.create!(name: 'bar')
'Hai'
get "/test" do
Widget.create!(name: "bar")
"Hai"
end
def current_user
@current_user ||= OpenStruct.new(id: 'raboof')
@current_user ||= OpenStruct.new(id: "raboof")
end
end
end
@ -39,19 +39,19 @@ if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
@app ||= Sinatra::Application
end
test 'baseline' do
test "baseline" do
assert_nil Widget.create.versions.first.whodunnit
end
context "`PaperTrail::Sinatra` in a `Sinatra::Application` application" do
should "sets the `user_for_paper_trail` from the `current_user` method" do
get '/test'
assert_equal 'Hai', last_response.body
get "/test"
assert_equal "Hai", last_response.body
widget = Widget.last
assert_not_nil widget
assert_equal 'bar', widget.name
assert_equal "bar", widget.name
assert_equal 1, widget.versions.size
assert_equal 'raboof', widget.versions.first.whodunnit
assert_equal "raboof", widget.versions.first.whodunnit
end
end
end

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class ThreadSafetyTest < ActionController::TestCase
test "thread-safe when using #set_paper_trail_whodunnit" do

View File

@ -1,11 +1,11 @@
require 'test_helper'
require "test_helper"
class PaperTrailTest < ActiveSupport::TestCase
test 'Sanity test' do
test "Sanity test" do
assert_kind_of Module, PaperTrail::Version
end
test 'Version Number' do
test "Version Number" do
assert PaperTrail.const_defined?(:VERSION)
end
@ -17,23 +17,23 @@ class PaperTrailTest < ActiveSupport::TestCase
teardown { PaperTrail.enabled = true }
end
test 'create with plain model class' do
test "create with plain model class" do
widget = Widget.create
assert_equal 1, widget.versions.length
end
test 'update with plain model class' do
test "update with plain model class" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.update_attributes(name: 'Bugle')
widget.update_attributes(name: "Bugle")
assert_equal 2, widget.versions.length
end
test 'destroy with plain model class' do
test "destroy with plain model class" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.destroy
versions_for_widget = PaperTrail::Version.with_item_keys('Widget', widget.id)
versions_for_widget = PaperTrail::Version.with_item_keys("Widget", widget.id)
assert_equal 2, versions_for_widget.length
end
end

View File

@ -1,9 +1,9 @@
require 'pry-nav'
require "pry-nav"
ENV["RAILS_ENV"] = "test"
ENV["DB"] ||= "sqlite"
unless File.exist?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
unless File.exist?(File.expand_path("../../test/dummy/config/database.yml", __FILE__))
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
end
@ -13,15 +13,15 @@ end
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
require 'shoulda'
require 'ffaker'
require 'database_cleaner'
require "shoulda"
require "ffaker"
require "database_cleaner"
def active_record_gem_version
Gem::Version.new(ActiveRecord::VERSION::STRING)
end
if active_record_gem_version >= Gem::Version.new('5.0.0.beta1')
if active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
# See https://github.com/rails/rails-controller-testing/issues/5
ActionController::TestCase.send(:include, Rails::Controller::Testing::TestProcess)
end
@ -104,7 +104,7 @@ end
# ActionDispatch::Integration HTTP request method switch to keyword args
# (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
def params_wrapper(args)
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new('5.0.0.beta1')
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
{ params: args }
else
args

View File

@ -1 +1 @@
require 'timecop'
require "timecop"

View File

@ -1,14 +1,14 @@
require 'test_helper'
require "test_helper"
class ARIdMapTest < ActiveSupport::TestCase
setup do
@widget = Widget.new
@widget.update_attributes name: 'Henry', created_at: Time.now - 1.day
@widget.update_attributes name: 'Harry'
@widget.update_attributes name: "Henry", created_at: Time.now - 1.day
@widget.update_attributes name: "Harry"
end
if defined?(ActiveRecord::IdentityMap) && ActiveRecord::IdentityMap.respond_to?(:without)
should 'not clobber the IdentityMap when reifying' do
should "not clobber the IdentityMap when reifying" do
module ActiveRecord::IdentityMap
class << self
alias __without without

View File

@ -1,5 +1,5 @@
require 'test_helper'
require 'time_travel_helper'
require "test_helper"
require "time_travel_helper"
class AssociationsTest < ActiveSupport::TestCase
CHAPTER_NAMES = [
@ -34,103 +34,103 @@ class AssociationsTest < ActiveSupport::TestCase
end
context "a has_one association" do
setup { @widget = Widget.create name: 'widget_0' }
setup { @widget = Widget.create name: "widget_0" }
context 'before the associated was created' do
context "before the associated was created" do
setup do
@widget.update_attributes name: 'widget_1'
@wotsit = @widget.create_wotsit name: 'wotsit_0'
@widget.update_attributes name: "widget_1"
@wotsit = @widget.create_wotsit name: "wotsit_0"
end
context 'when reified' do
context "when reified" do
setup { @widget_0 = @widget.versions.last.reify(has_one: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_nil @widget_0.wotsit
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal @wotsit, @widget.reload.wotsit
end
end
end
context 'where the association is created between model versions' do
context "where the association is created between model versions" do
setup do
@wotsit = @widget.create_wotsit name: 'wotsit_0'
@wotsit = @widget.create_wotsit name: "wotsit_0"
Timecop.travel 1.second.since
@widget.update_attributes name: 'widget_1'
@widget.update_attributes name: "widget_1"
end
context 'when reified' do
context "when reified" do
setup { @widget_0 = @widget.versions.last.reify(has_one: true) }
should 'see the associated as it was at the time' do
assert_equal 'wotsit_0', @widget_0.wotsit.name
should "see the associated as it was at the time" do
assert_equal "wotsit_0", @widget_0.wotsit.name
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal @wotsit, @widget.reload.wotsit
end
end
context 'and then the associated is updated between model versions' do
context "and then the associated is updated between model versions" do
setup do
@wotsit.update_attributes name: 'wotsit_1'
@wotsit.update_attributes name: 'wotsit_2'
@wotsit.update_attributes name: "wotsit_1"
@wotsit.update_attributes name: "wotsit_2"
Timecop.travel 1.second.since
@widget.update_attributes name: 'widget_2'
@wotsit.update_attributes name: 'wotsit_3'
@widget.update_attributes name: "widget_2"
@wotsit.update_attributes name: "wotsit_3"
end
context 'when reified' do
context "when reified" do
setup { @widget_1 = @widget.versions.last.reify(has_one: true) }
should 'see the associated as it was at the time' do
assert_equal 'wotsit_2', @widget_1.wotsit.name
should "see the associated as it was at the time" do
assert_equal "wotsit_2", @widget_1.wotsit.name
end
should 'not persist changes to the live association' do
assert_equal 'wotsit_3', @widget.reload.wotsit.name
should "not persist changes to the live association" do
assert_equal "wotsit_3", @widget.reload.wotsit.name
end
end
context 'when reified opting out of has_one reification' do
context "when reified opting out of has_one reification" do
setup { @widget_1 = @widget.versions.last.reify(has_one: false) }
should 'see the associated as it is live' do
assert_equal 'wotsit_3', @widget_1.wotsit.name
should "see the associated as it is live" do
assert_equal "wotsit_3", @widget_1.wotsit.name
end
end
end
context 'and then the associated is destroyed' do
context "and then the associated is destroyed" do
setup do
@wotsit.destroy
end
context 'when reify' do
context "when reify" do
setup { @widget_1 = @widget.versions.last.reify(has_one: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal @wotsit, @widget_1.wotsit
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_nil @widget.reload.wotsit
end
end
context 'and then the model is updated' do
context "and then the model is updated" do
setup do
Timecop.travel 1.second.since
@widget.update_attributes name: 'widget_3'
@widget.update_attributes name: "widget_3"
end
context 'when reified' do
context "when reified" do
setup { @widget_2 = @widget.versions.last.reify(has_one: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_nil @widget_2.wotsit
end
end
@ -140,28 +140,28 @@ class AssociationsTest < ActiveSupport::TestCase
end
context "a has_many association" do
setup { @customer = Customer.create name: 'customer_0' }
setup { @customer = Customer.create name: "customer_0" }
context 'updated before the associated was created' do
context "updated before the associated was created" do
setup do
@customer.update_attributes! name: 'customer_1'
@customer.update_attributes! name: "customer_1"
@customer.orders.create! order_date: Date.today
end
context 'when reified' do
context "when reified" do
setup { @customer_0 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [], @customer_0.orders
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_not_equal [], @customer.orders.reload
end
end
context 'when reified with option mark_for_destruction' do
should 'mark the associated for destruction' do
context "when reified with option mark_for_destruction" do
should "mark the associated for destruction" do
@customer_0 = @customer.versions.last.reify(
has_many: true,
mark_for_destruction: true
@ -171,144 +171,144 @@ class AssociationsTest < ActiveSupport::TestCase
end
end
context 'where the association is created between model versions' do
context "where the association is created between model versions" do
setup do
@order = @customer.orders.create! order_date: 'order_date_0'
@order = @customer.orders.create! order_date: "order_date_0"
Timecop.travel 1.second.since
@customer.update_attributes name: 'customer_1'
@customer.update_attributes name: "customer_1"
end
context 'when reified' do
context "when reified" do
setup { @customer_0 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
assert_equal ['order_date_0'], @customer_0.orders.map(&:order_date)
should "see the associated as it was at the time" do
assert_equal ["order_date_0"], @customer_0.orders.map(&:order_date)
end
end
context 'and then a nested has_many association is created' do
context "and then a nested has_many association is created" do
setup do
@order.line_items.create! product: 'product_0'
@order.line_items.create! product: "product_0"
end
context 'when reified' do
context "when reified" do
setup { @customer_0 = @customer.versions.last.reify(has_many: true) }
should 'see the live version of the nested association' do
assert_equal ['product_0'], @customer_0.orders.first.line_items.map(&:product)
should "see the live version of the nested association" do
assert_equal ["product_0"], @customer_0.orders.first.line_items.map(&:product)
end
end
end
context 'and then the associated is updated between model versions' do
context "and then the associated is updated between model versions" do
setup do
@order.update_attributes order_date: 'order_date_1'
@order.update_attributes order_date: 'order_date_2'
@order.update_attributes order_date: "order_date_1"
@order.update_attributes order_date: "order_date_2"
Timecop.travel 1.second.since
@customer.update_attributes name: 'customer_2'
@order.update_attributes order_date: 'order_date_3'
@customer.update_attributes name: "customer_2"
@order.update_attributes order_date: "order_date_3"
end
context 'when reified' do
context "when reified" do
setup { @customer_1 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
assert_equal ['order_date_2'], @customer_1.orders.map(&:order_date)
should "see the associated as it was at the time" do
assert_equal ["order_date_2"], @customer_1.orders.map(&:order_date)
end
should 'not persist changes to the live association' do
assert_equal ['order_date_3'], @customer.orders.reload.map(&:order_date)
should "not persist changes to the live association" do
assert_equal ["order_date_3"], @customer.orders.reload.map(&:order_date)
end
end
context 'when reified opting out of has_many reification' do
context "when reified opting out of has_many reification" do
setup { @customer_1 = @customer.versions.last.reify(has_many: false) }
should 'see the associated as it is live' do
assert_equal ['order_date_3'], @customer_1.orders.map(&:order_date)
should "see the associated as it is live" do
assert_equal ["order_date_3"], @customer_1.orders.map(&:order_date)
end
end
context 'and then the associated is destroyed' do
context "and then the associated is destroyed" do
setup do
@order.destroy
end
context 'when reified' do
context "when reified" do
setup { @customer_1 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
assert_equal ['order_date_2'], @customer_1.orders.map(&:order_date)
should "see the associated as it was at the time" do
assert_equal ["order_date_2"], @customer_1.orders.map(&:order_date)
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal [], @customer.orders.reload
end
end
end
end
context 'and then the associated is destroyed' do
context "and then the associated is destroyed" do
setup do
@order.destroy
end
context 'when reified' do
context "when reified" do
setup { @customer_1 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [@order.order_date], @customer_1.orders.map(&:order_date)
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal [], @customer.orders.reload
end
end
end
context 'and then the associated is destroyed between model versions' do
context "and then the associated is destroyed between model versions" do
setup do
@order.destroy
Timecop.travel 1.second.since
@customer.update_attributes name: 'customer_2'
@customer.update_attributes name: "customer_2"
end
context 'when reified' do
context "when reified" do
setup { @customer_1 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [], @customer_1.orders
end
end
end
context 'and then another association is added' do
context "and then another association is added" do
setup do
@customer.orders.create! order_date: 'order_date_1'
@customer.orders.create! order_date: "order_date_1"
end
context 'when reified' do
context "when reified" do
setup { @customer_0 = @customer.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
assert_equal ['order_date_0'], @customer_0.orders.map(&:order_date)
should "see the associated as it was at the time" do
assert_equal ["order_date_0"], @customer_0.orders.map(&:order_date)
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal %w(order_date_0 order_date_1),
@customer.orders.reload.map(&:order_date).sort
end
end
context 'when reified with option mark_for_destruction' do
should 'mark the newly associated for destruction' do
context "when reified with option mark_for_destruction" do
should "mark the newly associated for destruction" do
@customer_0 = @customer.versions.last.reify(
has_many: true,
mark_for_destruction: true
)
assert @customer_0.
orders.
detect { |o| o.order_date == 'order_date_1'}.
detect { |o| o.order_date == "order_date_1"}.
marked_for_destruction?
end
end
@ -318,27 +318,27 @@ class AssociationsTest < ActiveSupport::TestCase
context "has_many through associations" do
context "Books, Authors, and Authorships" do
setup { @book = Book.create title: 'book_0' }
setup { @book = Book.create title: "book_0" }
context 'updated before the associated was created' do
context "updated before the associated was created" do
setup do
@book.update_attributes! title: 'book_1'
@book.authors.create! name: 'author_0'
@book.update_attributes! title: "book_1"
@book.authors.create! name: "author_0"
end
context 'when reified' do
context "when reified" do
setup { @book_0 = @book.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [], @book_0.authors
end
should 'not persist changes to the live association' do
assert_equal ['author_0'], @book.authors.reload.map(&:name)
should "not persist changes to the live association" do
assert_equal ["author_0"], @book.authors.reload.map(&:name)
end
end
context 'when reified with option mark_for_destruction' do
context "when reified with option mark_for_destruction" do
setup do
@book_0 = @book.versions.last.reify(
has_many: true,
@ -346,35 +346,35 @@ class AssociationsTest < ActiveSupport::TestCase
)
end
should 'mark the associated for destruction' do
should "mark the associated for destruction" do
assert_equal [true], @book_0.authors.map(&:marked_for_destruction?)
end
should 'mark the associated-through for destruction' do
should "mark the associated-through for destruction" do
assert_equal [true], @book_0.authorships.map(&:marked_for_destruction?)
end
end
end
context 'updated before it is associated with an existing one' do
context "updated before it is associated with an existing one" do
setup do
person_existing = Person.create(name: 'person_existing')
person_existing = Person.create(name: "person_existing")
Timecop.travel 1.second.since
@book.update_attributes! title: 'book_1'
@book.update_attributes! title: "book_1"
@book.authors << person_existing
end
context 'when reified' do
context "when reified" do
setup do
@book_0 = @book.versions.last.reify(has_many: true)
end
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [], @book_0.authors
end
end
context 'when reified with option mark_for_destruction' do
context "when reified with option mark_for_destruction" do
setup do
@book_0 = @book.versions.last.reify(
has_many: true,
@ -382,130 +382,130 @@ class AssociationsTest < ActiveSupport::TestCase
)
end
should 'not mark the associated for destruction' do
should "not mark the associated for destruction" do
assert_equal [false], @book_0.authors.map(&:marked_for_destruction?)
end
should 'mark the associated-through for destruction' do
should "mark the associated-through for destruction" do
assert_equal [true], @book_0.authorships.map(&:marked_for_destruction?)
end
end
end
context 'where the association is created between model versions' do
context "where the association is created between model versions" do
setup do
@author = @book.authors.create! name: 'author_0'
@person_existing = Person.create(name: 'person_existing')
@author = @book.authors.create! name: "author_0"
@person_existing = Person.create(name: "person_existing")
Timecop.travel 1.second.since
@book.update_attributes! title: 'book_1'
@book.update_attributes! title: "book_1"
end
context 'when reified' do
context "when reified" do
setup { @book_0 = @book.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
assert_equal ['author_0'], @book_0.authors.map(&:name)
should "see the associated as it was at the time" do
assert_equal ["author_0"], @book_0.authors.map(&:name)
end
end
context 'and then the associated is updated between model versions' do
context "and then the associated is updated between model versions" do
setup do
@author.update_attributes name: 'author_1'
@author.update_attributes name: 'author_2'
@author.update_attributes name: "author_1"
@author.update_attributes name: "author_2"
Timecop.travel 1.second.since
@book.update_attributes title: 'book_2'
@author.update_attributes name: 'author_3'
@book.update_attributes title: "book_2"
@author.update_attributes name: "author_3"
end
context 'when reified' do
context "when reified" do
setup { @book_1 = @book.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
assert_equal ['author_2'], @book_1.authors.map(&:name)
should "see the associated as it was at the time" do
assert_equal ["author_2"], @book_1.authors.map(&:name)
end
should 'not persist changes to the live association' do
assert_equal ['author_3'], @book.authors.reload.map(&:name)
should "not persist changes to the live association" do
assert_equal ["author_3"], @book.authors.reload.map(&:name)
end
end
context 'when reified opting out of has_many reification' do
context "when reified opting out of has_many reification" do
setup { @book_1 = @book.versions.last.reify(has_many: false) }
should 'see the associated as it is live' do
assert_equal ['author_3'], @book_1.authors.map(&:name)
should "see the associated as it is live" do
assert_equal ["author_3"], @book_1.authors.map(&:name)
end
end
end
context 'and then the associated is destroyed' do
context "and then the associated is destroyed" do
setup do
@author.destroy
end
context 'when reified' do
context "when reified" do
setup { @book_1 = @book.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [@author.name], @book_1.authors.map(&:name)
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal [], @book.authors.reload
end
end
end
context 'and then the associated is destroyed between model versions' do
context "and then the associated is destroyed between model versions" do
setup do
@author.destroy
Timecop.travel 1.second.since
@book.update_attributes title: 'book_2'
@book.update_attributes title: "book_2"
end
context 'when reified' do
context "when reified" do
setup { @book_1 = @book.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [], @book_1.authors
end
end
end
context 'and then the associated is dissociated between model versions' do
context "and then the associated is dissociated between model versions" do
setup do
@book.authors = []
Timecop.travel 1.second.since
@book.update_attributes title: 'book_2'
@book.update_attributes title: "book_2"
end
context 'when reified' do
context "when reified" do
setup { @book_1 = @book.versions.last.reify(has_many: true) }
should 'see the associated as it was at the time' do
should "see the associated as it was at the time" do
assert_equal [], @book_1.authors
end
end
end
context 'and then another associated is created' do
context "and then another associated is created" do
setup do
@book.authors.create! name: 'author_1'
@book.authors.create! name: "author_1"
end
context 'when reified' do
context "when reified" do
setup { @book_0 = @book.versions.last.reify(has_many: true) }
should 'only see the first associated' do
assert_equal ['author_0'], @book_0.authors.map(&:name)
should "only see the first associated" do
assert_equal ["author_0"], @book_0.authors.map(&:name)
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal %w(author_0 author_1), @book.authors.reload.map(&:name)
end
end
context 'when reified with option mark_for_destruction' do
context "when reified with option mark_for_destruction" do
setup do
@book_0 = @book.versions.last.reify(
has_many: true,
@ -513,40 +513,40 @@ class AssociationsTest < ActiveSupport::TestCase
)
end
should 'mark the newly associated for destruction' do
should "mark the newly associated for destruction" do
assert @book_0.
authors.
detect { |a| a.name == 'author_1' }.
detect { |a| a.name == "author_1" }.
marked_for_destruction?
end
should 'mark the newly associated-through for destruction' do
should "mark the newly associated-through for destruction" do
assert @book_0.
authorships.
detect { |as| as.person.name == 'author_1' }.
detect { |as| as.person.name == "author_1" }.
marked_for_destruction?
end
end
end
context 'and then an existing one is associated' do
context "and then an existing one is associated" do
setup do
@book.authors << @person_existing
end
context 'when reified' do
context "when reified" do
setup { @book_0 = @book.versions.last.reify(has_many: true) }
should 'only see the first associated' do
assert_equal ['author_0'], @book_0.authors.map(&:name)
should "only see the first associated" do
assert_equal ["author_0"], @book_0.authors.map(&:name)
end
should 'not persist changes to the live association' do
should "not persist changes to the live association" do
assert_equal %w(author_0 person_existing), @book.authors.reload.map(&:name).sort
end
end
context 'when reified with option mark_for_destruction' do
context "when reified with option mark_for_destruction" do
setup do
@book_0 = @book.versions.last.reify(
has_many: true,
@ -554,34 +554,34 @@ class AssociationsTest < ActiveSupport::TestCase
)
end
should 'not mark the newly associated for destruction' do
should "not mark the newly associated for destruction" do
assert !@book_0.
authors.
detect { |a| a.name == 'person_existing' }.
detect { |a| a.name == "person_existing" }.
marked_for_destruction?
end
should 'mark the newly associated-through for destruction' do
should "mark the newly associated-through for destruction" do
assert @book_0.
authorships.
detect { |as| as.person.name == 'person_existing' }.
detect { |as| as.person.name == "person_existing" }.
marked_for_destruction?
end
end
end
end
context 'updated before the associated without paper_trail was created' do
context "updated before the associated without paper_trail was created" do
setup do
@book.update_attributes! title: 'book_1'
@book.editors.create! name: 'editor_0'
@book.update_attributes! title: "book_1"
@book.editors.create! name: "editor_0"
end
context 'when reified' do
context "when reified" do
setup { @book_0 = @book.versions.last.reify(has_many: true) }
should 'see the live association' do
assert_equal ['editor_0'], @book_0.editors.map(&:name)
should "see the live association" do
assert_equal ["editor_0"], @book_0.editors.map(&:name)
end
end
end
@ -635,7 +635,7 @@ class AssociationsTest < ActiveSupport::TestCase
# Shows the value of the section as it was before
# the chapter was updated.
assert_equal ['section 2'], chapter_v2.sections.map(&:name)
assert_equal ["section 2"], chapter_v2.sections.map(&:name)
# Shows the value of the chapter as it was before
assert_equal CHAPTER_NAMES[1], chapter_v2.name
@ -652,7 +652,7 @@ class AssociationsTest < ActiveSupport::TestCase
should "have the one section" do
chapter_v2 = @chapter.versions[2].reify(has_many: true)
assert_equal ['section 2'], chapter_v2.sections.map(&:name)
assert_equal ["section 2"], chapter_v2.sections.map(&:name)
end
end
@ -675,7 +675,7 @@ class AssociationsTest < ActiveSupport::TestCase
assert_equal 3, @chapter.versions.size
@section = @chapter.sections.first
Timecop.travel 1.second.since
@paragraph = @section.paragraphs.create name: 'para1'
@paragraph = @section.paragraphs.create name: "para1"
end
context "new chapter version" do
@ -686,7 +686,7 @@ class AssociationsTest < ActiveSupport::TestCase
@chapter.update_attributes name: CHAPTER_NAMES[4]
assert_equal 4, @chapter.versions.size
Timecop.travel 1.second.since
@paragraph.update_attributes name: 'para3'
@paragraph.update_attributes name: "para3"
chapter_v3 = @chapter.versions[3].reify(has_many: true)
assert_equal [initial_section_name], chapter_v3.sections.map(&:name)
paragraphs = chapter_v3.sections.first.paragraphs
@ -753,8 +753,8 @@ class AssociationsTest < ActiveSupport::TestCase
context "a chapter with one paragraph and one citation" do
should "reify paragraphs and citations" do
chapter = Chapter.create(name: CHAPTER_NAMES[0])
section = Section.create(name: 'Section One', chapter: chapter)
paragraph = Paragraph.create(name: 'Paragraph One', section: section)
section = Section.create(name: "Section One", chapter: chapter)
paragraph = Paragraph.create(name: "Paragraph One", section: section)
quotation = Quotation.create(chapter: chapter)
citation = Citation.create(quotation: quotation)
Timecop.travel 1.second.since

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class PaperTrailCleanerTest < ActiveSupport::TestCase
def populate_db!
@ -8,26 +8,26 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context '`clean_versions!` method' do
context "`clean_versions!` method" do
setup { self.populate_db! }
should 'Baseline' do
should "Baseline" do
assert_equal 9, PaperTrail::Version.count
@animals.each { |animal| assert_equal 3, animal.versions.size }
end
should 'be extended by `PaperTrail` module' do
should "be extended by `PaperTrail` module" do
assert_respond_to PaperTrail, :clean_versions!
end
context 'No options provided' do
should 'removes extra versions for each item' do
context "No options provided" do
should "removes extra versions for each item" do
PaperTrail.clean_versions!
assert_equal 3, PaperTrail::Version.count
@animals.each { |animal| assert_equal 1, animal.versions.size }
end
should 'removes the earliest version(s)' do
should "removes the earliest version(s)" do
before = @animals.map { |animal| animal.versions.last.reify.name }
PaperTrail.clean_versions!
after = @animals.map { |animal| animal.versions.last.reify.name }
@ -35,22 +35,22 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context '`:keeping` option' do
should 'modifies the number of versions ommitted from destruction' do
context "`:keeping` option" do
should "modifies the number of versions ommitted from destruction" do
PaperTrail.clean_versions!(keeping: 2)
assert_equal 6, PaperTrail::Version.all.count
@animals.each { |animal| assert_equal 2, animal.versions.size }
end
end
context '`:date` option' do
context "`:date` option" do
setup do
@animal.versions.each { |ver| ver.update_attribute(:created_at, ver.created_at - 1.day) }
@date = @animal.versions.first.created_at.to_date
@animal.update_attribute(:name, FFaker::Name.name)
end
should 'restrict the versions destroyed to those that were created on the date provided' do
should "restrict the versions destroyed to those that were created on the date provided" do
assert_equal 10, PaperTrail::Version.count
assert_equal 4, @animal.versions.size
assert_equal 3, @animal.versions_between(@date, @date + 1.day).size
@ -62,9 +62,9 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context '`:item_id` option' do
context 'single ID received' do
should 'restrict the versions destroyed to the versions for the Item with that ID' do
context "`:item_id` option" do
context "single ID received" do
should "restrict the versions destroyed to the versions for the Item with that ID" do
PaperTrail.clean_versions!(item_id: @animal.id)
assert_equal 1, @animal.versions.size
assert_equal 7, PaperTrail::Version.count
@ -81,8 +81,8 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context 'options combinations' do # additional tests to cover combinations of options
context '`:date`' do
context "options combinations" do # additional tests to cover combinations of options
context "`:date`" do
setup do
[@animal, @dog].each do |animal|
animal.versions.each { |ver| ver.update_attribute(:created_at, ver.created_at - 1.day) }
@ -91,7 +91,7 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
@date = @animal.versions.first.created_at.to_date
end
should 'Baseline' do
should "Baseline" do
assert_equal 11, PaperTrail::Version.count
[@animal, @dog].each do |animal|
assert_equal 4, animal.versions.size
@ -99,8 +99,8 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context 'and `:keeping`' do
should 'restrict cleaning properly' do
context "and `:keeping`" do
should "restrict cleaning properly" do
PaperTrail.clean_versions!(date: @date, keeping: 2)
[@animal, @dog].each do |animal|
# reload the association to pick up the destructions made by the `Cleaner`
@ -113,8 +113,8 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context 'and `:item_id`' do
should 'restrict cleaning properly' do
context "and `:item_id`" do
should "restrict cleaning properly" do
PaperTrail.clean_versions!(date: @date, item_id: @dog.id)
# reload the association to pick up the destructions made by the `Cleaner`
@dog.versions.reload
@ -125,8 +125,8 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context ', `:item_id`, and `:keeping`' do
should 'restrict cleaning properly' do
context ", `:item_id`, and `:keeping`" do
should "restrict cleaning properly" do
PaperTrail.clean_versions!(date: @date, item_id: @dog.id, keeping: 2)
# reload the association to pick up the destructions made by the `Cleaner`
@dog.versions.reload
@ -138,8 +138,8 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
context '`:keeping` and `:item_id`' do
should 'restrict cleaning properly' do
context "`:keeping` and `:item_id`" do
should "restrict cleaning properly" do
PaperTrail.clean_versions!(keeping: 2, item_id: @animal.id)
assert_equal 2, @animal.versions.size
# ensure the versions for other animals besides `@animal` weren't touched
@ -168,7 +168,7 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
restore_schema
end
should 'Baseline' do
should "Baseline" do
assert_equal 9, PaperTrail::Version.count
@animals.each do |animal|
assert_equal 3, animal.versions.size
@ -179,7 +179,7 @@ class PaperTrailCleanerTest < ActiveSupport::TestCase
end
end
should 'group by `PaperTrail.timestamp_field` when seperating the versions by date to clean' do
should "group by `PaperTrail.timestamp_field` when seperating the versions by date to clean" do
assert_equal 9, PaperTrail::Version.count
PaperTrail.clean_versions!
assert_equal 9, PaperTrail::Version.count

View File

@ -1,29 +1,29 @@
require 'test_helper'
require "test_helper"
class InheritanceColumnTest < ActiveSupport::TestCase
context 'STI models' do
context "STI models" do
setup do
@animal = Animal.create name: 'Animal'
@animal.update_attributes name: 'Animal from the Muppets'
@animal.update_attributes name: 'Animal Muppet'
@animal = Animal.create name: "Animal"
@animal.update_attributes name: "Animal from the Muppets"
@animal.update_attributes name: "Animal Muppet"
@animal.destroy
@dog = Dog.create name: 'Snoopy'
@dog.update_attributes name: 'Scooby'
@dog.update_attributes name: 'Scooby Doo'
@dog = Dog.create name: "Snoopy"
@dog.update_attributes name: "Scooby"
@dog.update_attributes name: "Scooby Doo"
@dog.destroy
@cat = Cat.create name: 'Garfield'
@cat.update_attributes name: 'Garfield (I hate Mondays)'
@cat.update_attributes name: 'Garfield The Cat'
@cat = Cat.create name: "Garfield"
@cat.update_attributes name: "Garfield (I hate Mondays)"
@cat.update_attributes name: "Garfield The Cat"
@cat.destroy
end
should 'work with custom STI inheritance column' do
should "work with custom STI inheritance column" do
assert_equal 12, PaperTrail::Version.count
assert_equal 4, @animal.versions.count
assert_nil @animal.versions.first.reify
@animal.versions[1..-1].each { |v| assert_equal 'Animal', v.reify.class.name }
@animal.versions[1..-1].each { |v| assert_equal "Animal", v.reify.class.name }
# For some reason `@dog.versions` doesn't include the final `destroy` version.
# Neither do `@dog.versions.scoped` nor `@dog.versions(true)` nor `@dog.versions.reload`.

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class ProtectedAttrsTest < ActiveSupport::TestCase
subject { ProtectedWidget.new }
@ -18,28 +18,28 @@ class ProtectedAttrsTest < ActiveSupport::TestCase
end
end
context 'A model with `attr_accessible` created' do
context "A model with `attr_accessible` created" do
setup do
@widget = ProtectedWidget.create! name: 'Henry'
@widget = ProtectedWidget.create! name: "Henry"
@initial_attributes = @widget.attributes
end
should 'be `nil` in its previous version' do
should "be `nil` in its previous version" do
assert_nil @widget.previous_version
end
context 'which is then updated' do
context "which is then updated" do
setup do
@widget.assign_attributes(name: 'Jeff', a_text: 'Short statement')
@widget.assign_attributes(name: "Jeff", a_text: "Short statement")
@widget.an_integer = 42
@widget.save!
end
should 'not be `nil` in its previous version' do
should "not be `nil` in its previous version" do
assert_not_nil @widget.previous_version
end
should 'the previous version should contain right attributes' do
should "the previous version should contain right attributes" do
# For some reason this test seems to be broken in JRuby 1.9 mode in the
# test env even though it works in the console. WTF?
unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION)

View File

@ -1,26 +1,26 @@
require 'test_helper'
require 'custom_json_serializer'
require "test_helper"
require "custom_json_serializer"
class SerializerTest < ActiveSupport::TestCase
context 'YAML Serializer' do
context "YAML Serializer" do
setup do
Fluxor.instance_eval <<-END
has_paper_trail
END
@fluxor = Fluxor.create name: 'Some text.'
@fluxor = Fluxor.create name: "Some text."
# this is exactly what PaperTrail serializes
@original_fluxor_attributes = @fluxor.send(:attributes_before_change)
@fluxor.update_attributes name: 'Some more text.'
@fluxor.update_attributes name: "Some more text."
end
should 'work with the default `YAML` serializer' do
should "work with the default `YAML` serializer" do
# Normal behaviour
assert_equal 2, @fluxor.versions.length
assert_nil @fluxor.versions[0].reify
assert_equal 'Some text.', @fluxor.versions[1].reify.name
assert_equal "Some text.", @fluxor.versions[1].reify.name
# Check values are stored as `YAML`.
assert_equal @original_fluxor_attributes, YAML.load(@fluxor.versions[1].object)
@ -28,7 +28,7 @@ class SerializerTest < ActiveSupport::TestCase
end
end
context 'JSON Serializer' do
context "JSON Serializer" do
setup do
PaperTrail.configure do |config|
config.serializer = PaperTrail::Serializers::JSON
@ -38,23 +38,23 @@ class SerializerTest < ActiveSupport::TestCase
has_paper_trail
END
@fluxor = Fluxor.create name: 'Some text.'
@fluxor = Fluxor.create name: "Some text."
# this is exactly what PaperTrail serializes
@original_fluxor_attributes = @fluxor.send(:attributes_before_change)
@fluxor.update_attributes name: 'Some more text.'
@fluxor.update_attributes name: "Some more text."
end
teardown do
PaperTrail.config.serializer = PaperTrail::Serializers::YAML
end
should 'reify with JSON serializer' do
should "reify with JSON serializer" do
# Normal behaviour
assert_equal 2, @fluxor.versions.length
assert_nil @fluxor.versions[0].reify
assert_equal 'Some text.', @fluxor.versions[1].reify.name
assert_equal "Some text.", @fluxor.versions[1].reify.name
# Check values are stored as JSON.
assert_equal @original_fluxor_attributes,
@ -63,7 +63,7 @@ class SerializerTest < ActiveSupport::TestCase
@fluxor.versions[1].object
end
should 'store object_changes' do
should "store object_changes" do
initial_changeset = {"name" => [nil, "Some text."], "id" => [nil, @fluxor.id]}
second_changeset = {"name"=>["Some text.", "Some more text."]}
assert_equal initial_changeset, @fluxor.versions[0].changeset
@ -71,7 +71,7 @@ class SerializerTest < ActiveSupport::TestCase
end
end
context 'Custom Serializer' do
context "Custom Serializer" do
setup do
PaperTrail.configure do |config|
config.serializer = CustomJsonSerializer
@ -88,14 +88,14 @@ class SerializerTest < ActiveSupport::TestCase
send(:attributes_before_change).
reject { |_k, v| v.nil? }
@fluxor.update_attributes name: 'Some more text.'
@fluxor.update_attributes name: "Some more text."
end
teardown do
PaperTrail.config.serializer = PaperTrail::Serializers::YAML
end
should 'reify with custom serializer' do
should "reify with custom serializer" do
# Normal behaviour
assert_equal 2, @fluxor.versions.length
assert_nil @fluxor.versions[0].reify
@ -108,7 +108,7 @@ class SerializerTest < ActiveSupport::TestCase
@fluxor.versions[1].object
end
should 'store object_changes' do
should "store object_changes" do
initial_changeset = {"id" => [nil, @fluxor.id]}
second_changeset = {"name"=>[nil, "Some more text."]}
assert_equal initial_changeset, @fluxor.versions[0].changeset

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class JSONTest < ActiveSupport::TestCase
setup do
@ -14,36 +14,36 @@ class JSONTest < ActiveSupport::TestCase
@array_as_json = @array.to_json
end
context '`load` class method' do
should 'exist' do
context "`load` class method" do
should "exist" do
assert PaperTrail::Serializers::JSON.respond_to?(:load)
end
should '`deserialize` JSON to Ruby' do
should "`deserialize` JSON to Ruby" do
assert_equal @hash, PaperTrail::Serializers::JSON.load(@hash_as_json)
assert_equal @array, PaperTrail::Serializers::JSON.load(@array_as_json)
end
end
context '`dump` class method' do
should 'exist' do
context "`dump` class method" do
should "exist" do
assert PaperTrail::Serializers::JSON.respond_to?(:dump)
end
should '`serialize` Ruby to JSON' do
should "`serialize` Ruby to JSON" do
assert_equal @hash_as_json, PaperTrail::Serializers::JSON.dump(@hash)
assert_equal @array_as_json, PaperTrail::Serializers::JSON.dump(@array)
end
end
context '`where_object` class method' do
context "`where_object` class method" do
context "when value is a string" do
should 'construct correct WHERE query' do
should "construct correct WHERE query" do
matches = PaperTrail::Serializers::JSON.where_object_condition(
PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
assert matches.instance_of?(Arel::Nodes::Matches)
if Arel::VERSION >= '6'
if Arel::VERSION >= "6"
assert_equal matches.right.val, "%\"arg1\":\"Val 1\"%"
else
assert_equal matches.right, "%\"arg1\":\"Val 1\"%"
@ -52,12 +52,12 @@ class JSONTest < ActiveSupport::TestCase
end
context "when value is `null`" do
should 'construct correct WHERE query' do
should "construct correct WHERE query" do
matches = PaperTrail::Serializers::JSON.where_object_condition(
PaperTrail::Version.arel_table[:object], :arg1, nil)
assert matches.instance_of?(Arel::Nodes::Matches)
if Arel::VERSION >= '6'
if Arel::VERSION >= "6"
assert_equal matches.right.val, "%\"arg1\":null%"
else
assert_equal matches.right, "%\"arg1\":null%"
@ -66,7 +66,7 @@ class JSONTest < ActiveSupport::TestCase
end
context "when value is a number" do
should 'construct correct WHERE query' do
should "construct correct WHERE query" do
grouping = PaperTrail::Serializers::JSON.where_object_condition(
PaperTrail::Version.arel_table[:object], :arg1, -3.5)
@ -74,7 +74,7 @@ class JSONTest < ActiveSupport::TestCase
matches = grouping.select { |v| v.instance_of?(Arel::Nodes::Matches) }
# Numeric arguments need to ensure that they match for only the number, not the beginning
# of a #, so it uses an Grouping matcher (See notes on `PaperTrail::Serializers::JSON`)
if Arel::VERSION >= '6'
if Arel::VERSION >= "6"
assert_equal matches.first.right.val, "%\"arg1\":-3.5,%"
assert_equal matches.last.right.val, "%\"arg1\":-3.5}%"
else

View File

@ -1,5 +1,5 @@
require 'test_helper'
require 'custom_json_serializer'
require "test_helper"
require "custom_json_serializer"
class MixinJsonTest < ActiveSupport::TestCase
setup do
@ -8,28 +8,28 @@ class MixinJsonTest < ActiveSupport::TestCase
(1..4).each do |i|
@hash["key#{i}"] = [FFaker::Lorem.word, nil].sample
end
@hash['tkey'] = nil
@hash[''] = 'foo'
@hash["tkey"] = nil
@hash[""] = "foo"
@hash_as_json = @hash.to_json
end
context '`load` class method' do
should 'exist' do
context "`load` class method" do
should "exist" do
assert CustomJsonSerializer.respond_to?(:load)
end
should '`deserialize` JSON to Ruby, removing pairs with `blank` keys or values' do
should "`deserialize` JSON to Ruby, removing pairs with `blank` keys or values" do
assert_equal @hash.reject { |k, v| k.blank? || v.blank? },
CustomJsonSerializer.load(@hash_as_json)
end
end
context '`dump` class method' do
should 'exist' do
context "`dump` class method" do
should "exist" do
assert CustomJsonSerializer.respond_to?(:dump)
end
should '`serialize` Ruby to JSON, removing pairs with `nil` values' do
should "`serialize` Ruby to JSON, removing pairs with `nil` values" do
assert_equal @hash.reject { |_k, v| v.nil? }.to_json,
CustomJsonSerializer.dump(@hash)
end

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
module CustomYamlSerializer
extend PaperTrail::Serializers::YAML
@ -24,28 +24,28 @@ class MixinYamlTest < ActiveSupport::TestCase
(1..4).each do |i|
@hash["key#{i}"] = [FFaker::Lorem.word, nil].sample
end
@hash['tkey'] = nil
@hash[''] = 'foo'
@hash["tkey"] = nil
@hash[""] = "foo"
@hash_as_yaml = @hash.to_yaml
end
context '`load` class method' do
should 'exist' do
context "`load` class method" do
should "exist" do
assert CustomYamlSerializer.respond_to?(:load)
end
should '`deserialize` YAML to Ruby, removing pairs with `blank` keys or values' do
should "`deserialize` YAML to Ruby, removing pairs with `blank` keys or values" do
assert_equal @hash.reject { |k, v| k.blank? || v.blank? },
CustomYamlSerializer.load(@hash_as_yaml)
end
end
context '`dump` class method' do
should 'exist' do
context "`dump` class method" do
should "exist" do
assert CustomYamlSerializer.respond_to?(:dump)
end
should '`serialize` Ruby to YAML, removing pairs with `nil` values' do
should "`serialize` Ruby to YAML, removing pairs with `nil` values" do
assert_equal @hash.reject { |_k, v| v.nil? }.to_yaml,
CustomYamlSerializer.dump(@hash)
end

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class YamlTest < ActiveSupport::TestCase
setup do
@ -14,34 +14,34 @@ class YamlTest < ActiveSupport::TestCase
@array_as_yaml = @array.to_yaml
end
context '`load` class method' do
should 'exist' do
context "`load` class method" do
should "exist" do
assert PaperTrail::Serializers::YAML.respond_to?(:load)
end
should 'deserialize `YAML` to Ruby' do
should "deserialize `YAML` to Ruby" do
assert_equal @hash, PaperTrail::Serializers::YAML.load(@hash_as_yaml)
assert_equal @array, PaperTrail::Serializers::YAML.load(@array_as_yaml)
end
end
context '`dump` class method' do
should 'exist' do
context "`dump` class method" do
should "exist" do
assert PaperTrail::Serializers::YAML.respond_to?(:dump)
end
should 'serialize Ruby to `YAML`' do
should "serialize Ruby to `YAML`" do
assert_equal @hash_as_yaml, PaperTrail::Serializers::YAML.dump(@hash)
assert_equal @array_as_yaml, PaperTrail::Serializers::YAML.dump(@array)
end
end
context '`where_object` class method' do
should 'construct correct WHERE query' do
context "`where_object` class method" do
should "construct correct WHERE query" do
matches = PaperTrail::Serializers::YAML.where_object_condition(
PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
assert matches.instance_of?(Arel::Nodes::Matches)
if Arel::VERSION >= '6'
if Arel::VERSION >= "6"
assert_equal matches.right.val, "%\narg1: Val 1\n%"
else
assert_equal matches.right, "%\narg1: Val 1\n%"

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class TimestampTest < ActiveSupport::TestCase
setup do
@ -9,9 +9,9 @@ class TimestampTest < ActiveSupport::TestCase
has_paper_trail
END
@fluxor = Fluxor.create name: 'Some text.'
@fluxor.update_attributes name: 'Some more text.'
@fluxor.update_attributes name: 'Even more text.'
@fluxor = Fluxor.create name: "Some text."
@fluxor.update_attributes name: "Some more text."
@fluxor.update_attributes name: "Even more text."
end
teardown do
@ -19,12 +19,12 @@ class TimestampTest < ActiveSupport::TestCase
restore_schema
end
test 'versions works with custom timestamp field' do
test "versions works with custom timestamp field" do
# Normal behaviour
assert_equal 3, @fluxor.versions.length
assert_nil @fluxor.versions[0].reify
assert_equal 'Some text.', @fluxor.versions[1].reify.name
assert_equal 'Some more text.', @fluxor.versions[2].reify.name
assert_equal "Some text.", @fluxor.versions[1].reify.name
assert_equal "Some more text.", @fluxor.versions[2].reify.name
# Tinker with custom timestamps.
now = Time.now.utc
@ -35,7 +35,7 @@ class TimestampTest < ActiveSupport::TestCase
# Test we are ordering by custom timestamps.
@fluxor.versions.reload # reload association
assert_nil @fluxor.versions[2].reify
assert_equal 'Some text.', @fluxor.versions[1].reify.name
assert_equal 'Some more text.', @fluxor.versions[0].reify.name
assert_equal "Some text.", @fluxor.versions[1].reify.name
assert_equal "Some more text.", @fluxor.versions[0].reify.name
end
end

View File

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
module PaperTrail
class VersionTest < ActiveSupport::TestCase
@ -24,7 +24,7 @@ module PaperTrail
context ".updates" do
setup {
@animal.update_attributes(name: 'Animal')
@animal.update_attributes(name: "Animal")
assert Version.updates.present?
}
@ -50,7 +50,7 @@ module PaperTrail
context ".not_creates" do
setup {
@animal.update_attributes(name: 'Animal')
@animal.update_attributes(name: "Animal")
@animal.destroy
assert Version.not_creates.present?
}