diff --git a/app/models/listing.rb b/app/models/listing.rb index 2ac91fe37..971188dd0 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -40,6 +40,24 @@ class Listing < ApplicationRecord delegate :cost, to: :listing_category + # As part of making listings "optional", this is the current place to go for the answer "Is the + # Listing feature enabled?" This approach will get us quite far, at least up until we flip this + # into a plugin (e.g. we won't be able to guarantee that we have the constant :Listing in the Ruby + # object space). + # + # @note As of <2022-01-28 Fri>, the assumption is that everyone will have this feature enabled. + # In part because marking this feature as disabled won't yet properly disable all aspects of + # the feature. + # + # @see https://github.com/forem/rfcs/issues/291 for discussion and rollout strategy + # @see FeatureFlag.accessible? + # + # @return [TrueClass] if the Listing is enabled for this Forem + # @return [FalseClass] if the Listing is disabled for this Forem + def self.feature_enabled? + FeatureFlag.accessible?(:listing_feature_enabled) + end + # Wrapping the column accessor names for consistency. Aliasing did not work. def listing_category_id classified_listing_category_id diff --git a/app/views/articles/_sidebar_listings.html.erb b/app/views/articles/_sidebar_listings.html.erb new file mode 100644 index 000000000..a2016e48e --- /dev/null +++ b/app/views/articles/_sidebar_listings.html.erb @@ -0,0 +1,21 @@ +<% @listings = Listing.where(published: true).select(:title, :classified_listing_category_id, :slug, :bumped_at) %> +<% if params[:timeframe].blank? && @listings.any? %> +
+
+

<%= t("views.main.side.listings.heading") %>

+ +
+ +
+ <% @listings.order(bumped_at: :desc).limit(5).each do |listing| %> + +
<%= listing.title %>
+ +
+ <% end %> + <%= t("views.main.side.listings.new") %> +
+
+<% end %> diff --git a/app/views/sidebars/_homepage_content.html.erb b/app/views/sidebars/_homepage_content.html.erb index 850870b1a..ecfad2f2d 100644 --- a/app/views/sidebars/_homepage_content.html.erb +++ b/app/views/sidebars/_homepage_content.html.erb @@ -8,27 +8,7 @@ <% end %> <%= render "articles/sidebar_campaign" if Campaign.current.show_in_sidebar? %> - <% @listings = Listing.where(published: true).select(:title, :classified_listing_category_id, :slug, :bumped_at) %> - <% if params[:timeframe].blank? && @listings.any? %> -
-
-

<%= t("views.main.side.listings.heading") %>

- -
- -
- <% @listings.order(bumped_at: :desc).limit(5).each do |listing| %> - -
<%= listing.title %>
- -
- <% end %> - <%= t("views.main.side.listings.new") %> -
-
- <% end %> + <%= render "articles/sidebar_listings" if Listing.feature_enabled? %> <% Settings::General.sidebar_tags.each do |tag| %>
diff --git a/spec/models/listing_spec.rb b/spec/models/listing_spec.rb index 248082e64..efc659921 100644 --- a/spec/models/listing_spec.rb +++ b/spec/models/listing_spec.rb @@ -9,6 +9,12 @@ RSpec.describe Listing, type: :model do # This may apply default parser on area that should not use it. after { ActsAsTaggableOn.default_parser = ActsAsTaggableOn::DefaultParser } + describe "class methods" do + subject(:klass) { described_class } + + it { is_expected.to respond_to(:feature_enabled?) } + end + it { is_expected.to validate_presence_of(:title) } it { is_expected.to validate_presence_of(:body_markdown) } it { is_expected.to have_many(:credits) }