Reset mysql root password
This article describes how to reset MySQL's or MariaDB's root password on your workstation. It's meant for local development purposes only, don't do this in production. This article will also help you if you have a fairly recent MariaDB version that uses authentication based on linux users instead of passwords for the root user and you prefer using a password for root.
Solution
Step 1 is getting a root mysql shell that allows us to change user credentials. We need to stop the mysql
daemon first and re-start it without authorization c...
RSpec and Cucumber: Shorthand syntax to run multiple line numbers in the same file
This works in modern RSpecs (RSpec >= 2.x) and Cucumbers:
rspec spec/models/node_spec.rb:294:322
cucumber features/nodes.feature:543:563:579
Also your features should be shorter than that :)
How to inspect controller filter chains in specs
Sometimes you need to look at the filter chain in specs. You can do it like that on Rails 2:
controller.class.filter_chain.map(&:method)
Note that we need to look at the controller's class since before_filter
and after_filter
stuff happens on the class level.
Also mind that the above code will give you all filters, both those run before and after an action. You can query before?
and after?
on the filter objects to scope down to only some of them:
controller.class.filter_chain.select(&:before?).map(&:method)
For Rails 3, ...
Understanding the Selenium error "Modal Dialog Present" (aka Selenium::WebDriver::Error::UnhandledAlertError)
So your Cucumber feature sometimes dies with this exception:
Modal Dialog Present (Selenium::WebDriver::Error::UnhandledAlertError)
As a seasoned Selenium veteran you are used to misleading error messages. Hence you might be surprised that the reason for this particular error is that there is actually a modal dialog present and preventing Selenium from executing commands like click
or page.have_css?
.
How your code triggers this issue
The reason why a dialog is shown is somewhat fucked ...
RubyMine: Accessing views and partials from controllers
You can quickly access views that belong to a controller by using the tiny "page with arrow" icon in the gutter:
Access a method's view file
Click the icon next to the method definition in the controller.
If a view file does not yet exist, RubyMine will prompt you for its filename.
All views & partials associated to a controller
For a list of all views and partials that belong to the current ...
Mock the browser time or time zone in Selenium features
In Selenium features the server and client are running in separate processes. Therefore, when mocking time with a tool like Timecop, the browser controlled by Selenium will still see the unmocked system time.
timemachine.js allows you to mock the client's time by monkey-patching into Javascript core classes. We use timemachine.js in combination with the Timecop gem to synchronize the local browser time to the ...
Git Landscaping
I recently worked on a project with 60+ old feature branches. Most of them had been merged into master and were subsequently abandoned. We decided we wanted to clean up a bit, and git made that easy.
Firebug tip: Log DOM Events
This Firebug feature is called simply Log Events and allows developers to log DOM events into the Console panel.
All you need to do is right click on an element in the HTML panel, pick Log Events from the context menu and switch to the Console panel to see the logs in action.
jQuery 1.8 Released
No big features, but many improvements under the hood:
- Faster selector engine
- Many bug fixes
Note that jQuery 2.0, scheduled for early 2013, will remove support for IE6 and 7. Before that there will be one more minor release with 1.9 that still has support for ancient IEs.
Modifying Rake Tasks - Dan Manges's Blog
For custom Rake tasks, you shouldn't need to modify them after the original definition. However, if you want to add behavior to some vendor tasks (such as those defined with Rails), this blog post will cover how to do that.
Consul 0.4.0 released
Consul 0.4.0 comes with some new features.
Dependencies
- Consul no longer requires
assignable_values
, it's optional for when you want to use theauthorize_values_for
macro. - Consul no longer uses
ActiveSupport::Memoizable
because that's deprecated in newer Railses. Consul now uses Memoizer for this.
Temporarily change the current power
When you set Power.current
to a power in an RS...
Use the "paper_trail" gem to track versions of records
paper_trail
is an excellent gem to track record versions and changes.
You almost never want to reimplement something like it yourself. If you need to log some extra information, you can add them on top.
It comes with a really good README file that holds lots of examples. I'll show you only some of its features here:
-
- Setting up a model to track changes
- Just add
has_paper_trail
to it:
class User < ActiveRecord::Base
has_paper_trail
end
-
- Accessing a previous version
- Saying
user.previous_version
gi...
How to change will_paginate's "per_page" in Cucumber features
The will_paginate
gem will show a default of 30 records per page.
If you want to test pagination in a Cucumber feature, you don't want to create 31 records just for that.
Instead, you probably want to modify the number of items shown, by saying something like this:
Given we paginate after 2 users
Using the following step definition, you now can! :)
require 'cucumber/rspec/doubles'
Given /^paginate after (\d+) (.*)$/ do |per_page, model_name|
model = model_name.singularize.gsub(/...
Git: How to rebase your feature branch from one branch to another
In a nutshell: Use git rebase --onto target-branch source-commit
-
target-branch
means "branch you want to be based on" -
source-commit
means "commit before your first feature commit"
Let's say my-feature-branch
is based on master
and we want it to be based on production
. Consider this history:
%%{init: { 'gitGraph': {'showCommitLabel': true, 'mainBranchName': 'production'}} }%%
gitGraph
commit id: "1"
commit id: "2"
branch master
commit id: "3"
commit id: "4"
branch my-feature...
jQuery.cssHooks – jQuery API
The $.cssHooks object provides a way to define functions for getting and setting particular CSS values. It can also be used to create new cssHooks for normalizing CSS3 features such as box shadows and gradients.
For example, some versions of Webkit-based browsers require -webkit-border-radius to set the border-radius on an element, while earlier Firefox versions require -moz-border-radius. A css hook can normalize these vendor-prefixed properties to let .css() accept a single, standard property name (border-radius, or with DOM property synt...
Updated: Capybara: Check that a page element is hidden via CSS
- The step we used in the past (
Then "foo" should not be visibile
) doesn't reliably work in Selenium features. - I overhauled the entire step so it uses Javascript to detect visibility in Selenium.
- The step has support for jQuery and Prototype projects, so it should be a drop-in replacement for all your projects.
- For Rack::Test the step no longer uses XPath so you should be able to understand it when you are not a cyborg :)
- There were some other cards detailing alternative steps to detect visibility. I deleted all these other cards s...
RubyMine: Using pinned tabs will increase your productivity
I highly recommend that you make use of RubyMine's feature to pin tabs.
When you pin all "important" files, you can follow method definitions, wildly open files from search results and have a ton of open tabs -- without the problem of finding the stuff you were working on before.
Guide
- Pin the tabs of files that are currently in the focus of your work (important models, specs, etc):
- Right-click a tab and select "Pin tab"
- Or use a shortcut (see below)
- Work as usual.
- Once you opened other tabs because you searched ...
Click on a piece of text in Cucumber / Capyabra
The step definition below lets you write:
When I click on "Foo"
This is useful in Selenium features where the element you click on is not necessarily a link or button, but could be any HTML element with a Javascript event binding.
The easiest way to get this step is to use Spreewald. If you would like to add it manually, here is the step definition:
When /^I click on "([^\"]+)"$/ do |text|
matcher = ['*', { :text => text }]
element = page.find(:css, *matcher)
while be...
Speed up large Cucumber test suites
Test suites usually grow over time as more and more development time is spent on a projects. Overall run-time and performance of Cucumber suites in turn increases, too.
You can use the very same way Henning suggested for speeding up RSpec some time ago.
Put the following into features/support/deferred_garbage_collection.rb
Before do
DeferredGarbageCollection.start
end
After do
DeferredGarbageCollection.reconsider
end
We...
New cards feature: Personal RSS feed that includes public and private cards
Your account profile now links to a personal RSS feed. This RSS feed contains the newest public and private cards for all your decks.
New cards feature: Explicit language declaration for syntax highlighting
Makandra cards will auto-detect the language used for syntax highlighting.
This auto-detection sometimes fails for short code snippets. In such cases you can explicitly declare the language for Github-style code blocks:
```css
body {
font-size: 12px
}
```
Will turn into this:
body {
font-size: 12px
}
To disable syntax highlighting entirely use the text
language:
```text
I am nothing without pretend
...
Cucumber: Calling multiple steps from a step definition
When refactoring a sequence of steps to a new, more descriptive step, you can use the steps
method and Ruby's %-notation like this:
Given 'I have an article in my cart' do
steps %(
When I go the article list
And I open the first article
And I press "Add to cart"
)
end
This way you can simply copy the steps over without any changes.
Warning: Apparently, steps
processes its argument with the Gherkin parse...
How to: Specify size of Selenium browser window
Applications often show or hide elements based on viewport dimensions, or may have components that behave differently (like mobile vs desktop navigation menus).
Since you want your integration tests to behave consistently, you want to set a specific size for your tests' browser windows.
Using WebDriver options / Chrome device metrics
For Google Chrome, the preferred way is setting "device metrics". This allows you to configure dimensions larger than your display and enable/disable touch behavior.
Simply use register_driver
to set up...
rake spec + rails_admin = weirdly failing specs
If you use rails_admin, your specs pass with the rspec
binary, but not using rake spec
(or rake parallel:spec
etc), put this at the top of your spec_helper
:
ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'false'
Don't ask.
This is probably also true for cucumber, your env.rb
would be the right place.