active_projection 0.5.2 → 0.5.3
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/MIT-LICENSE +19 -19
- data/README.md +7 -7
- data/app/models/active_projection/cached_projection_repository.rb +4 -4
- data/app/models/active_projection/projection.rb +5 -5
- data/app/models/active_projection/projection_repository.rb +45 -45
- data/db/migrate/01_create_projections.rb +10 -10
- data/lib/active_projection.rb +17 -17
- data/lib/active_projection/autoload.rb +11 -9
- data/lib/active_projection/event_client.rb +171 -171
- data/lib/active_projection/projection_type.rb +91 -90
- data/lib/active_projection/projection_type_registry.rb +26 -28
- data/lib/active_projection/railtie.rb +8 -8
- data/lib/active_projection/server.rb +65 -66
- data/lib/active_projection/version.rb +1 -1
- data/spec/factories/event_factory.rb +8 -8
- data/spec/lib/projection_type_registry_spec.rb +19 -19
- data/spec/lib/projecton_type_spec.rb +87 -87
- data/spec/models/projection_repository_spec.rb +30 -30
- data/spec/support/active_record.rb +40 -38
- metadata +4 -4
@@ -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.
|
8
|
-
end
|
9
|
-
class DummyProjection
|
10
|
-
include ActiveProjection::ProjectionType
|
11
|
-
end
|
12
|
-
end
|
13
|
-
describe 'instance' do
|
14
|
-
class TestProjection
|
15
|
-
def test_event(
|
16
|
-
end
|
17
|
-
|
18
|
-
def admin__dummy_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.
|
35
|
-
handlers['TestEvent'].
|
36
|
-
handlers['DummyEvent'].
|
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(:
|
47
|
-
@projection.evaluate(
|
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(:
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'processes event with the correct id' do
|
57
|
-
expect(@projection.evaluate(
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'rejects event with last id smaller event id' do
|
61
|
-
expect(@projection.evaluate(
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'rejects event with last greater equal event id' do
|
65
|
-
expect(ActiveProjection::ProjectionRepository).to receive(:
|
66
|
-
expect(@projection.evaluate(
|
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,
|
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,
|
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.
|
24
|
-
expect(ActiveProjection::Projection.where(id:0).first.solid).to
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
module
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
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.
|
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-
|
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.
|
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.
|
26
|
+
version: 0.5.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|