-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api][webui] Update Notification to use JSON serialisation.
Otherwise the Event.payload gets parsed from json, then serialised as YAML into Notification.event_payload which sometimes causes errors because the payload can fit into the events table (with JSON serialisation) but might not fit into notifications.event_payload becuase YAML serialisation takes up more characters than JSON does.
- Loading branch information
Showing
6 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'rake db' do | ||
describe '#convert_notifications_serialization' do | ||
let!(:yaml) { "---\nhello: world\nhow:\n- are\n- you\n- today?\nim: fine thanks\n" } | ||
let!(:notification) { create(:notification, type: 'Notification::RssFeedItem') } | ||
let!(:task) { Rake::Task['db:convert_notifications_serialization'] } | ||
|
||
before do | ||
sql = "UPDATE `notifications` SET `event_payload` = '#{yaml}' WHERE id = #{notification.id}" | ||
ActiveRecord::Base.connection.execute(sql) | ||
end | ||
|
||
subject! { task.execute } | ||
|
||
it 'converts the notifications event_payload from yaml to json' do | ||
json_hash = { "hello" => "world", "how" => ["are", "you", "today?"], "im" => "fine thanks"} | ||
expect(Notification.first.event_payload).to eq(json_hash) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters