Lint: RSpec/BeforeAfterAll
This commit is contained in:
parent
f2429ed624
commit
c2d5df8fde
|
@ -17,9 +17,6 @@ Metrics/PerceivedComplexity:
|
|||
Style/FrozenStringLiteralComment:
|
||||
Enabled: false
|
||||
|
||||
RSpec/BeforeAfterAll:
|
||||
Enabled: false
|
||||
|
||||
RSpec/ExpectInHook:
|
||||
Exclude:
|
||||
- spec/paper_trail/associations_spec.rb
|
||||
|
|
|
@ -6,10 +6,12 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
|||
include GeneratorSpec::TestCase
|
||||
destination File.expand_path("../tmp", __FILE__)
|
||||
|
||||
after(:all) { prepare_destination } # cleanup the tmp directory
|
||||
after do
|
||||
prepare_destination # cleanup the tmp directory
|
||||
end
|
||||
|
||||
describe "no options" do
|
||||
before(:all) do
|
||||
before do
|
||||
prepare_destination
|
||||
run_generator
|
||||
end
|
||||
|
@ -48,7 +50,7 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
|||
end
|
||||
|
||||
describe "`--with-changes` option set to `true`" do
|
||||
before(:all) do
|
||||
before do
|
||||
prepare_destination
|
||||
run_generator %w[--with-changes]
|
||||
end
|
||||
|
|
|
@ -15,13 +15,17 @@ module PaperTrail
|
|||
end
|
||||
|
||||
context "serializer is JSON" do
|
||||
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
||||
before do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
||||
end
|
||||
|
||||
it "store out as a plain hash" do
|
||||
expect(value =~ /HashWithIndifferentAccess/).to be_nil
|
||||
end
|
||||
|
||||
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
||||
after do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::YAML
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,6 +135,8 @@ module PaperTrail
|
|||
end
|
||||
|
||||
after do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::YAML
|
||||
|
||||
if column_datatype_override
|
||||
# In rails < 5, we use truncation, ie. there is no transaction
|
||||
# around the tests, so we can't use a savepoint.
|
||||
|
@ -151,13 +157,10 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe "#where_object", versioning: true do
|
||||
before do
|
||||
it "requires its argument to be a Hash" do
|
||||
widget.update_attributes!(name: name, an_integer: int)
|
||||
widget.update_attributes!(name: "foobar", an_integer: 100)
|
||||
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
|
||||
end
|
||||
|
||||
it "requires its argument to be a Hash" do
|
||||
expect {
|
||||
PaperTrail::Version.where_object(:foo)
|
||||
}.to raise_error(ArgumentError)
|
||||
|
@ -167,11 +170,11 @@ module PaperTrail
|
|||
end
|
||||
|
||||
context "`serializer == YAML`" do
|
||||
specify do
|
||||
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
|
||||
end
|
||||
|
||||
it "locates versions according to their `object` contents" do
|
||||
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
|
||||
widget.update_attributes!(name: name, an_integer: int)
|
||||
widget.update_attributes!(name: "foobar", an_integer: 100)
|
||||
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
|
||||
expect(
|
||||
PaperTrail::Version.where_object(an_integer: int)
|
||||
).to eq([widget.versions[1]])
|
||||
|
@ -185,15 +188,12 @@ module PaperTrail
|
|||
end
|
||||
|
||||
context "JSON serializer" do
|
||||
before(:all) do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
|
||||
end
|
||||
|
||||
it "locates versions according to their `object` contents" do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
||||
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
|
||||
widget.update_attributes!(name: name, an_integer: int)
|
||||
widget.update_attributes!(name: "foobar", an_integer: 100)
|
||||
widget.update_attributes!(name: FFaker::Name.last_name, an_integer: 15)
|
||||
expect(
|
||||
PaperTrail::Version.where_object(an_integer: int)
|
||||
).to eq([widget.versions[1]])
|
||||
|
@ -204,10 +204,6 @@ module PaperTrail
|
|||
PaperTrail::Version.where_object(an_integer: 100)
|
||||
).to eq([widget.versions[2]])
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::YAML
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -266,7 +262,9 @@ module PaperTrail
|
|||
# no longer supported.
|
||||
if column_datatype_override
|
||||
context "JSON serializer" do
|
||||
before(:all) { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
||||
before do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
||||
end
|
||||
|
||||
it "locates versions according to their `object_changes` contents" do
|
||||
expect(
|
||||
|
@ -285,8 +283,6 @@ module PaperTrail
|
|||
widget.versions.where_object_changes(an_integer: 100, name: "foobar")
|
||||
).to eq(widget.versions[1..2])
|
||||
end
|
||||
|
||||
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
require "spec_helper"
|
||||
require "support/alt_db_init"
|
||||
|
||||
RSpec.describe PaperTrail::VersionConcern do
|
||||
before(:all) { require "support/alt_db_init" }
|
||||
|
||||
it "allows included class to have different connections" do
|
||||
expect(Foo::Version.connection).not_to eq(Bar::Version.connection)
|
||||
end
|
||||
|
|
|
@ -97,14 +97,6 @@ RSpec.describe PaperTrail do
|
|||
end
|
||||
|
||||
describe ".whodunnit" do
|
||||
context "when set globally" do
|
||||
before(:all) { described_class.whodunnit = "foobar" }
|
||||
|
||||
it "is set to `nil` by default" do
|
||||
expect(described_class.whodunnit).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "with block passed" do
|
||||
it "sets whodunnit only for the block passed" do
|
||||
described_class.whodunnit("foo") do
|
||||
|
@ -133,12 +125,4 @@ RSpec.describe PaperTrail do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".controller_info" do
|
||||
before(:all) { described_class.controller_info = { foo: "bar" } }
|
||||
|
||||
it "is set to an empty hash before each test" do
|
||||
expect(described_class.controller_info).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# This file copies the test database into locations for the `Foo` and `Bar` namespace,
|
||||
# then defines those namespaces, then establishes the sqlite3 connection for the namespaces
|
||||
# to simulate an application with multiple database connections.
|
||||
# This file copies the test database into locations for the `Foo` and `Bar`
|
||||
# namespace, then defines those namespaces, then establishes the sqlite3
|
||||
# connection for the namespaces to simulate an application with multiple
|
||||
# database connections.
|
||||
|
||||
# Load database yaml to use
|
||||
configs = YAML.load_file("#{Rails.root}/config/database.yml")
|
||||
|
|
Loading…
Reference in New Issue