Testing associations in Rspec

Problem
You would like to test your model associations in an RSpec model spec, to make sure that they are correctly set up.

Solution
After some Google searching and coming across this article here, ended up using the second method described there with the reflect_on_association method, as it doesn’t need the inclusion of another gem.
So for example to to test multiple has_many or belongs_to associations in your model rspec you could use something like:
context "check associations" do
# belongs_to associations
%w{bel_to1 bel_to2}.each do |bt|
it "should belong to #{bt}" do
m = Model.reflect_on_association(:"#{bt}")
m.macro.should == :belongs_to
end
end
# has_many associations
%w{has_many1 has_many2 has_many3}.each do |hm|
it "should have many #{hm}" do
m = Model.reflect_on_association(:"#{hm}")
m.macro.should == :has_many
end
end
end

The single-table inheritance mechanism failed to locate the subclass:

Problem
You have correctly setup your Single Table Inheritance tables as in:

class Parent < ActieRecord::Base ; end class Child < Parent ; end

but everytime you are trying to use that in a cucumber feature, or in rails console you get the following error:

The single-table inheritance mechanism failed to locate the subclass: 'child'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Parent.inheritance_column to use another column for that information. (ActiveRecord::SubclassNotFound)

Solution
Make sure that when use the subclass name in a feature, or you create a record in the database the initial letter is in capital!
So make sure that in this case the type column contains 'Child' and not 'child'

Google-Maps-Rails (gmaps4rails) does not display markers when upgrading to 0.10.0

Problem
When upgrading the gmaps4rails gem to version 0.10.0 the markers are not displayed any more on the map.

Solution
There is an issue raised about the bug here.
To make the markers appear downgrade to version 0.9.1 of the gem.

update: or upgrade to 0.10.2 as the bug is fixed.

Error while loading shared libraries – Mandriva

Problem
After installing a package and trying to run it in Mandriva 2010 64, you get errors about missing libraries, like:

error while loading shared libraries: libasound.so.2: cannot open shared object file: No such file or directory

Solution
Use the urpmf command to find the packages that contain the missing libraries like :

urpmf libasound.so.2

and then when you get something like the following:

lib64alsa2:/usr/lib64/libasound.so.2
lib64alsa2:/usr/lib64/libasound.so.2.0.0
lib64alsa2:/usr/lib64/libasound.so.2
lib64alsa2:/usr/lib64/libasound.so.2.0.0
libalsa2:/usr/lib/libasound.so.2
libalsa2:/usr/lib/libasound.so.2.0.0
libalsa2:/usr/lib/libasound.so.2
libalsa2:/usr/lib/libasound.so.2.0.0

install the missing packages with:

sudo urpmi lib64alsa2
or/and
sudo urpmi libalsa2

Using gitolite in a non standard ssh port

Problem
You have moved your gitolite server or you want to be able to access your gitolite server behind a firewall and port 22 for ssh is no longer available.

Solution
Edit your .git/config file and replace the line with :

url = git_user_name@http://server_ip:repo_name.git

to the following:

url = ssh://git_user_name@external_ip:non_standard_ssh_port/repo_name.git

OSx – VMware – Mandriva resizing partition

Problem
When you use WMware to run Mandriva or any other distribution on Mac OSx, if you resize the hard disk partition in VMware your Mandriva system won’t automatically resize the partition to use the newly available space.

Solution
To be able to use the available space the quickest solution is:

  • restart your VMware session but run in safe mode
  • start up drakdisk
  • select the partition you want to resize. WARNING (Make sure you back up important data – even though in my case everything went smoothly)
  • umount the select partition and resize using all the avaliable free space
  • after a few minutes you should be able to restart your VMware and login to your virtual machine as normal, and the partition should be resized