active_projection 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,87 +1,87 @@
1
- require_relative '../spec_helper'
2
- require_relative '../support/active_record'
3
-
4
- describe ActiveProjection::ProjectionType do
5
- it 'should register automatically' do
6
- expect(ActiveProjection::ProjectionTypeRegistry).to receive(:register) do |arg|
7
- arg.name.to_sym.should eq :DummyProjection
8
- end
9
- class DummyProjection
10
- include ActiveProjection::ProjectionType
11
- end
12
- end
13
- describe 'instance' do
14
- class TestProjection
15
- def test_event(event, headers)
16
- end
17
-
18
- def admin__dummy_event(event)
19
- end
20
- end
21
- class TestEvent
22
- end
23
- module Admin
24
- class DummyEvent
25
- end
26
- end
27
- before :each do
28
- allow(ActiveProjection::ProjectionTypeRegistry).to receive(:register)
29
- TestProjection.send(:include, ActiveProjection::ProjectionType)
30
- @projection = TestProjection.new
31
- end
32
- it 'initializes all handler' do
33
- handlers = @projection.instance_variable_get(:@handlers)
34
- handlers.length.should eq 2
35
- handlers['TestEvent'].should be
36
- handlers['DummyEvent'].should be
37
- end
38
-
39
- describe 'evaluate' do
40
- before :each do
41
- allow(@projection).to receive(:projection_id).and_return(0)
42
- end
43
-
44
- it 'rejects processing, if projection is broken' do
45
- expect(ActiveProjection::ProjectionRepository).to receive(:solid?).and_return(false)
46
- expect(ActiveProjection::ProjectionRepository).to_not receive(:get_last_id)
47
- @projection.evaluate({id: 1})
48
- end
49
-
50
- describe 'with solid projection' do
51
- before :each do
52
- allow(ActiveProjection::ProjectionRepository).to receive(:solid?).and_return(true)
53
- expect(ActiveProjection::ProjectionRepository).to receive(:get_last_id).and_return(5)
54
- end
55
-
56
- it 'processes event with the correct id' do
57
- expect(@projection.evaluate({id: 6})).to be_true
58
- end
59
-
60
- it 'rejects event with last id smaller event id' do
61
- expect(@projection.evaluate({id: 3})).to be_false
62
- end
63
-
64
- it 'rejects event with last greater equal event id' do
65
- expect(ActiveProjection::ProjectionRepository).to receive(:set_broken).with(0)
66
- expect(@projection.evaluate({id: 7})).to be_false
67
- end
68
- end
69
- end
70
-
71
- describe 'invokes correct handler' do
72
- it 'without namespace' do
73
- expect(ActiveProjection::ProjectionRepository).to receive(:set_last_id).with(1, 6)
74
- expect(@projection).to receive(:test_event)
75
- expect(@projection).to_not receive(:admin__dummy_event)
76
- @projection.invoke(TestEvent.new, {id: 6})
77
- end
78
-
79
- it 'with namespace' do
80
- expect(ActiveProjection::ProjectionRepository).to receive(:set_last_id).with(1, 6)
81
- expect(@projection).to receive(:admin__dummy_event)
82
- expect(@projection).to_not receive(:test_event)
83
- @projection.invoke(Admin::DummyEvent.new, {id: 6})
84
- end
85
- end
86
- end
87
- end
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/active_record'
3
+
4
+ describe ActiveProjection::ProjectionType do
5
+ it 'should register automatically' do
6
+ expect(ActiveProjection::ProjectionTypeRegistry).to receive(:register) do |arg|
7
+ expect(arg.name.to_sym).to eq :DummyProjection
8
+ end
9
+ class DummyProjection
10
+ include ActiveProjection::ProjectionType
11
+ end
12
+ end
13
+ describe 'instance' do
14
+ class TestProjection
15
+ def test_event(_event, _headers)
16
+ end
17
+
18
+ def admin__dummy_event(_event)
19
+ end
20
+ end
21
+ class TestEvent
22
+ end
23
+ module Admin
24
+ class DummyEvent
25
+ end
26
+ end
27
+ before :each do
28
+ allow(ActiveProjection::ProjectionTypeRegistry).to receive(:register)
29
+ TestProjection.send(:include, ActiveProjection::ProjectionType)
30
+ @projection = TestProjection.new
31
+ end
32
+ it 'initializes all handler' do
33
+ handlers = @projection.instance_variable_get(:@handlers)
34
+ expect(handlers.length).to eq 2
35
+ expect(handlers['TestEvent']).to be
36
+ expect(handlers['DummyEvent']).to be
37
+ end
38
+
39
+ describe 'evaluate' do
40
+ before :each do
41
+ allow(@projection).to receive(:projection_id).and_return(0)
42
+ end
43
+
44
+ it 'rejects processing, if projection is broken' do
45
+ expect(ActiveProjection::ProjectionRepository).to receive(:solid?).and_return(false)
46
+ expect(ActiveProjection::ProjectionRepository).to_not receive(:last_id)
47
+ @projection.evaluate(id: 1)
48
+ end
49
+
50
+ describe 'with solid projection' do
51
+ before :each do
52
+ allow(ActiveProjection::ProjectionRepository).to receive(:solid?).and_return(true)
53
+ expect(ActiveProjection::ProjectionRepository).to receive(:last_id).and_return(5)
54
+ end
55
+
56
+ it 'processes event with the correct id' do
57
+ expect(@projection.evaluate(id: 6)).to be_truthy
58
+ end
59
+
60
+ it 'rejects event with last id smaller event id' do
61
+ expect(@projection.evaluate(id: 3)).to be_falsey
62
+ end
63
+
64
+ it 'rejects event with last greater equal event id' do
65
+ expect(ActiveProjection::ProjectionRepository).to receive(:mark_broken).with(0)
66
+ expect(@projection.evaluate(id: 7)).to be_falsey
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'invokes correct handler' do
72
+ it 'without namespace' do
73
+ expect(ActiveProjection::ProjectionRepository).to receive(:set_last_id).with(1, 6)
74
+ expect(@projection).to receive(:test_event)
75
+ expect(@projection).to_not receive(:admin__dummy_event)
76
+ @projection.invoke(TestEvent.new, id: 6)
77
+ end
78
+
79
+ it 'with namespace' do
80
+ expect(ActiveProjection::ProjectionRepository).to receive(:set_last_id).with(1, 6)
81
+ expect(@projection).to receive(:admin__dummy_event)
82
+ expect(@projection).to_not receive(:test_event)
83
+ @projection.invoke(Admin::DummyEvent.new, id: 6)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,30 +1,30 @@
1
- require_relative '../spec_helper'
2
- require_relative '../support/active_record'
3
-
4
- describe ActiveProjection::ProjectionRepository do
5
- before :all do
6
- 5.times do |i|
7
- FactoryGirl.create :projection, id: i, class_name: "TestProjection#{i}", last_id: 5 - i
8
- end
9
- end
10
- describe 'ensure_exists' do
11
- it 'creates a projection, if classname is not present' do
12
- expect(ActiveProjection::ProjectionRepository.ensure_exists('TestProjection5').id).to eq 5
13
- expect(ActiveProjection::Projection.all.to_a.length).to eq 6
14
- end
15
-
16
- it 'does not create a projection, if classname is present' do
17
- expect(ActiveProjection::ProjectionRepository.ensure_exists('TestProjection3').id).to eq 3
18
- expect(ActiveProjection::Projection.all.to_a.length).to eq 5
19
- end
20
- end
21
- describe 'broken' do
22
- it 'sets solid to false' do
23
- ActiveProjection::ProjectionRepository.set_broken 0
24
- expect(ActiveProjection::Projection.where(id:0).first.solid).to be_false
25
- end
26
- end
27
- it 'returns array of last ids' do
28
- expect(ActiveProjection::ProjectionRepository.last_ids).to eq [5,4,3,2,1]
29
- end
30
- end
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/active_record'
3
+
4
+ describe ActiveProjection::ProjectionRepository do
5
+ before :all do
6
+ 5.times do |i|
7
+ FactoryGirl.create :projection, id: i, class_name: "TestProjection#{i}", last_id: 5 - i
8
+ end
9
+ end
10
+ describe 'ensure_exists' do
11
+ it 'creates a projection, if classname is not present' do
12
+ expect(ActiveProjection::ProjectionRepository.ensure_exists('TestProjection5').id).to eq 5
13
+ expect(ActiveProjection::Projection.all.to_a.length).to eq 6
14
+ end
15
+
16
+ it 'does not create a projection, if classname is present' do
17
+ expect(ActiveProjection::ProjectionRepository.ensure_exists('TestProjection3').id).to eq 3
18
+ expect(ActiveProjection::Projection.all.to_a.length).to eq 5
19
+ end
20
+ end
21
+ describe 'broken' do
22
+ it 'sets solid to false' do
23
+ ActiveProjection::ProjectionRepository.mark_broken 0
24
+ expect(ActiveProjection::Projection.where(id: 0).first.solid).to be_falsey
25
+ end
26
+ end
27
+ it 'returns array of last ids' do
28
+ expect(ActiveProjection::ProjectionRepository.last_ids).to eq [*1..5].reverse
29
+ end
30
+ end
@@ -1,38 +1,40 @@
1
-
2
- require 'active_record'
3
-
4
- ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
5
-
6
- ActiveRecord::Migrator.up 'db/migrate'
7
-
8
- module ActiveModel::Validations
9
- # Extension to enhance `should have` on AR Model instances. Calls
10
- # model.valid? in order to prepare the object's errors object.
11
- #
12
- # You can also use this to specify the content of the error messages.
13
- #
14
- # @example
15
- #
16
- # model.should have(:no).errors_on(:attribute)
17
- # model.should have(1).error_on(:attribute)
18
- # model.should have(n).errors_on(:attribute)
19
- #
20
- # model.errors_on(:attribute).should include("can't be blank")
21
- def errors_on(attribute)
22
- self.valid?
23
- [self.errors[attribute]].flatten.compact
24
- end
25
- alias :error_on :errors_on
26
- end
27
-
28
- RSpec.configure do |config|
29
- config.around do |example|
30
- ActiveRecord::Base.transaction do
31
- example.run
32
- raise ActiveRecord::Rollback
33
- end
34
- end
35
- end
36
-
37
- require 'factory_girl'
38
- FactoryGirl.find_definitions
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
4
+
5
+ ActiveRecord::Migrator.up 'db/migrate'
6
+
7
+ module ActiveModel
8
+ module Validations
9
+ # Extension to enhance `should have` on AR Model instances. Calls
10
+ # model.valid? in order to prepare the object's errors object.
11
+ #
12
+ # You can also use this to specify the content of the error messages.
13
+ #
14
+ # @example
15
+ #
16
+ # model.should have(:no).errors_on(:attribute)
17
+ # model.should have(1).error_on(:attribute)
18
+ # model.should have(n).errors_on(:attribute)
19
+ #
20
+ # model.errors_on(:attribute).should include("can't be blank")
21
+ def errors_on(attribute)
22
+ self.valid?
23
+ [errors[attribute]].flatten.compact
24
+ end
25
+
26
+ alias_method :error_on, :errors_on
27
+ end
28
+ end
29
+
30
+ RSpec.configure do |config|
31
+ config.around do |example|
32
+ ActiveRecord::Base.transaction do
33
+ example.run
34
+ fail ActiveRecord::Rollback
35
+ end
36
+ end
37
+ end
38
+
39
+ require 'factory_girl'
40
+ FactoryGirl.find_definitions
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_projection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - HicknHack Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_event
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.2
19
+ version: 0.5.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.2
26
+ version: 0.5.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement