active_event 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +19 -19
- data/README.md +9 -9
- data/app/models/active_event/event.rb +15 -15
- data/app/models/active_event/event_repository.rb +11 -11
- data/db/migrate/00_create_domain_events.rb +9 -9
- data/lib/active_event/autoload.rb +11 -9
- data/lib/active_event/command.rb +35 -39
- data/lib/active_event/domain.rb +4 -2
- data/lib/active_event/event_server.rb +72 -76
- data/lib/active_event/event_source_server.rb +149 -127
- data/lib/active_event/event_type.rb +29 -28
- data/lib/active_event/replay_server.rb +94 -98
- data/lib/active_event/sse.rb +26 -26
- data/lib/active_event/support/attr_initializer.rb +76 -74
- data/lib/active_event/support/attr_setter.rb +31 -29
- data/lib/active_event/support/autoload.rb +46 -44
- data/lib/active_event/support/autoloader.rb +41 -38
- data/lib/active_event/support/multi_logger.rb +31 -28
- data/lib/active_event/validations.rb +68 -68
- data/lib/active_event/validations_registry.rb +18 -18
- data/lib/active_event/version.rb +1 -1
- data/spec/factories/event_factory.rb +9 -9
- data/spec/lib/command_spec.rb +14 -14
- data/spec/lib/domain_spec.rb +21 -21
- data/spec/lib/event_server_spec.rb +29 -29
- data/spec/lib/event_type_spec.rb +38 -38
- data/spec/lib/replay_server_spec.rb +71 -68
- data/spec/lib/support/attr_initializer_spec.rb +55 -55
- data/spec/lib/support/attr_setter_spec.rb +61 -61
- data/spec/models/event_spec.rb +20 -20
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +40 -38
- metadata +2 -4
- data/lib/active_event/support/hash_buffer.rb +0 -24
- data/lib/active_event/support/ring_buffer.rb +0 -20
@@ -1,61 +1,61 @@
|
|
1
|
-
require_relative '../../spec_helper'
|
2
|
-
|
3
|
-
describe ActiveEvent::Support::AttrSetter do
|
4
|
-
class MutableRgbColor
|
5
|
-
include ActiveEvent::Support::AttrSetter
|
6
|
-
attributes :r, :g, :b
|
7
|
-
end
|
8
|
-
|
9
|
-
describe 'constructor' do
|
10
|
-
it 'works for no args' do
|
11
|
-
expect
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'works for defined attributes' do
|
15
|
-
expect
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'fails for undeclared attributes' do
|
19
|
-
expect { MutableRgbColor.new z: 10 }.to raise_error(ActiveEvent::Support::UnknownAttributeError)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'fails for unauthorized hash' do
|
23
|
-
class CheckedHash < Hash
|
24
|
-
def permitted?
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
expect { MutableRgbColor.new(CheckedHash.new.merge! r: 1) }.to raise_error(ActiveEvent::Support::ForbiddenAttributesError)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'instance' do
|
33
|
-
before :all do
|
34
|
-
@color = MutableRgbColor.new r: 10, g: 20
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'can retrieve attributes' do
|
38
|
-
@color.r.
|
39
|
-
@color.g.
|
40
|
-
@color.b.
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'can filter attributes' do
|
44
|
-
@color.attributes_except(:r).
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'can convert to hash' do
|
48
|
-
@color.to_hash.
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'is not automatically frozen' do
|
52
|
-
@color.frozen
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'allows write' do
|
56
|
-
@color.r = 20
|
57
|
-
@color.r.
|
58
|
-
@color.r = 10
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe ActiveEvent::Support::AttrSetter do
|
4
|
+
class MutableRgbColor
|
5
|
+
include ActiveEvent::Support::AttrSetter
|
6
|
+
attributes :r, :g, :b
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'constructor' do
|
10
|
+
it 'works for no args' do
|
11
|
+
expect( MutableRgbColor.new ).to be
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'works for defined attributes' do
|
15
|
+
expect( MutableRgbColor.new r: 10, g: 20 ).to be
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'fails for undeclared attributes' do
|
19
|
+
expect { MutableRgbColor.new z: 10 }.to raise_error(ActiveEvent::Support::UnknownAttributeError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'fails for unauthorized hash' do
|
23
|
+
class CheckedHash < Hash
|
24
|
+
def permitted?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
expect { MutableRgbColor.new(CheckedHash.new.merge! r: 1) }.to raise_error(ActiveEvent::Support::ForbiddenAttributesError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'instance' do
|
33
|
+
before :all do
|
34
|
+
@color = MutableRgbColor.new r: 10, g: 20
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can retrieve attributes' do
|
38
|
+
expect(@color.r).to eq(10)
|
39
|
+
expect(@color.g).to eq(20)
|
40
|
+
expect(@color.b).to be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'can filter attributes' do
|
44
|
+
expect(@color.attributes_except(:r)).to eq(g: 20)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can convert to hash' do
|
48
|
+
expect(@color.to_hash).to eq(r: 10, g: 20)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'is not automatically frozen' do
|
52
|
+
expect(@color.frozen?).to be_falsey
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'allows write' do
|
56
|
+
@color.r = 20
|
57
|
+
expect(@color.r).to eq(20)
|
58
|
+
@color.r = 10
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/models/event_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../support/active_record'
|
3
|
-
|
4
|
-
describe ActiveEvent::EventRepository do
|
5
|
-
describe 'instance' do
|
6
|
-
before :all do
|
7
|
-
5.times do |i|
|
8
|
-
FactoryGirl.create :event, id: (5 - i)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'gives all events ordered by event id' do
|
13
|
-
ActiveEvent::EventRepository.ordered.map { |event| event.id }.
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'gives newer events' do
|
17
|
-
ActiveEvent::EventRepository.after_id(3).map { |event| event.id }.
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../support/active_record'
|
3
|
+
|
4
|
+
describe ActiveEvent::EventRepository do
|
5
|
+
describe 'instance' do
|
6
|
+
before :all do
|
7
|
+
5.times do |i|
|
8
|
+
FactoryGirl.create :event, id: (5 - i)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'gives all events ordered by event id' do
|
13
|
+
expect(ActiveEvent::EventRepository.ordered.map { |event| event.id }).to eq [*1..5]
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'gives newer events' do
|
17
|
+
expect(ActiveEvent::EventRepository.after_id(3).map { |event| event.id }).to eq [4, 5]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -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_event
|
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: activerecord
|
@@ -165,9 +165,7 @@ files:
|
|
165
165
|
- lib/active_event/support/attr_setter.rb
|
166
166
|
- lib/active_event/support/autoload.rb
|
167
167
|
- lib/active_event/support/autoloader.rb
|
168
|
-
- lib/active_event/support/hash_buffer.rb
|
169
168
|
- lib/active_event/support/multi_logger.rb
|
170
|
-
- lib/active_event/support/ring_buffer.rb
|
171
169
|
- lib/active_event/validations.rb
|
172
170
|
- lib/active_event/validations_registry.rb
|
173
171
|
- lib/active_event/version.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# a hash with limited size
|
2
|
-
class HashBuffer < Array
|
3
|
-
attr_accessor :max_size
|
4
|
-
|
5
|
-
def initialize(max_size, *args, &block)
|
6
|
-
super(*args, &block)
|
7
|
-
self.max_size = max_size
|
8
|
-
end
|
9
|
-
|
10
|
-
def max_size=(new_size)
|
11
|
-
delete keys.first while new_size < size
|
12
|
-
self.max_size = new_size
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
attr_accessor entries
|
18
|
-
|
19
|
-
def []=(key, value)
|
20
|
-
delete keys.first if max_size && size == max_size
|
21
|
-
super
|
22
|
-
end
|
23
|
-
alias :push :<<
|
24
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# simple ring buffer
|
2
|
-
class RingBuffer < Array
|
3
|
-
attr_accessor :max_size
|
4
|
-
|
5
|
-
def initialize(max_size, *args, &block)
|
6
|
-
super(*args, &block)
|
7
|
-
self.max_size = max_size
|
8
|
-
end
|
9
|
-
|
10
|
-
def max_size=(new_size)
|
11
|
-
replace first(new_size) if new_size < size
|
12
|
-
self.max_size = new_size
|
13
|
-
end
|
14
|
-
|
15
|
-
def <<(item)
|
16
|
-
shift if max_size && size == max_size
|
17
|
-
super
|
18
|
-
end
|
19
|
-
alias :push :<<
|
20
|
-
end
|