forked from e621ng/e621ng
Fix test fixtures and seeds
This commit is contained in:
parent
a665b526a1
commit
fffe6b1c19
44
db/seeds.rb
44
db/seeds.rb
@ -4,9 +4,11 @@ require "digest/md5"
|
||||
require "net/http"
|
||||
require "tempfile"
|
||||
|
||||
puts "== Creating elasticsearch indices ==\n"
|
||||
unless Rails.env.test?
|
||||
puts "== Creating elasticsearch indices ==\n"
|
||||
|
||||
Post.__elasticsearch__.create_index!
|
||||
Post.__elasticsearch__.create_index!
|
||||
end
|
||||
|
||||
puts "== Seeding database with sample content ==\n"
|
||||
|
||||
@ -16,30 +18,32 @@ puts "== Seeding database with sample content ==\n"
|
||||
admin = User.find_or_create_by!(name: "admin") do |user|
|
||||
user.created_at = 2.weeks.ago
|
||||
user.password = "e621test"
|
||||
user.email = "admin@e621"
|
||||
user.email = "admin@e621.net"
|
||||
user.can_upload_free = true
|
||||
user.level = User::Levels::ADMIN
|
||||
end
|
||||
|
||||
CurrentUser.user = admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
unless Rails.env.test?
|
||||
CurrentUser.user = admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
resources = YAML.load_file Rails.root.join("db", "seeds.yml")
|
||||
resources["images"].each do |image|
|
||||
puts image["url"]
|
||||
resources = YAML.load_file Rails.root.join("db", "seeds.yml")
|
||||
resources["images"].each do |image|
|
||||
puts image["url"]
|
||||
|
||||
data = Net::HTTP.get(URI(image["url"]))
|
||||
file = Tempfile.new.binmode
|
||||
file.write data
|
||||
data = Net::HTTP.get(URI(image["url"]))
|
||||
file = Tempfile.new.binmode
|
||||
file.write data
|
||||
|
||||
md5 = Digest::MD5.hexdigest(data)
|
||||
service = UploadService.new({
|
||||
file: file,
|
||||
tag_string: image["tags"],
|
||||
rating: "s",
|
||||
md5: md5,
|
||||
md5_confirmation: md5
|
||||
})
|
||||
md5 = Digest::MD5.hexdigest(data)
|
||||
service = UploadService.new({
|
||||
file: file,
|
||||
tag_string: image["tags"],
|
||||
rating: "s",
|
||||
md5: md5,
|
||||
md5_confirmation: md5
|
||||
})
|
||||
|
||||
service.start!
|
||||
service.start!
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:artist) do
|
||||
name {rand(1_000_000).to_s}
|
||||
is_active true
|
||||
is_active { true }
|
||||
association :creator, factory: :user
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,6 @@ FactoryBot.define do
|
||||
factory(:ban) do |f|
|
||||
banner :factory => :admin_user
|
||||
reason {FFaker::Lorem.words.join(" ")}
|
||||
duration 60
|
||||
duration { 60 }
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:bulk_update_request) do |f|
|
||||
title "xxx"
|
||||
script "create alias aaa -> bbb"
|
||||
skip_secondary_validations true
|
||||
title { "xxx" }
|
||||
script { "create alias aaa -> bbb" }
|
||||
skip_secondary_validations { true }
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory(:comment_vote) do
|
||||
score 1
|
||||
score { 1 }
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +1,12 @@
|
||||
FactoryBot.define do
|
||||
factory(:forum_topic) do
|
||||
title {FFaker::Lorem.words.join(" ")}
|
||||
is_sticky false
|
||||
is_locked false
|
||||
category_id 0
|
||||
is_sticky { false }
|
||||
is_locked { false }
|
||||
category_id { 0 }
|
||||
|
||||
factory(:mod_up_forum_topic) do
|
||||
min_level User::Levels::MODERATOR
|
||||
min_level { User::Levels::MODERATOR }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,8 @@
|
||||
FactoryBot.define do
|
||||
factory(:mod_action) do
|
||||
creator :factory => :user
|
||||
description "1234"
|
||||
action { "1234" }
|
||||
category { 3 }
|
||||
values { {a: 'b'} }
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory(:news_update) do
|
||||
message "xxx"
|
||||
message { "xxx" }
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
FactoryBot.define do
|
||||
factory(:note) do
|
||||
post
|
||||
x 1
|
||||
y 1
|
||||
width 1
|
||||
height 1
|
||||
is_active true
|
||||
x { 1 }
|
||||
y { 1 }
|
||||
width { 1 }
|
||||
height { 1 }
|
||||
is_active { true }
|
||||
body {FFaker::Lorem.sentences.join(" ")}
|
||||
end
|
||||
end
|
||||
|
@ -4,15 +4,15 @@ FactoryBot.define do
|
||||
n.to_s
|
||||
end
|
||||
uploader :factory => :user
|
||||
uploader_ip_addr "127.0.0.1"
|
||||
tag_string "tag1 tag2"
|
||||
tag_count 2
|
||||
tag_count_general 2
|
||||
file_ext "jpg"
|
||||
image_width 1500
|
||||
image_height 1000
|
||||
file_size 2000
|
||||
rating "q"
|
||||
uploader_ip_addr { "127.0.0.1" }
|
||||
tag_string { "tag1 tag2" }
|
||||
tag_count { 2 }
|
||||
tag_count_general { 2 }
|
||||
file_ext { "jpg" }
|
||||
image_width { 1500 }
|
||||
image_height { 1000 }
|
||||
file_size { 2000 }
|
||||
rating { "q" }
|
||||
source { FFaker::Internet.http_url }
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory(:post_appeal) do
|
||||
reason "xxx"
|
||||
reason { "xxx" }
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:post_flag) do
|
||||
reason "xxx"
|
||||
is_resolved false
|
||||
reason { "xxx" }
|
||||
is_resolved { false }
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
FactoryBot.define do
|
||||
factory(:tag) do
|
||||
name {"#{FFaker::Name.first_name.downcase}#{rand(1000)}"}
|
||||
post_count 0
|
||||
post_count { 0 }
|
||||
category {Tag.categories.general}
|
||||
related_tags ""
|
||||
related_tags { "" }
|
||||
related_tags_updated_at {Time.now}
|
||||
|
||||
factory(:artist_tag) do
|
||||
|
@ -1,9 +1,9 @@
|
||||
FactoryBot.define do
|
||||
factory :tag_alias do
|
||||
antecedent_name "aaa"
|
||||
consequent_name "bbb"
|
||||
status "active"
|
||||
skip_secondary_validations true
|
||||
antecedent_name { "aaa" }
|
||||
consequent_name { "bbb" }
|
||||
status { "active" }
|
||||
skip_secondary_validations { true }
|
||||
creator_ip_addr { FFaker::Internet.ip_v4_address }
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
FactoryBot.define do
|
||||
factory :tag_implication do
|
||||
antecedent_name "aaa"
|
||||
consequent_name "bbb"
|
||||
status "active"
|
||||
skip_secondary_validations true
|
||||
antecedent_name { "aaa" }
|
||||
consequent_name { "bbb" }
|
||||
status { "active" }
|
||||
skip_secondary_validations { true }
|
||||
end
|
||||
end
|
||||
|
@ -2,16 +2,16 @@ require 'fileutils'
|
||||
|
||||
FactoryBot.define do
|
||||
factory(:upload) do
|
||||
rating "s"
|
||||
rating { "s" }
|
||||
uploader :factory => :user, :level => 20
|
||||
uploader_ip_addr "127.0.0.1"
|
||||
tag_string "special"
|
||||
status "pending"
|
||||
server Socket.gethostname
|
||||
source "xxx"
|
||||
uploader_ip_addr { "127.0.0.1" }
|
||||
tag_string { "special" }
|
||||
status { "pending" }
|
||||
server { Socket.gethostname }
|
||||
source { "xxx" }
|
||||
|
||||
factory(:source_upload) do
|
||||
source "http://www.google.com/intl/en_ALL/images/logo.gif"
|
||||
source { "http://www.google.com/intl/en_ALL/images/logo.gif" }
|
||||
end
|
||||
|
||||
factory(:ugoira_upload) do
|
||||
|
@ -3,61 +3,56 @@ FactoryBot.define do
|
||||
sequence :name do |n|
|
||||
"user#{n}"
|
||||
end
|
||||
password "password"
|
||||
password_hash {PasswordHash.create_hash("password")}
|
||||
password { "password" }
|
||||
bcrypt_password_hash {User.bcrypt("password")}
|
||||
email {FFaker::Internet.email}
|
||||
default_image_size "large"
|
||||
base_upload_limit 10
|
||||
level 20
|
||||
default_image_size { "large" }
|
||||
base_upload_limit { 10 }
|
||||
level { 20 }
|
||||
created_at {Time.now}
|
||||
last_logged_in_at {Time.now}
|
||||
favorite_count 0
|
||||
bit_prefs 0
|
||||
bit_prefs { 0 }
|
||||
|
||||
factory(:banned_user) do
|
||||
transient { ban_duration 3 }
|
||||
is_banned true
|
||||
transient { ban_duration { 3 } }
|
||||
is_banned { true }
|
||||
end
|
||||
|
||||
factory(:member_user) do
|
||||
level 20
|
||||
level { 20 }
|
||||
end
|
||||
|
||||
factory(:privileged_user) do
|
||||
level 30
|
||||
end
|
||||
|
||||
factory(:contributor_user) do
|
||||
level 31
|
||||
level { 30 }
|
||||
end
|
||||
|
||||
factory(:janitor_user) do
|
||||
level 35
|
||||
level { 35 }
|
||||
end
|
||||
|
||||
factory(:contributor_user) do
|
||||
level 32
|
||||
bit_prefs User.flag_value_for("can_upload_free")
|
||||
level { 32 }
|
||||
bit_prefs { User.flag_value_for("can_upload_free") }
|
||||
end
|
||||
|
||||
factory(:contrib_user) do
|
||||
level 32
|
||||
bit_prefs User.flag_value_for("can_upload_free")
|
||||
level { 32 }
|
||||
bit_prefs { User.flag_value_for("can_upload_free") }
|
||||
end
|
||||
|
||||
factory(:moderator_user) do
|
||||
level 40
|
||||
can_approve_posts true
|
||||
level { 40 }
|
||||
can_approve_posts { true }
|
||||
end
|
||||
|
||||
factory(:mod_user) do
|
||||
level 40
|
||||
can_approve_posts true
|
||||
level { 40 }
|
||||
can_approve_posts { true }
|
||||
end
|
||||
|
||||
factory(:admin_user) do
|
||||
level 50
|
||||
can_approve_posts true
|
||||
level { 50 }
|
||||
can_approve_posts { true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:user_feedback) do
|
||||
user
|
||||
category "positive"
|
||||
category { "positive" }
|
||||
body {FFaker::Lorem.words.join(" ")}
|
||||
end
|
||||
end
|
||||
|
@ -84,6 +84,7 @@ class ActiveSupport::TestCase
|
||||
storage_manager = StorageManager::Local.new(base_dir: "#{Rails.root}/tmp/test-storage2")
|
||||
Danbooru.config.stubs(:storage_manager).returns(storage_manager)
|
||||
Danbooru.config.stubs(:backup_storage_manager).returns(StorageManager::Null.new)
|
||||
Danbooru.config.stubs(:enable_email_verification?).returns(false)
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
Loading…
Reference in New Issue
Block a user