Setup Faker and Factorybot
This commit is contained in:
parent
12f9f33034
commit
7023600cd1
2
Gemfile
2
Gemfile
@ -56,6 +56,8 @@ group :development, :test do
|
|||||||
gem "rubocop-rails-omakase", require: false
|
gem "rubocop-rails-omakase", require: false
|
||||||
|
|
||||||
gem "rspec-rails"
|
gem "rspec-rails"
|
||||||
|
gem "factory_bot_rails"
|
||||||
|
gem "faker"
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
|
@ -119,6 +119,13 @@ GEM
|
|||||||
et-orbi (1.2.11)
|
et-orbi (1.2.11)
|
||||||
tzinfo
|
tzinfo
|
||||||
execjs (2.10.0)
|
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)
|
friendly_id (5.5.1)
|
||||||
activerecord (>= 4.0.0)
|
activerecord (>= 4.0.0)
|
||||||
fugit (1.11.1)
|
fugit (1.11.1)
|
||||||
@ -423,6 +430,8 @@ DEPENDENCIES
|
|||||||
capybara
|
capybara
|
||||||
dartsass-rails
|
dartsass-rails
|
||||||
debug
|
debug
|
||||||
|
factory_bot_rails
|
||||||
|
faker
|
||||||
friendly_id (~> 5.5.0)
|
friendly_id (~> 5.5.0)
|
||||||
importmap-rails
|
importmap-rails
|
||||||
jbuilder
|
jbuilder
|
||||||
|
@ -4,6 +4,7 @@ class SessionsController < ApplicationController
|
|||||||
before_action :skip_authorization
|
before_action :skip_authorization
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@title = "Login"
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -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 %>
|
|
13
app/views/sessions/new.html.slim
Normal file
13
app/views/sessions/new.html.slim
Normal 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
7
spec/factories/users.rb
Normal 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
|
20
spec/features/contest_spec.rb
Normal file
20
spec/features/contest_spec.rb
Normal 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
|
@ -23,7 +23,7 @@ require 'rspec/rails'
|
|||||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||||
# require only the support files necessary.
|
# 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.
|
# Checks for pending migrations and applies them before tests are run.
|
||||||
# If you are not using ActiveRecord, you can remove these lines.
|
# If you are not using ActiveRecord, you can remove these lines.
|
||||||
|
5
spec/support/factory_bot.rb
Normal file
5
spec/support/factory_bot.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
require "factory_bot_rails"
|
||||||
|
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.include FactoryBot::Syntax::Methods
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user