diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-04-29 17:25:03 +0300 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-05-20 23:58:36 +0300 |
commit | e166a8022a3f239938a1449a0a8ce3485f309766 (patch) | |
tree | af9f612f599b01f5736e7b439f9579d77658f156 /spec | |
parent | 56eb42007ae8c3c390b35bf336884b3bad3591c5 (diff) |
Backend for a gitignores dropdown
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/gitignore_spec.rb | 38 | ||||
-rw-r--r-- | spec/requests/api/gitignores_spec.rb | 29 |
2 files changed, 67 insertions, 0 deletions
diff --git a/spec/lib/gitlab/gitignore_spec.rb b/spec/lib/gitlab/gitignore_spec.rb new file mode 100644 index 00000000000..5dab821a8ec --- /dev/null +++ b/spec/lib/gitlab/gitignore_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe Gitlab::Gitignore do + subject { Gitlab::Gitignore } + describe '.all' do + it 'strips the gitignore suffix' do + expect(subject.all.first.name).not_to end_with('.gitignore') + end + + it 'combines the globals and rest' do + all = subject.all.map(&:name) + + expect(all).to include('Vim') + expect(all).to include('Ruby') + end + end + + describe '.find' do + it 'returns nil if the file does not exist' do + expect(subject.find('mepmep-yadida')).to be nil + end + + it 'returns the Gitignore object of a valid file' do + ruby = subject.find('Ruby') + + expect(ruby).to be_a Gitlab::Gitignore + end + end + + describe '#content' do + it 'loads the full file' do + gitignore = subject.new('Ruby', File.expand_path('vendor/gitignore', Rails.root)) + + expect(gitignore.name).to eq 'Ruby' + expect(gitignore.content).to start_with('*.gem') + end + end +end diff --git a/spec/requests/api/gitignores_spec.rb b/spec/requests/api/gitignores_spec.rb new file mode 100644 index 00000000000..d0e576e637c --- /dev/null +++ b/spec/requests/api/gitignores_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe API::Gitignores, api: true do + include ApiHelpers + + describe 'Entity Gitignore' do + before { get api('/gitignores/Ruby') } + + it { expect(json_response['name']).to eq('Ruby') } + it { expect(json_response['content']).to include('*.gem') } + end + + describe 'Entity GitignoresList' do + before { get api('/gitignores') } + + it { expect(json_response.first['name']).to be_truthy } + it { expect(json_response.first['content']).to be_falsey } + end + + describe 'GET /gitignores' do + it 'returns a list of available license templates' do + get api('/gitignores') + + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.size).to be > 15 + end + end +end |