From e5e6c512e05b12f6439046cd0171fd3cf57e138a Mon Sep 17 00:00:00 2001 From: Joshua Krall Date: Sun, 7 Aug 2011 15:01:45 -0500 Subject: [PATCH] Reword gem loading to work with Rails 2.x & 3.x, as well as letting the specs run properly. Kindof tricky, hope I got it all right. --- config/application.rb | 16 --------- config/boot.rb | 13 -------- config/environment.rb | 8 ----- config/environments/development.rb | 26 --------------- config/environments/production.rb | 45 -------------------------- config/environments/test.rb | 38 ---------------------- config/routes.rb | 3 -- lib/analytical.rb | 1 + lib/analytical/rails/engine.rb | 9 ++++++ rails/init.rb | 1 + {config => spec/config}/analytical.yml | 0 spec/spec_helper.rb | 14 ++++++-- 12 files changed, 23 insertions(+), 151 deletions(-) delete mode 100644 config/application.rb delete mode 100644 config/boot.rb delete mode 100644 config/environment.rb delete mode 100644 config/environments/development.rb delete mode 100644 config/environments/production.rb delete mode 100644 config/environments/test.rb delete mode 100644 config/routes.rb create mode 100644 lib/analytical/rails/engine.rb create mode 100644 rails/init.rb rename {config => spec/config}/analytical.yml (100%) diff --git a/config/application.rb b/config/application.rb deleted file mode 100644 index dfc0c4b..0000000 --- a/config/application.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.expand_path('../boot', __FILE__) - -require "action_controller/railtie" -require "action_mailer/railtie" -require "active_resource/railtie" - -Bundler.require(:default, Rails.env) if defined?(Bundler) - -module Analytical - class Application < Rails::Application - - # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" - - end -end diff --git a/config/boot.rb b/config/boot.rb deleted file mode 100644 index ab6cb37..0000000 --- a/config/boot.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'rubygems' - -# Set up gems listed in the Gemfile. -gemfile = File.expand_path('../../Gemfile', __FILE__) -begin - ENV['BUNDLE_GEMFILE'] = gemfile - require 'bundler' - Bundler.setup -rescue Bundler::GemNotFound => e - STDERR.puts e.message - STDERR.puts "Try running `bundle install`." - exit! -end if File.exist?(gemfile) diff --git a/config/environment.rb b/config/environment.rb deleted file mode 100644 index 79da5fa..0000000 --- a/config/environment.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Load the rails application -require File.expand_path('../application', __FILE__) - -Analytical::Application.configure do -end - -# Initialize the rails application -Analytical::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb deleted file mode 100644 index 81d532e..0000000 --- a/config/environments/development.rb +++ /dev/null @@ -1,26 +0,0 @@ -Analytical::Application.configure do - # Settings specified here will take precedence over those in config/application.rb - - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the webserver when you make code changes. - config.cache_classes = false - - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - - # Show full error reports and disable caching - config.consider_all_requests_local = true - config.action_view.debug_rjs = true - config.action_controller.perform_caching = false - - # Don't care if the mailer can't send - config.action_mailer.raise_delivery_errors = false - - # Print deprecation notices to the Rails logger - config.active_support.deprecation = :log - - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin -end - diff --git a/config/environments/production.rb b/config/environments/production.rb deleted file mode 100644 index db394d6..0000000 --- a/config/environments/production.rb +++ /dev/null @@ -1,45 +0,0 @@ -Analytical::Application.configure do - # Settings specified here will take precedence over those in config/application.rb - - # The production environment is meant for finished, "live" apps. - # Code is not reloaded between requests - config.cache_classes = true - - # Full error reports are disabled and caching is turned on - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Specifies the header that your server uses for sending files - config.action_dispatch.x_sendfile_header = "X-Sendfile" - - # For nginx: - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' - - # If you have no front-end server that supports something like X-Sendfile, - # just comment this out and Rails will serve the files - - # See everything in the log (default is :info) - # config.log_level = :debug - - # Use a different logger for distributed setups - # config.logger = SyslogLogger.new - - # Enable serving of images, stylesheets, and javascripts from an asset server - # config.action_controller.asset_host = "http://assets.example.com" - - # Disable delivery errors, bad email addresses will be ignored - # config.action_mailer.raise_delivery_errors = false - - # fallback to localhost if we can't find Heroku's ENV["URL"] - config.action_mailer.default_url_options = { host: ENV["URL"] || "localhost:3000" } - - # Enable threaded mode - # config.threadsafe! - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners - config.active_support.deprecation = :notify -end diff --git a/config/environments/test.rb b/config/environments/test.rb deleted file mode 100644 index 48ca4fd..0000000 --- a/config/environments/test.rb +++ /dev/null @@ -1,38 +0,0 @@ -Analytical::Application.configure do - # Settings specified here will take precedence over those in config/application.rb - - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true - - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - - # Show full error reports and disable caching - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - - # Raise exceptions instead of rendering exception templates - config.action_dispatch.show_exceptions = false - - # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test - - config.action_mailer.default_url_options = { host: ENV["URL"] || "localhost:3000" } - - # Use SQL instead of Active Record's schema dumper when creating the test database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql - - # Print deprecation notices to the stderr - config.active_support.deprecation = :stderr - -end diff --git a/config/routes.rb b/config/routes.rb deleted file mode 100644 index 9e3ce27..0000000 --- a/config/routes.rb +++ /dev/null @@ -1,3 +0,0 @@ -Analytical::Application.routes.draw do - -end diff --git a/lib/analytical.rb b/lib/analytical.rb index 0e5afb9..bc0f4a1 100644 --- a/lib/analytical.rb +++ b/lib/analytical.rb @@ -1,3 +1,4 @@ +require File.dirname(__FILE__)+'/analytical/rails/engine' require File.dirname(__FILE__)+'/analytical/modules/base' Dir.glob(File.dirname(__FILE__)+'/analytical/**/*.rb').each do |f| require f diff --git a/lib/analytical/rails/engine.rb b/lib/analytical/rails/engine.rb new file mode 100644 index 0000000..3fd8df4 --- /dev/null +++ b/lib/analytical/rails/engine.rb @@ -0,0 +1,9 @@ +if defined?(::Rails::Engine) + module Analytical + module Rails + class Engine < ::Rails::Engine + # auto wire + end + end + end +end \ No newline at end of file diff --git a/rails/init.rb b/rails/init.rb new file mode 100644 index 0000000..c2695e1 --- /dev/null +++ b/rails/init.rb @@ -0,0 +1 @@ +require 'analytical' diff --git a/config/analytical.yml b/spec/config/analytical.yml similarity index 100% rename from config/analytical.yml rename to spec/config/analytical.yml diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e7f4c61..f3885d5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,14 +2,24 @@ ENV["RAILS_ENV"] ||= 'test' -require "rails/application" -require File.expand_path("../../config/environment", __FILE__) +#require "rails/application" +#require File.expand_path("../../config/environment", __FILE__) +require 'active_support' +require 'active_support/core_ext' +require 'active_support/json' +require 'action_view' +require 'active_model' +require 'action_controller' +require 'rails' require 'rspec/rails' RSpec.configure do |config| config.mock_with :rspec config.expect_with :rspec + config.before do + Rails.stub(:root).and_return(Pathname.new(__FILE__).dirname) + end end require 'analytical'