Commit 2e332607 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'issue_695' into 'master'

Use RequestStore to cache the contents of the current License

Fixes #695 

See merge request !566
parents fa84c23a 2c07734e
...@@ -14,21 +14,27 @@ class License < ActiveRecord::Base ...@@ -14,21 +14,27 @@ class License < ActiveRecord::Base
class << self class << self
def current def current
return @current if @current if RequestStore.active?
RequestStore.fetch(:current_license) { load_license }
license = self.last else
return unless license && license.valid? load_license
end
@current = license
end end
def reset_current def reset_current
@current = nil RequestStore.delete(:current_license)
end end
def block_changes? def block_changes?
!current || current.block_changes? !current || current.block_changes?
end end
def load_license
license = self.last
return unless license && license.valid?
license
end
end end
def data_filename def data_filename
......
...@@ -9,7 +9,8 @@ Feature: Admin license ...@@ -9,7 +9,8 @@ Feature: Admin license
Then I should see to whom the license is licensed Then I should see to whom the license is licensed
Scenario: Viewing license when there is none Scenario: Viewing license when there is none
Given I visit admin license page Given There is no license
And I visit admin license page
Then I should see a warning telling me there is no license Then I should see a warning telling me there is no license
And I should be redirected to the license upload page And I should be redirected to the license upload page
......
...@@ -10,6 +10,10 @@ class Spinach::Features::AdminLicense < Spinach::FeatureSteps ...@@ -10,6 +10,10 @@ class Spinach::Features::AdminLicense < Spinach::FeatureSteps
create(:license) create(:license)
end end
step 'there is no license' do
License.destroy_all
end
step 'I should see a warning telling me there is no license' do step 'I should see a warning telling me there is no license' do
expect(page).to have_content "No GitLab Enterprise Edition license has been provided yet." expect(page).to have_content "No GitLab Enterprise Edition license has been provided yet."
end end
......
require 'database_cleaner' require 'database_cleaner'
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation, { except: ['licenses'] }
Spinach.hooks.before_scenario do Spinach.hooks.before_scenario do
DatabaseCleaner.start DatabaseCleaner.start
......
...@@ -8,7 +8,7 @@ RSpec.configure do |config| ...@@ -8,7 +8,7 @@ RSpec.configure do |config|
end end
config.before(:each, js: true) do config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation, { except: ['licenses'] }
end end
config.before(:each) do config.before(:each) do
......
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