diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-03 14:03:57 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-03 14:03:57 +0300 |
commit | 16a72896a21ef065a0b259d32a43dd6554cee1d2 (patch) | |
tree | fe22b8f3f2a4ceba7b6cb5318c8137e80652a48c /spec/serializers | |
parent | a5e5e4ac8a02a6f35745bb1b5b118135f63d4003 (diff) |
Extend environments folders and pagination API specs
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/environment_serializer_spec.rb | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index 0eaf6db4761..1b95f1ff198 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -53,6 +53,68 @@ describe EnvironmentSerializer do end end + context 'when representing environments within folders' do + let(:serializer) do + described_class.new(project: project).within_folders + end + + let(:resource) { Environment.all } + + subject { serializer.represent(resource) } + + context 'when there is a single environment' do + before { create(:environment, name: 'staging') } + + it 'represents one standalone environment' do + expect(subject.count).to eq 1 + expect(subject.first[:name]).to eq 'staging' + expect(subject.first[:size]).to eq 1 + expect(subject.first[:latest][:name]).to eq 'staging' + end + end + + context 'when there are multiple environments in folder' do + before do + create(:environment, name: 'staging/my-review-1') + create(:environment, name: 'staging/my-review-2') + end + + it 'represents one item that is a folder' do + expect(subject.count).to eq 1 + expect(subject.first[:name]).to eq 'staging' + expect(subject.first[:size]).to eq 2 + expect(subject.first[:latest][:name]).to eq 'staging/my-review-2' + expect(subject.first[:latest][:environment_type]).to eq 'staging' + end + end + + context 'when there are multiple folders and standalone environments' do + before do + create(:environment, name: 'staging/my-review-1') + create(:environment, name: 'staging/my-review-2') + create(:environment, name: 'production/my-review-3') + create(:environment, name: 'testing') + end + + it 'represents multiple items grouped within folders' do + expect(subject.count).to eq 3 + + expect(subject.first[:name]).to eq 'production' + expect(subject.first[:size]).to eq 1 + expect(subject.first[:latest][:name]).to eq 'production/my-review-3' + expect(subject.first[:latest][:environment_type]).to eq 'production' + expect(subject.second[:name]).to eq 'staging' + expect(subject.second[:size]).to eq 2 + expect(subject.second[:latest][:name]).to eq 'staging/my-review-2' + expect(subject.second[:latest][:environment_type]).to eq 'staging' + expect(subject.third[:name]).to eq 'testing' + expect(subject.third[:size]).to eq 1 + expect(subject.third[:latest][:name]).to eq 'testing' + expect(subject.third[:latest][:environment_type]).to be_nil + end + end + end + context 'when used with pagination' do let(:request) { spy('request') } let(:response) { spy('response') } @@ -99,6 +161,27 @@ describe EnvironmentSerializer do subject end end + + context 'when grouping environments within folders' do + let(:serializer) do + described_class.new(project: project) + .with_pagination(request, response) + .within_folders + end + + before do + create(:environment, name: 'staging/review-1') + create(:environment, name: 'staging/review-2') + create(:environment, name: 'production/deploy-3') + create(:environment, name: 'testing') + end + + it 'paginates grouped items including ordering' do + expect(subject.count).to eq 2 + expect(subject.first[:name]).to eq 'production' + expect(subject.second[:name]).to eq 'staging' + end + end end end end |