public_activity 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.must_be_same_as Thread.current[:public_activity_controller]
15
- controller.must_be_same_as PublicActivity.get_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
- controller._process_action_callbacks.select {|c| c.kind == :around}.map(&:filter).must_include :store_controller_for_public_activity
21
- controller.instance_eval do
22
- store_controller_for_public_activity do
23
- controller.must_be_same_as PublicActivity.get_controller
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
- end
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.must_equal 1
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.must_equal 1
44
+ assert_equal PublicActivity.get_controller, 1
39
45
 
40
46
  PublicActivity.set_controller(nil)
41
47
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if ENV["PA_ORM"] == "active_record"
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("../tmp", File.dirname(__FILE__))
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 "db/migrate/create_activities.rb"
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("../tmp", File.dirname(__FILE__))
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 "db/migrate/upgrade_activities.rb"
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 "rubygems"
4
- require "bundler"
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 "/test/"
10
+ add_filter '/test/'
11
11
  end
12
12
  end
13
- $:.unshift File.expand_path('../../lib/', __FILE__)
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(:adapter => 'sqlite3', :database => ':memory:')
29
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
30
30
 
31
- migrations_path = File.expand_path('../migrations', __FILE__)
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("../tmp/schema.rb", File.dirname(__FILE__))
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
- klass = Class.new(ActiveRecord::Base) do
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
- "Article"
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
- if ::ActiveRecord::VERSION::MAJOR < 4
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("test/mongoid.yml"), :test)
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("test/mongo_mapper.yml"))
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
- describe "self.with_tracking" do
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 "enables tracking inside the block" do
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?.must_equal true
15
+ assert PublicActivity.enabled?
16
16
  end
17
17
  end
18
18
 
19
- it "restores previous `enabled` state" do
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
- PublicActivity.enabled?.must_equal false
24
+
25
+ assert_equal PublicActivity.enabled?, false
25
26
  end
26
27
  end
27
28
 
28
- describe "self.without_tracking" do
29
- it "disables tracking inside the block" do
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?.must_equal false
34
+ assert_equal PublicActivity.enabled?, false
34
35
  end
35
36
  end
36
37
  end