notify_user 0.1.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -0
  3. data/Rakefile +7 -1
  4. data/app/controllers/notify_user/base_notifications_controller.rb +36 -35
  5. data/app/mailers/notify_user/notification_mailer.rb +1 -1
  6. data/app/models/notify_user/apn_connection.rb +35 -17
  7. data/app/models/notify_user/apns.rb +124 -14
  8. data/app/models/notify_user/base_notification.rb +172 -35
  9. data/app/models/notify_user/gcm.rb +58 -0
  10. data/app/models/notify_user/push.rb +37 -0
  11. data/app/models/notify_user/unsubscribe.rb +26 -9
  12. data/app/models/notify_user/urban_airship.rb +1 -1
  13. data/app/serializers/notify_user/notification_serializer.rb +1 -4
  14. data/config/routes.rb +2 -2
  15. data/lib/generators/notify_user/aggr_interval_update/USAGE +5 -0
  16. data/lib/generators/notify_user/aggr_interval_update/aggr_interval_update_generator.rb +36 -0
  17. data/lib/generators/notify_user/aggr_interval_update/templates/add_sent_time_to_notifications.rb +10 -0
  18. data/lib/generators/notify_user/aggr_interval_update/templates/update_unsubscribe.rb +6 -0
  19. data/lib/generators/notify_user/install/install_generator.rb +2 -5
  20. data/lib/generators/notify_user/install/templates/create_notify_user_notifications.rb +8 -0
  21. data/lib/generators/notify_user/install/templates/create_notify_user_unsubscribes.rb +5 -0
  22. data/lib/generators/notify_user/notification/notification_generator.rb +1 -0
  23. data/lib/notify_user/channels/action_mailer/action_mailer_channel.rb +1 -1
  24. data/lib/notify_user/channels/apns/apns_channel.rb +23 -23
  25. data/lib/notify_user/engine.rb +0 -1
  26. data/lib/notify_user/version.rb +1 -1
  27. data/spec/controllers/notify_user/notifications_controller_spec.rb +130 -108
  28. data/spec/dummy/rails-4.1.0/Gemfile +1 -1
  29. data/spec/dummy/rails-4.1.0/app/notifications/new_post_notification.rb +2 -6
  30. data/spec/dummy/{rails-4.0.4/app/views/notify_user/new_post_notification/mobile_sdk/notification.html.erb → rails-4.1.0/app/views/notify_user/new_post_notification/mobile_sdk/aggregate_notifications.html.erb} +0 -0
  31. data/spec/dummy/rails-4.1.0/app/views/notify_user/new_post_notification/mobile_sdk/notification.html.erb +1 -0
  32. data/spec/dummy/rails-4.1.0/config/environments/production.rb +1 -6
  33. data/spec/dummy/rails-4.1.0/config/initializers/assets.rb +8 -0
  34. data/spec/dummy/rails-4.1.0/config/initializers/notify_user.rb +10 -0
  35. data/spec/dummy/rails-4.1.0/config/secrets.yml +2 -2
  36. data/spec/dummy/{rails-3.2.17/db/migrate/20141102231350_create_users.rb → rails-4.1.0/db/migrate/20150907004705_create_users.rb} +0 -0
  37. data/spec/dummy/{rails-4.0.4/db/migrate/20141102231413669669843000_create_notify_user_notifications.rb → rails-4.1.0/db/migrate/20150907004707_create_notify_user_notifications.rb} +8 -0
  38. data/spec/dummy/rails-4.1.0/db/migrate/{20141102231434013013078000_create_notify_user_unsubscribes.rb → 20150907004708_create_notify_user_unsubscribes.rb} +5 -0
  39. data/spec/dummy/{rails-3.2.17/db/migrate/20141102231353651651843000_create_notify_user_user_hashes.rb → rails-4.1.0/db/migrate/20150907004709_create_notify_user_user_hashes.rb} +0 -0
  40. data/spec/dummy/rails-4.1.0/db/schema.rb +12 -1
  41. data/spec/dummy/rails-4.1.0/log/test.log +55083 -8099
  42. data/spec/dummy/rails-4.1.0/test/test_helper.rb +0 -3
  43. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/2iFf6DF21eHswaXamThRpysQhZa4HHhfXSwW0I26I_Q.cache +3 -0
  44. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/56gcPUZsFk_z-NC4BqxyzJ2fHeG-wa2DVNUK5iFQico.cache +0 -0
  45. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/8DepzOh5SIwaxC825zft8xeBhAi84AFjIkQLBafpfcI.cache +1 -0
  46. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/DFBSCnNmEyoM8roYdJ4CwzgAxnyRtTG3S2qD1ryqXxw.cache +1 -0
  47. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/DcdyyraxoBKSYh1m6Spmfn5Qtn0V2X2t8aO3dmAi0Po.cache +3 -0
  48. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/IO46kchRzb_wUQ8H3D25_DHv7lZK4CxthkOj6ZKp8mQ.cache +1 -0
  49. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/JTg9Khb4iQ4MkGt2OoYdfz6rYD9ccxMNxCOnVK92fJA.cache +1 -0
  50. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/O8akbUwAbmIKY-AhITimq-JDQ6IgsO3Hvq2v5etufFw.cache +2 -0
  51. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/RJrFPSmoXCFaapGXw1bP4Lg0NLmr9qG2RMuN56UrR7U.cache +0 -0
  52. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/TWJMA4bg5d25falxiw_TLK0GtSXWpfl0vFaFLRpkYKI.cache +1 -0
  53. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/XjnNasrgRd0l5xx4UR4IeE-Tz1EtjiPKwmizcf59P9U.cache +0 -0
  54. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/Y829B5qbE0t7idbBscHZCJxlb-D9S6G_8P6HwwMe7J4.cache +2 -0
  55. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/aXGU_8_bWOQw87gl5m_8fgEUtethSIj95P57d5YuW5k.cache +0 -0
  56. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/cjXxcrFHyMpHUOqA38Yaft85pmxR7gZ4__TFcgJQyKA.cache +1 -0
  57. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/cpoXvFR-s_2VM6kFm4ixeZKjW6en5HiD8B-ttj-iUSI.cache +0 -0
  58. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/hAsOx0KPt1yL2Nh2sDOmOIWrAfoEZo1RxZQkNop9FOU.cache +0 -0
  59. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/j52KuMJNJLJcKPVLf8rk8USLswZAmy6Hi1OW35JjVTo.cache +1 -0
  60. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/mwsAf4xggfO0hGKNns79uKcXG7B5rk8a4Zav3vXyr6M.cache +2 -0
  61. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/tPF6H9NRpGO3whu2y5_e_R_1EACKdCwu5437D83qJT0.cache +3 -0
  62. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/x5V5ICXz753PW9A8l6gpNAh_utfwyXyixuUxtMgJ2Pg.cache +1 -0
  63. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/y8AwtETeMIB25XCoxQDwn3DmMpUFLblIFK4yb18zN4c.cache +1 -0
  64. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/yWa5z3IIFR71QlDOGDwO5IpC9vsVUGFNfficVy0q3zo.cache +1 -0
  65. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/zDCAil6tD1zhO-gqs7OG9_zEEdMVEZo_aUkZjLHP53M.cache +0 -0
  66. data/spec/factories/notify_user_notifications.rb +4 -7
  67. data/spec/factories/users.rb +7 -0
  68. data/spec/lib/notify_user/channels/apns_channel_spec.rb +65 -0
  69. data/spec/mailers/notify_user/notification_mailer_spec.rb +24 -24
  70. data/spec/models/notify_user/apn_connection_spec.rb +29 -0
  71. data/spec/models/notify_user/apns_spec.rb +96 -0
  72. data/spec/models/notify_user/gcm_spec.rb +70 -0
  73. data/spec/models/notify_user/notification_spec.rb +456 -64
  74. data/spec/models/notify_user/unsubscribe_spec.rb +59 -16
  75. data/spec/models/notify_user/user_hash_spec.rb +11 -14
  76. data/spec/serializers/notify_user/notification_serializer_spec.rb +24 -6
  77. data/spec/setup_spec.rb +3 -4
  78. data/spec/spec_helper.rb +20 -12
  79. data/spec/support/test_apn_connection.rb +8 -0
  80. data/spec/support/test_gcm_connection.rb +5 -0
  81. metadata +131 -332
  82. data/app/models/notify_user/houston.rb +0 -101
  83. data/spec/dummy/rails-3.2.17/Gemfile +0 -38
  84. data/spec/dummy/rails-3.2.17/README.rdoc +0 -261
  85. data/spec/dummy/rails-3.2.17/Rakefile +0 -7
  86. data/spec/dummy/rails-3.2.17/app/assets/images/rails.png +0 -0
  87. data/spec/dummy/rails-3.2.17/app/assets/javascripts/application.js +0 -15
  88. data/spec/dummy/rails-3.2.17/app/assets/stylesheets/application.css +0 -13
  89. data/spec/dummy/rails-3.2.17/app/controllers/application_controller.rb +0 -3
  90. data/spec/dummy/rails-3.2.17/app/controllers/notify_user/notifications_controller.rb +0 -9
  91. data/spec/dummy/rails-3.2.17/app/helpers/application_helper.rb +0 -2
  92. data/spec/dummy/rails-3.2.17/app/models/user.rb +0 -3
  93. data/spec/dummy/rails-3.2.17/app/notifications/new_post_notification.rb +0 -15
  94. data/spec/dummy/rails-3.2.17/app/views/layouts/application.html.erb +0 -14
  95. data/spec/dummy/rails-3.2.17/app/views/notify_user/layouts/action_mailer.html.erb +0 -39
  96. data/spec/dummy/rails-3.2.17/app/views/notify_user/new_post_notification/action_mailer/notification.html.erb +0 -1
  97. data/spec/dummy/rails-3.2.17/config.ru +0 -4
  98. data/spec/dummy/rails-3.2.17/config/application.rb +0 -62
  99. data/spec/dummy/rails-3.2.17/config/boot.rb +0 -6
  100. data/spec/dummy/rails-3.2.17/config/database.yml +0 -24
  101. data/spec/dummy/rails-3.2.17/config/environment.rb +0 -5
  102. data/spec/dummy/rails-3.2.17/config/environments/development.rb +0 -37
  103. data/spec/dummy/rails-3.2.17/config/environments/production.rb +0 -67
  104. data/spec/dummy/rails-3.2.17/config/environments/test.rb +0 -37
  105. data/spec/dummy/rails-3.2.17/config/initializers/backtrace_silencers.rb +0 -7
  106. data/spec/dummy/rails-3.2.17/config/initializers/inflections.rb +0 -15
  107. data/spec/dummy/rails-3.2.17/config/initializers/mime_types.rb +0 -5
  108. data/spec/dummy/rails-3.2.17/config/initializers/notify_user.rb +0 -14
  109. data/spec/dummy/rails-3.2.17/config/initializers/secret_token.rb +0 -7
  110. data/spec/dummy/rails-3.2.17/config/initializers/session_store.rb +0 -8
  111. data/spec/dummy/rails-3.2.17/config/initializers/wrap_parameters.rb +0 -14
  112. data/spec/dummy/rails-3.2.17/config/keys/development_push.pem +0 -0
  113. data/spec/dummy/rails-3.2.17/config/locales/en.yml +0 -5
  114. data/spec/dummy/rails-3.2.17/config/routes.rb +0 -58
  115. data/spec/dummy/rails-3.2.17/db/migrate/20141102231353649649586000_create_notify_user_notifications.rb +0 -13
  116. data/spec/dummy/rails-3.2.17/db/migrate/20141102231353650650817000_create_notify_user_unsubscribes.rb +0 -10
  117. data/spec/dummy/rails-3.2.17/db/schema.rb +0 -50
  118. data/spec/dummy/rails-3.2.17/db/seeds.rb +0 -7
  119. data/spec/dummy/rails-3.2.17/doc/README_FOR_APP +0 -2
  120. data/spec/dummy/rails-3.2.17/log/test.log +0 -9574
  121. data/spec/dummy/rails-3.2.17/public/404.html +0 -26
  122. data/spec/dummy/rails-3.2.17/public/422.html +0 -26
  123. data/spec/dummy/rails-3.2.17/public/500.html +0 -25
  124. data/spec/dummy/rails-3.2.17/public/favicon.ico +0 -0
  125. data/spec/dummy/rails-3.2.17/public/index.html +0 -241
  126. data/spec/dummy/rails-3.2.17/public/robots.txt +0 -5
  127. data/spec/dummy/rails-3.2.17/script/rails +0 -6
  128. data/spec/dummy/rails-3.2.17/test/fixtures/users.yml +0 -7
  129. data/spec/dummy/rails-3.2.17/test/performance/browsing_test.rb +0 -12
  130. data/spec/dummy/rails-3.2.17/test/test_helper.rb +0 -13
  131. data/spec/dummy/rails-3.2.17/test/unit/user_test.rb +0 -7
  132. data/spec/dummy/rails-4.0.4/Gemfile +0 -45
  133. data/spec/dummy/rails-4.0.4/README.rdoc +0 -28
  134. data/spec/dummy/rails-4.0.4/Rakefile +0 -6
  135. data/spec/dummy/rails-4.0.4/app/assets/javascripts/application.js +0 -16
  136. data/spec/dummy/rails-4.0.4/app/assets/stylesheets/application.css +0 -13
  137. data/spec/dummy/rails-4.0.4/app/controllers/application_controller.rb +0 -5
  138. data/spec/dummy/rails-4.0.4/app/controllers/notify_user/notifications_controller.rb +0 -9
  139. data/spec/dummy/rails-4.0.4/app/helpers/application_helper.rb +0 -2
  140. data/spec/dummy/rails-4.0.4/app/models/user.rb +0 -2
  141. data/spec/dummy/rails-4.0.4/app/notifications/new_post_notification.rb +0 -15
  142. data/spec/dummy/rails-4.0.4/app/views/layouts/application.html.erb +0 -14
  143. data/spec/dummy/rails-4.0.4/app/views/notify_user/layouts/action_mailer.html.erb +0 -39
  144. data/spec/dummy/rails-4.0.4/app/views/notify_user/new_post_notification/action_mailer/notification.html.erb +0 -1
  145. data/spec/dummy/rails-4.0.4/bin/bundle +0 -3
  146. data/spec/dummy/rails-4.0.4/bin/rails +0 -4
  147. data/spec/dummy/rails-4.0.4/bin/rake +0 -4
  148. data/spec/dummy/rails-4.0.4/config.ru +0 -4
  149. data/spec/dummy/rails-4.0.4/config/application.rb +0 -23
  150. data/spec/dummy/rails-4.0.4/config/boot.rb +0 -4
  151. data/spec/dummy/rails-4.0.4/config/database.yml +0 -24
  152. data/spec/dummy/rails-4.0.4/config/environment.rb +0 -5
  153. data/spec/dummy/rails-4.0.4/config/environments/development.rb +0 -29
  154. data/spec/dummy/rails-4.0.4/config/environments/production.rb +0 -80
  155. data/spec/dummy/rails-4.0.4/config/environments/test.rb +0 -36
  156. data/spec/dummy/rails-4.0.4/config/initializers/backtrace_silencers.rb +0 -7
  157. data/spec/dummy/rails-4.0.4/config/initializers/filter_parameter_logging.rb +0 -4
  158. data/spec/dummy/rails-4.0.4/config/initializers/inflections.rb +0 -16
  159. data/spec/dummy/rails-4.0.4/config/initializers/mime_types.rb +0 -5
  160. data/spec/dummy/rails-4.0.4/config/initializers/notify_user.rb +0 -14
  161. data/spec/dummy/rails-4.0.4/config/initializers/secret_token.rb +0 -12
  162. data/spec/dummy/rails-4.0.4/config/initializers/session_store.rb +0 -3
  163. data/spec/dummy/rails-4.0.4/config/initializers/wrap_parameters.rb +0 -14
  164. data/spec/dummy/rails-4.0.4/config/keys/development_push.pem +0 -136
  165. data/spec/dummy/rails-4.0.4/config/locales/en.yml +0 -23
  166. data/spec/dummy/rails-4.0.4/config/routes.rb +0 -56
  167. data/spec/dummy/rails-4.0.4/db/migrate/20141102231412_create_users.rb +0 -9
  168. data/spec/dummy/rails-4.0.4/db/migrate/20141102231413670670945000_create_notify_user_unsubscribes.rb +0 -10
  169. data/spec/dummy/rails-4.0.4/db/migrate/20141102231413671671735000_create_notify_user_user_hashes.rb +0 -12
  170. data/spec/dummy/rails-4.0.4/db/schema.rb +0 -53
  171. data/spec/dummy/rails-4.0.4/db/seeds.rb +0 -7
  172. data/spec/dummy/rails-4.0.4/log/test.log +0 -45689
  173. data/spec/dummy/rails-4.0.4/public/404.html +0 -58
  174. data/spec/dummy/rails-4.0.4/public/422.html +0 -58
  175. data/spec/dummy/rails-4.0.4/public/500.html +0 -57
  176. data/spec/dummy/rails-4.0.4/public/favicon.ico +0 -0
  177. data/spec/dummy/rails-4.0.4/public/robots.txt +0 -5
  178. data/spec/dummy/rails-4.0.4/test/fixtures/users.yml +0 -7
  179. data/spec/dummy/rails-4.0.4/test/models/user_test.rb +0 -7
  180. data/spec/dummy/rails-4.0.4/test/test_helper.rb +0 -15
  181. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/0e8918f38b9bf3fc19fca4efda1600a1 +0 -0
  182. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  183. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/1bded108b40ef13c7e07be129e2cd83c +0 -0
  184. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/1ebdd9dfe7e88e90bee37951e2da1ea2 +0 -0
  185. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/23fe609acece1521082ad6b8249f96b1 +0 -0
  186. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  187. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  188. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/40fd179449501b801f80c852d1635a16 +0 -0
  189. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/4499e16a29d89bdf30304de41c456b43 +0 -0
  190. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/49088e1598df49c63ff7d874c97e958f +0 -0
  191. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/7398a3a743326d3576cbb05a000df04b +0 -0
  192. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/8eedfb1d9aee665c9f5a77df67b64a81 +0 -0
  193. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/91d718eeae4552c702b8eafd9e8bbe76 +0 -0
  194. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/9e2c26ef339b5827a5c296acb284ab99 +0 -0
  195. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/a4f2f445b4f8578493957e4f7b0c76e3 +0 -0
  196. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/af361e697648848dbf0282eba1d15c2f +0 -0
  197. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/af95fe3d35c9fe417700e8c3625329fe +0 -0
  198. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/b89f385c2540cb58f04dbfed561d3902 +0 -0
  199. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/bc1864fd5bfa875243b05071735cbb82 +0 -0
  200. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/bede0f0813e15081ea4ee32b640c92c4 +0 -0
  201. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/c1ba4e65491e8bb9fcdc38b22cb64aa9 +0 -0
  202. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/cb741827a22668ecf975f78242076b6b +0 -0
  203. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  204. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/d3516b65bb025bc333e0f91647a7b119 +0 -0
  205. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  206. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/df7c1d81da90fb0287da1e283291dc81 +0 -0
  207. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/f78ea05f6019d54c3572513ebae03556 +0 -0
  208. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/f7c2f64864ec1995aee8dcead45d7f24 +0 -0
  209. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  210. data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/fbbb5b21a4144f5e3efee9eda4fc38e5 +0 -0
  211. data/spec/dummy/rails-4.1.0/db/migrate/20141102231432_create_users.rb +0 -9
  212. data/spec/dummy/rails-4.1.0/db/migrate/20141102231434012012157000_create_notify_user_notifications.rb +0 -13
  213. data/spec/dummy/rails-4.1.0/db/migrate/20141102231434013013847000_create_notify_user_user_hashes.rb +0 -12
  214. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  215. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/1bded108b40ef13c7e07be129e2cd83c +0 -0
  216. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/1ebdd9dfe7e88e90bee37951e2da1ea2 +0 -0
  217. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/23fe609acece1521082ad6b8249f96b1 +0 -0
  218. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  219. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  220. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/3fa5cc1bc06bfb81887b971eb8d36258 +0 -0
  221. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/796287194e2490ae173cabd0f8e0fce7 +0 -0
  222. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/8d2563dcd2d59f9e020fc2623eda3999 +0 -0
  223. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/8ebc0d0c963e18c7c16e6e7f55fd379f +0 -0
  224. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/91d718eeae4552c702b8eafd9e8bbe76 +0 -0
  225. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/9e2c26ef339b5827a5c296acb284ab99 +0 -0
  226. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/a098882f88a8b3ca91d2efaada23dba3 +0 -0
  227. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/af361e697648848dbf0282eba1d15c2f +0 -0
  228. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/b89f385c2540cb58f04dbfed561d3902 +0 -0
  229. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/c1ba4e65491e8bb9fcdc38b22cb64aa9 +0 -0
  230. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/cb741827a22668ecf975f78242076b6b +0 -0
  231. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  232. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  233. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/df7c1d81da90fb0287da1e283291dc81 +0 -0
  234. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/f031b3342a7246183ffa1bb7819f293e +0 -0
  235. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/f78ea05f6019d54c3572513ebae03556 +0 -0
  236. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  237. data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/fbbb5b21a4144f5e3efee9eda4fc38e5 +0 -0
  238. data/spec/models/notify_user/houston_spec.rb +0 -33
@@ -0,0 +1,58 @@
1
+ require 'gcm'
2
+
3
+ module NotifyUser
4
+ class Gcm < Push
5
+ PAYLOAD_LIMIT = 4096
6
+
7
+ attr_accessor :client, :push_options
8
+
9
+ def initialize(notifications, devices, options)
10
+ super(notifications, devices, options)
11
+
12
+ @push_options = setup_options
13
+ end
14
+
15
+ def push
16
+ send_notifications
17
+ end
18
+
19
+ def client
20
+ @client ||= GCM.new(ENV['GCM_API_KEY'])
21
+ end
22
+
23
+ def valid?(payload)
24
+ payload.to_json.bytesize <= PAYLOAD_LIMIT
25
+ end
26
+
27
+ private
28
+
29
+ def setup_options
30
+ space_allowance = PAYLOAD_LIMIT - used_space
31
+ mobile_message = ''
32
+
33
+ if @notification.parent_id
34
+ parent = @notification.class.find(@notification.parent_id)
35
+ mobile_message = parent.mobile_message(space_allowance)
36
+ else
37
+ mobile_message = @notification.mobile_message(space_allowance)
38
+ end
39
+
40
+ {
41
+ data: {
42
+ notification_id: @notification.id,
43
+ message: mobile_message,
44
+ type: @options[:category] || @notification.type,
45
+ unread_count: @notification.count_for_target,
46
+ custom_data: @notification.params,
47
+ }
48
+ }
49
+ end
50
+
51
+ def send_notifications
52
+ return unless device_tokens.any?
53
+ response = client.send(device_tokens, @push_options)
54
+ # should be checking for errors in the response here
55
+ return true
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ module NotifyUser
2
+ class Push
3
+ SYMBOL_NAMES_SIZE = 10
4
+ PAYLOAD_LIMIT = 255
5
+
6
+ def initialize(notifications, devices, options)
7
+ @notifications = notifications
8
+ @notification = notifications.first
9
+
10
+ @devices = devices
11
+ @options = options
12
+ end
13
+
14
+ # Sends push notification:
15
+ def push
16
+ raise "Base APNS class should not be used."
17
+ end
18
+
19
+ private
20
+
21
+ attr_accessor :device_tokens
22
+
23
+ def device_tokens
24
+ @device_tokens = @devices.map(&:token)
25
+ end
26
+
27
+ # Calculates the bytes already used:
28
+ def used_space
29
+ used_space = SYMBOL_NAMES_SIZE + @notification.id.size + @notification.created_at.to_time.to_i.size +
30
+ @notification.type.size
31
+
32
+ used_space += @notification.params[:action_id].size if @notification.params[:action_id]
33
+
34
+ used_space
35
+ end
36
+ end
37
+ end
@@ -12,7 +12,7 @@ module NotifyUser
12
12
  self.inheritance_column = :_type_disabled
