Posts Tagged ‘coding’

undefined method `use_transactional_fixtures=’ for Test::Unit::TestCase:Class

// April 17th, 2009 // 2 Comments » // Blog

If you have upgraded to Rails 2.3 and come across this error:
undefined method `use_transactional_fixtures=’ for Test::Unit::TestCase:Class

It probably means you have tests that were generated in an older version of Rails. Just open up test/test_helper.rb and change this:


class Test::Unit::TestCase

To this:


class ActiveSupport::TestCase

Voila!

Ruby on Rails HTTP Basic Auth with LDAP

// December 8th, 2008 // 8 Comments » // Blog

My friend Fred has a nifty tip over on his Binary Fever blog about Ruby on Rails LDAP authentication using HTTP Basic Auth. I took what he had done and made a few minor improvements:


# mygeneric_controller.rb
LDAPBASE = ‘, ou=active, ou=employees, ou=people, o=host.com’
before_filter :authenticate

protected

def authenticate
  authenticate_or_request_with_http_basic('LDAP Login') do |username, password|
   ldap = Net::LDAP.new :host => ‘ldap.host.com’, :base => LDAPBASE
   ldap.auth ‘uid=’ + username + LDAPBASE, password
   if ldap.bind
    @point_person = PointPerson.find_by_username(username)
    if !@point_person.nil?
     return true
    end
   else
    return false
   end
  end
 end

Neater “other” field

// August 1st, 2008 // No Comments » // Blog

Do you think drop down select lists that have “Other” are made ugly with the necessary test field to capture the “Other” forced to sit right next to lit like this:

Well here is a slick alternative that makes use of Script.aculo.us:
Demo

Here’s the Javascript:


   function swapthem() {
	Effect.toggle('test1','blind')
   	Effect.toggle('test2','blind')
   }

   function pop() {

     len = document.f1.s1.length
     i = 0
     chosen = "none"

     for (i = 0; i < len; i++) {
       if (document.f1.s1[i].selected) {
         chosen = document.f1.s1[i].value
       }
     }
     if (chosen == "other") {
	  swapthem()
	 }
   }

And the HTML:


	<form name="f1"action="">
	  <div id="test1">
		<select name="s1" onChange = pop()>
		<option value="home" selected="selected">
                  Home
                </option>
		<option value="work">Work</option>
		<option value="mobile">Mobile</option>
		<option value="other">Other</option>
		</select>
	  </div>
	  <div id="test2" style='display:none;'>
		<input type="text" name="t1">
                <a href="javascript:swapthem()">
                   list
                </a>
   	  </div>
	</form>