Skip to content

Instantly share code, notes, and snippets.

View redrick's full-sized avatar
🏡
Working from home

Andrej Antas redrick

🏡
Working from home
View GitHub Profile
@tansengming
tansengming / Rails Console Actionmailer test.rb
Created April 24, 2009 15:14
Rails Console Actionmailer test
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "someone@somewhere.com"
@from = "must_be_same_as_smpt_account_login@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
anonymous
anonymous / factories.rb
Created February 24, 2010 05:05
Factory.define :item do |f|
include ActionDispatch::TestProcess
f.name "Macbook Pro 15"
f.price_in_dollars 1500
f.photo fixture_file_upload('/files/avatar.jpg', 'image/jpg')
end
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=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')
@mudge
mudge / gist:428455
Created June 7, 2010 09:29
Namespaces with Nokogiri::Builder
# Dealing with namespaces in Nokogiri.
#
# First thing you must do is abandon what you're used to with Builder,
# namespaces aren't just attributes on an element, they uniquely identify
# what sort of element you are building and, as such, you are better off
# specifying them manually.
#
# The key here is accessing the Nokogiri::XML::Element being built with
# b.parent, then you can set the namespace (distinguished by an element
# with a prefix such as "soap12:Envelope") or add a default namespace
With this code:
browser.link(:text, "Move questions to...").click
browser.alert do
browser.button(:id => "alert").click
end #=> "the alert message"
I get this error:
@txus
txus / delegate_matcher.rb
Created February 2, 2011 09:19
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@magic-hat
magic-hat / gist:1080765
Created July 13, 2011 17:09
"$ Heroku keys:add" error
james@Blue-moon:~/rails_projects/first_app$ gem install heroku
Fetching: term-ansicolor-1.0.5.gem (100%)
Fetching: rest-client-1.6.3.gem (100%)
Fetching: configuration-1.3.1.gem (100%)
Fetching: launchy-0.4.0.gem (100%)
Fetching: heroku-2.3.6.gem (100%)
Successfully installed term-ansicolor-1.0.5
Successfully installed rest-client-1.6.3
Successfully installed configuration-1.3.1
Successfully installed launchy-0.4.0
@minikomi
minikomi / _map.html.haml
Created July 26, 2011 08:46
Rough google maps partial
#map_canvas{:style=>"width: 400px; height: 400px"}
%script{:type => "text/javascript", :src=>"http://maps.google.com/maps/api/js?sensor=false"}
= javascript_include_tag 'map'
:javascript
$(document).ready(function(){mappit("#{address}")});
@mgreenly
mgreenly / gist:1109325
Created July 27, 2011 13:11
database cleaner multiple connections single orm outside of rails
RSpec.configure do |config|
config.before(:suite) do
ActiveRecord::Base.establish_connection database['one']
DatabaseCleaner.strategy = :deletion
ActiveRecord::Base.establish_connection config.database['two']
DatabaseCleaner.strategy = :deletion
end
config.before(:each) do
@thermistor
thermistor / assets.rake
Created October 20, 2011 13:55 — forked from shedd/assets.rake
Check asset encoding for valid UTF-8
namespace :assets do
desc "Check that all assets have valid encoding"
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
extensions = ["js", "coffee", "css", "scss"]
paths.each do |path|
dir_path = Rails.root + path