ruby

HTTP POST XML content from cucumber

I am trying to sending XML content through POST to a controller ('Parse') method ('index') in a simple Rails project. It is not RESTful as my model name is different, say, 'cars'. I have the following in a functional test that works: def test_index ... data_file_path = File.dirname(__FILE__) + '/../../app/views/layouts/in...

How can you easily test hash equality in Ruby when you only care about intersecting keys?

Say I have the following hashes: hash_x = { :a => 1, :b => 2 } hash_y = { :b => 2, :c => 3 } I need a chunk of logic that compares the two for equality only taking into consideration intersecting keys. In this example the 'b' key is the only commonality between the two hashes and it's value is set to '2' in both so by that ...

How can I do to profile ruby Unit tests execution?

I'd like to know how much took to run the 10 most time consuming tests.. like I can do with rspec, any suggestion? ...

Ruby UDP server/client test fails

I am trying to setup a simple UDP client and server using Ruby. The code looks like this: require 'socket.so' class UDPServer def initialize(port) @port = port end def start @socket = UDPSocket.new @socket.bind(nil, @port) # is nil OK here? while true packet = @socket.recvfrom(1024) puts packet en...

How to use rspec's should_raise with any kind of exception?

I'd like to do something like this: some_method.should_raise <any kind of exception, I don't care> How should I do this? some_method.should_raise exception ... doesn't work. ...

Ruby + Tk command binding - scope issue?

So I have this app require 'tk' class Foo def my_fancy_function puts "hello, world!" end def initialize @root = TkRoot.new{title "Hello, world!"} frame = TkFrame.new my_fancy_button = TkButton.new(frame) do text "Press meee" command {my_fancy_function} pack end frame.pack Tk.mainloop ...

Problem with one-to-many relationship with Single Table Inheritance (Rails)

I have problem with STI and relationship in ActiveRecord. I think I missed something in the class methods, but I don't know for sure. Below is my models: class User < ActiveRecord::Base has_many :advertisements end class Advertisement < ActiveRecord::Base belongs_to :user end class FreeAdvertisement < Advertisement end class Paid...

Safely escape strings for SQL fragments for joins, limits, selects, and so on (not conditions) on Rails

In Ruby on Rails, for conditions, it's easy to make SQL-injection-proof queries: :conditions => ["title = ?", title] where title comes from the outside, from a web form or something like that. But what if you are using SQL fragments in other parts of the query, like: :select => "\"#{title}\" AS title" # I do have something like th...

How can I programatically call the ruby debugger from within a ruby program in Ruby 1.9?

I am writing a web based debugger for Ruby, but in order to do this I need to be able to call the Ruby debugger from within a Ruby program on the server side. Has this ever been done? Is this even possible? The end product being built will allow Ruby code to be edited, executed and stepped through using just a web browser. The ruby code...

Is it normal for so many ruby processes to be running?

I'm having issues with a site on my server loading and was running 'top' and saw this: Dozens of ruby processes...and I have no idea what that means or if that's normal. :) ...

Using Ruby popen and PostgreSQL createuser

Hello all, I am attempting to write a very simple rake task (and merge it into a rather large rake task) that will call the following command and pass in a randomly generated password. For the moment, let's even fake the random generation and just give it a set password of 'test': createuser -SDPRE test The code I have for my task is...

Iterate every month with date objects

So I have two ruby Date objects, and I want to iterate them every month. For example if I have Date.new(2008, 12) and Date.new(2009, 3), it would yield me 2008-12, 2009-1, 2009-2, 2009-3 (as Date objects of course). I tried using range, but it yields every day. I saw step method for Date however it only allows me to pass number of days (...

Ruby string to_f... bug?

"9.99".to_f => 999.0 Is this the expected behavior? How would one convert "9.99" to 9.99 ...

Transliteration in ruby

What is the simplest way for transliteration of non English characters in ruby. That is conversion such as: translit "Gévry" #=> "Gevry" ...

How to manage multiple client sessions within server application?

Hello folks, I'm writing web chat application, similar to GTalk. It based on Orbited + Sinatra for client side, and Ruby for server side. I've already implemented all the protocol, everything working good. But. I got a problem - dont know how to deal if there are multiple connections from one user. Let`s say for example, i logged to cha...

passing rather huge arguments to ruby script, problems ?

ruby somescript.rb somehugelonglistoftextforprocessing is this a bad idea? rather should i create a separate flat file containig the somehugelonglistoftextforprocessing, and let somescript.rb read it ? does it matter if the script argument is very very long text(1KB~300KB) ? what are some problems that can arise if any. ...

File.open ,open and IO.foreach in Ruby ,what is the difference?

Hi, All of the following API do the same thing: open a file and call a block for each line. Is there any preference we should use one than another? File.open("file").each_line {|line| puts line} open("file").each_line {|line| puts line} IO.foreach("file") {|line | puts line} ...

mysql gem for snow leopard

I had trouble with the gem at first but got it to work when I installed the 64-bit MySQL and reinsatlled the gem with arch flags. So it work in rails. The error I used to get was uninitialized constant MysqlCompat::MysqlRes but that is now gone :) However in Xcode when I run a RubyCocoa project I still get the old error of uninit...

Trying to understand what Base.rakismet_binding is for

What does this part . . . unless Rakismet::Base.rakismet_binding.nil? { :referrer => 'request.referer', :user_ip => 'request.remote_ip', :user_agent => 'request.user_agent' }.each_pair do |k,v| data[k] = eval(v, Rakismet::Base.rakismet_binding) || '' end end of the following method do? module In...

Starting out with rails. Suggestions for SDKs plug-ins etc?

I have 6 years of C# programming experience and I'm looking to broaden my horizons. I'm going to build a simple web app to demonstrate knowledge of Ruby on Rails so I can get my foot in a place that might want a Rails programmer. It's the hot new thing, so I want to be marketable. Anyway, I have been playing around with solr and tomcat ...