DEV: Allow fab! without block (#24314)

The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
This commit is contained in:
Daniel Waterworth
2023-11-09 16:47:59 -06:00
committed by GitHub
parent d91456fd53
commit 6e161d3e75
471 changed files with 1277 additions and 1273 deletions

View File

@@ -4,9 +4,9 @@ describe "Admin Customize Form Templates", type: :system do
let(:form_template_page) { PageObjects::Pages::FormTemplate.new }
let(:ace_editor) { PageObjects::Components::AceEditor.new }
fab!(:admin) { Fabricate(:admin) }
fab!(:form_template) { Fabricate(:form_template) }
fab!(:category) { Fabricate(:category) }
fab!(:admin)
fab!(:form_template)
fab!(:category)
before do
SiteSetting.experimental_form_templates = true

View File

@@ -1,9 +1,9 @@
# frozen_string_literal: true
describe "Admin Customize Themes", type: :system do
fab!(:color_scheme) { Fabricate(:color_scheme) }
fab!(:theme) { Fabricate(:theme) }
fab!(:admin) { Fabricate(:admin) }
fab!(:color_scheme)
fab!(:theme)
fab!(:admin)
before { sign_in(admin) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Admin Revamp | Sidebar Naviagion", type: :system do
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
let(:sidebar_page) { PageObjects::Components::NavigationMenu::Sidebar.new }
before do

View File

@@ -2,7 +2,7 @@
describe "Admin Site Setting Search", type: :system do
let(:settings_page) { PageObjects::Pages::AdminSettings.new }
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
before do
SiteSetting.title = "Discourse"

View File

@@ -4,7 +4,7 @@ describe "Admin User Badges Page", type: :system do
before { SiteSetting.enable_badges = true }
fab!(:granter) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:badge) { Fabricate(:manually_grantable_badge) }
let(:user_badges_page) { PageObjects::Pages::AdminUserBadges.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Bookmarking posts and topics", type: :system do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:current_user) { Fabricate(:user) }
fab!(:post) { Fabricate(:post, topic: topic, raw: "This is some post to bookmark") }
fab!(:post_2) { Fabricate(:post, topic: topic, raw: "Some interesting post content") }

View File

@@ -1,10 +1,10 @@
# frozen_string_literal: true
describe "Edit Category", type: :system do
fab!(:color_scheme) { Fabricate(:color_scheme) }
fab!(:theme) { Fabricate(:theme) }
fab!(:admin) { Fabricate(:admin) }
fab!(:form_template) { Fabricate(:form_template) }
fab!(:color_scheme)
fab!(:theme)
fab!(:admin)
fab!(:form_template)
fab!(:form_template_2) { Fabricate(:form_template) }
fab!(:category) do
Fabricate(:category, name: "Cool Category", slug: "cool-cat", topic_count: 3234)

View File

@@ -1,10 +1,10 @@
# frozen_string_literal: true
describe "Viewing top topics on categories page", type: :system, js: true do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:category_list) { PageObjects::Components::CategoryList.new }
let(:topic_view) { PageObjects::Components::TopicView.new }
fab!(:category) { Fabricate(:category) }
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:post) { Fabricate(:post, topic: topic) }

View File

