Refactored contact attribute assignment

This commit is contained in:
Andres Keskküla 2014-08-15 11:52:43 +03:00
parent 5b91acb343
commit 6bcf508fac
7 changed files with 94 additions and 33 deletions

View file

@ -4,3 +4,19 @@ describe Address do
it { should belong_to(:contact) }
it { should belong_to(:country) }
end
describe Address, '.extract_params' do
it 'returns params hash'do
Fabricate(:country, iso:'EE')
ph = { postalInfo: { name: "fred", addr: { cc: 'EE', city: 'Village', street: [ 'street1', 'street2' ] } } }
expect(Address.extract_attributes(ph[:postalInfo][:addr])).to eq( {
city: 'Village',
country_id: 1,
street: 'street1',
street2: 'street2'
} )
end
end

View file

@ -65,6 +65,18 @@ describe Contact, '#upID' do
end
describe Contact, '.extract_params' do
it 'returns params hash'do
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: "fred", addr: { cc: 'EE' } } }
expect(Contact.extract_attributes(ph)).to eq( {
code: '123123',
email: 'jdoe@example.com',
name: 'fred'
} )
end
end
describe Contact, '.check_availability' do
before(:each) {