foreign_office 0.16.2 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/foreign_office/busses/pubnub_bus.rb +7 -2
- data/lib/foreign_office/busses/pusher_bus.rb +5 -0
- data/lib/foreign_office/foreign_office_helper.rb +12 -6
- data/lib/foreign_office/version.rb +1 -1
- data/test/foreign_office_test.rb +63 -4
- data/test/support/pubnub.rb +15 -0
- data/test/support/pusher.rb +17 -0
- data/test/test_helper.rb +1 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dcd8f2b90d4074f1ca898d3c1e15119e2524dd1
|
4
|
+
data.tar.gz: 7cc327155c63a6b0a081e9a43e596a56bad97feb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79fb12070d6bf97c9c6d2fa31531790459e1cc8ac79d00762da6706b4786edf146e6cfcc3d0ffc60d96c2eb5be1020b9ed9d521930423b1864a0a30e88ecca9a
|
7
|
+
data.tar.gz: 3d197949fcfd7ae17cd27a605364f48a0d63325d881651140a5ce91ccfd1b8f67a2ae6487d281ebb39d9f19d60352f499a0756a866492ef0daf76e4e05ac6609
|
@@ -40,9 +40,14 @@ class ForeignOffice::Busses::PubnubBus < ForeignOffice::Busses::GenericBus
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.publish(message)
|
43
|
-
message
|
43
|
+
channel = message[:channel]
|
44
|
+
|
45
|
+
if browser_tab_id = message[:browser_tab_id]
|
46
|
+
channel += "@#{browser_tab_id}"
|
47
|
+
end
|
48
|
+
|
44
49
|
self.connection.publish(
|
45
|
-
channel:
|
50
|
+
channel: channel,
|
46
51
|
message: message,
|
47
52
|
http_sync: true
|
48
53
|
) do |envelope|
|
@@ -35,6 +35,11 @@ class ForeignOffice::Busses::PusherBus < ForeignOffice::Busses::GenericBus
|
|
35
35
|
def self.publish(message)
|
36
36
|
message.symbolize_keys!
|
37
37
|
channel = sanitize_channel(message[:channel])
|
38
|
+
|
39
|
+
if browser_tab_id = message[:browser_tab_id]
|
40
|
+
channel += "@#{browser_tab_id}"
|
41
|
+
end
|
42
|
+
|
38
43
|
self.connection.trigger(
|
39
44
|
channel,
|
40
45
|
'publish',
|
@@ -2,8 +2,10 @@ module ForeignOffice
|
|
2
2
|
module ForeignOfficeHelper
|
3
3
|
def listener_attrs(resource, key, reveal_hide: false, endpoint: nil, download: nil,
|
4
4
|
trigger: nil, delete: nil, href_target: nil, create_modal: nil, mask_me: nil,
|
5
|
-
exclude_value: nil)
|
6
|
-
|
5
|
+
exclude_value: nil, browser_tab_id: nil )
|
6
|
+
channel = "#{resource.class.name}#{resource.id}"
|
7
|
+
channel += "@#{browser_tab_id}" if browser_tab_id
|
8
|
+
data_attrs = "data-listener=true data-channel=#{channel}"
|
7
9
|
if delete
|
8
10
|
data_attrs += " data-delete-key=#{key}"
|
9
11
|
else
|
@@ -27,7 +29,8 @@ module ForeignOffice
|
|
27
29
|
|
28
30
|
def listener_attrs_raw(channel, key, reveal_hide: false, endpoint: nil, download: nil,
|
29
31
|
trigger: nil, delete: nil, href_target: nil, create_modal: nil, mask_me: nil,
|
30
|
-
exclude_value: nil)
|
32
|
+
exclude_value: nil, browser_tab_id: nil)
|
33
|
+
channel += "@#{browser_tab_id}" if browser_tab_id
|
31
34
|
data_attrs = "data-listener=true data-channel=#{channel}"
|
32
35
|
if delete
|
33
36
|
data_attrs += " data-delete-key=#{key}"
|
@@ -47,8 +50,10 @@ module ForeignOffice
|
|
47
50
|
|
48
51
|
def listener_hash(resource, key, reveal_hide: false, endpoint: nil, download: nil,
|
49
52
|
trigger: nil, delete: nil, href_target: nil, create_modal: nil, mask_me: nil,
|
50
|
-
exclude_value: nil)
|
51
|
-
|
53
|
+
exclude_value: nil, browser_tab_id: nil)
|
54
|
+
channel = resource.class.name + resource.id
|
55
|
+
channel += "@#{browser_tab_id}" if browser_tab_id
|
56
|
+
hash = {listener: true, channel: channel}
|
52
57
|
if delete
|
53
58
|
hash[:delete_key] = key
|
54
59
|
else
|
@@ -67,7 +72,8 @@ module ForeignOffice
|
|
67
72
|
|
68
73
|
def listener_hash_raw(channel, key, reveal_hide: false, endpoint: nil, download: nil,
|
69
74
|
trigger: nil, delete: nil, href_target: nil, create_modal: nil, mask_me: nil,
|
70
|
-
exclude_value: nil)
|
75
|
+
exclude_value: nil, browser_tab_id: nil)
|
76
|
+
channel += "@#{browser_tab_id}" if browser_tab_id
|
71
77
|
hash = {listener: true, channel: channel}
|
72
78
|
if delete
|
73
79
|
hash[:delete_key] = key
|
data/test/foreign_office_test.rb
CHANGED
@@ -2,12 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ForeignOfficeTest < MiniTest::Unit::TestCase
|
4
4
|
describe "ForeignOffice" do
|
5
|
-
before do
|
6
|
-
@bus = Minitest::Mock.new
|
7
|
-
ForeignOffice.bus = @bus
|
8
|
-
end
|
9
5
|
describe "caches messages when asked" do
|
10
6
|
before do
|
7
|
+
@bus = Minitest::Mock.new
|
8
|
+
ForeignOffice.bus = @bus
|
11
9
|
ForeignOffice.cache_messages
|
12
10
|
end
|
13
11
|
it "caches multiple messages" do
|
@@ -30,6 +28,10 @@ class ForeignOfficeTest < MiniTest::Unit::TestCase
|
|
30
28
|
end
|
31
29
|
end
|
32
30
|
describe "doesn't have to cache" do
|
31
|
+
before do
|
32
|
+
@bus = Minitest::Mock.new
|
33
|
+
ForeignOffice.bus = @bus
|
34
|
+
end
|
33
35
|
it "publishes messages directly when not caching" do
|
34
36
|
ForeignOffice.publish_directly
|
35
37
|
@bus.expect :publish, nil, [{channel: 'TestMe', object: {this: 'is a test'}}]
|
@@ -38,6 +40,10 @@ class ForeignOfficeTest < MiniTest::Unit::TestCase
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
describe "offers custom publishing" do
|
43
|
+
before do
|
44
|
+
@bus = Minitest::Mock.new
|
45
|
+
ForeignOffice.bus = @bus
|
46
|
+
end
|
41
47
|
it "publishes with a custom method if provided" do
|
42
48
|
ForeignOffice.publish_directly
|
43
49
|
@bus.expect :custom_publish, nil, [{channel: 'TestMe', object: {this: 'is a test'}}]
|
@@ -47,5 +53,58 @@ class ForeignOfficeTest < MiniTest::Unit::TestCase
|
|
47
53
|
ForeignOffice.unset_publish_method
|
48
54
|
end
|
49
55
|
end
|
56
|
+
describe "passing browser tab id to pusher" do
|
57
|
+
before do
|
58
|
+
ForeignOffice.unset_publish_method
|
59
|
+
ForeignOffice.publish_directly
|
60
|
+
end
|
61
|
+
|
62
|
+
it "publishes with browser id appended" do
|
63
|
+
ForeignOffice.config({bus: {klass: ForeignOffice::Busses::PusherBus}})
|
64
|
+
resp = ForeignOffice.publish({channel: "TestMe", object: {this: 'is a test'}, browser_tab_id: 'tab-id-123'})
|
65
|
+
resp[:channel].must_equal("TestMe@tab-id-123")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "published without browser id appended" do
|
69
|
+
ForeignOffice.config({bus: {klass: ForeignOffice::Busses::PusherBus}})
|
70
|
+
resp = ForeignOffice.publish({channel: "TestMe", object: {this: 'is a test'}})
|
71
|
+
resp[:channel].must_equal("TestMe")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
describe "passing browser tab id to pubnub" do
|
75
|
+
before do
|
76
|
+
ForeignOffice.unset_publish_method
|
77
|
+
ForeignOffice.publish_directly
|
78
|
+
end
|
79
|
+
|
80
|
+
it "published with browser id appended" do
|
81
|
+
ForeignOffice.config(
|
82
|
+
{
|
83
|
+
bus: {
|
84
|
+
klass: ForeignOffice::Busses::PubnubBus,
|
85
|
+
publish_key: "1234",
|
86
|
+
subscribe_key: '5678',
|
87
|
+
secret_key: '91011'
|
88
|
+
}
|
89
|
+
}
|
90
|
+
)
|
91
|
+
resp = ForeignOffice.publish({channel: "TestMe", object: {this: 'is a test'}, browser_tab_id: 'tab-id-123'})
|
92
|
+
resp[:channel].must_equal "TestMe@tab-id-123"
|
93
|
+
end
|
94
|
+
it "published without browser id appended" do
|
95
|
+
ForeignOffice.config(
|
96
|
+
{
|
97
|
+
bus: {
|
98
|
+
klass: ForeignOffice::Busses::PubnubBus,
|
99
|
+
publish_key: "1234",
|
100
|
+
subscribe_key: '5678',
|
101
|
+
secret_key: '91011'
|
102
|
+
}
|
103
|
+
}
|
104
|
+
)
|
105
|
+
resp = ForeignOffice.publish({channel: "TestMe", object: {this: 'is a test'}})
|
106
|
+
resp[:channel].must_equal "TestMe"
|
107
|
+
end
|
108
|
+
end
|
50
109
|
end
|
51
110
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Pubnub
|
2
|
+
def initialize(hash)
|
3
|
+
@publish_key = hash[:publish_key]
|
4
|
+
@subscribe_key = hash[:subscribe_key]
|
5
|
+
@secret_key = hash[:secret_key]
|
6
|
+
@ssl = true
|
7
|
+
end
|
8
|
+
|
9
|
+
def publish(message)
|
10
|
+
return {
|
11
|
+
channel: message[:channel],
|
12
|
+
message: message[:message]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Pusher
|
2
|
+
def self.encrypted=(bool)
|
3
|
+
@encrypt = bool
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.encrypted
|
7
|
+
@encrypt
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.trigger(channel, command, message)
|
11
|
+
return {
|
12
|
+
channel: channel,
|
13
|
+
command: command,
|
14
|
+
message: message,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -12,6 +12,7 @@ Rails.backtrace_cleaner.remove_silencers!
|
|
12
12
|
# Load support files
|
13
13
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
14
14
|
|
15
|
+
Dir[Rails.root.join("test/support/*.rb")].each {|f| require f}
|
15
16
|
# Load fixtures from the engine
|
16
17
|
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
17
18
|
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreign_office
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Draut
|
@@ -136,6 +136,8 @@ files:
|
|
136
136
|
- test/dummy/public/500.html
|
137
137
|
- test/dummy/public/favicon.ico
|
138
138
|
- test/foreign_office_test.rb
|
139
|
+
- test/support/pubnub.rb
|
140
|
+
- test/support/pusher.rb
|
139
141
|
- test/test_helper.rb
|
140
142
|
homepage: http://edraut.github.io/foreign-office
|
141
143
|
licenses:
|
@@ -200,4 +202,6 @@ test_files:
|
|
200
202
|
- test/dummy/Rakefile
|
201
203
|
- test/dummy/README.rdoc
|
202
204
|
- test/foreign_office_test.rb
|
205
|
+
- test/support/pubnub.rb
|
206
|
+
- test/support/pusher.rb
|
203
207
|
- test/test_helper.rb
|