bookingsync-engine 0.3.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bookingsync/engine.rb +1 -0
- data/lib/bookingsync/engine/api_client.rb +19 -0
- data/lib/bookingsync/engine/model.rb +9 -5
- data/lib/bookingsync/engine/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +16 -0
- data/spec/dummy/log/test.log +785 -1042
- data/spec/models/account_spec.rb +40 -0
- metadata +8 -5
data/spec/models/account_spec.rb
CHANGED
@@ -59,6 +59,46 @@ RSpec.describe Account, type: :model do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
describe "#token" do
|
63
|
+
let(:expires_at) { 1.day.from_now.to_i }
|
64
|
+
let(:account) { Account.create!(uid: 123, oauth_access_token: "token",
|
65
|
+
oauth_refresh_token: "refresh_token", oauth_expires_at: expires_at) }
|
66
|
+
|
67
|
+
context "when the stored token is fresh" do
|
68
|
+
it "returns the token" do
|
69
|
+
expect(account.token).to be_a OAuth2::AccessToken
|
70
|
+
expect(account.token.token).to eq "token"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when the stored token is expired" do
|
75
|
+
let(:expires_at) { 1.day.ago.to_i.to_s }
|
76
|
+
let(:new_expires_at) { 2.days.from_now.to_i.to_s }
|
77
|
+
let(:token) { double(expired?: true, refresh!: double(token: "refreshed_token",
|
78
|
+
refresh_token: "refreshed_refresh_token", expires_at: new_expires_at)) }
|
79
|
+
let(:client) { double }
|
80
|
+
|
81
|
+
before do
|
82
|
+
expect(BookingSync::Engine).to receive(:oauth_client) { client }
|
83
|
+
expect(OAuth2::AccessToken).to receive(:new).with(client, "token",
|
84
|
+
refresh_token: "refresh_token", expires_at: expires_at) { token }
|
85
|
+
end
|
86
|
+
|
87
|
+
it "refreshes the token" do
|
88
|
+
expect(token).to receive(:refresh!)
|
89
|
+
account.token
|
90
|
+
end
|
91
|
+
|
92
|
+
it "stores the refreshed token" do
|
93
|
+
account.token
|
94
|
+
account.reload
|
95
|
+
expect(account.oauth_access_token).to eq("refreshed_token")
|
96
|
+
expect(account.oauth_refresh_token).to eq("refreshed_refresh_token")
|
97
|
+
expect(account.oauth_expires_at).to eq(new_expires_at)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
62
102
|
describe "#clear_token!" do
|
63
103
|
it "clears token related fields on account" do
|
64
104
|
account = Account.create!(oauth_access_token: "token",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookingsync-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastien Grosjean
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.0.
|
48
|
+
version: 0.0.23
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.0.
|
55
|
+
version: 0.0.23
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: appraisal
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- config/routes.rb
|
153
153
|
- lib/bookingsync.rb
|
154
154
|
- lib/bookingsync/engine.rb
|
155
|
+
- lib/bookingsync/engine/api_client.rb
|
155
156
|
- lib/bookingsync/engine/auth_helpers.rb
|
156
157
|
- lib/bookingsync/engine/helpers.rb
|
157
158
|
- lib/bookingsync/engine/model.rb
|
@@ -196,6 +197,7 @@ files:
|
|
196
197
|
- spec/dummy/db/migrate/20140522110454_add_o_auth_fields_to_accounts.rb
|
197
198
|
- spec/dummy/db/schema.rb
|
198
199
|
- spec/dummy/db/test.sqlite3
|
200
|
+
- spec/dummy/log/development.log
|
199
201
|
- spec/dummy/log/test.log
|
200
202
|
- spec/dummy/public/404.html
|
201
203
|
- spec/dummy/public/422.html
|
@@ -233,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
235
|
version: '0'
|
234
236
|
requirements: []
|
235
237
|
rubyforge_project:
|
236
|
-
rubygems_version: 2.
|
238
|
+
rubygems_version: 2.4.5
|
237
239
|
signing_key:
|
238
240
|
specification_version: 4
|
239
241
|
summary: A Rails engine to simplify integration with BookingSync API
|
@@ -272,6 +274,7 @@ test_files:
|
|
272
274
|
- spec/dummy/db/migrate/20140522110454_add_o_auth_fields_to_accounts.rb
|
273
275
|
- spec/dummy/db/schema.rb
|
274
276
|
- spec/dummy/db/test.sqlite3
|
277
|
+
- spec/dummy/log/development.log
|
275
278
|
- spec/dummy/log/test.log
|
276
279
|
- spec/dummy/public/404.html
|
277
280
|
- spec/dummy/public/422.html
|