update factories + tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
module Maintenance
|
module Maintenance
|
||||||
extend self
|
module_function
|
||||||
|
|
||||||
def hourly
|
def hourly
|
||||||
UploadErrorChecker.new.check!
|
UploadErrorChecker.new.check!
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
class Comment < ApplicationRecord
|
class Comment < ApplicationRecord
|
||||||
include Mentionable
|
include Mentionable
|
||||||
|
|
||||||
validate :validate_post_exists, :on => :create
|
|
||||||
validate :validate_creator_is_not_limited, :on => :create
|
validate :validate_creator_is_not_limited, :on => :create
|
||||||
validates_presence_of :body, :message => "has no content"
|
validates_presence_of :body, :message => "has no content"
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Note < ApplicationRecord
|
|||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to_creator
|
belongs_to_creator
|
||||||
has_many :versions, -> {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy
|
has_many :versions, -> {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy
|
||||||
validates_presence_of :post_id, :creator_id, :x, :y, :width, :height, :body
|
validates_presence_of :creator_id, :x, :y, :width, :height, :body
|
||||||
validate :post_must_exist
|
validate :post_must_exist
|
||||||
validate :note_within_image
|
validate :note_within_image
|
||||||
after_save :update_post
|
after_save :update_post
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:artist) do
|
factory(:artist) do
|
||||||
name {rand(1_000_000).to_s}
|
name { rand(1_000_000).to_s }
|
||||||
is_active true
|
is_active { true }
|
||||||
association :creator, factory: :user
|
association :creator, factory: :user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ FactoryBot.define do
|
|||||||
factory(:ban) do |f|
|
factory(:ban) do |f|
|
||||||
banner :factory => :admin_user
|
banner :factory => :admin_user
|
||||||
reason {FFaker::Lorem.words.join(" ")}
|
reason {FFaker::Lorem.words.join(" ")}
|
||||||
duration 60
|
duration {60}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:bulk_update_request) do |f|
|
factory(:bulk_update_request) do |f|
|
||||||
title "xxx"
|
title {"xxx"}
|
||||||
script "create alias aaa -> bbb"
|
script {"create alias aaa -> bbb"}
|
||||||
skip_secondary_validations true
|
skip_secondary_validations {true}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:comment_vote) do
|
factory(:comment_vote) do
|
||||||
score 1
|
score {1}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:forum_subscription) do
|
factory(:forum_subscription)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:forum_topic) do
|
factory(:forum_topic) do
|
||||||
title {FFaker::Lorem.words.join(" ")}
|
title {FFaker::Lorem.words.join(" ")}
|
||||||
is_sticky false
|
is_sticky {false}
|
||||||
is_locked false
|
is_locked {false}
|
||||||
category_id 0
|
category_id {0}
|
||||||
|
|
||||||
factory(:mod_up_forum_topic) do
|
factory(:mod_up_forum_topic) do
|
||||||
min_level User::Levels::MODERATOR
|
min_level {User::Levels::MODERATOR}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:forum_topic_visit) do
|
factory(:forum_topic_visit)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ FactoryBot.define do
|
|||||||
factory(:ip_ban) do
|
factory(:ip_ban) do
|
||||||
creator :factory => :user
|
creator :factory => :user
|
||||||
reason {FFaker::Lorem.words.join(" ")}
|
reason {FFaker::Lorem.words.join(" ")}
|
||||||
ip_addr "127.0.0.2"
|
ip_addr {"127.0.0.2"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:mod_action) do
|
factory(:mod_action) do
|
||||||
creator :factory => :user
|
creator :factory => :user
|
||||||
description "1234"
|
description {"1234"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:news_update) do
|
factory(:news_update) do
|
||||||
message "xxx"
|
message {"xxx"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:note) do
|
factory(:note) do
|
||||||
post
|
post
|
||||||
x 1
|
x { 1 }
|
||||||
y 1
|
y { 1 }
|
||||||
width 1
|
width { 1 }
|
||||||
height 1
|
height { 1 }
|
||||||
is_active true
|
is_active { true }
|
||||||
body {FFaker::Lorem.sentences.join(" ")}
|
body { FFaker::Lorem.sentences.join(" ") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ FactoryBot.define do
|
|||||||
n.to_s
|
n.to_s
|
||||||
end
|
end
|
||||||
uploader :factory => :user
|
uploader :factory => :user
|
||||||
uploader_ip_addr "127.0.0.1"
|
uploader_ip_addr {"127.0.0.1"}
|
||||||
tag_string "tag1 tag2"
|
tag_string {"tag1 tag2"}
|
||||||
tag_count 2
|
tag_count {2}
|
||||||
tag_count_general 2
|
tag_count_general {2}
|
||||||
file_ext "jpg"
|
file_ext {"jpg"}
|
||||||
image_width 1500
|
image_width {1500}
|
||||||
image_height 1000
|
image_height {1000}
|
||||||
file_size 2000
|
file_size {2000}
|
||||||
rating "q"
|
rating {"q"}
|
||||||
source { FFaker::Internet.http_url }
|
source { FFaker::Internet.http_url }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:post_appeal) do
|
factory(:post_appeal) do
|
||||||
reason "xxx"
|
reason {"xxx"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:post_flag) do
|
factory(:post_flag) do
|
||||||
reason "xxx"
|
reason {"xxx"}
|
||||||
is_resolved false
|
is_resolved {false}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:tag) do
|
factory(:tag) do
|
||||||
name {"#{FFaker::Name.first_name.downcase}#{rand(1000)}"}
|
name {"#{FFaker::Name.first_name.downcase}#{rand(1000)}"}
|
||||||
post_count 0
|
post_count {0}
|
||||||
category {Tag.categories.general}
|
category {Tag.categories.general}
|
||||||
related_tags ""
|
related_tags {""}
|
||||||
related_tags_updated_at {Time.now}
|
related_tags_updated_at {Time.now}
|
||||||
|
|
||||||
factory(:artist_tag) do
|
factory(:artist_tag) do
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :tag_alias do
|
factory :tag_alias do
|
||||||
antecedent_name "aaa"
|
antecedent_name {"aaa"}
|
||||||
consequent_name "bbb"
|
consequent_name {"bbb"}
|
||||||
status "active"
|
status {"active"}
|
||||||
skip_secondary_validations true
|
skip_secondary_validations {true}
|
||||||
creator_ip_addr { FFaker::Internet.ip_v4_address }
|
creator_ip_addr { FFaker::Internet.ip_v4_address }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :tag_implication do
|
factory :tag_implication do
|
||||||
antecedent_name "aaa"
|
antecedent_name {"aaa"}
|
||||||
consequent_name "bbb"
|
consequent_name {"bbb"}
|
||||||
status "active"
|
status {"active"}
|
||||||
skip_secondary_validations true
|
skip_secondary_validations {true}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ require 'fileutils'
|
|||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:upload) do
|
factory(:upload) do
|
||||||
rating "s"
|
rating {"s"}
|
||||||
uploader :factory => :user, :level => 20
|
uploader :factory => :user, :level => 20
|
||||||
uploader_ip_addr "127.0.0.1"
|
uploader_ip_addr {"127.0.0.1"}
|
||||||
tag_string "special"
|
tag_string {"special"}
|
||||||
status "pending"
|
status {"pending"}
|
||||||
server Socket.gethostname
|
server {Socket.gethostname}
|
||||||
source "xxx"
|
source {"xxx"}
|
||||||
|
|
||||||
factory(:source_upload) do
|
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
|
end
|
||||||
|
|
||||||
factory(:ugoira_upload) do
|
factory(:ugoira_upload) do
|
||||||
|
|||||||
@@ -3,61 +3,61 @@ FactoryBot.define do
|
|||||||
sequence :name do |n|
|
sequence :name do |n|
|
||||||
"user#{n}"
|
"user#{n}"
|
||||||
end
|
end
|
||||||
password "password"
|
password {"password"}
|
||||||
password_hash {User.sha1("password")}
|
password_hash {User.sha1("password")}
|
||||||
email {FFaker::Internet.email}
|
email {FFaker::Internet.email}
|
||||||
default_image_size "large"
|
default_image_size {"large"}
|
||||||
base_upload_limit 10
|
base_upload_limit {10}
|
||||||
level 20
|
level {20}
|
||||||
created_at {Time.now}
|
created_at {Time.now}
|
||||||
last_logged_in_at {Time.now}
|
last_logged_in_at {Time.now}
|
||||||
favorite_count 0
|
favorite_count {0}
|
||||||
bit_prefs 0
|
bit_prefs {0}
|
||||||
|
|
||||||
factory(:banned_user) do
|
factory(:banned_user) do
|
||||||
transient { ban_duration 3 }
|
transient { ban_duration {3} }
|
||||||
is_banned true
|
is_banned {true}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:member_user) do
|
factory(:member_user) do
|
||||||
level 20
|
level {20}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:gold_user) do
|
factory(:gold_user) do
|
||||||
level 30
|
level {30}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:platinum_user) do
|
factory(:platinum_user) do
|
||||||
level 31
|
level {31}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:builder_user) do
|
factory(:builder_user) do
|
||||||
level 32
|
level {32}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:contributor_user) do
|
factory(:contributor_user) do
|
||||||
level 32
|
level {32}
|
||||||
bit_prefs User.flag_value_for("can_upload_free")
|
bit_prefs {User.flag_value_for("can_upload_free")}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:contrib_user) do
|
factory(:contrib_user) do
|
||||||
level 32
|
level {32}
|
||||||
bit_prefs User.flag_value_for("can_upload_free")
|
bit_prefs {User.flag_value_for("can_upload_free")}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:moderator_user) do
|
factory(:moderator_user) do
|
||||||
level 40
|
level {40}
|
||||||
can_approve_posts true
|
can_approve_posts {true}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:mod_user) do
|
factory(:mod_user) do
|
||||||
level 40
|
level {40}
|
||||||
can_approve_posts true
|
can_approve_posts {true}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory(:admin_user) do
|
factory(:admin_user) do
|
||||||
level 50
|
level {50}
|
||||||
can_approve_posts true
|
can_approve_posts {true}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:user_feedback) do
|
factory(:user_feedback) do
|
||||||
user
|
user
|
||||||
category "positive"
|
category { "positive" }
|
||||||
body {FFaker::Lorem.words.join(" ")}
|
body { FFaker::Lorem.words.join(" ") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ class CommentTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "fail creation" do
|
should "fail creation" do
|
||||||
comment = FactoryBot.build(:comment)
|
post = FactoryBot.create(:post)
|
||||||
|
comment = FactoryBot.build(:comment, post: post)
|
||||||
comment.save
|
comment.save
|
||||||
assert_equal(["You can not post comments within 1 week of sign up"], comment.errors.full_messages)
|
assert_equal(["You can not post comments within 1 week of sign up"], comment.errors.full_messages)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class NoteSanitizerTest < ActiveSupport::TestCase
|
|||||||
context "Sanitizing a note" do
|
context "Sanitizing a note" do
|
||||||
should "strip unsafe tags" do
|
should "strip unsafe tags" do
|
||||||
body = '<p>test</p> <script>alert("owned")</script>'
|
body = '<p>test</p> <script>alert("owned")</script>'
|
||||||
assert_equal('<p>test</p> alert("owned")', NoteSanitizer.sanitize(body))
|
assert_equal('<p>test</p> ', NoteSanitizer.sanitize(body))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "strip unsafe css" do
|
should "strip unsafe css" do
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class NoteTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "not validate if the body is blank" do
|
should "not validate if the body is blank" do
|
||||||
@note = FactoryBot.build(:note, body: " ")
|
@note = FactoryBot.build(:note, body: " ", :post => @post)
|
||||||
|
|
||||||
assert_equal(false, @note.valid?)
|
assert_equal(false, @note.valid?)
|
||||||
assert_equal(["Body can't be blank"], @note.errors.full_messages)
|
assert_equal(["Body can't be blank"], @note.errors.full_messages)
|
||||||
|
|||||||
Reference in New Issue
Block a user