Skip to content

Commit

Permalink
🧹 Marketplace: return only Marketplaces! (#1423)
Browse files Browse the repository at this point in the history
- #831
- #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...
  • Loading branch information
zspencer authored May 4, 2023
1 parent fe9cec6 commit c335e73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/furniture/marketplace/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/furniture/marketplace/marketplace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c335e73

Please sign in to comment.