spec/lib/contentful/management/entry_spec.rb in contentful-management-1.2.0 vs spec/lib/contentful/management/entry_spec.rb in contentful-management-1.3.0

- old
+ new

@@ -1,9 +1,22 @@ require 'spec_helper' require 'contentful/management/space' require 'contentful/management/client' +class RetryLoggerMock < Logger + attr_reader :retry_attempts + + def initialize(*) + super + @retry_attempts = 0 + end + + def info(message) + @retry_attempts += 1 if message.include?('Contentful Management API Rate Limit Hit! Retrying') + end +end + module Contentful module Management describe Entry do let(:token) { '<ACCESS_TOKEN>' } let(:space_id) { 'yr5m0jky5hsh' } @@ -251,13 +264,13 @@ let(:content_type) { client.content_types.find(space_id, content_type_id) } it 'create with all attributes' do vcr('entry/create') do content_type = client.content_types.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c') - location = Location.new.tap do |location| - location.lat = 22.44 - location.lon = 33.33 + location = Location.new.tap do |loc| + loc.lat = 22.44 + loc.lon = 33.33 end file = client.assets.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG') entry_att = subject.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm') entry = subject.create( content_type, @@ -409,10 +422,23 @@ expect(publish).to be_a RateLimitExceeded expect(publish.error[:message]).to eq 'You have exceeded the rate limit of the Organization this Space belongs to by making too many API requests within a short timespan. Please wait a moment before trying the request again.' end end + it 'too many requests auto-retry' do + vcr('entry/too_many_requests_retry') do + logger = RetryLoggerMock.new(STDOUT) + space = Client.new(token, raise_errors: true, logger: logger).spaces.find('286arvy86ry9') + invalid_entry = space.entries.find('1YNepnMpXGiMWikaKC4GG0') + ct = space.content_types.find('5lIEiXrCIoKoIKaSW2C8aa') + entry = ct.entries.create(name: 'Create test', entry: invalid_entry) + entry.publish + + expect(logger.retry_attempts).to eq 1 + end + end + it 'with just an id' do vcr('entry/create_with_just_id') do space = client.spaces.find('bbukbffokvih') entry = space.content_types.all.first.entries.create({'id' => 'yol'}) entry.save @@ -733,12 +759,12 @@ 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 + location = Location.new.tap do |loc| + loc.lat = 22.44 + loc.lon = 33.33 end attributes = { name: 'Test name', number: 30,