name space module

This commit is contained in:
Rimian Perkins 2019-12-04 11:23:45 +11:00
parent 0b908e4da8
commit b397ba5a68
30 changed files with 69 additions and 69 deletions

View File

@ -1,9 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
module Admin module Admin
class PlansController < ::Admin::AdminController class PlansController < ::Admin::AdminController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
before_action :set_api_key before_action :set_api_key

View File

@ -1,9 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
module Admin module Admin
class ProductsController < ::Admin::AdminController class ProductsController < ::Admin::AdminController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
before_action :set_api_key before_action :set_api_key

View File

@ -1,10 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
module Admin module Admin
class SubscriptionsController < ::Admin::AdminController class SubscriptionsController < ::Admin::AdminController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
include DiscoursePatrons::Group include DiscourseSubscriptions::Group
before_action :set_api_key before_action :set_api_key
def index def index
@ -21,7 +21,7 @@ module DiscoursePatrons
begin begin
subscription = ::Stripe::Subscription.delete(params[:id]) subscription = ::Stripe::Subscription.delete(params[:id])
customer = DiscoursePatrons::Customer.find_by( customer = DiscourseSubscriptions::Customer.find_by(
product_id: subscription[:plan][:product], product_id: subscription[:plan][:product],
customer_id: subscription[:customer] customer_id: subscription[:customer]
) )

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class AdminController < ::Admin::AdminController class AdminController < ::Admin::AdminController
def index def index
head 200 head 200

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
module Group module Group
extend ActiveSupport::Concern extend ActiveSupport::Concern

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
module Stripe module Stripe
extend ActiveSupport::Concern extend ActiveSupport::Concern

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class CustomersController < ::ApplicationController class CustomersController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
before_action :set_api_key before_action :set_api_key
@ -13,7 +13,7 @@ module DiscoursePatrons
source: params[:source] source: params[:source]
) )
DiscoursePatrons::Customer.create_customer( DiscourseSubscriptions::Customer.create_customer(
current_user, current_user,
customer customer
) )

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class InvoicesController < ::ApplicationController class InvoicesController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
before_action :set_api_key before_action :set_api_key
requires_login requires_login
@ -29,7 +29,7 @@ module DiscoursePatrons
end end
def find_customer def find_customer
DiscoursePatrons::Customer.find_user(current_user) DiscourseSubscriptions::Customer.find_user(current_user)
end end
end end
end end

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class PatronsController < ::ApplicationController class PatronsController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
skip_before_action :verify_authenticity_token, only: [:create] skip_before_action :verify_authenticity_token, only: [:create]
before_action :set_api_key before_action :set_api_key

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class PlansController < ::ApplicationController class PlansController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
before_action :set_api_key before_action :set_api_key

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class ProductsController < ::ApplicationController class ProductsController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
before_action :set_api_key before_action :set_api_key
@ -46,7 +46,7 @@ module DiscoursePatrons
def current_user_products def current_user_products
return [] if current_user.nil? return [] if current_user.nil?
::DiscoursePatrons::Customer ::DiscourseSubscriptions::Customer
.select(:product_id) .select(:product_id)
.where(user_id: current_user.id) .where(user_id: current_user.id)
.map { |c| c.product_id }.compact .map { |c| c.product_id }.compact

View File

@ -1,9 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class SubscriptionsController < ::ApplicationController class SubscriptionsController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
include DiscoursePatrons::Group include DiscourseSubscriptions::Group
before_action :set_api_key before_action :set_api_key
requires_login requires_login
@ -41,7 +41,7 @@ module DiscoursePatrons
group.add(current_user) group.add(current_user)
end end
DiscoursePatrons::Customer.create( DiscourseSubscriptions::Customer.create(
user_id: current_user.id, user_id: current_user.id,
customer_id: params[:customer], customer_id: params[:customer],
product_id: plan[:product] product_id: plan[:product]

View File

@ -1,10 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
module User module User
class SubscriptionsController < ::ApplicationController class SubscriptionsController < ::ApplicationController
include DiscoursePatrons::Stripe include DiscourseSubscriptions::Stripe
include DiscoursePatrons::Group include DiscourseSubscriptions::Group
before_action :set_api_key before_action :set_api_key
requires_login requires_login

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscourseSubscriptions
class Customer < ActiveRecord::Base class Customer < ActiveRecord::Base
self.table_name = "discourse_subscriptions_customers" self.table_name = "discourse_subscriptions_customers"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
DiscoursePatrons::Engine.routes.draw do DiscourseSubscriptions::Engine.routes.draw do
# TODO: namespace this # TODO: namespace this
scope 'admin' do scope 'admin' do
get '/' => 'admin#index' get '/' => 'admin#index'

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module ::DiscoursePatrons module ::DiscourseSubscriptions
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
engine_name 'discourse-patrons' engine_name 'discourse-subscriptions'
isolate_namespace DiscoursePatrons isolate_namespace DiscourseSubscriptions
end end
end end

View File

@ -69,6 +69,6 @@ after_initialize do
].each { |path| require File.expand_path(path, __FILE__) } ].each { |path| require File.expand_path(path, __FILE__) }
Discourse::Application.routes.append do Discourse::Application.routes.append do
mount ::DiscoursePatrons::Engine, at: 's' mount ::DiscourseSubscriptions::Engine, at: 's'
end end
end end

