Skip to content

Instantly share code, notes, and snippets.

View mikebaldry's full-sized avatar

Michael Baldry mikebaldry

View GitHub Profile
def active_if(controller, action = nil)
active = params[:controller] == controller.to_s &&
(action.nil? || params[:action] == action.to_s)
active ? "active" : nil
end
def active_class(controller, action = nil)
active = params[:controller] == controller.to_s &&
(action.nil? || params[:action] == action.to_s)
active ? "active" : nil
end
def nav_link(link_text, controller)
content_tag(:li, :class => active_class(controller, action) do
link_to link_text, controller
tag_method_map = {"string" => :text_field_tag, "text" => :text_area_tag, "integer" => :number_field_tag}
tag_method = tag_method_map[options[:type]]
input = @template.send(tag_method, options[:name], "", :class => options[:input_class], :required => options[:required] ? "required" : nil)
namespace :db do
desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n"
task :rollback => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
version = ActiveRecord::Migrator.current_version - step
ActiveRecord::Migrator.migrate('db/migrate/', version)
end
end
global_client_stats $ rake routes
root / application#root
/resque #<struct Sinatra::ExtendedRack app=#<Sinatra::ShowExceptions:0x00000005b3ddf0 @app=#<Rack::Head:0x00000005b3de18 @app=#<Rack::NullLogger:0x00000005b3de40 @app=#<Rack::Protection::FrameOptions:0x00000005b3df08 @app=#<Rack::Protection::IPSpoofing:0x00000005b3df80 @app=#<Rack::Protection::JsonCsrf:0x00000005b3dff8 @app=#<Rack::Protection::PathTraversal:0x00000005b3e070 @app=#<Rack::Protection::XSSHeader:0x00000005b3e110 @app=#<Resque::Server:0x00000005b3e570 @default_layout=:layout, @app=nil, @template_cache=#<Tilt::Cache:0x00000005b3e548 @cache={}>>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :xss_mode=>:block, :except=>[:session_hijacking, :remote_token]}>, @op
<clocKwize> vectorshelve, your cucumber tests should be from a users point of view, so write "Then the user should see a sucessful message in their current locale" and the step for that be page.should have_content i18n.get(arg1, @user.locale) or something
* stantona has quit (Ping timeout: 268 seconds)
<clocKwize> arg1 should actually be :feedback_sucess_message or something whatever
* CrazyHorse18 has quit (Quit: Leaving.)
* sideshow1oder ([email protected]) has joined #RubyOnRails
* vectorshelve_ (75c126a0@gateway/web/freenode/ip.117.193.38.160) has joined #RubyOnRails
<clocKwize> otherwise the implementation details a user doesn't cares about are visible in a user centric test. would your user say "Then I should see a sucessful message" or "Then i should see t(feedback_sucessful)"
require "spec_helper"
describe Formulae do
it "should do some stuff.." do
nmpf = Formulae.new "days / 273.93", days: 420
aobf = Formulae.new "breedfactor * trimsters", breedfactor: 1.10, trimsters: nmpf
ccf = Formulae.new "cats * breeding", cats: 2, breeding: aobf
f = Formulae.new "10 * catcount", catcount: ccf
class Array
def expand_ranges
self.collect { |wtf| wtf.is_a?(Range) ? wtf.to_a : wtf }.flatten
end
end
[1..15, 19, 21..25].expand_ranges.each { |i| puts i }
I would have thought that regular WTF readers would have grown out of the "language x is bad" mentality. There are few bad languages but many bad programmers. There's little correlation between the two. Apart from PHP.
@mikebaldry
mikebaldry / gist:3987978
Created October 31, 2012 16:15
Timezones...
1.9.3p194 :012 > ActiveSupport::TimeZone["America/New_York"]
=> (GMT-05:00) America/New_York
1.9.3p194 :013 > DateTime.now.utc
=> Wed, 31 Oct 2012 16:15:11 +0000
1.9.3p194 :014 > ActiveSupport::TimeZone["America/New_York"].utc_to_local(DateTime.now.utc)
=> Wed, 31 Oct 2012 12:15:18 +0000
1.9.3p194 :015 >