...be fixed with the :prefix-option: class Form state_machine :first_wizard_stage, prefix: :foo do state :completed end state_machine :second_wizard_stage, prefix: :bar do state :completed

This defines the following: constants: Form::STATE_FOO_COMPLETED and Form::STATE_BAR_COMPLETE instance methods: #foo_completed? and #bar_completed? Fix bug where additional inclusions of RailsStateMachine::Model...

apidock.com

...to look something up and gets different results on different Rubies. Consider this: module Foo FOO = 42 end class Bar include Foo 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? :FOO => false 1.8.7 > Bar::FOO => 42 Ruby 1.9 introduces...

...try not to throw synchronous exceptions when encountering fatal errors. So avoid this: function foo(x) { if (!x) { throw "No x given" } else return new Promise(function(resolve, reject) { ... }); } }

...s hard to handle errors when calling foo, since we need to handle both a synchronous throw and an asynchronous rejection. Look how much code we need to handle failures...

\di Create user that can create databases CREATE USER harry IDENTIFIED BY 'foo'; CREATE ROLE username WITH createdb LOGIN [PASSWORD 'password']; Change password of an existing user ...

makandra dev

...branch means switching branches. Example git checkout HEAD~2 app/models/foo.rb … drops all modifications of foo.rb and replaces the file with its version from HEAD~2 = two commits before the current...

...set the path=/ option. Reading cookies A result may look like this: hello=universe; foo=bar This means that there are 2 cookies: "hello" with value "universe", and "foo" with...

...cookie that we just stored, and any cookies that existed previously. document.cookie // => "hello=universe; foo=bar; yes=please" That applies to all browsers. Options Cookie options like expiry or the...

During debugging you might pepper your code with lines like these: console.log('foo = ' + foo + ', bar = ' + bar) I recommend to use variable interpolation instead: console.log('foo = %o, bar = %o', foo, bar...

...look at its contents Another concise way to write the statement is this: console.log({ foo, bar }); This uses Javascript's new destructuring syntax and is actually shorthand for: console.log({ foo...

include_hash Matches if the given hash is included in the receiving hash: { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a') # passes { :foo => 'a', :bar => 'b' }.should include...

...hash(:foo => 'b') # fails { :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a', :baz => 'c') # fails

...to be able to say this? When I go to the user form for "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de')) When I go to the form...

...for the user "foo@bar.de" # goes to edit_user_path(User.find_by_anything!('foo@bar.de')) When I go to the form for the user above" # goes to edit_user_path(User.last)

...x you might instead want to use an older cheat sheet. Expectations # RSpec expect(foo).to.eq("value") expect(foo).to_not eq("value") # Jasmine expect(foo).toBe("value")

...not.toBe("value") Mocks # RSpec expect(foo).to_receive(:method).twice.with('arg').and_return('value') # Jasmine spyOn(foo, 'method').and.returnValue('value') expect(foo.calls.count()).toBe(2) expect(foo.method).toHaveBeenCalledWith('arg...

...computed property name in square brackets. We may now use Account instances with up.util.isBlank(): foo = new Account('foo@foo.com') bar = new Account('') console.log(up.util.isBlank(foo)) // prints false console.log(up.util.isBlank(bar)) // prints...

...to be more precise, it inherits from Hash): errors = ActiveModel::Errors.new(Object.new) => {} >> ?> errors.add(:base, "foo") => ["foo"] >> errors.add(:base, "bar") => ["foo", "bar"] >> ?> errors => {:base=>["foo", "bar"]} If you need to hack...

...the errors it will decompose arrays. For attributes with multiple errors such as :base => ["foo", "bar"] it yields once per value ("foo" and "bar" here) within the array and not...

uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: {foo: 1, bar: 2}) Net::HTTP.get(uri) # ===> Success If you only want to check if foo...

uri = URI('http://example.com/?foo=1&bar=2') stub_request(:get, 'example.com').with(query: hash_including(foo: 1)) Net::HTTP.get(uri) # ===> Error hash_including doesn't parse query values to string, you...

