improve test setup with factory bot
This commit is contained in:
26
spec/factories/admin_users.rb
Normal file
26
spec/factories/admin_users.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: admin_users
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# email :string default(""), not null
|
||||
# encrypted_password :string default(""), not null
|
||||
# remember_created_at :datetime
|
||||
# reset_password_sent_at :datetime
|
||||
# reset_password_token :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_admin_users_on_email (email) UNIQUE
|
||||
# index_admin_users_on_reset_password_token (reset_password_token) UNIQUE
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :admin_user do
|
||||
sequence(:email) { |n| "admin-#{n}@example.com" }
|
||||
password { "password" }
|
||||
end
|
||||
end
|
||||
30
spec/factories/balances.rb
Normal file
30
spec/factories/balances.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: balances
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_balances_on_currency_id (currency_id)
|
||||
# index_balances_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :balance do
|
||||
association :user
|
||||
association :currency
|
||||
amount { (rand * (10000 - 0) + 0) }
|
||||
end
|
||||
end
|
||||
16
spec/factories/currencies.rb
Normal file
16
spec/factories/currencies.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: currencies
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :currency do
|
||||
name { "CAKE" }
|
||||
end
|
||||
end
|
||||
28
spec/factories/fiat_balances.rb
Normal file
28
spec/factories/fiat_balances.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: fiat_balances
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# amount_cents :integer default(0), not null
|
||||
# amount_currency :string default("BRL"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_fiat_balances_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :fiat_balance do
|
||||
association :user
|
||||
amount_currency { "BRL" }
|
||||
amount_cents { Faker::Number.number(digits: 10) }
|
||||
end
|
||||
end
|
||||
26
spec/factories/user_documents.rb
Normal file
26
spec/factories/user_documents.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: user_documents
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_user_documents_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :user_document do
|
||||
association :user
|
||||
status { :pending_review }
|
||||
end
|
||||
end
|
||||
30
spec/factories/users.rb
Normal file
30
spec/factories/users.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: users
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# email :string default(""), not null
|
||||
# encrypted_password :string default(""), not null
|
||||
# first_name :string not null
|
||||
# last_name :string not null
|
||||
# remember_created_at :datetime
|
||||
# reset_password_sent_at :datetime
|
||||
# reset_password_token :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_users_on_email (email) UNIQUE
|
||||
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
first_name { Faker::Name.first_name }
|
||||
last_name { Faker::Name.last_name }
|
||||
email { Faker::Internet.email }
|
||||
password { "password" }
|
||||
end
|
||||
end
|
||||
@@ -66,6 +66,9 @@ RSpec.configure do |config|
|
||||
config.filter_rails_from_backtrace!
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
|
||||
# Add FactoryBot
|
||||
config.include(FactoryBot::Syntax::Methods)
|
||||
end
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe("home/index.html.erb", type: :view) do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
it "render div with id root" do
|
||||
render
|
||||
|
||||
expect(rendered).to(eq("<div id=\"root\"></div>"))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user