@@ -3,7 +3,7 @@
describe "Change Owner Modal", type: :system do
fab!(:post) { Fabricate(:post, raw: "This is some post to change owner for") }
fab!(:other_user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
let(:user) { post.user }
let(:topic) { post.topic }
let(:topic_page) { PageObjects::Pages::Topic.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Composer Form Templates", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:form_template_1) do
Fabricate(
:form_template,

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe "Default to Subcategory when parent Category doesn't allow posting", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:group) { Fabricate(:group) }
fab!(:user)
fab!(:group)
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
fab!(:default_latest_category) { Fabricate(:category, name: "General") }
fab!(:category) { Fabricate(:private_category, group: group, permission_type: 3) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Composer don't feed the trolls popup", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:troll) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post) { Fabricate(:post, user: user, topic: topic) }

View File

@@ -4,7 +4,7 @@ describe "Composer Post Validations", type: :system, js: true do
fab!(:tl0_user) { Fabricate(:user, trust_level: 0) }
fab!(:tl1_user) { Fabricate(:user, trust_level: 1) }
fab!(:tl2_user) { Fabricate(:user, trust_level: 2) }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
let(:composer) { PageObjects::Components::Composer.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Composer using review_media", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:topic) { Fabricate(:topic, category: Category.find(SiteSetting.uncategorized_category_id)) }
fab!(:post) { Fabricate(:post, topic: topic) }
let(:topic_page) { PageObjects::Pages::Topic.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Composer Form Template Validations", type: :system, js: true do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:form_template) do
Fabricate(
:form_template,

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "CSV Exports", type: :system do
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
let(:csv_export_pm_page) { PageObjects::Pages::CSVExportPM.new }
let(:time_format) { "%Y-%m-%d %H:%M:%S UTC" }

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe "Custom sidebar sections", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user)
fab!(:admin)
let(:section_modal) { PageObjects::Modals::SidebarSectionForm.new }
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }

View File

@@ -49,7 +49,7 @@ describe "Navigating with breadcrumbs", type: :system do
end
context "with tags" do
fab!(:tag) { Fabricate(:tag) }
fab!(:tag)
fab!(:c1_topic_tagged) { Fabricate(:topic, category: category1, tags: [tag]) }
fab!(:c3_topic_tagged) { Fabricate(:topic, category: category3, tags: [tag]) }
fab!(:c3_child_topic_tagged) { Fabricate(:topic, category: category3_child, tags: [tag]) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Dismissing New", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:discovery) { PageObjects::Pages::Discovery.new }
let(:topic_list_controls) { PageObjects::Components::TopicListControls.new }
@@ -56,7 +56,7 @@ RSpec.describe "Dismissing New", type: :system do
end
describe "when a user has a new topic" do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
it "should remove the new topic across sessions after the user dismisses it" do
sign_in(user)
@@ -132,7 +132,7 @@ RSpec.describe "Dismissing New", type: :system do
end
context "with a tagged topic" do
fab!(:tag) { Fabricate(:tag) }
fab!(:tag)
fab!(:tagged_topic) { Fabricate(:topic, tags: [tag]) }
fab!(:tagged_first_post) { Fabricate(:post, topic: tagged_topic) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Editing sidebar categories navigation", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:category2) { Fabricate(:category, name: "category2") }

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe "Editing Sidebar Community Section", type: :system do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:admin)
fab!(:user)
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
let(:sidebar_header_dropdown) { PageObjects::Components::NavigationMenu::HeaderDropdown.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Editing sidebar tags navigation", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:tag1) { Fabricate(:tag, name: "tag").tap { |tag| Fabricate.times(3, :topic, tags: [tag]) } }
fab!(:tag2) do

View File

@@ -4,7 +4,7 @@ describe "Emoji deny list", type: :system do
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:composer) { PageObjects::Components::Composer.new }
let(:emoji_picker) { PageObjects::Components::EmojiPicker.new }
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
before { sign_in(admin) }
@@ -44,7 +44,7 @@ describe "Emoji deny list", type: :system do
Emoji.clear_cache && Discourse.request_refresh!
end
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
xit "should remove denied emojis from emoji picker" do

View File

@@ -3,7 +3,7 @@
describe "Fast edit", type: :system do
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:fast_editor) { PageObjects::Components::FastEditor.new }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:post_2) { Fabricate(:post, topic: topic, raw: "It twas a great “time”!") }
fab!(:current_user) { Fabricate(:admin) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Filtering topics", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:topic_query_filter) { PageObjects::Components::TopicQueryFilter.new }
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
@@ -44,7 +44,7 @@ describe "Filtering topics", type: :system do
end
describe "when filtering by status" do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
it "should display the right topics when the status filter is used in the query string" do

View File

@@ -5,7 +5,7 @@ describe "Granting Badges", type: :system do
context "when in topic" do
fab!(:post) { Fabricate(:post, raw: "This is some post to bookmark") }
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
fab!(:badge_to_grant) { Fabricate(:manually_grantable_badge) }
fab!(:other_badge) { Fabricate(:manually_grantable_badge) }
let(:user) { post.user }

View File

@@ -3,7 +3,7 @@
describe "Group Card", type: :system do
fab!(:current_user) { Fabricate(:user) }
fab!(:members) { Fabricate.times(12, :user) }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:group) { Fabricate(:public_group, users: members) }
let(:mention) { "@#{group.name}" }
let(:post_with_mention) do

View File

@@ -2,8 +2,8 @@
describe "Group members", type: :system do
let(:group_page) { PageObjects::Pages::Group.new }
fab!(:admin) { Fabricate(:admin) }
fab!(:group) { Fabricate(:group) }
fab!(:admin)
fab!(:group)
before { sign_in(admin) }

View File

@@ -243,7 +243,7 @@ describe "Using #hashtag autocompletion to search for and lookup categories and
end
context "when a user cannot access the category for a hashtag cooked in another post" do
fab!(:admin) { Fabricate(:admin) }
fab!(:admin)
fab!(:manager_group) { Fabricate(:group, name: "Managers") }
fab!(:private_category) do
Fabricate(:private_category, name: "Management", slug: "management", group: manager_group)

View File

@@ -32,7 +32,7 @@ RSpec.describe "Keyboard shortcuts", type: :system do
end
context "when on a public topic page" do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
it "doesn't archive the topic" do
topic_page.visit_topic(topic)

View File

@@ -1,10 +1,10 @@
# frozen_string_literal: true
describe "New topic list", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:group) { Fabricate(:group, users: [user]) }
fab!(:category) { Fabricate(:category) }
fab!(:tag) { Fabricate(:tag) }
fab!(:category)
fab!(:tag)
fab!(:new_reply) do
Fabricate(:post).topic.tap do |topic|

View File

@@ -2,8 +2,8 @@
describe "Reviewables", type: :system do
let(:review_page) { PageObjects::Pages::Review.new }
fab!(:admin) { Fabricate(:admin) }
fab!(:theme) { Fabricate(:theme) }
fab!(:admin)
fab!(:theme)
fab!(:long_post) { Fabricate(:post_with_very_long_raw_content) }
before { sign_in(admin) }
@@ -57,7 +57,7 @@ describe "Reviewables", type: :system do
end
describe "when there is a reviewable user" do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:rejection_reason_modal) { PageObjects::Modals::RejectReasonReviewable.new }
before do

View File

@@ -2,7 +2,7 @@
describe "Search", type: :system do
let(:search_page) { PageObjects::Pages::Search.new }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic, raw: "This is a test post in a test topic") }
describe "when using full page search on mobile" do

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Topic page", type: :system do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
before { Fabricate(:post, topic: topic, cooked: <<~HTML) }
<h2 dir="ltr" id="toc-h2-testing" data-d-toc="toc-h2-testing" class="d-toc-post-heading">

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe "Viewing user staff info as an admin", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user)
fab!(:admin)
let(:user_page) { PageObjects::Pages::User.new }
before { sign_in(admin) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "User preferences for Account", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:user_account_preferences_page) { PageObjects::Pages::UserPreferencesAccount.new }
let(:avatar_selector_modal) { PageObjects::Modals::AvatarSelector.new }
before { sign_in(user) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "User preferences for Interface", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:user_preferences_page) { PageObjects::Pages::UserPreferences.new }
let(:user_preferences_interface_page) { PageObjects::Pages::UserPreferencesInterface.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "User page navigation menu", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:everyone_group) { Group[:everyone] }
let(:user_preferences_page) { PageObjects::Pages::UserPreferences.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "User selector", type: :system do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:current_user) { Fabricate(:admin) }
fab!(:user) { with_search_indexer_enabled { Fabricate(:user, username: "someone") } }

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe "Viewing a category", type: :system do
fab!(:category) { Fabricate(:category) }
fab!(:user) { Fabricate(:user) }
fab!(:category)
fab!(:user)
let(:category_page) { PageObjects::Pages::Category.new }
let(:topic_list) { PageObjects::Components::TopicList.new }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Viewing group members", type: :system do
fab!(:group) { Fabricate(:group) }
fab!(:group)
fab!(:user_in_group_1) { Fabricate(:user).tap { |u| group.add(u) } }
fab!(:user_in_group_2) { Fabricate(:user).tap { |u| group.add(u) } }
fab!(:user_in_group_3) { Fabricate(:user).tap { |u| group.add(u) } }

View File

@@ -8,8 +8,8 @@ describe "Viewing sidebar preferences", type: :system do
before { SiteSetting.navigation_menu = "sidebar" }
context "as an admin" do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:admin)
fab!(:user)
before { sign_in(admin) }

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "Viewing sidebar mobile", type: :system, mobile: true do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:sidebar_dropdown) { PageObjects::Components::SidebarHeaderDropdown.new }
let(:composer) { PageObjects::Components::Composer.new }

View File

@@ -1,8 +1,8 @@
# frozen_string_literal: true
describe "Viewing sidebar as logged in user", type: :system do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:admin)
fab!(:user)
fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) }
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }

View File

@@ -1,12 +1,12 @@
# frozen_string_literal: true
RSpec.describe "Viewing User Menu", system: true do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:user_menu) { PageObjects::Components::UserMenu.new }
describe "when viewing replies notifications tab" do
fab!(:topic) { Fabricate(:topic) }
fab!(:topic)
it "should display group mentioned notifications in the tab" do
Jobs.run_immediately!