13
13
 
14
14
  if Rails.version.to_i < 4
15
- attr_accessible :target, :type
15
+ attr_accessible :target, :type, :group_id
16
16
  end
17
17
 
18
18
  def self.for_target(target)
@@ -21,24 +21,41 @@ module NotifyUser
21
21
  end
22
22
 
23
23
  def self.toggle_status(target, type)
24
- if NotifyUser::Unsubscribe.has_unsubscribed_from(target, type).empty?
25
- NotifyUser::Unsubscribe.create(target: target, type: type)
24
+ if NotifyUser::Unsubscribe.has_unsubscribed_from?(target, type)
25
+ NotifyUser::Unsubscribe.subscribe(target, type)
26
26
  else
27
27
  NotifyUser::Unsubscribe.unsubscribe(target,type)
28
- end
28
+ end
29
29
  end
30
30
 
31
- def self.unsubscribe(target, type)
31
+ def self.unsubscribe(target, type, group_id=nil)
32
+ ## creates unsubscribe object if it doesn't already exist
33
+ unless exists?(target_id: target.id, target_type: target.class.base_class,
34
+ type: type, group_id: group_id)
35
+ create(target: target, type: type, group_id: group_id)
36
+ end
37
+ end
38
+
39
+ def self.subscribe(target, type, group_id=nil)
32
40
  #deletes unsubscribe object in essence subscribing a user
