Skip to content

Commit 99edf4b

Browse files
authored
Merge pull request #434 from coopdevs/develop
Release v1.9.1
2 parents a118ba1 + cd18f3e commit 99edf4b

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

app/models/push_notification.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class PushNotification < ActiveRecord::Base
22
belongs_to :event, foreign_key: 'event_id'
33
belongs_to :device_token, foreign_key: 'device_token_id'
44

5-
validates :event, :device_token, :title, presence: true
5+
validates :event, :device_token, presence: true
6+
validates :title, :body, presence: true, allow_blank: false
67

78
delegate :token, to: :device_token
89
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class ProcessInvalidPushNotifications < ActiveRecord::Migration
2+
def up
3+
PushNotification.where(processed_at: nil).find_in_batches do |batch|
4+
batch.each do |push_notification|
5+
unless push_notification.valid?
6+
now = Time.now.utc
7+
push_notification.update_columns(processed_at: now, updated_at: now)
8+
puts "Updating invalid PushNotification ##{push_notification.id}"
9+
end
10+
end
11+
end
12+
end
13+
14+
def down
15+
puts 'no.'
16+
end
17+
end

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20180831161349) do
14+
ActiveRecord::Schema.define(version: 20180924164456) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"

spec/jobs/send_push_notifications_job_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
:push_notification,
1313
event: event_created,
1414
device_token: device_token,
15-
title: 'A new Post hase been created.'
15+
title: 'A new Post hase been created.',
16+
body: 'A push notification body.'
1617
)
1718
end
1819
let(:processed_push_notification) do
@@ -21,6 +22,7 @@
2122
event: event_updated,
2223
device_token: device_token,
2324
title: 'A new Post hase been created.',
25+
body: 'A push notification body.',
2426
processed_at: Time.zone.now
2527
)
2628
end

spec/models/push_notification_spec.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
require 'spec_helper'
22

33
RSpec.describe PushNotification do
4+
let!(:event) { Fabricate.build(:event) }
5+
let!(:device_token) { Fabricate.build(:device_token, token: 'token') }
6+
let!(:push_notification) { described_class.new(device_token: device_token) }
7+
48
describe 'Validations' do
59
it { is_expected.to validate_presence_of(:event) }
610
it { is_expected.to validate_presence_of(:device_token) }
711
it { is_expected.to validate_presence_of(:title) }
12+
it { is_expected.to validate_presence_of(:body) }
13+
end
14+
15+
describe 'Not blank validations' do
16+
let(:valid_push_notification) {
17+
PushNotification.new(
18+
event: event,
19+
device_token: device_token,
20+
title: "A title",
21+
body: "A body"
22+
)
23+
}
24+
25+
it 'validates non blank fields' do
26+
expect(valid_push_notification).to be_valid
27+
28+
valid_push_notification.tap do |with_blank_title|
29+
with_blank_title.title = ''
30+
expect(with_blank_title).to_not be_valid
31+
end
32+
33+
valid_push_notification.tap do |with_blank_body|
34+
with_blank_body.body = ''
35+
expect(with_blank_body).to_not be_valid
36+
end
37+
end
838
end
939

1040
describe 'Associations' do
@@ -16,9 +46,6 @@
1646
end
1747

1848
describe "#token" do
19-
let(:device_token) { Fabricate.build(:device_token, token: 'token') }
20-
let(:push_notification) { described_class.new(device_token: device_token) }
21-
2249
it 'returns the associated DeviceToken\'s token' do
2350
expect(push_notification.token).to eq('token')
2451
end

0 commit comments

Comments
 (0)