diff --git a/app/logical/maintenance.rb b/app/logical/maintenance.rb index 6ffe832cb..38382bd17 100644 --- a/app/logical/maintenance.rb +++ b/app/logical/maintenance.rb @@ -1,5 +1,5 @@ module Maintenance - extend self + module_function def hourly UploadErrorChecker.new.check! diff --git a/app/models/comment.rb b/app/models/comment.rb index 5a9f48786..5adf2385c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,7 +1,6 @@ class Comment < ApplicationRecord include Mentionable - validate :validate_post_exists, :on => :create validate :validate_creator_is_not_limited, :on => :create validates_presence_of :body, :message => "has no content" belongs_to :post diff --git a/app/models/note.rb b/app/models/note.rb index 4955c75c1..9bd1f2d15 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -5,7 +5,7 @@ class Note < ApplicationRecord belongs_to :post belongs_to_creator 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 :note_within_image after_save :update_post diff --git a/test/factories/artist.rb b/test/factories/artist.rb index a147aa233..3761bd554 100644 --- a/test/factories/artist.rb +++ b/test/factories/artist.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory(:artist) do - name {rand(1_000_000).to_s} - is_active true + name { rand(1_000_000).to_s } + is_active { true } association :creator, factory: :user end end diff --git a/test/factories/ban.rb b/test/factories/ban.rb index 58c195d09..da8abcd51 100644 --- a/test/factories/ban.rb +++ b/test/factories/ban.rb @@ -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 diff --git a/test/factories/bulk_update_request.rb b/test/factories/bulk_update_request.rb index dcfda5961..e9b72f5e0 100644 --- a/test/factories/bulk_update_request.rb +++ b/test/factories/bulk_update_request.rb @@ -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 diff --git a/test/factories/comment_vote.rb b/test/factories/comment_vote.rb index 25e451b47..1419077df 100644 --- a/test/factories/comment_vote.rb +++ b/test/factories/comment_vote.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory(:comment_vote) do - score 1 + score {1} end end diff --git a/test/factories/forum_subscription.rb b/test/factories/forum_subscription.rb index cb6713b0b..62fa7203b 100644 --- a/test/factories/forum_subscription.rb +++ b/test/factories/forum_subscription.rb @@ -1,4 +1,3 @@ FactoryBot.define do - factory(:forum_subscription) do - end + factory(:forum_subscription) end diff --git a/test/factories/forum_topic.rb b/test/factories/forum_topic.rb index a355795b8..8f2a1d331 100644 --- a/test/factories/forum_topic.rb +++ b/test/factories/forum_topic.rb @@ -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 diff --git a/test/factories/forum_topic_visit.rb b/test/factories/forum_topic_visit.rb index ed07fda71..1c4e910f4 100644 --- a/test/factories/forum_topic_visit.rb +++ b/test/factories/forum_topic_visit.rb @@ -1,4 +1,3 @@ FactoryBot.define do - factory(:forum_topic_visit) do - end + factory(:forum_topic_visit) end diff --git a/test/factories/ip_ban.rb b/test/factories/ip_ban.rb index 4d61a1186..1b925ccbe 100644 --- a/test/factories/ip_ban.rb +++ b/test/factories/ip_ban.rb @@ -2,6 +2,6 @@ FactoryBot.define do factory(:ip_ban) do creator :factory => :user reason {FFaker::Lorem.words.join(" ")} - ip_addr "127.0.0.2" + ip_addr {"127.0.0.2"} end end diff --git a/test/factories/mod_action.rb b/test/factories/mod_action.rb index 329748d0e..4be3425e2 100644 --- a/test/factories/mod_action.rb +++ b/test/factories/mod_action.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory(:mod_action) do creator :factory => :user - description "1234" + description {"1234"} end end diff --git a/test/factories/news_update.rb b/test/factories/news_update.rb index 98d42ef94..3923185e2 100644 --- a/test/factories/news_update.rb +++ b/test/factories/news_update.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory(:news_update) do - message "xxx" + message {"xxx"} end end diff --git a/test/factories/note.rb b/test/factories/note.rb index 33a8b533e..6fbcd8a7e 100644 --- a/test/factories/note.rb +++ b/test/factories/note.rb @@ -1,11 +1,11 @@ FactoryBot.define do factory(:note) do post - x 1 - y 1 - width 1 - height 1 - is_active true - body {FFaker::Lorem.sentences.join(" ")} + x { 1 } + y { 1 } + width { 1 } + height { 1 } + is_active { true } + body { FFaker::Lorem.sentences.join(" ") } end end diff --git a/test/factories/post.rb b/test/factories/post.rb index 253a3eafb..517b6764d 100644 --- a/test/factories/post.rb +++ b/test/factories/post.rb @@ -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 diff --git a/test/factories/post_appeal.rb b/test/factories/post_appeal.rb index 0a8ca243e..1c2c93ca6 100644 --- a/test/factories/post_appeal.rb +++ b/test/factories/post_appeal.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory(:post_appeal) do - reason "xxx" + reason {"xxx"} end end diff --git a/test/factories/post_flag.rb b/test/factories/post_flag.rb index 0e883c21f..e2c49c5bb 100644 --- a/test/factories/post_flag.rb +++ b/test/factories/post_flag.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory(:post_flag) do - reason "xxx" - is_resolved false + reason {"xxx"} + is_resolved {false} end end diff --git a/test/factories/tag.rb b/test/factories/tag.rb index 621fc2e13..2fa0dc183 100644 --- a/test/factories/tag.rb +++ b/test/factories/tag.rb @@ -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 diff --git a/test/factories/tag_alias.rb b/test/factories/tag_alias.rb index 641074e9b..3bedfb9d4 100644 --- a/test/factories/tag_alias.rb +++ b/test/factories/tag_alias.rb @@ -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 diff --git a/test/factories/tag_implication.rb b/test/factories/tag_implication.rb index 6830d5d43..79965b1b7 100644 --- a/test/factories/tag_implication.rb +++ b/test/factories/tag_implication.rb @@ -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 diff --git a/test/factories/upload.rb b/test/factories/upload.rb index 3c59f799d..69da6490f 100644 --- a/test/factories/upload.rb +++ b/test/factories/upload.rb @@ -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 diff --git a/test/factories/user.rb b/test/factories/user.rb index c3e4985d1..9d3024f65 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -3,61 +3,61 @@ FactoryBot.define do sequence :name do |n| "user#{n}" end - password "password" + password {"password"} password_hash {User.sha1("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 + favorite_count {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(:gold_user) do - level 30 + level {30} end factory(:platinum_user) do - level 31 + level {31} end factory(:builder_user) do - level 32 + level {32} 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 diff --git a/test/factories/user_feedback.rb b/test/factories/user_feedback.rb index 97651690f..516ce9fa4 100644 --- a/test/factories/user_feedback.rb +++ b/test/factories/user_feedback.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory(:user_feedback) do user - category "positive" - body {FFaker::Lorem.words.join(" ")} + category { "positive" } + body { FFaker::Lorem.words.join(" ") } end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 44fe6e6c6..218e2e670 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -89,7 +89,8 @@ class CommentTest < ActiveSupport::TestCase end should "fail creation" do - comment = FactoryBot.build(:comment) + post = FactoryBot.create(:post) + comment = FactoryBot.build(:comment, post: post) comment.save assert_equal(["You can not post comments within 1 week of sign up"], comment.errors.full_messages) end diff --git a/test/unit/note_sanitizer_test.rb b/test/unit/note_sanitizer_test.rb index 43fa32b4d..63c0cbf52 100644 --- a/test/unit/note_sanitizer_test.rb +++ b/test/unit/note_sanitizer_test.rb @@ -4,7 +4,7 @@ class NoteSanitizerTest < ActiveSupport::TestCase context "Sanitizing a note" do should "strip unsafe tags" do body = '
test
' - assert_equal('test
alert("owned")', NoteSanitizer.sanitize(body)) + assert_equal('test
', NoteSanitizer.sanitize(body)) end should "strip unsafe css" do diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index c5fc05e9b..d20ce611d 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -68,7 +68,7 @@ class NoteTest < ActiveSupport::TestCase end 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(["Body can't be blank"], @note.errors.full_messages)