33
41
  where(target_id: target.id)
34
42
  .where(target_type: target.class.base_class)
35
- .where(type: type).destroy_all
36
- end
43
+ .where(type: type, group_id: group_id).destroy_all
44
+ end
45
+
46
+ ## checks to see if you've unsubscribed from the overall notification type
47
+ ## before checking you've unsubscribed from the specific group_id
48
+ def self.has_unsubscribed_from?(target, type, group_id=nil, channel_name=nil)
49
+ return true if where(target_id: target.id, target_type: target.class.base_class).where(type: type).any?
50
+ return true if where(target_id: target.id, target_type: target.class.base_class, type: type, group_id: group_id).any? if group_id
51
+ return true if where(target_id: target.id, target_type: target.class.base_class, type: channel_name).any? if channel_name
52
+ false
53
+ end
37
54
 
38
- def self.has_unsubscribed_from(target, type)
55
+ def self.has_unsubscribed_from(target, type, group_id=nil)
39
56
  where(target_id: target.id)
40
57
  .where(target_type: target.class.base_class)
41
- .where(type: type)
58
+ .where(type: type, group_id: group_id)
42
59
  end
43
60
 
44
61
  end
@@ -1,5 +1,5 @@
1
1
  module NotifyUser
2
- class UrbanAirship < Apns
2
+ class UrbanAirship < Push
3
3
 
