spec/lib/contentful/management/entry_spec.rb in contentful-management-0.2.0 vs spec/lib/contentful/management/entry_spec.rb in contentful-management-0.2.1

- old
+ new

@@ -194,10 +194,47 @@ end describe '.create' do let(:content_type_id) { '5DSpuKrl04eMAGQoQckeIq' } let(:content_type) { Contentful::Management::ContentType.find(space_id, content_type_id) } + + it 'create with all attributes' do + vcr('entry/create') do + content_type = Contentful::Management::ContentType.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c') + location = Location.new.tap do |location| + location.lat = 22.44 + location.lon = 33.33 + end + file = Asset.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG') + entry_att = Entry.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm') + entry = subject.create(content_type, + name: 'Test name', + number: 30, + float1: 1.1, + boolean: true, date: '2000-07-12T11:11:00+02:00', + time: '2000-07-12T11:11:00+02:00', + location: location, + file: file, + image: file, + array: %w(PL USD XX), + entry: entry_att, + entries: [entry_att, entry_att], + object_json: {'test' => {'@type' => 'Codequest'}} + ) + expect(entry.name).to eq 'Test name' + expect(entry.number).to eq 30 + expect(entry.float1).to eq 1.1 + expect(entry.boolean).to eq true + expect(entry.date.to_s).to eq '2000-07-12T11:11:00+02:00' + expect(entry.time.to_s).to eq '2000-07-12T11:11:00+02:00' + expect(entry.file['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG' + expect(entry.image['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG' + expect(entry.array).to eq %w(PL USD XX) + expect(entry.entry['sys']['id']).to eq entry_att.id + expect(entry.entries.first['sys']['id']).to eq entry_att.id + end + end it 'with location' do vcr('entry/create_with_location') do location = Location.new location.lat = 22.44 location.lon = 33.33 @@ -247,12 +284,13 @@ expect(entry.name).to eq 'multiAssets' end end it 'with symbols' do vcr('entry/create_with_symbols') do - entry = subject.create(content_type, name: 'SymbolTest', symbols: 'USD, PL, XX') + entry = subject.create(content_type, name: 'SymbolTest', symbols: %w(PL USD XX)) expect(entry.name).to eq 'SymbolTest' + expect(entry.symbols).to eq %w(USD PL XX) end end it 'with custom id' do vcr('entry/create_with_custom_id') do entry = subject.create(content_type, id: 'custom_id', name: 'Custom Id') @@ -282,13 +320,15 @@ location.lon = 33.33 result = entry.update(name: 'Tom Handy', age: 20, birthday: '2000-07-12T11:11:00+02:00', city: location, bool: false, - asset: asset, assets: [asset, asset, asset], - entry: entry_att, entries: [entry_att, entry_att, entry_att], - symbols: ['PL', 'USD', 'XX']) + asset: asset, + assets: [asset, asset, asset], + entry: entry_att, + entries: [entry_att, entry_att, entry_att], + symbols: %w(PL USD XX)) expect(result).to be_kind_of Contentful::Management::Entry expect(result.fields[:name]).to eq 'Tom Handy' expect(result.fields[:age]).to eq 20 @@ -353,12 +393,13 @@ end end end describe 'search filters' do - let(:space) { Contentful::Management::Space.find('bfsvtul0c41g') - } + let(:space) do + Contentful::Management::Space.find('bfsvtul0c41g') + end context 'order' do it 'returns ordered entries by createdAt' do vcr('entry/search_filter/order_sys.createdAt') do ordered_entries = space.entries.all(order: 'sys.createdAt') expect(ordered_entries).to be_kind_of Contentful::Management::Array @@ -510,8 +551,55 @@ end end end end end + + describe '#fields_from_attributes' do + + it 'parses all kind of fields' do + + location = Location.new.tap do |location| + location.lat = 22.44 + location.lon = 33.33 + end + # file = Asset.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG') + # entry_att = Entry.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm') + + attributes = { + name: 'Test name', + number: 30, + float1: 1.1, + boolean: true, date: '2000-07-12T11:11:00+02:00', + time: '2000-07-12T11:11:00+02:00', + location: location, + image: Asset.new, + images: [Asset.new, Asset.new], + array: %w(PL USD XX), + entry: Entry.new, + entries: [Entry.new, Entry.new], + object_json: {'test' => {'@type' => 'Codequest'}} + } + + parsed_attributes = Entry.new.fields_from_attributes(attributes) + + expect(parsed_attributes[:name]).to match('en-US' => 'Test name') + expect(parsed_attributes[:number]).to match('en-US' => 30) + expect(parsed_attributes[:float1]).to match('en-US' => 1.1) + expect(parsed_attributes[:boolean]).to match('en-US' => true) + expect(parsed_attributes[:date]).to match('en-US' => '2000-07-12T11:11:00+02:00') + expect(parsed_attributes[:time]).to match('en-US' => '2000-07-12T11:11:00+02:00') + expect(parsed_attributes[:location]).to match('en-US' => {lat: 22.44, lon: 33.33}) + expect(parsed_attributes[:array]).to match('en-US' => %w(PL USD XX)) + expect(parsed_attributes[:object_json]).to match('en-US' => {'test' => {'@type' => 'Codequest'}}) + expect(parsed_attributes[:image]).to match('en-US' => {sys: {type: 'Link', linkType: 'Asset', id: nil}}) + expect(parsed_attributes[:images]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Asset', id: nil}}, {sys: {type: 'Link', linkType: 'Asset', id: nil}}]) + expect(parsed_attributes[:entry]).to match('en-US' => {sys: {type: 'Link', linkType: 'Entry', id: nil}}) + expect(parsed_attributes[:entries]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}]) + + end + + end + end end end