...want to be in there. In order to reduce the chance to accidentally commit something you didn't intend, review your changes before committing. My preferred way of doing this...
...paths (including new files), but not their contents git add -p Git will now show you all your changes in small chunks and ask you in an interactive mode whether...
...default it allows only accessing visible elements -- when you are using a driver that supports it (e.g. Selenium, not the default Rack::Test driver). Consider the following HTML: One
...true) or find(..., visible: :visible). Note that you could change the default behavior by setting the ignore_hidden_elements config option. However, ignoring invisible elements is a useful default.
CarrierWave comes with some RSpec matchers which will make testing more comfortable. Let's say you have an Uploader like this: class MyUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick
...different versions of your uploaded files: version :small do process resize_to_fill: [100, 100] end version :medium do process resize_to_fit: [200, nil] end version :large do
...or ::1 (IPv6) can only be reached from your own PC: Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process tcp LISTEN...
...address 0.0.0.0 can be reached from other PCs on your network: Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process tcp LISTEN...
...a global variable in Rails? Ugh, that's the worst. If you need global state, you've probably reached for Thread.current. When you're using Thread.current, you must make sure...
...yourself or your cached data will stay in Thread.current. For Sidekiq, you can use request_store-sidekiq. Cronjobs are unaffected, as a new process is created each time...
When your Rails application server raises error, Capybara will fail your test when it clears the session after the last step. The effect is a test that passes all steps...
...behavior will help you to detect and fix errors in your application code. However, sometimes your application will explode with an error outside your control. Two examples: A JavaScript library...
...just barely wider than the container it should fit into, and it wraps a single word to a new line and it's not really pretty? Cry no more, for...
...in some browsers. When browsers encounter a text-wrapping element with text-wrap: balance style, they will try breaking to a new line sooner, if it balances out the width...
ActiveRecord offers an explain method similar to using EXPLAIN SQL statements on the database. However, this approach will explain all queries for the given scope which may include joins or...
Output will resemble your database's EXPLAIN style. For example, it looks like this on MySQL: User.where(id: 1).includes(:articles).explain EXPLAIN for: SELECT `users`.* FROM `users` WHERE...
...tough challenge. To get more detailed insights consider using the rack-mini-profiler gem. Setup with Unpoly Add the following gems: group :development do gem 'memory_profiler' gem 'rack-mini...
If you have slow views (Haml/Partials can be slow), consider caching them. Remove code & sql-queries that are not needed to render the page. Calling to_a blindly on...
...an event handler, there are multiple methods to cancel event propagation, each with different semantics. event.preventDefault() Only prevents the default browser behavior for the click, i.e. going to a different...
...url or submitting a form. When invoked on a touchstart event, this also prevents mouse events like click to be triggered. event.stopPropagation() Prevents the event from bubbling up the DOM...
When RSpecs runs the first feature spec, you may see log output like this: Capybara starting Puma... * Version 6.5.0, codename: Sky's Version * Min threads: 0, max threads: 4
...on http://127.0.0.1:39949 You can disable this behavior by tweaking Capybara's Puma server in your spec/support/capybara.rb: Capybara.server = :puma, { Silent: true } Note You don't need to configure this...
If you want to switch to another ruby versions, you have several options, depending on what you want: Do you want to switch temporarily, per project, or globally?
Unlike RVM, rbenv does not offer a command like rvm use. By default, it respects your project's .ruby-version file. If you need to change manually...
git shortlog -s -n [commit-range] -n, --numbered Sort output according to the number of commits per author -s, --summary Suppress commit descriptions, only provide commit count [commit-range]
...tagname.. for "everything after that tag" Example output for spreewald: 60 Tobias Kraze 12 Henning Koch 7 Dominik Schöler 6 Thomas Eisenbarth 5 Martin Straub 3 Minh Hemmer...
While it might seem trivial to implement an invoice that sums up items and shows net, gross and vat totals, it actually involves a lot of rules and caveats. It...
...examples in Ruby and MySQL, the concepts apply to all programming languages and data stores. When to round There are exactly two spots where your invoice logic should round money...
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...
def method_missing(method_name, *args, &block) if method_name == :bark 'woof!' else super end end end This will allow you to say: Dog.new.bark => "woof!" But: Dog.new.respond_to? :bark...
Detecting if a Javascript is running under Selenium WebDriver is super-painful. It's much easier to detect the current Rails environment instead. You might be better of checking against...
...the name of the current Rails environment. To do this, store the environment name in a data-environment of your . E.g., in your application layout: <html data-environment=<%= Rails.env %>>
Since I use this a lot in my daily work and there were no scripts working properly for me, I made one myself. It's actually not bound to Xfce...
...t tried it, though). Installation If you don't yet have xdotool, install it: sudo apt-get install xdotool If you don't yet have wmctrl, install it:
You can change which branches will be pushed when saying git push. Our recommendation is to set it to current. From the git-config documentation: push.default Defines the action git...
...branch, but forgot to setup tracking. If you can't currently push, use git branch --set-upstream-to=origin/$(git branch --show-current...
In RSpec you can tag examples or example groups with any tags you like simply by saying describe ReportCreator, slow: true do # .. end describe ReportCreator do it 'generates reports', slow...
# ... end end You can then only run examples with these tags. rspec --tag slow rspec -t slow # Using the parallel_tests gem rake "parallel:spec[,,--tag slow]"
This is a small example on how you can check if your Postgres index can be used by a specific query in you Rails application. For more complex execution plans...
...it might still be a good idea to use the same path of proof. 1. Identify the query your application produces query = User.order(:last_name, :created_at).to_sql
...to read the The framework field guide - Fundamentals, the first of a three part series to learn the basics of frontend technologies. I can highly suggest it for learning the...
...fundamentals. 'The framework field guide' is written by Unicron Utterances and there side has many high quality articles on web development and computer science related to programming. The Framework Field...
Why string sorting sucks in vanilla Ruby Ruby's sort method doesn't work as expected with special characters (like German umlauts): ["Schwertner", "Schöler"].sort # => ["Schwertner", "Schöler"] # you probably expected...
...Schöler", "Schwertner"] Also numbers in strings will be sorted character by character which you probably don't want: ["1", "2", "11"].sort # => ["1", "11", "2"] # you probably expected...
Don't sum up columns with + in a sql-query if NULL-Values can be present. MySQL and PostgreSQL cannot sum up NULL values with the + value. The sum value...
MySQL: mysql> select 1 + 2 + 3; +-----------+ | 1 + 2 + 3 | +-----------+ | 6 | +-----------+ 1 row in set (0,00 sec) mysql> select 1 + NULL + 3; +--------------+ | 1 + NULL + 3 | +--------------+ | NULL...
...popup on all browsers. When you integrate a date picker popup, remember to also set autocomplete="off" on the text input that opens the calendar on click. Otherwise the autocomplete...
...suggestions will cover the calendar box and make it unusable: If you are using a tool like Unpoly you might want to set autocomplete="off" in the JavaScript that also...