...considers text that is actually visible to a user. Then I should not see "foobear" This is because the Rack::Test driver does not know if an element is visible...

Spreewald offers steps to check that an element is hidden by CSS: Then "foo" should be hidden You can also check that an element is visible: Then "foo" should...

errors.add_to_base('failed') if bad_things? end end ^ # app/models/foo.rb require 'user' class Foo # something happens here end Now, when your environment is booted, Rails will automatically load your...

...models, like User. In our example, when Foo gets loaded, it will require the User class itself again. Since Ruby 1.8 identifies required files by the string you used (as...

# something like has_defaults would be nicer, but fails with e.g. User.new :password => 'foo' self.salt ||= ActiveSupport::SecureRandom.hex(20) if new_record? # this double-hashing technique is explained in...

github.com

...using the json gem, you might run into this error when using JSON.parse: >> json = 'foo'.to_json >> JSON.parse(json) JSON::ParserError: 757: unexpected token at '"foo"' from /.../gems/json-1.7.7/lib/json/common.rb:155:in...

...fix that, use a valid object to build JSON from, e.g. an array: >> JSON.parse([ 'foo' ].to_json).first => "foo" When you do that, remember to select the record from the...

...do it like this: page.within_frame('iframe-id') do fill_in 'E-mail', with: 'foo@bar.com' fill_in 'Password', with: 'secret' click_button 'Submit' end Instead of the frame's [id...

...can use your existing steps like this: When I fill in "E-mail" with "foo@bar.com" inside the login frame Note: Spreewald >= 4.1.0 already includes that step

Consider this class: class Foo private def test puts "Hello" end end While you can say create a block to call that method (using ampersand and colon) on Ruby...

...Foo.new.tap(&:test) Hello => # ... you cannot do that on Ruby 1.9 or 2.0: 1.9.3 > Foo.new.tap(&:test) NoMethodError: private method `test' called for # ^ 2.0.0 > Foo.new.tap(&:test) NoMethodError: private method `test' called for...

apidock.com

...virtual attributes that get and set a string array: post = Post.last puts post.tag_list # ['foo', 'bar', 'baz'] post.tag_list = ['bam'] puts post.tag_list # ['bam'] If you would like to create...

- form_for @post do |form| = form.check_box :tag_list, { :multiple => true }, 'foo', nil = form.check_box :tag_list, { :multiple => true }, 'bar', nil = form.check_box :tag_list, { :multiple => true...

With the most recent spec_candy.rb helpers you can say: User.stub_any_instance(:foo => :bar) user = User.new user.foo # => :bar RSpec 2 (Rails 3) RSpec 2 comes with this feature...

User.any_instance.stub(:foo => :bar) user = User.new user.foo # => :bar RSpec 3 RSpec Mocks 3.3: any_instance allow_any_instance_of(User).to receive(:foo).and_return(:bar) user = User.new

w3.org

You probably commonly used the :last-child CSS meta selector like so: .foo { border-bottom: 1px dashed #000; } .foo:last-child { border-bottom-width: 0; } However, this only...

...Instead, prefer using the + sibling selector. It applies to the element following the other. .foo + .foo { border-top: 1px dashed #000; } Note how we now use a top border instead...

...Ruby objects you may run into problems when encountering fields with NULL values: SELECT foo, bar, foo - bar AS baz FROM plop; +-----+------+------+ | foo | bar | baz | +-----+------+------+ | 30 | 20 | 10 |

...selected value if present and a given alternative if it would select NULL: SELECT foo, bar, foo - IFNULL(bar, 0) AS baz FROM plop; +-----+------+-----+ | foo | bar | baz...

`role_list_from': unknown role `something' (ArgumentError) Consider this task definition: namespace :foo do task :bar, :roles => :something do # do crazy stuff end end Whenever we call foo.bar...

...that is only available for that group of servers, you'll get another error: `foo.bar' is only run for servers matching {:roles=>:something}, but no servers matched To properly fix...