diff options
author | Azul <azul@leap.se> | 2014-04-08 09:58:41 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-04-08 10:08:26 +0200 |
commit | 045237ff88ffd5f1fe23d9621b043a9e604e54fa (patch) | |
tree | 59bbfc5a4855a73789118ebe994acc03158e20fe | |
parent | 53808b073f539ba2b442738b6abf97228488e311 (diff) |
fix requiring core extensions - most tests pass
some message tests are failing for me right now.
-rw-r--r-- | config/initializers/couchrest_model.rb | 2 | ||||
-rw-r--r-- | lib/extensions/testing.rb | 48 | ||||
-rw-r--r-- | lib/leap_web.rb | 4 | ||||
-rw-r--r-- | lib/leap_web_core.rb | 14 | ||||
-rw-r--r-- | lib/leap_web_core/dependencies.rb | 40 | ||||
-rw-r--r-- | lib/leap_web_core/engine.rb | 9 | ||||
-rw-r--r-- | lib/leap_web_core/ui_dependencies.rb | 11 | ||||
-rw-r--r-- | test/support/assert_responses.rb | 46 | ||||
-rw-r--r-- | test/support/rack_test.rb | 2 | ||||
-rw-r--r-- | test/test_helper.rb | 3 |
10 files changed, 52 insertions, 127 deletions
diff --git a/config/initializers/couchrest_model.rb b/config/initializers/couchrest_model.rb index ce4f41a..1a3e921 100644 --- a/config/initializers/couchrest_model.rb +++ b/config/initializers/couchrest_model.rb @@ -1,3 +1,5 @@ +require 'extensions/couchrest' + CouchRest::Model::Base.configure do |config| config.auto_update_design_doc = false end diff --git a/lib/extensions/testing.rb b/lib/extensions/testing.rb deleted file mode 100644 index 8f7e73c..0000000 --- a/lib/extensions/testing.rb +++ /dev/null @@ -1,48 +0,0 @@ -module LeapWebCore - module AssertResponses - - # response that works with different TestCases: - # ActionController::TestCase has @response - # ActionDispatch::IntegrationTest has @response - # Rack::Test::Methods defines last_response - def get_response - @response || last_response - end - - def assert_attachement_filename(name) - assert_equal %Q(attachment; filename="#{name}"), - get_response.headers["Content-Disposition"] - end - - def json_response - response = JSON.parse(get_response.body) - response.respond_to?(:with_indifferent_access) ? - response.with_indifferent_access : - response - end - - def assert_json_response(object) - assert_equal 'application/json', - get_response.content_type.to_s.split(';').first - if object.is_a? Hash - object.stringify_keys! if object.respond_to? :stringify_keys! - assert_equal object, json_response - else - assert_equal object.to_json, get_response.body - end - end - - def assert_json_error(object) - object.stringify_keys! if object.respond_to? :stringify_keys! - assert_json_response :errors => object - end - end -end - -class ::ActionController::TestCase - include LeapWebCore::AssertResponses -end - -class ::ActionDispatch::IntegrationTest - include LeapWebCore::AssertResponses -end diff --git a/lib/leap_web.rb b/lib/leap_web.rb deleted file mode 100644 index 9495fc6..0000000 --- a/lib/leap_web.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'leap_web_core' -require 'leap_web_certs' -require 'leap_web_users' -# do we want billing and help here? diff --git a/lib/leap_web_core.rb b/lib/leap_web_core.rb deleted file mode 100644 index a58d140..0000000 --- a/lib/leap_web_core.rb +++ /dev/null @@ -1,14 +0,0 @@ -require "rails" - -require "couchrest" -require "couchrest_model" -require "couchrest_session_store" - -require "json" - -require "extensions/testing" -require "extensions/couchrest" -require "leap_web_core/engine" - -module LeapWebCore -end diff --git a/lib/leap_web_core/dependencies.rb b/lib/leap_web_core/dependencies.rb deleted file mode 100644 index 877e3d1..0000000 --- a/lib/leap_web_core/dependencies.rb +++ /dev/null @@ -1,40 +0,0 @@ -module LeapWebCore - class Dependencies - UI_DEV = { - "haml-rails" => "~> 0.3.4", - "sass-rails" => "~> 3.2.5", - "coffee-rails" => "~> 3.2.2", - "uglifier" => "~> 1.2.7" - } - - UI = { - "haml" => "~> 3.1.7", - "jquery-rails" => nil, - "simple_form" => nil, - "bootswatch-rails", "~> 0.5.0" - } - - def self.require_ui_gems - UI.keys.each {|dep| require dep} - if Rails.env == "development" - # This will be run in the app including plugins that run it. - # However not all development_dependencies might be present. - # So we better only require those that are. - available = Bundler.definition.specs.map(&:name) - gems_to_require = available & UI_DEV.keys - gems_to_require.each {|dep| require dep} - end - end - - def self.add_ui_gems_to_spec(spec) - UI.each do |dep, version| - spec.add_dependency dep, version - end - - UI_DEV.each do |dep, version| - spec.add_development_dependency dep, version - end - end - - end -end diff --git a/lib/leap_web_core/engine.rb b/lib/leap_web_core/engine.rb deleted file mode 100644 index 940b5e2..0000000 --- a/lib/leap_web_core/engine.rb +++ /dev/null @@ -1,9 +0,0 @@ -# thou shall require all your dependencies in an engine. -require "couchrest" -require "couchrest_model" - -module LeapWebCore - class Engine < ::Rails::Engine - - end -end diff --git a/lib/leap_web_core/ui_dependencies.rb b/lib/leap_web_core/ui_dependencies.rb deleted file mode 100644 index 2daee37..0000000 --- a/lib/leap_web_core/ui_dependencies.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "haml" -require "jquery-rails" -require "simple_form" -require "bootswatch-rails" - -if Rails.env == "development" - require "haml-rails" - require "sass-rails" - require "coffee-rails" - require "uglifier" -end diff --git a/test/support/assert_responses.rb b/test/support/assert_responses.rb new file mode 100644 index 0000000..b01166f --- /dev/null +++ b/test/support/assert_responses.rb @@ -0,0 +1,46 @@ +module AssertResponses + + # response that works with different TestCases: + # ActionController::TestCase has @response + # ActionDispatch::IntegrationTest has @response + # Rack::Test::Methods defines last_response + def get_response + @response || last_response + end + + def assert_attachement_filename(name) + assert_equal %Q(attachment; filename="#{name}"), + get_response.headers["Content-Disposition"] + end + + def json_response + response = JSON.parse(get_response.body) + response.respond_to?(:with_indifferent_access) ? + response.with_indifferent_access : + response + end + + def assert_json_response(object) + assert_equal 'application/json', + get_response.content_type.to_s.split(';').first + if object.is_a? Hash + object.stringify_keys! if object.respond_to? :stringify_keys! + assert_equal object, json_response + else + assert_equal object.to_json, get_response.body + end + end + + def assert_json_error(object) + object.stringify_keys! if object.respond_to? :stringify_keys! + assert_json_response :errors => object + end +end + +class ::ActionController::TestCase + include AssertResponses +end + +class ::ActionDispatch::IntegrationTest + include AssertResponses +end diff --git a/test/support/rack_test.rb b/test/support/rack_test.rb index 2d8e5c4..35d191b 100644 --- a/test/support/rack_test.rb +++ b/test/support/rack_test.rb @@ -1,7 +1,7 @@ class RackTest < ActiveSupport::TestCase include Rack::Test::Methods include Warden::Test::Helpers - include LeapWebCore::AssertResponses + include AssertResponses CONFIG_RU = (Rails.root + 'config.ru').to_s OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first diff --git a/test/test_helper.rb b/test/test_helper.rb index f63591f..b844b90 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,9 @@ require 'rails/test_help' require 'mocha/setup' +# Load support files from toplevel +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + # Load support files from all engines Dir["#{File.dirname(__FILE__)}/../*/test/support/**/*.rb"].each { |f| require f } |