1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

rubocop 0.48.1 (was 0.48.0)

This commit is contained in:
Jared Beck 2017-05-21 02:40:23 -04:00
parent adf1c99c05
commit e2505c4f30
20 changed files with 48 additions and 48 deletions

View file

@ -32,4 +32,4 @@ require "rubocop/rake_task"
RuboCop::RakeTask.new
desc "Default: run all available test suites"
task default: %i(rubocop prepare test spec)
task default: %i[rubocop prepare test spec]

View file

@ -36,7 +36,7 @@ ActiveRecord::Schema.define do
t.integer :transaction_id
t.datetime :created_at
end
add_index :versions, %i(item_type item_id)
add_index :versions, %i[item_type item_id]
add_index :versions, [:transaction_id]
create_table :version_associations do |t|
@ -45,7 +45,7 @@ ActiveRecord::Schema.define do
t.integer :foreign_key_id
end
add_index :version_associations, [:version_id]
add_index :version_associations, %i(foreign_key_name foreign_key_id),
add_index :version_associations, %i[foreign_key_name foreign_key_id],
name: "index_version_associations_on_foreign_key"
end
ActiveRecord::Base.logger = Logger.new(STDOUT)

View file

@ -40,7 +40,7 @@ module PaperTrail
# Adds a callback that records a version before or after a "destroy" event.
def on_destroy(recording_order = "before")
unless %w(after before).include?(recording_order.to_s)
unless %w[after before].include?(recording_order.to_s)
raise ArgumentError, 'recording order can only be "after" or "before"'
end
@ -76,7 +76,7 @@ module PaperTrail
# "class attributes", instance methods, and more.
# @api private
def setup(options = {})
options[:on] ||= %i(create update destroy)
options[:on] ||= %i[create update destroy]
options[:on] = Array(options[:on]) # Support single symbol
@model_class.send :include, ::PaperTrail::Model::InstanceMethods
if ::ActiveRecord::VERSION::STRING < "4.2"
@ -153,7 +153,7 @@ module PaperTrail
def setup_habtm_change_callbacks(assoc)
assoc_name = assoc.name
%w(add remove).each do |verb|
%w[add remove].each do |verb|
@model_class.send(:"before_#{verb}_for_#{assoc_name}").send(
:<<,
lambda do |*args|
@ -167,7 +167,7 @@ module PaperTrail
@model_class.class_attribute :paper_trail_options
@model_class.paper_trail_options = options.dup
%i(ignore skip only).each do |k|
%i[ignore skip only].each do |k|
@model_class.paper_trail_options[k] = [@model_class.paper_trail_options[k]].
flatten.
compact.

View file

@ -24,7 +24,7 @@ module PaperTrail
validates_presence_of :event
after_create :enforce_version_limit!
scope :within_transaction, ->(id) { where transaction_id: id }
scope(:within_transaction, ->(id) { where transaction_id: id })
end
# :nodoc:
@ -162,13 +162,13 @@ module PaperTrail
# Returns whether the `object` column is using the `json` type supported
# by PostgreSQL.
def object_col_is_json?
%i(json jsonb).include?(columns_hash["object"].type)
%i[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?
%i(json jsonb).include?(columns_hash["object_changes"].try(:type))
%i[json jsonb].include?(columns_hash["object_changes"].try(:type))
end
end

View file

@ -41,7 +41,7 @@ has been destroyed.
s.add_development_dependency "generator_spec", "~> 0.9.3"
s.add_development_dependency "database_cleaner", "~> 1.2"
s.add_development_dependency "pry-byebug", "~> 3.4"
s.add_development_dependency "rubocop", "0.48.0"
s.add_development_dependency "rubocop", "0.48.1"
s.add_development_dependency "rubocop-rspec", "~> 1.15.0"
s.add_development_dependency "timecop", "~> 0.8.0"
s.add_development_dependency "sqlite3", "~> 1.2"

View file

@ -50,7 +50,7 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do
describe "`--with-changes` option set to `true`" do
before(:all) do
prepare_destination
run_generator %w(--with-changes)
run_generator %w[--with-changes]
end
it "generates a migration for creating the 'versions' table" do

View file

@ -28,11 +28,11 @@ RSpec.describe Animal, type: :model, versioning: true do
dog_versions = PaperTrail::Version.where(item_id: dog.id).order(:created_at)
expect(dog_versions.count).to(eq(4))
expect(dog_versions.first.reify).to(be_nil)
expect(dog_versions.map { |v| v.reify.class.name }).to eq(%w(NilClass Dog Dog Dog))
expect(dog_versions.map { |v| v.reify.class.name }).to eq(%w[NilClass Dog Dog Dog])
cat_versions = PaperTrail::Version.where(item_id: cat.id).order(:created_at)
expect(cat_versions.count).to(eq(4))
expect(cat_versions.first.reify).to(be_nil)
expect(cat_versions.map { |v| v.reify.class.name }).to eq(%w(NilClass Cat Cat Cat))
expect(cat_versions.map { |v| v.reify.class.name }).to eq(%w[NilClass Cat Cat Cat])
end
it "allows the inheritance_column (species) to be updated" do
@ -49,7 +49,7 @@ RSpec.describe Animal, type: :model, versioning: true do
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)
expect(callback_cat.versions.collect(&:event)).to eq %w[create update destroy]
end
it "does not break reify" do

View file

@ -60,7 +60,7 @@ RSpec.describe CallbackModifier, type: :model, versioning: true do
context "when no callback-method used" do
it "sets 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 %i(create update destroy)
expect(modifier.paper_trail_options[:on]).to eq %i[create update destroy]
end
it "tracks destroy" do

View file

@ -31,7 +31,7 @@ if JsonVersion.table_exists?
end
context "valid arguments", versioning: true do
let(:fruit_names) { %w(apple orange lemon banana lime coconut strawberry blueberry) }
let(:fruit_names) { %w[apple orange lemon banana lime coconut strawberry blueberry] }
let(:fruit) { Fruit.new }
let(:name) { "pomegranate" }
let(:color) { FFaker::Color.name }
@ -70,9 +70,9 @@ if JsonVersion.table_exists?
end
context "valid arguments", versioning: true do
let(:color) { %w(red green) }
let(:color) { %w[red green] }
let(:fruit) { Fruit.create!(name: name[0]) }
let(:name) { %w(banana kiwi mango) }
let(:name) { %w[banana kiwi mango] }
before do
fruit.update_attributes!(name: name[1], color: color[0])

View file

@ -17,7 +17,7 @@ RSpec.describe PostWithStatus, type: :model do
# Simulate behavior PT 4, which used to save the string version of
# enums to `object_changes`
version.update(object_changes: "---\nid:\n- \n- 1\nstatus:\n- draft\n- published\n")
assert_equal %w(draft published), version.changeset["status"]
assert_equal %w[draft published], version.changeset["status"]
end
context "storing enum object_changes" do
@ -26,7 +26,7 @@ RSpec.describe PostWithStatus, type: :model do
it "saves the enum value properly in versions object_changes" do
post.published!
post.archived!
expect(subject.changeset["status"]).to eql %w(published archived)
expect(subject.changeset["status"]).to eql %w[published archived]
end
end

View file

@ -105,7 +105,7 @@ module PaperTrail
before do
if override
ActiveRecord::Base.connection.execute("SAVEPOINT pgtest;")
%w(object object_changes).each do |column|
%w[object object_changes].each do |column|
ActiveRecord::Base.connection.execute(
"ALTER TABLE versions DROP COLUMN #{column};"
)

View file

@ -31,7 +31,7 @@ module PaperTrail
animal = Animal.create
animal.update_attributes(name: "Animal")
animal.destroy
expect(described_class.not_creates.pluck(:event)).to eq(%w(update destroy))
expect(described_class.not_creates.pluck(:event)).to eq(%w[update destroy])
end
end

View file

@ -1,6 +1,6 @@
class Document < ActiveRecord::Base
has_paper_trail(
versions: :paper_trail_versions,
on: %i(create update)
on: %i[create update]
)
end

View file

@ -1,4 +1,4 @@
# This model does not record versions when updated.
class NotOnUpdate < ActiveRecord::Base
has_paper_trail on: %i(create destroy)
has_paper_trail on: %i[create destroy]
end

View file

@ -2,7 +2,7 @@ class Widget < ActiveRecord::Base
EXCLUDED_NAME = "Biglet".freeze
has_paper_trail
has_one :wotsit
has_many :fluxors, -> { order(:name) }
has_many(:fluxors, -> { order(:name) })
has_many :whatchamajiggers, as: :owner
validates :name, exclusion: { in: [EXCLUDED_NAME] }
end

View file

@ -1,4 +1,4 @@
Dummy::Application.routes.draw do
resources :articles, only: [:create]
resources :widgets, only: %i(create update destroy)
resources :widgets, only: %i[create update destroy]
end

View file

@ -82,7 +82,7 @@ class SetUpTestTables < (
t.string :ip
t.string :user_agent
end
add_index :versions, %i(item_type item_id)
add_index :versions, %i[item_type item_id]
create_table :version_associations do |t|
t.integer :version_id
@ -91,7 +91,7 @@ class SetUpTestTables < (
end
add_index :version_associations, [:version_id]
add_index :version_associations,
%i(foreign_key_name foreign_key_id),
%i[foreign_key_name foreign_key_id],
name: "index_version_associations_on_foreign_key"
create_table :post_versions, force: true do |t|
@ -106,7 +106,7 @@ class SetUpTestTables < (
t.string :ip
t.string :user_agent
end
add_index :post_versions, %i(item_type item_id)
add_index :post_versions, %i[item_type item_id]
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 4
create_table :json_versions, force: true do |t|
@ -118,7 +118,7 @@ class SetUpTestTables < (
t.json :object_changes
t.datetime :created_at
end
add_index :json_versions, %i(item_type item_id)
add_index :json_versions, %i[item_type item_id]
end
create_table :not_on_updates, force: true do |t|
@ -137,7 +137,7 @@ class SetUpTestTables < (
t.text :object
t.datetime :created_at
end
add_index :banana_versions, %i(item_type item_id)
add_index :banana_versions, %i[item_type item_id]
create_table :wotsits, force: true do |t|
t.integer :widget_id
@ -314,7 +314,7 @@ class SetUpTestTables < (
t.text :object
t.datetime :created_at
end
add_index :custom_primary_key_record_versions, %i(item_type item_id), name: "idx_cust_pk_item"
add_index :custom_primary_key_record_versions, %i[item_type item_id], name: "idx_cust_pk_item"
end
def down

View file

@ -62,7 +62,7 @@ module ActiveSupport
actual = actual.dup
# Adjust timestamps for missing fractional seconds precision.
%w(created_at updated_at).each do |timestamp|
%w[created_at updated_at].each do |timestamp|
expected[timestamp] = expected[timestamp].change(usec: 0)
actual[timestamp] = actual[timestamp].change(usec: 0)
end
@ -77,7 +77,7 @@ module ActiveSupport
actual = actual.dup
# Adjust timestamps for missing fractional seconds precision.
%w(created_at updated_at).each do |timestamp|
%w[created_at updated_at].each do |timestamp|
expected[timestamp][1] = expected[timestamp][1].change(usec: 0)
actual[timestamp][1] = actual[timestamp][1].change(usec: 0)
end

View file

@ -295,7 +295,7 @@ class AssociationsTest < ActiveSupport::TestCase
end
should "not persist changes to the live association" do
assert_equal %w(order_date_0 order_date_1),
assert_equal %w[order_date_0 order_date_1],
@customer.orders.reload.map(&:order_date).sort
end
end
@ -501,7 +501,7 @@ class AssociationsTest < ActiveSupport::TestCase
end
should "not persist changes to the live association" do
assert_equal %w(author_0 author_1), @book.authors.reload.map(&:name)
assert_equal %w[author_0 author_1], @book.authors.reload.map(&:name)
end
end
@ -542,7 +542,7 @@ class AssociationsTest < ActiveSupport::TestCase
end
should "not persist changes to the live association" do
assert_equal %w(author_0 person_existing), @book.authors.reload.map(&:name).sort
assert_equal %w[author_0 person_existing], @book.authors.reload.map(&:name).sort
end
end

View file

@ -328,16 +328,16 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
actual = PaperTrail.serializer.load(last_obj_changes).reject { |k, _v|
k.to_sym == :updated_at
}
assert_equal ({ "name" => %w(Henry Harry) }), actual
assert_equal ({ "name" => %w[Henry Harry] }), actual
actual = @widget.versions.last.changeset.reject { |k, _v|
k.to_sym == :updated_at
}
assert_equal ({ "name" => %w(Henry Harry) }), actual
assert_equal ({ "name" => %w[Henry Harry] }), actual
end
should "return changes with indifferent access" do
assert_equal %w(Henry Harry), @widget.versions.last.changeset[:name]
assert_equal %w(Henry Harry), @widget.versions.last.changeset["name"]
assert_equal %w[Henry Harry], @widget.versions.last.changeset[:name]
assert_equal %w[Henry Harry], @widget.versions.last.changeset["name"]
end
context "and has one associated object" do
@ -798,9 +798,9 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
should "return versions in the time period" do
assert_equal ["Fidget"],
@widget.paper_trail.versions_between(20.days.ago, 10.days.ago).map(&:name)
assert_equal %w(Widget Fidget),
assert_equal %w[Widget Fidget],
@widget.paper_trail.versions_between(45.days.ago, 10.days.ago).map(&:name)
assert_equal %w(Fidget Digit Digit),
assert_equal %w[Fidget Digit Digit],
@widget.paper_trail.versions_between(16.days.ago, 1.minute.ago).map(&:name)
assert_equal [],
@widget.paper_trail.versions_between(60.days.ago, 45.days.ago).map(&:name)
@ -916,7 +916,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
context "A reified item" do
setup do
widget = Widget.create name: "Bob"
%w(Tom Dick Jane).each { |name| widget.update_attributes name: name }
%w[Tom Dick Jane].each { |name| widget.update_attributes name: name }
@version = widget.versions.last
@widget = @version.reify
end
@ -945,7 +945,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
context "with versions" do
setup do
@widget.save
%w(Tom Dick Jane).each { |name| @widget.update_attributes name: name }
%w[Tom Dick Jane].each { |name| @widget.update_attributes name: name }
end
should "have a previous version" do
@ -962,7 +962,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
context "A reified item" do
setup do
@widget = Widget.create name: "Bob"
%w(Tom Dick Jane).each { |name| @widget.update_attributes name: name }
%w[Tom Dick Jane].each { |name| @widget.update_attributes name: name }
@second_widget = @widget.versions[1].reify # first widget is `nil`
@last_widget = @widget.versions.last.reify
end
@ -1347,7 +1347,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
context "A reified item with a column -version- and custom version_method" do
setup do
widget = LegacyWidget.create(name: "foo", version: 2)
%w(bar baz).each { |name| widget.update_attributes name: name }
%w[bar baz].each { |name| widget.update_attributes name: name }
@version = widget.versions.last
@widget = @version.reify
end