Fix blinky test

pull/744/head
Rick Carlino 2018-03-24 09:16:17 -05:00
parent 0ba46da967
commit ed6fa145e4
3 changed files with 21 additions and 12 deletions

View File

@ -2,6 +2,7 @@
module Api
class GlobalConfigController < Api::AbstractController
skip_before_action :authenticate_user!
def show
render json: GlobalConfig.dump
end

View File

@ -18,11 +18,15 @@ class GlobalConfig < ApplicationRecord
# Memoized version of every GlobalConfig, with key/values layed out in a hash.
# Database values prempt values set in ::DEFAULTS
def self.dump
@dump ||= reload
@dump ||= reload_
end
def self.reload
@dump = DEFAULTS
.merge(GlobalConfig.all.map{ |x| {x.key => x.value} }.reduce({}, :merge))
def self.reload_
config_hash = GlobalConfig
.all
.map(&:reload)
.map{ |x| {x.key => x.value} }
.reduce({}, :merge)
@dump = DEFAULTS.merge(config_hash)
end
end

View File

@ -4,16 +4,20 @@ describe Api::GlobalConfigController do
include Devise::Test::ControllerHelpers
describe '#show' do
it 'shows / updates configs' do
conf = GlobalConfig.create!(key: "DYNAMIC", value: "Yup!")
conf = GlobalConfig.create!(key: "PING",
value: "INITIAL_" + SecureRandom.hex)
it 'shows configs' do
get :show
expect(json[:DYNAMIC]).to eq("Yup!")
conf.update_attributes!(value: "Still dynamic!")
GlobalConfig.reload
expect(json[:PING]).to eq(GlobalConfig.find_by(key: "PING").value)
end
it 'changes configs dynamically' do
value = SecureRandom.hex
conf.update_attributes!(value: value)
GlobalConfig.reload_
get :show
json
sleep 0.2 # WHY!?
expect(json[:DYNAMIC]).to eq("Still dynamic!")
expect(json[:PING]).to eq(value)
end
end
end