ruby

Array.find method problem

I find this line in the ZenTest source code: result = @test_mappings.find { |file_re, ignored| filename =~ file_re } The @test_mappings and result here are both Array object, but I didn't found 'find' method on Array class in ruby doc. I also tried it on irb: irb(main):014:0> Array.respond_to? :find => false irb(main):015:0> [1,2,3]....

Setting up dev server for Ruby

I want to make a development server for Ruby. (I have done this for IIS and a LAMP set up, but am by no means proficient at it.) What will I need besides the actual server (which I already have)? And also any security issues? I know I could dev locally on my machine, but don't want to do that. ...

How to properly test this controller action with Shoulda?

I have the following controller action and test. I'm new to testing with Shoulda and I know there are areas of my controller that I can test further. For example, my flash messages as well as verifying the renders. So my question is, how would I properly test this controller action in Shoulda? My controller action (names have been ch...

How will Python and Ruby applications be affected by .NET?

I'm curious about how .NET will affect Python and Ruby applications. Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? If they don't use any of the .NET features, then what is the advantage of IronPython/IronRuby over their non .NET counterpar...

How to position editbox's cursor in shoes?

Shoes is very handy GUI tool. I would like to do a search form so that a user is helped to navigate through larger texts for editing. For this I need to move the cursor within an editbox element. Here you'll see my question in code: Shoes.app do stack do p=para "After pressing 'search' a question will arise" box=edit_box ...

Testing basic HTTP authenticated request in Merb

The Merb Open Source Book has a chapter on authentication. However, the testing an authenticated request section example only shows what you can do for forms based authentication. I have a web service that I want to test with HTTP basic authentication. How would I do that? ...

How to test a named_scope that references a class attribute with Shoulda?

I have the following ActiveRecord classes: class User < ActiveRecord::Base cattr_accessor :current_user has_many :batch_records end class BatchRecord < ActiveRecord::Base belongs_to :user named_scope :current_user, lambda { { :conditions => { :user_id => User.current_user && User.current_user.id } } } end and I'm tryin...

How to determine the class from which a specified method originated?

I got this question from this discussion. A method call like object.m does not always mean the class of "object" has a "m" method, just like the find method to a Array object is not directly originated from Array object, but from the mixed-in Enumerable module. My question is, given a method, how can we determine the class from which the...

Ruby equivalent of Python's "dir"?

In Python we can "dir" a module, like this: >>> import re >>> dir(re) And it lists all functions in the module. Is there a similar way to do this in Ruby? ...

Is there a RESTful way to configure routes for habtm?

In Rails you can use nested routes to create RESTful routes for has_one and has_many relationships. Examples can be found on the Rails Guides I'd like to ask if there is a good way to configure RESTful routes for habtm relationships? For example if I have a relationship A-habtm-B, my idea is to configure nested routes for A has_many B, ...

Rails: Multiple parameters before do?

I have this syntax which works (since it's from the API, pretty much) <% form_tag :action => "whatever" do -%> <div><%= submit_tag 'Save' %></div> <% end -%> and this, which works <%= form_tag({:action => "whatever"}, {:method => "get"})%> Now I have tried to combine them, guessing the syntax. The "get" does not get added ...

Configuring Ruby On Rails App in a subdirectory under Apache

I've got apache2.2 on windows. I'm trying to serve both subversion (/svn) and redmine (/redmine). I have svn running fine with this config: <Location /svn> DAV svn SVNParentPath C:/svn_repository ... </Location> This is working great--my svn users can hit http://mybox/svn just fine. Now I want to add another directory for a rai...

What is the best way to load Ruby classes into an application?

Currently I am loading Ruby classes into each class file using the require command, for example: require File.join(File.dirname(__FILE__), 'observation_worker') require File.join(File.dirname(__FILE__), 'log_worker') For each class I am defining the classes it requires. It would be great if I could do this at the entry point to my app...

Recurring billing with Rails and ActiveMerchant: Best practices, pitfalls, gotchas?

We are prepping for the release of a large web application that has been in development for the past year. We are about to start the process of integrating ActiveMerchant to handle recurring subscription fees for the service. I am looking for any advice regarding best practices considering our requirements (listed below) and any additio...

"_" parameter of Ruby block

I met this when I read ZenTest source code: Here is the definition of add_mapping method: def add_mapping(regexp, &proc) @test_mappings << [regexp, proc] end In the Autottest.initailize(), add_method get called to add mapping for implementations. self.add_mapping(/^lib\/.*\.rb$/) do |filename, _| possible = File.basename(filenam...

Port a Ruby/Rails application to PHP 5

I have a very large Ruby on Rails application that I would like to port to PHP 5.2 or maybe PHP 5.3 (if 5.3 ever gets released). I've been looking for a some way of automatically converting the simple stuff like simple classes and the ERB templates. I would expect that I'd have to do the more complicated stuff myself in cases where the ...

ActiveMerchant: How to authorise cards when using gateways that do not support the void operation?

I am working on the billing component of a Ruby on Rails application using ActiveMerchant. The payment gateway we have chosen is PaymentExpress. Code examples I am seeing such as the one below, use authorize() and void() to test the validity of a card: def test_card! auth_response = gateway.authorize(100, card) gateway.void(auth_re...

Netbeans tells me I have the wrong gems version when trying to run a rails app

I have been using Netbeans 6.5 recently - it complains (on startup, and if I try to run a unit test): "Rails requires RubyGems >= 1.3.1 (you have 1.0.1). Please gem update --system and try again." Yet from the command line "gem --version" : 1.3.1 any ideas? why does netbeans not realise I have gems 1.3.1 ? ...

performance testing tool

Hi All, We are using watir and integrated with VS 2008 using ruby in steel and we have automated our web application and it awsome. Is there way to use the same script to do the performance testing or is there any better tool. ...

How would you tidy up this controller logic?

I've got some logic in a controller that sets a status of an object if certain conditions are met: if params[:concept][:consulted_legal] == 0 && params[:concept][:consulted_marketing] == 1 @concept.attributes = {:status => 'Awaiting Compliance Approval'} elsif params[:concept][:consulted_marketing] == 0 && params[:concept][:consulted_...