From 1f41dd3b7d542d52ad96d062269b381786b023aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 2 Apr 2014 18:22:02 -0300 Subject: [PATCH] Warn users if Simple Form is not configured in the application --- lib/simple_form.rb | 7 +++++++ lib/simple_form/railtie.rb | 7 +++++++ test/simple_form_test.rb | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/simple_form.rb b/lib/simple_form.rb index ac8c3905..75c49be0 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -36,6 +36,12 @@ to See https://github.com/plataformatec/simple_form/pull/997 for more information. WARN + @@configured = false + + def self.configured? #:nodoc: + @@configured + end + ## CONFIGURATION OPTIONS # Method used to tidy up errors. @@ -235,6 +241,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information. # Default way to setup SimpleForm. Run rails generate simple_form:install # to create a fresh initializer with all configuration values. def self.setup + @@configured = true yield self end end diff --git a/lib/simple_form/railtie.rb b/lib/simple_form/railtie.rb index 35b722be..f4144964 100644 --- a/lib/simple_form/railtie.rb +++ b/lib/simple_form/railtie.rb @@ -3,5 +3,12 @@ require 'rails/railtie' module SimpleForm class Railtie < Rails::Railtie config.eager_load_namespaces << SimpleForm + + config.after_initialize do + unless SimpleForm.configured? + warn '[Simple Form] Simple Form is not configured in the application and will use the default values.' + + ' Use `rails generate simple_form:install` to generate the Simple Form configuration.' + end + end end end diff --git a/test/simple_form_test.rb b/test/simple_form_test.rb index 662e13d9..351b1aae 100644 --- a/test/simple_form_test.rb +++ b/test/simple_form_test.rb @@ -6,4 +6,12 @@ class SimpleFormTest < ActiveSupport::TestCase assert_equal SimpleForm, config end end + + test 'setup block configure Simple Form' do + SimpleForm.setup do |config| + assert_equal SimpleForm, config + end + + assert_equal true, SimpleForm.configured? + end end