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
@@ -11,31 +11,37 @@ describe PublicActivity::StoreController do
|
|
11
11
|
it 'stores controller' do
|
12
12
|
controller = StoringController.new
|
13
13
|
PublicActivity.set_controller(controller)
|
14
|
-
controller
|
15
|
-
controller
|
14
|
+
assert_same controller, Thread.current[:public_activity_controller]
|
15
|
+
assert_same controller, PublicActivity.get_controller
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'stores controller with a filter in controller' do
|
19
19
|
controller = StoringController.new
|
20
|
-
|
21
|
-
controller.
|
22
|
-
|
23
|
-
|
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
|
24
29
|
end
|
25
|
-
|
30
|
+
|
31
|
+
assert_equal controller, public_activity_controller
|
26
32
|
end
|
27
33
|
|
28
34
|
it 'stores controller in a threadsafe way' do
|
29
35
|
PublicActivity.set_controller(1)
|
30
|
-
PublicActivity.get_controller
|
36
|
+
assert_equal PublicActivity.get_controller, 1
|
31
37
|
|
32
|
-
Thread.new
|
38
|
+
Thread.new do
|
33
39
|
PublicActivity.set_controller(2)
|
34
40
|
assert_equal 2, PublicActivity.get_controller
|
35
41
|
PublicActivity.set_controller(nil)
|
36
|
-
|
42
|
+
end
|
37
43
|
|
38
|
-
PublicActivity.get_controller
|
44
|
+
assert_equal PublicActivity.get_controller, 1
|
39
45
|
|
40
46
|
PublicActivity.set_controller(nil)
|
41
47
|
end
|
data/test/test_generators.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if ENV[
|
3
|
+
if ENV['PA_ORM'] == 'active_record'
|
4
4
|
|
5
5
|
require 'test_helper'
|
6
6
|
require 'rails/generators/test_case'
|
@@ -9,23 +9,23 @@ if ENV["PA_ORM"] == "active_record"
|
|
9
9
|
|
10
10
|
class TestMigrationGenerator < Rails::Generators::TestCase
|
11
11
|
tests PublicActivity::Generators::MigrationGenerator
|
12
|
-
destination File.expand_path(
|
12
|
+
destination File.expand_path('../tmp', File.dirname(__FILE__))
|
13
13
|
setup :prepare_destination
|
14
14
|
|
15
15
|
def test_generating_activity_model
|
16
16
|
run_generator
|
17
|
-
assert_migration
|
17
|
+
assert_migration 'db/migrate/create_activities.rb'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
class TestMigrationUpgradeGenerator < Rails::Generators::TestCase
|
22
22
|
tests PublicActivity::Generators::MigrationUpgradeGenerator
|
23
|
-
destination File.expand_path(
|
23
|
+
destination File.expand_path('../tmp', File.dirname(__FILE__))
|
24
24
|
setup :prepare_destination
|
25
25
|
|
26
26
|
def test_generating_activity_model
|
27
27
|
run_generator
|
28
|
-
assert_migration
|
28
|
+
assert_migration 'db/migrate/upgrade_activities.rb'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
5
|
Bundler.setup(:default, :test)
|
6
6
|
|
7
7
|
if ENV['COV']
|
8
8
|
require 'simplecov'
|
9
9
|
SimpleCov.start do
|
10
|
-
add_filter
|
10
|
+
add_filter '/test/'
|
11
11
|
end
|
12
12
|
end
|
13
|
-
$:.unshift File.expand_path('
|
13
|
+
$:.unshift File.expand_path('../lib', __dir__)
|
14
14
|
require 'active_support/testing/setup_and_teardown'
|
15
15
|
require 'public_activity'
|
16
16
|
require 'public_activity/testing'
|
@@ -26,13 +26,13 @@ when :active_record
|
|
26
26
|
require 'active_record/connection_adapters/sqlite3_adapter'
|
27
27
|
require 'stringio' # silence the output
|
28
28
|
$stdout = StringIO.new # from migrator
|
29
|
-
ActiveRecord::Base.establish_connection(:
|
29
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
30
30
|
|
31
|
-
migrations_path = File.expand_path('
|
32
|
-
active_record_version = ActiveRecord.version.release
|
31
|
+
migrations_path = File.expand_path('migrations', __dir__)
|
32
|
+
active_record_version = ActiveRecord.version.release
|
33
33
|
|
34
34
|
if active_record_version >= Gem::Version.new('6.0.0')
|
35
|
-
schema_path = File.expand_path(
|
35
|
+
schema_path = File.expand_path('../tmp/schema.rb', File.dirname(__FILE__))
|
36
36
|
ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate
|
37
37
|
elsif active_record_version >= Gem::Version.new('5.2.0')
|
38
38
|
ActiveRecord::MigrationContext.new(migrations_path).migrate
|
@@ -43,33 +43,23 @@ when :active_record
|
|
43
43
|
$stdout = STDOUT
|
44
44
|
|
45
45
|
def article(options = {})
|
46
|
-
|
46
|
+
Class.new(ActiveRecord::Base) do
|
47
47
|
self.table_name = 'articles'
|
48
48
|
include PublicActivity::Model
|
49
49
|
tracked options
|
50
50
|
belongs_to :user
|
51
51
|
|
52
52
|
def self.name
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
if ::ActiveRecord::VERSION::MAJOR < 4
|
57
|
-
attr_accessible :name, :published, :user
|
53
|
+
'Article'
|
58
54
|
end
|
59
55
|
end
|
60
|
-
klass
|
61
56
|
end
|
62
|
-
class User < ActiveRecord::Base; end
|
63
57
|
|
64
|
-
|
65
|
-
PublicActivity::Activity.class_eval do
|
66
|
-
attr_accessible :nonstandard
|
67
|
-
end
|
68
|
-
end
|
58
|
+
class User < ActiveRecord::Base; end
|
69
59
|
when :mongoid
|
70
60
|
require 'mongoid'
|
71
61
|
|
72
|
-
Mongoid.load!(File.expand_path(
|
62
|
+
Mongoid.load!(File.expand_path('test/mongoid.yml'), :test)
|
73
63
|
|
74
64
|
class User
|
75
65
|
include Mongoid::Document
|
@@ -106,7 +96,7 @@ when :mongoid
|
|
106
96
|
when :mongo_mapper
|
107
97
|
require 'mongo_mapper'
|
108
98
|
|
109
|
-
config = YAML.load(File.read(
|
99
|
+
config = YAML.load(File.read('test/mongo_mapper.yml'))
|
110
100
|
MongoMapper.setup(config, :test)
|
111
101
|
|
112
102
|
class User
|
data/test/test_testing.rb
CHANGED
@@ -1,36 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
|
-
describe PublicActivity do
|
5
4
|
|
6
|
-
|
5
|
+
describe PublicActivity do
|
6
|
+
describe 'self.with_tracking' do
|
7
7
|
after do
|
8
8
|
PublicActivity.enabled = true
|
9
9
|
end
|
10
|
-
|
11
|
-
it
|
10
|
+
|
11
|
+
it 'enables tracking inside the block' do
|
12
12
|
PublicActivity.enabled = false
|
13
13
|
|
14
14
|
PublicActivity.with_tracking do
|
15
|
-
PublicActivity.enabled
|
15
|
+
assert PublicActivity.enabled?
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'restores previous `enabled` state' do
|
20
20
|
PublicActivity.enabled = false
|
21
21
|
PublicActivity.with_tracking do
|
22
22
|
# something
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
assert_equal PublicActivity.enabled?, false
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
describe
|
29
|
-
it
|
29
|
+
describe 'self.without_tracking' do
|
30
|
+
it 'disables tracking inside the block' do
|
30
31
|
PublicActivity.enabled = true
|
31
32
|
|
32
33
|
PublicActivity.without_tracking do
|
33
|
-
PublicActivity.enabled
|
34
|
+
assert_equal PublicActivity.enabled?, false
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|