test/misc/calculation_test.rb in active_scaffold-3.4.43 vs test/misc/calculation_test.rb in active_scaffold-3.5.0

- old
+ new

@@ -1,62 +1,39 @@ require 'test_helper' +require 'class_with_finder' -class ClassWithFinder - include ActiveScaffold::Finder - def conditions_for_collection; end - - def conditions_from_params; end - - def conditions_from_constraints; end - - def joins_for_collection; end - - def custom_finder_options - {} - end - - def beginning_of_chain - active_scaffold_config.model - end - - def conditional_get_support?; end - - def params; {}; end -end - class CalculationTest < MiniTest::Test def setup @buildings = [] @buildings << Building.create { |b| b.create_owner(:first_name => 'foo') } @buildings << Building.create(:name => 'foo bar') @buildings << Building.create @klass = ClassWithFinder.new - @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(Building) }) - @klass.stubs(:active_scaffold_session_storage).returns({}) + @klass.active_scaffold_config.stubs(:model).returns(Building) end def teardown @buildings.each(&:destroy).map(&:owner).compact.each(&:destroy) end def test_calculation_with_conditions @klass.expects(:conditions_for_collection).returns(['"buildings"."name" LIKE ? OR "people"."first_name" LIKE ?', '%foo%', '%foo%']) @klass.expects(:active_scaffold_references).returns([:owner]) - @klass.active_scaffold_config.expects(:list).returns(mock { stubs(:count_includes).returns(nil) }) + @klass.active_scaffold_config.expects(:list).returns(mock.tap { |m| m.stubs(:count_includes).returns(nil) }) - column = mock { stubs(:field).returns('"buildings"."id"') } - @klass.active_scaffold_config.expects(:columns).returns(mock { stubs(:"[]").returns(column) }) + column = mock.tap { |m| m.stubs(:field).returns('"buildings"."id"') } + @klass.active_scaffold_config.expects(:columns).returns(mock.tap { |m| m.stubs(:"[]").returns(column) }) query = @klass.send :calculate_query assert_equal 2, query.count end def test_calculation_without_conditions @klass.stubs(:active_scaffold_references).returns([:owner]) - @klass.active_scaffold_config.expects(:list).returns(mock { stubs(:count_includes).returns(nil) }) + @klass.active_scaffold_config.expects(:list).returns(mock.tap { |m| m.stubs(:count_includes).returns(nil) }) - column = mock { stubs(:field).returns('"buildings"."id"') } - @klass.active_scaffold_config.expects(:columns).returns(mock { stubs(:"[]").returns(column) }) + column = mock.tap { |m| m.stubs(:field).returns('"buildings"."id"') } + @klass.active_scaffold_config.expects(:columns).returns(mock.tap { |m| m.stubs(:"[]").returns(column) }) query = @klass.send :calculate_query assert_equal Building.count, query.count end end