diff options
author | Nick Thomas <nick@gitlab.com> | 2019-02-25 19:41:04 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-02-25 19:41:04 +0300 |
commit | 0b0a04fdf7ba31975407daa978f6f8f7c2f8bb3e (patch) | |
tree | 04b55a37cd1083728677208b3bc73bad98c0d067 /spec/requests/api/projects_spec.rb | |
parent | d63f3ea7da1fefbb9374b0b4b077f08b8a44d2f6 (diff) | |
parent | abe8cbe90b06f4355b6a783eb22bf46154569ec5 (diff) |
Merge branch 'zj-load-languages-from-database' into 'master'
Load repository language from the DB if detected
Closes #47390
See merge request gitlab-org/gitlab-ce!25518
Diffstat (limited to 'spec/requests/api/projects_spec.rb')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 494808e399f..792abdb2972 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -4,6 +4,15 @@ require 'spec_helper' shared_examples 'languages and percentages JSON response' do let(:expected_languages) { project.repository.languages.map { |language| language.values_at(:label, :value)}.to_h } + before do + allow(project.repository).to receive(:languages).and_return( + [{ value: 66.69, label: "Ruby", color: "#701516", highlight: "#701516" }, + { value: 22.98, label: "JavaScript", color: "#f1e05a", highlight: "#f1e05a" }, + { value: 7.91, label: "HTML", color: "#e34c26", highlight: "#e34c26" }, + { value: 2.42, label: "CoffeeScript", color: "#244776", highlight: "#244776" }] + ) + end + it 'returns expected language values' do get api("/projects/#{project.id}/languages", user) @@ -11,6 +20,23 @@ shared_examples 'languages and percentages JSON response' do expect(json_response).to eq(expected_languages) expect(json_response.count).to be > 1 end + + context 'when the languages were detected before' do + before do + Projects::DetectRepositoryLanguagesService.new(project, project.owner).execute + end + + it 'returns the detection from the database' do + # Allow this to happen once, so the expected languages can be determined + expect(project.repository).to receive(:languages).once + + get api("/projects/#{project.id}/languages", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to eq(expected_languages) + expect(json_response.count).to be > 1 + end + end end describe API::Projects do |