summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--certs/test/functional/certs_controller_test.rb17
-rw-r--r--core/test/support/with_config_helper.rb16
2 files changed, 28 insertions, 5 deletions
diff --git a/certs/test/functional/certs_controller_test.rb b/certs/test/functional/certs_controller_test.rb
index 70ca56d..7826dd6 100644
--- a/certs/test/functional/certs_controller_test.rb
+++ b/certs/test/functional/certs_controller_test.rb
@@ -20,13 +20,20 @@ class CertsControllerTest < ActionController::TestCase
end
test "login required if free certs disabled" do
- begin
- old_setting = APP_CONFIG[:free_certs_enabled]
- APP_CONFIG[:free_certs_enabled] = false
+ with_config free_certs_enabled: false do
get :show
assert_response :redirect
- ensure
- APP_CONFIG[:free_certs_enabled] = old_setting
+ end
+ end
+
+ test "get paid cert if free certs disabled" do
+ with_config free_certs_enabled: false do
+ login
+ cert = stub :to_s => "real cert"
+ ClientCertificate.expects(:new).with(free: false).returns(cert)
+ get :show
+ assert_response :success
+ assert_equal cert.to_s, @response.body
end
end
diff --git a/core/test/support/with_config_helper.rb b/core/test/support/with_config_helper.rb
new file mode 100644
index 0000000..65eb7bc
--- /dev/null
+++ b/core/test/support/with_config_helper.rb
@@ -0,0 +1,16 @@
+module WithConfigHelper
+ extend ActiveSupport::Concern
+
+ def with_config(options)
+ old_config = APP_CONFIG.dup
+ APP_CONFIG.merge! options
+ yield
+ ensure
+ APP_CONFIG.replace old_config
+ end
+
+end
+
+class ActiveSupport::TestCase
+ include WithConfigHelper
+end