centrifuge 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98fe217d5cfae7faea96a53a7639a26b66a48038
4
- data.tar.gz: c4d0450027b408d23bb13da3ccf5400a7939ef6f
3
+ metadata.gz: 36cd65153a6cd85e74497215b746aa5fa47c8bd2
4
+ data.tar.gz: 71079475e325a95aa71ad4d94a1301773dc08322
5
5
  SHA512:
6
- metadata.gz: 15a092b443b206561f95a29c71271391f0258c283f80dd6db23a25518681b01c780cf3c411692884aee6df4a8db3ee9de2470d54d68f160f8607f47beecfd552
7
- data.tar.gz: 2e6d765c38c309bc18bf195c3ee934d7203c1b9494c99a50482b40137a023c3c9e00f169ea33b31fb6321ac1c570adae28f28d9db55c253ce5fd2e852d7b5cd5
6
+ metadata.gz: ad4e4c0843ebe3b2a9d0c5b58d2aa55cc41bf5b89d20021f0a77017d4f4773e62fdb69dc4c13b7267fd0e632a5b823f25922c8a452c3681d9a926bc797056134
7
+ data.tar.gz: 2967bf499ba71414c7542bd3400cd159c81850e25a2be1344c0d1ed5cc8ab3e78f1ecdb6bb79342f5c36e0b80cee75cdb96d0cce61c6f1bd7e70ce8ddf7272b4
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec"
27
- spec.add_development_dependency "guard-rspec"
28
27
  spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "vcr"
29
29
 
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Centrifuge
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -4,38 +4,49 @@ describe Centrifuge::Client do
4
4
  let(:options) { { scheme: :https, host: 'centrifugo.herokuapp.com', port: 443, secret: 'secret' } }
5
5
  let(:client) { Centrifuge::Client.new(options) }
6
6
  let(:data) { { action: :test } }
7
-
8
- it 'generates url' do
9
- expect(client.url.to_s).to eq "https://centrifugo.herokuapp.com:443/api/"
10
- end
11
-
12
- it 'publishes data' do
13
- channel = SecureRandom.hex
14
- expect(client.publish(channel, data)).to eq [{"body" => nil, "error" => nil, "method" => "publish"}]
15
- end
16
-
17
- it 'broadcasts data' do
18
- channel = SecureRandom.hex
19
- channel1 = SecureRandom.hex
20
- expect(client.broadcast([channel, channel1], data)).to eq [{"body" => nil, "error" => nil, "method" => "broadcast"}]
21
- end
22
-
23
- it 'unsubscribes user' do
24
- channel = SecureRandom.hex
25
- expect(client.unsubscribe(channel, "23")).to eq [{"body"=>nil, "error"=>nil, "method"=>"unsubscribe"}]
26
- end
27
-
28
- it 'disconnects user' do
29
- expect(client.disconnect("23")).to eq [{"body" => nil, "error" => nil, "method" => "disconnect"}]
30
- end
31
-
32
- it 'fetches presence info' do
33
- channel = SecureRandom.hex
34
- expect(client.presence(channel)).to eq [{"body" => {"channel" => channel, "data" => {}}, "error" => nil, "method" => "presence"}]
7
+ let(:channel) { 'test_channel' }
8
+
9
+ context 'API calls', :vcr do
10
+ it 'generates url' do
11
+ expect(client.url.to_s).to eq "https://centrifugo.herokuapp.com:443/api/"
12
+ end
13
+
14
+ it 'publishes data' do
15
+ expect(client.publish(channel, data)).to eq [{"body" => nil, "error" => nil, "method" => "publish"}]
16
+ end
17
+
18
+ it 'broadcasts data' do
19
+ channel1 = "#{channel}_1"
20
+ expect(client.broadcast([channel, channel1], data)).to eq [{"body" => nil, "error" => nil, "method" => "broadcast"}]
21
+ end
22
+
23
+ it 'unsubscribes user' do
24
+ expect(client.unsubscribe(channel, "23")).to eq [{"body"=>nil, "error"=>nil, "method"=>"unsubscribe"}]
25
+ end
26
+
27
+ it 'disconnects user' do
28
+ expect(client.disconnect("23")).to eq [{"body" => nil, "error" => nil, "method" => "disconnect"}]
29
+ end
30
+
31
+ it 'fetches presence info' do
32
+ expect(client.presence(channel)).to eq [{"body" => {"channel" => channel, "data" => {}}, "error" => nil, "method" => "presence"}]
33
+ end
34
+
35
+ it 'fetches history' do
36
+ #we do so bcz history request store data on server and test can fall depend on it
37
+ WebMock.allow_net_connect!
38
+ VCR.eject_cassette
39
+ VCR.turned_off do
40
+ channel_history = "#{channel}_#{SecureRandom.hex}"
41
+ expect(client.history(channel_history)).to eq [{"body" => {"channel" => channel_history, "data" => []}, "error" => nil, "method"=>"history"}]
42
+ end
43
+ end
35
44
  end
