From 801081b1c1d12017040ce23ff51bc04ca4a42b3f Mon Sep 17 00:00:00 2001 From: arvicco Date: Mon, 16 Jul 2012 13:33:48 +0700 Subject: [PATCH] Specs should pass with all supported options --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/controllers/ib/application_controller.rb | 3 ++- lib/ib.rb | 7 ++++++- lib/ib/base.rb | 8 ++++++++ lib/ib/db.rb | 2 -- lib/ib/engine.rb | 2 +- spec/my.rb | 2 +- spec/spec_helper.rb | 16 ++++------------ 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 12ec91a..6306377 100644 --- a/Gemfile +++ b/Gemfile @@ -12,3 +12,5 @@ gem "jquery-rails" gem 'sqlite3', '> 1.3.3', :platforms => [:ruby_18, :ruby_19] #:ruby gem 'activerecord-jdbcsqlite3-adapter', '>= 1.2.2', :platforms => :jruby gem 'jdbc-sqlite3', '>= 3.7.2', :platforms => :jruby + +gem "backports" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 08390ad..dc05102 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,6 +43,7 @@ GEM multi_json (~> 1.0) addressable (2.2.8) arel (3.0.2) + backports (2.6.1) builder (3.0.0) capybara (1.1.2) mime-types (>= 1.16) @@ -162,6 +163,7 @@ PLATFORMS DEPENDENCIES activerecord-jdbcsqlite3-adapter (>= 1.2.2) + backports capybara combustion database_cleaner (>= 0.7.2) diff --git a/app/controllers/ib/application_controller.rb b/app/controllers/ib/application_controller.rb index 633a54a..e7eba3f 100644 --- a/app/controllers/ib/application_controller.rb +++ b/app/controllers/ib/application_controller.rb @@ -1,4 +1,5 @@ module Ib - class ApplicationController < ::ApplicationController + class ApplicationController < + defined?(::ApplicationController) ? ::ApplicationController : ActionController::Base end end diff --git a/lib/ib.rb b/lib/ib.rb index ff08fa4..b266249 100644 --- a/lib/ib.rb +++ b/lib/ib.rb @@ -2,6 +2,11 @@ module IB def self.db_backed? !!defined?(IB::DB) end + + def self.rails? + !!defined?(Rails) && Rails.respond_to?('env') + end + end # module IB IbRuby = IB @@ -11,7 +16,7 @@ def self.db_backed? # By default there is no DB backend, unless specifically requested # require 'ib/db' # to make all IB models database-backed -if defined?(Rails) && Rails.respond_to?('env') +if IB.rails? require 'ib/engine' else require 'ib/requires' diff --git a/lib/ib/base.rb b/lib/ib/base.rb index 5832cb9..e298511 100644 --- a/lib/ib/base.rb +++ b/lib/ib/base.rb @@ -53,6 +53,14 @@ def save alias save! save + ### Noop methods mocking ActiveRecord::Base macros + + def self.attr_protected *args + end + + def self.attr_accessible *args + end + ### ActiveRecord::Base association API mocks def self.belongs_to model, *args diff --git a/lib/ib/db.rb b/lib/ib/db.rb index 8cfcafa..49e2afb 100644 --- a/lib/ib/db.rb +++ b/lib/ib/db.rb @@ -26,6 +26,4 @@ def self.connect config end # module DB end -# You may just require 'ib/db', it will then auto-require core 'ib' for you -require 'ib' diff --git a/lib/ib/engine.rb b/lib/ib/engine.rb index cd6b3e0..2bc0eaa 100644 --- a/lib/ib/engine.rb +++ b/lib/ib/engine.rb @@ -1,6 +1,6 @@ module IB class Engine < ::Rails::Engine - isolate_namespace IB + isolate_namespace Ib #paths["app"] # => ["app"] #paths["app/controllers"] # => ["app/controllers"] diff --git a/spec/my.rb b/spec/my.rb index ba9cabd..e15ff40 100644 --- a/spec/my.rb +++ b/spec/my.rb @@ -1,4 +1,4 @@ -# My very specific connection configuration to run specs +# My very specific IB connection configuration to run the specs ACCOUNT = 'DU118180' HOST = '10.211.55.2' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6e1f2db..11910ce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,10 +33,11 @@ } end -puts 'Running specs with OPTS:' -pp OPTS - RSpec.configure do |config| + + puts "Running specs '#{config.pattern}' with OPTS:" + pp OPTS + # config.filter = { :focus => true } # config.include(UserExampleHelpers) # config.mock_with :mocha @@ -82,14 +83,5 @@ config.include Capybara::DSL, :example_group => { :file_path => /\brails_spec\//} - else - # We need to prevent loading Rails-related spec files unless Rails support was required - # However, when spec_helper.rb is first required, we're already inside a - # config.load_spec_files cycle - p config.pattern - p config.files_to_run - config.files_to_run = config.files_to_run.reject {|path| path =~ /rails/} - p config.files_to_run - end end