about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2017-05-30 19:32:09 +0900
committerMatt Jankowski <mjankowski@thoughtbot.com>2017-05-30 06:32:09 -0400
commit67bc58dd60645a9451899e3368ae40a1edd4806c (patch)
tree18ebfa33655cebe363e7bdfe38bf3c9a15f6b7da
parent2d39560dc1811c29c1663b11a4a351089898e244 (diff)
Use around hook to restore context in Admin::SettingsController spec (#3428)
-rw-r--r--spec/controllers/admin/settings_controller_spec.rb36
1 files changed, 26 insertions, 10 deletions
diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb
index 7fd49a0f1..d9dde3c92 100644
--- a/spec/controllers/admin/settings_controller_spec.rb
+++ b/spec/controllers/admin/settings_controller_spec.rb
@@ -47,20 +47,36 @@ RSpec.describe Admin::SettingsController, type: :controller do
         end
       end
 
-      it 'updates a settings value' do
-        Setting.site_title = 'Original'
-        patch :update, params: { site_title: 'New title' }
+      context do
+        around do |example|
+          site_title = Setting.site_title
+          example.run
+          Setting.site_title = site_title
+        end
 
-        expect(response).to redirect_to(edit_admin_settings_path)
-        expect(Setting.site_title).to eq 'New title'
+        it 'updates a settings value' do
+          Setting.site_title = 'Original'
+          patch :update, params: { site_title: 'New title' }
+
+          expect(response).to redirect_to(edit_admin_settings_path)
+          expect(Setting.site_title).to eq 'New title'
+        end
       end
 
-      it 'typecasts open_registrations to boolean' do
-        Setting.open_registrations = false
-        patch :update, params: { open_registrations: 'true' }
+      context do
+        around do |example|
+          open_registrations = Setting.open_registrations
+          example.run
+          Setting.open_registrations = open_registrations
+        end
 
-        expect(response).to redirect_to(edit_admin_settings_path)
-        expect(Setting.open_registrations).to eq true
+        it 'typecasts open_registrations to boolean' do
+          Setting.open_registrations = false
+          patch :update, params: { open_registrations: 'true' }
+
+          expect(response).to redirect_to(edit_admin_settings_path)
+          expect(Setting.open_registrations).to eq true
+        end
       end
     end
   end