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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83290b8f83bb4db6127ed0b907380946d30a3d8a91b2ea3d1a835d7dfb36327d
4
- data.tar.gz: 2a7e5abad8fae61ff03440747938653eb1624e14f62279fddb28b2d10362b75e
3
+ metadata.gz: f12beefe37e1f8d3c8fbaada9d0318de0838dd8514c1b32c93d47b97d7af6d57
4
+ data.tar.gz: bf5e00de61c14049488a4fe549a9bc198367eca931e9d73c0d47dd0ba9c173f3
5
5
  SHA512:
6
- metadata.gz: 502c70c85f62ec2838d592a2eaed2de714e97bbc27dcf0e7677dc27ac21e76e2fa1960c7c8d9fae218ff77ac1b103d0b7228ab4ed9afe2b50e7eb09bd2f6b7fe
7
- data.tar.gz: ef18dda98ec4e763311971ec8a3a9382b4ba05a5b00a76c7ee6e3a58a9d4ec80f1c9a11487d9bb2e30c5ca9f0a336136033e2811f9ac52974a9cb8f9c95efa39
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 "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
-
@@ -9,7 +9,7 @@ module PublicActivity
9
9
  class MigrationGenerator < ActiveRecord::Generators::Base
10
10
  extend Base
11
11
 
12
- argument :name, :type => :string, :default => 'create_activities'
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 < MigrationsBase
4
+ class CreateActivities < ActiveRecord::Migration[5.0]
7
5
  def self.up
8
6
  create_table :activities do |t|
9
- t.belongs_to :trackable, :polymorphic => true
10
- t.belongs_to :owner, :polymorphic => true
11
- t.string :key
12
- t.text :parameters
13
- 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
14
12
 
15
13
  t.timestamps
16
14
  end
17
15
 
18
- add_index :activities, [:trackable_id, :trackable_type]
19
- add_index :activities, [:owner_id, :owner_type]
20
- 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]
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, :type => :string, :default => 'upgrade_activities'
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, :polymorphic => true
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, :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..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, :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
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PublicActivity
4
4
  # A constant with gem's version
5
- VERSION = '2.0.0'
5
+ VERSION = '2.0.1'
6
6
  end
@@ -1,10 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'migrations_base'
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'
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,85 @@ 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})
22
- s.save && s
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('../views', __FILE__) }
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, :two => 2)
31
- rendered.must_equal template_output + "fake\n"
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, :two => 2)
39
- rendered.must_equal template_output + "\n"
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.must_equal "2"
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.must_equal '1 2'
51
+ assert_equal rendered, '1 2'
55
52
  end
56
53
 
57
- it "pass all params to view context" do
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() {|params| params[:formats] == ['json']}
61
- subject.render(view_context, :formats => ['json'])
57
+ view_context.expects(:render).with { |params| params[:formats] == ['json'] }
58
+ subject.render(view_context, formats: ['json'])
62
59
  end
63
60
 
64
- it "uses specified layout" do
61
+ it 'uses specified layout' do
65
62
  PublicActivity.set_controller(nil)
66
- subject.render(self, :layout => "activity")
67
- rendered.must_include "Here be the layouts"
63
+ subject.render(self, layout: 'activity')
64
+ assert_includes rendered, 'Here be the layouts'
68
65
 
69
- subject.render(self, :layout => "layouts/activity")
70
- rendered.must_include "Here be the layouts"
66
+ subject.render(self, layout: 'layouts/activity')
67
+ assert_includes rendered, 'Here be the layouts'
71
68
 
72
- subject.render(self, :layout => :activity)
73
- rendered.must_include "Here be the layouts"
69
+ subject.render(self, layout: :activity)
70
+ assert_includes rendered, 'Here be the layouts'
74
71
  end
75
72
 
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"
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
- it "accepts an absolute layout path" do
81
- subject.render(self, :layout => '/custom/layout')
82
- rendered.must_include "Here be the custom layouts"
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
- it "accepts a template root" do
85
- subject.render(self, :root => "custom")
86
- rendered.must_include "Custom Template Root"
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(:name => "Peter Pan")
8
- @recipient = User.create(:name => "Bruce Wayne")
9
- @options = {:params => {:author_name => "Peter",
10
- :summary => "Default summary goes here..."},
11
- :owner => @owner, :recipient => @recipient}
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].must_equal 'Pan'
18
- subject.create_activity(:test, parameters: {author_name: 'Pan'}).parameters[:author_name].must_equal 'Pan'
19
- subject.create_activity(:test, params: {author_name: nil}).parameters[:author_name].must_be_nil
20
- subject.create_activity(:test, parameters: {author_name: nil}).parameters[:author_name].must_be_nil
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.must_equal @recipient
26
- subject.create_activity(:test, owner: nil).owner.must_be_nil
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.must_equal @owner
32
- subject.create_activity(:test, recipient: nil).recipient.must_be_nil
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.must_equal @options[:params]
39
- activity.owner.must_equal @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: "Custom allowed"
45
- subject.activities.last.nonstandard.must_equal "Custom allowed"
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("some.key").wont_be_nil
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!("some.key")
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.must_equal after_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("some.key", :owner => @owner)
74
- activity.owner.must_equal @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 = "Resolving is great"
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.must_equal "Resolving is great"
83
- subject.create_activity :with_custom_fields_2, nonstandard: proc {|_, model| model.published.to_s}
84
- subject.activities.last.nonstandard.must_equal "true"
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 :params => {:author_name => "Michael"}
92
+ subject.activity params: { author_name: 'Michael' }
89
93
  subject.save
90
94
  activity = subject.activities.last
91
95
 
92
- activity.parameters[:author_name].must_equal "Michael"
96
+ assert_equal activity.parameters[:author_name], 'Michael'
93
97
  end
94
98
 
95
99
  it 'accepts instance recipient' do
96
- subject.activity :recipient => @recipient
100
+ subject.activity recipient: @recipient
97
101
  subject.save
98
- subject.activities.last.recipient.must_equal @recipient
102
+ assert_equal subject.activities.last.recipient, @recipient
99
103
  end
100
104
 
101
105
  it 'accepts instance owner' do
102
- subject.activity :owner => @owner
106
+ subject.activity owner: @owner
103
107
  subject.save
104
- subject.activities.last.owner.must_equal @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(:owner => :user)
109
- @article = klass.new(:user => @owner)
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.must_equal @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["PA_ORM"] == "active_record" # Only relevant for ActiveRecord
121
+ if ENV['PA_ORM'] == 'active_record' # Only relevant for ActiveRecord
118
122
  subject.save
119
- subject.activities.last.class.base_class.must_equal PublicActivity::Activity
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(:owner => :user).new(:user => @owner)
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; "my_custom_key" end
134
+ def @article.activity_key; 'my_custom_key' end
131
135
 
132
- @article.prepare_key(:create, {}).must_equal "my_custom_key"
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).must_equal "article.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, :key => :my_custom_key).must_equal "my_custom_key"
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(:owner => :user)
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, {}).must_equal "camel_case.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(:owner => :user)
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, {}).must_equal "my_namespace_camel_case.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 { ->{subject.prepare_settings}.must_raise PublicActivity::NoKeyProvided }
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