mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-16 11:03:27 +00:00
fix broken unauthenticated page
This commit is contained in:
parent
56b73139d1
commit
d8a3ae5554
@ -44,6 +44,8 @@ module DiscoursePatrons
|
||||
end
|
||||
|
||||
def current_user_products
|
||||
return [] if current_user.nil?
|
||||
|
||||
::DiscoursePatrons::Customer
|
||||
.select(:product_id)
|
||||
.where(user_id: current_user.id)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# name: discourse-subscriptions
|
||||
# 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
|
||||
# authors: Rimian Perkins
|
||||
|
||||
@ -44,7 +44,7 @@ after_initialize do
|
||||
|
||||
::Stripe.set_app_info(
|
||||
'Discourse Subscriptions',
|
||||
version: '2.5.0',
|
||||
version: '2.5.1',
|
||||
url: 'https://github.com/rimian/discourse-subscriptions'
|
||||
)
|
||||
|
||||
|
@ -4,9 +4,7 @@ require 'rails_helper'
|
||||
|
||||
module DiscoursePatrons
|
||||
RSpec.describe ProductsController do
|
||||
context "authenticated" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe "products" do
|
||||
let(:product) do
|
||||
{
|
||||
id: "prodct_23456",
|
||||
@ -18,11 +16,7 @@ module DiscoursePatrons
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
context "unauthenticated" do
|
||||
it "gets products" do
|
||||
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
|
||||
|
||||
@ -35,37 +29,60 @@ module DiscoursePatrons
|
||||
"subscribed" => false
|
||||
}])
|
||||
end
|
||||
|
||||
it "is subscribed" do
|
||||
::DiscoursePatrons::Customer.create(product_id: product[:id], user_id: user.id, customer_id: 'x')
|
||||
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
|
||||
|
||||
get "/s/products.json"
|
||||
data = JSON.parse(response.body)
|
||||
expect(data.first["subscribed"]).to eq true
|
||||
end
|
||||
|
||||
it "is not subscribed" do
|
||||
::DiscoursePatrons::Customer.delete_all
|
||||
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
|
||||
|
||||
get "/s/products.json"
|
||||
data = JSON.parse(response.body)
|
||||
expect(data.first["subscribed"]).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'show' do
|
||||
it 'retrieves the product' do
|
||||
::Stripe::Product.expects(:retrieve).with('prod_walterwhite').returns(product)
|
||||
get "/s/products/prod_walterwhite.json"
|
||||
context "authenticated" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
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
|
||||
)
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
describe "index" 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
|
||||
|
||||
it "is subscribed" do
|
||||
::DiscoursePatrons::Customer.create(product_id: product[:id], user_id: user.id, customer_id: 'x')
|
||||
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
|
||||
|
||||
get "/s/products.json"
|
||||
data = JSON.parse(response.body)
|
||||
expect(data.first["subscribed"]).to eq true
|
||||
end
|
||||
|
||||
it "is not subscribed" do
|
||||
::DiscoursePatrons::Customer.delete_all
|
||||
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
|
||||
|
||||
get "/s/products.json"
|
||||
data = JSON.parse(response.body)
|
||||
expect(data.first["subscribed"]).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'show' do
|
||||
it 'retrieves the product' do
|
||||
::Stripe::Product.expects(:retrieve).with('prod_walterwhite').returns(product)
|
||||
get "/s/products/prod_walterwhite.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
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user