lanes 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dir-locals.el +8 -0
- data/client/lanes/Config.coffee +1 -1
- data/client/lanes/access/Extension.coffee +1 -6
- data/client/lanes/access/screens/user-management/GridUserEditor.coffee +6 -5
- data/client/lanes/access/screens/user-management/grid-popover-editor.html +2 -2
- data/client/lanes/components/grid/vendor/jquery.dataTables.js +1 -1
- data/client/lanes/components/multi-select/MultiSelect.coffee +10 -5
- data/client/lanes/components/select-field/SelectField.coffee +2 -1
- data/client/lanes/models/Base.coffee +1 -1
- data/client/lanes/models/PubSub.coffee +4 -3
- data/client/lanes/models/Sync.coffee +3 -3
- data/client/lanes/screens/ChangeListener.coffee +0 -3
- data/client/lanes/testing/ModelSaver.coffee +12 -1
- data/client/lanes/views/Base.coffee +1 -1
- data/client/lanes/views/Helpers.coffee +2 -1
- data/client/lanes/views/SaveNotify.coffee +9 -7
- data/client/lanes/views/TimedMask.coffee +1 -1
- data/lanes.gemspec +1 -1
- data/lib/lanes/access/authentication_provider.rb +17 -11
- data/lib/lanes/access/config/routes.rb +1 -1
- data/lib/lanes/access/extension.rb +9 -2
- data/lib/lanes/access/role.rb +12 -0
- data/lib/lanes/access.rb +8 -8
- data/lib/lanes/api/null_authentication_provider.rb +2 -2
- data/lib/lanes/api/request_wrapper.rb +10 -10
- data/lib/lanes/concerns/association_extensions.rb +16 -7
- data/lib/lanes/concerns/pub_sub.rb +55 -30
- data/lib/lanes/guard_tasks.rb +7 -3
- data/lib/lanes/version.rb +1 -1
- data/{appy-app → spec/command-reference-files/initial}/.gitignore +0 -0
- data/{appy-app → spec/command-reference-files/initial}/Gemfile +1 -1
- data/{appy-app → spec/command-reference-files/initial}/Guardfile +0 -0
- data/{appy-app → spec/command-reference-files/initial}/Rakefile +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/Extension.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/Router.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/components/.gitkeep +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/controllers/.gitkeep +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/index.js +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/models/.gitkeep +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/models/Base.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/screens/.gitkeep +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/initial/client/appy-app/screens/Base.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/styles.scss +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/views/.gitkeep +0 -0
- data/{appy-app → spec/command-reference-files/initial}/client/appy-app/views/Base.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/config/database.yml +0 -0
- data/{appy-app → spec/command-reference-files/initial}/config/lanes.rb +0 -0
- data/{appy-app → spec/command-reference-files/initial}/config/routes.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/initial/config/screens.rb +0 -0
- data/{appy-app → spec/command-reference-files/initial}/config.ru +0 -0
- data/{appy-app → spec/command-reference-files/initial}/db/.gitkeep +0 -0
- data/{appy-app → spec/command-reference-files/initial}/lib/appy-app/extension.rb +0 -0
- data/{appy-app → spec/command-reference-files/initial}/lib/appy-app/model.rb +0 -0
- data/{appy-app → spec/command-reference-files/initial}/lib/appy-app/models/empty.rb +0 -0
- data/{appy-app → spec/command-reference-files/initial}/lib/appy-app/version.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/initial/lib/appy-app.rb +0 -0
- data/{appy-app → spec/command-reference-files/initial}/spec/appy-app/helpers/AppyAppHelpers.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/spec/appy-app/screens/Base.coffee +0 -0
- data/{appy-app → spec/command-reference-files/initial}/spec/server/spec_helpers.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/client/appy-app/models/TestTest.coffee +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/config/routes.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/db/migrate/20150218032025_create_test_tests.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/lib/appy-app/models/test_test.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/spec/appy-app/models/TestTestSpec.coffee +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/spec/fixtures/appy-app/test_test.yml +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/model/spec/server/test_test_spec.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/screen/client/appy-app/screens/ready-set-go/ReadySetGo.coffee +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/screen/client/appy-app/screens/ready-set-go/index.js +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/screen/client/appy-app/screens/ready-set-go/index.scss +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/screen/client/appy-app/screens/ready-set-go/layout.html +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/screen/config/screens.rb +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/screen/spec/appy-app/screens/ready-set-go/ReadySetGoSpec.coffee +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/view/client/appy-app/views/BigView.coffee +0 -0
- data/spec/{server/command-reference-files → command-reference-files}/view/spec/appy-app/views/BigViewSpec.coffee +0 -0
- data/spec/lanes/models/BaseSpec.coffee +4 -4
- data/spec/server/command_spec.rb +5 -1
- data/spec/server/concerns/association_extensions_spec.rb +0 -8
- data/spec/server/concerns/pub_sub_spec.rb +77 -31
- data/spec/server/spec_helper.rb +1 -0
- metadata +48 -91
- data/appy-app/client/appy-app/screens/Base.coffee +0 -10
- data/appy-app/config/screens.rb +0 -8
- data/appy-app/lib/appy-app.rb +0 -14
- data/spec/server/command-reference-files/initial/.gitignore +0 -3
- data/spec/server/command-reference-files/initial/Gemfile +0 -6
- data/spec/server/command-reference-files/initial/Guardfile +0 -13
- data/spec/server/command-reference-files/initial/Rakefile +0 -2
- data/spec/server/command-reference-files/initial/client/appy-app/Extension.coffee +0 -7
- data/spec/server/command-reference-files/initial/client/appy-app/Router.coffee +0 -4
- data/spec/server/command-reference-files/initial/client/appy-app/components/.gitkeep +0 -0
- data/spec/server/command-reference-files/initial/client/appy-app/controllers/.gitkeep +0 -0
- data/spec/server/command-reference-files/initial/client/appy-app/index.js +0 -21
- data/spec/server/command-reference-files/initial/client/appy-app/models/.gitkeep +0 -0
- data/spec/server/command-reference-files/initial/client/appy-app/models/Base.coffee +0 -5
- data/spec/server/command-reference-files/initial/client/appy-app/screens/.gitkeep +0 -0
- data/spec/server/command-reference-files/initial/client/appy-app/styles.scss +0 -1
- data/spec/server/command-reference-files/initial/client/appy-app/views/.gitkeep +0 -0
- data/spec/server/command-reference-files/initial/client/appy-app/views/Base.coffee +0 -5
- data/spec/server/command-reference-files/initial/config/database.yml +0 -9
- data/spec/server/command-reference-files/initial/config/lanes.rb +0 -7
- data/spec/server/command-reference-files/initial/config/routes.rb +0 -2
- data/spec/server/command-reference-files/initial/config.ru +0 -5
- data/spec/server/command-reference-files/initial/db/.gitkeep +0 -0
- data/spec/server/command-reference-files/initial/lib/appy-app/extension.rb +0 -13
- data/spec/server/command-reference-files/initial/lib/appy-app/model.rb +0 -11
- data/spec/server/command-reference-files/initial/lib/appy-app/models/empty.rb +0 -0
- data/spec/server/command-reference-files/initial/lib/appy-app/version.rb +0 -3
- data/spec/server/command-reference-files/initial/spec/appy-app/helpers/AppyAppHelpers.coffee +0 -5
- data/spec/server/command-reference-files/initial/spec/appy-app/screens/Base.coffee +0 -5
- data/spec/server/command-reference-files/initial/spec/server/spec_helpers.rb +0 -16
@@ -1,15 +1,5 @@
|
|
1
1
|
module Lanes::Concerns
|
2
2
|
|
3
|
-
module PendingEventListeners
|
4
|
-
# @private
|
5
|
-
@@listeners = Hash.new{ |hash, klass| hash[klass] = Hash.new{ |kh, event| kh[event]=Array.new } }
|
6
|
-
# @api private
|
7
|
-
def self.all
|
8
|
-
@@listeners
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
3
|
# Event subscription and publishing for Stockor Models
|
14
4
|
# Every model has certain built-in events (:save, :create, :update, :destroy)
|
15
5
|
# And may also implement custom events that reflect the models domain
|
@@ -24,6 +14,33 @@ module Lanes::Concerns
|
|
24
14
|
module PubSub
|
25
15
|
extend ActiveSupport::Concern
|
26
16
|
|
17
|
+
|
18
|
+
module PendingListeners
|
19
|
+
# @private
|
20
|
+
@@listeners = Hash.new{ |hash, klass|
|
21
|
+
hash[klass] = Hash.new{ |kh, event|
|
22
|
+
kh[event]=Array.new
|
23
|
+
}
|
24
|
+
}
|
25
|
+
class << self
|
26
|
+
|
27
|
+
# @api private
|
28
|
+
def claim(class_name)
|
29
|
+
if @@listeners.has_key?(class_name)
|
30
|
+
return @@listeners.delete(class_name)
|
31
|
+
else
|
32
|
+
return {}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# @api private
|
37
|
+
def add(class_name)
|
38
|
+
@@listeners[class_name]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
27
44
|
class InvalidEvent < RuntimeError
|
28
45
|
end
|
29
46
|
|
@@ -31,35 +48,41 @@ module Lanes::Concerns
|
|
31
48
|
|
32
49
|
class_attribute :valid_event_names
|
33
50
|
class_attribute :_event_listeners
|
34
|
-
|
51
|
+
base.valid_event_names = [ :save, :create, :update, :destroy ]
|
35
52
|
|
36
|
-
after_save :fire_after_save_events
|
37
|
-
after_create :fire_after_create_events
|
38
|
-
after_update :fire_after_update_events
|
39
|
-
after_destroy :fire_after_destroy_events
|
53
|
+
base.after_save :fire_after_save_events
|
54
|
+
base.after_create :fire_after_create_events
|
55
|
+
base.after_update :fire_after_update_events
|
56
|
+
base.after_destroy :fire_after_destroy_events
|
40
57
|
end
|
41
58
|
|
42
59
|
module ClassMethods
|
43
60
|
def inherited(base)
|
44
61
|
super
|
45
62
|
klass = base.to_s.demodulize
|
46
|
-
if PendingEventListeners.all.has_key?( klass )
|
47
|
-
events = PendingEventListeners.all.delete(klass)
|
48
|
-
events.each{ | name, procs | base.event_listeners[name] += procs }
|
49
|
-
end
|
50
|
-
end
|
51
63
|
|
52
|
-
|
53
|
-
|
54
|
-
|
64
|
+
#p klass
|
65
|
+
# if klass=="Tester"
|
66
|
+
# binding.pry
|
67
|
+
# end
|
68
|
+
events = PubSub::PendingListeners.claim( klass )
|
69
|
+
events.each{ | name, procs | base.event_listeners[name] += procs }
|
55
70
|
|
56
|
-
def _add_event_listener( name, proc )
|
57
|
-
self.event_listeners[name].push( proc ) unless self.event_listeners[name].include?(proc)
|
58
71
|
end
|
59
72
|
|
60
73
|
def observe( event, &block )
|
61
74
|
_ensure_validate_event( event )
|
62
|
-
_add_event_listener( event.to_sym, block )
|
75
|
+
_add_event_listener( event.to_sym, &block )
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def _add_event_listener(name, &block)
|
81
|
+
self._event_listeners ||= Hash.new{ |hash, key| hash[key]=Array.new }
|
82
|
+
listeners = self._event_listeners[name].dup
|
83
|
+
listeners << block
|
84
|
+
self._event_listeners = self._event_listeners.dup
|
85
|
+
self._event_listeners[name] = listeners
|
63
86
|
end
|
64
87
|
|
65
88
|
def _ensure_validate_event(event)
|
@@ -68,14 +91,13 @@ module Lanes::Concerns
|
|
68
91
|
end
|
69
92
|
end
|
70
93
|
|
71
|
-
protected
|
72
|
-
|
73
94
|
def has_additional_events( *names )
|
74
95
|
self.valid_event_names += names.map{ |name| name.to_sym }
|
75
96
|
end
|
76
97
|
end
|
77
98
|
|
78
99
|
protected
|
100
|
+
|
79
101
|
def fire_after_destroy_events
|
80
102
|
_fire_event(:update, self )
|
81
103
|
end
|
@@ -96,9 +118,12 @@ module Lanes::Concerns
|
|
96
118
|
end
|
97
119
|
|
98
120
|
private
|
121
|
+
|
99
122
|
def _fire_event( name, *arguments )
|
100
|
-
self.class.
|
101
|
-
|
123
|
+
return if self.class._event_listeners.nil? ||
|
124
|
+
!self.class._event_listeners.has_key?(name.to_sym)
|
125
|
+
|
126
|
+
self.class._event_listeners[ name.to_sym ].each{ | block | block.call(*arguments) }
|
102
127
|
end
|
103
128
|
end
|
104
129
|
|
data/lib/lanes/guard_tasks.rb
CHANGED
@@ -26,15 +26,19 @@ module Lanes
|
|
26
26
|
spec_dir: "spec/#{app_name}", console: :always, debug: false
|
27
27
|
})
|
28
28
|
|
29
|
+
minitest_options = {
|
30
|
+
all_on_start: true, test_folders: 'spec/server'
|
31
|
+
}
|
32
|
+
|
29
33
|
dsl.guard :jasmine, jasmine_options do
|
30
34
|
dsl.watch(%r{^client/(.+?)\.(js|coffee)$}){ |m| "spec/#{m[1]}Spec.#{m[2]}" }
|
31
35
|
dsl.watch(%r{^spec/.*(?:_s|S)pec\.coffee$})
|
32
36
|
matchers.client_matches.call if matchers.client_matches
|
33
37
|
end
|
34
38
|
|
35
|
-
dsl.guard :minitest,
|
36
|
-
dsl.watch(%r{^spec/spec_helper\.rb}) { 'test' }
|
37
|
-
dsl.watch(%r{^spec/.+_spec\.rb})
|
39
|
+
dsl.guard :minitest, minitest_options do
|
40
|
+
dsl.watch(%r{^spec/server/spec_helper\.rb}) { 'test' }
|
41
|
+
dsl.watch(%r{^spec/server/.+_spec\.rb})
|
38
42
|
dsl.watch(%r{^spec/fixtures/#{app_name}/(.+)s\.yml}) { |m| "spec/server/#{m[1]}_spec.rb" }
|
39
43
|
dsl.watch(%r{^lib/#{app_name}/(.+)\.rb}) { |m| "spec/server/#{m[1]}_spec.rb" }
|
40
44
|
matchers.server_matches.call if matchers.server_matches
|
data/lib/lanes/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/{server/command-reference-files → command-reference-files}/initial/config/screens.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/{server/command-reference-files → command-reference-files}/initial/lib/appy-app.rb
RENAMED
File without changes
|
data/{appy-app → spec/command-reference-files/initial}/spec/appy-app/helpers/AppyAppHelpers.coffee
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/{server/command-reference-files → command-reference-files}/screen/config/screens.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -12,12 +12,12 @@ describe "Lanes.Models.Base", ->
|
|
12
12
|
props:
|
13
13
|
saved: 'string'
|
14
14
|
}, {bar: 'baz'})
|
15
|
-
expect(model.isDirty
|
15
|
+
expect(model.isDirty).toBe(false)
|
16
16
|
model.foo = 'baz' # session prop
|
17
|
-
expect(model.isDirty
|
17
|
+
expect(model.isDirty).toBe(false)
|
18
18
|
expect(model.unsavedAttributes()).toBeEmptyObject()
|
19
19
|
model.set( saved: 'true' )
|
20
|
-
expect(model.isDirty
|
20
|
+
expect(model.isDirty).toBe(true)
|
21
21
|
|
22
22
|
|
23
23
|
it "can tell if it has attributes", ->
|
@@ -62,7 +62,7 @@ describe "Lanes.Models.Base", ->
|
|
62
62
|
bar: 'string'
|
63
63
|
|
64
64
|
}, { foo: 'one, two, three'} )
|
65
|
-
expect(model.isDirty
|
65
|
+
expect(model.isDirty).toBe(true)
|
66
66
|
expect(model.unsavedAttributes()).toEqual( foo: 'one, two, three' )
|
67
67
|
model.save()
|
68
68
|
expect(model.sync).toHaveBeenCalledWith('create', model, jasmine.any(Object))
|
data/spec/server/command_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Lanes::Command do
|
|
7
7
|
let(:app_name) { "appy-app" }
|
8
8
|
let(:lanes) { Pathname.new(__FILE__).dirname.join('..','..','bin','lanes') }
|
9
9
|
let(:generated_path) { Pathname.pwd }
|
10
|
-
let(:reference_path) { Pathname(__FILE__).dirname.join("command-reference-files") }
|
10
|
+
let(:reference_path) { Pathname(__FILE__).dirname.join("..","command-reference-files") }
|
11
11
|
|
12
12
|
around do |test|
|
13
13
|
Dir.mktmpdir do |dir|
|
@@ -34,6 +34,10 @@ describe Lanes::Command do
|
|
34
34
|
|
35
35
|
it "generates an application" do
|
36
36
|
reference = reference_path.join('initial')
|
37
|
+
gemfile = reference.join("Gemfile")
|
38
|
+
gemfile.write gemfile.read.gsub(/gem \"lanes\", \'\d+\.\d+\.\d+\'/, "gem \"lanes\", '#{Lanes::VERSION}'")
|
39
|
+
|
40
|
+
|
37
41
|
compare_generated(reference)
|
38
42
|
generated_path.find.each do | path |
|
39
43
|
relative = path.relative_path_from(generated_path)
|
@@ -11,14 +11,6 @@ class AssociationExtensionsTest < Lanes::TestCase
|
|
11
11
|
assert_match( /does not have an inverse_of specified./, err.message )
|
12
12
|
end
|
13
13
|
|
14
|
-
def test_adds_listener
|
15
|
-
Tmhm.belongs_to(:tm)
|
16
|
-
TestModel.has_one(:tmhm,:listen=>{:save=>:on_tmhm_save}, :inverse_of=>:tm)
|
17
|
-
tm = TestModel.new
|
18
|
-
tm.expects(:on_tmhm_save)
|
19
|
-
tm.build_tmhm
|
20
|
-
assert tm.save
|
21
|
-
end
|
22
14
|
|
23
15
|
def test_exports_associations
|
24
16
|
TestModel.expects(:export_associations).with(:tmhm,{})
|
@@ -1,35 +1,79 @@
|
|
1
1
|
require_relative "../spec_helper"
|
2
2
|
|
3
|
-
|
3
|
+
describe "PubSub" do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
include ActiveRecordMocks::IncludeMe
|
6
|
+
around do | test |
|
7
|
+
with_mocked_tables do |m|
|
8
|
+
m.create_table do |t|
|
9
|
+
t.model_name :Evbt
|
10
|
+
t.belongs_to :evhm, class_name: "Evhm", listen: { create: 'on_create_hm' },
|
11
|
+
inverse_of: :evbt
|
12
|
+
t.layout do |l|
|
13
|
+
l.integer :evhm_id
|
14
|
+
end
|
15
|
+
t.parent_class "Lanes::Model"
|
16
|
+
end
|
17
|
+
class Evbt
|
18
|
+
has_additional_events :test_one
|
19
|
+
def on_create_hm(*args)
|
20
|
+
32
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
m.create_table do |t|
|
25
|
+
t.model_name :EventTester
|
26
|
+
t.parent_class "Lanes::Model"
|
27
|
+
t.belongs_to :evbt, class_name: 'Evhm'
|
28
|
+
|
29
|
+
t.has_many :evhm, class_name: 'Evhm', inverse_of: :event_tester
|
30
|
+
|
31
|
+
t.layout do |l|
|
32
|
+
l.integer :bt_id
|
33
|
+
l.string :name, :number
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
table = m.create_table do |t|
|
38
|
+
t.model_name :Evhm
|
39
|
+
t.belongs_to :evbt, class_name: "Evbt", listen: { save: 'on_create_bt' },
|
40
|
+
inverse_of: :evhm
|
41
|
+
t.belongs_to :event_tester, class_name: "EventTester", inverse_of: :evhm,
|
42
|
+
listen: { save: 'on_save_event_tester' }
|
43
|
+
t.parent_class "Lanes::Model"
|
44
|
+
t.layout do | l |
|
45
|
+
l.string :mumble
|
46
|
+
l.integer :evbt_id, :event_tester_id
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def table.on_save_event_tester(*args)
|
50
|
+
end
|
10
51
|
|
11
|
-
include Lanes::Concerns::PubSub
|
12
52
|
|
13
|
-
|
14
|
-
|
53
|
+
|
54
|
+
test.call
|
15
55
|
end
|
16
56
|
end
|
17
57
|
|
18
|
-
|
19
|
-
|
20
|
-
|
58
|
+
it "listens to other associations" do
|
59
|
+
e=Evbt.new
|
60
|
+
assert_equal 32, e.on_create_hm
|
61
|
+
b=e.build_evhm
|
62
|
+
b.expects(:on_create_bt)
|
63
|
+
assert e.save
|
21
64
|
|
22
|
-
|
23
|
-
|
65
|
+
et = EventTester.new
|
66
|
+
evh = et.evhm.build
|
67
|
+
evh.expects(:on_save_event_tester)
|
68
|
+
assert et.save
|
24
69
|
end
|
25
70
|
|
26
|
-
|
27
|
-
def test_event_name_registration
|
71
|
+
it "registers" do
|
28
72
|
assert_equal [ :save, :create, :update, :destroy ],EventTester.valid_event_names
|
29
|
-
assert_equal [ :save, :create, :update, :destroy, :test_one ],
|
73
|
+
assert_equal [ :save, :create, :update, :destroy, :test_one ],Evbt.valid_event_names
|
30
74
|
end
|
31
75
|
|
32
|
-
|
76
|
+
it "can only observe valid events" do
|
33
77
|
assert_raises( EventTester::InvalidEvent) do
|
34
78
|
EventTester.observe(:invalid_event) do | ev |
|
35
79
|
end
|
@@ -37,45 +81,47 @@ class PubSubTest < Lanes::TestCase
|
|
37
81
|
assert_raises( EventTester::InvalidEvent) do
|
38
82
|
EventTester.observe(:save) do | ev |
|
39
83
|
end
|
40
|
-
EventTester.new.
|
84
|
+
EventTester.new.send(:fire_event,:invalid_event)
|
41
85
|
end
|
42
86
|
assert_raises( EventTester::InvalidEvent) do
|
43
|
-
|
87
|
+
Evbt.observe(:test_two) do | ev |
|
44
88
|
end
|
45
89
|
end
|
46
90
|
assert_raises( EventTester::InvalidEvent) do
|
47
|
-
|
91
|
+
Evhm.observe(:test_one) do | ev |
|
48
92
|
end
|
49
93
|
end
|
50
94
|
begin
|
51
|
-
|
95
|
+
Evbt.observe(:test_one) do | ev |
|
52
96
|
end
|
53
97
|
rescue EventTester::InvalidEvent=>e
|
54
98
|
assert_equal 'test_one is not a valid event for PubSubTest::Ev2', e.to_s
|
55
99
|
end
|
56
100
|
end
|
57
101
|
|
58
|
-
|
102
|
+
it "events can be subscribed to" do
|
59
103
|
EventTester.observe(:save) do | ev |
|
104
|
+
|
60
105
|
end
|
61
106
|
end
|
62
|
-
|
107
|
+
|
108
|
+
it "can be fired and observed" do
|
63
109
|
results=[]
|
64
|
-
|
110
|
+
Evbt.observe(:test_one) do | ev, one, two |
|
65
111
|
results = [ ev, one, two ]
|
66
112
|
end
|
67
|
-
evt=
|
68
|
-
evt.
|
113
|
+
evt=Evbt.new
|
114
|
+
evt.send(:fire_event, :test_one, 3, 5 )
|
69
115
|
assert_equal [ evt, 3, 5 ], results
|
70
116
|
|
71
|
-
evt.
|
117
|
+
evt.send(:fire_event, :test_one, 'foo' )
|
72
118
|
assert_equal [ evt, 'foo', nil ], results
|
73
119
|
end
|
74
120
|
|
75
121
|
|
76
|
-
|
77
|
-
assert_event_fires(
|
78
|
-
|
122
|
+
it "can use custom event assertions" do
|
123
|
+
assert_event_fires( Evbt, :test_one ) do
|
124
|
+
Evbt.new.send(:fire_event, :test_one, 3, 5 )
|
79
125
|
end
|
80
126
|
assert_equal [ 3, 5 ], last_event_results[1..-1]
|
81
127
|
end
|