omniauth-applicaster 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/lib/applicaster/test.rb +18 -0
- data/lib/applicaster/test/accounts/mock_data.rb +19 -0
- data/lib/applicaster/test/accounts/web_mock_helper.rb +54 -0
- data/lib/omniauth-applicaster.rb +1 -0
- data/lib/omniauth-applicaster/version.rb +1 -1
- data/spec/lib/applicaster/test/accounts/mock_data_spec.rb +20 -0
- data/spec/lib/applicaster/test/accounts/webmock_helper_spec.rb +11 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e551c14cc83eda398d5b50f875d69449addcb08d
|
4
|
+
data.tar.gz: 527028283f9b204b66e53925d91350ead8c19cec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e65beba13fd06bea78988069a4cbaf872a492da5941cbda4ea52795e6c95717378bd1895a096b2c338fdba1962c7ffd86d641cfe3f29e3ba13a4dcec17be3ae
|
7
|
+
data.tar.gz: 06349a9fab30e5a1a31fdbacd10f338534fd39343c9e834ece3f22126ea7361b55ddf7c1cc2191ca9935e2d3e3dfd5d8563170cc5a5f5ab8be81d8a370a67c8f
|
data/README.md
CHANGED
@@ -111,6 +111,31 @@ accounts = Applicaster::Accounts.accounts_from_token(access_token)
|
|
111
111
|
# accounts is an array of `Applicaster::Accounts::User` objects
|
112
112
|
```
|
113
113
|
|
114
|
+
|
115
|
+
### Testing your app
|
116
|
+
|
117
|
+
The library contains helpers to make functional tests easier
|
118
|
+
|
119
|
+
In `spec/spec_helper.rb` add:
|
120
|
+
```ruby
|
121
|
+
RSpec.configure do |config|
|
122
|
+
config.include Applicaster::Test::Accounts::WebMockHelper
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
You can use `accounts_mock_data` to access the fake data, for example:
|
127
|
+
`accounts_mock_data.all_accounts_attributes.first`
|
128
|
+
|
129
|
+
in example groups that use the client_credentials flow use:
|
130
|
+
```ruby
|
131
|
+
before do
|
132
|
+
stub_client_credentials_request
|
133
|
+
stub_accounts_index_response(token: client_credentials_token)
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
|
114
139
|
## Contributing
|
115
140
|
|
116
141
|
1. Fork it ( https://github.com/[my-github-username]/omniauth-applicaster/fork )
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Applicaster
|
2
|
+
module Test
|
3
|
+
module Accounts
|
4
|
+
autoload :MockData, "applicaster/test/accounts/mock_data"
|
5
|
+
autoload :WebMockHelper, "applicaster/test/accounts/web_mock_helper"
|
6
|
+
end
|
7
|
+
|
8
|
+
module_function
|
9
|
+
def inc_sequence
|
10
|
+
@sequence ||= 0
|
11
|
+
@sequence += 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_object_id(sequence = inc_sequence)
|
15
|
+
sprintf("11223344%016d", sequence)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Applicaster
|
2
|
+
module Test
|
3
|
+
module Accounts
|
4
|
+
class MockData
|
5
|
+
def all_accounts_attributes
|
6
|
+
@all_accounts_attributes ||= (1..2).map do |i|
|
7
|
+
sequence = Test.inc_sequence
|
8
|
+
id = Test.generate_object_id(sequence)
|
9
|
+
{
|
10
|
+
id: id,
|
11
|
+
name: "Test Account #{sequence}",
|
12
|
+
old_id: id,
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
begin
|
2
|
+
require "webmock/rspec"
|
3
|
+
rescue NameError
|
4
|
+
warn "webmock is not installed."
|
5
|
+
warn "Applicaster::Test::Accounts::WebMockHelper uses webmock to setup stubs."
|
6
|
+
end
|
7
|
+
|
8
|
+
module Applicaster
|
9
|
+
module Test
|
10
|
+
module Accounts
|
11
|
+
module WebMockHelper
|
12
|
+
def stub_accounts_index_response(options = {})
|
13
|
+
accounts = options[:accounts] || accounts_mock_data.all_accounts_attributes
|
14
|
+
|
15
|
+
stub_request(:get, accounts_base_url.join("/api/v1/accounts.json"))
|
16
|
+
.with(query: { access_token: options[:token] })
|
17
|
+
.to_return(successful_json_response(accounts))
|
18
|
+
end
|
19
|
+
|
20
|
+
def stub_client_credentials_request
|
21
|
+
url = accounts_base_url.join("/oauth/token")
|
22
|
+
url.user = Applicaster::Accounts.config.client_id
|
23
|
+
url.password = Applicaster::Accounts.config.client_secret
|
24
|
+
|
25
|
+
stub_request(:post, url)
|
26
|
+
.with(body: { "grant_type" => "client_credentials" })
|
27
|
+
.to_return(successful_json_response(access_token: client_credentials_token))
|
28
|
+
end
|
29
|
+
|
30
|
+
def accounts_mock_data
|
31
|
+
@accounts_mock_data ||= Test::Accounts::MockData.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def client_credentials_token
|
35
|
+
"client-credentials-token"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def successful_json_response(body)
|
41
|
+
{
|
42
|
+
status: 200,
|
43
|
+
body: body.to_json,
|
44
|
+
headers: { "Content-Type" => "application/json" },
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def accounts_base_url
|
49
|
+
Addressable::URI.parse(Applicaster::Accounts.config.base_url)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/omniauth-applicaster.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Applicaster::Test::Accounts::MockData do
|
4
|
+
subject(:mock_data) { described_class.new }
|
5
|
+
|
6
|
+
describe "#all_accounts_attributes" do
|
7
|
+
it "has 2 elements" do
|
8
|
+
expect(mock_data.all_accounts_attributes.size).to eq(2)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "returned account" do
|
12
|
+
subject(:account) { mock_data.all_accounts_attributes.first }
|
13
|
+
let(:id_regexp) { /^11223344\d{16}$/ }
|
14
|
+
|
15
|
+
it { is_expected.to include(id: id_regexp) }
|
16
|
+
it { is_expected.to include(old_id: id_regexp) }
|
17
|
+
it { is_expected.to include(name: /Test Account \d+/) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Applicaster::Test::Accounts::WebMockHelper do
|
4
|
+
let(:including_class) { Class.new { include(Applicaster::Test::Accounts::WebMockHelper) } }
|
5
|
+
subject(:instace) { including_class.new }
|
6
|
+
|
7
|
+
it { is_expected.to respond_to(:stub_accounts_index_response) }
|
8
|
+
it { is_expected.to respond_to(:stub_client_credentials_request) }
|
9
|
+
it { is_expected.to respond_to(:accounts_mock_data) }
|
10
|
+
it { is_expected.to respond_to(:client_credentials_token) }
|
11
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-applicaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neer Friedman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,6 +142,9 @@ files:
|
|
142
142
|
- lib/applicaster/accounts/user.rb
|
143
143
|
- lib/applicaster/auth_helpers.rb
|
144
144
|
- lib/applicaster/sessions_controller_mixin.rb
|
145
|
+
- lib/applicaster/test.rb
|
146
|
+
- lib/applicaster/test/accounts/mock_data.rb
|
147
|
+
- lib/applicaster/test/accounts/web_mock_helper.rb
|
145
148
|
- lib/omniauth-applicaster.rb
|
146
149
|
- lib/omniauth-applicaster/version.rb
|
147
150
|
- lib/omniauth/strategies/applicaster.rb
|
@@ -150,6 +153,8 @@ files:
|
|
150
153
|
- spec/lib/applicaster/accounts/configuration_spec.rb
|
151
154
|
- spec/lib/applicaster/accounts_spec.rb
|
152
155
|
- spec/lib/applicaster/auth_helpers_spec.rb
|
156
|
+
- spec/lib/applicaster/test/accounts/mock_data_spec.rb
|
157
|
+
- spec/lib/applicaster/test/accounts/webmock_helper_spec.rb
|
153
158
|
- spec/spec_helper.rb
|
154
159
|
- spec/support/dummy_controller.rb
|
155
160
|
- spec/support/env_variable_helper.rb
|
@@ -184,6 +189,8 @@ test_files:
|
|
184
189
|
- spec/lib/applicaster/accounts/configuration_spec.rb
|
185
190
|
- spec/lib/applicaster/accounts_spec.rb
|
186
191
|
- spec/lib/applicaster/auth_helpers_spec.rb
|
192
|
+
- spec/lib/applicaster/test/accounts/mock_data_spec.rb
|
193
|
+
- spec/lib/applicaster/test/accounts/webmock_helper_spec.rb
|
187
194
|
- spec/spec_helper.rb
|
188
195
|
- spec/support/dummy_controller.rb
|
189
196
|
- spec/support/env_variable_helper.rb
|