public_activity 1.6.3 → 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/Gemfile +2 -0
- data/README.md +26 -28
- data/Rakefile +6 -5
- data/lib/generators/public_activity/migration/migration_generator.rb +3 -1
- data/lib/generators/public_activity/migration/templates/migration.rb +12 -10
- data/lib/generators/public_activity/migration_upgrade/migration_upgrade_generator.rb +4 -1
- data/lib/generators/public_activity/migration_upgrade/templates/upgrade.rb +4 -2
- data/lib/generators/public_activity.rb +2 -0
- data/lib/public_activity/actions/creation.rb +3 -1
- data/lib/public_activity/actions/destruction.rb +2 -0
- data/lib/public_activity/actions/update.rb +2 -0
- data/lib/public_activity/activity.rb +3 -1
- data/lib/public_activity/common.rb +16 -0
- data/lib/public_activity/config.rb +2 -0
- data/lib/public_activity/models/activist.rb +3 -1
- data/lib/public_activity/models/activity.rb +3 -1
- data/lib/public_activity/models/adapter.rb +3 -1
- data/lib/public_activity/models/trackable.rb +3 -1
- data/lib/public_activity/orm/active_record/activist.rb +2 -0
- data/lib/public_activity/orm/active_record/activity.rb +29 -11
- data/lib/public_activity/orm/active_record/adapter.rb +7 -0
- data/lib/public_activity/orm/active_record/trackable.rb +2 -0
- data/lib/public_activity/orm/active_record.rb +3 -1
- data/lib/public_activity/orm/mongo_mapper/activist.rb +2 -0
- data/lib/public_activity/orm/mongo_mapper/activity.rb +2 -0
- data/lib/public_activity/orm/mongo_mapper/adapter.rb +7 -0
- data/lib/public_activity/orm/mongo_mapper/trackable.rb +2 -0
- data/lib/public_activity/orm/mongo_mapper.rb +3 -1
- data/lib/public_activity/orm/mongoid/activist.rb +2 -0
- data/lib/public_activity/orm/mongoid/activity.rb +2 -0
- data/lib/public_activity/orm/mongoid/adapter.rb +7 -0
- data/lib/public_activity/orm/mongoid/trackable.rb +2 -0
- data/lib/public_activity/orm/mongoid.rb +3 -1
- data/lib/public_activity/renderable.rb +5 -2
- data/lib/public_activity/roles/deactivatable.rb +2 -0
- data/lib/public_activity/roles/tracked.rb +2 -0
- data/lib/public_activity/testing.rb +2 -0
- data/lib/public_activity/utility/store_controller.rb +2 -0
- data/lib/public_activity/utility/view_helpers.rb +2 -0
- data/lib/public_activity/version.rb +3 -1
- data/lib/public_activity.rb +2 -0
- data/test/migrations/001_create_activities.rb +1 -1
- data/test/migrations/002_create_articles.rb +2 -3
- data/test/migrations/003_create_users.rb +2 -2
- data/test/migrations/004_add_nonstandard_to_activities.rb +2 -2
- data/test/test_activist.rb +39 -36
- data/test/test_activity.rb +39 -38
- data/test/test_common.rb +66 -48
- data/test/test_controller_integration.rb +19 -11
- data/test/test_generators.rb +7 -17
- data/test/test_helper.rb +20 -24
- data/test/test_testing.rb +13 -10
- data/test/test_tracking.rb +171 -147
- data/test/test_view_helpers.rb +8 -6
- metadata +49 -40
- data/lib/generators/public_activity/activity/activity_generator.rb +0 -17
- data/lib/generators/public_activity/activity/templates/activity.rb +0 -3
- data/test/migrations_base.rb +0 -5
data/test/test_activist.rb
CHANGED
@@ -1,56 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe PublicActivity::Activist do
|
4
6
|
it 'adds owner association' do
|
5
7
|
klass = article
|
6
|
-
klass
|
8
|
+
assert_respond_to klass, :activist
|
7
9
|
klass.activist
|
8
|
-
klass.new
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
19
|
end
|
17
20
|
|
18
|
-
if ENV[
|
19
|
-
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'
|
20
23
|
else
|
21
|
-
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'
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
28
|
it 'returns activities from association' do
|
26
29
|
case PublicActivity::Config.orm
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
49
52
|
end
|
50
|
-
owner = ActivistUser.create(:
|
53
|
+
owner = ActivistUser.create(name: 'Peter Pan')
|
51
54
|
a = article(owner: owner).new
|
52
55
|
a.save
|
53
56
|
|
54
|
-
owner.activities_as_owner.length
|
57
|
+
assert_equal owner.activities_as_owner.length, 1
|
55
58
|
end
|
56
59
|
end
|
data/test/test_activity.rb
CHANGED
@@ -1,87 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe 'PublicActivity::Activity Rendering' do
|
4
6
|
describe '#text' do
|
5
|
-
subject { PublicActivity::Activity.new(:
|
7
|
+
subject { PublicActivity::Activity.new(key: 'activity.test', parameters: { one: 1 }) }
|
6
8
|
|
7
9
|
specify '#text uses translations' do
|
8
10
|
subject.save
|
9
|
-
I18n.config.backend.store_translations(:en,
|
10
|
-
|
11
|
-
|
12
|
-
subject.text(:two => 2).must_equal('1 2')
|
13
|
-
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
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#render' do
|
18
18
|
subject do
|
19
|
-
s = PublicActivity::Activity.new(:
|
20
|
-
s.save
|
19
|
+
s = PublicActivity::Activity.new(key: 'activity.test', parameters: { one: 1 })
|
20
|
+
s.save
|
21
|
+
s
|
21
22
|
end
|
22
23
|
|
23
24
|
let(:template_output) { "<strong>1, 2</strong>\n<em>activity.test, #{subject.id}</em>\n" }
|
24
|
-
before { @controller.view_paths << File.expand_path('
|
25
|
+
before { @controller.view_paths << File.expand_path('views', __dir__) }
|
25
26
|
|
26
27
|
it 'uses view partials when available' do
|
27
28
|
PublicActivity.set_controller(Struct.new(:current_user).new('fake'))
|
28
|
-
subject.render(self, :
|
29
|
-
rendered
|
29
|
+
subject.render(self, two: 2)
|
30
|
+
assert_equal rendered, "#{template_output}fake\n"
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'uses requested partial'
|
33
34
|
|
34
35
|
it 'uses view partials without controller' do
|
35
36
|
PublicActivity.set_controller(nil)
|
36
|
-
subject.render(self, :
|
37
|
-
rendered
|
37
|
+
subject.render(self, two: 2)
|
38
|
+
assert_equal rendered, "#{template_output}\n"
|
38
39
|
end
|
39
40
|
|
40
41
|
it 'provides local variables' do
|
41
42
|
PublicActivity.set_controller(nil)
|
42
|
-
subject.render(self, locals: {two: 2})
|
43
|
-
rendered.chomp
|
43
|
+
subject.render(self, locals: { two: 2 })
|
44
|
+
assert_equal rendered.chomp, '2'
|
44
45
|
end
|
45
46
|
|
46
47
|
it 'uses translations only when requested' do
|
47
|
-
I18n.config.backend.store_translations(:en,
|
48
|
-
{:activity => {:test => '%{one} %{two}'}}
|
49
|
-
)
|
48
|
+
I18n.config.backend.store_translations(:en, activity: { test: '%{one} %{two}' })
|
50
49
|
@controller.view_paths.paths.clear
|
51
50
|
subject.render(self, two: 2, display: :i18n)
|
52
|
-
rendered
|
51
|
+
assert_equal rendered, '1 2'
|
53
52
|
end
|
54
53
|
|
55
|
-
it
|
54
|
+
it 'pass all params to view context' do
|
56
55
|
view_context = mock('ViewContext')
|
57
56
|
PublicActivity.set_controller(nil)
|
58
|
-
view_context.expects(:render).with
|
59
|
-
subject.render(view_context, :
|
57
|
+
view_context.expects(:render).with { |params| params[:formats] == ['json'] }
|
58
|
+
subject.render(view_context, formats: ['json'])
|
60
59
|
end
|
61
60
|
|
62
|
-
it
|
61
|
+
it 'uses specified layout' do
|
63
62
|
PublicActivity.set_controller(nil)
|
64
|
-
subject.render(self, :
|
65
|
-
rendered
|
63
|
+
subject.render(self, layout: 'activity')
|
64
|
+
assert_includes rendered, 'Here be the layouts'
|
66
65
|
|
67
|
-
subject.render(self, :
|
68
|
-
rendered
|
66
|
+
subject.render(self, layout: 'layouts/activity')
|
67
|
+
assert_includes rendered, 'Here be the layouts'
|
69
68
|
|
70
|
-
subject.render(self, :
|
71
|
-
rendered
|
69
|
+
subject.render(self, layout: :activity)
|
70
|
+
assert_includes rendered, 'Here be the layouts'
|
72
71
|
end
|
73
72
|
|
74
|
-
it
|
75
|
-
subject.render(self, :
|
76
|
-
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'
|
77
76
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
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'
|
81
81
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
|
83
|
+
it 'accepts a template root' do
|
84
|
+
subject.render(self, root: 'custom')
|
85
|
+
assert_includes rendered, 'Custom Template Root'
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
data/test/test_common.rb
CHANGED
@@ -1,51 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe PublicActivity::Common do
|
4
6
|
before do
|
5
|
-
@owner = User.create(:
|
6
|
-
@recipient = User.create(:
|
7
|
-
@options = {
|
8
|
-
|
9
|
-
|
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
|
+
}
|
10
17
|
end
|
11
18
|
subject { article(@options).new }
|
12
19
|
|
13
20
|
it 'prioritizes parameters passed to #create_activity' do
|
14
21
|
subject.save
|
15
|
-
subject.create_activity(:test, params: {author_name: 'Pan'}).parameters[:author_name]
|
16
|
-
subject.create_activity(:test, parameters: {author_name: 'Pan'}).parameters[:author_name]
|
17
|
-
subject.create_activity(:test, params: {author_name: nil}).parameters[:author_name]
|
18
|
-
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]
|
19
26
|
end
|
20
27
|
|
21
28
|
it 'prioritizes owner passed to #create_activity' do
|
22
29
|
subject.save
|
23
|
-
subject.create_activity(:test, owner: @recipient).owner
|
24
|
-
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
|
25
32
|
end
|
26
33
|
|
27
34
|
it 'prioritizes recipient passed to #create_activity' do
|
28
35
|
subject.save
|
29
|
-
subject.create_activity(:test, recipient: @owner).recipient
|
30
|
-
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
|
31
38
|
end
|
32
39
|
|
33
40
|
it 'uses global fields' do
|
34
41
|
subject.save
|
35
42
|
activity = subject.activities.last
|
36
|
-
activity.parameters
|
37
|
-
activity.owner
|
43
|
+
assert_equal activity.parameters, @options[:params]
|
44
|
+
assert_equal activity.owner, @owner
|
38
45
|
end
|
39
46
|
|
40
47
|
it 'allows custom fields' do
|
41
48
|
subject.save
|
42
|
-
subject.create_activity :with_custom_fields, nonstandard:
|
43
|
-
subject.activities.last.nonstandard
|
49
|
+
subject.create_activity :with_custom_fields, nonstandard: 'Custom allowed'
|
50
|
+
assert_equal subject.activities.last.nonstandard, 'Custom allowed'
|
44
51
|
end
|
45
52
|
|
46
53
|
it '#create_activity returns a new activity object' do
|
47
54
|
subject.save
|
48
|
-
subject.create_activity(
|
55
|
+
assert subject.create_activity('some.key')
|
56
|
+
end
|
57
|
+
|
58
|
+
it '#create_activity! returns a new activity object' do
|
59
|
+
subject.save
|
60
|
+
activity = subject.create_activity!('some.key')
|
61
|
+
assert activity.persisted?
|
62
|
+
assert_equal 'article.some.key', activity.key
|
49
63
|
end
|
50
64
|
|
51
65
|
it 'update action should not create activity on save unless model changed' do
|
@@ -54,103 +68,102 @@ describe PublicActivity::Common do
|
|
54
68
|
subject.save
|
55
69
|
subject.save
|
56
70
|
after_count = subject.activities.count
|
57
|
-
before_count
|
71
|
+
assert_equal before_count, after_count
|
58
72
|
end
|
59
73
|
|
60
|
-
|
61
74
|
it 'allows passing owner through #create_activity' do
|
62
75
|
article = article().new
|
63
76
|
article.save
|
64
|
-
activity = article.create_activity(
|
65
|
-
activity.owner
|
77
|
+
activity = article.create_activity('some.key', owner: @owner)
|
78
|
+
assert_equal activity.owner, @owner
|
66
79
|
end
|
67
80
|
|
68
81
|
it 'allows resolving custom fields' do
|
69
|
-
subject.name =
|
82
|
+
subject.name = 'Resolving is great'
|
70
83
|
subject.published = true
|
71
84
|
subject.save
|
72
85
|
subject.create_activity :with_custom_fields, nonstandard: :name
|
73
|
-
subject.activities.last.nonstandard
|
74
|
-
subject.create_activity :with_custom_fields_2, nonstandard: proc {|_, model| model.published.to_s}
|
75
|
-
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'
|
76
89
|
end
|
77
90
|
|
78
91
|
it 'inherits instance parameters' do
|
79
|
-
subject.activity :
|
92
|
+
subject.activity params: { author_name: 'Michael' }
|
80
93
|
subject.save
|
81
94
|
activity = subject.activities.last
|
82
95
|
|
83
|
-
activity.parameters[:author_name]
|
96
|
+
assert_equal activity.parameters[:author_name], 'Michael'
|
84
97
|
end
|
85
98
|
|
86
99
|
it 'accepts instance recipient' do
|
87
|
-
subject.activity :
|
100
|
+
subject.activity recipient: @recipient
|
88
101
|
subject.save
|
89
|
-
subject.activities.last.recipient
|
102
|
+
assert_equal subject.activities.last.recipient, @recipient
|
90
103
|
end
|
91
104
|
|
92
105
|
it 'accepts instance owner' do
|
93
|
-
subject.activity :
|
106
|
+
subject.activity owner: @owner
|
94
107
|
subject.save
|
95
|
-
subject.activities.last.owner
|
108
|
+
assert_equal subject.activities.last.owner, @owner
|
96
109
|
end
|
97
110
|
|
98
111
|
it 'accepts owner as a symbol' do
|
99
|
-
klass = article(:
|
100
|
-
@article = klass.new(:
|
112
|
+
klass = article(owner: :user)
|
113
|
+
@article = klass.new(user: @owner)
|
101
114
|
@article.save
|
102
115
|
activity = @article.activities.last
|
103
116
|
|
104
|
-
activity.owner
|
117
|
+
assert_equal activity.owner, @owner
|
105
118
|
end
|
106
119
|
|
107
120
|
it 'reports PublicActivity::Activity as the base class' do
|
108
|
-
if ENV[
|
121
|
+
if ENV['PA_ORM'] == 'active_record' # Only relevant for ActiveRecord
|
109
122
|
subject.save
|
110
|
-
subject.activities.last.class.base_class
|
123
|
+
assert_equal subject.activities.last.class.base_class, PublicActivity::Activity
|
111
124
|
end
|
112
125
|
end
|
113
126
|
|
114
127
|
describe '#prepare_key' do
|
115
128
|
describe 'for class#activity_key method' do
|
116
129
|
before do
|
117
|
-
@article = article(:
|
130
|
+
@article = article(owner: :user).new(user: @owner)
|
118
131
|
end
|
119
132
|
|
120
133
|
it 'assigns key to value of activity_key if set' do
|
121
|
-
def @article.activity_key;
|
134
|
+
def @article.activity_key; 'my_custom_key' end
|
122
135
|
|
123
|
-
@article.prepare_key(:create, {})
|
136
|
+
assert_equal @article.prepare_key(:create, {}), 'my_custom_key'
|
124
137
|
end
|
125
138
|
|
126
139
|
it 'assigns key based on class name as fallback' do
|
127
140
|
def @article.activity_key; nil end
|
128
141
|
|
129
|
-
@article.prepare_key(:create)
|
142
|
+
assert_equal @article.prepare_key(:create), 'article.create'
|
130
143
|
end
|
131
144
|
|
132
145
|
it 'assigns key value from options hash' do
|
133
|
-
@article.prepare_key(:create, :
|
146
|
+
assert_equal @article.prepare_key(:create, key: :my_custom_key), 'my_custom_key'
|
134
147
|
end
|
135
148
|
end
|
136
149
|
|
137
150
|
describe 'for camel cased classes' do
|
138
151
|
before do
|
139
|
-
class CamelCase < article(:
|
152
|
+
class CamelCase < article(owner: :user)
|
140
153
|
def self.name; 'CamelCase' end
|
141
154
|
end
|
142
155
|
@camel_case = CamelCase.new
|
143
156
|
end
|
144
157
|
|
145
158
|
it 'assigns generates key from class name' do
|
146
|
-
@camel_case.prepare_key(:create, {})
|
159
|
+
assert_equal @camel_case.prepare_key(:create, {}), 'camel_case.create'
|
147
160
|
end
|
148
161
|
end
|
149
162
|
|
150
163
|
describe 'for namespaced classes' do
|
151
164
|
before do
|
152
165
|
module ::MyNamespace;
|
153
|
-
class CamelCase < article(:
|
166
|
+
class CamelCase < article(owner: :user)
|
154
167
|
def self.name; 'MyNamespace::CamelCase' end
|
155
168
|
end
|
156
169
|
end
|
@@ -158,13 +171,15 @@ describe PublicActivity::Common do
|
|
158
171
|
end
|
159
172
|
|
160
173
|
it 'assigns key value from options hash' do
|
161
|
-
@namespaced_camel_case.prepare_key(:create, {})
|
174
|
+
assert_equal @namespaced_camel_case.prepare_key(:create, {}), 'my_namespace_camel_case.create'
|
162
175
|
end
|
163
176
|
end
|
164
177
|
end
|
165
178
|
|
166
179
|
# no key implicated or given
|
167
|
-
specify
|
180
|
+
specify do
|
181
|
+
assert_raises(PublicActivity::NoKeyProvided) { subject.prepare_settings }
|
182
|
+
end
|
168
183
|
|
169
184
|
describe 'resolving values' do
|
170
185
|
it 'allows procs with models and controllers' do
|
@@ -173,7 +188,7 @@ describe PublicActivity::Common do
|
|
173
188
|
controller = mock('controller')
|
174
189
|
controller.expects(:current_user).returns(:cu)
|
175
190
|
PublicActivity.set_controller(controller)
|
176
|
-
p = proc {|c, m|
|
191
|
+
p = proc { |c, m|
|
177
192
|
assert_equal :cu, c.current_user
|
178
193
|
assert_equal 5, m.accessor
|
179
194
|
}
|
@@ -182,4 +197,7 @@ describe PublicActivity::Common do
|
|
182
197
|
end
|
183
198
|
end
|
184
199
|
|
200
|
+
def teardown
|
201
|
+
PublicActivity.set_controller(nil)
|
202
|
+
end
|
185
203
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class StoringController < ActionView::TestCase::TestController
|
@@ -9,31 +11,37 @@ describe PublicActivity::StoreController do
|
|
9
11
|
it 'stores controller' do
|
10
12
|
controller = StoringController.new
|
11
13
|
PublicActivity.set_controller(controller)
|
12
|
-
controller
|
13
|
-
controller
|
14
|
+
assert_same controller, Thread.current[:public_activity_controller]
|
15
|
+
assert_same controller, PublicActivity.get_controller
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'stores controller with a filter in controller' do
|
17
19
|
controller = StoringController.new
|
18
|
-
|
19
|
-
controller.
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
callbacks = controller._process_action_callbacks.select { |c| c.kind == :around }.map(&:filter)
|
22
|
+
assert_includes(callbacks, :store_controller_for_public_activity)
|
23
|
+
|
24
|
+
public_activity_controller =
|
25
|
+
controller.instance_eval do
|
26
|
+
store_controller_for_public_activity do
|
27
|
+
PublicActivity.get_controller
|
28
|
+
end
|
22
29
|
end
|
23
|
-
|
30
|
+
|
31
|
+
assert_equal controller, public_activity_controller
|
24
32
|
end
|
25
33
|
|
26
34
|
it 'stores controller in a threadsafe way' do
|
27
35
|
PublicActivity.set_controller(1)
|
28
|
-
PublicActivity.get_controller
|
36
|
+
assert_equal PublicActivity.get_controller, 1
|
29
37
|
|
30
|
-
Thread.new
|
38
|
+
Thread.new do
|
31
39
|
PublicActivity.set_controller(2)
|
32
40
|
assert_equal 2, PublicActivity.get_controller
|
33
41
|
PublicActivity.set_controller(nil)
|
34
|
-
|
42
|
+
end
|
35
43
|
|
36
|
-
PublicActivity.get_controller
|
44
|
+
assert_equal PublicActivity.get_controller, 1
|
37
45
|
|
38
46
|
PublicActivity.set_controller(nil)
|
39
47
|
end
|
data/test/test_generators.rb
CHANGED
@@ -1,41 +1,31 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if ENV['PA_ORM'] == 'active_record'
|
2
4
|
|
3
5
|
require 'test_helper'
|
4
6
|
require 'rails/generators/test_case'
|
5
|
-
require 'generators/public_activity/activity/activity_generator'
|
6
7
|
require 'generators/public_activity/migration/migration_generator'
|
7
8
|
require 'generators/public_activity/migration_upgrade/migration_upgrade_generator'
|
8
9
|
|
9
|
-
class TestActivityGenerator < Rails::Generators::TestCase
|
10
|
-
tests PublicActivity::Generators::ActivityGenerator
|
11
|
-
destination File.expand_path("../tmp", File.dirname(__FILE__))
|
12
|
-
setup :prepare_destination
|
13
|
-
|
14
|
-
def test_generating_activity_model
|
15
|
-
run_generator
|
16
|
-
assert_file "app/models/activity.rb"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
class TestMigrationGenerator < Rails::Generators::TestCase
|
21
11
|
tests PublicActivity::Generators::MigrationGenerator
|
22
|
-
destination File.expand_path(
|
12
|
+
destination File.expand_path('../tmp', File.dirname(__FILE__))
|
23
13
|
setup :prepare_destination
|
24
14
|
|
25
15
|
def test_generating_activity_model
|
26
16
|
run_generator
|
27
|
-
assert_migration
|
17
|
+
assert_migration 'db/migrate/create_activities.rb'
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
31
21
|
class TestMigrationUpgradeGenerator < Rails::Generators::TestCase
|
32
22
|
tests PublicActivity::Generators::MigrationUpgradeGenerator
|
33
|
-
destination File.expand_path(
|
23
|
+
destination File.expand_path('../tmp', File.dirname(__FILE__))
|
34
24
|
setup :prepare_destination
|
35
25
|
|
36
26
|
def test_generating_activity_model
|
37
27
|
run_generator
|
38
|
-
assert_migration
|
28
|
+
assert_migration 'db/migrate/upgrade_activities.rb'
|
39
29
|
end
|
40
30
|
end
|
41
31
|
end
|