bank_lookup 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,8 +32,17 @@ module BankLookup
32
32
  end
33
33
 
34
34
  class API < Sinatra::Base
35
+ before do
36
+ content_type :json
37
+ end
38
+
35
39
  # GET /bank_name?number=23413421
36
40
  get '/bank_name' do
41
+ if params['number'].nil?
42
+ halt 400, MultiJson.encode(:error => '"number" param is required')
43
+ end
44
+ params['number'].strip!
45
+
37
46
  number = params['number']
38
47
  if name = DB[number]
39
48
  MultiJson.encode({:name => name, :pretty_name => name.titleize})
@@ -1,3 +1,3 @@
1
1
  module BankLookup
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe BankLookup::API, 'GET /bank_name' do
4
+ def app
5
+ BankLookup::API.new
6
+ end
7
+
8
+ def get(url)
9
+ Rack::MockRequest.new(app).get(url)
10
+ end
11
+
12
+ describe "when passed a number that exists in the db" do
13
+ it 'responds with 200' do
14
+ get("/bank_name?number=011000015").status.should == 200
15
+ end
16
+
17
+ it 'responds with json content type' do
18
+ get("/bank_name?number=011000015").content_type.should =~ /json/
19
+ end
20
+
21
+ it 'responds with name and pretty name keys' do
22
+ data = MultiJson.decode(get("/bank_name?number=011000015").body)
23
+ data.should have_key 'name'
24
+ data.should have_key 'pretty_name'
25
+ end
26
+
27
+ it 'strips whitespace from the front' do
28
+ get("/bank_name?number=%20011000015").status.should == 200
29
+ end
30
+
31
+ it 'strips whitespace from the end' do
32
+ get("/bank_name?number=011000015%20").status.should == 200
33
+ end
34
+ end
35
+
36
+ describe 'when passed a number that does not exist' do
37
+ it 'responds with 404' do
38
+ get('/bank_name?number=234').status.should == 404
39
+ end
40
+
41
+ it 'responds with json' do
42
+ get('/bank_name?number=234').content_type.should =~ /json/
43
+ end
44
+ end
45
+
46
+ describe 'when not passed a number param' do
47
+ it 'responds with 400' do
48
+ get('/bank_name').status.should == 400
49
+ end
50
+
51
+ it 'responds with an error message' do
52
+ MultiJson.decode(get('/bank_name').body).should == {'error' => '"number" param is required'}
53
+ end
54
+
55
+ it 'responds with a text content type' do
56
+ get('/bank_name').content_type.should =~ /json/
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe BankLookup::DB do
4
+ it 'allows looking up a number with a string number' do
5
+ BankLookup::DB['011000015'].should == 'FEDERAL RESERVE BANK'
6
+ end
7
+
8
+ it 'does not allow looking up a number with an int number' do
9
+ BankLookup::DB[011000015].should be_nil
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ ENV['RACK_ENV'] ||= 'test'
5
+
6
+ $:.push File.dirname(File.expand_path(__FILE__))
7
+ $:.push(File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib'))
8
+
9
+ require 'bank_lookup'
10
+
11
+ Bundler.setup :default, :test
12
+ Bundler.require :default, :test
13
+
14
+ BankLookup::Parser.parse
15
+
16
+ RSpec.configure do |c|
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-08 00:00:00.000000000 Z
13
+ date: 2013-03-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
17
- requirement: &70147441679220 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70147441679220
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: sinatra
28
- requirement: &70147441678720 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70147441678720
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: activesupport
39
- requirement: &70147441678160 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,7 +54,12 @@ dependencies:
44
54
  version: '0'
45
55
  type: :runtime
46
56
  prerelease: false
47
- version_requirements: *70147441678160
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  description: Lookup bank names by routing number.
49
64
  email:
50
65
  - ajsharp@gmail.com
@@ -54,6 +69,7 @@ executables:
54
69
  extensions: []
55
70
  extra_rdoc_files: []
56
71
  files:
72
+ - .gitignore
57
73
  - Gemfile
58
74
  - README.md
59
75
  - bank_lookup.gemspec
@@ -62,6 +78,9 @@ files:
62
78
  - examples/config.ru
63
79
  - lib/bank_lookup.rb
64
80
  - lib/bank_lookup/version.rb
81
+ - spec/api_spec.rb
82
+ - spec/bank_lookup_spec.rb
83
+ - spec/spec_helper.rb
65
84
  homepage: https://github.com/zaarly/bank_lookup
66
85
  licenses: []
67
86
  post_install_message:
@@ -82,8 +101,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
101
  version: '0'
83
102
  requirements: []
84
103
  rubyforge_project: bank_lookup
85
- rubygems_version: 1.8.15
104
+ rubygems_version: 1.8.24
86
105
  signing_key:
87
106
  specification_version: 3
88
107
  summary: Lookup bank names by routing number.
89
- test_files: []
108
+ test_files:
109
+ - spec/api_spec.rb
110
+ - spec/bank_lookup_spec.rb
111
+ - spec/spec_helper.rb
112
+ has_rdoc: