Permalink
Browse files

Merge pull request #29782 from y-yagi/follow_up_29699

Set `represent_boolean_as_integer` via `configuration`
  • Loading branch information...
kaspth committed Jul 16, 2017
2 parents 720cf7f + c98a641 commit a5b14a4e3486d171e6cdca699fc0d8afc38ef039
@@ -86,7 +86,7 @@ class SQLite3Adapter < AbstractAdapter
# for all models and all boolean columns, after which the flag must be set
# to true by adding the following to your application.rb file:
#
# ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = true
# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
class_attribute :represent_boolean_as_integer, default: false
class StatementPool < ConnectionAdapters::StatementPool
@@ -26,6 +26,9 @@ class Railtie < Rails::Railtie # :nodoc:
config.active_record.use_schema_cache_dump = true
config.active_record.maintain_test_schema = true
config.active_record.sqlite3 = ActiveSupport::OrderedOptions.new
config.active_record.sqlite3.represent_boolean_as_integer = nil
config.eager_load_namespaces << ActiveRecord
rake_tasks do
@@ -108,7 +111,9 @@ class Railtie < Rails::Railtie # :nodoc:
initializer "active_record.set_configs" do |app|
ActiveSupport.on_load(:active_record) do
app.config.active_record.each do |k, v|
configs = app.config.active_record.dup
configs.delete(:sqlite3)
configs.each do |k, v|
send "#{k}=", v
end
end
@@ -178,6 +183,11 @@ class Railtie < Rails::Railtie # :nodoc:
initializer "active_record.check_represent_sqlite3_boolean_as_integer" do
config.after_initialize do
ActiveSupport.on_load(:active_record_sqlite3adapter) do
represent_boolean_as_integer = Rails.application.config.active_record.sqlite3.delete(:represent_boolean_as_integer)
unless represent_boolean_as_integer.nil?
ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = represent_boolean_as_integer
end
unless ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
ActiveSupport::Deprecation.warn <<-MSG
Leaving `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer`
@@ -192,7 +202,7 @@ class Railtie < Rails::Railtie # :nodoc:
for all models and all boolean columns, after which the flag must be set to
true by adding the following to your application.rb file:
ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = true
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
MSG
end
end
@@ -394,7 +394,7 @@ by setting up a rake task which runs
by adding the following to your application.rb file:
```ruby
ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = true
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
```
The schema dumper adds one additional configuration option:
@@ -24,4 +24,4 @@
# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and
# 'f' after migrating old data.
# ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = true
# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
@@ -1130,7 +1130,7 @@ def create
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
@@ -1141,7 +1141,7 @@ def create
test "config.action_controller.always_permitted_parameters are: controller, action by default" do
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal %w(controller action), ActionController::Parameters.always_permitted_parameters
end
@@ -1153,7 +1153,7 @@ def create
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal %w( controller action format ), ActionController::Parameters.always_permitted_parameters
end
@@ -1177,7 +1177,7 @@ def create
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
@@ -1188,23 +1188,23 @@ def create
test "config.action_controller.action_on_unpermitted_parameters is :log by default on development" do
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters
end
test "config.action_controller.action_on_unpermitted_parameters is :log by default on test" do
app "test"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal :log, ActionController::Parameters.action_on_unpermitted_parameters
end
test "config.action_controller.action_on_unpermitted_parameters is false by default on production" do
app "production"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal false, ActionController::Parameters.action_on_unpermitted_parameters
end
@@ -1223,7 +1223,7 @@ def create
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal true, ActionController::Parameters.permit_all_parameters
end
@@ -1234,7 +1234,7 @@ def create
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal [], ActionController::Parameters.always_permitted_parameters
end
@@ -1245,7 +1245,7 @@ def create
app "development"
ActionController::Base.object_id # force lazy load hooks to run
lazy_load { ActionController::Base }
assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
end
@@ -1596,7 +1596,7 @@ class Post < ActiveRecord::Base
RUBY
app "development"
Post.object_id # force lazy load hooks to run
lazy_load { Post }
assert_not ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
end
@@ -1608,7 +1608,25 @@ class Post < ActiveRecord::Base
RUBY
app "development"
Post.object_id # force lazy load hooks to run
lazy_load { Post }
assert ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
end
test "represent_boolean_as_integer should be able to set via config.active_record.sqlite3.represent_boolean_as_integer" do
remove_from_config '.*config\.load_defaults.*\n'
app_file "config/initializers/new_framework_defaults_5_2.rb", <<-RUBY
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
RUBY
app_file "app/models/post.rb", <<-RUBY
class Post < ActiveRecord::Base
end
RUBY
app "development"
lazy_load { Post }
assert ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
end
@@ -1719,5 +1737,10 @@ def index
assert_equal 301, last_response.status
assert_equal "https://example.org/", last_response.location
end
private
def lazy_load
yield # Tasty clarifying sugar, homie! We only need to reference a constant to load it.
end
end
end

0 comments on commit a5b14a4

Please sign in to comment.