diff --git a/test/dummy/app/assets/images/avatar.jpg b/test/dummy/app/assets/images/avatar.jpg new file mode 100644 index 00000000..1c7ac46b Binary files /dev/null and b/test/dummy/app/assets/images/avatar.jpg differ diff --git a/test/dummy/app/assets/images/sample.jpg b/test/dummy/app/assets/images/sample.jpg new file mode 100644 index 00000000..ecde5ec0 Binary files /dev/null and b/test/dummy/app/assets/images/sample.jpg differ diff --git a/test/dummy/app/madmin/resources/numerical_resource.rb b/test/dummy/app/madmin/resources/numerical_resource.rb index 76a90b0b..c812bbca 100644 --- a/test/dummy/app/madmin/resources/numerical_resource.rb +++ b/test/dummy/app/madmin/resources/numerical_resource.rb @@ -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 diff --git a/test/dummy/app/madmin/resources/user_resource.rb b/test/dummy/app/madmin/resources/user_resource.rb index 29fe5195..e66f793e 100644 --- a/test/dummy/app/madmin/resources/user_resource.rb +++ b/test/dummy/app/madmin/resources/user_resource.rb @@ -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] diff --git a/test/dummy/app/models/numerical.rb b/test/dummy/app/models/numerical.rb index ef7e6b72..c59ceb20 100644 --- a/test/dummy/app/models/numerical.rb +++ b/test/dummy/app/models/numerical.rb @@ -1,2 +1,3 @@ class Numerical < ApplicationRecord + belongs_to :user end diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb index 93717bc6..6a6d9ee0 100644 --- a/test/dummy/app/models/user.rb +++ b/test/dummy/app/models/user.rb @@ -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 diff --git a/test/dummy/db/migrate/20240824221908_add_users_attributes.rb b/test/dummy/db/migrate/20240824221908_add_users_attributes.rb new file mode 100644 index 00000000..c75747a2 --- /dev/null +++ b/test/dummy/db/migrate/20240824221908_add_users_attributes.rb @@ -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 diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 5d5096c7..c3d857ea 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -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| @@ -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| @@ -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 diff --git a/test/dummy/db/seeds.rb b/test/dummy/db/seeds.rb index f2ae33cf..b77f0c85 100644 --- a/test/dummy/db/seeds.rb +++ b/test/dummy/db/seeds.rb @@ -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 "
#{FFaker::Lorem.paragraph}
" + end end end \ No newline at end of file