Most of the JavaScript snippets have code that manipulates the DOM. For that reason dom manipulating javascript code should have...

...to attach a timestamp or content hash to your asset's filenames, e.g. foo.png becomes foo-2179b43e243cf343.png. This way, when the asset changes, its URL changes. You can now safely tell...

...helper attaches an MD5 hash of the file content to the asset. E.g. /app/assets/foo.png becomes: /assets/foo-2179b43e243cf343.png These hashes will only be added when assets.digests is enabled for your environment (it...

...timing in your tests, this requires a lot of work and sustained diligence. A better approach is to use feature flags to only enable these features for the one test...

...is something that we fixed in the code, not the test. The code is better now. However, it took a day to find a bug that no user has seen...

...form disables the submit button while working. // bad (how we used to do it) beforeEach(() => { this.form = setupMyForm() this.submitButton = findTheSubmitButton() }) it('disables the submit button while working', (done) => { expect(this.submitButton.disabled).toBe...

...our specs to simply return a Promise, so we could rewrite this as // slightly better it('disables the submit button while working', () => { expect(this.submitButton.disabled).toBe(false) let submitPromise = this.form.onSubmit()

cirw.in

If you ever wondered why a constant wasn't defined or wasn't available where you expected it to be...

RSpec's be_false behaves unexpectedly: nil.should be_false # passes, as the expectation returns true If you want to check for false, you need to do it like this:

...initializer provides a default way to deal with this. You'll get the following behaviour: if the incorrect request has a HTTP_REFERER coming from the same application, set a...

...use ActionDispatch::RemoteIp use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use BetterErrors::Middleware use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::Migration::CheckPending use ActionDispatch::Cookies

Below is a strict, but still workable Content Security Policy for your Ruby on Rails project. Use this CSP if...

In /etc/crontab In /etc/cron.d/* In /etc/cron.hourly/* In /etc/cron.daily/* In /etc/cron.weekly/* In /etc/cron.monthly/* In the personal crontab of any user. This...

To do so, call clear_active_connections! before your thread terminates: Thread.new do begin User.first # first database access makes a new connection ensure ActiveRecord::Base.connection_handler.clear_active_connections! # or, in...

With the the Ruby Tempfile class you can create temporary files. Those files only stick around as long as you...

github.com

...that you can also make your matcher chainable, so a test can modifier its behavior. Using chaining you can write a matcher like this: expect(x).to be_a_multiple...

en.wikipedia.org

...the redirect. It is preferrable to use the newer status code to avoid unexpected behavior. 303 See Other The response to the request can be found under another URI using...

...all future requests should be repeated using another URI. 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. So, for...

Rails partials have a lot of "hidden" features and this card describes some non-obvious usages of Rails Partials.

If you need to enable NewRelic monitoring on certain machines within the same Rails environment, a simple solution is to...

...not waste your time optimizing code where it does not even matter. However, I believe there are some kinds of optimizations you should do right away, because they are either...

...how a library works. This is especially true for all polyfill that fix browser behaviours with all weird kinds of tricks. In your own scripts, don't add event handles...

Download buttons can be difficult to test, especially with Selenium. Depending on browser, user settings and response headers, one of...

Xfce gives you a million options to configure your panels. Together with Xfce's sometimes arcane configuration UI, this can...

rubydoc.info

CarrierWave comes with some RSpec matchers which will make testing more comfortable. Let's say you have an Uploader like...

When you repeat a subpattern with a *, + or {...} operator, you may choose between greedy, lazy and possessive modes. Switching modes...

makandra dev

The bash offers control over the behavior of autocompletion. The most primitive example is this (just run it in your bash; if you want it available everywhere, put the complete...

...pattern and many more. complete -p gives you a list of currently defined autocompletions. Behold, thou might not define multiple completions for one command. I recently built a script that...

stackoverflow.com

One really simple way to check whether JavaScript Sentry integration was successful (raven-js or @sentry/browser), is to create an...

Even when you're using bundler, it might be significant in which order your gems are listed in your Gemfile...