diff --git a/spec/controllers/user/registration_controller_spec.rb b/spec/controllers/user/registration_controller_spec.rb index c31f5670..59f10468 100644 --- a/spec/controllers/user/registration_controller_spec.rb +++ b/spec/controllers/user/registration_controller_spec.rb @@ -15,14 +15,15 @@ describe User::RegistrationsController, type: :controller do justask_admin retrospring_admin admin justask retrospring moderation moderator mod administrator siteadmin site_admin help retro_spring retroospring retrosprlng - ] - }) + ], + },) end describe "#create" do context "valid user sign up" do before do allow(APP_CONFIG).to receive(:dig).with(:hcaptcha, :enabled).and_return(true) + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(true) allow(controller).to receive(:verify_hcaptcha).and_return(captcha_successful) end @@ -32,8 +33,8 @@ describe User::RegistrationsController, type: :controller do screen_name: "dio", email: "the-world-21@somewhere.everywhere.now", password: "AReallySecurePassword456!", - password_confirmation: "AReallySecurePassword456!" - } + password_confirmation: "AReallySecurePassword456!", + }, } end @@ -59,6 +60,7 @@ describe User::RegistrationsController, type: :controller do context "invalid user sign up" do before do allow(APP_CONFIG).to receive(:dig).with(:hcaptcha, :enabled).and_return(false) + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(true) end subject { post :create, params: registration_params } @@ -70,8 +72,8 @@ describe User::RegistrationsController, type: :controller do screen_name: "", email: "", password: "", - password_confirmation: "" - } + password_confirmation: "", + }, } end @@ -87,8 +89,8 @@ describe User::RegistrationsController, type: :controller do screen_name: "Dio Brando", email: "the-world-21@somewhere.everywhere.now", password: "AReallySecurePassword456!", - password_confirmation: "AReallySecurePassword456!" - } + password_confirmation: "AReallySecurePassword456!", + }, } end @@ -104,8 +106,8 @@ describe User::RegistrationsController, type: :controller do screen_name: "moderator", email: "the-world-21@somewhere.everywhere.now", password: "AReallySecurePassword456!", - password_confirmation: "AReallySecurePassword456!" - } + password_confirmation: "AReallySecurePassword456!", + }, } end @@ -114,5 +116,33 @@ describe User::RegistrationsController, type: :controller do end end end + + context "when registrations are disabled" do + before do + allow(APP_CONFIG).to receive(:dig).with(:hcaptcha, :enabled).and_return(false) + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(false) + end + + it "redirects to the root page" do + subject + expect(response).to redirect_to(root_path) + end + end + end + + describe "#new" do + subject { get :new } + + context "when registrations are disabled" do + before do + allow(APP_CONFIG).to receive(:dig).with(:hcaptcha, :enabled).and_return(false) + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(false) + end + + it "redirects to the root page" do + subject + expect(response).to redirect_to(root_path) + end + end end end diff --git a/spec/views/about/index.html.haml_spec.rb b/spec/views/about/index.html.haml_spec.rb new file mode 100644 index 00000000..0551a9c8 --- /dev/null +++ b/spec/views/about/index.html.haml_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "about/index.html.haml", type: :view do + before do + stub_const("APP_CONFIG", { + "hostname" => "example.com", + "https" => true, + "sitename" => "yastask", + },) + end + + subject(:rendered) { render } + + context "registrations are enabled" do + before do + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(true) + end + + it "has references to registering now" do + expect(rendered).to match(/Register now/) + end + end + + context "registrations are disabled" do + before do + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(false) + end + + it "has no references to registering now" do + expect(rendered).to_not match(/Register now/) + end + end +end diff --git a/spec/views/navigation/_guest.html.haml_spec.rb b/spec/views/navigation/_guest.html.haml_spec.rb new file mode 100644 index 00000000..8f60c87d --- /dev/null +++ b/spec/views/navigation/_guest.html.haml_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "navigation/_guest.html.haml", type: :view do + subject(:rendered) do + render partial: "navigation/guest" + end + + context "registrations are enabled" do + before do + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(true) + end + + it "has a sign up link" do + expect(rendered).to match(/Sign up/) + end + end + + context "registrations are disabled" do + before do + allow(APP_CONFIG).to receive(:dig).with(:features, :registration, :enabled).and_return(false) + end + + it "has no sign up link" do + expect(rendered).to_not match(/Sign up/) + end + end +end