View File

@ -2,9 +2,9 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe PatronsController, type: :controller do RSpec.describe PatronsController, type: :controller do
routes { DiscoursePatrons::Engine.routes } routes { DiscourseSubscriptions::Engine.routes }
describe 'index' do describe 'index' do
it 'responds ok' do it 'responds ok' do

View File

@ -1,3 +1,3 @@
# frozen_string_literal: true # frozen_string_literal: true
Fabricator(:customer, from: "DiscoursePatrons::Customer") Fabricator(:customer, from: "DiscourseSubscriptions::Customer")

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe Customer do RSpec.describe Customer do
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }
let(:stripe_customer) { { id: 'cus_id4567' } } let(:stripe_customer) { { id: 'cus_id4567' } }

View File

@ -2,11 +2,11 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
module Admin module Admin
RSpec.describe PlansController do RSpec.describe PlansController do
it 'is a subclass of AdminController' do it 'is a subclass of AdminController' do
expect(DiscoursePatrons::Admin::PlansController < ::Admin::AdminController).to eq(true) expect(DiscourseSubscriptions::Admin::PlansController < ::Admin::AdminController).to eq(true)
end end
context 'not authenticated' do context 'not authenticated' do

View File

@ -2,11 +2,11 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
module Admin module Admin
RSpec.describe ProductsController do RSpec.describe ProductsController do
it 'is a subclass of AdminController' do it 'is a subclass of AdminController' do
expect(DiscoursePatrons::Admin::ProductsController < ::Admin::AdminController).to eq(true) expect(DiscourseSubscriptions::Admin::ProductsController < ::Admin::AdminController).to eq(true)
end end
context 'unauthenticated' do context 'unauthenticated' do

View File

