spec/spec_helper.rb in magic_grid-0.11.1 vs spec/spec_helper.rb in magic_grid-0.12.0
- old
+ new
@@ -9,13 +9,12 @@
end
end
require 'magic_grid/logger'
require 'action_view'
-require 'rails'
+require 'action_dispatch'
require 'test/unit'
-require 'action_controller'
begin
require 'will_paginate'
require 'will_paginate/array'
require 'will_paginate/view_helpers/action_view'
@@ -30,22 +29,31 @@
puts "Testing with Kaminari"
rescue LoadError
puts "skipping Kaminari"
end
-Rails.backtrace_cleaner.remove_silencers!
-
class NullObject
def method_missing(*args, &block) self; end
def nil?; true; end
end
module ActionFaker
attr_accessor :output_buffer
def url_for(*args)
"fake_url(#{args.inspect})"
end
+
+ def make_controller
+ request = double.tap { |r|
+ r.stub(:fullpath, "/foo?page=bar")
+ }
+ double.tap { |v|
+ v.stub(:render)
+ v.stub(:params) { {} }
+ v.stub(:request) { request }
+ }
+ end
end
class TextSelector
include ActionDispatch::Assertions::SelectorAssertions
include Test::Unit::Assertions
@@ -58,20 +66,44 @@
match do |actual|
TextSelector.new(actual).assert_select(*expected)
end
end
+module FakeCollections
+ def fake_connection
+ double(:connection).tap do |c|
+ c.stub(:quote_column_name) { |col| col.to_s }
+ end
+ end
+ def fake_active_record_collection(table_name = 'some_table',
+ columns = [:name, :description])
+ (1..1000).to_a.tap do |c|
+ c.stub(connection: fake_connection)
+ c.stub(quoted_table_name: table_name)
+ c.stub(table_name: table_name)
+ c.stub(to_sql: "SELECT * FROM MONKEYS")
+ c.stub(:table) {
+ double.tap do |t|
+ t.stub(:columns) { columns.map{|c| {name: c} } }
+ end
+ }
+ c.stub(:where) { c }
+ end
+ end
+end
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.include ActionView::Helpers
config.include WillPaginate::ActionView if Module.const_defined? :WillPaginate
config.include Kaminari::ActionViewExtension if Module.const_defined? :Kaminari
config.include ActionFaker
+ config.include FakeCollections
config.before do
MagicGrid.logger = NullObject.new
end