How to skip Sprockets asset compile during Capistrano deployment
For applications coming with lots of stylesheets and scripts, asset compilation might take quite long. This can be annoying when deploying a release that does not actually change assets.
When your app uses Sprockets, you can simply skip asset compilation and re-use the previous release's assets. [1]
That is especially easy via Capistrano. Capistrano will automatically symlink your release's public/assets
to a shared directory, so all you need to do is skip the deploy:assets:precompile
task.
Put the following code where you'd put other ...
User-defined Order in SQL
The attached article explains options you have to store the order of items in a database table.
The simplest solution of course is to use a position
column. However the author explores some alternatives where you don't need to update multiple rows when you move a single item.
RSpec: Expecting multiple calls of the same method
If the argument list is the same every time:
expect(object).to receive(:foo).with('argument').and_return('response 1', 'response 2')
If the argument list differs between invocations:
expect(object).to receive(:foo).with('argument 1').ordered.and_return('response 1')
expect(object).to receive(:foo).with('argument 2').ordered.and_return('response 2')
How to resize your boot partition when there is an encrypted partition after it
Boot partitions from installations prior to the 16.04 era are terribly small. When you install updates and encounter errors due to a full /boot
partition, consider risizing it.
If you can't do the steps described below, ask someone experienced to help you out.
This has worked 100% so far. 1 out of 1 tries. ;)
Scenario A: There is unassigned space on your physical drive
When there is some unpartitioned space on your drive, increasing the size of /boot
is actually very easy (even though the list below is rather long). It only takes a...
RubyMine: You can disable inspections you don't care about
When you find yourself constantly ignoring a RubyMine warning, you can simple disable that warning and de-clutter your editor. E.g. in my Cucumber scenarios RubyMine underlines 90% of all lines because it does not know about spreewald, making the file really hard to read.
You can disable any unwanted inspection by opening File / Settings / Editor / Inspections
and searching for the warning text.
What you disable or keep is up to your personal preference. I personally disable at least the following...
Geordi 1.9 released
New features:
geordi delete_dumps [directory]
Recursively search for files ending in *.dump and offer to delete those. When no argument is given, two default directories are searched for dump files: the current working directory and ~/dumps (for dumps created with geordi).
geordi drop_databases
Delete local MySQL/MariaDB and Postgres databases that are not whitelisted.
Authentication is handled via PAM for Postgres and MariaDB, via .my.cnf
with fallback to mysql -p
for MySQL. Different connection methods can be chosen via ...
Running Rails 2 apps with modern MariaDB SQL server
You might have some trouble running a Rails LTS 2 app with MySQL 5.7.
If you don't want to hack Mysql 5.6 into your modern Ubuntu or use the MySQL sandbox, you might want to try MariaDB 10.x.
MariaDB 10.x should work with both old and new Rails applications.
[Switch to MariaDB](https://makandracards.com/makandra/468343-how-...
Store MySQL passwords for development
On your local system that only hosts non-critical development data and only you have access to, you can store MySQL's root password in your home directory so you can use mysql
commands without prompt for passwords, i.e. when doing batch processing.
Of course, this has security implications. The password must be stored in plain text, so this method is out of the question if there's any confidential data in your databases. Assuming diligent screen-locking, an encrypted hard disk and correct permissions set on your credential file, it shoul...
Making httpclient use the operating system's SSL cert store
The httpclient gem comes with a custom SSL cert store.
While an customizable, application-level cert store is great when you need to deal with broken or self-signed certificates, you usually want to use the cert store from the underlying Linux. The Linux cert store is updated periodically while httpclient's cert store goes out of date and will eventually not be able to verify certs.
To use the cert store from the underlying operating system:
client = HTTPClient.new
client.ssl_config.cert_store...
Upgrading a Rails app to Cucumber 3
Upgrade gems
You need to update a lof gems. Make sure you don't have any version constraints in your Gemfile
or your bundle update
won't do anything!
Upgrade cucumber_priority
:
bundle update cucumber_priority
Upgrade spreewald
:
bundle update spreewald
Upgrade cucumber_factory
:
bundle update cucumber_factory
Upgrade parallel_tests
:
bundle update parallel_tests
Even on the latest version, parallel_tests
will print some deprecation warnings due to using an older formatter A...
Delegating an instance method to a class method in Ruby
With ActiveSupport
you can say:
class Robot
def self.likes_humans?
'Nope.'
end
delegate :likes_humans?, to: :class
end
Robot.likes_humans?
# => 'Nope.'
Robot.new.likes_humans?
# => 'Nope.'
Legacy docs for Font Awesome 4.7
See the attached link for a list of icons in Font Awesome 4.
Icon names work differently in Font Awesome 5, where a name is only valid in combination with a name of the icon set.
VNC browser disappears while typing
We often use the Then console
step from spreewald in combination with geordi vnc
from geordi to debug tests within a real browser. Sometimes when you type in the browser it suddenly disappears. You will only see a grey screen then.
This will always happen if you press the d
key. Press the d
key again and the browser will appear again.
Firefox: Focus-sensitive Selenium tests do not work reliably in parallel test execution
This is a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests.
Firefox will not trigger focus/blur events when its window is not focused. While this makes sense in standard usage, it breaks in parallel test execution.
Please do not rely on focus events in your tests. The linked card has an example of how to build passing tests that deal with focus/blur events.
Nested Spreewald patiently blocks are now patient
In Spreewald 1.10.4+, nested patiently
blocks are now patient.
Here is an example:
patiently do
outer_code
patiently do
inner_code
end
end
On spreewald 1.11.2+ the inner block will wait for the full configured wait time (by default 5 seconds). The outer patiently
block would now be out of time, but it will always be retried at least a second time. This behavior allows with_scope
to be patient, and it must be patient, as explained below.
In versions 1.10.4 - 1.11.1, inner blocks would keep giving the ou...
PostgreSQL: Upgrading your user to a superuser
Your default postgres user is named like your linux user. That default user has limited access privileges, which can cause issues such as:
- DatabaseCleaner needs to disable foreign key constraints before it can wipe the database.
- Importing a remote dump with geordi
- Asking Postgres to show the storage path of a database
Doing these things without a superuser will show a Postgres error or (in Ruby) raise PG::InsufficientPrivilege
.
To do so, the application's PostgreSQL user must be a superuser. ...
How to: Fix incorrect MySQL client library version
Bundler::GemRequireError: There was an error while trying to load the gem 'mysql2'.
Gem Load Error is: Incorrect MySQL client library version! This gem was compiled for 5.5.46 but the client library is 5.6.30.
Same as in Fix "libmysqlclient.so.20: cannot open shared object file: No such file or directory":
gem pristine mysql2
gem pristine
re-installs a gem (without re-downloading), re-compiling all native extensions in the process.
How to: Restart vnc server for geordi
Trying to open a vnc window with geordi geordi vnc
ended up with this error:
> VNC viewer could not be opened:
vncviewer: ConnectToTcpAddr: connect: Connection refused
Check if vncserver 17 (default geordi session) is running:
ps -aux|grep vnc
If you see Xvnc4 :17
then the server is already running. Kill this server if it is already running.
vncserver -kill :17
Als...
Mysql::Error: BLOB/TEXT column can't have a default value
mysql> SELECT @@global.version;
+------------------+
| @@global.version |
+------------------+
| 5.6.30 |
+------------------+
1 row in set (0,00 sec)
MySQL 5.6 Reference Manual says "BLOB and TEXT columns cannot have DEFAULT values"
.
If you want to run migrations in development
here are two variants which might help. If you are not sure about the side effects (e.g. your application is broken when it doesn't set additional default values on application side, too...
How to: Solve gem loaded specs mutex
Use bundler > 1.15
to fix Gem::LOADED_SPECS_MUTEX (NameError)
.
Given the following project:
ruby -v
ruby 1.8.7
bundler -v
Bundler version 1.13.7
gem -v
1.8.30
rails -v
Rails 3.2.22.1
Running specs or features resulted in:
uninitialized constant Gem::LOADED_SPECS_MUTEX (NameError)
The previous settings described in Maximum version of Rubygems and Bundler for Ruby 1.8.7 and Rails 2.3 (even the rails version was rails 3.2 and not 2.3) seems not to work here, so I used (also described in the ca...
List of :status symbols for rendering in Rails
When your Rails controller calls render
, you can pass a :status
option for the HTTP status code:
render 'results', status: 400
All important status codes also have a symbol alias, which makes your code easier to read:
render 'results', status: :bad_request
Attached is a list of available symbol values for :status
.
How to stub class constants in RSpec
Hint: There's another card with this helper for Cucumber features.
Sometimes you feel like you need to stub some CONSTANT you have defined in an other class. Since actually constants are called constants because they're constant, there's no way to easily stub a constant.
Here are three solutions for you.
Easiest solution
Rethink! Do you really need CONSTANT = %w[foo bar]
to be constant? In many cases, setting it as a...
How to control Chromedriver using curl
Here is how to use Chromedriver without libraries like selenium-webdriver
. This can be useful for debugging.
The following example visits a web page and reads the a headline's text contents.
-
Create a session:
curl -XPOST http://localhost:9515/session -d '{"desiredCapabilities":{"browserName":"chrome"}}'
You will get a JSON response containing lots of information about your Chrome session, including a
sessionId
. Use this to send any future commands to your chromedriver session.{"sessionId":...
Ruby: Removing leading whitespace from HEREDOCs
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...