36
45
 
37
- it 'fetches history' do
38
- channel = SecureRandom.hex
39
- expect(client.history(channel)).to eq [{"body" => {"channel" => channel, "data" => []}, "error" => nil, "method"=>"history"}]
46
+ context 'calculate hash' do
47
+ let(:user) { "test@test.com" }
48
+ let(:timestamp) { "1461702408" }
49
+ let(:result) { client.token_for user, timestamp }
50
+ it { expect(result).to eq 'be26ac57ef264c23662ba373e4b68670c1a006431c763af6d33ad10ab6aa97d9' }
40
51
  end
41
52
  end
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://centrifugo.herokuapp.com/api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: data=%7B%22method%22%3A%22broadcast%22%2C%22params%22%3A%7B%22channels%22%3A%5B%22test_channel%22%2C%22test_channel_1%22%5D%2C%22data%22%3A%7B%22action%22%3A%22test%22%7D%7D%7D&sign=249cbaaa695d6d18a9e781e3fd9ca7e65f38780383a17a8f921d53d6016c631a
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.2.2 (2015-04-13))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Tue, 26 Apr 2016 21:28:15 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Date:
30
+ - Tue, 26 Apr 2016 21:28:16 GMT
31
+ Content-Length:
32
+ - '49'
33
+ Via:
34
+ - 1.1 vegur
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"body":null,"error":null,"method":"broadcast"}]'
38
+ http_version:
39
+ recorded_at: Tue, 26 Apr 2016 21:28:16 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://centrifugo.herokuapp.com/api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: data=%7B%22method%22%3A%22disconnect%22%2C%22params%22%3A%7B%22user%22%3A%2223%22%7D%7D&sign=1c3c7a255a2c1bbf4df7bb8147efca54d065542c13c9559c505841f664c3324d
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.2.2 (2015-04-13))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Tue, 26 Apr 2016 21:28:13 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Date:
30
+ - Tue, 26 Apr 2016 21:28:14 GMT
31
+ Content-Length:
32
+ - '50'
33
+ Via:
34
+ - 1.1 vegur
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"body":null,"error":null,"method":"disconnect"}]'
38
+ http_version:
39
+ recorded_at: Tue, 26 Apr 2016 21:28:14 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://centrifugo.herokuapp.com/api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: data=%7B%22method%22%3A%22history%22%2C%22params%22%3A%7B%22channel%22%3A%22test_channel%22%7D%7D&sign=b84aa6df4715845e6a536f14d241a33c8347a4fb1f74ba0eef96e00fb66f36c5
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.2.2 (2015-04-13))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Tue, 26 Apr 2016 21:28:14 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Date:
30
+ - Tue, 26 Apr 2016 21:28:14 GMT
31
+ Content-Length:
32
+ - '79'
33
+ Via:
34
+ - 1.1 vegur
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"body":{"channel":"test_channel","data":[]},"error":null,"method":"history"}]'
38
+ http_version:
39
+ recorded_at: Tue, 26 Apr 2016 21:28:15 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://centrifugo.herokuapp.com/api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: data=%7B%22method%22%3A%22presence%22%2C%22params%22%3A%7B%22channel%22%3A%22test_channel%22%7D%7D&sign=c25781e7d8f066d7410c3a493baf27371267a366c7a07a42bc42169fbed2d26a
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.2.2 (2015-04-13))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Tue, 26 Apr 2016 21:28:15 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Date:
30
+ - Tue, 26 Apr 2016 21:28:15 GMT
31
+ Content-Length:
32
+ - '80'
33
+ Via:
34
+ - 1.1 vegur
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"body":{"channel":"test_channel","data":{}},"error":null,"method":"presence"}]'
38
+ http_version:
39
+ recorded_at: Tue, 26 Apr 2016 21:28:15 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://centrifugo.herokuapp.com/api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: data=%7B%22method%22%3A%22publish%22%2C%22params%22%3A%7B%22channel%22%3A%22test_channel%22%2C%22data%22%3A%7B%22action%22%3A%22test%22%7D%7D%7D&sign=9613e1a01f65fa86e6d8ecefe02637eb2d10c4a36658182b9d77417cd720a7e2
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.2.2 (2015-04-13))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Tue, 26 Apr 2016 21:28:15 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Date:
30
+ - Tue, 26 Apr 2016 21:28:15 GMT
31
+ Content-Length:
32
+ - '47'
33
+ Via:
34
+ - 1.1 vegur
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"body":null,"error":null,"method":"publish"}]'
38
+ http_version:
39
+ recorded_at: Tue, 26 Apr 2016 21:28:15 GMT
40
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://centrifugo.herokuapp.com/api/
6
+ body:
7
+ encoding: UTF-8
8
+ string: data=%7B%22method%22%3A%22unsubscribe%22%2C%22params%22%3A%7B%22channel%22%3A%22test_channel%22%2C%22user%22%3A%2223%22%7D%7D&sign=64dfcdb9f9daca42f409dbe791b990f0e8ab9c9e92a8b10daded5701355b7bcc
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.8.0, ruby 2.2.2 (2015-04-13))
12
+ Accept:
13
+ - "*/*"
14
+ Date:
15
+ - Tue, 26 Apr 2016 21:28:16 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Date:
30
+ - Tue, 26 Apr 2016 21:28:16 GMT
31
+ Content-Length:
32
+ - '51'
33
+ Via:
34
+ - 1.1 vegur
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"body":null,"error":null,"method":"unsubscribe"}]'
38
+ http_version:
39
+ recorded_at: Tue, 26 Apr 2016 21:28:16 GMT
40
+ recorded_with: VCR 3.0.1
@@ -1,98 +1,33 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
5
- #
6
- # Given that it is always loaded, you are encouraged to keep this file as
7
- # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # will add to the boot time of your test suite on EVERY test run, even for an
9
- # individual file that may not need all of that loaded. Instead, consider making
10
- # a separate helper file that requires the additional dependencies and performs
11
- # the additional setup, and require it from the spec files that actually need it.
12
- #
13
- # The `.rspec` file also contains a few flags that are not defaults but that
14
- # users commonly want.
15
1
  require 'bundler/setup'
