Skip to content

Commit

Permalink
Don't render signup link if registration feature is disabled (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgomes authored May 24, 2024
1 parent 55c91cd commit 0a9cd15
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
8 changes: 5 additions & 3 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

<h2 class='text-3xl font-semibold'>Welcome back</h2>

<span class='text-sm text-center'>
Don't have an account? <%= link_to "Sign up", register_path, class: "underline" %>
</span>
<% if Feature.registration? %>
<span class='text-sm text-center'>
Don't have an account? <%= link_to "Sign up", register_path, class: "underline" %>
</span>
<% end %>

<%= form_with(url: login_path, method: :post, class: "flex flex-col space-y-4 w-80") do |f| %>
<%= f.email_field :email,
Expand Down
20 changes: 2 additions & 18 deletions test/models/feature_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "test_helper"

class FeatureTest < ActiveSupport::TestCase
include FeatureHelpers

test "should return value of feature" do
stub_features(my_feature: true) do
assert Feature.enabled?(:my_feature)
Expand Down Expand Up @@ -65,22 +67,4 @@ class FeatureTest < ActiveSupport::TestCase
refute Feature.google_authentication?
end
end

private

def stub_features(hash, &block)
Feature.features_hash = nil
Feature.stub :features, hash do
yield
end
Feature.features_hash = nil
end

def stub_raw_features(hash, &block)
Feature.features_hash = nil
Feature.stub :raw_features, hash do
yield
end
Feature.features_hash = nil
end
end
20 changes: 20 additions & 0 deletions test/support/feature_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module FeatureHelpers

private

def stub_features(hash, &block)
Feature.features_hash = nil
Feature.stub :features, hash do
yield
end
Feature.features_hash = nil
end

def stub_raw_features(hash, &block)
Feature.features_hash = nil
Feature.stub :raw_features, hash do
yield
end
Feature.features_hash = nil
end
end
9 changes: 9 additions & 0 deletions test/system/users_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "application_system_test_case"

class UsersTest < ApplicationSystemTestCase
include FeatureHelpers

setup do
@user = users(:keith)
visit root_url
Expand Down Expand Up @@ -37,6 +39,13 @@ class UsersTest < ApplicationSystemTestCase
assert_text "can't be blank"
end

test "should hide the Sign Up link if the registration feature is disabled" do
stub_features(registration: false) do
visit root_url
assert_no_text 'Sign up'
end
end

test "should create a new user" do
click_text "Sign up", match: :first

Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "minitest/autorun"
require "pry"

require_relative 'support/feature_helpers'

class Capybara::Node::Element
def obsolete?
inspect.include?('Obsolete')
Expand Down Expand Up @@ -57,4 +59,4 @@ class TestCase
ActiveStorage::Current.reset
end
end
end
end

0 comments on commit 0a9cd15

Please sign in to comment.