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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +19 -19
  3. data/README.md +9 -9
  4. data/app/models/active_event/event.rb +15 -15
  5. data/app/models/active_event/event_repository.rb +11 -11
  6. data/db/migrate/00_create_domain_events.rb +9 -9
  7. data/lib/active_event/autoload.rb +11 -9
  8. data/lib/active_event/command.rb +35 -39
  9. data/lib/active_event/domain.rb +4 -2
  10. data/lib/active_event/event_server.rb +72 -76
  11. data/lib/active_event/event_source_server.rb +149 -127
  12. data/lib/active_event/event_type.rb +29 -28
  13. data/lib/active_event/replay_server.rb +94 -98
  14. data/lib/active_event/sse.rb +26 -26
  15. data/lib/active_event/support/attr_initializer.rb +76 -74
  16. data/lib/active_event/support/attr_setter.rb +31 -29
  17. data/lib/active_event/support/autoload.rb +46 -44
  18. data/lib/active_event/support/autoloader.rb +41 -38
  19. data/lib/active_event/support/multi_logger.rb +31 -28
  20. data/lib/active_event/validations.rb +68 -68
  21. data/lib/active_event/validations_registry.rb +18 -18
  22. data/lib/active_event/version.rb +1 -1
  23. data/spec/factories/event_factory.rb +9 -9
  24. data/spec/lib/command_spec.rb +14 -14
  25. data/spec/lib/domain_spec.rb +21 -21
  26. data/spec/lib/event_server_spec.rb +29 -29
  27. data/spec/lib/event_type_spec.rb +38 -38
  28. data/spec/lib/replay_server_spec.rb +71 -68
  29. data/spec/lib/support/attr_initializer_spec.rb +55 -55
  30. data/spec/lib/support/attr_setter_spec.rb +61 -61
  31. data/spec/models/event_spec.rb +20 -20
  32. data/spec/spec_helper.rb +1 -1
  33. data/spec/support/active_record.rb +40 -38
  34. metadata +2 -4
  35. data/lib/active_event/support/hash_buffer.rb +0 -24
  36. 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 { 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
- @color.r.should == 10
39
- @color.g.should == 20
40
- @color.b.should be_nil
41
- end
42
-
43
- it 'can filter attributes' do
44
- @color.attributes_except(:r).should eq(g: 20)
45
- end
46
-
47
- it 'can convert to hash' do
48
- @color.to_hash.should eq(r: 10, g: 20)
49
- end
50
-
51
- it 'is not automatically frozen' do
52
- @color.frozen?.should be_false
53
- end
54
-
55
- it 'allows write' do
56
- @color.r = 20
57
- @color.r.should == 20
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
@@ -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 }.should eq [1,2,3,4,5]
14
- end
15
-
16
- it 'gives newer events' do
17
- ActiveEvent::EventRepository.after_id(3).map { |event| event.id }.should eq [4,5]
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
@@ -3,4 +3,4 @@ Coveralls.wear!
3
3
  require 'factory_girl'
4
4
 
5
5
  require 'active_event'
6
- LOGGER ||= Logger.new(STDOUT)
6
+ LOGGER ||= Logger.new(STDOUT)
@@ -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_event
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: 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