public_activity 1.6.4 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed14383fee5beb59cc2e6963aec4b151edac0d910dba6ae076f158dce0791ba8
4
- data.tar.gz: 2cb71a7c50553cddeb0500c882bf7709a780b3ca8cb60318da8d7e4b6be00e77
3
+ metadata.gz: aa4a946e3b5ec45ad643a08338a4b150ddb912fa0489e053dc9d310727cc9367
4
+ data.tar.gz: ba63edb8f4731b604cee4043fd31bf76abdcf45ca9eab971502ec7caa1b31939
5
5
  SHA512:
6
- metadata.gz: 57aed9400b411ae43657dea3944be5aa062139356e4c5a686c97f84439369619ea6471e1685946d71c63a8765014250467646f2da37699e4f8b7723ec09e8b64
7
- data.tar.gz: '098d249436ad7f6d16e1f7d3dfff28a8da55ee567e480a1030db9bdf0d3a68fe4d8ffcc011ad96fc332d5b98d001186b483ba41f3681cacb74a072a6a8e22ccb'
6
+ metadata.gz: 04f48aec79e23c926de4ebe00219c611d5483e1eb9029cd400b501625eb1ca5d4be4b8071f6ae4552888175f2bfa4b7003b4fac9d610b4a649a8a5925d7d9676
7
+ data.tar.gz: cb0abcede1c4c52de2ce8f572b25818f98803413e95959fed94382e3f65b843ae1caab9db10ca76dbfba1b50174e90935d424f58231014803ba017f90ee90416
data/README.md CHANGED
@@ -1,37 +1,35 @@
1
1
  # PublicActivity [![Build Status](https://secure.travis-ci.org/chaps-io/public_activity.svg)](http://travis-ci.org/chaps-io/public_activity) [![Code Climate](https://codeclimate.com/github/chaps-io/public_activity.svg)](https://codeclimate.com/github/chaps-io/public_activity) [![Gem Version](https://badge.fury.io/rb/public_activity.svg)](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 3.0 - 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 - in a similar way to how GitHub does it.
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
- 1. [Example](#example)
20
- * [Demo](#online-demo)
21
- * [Screencast](#screencast)
22
- * **[Common examples](#common-examples)**
23
- 2. [Setup](#setup)
24
- 1. [Gem installation](#gem-installation)
25
- 2. [Database setup](#database-setup)
26
- 3. [Model configuration](#model-configuration)
27
- 4. [Custom activities](#custom-activities)
28
- 5. [Displaying activities](#displaying-activities)
29
- 1. [Activity views](#activity-views)
30
- 2. [i18n](#i18n)
31
- 3. [Testing](#testing)
32
- 4. [Documentation](#documentation)
33
- 5. **[Help](#help)**
34
- 6. [Upgrading](https://github.com/pokonski/public_activity/wiki/Upgrading-from-pre-0.4.0-versions)
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
- #### i18n
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 wether to turn `public_activity` on
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 "bundler/gem_tasks"
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 :default => :test
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
- t.libs << "test"
18
- t.test_files = FileList['test/test*.rb']
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 < (ActiveRecord.version.release() < Gem::Version.new('5.2.0') ? ActiveRecord::Migration : ActiveRecord::Migration[5.2])
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, :polymorphic => true
9
- t.belongs_to :owner, :polymorphic => true
10
- t.string :key
11
- t.text :parameters
12
- t.belongs_to :recipient, :polymorphic => true
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, [:trackable_id, :trackable_type]
18
- add_index :activities, [:owner_id, :owner_type]
19
- add_index :activities, [:recipient_id, :recipient_type]
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, :polymorphic => true
28
+ belongs_to :trackable, polymorphic: true
29
29
 
30
30
  case ::ActiveRecord::VERSION::MAJOR
31
- when 3..4
32
- # Define ownership to a resource responsible for this activity
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, :polymorphic => true
34
+ belongs_to :owner, polymorphic: true
40
35
  # Define ownership to a resource targeted by this activity
41
- belongs_to :recipient, :polymorphic => true
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 => e
54
+ rescue ::ActiveRecord::NoDatabaseError
53
55
  warn("[WARN] database doesn't exist. Skipping PublicActivity::Activity#parameters's serialization")
54
- rescue ::PG::ConnectionBad => e
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
- I18n.t(k, parameters.merge(params) || {})
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.starts_with?(root) || path.starts_with?("/")
146
+ unless path.start_with?(root) || path.start_with?("/")
146
147
  return File.join(root, path)
147
148
  end
148
149
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PublicActivity
4
4
  # A constant with gem's version
5
- VERSION = '1.6.4'
5
+ VERSION = '2.0.2'
6
6
  end
@@ -1 +1 @@
1
- test/migrations/../../lib/generators/public_activity/migration/templates/migration.rb
1
+ ../../lib/generators/public_activity/migration/templates/migration.rb
@@ -1,10 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'migrations_base.rb'
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
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'migrations_base.rb'
4
-
5
- class CreateUsers < MigrationsBase
3
+ class CreateUsers < ActiveRecord::Migration[5.0]
6
4
  def self.up
7
5
  create_table :users do |t|
8
6
  t.string :name
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'migrations_base.rb'
4
-
5
- class AddNonstandardToActivities < MigrationsBase
3
+ class AddNonstandardToActivities < ActiveRecord::Migration[5.0]
6
4
  def change
7
5
  change_table :activities do |t|
8
6
  t.string :nonstandard
@@ -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.must_respond_to :activist
8
+ assert_respond_to klass, :activist
9
9
  klass.activist
10
- klass.new.must_respond_to :activities
11
- case ENV["PA_ORM"]
12
- when "active_record"
13
- klass.reflect_on_association(:activities_as_owner).options[:as].must_equal :owner
14
- when "mongoid"
15
- klass.reflect_on_association(:activities_as_owner).options[:inverse_of].must_equal :owner
16
- when "mongo_mapper"
17
- klass.associations[:activities_as_owner].options[:as].must_equal :owner
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["PA_ORM"] == "mongo_mapper"
21
- klass.associations[:activities_as_owner].options[:class_name].must_equal "::PublicActivity::Activity"
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].must_equal "::PublicActivity::Activity"
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
- when :active_record
30
- class ActivistUser < ActiveRecord::Base
31
- include PublicActivity::Model
32
- self.table_name = 'users'
33
- activist
34
- end
35
- when :mongoid
36
- class ActivistUser
37
- include Mongoid::Document
38
- include PublicActivity::Model
39
- activist
40
-
41
- field :name, type: String
42
- end
43
- when :mongo_mapper
44
- class ActivistUser
45
- include MongoMapper::Document
46
- include PublicActivity::Model
47
- activist
48
-
49
- key :name, String
50
- end
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(:name => "Peter Pan")
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.must_equal 1
57
+ assert_equal owner.activities_as_owner.length, 1
57
58
  end
58
59
  end
@@ -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(:key => 'activity.test', :parameters => {:one => 1}) }
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
- {:activity => {:test => '%{one} %{two}'}}
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(:key => 'activity.test', :parameters => {:one => 1})
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('../views', __FILE__) }
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, :two => 2)
31
- rendered.must_equal template_output + "fake\n"
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, :two => 2)
39
- rendered.must_equal template_output + "\n"
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.must_equal "2"
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.must_equal '1 2'
50
+ assert_equal rendered, '1 2'
55
51
  end
56
52
 
57
- it "pass all params to view context" do
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() {|params| params[:formats] == ['json']}
61
- subject.render(view_context, :formats => ['json'])
56
+ view_context.expects(:render).with { |params| params[:formats] == ['json'] }
57
+ subject.render(view_context, formats: ['json'])
62
58
  end
63
59
 
64
- it "uses specified layout" do
60
+ it 'uses specified layout' do
65
61
  PublicActivity.set_controller(nil)
66
- subject.render(self, :layout => "activity")
67
- rendered.must_include "Here be the layouts"
62
+ subject.render(self, layout: 'activity')
63
+ assert_includes rendered, 'Here be the layouts'
68
64
 
69
- subject.render(self, :layout => "layouts/activity")
70
- rendered.must_include "Here be the layouts"
65
+ subject.render(self, layout: 'layouts/activity')
66
+ assert_includes rendered, 'Here be the layouts'
71
67
 
72
- subject.render(self, :layout => :activity)
73
- rendered.must_include "Here be the layouts"
68
+ subject.render(self, layout: :activity)
69
+ assert_includes rendered, 'Here be the layouts'
74
70
  end
75
71
 
76
- it "accepts a custom layout root" do
77
- subject.render(self, :layout => :layout, :layout_root => "custom")
78
- rendered.must_include "Here be the custom layouts"
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
- it "accepts an absolute layout path" do
81
- subject.render(self, :layout => '/custom/layout')
82
- rendered.must_include "Here be the custom layouts"
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
- it "accepts a template root" do
85
- subject.render(self, :root => "custom")
86
- rendered.must_include "Custom Template Root"
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