We have several customers using our installation of Best Practical’s Request Tracker (RT) system for keeping track of issues and making sure projects get done. We also have a few custom applications that we need to get information into and out of RT. Since most of our custom apps are written in Ruby, we started working on a library to make doing this as easy as possible. It may look a lot like ActiveRecord, and this is no accident. Since ActiveRecord is so easy and many people are already familiar with it, we based a large part of the API on it.
You can fork the project here: http://github.com/pjdavis/roart
Autotest broke on me, probably from months of neglect (I’ve been running tests directly from Textmate), and I had a tough time figuring it out. Whenever I tried to run autotest, I’d get:
/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/ZenTest-4.1.3/lib/unit_diff.rb:70:in `gets': No such file or directory - -u (Errno::ENOENT)
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/ZenTest-4.1.3/lib/unit_diff.rb:70:in `parse_input'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/ZenTest-4.1.3/lib/unit_diff.rb:182:in `unit_diff'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/ZenTest-4.1.3/lib/unit_diff.rb:56:in `unit_diff'
from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/ZenTest-4.1.3/bin/unit_diff:37
from /opt/ruby-enterprise/bin/unit_diff:19:in `load'
from /opt/ruby-enterprise/bin/unit_diff:19
It turns out that the autotest file in rubygems/bin/autotest wasn’t using the -s flag in the shebang line and that was causing the -u in the unit_diff program to be interpreted as a filename. To fix, i simply added -s to the end of the shebang line so it looks something like this:
#!/opt/ruby-enterprise/bin/ruby -ws
Tonight I was installing Ruby Enterprise Edition on FreeBSD old.stupid and I ran into a problem. I was including ActiveSupport to get the Hash.from_xml() function (really good if you need just a dirty hash from some xml you got) and every time I would require ‘active_support’ i would get
…custom_require.rb:31:in `gem_original_require’: no such file to load — iconv (LoadError)
If you ever have to install Ruby Enterprise Edition on FreeBSD, you may run into the same problem. What I had to do was.
cd ruby-enterprise-1.8.6-20090421/source/ext/iconv
/opt/ruby-enterprise/bin/ruby extconf.rb --prefix=/opt/ruby-enterprise --with-iconv-dir=/usr/local/
cp iconv.so /opt/ruby-enterprise/lib/ruby/1.8/i386-freebsdx.x/
That should get you running without having to reinstall Ruby Enterprise Edition. Why does this happen though? I found this on a mailing list from Hongli Lai at Phusion.
The problem is that FreeBSD doesn’t add /usr/local/lib to GCC’s linker search path for some reason. libiconv.so is in /usr/local/lib, and so libiconv.so is not detected while installing REE. I had to manually hack iconv’s extconf.rb to work around this.
Working on a project this weekend, I found that i needed to tell if a page was not found (404 Error) and then do something based off that. I was writing specs and trying to figure out how to stub a Mechanize object to return a 404. It turns out that anything except a 200 (OK), 301 (Moved Permanently) and 302 (Found, Redirect) will raise an exception. Specifically a WWW::Mechanize::ResponseCodeError.
RSpec conveniently gives us a way to say that a method will raise an exception when it is called. and_raise(ExceptionClass). Trying this out myself, I kept getting back
wrong number of arguments (0 for 1)
and I didn’t understand why. I came across a posting to the rspec-users mailing list that said that what i was doing (
agent.stub(:get).with(some_url).and_raise(WWW::Mechanize::ResponseCodeError)
wasn’t quite right. Many exception classes, it turns out, take an argument when they are raised. So I tried
agent.stub(:get).with(some_url).and_raise(WWW::Mechanize::ResponseCodeError(agent))
and that still didn’t work, as agent didn’t respond to :code. A little bit of stubbing later, and agent responds to code (returned a “400″) and now it works like a charm.
This is a reply to Rails is a Step by bryanp. Check out metabahn for some awesome guys who really know their stuff. I’m posting it here also because it got pretty long.
First off, I agree with the sentiment of the post, Rails is not the best way in all situations, just like PHP, Sinatra, Merb, Grails and whatever that busted C++ web framework is called are not the best way for every situation. However, Rails is a pretty good way.
I believe that Rails is sufficiently versatile that most web-based applications could be written successfully in Rails. Partly because of the limited domain in which web applications are created, and partly because of the sheer amount of mental power behind Rails development right now.
Many of the Rails Consultancies springing up (Hashrocket, ENTP, etc…) are using rails almost exclusively. Does this mean they are treating rails as the destination? Well, not exactly. Rails just happens to be the tool they’re most comfortable with.
A lot of what is heard from the Rails super-evangelists is just that, someone pumping religion as the end-all be-all of whatever domain they’re in. However, I would venture to say that the vast majority of the the top Rails developers would say that Rails is not the best suite of tools for every situation.
It seems that the lash-back against Rails in the latter part of 2008 was less about the technology itself, and more about a) the hype building up around rails since 2005 b) the high profile outages of Twitter, c) spreading of FUD about something new by a minority that didn’t like Rails for various (not necessarily invalid) reasons.
It happens all the time. A very vocal minority will try something new, decided they don’t like it, and let everyone else know they don’t like it and why you shouldn’t either. They share their opinions as fact, over-generalize and spin information, and use community rivalries as reasons to dismiss whatever it is they hate. I think it’s less a technology issue than a human nature issue.
That said. Rails IS NOT the be-all end-all of web development. You should devote time to exploring new tools, ideas, and technologies. That’s how you grow, however when you find something you like, you tend to stick with it. Nobody pays the bills by jumping to every new flavor of the month; eventually you have to produce something.
When you’re writing your spec files in RSpec, it is my belief that you should spec out even the validations that you add (validates_presence_of, validates_uniqueness_of, etc..). Even though these are core parts of Rails, your spec file should be able to be read by someone with little background in development and still get what is required of your application. Validating that a field is present and required is part of these specifications, so they should be there. However, testing to make sure something is always present isn’t necessarily exciting, and you’re basically doing the same thing over and over. Making sure that if a field is nil, it’s not saved to the database, and it give back an error. So I wrote something that will test to make sure that these fields are always valid. If this is already in RSpec, or something similar; or if you know a better way to do this, please let me know.
def validate_presence_of(klass, fields)
fields.each do |field|
it "should include #{field}" do
lambda do
instance = klass.create(field.to_sym => nil)
instance.errors.on(field.to_sym).should_not be_nil
end.should_not change(klass, :count)
end
end
end
Stick that in your spec helper file, and now you can just add
validate_presence_of(SomeClass, %w(afield another_field field3 ))
to your model specs, and you’ve just saved yourself alot of typing, and it’s still pretty clear what you’re trying to test.
I was trying to import the subversion repository for our central application to git tonight, and I ran into some problems.
First, I tried to install the svn2git gem, but i kept getting:
ERROR: could not find gem svn2git locally or in a repository
and James Coglan doesn’t have github gems enabled on the repository. So I had to clone the repository and install the gem manually. Read more…
I was clicking around on StackOverflow.com earlier, trying to fix a problem with an application I was working on, when i got interested in the Creative Commons license badge at the bottom. I clicked on it, and read over what you could do with it. The CC licenses offer a pretty good amount of freedom to muck about with others content, which is good because it allows people to create derivative works that expand the human sphere of experience. I mean, without derivative works, you wouldn’t have Rosencrantz and Guildenstern Are Dead (best play evar!)
It turns out that StackOverflows content is licensed under Attribution-Share Alike 2.5 Generic, basically meaning that you can Distribute freely, and derive content(remix) from the work.
Anyway, I saw at the bottom there was an upgrade for the license (what can’t be upgraded these days) and was reading through the different verbiage on the 3.0 license. The only real change on the dumbed down page was adding ‘or a compatible’ to the list of derivative works licensing requirements. Seems innocuous enough, however, in the legaleeze (e.g. Legal Code) …
You may Distribute or Publicly Perform an Adaptation only under the terms of: (i) this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible License.
Part (iv) looks kind of cool. It means if I found another license that was kinda like this that I liked better, I could license my derivative work under that. That’s very neat of Creative Commons, letting me change licenses. HOWEVER.
“Creative Commons Compatible License” means a license that is listed at http://creativecommons.org/compatiblelicenses that has been approved by Creative Commons as being essentially equivalent to this License, including, at a minimum, because that license: (i) contains terms that have the same purpose, meaning and effect as the License Elements of this License; and, (ii) explicitly permits the relicensing of adaptations of works made available under that license under this License or a Creative Commons jurisdiction license with the same License Elements as this License.
So let’s check out http://creativecommons.org/compatiblelicenses and tell me how many licenses you see there. Yeah, none. So, if you use a Creative Commons license, your content is, for the foreseeable future, trapped in a Creative Commons License.
Rails 2.2 was released earlier today, so you may be tempted (as indeed I was) to install it right away and play with the new features (such as Array#forty_two ) Well, there are a few things you need to be aware of before you start the update process. One is you must have rubygems 1.3.1 installed to use rails. The default way to do this is with
sudo gem update --system
However, there is a problem with updating rubygems this way when you don’t have rubygems-update installed. You can get around this by using
sudo gem install rubygems-update
sudo update_rubygems
After updating rubygems, install rails 2.2 with
sudo gem install rails
and you should have the new version of rails.
If you have an existing project, cd to that project directory and
rake rails:update
to update your javascript, scripts, and configs. This should get you running on the new version of Ruby on Rails.
When checking pages with option httpchk against an apache server with virtual hosts setup, you have to remember to put the full domain to what you want to check. This is because if you don’t have the domain, Apache won’t know which virtual host to sent the request to, and you could get pages that are UP showing DOWN, or worse, pages that are DOWN showing UP.
Another thing to remember is using option forwardfor, which passes the domain along with the request, so it will go to the right virtual host.
Read more…