4
4
  def push
5
5
  space_allowance = PAYLOAD_LIMIT - used_space
@@ -5,10 +5,7 @@ class NotifyUser::NotificationSerializer < ActiveModel::Serializer
5
5
  attributes :id, :type, :message, :read, :params, :created_at
6
6
 
7
7
  def message
8
- string = options[:template_renderer].render_to_string(:template => object.class.views[:mobile_sdk][:template_path].call(object),
9
- :locals => {params: object.params},
10
- :layout => false, :formats => [:html])
11
- return ::CGI.unescapeHTML("#{string}")
8
+ object.message
12
9
  end
13
10
 
14
11
  def read
data/config/routes.rb CHANGED
@@ -4,13 +4,13 @@ Rails.application.routes.draw do
4
4
  put 'notifications/mark_read' => 'notifications#mark_read'
5
5
  get 'notifications/notifications_count' => 'notifications#notifications_count'
6
6
  get 'notifications/:id/read' => 'notifications#read'
7
- get 'notifications/mark_all' => 'notifications#mark_all'
7
+ put 'notifications/mark_all' => 'notifications#mark_all'
8
8
  get 'notifications/unsubscribe' => 'notifications#unsubscribe'
9
9
  get 'notifications/subscribe' => 'notifications#subscribe'
10
10
  get 'notifications/unauth_unsubscribe' => 'notifications#unauth_unsubscribe'
11
11
  get 'notifications/subscriptions' => 'notifications#subscriptions'
12
12
  put 'notifications/subscriptions' => 'notifications#subscriptions'
13
13
  put 'notifications/mass_subscriptions' => 'notifications#mass_subscriptions'
14
-
14
+ put 'notification/unsubscribe_from_object' => 'notifications#unsubscribe_from_object'
15
15
  end
16
16
  end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Add sent_time column to notifications
3
+
4
+ Example:
5
+ rails generate notify_user:aggr_interval_update
@@ -0,0 +1,36 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class NotifyUser::AggrIntervalUpdateGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_migrations
9
+ copy_migration "add_sent_time_to_notifications"
10
+ copy_migration "update_unsubscribes"
11
+
12
+ puts "Update successful. You can now run:"
13
+ puts " rake db:migrate"
14
+ end
15
+
16
+ # This is defined in ActiveRecord::Generators::Base, but that inherits from NamedBase, so it expects a name argument
17
+ # which we don't want here. So we redefine it here. Yuck.
18
+ def self.next_migration_number(dirname)
19
+ if ActiveRecord::Base.timestamped_migrations
20
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
21
+ else
22
+ "%.3d" % (current_migration_number(dirname) + 1)
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def copy_migration(filename)
29
+ if self.class.migration_exists?("db/migrate", "#{filename}")
30
+ say_status("skipped", "Migration #{filename}.rb already exists")
31
+ else
32
+ migration_template "#{filename}.rb", "db/migrate/#{filename}.rb"
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,10 @@
1
+ class AddSentTimeToNotifications < ActiveRecord::Migration
2
+ def change
3
+ add_column :notify_user_notifications, :sent_time, :datetime
4
+ add_column :notify_user_notifications, :group_id, :integer
5
+ add_column :notify_user_notifications, :parent_id, :integer
6
+
7
+ add_index :notify_user_notifications, :group_id
8
+ add_index :notify_user_notifications, :parent_id
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class UpdateUnsubscribe < ActiveRecord::Migration
2
+ def change
3
+ add_column :notify_user_unsubscribes, :group_id, :integer
4
+ add_index :notify_user_unsubscribes, :group_id
5
+ end
6
+ end
@@ -25,11 +25,8 @@ class NotifyUser::InstallGenerator < Rails::Generators::Base
25
25
  # This is defined in ActiveRecord::Generators::Base, but that inherits from NamedBase, so it expects a name argument
26
26
  # which we don't want here. So we redefine it here. Yuck.
27
27
  def self.next_migration_number(dirname)
28
- if ActiveRecord::Base.timestamped_migrations
29
- Time.now.utc.strftime("%Y%m%d%H%M%S%L%N")
30
- else
31
- "%.3d" % (current_migration_number(dirname) + 1)
32
- end
28
+ next_migration_number = current_migration_number(dirname) + 1
29
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
33
30
  end
34
31
 
35
32
  protected
@@ -6,8 +6,16 @@ class CreateNotifyUserNotifications < ActiveRecord::Migration
6
6
  t.string :target_type
7
7
  t.json :params
8
8
  t.string :state
9
+ t.datetime :sent_time
10
+
11
+ t.integer :group_id
12
+ t.integer :parent_id
9
13
 
10
14
  t.timestamps
11
15
  end
16
+
17
+ add_index :notify_user_notifications, :group_id
18
+ add_index :notify_user_notifications, :parent_id
19
+ add_index :notify_user_notifications, :target_id
12
20
  end
13
21
  end
@@ -4,7 +4,12 @@ class CreateNotifyUserUnsubscribes < ActiveRecord::Migration
4
4
  t.string :type
5
5
  t.integer :target_id
6
6
  t.string :target_type
7
+
8
+ t.integer :group_id
7
9
  t.timestamps
8
10
  end
11
+
12
+ add_index :notify_user_unsubscribes, :group_id
13
+ add_index :notify_user_unsubscribes, :target_id
9
14
  end
10
15
  end
@@ -12,6 +12,7 @@ module NotifyUser
12
12
  def generate_view_scaffolds
13
13
  template "email_template.html.erb.erb", "app/views/notify_user/#{name.underscore}/action_mailer/notification.html.erb"
14
14
  template "mobile_sdk_template.html.erb.erb", "app/views/notify_user/#{name.underscore}/mobile_sdk/notification.html.erb"
15
+ template "mobile_sdk_template.html.erb.erb", "app/views/notify_user/#{name.underscore}/mobile_sdk/aggregate_notifications.html.erb"
15
16
  template "email_layout_template.html.erb.erb", "app/views/notify_user/layouts/action_mailer.html.erb"
16
17
  end
17
18
  end
@@ -11,7 +11,7 @@ class ActionMailerChannel
11
11
  description: "Email Notifications"
12
12
  }
13
13
  end
14
-
14
+
15
15
  def deliver(notification, options={})
16
16
  NotifyUser::NotificationMailer.notification_email(notification, default_options.deep_merge(options)).deliver
17
17
  end
@@ -1,5 +1,4 @@
1
1
  class ApnsChannel
2
-
3
2
  class << self
4
3
 
5
4
  def default_options
@@ -9,28 +8,29 @@ class ApnsChannel
9
8
  end
10
9
 
11
10
  def deliver(notification, options={})
12
- case NotifyUser.apns_provider
13
- when :houston
14
- NotifyUser::Houston.new(notification, options).push
15
- when :urban_airship
16
- # Check for the existence of development api keys and resend for development:
17
- if !ENV['DEV_UA_APPLICATION_KEY'].nil? && !ENV['DEV_UA_APPLICATION_SECRET'].nil? && !ENV['DEV_UA_MASTER_SECRET'].nil?
18
-
19
- Urbanairship.application_key = ENV['DEV_UA_APPLICATION_KEY']
20
- Urbanairship.application_secret = ENV['DEV_UA_APPLICATION_SECRET']
21
- Urbanairship.master_secret = ENV['DEV_UA_MASTER_SECRET']
22
-
23
- NotifyUser::UrbanAirship.new(notification).push
24
-
25
- # Sets the api keys back to their original state:
26
-
27
- Urbanairship.application_key = ENV['UA_APPLICATION_KEY']
28
- Urbanairship.application_secret = ENV['UA_APPLICATION_SECRET']
29
- Urbanairship.master_secret = ENV['UA_MASTER_SECRET']
30
- end
31
- end
11
+ devices = fetch_devices(notification, options[:device_method])
12
+
13
+ NotifyUser::Apns.new([notification], devices[:ios], options).push if devices[:ios].any?
14
+ NotifyUser::Gcm.new([notification], devices[:android], options).push if devices[:android].any?
32
15
  end
