From 8f5a935c3ac6b87a3c3f131fef7e7b7e24f3bcc0 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 29 Aug 2021 22:22:39 -0400 Subject: [PATCH] RSpec/ContextWording --- .rubocop_todo.yml | 6 -- spec/controllers/articles_controller_spec.rb | 4 +- spec/controllers/widgets_controller_spec.rb | 4 +- spec/models/article_spec.rb | 20 +++--- spec/models/boolit_spec.rb | 2 +- spec/models/family/celebrity_family_spec.rb | 8 +-- spec/models/gadget_spec.rb | 4 +- spec/models/json_version_spec.rb | 8 +-- spec/models/pet_spec.rb | 4 +- spec/models/post_spec.rb | 2 +- spec/models/post_with_status_spec.rb | 2 +- spec/models/skipper_spec.rb | 2 +- spec/models/translation_spec.rb | 12 ++-- spec/models/version_spec.rb | 18 +++--- spec/models/widget_spec.rb | 8 +-- spec/paper_trail/cleaner_spec.rb | 20 +++--- spec/paper_trail/events/base_spec.rb | 6 +- spec/paper_trail/events/destroy_spec.rb | 2 +- spec/paper_trail/events/update_spec.rb | 4 +- spec/paper_trail/model_spec.rb | 66 ++++++++++---------- spec/paper_trail/request_spec.rb | 8 +-- spec/paper_trail/serializer_spec.rb | 6 +- spec/paper_trail/version_spec.rb | 8 +-- spec/paper_trail_spec.rb | 8 +-- spec/requests/articles_spec.rb | 4 +- 25 files changed, 115 insertions(+), 121 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c119bade..c61ef94e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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/**/* diff --git a/spec/controllers/articles_controller_spec.rb b/spec/controllers/articles_controller_spec.rb index dee8c0d0..15d11c35 100644 --- a/spec/controllers/articles_controller_spec.rb +++ b/spec/controllers/articles_controller_spec.rb @@ -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 } } diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index 598dca8a..ae24ff42 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -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" } } diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 8526332e..57931db3 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -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( diff --git a/spec/models/boolit_spec.rb b/spec/models/boolit_spec.rb index 58a45475..6e648906 100644 --- a/spec/models/boolit_spec.rb +++ b/spec/models/boolit_spec.rb @@ -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 diff --git a/spec/models/family/celebrity_family_spec.rb b/spec/models/family/celebrity_family_spec.rb index b55e70b1..f7c70aa1 100644 --- a/spec/models/family/celebrity_family_spec.rb +++ b/spec/models/family/celebrity_family_spec.rb @@ -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 "\ diff --git a/spec/models/gadget_spec.rb b/spec/models/gadget_spec.rb index 531f116b..f71817a7 100644 --- a/spec/models/gadget_spec.rb +++ b/spec/models/gadget_spec.rb @@ -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] diff --git a/spec/models/json_version_spec.rb b/spec/models/json_version_spec.rb index d1d7253a..b4649b21 100644 --- a/spec/models/json_version_spec.rb +++ b/spec/models/json_version_spec.rb @@ -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") diff --git a/spec/models/pet_spec.rb b/spec/models/pet_spec.rb index 6a991a05..68362a7d 100644 --- a/spec/models/pet_spec.rb +++ b/spec/models/pet_spec.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 08bb5e2e..57cec579 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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 diff --git a/spec/models/post_with_status_spec.rb b/spec/models/post_with_status_spec.rb index 3916b73f..cd11f051 100644 --- a/spec/models/post_with_status_spec.rb +++ b/spec/models/post_with_status_spec.rb @@ -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! diff --git a/spec/models/skipper_spec.rb b/spec/models/skipper_spec.rb index c6945846..29e2f363 100644 --- a/spec/models/skipper_spec.rb +++ b/spec/models/skipper_spec.rb @@ -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) } diff --git a/spec/models/translation_spec.rb b/spec/models/translation_spec.rb index d00947b0..51413d5d 100644 --- a/spec/models/translation_spec.rb +++ b/spec/models/translation_spec.rb @@ -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)) diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb index c69556ba..9ecfdbce 100644 --- a/spec/models/version_spec.rb +++ b/spec/models/version_spec.rb @@ -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 diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index 409e7037..f8d6db31 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -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 diff --git a/spec/paper_trail/cleaner_spec.rb b/spec/paper_trail/cleaner_spec.rb index 78755bf9..33d954f4 100644 --- a/spec/paper_trail/cleaner_spec.rb +++ b/spec/paper_trail/cleaner_spec.rb @@ -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)) diff --git a/spec/paper_trail/events/base_spec.rb b/spec/paper_trail/events/base_spec.rb index 90b2e263..da7e1e62 100644 --- a/spec/paper_trail/events/base_spec.rb +++ b/spec/paper_trail/events/base_spec.rb @@ -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" diff --git a/spec/paper_trail/events/destroy_spec.rb b/spec/paper_trail/events/destroy_spec.rb index bfa91f3d..c63accdd 100644 --- a/spec/paper_trail/events/destroy_spec.rb +++ b/spec/paper_trail/events/destroy_spec.rb @@ -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 } diff --git a/spec/paper_trail/events/update_spec.rb b/spec/paper_trail/events/update_spec.rb index d16564bc..e4133ba4 100644 --- a/spec/paper_trail/events/update_spec.rb +++ b/spec/paper_trail/events/update_spec.rb @@ -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", diff --git a/spec/paper_trail/model_spec.rb b/spec/paper_trail/model_spec.rb index 1fec0823..4e53e12d 100644 --- a/spec/paper_trail/model_spec.rb +++ b/spec/paper_trail/model_spec.rb @@ -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", diff --git a/spec/paper_trail/request_spec.rb b/spec/paper_trail/request_spec.rb index 0a5db71d..5e2dae54 100644 --- a/spec/paper_trail/request_spec.rb +++ b/spec/paper_trail/request_spec.rb @@ -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 diff --git a/spec/paper_trail/serializer_spec.rb b/spec/paper_trail/serializer_spec.rb index 3ee71366..f35de11f 100644 --- a/spec/paper_trail/serializer_spec.rb +++ b/spec/paper_trail/serializer_spec.rb @@ -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 diff --git a/spec/paper_trail/version_spec.rb b/spec/paper_trail/version_spec.rb index e29008bb..749a144c 100644 --- a/spec/paper_trail/version_spec.rb +++ b/spec/paper_trail/version_spec.rb @@ -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 diff --git a/spec/paper_trail_spec.rb b/spec/paper_trail_spec.rb index 68d71f1e..5ff6d9aa 100644 --- a/spec/paper_trail_spec.rb +++ b/spec/paper_trail_spec.rb @@ -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 diff --git a/spec/requests/articles_spec.rb b/spec/requests/articles_spec.rb index 2d77ca0f..9bffdd36 100644 --- a/spec/requests/articles_spec.rb +++ b/spec/requests/articles_spec.rb @@ -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