Skip to content

Commit

Permalink
Don't allow for creating empty Digests (digest without listings)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyhtou committed Aug 5, 2023
1 parent 9711179 commit bd1bdb3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/models/hackathon/digest/listings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module Hackathon::Digest::Listings
has_many :listed_hackathons, through: :listings, source: :hackathon
has_many :listed_subscriptions, through: :listings, source: :subscription

before_create :build_list_of_relevant_hackathons
before_validation :build_relevant_listings
validates_length_of :listings, minimum: 1, on: :create, message: "must have at least one listing"
end

private

MAX_LISTINGS = 8

def build_list_of_relevant_hackathons(max_listings: MAX_LISTINGS)
# TODO: handle case where there are no nearby hackathons (don't allow for creation of digest)
def build_relevant_listings(max_listings: MAX_LISTINGS)
nearby_upcoming_hackathons.first(max_listings).each do |result|
listings.build hackathon: result[:hackathon], subscription: result[:subscription]
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/hackathon/digest_mailer/_subscription.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<%= render "hackathon", hackathon: listing.hackathon %>
</td>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/hackathon/digest_mailer/_subscription.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Near <%= subscription.to_location.to_fs(:short) %>
<% listings.each do |listing| %>
<%= render "hackathon", hackathon: listing.hackathon %>
<% end %>
<% end %>

0 comments on commit bd1bdb3

Please sign in to comment.