Where is the defination of rails validators? - oop

I am a beginner in rails. As I was working on rails validation, I wanted to know where is the definition of valid? and new_record? and all the validation helpers?
I was trying to find the definition of all these functions but couldn't find any.
Where do all this validations reside? As I know Ruby on Rails is pure object oriented programming language.
Any help will be appreciated. I already went through
http://guides.rubyonrails.org/active_record_validations.html
Thank you.

These are Rails methods:
You can find valid? here and its code on Github.
Likewise with new_record?, you can find a description and its source code here.
Also, here is a link to the Rails repository on Github.
These methods are not defined in the project, they are defined in the rails gem which you have in your Gemfile.

Related

How can I test ActionController extensions within Rails 3.2?

I wrote an extension for ActionController::Base in Rails 3.2. Now I want to test it. But because the gem I created is no application it has neither specific controllers nor routes, so I cannot use "get" or "post" to call any action.
Is there any module which can create generic controllers on the fly (like acts_as_fu does with ActiveRecord models)? Or is there any testing pattern I can relate to?
I have found this article which explains how to test a before_filter. So far so good although the solutions are to some extend heavy-weight or unclean.
Edit: In particular I want to test an around_filter (if it works and if it redirects correctly) which is created by my extension.
I'm looking forward to your answers.
Thanks and kind regards.

Is there a web UI for modifying I18n locales for Rails 3?

I'm looking for a way to modify the values of I18n yml files for locales via web gui, is there some gem for that?
A gem that mimics Twitter Translation Center github.com/badrit/translation_center
Tolk is a web interface for doing i18n translations packaged as an engine for Rails 4 applications
https://github.com/tolk/tolk
Yes, I modified the Newsdesk's translate plugin for using with Rails 3:
https://github.com/romanbsd/translate
There's also tolk written by the creator of rails:
https://github.com/dhh/tolk
In http://rst-it.com we also had problems with finding the right solution, so we decided to make an activeadmin translation panel with interface similar to http://www.localeapp.com/.
Currently we are in design stage (first draft is on https://github.com/KMPgroup/active_I18n) but next week we will have working solution.
I will post here info when we lunch it, but in the meantime you can check https://github.com/KMPgroup/active_I18n and tell us what you think or even write an issue - the more feedback at the beginning the better.
This looks promising too:
http://www.localeapp.com/
I think I will give it a try. Anyone has experience with this service?

Can I replace Prototype with Dojo in Rails 3?

Can I replace Prototype with Dojo in Rails 3?
I know I can put jQuery as the javascript library, but I want to know if there is some plugin that replaces Prototype with Dojo.
Thanks!
EDIT:
For those seeking an answer for this question, it seems that the dojo project is developing an extension that replaces prototype's rails.js by dojo's rails.js. The extension is still unstable, but already make its way to DojoX (dojox.rails) in trunk.
http://bugs.dojotoolkit.org/browser/dojox/trunk/rails.js
I'm using dojox.rails in an application without any problem so far with rails 3.0.7
I still need to assess what will need to be changed considering the upcoming release of rails 3.1
Cheers
Guy

Has anyone used Minitest::Spec withing a Rails functional test?

The spec library in Minitest is great. I've been able to use it within Rails unit tests no problem. However, Rails functional test inherit from ActionController::TestCase which provides instance variables like #controller in it's setup.
Has anyone been using the Minitest::Spec lib for their Rails functional tests?
If not, I'm considering creating a small library to do just that. I'm not too keen on rspec, and shoulda is starting to shift it's focus to rspec. It would be nice to have something lightweight and built on tools already provided.
Thoughtbot have now split shoulda into shoulda_contexts and shoulda_matchers so the worry about a shift to rspec for thoughtbot doesn't mean shoulda contexts are going away. Just being maintained in the community.
Here's a simple test_helper rig to run functional & integration tests in Rails using spec syntax. Based on a gist by tenderlove, this excellent article about MiniTest with Capybara, & a lot of tinkering & source-poring.
https://gist.github.com/1607879
Maybe try http://metaskills.net/2011/03/26/using-minitest-spec-with-rails/.

Rails 3: app template example?

I'd like to see an example of an application generator template for Rails 3. Any suggestions?
I'm interested in an example of a template that is used to generate a new Rails application. Ryan Bates has a screencast (#148 App Templates in Rails 2.3) that describes how to create an application generator template for Rails 2.3 but I'd like to see how something similar is implemented in Rails 3. I've seen several tutorials on using the Rails 3 generators but I haven't found anything that shows how to create an application generator template.
I presume all of the capabilities of Thor and Rails::Generators::Actions are available but I'd like to see how to use them in an application generator template.
It seems terminology is confusing here. "View Template Engines" (such as Haml) are one thing; "Rails Generators" (such as used for "rails generate helper") are another thing; and "Application Generator Templates" (used for "rails new app_name -m some/path/to/template") are quite another thing.
Dug around in the Rails source and answered this question myself :-)
Here's an example of an application generator template for Rails 3:
http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
Usage:
rails new app_name -m http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
In customizing this template, you can use any methods provided by Thor::Actions
http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html
and Rails::Generators::Actions
http://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb