require 'spec_helper' describe EmberCliDeployRedis::RevisionList do subject { described_class.new(application, revisions) } let(:application) { double('application', name: 'app_name') } let(:revisions) { %w(one two three) } describe '#[]' do it 'delegates to the revisions array' do expect(revisions).to receive(:[]).and_call_original expect(subject[0]).to eq('one') end end describe '#first' do it 'delegates to the revisions array' do expect(revisions).to receive(:first).and_call_original expect(subject.first).to eq('one') end end describe '#last' do it 'delegates to the revisions array' do expect(revisions).to receive(:last).and_call_original expect(subject.last).to eq('three') end end describe '#each' do it 'delegates to the revisions array' do expect(revisions).to receive(:each).and_call_original expect(subject.each(&:to_s)).to eq(revisions) end end describe '#map' do it 'delegates to the revisions array' do expect(revisions).to receive(:map).and_call_original expect(subject.map(&:to_s)).to eq(revisions) end end describe '#initialize' do it 'stores the application' do expect(subject.application).to eq(application) end it 'stores the revisions' do expect(subject.revisions).to eq(revisions) end end describe '.from_redis' do subject { described_class.from_redis(application) } before do allow(described_class).to receive(:list_from_redis).and_return(revisions) end it 'gets the list from redis' do expect(described_class).to receive(:list_from_redis).with(application) subject end it 'returns a Revision for each revision' do expect(described_class).to receive(:new) do |app, revs| expect(app).to eq(application) revs.each do |revision| expect(revision).to be_kind_of(EmberCliDeployRedis::Revision) end expect(revs.map(&:name)).to eq(revisions) :response_from_new end expect(subject).to eq(:response_from_new) end end describe '.list_from_redis' do subject { described_class.list_from_redis(application) } let(:redis_key) { 'revision_list' } let(:most_recent_revision) { 'recent' } let(:oldest_revision) { 'oldest' } before do allow(EmberCliDeployRedis.configuration).to receive(:redis_key_for_revision_list) .and_return(redis_key) end context 'with deployed revisions' do before do EmberCliDeployRedis.configuration.redis.lpush(redis_key, oldest_revision) EmberCliDeployRedis.configuration.redis.lpush(redis_key, most_recent_revision) end it 'gets the redis key from configuration' do expect(EmberCliDeployRedis.configuration).to receive(:redis_key_for_revision_list) .with(application) subject end it 'returns the list of revisions from redis' do expect(subject).to match_array([most_recent_revision, oldest_revision]) end end context 'with no deployed revisions' do it { is_expected.to eq([]) } end end end