From c335e73464d641f8fa3a139b952a8eac8d774edf Mon Sep 17 00:00:00 2001 From: Zee <50284+zspencer@users.noreply.github.com> Date: Wed, 3 May 2023 17:21:00 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20`Marketplace`:=20return=20only?= =?UTF-8?q?=20`Marketplace`s!=20(#1423)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene/issues/831 - https://github.com/zinc-collective/convene/issues/709 There's something appealing about switching to Rails' built in `Single Table Inheritance` for `Furniture`, rather than our flyweight registry; but I also know that STI can be a bit of a smell... Anyway, now when you call `Marketplace.all` and get *only* `Marketplace`s. Maybe someday we'll pull this up in to the `Furniture` classes responsibilities so we don't have to do it on every single piece of Furniture... --- app/furniture/marketplace/marketplace.rb | 1 + spec/furniture/marketplace/marketplace_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/app/furniture/marketplace/marketplace.rb b/app/furniture/marketplace/marketplace.rb index 94e13e8fc..47b7bc401 100644 --- a/app/furniture/marketplace/marketplace.rb +++ b/app/furniture/marketplace/marketplace.rb @@ -3,6 +3,7 @@ class Marketplace class Marketplace < Furniture location(parent: :room) + default_scope { where(furniture_kind: "marketplace") } has_many :products, inverse_of: :marketplace, dependent: :destroy has_many :carts, inverse_of: :marketplace, dependent: :destroy diff --git a/spec/furniture/marketplace/marketplace_spec.rb b/spec/furniture/marketplace/marketplace_spec.rb index dec15a731..bef49f457 100644 --- a/spec/furniture/marketplace/marketplace_spec.rb +++ b/spec/furniture/marketplace/marketplace_spec.rb @@ -16,4 +16,14 @@ specify { expect { marketplace.destroy }.not_to change(orders, :count) } end end + + describe ".all" do + subject(:all) { described_class.all } + + let!(:non_marketplace_furniture) { create(:journal) } + let!(:marketplace_furniture) { create(:marketplace) } + + it { is_expected.not_to include(non_marketplace_furniture) } + it { is_expected.to include(marketplace_furniture) } + end end