16
2
  Bundler.setup
17
3
  require 'centrifuge'
18
4
  require 'rspec'
19
- # require 'webmock/rspec'
20
- #
21
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
5
+ require 'vcr'
6
+
22
7
  RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
8
  config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
9
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
10
  end
36
11
 
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = File.expand_path "../fixtures/vcr_cassettes", __FILE__
14
+ config.hook_into :webmock
15
+ config.configure_rspec_metadata!
16
+ config.default_cassette_options = { :record => :new_episodes }
44
17
  end
45
18
 
46
- # config.before(:each) do
47
- # WebMock.reset!
48
- # WebMock.disable_net_connect!
49
- # end
50
-
51
- # The settings below are suggested to provide a good initial experience
52
- # with RSpec, but feel free to customize to your heart's content.
53
-
54
- # These two settings work together to allow you to limit a spec run
55
- # to individual examples or groups you care about by tagging them with
56
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
57
- # get run.
58
- # config.filter_run :focus
59
- # config.run_all_when_everything_filtered = true
60
19
 
61
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
62
- # For more details, see:
63
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
66
- # config.disable_monkey_patching!
20
+ config.mock_with :rspec do |mocks|
21
+ mocks.verify_partial_doubles = true
22
+ end
67
23
 
68
- # This setting enables warnings. It's recommended, but in some cases may
69
- # be too noisy due to issues in dependencies.
70
24
  config.warnings = false
71
25
 
72
- # Many RSpec users commonly either run the entire suite or an individual
73
- # file, and it's useful to allow more verbose output when running an
74
- # individual spec file.
75
26
  if config.files_to_run.one?
76
- # Use the documentation formatter for detailed output,
77
- # unless a formatter has already been configured
78
- # (e.g. via a command-line flag).
79
27
  config.default_formatter = 'doc'
80
28
  end
81
29
 
82
- # Print the 10 slowest examples and example groups at the
83
- # end of the spec run, to help surface which specs are running
84
- # particularly slow.
85
30
  config.profile_examples = 10
86
-
87
- # Run specs in random order to surface order dependencies. If you find an
88
- # order dependency and want to debug it, you can fix the order by providing
89
- # the seed, which is printed after each run.
90
- # --seed 1234
91
31
  config.order = :random
92
-
93
- # Seed global randomization in this process using the `--seed` CLI option.
94
- # Setting this allows you to use `--seed` to deterministically reproduce
95
- # test failures related to randomization by passing the same `--seed` value
96
- # as the one that triggered the failure.
97
32
  Kernel.srand config.seed
98
33
  end