vin_exploder 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vin_exploder (0.4.0)
4
+ vin_exploder (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -37,7 +37,7 @@ module VinExploder
37
37
  if block_given?
38
38
  if hash.nil?
39
39
  hash = yield
40
- cachewrite(vin, hash) unless hash.empty? || (hash[:errors] && !hash[:errors].empty?)
40
+ write(vin, hash) unless hash.empty? || (hash[:errors] && !hash[:errors].empty?)
41
41
  end
42
42
  end
43
43
  hash
@@ -0,0 +1,46 @@
1
+ require 'vin_exploder/abstract_adapter'
2
+
3
+ module VinExploder
4
+
5
+ module Decode
6
+
7
+ class TestAdapter < AbstractAdapter
8
+
9
+ # Create new vinquery adapter
10
+ #
11
+ # == Parameters
12
+ # options:: access_code, report_type, url
13
+ def initialize(options={})
14
+ super
15
+ end
16
+
17
+ def explode(vin)
18
+ fetch(vin)
19
+ end
20
+
21
+
22
+ def fetch(vin)
23
+ #could make the hashes more complete
24
+ case vin
25
+ when '3D7LU38C83G854645'
26
+ { :make => 'Dodge', :model => 'Ram 3500', :year => '2004', :trim_level => 'ST Quad Cab Long Bed 4WD', :fuel_type => 'Desiel', :engine_type => '5.9L L6 OHV 24V TURBO DIESEL', :number_of_doors => '4', :manufactured_in => 'UNITED STATES', :production_seq_number => 'C27031', :driveline => '4WD', :body_style => "CREW CAB PICKUP 4-DR" }
27
+ when '1G1ND52F14M587843'
28
+ { :make => 'Chevrolet', :model => 'Classic', :year => '2004', :trim_level => 'Fleet', :fuel_type => 'Gas', :engine_type => '2.2L L4 DOHC', :number_of_doors => '4', :manufactured_in => 'UNITED STATES', :production_seq_number => '587843', :driveline => 'FWD', :body_style => "SEDAN 4-DR" }
29
+ when '12345678912345678'
30
+ { :errors => [{'5' => 'Invalid VIN number: This VIN number did not pass checksum test.'}] }
31
+ when /[IOQ]/
32
+ { :errors => [{'3' => "Invalid VIN number: This VIN number contains invalid letters: I,O or Q."}] }
33
+ else
34
+ { :errors => [{'0' => "VIN not found"}] }
35
+ end
36
+ end
37
+
38
+ def normalize(vq_hash)
39
+ vq_hash
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -1,3 +1,3 @@
1
1
  module VinExploder
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'vin_exploder/test_adapter'
3
+
4
+ module VinExploder
5
+ module Decode
6
+
7
+ describe TestAdapter do
8
+
9
+ before(:each) do
10
+ @adapter = TestAdapter.new({})
11
+ end
12
+
13
+ it "should return Dodge Ram for vin 3D7LU38C83G854645" do
14
+ hash = @adapter.explode '3D7LU38C83G854645'
15
+ hash[:make].should == 'Dodge'
16
+ hash[:model].should == 'Ram 3500'
17
+ hash[:fuel_type].should == 'Desiel'
18
+ end
19
+
20
+ it "should return Chevrolet Classic for vin 1G1ND52F14M587843" do
21
+ hash = @adapter.explode '1G1ND52F14M587843'
22
+ hash[:make].should == 'Chevrolet'
23
+ hash[:model].should == 'Classic'
24
+ hash[:fuel_type].should == 'Gas'
25
+ end
26
+
27
+ it "should return checksum error for vin 12345678912345678" do
28
+ hash = @adapter.explode '12345678912345678'
29
+ hash[:errors].first.values.first.should == 'Invalid VIN number: This VIN number did not pass checksum test.'
30
+ hash[:make].should be_nil
31
+ end
32
+
33
+ it "should return invalid letters error for vins with I, O or Q" do
34
+ hash = @adapter.explode 'I2345678912345678'
35
+ hash[:errors].first.values.first.should == 'Invalid VIN number: This VIN number contains invalid letters: I,O or Q.'
36
+ hash[:make].should be_nil
37
+ hash = @adapter.explode 'O2345678912345678'
38
+ hash[:errors].first.values.first.should == 'Invalid VIN number: This VIN number contains invalid letters: I,O or Q.'
39
+ hash = @adapter.explode 'Q2345678912345678'
40
+ hash[:errors].first.values.first.should == 'Invalid VIN number: This VIN number contains invalid letters: I,O or Q.'
41
+ end
42
+
43
+ it "should return 'VIN not found' error for all other vins" do
44
+ hash = @adapter.explode '1J1ND33F14M537843'
45
+ hash[:errors].first.values.first.should == 'VIN not found'
46
+ hash[:make].should be_nil
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'vin_exploder'
3
-
4
- class VinExploder::Decode::TestAdapter; end
3
+ require 'vin_exploder/test_adapter'
5
4
 
6
5
  module VinExploder
7
6
 
@@ -37,10 +36,6 @@ describe Exploder do
37
36
 
38
37
  describe "VinExploder#explode" do
39
38
  it "should return an Explosion object" do
40
- ta = VinExploder::Decode::TestAdapter.new
41
- ta.should_receive(:explode) { {} }
42
- VinExploder::Decode::TestAdapter.should_receive(:new){ ta }
43
-
44
39
  VinExploder.config.adapter :test_adapter
45
40
  VinExploder.explode("VIN").class.should == Explosion
46
41
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: vin_exploder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.1
5
+ version: 0.4.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jake Mallory
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-06 00:00:00 Z
13
+ date: 2011-07-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -97,6 +97,7 @@ files:
97
97
  - lib/vin_exploder/configuration.rb
98
98
  - lib/vin_exploder/exploder.rb
99
99
  - lib/vin_exploder/explosion.rb
100
+ - lib/vin_exploder/test_adapter.rb
100
101
  - lib/vin_exploder/version.rb
101
102
  - lib/vin_exploder.rb
102
103
  - Gemfile
@@ -109,6 +110,7 @@ files:
109
110
  - spec/cache/sequel_cache_store_spec.rb
110
111
  - spec/configuration_spec.rb
111
112
  - spec/spec_helper.rb
113
+ - spec/test_adapter_spec.rb
112
114
  - spec/vin_exploder_spec.rb
113
115
  homepage: http://github.com/tinomen/vin_exploder
114
116
  licenses: []
@@ -150,4 +152,5 @@ test_files:
150
152
  - spec/cache/sequel_cache_store_spec.rb
151
153
  - spec/configuration_spec.rb
152
154
  - spec/spec_helper.rb
155
+ - spec/test_adapter_spec.rb
153
156
  - spec/vin_exploder_spec.rb