BigW Consortium Gitlab

Commit 3be9820d by Z.J. van de Weg

Test etag caching router and incorporate review

parent f0cd6ffd
...@@ -15,7 +15,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -15,7 +15,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
Gitlab::PollingInterval.set_header(response, interval: 15_000) Gitlab::PollingInterval.set_header(response, interval: 3_000)
render json: { render json: {
environments: EnvironmentSerializer environments: EnvironmentSerializer
......
...@@ -12,6 +12,7 @@ class Deployment < ActiveRecord::Base ...@@ -12,6 +12,7 @@ class Deployment < ActiveRecord::Base
delegate :name, to: :environment, prefix: true delegate :name, to: :environment, prefix: true
after_create :create_ref after_create :create_ref
after_create :invalidate_cache
def commit def commit
project.commit(sha) project.commit(sha)
...@@ -33,6 +34,10 @@ class Deployment < ActiveRecord::Base ...@@ -33,6 +34,10 @@ class Deployment < ActiveRecord::Base
project.repository.create_ref(ref, ref_path) project.repository.create_ref(ref, ref_path)
end end
def invalidate_cache
environment.expire_etag_cache
end
def manual_actions def manual_actions
@manual_actions ||= deployable.try(:other_actions) @manual_actions ||= deployable.try(:other_actions)
end end
......
require 'spec_helper' require 'spec_helper'
describe Projects::EnvironmentsController do describe Projects::EnvironmentsController do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:project) { create(:empty_project) } set(:project) { create(:empty_project) }
let(:environment) do set(:environment) do
create(:environment, name: 'production', project: project) create(:environment, name: 'production', project: project)
end end
before do before do
project.team << [user, :master] project.add_master(user)
sign_in(user) sign_in(user)
end end
...@@ -57,6 +57,11 @@ describe Projects::EnvironmentsController do ...@@ -57,6 +57,11 @@ describe Projects::EnvironmentsController do
expect(json_response['available_count']).to eq 3 expect(json_response['available_count']).to eq 3
expect(json_response['stopped_count']).to eq 1 expect(json_response['stopped_count']).to eq 1
end end
it 'sets the polling interval header' do
expect(response).to have_http_status(:ok)
expect(response.headers['Poll-Interval']).to eq("3000")
end
end end
context 'when requesting stopped environments scope' do context 'when requesting stopped environments scope' do
......
...@@ -84,7 +84,8 @@ describe Gitlab::EtagCaching::Router do ...@@ -84,7 +84,8 @@ describe Gitlab::EtagCaching::Router do
result = described_class.match(env) result = described_class.match(env)
expect(result).to be_blank expect(result).to be_present
expect(result.name).to eq 'environments'
end end
def build_env(path) def build_env(path)
......
...@@ -16,6 +16,14 @@ describe Deployment, models: true do ...@@ -16,6 +16,14 @@ describe Deployment, models: true do
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:sha) }
describe 'after_create callbacks' do
it 'invalidates the cache for the environment' do
expect(subject).to receive(:invalidate_cache)
subject.save!
end
end
describe '#includes_commit?' do describe '#includes_commit?' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:environment) { create(:environment, project: project) } let(:environment) { create(:environment, project: project) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment