From 3613bc445de3a820536ae140c2009467742d97d0 Mon Sep 17 00:00:00 2001 From: James Smith Date: Thu, 8 Aug 2024 21:34:39 +0100 Subject: [PATCH 1/6] ignore vscode workspace --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1a167e01c..a22f0bb0c 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,6 @@ docker-compose.yml # ignore asdf config files /.tool-versions dump.rdb + +# IDE workspace files +*.code-workspace From 78346131bf14f87b8f2f6dae19a6adbcc2c7e569 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 9 Aug 2024 10:43:02 +0100 Subject: [PATCH 2/6] remove flipper gem --- Gemfile | 3 --- Gemfile.lock | 7 ------- 2 files changed, 10 deletions(-) diff --git a/Gemfile b/Gemfile index 11260bbf5..42b8848de 100644 --- a/Gemfile +++ b/Gemfile @@ -115,9 +115,6 @@ gem "translation", "~> 1.41", group: :development gem "string-similarity", "~> 2.1" -gem "flipper", "~> 1.3" -gem "flipper-active_record", "~> 1.3" - gem "rolify", "~> 6.0" gem "letter_opener", "~> 1.10", group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 889299ff8..fce56864b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -257,11 +257,6 @@ GEM ffi (1.17.0-x86_64-linux-gnu) ffi-libarchive (1.1.14) ffi (~> 1.0) - flipper (1.3.0) - concurrent-ruby (< 2) - flipper-active_record (1.3.0) - activerecord (>= 4.2, < 8) - flipper (~> 1.3.0) formatador (1.1.0) formtastic (5.0.0) actionpack (>= 6.0.0) @@ -713,8 +708,6 @@ DEPENDENCIES faker (~> 3.4) federails! ffi-libarchive (~> 1.1) - flipper (~> 1.3) - flipper-active_record (~> 1.3) guard (~> 2.18) guard-rspec (~> 4.7) i18n-js (~> 4.2) From c3c4bd284ff8647631bbb309033571f79396dd1c Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 9 Aug 2024 10:58:06 +0100 Subject: [PATCH 3/6] don't load dotenv in test mode avoids pollution of tests with dev settings --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 42b8848de..79836f8e1 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem "redis", "~> 5.2" # Use Active Storage variant # gem 'image_processing', '~> 1.2' -gem "dotenv-rails", "~> 3.1" +gem "dotenv-rails", "~> 3.1", group: :development gem "acts-as-taggable-on", "~> 10.0" gem "ffi-libarchive", "~> 1.1" From 15df20c58193da4ba324c6e8e1328c974d40e709 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 9 Aug 2024 11:23:33 +0100 Subject: [PATCH 4/6] move feature flags out of flipper and into site config and SiteSettings --- app/models/site_settings.rb | 16 ++++++++++++++-- config/application.rb | 7 +++++++ config/initializers/flipper.rb | 32 -------------------------------- 3 files changed, 21 insertions(+), 34 deletions(-) delete mode 100644 config/initializers/flipper.rb diff --git a/app/models/site_settings.rb b/app/models/site_settings.rb index d65374767..d251c53b8 100644 --- a/app/models/site_settings.rb +++ b/app/models/site_settings.rb @@ -13,11 +13,11 @@ class SiteSettings < RailsSettings::Base field :analyse_manifold, type: :boolean, default: false field :anonymous_usage_id, type: :string, default: nil - def self.registration_enabled + def self.registration_enabled? ENV.fetch("REGISTRATION", false) == "enabled" end - def self.email_configured + def self.email_configured? !Rails.env.production? || ENV.fetch("SMTP_SERVER", false) end @@ -29,6 +29,18 @@ def self.max_file_extract_size ENV.fetch("MAX_FILE_EXTRACT_SIZE", 1_073_741_824).to_i end + def self.demo_mode_enabled? + Rails.application.config.manyfold_features[:demo_mode] + end + + def self.multiuser_enabled? + Rails.application.config.manyfold_features[:multiuser] + end + + def self.federation_enabled? + Rails.application.config.manyfold_features[:federation] + end + module UserDefaults RENDERER = { grid_width: 200, diff --git a/config/application.rb b/config/application.rb index c68dbf412..fb26d989c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -61,6 +61,13 @@ class Application < Rails::Application user_name: ENV.fetch("SMTP_USERNAME", nil), password: ENV.fetch("SMTP_PASSWORD", nil) }.compact + + # Load some feature settings from ENV + config.manyfold_features = { + multiuser: (ENV.fetch("MULTIUSER", nil) == "enabled"), + federation: (ENV.fetch("FEDERATION", nil) == "enabled"), + demo_mode: (ENV.fetch("DEMO_MODE", nil) == "enabled") + } end end diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb deleted file mode 100644 index a264f566a..000000000 --- a/config/initializers/flipper.rb +++ /dev/null @@ -1,32 +0,0 @@ -begin - # This file sets up the various flags that we use to control large-scale features - # using Flipper, a feature flagging gem. - - # This isn't strictly necessary to do, but it keeps a list in one place, and removes - # some log warnings when checking features that haven't been enabled yet. - - # Note: We're using Flipper for local settings only, no cloud features. - - Flipper.add :demo_mode - if ENV.fetch("DEMO_MODE", nil) == "enabled" - Flipper.enable :demo_mode - else - Flipper.disable :demo_mode - end - - Flipper.add :multiuser - if ENV.fetch("MULTIUSER", nil) == "enabled" - Flipper.enable :multiuser - else - Flipper.disable :multiuser - end - - Flipper.add :federation - if ENV.fetch("FEDERATION", nil) == "enabled" - Flipper.enable :federation - else - Flipper.disable :federation - end -rescue ActiveRecord::StatementInvalid - # If we've not migrated Flipper yet, we'll get an exception, which we can swallow -end From 99bcfd01a2d44aee45dd1d7287ffcb81887a67ee Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 9 Aug 2024 11:26:18 +0100 Subject: [PATCH 5/6] swap flipper checks for SiteSettings checks --- app/components/follow_button_component.rb | 2 +- app/controllers/users/sessions_controller.rb | 2 +- app/policies/application_policy.rb | 2 +- app/policies/federails/following_policy.rb | 4 ++-- app/policies/library_policy.rb | 2 +- app/policies/model_policy.rb | 2 +- app/policies/upload_policy.rb | 2 +- app/policies/user_policy.rb | 12 ++++++------ app/policies/users/passwords_policy.rb | 4 ++-- app/policies/users/registrations_policy.rb | 2 +- app/policies/users/sessions_policy.rb | 4 ++-- app/views/activity/index.html.erb | 2 +- app/views/application/_navbar.html.erb | 2 +- app/views/devise/registrations/edit.html.erb | 2 +- app/views/home/index.html.erb | 2 +- app/views/settings/_multiuser_settings.html.erb | 6 +++--- app/views/settings/show.html.erb | 2 +- config/initializers/active_admin.rb | 2 +- config/initializers/federails.rb | 8 +------- config/routes.rb | 10 ++-------- spec/components/follow_button_component_spec.rb | 2 +- spec/requests/users/registrations_spec.rb | 4 ++-- 22 files changed, 34 insertions(+), 46 deletions(-) diff --git a/app/components/follow_button_component.rb b/app/components/follow_button_component.rb index f8f26c314..3dbf5cdcf 100644 --- a/app/components/follow_button_component.rb +++ b/app/components/follow_button_component.rb @@ -14,7 +14,7 @@ def before_render end def render? - Flipper.enabled? :multiuser + SiteSettings.multiuser_enabled? end erb_template <<-ERB diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index c5a727166..1636d5078 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -36,7 +36,7 @@ def auto_login_single_user create_admin_user if User.with_role(:administrator).empty? # If in single user mode, or on first run, # automatically log in with an admin account - if !Flipper.enabled?(:multiuser) || User.with_role(:administrator).first.reset_password_token == "first_use" + if !SiteSettings.multiuser_enabled? || User.with_role(:administrator).first.reset_password_token == "first_use" sign_in(:user, User.with_role(:administrator).first) flash.discard redirect_back_or_to root_path, alert: nil diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 80afb1a2d..02fe753d4 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -36,7 +36,7 @@ def destroy? all_of( user&.is_editor?, none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end diff --git a/app/policies/federails/following_policy.rb b/app/policies/federails/following_policy.rb index 64cd5e8ee..bb7eb4518 100644 --- a/app/policies/federails/following_policy.rb +++ b/app/policies/federails/following_policy.rb @@ -1,13 +1,13 @@ class Federails::FollowingPolicy < ApplicationPolicy def create? all_of( - Flipper.enabled?(:multiuser) + SiteSettings.multiuser_enabled? ) end def destroy? all_of( - Flipper.enabled?(:multiuser) + SiteSettings.multiuser_enabled? ) end diff --git a/app/policies/library_policy.rb b/app/policies/library_policy.rb index 73965e958..b7f2b1d49 100644 --- a/app/policies/library_policy.rb +++ b/app/policies/library_policy.rb @@ -3,7 +3,7 @@ def create? all_of( user&.is_administrator?, none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end diff --git a/app/policies/model_policy.rb b/app/policies/model_policy.rb index e51564f8f..ef96b7fc6 100644 --- a/app/policies/model_policy.rb +++ b/app/policies/model_policy.rb @@ -9,7 +9,7 @@ def merge? all_of( user&.is_editor?, none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end diff --git a/app/policies/upload_policy.rb b/app/policies/upload_policy.rb index 41d1fa429..6a91d56ca 100644 --- a/app/policies/upload_policy.rb +++ b/app/policies/upload_policy.rb @@ -7,7 +7,7 @@ def create? all_of( user&.is_contributor?, none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 3a278ce36..b7198b237 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -3,7 +3,7 @@ def index? all_of( user&.is_administrator?, none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end @@ -19,13 +19,13 @@ def show? def create? all_of( - Flipper.enabled?(:multiuser), + SiteSettings.multiuser_enabled?, one_of( - SiteSettings.registration_enabled, + SiteSettings.registration_enabled?, user&.is_administrator? ), none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end @@ -43,9 +43,9 @@ def destroy? user == record, user&.is_administrator? ), - Flipper.enabled?(:multiuser), + SiteSettings.multiuser_enabled?, none_of( - Flipper.enabled?(:demo_mode) + SiteSettings.demo_mode_enabled? ) ) end diff --git a/app/policies/users/passwords_policy.rb b/app/policies/users/passwords_policy.rb index 51cb9b29b..d2b1a4133 100644 --- a/app/policies/users/passwords_policy.rb +++ b/app/policies/users/passwords_policy.rb @@ -2,10 +2,10 @@ class Users::PasswordsPolicy < ApplicationPolicy def create? - Flipper.enabled?(:multiuser) && SiteSettings.email_configured + SiteSettings.multiuser_enabled? && SiteSettings.email_configured? end def update? - Flipper.enabled?(:multiuser) && SiteSettings.email_configured + SiteSettings.multiuser_enabled? && SiteSettings.email_configured? end end diff --git a/app/policies/users/registrations_policy.rb b/app/policies/users/registrations_policy.rb index 7b5f913dc..462556797 100644 --- a/app/policies/users/registrations_policy.rb +++ b/app/policies/users/registrations_policy.rb @@ -2,6 +2,6 @@ class Users::RegistrationsPolicy < ApplicationPolicy def cancel? - Flipper.enabled?(:multiuser) + SiteSettings.multiuser_enabled? end end diff --git a/app/policies/users/sessions_policy.rb b/app/policies/users/sessions_policy.rb index 586de5c8e..94d3f9ead 100644 --- a/app/policies/users/sessions_policy.rb +++ b/app/policies/users/sessions_policy.rb @@ -6,10 +6,10 @@ def new? end def create? - Flipper.enabled?(:multiuser) + SiteSettings.multiuser_enabled? end def destroy? - Flipper.enabled?(:multiuser) + SiteSettings.multiuser_enabled? end end diff --git a/app/views/activity/index.html.erb b/app/views/activity/index.html.erb index dd8856d38..23e688588 100644 --- a/app/views/activity/index.html.erb +++ b/app/views/activity/index.html.erb @@ -4,7 +4,7 @@
<%= t ".description", retention_period: distance_of_time_in_words(ActiveJob::Status.options[:expires_in]) %>
- <% if !Flipper.enabled?(:demo_mode) %> + <% if !SiteSettings.demo_mode_enabled? %>
<%= link_to safe_join([icon("activity", t(".sidekiq")), t(".sidekiq")], " "), "/sidekiq", diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index a82eb7d99..0b0129f33 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -81,7 +81,7 @@ <%= f.search_field :q, class: "form-control ms-1 me-3", placeholder: translate(".search"), aria_label: translate(".search"), aria_describedby: "button-search", value: params[:q] %> <% end %> - <%- if Flipper.enabled? :multiuser %> + <%- if SiteSettings.multiuser_enabled? %> <%- if current_user %>
- <%- if Flipper.enabled? :multiuser %> + <%- if SiteSettings.multiuser_enabled? %>

<%= t ".danger_zone" %>

diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index f9e0a0550..41db7accb 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -2,7 +2,7 @@ <%= render "application/content_header" %>

<%= t "application.title" %>

<%= t "application.tagline" %>

- <% if Flipper.enabled? :demo_mode %> + <% if SiteSettings.demo_mode_enabled? %>
<%= t "application.demo_mode" %>
diff --git a/app/views/settings/_multiuser_settings.html.erb b/app/views/settings/_multiuser_settings.html.erb index ba19c10ef..15dc08ae6 100644 --- a/app/views/settings/_multiuser_settings.html.erb +++ b/app/views/settings/_multiuser_settings.html.erb @@ -2,11 +2,11 @@

<%= t(".heading") %>

- <%= Flipper.enabled?(:multiuser) ? t(".multiuser_mode") : t(".single_user_mode") %> + <%= SiteSettings.multiuser_enabled? ? t(".multiuser_mode") : t(".single_user_mode") %>

- <% if Flipper.enabled?(:multiuser) %> + <% if SiteSettings.multiuser_enabled? %>

- <%= SiteSettings.registration_enabled ? t(".registrations_open") : t(".registrations_closed") %> + <%= SiteSettings.registration_enabled? ? t(".registrations_open") : t(".registrations_closed") %>

