Skip to content

Commit

Permalink
- Added faker gem
Browse files Browse the repository at this point in the history
- Generated 100 salaries for seeding db
  • Loading branch information
sabiou committed Feb 10, 2023
1 parent fd6ef73 commit 6706d8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .idea/niger_salaires.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ gem "turbo-rails", "1.1.1"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails", "1.0.4"

# Faker
gem "faker", "3.1.1"

# Use sqlite3 as the database for Active Record
# gem "sqlite3", "~> 1.4"

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ GEM
irb (>= 1.3.6)
reline (>= 0.2.7)
erubi (1.12.0)
faker (3.1.1)
i18n (>= 1.8.11, < 2)
globalid (1.0.1)
activesupport (>= 5.0)
i18n (1.12.0)
Expand Down Expand Up @@ -223,6 +225,7 @@ DEPENDENCIES
bootsnap (= 1.12.0)
capybara (= 3.37.1)
debug (= 1.5.0)
faker (= 3.1.1)
importmap-rails (= 1.1.0)
jbuilder (= 2.11.5)
pagy (~> 6.0)
Expand Down
17 changes: 10 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
# Character.create(name: "Luke", movie: movies.first)
# generate 100 salaries with Faker

99.times do |n|
title = Faker::Job.title
company = Faker::Company.name
city = Faker::Address.city
seniority = Faker::Number.between(from: 0, to: 3)
salary = Faker::Number.between(from: 100000, to: 800000)
Salary.create!(title: title, company: company, city: city, seniority: seniority, salary: salary)
end

0 comments on commit 6706d8a

Please sign in to comment.