mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 10:29:53 +01:00
make the export worker create a *real* notification and add specs for it
This commit is contained in:
parent
17783fbf38
commit
e1bdb1324f
6 changed files with 66 additions and 7 deletions
5
app/models/notification/data_exported.rb
Normal file
5
app/models/notification/data_exported.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# NOTE: `target` is not really used for this notification, but it should be of type `User::DataExport`
|
||||
class Notification::DataExported < Notification
|
||||
end
|
5
app/models/user/data_export.rb
Normal file
5
app/models/user/data_export.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# stub model to nicely allow for data export notifications, do NOT use this directly!
|
||||
class User::DataExport < User
|
||||
end
|
8
app/views/notifications/type/_dataexport.html.haml
Normal file
8
app/views/notifications/type/_dataexport.html.haml
Normal file
|
@ -0,0 +1,8 @@
|
|||
.media.notification
|
||||
.notification__icon
|
||||
%i.fa.fa-2x.fa-fw.fa-download
|
||||
.media-body
|
||||
%h6.media-heading.notification__user
|
||||
= t(".heading")
|
||||
.notification__text
|
||||
= t(".text_html", settings_export: link_to(t(".settings_export"), settings_export_path))
|
|
@ -1,4 +1,7 @@
|
|||
require 'exporter'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "exporter"
|
||||
|
||||
class ExportWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
|
@ -6,11 +9,16 @@ class ExportWorker
|
|||
|
||||
# @param user_id [Integer] the user id
|
||||
def perform(user_id)
|
||||
exporter = Exporter.new User.find(user_id)
|
||||
user = User.find(user_id)
|
||||
|
||||
exporter = Exporter.new(user)
|
||||
exporter.export
|
||||
question = Question.create(content: "Your #{APP_CONFIG['site_name']} data export is ready! You can download it " +
|
||||
"from the settings page under the \"Export\" tab.", author_is_anonymous: true,
|
||||
author_identifier: "retrospring_exporter")
|
||||
Inbox.create(user_id: user_id, question_id: question.id, new: true)
|
||||
|
||||
Notification::DataExported.create(
|
||||
target_id: user.id,
|
||||
target_type: "User::DataExport",
|
||||
recipient: user,
|
||||
new: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -327,6 +327,10 @@ en:
|
|||
link_text: "their answer"
|
||||
other:
|
||||
link_text_html: "%{user}'s answer"
|
||||
dataexport:
|
||||
heading: "Your data export is ready"
|
||||
text_html: "Head over to %{settings_export} to download it."
|
||||
settings_export: "the settings page"
|
||||
reaction:
|
||||
heading_html: "%{user} smiled %{type} %{time} ago"
|
||||
answer:
|
||||
|
@ -396,7 +400,7 @@ en:
|
|||
<p>The data is inside a <code>.zip</code> archive that contains some JSON files.
|
||||
The archive also contains a copy of your profile picture and header picture in all sizes.</p>
|
||||
<p>Please note that you can only export your data once a week. Exporting your data
|
||||
will take a while, so please be patient. You will receive a question once exporting
|
||||
will take a while, so please be patient. You will receive a notification once exporting
|
||||
is done.</p>
|
||||
export: "Export"
|
||||
export_url:
|
||||
|
|
29
spec/workers/export_worker_spec.rb
Normal file
29
spec/workers/export_worker_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe ExportWorker do
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
describe "#perform" do
|
||||
let(:exporter_double) { double("Exporter") }
|
||||
|
||||
before do
|
||||
# stub away the testing of the exporter itself since it is done in lib/exporter_spec
|
||||
allow(exporter_double).to receive(:export)
|
||||
allow(Exporter).to receive(:new).and_return(exporter_double)
|
||||
end
|
||||
|
||||
subject { described_class.new.perform(user.id) }
|
||||
|
||||
it "creates an exported notification" do
|
||||
expect { subject }.to change { Notification::DataExported.count }.by(1)
|
||||
|
||||
notification = Notification::DataExported.last
|
||||
expect(notification.target_id).to eq(user.id)
|
||||
expect(notification.target_type).to eq("User::DataExport")
|
||||
expect(notification.recipient).to eq(user)
|
||||
expect(notification.new).to be true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue