spree/spree — pull request #3832 by jhawthorn (2013-10-06 03:16:17+00:00)
Title: Preferences reset to defaults when app initialized with empty cache

I added some good old fashioned printf debugging at freerunningtech/spree@b9a705f4b9b442bae6d733f29cce0ef9970c39cf.

With this I get the following at startup ([Full output](https://gist.github.com/jhawthorn/132f62bd35538a86a2f7))

get("/spree/app_configuration/currency")
should_persist? false
= USD (fallback+saved)
get("/spree/app_configuration/override_actionmailer_config")
should_persist? false
= true (fallback+saved)
get("/spree/app_configuration/enable_mail_delivery")
should_persist? false
= false (fallback+saved)

`should_persist?` is always `false` at startup because `Spree::Preference.connected?` is `false` until an attempt is made at accessing the database. This causes the default values to be written to cache at application startup if the cache begins as empty, which is *extremely* bad.

The first commit (9fb53da) reverts 9ca8ef9, which is incorrect as it uses the default values for all startup settings. That alone fixed the issue. This may break asset compilation on heroku in rails 4, but IMO this was not the correct fix and it's much more important not to load incorrect settings.

The second commit (deafc0d) prevents writing the fallback values to cache if persistence is disabled.