Skip to content

Commit

Permalink
DEV: update annotations, rspec session handling and test db
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Nov 25, 2023
1 parent f50c602 commit 5d88ef9
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ DEPENDENCIES
message_bus
mini_scheduler
pg
rails (>= 7.0.4.1)
rails (~> 7.0.4.1)
rails_multisite
rspec-activemodel-mocks
rspec-rails
Expand Down
5 changes: 0 additions & 5 deletions app/models/subscription_client_notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,3 @@ def self.expire_all(notice_type, notice_subject_type, notice_subject_id)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_subscription_client_notices_on_notice_subject (notice_subject_type,notice_subject_id)
# sc_unique_notices (notice_type,notice_subject_type,notice_subject_id,changed_at) UNIQUE
#
14 changes: 14 additions & 0 deletions app/models/subscription_client_request.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: subscription_client_requests
#
# id :bigint not null, primary key
# request_id :bigint
# request_type :string
# expired_at :datetime
# message :string
# count :integer
# response :json
# created_at :datetime not null
# updated_at :datetime not null
#
class SubscriptionClientRequest < ActiveRecord::Base
end
9 changes: 0 additions & 9 deletions app/models/subscription_client_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,3 @@ class SubscriptionClientResource < ActiveRecord::Base
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_subscription_client_resources_on_supplier_id (supplier_id)
# index_subscription_client_resources_on_supplier_id_and_name (supplier_id,name) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (supplier_id => subscription_client_suppliers.id)
#
9 changes: 0 additions & 9 deletions app/models/subscription_client_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,3 @@ def self.update_period
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_subscription_client_subscriptions_on_resource_id (resource_id)
# sc_unique_subscriptions (resource_id,product_id,price_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (resource_id => subscription_client_resources.id)
#
6 changes: 1 addition & 5 deletions app/models/subscription_client_supplier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,5 @@ def self.publish_authorized_supplier_count
# authorized_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_subscription_client_suppliers_on_url (url) UNIQUE
# index_subscription_client_suppliers_on_user_id (user_id)
# products :json
#
2 changes: 1 addition & 1 deletion discourse_subscription_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "message_bus"
spec.add_development_dependency "mini_scheduler"
spec.add_development_dependency "pg"
spec.add_development_dependency "rails", ">= 7.0.4.1"
spec.add_development_dependency "rails", "~> 7.0.4.1"
spec.add_development_dependency "rails_multisite"
spec.add_development_dependency "rspec-activemodel-mocks"
spec.add_development_dependency "rspec-rails"
Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_subscription_client/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def configurable?
config.after_initialize do
gem_root = File.expand_path("../..", __dir__)

ActiveRecord::Tasks::DatabaseTasks.migrations_paths << "#{gem_root}/db/migrate" unless Rails.env.test?
ActiveRecord::Tasks::DatabaseTasks.migrations_paths << "#{gem_root}/db/migrate"

%w[
./request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
}
end

include_context "session double"

context "with admin" do
before do
sign_in(admin)
Expand Down Expand Up @@ -50,6 +52,7 @@
end

it "handles authorization callbacks" do
session_hash[:final_landing_path] = "/admin/plugins/subscription-client/subscriptions"
request_id = cookies[:user_api_request_id] = DiscourseSubscriptionClient::Authorization.request_id(supplier.id)
payload = generate_auth_payload(admin.id, request_id)
stub_subscription_request(200, resource, subscription_response)
Expand All @@ -63,7 +66,7 @@
end

it "handles authorization callbacks and redirects to prior requested landing path" do
session[:final_landing_path] = "/admin/wizards/wizard"
session_hash[:final_landing_path] = "/admin/wizards/wizard"
request_id = cookies[:user_api_request_id] = DiscourseSubscriptionClient::Authorization.request_id(supplier.id)
payload = generate_auth_payload(admin.id, request_id)
stub_subscription_request(200, resource, subscription_response)
Expand Down Expand Up @@ -119,6 +122,7 @@
end

it "handles authorization callbacks" do
session_hash[:final_landing_path] = "/admin/plugins/subscription-client/subscriptions"
request_id = cookies[:user_api_request_id] = DiscourseSubscriptionClient::Authorization.request_id(supplier.id)
payload = generate_auth_payload(moderator.id, request_id)
stub_subscription_request(200, resource, subscription_response)
Expand Down
36 changes: 36 additions & 0 deletions spec/support/session_double.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

shared_context "session double" do
let(:session_hash) { {} }

before do
session_double = instance_double(ActionDispatch::Request::Session, enabled?: true, loaded?: false)

allow(session_double).to receive(:[]) do |key|
session_hash[key]
end

allow(session_double).to receive(:[]=) do |key, value|
session_hash[key] = value
end

allow(session_double).to receive(:delete) do |key|
session_hash.delete(key)
end

allow(session_double).to receive(:clear) do |_key|
session_hash.clear
end

allow(session_double).to receive(:fetch) do |key|
session_hash.fetch(key)
end

allow(session_double).to receive(:key?) do |key|
session_hash.key?(key)
end

allow_any_instance_of(ActionDispatch::Request)
.to receive(:session).and_return(session_double)
end
end

0 comments on commit 5d88ef9

Please sign in to comment.