rails-push-notifications 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +150 -0
- data/Rakefile +8 -0
- data/lib/generators/rails-push-notifications/USAGE +6 -0
- data/lib/generators/rails-push-notifications/migrations_generator.rb +29 -0
- data/lib/generators/rails-push-notifications/templates/migrations/create_rails_push_notifications_apps.rb +23 -0
- data/lib/generators/rails-push-notifications/templates/migrations/create_rails_push_notifications_notifications.rb +22 -0
- data/lib/rails-push-notifications.rb +4 -0
- data/lib/rails-push-notifications/apps.rb +4 -0
- data/lib/rails-push-notifications/apps/apns_app.rb +24 -0
- data/lib/rails-push-notifications/apps/base_app.rb +26 -0
- data/lib/rails-push-notifications/apps/gcm_app.rb +17 -0
- data/lib/rails-push-notifications/apps/mpns_app.rb +17 -0
- data/lib/rails-push-notifications/notification.rb +29 -0
- data/lib/rails-push-notifications/rails_push_notifications_railtie.rb +7 -0
- data/lib/rails-push-notifications/version.rb +3 -0
- data/spec/apps/apns_app_spec.rb +96 -0
- data/spec/apps/gcm_app_spec.rb +69 -0
- data/spec/apps/mpns_app_spec.rb +75 -0
- data/spec/factories/apps.rb +15 -0
- data/spec/factories/notifications.rb +20 -0
- data/spec/generators/migrations_generator_spec.rb +25 -0
- data/spec/log/test.log +262 -0
- data/spec/notification_spec.rb +96 -0
- data/spec/rails_apps/rails4.rb +47 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/factory_girl.rb +5 -0
- metadata +196 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
module RailsPushNotifications
|
3
|
+
describe Notification, type: :model do
|
4
|
+
|
5
|
+
class FakeResults
|
6
|
+
attr_reader :value1, :success, :failed
|
7
|
+
|
8
|
+
def initialize(value1, success, failed)
|
9
|
+
@value1 = value1
|
10
|
+
@success = success
|
11
|
+
@failed = failed
|
12
|
+
end
|
13
|
+
|
14
|
+
def ==(other)
|
15
|
+
other != nil && other.is_a?(FakeResults) &&
|
16
|
+
@value1 == other.value1 && @success == other.success &&
|
17
|
+
@failed == failed || super(other)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:notification) { build :apns_notification }
|
22
|
+
|
23
|
+
describe 'app relationship' do
|
24
|
+
it 'requires an app' do
|
25
|
+
notification.app = nil
|
26
|
+
expect(notification).to_not be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'belongs to an app' do
|
30
|
+
expect(notification.app).to be_a APNSApp
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'data' do
|
35
|
+
it 'requires data' do
|
36
|
+
notification.data = nil
|
37
|
+
expect(notification).to_not be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has to be a Hash' do
|
41
|
+
expect do
|
42
|
+
notification.data = 'dummy text'
|
43
|
+
end.to raise_error ActiveRecord::SerializationTypeMismatch
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'destinations' do
|
48
|
+
it 'requires destinations' do
|
49
|
+
notification.destinations = nil
|
50
|
+
expect(notification).to_not be_valid
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'has to be an array' do
|
54
|
+
expect do
|
55
|
+
notification.destinations = 'dummy destinations'
|
56
|
+
end.to raise_error ActiveRecord::SerializationTypeMismatch
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'has to contain at least one destination' do
|
60
|
+
notification.destinations = []
|
61
|
+
expect(notification).to_not be_valid
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'sent' do
|
66
|
+
it 'is false by default' do
|
67
|
+
notification.save
|
68
|
+
expect(notification.sent).to eq false
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'is sent if results assigned' do
|
72
|
+
notification.save
|
73
|
+
expect do
|
74
|
+
notification.results = FakeResults.new(1, 2, 3)
|
75
|
+
notification.save
|
76
|
+
end.to change { notification.reload.sent }.from(false).to true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'results' do
|
81
|
+
|
82
|
+
let(:success) { 1 }
|
83
|
+
let(:failed) { 3 }
|
84
|
+
let(:results) { FakeResults.new 'abc', success, failed }
|
85
|
+
|
86
|
+
it 'serializes any object' do
|
87
|
+
notification.results = results
|
88
|
+
notification.save
|
89
|
+
notification.reload
|
90
|
+
expect(notification.results).to eq results
|
91
|
+
expect(notification.success).to eq success
|
92
|
+
expect(notification.failed).to eq failed
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'rails/all'
|
3
|
+
require 'action_view/testing/resolvers'
|
4
|
+
|
5
|
+
require 'rails-push-notifications'
|
6
|
+
|
7
|
+
module RailsPushNotificationsApp
|
8
|
+
class Application < Rails::Application
|
9
|
+
config.root = File.expand_path("../../..", __FILE__)
|
10
|
+
config.cache_classes = true
|
11
|
+
|
12
|
+
config.eager_load = false
|
13
|
+
config.static_cache_control = "public, max-age=3600"
|
14
|
+
|
15
|
+
config.consider_all_requests_local = true
|
16
|
+
config.action_controller.perform_caching = false
|
17
|
+
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
config.action_controller.allow_forgery_protection = false
|
21
|
+
|
22
|
+
config.active_support.deprecation = :stderr
|
23
|
+
|
24
|
+
config.middleware.delete "Rack::Lock"
|
25
|
+
config.middleware.delete "ActionDispatch::Flash"
|
26
|
+
config.middleware.delete "ActionDispatch::BestStandardsSupport"
|
27
|
+
config.secret_key_base = '49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk'
|
28
|
+
routes.append do
|
29
|
+
get "/" => "application#index"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ApplicationController < ActionController::Base
|
35
|
+
include Rails.application.routes.url_helpers
|
36
|
+
layout 'application'
|
37
|
+
self.view_paths = [ActionView::FixtureResolver.new(
|
38
|
+
"layouts/application.html.erb" => '<%= yield %>',
|
39
|
+
"welcome/index.html.erb"=> 'Hello from index.html.erb',
|
40
|
+
)]
|
41
|
+
|
42
|
+
def index
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
RailsPushNotificationsApp::Application.initialize!
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
ENV['RAILS_ENV'] = 'test'
|
8
|
+
ENV['DATABASE_URL'] = 'sqlite3::memory:'
|
9
|
+
|
10
|
+
require 'rails_apps/rails4'
|
11
|
+
require 'rspec/rails'
|
12
|
+
Bundler.require :default, :development
|
13
|
+
require 'webmock/rspec'
|
14
|
+
require 'ruby-push-notifications'
|
15
|
+
|
16
|
+
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
|
17
|
+
|
18
|
+
require 'rails-push-notifications'
|
19
|
+
|
20
|
+
ActiveRecord::Base.establish_connection(
|
21
|
+
:adapter => 'sqlite3',
|
22
|
+
:database => ':memory:'
|
23
|
+
)
|
24
|
+
|
25
|
+
files = Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'rails-push-notifications', 'templates', 'migrations', '*.rb'))
|
26
|
+
|
27
|
+
migrations = []
|
28
|
+
files.each_with_index do |file, version|
|
29
|
+
name, scope = file.scan(/([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/).first
|
30
|
+
|
31
|
+
name = name.camelize
|
32
|
+
|
33
|
+
migrations << ActiveRecord::MigrationProxy.new(name, version, file, scope)
|
34
|
+
end
|
35
|
+
|
36
|
+
migrations.sort_by(&:version)
|
37
|
+
|
38
|
+
ActiveRecord::Migrator.new(:up, migrations).migrate
|
39
|
+
|
40
|
+
RSpec.configure do |config|
|
41
|
+
config.use_transactional_fixtures = true
|
42
|
+
config.order = :random
|
43
|
+
end
|
44
|
+
|
45
|
+
WebMock.disable_net_connect!(:allow => "codeclimate.com")
|
metadata
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-push-notifications
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Alonso
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-push-notifications
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_girl
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: generator_spec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.20'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.20'
|
125
|
+
description: Free Open Source Rails gem for performing push notifications for both
|
126
|
+
iOS and Android devices
|
127
|
+
email:
|
128
|
+
- info@mrcalonso.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- MIT-LICENSE
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- lib/generators/rails-push-notifications/USAGE
|
137
|
+
- lib/generators/rails-push-notifications/migrations_generator.rb
|
138
|
+
- lib/generators/rails-push-notifications/templates/migrations/create_rails_push_notifications_apps.rb
|
139
|
+
- lib/generators/rails-push-notifications/templates/migrations/create_rails_push_notifications_notifications.rb
|
140
|
+
- lib/rails-push-notifications.rb
|
141
|
+
- lib/rails-push-notifications/apps.rb
|
142
|
+
- lib/rails-push-notifications/apps/apns_app.rb
|
143
|
+
- lib/rails-push-notifications/apps/base_app.rb
|
144
|
+
- lib/rails-push-notifications/apps/gcm_app.rb
|
145
|
+
- lib/rails-push-notifications/apps/mpns_app.rb
|
146
|
+
- lib/rails-push-notifications/notification.rb
|
147
|
+
- lib/rails-push-notifications/rails_push_notifications_railtie.rb
|
148
|
+
- lib/rails-push-notifications/version.rb
|
149
|
+
- spec/apps/apns_app_spec.rb
|
150
|
+
- spec/apps/gcm_app_spec.rb
|
151
|
+
- spec/apps/mpns_app_spec.rb
|
152
|
+
- spec/factories/apps.rb
|
153
|
+
- spec/factories/notifications.rb
|
154
|
+
- spec/generators/migrations_generator_spec.rb
|
155
|
+
- spec/log/test.log
|
156
|
+
- spec/notification_spec.rb
|
157
|
+
- spec/rails_apps/rails4.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/support/factory_girl.rb
|
160
|
+
homepage: https://github.com/calonso/rails-push-notifications
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 1.9.3
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.2.2
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: Professional iOS and Android push notifications for Ruby on Rails
|
184
|
+
test_files:
|
185
|
+
- spec/apps/apns_app_spec.rb
|
186
|
+
- spec/apps/gcm_app_spec.rb
|
187
|
+
- spec/apps/mpns_app_spec.rb
|
188
|
+
- spec/factories/apps.rb
|
189
|
+
- spec/factories/notifications.rb
|
190
|
+
- spec/generators/migrations_generator_spec.rb
|
191
|
+
- spec/log/test.log
|
192
|
+
- spec/notification_spec.rb
|
193
|
+
- spec/rails_apps/rails4.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
- spec/support/factory_girl.rb
|
196
|
+
has_rdoc:
|