From 4e023c0e3dbde2cc17741938c8ecc206a982ff3e Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Sat, 11 Mar 2023 06:36:59 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20`Furniture`:=20Appease=20the=20F?= =?UTF-8?q?uzz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene/pull/1209#discussion_r1133016759 - https://github.com/zinc-collective/convene/issues/709 I don't really like the direction this pushes specs, but I can live with it. In particular, a single assert per request/response seems... excruciatingly slow. But there are other mechanisms we can explore to mitigate that as it gets out of hand. --- .rubocop_todo.yml | 18 ----- spec/furniture/embedded_form_spec.rb | 24 +++++-- .../furniture/journal/entries_request_spec.rb | 65 ++++++++++++------- spec/furniture/journal/entry_policy_spec.rb | 2 +- spec/furniture/markdown_text_block_spec.rb | 13 ++-- .../checkouts_controller_request_spec.rb | 8 +-- .../products_controller_request_spec.rb | 35 ++++++---- ...stripe_accounts_controller_request_spec.rb | 5 +- .../stripe_events_controller_request_spec.rb | 4 +- spec/models/furniture_spec.rb | 12 +++- .../furnitures_controller_request_spec.rb | 11 ++-- 11 files changed, 115 insertions(+), 82 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f0b5569c6..5e0d22677 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -23,7 +23,6 @@ RSpec/AnyInstance: # Prefixes: when, with, without RSpec/ContextWording: Exclude: - - 'spec/furniture/journal/entry_policy_spec.rb' - 'spec/models/authenticated_session_spec.rb' - 'spec/support/shared_examples/a_space_member_only_route.rb' @@ -37,15 +36,9 @@ RSpec/DescribeClass: # Configuration parameters: Max, CountAsOne. RSpec/ExampleLength: Exclude: - - 'spec/furniture/embedded_form_spec.rb' - - 'spec/furniture/journal/entries_request_spec.rb' - - 'spec/furniture/markdown_text_block_spec.rb' - - 'spec/furniture/marketplace/products_controller_request_spec.rb' - - 'spec/models/furniture_spec.rb' - 'spec/models/membership_spec.rb' - 'spec/models/room_spec.rb' - 'spec/policies/room_policy_spec.rb' - - 'spec/requests/furnitures_controller_request_spec.rb' - 'spec/requests/rsvps_controller_request_spec.rb' - 'spec/requests/spaces/invitations_request_spec.rb' - 'spec/requests/spaces_controller_request_spec.rb' @@ -66,8 +59,6 @@ RSpec/LeakyConstantDeclaration: # Offense count: 4 RSpec/LetSetup: Exclude: - - 'spec/furniture/marketplace/checkouts_controller_request_spec.rb' - - 'spec/furniture/marketplace/stripe_accounts_controller_request_spec.rb' - 'spec/policies/membership_policy_spec.rb' # Offense count: 6 @@ -80,11 +71,6 @@ RSpec/NamedSubject: - 'spec/models/membership_spec.rb' - 'spec/models/space_spec.rb' -# Offense count: 2 -RSpec/RepeatedExampleGroupBody: - Exclude: - - 'spec/furniture/marketplace/checkout_policy_spec.rb' - # Offense count: 2 RSpec/RepeatedExampleGroupDescription: Exclude: @@ -94,9 +80,6 @@ RSpec/RepeatedExampleGroupDescription: # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - - 'spec/furniture/marketplace/checkouts_controller_request_spec.rb' - - 'spec/furniture/marketplace/stripe_accounts_controller_request_spec.rb' - - 'spec/furniture/marketplace/stripe_events_controller_request_spec.rb' - 'spec/requests/spaces/invitations_request_spec.rb' # Offense count: 6 @@ -142,7 +125,6 @@ Rails/HasManyOrHasOneDependent: # Offense count: 2 Rails/I18nLocaleTexts: Exclude: - - 'app/furniture/marketplace/stripe_accounts_controller.rb' - 'app/mailers/authenticated_session_mailer.rb' # Offense count: 1 diff --git a/spec/furniture/embedded_form_spec.rb b/spec/furniture/embedded_form_spec.rb index 2e3380773..a05e558e8 100644 --- a/spec/furniture/embedded_form_spec.rb +++ b/spec/furniture/embedded_form_spec.rb @@ -3,16 +3,26 @@ require "rails_helper" RSpec.describe EmbeddedForm do + subject(:embedded_form) { build(:embedded_form, form_url: form_url) } + describe "#embeddable_form_url" do - it "converts Airtable Share URLs into the Embed url" do - embedded_form = build(:embedded_form, form_url: "https://airtable.com/shrCnrBzflvzDIlvg") - expect(embedded_form.embeddable_form_url).to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") + subject(:embeddable_form_url) { embedded_form.embeddable_form_url } + context "with a #form_url that is the basic share url" do + let(:form_url) { "https://airtable.com/shrCnrBzflvzDIlvg" } + + it { is_expected.to eql "https://airtable.com/embed/shrCnrBzflvzDIlvg" } + end + + context "with a #form_url that is the embed instructions url" do + let(:form_url) { "https://airtable.com/shrCnrBzflvzDIlvg/embed" } + + it { is_expected.to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") } + end - embedded_form = build(:embedded_form, form_url: "https://airtable.com/shrCnrBzflvzDIlvg/embed") - expect(embedded_form.embeddable_form_url).to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") + context "with a #form_url that is the actual embed url" do + let(:form_url) { "https://airtable.com/embed/shrCnrBzflvzDIlvg" } - embedded_form = build(:embedded_form, form_url: "https://airtable.com/embed/shrCnrBzflvzDIlvg") - expect(embedded_form.embeddable_form_url).to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") + it { is_expected.to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") } end end end diff --git a/spec/furniture/journal/entries_request_spec.rb b/spec/furniture/journal/entries_request_spec.rb index 0a70df296..ef60a4c06 100644 --- a/spec/furniture/journal/entries_request_spec.rb +++ b/spec/furniture/journal/entries_request_spec.rb @@ -7,44 +7,59 @@ let(:room) { journal.room } let(:member) { create(:person, spaces: [space]) } - describe "#index" do - it "shows all the journal entries" do - sign_in(space, member) - unpublished_entry = create(:journal_entry, journal: journal) - published_entry = create(:journal_entry, journal: journal, published_at: 1.week.ago) + before { sign_in(space, member) } + describe "#index" do + subject(:perform_request) do get polymorphic_path(journal.location(child: :entries)) + response + end + + let!(:unpublished_entry) { create(:journal_entry, journal: journal) } + let!(:published_entry) { create(:journal_entry, journal: journal, published_at: 1.week.ago) } + + it { is_expected.to be_ok } + + describe "response body" do + subject(:response_body) { response.body } - expect(response).to be_ok - expect(response.body).to include(CGI.escapeHTML(published_entry.headline)) - expect(response.body).to include(CGI.escapeHTML(unpublished_entry.headline)) + before { perform_request } + it { is_expected.to include(CGI.escapeHTML(published_entry.headline)) } + it { is_expected.to include(CGI.escapeHTML(unpublished_entry.headline)) } end end describe "#create" do - it "Creates an Entry in the Journal" do - sign_in(space, member) + subject(:perform_request) do + post polymorphic_path([space, room, journal, :entries]), params: {entry: journal_entry_attributes} + end - attributes = attributes_for(:journal_entry) + let(:journal_entry_attributes) { attributes_for(:journal_entry) } + let(:created_journal_entry) { journal.entries.first } - expect do - post polymorphic_path([space, room, journal, :entries]), params: {entry: attributes} - end.to change(journal.entries, :count).by(1) + specify { expect { perform_request }.to change(journal.entries, :count).by(1) } - created_entry = journal.entries.first - expect(created_entry.headline).to eql(attributes[:headline]) - expect(created_entry.body).to eql(attributes[:body]) - end + specify { + perform_request + expect(created_journal_entry.headline).to eql(journal_entry_attributes[:headline]) + } + + specify { + perform_request + expect(created_journal_entry.body).to eql(journal_entry_attributes[:body]) + } end describe "#update" do - it "allows members to update Journal Entries" do - sign_in(space, member) - entry = create(:journal_entry, journal: journal) - published_at = 1.day.ago.beginning_of_day - expect do - put polymorphic_path(entry.location), params: {entry: {published_at: published_at}} - end.to change { entry.reload.published_at }.from(nil).to(published_at.to_time) + subject(:perform_request) do + put polymorphic_path(entry.location), params: {entry: {published_at: published_at}} end + + let(:published_at) { 1.day.ago.beginning_of_day } + let(:entry) { create(:journal_entry, journal: journal) } + + before { sign_in(space, member) } + + specify { expect { perform_request }.to change { entry.reload.published_at }.from(nil).to(published_at.to_time) } end end diff --git a/spec/furniture/journal/entry_policy_spec.rb b/spec/furniture/journal/entry_policy_spec.rb index b9396f78b..b9e5b2ed0 100644 --- a/spec/furniture/journal/entry_policy_spec.rb +++ b/spec/furniture/journal/entry_policy_spec.rb @@ -51,7 +51,7 @@ let!(:unpublished_entry) { create(:journal_entry, journal: published_entry.journal) } - context "When a Guest" do + context "when a Guest" do let(:user) { Guest.new } it { is_expected.not_to include(unpublished_entry) } diff --git a/spec/furniture/markdown_text_block_spec.rb b/spec/furniture/markdown_text_block_spec.rb index 3f3869ad4..a1b2f3ca7 100644 --- a/spec/furniture/markdown_text_block_spec.rb +++ b/spec/furniture/markdown_text_block_spec.rb @@ -6,17 +6,20 @@ subject(:content_block) { create(:furniture).becomes(described_class) } describe "#to_html" do - it "renders markdown correctly" do + subject(:to_html) { content_block.to_html } + + before do content_block.content = <<~MARKDOWN # Title ## Subtitle * item the first * item the _second_ MARKDOWN - expect(content_block.to_html).to include '