Rails i18n coverage - ruby-on-rails

Is there a tool (or built-in way) to see if a given translation entry is no longer referenced? Even a "mechanical" way would be helpful, meaning something which runs the test suite and reports which i18n entries were and were not hit. (I suppose it could report which translations are missing, too, but that's not what I'm after for the time being.)

I think the i18n-tasks gem has what you're looking for as it can find missing and unused translations. It also provides you with a spec template that will fail your suite if any locales have missing or unused translations (see Installation section on the README).

Related

After installing paper_trail, get "irb: warn: can't alias context from irb_context." from rails console

I've tested this by running rails c both before and after git stash. On Rails 4.1 in Mavericks, after following the instructions to add the versions table and adding has_paper_trail to three models, whenever I run rails c I get
irb: warn: can't alias context from irb_context.
I've spent some time Googling without much luck, there's old threads talking about rspec, but I don't see how that's relevant since I'm not using it. Any ideas why this is happening?
RSpec used to polute provide Object top-level methods, e.g. describe, context, etc. Fortunately they've got rid of all the monkey patching in version 3, and now all these methods are namespaced under RSpec.
One can change this behaviour through the expose_dsl_globally config flag. For backwards compatibility, it defaults to true.
The warning shows up when you open the console because paper_trail automatically loads its rspec helpers when rspec is found. And it calls RSpec.configure before you have the chance to tweak your own configuration.
One possible solution would be paper_trail to disable the automatically loading and let users to load it themselves when they see fit. However, I am not aware of the internals of the library, so I can't guarantee this wouldn't break other things.
Best!
This is now fixed in papertrail 4.0.0, here's the commit.

Rails internationalization - is there better way to keep messages in english?

I recently make a decision to translate my tiny rails app with I18n gem as it described here.
While a testing, as it expected, I got a error messages from activerecord and devise:
translation missing: ru.devise.failure.user.not_found_in_database
translation missing: ru.activerecord.errors.models.user.attributes.name.taken
At this moment I know only one way to set up massages with custom locale - simply copy en.yml file which contains messages into my custom ru.yml, but it's weird way.
Maybe I missed something?
Cheers!
You can use the default option (related question)
I also advise you to look into the rails-18n gem for common translations
Devise provide common translations on their wiki
You can also set up a fallback locale to avoid missing translations (related question)

Automatic identification of Ruby Gems no longer in use within Rails

Is it possible to automatically identify Ruby gems that are no longer in use within a Rails project?
For example if a fellow developer added gem 'nokogiri' to the Gemfile, for a piece of functionally, but the code that depended on that gem has now been removed. I am looking to port my entire project to jRuby so removing the gems that we no longer seems a very sensible starting point.
Thanks
Usually gems are used in a specific way, so for each one you will have to look for patterns manually.
For example, if I had to figure if Nokogiri is being used, I'd use git grep to find Nokogiri occurrences (I assume you use git):
git grep Nokogiri
If nothing is returned, you are probably not using it.
Another way is, if you have a test suite, is just to remove it and see if something breaks. Not foolproof, but if you have good tests it should be a pretty safe path.
On rubyforge there is a gem called gem_unused. It adds an 'unused' command to 'gem'. However, I am not able to test this as it seems to be failing on my system. (I'm new to the rails world so maybe this is an issue someone else could troubleshoot. I filed an issue on it on the maintainer's github)

Rails find unused plugins

You know it, a Rails project is growing for years, many developers comes, many developers go...
Now it's your turn, You are a newcommer in the company and you are sitting for the "shiny" Rails app source code.
You task is to remove all plugins that clutters the source and are not used anymore.
How will you find them ?
If you have any tests on that rails app you could use rcov to see how much test coverage on the project, if its a good amount of coverage then remove one of the plugins, run the test suite and see if anything fails.
Look at each plugin's source code (usually lives in /lib of the plugin or gem folder).
Most of them only define a handful of methods that you are supposed to call in your application code. Search your project directory for all of these method names to see if they are called anywhere.
For example: you have acts_as_ferret plugin, search your codebase for the words "acts_as_ferret".
If you have delayed_job, search for "delay", "send_later", or "handle_asynchronously".
Sure it will take some time, but removing dependencies isn't something you want to do haphazardly.

Where are the downloadable Rails generators?

When I run...
$ script/generate
I get a list of installed generators and a message saying "More are available at http://wiki.rubyonrails.org/rails/pages/AvailableGenerators." However, the indicated wiki page says "This topic does not exist yet."
Does there exist some central repository of downloadable Rails generators?
In particular, I'd like one that creates the Rails scaffolding, but uses Haml instead of ERB.
It would also be neat if it would generate the Test::Unit tests but using the Shoulda enhancements.
That wiki was a wonderful resource back in the day, but it's long gone. I threw up a archive containing that page from when the wiki started wobbling. It's dated but you can at least see what was there.
As for now, look for gems (especially plugins) to provide the generators rather than expecting them as isolated resources. The gems command can be used to find whats available.
A lot of plugins come with their own generators. The one that springs to mind is restful_authentication because I have used it quite a bit.
Edit: Did you google here?
There's Rails Boost, which is a template generator. In fact, the template you want has already been generated -- that one uses HAML and Shoulda.

Resources