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.
@@ -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::User).to receive(:load).with(:connect, "test_wells").and_raise("boom")
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
- user = double
29
- expect(Plaid::User).to receive(:load).with(:connect, "test_wells").and_return(user)
30
- expect(user).to receive(:transactions).and_return([1])
31
- expect(user).to receive(:delete)
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::User).to_not receive(:load).with(:connect, "test_wells").and_raise("boom")
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::User).to receive(:load).with(:connect, "test_wells").and_return(user)
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::User).to_not receive(:load).with(:connect, "test_wells")
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(:code)}
7
- it { should validate_presence_of(:message)}
8
- it { should validate_presence_of(:access_token)}
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(:user){Plaid::User.create(:connect, 'wells', 'plaid_test', 'plaid_good')}
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"=> user.accounts.map{|a| a.id},
9
- "access_token"=> 'test_wells',
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,
@@ -7,11 +7,37 @@ require 'plaid'
7
7
  require 'webmock/rspec'
8
8
 
9
9
  WebMock.allow_net_connect!
10
- Plaid.config do |p|
11
- p.client_id = 'test_id'
12
- p.secret = 'test_secret'
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.10.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: 2017-11-06 00:00:00.000000000 Z
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: '4.1'
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: '4.1'
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: '3.0'
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: '3.0'
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/controllers/plaid_rails/accounts_controller_spec.rb
257
- - spec/controllers/plaid_rails/application_controller_spec.rb
258
- - spec/controllers/plaid_rails/link_controller_spec.rb
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/app/views/layouts/application.html.erb
278
+ - spec/dummy/bin/rake
265
279
  - spec/dummy/bin/bundle
266
280
  - spec/dummy/bin/rails
267
- - spec/dummy/bin/rake
268
- - spec/dummy/config/application.rb
269
- - spec/dummy/config/boot.rb
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/initializers/assets.rb
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/locales/en.yml
284
- - spec/dummy/config/routes.rb
285
- - spec/dummy/config/secrets.yml
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/db/development.sqlite3
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/log/development.log
307
+ - spec/dummy/db/development.sqlite3
291
308
  - spec/dummy/log/test.log
292
- - spec/dummy/public/404.html
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/models/plaid_rails/account_spec.rb
301
- - spec/models/plaid_rails/webhook_spec.rb
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