Skip to content

Commit 541a138

Browse files
committed
seperate ios push notification action
1 parent 98e5141 commit 541a138

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

app/controllers/admin/events_controller.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ def duplicate
77
def publish
88
event = Event.find(params[:id])
99
UsergroupMailer.invitation_mail(event).deliver_now!
10-
push_app_notification(event)
1110
event.update_attributes! published: true
1211

1312
redirect_to url_for(controller: "/admin/events", action: :edit, id: event.id), notice: "Published!"
1413
end
1514

16-
private
15+
def send_ios_push_notification
16+
event = Event.find(params[:id])
1717

18-
def push_app_notification(event)
1918
options = {
2019
channel: Whitelabel[:label_id],
2120
alert: "#{I18n.tw('name')}: new event at #{I18n.l(event.date)}",
2221
content_available: true
2322
}
2423

2524
ZeroPush.broadcast(options)
25+
26+
redirect_to url_for(controller: "/admin/events", action: :show, id: event.id), alert: "iOS Push Notification sent!"
2627
end
2728
end

app/views/admin/dashboard/_sidebar.slim

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
h3 Event Actions
22

3-
- if unpublished = Event.unpublished
3+
- if events = Event.latest.limit(5)
4+
h4 Latest 5 Events
5+
ul
6+
- events.each do |event|
7+
li
8+
= "#{event.name}: "
9+
= link_to("tweet", twitter_update_url(event))
10+
= " / "
11+
= link_to("send ios push notification", url_for(controller: "/admin/events", action: :send_ios_push_notification, id: event.id))
12+
13+
- unless (unpublished = Event.unpublished).empty?
14+
h4 Unpublished
415
ul
516
- unpublished.each do |event|
617
li

spec/controllers/admin/events_controller_spec.rb

+13-5
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@
2828
it "publish the event" do
2929
event = create(:event)
3030

31+
expect {
32+
get :publish, id: event.id
33+
}.to change {
34+
ActionMailer::Base.deliveries.size
35+
}.by(1)
36+
end
37+
end
38+
39+
context "GET :send_ios_push_notification" do
40+
it "send notification with zeropush" do
41+
event = create(:event)
42+
3143
expect(ZeroPush).to receive(:broadcast).with({
3244
channel: Whitelabel[:label_id],
3345
alert: "#{I18n.tw("name")}: new event at #{I18n.l(event.date)}",
3446
content_available: true
3547
})
3648

37-
expect {
38-
get :publish, id: event.id
39-
}.to change {
40-
ActionMailer::Base.deliveries.size
41-
}.by(1)
49+
get :send_ios_push_notification, id: event.id
4250
end
4351
end
4452
end

0 commit comments

Comments
 (0)