Skip to content

Instantly share code, notes, and snippets.

View jeroenvandijk's full-sized avatar

Jeroen van Dijk jeroenvandijk

View GitHub Profile
class AddAttachmentsDataToWrapper < ActiveRecord::Migration
def self.up
add_column :wrappers, :data_file_name, :string
add_column :wrappers, :data_content_type, :string
add_column :wrappers, :data_file_size, :integer
add_column :wrappers, :data_updated_at, :datetime
end
def self.down
remove_column :wrappers, :data_file_name
# Hack needed to be compatible with webrat
module Webrat
class SeleniumSession
extend Forwardable
# Add more methods of webrat/core/session when needed
def_delegators :current_scope, :field_labeled, :table_at, :css_search
def within(selector)
scopes.push(Webrat::Scope.from_scope(self, current_scope, selector))
# Allowing step transformations to transform tupils
#
# The feature:
# Scenario: transform with String and table
# Given some objects
# | a | b |
#
# The steps:
# Given /^some (.+)$/ do |objects, table|
# [objects, table].should == ["objects", "this is a string"]
### An example of a feature in Dutch with tables. All the table headers need to be translated.
Feature
# Given the following persons
Gegeven de volgende personen
| Naam | Adres | Plaats |
| Bas | stationstraat 1 | Amsterdam |
| Jeroen | dwarsstraat 3 | Den Haag |
| Mike | Hoofdstraat 4 | Hoofddorp |
# And the following occupations
En de volgende beroepen
# Run this file with the bacon gem: 'bacon bacon_nokogiri.rb'
require 'nokogiri'
module Nokogiri
module CSS
class XPathVisitor
def visit_function_has node
Nokogiri::CSS.xpath_for(node.value.last, :prefix => '').first
end
end
# Content of the article (CMS content)
<cell name="contact_mailer/display" recipients="[email protected]">
<fields>
<field name="naam" label="Naam" type="text_field" />
<field name="voornaam" label="Voornaam" type="text_field" />
<field name="email" label="Email" type="text_field" />
<field name="telefoon" label="Telefoon" type="text_field" />
<field name="motivatie" label="Motivatie" type="text_field" />
</fields>
<submit label="Verstuur" />
#!/usr/bin/env ruby
module Chars
def scale(chars, scale)
print_chars scale_vertically(scale_horizontally(chars, scale), scale)
end
private
def chars
@chars ||= [
#!/usr/bin/env ruby
module Chars
extend self
def scale(args, options={})
scale = options[:scale]
chars = args.map { |x| char(x.to_i).map { |row| row.split("") } }
print_chars scale_vertically(scale_horizontally(chars, scale), scale)
end
# In example.rb
module Example
# This method does something
def command1(arg1, arg2, options = {})
end
# This method does something else
def command2(arg1, arg2, options = {})
def patch_file(path, after, insert)
content = File.open(path) { |f| f.read }
content.gsub!(after, "#{after}\n#{insert}") unless content =~ /#{Regexp.escape(insert)}/mi
File.open(path, 'w') { |f| f.write(content) }
end
File.unlink 'public/index.html' rescue Errno::ENOENT
file 'script/test-adva-cms', <<-src
#!/usr/bin/env ruby