remove mocha

This commit is contained in:
Vasiliy Ermolovich 2013-02-28 00:12:37 +03:00
parent 774dc49820
commit 3a9a81fa85
6 changed files with 47 additions and 23 deletions

View File

@ -8,5 +8,4 @@ gem 'activemodel', '>= 4.0.0.beta1', '< 4.1'
gem 'actionpack', '>= 4.0.0.beta1', '< 4.1' gem 'actionpack', '>= 4.0.0.beta1', '< 4.1'
gem 'rake' gem 'rake'
gem 'rdoc' gem 'rdoc'
gem 'mocha', require: false
gem 'tzinfo' gem 'tzinfo'

View File

@ -29,10 +29,7 @@ GEM
erubis (2.7.0) erubis (2.7.0)
i18n (0.6.2) i18n (0.6.2)
json (1.7.7) json (1.7.7)
metaclass (0.0.1)
minitest (4.6.1) minitest (4.6.1)
mocha (0.13.2)
metaclass (~> 0.0.1)
multi_json (1.6.1) multi_json (1.6.1)
rack (1.5.2) rack (1.5.2)
rack-test (0.6.2) rack-test (0.6.2)
@ -58,7 +55,6 @@ DEPENDENCIES
actionpack (>= 4.0.0.beta1, < 4.1) actionpack (>= 4.0.0.beta1, < 4.1)
activemodel (>= 4.0.0.beta1, < 4.1) activemodel (>= 4.0.0.beta1, < 4.1)
country_select (~> 1.1.1) country_select (~> 1.1.1)
mocha
railties (>= 4.0.0.beta1, < 4.1) railties (>= 4.0.0.beta1, < 4.1)
rake rake
rdoc rdoc

View File

@ -41,36 +41,46 @@ class AssociationTest < ActionView::TestCase
end end
test 'builder preloads collection association' do test 'builder preloads collection association' do
value = @user.tags = Object.new value = @user.tags = MiniTest::Mock.new
value.expects(:to_a).returns(value) value.expect(:to_a, value)
with_association_for @user, :tags with_association_for @user, :tags
assert_select 'form select.select#user_tag_ids' assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1' assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2' assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3' assert_select 'form select option[value=3]', 'Tag 3'
value.verify
end end
test 'builder does not preload collection association if preload is false' do test 'builder does not preload collection association if preload is false' do
value = @user.tags = Object.new value = @user.tags = MiniTest::Mock.new
value.expects(:to_a).never value.expect(:to_a, nil)
with_association_for @user, :tags, preload: false with_association_for @user, :tags, preload: false
assert_select 'form select.select#user_tag_ids' assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1' assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2' assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3' assert_select 'form select option[value=3]', 'Tag 3'
assert_raises MockExpectationError do
value.verify
end
end end
test 'builder does not preload non-collection association' do test 'builder does not preload non-collection association' do
value = @user.company = Object.new value = @user.company = MiniTest::Mock.new
value.expects(:to_a).never value.expect(:to_a, nil)
with_association_for @user, :company with_association_for @user, :company
assert_select 'form select.select#user_company_id' assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=1]', 'Company 1' assert_select 'form select option[value=1]', 'Company 1'
assert_select 'form select option[value=2]', 'Company 2' assert_select 'form select option[value=2]', 'Company 2'
assert_select 'form select option[value=3]', 'Company 3' assert_select 'form select option[value=3]', 'Company 3'
assert_raises MockExpectationError do
value.verify
end
end end
# ASSOCIATIONS - BELONGS TO # ASSOCIATIONS - BELONGS TO

View File

@ -156,18 +156,16 @@ class FormBuilderTest < ActionView::TestCase
end end
test 'builder should generate file for file columns' do test 'builder should generate file for file columns' do
@user.avatar = mock("file") @user.avatar = MiniTest::Mock.new
@user.avatar.expects(:respond_to?).with(:mounted_as).returns(false) @user.avatar.expect(:public_filename, true)
@user.avatar.expects(:respond_to?).with(:file?).returns(false)
@user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
with_form_for @user, :avatar with_form_for @user, :avatar
assert_select 'form input#user_avatar.file' assert_select 'form input#user_avatar.file'
end end
test 'builder should generate file for attributes that are real db columns but have file methods' do test 'builder should generate file for attributes that are real db columns but have file methods' do
@user.home_picture = mock("file") @user.home_picture = MiniTest::Mock.new
@user.home_picture.expects(:respond_to?).with(:mounted_as).returns(true) @user.home_picture.expect(:mounted_as, true)
with_form_for @user, :home_picture with_form_for @user, :home_picture
assert_select 'form input#user_home_picture.file' assert_select 'form input#user_home_picture.file'
@ -264,12 +262,12 @@ class FormBuilderTest < ActionView::TestCase
test 'builder should be able to disable a hint even if it exists in i18n' do test 'builder should be able to disable a hint even if it exists in i18n' do
store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
SimpleForm::Inputs::Base.any_instance.expects(:hint).never stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
with_form_for @user, :name, hint: false with_form_for @user, :name, hint: false
assert_no_select 'span.hint' assert_no_select 'span.hint'
end end
end end
end
test 'builder should pass options to hint' do test 'builder should pass options to hint' do
with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" } with_form_for @user, :name, hint: 'test', hint_html: { id: "cool" }

View File

@ -24,6 +24,28 @@ module MiscHelpers
end end
end end
def stub_any_instance(klass, method, value)
klass.class_eval do
alias_method :"new_#{method}", method
define_method(method) do
if value.respond_to?(:call)
value.call
else
value
end
end
end
yield
ensure
klass.class_eval do
undef_method method
alias_method method, :"new_#{method}"
undef_method :"new_#{method}"
end
end
def swap_wrapper(name=:default, wrapper=self.custom_wrapper) def swap_wrapper(name=:default, wrapper=self.custom_wrapper)
old = SimpleForm.wrappers[name] old = SimpleForm.wrappers[name]
SimpleForm.wrappers[name] = wrapper SimpleForm.wrappers[name] = wrapper

View File

@ -1,8 +1,7 @@
require 'rubygems' require 'rubygems'
require 'bundler/setup' require 'bundler/setup'
require 'test/unit' require 'minitest/autorun'
require 'mocha/setup'
require 'active_model' require 'active_model'
require 'action_controller' require 'action_controller'