We''re using migrations for generating our test schemas (for a whole load of reasons) and need to specifically run code when we are running our rspec tests as opposed to running the actual migrations on the production or development boxes. Is there a way to detect the current environment that rspec is connecting too? I''ve tried looking in ENV[''RAILS_ENV''] but it doesn''t appear to be set. I''ve also tried looking in ActiveRecord::Base.connection to see if the connection would give me a clue. I want to do something like: if RAILS_ENVIRONMENT == ''TEST'' # RUN THIS SQL end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Moore wrote:> Is there a way to detect the current environment that rspec is > connecting too? >I''m not sure if this is helpful, but I use the following code to generate development and test databases for a system that I report on only in Rails (the production database is part of another application). This works for me: def self.up if ENV["RAILS_ENV"] and ENV["RAILS_ENV"] == "production" puts "Production db not altered by migration" else sql = "CREATE TABLE ....." #creation SQL code. execute sql end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---