Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added test/dummy/app/assets/images/avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/dummy/app/assets/images/sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/dummy/app/madmin/resources/numerical_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class NumericalResource < Madmin::Resource
attribute :id, form: false
attribute :decimal
attribute :float
attribute :user, :belongs_to
attribute :created_at, form: false
attribute :updated_at, form: false

Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/madmin/resources/user_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class UserResource < Madmin::Resource
attribute :monthly_newsletter
attribute :avatar, index: false
attribute :something, :string, index: false, form: false
attribute :active
attribute :balance, field: Madmin::Fields::Currency
attribute :last_login_time
attribute :numerical

# Associations
attribute :posts, :nested_has_many, skip: %I[attachments]
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/models/numerical.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Numerical < ApplicationRecord
belongs_to :user
end
1 change: 1 addition & 0 deletions test/dummy/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class User < ApplicationRecord
has_many :comments, dependent: :destroy
has_and_belongs_to_many :habtms, join_table: :user_habtms, dependent: :destroy

has_one :numerical
has_one_attached :avatar
has_person_name
has_secure_password
Expand Down
9 changes: 9 additions & 0 deletions test/dummy/db/migrate/20240824221908_add_users_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddUsersAttributes < ActiveRecord::Migration[6.1]
def change
add_column :users, :active, :boolean, default: true
add_column :users, :balance, :decimal, precision: 10, scale: 2
add_column :users, :last_login_time, :time

add_reference :numericals, :user, foreign_key: true
end
end
6 changes: 6 additions & 0 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
t.float "float"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "user_id"
t.index ["user_id"], name: "index_numericals_on_user_id"
end

create_table "posts", force: :cascade do |t|
Expand Down Expand Up @@ -123,6 +125,9 @@
t.datetime "updated_at", precision: 6, null: false
t.json "settings"
t.text "preferences"
t.boolean "active", default: true
t.decimal "balance", precision: 10, scale: 2
t.time "last_login_time"
end

create_table "versions", force: :cascade do |t|
Expand All @@ -139,5 +144,6 @@
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "comments", "users"
add_foreign_key "numericals", "users"
add_foreign_key "user_connected_accounts", "users"
end
89 changes: 82 additions & 7 deletions test/dummy/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,91 @@
require 'action_mailbox/test_helper'
include ActionMailbox::TestHelper

10.times do
Numerical.create!(
decimal: rand(1..100).to_f,
float: rand(1..100).to_f
)
end

100.times do
user = User.create!(
first_name: FFaker::Name.first_name,
last_name: FFaker::Name.last_name,
birthday: Date.today,
password: "password"
birthday: FFaker::Time.between(80.years.ago, 18.years.ago).to_date,
password: "password",
ssn: FFaker::SSN.ssn,
preferences: { language: ['en', 'es', 'fr'].sample, notifications: [true, false].sample },
settings: { weekly_email: [true, false].sample, monthly_newsletter: [true, false].sample },
numerical: Numerical.all.sample,
active: [true, false].sample,
balance: rand(1..100).to_f,
last_login_time: FFaker::Time.between(1.year.ago, Time.now)
)
end

sample_image_blob = ActiveStorage::Blob.create_and_upload!(
io: File.open(Rails.root.join('app', 'assets', 'images', 'sample.jpg')),
filename: 'sample.jpg',
content_type: 'image/jpeg'
)

sample_avatar_blob = ActiveStorage::Blob.create_and_upload!(
io: File.open(Rails.root.join('app', 'assets', 'images', 'avatar.jpg')),
filename: 'avatar.png',
content_type: 'image/png'
)

# For pagination testing
100.times do
Post.create!(
title: FFaker::Lorem.sentence,
user:,
User.all.last(20).each do |user|

user.connected_accounts.create!(
service: ['facebook', 'google', 'twitter'].sample
)

3.times do
post = user.posts.create!(
title: FFaker::Music.song,
state: Post.states.keys.sample,
created_at: Time.now - rand(1..3).weeks
)

post.image.attach(sample_image_blob)
post.attachments.attach([sample_image_blob, sample_avatar_blob])

post.update(body: ActionText::Content.new(FFaker::Lorem.paragraphs.join("\n\n")))

3.times do
post.comments.create!(
user: User.all.sample,
body: FFaker::Lorem.paragraph
)
end
end
end

5.times do
habtm = Habtm.create!(name: FFaker::Lorem.word)
User.all.sample(10).each do |user|
user.habtms << habtm
end
end

User.all.each do |user|
user.avatar.attach(sample_avatar_blob)
end

10.times do
create_inbound_email_from_mail do |mail|
mail.to "recipient@example.com"
mail.from "sender@example.com"
mail.subject FFaker::Lorem.sentence

mail.text_part do |part|
part.body FFaker::Lorem.paragraph
end

mail.html_part do |part|
part.body "<p>#{FFaker::Lorem.paragraph}</p>"
end
end
end