hyper-mesh 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +7 -2
- data/README.md +112 -87
- data/Rakefile +6 -1
- data/docs/action_cable_quickstart.md +20 -16
- data/docs/activerecord_api.md +23 -17
- data/docs/authorization-policies.md +45 -35
- data/docs/client_side_scoping.md +5 -5
- data/docs/configuration_details.md +6 -46
- data/docs/pusher_faker_quickstart.md +7 -68
- data/docs/pusher_quickstart.md +7 -68
- data/docs/simple_poller_quickstart.md +6 -67
- data/docs/todo-example.md +2 -2
- data/docs/word_game.md +3 -1
- data/docs/words-example.md +2 -3
- data/examples/action-cable/Gemfile +2 -1
- data/examples/action-cable/Gemfile.lock +73 -54
- data/examples/action-cable/config/initializers/{hyper_mesh.rb → hyperloop.rb} +1 -1
- data/examples/action-cable/config/routes.rb +1 -1
- data/hyper-mesh.gemspec +10 -4
- data/lib/active_record_base.rb +3 -3
- data/{examples/action-cable-production-mode/log/.keep → lib/acts_as_string.rb} +0 -0
- data/lib/hyper-mesh.rb +11 -19
- data/lib/hyper_mesh/version.rb +3 -0
- data/lib/hypermesh/version.rb +1 -1
- data/lib/reactive_record/active_record/class_methods.rb +10 -3
- data/lib/reactive_record/active_record/instance_methods.rb +8 -0
- data/lib/reactive_record/active_record/public_columns_hash.rb +8 -2
- data/lib/reactive_record/active_record/reactive_record/collection.rb +0 -1
- data/lib/reactive_record/active_record/reactive_record/dummy_value.rb +2 -1
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +55 -63
- data/lib/reactive_record/active_record/reactive_record/operations.rb +51 -0
- data/lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb +3 -3
- data/lib/reactive_record/active_record/reactive_record/while_loading.rb +93 -84
- data/lib/reactive_record/broadcast.rb +183 -0
- data/lib/reactive_record/permissions.rb +2 -2
- data/reactive_record_test_app/Gemfile +6 -2
- data/reactive_record_test_app/Gemfile.lock +120 -60
- data/reactive_record_test_app/app/assets/javascripts/application.rb +3 -5
- data/reactive_record_test_app/app/assets/javascripts/bigdecimal.rb +1 -0
- data/reactive_record_test_app/app/assets/javascripts/reactive_record_config.js +2 -2
- data/reactive_record_test_app/app/controllers/application_controller.rb +3 -3
- data/reactive_record_test_app/app/controllers/home_controller.rb +1 -1
- data/reactive_record_test_app/app/models/models.rb.erb +6 -0
- data/reactive_record_test_app/config/application.rb +2 -0
- data/reactive_record_test_app/config/environments/development.rb +1 -1
- data/reactive_record_test_app/config/routes.rb +1 -2
- data/reactive_record_test_app/db/seeds.rb +6 -0
- data/reactive_record_test_app/script/rails +0 -0
- data/reactive_record_test_app/spec-opal/active-record/rendering_spec.rb +11 -2
- data/reactive_record_test_app/spec-opal/active-record/save_spec.rb +3 -4
- data/reactive_record_test_app/spec-opal/spec_helper.js.rb +1 -1
- data/reactive_record_test_app/spec-opal/test_spec.rb +7 -0
- data/reactive_record_test_app/spec_dont_run/README.md +7 -0
- data/reactive_record_test_app/{spec-opal/active-record → spec_dont_run/active_record_broken}/permissions_spec.rb +0 -0
- data/reactive_record_test_app/{spec-opal/active-record → spec_dont_run/active_record_broken}/prerendering_spec.rb +1 -0
- data/spec/{synchromesh/aaa-unit_tests/connection_spec.rb → batch1/aaa-unit_tests/connection_movedspec.rb} +0 -0
- data/spec/{synchromesh → batch1}/aaa-unit_tests/dummy_value_spec.rb +2 -2
- data/spec/{synchromesh → batch1}/column_types/column_type_spec.rb +2 -2
- data/spec/{synchromesh → batch1}/crud_access_regulation/broadcast_controls_access_spec.rb +1 -1
- data/spec/{synchromesh → batch1}/crud_access_regulation/model_policies_spec.rb +6 -6
- data/spec/batch1/misc/access_like_hash_spec.rb +43 -0
- data/spec/batch1/misc/while_loading_spec.rb +196 -0
- data/spec/{synchromesh → batch1}/policies/regulate_all_broadcasts_spec.rb +12 -12
- data/spec/{synchromesh → batch1}/policies/regulate_broadcast_spec.rb +25 -25
- data/spec/{synchromesh/integration → batch2}/authorization_spec.rb +8 -7
- data/spec/{synchromesh/integration → batch2}/default_scope_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch2}/has_many_through_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch2}/relationships_spec.rb +3 -3
- data/spec/{reactive_record → batch3}/auto_load_itself_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/edge_cases_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/finder_method_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/many_to_many_spec.rb +2 -2
- data/spec/{reactive_record → batch3}/pry_rescue_xspec.rb +0 -0
- data/{examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css → spec/batch3/readme.txt} +0 -0
- data/spec/{reactive_record → batch3}/revert_spec.rb +2 -2
- data/spec/{reactive_record → batch3}/save_while_loading_spec.rb +1 -1
- data/spec/{reactive_record → batch3}/update_associations_spec.rb +2 -2
- data/spec/{reactive_record → batch3}/update_scopes_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch4}/saving_during_commit_spec.rb +2 -2
- data/spec/{synchromesh/integration → batch4}/scope_spec.rb +30 -2
- data/spec/{synchromesh/examples → batch4}/scoped_todos_spec.rb +3 -3
- data/spec/{synchromesh/integration → batch4}/synchromesh_spec.rb +2 -2
- data/spec/{synchromesh/examples → examples}/dictionary.rb +2 -2
- data/spec/{synchromesh/examples → examples}/dictionary_with_client_scopes.rb +2 -2
- data/spec/{synchromesh/examples → examples}/random_examples.rb +1 -1
- data/spec/{reactive_record/play.rb → play_ground.rb} +0 -0
- data/spec/{reactive_record/factory.rb → reactive_record_factory.rb} +0 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/test_app/Gemfile +8 -3
- data/spec/test_app/Gemfile.lock +114 -64
- data/spec/test_app/app/views/components.rb +1 -2
- data/spec/test_app/config/application.rb +2 -0
- data/spec/test_app/config/routes.rb +1 -1
- data/spec/{synchromesh/integration/test_components.rb → test_components.rb} +0 -0
- metadata +144 -137
- data/app/controllers/reactive_record/application_controller.rb +0 -4
- data/app/controllers/reactive_record/reactive_record_controller.rb +0 -49
- data/config/routes.rb +0 -7
- data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js +0 -50
- data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js.gz +0 -0
- data/examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz +0 -0
- data/examples/action-cable-production-mode/tmp/.keep +0 -0
- data/examples/action-cable/log/.keep +0 -0
- data/examples/action-cable/tmp/.keep +0 -0
- data/examples/pusher-fake/log/.keep +0 -0
- data/examples/pusher-fake/tmp/.keep +0 -0
- data/examples/pusher/log/.keep +0 -0
- data/examples/pusher/tmp/.keep +0 -0
- data/examples/simple-poller/log/.keep +0 -0
- data/examples/simple-poller/tmp/.keep +0 -0
- data/examples/word-game/log/.keep +0 -0
- data/examples/word-game/tmp/.keep +0 -0
- data/examples/words/log/.keep +0 -0
- data/examples/words/tmp/.keep +0 -0
- data/lib/reactive_record/version.rb +0 -3
- data/lib/sources/hyper-mesh/pusher.js +0 -98
- data/lib/synchromesh/action_cable.rb +0 -39
- data/lib/synchromesh/client_drivers.rb +0 -357
- data/lib/synchromesh/configuration.rb +0 -40
- data/lib/synchromesh/connection.rb +0 -170
- data/lib/synchromesh/policy.rb +0 -504
- data/lib/synchromesh/synchromesh.rb +0 -159
- data/lib/synchromesh/synchromesh_controller.rb +0 -162
- data/reactive_record_test_app/README.rdoc +0 -261
- data/reactive_record_test_app/app/assets/javascripts/components/another_component.rb +0 -24
- data/reactive_record_test_app/app/assets/javascripts/components/empty_component.rb +0 -6
- data/reactive_record_test_app/app/assets/javascripts/components/todo_item_component.js.rb +0 -16
- data/reactive_record_test_app/app/assets/javascripts/components/todos_component.js.rb +0 -42
- data/reactive_record_test_app/app/assets/javascripts/components/todos_main_component.rb +0 -49
- data/reactive_record_test_app/app/assets/javascripts/react_js_test_only.js +0 -21618
- data/reactive_record_test_app/app/assets/javascripts/spec/reactive_record_xspec.js.rb +0 -42
- data/reactive_record_test_app/app/controllers/test_controller.rb +0 -7
- data/reactive_record_test_app/app/mailers/.gitkeep +0 -0
- data/reactive_record_test_app/app/models/models.rb +0 -1
- data/reactive_record_test_app/app/policies/application_policy.rb +0 -5
- data/reactive_record_test_app/app/views/components.rb +0 -4
- data/reactive_record_test_app/app/views/components/test.rb +0 -18
- data/reactive_record_test_app/app/views/home/index.html.erb +0 -1
- data/reactive_record_test_app/app/views/layouts/application.html.erb +0 -17
- data/reactive_record_test_app/config/environments/production.rb +0 -70
- data/reactive_record_test_app/config/environments/test.rb +0 -41
- data/spec/synchromesh/integration/transports_spec.rb +0 -308
- data/spec/synchromesh/policies/auto_connect_spec.rb +0 -60
- data/spec/synchromesh/policies/auto_loader_spec.rb +0 -34
- data/spec/synchromesh/policies/policy_methods_spec.rb +0 -85
- data/spec/synchromesh/policies/regulate_class_connection_spec.rb +0 -50
- data/spec/synchromesh/policies/regulate_instance_connection_spec.rb +0 -66
- data/spec/test_app/log/.keep +0 -0
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'channel auto connect' do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
stub_const 'ApplicationPolicy', Class.new
|
7
|
-
stub_const 'TestModelPolicy', Class.new
|
8
|
-
stub_const 'TestModel', Class.new
|
9
|
-
TestModel.class_eval do
|
10
|
-
def initialize(id)
|
11
|
-
@id = id
|
12
|
-
end
|
13
|
-
def self.find(id)
|
14
|
-
new(id)
|
15
|
-
end
|
16
|
-
def id
|
17
|
-
@id
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'will autoconnect' do
|
23
|
-
ApplicationPolicy.always_allow_connection
|
24
|
-
expect(HyperMesh::AutoConnect.channels(0, nil)).to eq(["Application"])
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'will autoconnect to multiple channels' do
|
28
|
-
ApplicationPolicy.regulate_class_connection { true }
|
29
|
-
ApplicationPolicy.regulate_class_connection('AnotherChannel') { true }
|
30
|
-
expect(HyperMesh::AutoConnect.channels(0, nil)).to eq(['Application', 'AnotherChannel'])
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'will not autoconnect a class channel if disabled' do
|
34
|
-
ApplicationPolicy.regulate_class_connection(auto_connect: false) { true }
|
35
|
-
ApplicationPolicy.regulate_instance_connections(TestModel) { self }
|
36
|
-
expect(HyperMesh::AutoConnect.channels(0, TestModel.find(1))).to eq([['TestModel',1]])
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'will not autoconnect an instance channel if disabled' do
|
40
|
-
ApplicationPolicy.regulate_class_connection { true }
|
41
|
-
ApplicationPolicy.regulate_instance_connections(TestModel, auto_connect: false) { self }
|
42
|
-
expect(HyperMesh::AutoConnect.channels(0, TestModel.find(1))).to eq(['Application'])
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'can autoconnect to an instance' do
|
46
|
-
TestModelPolicy.regulate_instance_connections { self }
|
47
|
-
expect(HyperMesh::AutoConnect.channels(0, TestModel.find(1))).to eq([['TestModel', 1]])
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'can autoconnect to an instance and class' do
|
51
|
-
TestModelPolicy.always_allow_connection
|
52
|
-
TestModelPolicy.regulate_instance_connections { self }
|
53
|
-
expect(HyperMesh::AutoConnect.channels(0, TestModel.find(1))).to eq(['TestModel', ['TestModel', 1]])
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'can autoconnect to multiple instances' do
|
57
|
-
TestModelPolicy.regulate_instance_connections { [TestModel.find(1), TestModel.find(2)] if self == 'acting_user'}
|
58
|
-
expect(HyperMesh::AutoConnect.channels(0, 'acting_user')).to eq([['TestModel', 1], ['TestModel', 2]])
|
59
|
-
end
|
60
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'rails autoloader' do
|
5
|
-
|
6
|
-
# can't figure out how to get rails to dump class cache between tests so
|
7
|
-
# we define two different class policy pairs...
|
8
|
-
|
9
|
-
context "when using const_set" do
|
10
|
-
|
11
|
-
it 'will find the policy class file if available' do
|
12
|
-
stub_const "AutoLoaderTestClassa", Class.new
|
13
|
-
expect(HyperMesh::AutoConnect.channels(0, nil)).to eq(["AutoLoaderTestClassa"])
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'will raise a load error if file does not define the class' do
|
17
|
-
expect { stub_const "AutoLoaderTestClassc", Class.new }.to raise_error(LoadError)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when defining a new class" do
|
22
|
-
|
23
|
-
it 'will find the policy class if available' do
|
24
|
-
class AutoLoaderTestClassb
|
25
|
-
end
|
26
|
-
expect(HyperMesh::AutoConnect.channels(0, nil)).to eq(["AutoLoaderTestClassb"])
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'will raise a load error if file does not define the class' do
|
30
|
-
expect { class AutoLoaderTestClassd; end }.to raise_error(LoadError)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
#require 'synchromesh/test_components'
|
3
|
-
|
4
|
-
describe "including HyperMesh::PolicyMethods" do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
stub_const "TestClass", Class.new
|
8
|
-
TestClass.class_eval do
|
9
|
-
include HyperMesh::PolicyMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it "defines the regulate_class_connection method" do
|
14
|
-
expect(TestClass).to respond_to(:regulate_class_connection)
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
it "defines the regulate_instance_connections method" do
|
19
|
-
expect(TestClass).to respond_to(:regulate_instance_connections)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "defines the always_allow_connection method" do
|
23
|
-
expect(TestClass).to respond_to(:always_allow_connection)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "defines the regulate_all_broadcasts method" do
|
27
|
-
expect(TestClass).to respond_to(:regulate_all_broadcasts)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "defines the regulate_broadcast method" do
|
31
|
-
expect(TestClass).to respond_to(:regulate_broadcast)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "sets the correct regulated class" do
|
35
|
-
expect(TestClass.synchromesh_internal_policy_object.instance_variable_get("@regulated_klass")).to eq("TestClass")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "exposes the underlying regulate_class_connection method" do
|
39
|
-
expect(TestClass.synchromesh_internal_policy_object).to respond_to(:regulate_class_connection)
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
it "exposes the underlying regulate_instance_connections method" do
|
44
|
-
expect(TestClass.synchromesh_internal_policy_object).to respond_to(:regulate_instance_connections)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "exposes the underlying always_allow_connection method" do
|
48
|
-
expect(TestClass.synchromesh_internal_policy_object).to respond_to(:always_allow_connection)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "exposes the underlying regulate_all_broadcasts method" do
|
52
|
-
expect(TestClass.synchromesh_internal_policy_object).to respond_to(:regulate_all_broadcasts)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "exposes the underlying regulate_broadcast method" do
|
56
|
-
expect(TestClass.synchromesh_internal_policy_object).to respond_to(:regulate_broadcast)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "defines the send_all instance method" do
|
60
|
-
expect(TestClass.new).to respond_to(:send_all)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "defines the send_all_but instance method" do
|
64
|
-
expect(TestClass.new).to respond_to(:send_all_but)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "defines the send_only instance method" do
|
68
|
-
expect(TestClass.new).to respond_to(:send_only)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "defines the obj instance method" do
|
72
|
-
expect(TestClass.new).to respond_to(:obj)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "will automatically create an empty Application class if needed" do
|
76
|
-
expect(defined? Application).to be_falsy
|
77
|
-
stub_const 'ApplicationPolicy', Class.new
|
78
|
-
ApplicationPolicy.class_eval do
|
79
|
-
regulate_class_connection { true }
|
80
|
-
end
|
81
|
-
HyperMesh.configuration {}
|
82
|
-
expect(Application).to be_a(Class)
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "regulate class connections" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
stub_const "ApplicationPolicy", Class.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "will fail if there is no connection policy for a class" do
|
10
|
-
ApplicationPolicy.regulate_instance_connections { self }
|
11
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Application") }.to raise_error('connection failed')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "will succeed if there is a connection policy for a class" do
|
15
|
-
ApplicationPolicy.regulate_class_connection { true }
|
16
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Application") }.not_to raise_error
|
17
|
-
end
|
18
|
-
|
19
|
-
it "the class connection policy ignores the acting_user object" do
|
20
|
-
ApplicationPolicy.regulate_class_connection { true }
|
21
|
-
expect { HyperMesh::InternalPolicy.regulate_connection("acting_user", "Application") }.not_to raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
it "can be applied to a different class" do
|
25
|
-
stub_const "Class1", Class.new
|
26
|
-
stub_const "Class2", Class.new
|
27
|
-
ApplicationPolicy.regulate_class_connection(Class1, Class2) { true }
|
28
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Class1") }.not_to raise_error
|
29
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Class2") }.not_to raise_error
|
30
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Application") }.to raise_error('connection failed')
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can be simplified using the always_allow_connection method" do
|
34
|
-
ApplicationPolicy.always_allow_connection
|
35
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Application") }.not_to raise_error
|
36
|
-
end
|
37
|
-
|
38
|
-
it "can conditionally regulate the connection" do
|
39
|
-
ApplicationPolicy.regulate_class_connection { self }
|
40
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(true, "Application") }.not_to raise_error
|
41
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Application") }.to raise_error('connection failed')
|
42
|
-
end
|
43
|
-
|
44
|
-
it "can conditionally regulate the connection by raising an error" do
|
45
|
-
ApplicationPolicy.regulate_class_connection { raise "POW" unless self=="okay"; true }
|
46
|
-
expect { HyperMesh::InternalPolicy.regulate_connection("okay", "Application") }.not_to raise_error
|
47
|
-
expect { HyperMesh::InternalPolicy.regulate_connection("dokey", "Application") }.to raise_error('connection failed')
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "regulate_instance_connections" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
stub_const "ApplicationPolicy", Class.new
|
7
|
-
stub_const "Application", Class.new
|
8
|
-
Application.class_eval do
|
9
|
-
def initialize(id)
|
10
|
-
@id = id
|
11
|
-
end
|
12
|
-
def ==(other)
|
13
|
-
id == other.id
|
14
|
-
end
|
15
|
-
def self.find(id)
|
16
|
-
new(id)
|
17
|
-
end
|
18
|
-
def id
|
19
|
-
@id.to_s
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "will fail for an instance connection if the connection policy does not support instances" do
|
25
|
-
ApplicationPolicy.always_allow_connection
|
26
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.find(123), "Application-123") }.to raise_error('connection failed')
|
27
|
-
end
|
28
|
-
|
29
|
-
it "will succeed for an instance connection if the connection policy does support instances" do
|
30
|
-
ApplicationPolicy.always_allow_connection
|
31
|
-
ApplicationPolicy.regulate_instance_connections { self }
|
32
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.find(123), "Application-123") }.not_to raise_error
|
33
|
-
end
|
34
|
-
|
35
|
-
it "will succeed only if the user id is correct" do
|
36
|
-
ApplicationPolicy.regulate_instance_connections { Application.find('baz') }
|
37
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(nil, "Application-baz") }.not_to raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it "can be applied to a different class" do
|
41
|
-
stub_const "Class1", Class.new(Application)
|
42
|
-
stub_const "Class2", Class.new(Application)
|
43
|
-
ApplicationPolicy.regulate_instance_connections(Class1, Class2) { self }
|
44
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Class1.find('baz'), "Class1-baz") }.not_to raise_error
|
45
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Class2.find('baz-2'), "Class2-baz-2") }.not_to raise_error
|
46
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.find('baz'), "Application-baz") }.to raise_error('connection failed')
|
47
|
-
end
|
48
|
-
|
49
|
-
it "can return an array objects" do
|
50
|
-
ApplicationPolicy.regulate_instance_connections { [Application.find(1), Application.find(2)] }
|
51
|
-
expect { HyperMesh::InternalPolicy.regulate_connection("foo", "Application-1") }.not_to raise_error
|
52
|
-
expect { HyperMesh::InternalPolicy.regulate_connection("foo", "Application-2") }.not_to raise_error
|
53
|
-
end
|
54
|
-
|
55
|
-
it "can conditionally regulate the connection" do
|
56
|
-
ApplicationPolicy.regulate_instance_connections { id == '1' && self }
|
57
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.new(1), "Application-1") }.not_to raise_error
|
58
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.new(2), "Application-2") }.to raise_error('connection failed')
|
59
|
-
end
|
60
|
-
|
61
|
-
it "can regulate the connection by raising an error" do
|
62
|
-
ApplicationPolicy.regulate_instance_connections { raise "POW" unless id == '1'; self}
|
63
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.new(1), "Application-1") }.not_to raise_error
|
64
|
-
expect { HyperMesh::InternalPolicy.regulate_connection(Application.new(2), "Application-2") }.to raise_error('connection failed')
|
65
|
-
end
|
66
|
-
end
|
data/spec/test_app/log/.keep
DELETED
File without changes
|