mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Lint: Fix RSpec/NamedSubject
This commit is contained in:
parent
5a8037b5e5
commit
515f0958a6
7 changed files with 54 additions and 62 deletions
|
@ -30,9 +30,6 @@ RSpec/InstanceVariable:
|
|||
- spec/paper_trail/associations_spec.rb
|
||||
- spec/paper_trail/model_spec.rb
|
||||
|
||||
RSpec/NamedSubject:
|
||||
Enabled: false
|
||||
|
||||
RSpec/NestedGroups:
|
||||
Exclude:
|
||||
- spec/paper_trail/associations_spec.rb
|
||||
|
|
|
@ -2,39 +2,39 @@ require "spec_helper"
|
|||
require "support/custom_json_serializer"
|
||||
|
||||
RSpec.describe Boolit, type: :model, versioning: true do
|
||||
subject { Boolit.create! }
|
||||
let(:boolit) { Boolit.create! }
|
||||
|
||||
before { subject.update_attributes!(name: FFaker::Name.name) }
|
||||
before { boolit.update_attributes!(name: FFaker::Name.name) }
|
||||
|
||||
it "has two versions" do
|
||||
expect(subject.versions.size).to eq(2)
|
||||
expect(boolit.versions.size).to eq(2)
|
||||
end
|
||||
|
||||
it "can be reified and persisted" do
|
||||
expect { subject.versions.last.reify.save! }.not_to raise_error
|
||||
expect { boolit.versions.last.reify.save! }.not_to raise_error
|
||||
end
|
||||
|
||||
context "Instance falls out of default scope" do
|
||||
before { subject.update_attributes!(scoped: false) }
|
||||
before { boolit.update_attributes!(scoped: false) }
|
||||
|
||||
it "is NOT scoped" do
|
||||
expect(Boolit.first).to be_nil
|
||||
end
|
||||
|
||||
it "still can be reified and persisted" do
|
||||
expect { subject.paper_trail.previous_version.save! }.not_to raise_error
|
||||
expect { boolit.paper_trail.previous_version.save! }.not_to raise_error
|
||||
end
|
||||
|
||||
context "with `nil` attributes on the live instance" do
|
||||
before do
|
||||
PaperTrail.serializer = CustomJsonSerializer
|
||||
subject.update_attributes!(name: nil)
|
||||
subject.update_attributes!(name: FFaker::Name.name)
|
||||
boolit.update_attributes!(name: nil)
|
||||
boolit.update_attributes!(name: FFaker::Name.name)
|
||||
end
|
||||
after { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
||||
|
||||
it "does not overwrite that attribute during the reification process" do
|
||||
expect(subject.paper_trail.previous_version.name).to be_nil
|
||||
expect(boolit.paper_trail.previous_version.name).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,31 +32,31 @@ RSpec.describe Gadget, type: :model do
|
|||
|
||||
context "persisted record without update timestamps" do
|
||||
it "only acknowledges non-ignored attrs" do
|
||||
subject = Gadget.create!(created_at: Time.now)
|
||||
subject.name = "Wrench"
|
||||
expect(subject.paper_trail.changed_notably?).to be true
|
||||
gadget = Gadget.create!(created_at: Time.now)
|
||||
gadget.name = "Wrench"
|
||||
expect(gadget.paper_trail.changed_notably?).to be true
|
||||
end
|
||||
|
||||
it "does not acknowledge ignored attr (brand)" do
|
||||
subject = Gadget.create!(created_at: Time.now)
|
||||
subject.brand = "Acme"
|
||||
expect(subject.paper_trail.changed_notably?).to be false
|
||||
gadget = Gadget.create!(created_at: Time.now)
|
||||
gadget.brand = "Acme"
|
||||
expect(gadget.paper_trail.changed_notably?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context "persisted record with update timestamps" do
|
||||
it "only acknowledges non-ignored attrs" do
|
||||
subject = Gadget.create!(created_at: Time.now)
|
||||
subject.name = "Wrench"
|
||||
subject.updated_at = Time.now
|
||||
expect(subject.paper_trail.changed_notably?).to be true
|
||||
gadget = Gadget.create!(created_at: Time.now)
|
||||
gadget.name = "Wrench"
|
||||
gadget.updated_at = Time.now
|
||||
expect(gadget.paper_trail.changed_notably?).to be true
|
||||
end
|
||||
|
||||
it "does not acknowledge ignored attrs and timestamps only" do
|
||||
subject = Gadget.create!(created_at: Time.now)
|
||||
subject.brand = "Acme"
|
||||
subject.updated_at = Time.now
|
||||
expect(subject.paper_trail.changed_notably?).to be false
|
||||
gadget = Gadget.create!(created_at: Time.now)
|
||||
gadget.brand = "Acme"
|
||||
gadget.updated_at = Time.now
|
||||
expect(gadget.paper_trail.changed_notably?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,12 +21,11 @@ RSpec.describe PostWithStatus, type: :model do
|
|||
end
|
||||
|
||||
context "storing enum object_changes" do
|
||||
subject { post.versions.last }
|
||||
|
||||
it "saves the enum value properly in versions object_changes" do
|
||||
post.published!
|
||||
post.archived!
|
||||
expect(subject.changeset["status"]).to eql %w[published archived]
|
||||
post_version = post.versions.last
|
||||
expect(post_version.changeset["status"]).to eql(%w[published archived])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -62,12 +62,12 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe "#originator" do
|
||||
it "sets the invoke `paper_trail_originator`" do
|
||||
it "delegates to paper_trail_originator" do
|
||||
allow(ActiveSupport::Deprecation).to receive(:warn)
|
||||
subject = PaperTrail::Version.new
|
||||
allow(subject).to receive(:paper_trail_originator)
|
||||
subject.originator
|
||||
expect(subject).to have_received(:paper_trail_originator)
|
||||
version = PaperTrail::Version.new
|
||||
allow(version).to receive(:paper_trail_originator)
|
||||
version.originator
|
||||
expect(version).to have_received(:paper_trail_originator)
|
||||
end
|
||||
|
||||
it "displays a deprecation warning" do
|
||||
|
@ -81,19 +81,19 @@ module PaperTrail
|
|||
describe "#terminator" do
|
||||
it "is an alias for the `whodunnit` attribute" do
|
||||
attributes = { whodunnit: FFaker::Name.first_name }
|
||||
subject = PaperTrail::Version.new(attributes)
|
||||
expect(subject.terminator).to eq(attributes[:whodunnit])
|
||||
version = PaperTrail::Version.new(attributes)
|
||||
expect(version.terminator).to eq(attributes[:whodunnit])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#version_author" do
|
||||
it "is an alias for the `terminator` method" do
|
||||
subject = PaperTrail::Version.new
|
||||
expect(subject.method(:version_author)).to eq(subject.method(:terminator))
|
||||
version = PaperTrail::Version.new
|
||||
expect(version.method(:version_author)).to eq(version.method(:terminator))
|
||||
end
|
||||
end
|
||||
|
||||
describe "Methods" do
|
||||
context "changing the data type of database columns on the fly" do
|
||||
# TODO: Changing the data type of these database columns in the middle
|
||||
# of the test suite adds a fair amount of complication. Is there a better
|
||||
# way? We already have a `json_versions` table in our tests, maybe we
|
||||
|
|
|
@ -52,14 +52,12 @@ RSpec.describe Widget, type: :model do
|
|||
|
||||
describe "Callbacks", versioning: true do
|
||||
describe "before_save" do
|
||||
before { widget.update_attributes!(name: "Foobar") }
|
||||
|
||||
subject { widget.versions.last.reify }
|
||||
|
||||
it "resets value for timestamp attrs for update so that value gets updated properly" do
|
||||
widget.update_attributes!(name: "Foobar")
|
||||
w = widget.versions.last.reify
|
||||
# Travel 1 second because MySQL lacks sub-second resolution
|
||||
Timecop.travel(1) do
|
||||
expect { subject.save! }.to change(subject, :updated_at)
|
||||
expect { w.save! }.to change(w, :updated_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -73,15 +71,15 @@ RSpec.describe Widget, type: :model do
|
|||
end
|
||||
|
||||
describe "after_update" do
|
||||
before { widget.update_attributes!(name: "Foobar", updated_at: Time.now + 1.week) }
|
||||
|
||||
subject { widget.versions.last.reify }
|
||||
|
||||
it { expect(subject.paper_trail).not_to be_live }
|
||||
before do
|
||||
widget.update_attributes!(name: "Foobar", updated_at: Time.now + 1.week)
|
||||
end
|
||||
|
||||
it "clears the `versions_association_name` virtual attribute" do
|
||||
subject.save!
|
||||
expect(subject.paper_trail).to be_live
|
||||
w = widget.versions.last.reify
|
||||
expect(w.paper_trail).not_to be_live
|
||||
w.save!
|
||||
expect(w.paper_trail).to be_live
|
||||
end
|
||||
|
||||
it "corresponding version uses the widget updated_at" do
|
||||
|
|
|
@ -2,26 +2,24 @@ require "spec_helper"
|
|||
|
||||
RSpec.describe PaperTrail do
|
||||
describe "#config", versioning: true do
|
||||
it { is_expected.to respond_to(:config) }
|
||||
|
||||
it "allows for config values to be set" do
|
||||
expect(subject.config.enabled).to eq(true)
|
||||
subject.config.enabled = false
|
||||
expect(subject.config.enabled).to eq(false)
|
||||
expect(described_class.config.enabled).to eq(true)
|
||||
described_class.config.enabled = false
|
||||
expect(described_class.config.enabled).to eq(false)
|
||||
end
|
||||
|
||||
it "accepts blocks and yield the config instance" do
|
||||
expect(subject.config.enabled).to eq(true)
|
||||
subject.config { |c| c.enabled = false }
|
||||
expect(subject.config.enabled).to eq(false)
|
||||
expect(described_class.config.enabled).to eq(true)
|
||||
described_class.config { |c| c.enabled = false }
|
||||
expect(described_class.config.enabled).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#configure" do
|
||||
it { is_expected.to respond_to(:configure) }
|
||||
|
||||
it "is an alias for the `config` method" do
|
||||
expect(subject.method(:configure)).to eq(subject.method(:config))
|
||||
expect(described_class.method(:configure)).to eq(
|
||||
described_class.method(:config)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue