activity_engine 0.0.3 → 0.0.5

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
  SHA1:
3
- metadata.gz: 44e070ee34ba7d6773a9d4ce58474044c08304cc
4
- data.tar.gz: f28abe04afab9921b4491fdd7d013c0bc607c64b
3
+ metadata.gz: dd4228050d5a42c2041d1887fc5190c8f674e835
4
+ data.tar.gz: 0d2eca2469b07a9c17395d7e2336c97b44c11316
5
5
  SHA512:
6
- metadata.gz: eb936342551fe849a5dda6b7f7c3719c3cee77b79b5db47e29600311a597981029858076912bdf41a58773940def2dc56b207e6a7ae88df1160fffd6bb9e6ea1
7
- data.tar.gz: e035c9e31eeb99dd197604759ef9cca6bff80c1f37883240c9fdd4e64722686aefc626aa2844a279a4168ef1138d7e6d5f3f846cb59ed6d5a79bf6b63823dbce
6
+ metadata.gz: d429da6d161dc74357cfd57d14646b5f1191572f37f7a4373046ccef7c82b8ebebcd7af8cf01c13b3a43fef49fd64c178739eac97215b8f0dd11516ae395d4b2
7
+ data.tar.gz: f4246549a5c52a4b8ae6af8dd6fb2f1f861f5160bcfe6270df577ee64c24929155d3dab913131fd66cc0b97af7e2a05d0262cd5076e81a84ec5e498e39666060
@@ -13,7 +13,7 @@ module ActivityEngine
13
13
 
14
14
  scope :for_user, lambda {|user| where(user: user)}
15
15
  scope :for_subject, lambda {|subject|
16
- where(subject_id: subject.to_param, subject_type: subject.class.to_s)
16
+ where(subject_id: ActivityEngine.extract_subject_id(subject), subject_type: subject.class.to_s)
17
17
  }
18
18
  scope :for_activity_type, lambda {|activity_type|
19
19
  where(activity_type: activity_type)
@@ -31,7 +31,7 @@ module ActivityEngine
31
31
  def subject=(object)
32
32
  if object.persisted?
33
33
  write_attribute(:subject_type, object.class.to_s)
34
- write_attribute(:subject_id, object.to_param)
34
+ write_attribute(:subject_id, ActivityEngine.extract_subject_id(object))
35
35
  else
36
36
  raise UnpersistedSubjectError.new(object)
37
37
  end
@@ -11,4 +11,8 @@ module ActivityEngine
11
11
  context_builder.wrap!(activity_builder)
12
12
  end
13
13
 
14
+ def extract_subject_id(object)
15
+ Array(object.to_key).join(":")
16
+ end
17
+
14
18
  end
@@ -31,15 +31,6 @@ module ActivityEngine
31
31
  }
32
32
  end
33
33
 
34
- def subject=(persisted_object)
35
- if persisted_object.persisted?
36
- @subject = persisted_object
37
- else
38
- raise UnpersistedSubjectError.new(persisted_object)
39
- end
40
- end
41
-
42
- attr_reader :subject
43
- attr_accessor :current_user, :message, :activity_type
34
+ attr_accessor :current_user, :message, :activity_type, :subject
44
35
  end
45
36
  end
@@ -1,3 +1,3 @@
1
1
  module ActivityEngine
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,7 +13,7 @@ module ActivityEngine
13
13
  text = [
14
14
  "ActivityEngine.register('#{class_name}', '#{method_name}') do |activity, context|",
15
15
  " activity.subject = context.#{subject_method}",
16
- " activity.user = context.current_user",
16
+ " activity.current_user = context.current_user",
17
17
  " activity.activity_type = '#{class_name}##{method_name}'",
18
18
  "# activity.message = 'Specify a custom message if applicable'",
19
19
  "end",
@@ -1,6 +1,6 @@
1
1
  # ActivityEngine.register('PagesController', 'show') do |activity,context|
2
2
  # activity.subject = context.page
3
- # activity.user = context.current_user
3
+ # activity.current_user = context.current_user
4
4
  # activity.activity_type = 'pages#show'
5
5
  # activity.message = "A particulare message?"
6
6
  # end
@@ -30,25 +30,8 @@ describe ActivityEngine::ActivityBuilder do
30
30
  end
31
31
  end
32
32
 
33
- describe '#subject=' do
34
- it 'accepts a subject that is persisted' do
35
- expect {
36
- subject.subject = persisted_object
37
- }.to_not raise_error
38
- end
39
- it 'rejects a subject that is not persisted' do
40
- expect {
41
- subject.subject = non_persisted_object
42
- }.to raise_error
43
- end
44
- it 'rejects a subject that does not respond_to persisted?' do
45
- expect {
46
- subject.subject = ""
47
- }.to raise_error(NoMethodError)
48
- end
49
- end
50
-
51
33
  it { should respond_to :current_user= }
34
+ it { should respond_to :subject= }
52
35
  it { should respond_to :message= }
53
36
  it { should respond_to :activity_type= }
54
37
  end
@@ -27,6 +27,21 @@ describe ActivityEngine do
27
27
  end
28
28
  end
29
29
 
30
+ describe '.extract_subject_id' do
31
+ it 'with multi-values' do
32
+ obj = double(to_key: ['a','b'] )
33
+ expect(ActivityEngine.extract_subject_id(obj)).to eq('a:b')
34
+ end
35
+ it 'with single value' do
36
+ obj = double(to_key: ['a'] )
37
+ expect(ActivityEngine.extract_subject_id(obj)).to eq('a')
38
+ end
39
+ it 'with string' do
40
+ obj = double(to_key: 'a' )
41
+ expect(ActivityEngine.extract_subject_id(obj)).to eq('a')
42
+ end
43
+ end
44
+
30
45
  describe 'entry creation' do
31
46
  it 'creates an entry for a persisted object'
32
47
  it 'requires an object to be persisted'
@@ -6,9 +6,10 @@ class PersistenceLayer
6
6
  self.class.registry << self
7
7
  end
8
8
  def self.find(id)
9
- @registry.find {|obj| obj.to_param == Integer(id)}
9
+ @registry.find {|obj| obj.to_key == Array(id)}
10
10
  end
11
11
 
12
12
  def persisted?; true; end
13
- def to_param; object_id; end
13
+ def to_param; String(object_id); end
14
+ def to_key; [String(object_id)]; end
14
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activity_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen