pusher-fake 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pusher-fake.rb +1 -1
  3. data/lib/pusher-fake/configuration.rb +2 -1
  4. data/lib/pusher-fake/server/application.rb +1 -1
  5. data/spec/features/api/channels_spec.rb +82 -0
  6. data/spec/features/api/users_spec.rb +34 -0
  7. data/spec/features/client/connect_spec.rb +9 -0
  8. data/spec/features/client/event_spec.rb +45 -0
  9. data/spec/features/client/presence_spec.rb +56 -0
  10. data/spec/features/client/subscribe_spec.rb +61 -0
  11. data/spec/features/server/event_spec.rb +120 -0
  12. data/spec/features/server/webhooks_spec.rb +64 -0
  13. data/spec/lib/pusher-fake/channel/presence_spec.rb +36 -30
  14. data/spec/lib/pusher-fake/channel/private_spec.rb +29 -25
  15. data/spec/lib/pusher-fake/channel/public_spec.rb +18 -18
  16. data/spec/lib/pusher-fake/channel_spec.rb +14 -14
  17. data/spec/lib/pusher-fake/configuration_spec.rb +6 -0
  18. data/spec/lib/pusher-fake/connection_spec.rb +38 -36
  19. data/spec/lib/pusher-fake/server/application_spec.rb +70 -70
  20. data/spec/lib/pusher-fake/server_spec.rb +42 -41
  21. data/spec/lib/pusher-fake/webhook_spec.rb +9 -7
  22. data/spec/lib/pusher_fake_spec.rb +5 -4
  23. data/spec/spec_helper.rb +3 -1
  24. data/{features → spec}/support/application.rb +0 -0
  25. data/{features/support/application/public/javascripts/vendor/pusher-2.2.2.js → spec/support/application/public/javascripts/vendor/pusher-2.2.4.js} +26 -19
  26. data/spec/support/application/views/index.erb +83 -0
  27. data/spec/support/capybara.rb +10 -0
  28. data/spec/support/coveralls.rb +0 -1
  29. data/spec/support/helpers/connect.rb +21 -0
  30. data/spec/support/helpers/event.rb +9 -0
  31. data/spec/support/helpers/subscription.rb +29 -0
  32. data/spec/support/helpers/user.rb +11 -0
  33. data/spec/support/{have_configuration_option_matcher.rb → matchers/have_configuration_option.rb} +0 -0
  34. data/spec/support/pusher-fake.rb +15 -0
  35. data/{features → spec}/support/webhooks.rb +5 -1
  36. metadata +51 -101
  37. data/features/channel.feature +0 -109
  38. data/features/channel_presence.feature +0 -27
  39. data/features/channel_subscribe.feature +0 -33
  40. data/features/channel_trigger.feature +0 -91
  41. data/features/channel_webhooks.feature +0 -40
  42. data/features/client_connect.feature +0 -8
  43. data/features/step_definitions/api_steps.rb +0 -40
  44. data/features/step_definitions/channel_steps.rb +0 -86
  45. data/features/step_definitions/client_steps.rb +0 -23
  46. data/features/step_definitions/event_steps.rb +0 -56
  47. data/features/step_definitions/navigation_steps.rb +0 -3
  48. data/features/step_definitions/presence_steps.rb +0 -6
  49. data/features/step_definitions/webhook_steps.rb +0 -21
  50. data/features/support/application/views/index.erb +0 -35
  51. data/features/support/coveralls.rb +0 -1
  52. data/features/support/environment.rb +0 -13
  53. data/features/support/pusher-fake.rb +0 -11
  54. data/features/support/timing.rb +0 -15
  55. data/features/user.feature +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3f79253d72f830d37f4a25a95b9bde1d58cdb19
4
- data.tar.gz: fa1401d5a24e2d49f2ed0b89cd02b663e5dd0361
3
+ metadata.gz: e6cba6ba2781f922d0e29bcb41add3f6a3a03595
4
+ data.tar.gz: 30198ebca214e71b377562aec841ce4aa80ee71d
5
5
  SHA512:
6
- metadata.gz: 4b629399e6094408686c54492d02e40a19a5331f85057a97146fe879e88d6f3f44812e0d334dd759bd33051a0495c55cecae80ae150710ffe0d30516f0e56425
7
- data.tar.gz: e9a65e650f03408fe170c9d88fac0cfa05b8061ade712812304ddabe270c9853fedf63a3a960ac879e2cae5dd41f530a8487ca6c828147fc09dc49fe0696de1c
6
+ metadata.gz: 75903dbd7cd960d3d762934dea6395dbfd9cfb8e4b201cf7c989e58ee58f9bf98a691371f5922286a2994dc63141e6261ad1dab4615ed75f59c9e5e7c1f9b219
7
+ data.tar.gz: 3f9628b6a3ec64220c88fd48afb487c83e5191c8a1643a2ca97b6200f6071aa7f90f1507abeea48c43b2d71aa1ccf5e8add5cb1ba9e9483a6b3d127d8f22e47f
@@ -6,7 +6,7 @@ require "thin"
6
6
 
