This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then /^I should see an error$/ do | |
page.should have_selector('div.error') | |
end | |
Then /^I should not see any errors$/ do | |
page.should have_no_selector('div.error') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvm use @$(basename `pwd`) --create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
ta.*, | |
coalesce(tb.weight, 0) as weight | |
from | |
(values ('A1','B1', 3), | |
('A2','B2', 7) ) | |
as ta(a_d,b_id,qty) | |
left join | |
(values ('B1',2) ) | |
as tb(b_id, weight) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def run | |
puts "usage: foo" | |
0 | |
end | |
end | |
RSpec.configure do |config| | |
config.before(:all) do | |
@null_out = File.open('/dev/null', 'w') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
original_zone = Time.zone | |
Time.zone= TZInfo::Timezone.all.shuffle.first | |
# do tests | |
Time.zone= original_zone | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class Date | |
class << self | |
def convert_date_string(input) | |
# mm-dd-yyyy | |
if input =~ /^(\d{1,2})[^\d\w\s](\d{1,2})[^\d\w\s](\d{4})([T|\W].*)?/ | |
"%0.4d/%0.2d/%0.2d#{$4}" % [$3, $1, $2].map(&:to_i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
RedirectMatch permanent /(.*)$ https://example.com/$1 | |
</VirtualHost> | |
<VirtualHost *:443> | |
ServerName example.com | |
# config... | |
</VirtualHost> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a variation on DHH's slice pattern for the mass assignment problem that may save on typing | |
# in common situations. Since it seems to me that most of the time there are only a small | |
# number of attributes that have authorization limited by role it would be nice if they were | |
# the only one's you had to specify. | |
# none of this was tested it may not actually work! | |
# since this is the same for every class just put it in a common base class | |
class ActiveRecord::Base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def present(subject, klass = nil) | |
klass ||= "#{subject.class}Presenter".constantize | |
presenter = klass.new(subject, self) | |
yield presenter if block_given? | |
presenter | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SalesOrder < ActiveRecord::Base | |
def self.stock | |
# complex logic to define what a stock order is | |
end | |
def stock? | |
SalesOrder.stock.exists?(self) | |
end |