plaid_rails 0.10.0 → 0.11.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 +8 -0
- data/app/assets/javascripts/plaid_rails/link.js +22 -12
- data/app/controllers/plaid_rails/accounts_controller.rb +9 -5
- data/app/controllers/plaid_rails/link_controller.rb +24 -19
- data/app/controllers/plaid_rails/webhooks_controller.rb +4 -3
- data/app/models/plaid_rails/account.rb +6 -4
- data/app/models/plaid_rails/webhook.rb +7 -3
- data/app/services/plaid_rails/create_account_service.rb +17 -12
- data/app/views/plaid_rails/accounts/new.html.erb +2 -2
- data/app/views/plaid_rails/link/_auth.html.erb +1 -1
- data/config/routes.rb +1 -1
- data/db/migrate/20180617232228_api_update.rb +12 -0
- data/lib/generators/plaid_rails/templates/initializer.rb +4 -6
- data/lib/plaid_rails.rb +1 -1
- data/lib/plaid_rails/event.rb +6 -6
- data/lib/plaid_rails/version.rb +1 -1
- data/spec/controllers/plaid_rails/accounts_controller_spec.rb +12 -14
- data/spec/controllers/plaid_rails/link_controller_spec.rb +18 -11
- data/spec/controllers/plaid_rails/webhooks_controller_spec.rb +79 -5
- data/spec/dummy/db/schema.rb +9 -3
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +10529 -0
- data/spec/models/plaid_rails/account_spec.rb +28 -10
- data/spec/models/plaid_rails/webhook_spec.rb +3 -3
- data/spec/services/plaid_rails/create_account_service_spec.rb +7 -3
- data/spec/spec_helper.rb +31 -4
- data/spec/support/token_helper.rb +25 -0
- metadata +54 -37
@@ -4,11 +4,12 @@ module PlaidRails
|
|
4
4
|
describe Account do
|
5
5
|
it { should validate_presence_of(:access_token)}
|
6
6
|
it { should validate_presence_of(:plaid_id)}
|
7
|
-
it { should validate_presence_of(:plaid_type)}
|
8
7
|
it { should validate_presence_of(:name)}
|
9
8
|
it { should belong_to(:owner).with_foreign_key(:owner_id)}
|
10
9
|
|
11
10
|
let(:account){FactoryGirl.create(:account)}
|
11
|
+
let(:token){create_access_token}
|
12
|
+
let(:public_token){create_public_token}
|
12
13
|
|
13
14
|
describe 'delete_connect' do
|
14
15
|
it "from destroy" do
|
@@ -18,35 +19,52 @@ module PlaidRails
|
|
18
19
|
|
19
20
|
it "has error" do
|
20
21
|
account = FactoryGirl.create(:account)
|
21
|
-
expect(Plaid::
|
22
|
+
expect(Plaid::Client).to receive(:new).with(env: PlaidRails.env,
|
23
|
+
client_id: PlaidRails.client_id,
|
24
|
+
secret: PlaidRails.secret,
|
25
|
+
public_key: PlaidRails.public_key).and_raise("boom")
|
22
26
|
expect(Rails.logger).to receive(:error).exactly(1).times
|
23
27
|
account.send(:delete_connect)
|
24
28
|
end
|
25
29
|
|
26
30
|
it "delete_connect" do
|
27
|
-
account = FactoryGirl.create(:account)
|
28
|
-
|
29
|
-
|
30
|
-
expect(
|
31
|
-
|
31
|
+
account = FactoryGirl.create(:account,access_token: token)
|
32
|
+
client = double
|
33
|
+
item = double
|
34
|
+
expect(Plaid::Client).to receive(:new).with(env: PlaidRails.env,
|
35
|
+
client_id: PlaidRails.client_id,
|
36
|
+
secret: PlaidRails.secret,
|
37
|
+
public_key: PlaidRails.public_key).and_return(client)
|
38
|
+
expect(client).to receive(:transactions).and_return([1])
|
39
|
+
expect(client).to receive(:item).and_return(item)
|
40
|
+
expect(item).to receive(:remove).with(token)
|
32
41
|
account.send(:delete_connect)
|
33
42
|
end
|
34
43
|
|
35
44
|
it "does not delete_connect" do
|
36
45
|
FactoryGirl.create(:account)
|
37
|
-
expect(Plaid::
|
46
|
+
expect(Plaid::Client).to_not receive(:new).with(env: PlaidRails.env,
|
47
|
+
client_id: PlaidRails.client_id,
|
48
|
+
secret: PlaidRails.secret,
|
49
|
+
public_key: PlaidRails.public_key).and_raise("boom")
|
38
50
|
end
|
39
51
|
|
40
52
|
it "does not delete_connect without transactions" do
|
41
53
|
user = double
|
42
|
-
expect(Plaid::
|
54
|
+
expect(Plaid::Client).to receive(:new).with(env: PlaidRails.env,
|
55
|
+
client_id: PlaidRails.client_id,
|
56
|
+
secret: PlaidRails.secret,
|
57
|
+
public_key: PlaidRails.public_key).and_return(user)
|
43
58
|
expect(user).to receive(:transactions).and_return([])
|
44
59
|
account.update(access_token: 'foobar')
|
45
60
|
end
|
46
61
|
|
47
62
|
it 'does not delete_connect with same access_token' do
|
48
63
|
2.times{FactoryGirl.create(:account) }
|
49
|
-
expect(Plaid::
|
64
|
+
expect(Plaid::Client).to_not receive(:new).with(env: PlaidRails.env,
|
65
|
+
client_id: PlaidRails.client_id,
|
66
|
+
secret: PlaidRails.secret,
|
67
|
+
public_key: PlaidRails.public_key)
|
50
68
|
Account.first.destroy
|
51
69
|
end
|
52
70
|
end
|
@@ -3,9 +3,9 @@ module PlaidRails
|
|
3
3
|
describe Webhook do
|
4
4
|
describe "validations" do
|
5
5
|
|
6
|
-
it { should validate_presence_of(:
|
7
|
-
it { should validate_presence_of(:
|
8
|
-
it { should validate_presence_of(:
|
6
|
+
# it { should validate_presence_of(:item_id)}
|
7
|
+
# it { should validate_presence_of(:webhook_type)}
|
8
|
+
# it { should validate_presence_of(:webhook_code)}
|
9
9
|
end
|
10
10
|
describe "methods" do
|
11
11
|
it "calls event" do
|
@@ -2,11 +2,15 @@ require 'spec_helper'
|
|
2
2
|
module PlaidRails
|
3
3
|
describe CreateAccountService do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:client){Plaid::Client.new(env: PlaidRails.env,
|
6
|
+
client_id: PlaidRails.client_id,
|
7
|
+
secret: PlaidRails.secret,
|
8
|
+
public_key: PlaidRails.public_key)}
|
9
|
+
let(:access_token){create_access_token}
|
6
10
|
|
7
11
|
let(:account_params){{
|
8
|
-
"account_ids"=>
|
9
|
-
"access_token"=>
|
12
|
+
"account_ids"=> client.accounts.get(access_token).accounts.map{|a| a.account_id},
|
13
|
+
"access_token"=> access_token,
|
10
14
|
"type"=> 'wells',
|
11
15
|
"name"=> 'Wells Fargo',
|
12
16
|
"owner_id"=> 1,
|
data/spec/spec_helper.rb
CHANGED
@@ -7,11 +7,37 @@ require 'plaid'
|
|
7
7
|
require 'webmock/rspec'
|
8
8
|
|
9
9
|
WebMock.allow_net_connect!
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
p.env = :tartan
|
10
|
+
unless ENV['PLAID_CLIENT_ID']
|
11
|
+
$stderr.puts "Missing Plaid Credentials. Set PLAID_CLIENT_ID,PLAID_SECRET,PLAID_PUBLIC_KEY"
|
12
|
+
exit(1)
|
14
13
|
end
|
14
|
+
PlaidRails.configure do |p|
|
15
|
+
p.client_id = ENV['PLAID_CLIENT_ID']
|
16
|
+
p.secret = ENV['PLAID_SECRET']
|
17
|
+
p.public_key = ENV['PLAID_PUBLIC_KEY']
|
18
|
+
p.env = :sandbox
|
19
|
+
|
20
|
+
# FOR TESTING NOTIFICATIONS
|
21
|
+
p.subscribe "transactions.initial" do |event|
|
22
|
+
Rails.logger.debug "transactions.initial #{event.inspect}"
|
23
|
+
end
|
24
|
+
p.subscribe "transactions.new" do |event|
|
25
|
+
Rails.logger.debug "transactions.new #{event.inspect}"
|
26
|
+
end
|
27
|
+
p.subscribe "transactions.interval" do |event|
|
28
|
+
Rails.logger.debug "transactions.interval #{event.inspect}"
|
29
|
+
end
|
30
|
+
p.subscribe "transactions.removed" do |event|
|
31
|
+
Rails.logger.debug "transactions.removed #{event.inspect}"
|
32
|
+
end
|
33
|
+
p.subscribe "webhook.updated" do |event|
|
34
|
+
Rails.logger.debug "webhook.updated #{event.inspect}"
|
35
|
+
end
|
36
|
+
p.subscribe "plaid.error" do |event|
|
37
|
+
Rails.logger.debug "plaid.error #{event.inspect}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
15
41
|
Rails.backtrace_cleaner.remove_silencers!
|
16
42
|
# Load support files
|
17
43
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
@@ -25,4 +51,5 @@ RSpec.configure do |config|
|
|
25
51
|
config.order = "random"
|
26
52
|
config.infer_spec_type_from_file_location!
|
27
53
|
config.include FactoryGirl::Syntax::Methods
|
54
|
+
config.include TokenHelper
|
28
55
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
module TokenHelper
|
3
|
+
def create_public_token
|
4
|
+
response = RestClient.post('https://sandbox.plaid.com/sandbox/public_token/create',
|
5
|
+
{ "public_key"=> PlaidRails.public_key,
|
6
|
+
"institution_id"=> "ins_109508",
|
7
|
+
"initial_products"=> ['auth','transactions']}.to_json,
|
8
|
+
{content_type: :json, accept: :json})
|
9
|
+
if response.code==200
|
10
|
+
JSON.parse(response.body)['public_token']
|
11
|
+
else
|
12
|
+
Rails.logger.error "unable to create token: #{response.body}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_access_token
|
17
|
+
public_token = create_public_token
|
18
|
+
client = Plaid::Client.new(env: PlaidRails.env,
|
19
|
+
client_id: PlaidRails.client_id,
|
20
|
+
secret: PlaidRails.secret,
|
21
|
+
public_key: PlaidRails.public_key)
|
22
|
+
exchange_token = client.item.public_token.exchange(public_token)
|
23
|
+
exchange_token.access_token
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plaid_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Curt Wilhelm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.1.15
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.1.15
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jquery-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '6.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '6.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rest-client
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: A Rails Engine to work with Plaid
|
140
154
|
email:
|
141
155
|
- curt@9ksoftware.com
|
@@ -171,6 +185,7 @@ files:
|
|
171
185
|
- db/migrate/20160214150149_create_plaid_rails_webhooks.rb
|
172
186
|
- db/migrate/20160215155024_create_plaid_rails_accounts.rb
|
173
187
|
- db/migrate/20160323141534_add_transactions_start_date_to_accounts.rb
|
188
|
+
- db/migrate/20180617232228_api_update.rb
|
174
189
|
- db/test.sqlite3
|
175
190
|
- lib/generators/plaid_rails/install_generator.rb
|
176
191
|
- lib/generators/plaid_rails/templates/initializer.rb
|
@@ -228,6 +243,7 @@ files:
|
|
228
243
|
- spec/plaid_rails.spec.rb
|
229
244
|
- spec/services/plaid_rails/create_account_service_spec.rb
|
230
245
|
- spec/spec_helper.rb
|
246
|
+
- spec/support/token_helper.rb
|
231
247
|
homepage: https://github.com/cdwilhelm/plaid_rails
|
232
248
|
licenses:
|
233
249
|
- MIT
|
@@ -253,52 +269,53 @@ signing_key:
|
|
253
269
|
specification_version: 4
|
254
270
|
summary: A Rails Engine to work with Plaid
|
255
271
|
test_files:
|
256
|
-
- spec/
|
257
|
-
- spec/controllers/
|
258
|
-
- spec/
|
259
|
-
- spec/controllers/plaid_rails/webhooks_controller_spec.rb
|
272
|
+
- spec/spec_helper.rb
|
273
|
+
- spec/dummy/app/controllers/application_controller.rb
|
274
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
260
275
|
- spec/dummy/app/assets/javascripts/application.js
|
261
276
|
- spec/dummy/app/assets/stylesheets/application.css
|
262
|
-
- spec/dummy/app/controllers/application_controller.rb
|
263
277
|
- spec/dummy/app/helpers/application_helper.rb
|
264
|
-
- spec/dummy/
|
278
|
+
- spec/dummy/bin/rake
|
265
279
|
- spec/dummy/bin/bundle
|
266
280
|
- spec/dummy/bin/rails
|
267
|
-
- spec/dummy/
|
268
|
-
- spec/dummy/config/
|
269
|
-
- spec/dummy/config/
|
270
|
-
- spec/dummy/config/database.yml
|
271
|
-
- spec/dummy/config/environment.rb
|
272
|
-
- spec/dummy/config/environments/development.rb
|
281
|
+
- spec/dummy/config/secrets.yml
|
282
|
+
- spec/dummy/config/routes.rb
|
283
|
+
- spec/dummy/config/locales/en.yml
|
273
284
|
- spec/dummy/config/environments/production.rb
|
285
|
+
- spec/dummy/config/environments/development.rb
|
274
286
|
- spec/dummy/config/environments/test.rb
|
275
|
-
- spec/dummy/config/
|
287
|
+
- spec/dummy/config/environment.rb
|
288
|
+
- spec/dummy/config/application.rb
|
289
|
+
- spec/dummy/config/database.yml
|
290
|
+
- spec/dummy/config/boot.rb
|
276
291
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
277
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
278
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
279
|
-
- spec/dummy/config/initializers/inflections.rb
|
280
292
|
- spec/dummy/config/initializers/mime_types.rb
|
293
|
+
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
281
294
|
- spec/dummy/config/initializers/session_store.rb
|
282
295
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
283
|
-
- spec/dummy/config/
|
284
|
-
- spec/dummy/config/
|
285
|
-
- spec/dummy/config/
|
296
|
+
- spec/dummy/config/initializers/assets.rb
|
297
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
298
|
+
- spec/dummy/config/initializers/inflections.rb
|
286
299
|
- spec/dummy/config.ru
|
287
|
-
- spec/dummy/
|
300
|
+
- spec/dummy/Rakefile
|
301
|
+
- spec/dummy/public/favicon.ico
|
302
|
+
- spec/dummy/public/422.html
|
303
|
+
- spec/dummy/public/500.html
|
304
|
+
- spec/dummy/public/404.html
|
288
305
|
- spec/dummy/db/schema.rb
|
289
306
|
- spec/dummy/db/test.sqlite3
|
290
|
-
- spec/dummy/
|
307
|
+
- spec/dummy/db/development.sqlite3
|
291
308
|
- spec/dummy/log/test.log
|
292
|
-
- spec/dummy/
|
293
|
-
- spec/dummy/public/422.html
|
294
|
-
- spec/dummy/public/500.html
|
295
|
-
- spec/dummy/public/favicon.ico
|
296
|
-
- spec/dummy/Rakefile
|
309
|
+
- spec/dummy/log/development.log
|
297
310
|
- spec/dummy/README.rdoc
|
311
|
+
- spec/models/plaid_rails/webhook_spec.rb
|
312
|
+
- spec/models/plaid_rails/account_spec.rb
|
313
|
+
- spec/support/token_helper.rb
|
298
314
|
- spec/factories/account.rb
|
299
315
|
- spec/factories/webhook.rb
|
300
|
-
- spec/
|
301
|
-
- spec/
|
316
|
+
- spec/controllers/plaid_rails/link_controller_spec.rb
|
317
|
+
- spec/controllers/plaid_rails/accounts_controller_spec.rb
|
318
|
+
- spec/controllers/plaid_rails/application_controller_spec.rb
|
319
|
+
- spec/controllers/plaid_rails/webhooks_controller_spec.rb
|
302
320
|
- spec/plaid_rails.spec.rb
|
303
321
|
- spec/services/plaid_rails/create_account_service_spec.rb
|
304
|
-
- spec/spec_helper.rb
|