Lint: Fix Lint/AmbiguousBlockAssociation
This commit is contained in:
parent
3089e51206
commit
3df7dc27d2
|
@ -3,9 +3,6 @@ require: rubocop-rspec
|
||||||
# Remove these configuration records
|
# Remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
|
|
||||||
Lint/AmbiguousBlockAssociation:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 22 # Goal: 15
|
Max: 22 # Goal: 15
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "rails_helper"
|
||||||
require "generator_spec/test_case"
|
require "generator_spec/test_case"
|
||||||
require File.expand_path("../../../lib/generators/paper_trail/install_generator", __FILE__)
|
require File.expand_path("../../../lib/generators/paper_trail/install_generator", __FILE__)
|
||||||
|
|
||||||
describe PaperTrail::InstallGenerator, type: :generator do
|
RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
||||||
include GeneratorSpec::TestCase
|
include GeneratorSpec::TestCase
|
||||||
destination File.expand_path("../tmp", __FILE__)
|
destination File.expand_path("../tmp", __FILE__)
|
||||||
|
|
||||||
|
@ -15,17 +15,19 @@ describe PaperTrail::InstallGenerator, type: :generator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates a migration for creating the 'versions' table" do
|
it "generates a migration for creating the 'versions' table" do
|
||||||
expect(destination_root).to have_structure {
|
expect(destination_root).to(
|
||||||
directory "db" do
|
have_structure {
|
||||||
directory "migrate" do
|
directory("db") {
|
||||||
migration "create_versions" do
|
directory("migrate") {
|
||||||
contains "class CreateVersions"
|
migration("create_versions") {
|
||||||
contains "def change"
|
contains "class CreateVersions"
|
||||||
contains "create_table :versions"
|
contains "def change"
|
||||||
end
|
contains "create_table :versions"
|
||||||
end
|
}
|
||||||
end
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,31 +38,35 @@ describe PaperTrail::InstallGenerator, type: :generator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates a migration for creating the 'versions' table" do
|
it "generates a migration for creating the 'versions' table" do
|
||||||
expect(destination_root).to have_structure {
|
expect(destination_root).to(
|
||||||
directory "db" do
|
have_structure {
|
||||||
directory "migrate" do
|
directory("db") {
|
||||||
migration "create_versions" do
|
directory("migrate") {
|
||||||
contains "class CreateVersions"
|
migration("create_versions") {
|
||||||
contains "def change"
|
contains "class CreateVersions"
|
||||||
contains "create_table :versions"
|
contains "def change"
|
||||||
end
|
contains "create_table :versions"
|
||||||
end
|
}
|
||||||
end
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
|
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
|
||||||
expect(destination_root).to have_structure {
|
expect(destination_root).to(
|
||||||
directory "db" do
|
have_structure {
|
||||||
directory "migrate" do
|
directory("db") {
|
||||||
migration "add_object_changes_to_versions" do
|
directory("migrate") {
|
||||||
contains "class AddObjectChangesToVersions"
|
migration("add_object_changes_to_versions") {
|
||||||
contains "def change"
|
contains "class AddObjectChangesToVersions"
|
||||||
contains "add_column :versions, :object_changes, :text"
|
contains "def change"
|
||||||
end
|
contains "add_column :versions, :object_changes, :text"
|
||||||
end
|
}
|
||||||
end
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,18 +7,18 @@ describe Gadget, type: :model do
|
||||||
|
|
||||||
describe "updates", versioning: true do
|
describe "updates", versioning: true do
|
||||||
it "should generate a version for updates to `name` attribute" 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
|
end
|
||||||
|
|
||||||
it "should ignore for updates to `brand` attribute" do
|
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
|
end
|
||||||
|
|
||||||
it "should still generate a version when only the `updated_at` attribute is updated" do
|
it "should still generate a version when only the `updated_at` attribute is updated" do
|
||||||
# Plus 1 second because MySQL lacks sub-second resolution
|
# Plus 1 second because MySQL lacks sub-second resolution
|
||||||
expect {
|
expect {
|
||||||
gadget.update_attribute(:updated_at, Time.now + 1)
|
gadget.update_attribute(:updated_at, Time.now + 1)
|
||||||
}.to change { gadget.versions.size }.by(1)
|
}.to(change { gadget.versions.size }.by(1))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe Skipper, type: :model do
|
||||||
skipper = Skipper.create!(another_timestamp: t1)
|
skipper = Skipper.create!(another_timestamp: t1)
|
||||||
expect {
|
expect {
|
||||||
skipper.update_attributes!(another_timestamp: t2)
|
skipper.update_attributes!(another_timestamp: t2)
|
||||||
}.to_not change { skipper.versions.length }
|
}.to_not(change { skipper.versions.length })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -317,9 +317,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have versions that are not live" do
|
should "have versions that are not live" do
|
||||||
assert @widget.versions.map(&:reify).compact.all? { |w|
|
assert(@widget.versions.map(&:reify).compact.all? { |w| !w.paper_trail.live? })
|
||||||
!w.paper_trail.live?
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have stored changes" do
|
should "have stored changes" do
|
||||||
|
|
|
@ -19,8 +19,10 @@ class MixinJsonTest < ActiveSupport::TestCase
|
||||||
end
|
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? },
|
assert_equal(
|
||||||
|
@hash.reject { |k, v| k.blank? || v.blank? },
|
||||||
CustomJsonSerializer.load(@hash_as_json)
|
CustomJsonSerializer.load(@hash_as_json)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue