spec/lib/morph_spec.rb in morph-0.2.5 vs spec/lib/morph_spec.rb in morph-0.2.6

- old
+ new

@@ -350,10 +350,33 @@ check_convert_to_morph_method_name '年龄', '年龄' end end describe 'creating from hash' do + it 'should create classes and object instances with array of hashes' do + h = { + "CompanyDetails"=> { + "SearchItems"=> [ + { "CompanyDate"=> '', + "CompanyIndexStatus"=> '', + "DataSet"=>"LIVE", + "CompanyName"=>"CANONGROVE LIMITED", + "CompanyNumber"=>"SC244777" }, + { "CompanyDate"=>"", + "CompanyIndexStatus"=>"", + "DataSet"=>"LIVE", + "CompanyName"=>"CANONHALL ACCOUNTANCY LTD", + "CompanyNumber"=>"05110715" } + ] + } + } + company_details = Morph.from_hash(h) + company_details.search_items.first.class.name.should == 'Morph::SearchItem' + company_details.search_items.first.data_set.should == 'LIVE' + company_details.search_items.first.company_name.should == 'CANONGROVE LIMITED' + end + it 'should create classes and object instances' do h = { "CompanyDetails"=> { "RegAddress"=> { "AddressLine"=>["ST DAVID'S HOUSE", "WEST WING", "WOOD STREET", "CARDIFF CF10 1ES"]}, @@ -388,23 +411,11 @@ "NextDueDate"=>"2002-11-30", "LastMadeUpDate"=>"2001-04-30", "AccountRefDate"=>"0000-30-04"}, "IncorporationDate"=>"1996-03-25", "CompanyNumber"=>"03176906", - "xmlns"=>"http://xmlgw.companieshouse.gov.uk/v1-0", - "SearchItems"=> [ - { "CompanyDate"=> '', - "CompanyIndexStatus"=> '', - "DataSet"=>"LIVE", - "CompanyName"=>"CANONGROVE LIMITED", - "CompanyNumber"=>"SC244777" }, - { "CompanyDate"=>"", - "CompanyIndexStatus"=>"", - "DataSet"=>"LIVE", - "CompanyName"=>"CANONHALL ACCOUNTANCY LTD", - "CompanyNumber"=>"05110715" } - ] + "xmlns"=>"http://xmlgw.companieshouse.gov.uk/v1-0" } } Object.const_set 'Company', Module.new Company.const_set 'House', Module.new @@ -417,12 +428,58 @@ company_details.accounts.overdue.should == 'NO' company_details.last_full_mem_date.should == "2002-03-25" company_details.sic_codes.sic_text.should == 'stadiums' company_details.reg_address.address_lines.should == ["ST DAVID'S HOUSE", "WEST WING", "WOOD STREET", "CARDIFF CF10 1ES"] - company_details.search_items.first.class.name.should == 'Company::House::SearchItem' - company_details.search_items.first.data_set.should == 'LIVE' - company_details.search_items.first.company_name.should == 'CANONGROVE LIMITED' - # puts company_details.to_yaml + list = Morph.generate_migrations company_details, :ignore=>['xmlns','xmlns_xsi','xsi_schema_location'] + list.size.should == 7 + list[0].should == "./script/generate model company_details company_category:string company_name:string company_number:string company_status:string country_of_origin:string has_appointments:string has_branch_info:string in_liquidation:string incorporation_date:date last_full_mem_date:date" + list[1].should == './script/generate model accounts company_details_id:integer account_category:string account_ref_date:date document_available:string last_made_up_date:date next_due_date:date overdue:string' + list[2].should == './script/generate model mortgages company_details_id:integer mortgage_ind:string num_mort_charges:string num_mort_outstanding:string num_mort_part_satisfied:string num_mort_satisfied:string' + list[3].should == './script/generate model reg_address company_details_id:integer' + list[4].should == './script/generate model address_lines reg_address_id:integer' + list[5].should == './script/generate model returns company_details_id:integer document_available:string last_made_up_date:date next_due_date:date overdue:string' + list[6].should == './script/generate model sic_codes company_details_id:integer sic_text:string' + + yaml = %Q|--- !ruby/object:Company::House::CompanyDetails +accounts: !ruby/object:Company::House::Accounts + account_category: FULL + account_ref_date: "0000-30-04" + document_available: "1" + last_made_up_date: "2001-04-30" + next_due_date: "2002-11-30" + overdue: "NO" +company_category: Public Limited Company +company_name: MILLENNIUM STADIUM PLC +company_number: 03176906 +company_status: Active +country_of_origin: United Kingdom +has_appointments: "1" +has_branch_info: "0" +in_liquidation: "0" +incorporation_date: "1996-03-25" +last_full_mem_date: "2002-03-25" +mortgages: !ruby/object:Company::House::Mortgages + mortgage_ind: LT300 + num_mort_charges: "7" + num_mort_outstanding: "7" + num_mort_part_satisfied: "0" + num_mort_satisfied: "0" +reg_address: !ruby/object:Company::House::RegAddress + address_lines: + - ST DAVID'S HOUSE + - WEST WING + - WOOD STREET + - CARDIFF CF10 1ES +returns: !ruby/object:Company::House::Returns + document_available: "1" + last_made_up_date: "2002-03-25" + next_due_date: "2003-04-22" + overdue: "NO" +sic_codes: !ruby/object:Company::House::SICCodes + sic_text: stadiums +xmlns: http://xmlgw.companieshouse.gov.uk/v1-0 +xmlns_xsi: http://www.w3.org/2001/XMLSchema-instance +xsi_schema_location: xmlgwdev.companieshouse.gov.uk/v1-0/schema/CompanyDetails.xsd| end end end