activity_notification 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -32
  3. data/Gemfile +0 -3
  4. data/Gemfile.lock +66 -73
  5. data/README.md +190 -184
  6. data/activity_notification.gemspec +2 -3
  7. data/gemfiles/Gemfile.rails-4.2 +7 -1
  8. data/gemfiles/Gemfile.rails-4.2.lock +35 -26
  9. data/gemfiles/Gemfile.rails-5.0 +7 -1
  10. data/gemfiles/Gemfile.rails-5.0.lock +73 -64
  11. data/gemfiles/Gemfile.rails-5.1 +6 -3
  12. data/gemfiles/Gemfile.rails-5.1.lock +77 -74
  13. data/lib/activity_notification/apis/notification_api.rb +3 -3
  14. data/lib/activity_notification/models.rb +1 -1
  15. data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
  16. data/lib/activity_notification/models/concerns/target.rb +1 -1
  17. data/lib/activity_notification/orm/active_record/notification.rb +7 -0
  18. data/lib/activity_notification/orm/mongoid.rb +11 -1
  19. data/lib/activity_notification/orm/mongoid/notification.rb +9 -2
  20. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  21. data/lib/activity_notification/roles/acts_as_notifiable.rb +30 -15
  22. data/lib/activity_notification/version.rb +1 -1
  23. data/spec/rails_app/app/models/admin.rb +1 -1
  24. data/spec/rails_app/app/models/article.rb +1 -1
  25. data/spec/rails_app/app/models/comment.rb +1 -1
  26. data/spec/rails_app/app/models/dummy/dummy_base.rb +10 -2
  27. data/spec/rails_app/app/models/dummy/dummy_group.rb +13 -3
  28. data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +13 -3
  29. data/spec/rails_app/app/models/dummy/dummy_notifier.rb +13 -3
  30. data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +12 -3
  31. data/spec/rails_app/app/models/dummy/dummy_target.rb +14 -3
  32. data/spec/rails_app/app/models/user.rb +1 -1
  33. data/spec/rails_app/config/application.rb +7 -3
  34. data/spec/rails_app/config/environment.rb +1 -1
  35. data/spec/rails_app/config/environments/development.rb +3 -1
  36. data/spec/rails_app/config/environments/test.rb +4 -1
  37. data/spec/roles/acts_as_notifiable_spec.rb +10 -6
  38. data/spec/spec_helper.rb +0 -3
  39. metadata +6 -20
@@ -1,3 +1,3 @@
1
1
  module ActivityNotification
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- if ENV['AN_TEST_DB'] != 'mongodb'
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
2
  class Admin < ActiveRecord::Base
3
3
  belongs_to :user
4
4
  validates :user, presence: true
@@ -1,4 +1,4 @@
1
- if ENV['AN_TEST_DB'] != 'mongodb'
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
2
  class Article < ActiveRecord::Base
3
3
  belongs_to :user
4
4
  has_many :comments, dependent: :destroy
@@ -1,4 +1,4 @@
1
- if ENV['AN_TEST_DB'] != 'mongodb'
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
2
  class Comment < ActiveRecord::Base
3
3
  belongs_to :article
4
4
  belongs_to :user
@@ -1,2 +1,10 @@
1
- class Dummy::DummyBase < ActiveRecord::Base
2
- end
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
+ class Dummy::DummyBase < ActiveRecord::Base
3
+ end
4
+ else
5
+ class Dummy::DummyBase
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+ include ActivityNotification::Models
9
+ end
10
+ end
@@ -1,4 +1,14 @@
1
- class Dummy::DummyGroup < ActiveRecord::Base
2
- self.table_name = :articles
3
- include ActivityNotification::Group
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
+ class Dummy::DummyGroup < ActiveRecord::Base
3
+ self.table_name = :articles
4
+ include ActivityNotification::Group
5
+ end
6
+ else
7
+ class Dummy::DummyGroup
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+ include ActivityNotification::Models
11
+ include ActivityNotification::Group
12
+ field :title, type: String
13
+ end
4
14
  end
@@ -1,4 +1,14 @@
1
- class Dummy::DummyNotifiable < ActiveRecord::Base
2
- self.table_name = :articles
3
- include ActivityNotification::Notifiable
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
+ class Dummy::DummyNotifiable < ActiveRecord::Base
3
+ self.table_name = :articles
4
+ include ActivityNotification::Notifiable
5
+ end
6
+ else
7
+ class Dummy::DummyNotifiable
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+ include ActivityNotification::Models
11
+ include ActivityNotification::Notifiable
12
+ field :title, type: String
13
+ end
4
14
  end
@@ -1,4 +1,14 @@
1
- class Dummy::DummyNotifier < ActiveRecord::Base
2
- self.table_name = :users
3
- include ActivityNotification::Notifier
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
+ class Dummy::DummyNotifier < ActiveRecord::Base
3
+ self.table_name = :users
4
+ include ActivityNotification::Notifier
5
+ end
6
+ else
7
+ class Dummy::DummyNotifier
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+ include ActivityNotification::Models
11
+ include ActivityNotification::Notifier
12
+ field :name, type: String
13
+ end
4
14
  end
@@ -1,4 +1,13 @@
1
- class Dummy::DummySubscriber < ActiveRecord::Base
2
- self.table_name = :users
3
- acts_as_target email: 'dummy@example.com', email_allowed: true, batch_email_allowed: true, subscription_allowed: true
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
+ class Dummy::DummySubscriber < ActiveRecord::Base
3
+ self.table_name = :users
4
+ acts_as_target email: 'dummy@example.com', email_allowed: true, batch_email_allowed: true, subscription_allowed: true
5
+ end
6
+ else
7
+ class Dummy::DummySubscriber
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+ include ActivityNotification::Models
11
+ acts_as_target email: 'dummy@example.com', email_allowed: true, batch_email_allowed: true, subscription_allowed: true
12
+ end
4
13
  end
@@ -1,4 +1,15 @@
1
- class Dummy::DummyTarget < ActiveRecord::Base
2
- self.table_name = :users
3
- include ActivityNotification::Target
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
+ class Dummy::DummyTarget < ActiveRecord::Base
3
+ self.table_name = :users
4
+ include ActivityNotification::Target
5
+ end
6
+ else
7
+ class Dummy::DummyTarget
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps
10
+ include ActivityNotification::Models
11
+ include ActivityNotification::Target
12
+ field :email, type: String, default: ""
13
+ field :name, type: String
14
+ end
4
15
  end
@@ -1,4 +1,4 @@
1
- if ENV['AN_TEST_DB'] != 'mongodb'
1
+ unless ENV['AN_TEST_DB'] == 'mongodb'
2
2
  class User < ActiveRecord::Base
3
3
  devise :database_authenticatable, :registerable, :confirmable
4
4
  validates :email, presence: true
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- # Pick the frameworks you want:
3
+ # Load mongoid configuration if necessary:
4
4
  if ENV['AN_ORM'] == 'mongoid'
5
5
  require 'mongoid'
6
6
  require 'rails'
@@ -8,7 +8,11 @@ if ENV['AN_ORM'] == 'mongoid'
8
8
  Mongoid.load!(File.expand_path("config/mongoid.yml"), :development)
9
9
  end
10
10
  end
11
- require "active_record/railtie"
11
+
12
+ # Pick the frameworks you want:
13
+ unless ENV['AN_ORM'] == 'mongoid' && ENV['AN_TEST_DB'] == 'mongodb'
14
+ require "active_record/railtie"
15
+ end
12
16
  require "action_controller/railtie"
13
17
  require "action_mailer/railtie"
14
18
  require "action_view/railtie"
@@ -21,7 +25,7 @@ require "activity_notification"
21
25
  module Dummy
22
26
  class Application < Rails::Application
23
27
  # Do not swallow errors in after_commit/after_rollback callbacks.
24
- if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
28
+ if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2 && ENV['AN_TEST_DB'] != 'mongodb'
25
29
  config.active_record.raise_in_transactional_callbacks = true
26
30
  end
27
31
  end
@@ -15,7 +15,7 @@ def silent_stdout(&block)
15
15
  end
16
16
 
17
17
  # Load database schema
18
- if Rails.env.test?
18
+ if Rails.env.test? && ENV['AN_TEST_DB'] != 'mongodb'
19
19
  silent_stdout do
20
20
  load "#{Rails.root}/db/schema.rb"
21
21
  end
@@ -20,7 +20,9 @@ Rails.application.configure do
20
20
  config.active_support.deprecation = :log
21
21
 
22
22
  # Raise an error on page load if there are pending migrations.
23
- config.active_record.migration_error = :page_load
23
+ unless ENV['AN_ORM'] == 'mongoid' && ENV['AN_TEST_DB'] == 'mongodb'
24
+ config.active_record.migration_error = :page_load
25
+ end
24
26
 
25
27
  # Debug mode disables concatenation and preprocessing of assets.
26
28
  # This option may cause significant delays in view rendering with a large
@@ -49,6 +49,9 @@ Rails.application.configure do
49
49
  # Raises error for missing translations
50
50
  # config.action_view.raise_on_missing_translations = true
51
51
 
52
- # For devise and notification email
52
+ # Use :test Active Job adapter for RSpec.
53
+ config.active_job.queue_adapter = :test
54
+
55
+ # Set default_url_options for devise and notification email.
53
56
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
54
57
  end
@@ -45,7 +45,7 @@ describe ActivityNotification::ActsAsNotifiable do
45
45
  it "does not generate notifications when notifiable is created and updated" do
46
46
  dummy_notifiable_class.acts_as_notifiable :users, targets: [user_target]
47
47
  notifiable = dummy_notifiable_class.create
