mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Replace #pluck_first freedom patch with AR #pick in core (#19893)
The #pluck_first freedom patch, first introduced by @danielwaterworth has served us well, and is used widely throughout both core and plugins. It seems to have been a common enough use case that Rails 6 introduced it's own method #pick with the exact same implementation. This allows us to retire the freedom patch and switch over to the built-in ActiveRecord method. There is no replacement for #pluck_first!, but a quick search shows we are using this in a very limited capacity, and in some cases incorrectly (by assuming a nil return rather than an exception), which can quite easily be replaced with #pick plus some extra handling.
This commit is contained in:
@@ -683,8 +683,7 @@ RSpec.describe ApplicationHelper do
|
||||
end
|
||||
|
||||
it "returns two color scheme link tags when dark mode is enabled" do
|
||||
SiteSetting.default_dark_mode_color_scheme_id =
|
||||
ColorScheme.where(name: "Dark").pluck_first(:id)
|
||||
SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pick(:id)
|
||||
cs_stylesheets = helper.discourse_color_scheme_stylesheets
|
||||
|
||||
expect(cs_stylesheets).to include("(prefers-color-scheme: dark)")
|
||||
@@ -740,8 +739,7 @@ RSpec.describe ApplicationHelper do
|
||||
helper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user
|
||||
@new_cs = Fabricate(:color_scheme, name: "Custom Color Scheme")
|
||||
|
||||
SiteSetting.default_dark_mode_color_scheme_id =
|
||||
ColorScheme.where(name: "Dark").pluck_first(:id)
|
||||
SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pick(:id)
|
||||
end
|
||||
|
||||
it "returns no dark scheme stylesheet when user has disabled that option" do
|
||||
|
Reference in New Issue
Block a user