Skip to content

Commit

Permalink
fixed bug preventing multiple sic codes being returned in query respo…
Browse files Browse the repository at this point in the history
…nse; ready for v0.0.9 release
  • Loading branch information
robmckinnon committed Jan 11, 2011
1 parent d039aac commit 1620852
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
v0.0.9. fixes bug preventing multiple sic codes being returned in query response

v0.0.8. use Nokogiri instead of Hpricot

v0.0.7. fixes bug preventing unique transaction ids being created when api called frequently
Expand Down
4 changes: 3 additions & 1 deletion lib/companies_house.rb
Expand Up @@ -14,7 +14,7 @@
$KCODE = 'UTF8' unless RUBY_VERSION >= "1.9"

module CompaniesHouse
VERSION = "0.0.8" unless defined? CompaniesHouse::VERSION
VERSION = "0.0.9" unless defined? CompaniesHouse::VERSION

class << self

Expand Down Expand Up @@ -124,6 +124,8 @@ def objectify_body body
sic_codes = object.sic_codes
if sic_codes.respond_to?(:sic_text) && sic_codes.sic_text
sic_codes.morph(:sic_texts, [sic_codes.sic_text])
elsif sic_codes.respond_to?(:sic_texts) && sic_codes.sic_texts
# leave as is
else
object.morph(:sic_codes, Morph.from_hash({:sic_codes => {'sic_texts' => []} }) )
end
Expand Down
9 changes: 8 additions & 1 deletion spec/lib/companies_house_spec.rb
Expand Up @@ -18,7 +18,7 @@
end
describe 'and xml contains single sic_text' do
it 'should convert to sic_code sic_texts' do
xml = '<Body><company_details><sic_codes><sic_text>9261 - Operate sports arenas &amp; stadiums</sic_text></sic_codes></company_details></Body>'
xml = '<Body><company_details><SICCodes><SicText>9261 - Operate sports arenas &amp; stadiums</SicText></SICCodes></company_details></Body>'

object = CompaniesHouse.objectify xml
object.sic_codes.sic_text.should == '9261 - Operate sports arenas & stadiums'
Expand All @@ -37,6 +37,13 @@
object.sic_codes.sic_texts.should == []
end
end
describe 'and xml contains multiple sic codes' do
it 'should return array of sic codes' do
xml = '<Body><CompanyDetails><SICCodes><SicText>2960 - Manufacture of weapons &amp; ammunition</SicText><SicText>3410 - Manufacture of motor vehicles</SicText></SICCodes></CompanyDetails></Body>'
object = CompaniesHouse.objectify xml
object.sic_codes.sic_texts.should == ['2960 - Manufacture of weapons & ammunition','3410 - Manufacture of motor vehicles']
end
end
end

describe 'and xml contains Error' do
Expand Down

0 comments on commit 1620852

Please sign in to comment.