33
16
 
34
- end
17
+ def deliver_aggregated(notifications, options={})
18
+ devices = fetch_devices(notifications.first, options[:device_method])
19
+
20
+ NotifyUser::Apns.new(notifications, devices[:ios], options).push if devices[:ios].any?
21
+ NotifyUser::Gcm.new(notifications, devices[:android], options).push if devices[:android].any?
22
+ end
35
23
 
36
- end
24
+ private
25
+
26
+ def fetch_devices(notification, device_method = nil)
27
+ device_method ||= :devices
28
+ devices = notification.target.send(device_method)
29
+
30
+ { ios: devices.ios.to_a, android: devices.android.to_a }
31
+ rescue
32
+ Rails.logger.info "Notification target, #{notification.target.class}, does not respond to the method, #{device_method}."
33
+ { ios: [], android: [] }
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,6 @@
1
1
  module NotifyUser
2
2
  class Engine < ::Rails::Engine
3
3
  require 'active_model_serializers'
4
- require 'urbanairship'
5
4
 
6
5
  config.generators do |g|
7
6
  g.test_framework :rspec, :fixture => false
@@ -1,3 +1,3 @@
1
1
  module NotifyUser
2
- VERSION = "0.1.4"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -1,142 +1,164 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module NotifyUser
4
+ describe NotificationsController, type: :controller do
5
+ let(:user) { create(:user) }
3
6
 
4
- describe NotifyUser::NotificationsController do
7
+ before :each do
8
+ allow_any_instance_of(NotificationsController).to receive(:current_user).and_return(user)
9
+ allow_any_instance_of(NotificationsController).to receive(:authenticate_user!).and_return(true)
10
+ end
5
11
 
6
- let(:user) { User.create({email: "user@example.com" })}
12
+ it 'delegates authentication to Devise' do
13
+ expect(subject).to receive(:authenticate_user!).and_return(true)
14
+ get :index
15
+ end
7
16
 
8
- before :each do
9
- NotifyUser::NotificationsController.any_instance.stub(:current_user).and_return(user)
10
- NotifyUser::NotificationsController.any_instance.stub(:authenticate_user!).and_return(true)
11
- end
17
+ describe 'GET notifications.json' do
18
+ render_views
12
19
 
13
- it "delegates authentication to Devise" do
14
- subject.should_receive(:authenticate_user!).and_return(true)
15
- subject.stub(:current_user).and_return(user)
16
- get :index
17
- end
20
+ let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: 'Mr. Blobby') }
18
21
 
19
- describe "GET notifications.json" do
20
- render_views
22
+ before :each do
23
+ notification.save
24
+ end
21
25
 
22
- let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Blobby") }
26
+ it 'returns a message from a rendered template' do
27
+ get :index, format: :json
28
+ expect(json[:notifications][0][:message]).to include 'New Post Notification happened with'
29
+ expect(json[:notifications][0][:message]).to include notification.params[:name]
30
+ end
23
31
 
24
- before :each do
25
- notification.save
26
- end
32
+ it 'returns notification without parent_id set' do
33
+ get :index, format: :json
34
+ expect(json[:notifications].count).to eq 1
35
+ end
27
36
 
28
- it "returns a message from a rendered template" do
29
- get :index, :format => :json
30
- json[:notifications][0][:message].should include "New Post Notification happened with"
31
- json[:notifications][0][:message].should include notification.params[:name]
32
- end
33
- end
34
-
35
- describe "GET web Index notifications" do
36
- render_views
37
+ it "doesn't return notifications with a parent_id set" do
38
+ NewPostNotification.create(target: user, parent_id: 1)
37
39
 
38
- let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Blobby") }
39
- let(:notification1) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Adams") }
40
- let(:notification2) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mrs. James") }
41
-
42
- before :each do
43
- notification.save
44
- notification1.save
45
- notification2.save
40
+ get :index, format: :json
41
+ expect(json[:notifications].count).to eq 1
42
+ end
46
43
  end
47
44
 
48
- it "returns a list of notifications" do
49
- NotifyUser::BaseNotification.any_instance.stub(:message).and_return("Mr. Blobby")
50
- get :index
51
- response.body.should have_content("Mr. Blobby")
52
- end
45
+ describe 'GET web Index notifications' do
46
+ render_views
53
47
 
54
- it "reading a notification marks it as read and takes to redirect action" do
55
- get :read, :id => notification.id
56
- @notification = NotifyUser::BaseNotification.where(id: notification.id).first
57
- @notification.state.should eq "read"
58
- response.body.should have_content("set redirect logic")
59
- end
48
+ let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: 'Mr. Blobby') }
49
+ let(:notification1) { NotifyUser.send_notification('new_post_notification').to(user).with(name: 'Mr. Addams') }
50
+ let(:notification2) { NotifyUser.send_notification('new_post_notification').to(user).with(name: 'Mrs. James') }
60
51
 
61
- it "reading a notification twice doesn't throw an exception" do
62
- get :read, :id => notification.id
63
- get :read, :id => notification.id
64
-
65
- end
52
+ before :each do
53
+ notification.save
54
+ notification1.save
55
+ notification2.save
56
+ end
66
57
 
67
- it "marks all unread messages as read" do
68
- get :mark_all
69
- notifications = NotifyUser::BaseNotification.for_target(user).where('state IN (?)', '["pending","sent"]')
70
- notifications.length.should eq 0
71
- end
58
+ it 'returns a list of notifications' do
59
+ allow_any_instance_of(BaseNotification).to receive(:message).and_return('Mr. Blobby')
60
+ get :index
61
+ expect(response.body).to have_content('Mr. Blobby')
62
+ end
72
63
 
73
- end
64
+ it 'reading a notification marks it as read and takes to redirect action' do
65
+ get :read, id: notification.id
66
+ @notification = BaseNotification.where(id: notification.id).first
67
+ expect(@notification.state).to eq 'read'
68
+ expect(response.body).to have_content('set redirect logic')
69
+ end
74
70
 
75
- describe "PUT notifications/mark_read.json" do
76
- let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Blobby") }
71
+ it "reading a notification twice doesn't throw an exception" do
72
+ expect do
73
+ get :read, id: notification.id
74
+ get :read, id: notification.id
75
+ end.not_to raise_error
76
+ end
77
77
 
78
- before :each do
79
- notification.save
78
+ it 'marks all unread messages as read' do
79
+ get :mark_all
80
+ notifications = BaseNotification.for_target(user).where('state IN (?)', '["pending","sent"]')
81
+ expect(notifications.length).to eq 0
82
+ end
80
83
  end
81
84
 
82
- it "marks notifications as read" do
83
- put :mark_read, ids: [notification.id]
84
- notification.reload
85
- notification.read?.should eq true
86
- end
85
+ describe 'PUT notifications/unsubscribe_from_object' do
86
+ it 'unsubscribe returns 201' do
87
+ expect(Unsubscribe).to receive(:unsubscribe)
88
+ put :unsubscribe_from_object, format: :json, subscription: { type: 'NewPostNotification', group_id: 1, unsubscribe: true }
89
+ expect(response.response_code).to eq 201
90
+ end
87
91
 
88
- it "returns updated notifications" do
89
- put :mark_read, ids: [notification.id]
90
- json[:notifications][0].should_not be_nil
92
+ it 'subscribe returns 201' do
93
+ expect(Unsubscribe).to receive(:subscribe)
94
+ put :unsubscribe_from_object, format: :json, subscription: { type: 'NewPostNotification', group_id: 1, unsubscribe: false }
95
+ expect(response.response_code).to eq 201
96
+ end
91
97
  end
92
- end
93
98
 
94
- describe "unsubscribing and subscribing" do
95
- let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: "Mr. Blobby") }
99
+ describe 'PUT notifications/mark_read.json' do
100
+ let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: 'Mr. Blobby') }
96
101
 
97
- before :each do
98
- notification.save
99
- end
102
+ before :each do
103
+ notification.save
104
+ end
100
105
 
101
- it "endpoint for updating notification subscription statuses" do
102
- NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should eq []
103
- put :subscriptions, :types => [{
104
- type: 'NewPostNotification',
105
- status: '0'
106
- }]
107
- NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should_not eq []
108
- end
106
+ it 'marks notifications as read' do
107
+ put :mark_read, ids: [notification.id]
108
+ notification.reload
109
+ expect(notification.read?).to eq true
110
+ end
109
111
 
110
- it "endpoint for updating notification subscription statuses passing 1 does nothing" do
111
- NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should eq []
112
- put :subscriptions, :types => [{
113
- type: 'NewPostNotification',
114
- status: '1'
112
+ it 'returns updated notifications' do
113
+ put :mark_read, ids: [notification.id]
114
+ expect(json[:notifications][0]).not_to be_nil
115
+ end
116
+ end
117
+
118
+ describe 'unsubscribing and subscribing' do
119
+ let(:notification) { NotifyUser.send_notification('new_post_notification').to(user).with(name: 'Mr. Blobby') }
120
+
121
+ before :each do
122
+ notification.save
123
+ end
124
+
125
+ it 'endpoint for updating notification subscription statuses' do
126
+ expect(Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification')).to eq []
127
+ put :subscriptions, types: [{
128
+ type: 'NewPostNotification',
129
+ status: '0'
115
130
  }]
116
- NotifyUser::Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification').should eq []
117
- end
118
-
119
- it "unsubscribing from notification type" do
120
- get :unsubscribe, :type => "NewPostNotification"
121
- NotifyUser::Unsubscribe.last.type.should eq "NewPostNotification"
122
- end
131
+ expect(Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification')).not_to eq []
132
+ end
133
+
134
+ it 'endpoint for updating notification subscription statuses passing 1 does nothing' do
135
+ expect(Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification')).to eq []
136
+ put :subscriptions, types: [{
137
+ type: 'NewPostNotification',
138
+ status: '1'
139
+ }]
140
+ expect(Unsubscribe.has_unsubscribed_from(user, 'NewPostNotification')).to eq []
141
+ end
123
142
 
124
- it "subscribing deletes the unsubscribe object" do
125
- #lack of unsubscribe object implies the user is subscribed
126
- NotifyUser::Unsubscribe.create(target: user, type: "NewPostNotification")
127
- get :subscribe, :type => "NewPostNotification"
128
- NotifyUser::Unsubscribe.all.should eq []
143
+ it 'unsubscribing from notification type' do
144
+ get :unsubscribe, type: 'NewPostNotification'
145
+ expect(Unsubscribe.last.type).to eq 'NewPostNotification'
146
+ end
129
147
 
130
- end
148
+ it 'subscribing deletes the unsubscribe object' do
149
+ # lack of unsubscribe object implies the user is subscribed
150
+ Unsubscribe.create(target: user, type: 'NewPostNotification')
151
+ get :subscribe, type: 'NewPostNotification'
152
+ expect(Unsubscribe.all).to eq []
153
+ end
131
154
 
132
- it "verifies user token before unsubscribe then deactivates that token" do
133
- user_hash = notification.generate_unsubscribe_hash
134
- get :unauth_unsubscribe, :type => "NewPostNotification", :token => user_hash.token
155
+ it 'verifies user token before unsubscribe then deactivates that token' do
156
+ user_hash = notification.generate_unsubscribe_hash
157
+ get :unauth_unsubscribe, type: 'NewPostNotification', token: user_hash.token
135
158
 
136
- user_hash = NotifyUser::UserHash.last
137
- user_hash.active.should eq false
159
+ user_hash = UserHash.last
160
+ expect(user_hash.active).to eq false
161
+ end
138
162
  end
139
-
140
163
  end
141
-
142
- end
164
+ end