Skip to content

Commit

Permalink
Allow blank categories for non-default feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 9, 2023
1 parent a703cd7 commit 6a32f9f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,14 @@ def itunes_category
end

def itunes_category=(value)
if (cat = itunes_categories[0])
if cat.name != value
cat.name = value
cat.subcategories = []
end
else
itunes_categories.build(name: value)
cat = itunes_categories[0] || itunes_categories.build

# allow destroying for non-default feeds
if custom? && value.blank?
cat.mark_for_destruction
elsif cat.name != value
cat.name = value
cat.subcategories = []
end
end

Expand Down
24 changes: 24 additions & 0 deletions test/models/feed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,28 @@
refute feed1.publish_to_apple?(create(:apple_config, public_feed: create(:feed), private_feed: create(:feed)))
end
end

describe "#itunes_category" do
it "is required for default feeds" do
assert_equal 1, feed1.itunes_categories.count
assert_equal "Leisure", feed1.itunes_category
assert_equal "Aviation", feed1.itunes_subcategory

feed1.itunes_category = nil
assert feed1.invalid?
assert_match(/can't be blank/i, feed1.errors.full_messages_for("itunes_categories.name").join)
end

it "can be deleted for non-default feeds" do
create(:itunes_category, feed: feed2)

assert_equal 1, feed2.itunes_categories.count
assert_equal "Leisure", feed2.itunes_category
assert_equal "Aviation", feed2.itunes_subcategory

feed2.itunes_category = nil
assert feed2.valid?
assert feed2.itunes_categories[0].marked_for_destruction?
end
end
end

0 comments on commit 6a32f9f

Please sign in to comment.