summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-05-26 15:47:54 +0200
committerMarin Jankovski <marin@gitlab.com>2014-05-26 15:47:54 +0200
commitf8a6d3405ea3a25f5b0776241831deb037020fc6 (patch)
tree2a3e5fae9a42da7edde4ce6f4e49e024365034d4 /spec
parent3b2b3cff04993c7247e953c10aa8c6fb5e8d6ddb (diff)
downloadgitlab-ce-f8a6d3405ea3a25f5b0776241831deb037020fc6.tar.gz
Add image_service spec.
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects_controller_spec.rb3
-rw-r--r--spec/services/projects/image_service_spec.rb65
2 files changed, 65 insertions, 3 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 1d465d4996e..7a772396e8b 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -3,10 +3,7 @@ require('spec_helper')
describe ProjectsController do
let(:project) { create(:project) }
let(:user) { create(:user) }
- let(:png) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png') }
let(:jpg) { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') }
- let(:gif) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
- let(:txt) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') }
describe "POST #upload_image" do
before do
diff --git a/spec/services/projects/image_service_spec.rb b/spec/services/projects/image_service_spec.rb
new file mode 100644
index 00000000000..0311e312b5d
--- /dev/null
+++ b/spec/services/projects/image_service_spec.rb
@@ -0,0 +1,65 @@
+require 'spec_helper'
+
+describe Projects::ImageService do
+ before(:each) { enable_observers }
+ after(:each) { disable_observers }
+
+ describe 'Image service' do
+ before do
+ @user = create :user
+ @project = create :project, creator_id: @user.id, namespace: @user.namespace
+ end
+
+ context 'for valid gif file' do
+ before do
+ gif = fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif')
+ @link_to_image = upload_image(@project.repository, { 'markdown_img' => gif }, "http://test.example/")
+ end
+
+ it { expect(@link_to_image).to have_key("alt") }
+ it { expect(@link_to_image).to have_key("url") }
+ it { expect(@link_to_image).to have_value("banana_sample") }
+ it { expect(@link_to_image["url"]).to match("http://test.example/uploads/#{@project.path_with_namespace}") }
+ it { expect(@link_to_image["url"]).to match("banana_sample.gif") }
+ end
+
+ context 'for valid png file' do
+ before do
+ png = fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png')
+ @link_to_image = upload_image(@project.repository, { 'markdown_img' => png }, "http://test.example/")
+ end
+
+ it { expect(@link_to_image).to have_key("alt") }
+ it { expect(@link_to_image).to have_key("url") }
+ it { expect(@link_to_image).to have_value("dk") }
+ it { expect(@link_to_image["url"]).to match("http://test.example/uploads/#{@project.path_with_namespace}") }
+ it { expect(@link_to_image["url"]).to match("dk.png") }
+ end
+
+ context 'for valid jpg file' do
+ before do
+ jpg = fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg')
+ @link_to_image = upload_image(@project.repository, { 'markdown_img' => jpg }, "http://test.example/")
+ end
+
+ it { expect(@link_to_image).to have_key("alt") }
+ it { expect(@link_to_image).to have_key("url") }
+ it { expect(@link_to_image).to have_value("rails_sample") }
+ it { expect(@link_to_image["url"]).to match("http://test.example/uploads/#{@project.path_with_namespace}") }
+ it { expect(@link_to_image["url"]).to match("rails_sample.jpg") }
+ end
+
+ context 'for txt file' do
+ before do
+ txt = fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain')
+ @link_to_image = upload_image(@project.repository, { 'markdown_img' => txt }, "http://test.example/")
+ end
+
+ it { expect(@link_to_image).to be_nil }
+ end
+ end
+
+ def upload_image(repository, params, root_url)
+ Projects::ImageService.new(repository, params, root_url).execute
+ end
+end