7
7
  module PusherFake
8
8
  # The current version string.
9
- VERSION = "1.2.0"
9
+ VERSION = "1.3.0"
10
10
 
11
11
  autoload :Channel, "pusher-fake/channel"
12
12
  autoload :Configuration, "pusher-fake/configuration"
@@ -47,7 +47,8 @@ module PusherFake
47
47
  def to_options(options = {})
48
48
  options.merge(
49
49
  wsHost: socket_options[:host],
50
- wsPort: socket_options[:port]
50
+ wsPort: socket_options[:port],
51
+ enabledTransports: ["ws"]
51
52
  )
52
53
  end
53
54
 
@@ -59,7 +59,7 @@ module PusherFake
59
59
  # presence channels.
60
60
  #
61
61
  # @param [String] name The channel name.
62
- # @params [Rack::Request] request The HTTP request.
62
+ # @param [Rack::Request] request The HTTP request.
63
63
  # @return [Hash] A hash of channel information.
64
64
  def self.channel(name, request)
65
65
  info = request.params["info"].to_s.split(",")
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ feature "Requesting channel API endpoint" do
4
+ let(:channel_name) { "public-1" }
5
+ let(:presence_name) { "presence-example" }
6
+
7
+ before do
8
+ connect
9
+ end
10
+
11
+ scenario "all channels, with none created" do
12
+ expect(channels).to be_empty
13
+ end
14
+
15
+ scenario "all channels, with one created" do
16
+ subscribe_to(channel_name)
17
+
18
+ expect(channels).to have_key(channel_name)
19
+ end
20
+
21
+ scenario "all channels, with a filter" do
22
+ subscribe_to("other")
23
+ subscribe_to(channel_name)
24
+
25
+ result = channels(filter_by_prefix: "pu")
26
+
27
+ expect(result.size).to eq(1)
28
+ expect(result).to have_key(channel_name)
29
+ end
30
+
31
+ scenario "all channels, with info attributes" do
32
+ subscribe_to(presence_name)
33
+
34
+ result = channels(filter_by_prefix: "presence-", info: "user_count")
35
+
36
+ expect(result.size).to eq(1)
37
+ expect(result).to have_key(presence_name)
38
+ expect(result[presence_name]).to have_key("user_count")
39
+ expect(result[presence_name]["user_count"]).to eq(1)
40
+ end
41
+
42
+ scenario "all channels, with invalid info attributes" do
43
+ expect {
44
+ channels(info: "user_count")
45
+ }.to raise_error(/user_count may only be requested for presence channels/)
46
+ end
47
+
48
+ scenario "channel, with no occupants" do
49
+ expect(channel[:occupied]).to eq(false)
50
+ end
51
+
52
+ scenario "channel, with an occupant" do
53
+ subscribe_to(channel_name)
54
+
55
+ expect(channel[:occupied]).to eq(true)
56
+ end
57
+
58
+ scenario "channel, with info attributes" do
59
+ subscribe_to(presence_name)
60
+
61
+ result = Pusher.get("/channels/#{presence_name}", info: "user_count")
62
+
63
+ expect(result[:occupied]).to eq(true)
64
+ expect(result[:user_count]).to eq(1)
65
+ end
66
+
67
+ scenario "channel, with invalid info attributes" do
68
+ expect {
69
+ channel(info: "user_count")
70
+ }.to raise_error(/Cannot retrieve the user count unless the channel is a presence channel/)
71
+ end
72
+
73
+ protected
74
+
75
+ def channel(options = {})
76
+ Pusher.get("/channels/#{channel_name}", options)
77
+ end
78
+
79
+ def channels(options = {})
80
+ Pusher.get("/channels", options)[:channels]
81
+ end
82
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ feature "Requesting user API endpoint" do
4
+ let(:users) { Pusher.get("/channels/#{channel_name}/users")[:users] }
5
+ let(:channel_name) { "public-1" }
6
+
7
+ before do
8
+ connect
9
+ connect_as "Bob"
10
+ end
11
+
12
+ scenario "with no users subscribed" do
13
+ expect(users).to be_empty
14
+ end
15
+
16
+ scenario "with a single user subscribed" do
17
+ subscribe_to(channel_name)
18
+
19
+ expect(users.size).to eq(1)
20
+ end
21
+
22
+ scenario "with a multiple users subscribed" do
23
+ subscribe_to(channel_name)
24
+ subscribe_to_as(channel_name, "Bob")
25
+
26
+ ids = PusherFake::Channel.channels[channel_name].connections.map(&:id)
27
+
28
+ expect(users.size).to eq(2)
29
+
30
+ users.each do |user|
31
+ expect(ids).to include(user["id"])
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ feature "Client connecting to the server" do
4
+ scenario "successfully connects" do
5
+ visit "/"
6
+
7
+ expect(page).to have_content("Client connected.")
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ feature "Client triggers a client event" do
4
+ let(:event) { "client-message" }
5
+ let(:other_user) { "Bob" }
6
+ let(:public_channel) { "chat" }
7
+ let(:private_channel) { "private-chat" }
8
+
9
+ before do
10
+ connect
11
+ connect_as(other_user)
12
+ end
13
+
14
+ scenario "on a subscribed private channel" do
15
+ subscribe_to(private_channel)
16
+ subscribe_to_as(private_channel, other_user)
17
+
18
+ trigger(private_channel, event)
19
+
20
+ expect(page).to_not have_event(event, on: private_channel)
21
+
22
+ using_session(other_user) do
23
+ expect(page).to have_event(event, on: private_channel)
24
+ end
25
+ end
26
+
27
+ scenario "on a subscribed public channel" do
28
+ subscribe_to(public_channel)
29
+ subscribe_to_as(public_channel, other_user)
30
+
31
+ trigger(public_channel, event)
32
+
33
+ expect(page).to_not have_event(event, on: public_channel)
34
+
35
+ using_session(other_user) do
36
+ expect(page).to_not have_event(event, on: public_channel)
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ def trigger(channel, event)
43
+ page.execute_script("Helpers.trigger(#{MultiJson.dump(channel)}, #{MultiJson.dump(event)})")
44
+ end
45
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ feature "Client on a presence channel" do
4
+ let(:other_user) { "Bob" }
5
+
6
+ before do
7
+ connect
8
+ end
9
+
10
+ scenario "subscribing to a presence channel" do
11
+ subscribe_to("presence-game-1")
12
+
13
+ expect(page).to have_clients(1, in: "presence-game-1")
14
+ end
15
+
16
+ scenario "subscribing to a presence channel, with existing users" do
17
+ connect_as(other_user, channel: "presence-game-1")
18
+
19
+ subscribe_to("presence-game-1")
20
+
21
+ expect(page).to have_clients(2, in: "presence-game-1", named: "Alan Turing")
22
+ end
23
+
24
+ scenario "member entering notification" do
25
+ subscribe_to("presence-game-1")
26
+
27
+ connect_as(other_user, channel: "presence-game-1")
28
+
29
+ expect(page).to have_clients(2, in: "presence-game-1")
30
+ end
31
+
32
+ scenario "member leaving notification" do
33
+ connect_as(other_user, channel: "presence-game-1")
34
+ subscribe_to("presence-game-1")
35
+
36
+ expect(page).to have_clients(2, in: "presence-game-1")
37
+
38
+ unsubscribe_from_as("presence-game-1", other_user)
39
+
40
+ expect(page).to have_clients(1, in: "presence-game-1")
41
+ end
42
+
43
+ scenario "other client connecting" do
44
+ subscribe_to("presence-game-1")
45
+
46
+ connect_as(other_user)
47
+
48
+ expect(page).to have_clients(1, in: "presence-game-1")
49
+ end
50
+
51
+ protected
52
+
53
+ def have_clients(count, options = {})
54
+ have_css("li.channel-#{options[:in]}", count: count, text: options[:named])
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+
3
+ feature "Client subscribing to a channel" do
4
+ before do
5
+ visit "/"
6
+
7
+ expect(page).to have_content("Client connected.")
8
+ end
9
+
10
+ scenario "successfully subscribes to a channel" do
11
+ subscribe_to("chat-message")
12
+
13
+ expect(page).to have_content("Subscribed to chat-message.")
14
+ end
15
+
16
+ scenario "successfully subscribes to multiple channel" do
17
+ subscribe_to("chat-enter")
18
+ subscribe_to("chat-exit")
19
+
20
+ expect(page).to have_content("Subscribed to chat-enter.")
21
+ expect(page).to have_content("Subscribed to chat-exit.")
22
+ end
23
+
24
+ scenario "successfully subscribes to a private channel" do
25
+ subscribe_to("private-message-bob")
26
+
27
+ expect(page).to have_content("Subscribed to private-message-bob.")
28
+ end
29
+
30
+ scenario "successfully subscribes to a presence channel" do
31
+ subscribe_to("presence-game-1")
32
+
33
+ expect(page).to have_content("Subscribed to presence-game-1.")
34
+ end
35
+
36
+ scenario "unsuccessfully subscribes to a private channel" do
37
+ set_socket_id(-1)
38
+
39
+ attempt_to_subscribe_to("private-message-bob")
40
+
41
+ expect(page).to_not have_content("Subscribed to private-message-bob.")
42
+ end
43
+
44
+ scenario "unsuccessfully subscribes to a presence channel" do
45
+ set_socket_id(-1)
46
+
47
+ attempt_to_subscribe_to("presence-game-1")
48
+
49
+ expect(page).to_not have_content("Subscribed to presence-game-1.")
50
+ end
51
+
52
+ protected
53
+
54
+ def attempt_to_subscribe_to(channel)
55
+ page.execute_script("Helpers.subscribe(#{MultiJson.dump(channel)})")
56
+ end
57
+
58
+ def set_socket_id(value)
59
+ page.execute_script("Pusher.instance.connection.socket_id = #{MultiJson.dump(value)};")
60
+ end
61
+ end
@@ -0,0 +1,120 @@
1
+ require "spec_helper"
2
+
3
+ feature "Server triggers event" do
4
+ let(:event) { "message" }
5
+ let(:other_user) { "Bob" }
6
+ let(:public_channel) { "chat" }
7
+ let(:private_channel) { "private-chat" }
8
+
9
+ before do
10
+ connect
11
+ connect_as(other_user)
12
+ end
13
+
14
+ scenario "on a subscribed public channel" do
15
+ subscribe_to(public_channel)
16
+ subscribe_to_as(public_channel, other_user)
17
+
18
+ trigger(public_channel, event)
19
+
20
+ expect(page).to have_event(event, on: public_channel)
21
+
22
+ using_session(other_user) do
23
+ expect(page).to have_event(event, on: public_channel)
24
+ end
25
+ end
26
+
27
+ scenario "on a previously subscribed public channel" do
28
+ subscribe_to(public_channel)
29
+ subscribe_to_as(public_channel, other_user)
30
+ unsubscribe_from(public_channel)
31
+
32
+ trigger(public_channel, event)
33
+
34
+ expect(page).to_not have_event(event, on: public_channel)
35
+
36
+ using_session(other_user) do
37
+ expect(page).to have_event(event, on: public_channel)
38
+ end
39
+ end
40
+
41
+ scenario "on an unsubscribed public channel" do
42
+ trigger(public_channel, event)
43
+
44
+ expect(page).to_not have_event(event, on: public_channel)
45
+
46
+ using_session(other_user) do
47
+ expect(page).to_not have_event(event, on: public_channel)
48
+ end
49
+ end
50
+
51
+ scenario "on a subscribed private channel" do
52
+ subscribe_to(private_channel)
53
+ subscribe_to_as(private_channel, other_user)
54
+
55
+ trigger(private_channel, event)
56
+
57
+ expect(page).to have_event(event, on: private_channel)
58
+
59
+ using_session(other_user) do
60
+ expect(page).to have_event(event, on: private_channel)
61
+ end
62
+ end
63
+
64
+ scenario "on a previously subscribed private channel" do
65
+ subscribe_to(private_channel)
66
+ subscribe_to_as(private_channel, other_user)
67
+ unsubscribe_from(private_channel)
68
+
69
+ trigger(private_channel, event)
70
+
71
+ expect(page).to_not have_event(event, on: private_channel)
72
+
73
+ using_session(other_user) do
74
+ expect(page).to have_event(event, on: private_channel)
75
+ end
76
+ end
77
+
78
+ scenario "on an unsubscribed private channel" do
79
+ trigger(private_channel, event)
80
+
81
+ expect(page).to_not have_event(event, on: private_channel)
82
+
83
+ using_session(other_user) do
84
+ expect(page).to_not have_event(event, on: private_channel)
85
+ end
86
+ end
87
+
88
+ scenario "on multiple subscribed private channels" do
89
+ subscribe_to("private-chat-1")
90
+ subscribe_to_as("private-chat-2", other_user)
91
+
92
+ trigger("private-chat-1", event)
93
+ trigger("private-chat-2", event)
94
+
95
+ expect(page).to have_event(event, on: "private-chat-1")
96
+
97
+ using_session(other_user) do
98
+ expect(page).to have_event(event, on: "private-chat-2")
99
+ end
100
+ end
101
+
102
+ scenario "on a subscribed public channel, ignoring a user" do
103
+ subscribe_to(public_channel)
104
+ subscribe_to_as(public_channel, other_user)
105
+
106
+ trigger(public_channel, event, socket_id: user_id(other_user))
107
+
108
+ expect(page).to have_event(event, on: public_channel)
109
+
110
+ using_session(other_user) do
111
+ expect(page).to_not have_event(event, on: public_channel)
112
+ end
113
+ end
114
+
115
+ protected
116
+
117
+ def trigger(channel, event, options = {})
118
+ Pusher.trigger(channel, event, {}, options)
119
+ end
120
+ end