Skip to content

Commit

Permalink
Fix default callback and http_sync (#136)
Browse files Browse the repository at this point in the history
fix(events): fix default `callback` and `http_sync`

Fix issue because of which `callback` and `http_sync` provided during client configuration not
used when missing in method call.
  • Loading branch information
parfeon authored Oct 26, 2022
1 parent f80d58a commit 4414f40
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/commands-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Checkout release actions
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: pubnub/client-engineering-deployment-tools
ref: v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
if: ${{ needs.check-release.outputs.release == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# This should be the same as the one specified for on.pull_request.branches
ref: master
- name: Checkout actions
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: pubnub/client-engineering-deployment-tools
ref: v1
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run_acceptance_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Checkout mock-server action
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: pubnub/client-engineering-deployment-tools
ref: github-actions
ref: v1
token: ${{ secrets.GH_TOKEN }}
path: client-engineering-deployment-tools
- name: Run mock server action
Expand All @@ -36,7 +36,7 @@ jobs:
jrm ./main.xml "./main/**/*.xml" &&
jrm ./beta.xml "./beta/**/*.xml"
- name: Expose main report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: always()
with:
name: acceptance-test-reports
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-pubnub-yml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Validate PubNub yml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
with:
Expand Down
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
version: "5.1.0"
version: "5.1.1"
changelog:
- date: 2022-10-26
version: v5.1.1
changes:
- type: bug
text: "Fix issue because of which `callback` and `http_sync` provided during client configuration not used when missing in method call."
- date: 2022-07-26
version: v5.1.0
changes:
Expand Down Expand Up @@ -632,7 +637,7 @@ sdks:
- x86-64
- distribution-type: package
distribution-repository: RubyGems
package-name: pubnub-5.1.0.gem
package-name: pubnub-5.1.1.gem
location: https://rubygems.org/gems/pubnub
requires:
- name: addressable
Expand Down Expand Up @@ -737,8 +742,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub-5.1.0.gem
location: https://github.com/pubnub/ruby/releases/download/v5.1.0/pubnub-5.1.0.gem
package-name: pubnub-5.1.1.gem
location: https://github.com/pubnub/ruby/releases/download/v5.1.1/pubnub-5.1.1.gem
requires:
- name: addressable
min-version: 2.0.0
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 2.7.6
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v5.1.1
October 26 2022

#### Fixed
- Fix issue because of which `callback` and `http_sync` provided during client configuration not used when missing in method call.

## v5.1.0
July 26 2022

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pubnub (5.1.0)
pubnub (5.1.1)
addressable (>= 2.0.0)
concurrent-ruby (~> 1.1.5)
concurrent-ruby-edge (~> 0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
5.1.1
4 changes: 3 additions & 1 deletion lib/pubnub/client/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ module Events
EVENTS.each do |event_name|
define_method event_name do |options = {}, &block|
options[:callback] = block if options[:callback].nil?
# Use constructor-provided :callback if nothing passed to method call.
options[:callback] = self.env[:callback] if options[:callback].nil?
event = Pubnub.const_get(
Formatter.classify_method(event_name)
).new(options, self)

if options[:http_sync]
if event.sync?
event.fire
elsif event.is_a? SubscribeEvent
@subscriber.add_subscription(event)
Expand Down
2 changes: 1 addition & 1 deletion lib/pubnub/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Toplevel Pubnub module.
module Pubnub
VERSION = '5.1.0'.freeze
VERSION = '5.1.1'.freeze
end
26 changes: 26 additions & 0 deletions spec/examples/where_now_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
describe Pubnub::WhereNow do
around :each do |example|
@fired = false
@defaultFired = false

@callback = -> (_envelope) do
@fired = true
end

@defaultCallback = -> (_envelope) do
@defaultFired = true
end

@pubnub = Pubnub.new(
publish_key: "pub-a-mock-key",
subscribe_key: "sub-a-mock-key",
user_id: "ruby-test-uuid-client-one",
auth_key: "ruby-test-auth-client-one",
http_sync: true,
callback: @defaultCallback
)

example.run_with_retry retry: 10
Expand Down Expand Up @@ -55,6 +62,25 @@
envelope = @pubnub.where_now(uuid: "ruby-test-uuid", http_sync: true, callback: @callback)
expect(envelope.is_a?(Pubnub::Envelope)).to eq true
expect(envelope.error?).to eq false
expect(@defaultFired).to eq false

expect(envelope.status[:code]).to eq(200)
expect(envelope.status[:category]).to eq(:ack)
expect(envelope.status[:config]).to eq({:tls => false, :uuid => "ruby-test-uuid-client-one", :auth_key => "ruby-test-auth-client-one", :origin => "ps.pndsn.com"})

expect(envelope.result[:code]).to eq(200)
expect(envelope.result[:operation]).to eq(:where_now)
expect(envelope.result[:data]).to eq({"channels" => []})
end
end

it "__uuid___ruby-test-uuid____http_sync__default___callback___default_" do
VCR.use_cassette("examples/where_now/4", record: :none) do
envelope = @pubnub.where_now(uuid: "ruby-test-uuid")
expect(envelope.is_a?(Pubnub::Envelope)).to eq true
expect(envelope.error?).to eq false
expect(@defaultFired).to eq true
expect(@fired).to eq false

expect(envelope.status[:code]).to eq(200)
expect(envelope.status[:category]).to eq(:ack)
Expand Down

0 comments on commit 4414f40

Please sign in to comment.