fix broken unauthenticated page

This commit is contained in:
Rimian Perkins 2019-12-03 14:31:15 +11:00
parent 56b73139d1
commit d8a3ae5554
3 changed files with 57 additions and 38 deletions

View File

@ -44,6 +44,8 @@ module DiscoursePatrons
end end
def current_user_products def current_user_products
return [] if current_user.nil?
::DiscoursePatrons::Customer ::DiscoursePatrons::Customer
.select(:product_id) .select(:product_id)
.where(user_id: current_user.id) .where(user_id: current_user.id)

View File

@ -2,7 +2,7 @@
# name: discourse-subscriptions # name: discourse-subscriptions
# about: Integrates Stripe into Discourse to allow visitors to subscribe # about: Integrates Stripe into Discourse to allow visitors to subscribe
# version: 2.5.0 # version: 2.5.1
# url: https://github.com/rimian/discourse-subscriptions # url: https://github.com/rimian/discourse-subscriptions
# authors: Rimian Perkins # authors: Rimian Perkins
@ -44,7 +44,7 @@ after_initialize do
::Stripe.set_app_info( ::Stripe.set_app_info(
'Discourse Subscriptions', 'Discourse Subscriptions',
version: '2.5.0', version: '2.5.1',
url: 'https://github.com/rimian/discourse-subscriptions' url: 'https://github.com/rimian/discourse-subscriptions'
) )

View File

@ -4,9 +4,7 @@ require 'rails_helper'
module DiscoursePatrons module DiscoursePatrons
RSpec.describe ProductsController do RSpec.describe ProductsController do
context "authenticated" do describe "products" do
let(:user) { Fabricate(:user) }
let(:product) do let(:product) do
{ {
id: "prodct_23456", id: "prodct_23456",
@ -18,6 +16,24 @@ module DiscoursePatrons
} }
end end
context "unauthenticated" do
it "gets products" do
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/s/products.json"
expect(JSON.parse(response.body)).to eq([{
"id" => "prodct_23456",
"name" => "Very Special Product",
"description" => "Many people listened to my phone call with the Ukrainian President while it was being made",
"subscribed" => false
}])
end
end
context "authenticated" do
let(:user) { Fabricate(:user) }
before do before do
sign_in(user) sign_in(user)
end end
@ -70,4 +86,5 @@ module DiscoursePatrons
end end
end end
end end
end
end end