Skip to content

Commit

Permalink
Only set tokens when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Sep 18, 2024
1 parent 9d120be commit 9841b5a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/feeds/apple_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def set_defaults
self.audio_format ||= DEFAULT_AUDIO_FORMAT
self.display_episodes_count ||= podcast&.default_feed&.display_episodes_count
self.include_zones ||= DEFAULT_ZONES
self.tokens = [FeedToken.new(label: DEFAULT_TITLE)]
self.tokens = [FeedToken.new(label: DEFAULT_TITLE)] if tokens.empty?
self.private = true

super
Expand Down
44 changes: 44 additions & 0 deletions test/models/feed/apple_subscription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,50 @@
let(:feed_1) { podcast.default_feed }
let(:apple_feed) { build(:apple_feed, podcast: podcast) }

describe "#set_defaults" do
let(:default_feed) { build_stubbed(:feed, display_episodes_count: 99) }
let(:podcast) { build_stubbed(:podcast, default_feed: default_feed) }

it "sets default values for apple subscription feeds" do
f = Feeds::AppleSubscription.new(podcast: podcast)

assert_equal Feeds::AppleSubscription::DEFAULT_FEED_SLUG, f.slug
assert_equal Feeds::AppleSubscription::DEFAULT_TITLE, f.title
assert_equal Feeds::AppleSubscription::DEFAULT_AUDIO_FORMAT, f.audio_format
assert_equal 99, f.display_episodes_count
assert_equal Feeds::AppleSubscription::DEFAULT_ZONES, f.include_zones
assert_equal true, f.private

assert_equal 1, f.tokens.length
assert_equal Feeds::AppleSubscription::DEFAULT_TITLE, f.tokens[0].label
end

it "does not override most existing values" do
t = FeedToken.new(label: "l1", token: "t1")
f = Feeds::AppleSubscription.new(
podcast: podcast,
slug: "foo",
title: "bar",
audio_format: {f: "baz"},
display_episodes_count: 88,
include_zones: ["something"],
private: false,
tokens: [t]
)

assert_equal "foo", f.slug
assert_equal "bar", f.title
assert_equal ({"f" => "baz"}), f.audio_format
assert_equal 88, f.display_episodes_count
assert_equal ["something"], f.include_zones
assert_equal true, f.private

assert_equal 1, f.tokens.length
assert_equal "l1", f.tokens[0].label
assert_equal "t1", f.tokens[0].token
end
end

describe "#valid?" do
it "cannot change the default properties once saved" do
apple_feed.title = "new apple feed"
Expand Down

0 comments on commit 9841b5a

Please sign in to comment.