...between the two methods is that unresolvable constants raise an error with constantize, but return nil with safe_constantize. If you validate the input string against an allowlist, an error...
...not correspond to a valid constant or if the constant is not accessible, it returns nil: "String".safe_constantize # => String "NonExistentClass".safe_constantize # => nil "Module::ExistingClass".safe_constantize # => Module::ExistingClass...
Unit test with error describe UsersHelper do describe '#user_display_name' do it 'returns the first and last name of a user' do user = FactoryBot.create(:user) allow(helper).to...
...receive(:current_user).and_return(user) expect(helper.user_display_name).to eq('Jim Knopf') end end end Error: does not implement: current_user Solutions RSpec >= 3.6 Unit test fixed with...
...to run code when an element is removed from the DOM. When your compiler returns a function, it is called when the element is detached from the DOM: compiler('textarea.wysiwyg...
let editor = new SuperEditor(select) return () => editor.shutdown...
const controller = new CustomDirectUploadController(input, input.files[0]) controller.start(storedInput) } const hasFile = function() { return (storedInput?.value !== undefined && storedInput?.value !== '') || input.value !== '' } const updateClearButton = function() { clearButton.classList.toggle('visually-hidden', !hasFile()) // Make sure...
...app/models/test.rb +++ app/models/test.rb @@ -19,6 +19,10 @@ module RoutingFilter path = Rails.root / 'app' + if true + + end + return path (1/1) Discard this hunk from worktree [y,n,q,a,d,e,?]? ?
...may also provide a block that inspects an error object. To ignore the error, return a truthy value: BrowserConsole.ignore do |error| error.message.size < 100 end Default ignore rules By default BrowserConsole...
...Relation#traverse_association(*names) Edge Rider gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. You can traverse multiple associations in...
...users WHERE sites.user_id = sites.id AND users.name = 'Bruce' It now uses these IDs to return a new relation that has no joins and a single condition on the id column...
...pool has a "reaper thread" that periodically looks for connections from inactive threads and returns them to the pool. By default the reaper runs once every 60 seconds. You can...
Will the pool ever close an unused connection? A released connection will be returned to the pool, but not disconnect from the database server. The connection will remain connected...
...created_at: 2.days.ago..), including orphan checks via where.missing(...). Important The inverted scope will not return rows where role is NULL, since in NOT NULL equals NULL in SQL. If this...
...the database adapter gives you methods like select_rows or select_all. These methods return query results as simple arrays, hashes, strings, numbers, etc.: select_all('SELECT * FROM articles') # => [ { 'name...
...an uncommon way to retrieve a file using selenium where JavaScript is used to return a binary data array to Ruby code. The following code example retrieves a PDF but...
...array of 8-bit unsigned integers # => [37, 208, 212, ...] const unsingedInt8Array = new Uint8Array(arrayBuffer) return unsingedInt8Array JS # convert the array we got from JS into a binary string which we...
...receive a locale parameter from a matching URL segment. Before Rails 7.1, this method returned all associated routes (as enumerable) and the using methods iterated over them. As the using...
...methods like serve do not actually need all routes, but may return early, a change has been introduced to add lazy behavior by adding an iterator block and yielding. This...
...nameCache: TERSER_NAME_CACHE, // preserve renames across files } function terserPlugin(terserOptions = DEFAULT_TERSER_OPTIONS) { return { name: 'terserPlugin', setup(build) { build.onLoad({ filter: /\.js$/ }, async (args) => { const text = await fs.promises.readFile(args.path, "utf8...
...let { code, map } = await terser.minify(text, terserOptions) return { contents: code, loader: 'js', } }) } } } Use the plugin in your build() or context() options: esbuild.build({ entrypoints: [...], minify: true, // prevent esbuild from pretty-printing...
Retrieve child nodes contents() (which behaves like children() except that it returns all types of child nodes) Filter manually using either plain Javascript or jQuery's filter...
Example Let's write a function that takes a jQuery element and returns an array of all child nodes that are text nodes: function selectTextNodes($container) { return $container.contents().filter...
...The execution times in the examples are very high, usually a Bitmap Index Scan returns within a few milliseconds. The approach above assumes you have a search_text field, where...
...const taskName = options.taskName || `observed changes in ${formOrField}` const delay = options.delay || formOrField.getAttribute('up-delay') || up.form.config.observeDelay return up.on(formOrField, 'input change', () => { window.CapybaraLockstep.startWork(taskName) setTimeout(() => window.CapybaraLockstep.stopWork(taskName), delay) }) } } if (window.CapybaraLockstep) { // lock capybara for...
...all changes to fields with callbacks up.compiler('[up-observe]', (formOrField) => { return lockCapybaraForObservedChanges(formOrField, { taskName: `[up-observe]: ${formOrField}` }) }); up.compiler('[up-autosubmit]', (formOrField) => { return lockCapybaraForObservedChanges(formOrField, { taskName: `[up-autosubmit]: ${formOrField}` }) }); up.compiler('[up...
The Edge Rider gem gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. Say we have a Post model and each...
...traversal is achieved internally by collecting all foreign keys in the current relation and return a new relation with an IN(...) query (which is very efficient even for many thousand...
When you use method_missing to have an object return something on a method call, always make sure you also redefine respond_to_missing?. If you don't do it...
...is not defined within the receiver. When it has not been defined properly, its return value is a false negative! Thus, you need to patch respond_to_missing? as well...
...with 100 comments and 10 attachments. The OUTER JOINs will cause the query to return 1000 database rows, the full cross product of the blog post × all its comments × all...
...If you want to check your setting, do the following. By default, it will return matching (see above). $ git config --global push.default matching So to change that to push only...
...error, it will fail with a not-so-helpful error message: expected present? to return true, got false (Spec::Expectations::ExpectationNotMetError) Solution That can be fixed easily. RSpec expectations allow...
...in replacement for trigger() (requires Unpoly): jQuery.fn.triggerNative = function(...args) { this.each(function() { up.emit(this, ...args) }) return this } With this you can replace a call like $element.trigger('change') with $element.triggerNative('change'). You...
if (!$event.originalEvent) { let eventProps = up.util.only($event, ...convertedPropNames) up.emit($event.target, eventName, eventProps) up.event.halt($event) } }) return this } Here is an example usage: $element.select2().enableNativeEvent('change') Make sure this function is applied...
...HTTPS forwarding header, Rails recognizes that a request originally was on HTTPS and will return the correct protocol. Caveats: You need to harden your server setup to forbid the routing...
...that dynamically composes person.firstName and person.lastName: var person = { firstName: 'Guybrush', lastName: 'Threepwood', get fullName() { return this.firstName + " " + this.lastName; }, set fullName(name) { var parts = name.split(" "); this.firstName = parts[0]; this.lastName = parts[1]; } };
...use Object.defineProperty() instead: var person = { firstName: 'Guybrush', lastName: 'Threepwood' }; Object.defineProperty(person, "fullName", { get: function() { return this.firstName + " " + this.lastName; }, set: function(name) { var parts = name.split(" "); this.firstName = parts[0]; this.lastName = parts[1]; } });