Skip to content

Commit

Permalink
Merge branch 'main' of github.com:excid3/noticed
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Feb 14, 2024
2 parents 92cdcde + d7ed992 commit 8c539c7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
21 changes: 16 additions & 5 deletions db/migrate/20231215190233_create_noticed_tables.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class CreateNoticedTables < ActiveRecord::Migration[6.1]
def change
create_table :noticed_events do |t|
primary_key_type, foreign_key_type = primary_and_foreign_key_types
create_table :noticed_events, id: primary_key_type do |t|
t.string :type
t.belongs_to :record, polymorphic: true
t.belongs_to :record, polymorphic: true, type: foreign_key_type
if t.respond_to?(:jsonb)
t.jsonb :params
else
Expand All @@ -12,14 +13,24 @@ def change
t.timestamps
end

create_table :noticed_notifications do |t|
create_table :noticed_notifications, id: primary_key_type do |t|
t.string :type
t.belongs_to :event, null: false
t.belongs_to :recipient, polymorphic: true, null: false
t.belongs_to :event, null: false, type: foreign_key_type
t.belongs_to :recipient, polymorphic: true, null: false, type: foreign_key_type
t.datetime :read_at
t.datetime :seen_at

t.timestamps
end
end

private

def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end
2 changes: 1 addition & 1 deletion lib/noticed/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def post_request(url, args = {})
if (json = args.delete(:json))
request.body = json.to_json
elsif (form = args.delete(:form))
request.set_form(form, "multipart/form-data")
request.form_data = form
end

logger.debug("POST #{url}")
Expand Down
2 changes: 1 addition & 1 deletion test/bulk_delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase
url: "https://example.org/webhook",
form: {foo: :bar}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /multipart\/form-data/})
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /application\/x-www-form-urlencoded/})
@delivery_method.deliver
end

Expand Down
7 changes: 6 additions & 1 deletion test/delivery_methods/twilio_messaging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class TwilioMessagingTest < ActiveSupport::TestCase
stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/acct_1234/Messages.json").with(
headers: {
"Authorization" => "Basic YWNjdF8xMjM0OnRva2Vu",
"Content-Type" => "multipart/form-data"
"Content-Type" => "application/x-www-form-urlencoded"
},
body: {
From: "+1234567890",
To: "+1234567890",
Body: "Hello world"
}
).to_return(status: 200)
@delivery_method.deliver
Expand Down
2 changes: 1 addition & 1 deletion test/delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WebhookDeliveryMethodTest < ActiveSupport::TestCase
url: "https://example.org/webhook",
form: {foo: :bar}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /multipart\/form-data/})
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /application\/x-www-form-urlencoded/})
@delivery_method.deliver
end

Expand Down

0 comments on commit 8c539c7

Please sign in to comment.