add conditional feature flag on quiz stats
closes CNVS-14678 This commit allows the quiz stats feature flag to be registered only when within the beta environment (or development or test). It should not be available in production. Test plan - Deploy normally to your QA portal. The 'quiz stats' feature flag should be available and operational. - Remove the testcluster.yml file from your config/ directory (or move / back it up to a safe place) - Restart your QA portal. - The quiz stats feature flag should not be available or visible. Change-Id: If51af6bae18b31fed8f7b2d666f59562ad0fb18e Reviewed-on: https://gerrit.instructure.com/39330 Reviewed-by: Derek DeVries <ddevries@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Josh Simpson <jsimpson@instructure.com>
This commit is contained in:
parent
9e26cd637f
commit
dea8c63410
|
@ -208,17 +208,6 @@ END
|
|||
beta: true,
|
||||
development: true
|
||||
},
|
||||
'quiz_stats' =>
|
||||
{
|
||||
display_name: -> { I18n.t('features.new_quiz_statistics', 'New Quiz Statistics Page') },
|
||||
description: -> { I18n.t('new_quiz_statistics_desc', <<-END) },
|
||||
When Draft State is allowed/on, this enables the new quiz statistics page for an account.
|
||||
END
|
||||
applies_to: 'Course',
|
||||
state: 'allowed',
|
||||
development: true,
|
||||
beta: true
|
||||
},
|
||||
'quiz_moderate' =>
|
||||
{
|
||||
display_name: -> { I18n.t('features.new_quiz_moderate', 'New Quiz Moderate Page') },
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# Copyright (C) 2014 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
module Features
|
||||
class QuizStatFeatureFlag
|
||||
def register!
|
||||
Feature.register(definition) if should_register?
|
||||
end
|
||||
|
||||
private
|
||||
def definition
|
||||
@definition ||= {
|
||||
'quiz_stats' =>
|
||||
{
|
||||
display_name: -> { I18n.t('features.new_quiz_statistics', 'New Quiz Statistics Page') },
|
||||
description: -> { I18n.t('new_quiz_statistics_desc', <<-END) },
|
||||
When Draft State is allowed/on, this enables the new quiz statistics page for an account.
|
||||
END
|
||||
applies_to: 'Course',
|
||||
state: 'allowed',
|
||||
development: true,
|
||||
beta: true
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def should_register?
|
||||
Rails.env.test? || Rails.env.development? || in_beta?
|
||||
end
|
||||
|
||||
def in_beta?
|
||||
Rails.env.production? && !!ConfigFile.load('testcluster', false).try(:[], 'test_cluster_name')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Features::QuizStatFeatureFlag.new.register!
|
|
@ -0,0 +1,87 @@
|
|||
#
|
||||
# Copyright (C) 2014 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
|
||||
|
||||
describe "Features::QuizStatFeatureFlag" do
|
||||
let(:account) { Account.default }
|
||||
context "enables the feature" do
|
||||
it "when in a development env" do
|
||||
remove_quiz_stats!
|
||||
flag = Features::QuizStatFeatureFlag.new
|
||||
|
||||
Rails.env.stubs(:test?).returns(false)
|
||||
Rails.env.stubs(:development?).returns(true)
|
||||
flag.register!
|
||||
|
||||
account.feature_allowed?('quiz_stats').should be_truthy
|
||||
end
|
||||
|
||||
it "when in a test env" do
|
||||
remove_quiz_stats!
|
||||
flag = Features::QuizStatFeatureFlag.new
|
||||
|
||||
Rails.env.stubs(:test?).returns(true)
|
||||
Rails.env.stubs(:development?).returns(false)
|
||||
flag.register!
|
||||
|
||||
account.feature_allowed?('quiz_stats').should be_truthy
|
||||
end
|
||||
|
||||
it "when in beta" do
|
||||
remove_quiz_stats!
|
||||
flag = Features::QuizStatFeatureFlag.new
|
||||
|
||||
Rails.env.stubs(:test?).returns(false)
|
||||
Rails.env.stubs(:development?).returns(false)
|
||||
flag.stubs(:in_beta?).returns(true)
|
||||
|
||||
flag.register!
|
||||
|
||||
account.feature_allowed?('quiz_stats').should be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context "doesn't enable the feature" do
|
||||
it "when in production" do
|
||||
remove_quiz_stats!
|
||||
flag = Features::QuizStatFeatureFlag.new
|
||||
|
||||
Rails.env.stubs(:test?).returns(false)
|
||||
Rails.env.stubs(:development?).returns(false)
|
||||
Rails.env.stubs(:production?).returns(true)
|
||||
|
||||
flag.register!
|
||||
|
||||
account.feature_allowed?('quiz_stats').should be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
def remove_quiz_stats!
|
||||
# need to strip quiz_stats from the frozen definitions hash on Feature
|
||||
features = {}
|
||||
Feature.definitions.each do |k, v|
|
||||
features[k] = v
|
||||
end
|
||||
|
||||
features.delete('quiz_stats')
|
||||
|
||||
Feature.instance_variable_set(:@features, features)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue