public_activity 1.6.4 → 2.0.2
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.
- checksums.yaml +4 -4
- data/README.md +26 -28
- data/Rakefile +4 -5
- data/lib/generators/public_activity/migration/templates/migration.rb +10 -10
- data/lib/generators/public_activity/migration_upgrade/templates/upgrade.rb +1 -1
- data/lib/public_activity/orm/active_record/activity.rb +17 -13
- data/lib/public_activity/renderable.rb +3 -2
- data/lib/public_activity/version.rb +1 -1
- data/test/migrations/001_create_activities.rb +1 -1
- data/test/migrations/002_create_articles.rb +1 -4
- data/test/migrations/003_create_users.rb +1 -3
- data/test/migrations/004_add_nonstandard_to_activities.rb +1 -3
- data/test/test_activist.rb +37 -36
- data/test/test_activity.rb +35 -37
- data/test/test_common.rb +58 -49
- data/test/test_controller_integration.rb +17 -11
- data/test/test_generators.rb +5 -17
- data/test/test_helper.rb +18 -24
- data/test/test_testing.rb +11 -10
- data/test/test_tracking.rb +169 -147
- data/test/test_view_helpers.rb +5 -5
- metadata +49 -40
- data/lib/generators/public_activity/activity/activity_generator.rb +0 -19
- data/lib/generators/public_activity/activity/templates/activity.rb +0 -5
- data/test/migrations_base.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa4a946e3b5ec45ad643a08338a4b150ddb912fa0489e053dc9d310727cc9367
|
4
|
+
data.tar.gz: ba63edb8f4731b604cee4043fd31bf76abdcf45ca9eab971502ec7caa1b31939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04f48aec79e23c926de4ebe00219c611d5483e1eb9029cd400b501625eb1ca5d4be4b8071f6ae4552888175f2bfa4b7003b4fac9d610b4a649a8a5925d7d9676
|
7
|
+
data.tar.gz: cb0abcede1c4c52de2ce8f572b25818f98803413e95959fed94382e3f65b843ae1caab9db10ca76dbfba1b50174e90935d424f58231014803ba017f90ee90416
|
data/README.md
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
# PublicActivity [](http://travis-ci.org/chaps-io/public_activity) [](https://codeclimate.com/github/chaps-io/public_activity) [](http://badge.fury.io/rb/public_activity)
|
2
2
|
|
3
3
|
`public_activity` provides easy activity tracking for your **ActiveRecord**, **Mongoid 3** and **MongoMapper** models
|
4
|
-
in Rails
|
5
|
-
recorded activities to users -
|
4
|
+
in Rails 5.0+. Simply put: it records what has been changed or created and gives you the ability to present those
|
5
|
+
recorded activities to users - similarly to how GitHub does it.
|
6
6
|
|
7
|
+
## Rails 7
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
## Rails 5
|
14
|
-
|
15
|
-
**As of 1.6.0 version, public_activity also supports Rails up to 5.2.**
|
9
|
+
**As of version 2.0.0, public_activity also supports Rails up to 7.0.**
|
16
10
|
|
17
11
|
## Table of contents
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
13
|
+
- [Rails 7](#rails-7)
|
14
|
+
- [Table of contents](#table-of-contents)
|
15
|
+
- [Example](#example)
|
16
|
+
- [Online demo](#online-demo)
|
17
|
+
- [Screencast](#screencast)
|
18
|
+
- [Setup](#setup)
|
19
|
+
- [Gem installation](#gem-installation)
|
20
|
+
- [Database setup](#database-setup)
|
21
|
+
- [Model configuration](#model-configuration)
|
22
|
+
- [Custom activities](#custom-activities)
|
23
|
+
- [Displaying activities](#displaying-activities)
|
24
|
+
- [Layouts](#layouts)
|
25
|
+
- [Locals](#locals)
|
26
|
+
- [Activity views](#activity-views)
|
27
|
+
- [I18n](#I18n)
|
28
|
+
- [Testing](#testing)
|
29
|
+
- [Documentation](#documentation)
|
30
|
+
- [Common examples](#common-examples)
|
31
|
+
- [Help](#help)
|
32
|
+
- [License](#license)
|
35
33
|
|
36
34
|
## Example
|
37
35
|
|
@@ -197,7 +195,7 @@ For example, if you have an activity with `:key` set to `"activity.user.changed_
|
|
197
195
|
|
198
196
|
If a view file does not exist, then p_a falls back to the old behaviour and tries to translate the activity `:key` using `I18n#translate` method (see the section below).
|
199
197
|
|
200
|
-
####
|
198
|
+
#### I18n
|
201
199
|
|
202
200
|
Translations are used by the `#text` method, to which you can pass additional options in form of a hash. `#render` method uses translations when view templates have not been provided. You can render pure i18n strings by passing `{display: :i18n}` to `#render_activity` or `#render`.
|
203
201
|
|
@@ -224,7 +222,7 @@ require 'public_activity/testing'
|
|
224
222
|
PublicActivity.enabled = false
|
225
223
|
```
|
226
224
|
|
227
|
-
In your specs you can then blockwise decide
|
225
|
+
In your specs you can then blockwise decide whether to turn `public_activity` on
|
228
226
|
or off.
|
229
227
|
|
230
228
|
```ruby
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
4
|
require 'rake'
|
5
5
|
require 'yard'
|
6
6
|
require 'yard/rake/yardoc_task'
|
7
7
|
require 'rake/testtask'
|
8
8
|
|
9
|
-
task :
|
9
|
+
task default: :test
|
10
10
|
|
11
11
|
desc 'Generate documentation for the public_activity plugin.'
|
12
12
|
YARD::Rake::YardocTask.new do |doc|
|
@@ -14,7 +14,6 @@ YARD::Rake::YardocTask.new do |doc|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Rake::TestTask.new do |t|
|
17
|
-
|
18
|
-
|
17
|
+
t.libs << 'test'
|
18
|
+
t.test_files = FileList['test/test*.rb']
|
19
19
|
end
|
20
|
-
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Migration responsible for creating a table with activities
|
4
|
-
class CreateActivities <
|
5
|
-
# Create table
|
4
|
+
class CreateActivities < ActiveRecord::Migration[5.0]
|
6
5
|
def self.up
|
7
6
|
create_table :activities do |t|
|
8
|
-
t.belongs_to :trackable, :
|
9
|
-
t.belongs_to :owner, :
|
10
|
-
t.string
|
11
|
-
t.text
|
12
|
-
t.belongs_to :recipient, :
|
7
|
+
t.belongs_to :trackable, polymorphic: true
|
8
|
+
t.belongs_to :owner, polymorphic: true
|
9
|
+
t.string :key
|
10
|
+
t.text :parameters
|
11
|
+
t.belongs_to :recipient, polymorphic: true
|
13
12
|
|
14
13
|
t.timestamps
|
15
14
|
end
|
16
15
|
|
17
|
-
add_index :activities, [
|
18
|
-
add_index :activities, [
|
19
|
-
add_index :activities, [
|
16
|
+
add_index :activities, %i[trackable_id trackable_type]
|
17
|
+
add_index :activities, %i[owner_id owner_type]
|
18
|
+
add_index :activities, %i[recipient_id recipient_type]
|
20
19
|
end
|
20
|
+
|
21
21
|
# Drop table
|
22
22
|
def self.down
|
23
23
|
drop_table :activities
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Migration responsible for creating a table with activities
|
4
|
-
class UpgradeActivities < ActiveRecord::Migration
|
4
|
+
class UpgradeActivities < ActiveRecord::Migration[5.0]
|
5
5
|
# Create table
|
6
6
|
def self.change
|
7
7
|
change_table :activities do |t|
|
@@ -14,7 +14,7 @@ module PublicActivity
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
module ORM
|
19
19
|
module ActiveRecord
|
20
20
|
# The ActiveRecord model containing
|
@@ -25,20 +25,22 @@ module PublicActivity
|
|
25
25
|
self.abstract_class = true
|
26
26
|
|
27
27
|
# Define polymorphic association to the parent
|
28
|
-
belongs_to :trackable, :
|
28
|
+
belongs_to :trackable, polymorphic: true
|
29
29
|
|
30
30
|
case ::ActiveRecord::VERSION::MAJOR
|
31
|
-
when
|
32
|
-
|
33
|
-
belongs_to :owner, :polymorphic => true
|
34
|
-
# Define ownership to a resource targeted by this activity
|
35
|
-
belongs_to :recipient, :polymorphic => true
|
36
|
-
when 5..6
|
37
|
-
with_options(:required => false) do
|
31
|
+
when 5
|
32
|
+
with_options(required: false) do
|
38
33
|
# Define ownership to a resource responsible for this activity
|
39
|
-
belongs_to :owner, :
|
34
|
+
belongs_to :owner, polymorphic: true
|
40
35
|
# Define ownership to a resource targeted by this activity
|
41
|
-
belongs_to :recipient, :
|
36
|
+
belongs_to :recipient, polymorphic: true
|
37
|
+
end
|
38
|
+
when 6..7
|
39
|
+
with_options(optional: true) do
|
40
|
+
# Define ownership to a resource responsible for this activity
|
41
|
+
belongs_to :owner, polymorphic: true
|
42
|
+
# Define ownership to a resource targeted by this activity
|
43
|
+
belongs_to :recipient, polymorphic: true
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -49,9 +51,11 @@ module PublicActivity
|
|
49
51
|
else
|
50
52
|
warn("[WARN] table #{name} doesn't exist. Skipping PublicActivity::Activity#parameters's serialization")
|
51
53
|
end
|
52
|
-
rescue ::ActiveRecord::NoDatabaseError
|
54
|
+
rescue ::ActiveRecord::NoDatabaseError
|
53
55
|
warn("[WARN] database doesn't exist. Skipping PublicActivity::Activity#parameters's serialization")
|
54
|
-
rescue ::
|
56
|
+
rescue ::ActiveRecord::ConnectionNotEstablished
|
57
|
+
warn("[WARN] couldn't connect to database. Skipping PublicActivity::Activity#parameters's serialization")
|
58
|
+
rescue ::PG::ConnectionBad
|
55
59
|
warn("[WARN] couldn't connect to database. Skipping PublicActivity::Activity#parameters's serialization")
|
56
60
|
rescue Mysql2::Error::ConnectionError
|
57
61
|
warn("[WARN] couldn't connect to database. Skipping PublicActivity::Activity#parameters's serialization")
|
@@ -12,7 +12,8 @@ module PublicActivity
|
|
12
12
|
k.unshift('activity') if k.first != 'activity'
|
13
13
|
k = k.join('.')
|
14
14
|
|
15
|
-
|
15
|
+
translate_params = parameters.merge(params) || {}
|
16
|
+
I18n.t(k, **translate_params)
|
16
17
|
end
|
17
18
|
|
18
19
|
# Renders activity from views.
|
@@ -142,7 +143,7 @@ module PublicActivity
|
|
142
143
|
def prepare_layout(root, layout)
|
143
144
|
if layout
|
144
145
|
path = layout.to_s
|
145
|
-
unless path.
|
146
|
+
unless path.start_with?(root) || path.start_with?("/")
|
146
147
|
return File.join(root, path)
|
147
148
|
end
|
148
149
|
end
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
../../lib/generators/public_activity/migration/templates/migration.rb
|
@@ -1,10 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
class CreateArticles < MigrationsBase
|
3
|
+
class CreateArticles < ActiveRecord::Migration[5.0]
|
6
4
|
def self.up
|
7
|
-
puts "creating"
|
8
5
|
create_table :articles do |t|
|
9
6
|
t.string :name
|
10
7
|
t.boolean :published
|
data/test/test_activist.rb
CHANGED
@@ -5,54 +5,55 @@ require 'test_helper'
|
|
5
5
|
describe PublicActivity::Activist do
|
6
6
|
it 'adds owner association' do
|
7
7
|
klass = article
|
8
|
-
klass
|
8
|
+
assert_respond_to klass, :activist
|
9
9
|
klass.activist
|
10
|
-
klass.new
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
assert_respond_to klass.new, :activities
|
11
|
+
|
12
|
+
case ENV['PA_ORM']
|
13
|
+
when 'active_record'
|
14
|
+
assert_equal klass.reflect_on_association(:activities_as_owner).options[:as], :owner
|
15
|
+
when 'mongoid'
|
16
|
+
assert_equal klass.reflect_on_association(:activities_as_owner).options[:inverse_of], :owner
|
17
|
+
when 'mongo_mapper'
|
18
|
+
assert_equal klass.associations[:activities_as_owner].options[:as], :owner
|
18
19
|
end
|
19
20
|
|
20
|
-
if ENV[
|
21
|
-
klass.associations[:activities_as_owner].options[:class_name]
|
21
|
+
if ENV['PA_ORM'] == 'mongo_mapper'
|
22
|
+
assert_equal klass.associations[:activities_as_owner].options[:class_name], '::PublicActivity::Activity'
|
22
23
|
else
|
23
|
-
klass.reflect_on_association(:activities_as_owner).options[:class_name]
|
24
|
+
assert_equal klass.reflect_on_association(:activities_as_owner).options[:class_name], '::PublicActivity::Activity'
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'returns activities from association' do
|
28
29
|
case PublicActivity::Config.orm
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
30
|
+
when :active_record
|
31
|
+
class ActivistUser < ActiveRecord::Base
|
32
|
+
include PublicActivity::Model
|
33
|
+
self.table_name = 'users'
|
34
|
+
activist
|
35
|
+
end
|
36
|
+
when :mongoid
|
37
|
+
class ActivistUser
|
38
|
+
include Mongoid::Document
|
39
|
+
include PublicActivity::Model
|
40
|
+
activist
|
41
|
+
|
42
|
+
field :name, type: String
|
43
|
+
end
|
44
|
+
when :mongo_mapper
|
45
|
+
class ActivistUser
|
46
|
+
include MongoMapper::Document
|
47
|
+
include PublicActivity::Model
|
48
|
+
activist
|
49
|
+
|
50
|
+
key :name, String
|
51
|
+
end
|
51
52
|
end
|
52
|
-
owner = ActivistUser.create(:
|
53
|
+
owner = ActivistUser.create(name: 'Peter Pan')
|
53
54
|
a = article(owner: owner).new
|
54
55
|
a.save
|
55
56
|
|
56
|
-
owner.activities_as_owner.length
|
57
|
+
assert_equal owner.activities_as_owner.length, 1
|
57
58
|
end
|
58
59
|
end
|
data/test/test_activity.rb
CHANGED
@@ -4,86 +4,84 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
describe 'PublicActivity::Activity Rendering' do
|
6
6
|
describe '#text' do
|
7
|
-
subject { PublicActivity::Activity.new(:
|
7
|
+
subject { PublicActivity::Activity.new(key: 'activity.test', parameters: { one: 1 }) }
|
8
8
|
|
9
9
|
specify '#text uses translations' do
|
10
10
|
subject.save
|
11
|
-
I18n.config.backend.store_translations(:en,
|
12
|
-
|
13
|
-
|
14
|
-
subject.text(:two => 2).must_equal('1 2')
|
15
|
-
subject.parameters.must_equal({:one => 1})
|
11
|
+
I18n.config.backend.store_translations(:en, activity: { test: '%{one} %{two}' })
|
12
|
+
assert_equal subject.text(two: 2), '1 2'
|
13
|
+
assert_equal subject.parameters, one: 1
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
17
|
describe '#render' do
|
20
18
|
subject do
|
21
|
-
s = PublicActivity::Activity.new(:
|
19
|
+
s = PublicActivity::Activity.new(key: 'activity.test', parameters: { one: 1 })
|
22
20
|
s.save && s
|
23
21
|
end
|
24
22
|
|
25
23
|
let(:template_output) { "<strong>1, 2</strong>\n<em>activity.test, #{subject.id}</em>\n" }
|
26
|
-
before { @controller.view_paths << File.expand_path('
|
24
|
+
before { @controller.view_paths << File.expand_path('views', __dir__) }
|
27
25
|
|
28
26
|
it 'uses view partials when available' do
|
29
27
|
PublicActivity.set_controller(Struct.new(:current_user).new('fake'))
|
30
|
-
subject.render(self, :
|
31
|
-
rendered
|
28
|
+
subject.render(self, two: 2)
|
29
|
+
assert_equal rendered, "#{template_output}fake\n"
|
32
30
|
end
|
33
31
|
|
34
32
|
it 'uses requested partial'
|
35
33
|
|
36
34
|
it 'uses view partials without controller' do
|
37
35
|
PublicActivity.set_controller(nil)
|
38
|
-
subject.render(self, :
|
39
|
-
rendered
|
36
|
+
subject.render(self, two: 2)
|
37
|
+
assert_equal rendered, "#{template_output}\n"
|
40
38
|
end
|
41
39
|
|
42
40
|
it 'provides local variables' do
|
43
41
|
PublicActivity.set_controller(nil)
|
44
|
-
subject.render(self, locals: {two: 2})
|
45
|
-
rendered.chomp
|
42
|
+
subject.render(self, locals: { two: 2 })
|
43
|
+
assert_equal rendered.chomp, '2'
|
46
44
|
end
|
47
45
|
|
48
46
|
it 'uses translations only when requested' do
|
49
|
-
I18n.config.backend.store_translations(:en,
|
50
|
-
{:activity => {:test => '%{one} %{two}'}}
|
51
|
-
)
|
47
|
+
I18n.config.backend.store_translations(:en, activity: { test: '%{one} %{two}' })
|
52
48
|
@controller.view_paths.paths.clear
|
53
49
|
subject.render(self, two: 2, display: :i18n)
|
54
|
-
rendered
|
50
|
+
assert_equal rendered, '1 2'
|
55
51
|
end
|
56
52
|
|
57
|
-
it
|
53
|
+
it 'pass all params to view context' do
|
58
54
|
view_context = mock('ViewContext')
|
59
55
|
PublicActivity.set_controller(nil)
|
60
|
-
view_context.expects(:render).with
|
61
|
-
subject.render(view_context, :
|
56
|
+
view_context.expects(:render).with { |params| params[:formats] == ['json'] }
|
57
|
+
subject.render(view_context, formats: ['json'])
|
62
58
|
end
|
63
59
|
|
64
|
-
it
|
60
|
+
it 'uses specified layout' do
|
65
61
|
PublicActivity.set_controller(nil)
|
66
|
-
subject.render(self, :
|
67
|
-
rendered
|
62
|
+
subject.render(self, layout: 'activity')
|
63
|
+
assert_includes rendered, 'Here be the layouts'
|
68
64
|
|
69
|
-
subject.render(self, :
|
70
|
-
rendered
|
65
|
+
subject.render(self, layout: 'layouts/activity')
|
66
|
+
assert_includes rendered, 'Here be the layouts'
|
71
67
|
|
72
|
-
subject.render(self, :
|
73
|
-
rendered
|
68
|
+
subject.render(self, layout: :activity)
|
69
|
+
assert_includes rendered, 'Here be the layouts'
|
74
70
|
end
|
75
71
|
|
76
|
-
it
|
77
|
-
subject.render(self, :
|
78
|
-
rendered
|
72
|
+
it 'accepts a custom layout root' do
|
73
|
+
subject.render(self, layout: :layout, layout_root: 'custom')
|
74
|
+
assert_includes rendered, 'Here be the custom layouts'
|
79
75
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
|
77
|
+
it 'accepts an absolute layout path' do
|
78
|
+
subject.render(self, layout: '/custom/layout')
|
79
|
+
assert_includes rendered, 'Here be the custom layouts'
|
83
80
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
|
82
|
+
it 'accepts a template root' do
|
83
|
+
subject.render(self, root: 'custom')
|
84
|
+
assert_includes rendered, 'Custom Template Root'
|
87
85
|
end
|
88
86
|
end
|
89
87
|
end
|