Skip to content

Commit

Permalink
overcome inheritance that was forcing table look up on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
merefield committed Sep 28, 2023
1 parent 1a32862 commit 6aa68eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
37 changes: 3 additions & 34 deletions spec/components/custom_wizard/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,11 @@
}
}

after do
undefine_client_classes
end

it "detects the subscription client" do
undefine_client_classes
expect(described_class.client_installed?).to eq(false)
end

context "without a subscription client" do
it "is not subscribed" do
expect(described_class.subscribed?).to eq(false)
end

it "has none type" do
subscription = described_class.new
expect(subscription.type).to eq(:none)
end

it "non subscriber features are included" do
expect(described_class.includes?(:wizard, :after_signup, true)).to eq(true)
end

it "subscriber features are not included" do
expect(described_class.includes?(:wizard, :permitted, {})).to eq(false)
end
end

context "with subscription client" do
context "with subscription client gem" do
before do
define_client_classes
end

it "detects the subscription client" do
expect(described_class.client_installed?).to eq(true)
end

context "without a subscription" do
before do
DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(nil)
Expand All @@ -69,11 +37,12 @@
end

context "with subscriptions" do

def get_subscription_result(product_ids)
result = DiscourseSubscriptionClient::Subscriptions::Result.new
result.supplier = SubscriptionClientSupplier.new(product_slugs)
result.resource = SubscriptionClientResource.new
result.subscriptions = product_ids.map { |product_id| SubscriptionClientSubscription.new(product_id) }
result.subscriptions = product_ids.map { |product_id| ::SubscriptionClientSubscription.new(product_id) }
result.products = product_slugs
result
end
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/subscription_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ def self.find_subscriptions(resource_name)
end
end

class SubscriptionClientSupplier
SubscriptionClientSupplier = Class.new Object do
attr_reader :product_slugs

def initialize(product_slugs)
@product_slugs = product_slugs
end
end

class SubscriptionClientResource
SubscriptionClientResource = Class.new Object do
end

class SubscriptionClientSubscription
SubscriptionClientSubscription = Class.new Object do
attr_reader :product_id

def initialize(product_id)
Expand Down

0 comments on commit 6aa68eb

Please sign in to comment.