48
- notifiable.update(created_at: notifiable.created_at + 10.second)
48
+ notifiable.update(created_at: notifiable.updated_at)
49
49
  expect(user_target.notifications.filtered_by_instance(notifiable).count).to eq(0)
50
50
  end
51
51
  end
@@ -71,7 +71,7 @@ describe ActivityNotification::ActsAsNotifiable do
71
71
  before do
72
72
  user_target.notifications.delete_all
73
73
  expect(user_target.notifications.count).to eq(0)
74
- @notifiable.update(created_at: @notifiable.created_at + 10.second)
74
+ @notifiable.update(created_at: @notifiable.updated_at)
75
75
  end
76
76
 
77
77
  it "generates notifications when notifiable is updated" do
@@ -106,7 +106,7 @@ describe ActivityNotification::ActsAsNotifiable do
106
106
  before do
107
107
  user_target.notifications.delete_all
108
108
  expect(user_target.notifications.count).to eq(0)
109
- @notifiable.update(created_at: @notifiable.created_at + 10.second)
109
+ @notifiable.update(created_at: @notifiable.updated_at)
110
110
  end
111
111
 
112
112
  it "does not generate notifications when notifiable is updated" do
@@ -136,7 +136,7 @@ describe ActivityNotification::ActsAsNotifiable do
136
136
  before do
137
137
  user_target.notifications.delete_all
138
138
  expect(user_target.notifications.count).to eq(0)
139
- @notifiable.update(created_at: @notifiable.created_at + 10.second)
139
+ @notifiable.update(created_at: @notifiable.updated_at)
140
140
  end
141
141
 
142
142
  it "does not generate notifications when notifiable is updated" do
@@ -166,7 +166,7 @@ describe ActivityNotification::ActsAsNotifiable do
166
166
  before do
167
167
  user_target.notifications.delete_all
168
168
  expect(user_target.notifications.count).to eq(0)
169
- @notifiable.update(created_at: @notifiable.created_at + 10.second)
169
+ @notifiable.update(created_at: @notifiable.updated_at)
170
170
  end
171
171
 
172
172
  it "generates notifications when notifiable is updated" do
@@ -248,7 +248,11 @@ describe ActivityNotification::ActsAsNotifiable do
248
248
  it "can not be deleted when it has generated notifications" do
249
249
  dummy_notifiable_class.acts_as_notifiable :users, dependent_notifications: :restrict_with_exception
250
250
  expect(user_target.notifications.reload.size).to eq(3)
251
- expect { @notifiable_1.destroy }.to raise_error(ActiveRecord::DeleteRestrictionError)
251
+ if ActivityNotification.config.orm == :active_record
252
+ expect { @notifiable_1.destroy }.to raise_error(ActiveRecord::DeleteRestrictionError)
253
+ else
254
+ expect { @notifiable_1.destroy }.to raise_error(RuntimeError)
255
+ end
252
256
  end
253
257
  end
254
258
 
data/spec/spec_helper.rb CHANGED
@@ -37,9 +37,6 @@ require 'ammeter/init'
37
37
  require 'factory_girl_rails'
38
38
  require 'activity_notification'
39
39
 
40
- # For active record ORM
41
- require 'active_record'
42
-
43
40
  def clear_database
44
41
  [ActivityNotification::Notification, ActivityNotification::Subscription, Comment, Article, Admin, User].each do |model_class|
45
42
  model_class.delete_all
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activity_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Yamazaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,20 +30,6 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.2'
33
- - !ruby/object:Gem::Dependency
34
- name: activerecord
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 4.2.0
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 4.2.0
47
33
  - !ruby/object:Gem::Dependency
48
34
  name: i18n
49
35
  requirement: !ruby/object:Gem::Requirement
@@ -134,14 +120,14 @@ dependencies:
134
120
  requirements:
135
121
  - - "~>"
136
122
  - !ruby/object:Gem::Version
137
- version: 3.5.2
123
+ version: 3.6.0
138
124
  type: :development
139
125
  prerelease: false
140
126
  version_requirements: !ruby/object:Gem::Requirement
141
127
  requirements:
142
128
  - - "~>"
143
129
  - !ruby/object:Gem::Version
144
- version: 3.5.2
130
+ version: 3.6.0
145
131
  - !ruby/object:Gem::Dependency
146
132
  name: factory_girl_rails
147
133
  requirement: !ruby/object:Gem::Requirement
@@ -204,14 +190,14 @@ dependencies:
204
190
  requirements:
205
191
  - - "~>"
206
192
  - !ruby/object:Gem::Version
207
- version: 4.2.1
193
+ version: 4.3.0
208
194
  type: :development
209
195
  prerelease: false
210
196
  version_requirements: !ruby/object:Gem::Requirement
211
197
  requirements:
212
198
  - - "~>"
213
199
  - !ruby/object:Gem::Version
214
- version: 4.2.1
200
+ version: 4.3.0
215
201
  - !ruby/object:Gem::Dependency
216
202
  name: aws-sdk
217
203
  requirement: !ruby/object:Gem::Requirement