I'm currently upgrading my rails application from rails 4 to rails 5. Is it necessary to change from Factory_girl to Factory_bot? What will happen if I proceed with a deprecation warning? further, I might be upgrading that application to rails 6, so would factory_girl work for rails 6?
FactoryGirl was renamed to FactoryBot in October 2017. (The original name was based on some inside joke/pop culture reference, which some argued was a poor decision.)
This has got nothing to do with upgrading rails, and everything to do with upgrading factory_girl/factory_bot.
Use the new name. It makes no sense to keep the old name - and regardless, your code will break at some point when updating versions, if you don't perform the rename.
The change is quite straightforward, and there are various guides people have written about the upgrade, such as this.
Essentially, all you need to do is:
Rename factory_girl and/or factory_girl_rails in the Gemfile, to factory_bot and factory_bot_rails.
Rename any mention of FactoryGirl to FactoryBot. (You could use git grep to ensure nothing is missed.)
Related
My rails app now runs fine with these versions:
ruby 1.9.3
rails 3.2
mongoid 2.4
I rely on both ActiveRecord and Mongoid APIs -- ActiveRecord
wraps around a sqlite3 database, and Mongoid around a mongodb database.
I need to upgrade my app to ruby 2.0 and rails 4.x. A quick search
shows that Mongoid APIs are not yet formally ported to ruby 2.0 / rails 4.x,
but some developers have figured out work-arounds. However, the work-arounds
I browsed are for mongodb-only backends (ie, they rely on --skip-active-record
when generating the application).
Question: can anyone say for sure whether using BOTH ActiveRecord
and Mongoid APIs will work under under ruby 2.0 and rails 4.x?
I'm in the middle of a Ruby-1.9.3/Rails-3.2/Mongoid-3 to Ruby-2.1.2/Rails-4.2/Mongoid-4 upgrade of a large application that uses both ActiveRecord and Mongoid. You'll want to use Mongoid-4 with Rails-4.x but I haven't encountered any problems specific to ActiveRecord and Mongoid (beyond the usual upgrading nonsense of course).
You might want to go from Mongoid-2 to Mongoid-3 before anything else. The Mongoid-3 and -4 interfaces are pretty much the same but I'm not so sure about Mongoid-2.
I'd also recommend moving to Ruby-2.x before touching Rails so a sequence like this might make things easier:
Upgrade Mongoid-2 to Mongoid-3.
Upgrade Ruby-1.9.3 to Ruby-2.x.
Upgrade Rails-3.2 and Mongoid-3 to Rails-4.0 and Mongoid-4.
Upgrade Rails-4.0 to Rails-4.1.
Upgrade Rails-4.1 to Rails-4.2.
Of course, you'll want to have a thorough test suite and you'll want to get everything passing before moving on to the next step.
Currently my application run on rails 3.1.3 & ruby 1.9.3.
I want to upgrade my application into rails 4.1 & ruby 2.1
Can anyone tell me how to upgrade the rails application ?
Thanks in advance
There is no specific defined way to upgrade. You can take reference from http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html or many other blog posts that people have written based on their personal experience. Just google them.
http://www.sitepoint.com/get-your-app-ready-for-rails-4/
https://developer.uservoice.com/blog/2012/03/04/how-to-upgrade-a-rails-2-3-app-to-ruby-1-9-3/
However follow a few points to make it easier. Upgrade one at a time. Better upgrade your ruby first, then rails in second cycle.
Do through testing at each step as the gems are likely to fail due to their dependencies.
Upgrade you gems manually and avoid bundle update
As addition to #shivam 's answer.
Guides often do not contain all the info. And they often do not say why some steps a necessary.
The most professional way is to read the release notes at least for the next major version.
Rails follows semantic versioning, meaning that all following 4.x.x versions are not allowed to introduce breaking public api changes.
Check the Rails 4 Release Notes. Watch out for things marked as deprecated and stuff that was extracted to a separate gem. The best tutorial available is the Upgrading to Rails 4 Screencast.
The most tricky part about the upgrade is the change from protected_attributes in models to strong_parameters in the controllers as a default mechanism against mass assignment protection.
If your app already heavily relies on protected_attributes it can be a tremendious task to move this protection outside of the model to every controller. In that case it is recommended to stick with protected_attributes by just including them as extra gem(same name).
In case of the ruby update. You can almost safely update to 2.1.2 from 1.9.3. Ruby follows semver only since Major version 2. If there even have been some incompatibilities since 1.9.3 the probability is very little, that your app used this features. We could upgrade all of our apps from 1.9.x to the last 2.x.x without a single ruby code change
Im considering upgrading a rails 2 app to rails 3 for a number of reasons (rails 3 features, certain plugins require rails 3 etc.)
Obviously ill have to update/grade some of the plugins as well. But concerning the code itself, should there be any compatibility issues when upgrading to 3? I know rails 3 changes a lot of helpers and syntax to make things easier, but do the older and more complicated ways still work (ex. gems in envioronment.rb, not Gemfile).
Also, anyone know a good tutorial on how to do it?
I have written a blogpost about it, where I point to the standard resources, but also handle some more deeper problems I encountered.
Hope this helps.
You may try this plugin to check your application compatibility in Rails 3. https://github.com/rails/rails_upgrade
If you want to upgrade from Rails 2 to Rails 3, first make sure to upgrade to the latest 2.3 version.
Then, before migrating, there is a list of changes you can make to make your Rails 2.3 application behaving like a Rails 3 application. Once you applied these changes, chances are the number of issues will be smaller and you can upgrade to Rails 3.
Once you installed Rails 3, use the rails_upgrade plugin to check the incompatibilities and fix them.
I'm developing an application with Ruby on Rails that I want to maintain for at least a few years, so I'm concerned about the next version coming up soon.
Going from Rails 1 to Rails 2 was such a big pain that I didn't bother and froze my gems and let the application die, alone, in the dark.
On this project I don't want to do that. First because this new version looks awesome, but also because this application may turn into a real product.
How can I prepare my application so that it will be upgradable with as little changes as possible.
How time consuming do you think switching version will be?
And what about my server? Deployment?
I'm already looking at deprecation notices... what else can I do?
The best thing you could do would be to follow development of Rails 3 via blogs and the Github repository and keep up a copy of your app along with it.
The official Ruby on Rails blog is updated with "What's new in Edge" posts every once in awhile. There are other blogs that often write about new things in edge as well. Larger features are often highlighted in these blogs, so you know about all the cool new features you can play with.
I'm not sure how close Rails 3 is to release (last I heard the core team was talking about a release at RailsConf 2009 in May), but you can always freeze the edge version of Rails into your application and just see what breaks. If you are using git, or another DVCS, you might make a branch specifically for Rails 3 and periodically update Rails to the latest edge code. Just be aware that edge Rails is a moving target so things in your app may break or fix themselves as you are pulling in newer Rails code.
Update:
Jeremy McAnally has a ton of info on upgrading from Rails 2 to Rails 3 on his blog.
http://omgbloglol.com/
I don't think there is going to be a major problem. Going off what was said in that initial report the Rails team realized that they can't do a major rewrite like they did from 1 to 2.
They even say:
I’m sure there’ll be some parts of Rails 3 that are incompatible, but we’ll try to keep them to a minimum and make it really easy to convert a Rails 2.x application to Rails 3.
I would be more concerned going from Merb to Rails 3.
The single most important thing you can do to make it easy to migrate to a new version of rails is to have a comprehensive test suite. Without a good test suite, I would never have the confidence that the new version of rails hasn't broken something in my app. On the current Rails app I'm working on, we started on Rails 2.1.1 back in October of 2008. Since then, we've migrated to Rails 2.1.2, 2.2.2, 2.3.2, 2.3.3 and now 2.3.4. I did the migrations to 2.3.2, 2.3.3 and 2.3.4...and for the 2.3.2 and 2.3.3 upgrades, we had some failing tests that alerted us to problems we would not have discovered without having such a good test suite. The failing tests actually alerted us to a regressive bug in rails that there was a patch for on the Rails lighthouse but that was not included in the release (since it was discovered, right after the release).
Once you've got that test suite in place, just stay current with each rails release (waiting a couple weeks to upgrade is fine, just don't skip any of the releases).
Yehuda Katz (a member of the Rails core team) has stated that there will most likely be a transitional release, containing deprecation warnings and such.
So as long as you have a good test suite to expose the inevitable upgrade problems, and stay current with the Rails release, the migration to Rails 3 should not be too difficult.
As simple as:
One
Two
Three
Great screencasts from Ryan Bates.
For preparing your application, the best way it what Jared said. Follow the Rails3 development.
For the time consuming, I think it depends of how you've followed the rails3 development before it's release.
And for the deployment, it shouldn't take too much problems. Rails 3 will be using Rack. So you can start it with mongrel, passenger or any server/gateway it shouldn't give you any problem.
There are some major changes in Rails 3, I posted about my experience upgrading my app to Rails 3 here: http://rails3.community-tracker.com/permalinks/5/notes-from-the-field-upgrading-to-rails-3
A good start in preparing would be to migrate over to using bundler. And doing a very deep review of strings that will go through the new XSS protection scheme.
There are going to be some automated compatibility checkers. Also, keep an eye on http://www.railsplugins.org/ so that you know if the libraries you depend on are going to be upgraded. The Rails Core team seems to be giving a lot of advance notice to the community this time around, so any lib that is actively maintained should be good to go.
Just do one thing
take a backup of your old version project first and then
on terminal(command prompt) write
rails new path/of/the/project
for example if my 2.3.* project is at home/rails_projects/myproject then
rails new home/rails_projects/myproject
or
cd home/rails_projects
rails new myproject
It will ask if there is any modifications done in any /config or other files. Do appropriate.
We are writing a Rails application that is using CouchDB as its data store. We're BDD/TDD'ing with RSpec and Cucumber, which is using WebRat for webpage testing
I'm trying to remove ActiveRecord as one of the resources that is being loaded by rails but its causing the cucumber tests to fail. I've removed all references that I can find (fixtures, environment files, etc...) but it still fails without it.
Has anyone seen this? The application runs fine without, but the test don't.
edit
I did remove the framework in env file, I also removed all the transactional fixture code. We're using the latest version of rspec and rspec-rails.
First stab at the problem.
Really I need a little more information, but...
Assuming you have done this in config/environment.rb:
# Skip frameworks you're not going to use. To use Rails without a database
# you must remove the Active Record framework.
config.frameworks -= [ :active_record ]
and are using rspec-rails 1.2.6, you would be getting an error like uninitialized constant Spec::Matchers::Change::ActiveRecord
which was brought up in ticket #810. It was fixed for 1.2.7, which was released only two weeks ago.
If that turns out not to be your problem, could you post the errors you've been getting and maybe some more information about your test environment?