@ -2,10 +2,10 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe Admin::SubscriptionsController do RSpec.describe Admin::SubscriptionsController do
it 'is a subclass of AdminController' do it 'is a subclass of AdminController' do
expect(DiscoursePatrons::Admin::SubscriptionsController < ::Admin::AdminController).to eq(true) expect(DiscourseSubscriptions::Admin::SubscriptionsController < ::Admin::AdminController).to eq(true)
end end
context 'unauthenticated' do context 'unauthenticated' do
@ -39,7 +39,7 @@ module DiscoursePatrons
let(:group) { Fabricate(:group, name: 'subscribers') } let(:group) { Fabricate(:group, name: 'subscribers') }
before do before do
DiscoursePatrons::Customer.create( DiscourseSubscriptions::Customer.create(
user_id: user.id, user_id: user.id,
customer_id: 'c_123', customer_id: 'c_123',
product_id: 'pr_34578' product_id: 'pr_34578'
@ -59,7 +59,7 @@ module DiscoursePatrons
expect { expect {
delete "/s/admin/subscriptions/sub_12345.json" delete "/s/admin/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscourseSubscriptions::Customer.count }.by(-1)
end end
it "removes the user from the group" do it "removes the user from the group" do

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe AdminController do RSpec.describe AdminController do
let(:admin) { Fabricate(:admin) } let(:admin) { Fabricate(:admin) }
@ -10,7 +10,7 @@ module DiscoursePatrons
before { sign_in(admin) } before { sign_in(admin) }
it 'is a subclass of AdminController' do it 'is a subclass of AdminController' do
expect(DiscoursePatrons::AdminController < ::Admin::AdminController).to eq(true) expect(DiscourseSubscriptions::AdminController < ::Admin::AdminController).to eq(true)
end end
it "is ok" do it "is ok" do

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe CustomersController do RSpec.describe CustomersController do
describe "create" do describe "create" do
describe "authenticated" do describe "authenticated" do
@ -26,7 +26,7 @@ module DiscoursePatrons
expect { expect {
post "/s/customers.json", params: { source: 'tok_interesting' } post "/s/customers.json", params: { source: 'tok_interesting' }
}.to change { DiscoursePatrons::Customer.count } }.to change { DiscourseSubscriptions::Customer.count }
end end
end end
end end

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe InvoicesController do RSpec.describe InvoicesController do
describe "index" do describe "index" do
describe "not authenticated" do describe "not authenticated" do
@ -39,7 +39,7 @@ module DiscoursePatrons
context "stripe customer exists" do context "stripe customer exists" do
before do before do
DiscoursePatrons::Customer.create_customer(user, stripe_customer) DiscourseSubscriptions::Customer.create_customer(user, stripe_customer)
end end
it "lists the invoices" do it "lists the invoices" do

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe PlansController do RSpec.describe PlansController do
describe "index" do describe "index" do
it "lists the active plans" do it "lists the active plans" do

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe ProductsController do RSpec.describe ProductsController do
describe "products" do describe "products" do
let(:product) do let(:product) do
@ -53,7 +53,7 @@ module DiscoursePatrons
end end
it "is subscribed" do it "is subscribed" do
::DiscoursePatrons::Customer.create(product_id: product[:id], user_id: user.id, customer_id: 'x') ::DiscourseSubscriptions::Customer.create(product_id: product[:id], user_id: user.id, customer_id: 'x')
::Stripe::Product.expects(:list).with(active: true).returns(data: [product]) ::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/s/products.json" get "/s/products.json"
@ -62,7 +62,7 @@ module DiscoursePatrons
end end
it "is not subscribed" do it "is not subscribed" do
::DiscoursePatrons::Customer.delete_all ::DiscourseSubscriptions::Customer.delete_all
::Stripe::Product.expects(:list).with(active: true).returns(data: [product]) ::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/s/products.json" get "/s/products.json"

View File

@ -2,7 +2,7 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe SubscriptionsController do RSpec.describe SubscriptionsController do
context "not authenticated" do context "not authenticated" do
it "does not create a subscription" do it "does not create a subscription" do
@ -34,7 +34,7 @@ module DiscoursePatrons
expect { expect {
post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.to change { DiscoursePatrons::Customer.count } }.to change { DiscourseSubscriptions::Customer.count }
end end
it "creates a customer model" do it "creates a customer model" do
@ -43,7 +43,7 @@ module DiscoursePatrons
expect { expect {
post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.to change { DiscoursePatrons::Customer.count } }.to change { DiscourseSubscriptions::Customer.count }
end end
end end

View File

@ -2,10 +2,10 @@
require 'rails_helper' require 'rails_helper'
module DiscoursePatrons module DiscourseSubscriptions
RSpec.describe User::SubscriptionsController do RSpec.describe User::SubscriptionsController do
it 'is a subclass of ApplicationController' do it 'is a subclass of ApplicationController' do
expect(DiscoursePatrons::User::SubscriptionsController < ::ApplicationController).to eq(true) expect(DiscourseSubscriptions::User::SubscriptionsController < ::ApplicationController).to eq(true)
end end
context "not authenticated" do context "not authenticated" do
@ -106,7 +106,7 @@ module DiscoursePatrons
expect { expect {
delete "/s/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.not_to change { DiscoursePatrons::Customer.count } }.not_to change { DiscourseSubscriptions::Customer.count }
expect(response.status).to eq 422 expect(response.status).to eq 422
end end
@ -126,7 +126,7 @@ module DiscoursePatrons
expect { expect {
delete "/s/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.not_to change { DiscoursePatrons::Customer.count } }.not_to change { DiscourseSubscriptions::Customer.count }
expect(response.status).to eq 422 expect(response.status).to eq 422
end end
@ -180,7 +180,7 @@ module DiscoursePatrons
expect { expect {
delete "/s/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscourseSubscriptions::Customer.count }.by(-1)
expect(response.status).to eq 200 expect(response.status).to eq 200
end end
@ -200,7 +200,7 @@ module DiscoursePatrons
expect { expect {
delete "/s/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscourseSubscriptions::Customer.count }.by(-1)
expect(response.status).to eq 200 expect(response.status).to eq 200
end end
@ -220,7 +220,7 @@ module DiscoursePatrons
expect { expect {
delete "/s/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscourseSubscriptions::Customer.count }.by(-1)
expect(response.status).to eq 200 expect(response.status).to eq 200
end end