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
respond_to do |format|
format.html
format.json do
Gitlab::PollingInterval.set_header(response, interval: 15_000)
Gitlab::PollingInterval.set_header(response, interval: 3_000)
render json: {
environments: EnvironmentSerializer
......
......@@ -12,6 +12,7 @@ class Deployment < ActiveRecord::Base
delegate :name, to: :environment, prefix: true
after_create :create_ref
after_create :invalidate_cache
def commit
project.commit(sha)
......@@ -33,6 +34,10 @@ class Deployment < ActiveRecord::Base
project.repository.create_ref(ref, ref_path)
end
def invalidate_cache
environment.expire_etag_cache
end
def manual_actions
@manual_actions ||= deployable.try(:other_actions)
end
......
require 'spec_helper'
describe Projects::EnvironmentsController do
let(:user) { create(:user) }
let(:project) { create(:empty_project) }
set(:user) { create(:user) }
set(:project) { create(:empty_project) }
let(:environment) do
set(:environment) do
create(:environment, name: 'production', project: project)
end
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......@@ -57,6 +57,11 @@ describe Projects::EnvironmentsController do
expect(json_response['available_count']).to eq 3
expect(json_response['stopped_count']).to eq 1
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
context 'when requesting stopped environments scope' do
......
......@@ -84,7 +84,8 @@ describe Gitlab::EtagCaching::Router do
result = described_class.match(env)
expect(result).to be_blank
expect(result).to be_present
expect(result.name).to eq 'environments'
end
def build_env(path)
......
......@@ -16,6 +16,14 @@ describe Deployment, models: true do
it { is_expected.to validate_presence_of(:ref) }
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
let(:project) { create(:project, :repository) }
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