Commit f8a6d3405ea3a25f5b0776241831deb037020fc6
1 parent
3b2b3cff
Exists in
spb-stable
and in
2 other branches
Add image_service spec.
Showing
2 changed files
with
65 additions
and
3 deletions
Show diff stats
spec/controllers/projects_controller_spec.rb
@@ -3,10 +3,7 @@ require('spec_helper') | @@ -3,10 +3,7 @@ require('spec_helper') | ||
3 | describe ProjectsController do | 3 | describe ProjectsController do |
4 | let(:project) { create(:project) } | 4 | let(:project) { create(:project) } |
5 | let(:user) { create(:user) } | 5 | let(:user) { create(:user) } |
6 | - let(:png) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png') } | ||
7 | let(:jpg) { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') } | 6 | let(:jpg) { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') } |
8 | - let(:gif) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } | ||
9 | - let(:txt) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') } | ||
10 | 7 | ||
11 | describe "POST #upload_image" do | 8 | describe "POST #upload_image" do |
12 | before do | 9 | before do |
@@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe Projects::ImageService do | ||
4 | + before(:each) { enable_observers } | ||
5 | + after(:each) { disable_observers } | ||
6 | + | ||
7 | + describe 'Image service' do | ||
8 | + before do | ||
9 | + @user = create :user | ||
10 | + @project = create :project, creator_id: @user.id, namespace: @user.namespace | ||
11 | + end | ||
12 | + | ||
13 | + context 'for valid gif file' do | ||
14 | + before do | ||
15 | + gif = fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') | ||
16 | + @link_to_image = upload_image(@project.repository, { 'markdown_img' => gif }, "http://test.example/") | ||
17 | + end | ||
18 | + | ||
19 | + it { expect(@link_to_image).to have_key("alt") } | ||
20 | + it { expect(@link_to_image).to have_key("url") } | ||
21 | + it { expect(@link_to_image).to have_value("banana_sample") } | ||
22 | + it { expect(@link_to_image["url"]).to match("http://test.example/uploads/#{@project.path_with_namespace}") } | ||
23 | + it { expect(@link_to_image["url"]).to match("banana_sample.gif") } | ||
24 | + end | ||
25 | + | ||
26 | + context 'for valid png file' do | ||
27 | + before do | ||
28 | + png = fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png') | ||
29 | + @link_to_image = upload_image(@project.repository, { 'markdown_img' => png }, "http://test.example/") | ||
30 | + end | ||
31 | + | ||
32 | + it { expect(@link_to_image).to have_key("alt") } | ||
33 | + it { expect(@link_to_image).to have_key("url") } | ||
34 | + it { expect(@link_to_image).to have_value("dk") } | ||
35 | + it { expect(@link_to_image["url"]).to match("http://test.example/uploads/#{@project.path_with_namespace}") } | ||
36 | + it { expect(@link_to_image["url"]).to match("dk.png") } | ||
37 | + end | ||
38 | + | ||
39 | + context 'for valid jpg file' do | ||
40 | + before do | ||
41 | + jpg = fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') | ||
42 | + @link_to_image = upload_image(@project.repository, { 'markdown_img' => jpg }, "http://test.example/") | ||
43 | + end | ||
44 | + | ||
45 | + it { expect(@link_to_image).to have_key("alt") } | ||
46 | + it { expect(@link_to_image).to have_key("url") } | ||
47 | + it { expect(@link_to_image).to have_value("rails_sample") } | ||
48 | + it { expect(@link_to_image["url"]).to match("http://test.example/uploads/#{@project.path_with_namespace}") } | ||
49 | + it { expect(@link_to_image["url"]).to match("rails_sample.jpg") } | ||
50 | + end | ||
51 | + | ||
52 | + context 'for txt file' do | ||
53 | + before do | ||
54 | + txt = fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') | ||
55 | + @link_to_image = upload_image(@project.repository, { 'markdown_img' => txt }, "http://test.example/") | ||
56 | + end | ||
57 | + | ||
58 | + it { expect(@link_to_image).to be_nil } | ||
59 | + end | ||
60 | + end | ||
61 | + | ||
62 | + def upload_image(repository, params, root_url) | ||
63 | + Projects::ImageService.new(repository, params, root_url).execute | ||
64 | + end | ||
65 | +end |