<% end %>

diff --git a/app/views/settings/show.html.erb b/app/views/settings/show.html.erb index 76674284a..e1ba272c8 100644 --- a/app/views/settings/show.html.erb +++ b/app/views/settings/show.html.erb @@ -39,7 +39,7 @@

- <% if current_user.is_administrator? && !Flipper.enabled?(:demo_mode) %> + <% if current_user.is_administrator? && !SiteSettings.demo_mode_enabled? %>
<%= link_to safe_join([icon("tools", t(".advanced_admin")), t(".advanced_admin")], " "), "/admin", diff --git a/config/initializers/active_admin.rb b/config/initializers/active_admin.rb index ae8c24041..65c6dcdca 100644 --- a/config/initializers/active_admin.rb +++ b/config/initializers/active_admin.rb @@ -140,7 +140,7 @@ # Active Admin resources and pages from here. # config.before_action do - raise Pundit::NotAuthorizedError, I18n.t("active_admin.demo_mode") if Flipper.enabled? :demo_mode + raise Pundit::NotAuthorizedError, I18n.t("active_admin.demo_mode") if SiteSettings.demo_mode_enabled? end # == Attribute Filters diff --git a/config/initializers/federails.rb b/config/initializers/federails.rb index 7e0fb5e7f..07d694e19 100644 --- a/config/initializers/federails.rb +++ b/config/initializers/federails.rb @@ -1,11 +1,5 @@ # frozen_string_literal: true -federation_enabled = begin - Flipper.enabled?(:federation) -rescue ActiveRecord::StatementInvalid - false -end - Federails.configure do |conf| conf.app_name = "Manyfold" conf.app_version = Rails.application.config.app_version @@ -14,7 +8,7 @@ conf.site_port = Rails.application.default_url_options[:port] conf.force_ssl = Rails.application.config.force_ssl - conf.enable_discovery = federation_enabled + conf.enable_discovery = Rails.application.config.manyfold_features[:federation] conf.server_routes_path = "federation" conf.client_routes_path = "client" diff --git a/config/routes.rb b/config/routes.rb index e46e8ce02..1e9237e51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,11 +18,7 @@ resources :activity end - begin - mount Federails::Engine => "/" if Flipper.enabled?(:multiuser) - rescue ActiveRecord::StatementInvalid - nil - end + mount Federails::Engine => "/" if Rails.application.config.manyfold_features[:multiuser] resources :users, only: [] do resource :settings, only: [:show, :update] @@ -40,15 +36,13 @@ end concern :followable do |options| - if Flipper.enabled?(:multiuser) + if Rails.application.config.manyfold_features[:multiuser] resources :follows, {only: [:create]}.merge(options) do collection do delete "/", action: "destroy" end end end - rescue ActiveRecord::StatementInvalid - nil end resources :models do diff --git a/spec/components/follow_button_component_spec.rb b/spec/components/follow_button_component_spec.rb index 6dd86afb1..39dbe3c9b 100644 --- a/spec/components/follow_button_component_spec.rb +++ b/spec/components/follow_button_component_spec.rb @@ -4,7 +4,7 @@ RSpec.describe FollowButtonComponent, type: :component do before do - allow(Flipper).to receive(:enabled?).with(:multiuser).and_return true + allow(SiteSettings).to receive(:multiuser_enabled?).and_return(true) end let(:follower) { create(:user) } diff --git a/spec/requests/users/registrations_spec.rb b/spec/requests/users/registrations_spec.rb index 9ade67b0b..f584e718b 100644 --- a/spec/requests/users/registrations_spec.rb +++ b/spec/requests/users/registrations_spec.rb @@ -138,7 +138,7 @@ context "when in multiuser mode with closed registrations", :multiuser do before do - allow(SiteSettings).to receive(:registration_enabled).and_return(false) + allow(SiteSettings).to receive(:registration_enabled?).and_return(false) end context "when signed out" do @@ -258,7 +258,7 @@ context "when in multiuser mode with open registrations", :multiuser do before do - allow(SiteSettings).to receive(:registration_enabled).and_return(true) + allow(SiteSettings).to receive(:registration_enabled?).and_return(true) end context "when signed out" do From 10d6494de9e5a506b4093047121ddd3c66544235 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 9 Aug 2024 11:26:42 +0100 Subject: [PATCH 6/6] mode demo mode check in specs into metadata --- spec/requests/admin/collections_spec.rb | 3 +-- spec/requests/admin/creators_spec.rb | 3 +-- spec/requests/admin/dashboard_spec.rb | 3 +-- spec/requests/admin/link_spec.rb | 3 +-- spec/requests/admin/log_spec.rb | 3 +-- spec/requests/admin/model_files_spec.rb | 3 +-- spec/requests/admin/models_spec.rb | 3 +-- spec/requests/admin/problem_spec.rb | 3 +-- spec/requests/admin/tags_spec.rb | 3 +-- spec/support/features.rb | 9 +++++++++ spec/support/multiuser.rb | 6 ------ 11 files changed, 18 insertions(+), 24 deletions(-) create mode 100644 spec/support/features.rb delete mode 100644 spec/support/multiuser.rb diff --git a/spec/requests/admin/collections_spec.rb b/spec/requests/admin/collections_spec.rb index d4dd74ff2..a6f82a971 100644 --- a/spec/requests/admin/collections_spec.rb +++ b/spec/requests/admin/collections_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/collections") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/creators_spec.rb b/spec/requests/admin/creators_spec.rb index 5aeb9195b..07c2e6bf4 100644 --- a/spec/requests/admin/creators_spec.rb +++ b/spec/requests/admin/creators_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/creators") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/dashboard_spec.rb b/spec/requests/admin/dashboard_spec.rb index e525973d0..d0f3c117a 100644 --- a/spec/requests/admin/dashboard_spec.rb +++ b/spec/requests/admin/dashboard_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/link_spec.rb b/spec/requests/admin/link_spec.rb index 0c9538e03..2d3857b8b 100644 --- a/spec/requests/admin/link_spec.rb +++ b/spec/requests/admin/link_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/links") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/log_spec.rb b/spec/requests/admin/log_spec.rb index 686a6d814..481e5e084 100644 --- a/spec/requests/admin/log_spec.rb +++ b/spec/requests/admin/log_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/log") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/model_files_spec.rb b/spec/requests/admin/model_files_spec.rb index 9ddb738c3..8247a55e1 100644 --- a/spec/requests/admin/model_files_spec.rb +++ b/spec/requests/admin/model_files_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/model_files") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/models_spec.rb b/spec/requests/admin/models_spec.rb index cbeff7e6f..86922a5df 100644 --- a/spec/requests/admin/models_spec.rb +++ b/spec/requests/admin/models_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/models") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/problem_spec.rb b/spec/requests/admin/problem_spec.rb index 2c9368882..ee40bc59c 100644 --- a/spec/requests/admin/problem_spec.rb +++ b/spec/requests/admin/problem_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/problems") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/admin/tags_spec.rb b/spec/requests/admin/tags_spec.rb index 4f6458c2a..cf21b935d 100644 --- a/spec/requests/admin/tags_spec.rb +++ b/spec/requests/admin/tags_spec.rb @@ -12,8 +12,7 @@ expect(response).to have_http_status(:success) end - it "is inaccessible in demo mode" do - Flipper.enable :demo_mode + it "is inaccessible in demo mode", :demo_mode do expect { get("/admin/acts_as_taggable_on_tags") }.to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/support/features.rb b/spec/support/features.rb new file mode 100644 index 000000000..703e72e88 --- /dev/null +++ b/spec/support/features.rb @@ -0,0 +1,9 @@ +RSpec.configure do |config| + config.before(:each, :multiuser) do + allow(SiteSettings).to receive(:multiuser_enabled?).and_return(true) + end + + config.before(:each, :demo_mode) do + allow(SiteSettings).to receive(:demo_mode_enabled?).and_return(true) + end +end diff --git a/spec/support/multiuser.rb b/spec/support/multiuser.rb deleted file mode 100644 index 94403a904..000000000 --- a/spec/support/multiuser.rb +++ /dev/null @@ -1,6 +0,0 @@ -RSpec.configure do |config| - config.before(:each, :multiuser) do - allow(Flipper).to receive(:enabled?).and_call_original - allow(Flipper).to receive(:enabled?).with(:multiuser).and_return(true) - end -end