Skip to content

Commit

Permalink
Add basic testing for subscribe links
Browse files Browse the repository at this point in the history
  • Loading branch information
radical-ube committed Feb 4, 2025
1 parent 5c2d4f7 commit 5c90324
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/subscribe_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SubscribeLink < ApplicationRecord
scope :with_apple_id, -> { where(platform: APPLE_PLATFORMS) }
scope :with_platform_id, -> { where(platform: UNIQUE_PLATFORMS) }

validates :platform, presence: true, inclusion: {in: PLATFORMS}
validates :external_id, presence: true

def uses_apple_id?
Expand Down
12 changes: 12 additions & 0 deletions test/models/podcast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@
end
end
end

describe "subscribe links" do
it "can only have one of each link platform" do
podcast.subscribe_links.create(platform: "apple", podcast: podcast, external_id: "12345")
podcast.subscribe_links.create(platform: "spotify", podcast: podcast, external_id: "12345")
podcast.save!
assert podcast.valid?

podcast.subscribe_links.create(platform: "apple", podcast: podcast, external_id: "54321")
refute podcast.valid?
end
end
end
22 changes: 22 additions & 0 deletions test/models/subscribe_link_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "test_helper"

describe SubscribeLink do
let(:podcast) { create(:podcast) }
let(:apple_link) { SubscribeLink.create(platform: "apple", podcast: podcast, external_id: "12345") }

describe "#valid?" do
it "requires a currently supported platform" do
assert apple_link.valid?
apple_link.platform = "wnyc"
refute apple_link.valid?
apple_link.platform = nil
refute apple_link.valid?
end

it "requires an external id" do
assert apple_link.valid?
apple_link.external_id = nil
refute apple_link.valid?
end
end
end

0 comments on commit 5c90324

Please sign in to comment.