Dont save `fun` logs
parent
9ca66c1760
commit
a333bfd616
|
@ -12,6 +12,7 @@ module Api
|
|||
.map { |i| new_log(i) }
|
||||
.select { |i| i.success? }
|
||||
.map { |i| i.result }
|
||||
.select { |i| i.meta["type"] != "fun"}
|
||||
.tap { |i| Log.transaction { i.map(&:save) } }
|
||||
.tap { current_device.limit_log_length }
|
||||
when Hash
|
||||
|
|
|
@ -21,7 +21,7 @@ describe Api::LogsController do
|
|||
sign_in user
|
||||
before_count = Log.count
|
||||
post :create,
|
||||
body: { meta: { x: 1, y: 2, z: 3, type: "fun" },
|
||||
body: { meta: { x: 1, y: 2, z: 3, type: "info" },
|
||||
channels: ["toast"],
|
||||
message: "Hello, world!"
|
||||
}.to_json,
|
||||
|
@ -29,7 +29,7 @@ describe Api::LogsController do
|
|||
expect(response.status).to eq(200)
|
||||
expect(Log.count).to be > before_count
|
||||
expect(Log.last.message).to eq("Hello, world!")
|
||||
expect(Log.last.device).to eq(user.device)
|
||||
expect(Log.last.device).to eq(user.device)
|
||||
end
|
||||
|
||||
it 'creates many logs (with an Array)' do
|
||||
|
@ -37,13 +37,13 @@ describe Api::LogsController do
|
|||
before_count = Log.count
|
||||
post :create,
|
||||
body: [
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "fun" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "info" },
|
||||
channels: ["toast"],
|
||||
message: "one" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "fun" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "info" },
|
||||
channels: ["toast"],
|
||||
message: "two" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "fun" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "info" },
|
||||
channels: ["toast"],
|
||||
message: "three" },
|
||||
].to_json,
|
||||
|
@ -52,9 +52,29 @@ describe Api::LogsController do
|
|||
expect(Log.count).to eq(before_count + 3)
|
||||
end
|
||||
|
||||
it 'does not bother saving `fun` logs' do
|
||||
sign_in user
|
||||
before_count = Log.count
|
||||
post :create,
|
||||
body: [
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "info" },
|
||||
channels: ["toast"],
|
||||
message: "one" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "fun" },
|
||||
channels: [],
|
||||
message: "two" },
|
||||
{ meta: { x: 1, y: 2, z: 3, type: "info" },
|
||||
channels: [],
|
||||
message: "three" },
|
||||
].to_json,
|
||||
params: {format: :json}
|
||||
expect(response.status).to eq(200)
|
||||
expect(Log.count).to eq(before_count + 2)
|
||||
end
|
||||
|
||||
it 'Runs compaction when the logs pile up' do
|
||||
stub = {
|
||||
meta: { x: 1, y: 2, z: 3, type: "fun" }, channels: ["toast"],
|
||||
meta: { x: 1, y: 2, z: 3, type: "info" }, channels: ["toast"],
|
||||
message: "one" }
|
||||
payl = []
|
||||
100.times { payl.push(stub) }
|
||||
|
|
|
@ -11,7 +11,8 @@ describe Api::PasswordResetsController do
|
|||
old_email_count = ActionMailer::Base.deliveries.length
|
||||
post :create, params: params
|
||||
expect(response.status).to eq(200)
|
||||
sleep 0.4 # Mail deliveries occur in background thread.
|
||||
sleep 0.5 # Mail deliveries occur in background thread. TODO: Fix this
|
||||
# `sleep` nonsense the right way.
|
||||
expect(ActionMailer::Base.deliveries.length).to be > old_email_count
|
||||
message = ActionMailer::Base.deliveries.last.to_s
|
||||
expect(message).to include("password reset")
|
||||
|
|
Loading…
Reference in New Issue