From e53b350cb6db7438c1a50c500b324fd87afc41c4 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 7 Dec 2015 15:03:50 +0100 Subject: Add specs for showing lfs object in UI. --- spec/controllers/projects/raw_controller_spec.rb | 32 ++++++++++++++++++++++++ spec/support/test_env.rb | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index c114f342021..2329c246daa 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -33,5 +33,37 @@ describe Projects::RawController do expect(response.header['Content-Type']).to eq('image/jpeg') end end + + context 'lfs object' do + let(:id) { 'master/files/lfs/lfs_object.iso' } + let!(:lfs_object) { create(:lfs_object, oid: '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', size: '1575078') } + + context 'when project has access' do + before do + public_project.lfs_objects << lfs_object + end + + it 'serves the file' do + get(:show, + namespace_id: public_project.namespace.to_param, + project_id: public_project.to_param, + id: id) + + expect(response.status).to eq(200) + expect(response.header['Content-Type']).to eq('application/octet-stream') + end + end + + context 'when project does not have access' do + it 'does not serve the file' do + get(:show, + namespace_id: public_project.namespace.to_param, + project_id: public_project.to_param, + id: id) + + expect(response.status).to eq(404) + end + end + end end end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 787670e9297..47c67475cd0 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -12,7 +12,7 @@ module TestEnv 'fix' => '48f0be4', 'improve/awesome' => '5937ac0', 'markdown' => '0ed8c6c', - 'master' => '5937ac0', + 'master' => 'be93687', "'test'" => 'e56497b', } -- cgit v1.2.1 From 9bf51ae47d344c5939f275bb5ae429023456d30e Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Dec 2015 10:58:15 +0100 Subject: Fix specs caused by update of gitlab-test repo. --- spec/controllers/projects/raw_controller_spec.rb | 2 +- spec/support/test_env.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index 2329c246daa..cd42a592759 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -35,7 +35,7 @@ describe Projects::RawController do end context 'lfs object' do - let(:id) { 'master/files/lfs/lfs_object.iso' } + let(:id) { 'be93687/files/lfs/lfs_object.iso' } let!(:lfs_object) { create(:lfs_object, oid: '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', size: '1575078') } context 'when project has access' do diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 47c67475cd0..985bd141e69 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -12,7 +12,8 @@ module TestEnv 'fix' => '48f0be4', 'improve/awesome' => '5937ac0', 'markdown' => '0ed8c6c', - 'master' => 'be93687', + 'lfs' => 'be93687', + 'master' => '5937ac0', "'test'" => 'e56497b', } -- cgit v1.2.1 From ea5b462a1408f9fcd77dfd2961049057fc8ccad9 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Dec 2015 13:33:12 +0100 Subject: Stub the calls to disk and check what send_file returns. --- spec/controllers/projects/raw_controller_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index cd42a592759..42c6d4f3f88 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -41,16 +41,18 @@ describe Projects::RawController do context 'when project has access' do before do public_project.lfs_objects << lfs_object + allow_any_instance_of(LfsObjectUploader).to receive(:exists?).and_return(true) + allow(controller).to receive(:send_file) { controller.render :nothing => true } end it 'serves the file' do + expect(controller).to receive(:send_file).with("#{Gitlab.config.shared.path}/lfs-objects/91/ef/f75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", :filename => "lfs_object.iso", :disposition => 'attachment') get(:show, namespace_id: public_project.namespace.to_param, project_id: public_project.to_param, id: id) expect(response.status).to eq(200) - expect(response.header['Content-Type']).to eq('application/octet-stream') end end -- cgit v1.2.1 From 6245be083d985df3dd5daebb78ecf300bacff7b6 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Dec 2015 14:00:15 +0100 Subject: All for you rubocop. --- spec/controllers/projects/raw_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index 42c6d4f3f88..1caa476d37d 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -42,11 +42,11 @@ describe Projects::RawController do before do public_project.lfs_objects << lfs_object allow_any_instance_of(LfsObjectUploader).to receive(:exists?).and_return(true) - allow(controller).to receive(:send_file) { controller.render :nothing => true } + allow(controller).to receive(:send_file) { controller.render nothing: true } end it 'serves the file' do - expect(controller).to receive(:send_file).with("#{Gitlab.config.shared.path}/lfs-objects/91/ef/f75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", :filename => "lfs_object.iso", :disposition => 'attachment') + expect(controller).to receive(:send_file).with("#{Gitlab.config.shared.path}/lfs-objects/91/ef/f75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", filename: "lfs_object.iso", disposition: 'attachment') get(:show, namespace_id: public_project.namespace.to_param, project_id: public_project.to_param, -- cgit v1.2.1