diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /spec/controllers/projects/static_site_editor_controller_spec.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/controllers/projects/static_site_editor_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/static_site_editor_controller_spec.rb | 87 |
1 files changed, 63 insertions, 24 deletions
diff --git a/spec/controllers/projects/static_site_editor_controller_spec.rb b/spec/controllers/projects/static_site_editor_controller_spec.rb index 7883c7e6f81..1cd32177e17 100644 --- a/spec/controllers/projects/static_site_editor_controller_spec.rb +++ b/spec/controllers/projects/static_site_editor_controller_spec.rb @@ -5,9 +5,11 @@ require 'spec_helper' RSpec.describe Projects::StaticSiteEditorController do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user) } - let(:data) { instance_double(Hash) } + let(:data) { { key: 'value' } } describe 'GET show' do + render_views + let(:default_params) do { namespace_id: project.namespace, @@ -50,41 +52,78 @@ RSpec.describe Projects::StaticSiteEditorController do end end - %w[developer maintainer].each do |role| - context "as #{role}" do - before_all do - project.add_role(user, role) + context "as developer" do + before do + project.add_role(user, 'developer') + sign_in(user) + get :show, params: default_params + end + + it 'renders the edit page' do + expect(response).to render_template(:show) + end + + it 'assigns ref and path variables' do + expect(assigns(:ref)).to eq('master') + expect(assigns(:path)).to eq('README.md') + end + + context 'when combination of ref and path is incorrect' do + let(:default_params) { super().merge(id: 'unknown') } + + it 'responds with 404 page' do + expect(response).to have_gitlab_http_status(:not_found) end + end + + context 'when invalid config file' do + let(:service_response) { ServiceResponse.error(message: 'invalid') } - before do - sign_in(user) - get :show, params: default_params + it 'redirects to project page and flashes error message' do + expect(response).to redirect_to(project_path(project)) + expect(response).to set_flash[:alert].to('invalid') end + end - it 'renders the edit page' do - expect(response).to render_template(:show) + context 'with a service response payload containing multiple data types' do + let(:data) do + { + a_string: 'string', + an_array: [ + { + foo: 'bar' + } + ], + an_integer: 123, + a_hash: { + a_deeper_hash: { + foo: 'bar' + } + }, + a_boolean: true + } end - it 'assigns a required variables' do - expect(assigns(:data)).to eq(data) - expect(assigns(:ref)).to eq('master') - expect(assigns(:path)).to eq('README.md') + let(:assigns_data) { assigns(:data) } + + it 'leaves data values which are strings as strings' do + expect(assigns_data[:a_string]).to eq('string') end - context 'when combination of ref and path is incorrect' do - let(:default_params) { super().merge(id: 'unknown') } + it 'leaves data values which are integers as integers' do + expect(assigns_data[:an_integer]).to eq(123) + end - it 'responds with 404 page' do - expect(response).to have_gitlab_http_status(:not_found) - end + it 'serializes data values which are booleans to JSON' do + expect(assigns_data[:a_boolean]).to eq('true') end - context 'when invalid config file' do - let(:service_response) { ServiceResponse.error(message: 'invalid') } + it 'serializes data values which are arrays to JSON' do + expect(assigns_data[:an_array]).to eq('[{"foo":"bar"}]') + end - it 'returns 422' do - expect(response).to have_gitlab_http_status(:unprocessable_entity) - end + it 'serializes data values which are hashes to JSON' do + expect(assigns_data[:a_hash]).to eq('{"a_deeper_hash":{"foo":"bar"}}') end end end |