notify_user 0.1.4 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/Rakefile +7 -1
- data/app/controllers/notify_user/base_notifications_controller.rb +36 -35
- data/app/mailers/notify_user/notification_mailer.rb +1 -1
- data/app/models/notify_user/apn_connection.rb +35 -17
- data/app/models/notify_user/apns.rb +124 -14
- data/app/models/notify_user/base_notification.rb +172 -35
- data/app/models/notify_user/gcm.rb +58 -0
- data/app/models/notify_user/push.rb +37 -0
- data/app/models/notify_user/unsubscribe.rb +26 -9
- data/app/models/notify_user/urban_airship.rb +1 -1
- data/app/serializers/notify_user/notification_serializer.rb +1 -4
- data/config/routes.rb +2 -2
- data/lib/generators/notify_user/aggr_interval_update/USAGE +5 -0
- data/lib/generators/notify_user/aggr_interval_update/aggr_interval_update_generator.rb +36 -0
- data/lib/generators/notify_user/aggr_interval_update/templates/add_sent_time_to_notifications.rb +10 -0
- data/lib/generators/notify_user/aggr_interval_update/templates/update_unsubscribe.rb +6 -0
- data/lib/generators/notify_user/install/install_generator.rb +2 -5
- data/lib/generators/notify_user/install/templates/create_notify_user_notifications.rb +8 -0
- data/lib/generators/notify_user/install/templates/create_notify_user_unsubscribes.rb +5 -0
- data/lib/generators/notify_user/notification/notification_generator.rb +1 -0
- data/lib/notify_user/channels/action_mailer/action_mailer_channel.rb +1 -1
- data/lib/notify_user/channels/apns/apns_channel.rb +23 -23
- data/lib/notify_user/engine.rb +0 -1
- data/lib/notify_user/version.rb +1 -1
- data/spec/controllers/notify_user/notifications_controller_spec.rb +130 -108
- data/spec/dummy/rails-4.1.0/Gemfile +1 -1
- data/spec/dummy/rails-4.1.0/app/notifications/new_post_notification.rb +2 -6
- 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
- data/spec/dummy/rails-4.1.0/app/views/notify_user/new_post_notification/mobile_sdk/notification.html.erb +1 -0
- data/spec/dummy/rails-4.1.0/config/environments/production.rb +1 -6
- data/spec/dummy/rails-4.1.0/config/initializers/assets.rb +8 -0
- data/spec/dummy/rails-4.1.0/config/initializers/notify_user.rb +10 -0
- data/spec/dummy/rails-4.1.0/config/secrets.yml +2 -2
- 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
- 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
- data/spec/dummy/rails-4.1.0/db/migrate/{20141102231434013013078000_create_notify_user_unsubscribes.rb → 20150907004708_create_notify_user_unsubscribes.rb} +5 -0
- 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
- data/spec/dummy/rails-4.1.0/db/schema.rb +12 -1
- data/spec/dummy/rails-4.1.0/log/test.log +55083 -8099
- data/spec/dummy/rails-4.1.0/test/test_helper.rb +0 -3
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/2iFf6DF21eHswaXamThRpysQhZa4HHhfXSwW0I26I_Q.cache +3 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/56gcPUZsFk_z-NC4BqxyzJ2fHeG-wa2DVNUK5iFQico.cache +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/8DepzOh5SIwaxC825zft8xeBhAi84AFjIkQLBafpfcI.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/DFBSCnNmEyoM8roYdJ4CwzgAxnyRtTG3S2qD1ryqXxw.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/DcdyyraxoBKSYh1m6Spmfn5Qtn0V2X2t8aO3dmAi0Po.cache +3 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/IO46kchRzb_wUQ8H3D25_DHv7lZK4CxthkOj6ZKp8mQ.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/JTg9Khb4iQ4MkGt2OoYdfz6rYD9ccxMNxCOnVK92fJA.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/O8akbUwAbmIKY-AhITimq-JDQ6IgsO3Hvq2v5etufFw.cache +2 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/RJrFPSmoXCFaapGXw1bP4Lg0NLmr9qG2RMuN56UrR7U.cache +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/TWJMA4bg5d25falxiw_TLK0GtSXWpfl0vFaFLRpkYKI.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/XjnNasrgRd0l5xx4UR4IeE-Tz1EtjiPKwmizcf59P9U.cache +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/Y829B5qbE0t7idbBscHZCJxlb-D9S6G_8P6HwwMe7J4.cache +2 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/aXGU_8_bWOQw87gl5m_8fgEUtethSIj95P57d5YuW5k.cache +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/cjXxcrFHyMpHUOqA38Yaft85pmxR7gZ4__TFcgJQyKA.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/cpoXvFR-s_2VM6kFm4ixeZKjW6en5HiD8B-ttj-iUSI.cache +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/hAsOx0KPt1yL2Nh2sDOmOIWrAfoEZo1RxZQkNop9FOU.cache +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/j52KuMJNJLJcKPVLf8rk8USLswZAmy6Hi1OW35JjVTo.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/mwsAf4xggfO0hGKNns79uKcXG7B5rk8a4Zav3vXyr6M.cache +2 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/tPF6H9NRpGO3whu2y5_e_R_1EACKdCwu5437D83qJT0.cache +3 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/x5V5ICXz753PW9A8l6gpNAh_utfwyXyixuUxtMgJ2Pg.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/y8AwtETeMIB25XCoxQDwn3DmMpUFLblIFK4yb18zN4c.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/yWa5z3IIFR71QlDOGDwO5IpC9vsVUGFNfficVy0q3zo.cache +1 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/v3.0/zDCAil6tD1zhO-gqs7OG9_zEEdMVEZo_aUkZjLHP53M.cache +0 -0
- data/spec/factories/notify_user_notifications.rb +4 -7
- data/spec/factories/users.rb +7 -0
- data/spec/lib/notify_user/channels/apns_channel_spec.rb +65 -0
- data/spec/mailers/notify_user/notification_mailer_spec.rb +24 -24
- data/spec/models/notify_user/apn_connection_spec.rb +29 -0
- data/spec/models/notify_user/apns_spec.rb +96 -0
- data/spec/models/notify_user/gcm_spec.rb +70 -0
- data/spec/models/notify_user/notification_spec.rb +456 -64
- data/spec/models/notify_user/unsubscribe_spec.rb +59 -16
- data/spec/models/notify_user/user_hash_spec.rb +11 -14
- data/spec/serializers/notify_user/notification_serializer_spec.rb +24 -6
- data/spec/setup_spec.rb +3 -4
- data/spec/spec_helper.rb +20 -12
- data/spec/support/test_apn_connection.rb +8 -0
- data/spec/support/test_gcm_connection.rb +5 -0
- metadata +131 -332
- data/app/models/notify_user/houston.rb +0 -101
- data/spec/dummy/rails-3.2.17/Gemfile +0 -38
- data/spec/dummy/rails-3.2.17/README.rdoc +0 -261
- data/spec/dummy/rails-3.2.17/Rakefile +0 -7
- data/spec/dummy/rails-3.2.17/app/assets/images/rails.png +0 -0
- data/spec/dummy/rails-3.2.17/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/rails-3.2.17/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/rails-3.2.17/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/rails-3.2.17/app/controllers/notify_user/notifications_controller.rb +0 -9
- data/spec/dummy/rails-3.2.17/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/rails-3.2.17/app/models/user.rb +0 -3
- data/spec/dummy/rails-3.2.17/app/notifications/new_post_notification.rb +0 -15
- data/spec/dummy/rails-3.2.17/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/rails-3.2.17/app/views/notify_user/layouts/action_mailer.html.erb +0 -39
- data/spec/dummy/rails-3.2.17/app/views/notify_user/new_post_notification/action_mailer/notification.html.erb +0 -1
- data/spec/dummy/rails-3.2.17/config.ru +0 -4
- data/spec/dummy/rails-3.2.17/config/application.rb +0 -62
- data/spec/dummy/rails-3.2.17/config/boot.rb +0 -6
- data/spec/dummy/rails-3.2.17/config/database.yml +0 -24
- data/spec/dummy/rails-3.2.17/config/environment.rb +0 -5
- data/spec/dummy/rails-3.2.17/config/environments/development.rb +0 -37
- data/spec/dummy/rails-3.2.17/config/environments/production.rb +0 -67
- data/spec/dummy/rails-3.2.17/config/environments/test.rb +0 -37
- data/spec/dummy/rails-3.2.17/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/rails-3.2.17/config/initializers/inflections.rb +0 -15
- data/spec/dummy/rails-3.2.17/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/rails-3.2.17/config/initializers/notify_user.rb +0 -14
- data/spec/dummy/rails-3.2.17/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/rails-3.2.17/config/initializers/session_store.rb +0 -8
- data/spec/dummy/rails-3.2.17/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/rails-3.2.17/config/keys/development_push.pem +0 -0
- data/spec/dummy/rails-3.2.17/config/locales/en.yml +0 -5
- data/spec/dummy/rails-3.2.17/config/routes.rb +0 -58
- data/spec/dummy/rails-3.2.17/db/migrate/20141102231353649649586000_create_notify_user_notifications.rb +0 -13
- data/spec/dummy/rails-3.2.17/db/migrate/20141102231353650650817000_create_notify_user_unsubscribes.rb +0 -10
- data/spec/dummy/rails-3.2.17/db/schema.rb +0 -50
- data/spec/dummy/rails-3.2.17/db/seeds.rb +0 -7
- data/spec/dummy/rails-3.2.17/doc/README_FOR_APP +0 -2
- data/spec/dummy/rails-3.2.17/log/test.log +0 -9574
- data/spec/dummy/rails-3.2.17/public/404.html +0 -26
- data/spec/dummy/rails-3.2.17/public/422.html +0 -26
- data/spec/dummy/rails-3.2.17/public/500.html +0 -25
- data/spec/dummy/rails-3.2.17/public/favicon.ico +0 -0
- data/spec/dummy/rails-3.2.17/public/index.html +0 -241
- data/spec/dummy/rails-3.2.17/public/robots.txt +0 -5
- data/spec/dummy/rails-3.2.17/script/rails +0 -6
- data/spec/dummy/rails-3.2.17/test/fixtures/users.yml +0 -7
- data/spec/dummy/rails-3.2.17/test/performance/browsing_test.rb +0 -12
- data/spec/dummy/rails-3.2.17/test/test_helper.rb +0 -13
- data/spec/dummy/rails-3.2.17/test/unit/user_test.rb +0 -7
- data/spec/dummy/rails-4.0.4/Gemfile +0 -45
- data/spec/dummy/rails-4.0.4/README.rdoc +0 -28
- data/spec/dummy/rails-4.0.4/Rakefile +0 -6
- data/spec/dummy/rails-4.0.4/app/assets/javascripts/application.js +0 -16
- data/spec/dummy/rails-4.0.4/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/rails-4.0.4/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/rails-4.0.4/app/controllers/notify_user/notifications_controller.rb +0 -9
- data/spec/dummy/rails-4.0.4/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/rails-4.0.4/app/models/user.rb +0 -2
- data/spec/dummy/rails-4.0.4/app/notifications/new_post_notification.rb +0 -15
- data/spec/dummy/rails-4.0.4/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/rails-4.0.4/app/views/notify_user/layouts/action_mailer.html.erb +0 -39
- data/spec/dummy/rails-4.0.4/app/views/notify_user/new_post_notification/action_mailer/notification.html.erb +0 -1
- data/spec/dummy/rails-4.0.4/bin/bundle +0 -3
- data/spec/dummy/rails-4.0.4/bin/rails +0 -4
- data/spec/dummy/rails-4.0.4/bin/rake +0 -4
- data/spec/dummy/rails-4.0.4/config.ru +0 -4
- data/spec/dummy/rails-4.0.4/config/application.rb +0 -23
- data/spec/dummy/rails-4.0.4/config/boot.rb +0 -4
- data/spec/dummy/rails-4.0.4/config/database.yml +0 -24
- data/spec/dummy/rails-4.0.4/config/environment.rb +0 -5
- data/spec/dummy/rails-4.0.4/config/environments/development.rb +0 -29
- data/spec/dummy/rails-4.0.4/config/environments/production.rb +0 -80
- data/spec/dummy/rails-4.0.4/config/environments/test.rb +0 -36
- data/spec/dummy/rails-4.0.4/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/rails-4.0.4/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/rails-4.0.4/config/initializers/inflections.rb +0 -16
- data/spec/dummy/rails-4.0.4/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/rails-4.0.4/config/initializers/notify_user.rb +0 -14
- data/spec/dummy/rails-4.0.4/config/initializers/secret_token.rb +0 -12
- data/spec/dummy/rails-4.0.4/config/initializers/session_store.rb +0 -3
- data/spec/dummy/rails-4.0.4/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/rails-4.0.4/config/keys/development_push.pem +0 -136
- data/spec/dummy/rails-4.0.4/config/locales/en.yml +0 -23
- data/spec/dummy/rails-4.0.4/config/routes.rb +0 -56
- data/spec/dummy/rails-4.0.4/db/migrate/20141102231412_create_users.rb +0 -9
- data/spec/dummy/rails-4.0.4/db/migrate/20141102231413670670945000_create_notify_user_unsubscribes.rb +0 -10
- data/spec/dummy/rails-4.0.4/db/migrate/20141102231413671671735000_create_notify_user_user_hashes.rb +0 -12
- data/spec/dummy/rails-4.0.4/db/schema.rb +0 -53
- data/spec/dummy/rails-4.0.4/db/seeds.rb +0 -7
- data/spec/dummy/rails-4.0.4/log/test.log +0 -45689
- data/spec/dummy/rails-4.0.4/public/404.html +0 -58
- data/spec/dummy/rails-4.0.4/public/422.html +0 -58
- data/spec/dummy/rails-4.0.4/public/500.html +0 -57
- data/spec/dummy/rails-4.0.4/public/favicon.ico +0 -0
- data/spec/dummy/rails-4.0.4/public/robots.txt +0 -5
- data/spec/dummy/rails-4.0.4/test/fixtures/users.yml +0 -7
- data/spec/dummy/rails-4.0.4/test/models/user_test.rb +0 -7
- data/spec/dummy/rails-4.0.4/test/test_helper.rb +0 -15
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/0e8918f38b9bf3fc19fca4efda1600a1 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/1bded108b40ef13c7e07be129e2cd83c +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/1ebdd9dfe7e88e90bee37951e2da1ea2 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/23fe609acece1521082ad6b8249f96b1 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/40fd179449501b801f80c852d1635a16 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/4499e16a29d89bdf30304de41c456b43 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/49088e1598df49c63ff7d874c97e958f +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/7398a3a743326d3576cbb05a000df04b +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/8eedfb1d9aee665c9f5a77df67b64a81 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/91d718eeae4552c702b8eafd9e8bbe76 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/9e2c26ef339b5827a5c296acb284ab99 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/a4f2f445b4f8578493957e4f7b0c76e3 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/af361e697648848dbf0282eba1d15c2f +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/af95fe3d35c9fe417700e8c3625329fe +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/b89f385c2540cb58f04dbfed561d3902 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/bc1864fd5bfa875243b05071735cbb82 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/bede0f0813e15081ea4ee32b640c92c4 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/c1ba4e65491e8bb9fcdc38b22cb64aa9 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/cb741827a22668ecf975f78242076b6b +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/d3516b65bb025bc333e0f91647a7b119 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/df7c1d81da90fb0287da1e283291dc81 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/f78ea05f6019d54c3572513ebae03556 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/f7c2f64864ec1995aee8dcead45d7f24 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/rails-4.0.4/tmp/cache/assets/test/sprockets/fbbb5b21a4144f5e3efee9eda4fc38e5 +0 -0
- data/spec/dummy/rails-4.1.0/db/migrate/20141102231432_create_users.rb +0 -9
- data/spec/dummy/rails-4.1.0/db/migrate/20141102231434012012157000_create_notify_user_notifications.rb +0 -13
- data/spec/dummy/rails-4.1.0/db/migrate/20141102231434013013847000_create_notify_user_user_hashes.rb +0 -12
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/1bded108b40ef13c7e07be129e2cd83c +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/1ebdd9dfe7e88e90bee37951e2da1ea2 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/23fe609acece1521082ad6b8249f96b1 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/3fa5cc1bc06bfb81887b971eb8d36258 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/796287194e2490ae173cabd0f8e0fce7 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/8d2563dcd2d59f9e020fc2623eda3999 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/8ebc0d0c963e18c7c16e6e7f55fd379f +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/91d718eeae4552c702b8eafd9e8bbe76 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/9e2c26ef339b5827a5c296acb284ab99 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/a098882f88a8b3ca91d2efaada23dba3 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/af361e697648848dbf0282eba1d15c2f +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/b89f385c2540cb58f04dbfed561d3902 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/c1ba4e65491e8bb9fcdc38b22cb64aa9 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/cb741827a22668ecf975f78242076b6b +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/df7c1d81da90fb0287da1e283291dc81 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/f031b3342a7246183ffa1bb7819f293e +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/f78ea05f6019d54c3572513ebae03556 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/rails-4.1.0/tmp/cache/assets/test/sprockets/fbbb5b21a4144f5e3efee9eda4fc38e5 +0 -0
- 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)
|
25
|
-
NotifyUser::Unsubscribe.
|
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
|
@@ -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
|
-
|
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
|
-
|
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,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
|
data/lib/generators/notify_user/aggr_interval_update/templates/add_sent_time_to_notifications.rb
ADDED
@@ -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
|
@@ -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
|
-
|
29
|
-
|
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
|
@@ -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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/notify_user/engine.rb
CHANGED
data/lib/notify_user/version.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
9
|
-
|
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
|
-
|
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
|
-
|
20
|
-
|
22
|
+
before :each do
|
23
|
+
notification.save
|
24
|
+
end
|
21
25
|
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
49
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
before :each do
|
53
|
+
notification.save
|
54
|
+
notification1.save
|
55
|
+
notification2.save
|
56
|
+
end
|
66
57
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
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
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
95
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
102
|
+
before :each do
|
103
|
+
notification.save
|
104
|
+
end
|
100
105
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
137
|
-
|
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
|