activity_engine 0.0.3 → 0.0.5
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/app/models/activity_engine/activity.rb +2 -2
- data/lib/activity_engine.rb +4 -0
- data/lib/activity_engine/activity_builder.rb +1 -10
- data/lib/activity_engine/version.rb +1 -1
- data/lib/generators/activity_engine/register_generator.rb +1 -1
- data/lib/generators/activity_engine/templates/activity_engine_config.rb +1 -1
- data/spec/lib/activity_engine/activity_builder_spec.rb +1 -18
- data/spec/lib/activity_engine_spec.rb +15 -0
- data/spec/support/persistence_layer.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd4228050d5a42c2041d1887fc5190c8f674e835
|
4
|
+
data.tar.gz: 0d2eca2469b07a9c17395d7e2336c97b44c11316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
34
|
+
write_attribute(:subject_id, ActivityEngine.extract_subject_id(object))
|
35
35
|
else
|
36
36
|
raise UnpersistedSubjectError.new(object)
|
37
37
|
end
|
data/lib/activity_engine.rb
CHANGED
@@ -31,15 +31,6 @@ module ActivityEngine
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
|
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
|
@@ -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.
|
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.
|
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.
|
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
|