RSpec's let allows you to super into "outside" definitions, in parent contexts. Example: describe '#save' do subject { described_class.new(attributes) } let(:attributes) { title: 'Example', user: create(:user) } it 'saves' do...

...expect(subject.save).to eq(true) end context 'when trying to set a disallowed title' do let(:attributes) { super().merge(title: 'Hello') } # <== it 'will not save' do expect(subject.save).to eq...

...that happens on your local machine Manually remove the offending's gem files and specifications. The paths will be something like /usr/lib/ruby/gems/1.8/gems/your-broken-gem and /usr/lib/ruby/gems/1.8/specifications/your-broken-gem Update Rubygems or Slimgems by running...

...gem update --system Run bundler on your project to reinstall the offending gem. If this happens to your during deployment Ask your operations team to do it. After the update...

To read the Rails session from a Rack middleware, use env['rack.session']. It's an ActionDispatch::Request::Session object. class MyMiddlware def initialize(app) @app = app end def call(env...

...status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is: " + session['foo'].inspect) [status, headers, body] end end You may not be able to write to...

paperplanes.de

This post is not about devops, it's not about lean startups, it's not about web scale, it's not about the cloud, and it's not about continuous...

Let's say you have two XML strings that are ordered differently but you don't care about the order of attributes inside containers: a = ' batman secret ' b = ' secret batman...

...Working with plain string comparison is not helpful, of course: a == b => false Instead, you can use the Nori gem to convert your XML into a hash: xml_parser = Nori.new...

When you set both a record's association and that association's foreign key attribute, Rails does not realize you are talking about the same thing. The association change will...

...win in the next save, even if the foreign key attribute was changed after the association. As an example, assume you have these two models: class Group < ActiveRecord::Base

github.com

fake_stripe spins up a local server that acts like Stripe’s and also serves a fake version of Stripe.js, Stripe’s JavaScript library that allows you to collect your...

...customers’ payment information without ever having it touch your servers. It spins up when you run your feature specs, so that you can test your purchase flow without hitting Stripe...

...needed a way to make my apps full screen from bash scripts. There is no super-easy way, but it's not too hard either. Put the attached script into...

...e.g. /usr/local/bin and make it executable. Now you can call fullscreen Safari and Safari will go full screen. Notes This script needs activated access for assisting devices. Turn it on...

apidock.com

...can be especially painful when external code (read: gems) uses const_defined? to look something up and gets different results on different Rubies. Consider this: module Foo FOO = 42

end On Ruby 1.8, Bar won't have FOO defined as a constant since that's (even though it's accessible): 1.8.7 > Foo.const_defined? :FOO => true 1.8.7 > Bar.const_defined...

makandra dev

...capistrano_colors' end It's possible you need to do a bundle update net-ssh to get things running. Now double check that all your custom hooks are actually still...

...called. One candidate might be an after deploy:symlink hook that has been renamed into after deploy:create_symlink. I also suggest to put a safeguard into your deploy.rb that...

makandra dev
activestate.com

...and a damaged reputation. Deploy Ruby with confidence knowing you're using the most secure, enterprise-grade builds for the platforms that power your business. You'll get priority access...

...fail-safe Ruby for business applications, but don't require advanced features like indemnification or site-wide licensing. Business Edition customers trust ActiveState's guaranteed technical support and regular fixes...

...association. For example you can put the blank form on top with the following snippet: actors = movie.actors actors.build actors.unshift(actors.pop(1)) # won't work with Rails 4+ Because build_for...

...one-to-many association collection object you only have to reorder the collection objects. Sorting with Rails 3+ = form.fields_for :children, @parent.children.sort_by(&:name) do |fieldsform...

developer.chrome.com

In the DevTools settings, there's a "Shortcuts" section. Found these keyboard shortcuts there: General ESC Toggle drawer CTRL + ~ or CTRL + ` Show console in drawer Styles SHIFT + up/down

...debugging page repaint times) CTRL + hover above element in the DOM list Don't show the yellow dimensions tooltip (useful when the tooltip covers just the area you need to...

...OPTS="--no-tcmalloc" rbenv install, but that would disable tcmalloc. Doing that, you might still encounter issues with ossl_ssl.c -- which is where I switched to the patched solution above...

...without_callbacks. There is no such thing in vanilla Rails 3. There is a gem sneaky-save that restores the missing functionality with a #sneaky_save method...

Deadlocks only occur if two transactions in separate threads compete for the same rows in the database. They usually (but not necessarily) only happen when trying to update or otherwise...

...lock several rows in different order. Solving deadlocks is potentially complicated, so here are a few pointers: MySQL should always detect the deadlock right when it happens, and will throw...

String#indent is not a standard Ruby method. When you use it, be sure to know where this method comes from. Many Gems shamelessly define this method for internal usage...

...and you'll never know when it may be removed (since it's usually not part of the Gem's API). Unless you're using Rails 4 (which brings String...

...both column name and value are coming from user input and need to be sanitized. Unfortunately this works in SQLite but does not in MySQL: named_scope :filter, lambda { |attribute...

{ :conditions => [ 'articles.? = ?', attribute, value ] } } The solution is to use sanitize_sql_array like this: named_scope :filter, lambda { |attribute, value| { :conditions => sanitize_sql_array([ "`articles`.`%s` = '%s'", attribute, value...

Current webkit browsers like Chrome and Safari have a special variable in their consoles that refers to the selected DOM node in the elements panel. This lets us easily inspect...

...Angular scopes. Right click in the page and click "Inspect" to open the Dev Tools Select the element you're interested in from the elements panel Focus the console (in...

Here's a one-liner to view base64 encoded secrets in kubernetes. Make sure you have jq installed. $ kubectl get -n $NAMESPACE secret/$SECRET_NAME -o json| jq '.data | map...

...values(@base64d)' { "database": "secret1", "endpoint": "secret2", "username": "secret3", "password": "secret4...

...it's likely that your cucumber.yml is just fine but not your rerun.txt.\ This sometimes happens when running multiple Cucumber workers with parallel_tests that write into rerun.txt simultaneously -- ending...

...Just remove it and you are good to go again: rm rerun.txt Another possible solution is to have one rerun file per worker for which you'd need to modify...

Back in the old days, we couldn't do something like that: .foo { position: absolute; bottom: 0; /* This was bad: */ left: 10px; right: 10px; } Why? Because IE5 and IE6 (which...

...then) failed horribly trying to render it. I've now checked if this is still an issue with any browser that's not from the stone age. \

...because a printer's resolution is usually much higher than that of a computer screen. If an image absolutely must look awesome when printed, a solution is to embed the...

...image in much higher solution than needed (e.g. four times the horizontal resolution), then scale it down to the desired width using CSS. Note that this will slightly alter the...

When dealing with external data sources, you may have to deal with improperly encoded strings. While you should prefer deciding on a single encoding with the data-providing party, you...

...can not always force that on external sources. It gets worse when you receive data with encoding declaration that does not reliably fit the accompanying string bytes.