Skip to content

Instantly share code, notes, and snippets.

@arturictus
arturictus / links
Last active August 29, 2015 13:56
Usefull repos
@arturictus
arturictus / Gemfile
Last active August 29, 2015 13:56
carrierwave S3 config
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@arturictus
arturictus / env_helpers.rb
Last active August 29, 2015 14:13
Set ENV variables for specific tests
# spec/support/env_helpers.rb
module EnvHelpers
def with_env_vars(vars)
original = ENV.to_hash
vars.each { |k, v| ENV[k] = v }
begin
yield
ensure
@arturictus
arturictus / rails_helper.rb
Created March 19, 2015 09:01
Rspec-capybara login with warden
# spec/rails_helper.rb
# add to your rails_helper inside the
RSpec.configure do |config|
config.around(:each, type: :request) do |example|
Warden.test_mode!
example.run
Warden.test_reset!
end
end
module SkippableCallbacks
extend ActiveSupport::Concern
module ClassMethods
def _skippable_callbacks
[
:after_initialize,
:after_build,
:before_validation,
:after_validation,
:before_create,
#############################################
# Push de la rama actual
git push origin $rama_actual
#############################################
# Volver a un commit anterior, descartando los cambios
git reset --HARD $SHA1
#############################################
# Ver y descargar Ramas remotas
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
# In not working!!
# Validations are added, but errors are not in the errors list after valid
module AddChildValidations
extend ActiveSupport::Concern
class_methods do
# Example:
# class User < ActiveRecord::Base
# has_one :address
# add_child_validations_for :address do