Permalink
Browse files

Merge branch 'master' into mapper

* master:
  Update url to rake docs [ci skip]
  Name#model_name doesn't return a String object
  Result sets never override a model's column type
  [ci skip] Make last note show up in postgresql guide.
  Add missing `:param` option from the docs for Mapper#match [ci skip] Option discovered by @zackperdue in #14741, implemented in #5581.
  Add @senny's changed from #14741, including code font for `resources` options, and wrapped to 80 chars. [ci skip]
  Use github url for homepage of log4r [ci skip]
  Remove TODO.
  Ensure we always use instances of the adapter specific column class
  Fix indentation from 1b4b26f [ci skip]
  [ci skip] Improve form_helpers.md guide.
  Clear inflections after test.
  Remove unnecessary include for integration tests.
  Added documentation for the :param option for resourceful routing
  • Loading branch information...
2 parents 8ed1a56 + 4584be9 commit 295e91221123b912f2545cdc2e5623aeb53b220f @tenderlove tenderlove committed May 29, 2014
@@ -4,7 +4,7 @@ The easiest way to run the unit tests is through Rake. The default task runs
the entire test suite for all classes. For more information, check out the
full array of rake tasks with "rake -T".
-Rake can be found at http://rake.rubyforge.org.
+Rake can be found at http://docs.seattlerb.org/rake/.
== Running by hand
@@ -432,6 +432,12 @@ def root(options = {})
# [:action]
# The route's action.
#
+ # [:param]
+ # Overrides the default resource identifier `:id` (name of the
+ # dynamic segment used to generate the routes).
+ # You can access that segment from your controller using
+ # <tt>params[<:param>]</tt>.
+ #
# [:path]
# The path prefix for the routes.
#
@@ -269,12 +269,6 @@ def process(method, path, parameters = nil, headers_or_env = nil)
path = location.query ? "#{location.path}?#{location.query}" : location.path
end
- unless ActionController::Base < ActionController::Testing
- ActionController::Base.class_eval do
- include ActionController::Testing
- end
- end
-
hostname, port = host.split(':')
env = {
@@ -251,7 +251,6 @@ def assert_header(name, value)
module ActionController
class Base
- include ActionController::Testing
# This stub emulates the Railtie including the URL helpers from a Rails application
include SharedTestRoutes.url_helpers
include SharedTestRoutes.mounted_helpers
@@ -337,14 +337,26 @@ def parse
tests ParamswrappernewsController
def test_uses_model_attribute_names_with_irregular_inflection
- ActiveSupport::Inflector.inflections do |inflect|
- inflect.irregular 'paramswrappernews_item', 'paramswrappernews'
- end
+ with_dup do
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.irregular 'paramswrappernews_item', 'paramswrappernews'
+ end
- with_default_wrapper_options do
- @request.env['CONTENT_TYPE'] = 'application/json'
- post :parse, { 'username' => 'sikachu', 'test_attr' => 'test_value' }
- assert_parameters({ 'username' => 'sikachu', 'test_attr' => 'test_value', 'paramswrappernews_item' => { 'test_attr' => 'test_value' }})
+ with_default_wrapper_options do
+ @request.env['CONTENT_TYPE'] = 'application/json'
+ post :parse, { 'username' => 'sikachu', 'test_attr' => 'test_value' }
+ assert_parameters({ 'username' => 'sikachu', 'test_attr' => 'test_value', 'paramswrappernews_item' => { 'test_attr' => 'test_value' }})
+ end
end
end
+
+ private
+
+ def with_dup
+ original = ActiveSupport::Inflector::Inflections.instance_variable_get(:@__instance__)[:en]
+ ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: original.dup)
+ yield
+ ensure
+ ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: original)
+ end
end
@@ -4,18 +4,10 @@
module ActionDispatch
module Journey
class TestRouter < ActiveSupport::TestCase
- # TODO : clean up routing tests so we don't need this hack
- class StubDispatcher < Routing::RouteSet::Dispatcher
- def initialize
- super({})
- end
- def dispatcher?; true; end
- end
-
attr_reader :routes
def setup
- @app = StubDispatcher.new
+ @app = Routing::RouteSet::Dispatcher.new({})
@routes = Routes.new
@router = Router.new(@routes)
@formatter = Formatter.new(@routes)
@@ -566,8 +558,6 @@ def add_routes router, paths
end
end
- RailsEnv = Struct.new(:env)
-
def rails_env env, klass = ActionDispatch::Request
klass.new env
end
@@ -4,7 +4,7 @@ The easiest way to run the unit tests is through Rake. The default task runs
the entire test suite for all classes. For more information, checkout the
full array of rake tasks with "rake -T"
-Rake can be found at http://rake.rubyforge.org
+Rake can be found at http://docs.seattlerb.org/rake/.
== Running by hand
@@ -274,7 +274,6 @@ def assert_header(name, value)
module ActionController
class Base
- include ActionController::Testing
# This stub emulates the Railtie including the URL helpers from a Rails application
include SharedTestRoutes.url_helpers
include SharedTestRoutes.mounted_helpers
View
@@ -147,7 +147,7 @@ behavior out of the box:
extend ActiveModel::Naming
end
- NamedPerson.model_name # => "NamedPerson"
+ NamedPerson.model_name.name # => "NamedPerson"
NamedPerson.model_name.human # => "Named person"
{Learn more}[link:classes/ActiveModel/Naming.html]
@@ -204,7 +204,7 @@ def _singularize(string, replacement='_')
# extend ActiveModel::Naming
# end
#
- # BookCover.model_name # => "BookCover"
+ # BookCover.model_name.name # => "BookCover"
# BookCover.model_name.human # => "Book cover"
#
# BookCover.model_name.i18n_key # => :book_cover
View
@@ -130,7 +130,7 @@ This would also define the following accessors: `Product#name` and
SQLite3[link:classes/ActiveRecord/ConnectionAdapters/SQLite3Adapter.html].
-* Logging support for Log4r[http://log4r.rubyforge.org] and Logger[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc].
+* Logging support for Log4r[https://github.com/colbygk/log4r] and Logger[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc].
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
ActiveRecord::Base.logger = Log4r::Logger.new('Application Log')
@@ -363,6 +363,10 @@ def type_map # :nodoc:
end
end
+ def new_column(name, default, cast_type, sql_type = nil, null = true)
+ Column.new(name, default, cast_type, sql_type, null)
+ end
+
protected
def lookup_cast_type(sql_type) # :nodoc:
@@ -206,8 +206,7 @@ def each_hash(result) # :nodoc:
raise NotImplementedError
end
- def new_column(field, default, sql_type, null, collation, extra = "") # :nodoc:
- cast_type = lookup_cast_type(sql_type)
+ def new_column(field, default, cast_type, sql_type = nil, null = true, collation = "", extra = "") # :nodoc:
Column.new(field, default, cast_type, sql_type, null, collation, strict_mode?, extra)
end
@@ -425,7 +424,9 @@ def columns(table_name)#:nodoc:
execute_and_free(sql, 'SCHEMA') do |result|
each_hash(result).map do |field|
field_name = set_field_encoding(field[:Field])
- new_column(field_name, field[:Default], field[:Type], field[:Null] == "YES", field[:Collation], field[:Extra])
+ sql_type = field[:Type]
+ cast_type = lookup_cast_type(sql_type)
+ new_column(field_name, field[:Default], cast_type, sql_type, field[:Null] == "YES", field[:Collation], field[:Extra])
end
end
end
@@ -181,10 +181,14 @@ def columns(table_name)
oid = get_oid_type(oid.to_i, fmod.to_i, column_name, type)
default_value = extract_value_from_default(default)
default_function = extract_default_function(default_value, default)
- PostgreSQLColumn.new(column_name, default_value, oid, type, notnull == 'f', default_function)
+ new_column(column_name, default_value, oid, type, notnull == 'f', default_function)
end
end
+ def new_column(name, default, cast_type, sql_type = nil, null = true, default_function = nil) # :nodoc:
+ PostgreSQLColumn.new(name, default, cast_type, sql_type, null, default_function)
+ end
+
# Returns the current database name.
def current_database
query('select current_database()', 'SCHEMA')[0][0]
@@ -393,7 +393,7 @@ def columns(table_name) #:nodoc:
sql_type = field['type']
cast_type = lookup_cast_type(sql_type)
- Column.new(field['name'], field['dflt_value'], cast_type, sql_type, field['notnull'].to_i == 0)
+ new_column(field['name'], field['dflt_value'], cast_type, sql_type, field['notnull'].to_i == 0)
end
end
@@ -65,7 +65,7 @@ module ClassMethods
def property(name, cast_type)
name = name.to_s
# Assign a new hash to ensure that subclasses do not share a hash
- self.user_provided_columns = user_provided_columns.merge(name => ConnectionAdapters::Column.new(name, nil, cast_type))
+ self.user_provided_columns = user_provided_columns.merge(name => connection.new_column(name, nil, cast_type))
end
# Returns an array of column objects for the table associated with this class.
@@ -40,7 +40,7 @@ def find_by_sql(sql, binds = [])
column_types = {}
if result_set.respond_to? :column_types
- column_types = result_set.column_types
+ column_types = result_set.column_types.merge(columns_hash)
else
ActiveSupport::Deprecation.warn "the object returned from `select_all` must respond to `column_types`"
end
@@ -0,0 +1,48 @@
+require "cases/helper"
+
+class MysqlConsistencyTest < ActiveRecord::TestCase
+ self.use_transactional_fixtures = false
+
+ class Consistency < ActiveRecord::Base
+ self.table_name = "mysql_consistency"
+ end
+
+ setup do
+ @old_emulate_booleans = ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false
+
+ @connection = ActiveRecord::Base.connection
+ @connection.create_table("mysql_consistency") do |t|
+ t.boolean "a_bool"
+ t.string "a_string"
+ end
+ Consistency.reset_column_information
+ Consistency.create!
+ end
+
+ teardown do
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = @old_emulate_booleans
+ @connection.drop_table "mysql_consistency"
+ end
+
+ test "boolean columns with random value type cast to 0 when emulate_booleans is false" do
+ with_new = Consistency.new
+ with_last = Consistency.last
+ with_new.a_bool = 'wibble'
+ with_last.a_bool = 'wibble'
+
+ assert_equal 0, with_new.a_bool
+ assert_equal 0, with_last.a_bool
+ end
+
+ test "string columns call #to_s" do
+ with_new = Consistency.new
+ with_last = Consistency.last
+ thing = Object.new
+ with_new.a_string = thing
+ with_last.a_string = thing
+
+ assert_equal thing.to_s, with_new.a_string
+ assert_equal thing.to_s, with_last.a_string
+ end
+end
@@ -37,7 +37,9 @@ def test_overloaded_properties_save
data.reload
assert_equal 2, data.overloaded_float
+ assert_kind_of Fixnum, OverloadedType.last.overloaded_float
assert_equal 2.0, UnoverloadedType.last.overloaded_float
+ assert_kind_of Float, UnoverloadedType.last.overloaded_float
end
def test_properties_assigned_in_constructor
@@ -429,5 +429,5 @@ first.archive!
p Article.count # => 2
```
-Note: This application only cares about non-archived `Articles`. A view also
+NOTE: This application only cares about non-archived `Articles`. A view also
allows for conditions so we can exclude the archived `Articles` directly.
Oops, something went wrong.

0 comments on commit 295e912

Please sign in to comment.