activity_engine 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Guardfile +7 -1
- data/app/models/activity_engine/activity.rb +12 -0
- data/lib/activity_engine/version.rb +1 -1
- data/spec/models/activity_engine/activity_spec.rb +40 -22
- data/spec/spec_helper.rb +16 -0
- 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: 44e070ee34ba7d6773a9d4ce58474044c08304cc
|
4
|
+
data.tar.gz: f28abe04afab9921b4491fdd7d013c0bc607c64b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb936342551fe849a5dda6b7f7c3719c3cee77b79b5db47e29600311a597981029858076912bdf41a58773940def2dc56b207e6a7ae88df1160fffd6bb9e6ea1
|
7
|
+
data.tar.gz: e035c9e31eeb99dd197604759ef9cca6bff80c1f37883240c9fdd4e64722686aefc626aa2844a279a4168ef1138d7e6d5f3f846cb59ed6d5a79bf6b63823dbce
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -4,7 +4,13 @@
|
|
4
4
|
guard 'rspec' do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
-
watch(%r{^app/(.+)\.rb$}) { |m| "spec
|
7
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
8
8
|
watch('spec/spec_helper.rb') { "spec" }
|
9
9
|
watch('spec/support/*') { "spec" }
|
10
10
|
end
|
11
|
+
|
12
|
+
guard 'bundler' do
|
13
|
+
watch('Gemfile')
|
14
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
15
|
+
watch(/^.+\.gemspec/)
|
16
|
+
end
|
@@ -9,6 +9,18 @@ module ActivityEngine
|
|
9
9
|
activity.activity_type = data.activity_type
|
10
10
|
end
|
11
11
|
end
|
12
|
+
default_scope { order("created_at DESC") }
|
13
|
+
|
14
|
+
scope :for_user, lambda {|user| where(user: user)}
|
15
|
+
scope :for_subject, lambda {|subject|
|
16
|
+
where(subject_id: subject.to_param, subject_type: subject.class.to_s)
|
17
|
+
}
|
18
|
+
scope :for_activity_type, lambda {|activity_type|
|
19
|
+
where(activity_type: activity_type)
|
20
|
+
}
|
21
|
+
scope :ascending_date, lambda { order("created_at ASC") }
|
22
|
+
scope :descending_date, lambda { order("created_at DESC") }
|
23
|
+
|
12
24
|
|
13
25
|
belongs_to :user
|
14
26
|
|
@@ -5,38 +5,56 @@ module ActivityEngine
|
|
5
5
|
subject { ActivityEngine::Activity.new }
|
6
6
|
let(:object) { PersistenceLayer.new }
|
7
7
|
|
8
|
-
describe '
|
9
|
-
it 'should
|
10
|
-
|
11
|
-
expect(subject.subject).to eq(object)
|
8
|
+
describe 'finder scopes' do
|
9
|
+
it 'should have .descending_date' do
|
10
|
+
expect(ActivityEngine::Activity.descending_date).to be_kind_of(ActiveRecord::Relation)
|
12
11
|
end
|
13
|
-
|
14
|
-
|
15
|
-
subject.subject = object
|
16
|
-
expect(subject.subject_id).to eq(object.to_param)
|
12
|
+
it 'should have .ascending_date' do
|
13
|
+
expect(ActivityEngine::Activity.ascending_date).to be_kind_of(ActiveRecord::Relation)
|
17
14
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
it 'should have .for_user' do
|
16
|
+
expect(ActivityEngine::Activity.for_user(nil)).to be_kind_of(ActiveRecord::Relation)
|
17
|
+
end
|
18
|
+
it 'should have .for_subject' do
|
19
|
+
expect(ActivityEngine::Activity.for_subject(object)).to be_kind_of(ActiveRecord::Relation)
|
20
|
+
end
|
21
|
+
it 'should have .for_activity_type' do
|
22
|
+
expect(ActivityEngine::Activity.for_activity_type('Hello#World')).to be_kind_of(ActiveRecord::Relation)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
describe '
|
26
|
+
describe '#subject=' do
|
27
|
+
describe 'with persisted object' do
|
28
|
+
it 'should marshal the subject' do
|
29
|
+
subject.subject = object
|
30
|
+
expect(subject.subject).to eq(object)
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
def object.persisted?; false; end
|
29
|
-
expect {
|
33
|
+
it 'should capture the subject id' do
|
30
34
|
subject.subject = object
|
31
|
-
|
32
|
-
|
35
|
+
expect(subject.subject_id).to eq(object.to_param)
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
subject.
|
37
|
-
|
38
|
+
it 'should capture the subject type' do
|
39
|
+
subject.subject = object
|
40
|
+
expect(subject.subject_type).to eq(object.class.to_s)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
44
|
+
describe 'with a non persisted object' do
|
45
|
+
it 'raise exception if the object is not persisted' do
|
46
|
+
def object.persisted?; false; end
|
47
|
+
expect {
|
48
|
+
subject.subject = object
|
49
|
+
}.to raise_error(ActivityEngine::UnpersistedSubjectError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'raise exception if the object does not respond to persisted' do
|
53
|
+
expect {
|
54
|
+
subject.subject = 2
|
55
|
+
}.to raise_error(NoMethodError)
|
56
|
+
end
|
57
|
+
end
|
40
58
|
end
|
41
59
|
end
|
42
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,8 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
13
13
|
require File.expand_path('../spec_patch', __FILE__)
|
14
14
|
require "rails/test_help"
|
15
15
|
require 'rspec/rails'
|
16
|
+
require 'database_cleaner'
|
17
|
+
|
16
18
|
|
17
19
|
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
|
18
20
|
|
@@ -32,4 +34,18 @@ RSpec.configure do |config|
|
|
32
34
|
# the seed, which is printed after each run.
|
33
35
|
# --seed 1234
|
34
36
|
config.order = 'random'
|
37
|
+
|
38
|
+
config.before(:suite) do
|
39
|
+
DatabaseCleaner.strategy = :truncation
|
40
|
+
DatabaseCleaner.clean_with(:truncation)
|
41
|
+
end
|
42
|
+
|
43
|
+
config.before(:each) do
|
44
|
+
DatabaseCleaner.start
|
45
|
+
end
|
46
|
+
|
47
|
+
config.after(:each) do
|
48
|
+
DatabaseCleaner.clean
|
49
|
+
end
|
50
|
+
|
35
51
|
end
|