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
module DiscoursePatrons
module DiscourseSubscriptions
module Admin
class PlansController < ::Admin::AdminController
include DiscoursePatrons::Stripe
include DiscourseSubscriptions::Stripe
before_action :set_api_key

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,11 +2,11 @@
require 'rails_helper'
module DiscoursePatrons
module DiscourseSubscriptions
module Admin
RSpec.describe PlansController 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
context 'not authenticated' do

View File

@ -2,11 +2,11 @@
require 'rails_helper'
module DiscoursePatrons
module DiscourseSubscriptions
module Admin
RSpec.describe ProductsController 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
context 'unauthenticated' do

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
require 'rails_helper'
module DiscoursePatrons
module DiscourseSubscriptions
RSpec.describe ProductsController do
describe "products" do
let(:product) do
@ -53,7 +53,7 @@ module DiscoursePatrons
end
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])
get "/s/products.json"
@ -62,7 +62,7 @@ module DiscoursePatrons
end
it "is not subscribed" do
::DiscoursePatrons::Customer.delete_all
::DiscourseSubscriptions::Customer.delete_all
::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/s/products.json"

View File

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

View File

@ -2,10 +2,10 @@
require 'rails_helper'
module DiscoursePatrons
module DiscourseSubscriptions
RSpec.describe User::SubscriptionsController 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
context "not authenticated" do
@ -106,7 +106,7 @@ module DiscoursePatrons
expect {
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
end
@ -126,7 +126,7 @@ module DiscoursePatrons
expect {
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
end
@ -180,7 +180,7 @@ module DiscoursePatrons
expect {
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
end
@ -200,7 +200,7 @@ module DiscoursePatrons
expect {
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
end
@ -220,7 +220,7 @@ module DiscoursePatrons
expect {
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
end