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