2009-11-18 17:45:35 +00:00
|
|
|
require 'rubygems'
|
2011-02-11 11:45:35 +00:00
|
|
|
require 'bundler/setup'
|
2009-11-18 23:50:43 +00:00
|
|
|
|
2010-07-06 12:07:24 +00:00
|
|
|
require 'test/unit'
|
|
|
|
require 'mocha'
|
2010-06-01 21:37:53 +00:00
|
|
|
|
2010-02-06 19:41:35 +00:00
|
|
|
require 'active_model'
|
2009-11-18 23:50:43 +00:00
|
|
|
require 'action_controller'
|
2010-03-19 12:29:24 +00:00
|
|
|
require 'action_view'
|
|
|
|
require 'action_view/template'
|
2011-02-11 11:45:35 +00:00
|
|
|
|
|
|
|
# Rails 3.0.4 is missing this "deprecation" require.
|
|
|
|
require 'active_support/core_ext/module/deprecation'
|
2009-11-18 23:50:43 +00:00
|
|
|
require 'action_view/test_case'
|
|
|
|
|
2011-04-27 18:55:03 +00:00
|
|
|
module Rails
|
|
|
|
def self.env
|
|
|
|
ActiveSupport::StringInquirer.new("test")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-07-06 12:07:24 +00:00
|
|
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
|
|
|
require 'simple_form'
|
2009-12-09 23:18:29 +00:00
|
|
|
|
2009-12-11 13:53:18 +00:00
|
|
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
2009-12-08 13:48:31 +00:00
|
|
|
I18n.default_locale = :en
|
2009-11-18 23:50:43 +00:00
|
|
|
|
2010-03-16 09:36:16 +00:00
|
|
|
country_select = "#{File.dirname(__FILE__)}/support/country_select/lib"
|
|
|
|
|
|
|
|
if File.exists?(country_select)
|
|
|
|
$:.unshift country_select
|
|
|
|
require 'country_select'
|
|
|
|
else
|
|
|
|
raise "Could not find country_select plugin in test/support. Please execute git submodule update --init."
|
|
|
|
end
|
2009-12-11 13:53:18 +00:00
|
|
|
|
2009-12-08 13:48:31 +00:00
|
|
|
class ActionView::TestCase
|
2009-12-10 01:57:05 +00:00
|
|
|
include MiscHelpers
|
2010-06-07 05:30:58 +00:00
|
|
|
include SimpleForm::ActionViewExtensions::FormHelper
|
2009-11-19 21:26:16 +00:00
|
|
|
|
|
|
|
setup :set_controller
|
|
|
|
setup :set_response
|
2009-12-08 13:48:31 +00:00
|
|
|
setup :setup_new_user
|
2009-11-19 21:26:16 +00:00
|
|
|
|
|
|
|
def set_controller
|
|
|
|
@controller = MockController.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_response
|
|
|
|
@response = MockResponse.new(self)
|
|
|
|
end
|
|
|
|
|
2009-12-10 02:22:53 +00:00
|
|
|
def setup_new_user(options={})
|
|
|
|
@user = User.new({
|
|
|
|
:id => 1,
|
2009-12-08 13:48:31 +00:00
|
|
|
:name => 'New in Simple Form!',
|
|
|
|
:description => 'Hello!',
|
2011-03-25 13:25:09 +00:00
|
|
|
:created_at => Time.now
|
2009-12-10 02:22:53 +00:00
|
|
|
}.merge(options))
|
2010-06-17 22:12:36 +00:00
|
|
|
|
2010-05-14 21:58:36 +00:00
|
|
|
@validating_user = ValidatingUser.new({
|
|
|
|
:id => 1,
|
|
|
|
:name => 'New in Simple Form!',
|
|
|
|
:description => 'Hello!',
|
2010-08-06 17:52:19 +00:00
|
|
|
:created_at => Time.now,
|
2010-09-05 15:19:45 +00:00
|
|
|
:age => 19,
|
2011-03-11 02:54:59 +00:00
|
|
|
:amount => 15,
|
2011-03-12 04:12:01 +00:00
|
|
|
:attempts => 1,
|
2011-04-29 19:23:42 +00:00
|
|
|
:company => [1]
|
2010-05-14 21:58:36 +00:00
|
|
|
}.merge(options))
|
2010-09-05 16:46:02 +00:00
|
|
|
|
|
|
|
@other_validating_user = OtherValidatingUser.new({
|
|
|
|
:id => 1,
|
|
|
|
:name => 'New in Simple Form!',
|
|
|
|
:description => 'Hello!',
|
|
|
|
:created_at => Time.now,
|
|
|
|
:age => 19,
|
|
|
|
:company => 1
|
|
|
|
}.merge(options))
|
2009-12-08 13:48:31 +00:00
|
|
|
end
|
|
|
|
|
2009-11-19 21:26:16 +00:00
|
|
|
def protect_against_forgery?
|
|
|
|
false
|
|
|
|
end
|
2009-12-08 13:48:31 +00:00
|
|
|
|
|
|
|
def user_path(*args)
|
|
|
|
'/users'
|
|
|
|
end
|
2009-12-10 20:03:27 +00:00
|
|
|
alias :users_path :user_path
|
2009-12-08 13:48:31 +00:00
|
|
|
alias :super_user_path :user_path
|
2010-05-14 21:58:36 +00:00
|
|
|
alias :validating_user_path :user_path
|
2010-09-05 16:46:02 +00:00
|
|
|
alias :other_validating_user_path :user_path
|
2009-11-19 21:26:16 +00:00
|
|
|
end
|