public_activity 2.0.0 → 2.0.1
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/Rakefile +4 -5
- data/lib/generators/public_activity/migration/migration_generator.rb +1 -1
- data/lib/generators/public_activity/migration/templates/migration.rb +10 -11
- data/lib/generators/public_activity/migration_upgrade/migration_upgrade_generator.rb +2 -1
- data/lib/generators/public_activity/migration_upgrade/templates/upgrade.rb +2 -2
- data/lib/public_activity/orm/active_record/activity.rb +12 -10
- data/lib/public_activity/version.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 +37 -38
- data/test/test_common.rb +58 -49
- data/test/test_controller_integration.rb +17 -11
- data/test/test_generators.rb +5 -5
- data/test/test_helper.rb +13 -23
- data/test/test_testing.rb +11 -10
- data/test/test_tracking.rb +169 -147
- data/test/test_view_helpers.rb +5 -5
- metadata +2 -4
- 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: f12beefe37e1f8d3c8fbaada9d0318de0838dd8514c1b32c93d47b97d7af6d57
|
4
|
+
data.tar.gz: bf5e00de61c14049488a4fe549a9bc198367eca931e9d73c0d47dd0ba9c173f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a95d53aac261777b5b52a1a35add35acc0d93d742d4cbb3d2f4deea08ec552ade88b61cbd4447146172953b4ecda464b3ea2539ecb82d58d26c7756cdc5c52b7
|
7
|
+
data.tar.gz: 7dc0ddb8a3622c52b856f1b5a1f45124d300892559800cd62b06115bc14854d0ff84bf33b5a88a50f9f6ae7c060f298f171cb7d082f9bae3aa9696dfdcb36d5a
|
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
|
-
|
@@ -9,7 +9,7 @@ module PublicActivity
|
|
9
9
|
class MigrationGenerator < ActiveRecord::Generators::Base
|
10
10
|
extend Base
|
11
11
|
|
12
|
-
argument :name, :
|
12
|
+
argument :name, type: :string, default: 'create_activities'
|
13
13
|
# Create migration in project's folder
|
14
14
|
def generate_files
|
15
15
|
migration_template 'migration.rb', "db/migrate/#{name}.rb"
|
@@ -1,24 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'migrations_base'
|
4
|
-
|
5
3
|
# Migration responsible for creating a table with activities
|
6
|
-
class CreateActivities <
|
4
|
+
class CreateActivities < ActiveRecord::Migration[5.0]
|
7
5
|
def self.up
|
8
6
|
create_table :activities do |t|
|
9
|
-
t.belongs_to :trackable, :
|
10
|
-
t.belongs_to :owner, :
|
11
|
-
t.string
|
12
|
-
t.text
|
13
|
-
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
|
14
12
|
|
15
13
|
t.timestamps
|
16
14
|
end
|
17
15
|
|
18
|
-
add_index :activities, [
|
19
|
-
add_index :activities, [
|
20
|
-
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]
|
21
19
|
end
|
20
|
+
|
22
21
|
# Drop table
|
23
22
|
def self.down
|
24
23
|
drop_table :activities
|
@@ -9,7 +9,8 @@ module PublicActivity
|
|
9
9
|
class MigrationUpgradeGenerator < ActiveRecord::Generators::Base
|
10
10
|
extend Base
|
11
11
|
|
12
|
-
argument :name, :
|
12
|
+
argument :name, type: :string, default: 'upgrade_activities'
|
13
|
+
|
13
14
|
# Create migration in project's folder
|
14
15
|
def generate_files
|
15
16
|
migration_template 'upgrade.rb', "db/migrate/#{name}.rb"
|
@@ -1,11 +1,11 @@
|
|
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|
|
8
|
-
t.belongs_to :recipient, :
|
8
|
+
t.belongs_to :recipient, polymorphic: true
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -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..7
|
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
|
|
@@ -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,85 @@ 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(:
|
22
|
-
s.save
|
19
|
+
s = PublicActivity::Activity.new(key: 'activity.test', parameters: { one: 1 })
|
20
|
+
s.save
|
21
|
+
s
|
23
22
|
end
|
24
23
|
|
25
24
|
let(:template_output) { "<strong>1, 2</strong>\n<em>activity.test, #{subject.id}</em>\n" }
|
26
|
-
before { @controller.view_paths << File.expand_path('
|
25
|
+
before { @controller.view_paths << File.expand_path('views', __dir__) }
|
27
26
|
|
28
27
|
it 'uses view partials when available' do
|
29
28
|
PublicActivity.set_controller(Struct.new(:current_user).new('fake'))
|
30
|
-
subject.render(self, :
|
31
|
-
rendered
|
29
|
+
subject.render(self, two: 2)
|
30
|
+
assert_equal rendered, "#{template_output}fake\n"
|
32
31
|
end
|
33
32
|
|
34
33
|
it 'uses requested partial'
|
35
34
|
|
36
35
|
it 'uses view partials without controller' do
|
37
36
|
PublicActivity.set_controller(nil)
|
38
|
-
subject.render(self, :
|
39
|
-
rendered
|
37
|
+
subject.render(self, two: 2)
|
38
|
+
assert_equal rendered, "#{template_output}\n"
|
40
39
|
end
|
41
40
|
|
42
41
|
it 'provides local variables' do
|
43
42
|
PublicActivity.set_controller(nil)
|
44
|
-
subject.render(self, locals: {two: 2})
|
45
|
-
rendered.chomp
|
43
|
+
subject.render(self, locals: { two: 2 })
|
44
|
+
assert_equal rendered.chomp, '2'
|
46
45
|
end
|
47
46
|
|
48
47
|
it 'uses translations only when requested' do
|
49
|
-
I18n.config.backend.store_translations(:en,
|
50
|
-
{:activity => {:test => '%{one} %{two}'}}
|
51
|
-
)
|
48
|
+
I18n.config.backend.store_translations(:en, activity: { test: '%{one} %{two}' })
|
52
49
|
@controller.view_paths.paths.clear
|
53
50
|
subject.render(self, two: 2, display: :i18n)
|
54
|
-
rendered
|
51
|
+
assert_equal rendered, '1 2'
|
55
52
|
end
|
56
53
|
|
57
|
-
it
|
54
|
+
it 'pass all params to view context' do
|
58
55
|
view_context = mock('ViewContext')
|
59
56
|
PublicActivity.set_controller(nil)
|
60
|
-
view_context.expects(:render).with
|
61
|
-
subject.render(view_context, :
|
57
|
+
view_context.expects(:render).with { |params| params[:formats] == ['json'] }
|
58
|
+
subject.render(view_context, formats: ['json'])
|
62
59
|
end
|
63
60
|
|
64
|
-
it
|
61
|
+
it 'uses specified layout' do
|
65
62
|
PublicActivity.set_controller(nil)
|
66
|
-
subject.render(self, :
|
67
|
-
rendered
|
63
|
+
subject.render(self, layout: 'activity')
|
64
|
+
assert_includes rendered, 'Here be the layouts'
|
68
65
|
|
69
|
-
subject.render(self, :
|
70
|
-
rendered
|
66
|
+
subject.render(self, layout: 'layouts/activity')
|
67
|
+
assert_includes rendered, 'Here be the layouts'
|
71
68
|
|
72
|
-
subject.render(self, :
|
73
|
-
rendered
|
69
|
+
subject.render(self, layout: :activity)
|
70
|
+
assert_includes rendered, 'Here be the layouts'
|
74
71
|
end
|
75
72
|
|
76
|
-
it
|
77
|
-
subject.render(self, :
|
78
|
-
rendered
|
73
|
+
it 'accepts a custom layout root' do
|
74
|
+
subject.render(self, layout: :layout, layout_root: 'custom')
|
75
|
+
assert_includes rendered, 'Here be the custom layouts'
|
79
76
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
|
78
|
+
it 'accepts an absolute layout path' do
|
79
|
+
subject.render(self, layout: '/custom/layout')
|
80
|
+
assert_includes rendered, 'Here be the custom layouts'
|
83
81
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
|
83
|
+
it 'accepts a template root' do
|
84
|
+
subject.render(self, root: 'custom')
|
85
|
+
assert_includes rendered, 'Custom Template Root'
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
data/test/test_common.rb
CHANGED
@@ -4,55 +4,60 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
describe PublicActivity::Common do
|
6
6
|
before do
|
7
|
-
@owner = User.create(:
|
8
|
-
@recipient = User.create(:
|
9
|
-
@options = {
|
10
|
-
|
11
|
-
|
7
|
+
@owner = User.create(name: 'Peter Pan')
|
8
|
+
@recipient = User.create(name: 'Bruce Wayne')
|
9
|
+
@options = {
|
10
|
+
params: {
|
11
|
+
author_name: 'Peter',
|
12
|
+
summary: 'Default summary goes here...'
|
13
|
+
},
|
14
|
+
owner: @owner,
|
15
|
+
recipient: @recipient
|
16
|
+
}
|
12
17
|
end
|
13
18
|
subject { article(@options).new }
|
14
19
|
|
15
20
|
it 'prioritizes parameters passed to #create_activity' do
|
16
21
|
subject.save
|
17
|
-
subject.create_activity(:test, params: {author_name: 'Pan'}).parameters[:author_name]
|
18
|
-
subject.create_activity(:test, parameters: {author_name: 'Pan'}).parameters[:author_name]
|
19
|
-
subject.create_activity(:test, params: {author_name: nil}).parameters[:author_name]
|
20
|
-
subject.create_activity(:test, parameters: {author_name: nil}).parameters[:author_name]
|
22
|
+
assert_equal subject.create_activity(:test, params: { author_name: 'Pan' }).parameters[:author_name], 'Pan'
|
23
|
+
assert_equal subject.create_activity(:test, parameters: { author_name: 'Pan' }).parameters[:author_name], 'Pan'
|
24
|
+
assert_nil subject.create_activity(:test, params: { author_name: nil }).parameters[:author_name]
|
25
|
+
assert_nil subject.create_activity(:test, parameters: { author_name: nil }).parameters[:author_name]
|
21
26
|
end
|
22
27
|
|
23
28
|
it 'prioritizes owner passed to #create_activity' do
|
24
29
|
subject.save
|
25
|
-
subject.create_activity(:test, owner: @recipient).owner
|
26
|
-
subject.create_activity(:test, owner: nil).owner
|
30
|
+
assert_equal subject.create_activity(:test, owner: @recipient).owner, @recipient
|
31
|
+
assert_nil subject.create_activity(:test, owner: nil).owner
|
27
32
|
end
|
28
33
|
|
29
34
|
it 'prioritizes recipient passed to #create_activity' do
|
30
35
|
subject.save
|
31
|
-
subject.create_activity(:test, recipient: @owner).recipient
|
32
|
-
subject.create_activity(:test, recipient: nil).recipient
|
36
|
+
assert_equal subject.create_activity(:test, recipient: @owner).recipient, @owner
|
37
|
+
assert_nil subject.create_activity(:test, recipient: nil).recipient
|
33
38
|
end
|
34
39
|
|
35
40
|
it 'uses global fields' do
|
36
41
|
subject.save
|
37
42
|
activity = subject.activities.last
|
38
|
-
activity.parameters
|
39
|
-
activity.owner
|
43
|
+
assert_equal activity.parameters, @options[:params]
|
44
|
+
assert_equal activity.owner, @owner
|
40
45
|
end
|
41
46
|
|
42
47
|
it 'allows custom fields' do
|
43
48
|
subject.save
|
44
|
-
subject.create_activity :with_custom_fields, nonstandard:
|
45
|
-
subject.activities.last.nonstandard
|
49
|
+
subject.create_activity :with_custom_fields, nonstandard: 'Custom allowed'
|
50
|
+
assert_equal subject.activities.last.nonstandard, 'Custom allowed'
|
46
51
|
end
|
47
52
|
|
48
53
|
it '#create_activity returns a new activity object' do
|
49
54
|
subject.save
|
50
|
-
subject.create_activity(
|
55
|
+
assert subject.create_activity('some.key')
|
51
56
|
end
|
52
57
|
|
53
58
|
it '#create_activity! returns a new activity object' do
|
54
59
|
subject.save
|
55
|
-
activity = subject.create_activity!(
|
60
|
+
activity = subject.create_activity!('some.key')
|
56
61
|
assert activity.persisted?
|
57
62
|
assert_equal 'article.some.key', activity.key
|
58
63
|
end
|
@@ -63,103 +68,102 @@ describe PublicActivity::Common do
|
|
63
68
|
subject.save
|
64
69
|
subject.save
|
65
70
|
after_count = subject.activities.count
|
66
|
-
before_count
|
71
|
+
assert_equal before_count, after_count
|
67
72
|
end
|
68
73
|
|
69
|
-
|
70
74
|
it 'allows passing owner through #create_activity' do
|
71
75
|
article = article().new
|
72
76
|
article.save
|
73
|
-
activity = article.create_activity(
|
74
|
-
activity.owner
|
77
|
+
activity = article.create_activity('some.key', owner: @owner)
|
78
|
+
assert_equal activity.owner, @owner
|
75
79
|
end
|
76
80
|
|
77
81
|
it 'allows resolving custom fields' do
|
78
|
-
subject.name =
|
82
|
+
subject.name = 'Resolving is great'
|
79
83
|
subject.published = true
|
80
84
|
subject.save
|
81
85
|
subject.create_activity :with_custom_fields, nonstandard: :name
|
82
|
-
subject.activities.last.nonstandard
|
83
|
-
subject.create_activity :with_custom_fields_2, nonstandard: proc {|_, model| model.published.to_s}
|
84
|
-
subject.activities.last.nonstandard
|
86
|
+
assert_equal subject.activities.last.nonstandard, 'Resolving is great'
|
87
|
+
subject.create_activity :with_custom_fields_2, nonstandard: proc { |_, model| model.published.to_s }
|
88
|
+
assert_equal subject.activities.last.nonstandard, 'true'
|
85
89
|
end
|
86
90
|
|
87
91
|
it 'inherits instance parameters' do
|
88
|
-
subject.activity :
|
92
|
+
subject.activity params: { author_name: 'Michael' }
|
89
93
|
subject.save
|
90
94
|
activity = subject.activities.last
|
91
95
|
|
92
|
-
activity.parameters[:author_name]
|
96
|
+
assert_equal activity.parameters[:author_name], 'Michael'
|
93
97
|
end
|
94
98
|
|
95
99
|
it 'accepts instance recipient' do
|
96
|
-
subject.activity :
|
100
|
+
subject.activity recipient: @recipient
|
97
101
|
subject.save
|
98
|
-
subject.activities.last.recipient
|
102
|
+
assert_equal subject.activities.last.recipient, @recipient
|
99
103
|
end
|
100
104
|
|
101
105
|
it 'accepts instance owner' do
|
102
|
-
subject.activity :
|
106
|
+
subject.activity owner: @owner
|
103
107
|
subject.save
|
104
|
-
subject.activities.last.owner
|
108
|
+
assert_equal subject.activities.last.owner, @owner
|
105
109
|
end
|
106
110
|
|
107
111
|
it 'accepts owner as a symbol' do
|
108
|
-
klass = article(:
|
109
|
-
@article = klass.new(:
|
112
|
+
klass = article(owner: :user)
|
113
|
+
@article = klass.new(user: @owner)
|
110
114
|
@article.save
|
111
115
|
activity = @article.activities.last
|
112
116
|
|
113
|
-
activity.owner
|
117
|
+
assert_equal activity.owner, @owner
|
114
118
|
end
|
115
119
|
|
116
120
|
it 'reports PublicActivity::Activity as the base class' do
|
117
|
-
if ENV[
|
121
|
+
if ENV['PA_ORM'] == 'active_record' # Only relevant for ActiveRecord
|
118
122
|
subject.save
|
119
|
-
subject.activities.last.class.base_class
|
123
|
+
assert_equal subject.activities.last.class.base_class, PublicActivity::Activity
|
120
124
|
end
|
121
125
|
end
|
122
126
|
|
123
127
|
describe '#prepare_key' do
|
124
128
|
describe 'for class#activity_key method' do
|
125
129
|
before do
|
126
|
-
@article = article(:
|
130
|
+
@article = article(owner: :user).new(user: @owner)
|
127
131
|
end
|
128
132
|
|
129
133
|
it 'assigns key to value of activity_key if set' do
|
130
|
-
def @article.activity_key;
|
134
|
+
def @article.activity_key; 'my_custom_key' end
|
131
135
|
|
132
|
-
@article.prepare_key(:create, {})
|
136
|
+
assert_equal @article.prepare_key(:create, {}), 'my_custom_key'
|
133
137
|
end
|
134
138
|
|
135
139
|
it 'assigns key based on class name as fallback' do
|
136
140
|
def @article.activity_key; nil end
|
137
141
|
|
138
|
-
@article.prepare_key(:create)
|
142
|
+
assert_equal @article.prepare_key(:create), 'article.create'
|
139
143
|
end
|
140
144
|
|
141
145
|
it 'assigns key value from options hash' do
|
142
|
-
@article.prepare_key(:create, :
|
146
|
+
assert_equal @article.prepare_key(:create, key: :my_custom_key), 'my_custom_key'
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
146
150
|
describe 'for camel cased classes' do
|
147
151
|
before do
|
148
|
-
class CamelCase < article(:
|
152
|
+
class CamelCase < article(owner: :user)
|
149
153
|
def self.name; 'CamelCase' end
|
150
154
|
end
|
151
155
|
@camel_case = CamelCase.new
|
152
156
|
end
|
153
157
|
|
154
158
|
it 'assigns generates key from class name' do
|
155
|
-
@camel_case.prepare_key(:create, {})
|
159
|
+
assert_equal @camel_case.prepare_key(:create, {}), 'camel_case.create'
|
156
160
|
end
|
157
161
|
end
|
158
162
|
|
159
163
|
describe 'for namespaced classes' do
|
160
164
|
before do
|
161
165
|
module ::MyNamespace;
|
162
|
-
class CamelCase < article(:
|
166
|
+
class CamelCase < article(owner: :user)
|
163
167
|
def self.name; 'MyNamespace::CamelCase' end
|
164
168
|
end
|
165
169
|
end
|
@@ -167,13 +171,15 @@ describe PublicActivity::Common do
|
|
167
171
|
end
|
168
172
|
|
169
173
|
it 'assigns key value from options hash' do
|
170
|
-
@namespaced_camel_case.prepare_key(:create, {})
|
174
|
+
assert_equal @namespaced_camel_case.prepare_key(:create, {}), 'my_namespace_camel_case.create'
|
171
175
|
end
|
172
176
|
end
|
173
177
|
end
|
174
178
|
|
175
179
|
# no key implicated or given
|
176
|
-
specify
|
180
|
+
specify do
|
181
|
+
assert_raises(PublicActivity::NoKeyProvided) { subject.prepare_settings }
|
182
|
+
end
|
177
183
|
|
178
184
|
describe 'resolving values' do
|
179
185
|
it 'allows procs with models and controllers' do
|
@@ -182,7 +188,7 @@ describe PublicActivity::Common do
|
|
182
188
|
controller = mock('controller')
|
183
189
|
controller.expects(:current_user).returns(:cu)
|
184
190
|
PublicActivity.set_controller(controller)
|
185
|
-
p = proc {|c, m|
|
191
|
+
p = proc { |c, m|
|
186
192
|
assert_equal :cu, c.current_user
|
187
193
|
assert_equal 5, m.accessor
|
188
194
|
}
|
@@ -191,4 +197,7 @@ describe PublicActivity::Common do
|
|
191
197
|
end
|
192
198
|
end
|
193
199
|
|
200
|
+
def teardown
|
201
|
+
PublicActivity.set_controller(nil)
|
202
|
+
end
|
194
203
|
end
|