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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67279cf55dbed635e902fdd9e1360922f774bc84
4
- data.tar.gz: 0849e330812d6b4e364dd4db17572833d472bcb3
3
+ metadata.gz: 44e070ee34ba7d6773a9d4ce58474044c08304cc
4
+ data.tar.gz: f28abe04afab9921b4491fdd7d013c0bc607c64b
5
5
  SHA512:
6
- metadata.gz: ad39086e8d7790407eafd2e7e26e2109fa6cd194a5b71aedc0e2fdeb189a798ea91b1b961be0582eca973b300ffa2667a90fb5a8b84aa8ea121646dccfecebc5
7
- data.tar.gz: 6108ebb34fa9abafc41cb1d86d6e3e210574bfac5b2623ab98ed5515cf550383f8733f13bd15ad2035a0eea7d4a5ba2dcf682070f62348187948ddc3d38cb2bd
6
+ metadata.gz: eb936342551fe849a5dda6b7f7c3719c3cee77b79b5db47e29600311a597981029858076912bdf41a58773940def2dc56b207e6a7ae88df1160fffd6bb9e6ea1
7
+ data.tar.gz: e035c9e31eeb99dd197604759ef9cca6bff80c1f37883240c9fdd4e64722686aefc626aa2844a279a4168ef1138d7e6d5f3f846cb59ed6d5a79bf6b63823dbce
data/Gemfile CHANGED
@@ -20,4 +20,6 @@ group :test do
20
20
  gem 'simplecov', require: false
21
21
  gem "guard"
22
22
  gem "guard-rspec"
23
+ gem 'guard-bundler'
24
+ gem 'database_cleaner'
23
25
  end
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/app/#{m[1]}_spec.rb" }
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
 
@@ -1,3 +1,3 @@
1
1
  module ActivityEngine
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,38 +5,56 @@ module ActivityEngine
5
5
  subject { ActivityEngine::Activity.new }
6
6
  let(:object) { PersistenceLayer.new }
7
7
 
8
- describe 'with persisted object' do
9
- it 'should marshal the subject' do
10
- subject.subject = object
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
- it 'should capture the subject id' do
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
- it 'should capture the subject type' do
20
- subject.subject = object
21
- expect(subject.subject_type).to eq(object.class.to_s)
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 'with a non persisted object' do
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
- it 'raise exception if the object is not persisted' do
28
- def object.persisted?; false; end
29
- expect {
33
+ it 'should capture the subject id' do
30
34
  subject.subject = object
31
- }.to raise_error(ActivityEngine::UnpersistedSubjectError)
32
- end
35
+ expect(subject.subject_id).to eq(object.to_param)
36
+ end
33
37
 
34
- it 'raise exception if the object does not respond to persisted' do
35
- expect {
36
- subject.subject = 2
37
- }.to raise_error(NoMethodError)
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
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen