PERF: Make tests faster by prefabricating more things (#15392)
This commit is contained in:
parent
28400f1cbe
commit
5ff0b86b57
|
@ -1884,7 +1884,6 @@ describe Guardian do
|
|||
|
||||
it 'returns true for a group member with reviewable status' do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
group = Fabricate(:group)
|
||||
GroupUser.create!(group_id: group.id, user_id: user.id)
|
||||
topic.category.update!(reviewable_by_group_id: group.id)
|
||||
expect(Guardian.new(user).can_review_topic?(topic)).to eq(true)
|
||||
|
@ -1906,7 +1905,6 @@ describe Guardian do
|
|||
|
||||
it 'returns true for a group member with reviewable status' do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
group = Fabricate(:group)
|
||||
GroupUser.create!(group_id: group.id, user_id: user.id)
|
||||
topic.category.update!(reviewable_by_group_id: group.id)
|
||||
expect(Guardian.new(user).can_close_topic?(topic)).to eq(true)
|
||||
|
@ -1928,7 +1926,6 @@ describe Guardian do
|
|||
|
||||
it 'returns true for a group member with reviewable status' do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
group = Fabricate(:group)
|
||||
GroupUser.create!(group_id: group.id, user_id: user.id)
|
||||
topic.category.update!(reviewable_by_group_id: group.id)
|
||||
expect(Guardian.new(user).can_archive_topic?(topic)).to eq(true)
|
||||
|
@ -1950,7 +1947,6 @@ describe Guardian do
|
|||
|
||||
it 'returns true for a group member with reviewable status' do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
group = Fabricate(:group)
|
||||
GroupUser.create!(group_id: group.id, user_id: user.id)
|
||||
topic.category.update!(reviewable_by_group_id: group.id)
|
||||
expect(Guardian.new(user).can_edit_staff_notes?(topic)).to eq(true)
|
||||
|
@ -2156,7 +2152,6 @@ describe Guardian do
|
|||
|
||||
it "returns true for category moderators" do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
group = Fabricate(:group)
|
||||
GroupUser.create(group: group, user: user)
|
||||
category = Fabricate(:category, reviewable_by_group_id: group.id)
|
||||
post.topic.update!(category: category)
|
||||
|
|
|
@ -7,6 +7,7 @@ require 'topic_subtype'
|
|||
describe PostCreator do
|
||||
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:coding_horror) { Fabricate(:coding_horror) }
|
||||
fab!(:evil_trout) { Fabricate(:evil_trout) }
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
|
@ -119,7 +120,6 @@ describe PostCreator do
|
|||
end
|
||||
|
||||
it "does not notify on system messages" do
|
||||
admin = Fabricate(:admin)
|
||||
messages = MessageBus.track_publish do
|
||||
p = PostCreator.create(admin, basic_topic_params.merge(post_type: Post.types[:moderator_action]))
|
||||
PostCreator.create(admin, basic_topic_params.merge(topic_id: p.topic_id, post_type: Post.types[:moderator_action]))
|
||||
|
@ -866,7 +866,6 @@ describe PostCreator do
|
|||
end
|
||||
|
||||
it 'creates the topic if the user is a staff member' do
|
||||
admin = Fabricate(:admin)
|
||||
post_creator = PostCreator.new(admin, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4)
|
||||
TopicUser.create!(user: admin, topic: topic, last_posted_at: 10.minutes.ago)
|
||||
|
||||
|
@ -961,7 +960,6 @@ describe PostCreator do
|
|||
UserArchivedMessage.create(user_id: target_user2.id, topic_id: post.topic_id)
|
||||
|
||||
# if an admin replies they should be added to the allowed user list
|
||||
admin = Fabricate(:admin)
|
||||
PostCreator.create!(admin,
|
||||
raw: 'hi there welcome topic, I am a mod',
|
||||
topic_id: post.topic_id
|
||||
|
@ -1064,8 +1062,6 @@ describe PostCreator do
|
|||
it 'closes private messages that have more than N posts' do
|
||||
SiteSetting.auto_close_messages_post_count = 2
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
|
||||
post1 = create_post(archetype: Archetype.private_message,
|
||||
target_usernames: [admin.username])
|
||||
|
||||
|
@ -1325,7 +1321,6 @@ describe PostCreator do
|
|||
it "automatically watches topic based on preference" do
|
||||
user.user_option.notification_level_when_replying = 3
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
topic = PostCreator.create(admin,
|
||||
title: "this is the title of a topic created by an admin for watching notification",
|
||||
raw: "this is the content of a topic created by an admin for keeping a watching notification state on a topic ;)"
|
||||
|
@ -1342,7 +1337,6 @@ describe PostCreator do
|
|||
it "topic notification level remains tracking based on preference" do
|
||||
user.user_option.notification_level_when_replying = 2
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
topic = PostCreator.create(admin,
|
||||
title: "this is the title of a topic created by an admin for tracking notification",
|
||||
raw: "this is the content of a topic created by an admin for keeping a tracking notification state on a topic ;)"
|
||||
|
@ -1359,7 +1353,6 @@ describe PostCreator do
|
|||
it "topic notification level is normal based on preference" do
|
||||
user.user_option.notification_level_when_replying = 1
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
topic = PostCreator.create(admin,
|
||||
title: "this is the title of a topic created by an admin for tracking notification",
|
||||
raw: "this is the content of a topic created by an admin for keeping a tracking notification state on a topic ;)"
|
||||
|
@ -1376,7 +1369,6 @@ describe PostCreator do
|
|||
it "user preferences for notification level when replying doesn't affect PMs" do
|
||||
user.user_option.update!(notification_level_when_replying: 1)
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
pm = Fabricate(:private_message_topic, user: admin)
|
||||
|
||||
pm.invite(admin, user.username)
|
||||
|
|
|
@ -5,6 +5,7 @@ require 'rails_helper'
|
|||
|
||||
describe Search do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
before do
|
||||
SearchIndexer.enable
|
||||
|
@ -671,7 +672,6 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'displays multiple results within a topic' do
|
||||
topic = Fabricate(:topic)
|
||||
topic2 = Fabricate(:topic)
|
||||
|
||||
new_post('this is the other post I am posting', topic2, created_at: 6.minutes.ago)
|
||||
|
@ -1086,7 +1086,6 @@ describe Search do
|
|||
it 'can use tag as a search context' do
|
||||
tag = Fabricate(:tag, name: 'important-stuff')
|
||||
|
||||
topic = Fabricate(:topic)
|
||||
topic_no_tag = Fabricate(:topic)
|
||||
Fabricate(:topic_tag, tag: tag, topic: topic)
|
||||
|
||||
|
@ -1151,7 +1150,6 @@ describe Search do
|
|||
describe 'Advanced search' do
|
||||
|
||||
it 'supports pinned' do
|
||||
topic = Fabricate(:topic)
|
||||
Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)
|
||||
_post = Fabricate(:post, raw: 'boom boom shake the room', topic: topic)
|
||||
|
||||
|
@ -1162,7 +1160,6 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'supports wiki' do
|
||||
topic = Fabricate(:topic)
|
||||
topic_2 = Fabricate(:topic)
|
||||
post = Fabricate(:post, raw: 'this is a test 248', wiki: true, topic: topic)
|
||||
Fabricate(:post, raw: 'this is a test 248', wiki: false, topic: topic_2)
|
||||
|
@ -1173,7 +1170,6 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'supports searching for posts that the user has seen/unseen' do
|
||||
topic = Fabricate(:topic)
|
||||
topic_2 = Fabricate(:topic)
|
||||
post = Fabricate(:post, raw: 'logan is longan', topic: topic)
|
||||
post_2 = Fabricate(:post, raw: 'longan is logan', topic: topic_2)
|
||||
|
@ -1231,7 +1227,6 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'supports in:first, user:, @username' do
|
||||
topic = Fabricate(:topic)
|
||||
post_1 = Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)
|
||||
post_2 = Fabricate(:post, raw: 'boom boom shake the room test', topic: topic)
|
||||
|
||||
|
@ -1569,7 +1564,6 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'can find posts with non-latin tag' do
|
||||
topic = Fabricate(:topic)
|
||||
topic.tags = [Fabricate(:tag, name: 'さようなら')]
|
||||
post = Fabricate(:post, raw: 'Testing post', topic: topic)
|
||||
|
||||
|
@ -1577,7 +1571,6 @@ describe Search do
|
|||
end
|
||||
|
||||
it 'can find posts with thai tag' do
|
||||
topic = Fabricate(:topic)
|
||||
topic.tags = [Fabricate(:tag, name: 'เรซิ่น')]
|
||||
post = Fabricate(:post, raw: 'Testing post', topic: topic)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe SvgSprite do
|
||||
fab!(:theme) { Fabricate(:theme) }
|
||||
|
||||
before do
|
||||
SvgSprite.expire_cache
|
||||
|
@ -50,7 +51,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'version should be based on bundled output, not requested icons' do
|
||||
theme = Fabricate(:theme)
|
||||
fname = "custom-theme-icon-sprite.svg"
|
||||
upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)
|
||||
|
||||
|
@ -92,8 +92,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'includes icons defined in theme settings' do
|
||||
theme = Fabricate(:theme)
|
||||
|
||||
# Works for default settings:
|
||||
theme.set_field(target: :settings, name: :yaml, value: "custom_icon: dragon")
|
||||
theme.save!
|
||||
|
@ -138,7 +136,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'includes icons defined in theme modifiers' do
|
||||
theme = Fabricate(:theme)
|
||||
child_theme = Fabricate(:theme, component: true)
|
||||
theme.add_relative_theme!(:child, child_theme)
|
||||
|
||||
|
@ -173,7 +170,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'includes svg sprites in themes stored in s3' do
|
||||
theme = Fabricate(:theme)
|
||||
theme.set_field(target: :common, name: SvgSprite.theme_sprite_variable_name, upload_id: upload_s3.id, type: :theme_upload_var)
|
||||
theme.save!
|
||||
|
||||
|
@ -253,7 +249,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'includes custom icons in a theme' do
|
||||
theme = Fabricate(:theme)
|
||||
fname = "custom-theme-icon-sprite.svg"
|
||||
|
||||
upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)
|
||||
|
@ -266,7 +261,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'does not fail on bad XML in custom icon sprite' do
|
||||
theme = Fabricate(:theme)
|
||||
fname = "bad-xml-icon-sprite.svg"
|
||||
|
||||
upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)
|
||||
|
@ -279,7 +273,6 @@ describe SvgSprite do
|
|||
end
|
||||
|
||||
it 'includes custom icons in a child theme' do
|
||||
theme = Fabricate(:theme)
|
||||
fname = "custom-theme-icon-sprite.svg"
|
||||
child_theme = Fabricate(:theme, component: true)
|
||||
theme.add_relative_theme!(:child, child_theme)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Notification do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:coding_horror) { Fabricate(:coding_horror) }
|
||||
|
||||
before do
|
||||
|
@ -269,8 +270,6 @@ describe Notification do
|
|||
|
||||
describe 'saw_regular_notification_id' do
|
||||
it 'correctly updates the read state' do
|
||||
user = Fabricate(:user)
|
||||
|
||||
t = Fabricate(:topic)
|
||||
|
||||
Notification.create!(read: false,
|
||||
|
@ -308,8 +307,6 @@ describe Notification do
|
|||
|
||||
describe 'mark_posts_read' do
|
||||
it "marks multiple posts as read if needed" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
(1..3).map do |i|
|
||||
Notification.create!(read: false, user_id: user.id, topic_id: 2, post_number: i, data: '{}', notification_type: 1)
|
||||
end
|
||||
|
@ -345,7 +342,6 @@ describe Notification do
|
|||
end
|
||||
|
||||
it 'does not delete chat_message notifications' do
|
||||
user = Fabricate(:user)
|
||||
Notification.create!(read: false, user_id: user.id, topic_id: nil, post_number: nil, data: '[]',
|
||||
notification_type: Notification.types[:chat_mention])
|
||||
|
||||
|
@ -357,7 +353,6 @@ describe Notification do
|
|||
|
||||
describe "do not disturb" do
|
||||
it "calls NotificationEmailer.process_notification when user is not in 'do not disturb'" do
|
||||
user = Fabricate(:user)
|
||||
notification = Notification.new(read: false, user_id: user.id, topic_id: 2, post_number: 1, data: '{}', notification_type: 1)
|
||||
NotificationEmailer.expects(:process_notification).with(notification)
|
||||
notification.save!
|
||||
|
@ -365,7 +360,6 @@ describe Notification do
|
|||
|
||||
it "doesn't call NotificationEmailer.process_notification when user is in 'do not disturb'" do
|
||||
freeze_time
|
||||
user = Fabricate(:user)
|
||||
Fabricate(:do_not_disturb_timing, user: user, starts_at: Time.zone.now, ends_at: 1.day.from_now)
|
||||
|
||||
notification = Notification.new(read: false, user_id: user.id, topic_id: 2, post_number: 1, data: '{}', notification_type: 1)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe PostTiming do
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
|
||||
it { is_expected.to validate_presence_of :post_number }
|
||||
it { is_expected.to validate_presence_of :msecs }
|
||||
|
@ -61,7 +62,6 @@ describe PostTiming do
|
|||
describe 'safeguard' do
|
||||
it "doesn't store timings that are larger than the account lifetime" do
|
||||
user = Fabricate(:user, created_at: 3.minutes.ago)
|
||||
post = Fabricate(:post)
|
||||
|
||||
PostTiming.process_timings(user, post.topic_id, 1, [[post.post_number, 123]])
|
||||
msecs = PostTiming.where(post_number: post.post_number, user_id: user.id).pluck(:msecs)[0]
|
||||
|
@ -81,7 +81,6 @@ describe PostTiming do
|
|||
it 'processes timings correctly' do
|
||||
PostActionNotifier.enable
|
||||
|
||||
post = Fabricate(:post)
|
||||
(2..5).each do |i|
|
||||
Fabricate(:post, topic: post.topic, post_number: i)
|
||||
end
|
||||
|
@ -131,17 +130,16 @@ describe PostTiming do
|
|||
|
||||
describe 'recording' do
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
@topic = @post.topic
|
||||
@topic = post.topic
|
||||
@coding_horror = Fabricate(:coding_horror)
|
||||
@timing_attrs = { msecs: 1234, topic_id: @post.topic_id, user_id: @coding_horror.id, post_number: @post.post_number }
|
||||
@timing_attrs = { msecs: 1234, topic_id: post.topic_id, user_id: @coding_horror.id, post_number: post.post_number }
|
||||
end
|
||||
|
||||
it 'adds a view to the post' do
|
||||
expect {
|
||||
PostTiming.record_timing(@timing_attrs)
|
||||
@post.reload
|
||||
}.to change(@post, :reads).by(1)
|
||||
post.reload
|
||||
}.to change(post, :reads).by(1)
|
||||
end
|
||||
|
||||
it "doesn't update the posts read count if the topic is a PM" do
|
||||
|
@ -157,7 +155,7 @@ describe PostTiming do
|
|||
it 'correctly works' do
|
||||
PostTiming.record_timing(@timing_attrs)
|
||||
PostTiming.record_timing(@timing_attrs)
|
||||
timing = PostTiming.find_by(topic_id: @post.topic_id, user_id: @coding_horror.id, post_number: @post.post_number)
|
||||
timing = PostTiming.find_by(topic_id: post.topic_id, user_id: @coding_horror.id, post_number: post.post_number)
|
||||
|
||||
expect(timing).to be_present
|
||||
expect(timing.msecs).to eq(2468)
|
||||
|
@ -192,7 +190,6 @@ describe PostTiming do
|
|||
|
||||
describe '.destroy_last_for' do
|
||||
it 'updates first unread for a user correctly when topic is public' do
|
||||
post = Fabricate(:post)
|
||||
post.topic.update!(updated_at: 10.minutes.ago)
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
||||
|
||||
|
|
|
@ -4,13 +4,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ThemeField do
|
||||
after do
|
||||
ThemeField.destroy_all
|
||||
end
|
||||
fab!(:theme) { Fabricate(:theme) }
|
||||
|
||||
describe "scope: find_by_theme_ids" do
|
||||
it "returns result in the specified order" do
|
||||
theme = Fabricate(:theme)
|
||||
theme2 = Fabricate(:theme)
|
||||
theme3 = Fabricate(:theme)
|
||||
|
||||
|
@ -159,7 +156,6 @@ HTML
|
|||
end
|
||||
|
||||
it "allows importing scss files" do
|
||||
theme = Fabricate(:theme)
|
||||
main_field = theme.set_field(target: :common, name: :scss, value: ".class1{color: red}\n@import 'rootfile1';\n@import 'rootfile3';")
|
||||
theme.set_field(target: :extra_scss, name: "rootfile1", value: ".class2{color:green}\n@import 'foldername/subfile1';")
|
||||
theme.set_field(target: :extra_scss, name: "rootfile2", value: ".class3{color:green} ")
|
||||
|
@ -179,7 +175,6 @@ HTML
|
|||
end
|
||||
|
||||
it "correctly handles extra JS fields" do
|
||||
theme = Fabricate(:theme)
|
||||
js_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery.js.es6", value: "import 'discourse/lib/ajax'; console.log('hello from .js.es6');")
|
||||
js_2_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery-2.js", value: "import 'discourse/lib/ajax'; console.log('hello from .js');")
|
||||
hbs_field = theme.set_field(target: :extra_js, name: "discourse/templates/discovery.hbs", value: "{{hello-world}}")
|
||||
|
@ -235,7 +230,6 @@ HTML
|
|||
let(:key) { "themes.settings_errors" }
|
||||
|
||||
it "forces re-transpilation of theme JS when settings YAML changes" do
|
||||
theme = Fabricate(:theme)
|
||||
settings_field = ThemeField.create!(theme: theme, target_id: Theme.targets[:settings], name: "yaml", value: "setting: 5")
|
||||
|
||||
html = <<~HTML
|
||||
|
|
|
@ -4,9 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe TopicTrackingState do
|
||||
|
||||
fab!(:user) do
|
||||
Fabricate(:user)
|
||||
end
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
let(:post) do
|
||||
create_post
|
||||
|
@ -335,8 +333,6 @@ describe TopicTrackingState do
|
|||
end
|
||||
|
||||
it "correctly handles muted categories" do
|
||||
|
||||
user = Fabricate(:user)
|
||||
post
|
||||
|
||||
report = TopicTrackingState.report(user)
|
||||
|
@ -359,7 +355,6 @@ describe TopicTrackingState do
|
|||
end
|
||||
|
||||
it "correctly handles category_users with null notification level" do
|
||||
user = Fabricate(:user)
|
||||
post
|
||||
|
||||
report = TopicTrackingState.report(user)
|
||||
|
@ -374,7 +369,6 @@ describe TopicTrackingState do
|
|||
it "works when categories are default muted" do
|
||||
SiteSetting.mute_all_categories_by_default = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
post
|
||||
|
||||
report = TopicTrackingState.report(user)
|
||||
|
@ -394,7 +388,6 @@ describe TopicTrackingState do
|
|||
context 'muted tags' do
|
||||
it "remove_muted_tags_from_latest is set to always" do
|
||||
SiteSetting.remove_muted_tags_from_latest = 'always'
|
||||
user = Fabricate(:user)
|
||||
tag1 = Fabricate(:tag)
|
||||
tag2 = Fabricate(:tag)
|
||||
Fabricate(:topic_tag, tag: tag1, topic: topic)
|
||||
|
@ -420,7 +413,6 @@ describe TopicTrackingState do
|
|||
|
||||
it "remove_muted_tags_from_latest is set to only_muted" do
|
||||
SiteSetting.remove_muted_tags_from_latest = 'only_muted'
|
||||
user = Fabricate(:user)
|
||||
tag1 = Fabricate(:tag)
|
||||
tag2 = Fabricate(:tag)
|
||||
Fabricate(:topic_tag, tag: tag1, topic: topic)
|
||||
|
@ -454,7 +446,6 @@ describe TopicTrackingState do
|
|||
|
||||
it "remove_muted_tags_from_latest is set to never" do
|
||||
SiteSetting.remove_muted_tags_from_latest = 'never'
|
||||
user = Fabricate(:user)
|
||||
tag1 = Fabricate(:tag)
|
||||
Fabricate(:topic_tag, tag: tag1, topic: topic)
|
||||
post
|
||||
|
@ -474,7 +465,7 @@ describe TopicTrackingState do
|
|||
|
||||
it "correctly handles dismissed topics" do
|
||||
freeze_time 1.minute.ago
|
||||
user = Fabricate(:user)
|
||||
user.update!(created_at: Time.now)
|
||||
post
|
||||
|
||||
report = TopicTrackingState.report(user)
|
||||
|
@ -492,8 +483,6 @@ describe TopicTrackingState do
|
|||
end
|
||||
|
||||
it "correctly handles capping" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
post1 = create_post
|
||||
Fabricate(:post, topic: post1.topic)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'rails_helper'
|
|||
require 'discourse_ip_info'
|
||||
|
||||
describe UserAuthToken do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
it "can remove old expired tokens" do
|
||||
|
||||
|
@ -12,7 +13,6 @@ describe UserAuthToken do
|
|||
freeze_time Time.zone.now
|
||||
SiteSetting.maximum_session_age = 1
|
||||
|
||||
user = Fabricate(:user)
|
||||
token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent 2",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -35,8 +35,6 @@ describe UserAuthToken do
|
|||
end
|
||||
|
||||
it "can lookup hashed" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent 2",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -51,9 +49,6 @@ describe UserAuthToken do
|
|||
end
|
||||
|
||||
it "can validate token was seen at lookup time" do
|
||||
|
||||
user = Fabricate(:user)
|
||||
|
||||
user_token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent 2",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -68,9 +63,6 @@ describe UserAuthToken do
|
|||
end
|
||||
|
||||
it "can rotate with no params maintaining data" do
|
||||
|
||||
user = Fabricate(:user)
|
||||
|
||||
user_token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent 2",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -84,7 +76,6 @@ describe UserAuthToken do
|
|||
|
||||
it "expires correctly" do
|
||||
freeze_time Time.zone.now
|
||||
user = Fabricate(:user)
|
||||
user_token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent 2",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -110,7 +101,6 @@ describe UserAuthToken do
|
|||
|
||||
it "can properly rotate tokens" do
|
||||
freeze_time 3.days.ago
|
||||
user = Fabricate(:user)
|
||||
|
||||
user_token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent 2",
|
||||
|
@ -164,9 +154,6 @@ describe UserAuthToken do
|
|||
end
|
||||
|
||||
it "keeps prev token valid for 1 minute after it is confirmed" do
|
||||
|
||||
user = Fabricate(:user)
|
||||
|
||||
token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -189,8 +176,6 @@ describe UserAuthToken do
|
|||
it "can correctly log auth tokens" do
|
||||
SiteSetting.verbose_auth_token_logging = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
|
||||
token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -256,8 +241,6 @@ describe UserAuthToken do
|
|||
it "calls before_destroy" do
|
||||
SiteSetting.verbose_auth_token_logging = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
|
||||
token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -273,8 +256,6 @@ describe UserAuthToken do
|
|||
end
|
||||
|
||||
it "will not mark token unseen when prev and current are the same" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
token = UserAuthToken.generate!(user_id: user.id,
|
||||
user_agent: "some user agent",
|
||||
client_ip: "1.1.2.3")
|
||||
|
@ -286,8 +267,6 @@ describe UserAuthToken do
|
|||
end
|
||||
|
||||
context "suspicious login" do
|
||||
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
it "is not checked when generated for non-staff" do
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe GroupsController do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
fab!(:other_user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group, users: [user]) }
|
||||
let(:moderator_group_id) { Group::AUTO_GROUPS[:moderators] }
|
||||
|
@ -877,7 +878,6 @@ describe GroupsController do
|
|||
it "should update default notification preference for existing users" do
|
||||
group.update!(default_notification_level: NotificationLevels.all[:watching])
|
||||
user1 = Fabricate(:user)
|
||||
user2 = Fabricate(:user)
|
||||
group.add(user1)
|
||||
group.add(user2)
|
||||
group_user1 = user1.group_users.first
|
||||
|
@ -937,7 +937,6 @@ describe GroupsController do
|
|||
|
||||
it "should update category & tag notification preferences for existing users" do
|
||||
user1 = Fabricate(:user)
|
||||
user2 = Fabricate(:user)
|
||||
CategoryUser.create!(user: user1, category: category, notification_level: 4)
|
||||
TagUser.create!(user: user1, tag: tag, notification_level: 4)
|
||||
TagUser.create!(user: user2, tag: tag, notification_level: 4)
|
||||
|
@ -1317,8 +1316,6 @@ describe GroupsController do
|
|||
end
|
||||
|
||||
it "can make incremental adds" do
|
||||
user2 = Fabricate(:user)
|
||||
|
||||
expect do
|
||||
put "/groups/#{group.id}/members.json", params: { usernames: user2.username }
|
||||
end.to change { group.users.count }.by(1)
|
||||
|
@ -1340,8 +1337,6 @@ describe GroupsController do
|
|||
end
|
||||
|
||||
it "does not notify users when the param is not present" do
|
||||
user2 = Fabricate(:user)
|
||||
|
||||
expect {
|
||||
put "/groups/#{group.id}/members.json", params: { usernames: user2.username }
|
||||
}.to change { Topic.where(archetype: "private_message").count }.by(0)
|
||||
|
@ -1350,8 +1345,6 @@ describe GroupsController do
|
|||
end
|
||||
|
||||
it "notifies users when the param is present" do
|
||||
user2 = Fabricate(:user)
|
||||
|
||||
expect {
|
||||
put "/groups/#{group.id}/members.json", params: { usernames: user2.username, notify_users: true }
|
||||
}.to change { Topic.where(archetype: "private_message").count }.by(1)
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe UserBadgesController do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:badge) { Fabricate(:badge) }
|
||||
|
||||
context 'index' do
|
||||
|
@ -107,7 +108,6 @@ describe UserBadgesController do
|
|||
end
|
||||
|
||||
it 'grants badges from staff' do
|
||||
admin = Fabricate(:admin)
|
||||
post_1 = create_post
|
||||
|
||||
sign_in(admin)
|
||||
|
@ -169,7 +169,6 @@ describe UserBadgesController do
|
|||
end
|
||||
|
||||
it 'does not grant badge when external link is used in reason' do
|
||||
admin = Fabricate(:admin)
|
||||
post = create_post
|
||||
|
||||
sign_in(admin)
|
||||
|
@ -184,7 +183,6 @@ describe UserBadgesController do
|
|||
end
|
||||
|
||||
it 'does not grant badge if invalid discourse post/topic link is used in reason' do
|
||||
admin = Fabricate(:admin)
|
||||
post = create_post
|
||||
|
||||
sign_in(admin)
|
||||
|
@ -199,7 +197,6 @@ describe UserBadgesController do
|
|||
end
|
||||
|
||||
it 'grants badge when valid post/topic link is given in reason' do
|
||||
admin = Fabricate(:admin)
|
||||
post = create_post
|
||||
|
||||
sign_in(admin)
|
||||
|
@ -217,7 +214,6 @@ describe UserBadgesController do
|
|||
it 'grants badge when valid post/topic link is given in reason' do
|
||||
set_subfolder "/discuss"
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
post = create_post
|
||||
|
||||
sign_in(admin)
|
||||
|
@ -248,7 +244,6 @@ describe UserBadgesController do
|
|||
end
|
||||
|
||||
it 'revokes the badge' do
|
||||
admin = Fabricate(:admin)
|
||||
sign_in(admin)
|
||||
delete "/user_badges/#{user_badge.id}.json"
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'rails_helper'
|
|||
require 'rotp'
|
||||
|
||||
describe UsersController do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user1) { Fabricate(:user) }
|
||||
fab!(:another_user) { Fabricate(:user) }
|
||||
fab!(:invitee) { Fabricate(:user) }
|
||||
|
@ -1930,7 +1931,6 @@ describe UsersController do
|
|||
|
||||
it "allows staff to edit the field" do
|
||||
sign_in(admin)
|
||||
user = Fabricate(:user)
|
||||
put "/u/#{user.username}.json", params: {
|
||||
name: 'Jim Tom',
|
||||
title: "foobar",
|
||||
|
@ -2346,7 +2346,6 @@ describe UsersController do
|
|||
|
||||
describe 'when user does not have a valid session' do
|
||||
it 'should not be valid' do
|
||||
user = Fabricate(:user)
|
||||
post "/u/action/send_activation_email.json", params: {
|
||||
username: user.username
|
||||
}
|
||||
|
@ -2867,7 +2866,6 @@ describe UsersController do
|
|||
end
|
||||
|
||||
it "returns emails and associated_accounts for self" do
|
||||
user = Fabricate(:user)
|
||||
Fabricate(:email_change_request, user: user1)
|
||||
sign_in(user)
|
||||
|
||||
|
@ -2882,7 +2880,6 @@ describe UsersController do
|
|||
end
|
||||
|
||||
it "returns emails and associated_accounts when you're allowed to see them" do
|
||||
user = Fabricate(:user)
|
||||
Fabricate(:email_change_request, user: user1)
|
||||
sign_in_admin
|
||||
|
||||
|
@ -3189,7 +3186,6 @@ describe UsersController do
|
|||
|
||||
describe '#summary' do
|
||||
it "generates summary info" do
|
||||
user = Fabricate(:user)
|
||||
create_post(user: user)
|
||||
|
||||
get "/u/#{user.username_lower}/summary.json"
|
||||
|
@ -3467,8 +3463,6 @@ describe UsersController do
|
|||
end
|
||||
|
||||
it "raises an error when the new email is taken" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
put "/u/update-activation-email.json", params: {
|
||||
username: inactive_user.username,
|
||||
password: 'qwerqwer123',
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe UserUpdater do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:u1) { Fabricate(:user) }
|
||||
fab!(:u2) { Fabricate(:user) }
|
||||
fab!(:u3) { Fabricate(:user) }
|
||||
|
||||
let(:acting_user) { Fabricate.build(:user) }
|
||||
|
||||
describe '#update_muted_users' do
|
||||
it 'has no cross talk' do
|
||||
u1 = Fabricate(:user)
|
||||
u2 = Fabricate(:user)
|
||||
u3 = Fabricate(:user)
|
||||
|
||||
updater = UserUpdater.new(u1, u1)
|
||||
updater.update_muted_users("#{u2.username},#{u3.username}")
|
||||
|
||||
|
@ -27,8 +27,6 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it 'excludes acting user' do
|
||||
u1 = Fabricate(:user)
|
||||
u2 = Fabricate(:user)
|
||||
updater = UserUpdater.new(u1, u1)
|
||||
updater.update_muted_users("#{u1.username},#{u2.username}")
|
||||
|
||||
|
@ -51,7 +49,6 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it 'can update categories and tags' do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(user, user)
|
||||
updater.update(watched_tags: "#{tag.name},#{tag2.name}", muted_category_ids: [category.id])
|
||||
|
||||
|
@ -110,7 +107,6 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it "doesn't remove notification prefs when updating something else" do
|
||||
user = Fabricate(:user)
|
||||
TagUser.create!(user: user, tag: tag, notification_level: TagUser.notification_levels[:watching])
|
||||
CategoryUser.create!(user: user, category: category, notification_level: CategoryUser.notification_levels[:muted])
|
||||
|
||||
|
@ -122,7 +118,6 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it 'updates various fields' do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
date_of_birth = Time.zone.now
|
||||
SiteSetting.disable_mailing_list_mode = false
|
||||
|
@ -194,7 +189,6 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it "disables email_digests when enabling mailing_list_mode" do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
SiteSetting.disable_mailing_list_mode = false
|
||||
|
||||
|
@ -208,7 +202,6 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it "filters theme_ids blank values before updating preferences" do
|
||||
user = Fabricate(:user)
|
||||
user.user_option.update!(theme_ids: [1])
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
|
@ -251,8 +244,6 @@ describe UserUpdater do
|
|||
}
|
||||
|
||||
context 'with user_notification_schedule' do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
it "allows users to create their notification schedule when it doesn't exist previously" do
|
||||
expect(user.user_notification_schedule).to be_nil
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
@ -307,7 +298,6 @@ describe UserUpdater do
|
|||
SiteSetting.enable_discourse_connect = true
|
||||
SiteSetting.discourse_connect_overrides_bio = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
expect(updater.update(bio_raw: "new bio")).to be_truthy
|
||||
|
@ -323,7 +313,6 @@ describe UserUpdater do
|
|||
SiteSetting.enable_discourse_connect = true
|
||||
SiteSetting.discourse_connect_overrides_location = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
expect(updater.update(location: "new location")).to be_truthy
|
||||
|
@ -339,7 +328,6 @@ describe UserUpdater do
|
|||
SiteSetting.enable_discourse_connect = true
|
||||
SiteSetting.discourse_connect_overrides_website = true
|
||||
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
expect(updater.update(website: "https://google.com")).to be_truthy
|
||||
|
@ -351,7 +339,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when updating primary group' do
|
||||
let(:new_group) { Group.create(name: 'new_group') }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'updates when setting is enabled' do
|
||||
SiteSetting.user_selected_primary_groups = true
|
||||
|
@ -406,7 +393,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when updating flair group' do
|
||||
let(:group) { Fabricate(:group, name: "Group", flair_bg_color: "#111111", flair_color: "#999999", flair_icon: "icon") }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'updates when setting is enabled' do
|
||||
group.add(user)
|
||||
|
@ -421,7 +407,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when update fails' do
|
||||
it 'returns false' do
|
||||
user = Fabricate(:user)
|
||||
user.stubs(save: false)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
|
@ -505,7 +490,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when website includes http' do
|
||||
it 'does not add http before updating' do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
updater.update(website: 'http://example.com')
|
||||
|
@ -516,7 +500,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when website does not include http' do
|
||||
it 'adds http before updating' do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
updater.update(website: 'example.com')
|
||||
|
@ -527,7 +510,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when website is invalid' do
|
||||
it 'returns an error' do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
||||
expect(updater.update(website: 'ʔ<')).to eq nil
|
||||
|
@ -536,7 +518,6 @@ describe UserUpdater do
|
|||
|
||||
context 'when custom_fields is empty string' do
|
||||
it "update is successful" do
|
||||
user = Fabricate(:user)
|
||||
user.custom_fields = { 'import_username' => 'my_old_username' }
|
||||
user.save
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
|
Loading…
Reference in New Issue