Setup Faker and Factorybot
All checks were successful
CI / scan_ruby (push) Successful in 20s
CI / scan_js (push) Successful in 11s
CI / lint (push) Successful in 11s
CI / test (push) Successful in 33s

This commit is contained in:
sto 2025-03-27 09:27:25 +01:00
parent 12f9f33034
commit 7023600cd1
9 changed files with 58 additions and 12 deletions

View File

@ -56,6 +56,8 @@ group :development, :test do
gem "rubocop-rails-omakase", require: false
gem "rspec-rails"
gem "factory_bot_rails"
gem "faker"
end
group :development do

View File

@ -119,6 +119,13 @@ GEM
et-orbi (1.2.11)
tzinfo
execjs (2.10.0)
factory_bot (6.5.1)
activesupport (>= 6.1.0)
factory_bot_rails (6.4.4)
factory_bot (~> 6.5)
railties (>= 5.0.0)
faker (3.5.1)
i18n (>= 1.8.11, < 2)
friendly_id (5.5.1)
activerecord (>= 4.0.0)
fugit (1.11.1)
@ -423,6 +430,8 @@ DEPENDENCIES
capybara
dartsass-rails
debug
factory_bot_rails
faker
friendly_id (~> 5.5.0)
importmap-rails
jbuilder

View File

@ -4,6 +4,7 @@ class SessionsController < ApplicationController
before_action :skip_authorization
def new
@title = "Login"
end
def create

View File

@ -1,11 +0,0 @@
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
<%= form_with url: session_path do |form| %>
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %><br>
<%= form.submit "Sign in" %>
<% end %>
<br>
<%= link_to "Forgot password?", new_password_path %>

View File

@ -0,0 +1,13 @@
= form_with url: session_path do |form|
.row.mb-3
.col
.form-floating
= form.email_field :email_address, autocomplete: "username", required: true, autofocus: true, class: "form-control"
= form.label :email_address, class: "required"
.row.mb-3
.col
.form-floating
= form.password_field :password, autocomplete: "current-password", required: true, autofocus: true, class: "form-control", maxlength: 72
= form.label :password, class: "required"
= form.submit "Sign in"

7
spec/factories/users.rb Normal file
View File

@ -0,0 +1,7 @@
FactoryBot.define do
factory :user do
username { Faker::Internet.username }
email_address { Faker::Internet.email }
password { Faker::Internet.password(min_length: 12, max_length: 18) }
end
end

View File

@ -0,0 +1,20 @@
require 'rails_helper'
RSpec.feature "Contests", type: :feature do
context "visiting the home page" do
let!(:user) { create(:user) }
before do
visit '/'
fill_in "Email address", with: user.email_address
fill_in "Password", with: user.password
click_button "Sign in"
end
it "should display the username" do
visit root_path
expect(page).to have_content(user.username)
end
end
end

View File

@ -23,7 +23,7 @@ require 'rspec/rails'
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.

View File

@ -0,0 +1,5 @@
require "factory_bot_rails"
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end