RSpec/ContextWording
This commit is contained in:
parent
562f59d21a
commit
8f5a935c3a
|
@ -21,12 +21,6 @@ Metrics/CyclomaticComplexity:
|
|||
Metrics/PerceivedComplexity:
|
||||
Max: 9 # Goal: 7
|
||||
|
||||
# Offense count: 115
|
||||
# Configuration parameters: Prefixes.
|
||||
# Prefixes: when, with, without
|
||||
RSpec/ContextWording:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
||||
# Include: **/*_spec*rb*, **/spec/**/*
|
||||
|
|
|
@ -4,7 +4,7 @@ require "spec_helper"
|
|||
|
||||
RSpec.describe ArticlesController, type: :controller do
|
||||
describe "PaperTrail.request.enabled?" do
|
||||
context "PaperTrail.enabled? == true" do
|
||||
context "when PaperTrail.enabled? == true" do
|
||||
before { PaperTrail.enabled = true }
|
||||
|
||||
after { PaperTrail.enabled = false }
|
||||
|
@ -18,7 +18,7 @@ RSpec.describe ArticlesController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context "PaperTrail.enabled? == false" do
|
||||
context "when PaperTrail.enabled? == false" do
|
||||
it "returns false" do
|
||||
expect(PaperTrail.enabled?).to eq(false)
|
||||
post :create, params: { article: { title: "Doh", content: FFaker::Lorem.sentence } }
|
||||
|
|
|
@ -8,7 +8,7 @@ RSpec.describe WidgetsController, type: :controller, versioning: true do
|
|||
after { RequestStore.store[:paper_trail] = nil }
|
||||
|
||||
describe "#create" do
|
||||
context "PT enabled" do
|
||||
context "with PT enabled" do
|
||||
it "stores information like IP address in version" do
|
||||
post(:create, params: { widget: { name: "Flugel" } })
|
||||
widget = assigns(:widget)
|
||||
|
@ -29,7 +29,7 @@ RSpec.describe WidgetsController, type: :controller, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "PT disabled" do
|
||||
context "with PT disabled" do
|
||||
it "does not save a version, and metadata is not set" do
|
||||
request.env["HTTP_USER_AGENT"] = "Disable User-Agent"
|
||||
post :create, params: { widget: { name: "Flugel" } }
|
||||
|
|
|
@ -11,7 +11,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates an ignored column" do
|
||||
context "when updating an ignored column" do
|
||||
it "not change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(title: "My first title")
|
||||
|
@ -19,7 +19,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates an ignored column with truly Proc" do
|
||||
context "when updating an ignored column with truly Proc" do
|
||||
it "not change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(abstract: "ignore abstract")
|
||||
|
@ -27,7 +27,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates an ignored column with falsy Proc" do
|
||||
context "when updating an ignored column with falsy Proc" do
|
||||
it "change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(abstract: "do not ignore abstract!")
|
||||
|
@ -35,7 +35,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates an ignored column, ignored with truly Proc and a selected column" do
|
||||
context "when updating an ignored column, ignored with truly Proc and a selected column" do
|
||||
it "change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(
|
||||
|
@ -59,7 +59,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates an ignored column, ignored with falsy Proc and a selected column" do
|
||||
context "when updating an ignored column, ignored with falsy Proc and a selected column" do
|
||||
it "change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(
|
||||
|
@ -86,7 +86,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates a selected column" do
|
||||
context "when updating a selected column" do
|
||||
it "change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(content: "Some text here.")
|
||||
|
@ -95,7 +95,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates a non-ignored and non-selected column" do
|
||||
context "when updating a non-ignored and non-selected column" do
|
||||
it "not change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(abstract: "Other abstract")
|
||||
|
@ -103,7 +103,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates a skipped column" do
|
||||
context "when updating a skipped column" do
|
||||
it "not change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(file_upload: "Your data goes here")
|
||||
|
@ -111,7 +111,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "which updates a skipped column and a selected column" do
|
||||
context "when updating a skipped column and a selected column" do
|
||||
it "change the number of versions" do
|
||||
article = described_class.create
|
||||
article.update(
|
||||
|
@ -141,7 +141,7 @@ RSpec.describe Article, type: :model, versioning: true do
|
|||
).to(eq("content" => [nil, "Some text here."]))
|
||||
end
|
||||
|
||||
context "and when updated again" do
|
||||
context "when updated again" do
|
||||
it "have removed the skipped attributes when saving the previous version" do
|
||||
article = described_class.create
|
||||
article.update(
|
||||
|
|
|
@ -16,7 +16,7 @@ RSpec.describe Boolit, type: :model, versioning: true do
|
|||
expect { boolit.versions.last.reify.save! }.not_to raise_error
|
||||
end
|
||||
|
||||
context "Instance falls out of default scope" do
|
||||
context "when Instance falls out of default scope" do
|
||||
before { boolit.update!(scoped: false) }
|
||||
|
||||
it "is NOT scoped" do
|
||||
|
|
|
@ -29,7 +29,7 @@ module Family
|
|||
end
|
||||
|
||||
describe "#reify" do
|
||||
context "belongs_to" do
|
||||
context "with belongs_to" do
|
||||
it "uses the correct item_subtype" do
|
||||
parent = described_class.new(name: "Jermaine Jackson")
|
||||
parent.path_to_stardom = "Emulating Motown greats such as the Temptations and "\
|
||||
|
@ -51,7 +51,7 @@ module Family
|
|||
end
|
||||
end
|
||||
|
||||
context "has_many" do
|
||||
context "with has_many" do
|
||||
it "uses the correct item_type in queries" do
|
||||
parent = described_class.new(name: "Gomez Addams")
|
||||
parent.path_to_stardom = "Buy a Victorian house next to a sprawling graveyard, "\
|
||||
|
@ -70,7 +70,7 @@ module Family
|
|||
end
|
||||
end
|
||||
|
||||
context "has_many through" do
|
||||
context "with has_many through" do
|
||||
it "uses the correct item_type in queries" do
|
||||
parent = described_class.new(name: "Grandad")
|
||||
parent.path_to_stardom = "Took a suitcase and started running a market trading "\
|
||||
|
@ -90,7 +90,7 @@ module Family
|
|||
end
|
||||
end
|
||||
|
||||
context "has_one" do
|
||||
context "with has_one" do
|
||||
it "uses the correct item_type in queries" do
|
||||
parent = described_class.new(name: "Minnie Marx")
|
||||
parent.path_to_stardom = "Gain a relentless dedication to the stage by having a "\
|
||||
|
|
|
@ -12,13 +12,13 @@ RSpec.describe Gadget, type: :model do
|
|||
expect { gadget.update_attribute(:name, "Hammer") }.to(change { gadget.versions.size }.by(1))
|
||||
end
|
||||
|
||||
context "ignored via symbol" do
|
||||
context "when ignored via symbol" do
|
||||
it "doesn't generate a version" do
|
||||
expect { gadget.update_attribute(:brand, "Picard") }.not_to(change { gadget.versions.size })
|
||||
end
|
||||
end
|
||||
|
||||
context "ignored via Hash" do
|
||||
context "when ignored via Hash" do
|
||||
it "generates a version when the ignored attribute isn't true" do
|
||||
expect { gadget.update_attribute(:color, "Blue") }.to(change { gadget.versions.size }.by(1))
|
||||
expect(gadget.versions.last.changeset.keys).to eq %w[color updated_at]
|
||||
|
|
|
@ -23,14 +23,14 @@ if JsonVersion.table_exists?
|
|||
).to eq(0)
|
||||
end
|
||||
|
||||
context "invalid arguments" do
|
||||
context "with invalid arguments" do
|
||||
it "raises an error" do
|
||||
expect { described_class.where_object(:foo) }.to raise_error(ArgumentError)
|
||||
expect { described_class.where_object([]) }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context "valid arguments", versioning: true do
|
||||
context "with valid arguments", versioning: true do
|
||||
it "locates versions according to their `object` contents" do
|
||||
fruit = Fruit.create!(name: "apple")
|
||||
expect(fruit.versions.length).to eq(1)
|
||||
|
@ -65,14 +65,14 @@ if JsonVersion.table_exists?
|
|||
).to eq(0)
|
||||
end
|
||||
|
||||
context "invalid arguments" do
|
||||
context "with invalid arguments" do
|
||||
it "raises an error" do
|
||||
expect { described_class.where_object_changes(:foo) }.to raise_error(ArgumentError)
|
||||
expect { described_class.where_object_changes([]) }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context "valid arguments", versioning: true do
|
||||
context "with valid arguments", versioning: true do
|
||||
it "finds versions according to their `object_changes` contents" do
|
||||
fruit = Fruit.create!(name: "apple")
|
||||
fruit.update!(name: "banana", color: "red")
|
||||
|
|
|
@ -24,7 +24,7 @@ RSpec.describe Pet, type: :model, versioning: true do
|
|||
expect(person.reload.versions.length).to(eq(3))
|
||||
end
|
||||
|
||||
context "Older version entry present where item_type refers to the base_class" do
|
||||
context "when an older version entry's item_type refers to the base_class" do
|
||||
let(:cat) { Cat.create(name: "Garfield") } # Index 0
|
||||
let(:animal) { Animal.create } # Index 4
|
||||
|
||||
|
@ -83,7 +83,7 @@ RSpec.describe Pet, type: :model, versioning: true do
|
|||
|
||||
# After creating a bunch of records above, we change the inheritance_column
|
||||
# so that we can demonstrate passing hints to the migration generator.
|
||||
context "simulate a historical change to inheritance_column" do
|
||||
context "when there was a historical change to inheritance_column" do
|
||||
before do
|
||||
Animal.inheritance_column = "species_xyz"
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ RSpec.describe Post, type: :model, versioning: true do
|
|||
expect(PaperTrail::Version.count).to(eq(0))
|
||||
end
|
||||
|
||||
context "on the first version" do
|
||||
context "with the first version" do
|
||||
it "have the correct index" do
|
||||
post = Post.create
|
||||
version = post.versions.first
|
||||
|
|
|
@ -22,7 +22,7 @@ RSpec.describe PostWithStatus, type: :model do
|
|||
assert_equal %w[draft published], version.changeset["status"]
|
||||
end
|
||||
|
||||
context "storing enum object_changes" do
|
||||
context "when storing enum object_changes" do
|
||||
it "saves the enum value properly in versions object_changes" do
|
||||
post.published!
|
||||
post.archived!
|
||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe Skipper, type: :model, versioning: true do
|
|||
it { is_expected.to be_versioned }
|
||||
|
||||
describe "#update!", versioning: true do
|
||||
context "updating a skipped attribute" do
|
||||
context "when updating a skipped attribute" do
|
||||
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
|
||||
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
require "spec_helper"
|
||||
|
||||
RSpec.describe Translation, type: :model, versioning: true do
|
||||
context "for non-US translations" do
|
||||
context "with non-US translations" do
|
||||
it "not change the number of versions" do
|
||||
described_class.create!(headline: "Headline")
|
||||
expect(PaperTrail::Version.count).to(eq(0))
|
||||
end
|
||||
|
||||
context "after update" do
|
||||
context "when after update" do
|
||||
it "not change the number of versions" do
|
||||
translation = described_class.create!(headline: "Headline")
|
||||
translation.update(content: "Content")
|
||||
|
@ -17,7 +17,7 @@ RSpec.describe Translation, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "after destroy" do
|
||||
context "when after destroy" do
|
||||
it "not change the number of versions" do
|
||||
translation = described_class.create!(headline: "Headline")
|
||||
translation.destroy
|
||||
|
@ -26,8 +26,8 @@ RSpec.describe Translation, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "for US translations" do
|
||||
context "that are drafts" do
|
||||
context "with US translations" do
|
||||
context "with drafts" do
|
||||
it "creation does not change the number of versions" do
|
||||
translation = described_class.new(headline: "Headline")
|
||||
translation.language_code = "US"
|
||||
|
@ -46,7 +46,7 @@ RSpec.describe Translation, type: :model, versioning: true do
|
|||
end
|
||||
end
|
||||
|
||||
context "that are not drafts" do
|
||||
context "with non-drafts" do
|
||||
it "create changes the number of versions" do
|
||||
described_class.create!(headline: "Headline", language_code: "US")
|
||||
expect(PaperTrail::Version.count).to(eq(1))
|
||||
|
|
|
@ -8,7 +8,7 @@ module PaperTrail
|
|||
let(:widget) { Widget.create!(name: "Dashboard") }
|
||||
let(:value) { widget.versions.last.object_changes }
|
||||
|
||||
context "serializer is YAML" do
|
||||
context "when serializer is YAML" do
|
||||
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
||||
|
||||
it "store out as a plain hash" do
|
||||
|
@ -42,7 +42,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "serializer is JSON" do
|
||||
context "when serializer is JSON" do
|
||||
before do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
||||
end
|
||||
|
@ -58,13 +58,13 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe "#paper_trail_originator" do
|
||||
context "no previous versions" do
|
||||
context "with no previous versions" do
|
||||
it "returns nil" do
|
||||
expect(PaperTrail::Version.new.paper_trail_originator).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "has previous version", versioning: true do
|
||||
context "with previous version", versioning: true do
|
||||
it "returns name of whodunnit" do
|
||||
name = FFaker::Name.name
|
||||
widget = Widget.create!(name: FFaker::Name.name)
|
||||
|
@ -76,13 +76,13 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe "#previous" do
|
||||
context "no previous versions" do
|
||||
context "with no previous versions" do
|
||||
it "returns nil" do
|
||||
expect(PaperTrail::Version.new.previous).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "has previous version", versioning: true do
|
||||
context "with previous version", versioning: true do
|
||||
it "returns a PaperTrail::Version" do
|
||||
name = FFaker::Name.name
|
||||
widget = Widget.create!(name: FFaker::Name.name)
|
||||
|
@ -108,7 +108,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "changing the data type of database columns on the fly" do
|
||||
context "when 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 complexity. Is there a better
|
||||
# way? We already have a `json_versions` table in our tests, maybe we
|
||||
|
@ -242,7 +242,7 @@ module PaperTrail
|
|||
}.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
context "YAML serializer" do
|
||||
context "with YAML serializer" do
|
||||
it "locates versions according to their `object` contents" do
|
||||
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
|
||||
widget.update!(name: name, an_integer: int)
|
||||
|
@ -260,7 +260,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "JSON serializer" do
|
||||
context "with JSON serializer" do
|
||||
it "locates versions according to their `object` contents" do
|
||||
PaperTrail.serializer = PaperTrail::Serializers::JSON
|
||||
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
|
||||
|
|
|
@ -24,13 +24,13 @@ RSpec.describe Widget, type: :model do
|
|||
end
|
||||
|
||||
describe "versioning option" do
|
||||
context "enabled", versioning: true do
|
||||
context "when enabled", versioning: true do
|
||||
it "enables versioning" do
|
||||
expect(widget.versions.size).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "disabled (default)" do
|
||||
context "when disabled (default)" do
|
||||
it "does not enable versioning" do
|
||||
expect(widget.versions.size).to eq(0)
|
||||
end
|
||||
|
@ -206,7 +206,7 @@ RSpec.describe Widget, type: :model do
|
|||
end
|
||||
|
||||
describe "#version_at", versioning: true do
|
||||
context "Timestamp argument is AFTER object has been destroyed" do
|
||||
context "when Timestamp argument is AFTER object has been destroyed" do
|
||||
it "returns nil" do
|
||||
widget.update_attribute(:name, "foobar")
|
||||
widget.destroy
|
||||
|
@ -222,7 +222,7 @@ RSpec.describe Widget, type: :model do
|
|||
}.by(+1)
|
||||
end
|
||||
|
||||
context "request is disabled" do
|
||||
context "when request is disabled" do
|
||||
it "does not create a version" do
|
||||
count = widget.versions.count
|
||||
PaperTrail.request(enabled: false) do
|
||||
|
|
|
@ -23,7 +23,7 @@ module PaperTrail
|
|||
animals.each { |animal| expect(animal.versions.size).to(eq(3)) }
|
||||
end
|
||||
|
||||
context "no options provided" do
|
||||
context "with no options provided" do
|
||||
it "removes extra versions for each item" do
|
||||
PaperTrail.clean_versions!
|
||||
expect(PaperTrail::Version.count).to(eq(3))
|
||||
|
@ -38,7 +38,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "keeping 2" do
|
||||
context "when keeping 2" do
|
||||
it "keeps two records, instead of the usual one" do
|
||||
PaperTrail.clean_versions!(keeping: 2)
|
||||
expect(PaperTrail::Version.all.count).to(eq(6))
|
||||
|
@ -67,7 +67,7 @@ module PaperTrail
|
|||
end
|
||||
|
||||
context "with the :item_id option" do
|
||||
context "single ID received" do
|
||||
context "when a single ID is received" do
|
||||
it "only deletes the versions for the Item with that ID" do
|
||||
PaperTrail.clean_versions!(item_id: animal.id)
|
||||
expect(animal.versions.size).to(eq(1))
|
||||
|
@ -75,7 +75,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "collection of IDs received" do
|
||||
context "when a collection of IDs is received" do
|
||||
it "only deletes versions for the Item(s) with those IDs" do
|
||||
PaperTrail.clean_versions!(item_id: [animal.id, dog.id])
|
||||
expect(animal.versions.size).to(eq(1))
|
||||
|
@ -85,8 +85,8 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "options combinations" do
|
||||
context ":date" do
|
||||
context "with options combinations" do
|
||||
context "with :date" do
|
||||
before do
|
||||
[animal, dog].each do |animal|
|
||||
animal.versions.each do |ver|
|
||||
|
@ -105,7 +105,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "and :keeping" do
|
||||
context "with :keeping" do
|
||||
it "restrict cleaning properly" do
|
||||
date = animal.versions.first.created_at.to_date
|
||||
PaperTrail.clean_versions!(date: date, keeping: 2)
|
||||
|
@ -118,7 +118,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "and :item_id" do
|
||||
context "with :item_id" do
|
||||
it "restrict cleaning properly" do
|
||||
date = animal.versions.first.created_at.to_date
|
||||
PaperTrail.clean_versions!(date: date, item_id: dog.id)
|
||||
|
@ -129,7 +129,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context ", :item_id, and :keeping" do
|
||||
context "with :item_id, and :keeping" do
|
||||
it "restrict cleaning properly" do
|
||||
date = animal.versions.first.created_at.to_date
|
||||
PaperTrail.clean_versions!(date: date, item_id: dog.id, keeping: 2)
|
||||
|
@ -141,7 +141,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context ":keeping and :item_id" do
|
||||
context "with :keeping and :item_id" do
|
||||
it "restrict cleaning properly" do
|
||||
PaperTrail.clean_versions!(keeping: 2, item_id: animal.id)
|
||||
expect(animal.versions.size).to(eq(2))
|
||||
|
|
|
@ -6,7 +6,7 @@ module PaperTrail
|
|||
module Events
|
||||
::RSpec.describe Base do
|
||||
describe "#changed_notably?", versioning: true do
|
||||
context "new record" do
|
||||
context "with a new record" do
|
||||
it "returns true" do
|
||||
g = Gadget.new(created_at: Time.current)
|
||||
event = PaperTrail::Events::Base.new(g, false)
|
||||
|
@ -14,7 +14,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "persisted record without update timestamps" do
|
||||
context "with a persisted record without update timestamps" do
|
||||
it "only acknowledges non-ignored attrs" do
|
||||
gadget = Gadget.create!(created_at: Time.current)
|
||||
gadget.name = "Wrench"
|
||||
|
@ -30,7 +30,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "persisted record with update timestamps" do
|
||||
context "with a persisted record with update timestamps" do
|
||||
it "only acknowledges non-ignored attrs" do
|
||||
gadget = Gadget.create!(created_at: Time.current)
|
||||
gadget.name = "Wrench"
|
||||
|
|
|
@ -16,7 +16,7 @@ module PaperTrail
|
|||
expect(data[:item_subtype]).to eq("Family::CelebrityFamily")
|
||||
end
|
||||
|
||||
context "skipper" do
|
||||
context "with skipper" do
|
||||
let(:skipper) { Skipper.create!(another_timestamp: Time.current) }
|
||||
let(:data) { PaperTrail::Events::Destroy.new(skipper, false).data }
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module PaperTrail
|
|||
module Events
|
||||
::RSpec.describe Update do
|
||||
describe "#data", versioning: true do
|
||||
context "is_touch false" do
|
||||
context "when is_touch false" do
|
||||
it "object_changes is present" do
|
||||
carter = Family::CelebrityFamily.create(
|
||||
name: "Carter",
|
||||
|
@ -25,7 +25,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "is_touch true" do
|
||||
context "when is_touch true" do
|
||||
it "object_changes is nil" do
|
||||
carter = Family::CelebrityFamily.create(
|
||||
name: "Carter",
|
||||
|
|
|
@ -18,7 +18,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
expect(changeset["updated_at"][1].to_i).to eq(widget.updated_at.to_i)
|
||||
end
|
||||
|
||||
context "custom object_changes_adapter" do
|
||||
context "with custom object_changes_adapter" do
|
||||
after do
|
||||
PaperTrail.config.object_changes_adapter = nil
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "a new record" do
|
||||
context "with a new record" do
|
||||
it "not have any previous versions" do
|
||||
expect(Widget.new.versions).to(eq([]))
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "a persisted record" do
|
||||
context "with a persisted record" do
|
||||
it "have one previous version" do
|
||||
widget = Widget.create(name: "Henry", created_at: (Time.current - 1.day))
|
||||
expect(widget.versions.length).to(eq(1))
|
||||
|
@ -83,7 +83,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
expect(widget.versions.first.created_at.to_i).to(eq(widget.updated_at.to_i))
|
||||
end
|
||||
|
||||
context "and then updated without any changes" do
|
||||
context "when updated without any changes" do
|
||||
it "to have two previous versions" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.touch
|
||||
|
@ -91,7 +91,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "and then updated with changes" do
|
||||
context "when updated with changes" do
|
||||
it "have three previous versions" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.update(name: "Harry")
|
||||
|
@ -148,7 +148,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "updated, and has one associated object" do
|
||||
context "when updated, and has one associated object" do
|
||||
it "not copy the has_one association by default when reifying" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.update(name: "Harry")
|
||||
|
@ -159,7 +159,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "updated, and has many associated objects" do
|
||||
context "when updated, and has many associated objects" do
|
||||
it "copy the has_many associations when reifying" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.update(name: "Harry")
|
||||
|
@ -173,7 +173,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "updated, and has many associated polymorphic objects" do
|
||||
context "when updated, and has many associated polymorphic objects" do
|
||||
it "copy the has_many associations when reifying" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.update(name: "Harry")
|
||||
|
@ -187,7 +187,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "updated, polymorphic objects by themselves" do
|
||||
context "when updated, polymorphic objects by themselves" do
|
||||
it "not fail with a nil pointer on the polymorphic association" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.update(name: "Harry")
|
||||
|
@ -196,7 +196,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "updated, and then destroyed" do
|
||||
context "when updated, and then destroyed" do
|
||||
it "record the correct event" do
|
||||
widget = Widget.create(name: "Henry")
|
||||
widget.update(name: "Harry")
|
||||
|
@ -279,7 +279,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "a record's papertrail" do
|
||||
context "with a record's papertrail" do
|
||||
let!(:d0) { Date.new(2009, 5, 29) }
|
||||
let!(:t0) { Time.current }
|
||||
let(:previous_widget) { widget.versions.last.reify }
|
||||
|
@ -348,7 +348,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
expect(previous_widget.a_boolean).to(be_truthy)
|
||||
end
|
||||
|
||||
context "after a column is removed from the record's schema" do
|
||||
context "when a column has been removed from the record's schema" do
|
||||
let(:last_version) { widget.versions.last }
|
||||
|
||||
it "reify previous version" do
|
||||
|
@ -371,7 +371,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "A record" do
|
||||
context "with a record" do
|
||||
context "with PaperTrail globally disabled, when updated" do
|
||||
after { PaperTrail.enabled = true }
|
||||
|
||||
|
@ -409,7 +409,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "A papertrail with somebody making changes" do
|
||||
context "with somebody making changes" do
|
||||
context "when a record is created" do
|
||||
it "tracks who made the change" do
|
||||
widget = Widget.new(name: "Fidget")
|
||||
|
@ -469,7 +469,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
expect { wotsit.update!(name: "name2") }.not_to(raise_error)
|
||||
end
|
||||
|
||||
context "A subclass" do
|
||||
context "with a subclass" do
|
||||
let(:foo) { FooWidget.create }
|
||||
|
||||
before do
|
||||
|
@ -498,8 +498,8 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "An item with versions" do
|
||||
context "which were created over time" do
|
||||
context "with an item with versions" do
|
||||
context "when the versions were created over time" do
|
||||
let(:widget) { Widget.create(name: "Widget") }
|
||||
let(:t0) { 2.days.ago }
|
||||
let(:t1) { 1.day.ago }
|
||||
|
@ -579,7 +579,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "on the first version" do
|
||||
context "with the first version" do
|
||||
let(:widget) { Widget.create(name: "Widget") }
|
||||
let(:version) { widget.versions.last }
|
||||
|
||||
|
@ -602,7 +602,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "on the last version" do
|
||||
context "with the last version" do
|
||||
let(:widget) { Widget.create(name: "Widget") }
|
||||
let(:version) { widget.versions.last }
|
||||
|
||||
|
@ -625,11 +625,11 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "An item" do
|
||||
context "with an item" do
|
||||
let(:article) { Article.new(title: initial_title) }
|
||||
let(:initial_title) { "Foobar" }
|
||||
|
||||
context "which is created" do
|
||||
context "when it is created" do
|
||||
before { article.save }
|
||||
|
||||
it "store fixed meta data" do
|
||||
|
@ -653,7 +653,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "created, then updated" do
|
||||
context "when it is created, then updated" do
|
||||
before do
|
||||
article.save
|
||||
article.update!(content: "Better text.", title: "Rhubarb")
|
||||
|
@ -676,7 +676,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "created, then destroyed" do
|
||||
context "when it is created, then destroyed" do
|
||||
before do
|
||||
article.save
|
||||
article.destroy
|
||||
|
@ -700,7 +700,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "A reified item" do
|
||||
context "with a reified item" do
|
||||
it "know which version it came from, and return its previous self" do
|
||||
widget = Widget.create(name: "Bob")
|
||||
%w[Tom Dick Jane].each do |name|
|
||||
|
@ -714,7 +714,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
|
||||
describe "#next_version" do
|
||||
context "a reified item" do
|
||||
context "with a reified item" do
|
||||
it "returns the object (not a Version) as it became next" do
|
||||
widget = Widget.create(name: "Bob")
|
||||
%w[Tom Dick Jane].each do |name|
|
||||
|
@ -727,7 +727,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "a non-reified item" do
|
||||
context "with a non-reified item" do
|
||||
it "always returns nil because cannot ever have a next version" do
|
||||
widget = Widget.new
|
||||
expect(widget.paper_trail.next_version).to(be_nil)
|
||||
|
@ -741,7 +741,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
|
||||
describe "#previous_version" do
|
||||
context "a reified item" do
|
||||
context "with a reified item" do
|
||||
it "returns the object (not a Version) as it was most recently" do
|
||||
widget = Widget.create(name: "Bob")
|
||||
%w[Tom Dick Jane].each do |name|
|
||||
|
@ -754,7 +754,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "a non-reified item" do
|
||||
context "with a non-reified item" do
|
||||
it "returns the object (not a Version) as it was most recently" do
|
||||
widget = Widget.new
|
||||
expect(widget.paper_trail.previous_version).to(be_nil)
|
||||
|
@ -767,7 +767,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context ":has_many :through" do
|
||||
context "with :has_many :through" do
|
||||
it "store version on source <<" do
|
||||
book = Book.create(title: "War and Peace")
|
||||
dostoyevsky = Person.create(name: "Dostoyevsky")
|
||||
|
@ -815,7 +815,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "the default accessor, length=, is overwritten" do
|
||||
context "when the default accessor, length=, is overwritten" do
|
||||
it "returns overwritten value on reified instance" do
|
||||
song = Song.create(length: 4)
|
||||
song.update(length: 5)
|
||||
|
@ -824,7 +824,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "song name is a virtual attribute (no such db column)" do
|
||||
context "when song name is a virtual attribute (no such db column)" do
|
||||
it "returns overwritten virtual attribute on the reified instance" do
|
||||
song = Song.create(length: 4)
|
||||
song.update(length: 5)
|
||||
|
@ -836,7 +836,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "An unsaved record" do
|
||||
context "with an unsaved record" do
|
||||
it "not have a version created on destroy" do
|
||||
widget = Widget.new
|
||||
widget.destroy
|
||||
|
@ -844,7 +844,7 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "Memory allocation of" do
|
||||
context "when measuring the memory allocation of" do
|
||||
let(:widget) do
|
||||
Widget.new(
|
||||
name: "Warble",
|
||||
|
|
|
@ -103,8 +103,8 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe ".with" do
|
||||
context "block given" do
|
||||
context "all allowed options" do
|
||||
context "with a block given" do
|
||||
context "with all allowed options" do
|
||||
it "sets options only for the block passed" do
|
||||
described_class.whodunnit = "some_whodunnit"
|
||||
described_class.enabled_for_model(Widget, true)
|
||||
|
@ -132,7 +132,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "some invalid options" do
|
||||
context "with some invalid options" do
|
||||
it "raises an invalid option error" do
|
||||
subject = proc do
|
||||
described_class.with(whodunnit: "blah", invalid_option: "foo") do
|
||||
|
@ -146,7 +146,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "all invalid options" do
|
||||
context "with all invalid options" do
|
||||
it "raises an invalid option error" do
|
||||
subject = proc do
|
||||
described_class.with(invalid_option: "foo", other_invalid_option: "blah") do
|
||||
|
|
|
@ -4,7 +4,7 @@ require "spec_helper"
|
|||
require "support/custom_json_serializer"
|
||||
|
||||
RSpec.describe(PaperTrail, versioning: true) do
|
||||
context "YAML serializer" do
|
||||
context "with YAML serializer" do
|
||||
it "saves the expected YAML in the object column" do
|
||||
customer = Customer.create(name: "Some text.")
|
||||
original_attributes = PaperTrail::Events::Base.
|
||||
|
@ -19,7 +19,7 @@ RSpec.describe(PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "JSON Serializer" do
|
||||
context "with JSON Serializer" do
|
||||
before do
|
||||
PaperTrail.configure do |config|
|
||||
config.serializer = PaperTrail::Serializers::JSON
|
||||
|
@ -55,7 +55,7 @@ RSpec.describe(PaperTrail, versioning: true) do
|
|||
end
|
||||
end
|
||||
|
||||
context "Custom Serializer" do
|
||||
context "with Custom Serializer" do
|
||||
before do
|
||||
PaperTrail.configure { |config| config.serializer = CustomJsonSerializer }
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe ".subsequent" do
|
||||
context "given a timestamp" do
|
||||
context "with a timestamp" do
|
||||
it "returns all versions that were created after the timestamp" do
|
||||
animal = Animal.create
|
||||
2.times do
|
||||
|
@ -54,7 +54,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "given a Version" do
|
||||
context "with a Version" do
|
||||
it "grab the timestamp from the version and use that as the value" do
|
||||
animal = Animal.create
|
||||
2.times do
|
||||
|
@ -68,7 +68,7 @@ module PaperTrail
|
|||
end
|
||||
|
||||
describe ".preceding" do
|
||||
context "given a timestamp" do
|
||||
context "with a timestamp" do
|
||||
it "returns all versions that were created before the timestamp" do
|
||||
animal = Animal.create
|
||||
2.times do
|
||||
|
@ -82,7 +82,7 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
context "given a Version" do
|
||||
context "with a Version" do
|
||||
it "grab the timestamp from the version and use that as the value" do
|
||||
animal = Animal.create
|
||||
2.times do
|
||||
|
|
|
@ -50,7 +50,7 @@ RSpec.describe PaperTrail do
|
|||
end
|
||||
end
|
||||
|
||||
context "default" do
|
||||
context "when default" do
|
||||
it "has versioning off by default" do
|
||||
expect(described_class).not_to be_enabled
|
||||
end
|
||||
|
@ -63,7 +63,7 @@ RSpec.describe PaperTrail do
|
|||
expect(described_class).not_to be_enabled
|
||||
end
|
||||
|
||||
context "error within `with_versioning` block" do
|
||||
context "when error within `with_versioning` block" do
|
||||
it "reverts the value of `PaperTrail.enabled?` to its previous state" do
|
||||
expect(described_class).not_to be_enabled
|
||||
expect { with_versioning { raise } }.to raise_error(RuntimeError)
|
||||
|
@ -72,7 +72,7 @@ RSpec.describe PaperTrail do
|
|||
end
|
||||
end
|
||||
|
||||
context "`versioning: true`", versioning: true do
|
||||
context "with `versioning: true`", versioning: true do
|
||||
it "has versioning on by default" do
|
||||
expect(described_class).to be_enabled
|
||||
end
|
||||
|
@ -86,7 +86,7 @@ RSpec.describe PaperTrail do
|
|||
end
|
||||
end
|
||||
|
||||
context "`with_versioning` block at class level" do
|
||||
context "with `with_versioning` block at class level" do
|
||||
it { expect(described_class).not_to be_enabled }
|
||||
|
||||
with_versioning do
|
||||
|
|
|
@ -5,7 +5,7 @@ require "spec_helper"
|
|||
RSpec.describe "Articles management", type: :request, order: :defined do
|
||||
let(:valid_params) { { article: { title: "Doh", content: FFaker::Lorem.sentence } } }
|
||||
|
||||
context "versioning disabled" do
|
||||
context "with versioning disabled" do
|
||||
specify { expect(PaperTrail).not_to be_enabled }
|
||||
|
||||
it "does not create a version" do
|
||||
|
@ -19,7 +19,7 @@ RSpec.describe "Articles management", type: :request, order: :defined do
|
|||
with_versioning do
|
||||
let(:article) { Article.last }
|
||||
|
||||
context "`current_user` method returns a `String`" do
|
||||
context "when `current_user` method returns a `String`" do
|
||||
it "sets that value as the `whodunnit`" do
|
||||
expect {
|
||||
post articles_path, params: valid_params
|
||||
|
|
Loading…
Reference in New Issue