Skip to content

Instantly share code, notes, and snippets.

View liangzan's full-sized avatar

Wong Liang Zan liangzan

View GitHub Profile
# lib/validation_reflection.rb
def remember_validation_metadata(validation_type, *attr_names)
configuration = attr_names.last.is_a?(::Hash) ? attr_names.pop : {}
attr_names.flatten.each do |attr_name|
self.write_inheritable_array :validations,
[::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
end
end
When I follow "Log in"
# lib/culerity.rb
def self.run_server
IO.popen(%{#{jruby_invocation} "#{celerity_invocation}"}, 'r+').extend(ServerCommands)
end
$browser.link(:text, "Log in").click
  1. features/step_definitions/culerity_steps.rb
    $browser = Culerity::RemoteBrowserProxy.new $server, {:browser => :firefox3,
    :javascript_exceptions => true,
    :resynchronize => true,
    :status_code_exceptions => true
    }
# lib/culerity/remote_browser_object.rb
def method_missing(name, *args, &block)
send_remote(name, *args, &block)
end
# lib/culerity/remote_browser_object.rb
def send_remote(name, *args, &blk)
input = [remote_object_id, %Q{"#{name}"}, *args.map{|a| arg_to_string(a)}]
serialized_block = ", #{block_to_string(&blk)}" if block_given?
@io << "[[#{input.join(", ")}]#{serialized_block}]\n"
process_result @io.gets.to_s.strip
end
[remote_object_id, "link", "Log in"]
# lib/culerity/celerity_server.rb
def initialize(_in, _out)
...
while(true)
call, block = eval _in.gets.to_s.strip
...
end
end
# lib/culerity/celerity_server.rb
def initialize(_in, _out)
...
while(true)
call, block = eval _in.gets.to_s.strip
...
unless call.nil?
begin
result = target(call.first).send call[1], *call[2..-1], &block