tl;dr: Do not use merge! for session hashes. Use update instead. Outline Let's assume you're modifying the Rails session. For simplicity, let's also assume your session...
...is empty when you start (same effect when there is data): # In our example, we're in a Rack middleware request = Rack::Request.new(env) request.session.merge! :hello => 'Universe' request.session => {} Wat?
Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest change is that they moved away from their custom DSL...
...release_roles|...) :some_role do Resources Very helpful, leads you 90% of the upgrade: https://semaphoreci.com/blog/2013/11/26/capistrano-3-upgrade-guide.html Official documentation Many examples of SSHKit...
The sprintf method has a reference by name format option: sprintf("% d : % f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 sprintf("%{foo}f", { :foo => 1 }) # => "1f" The format identifier % stands for...
...this example we are using %s identifier to replace strings. class Fetcher FIND_URI = 'https://someapi.com/3/search/record?query=% s&include_many=% s&language=en-US&page=1' # some public methods
gem install foobar --version="=2.3.0.alpha2" Also bundle update will never update a stable version to a pre-release version unless the user explicitly requests it in the Gemfile...
...gem 'foobar', '=2.3.0.alpha2' A note on Semantic Versioning Semantic Versioning has a naming convention for pre-releases that is incompatible with that from RubyGems. In Semantic Versioning, the version...
Chromedriver (or selenium-webdriver?) will not reliably scroll elements into view before clicking them, and actually not click the element because of that. We've seen this happen for elements...
...a 40px button). Our assumption is that the element is considered visible (i.e. Capybara::Selenium::ChromeNode#visible? returns true for such elements) but the Selenium driver wants to actually click...
You can scale background images in CSS to the container size using background-size (Demo). Commonly, we use contain or cover because we want to preserve the image's aspect...
If you do not want to do that, simply provide scaling values for X and Y: background-size: 100% 100% (a simple 100% would mean 100% auto and respect...
See the attached link for a useful overview of modern (and classic) DOM API methods, like matches, contains, append, cssText, etc. You will still need to look up some documentation...
...e.g. on how to modify a ClassList, but it's still better than browsing interfaces and superclasses of Element on MDN without knowing what to look for. When coming from...
...lambdas in Ruby work, check out the code at the attached link. Here the summary: ^ ---------------------------- Section 6: Summary ---------------------------- So, what's the final verdict on those 7 closure-like entities...
...method Y closure yes The things within each of these groups are all semantically identical -- that is, they're different syntaxes for the same thing: 1. block (called with yield...
This card shows you how to format a card's content using Markdown. We use the Commonmarker interpreter, so here are examples for its dialect. Formatting **Bold** Bold _Italics_
Add a new line for a paragraph. Headlines Underline headlines with an equals sign or dash -- or start a line with a hash symbol: Hello World ----------- Lorem ipsum...
...Ruby parser module of Ruby-GetText comes across a file in one of its search directories (e.g. lib/scripts/) and finds out that you are defining ActiveRecord classes inside it, it...
...the whole file. Here is how to avoid that. What's happening? Let's say you have the following script which is only run once, manually, via script/runner: # lib/scripts/doomsday.rb
jQuery's deferred objects behave somewhat like standard promises, but not really. One of many subtle differences is that there are two ways to chain callbacks to an async functions...
...is done, which only exists in jQuery: $.ajax('/foo').done(function(html) { console.debug("The server responded with %s", html); }); There is also then, which all promise libraries have:
You have an async function that rejects: async function failingFunction() { throw new Error("Something went wrong") } When you call that function in a test, your test will fail:
}) The failure message will look like this: Unhandled promise rejection: Error: Something went wrong You can fix this by expecting the state of the returned promise:
...use Solr by calling Article.search { fulltext(title) paginate(:per_page => limit) } Now look at http://sunspot.github.com/docs/ to learn about all the possibilities of Sunspot. Overwrite Sunspots' search method
...your SysOp team that you'll need Solr on staging and production, on Ubuntu the solr-common will provide what you need. First of all you should provide Solr with...
In CI test runs I noticed that string sorting order changed after switching from a debian-based PostgreSQL docker image to one that is based on Alpine Linux.
...sorting: bar Bar foo Foo Alpine image sorting: Bar Foo bar foo Explanation Alpine Linux is a very slim linux distribution that results in small docker image sizes (roughly 100MB...
...what git checkout and git reset do. Git basics A commit holds a certain state of...
...a directory and a pointer to its antecedent commit. A commit is identified by a so-called ref looking something like 7153617ff70e716e229a823cdd205ebb13fa314d. HEAD is a pointer that is always pointing...
Similar to the Webpack Bundle Analyzer, Chrome's new Lighthouse feature … … shows a visualisation of your JavaScript bundles. It's compatible with sourcemaps and is great for understanding large JavaScript...
...in development. It also works on production code, where its usefulness depends on the structure of the productive Javascript code. Warning This will only work when your bundler emits source...
...open a dialog with the route to your dialog's view. tinymce.init({ // ... toolbar: 'myCustomButton', setup: function(editor) { editor.ui.registry.addButton('myCustom Button', { icon: 'document-properties', tooltip: 'Further describe your button here', onAction...
...insertContent', content: linkTag, }); window.parent.postMessage({ mceAction: 'insertContent', content: ' ', }) window.parent.postMessage({ mceAction: 'close' }); }) function buildLinkTag(form) { // do stuff } }) See here for more commands...
You can say: $(element).is(':visible') and $(element).is(':hidden') jQuery considers an element to be visible if it consumes space in the document. For most purposes, this is...
Emulate jQuery's implementation : element.offsetWidth > 0 && element.offsetHeight > 0; jQuery > 3 Query 3 slightly modifies the meaning of :visible (and therefore of :hidden). Emulate jQuery's implementation: !(window.getComputedStyle(element...
Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for...
Git can help you to find the next git tag that was set in the branch. This usually has the name of the version in it (as the...
If you're on Ruby 2.3+ there's a <<~ operator to automatically unindent HEREDOCs: str = <<~MESSAGE Hello Universe! This is me. Bye! MESSAGE If you have an older Ruby, you...
...can use the String#strip_heredoc method from ActiveSupport. See Summarizing heredoc in ruby and rails for an example. Technically, it looks for the least indented line in the whole...
Web forms can be made much more usable with a few HTML attributes. Short summary: type: Tells browsers about the input data type. Mobile browsers will select a virtual keyboard...
...based on this value. Some browsers will add simple validation, e.g. for type email. inputmode: Direct hint about the virtual keyboard to use. Inferred from type, but can be very...
...you want to clean up this code with the modularity gem, you might try something like this: class Foo does 'bar' end module BarTrait as_trait do class Bar
...you would have to change all references accordingly, which is quite unpleasant. You can solve it like that: module BarTrait as_trait do class self::Bar end end end
...file download links in an end-to-end test can be painful, especially with Selenium. The attached download_helpers.rb provides a download_link method for your Capybara tests. It returns a...
details[:disposition] # => 'attachment' or 'inline' details[:filename] # => 'report.txt' details[:text] # => file content as string details[:content_type] # => 'text/plain' Features Compared to other approaches this helper has many useful features...
...flaky tests. You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist the result of your test runs to a file. This is...
...necessary to be able to rerun examples. Add this to your spec/spec_helper.rb : config.example_status_persistence_file_path = 'spec/examples.txt' Rerun all failed examples using --only-failures bundle exec rspec --only-failures...