Upgrade to rails 4 #1958

merged 85 commits into from Feb 19, 2015


None yet

8 participants

tekin commented Jan 30, 2015

This updates Whitehall to run on Rails 4.0. For the most part the changes deal with various deprecations and breakages due to changes in Rails' behaviour. There are a few key areas where more comprehensive changes were required:

Localised routing

The whitehall application patches Rails' routing code to support our particular flavour of localisation URLs, for example:


This patch had to be rewritten as the routing code had changed significantly in the move from Rails 3 to 4 (73d17ac).

Rails routing bug

There is a bug in the Rails routing code that was causing an issue with some of the localised routing, specifically when generating a localised route with a default format set. A fix has been submitted to Rails, and a monkey patch added to whitehall to cope with this in the meantime (6129a6f).

friendly_id conflict resolution change

The Rails 4 compatible version of friendly_id changes behaviour significantly, particularly around slug conflict resolution. Pre-Rails 4, slug conflicts were resolved by appending a sequence number to the end of the slug. friendly_id now resolves conflicts by appending a UUID to the end (simpler solution and also threadsafe). To maintain the previous behaviour in whitehall, the conflict resolution code in friendly_id is being overridden to generate sequential slugs again (5203d32)

friendly_id magic finders

Rails 4 compatible friendly_id no longer overrides ActiveRecord::Base#find so that it can be passed a slug string as well as an ID number by default. It can be switched back on, but it's not very stable as it requires hooking into ActiveRecord internals (and breaks often with newer versions of ActiveRecord). The preferred method is to use the new friendly scope, for example:


To keep the changes in this pull request to a minimum, the magic find override has been enabled (972e039). Ideally some future work would disable it and move all find calls to use the new friendly scope.

Globlize feature/Rails bug workaround

A change was made to the globalize gem that means a translated model is touched whenever one of its translations are updated/destroyed (useful if using the updated_at timestamp in cache keys). This unfortunately does not interact well with Rails' optimistic locking when attempting to destroy a translated model: the translated model destroy triggers the associated translations to be destroyed, which touch the translated model, which increments the lock_version, which results in the in-memory object becoming stale. This is ultimately a bug in ActiveRecord (it should know not to touch a record that is being destroyed), but fixing that appears to be non-trivial. To get around this, whitehall is now using forked version of globalize that doesn't include the touch: true directive on the translations assocation (95ee80a)

Other Globalize validation issue

There appears to be a bug in globalize that means presence validations are not being triggered when saving a translation using update_attributes (globalize/globalize#401). The workaround for now is to both explicitly set the locale attribute and also perform the action in a I18n.with_locale block. (5e6e665#diff-095e6f47d7355ba033961aeb9dd441b6R7).

shared_mustache gem change

The newest version of sprockets-rails is not correctly choosing the local templates.js over the copy in the shared_mustache gem, which was causing the compiled javascript in test mode to not include the compiled mustache templates. This has been resolved by removing the blank templates.js from the shared_mustache gem (it's only purpose was so that any app using the shared_mustache gem could include templates.js in it's asset manifest without having to actually have a local file present)

Changes to cookie signing

Rails 4 introduces a new way to generate and verify signed cookies. It has a mechanism to automatically upgrade old cookies transparently. However, because the new cookies are not backwards compatible, this has intentionally been left off until we are certain that the upgrade has gone smoothly and that we don't need to roll back to the Rails 3 version. Once the dust has settled, steps should be taken to enable the new cookie code and begin the upgrade process. See http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#action-pack for more details.

tekin commented Jan 30, 2015

There's a strange thing happening to the body text areas on the forms on this branch (currently visible on preview). On this version, the rows attribute is not being set, so the text areas are defaulting to two rows. On master, they somehow get rendered with rows set to 20. Thing is, I can't see anywhere in the app code where they are being set to 20! If anyone has any insight before I dig into this further, let me know /cc @edds


Tekin, you broke GitHub!

screen shot 2015-01-30 at 09 40 11


Epic PR of the day ๐Ÿ‘

edds commented Jan 30, 2015

@tekin following the apidocs through text areas were initialized using DEFAULT_TEXT_AREA_OPTIONS which are defined to have 20 rows if none are specified. http://apidock.com/rails/ActionView/Helpers/InstanceTagMethods

Though looking they have removed that default in rails 4.

tekin commented Jan 30, 2015

@edds Uurgh, glad they got rid of that particular piece of magic! I'll get this branch updated to fill in the blanks for text areas without an explicit row count. Thanks!

tekin commented Jan 30, 2015

So looks like my fix for "Other Globalize validation issue" (5e6e665#diff-095e6f47d7355ba033961aeb9dd441b6R7) is causing another issue - although it causes the presence validations to kick-in, setting the :locale attribute in LocalisedModel will overwrite the locale attribute on the editions table, i.e. what we use to signify the edition's primary locale. This is causing the primary locale to be changed on an edition when a new translation is added, which makes it appear as a non-english edition.

Looking at this now, I think the presence of an attribute called "locale" on the editions table is almost certainly the root cause. I'm going to have to investigate this further.

heathd commented Feb 5, 2015

ok I've finished reviewing this. All looks good, nice work! There were quite a few thorny issues to deal with along the way!

My only slight concern is the globalize fork. I'm not clear whether fixes in rails (ie rails 4.1+) will avoid the lock version issues or not. If we do need to patch globalize, it might be good to also work with them to develop an alternative solution, as it would be good to develop some confidence that we can avoid forking in the medium term.

Obviously there is also the issue with 5e6e665 which you mentioned.

@tekin tekin referenced this pull request in norman/friendly_id Feb 9, 2015

Addon for numerically sequential slugs #644

tekin commented Feb 11, 2015

This branch now includes a fix for the issue with non-english editions. The fix is to use a column not called "locale" to signify the primary locale of the edition as this conflicts with some of the internal behaviour of globalize: globalize uses a :locale key during mass-assignment to signify the locale of the attributes being set. Up to now we got away with it and the locale attribute was being correctly set on the edition table, but this has changed with newer versions of globalize.

tekin commented Feb 11, 2015

Nice work on getting a patch for the optimistic locking issue into globalize @heathd! ๐Ÿฐ We'll have to wait until we've got whitehall to Rails 4.2 before we can move back to the main fork though as master breaks compatibility with Rails versions below that. Either that or see if we can get the fix backported to 4-0-stable.

tekin commented Feb 11, 2015

Rebased against master

heathd commented Feb 11, 2015

Thanks @tekin. Just for the record, here's a link to the PR which has just been merged into globalize globalize/globalize#408

heathd commented Feb 11, 2015

Rather than forking globalize, perhaps we could now reference globalize@master (at a specific sha)

tekin commented Feb 11, 2015

Unfortunately not, master only works with Rails 4.2.

heathd commented Feb 18, 2015

I've rebased this onto perforance-improvements-to-document-searches-controller (which in turn has been rebased on master) in anticipation of that being merged

tekin and others added some commits Jan 8, 2015
@tekin @heathd tekin Update Gemfile for Rails 4.0.13
Updating one major Rails release at a time to take advantage of all deprecation

A change was also required to how webmock is loaded. Also, active_resource is no
longer part of Rails. As it isn't used by the app, we can remove it entirely.
@heathd heathd Regenerate db/schema.rb
Rails 4.0.x changes the schema syntax in a few ways:
- uses ruby 1.9 hash syntax
- explicitly declares index types on indexes

This commit regenerates the schema to use the new syntax without
changing the actual semantic content.
@tekin @heathd tekin Temporarily comment out localised routing patch
This is not compatible with Rails 4 so commenting out for the time being.
@tekin @heathd tekin Re-nest PublishingApiPresenters::Edition
This was causing a circular dependency issue. Whitespace-only changes
@tekin @heathd tekin Update app config for Rails 4 compatibility
This was mainly a case of generating a fresh Rails 4 app to see what the new
default configuration looks like and removing any configurations that are now
@tekin @heathd tekin Get rid of assets group in Gemfile 6d27748
@tekin @heathd tekin Remove unnecessary script/rails file
bundler/rails does the right thing
@tekin @heathd tekin Remove unnecessary rake task hack
This is no longer required in Rails 4
@tekin @heathd tekin ActiveRecord::Base#scoped is deprecated
The `all` method now returns a scope, use that instead.
@tekin @heathd tekin Disable deprecated implicit join references
ActiveRecord has deprecated implicit join references in the queries it
generates, e.g. it will no longer automatically join other tables that are
referenced in the WHERE clause. Instead, the reference should now be explicitly
includes using the `references` scope.

This pull request also explicitly turns them off so that any code that would
result in an implicit join raises an exception so that we can catch them all now
before they are removed permanently.
@tekin @heathd tekin Don't call deprecated `all` method on scopes
Either `load` or `to_a` should be used, depending on whether the scope should be
@tekin @heathd tekin Don't use deprecated `assert_present` method fd61b50
@tekin @heathd tekin Don't use deprecated magic find_by_* helpers
The find_by() method should be used instead. Note that the active record-like
interfaces define their own explicit find_by_* methods. I'd suggest these be
renamed to something else to avoid confusion, e.g. `by_slug` instead of
@tekin @heathd tekin Update the localised routing patch for Rails 4.
This had to be rewritten to work with the new routing code in Rails 4. Because
the app is now running on Ruby 2, we can make use of the Module#prepend method
to avoid the alias method chaining.
@tekin @heathd tekin Ensure all scopes are lambdas 4077e46
@tekin @heathd tekin Use new association syntax
Where available, scopes should now be used to define the conditions, ordering,
etc on associations
@tekin @heathd tekin Disable deprecated implicit join references e4e8eae
@tekin @heathd tekin Fix validations on join models
The upgrade to Rails 4 broke the validations on join models when creating new
joins on new records. This is because the join model is now validated before the
records it is joining are validated and saved, which means validating for the
presence of the joining records will fail because they don't yet exist in the
database. We can avoid this issue by updating the relevant associations to
include the inverse association, which means that the in-memory instances get
assigned to the join model and the presence check succeeds without having to try
the database. To get this to work, some of the validations needed adjusting such
that it checks for the presence of the model itself and not the id attribute.
@tekin @heathd tekin ActiveModel::Name no longer string-like 6e21dd1
@tekin @heathd tekin Generate sequential slugs with friendly_id
This re-instates the friendly_id v4 behaviour of generating sequential slugs
when there are conflicts. Note that the `should_generate_new_friendly_id?`
method no longer needs overriding as the default behaviour in friendly_id v5 is
to only generate the friendld_id on new records.
@tekin @heathd tekin Reinstate magic finders for friendly_id
By default, friendly_id v5 turns off the magic finder overrides that allow
`Model.find(slug)` to work. We can configure friendly_id to include this

It would be a good idea to stop relying on this behaviour and instead either
call `Model.friendly.find(slug)` (which is the new way friendly_id recommends
finding by slug), or `Model.find_by(slug: slug)`. Until the test suite is green
and the Rails 4 upgrade is complete however, that is going to be very tricky.
@tekin @heathd tekin Don't use deprecated assert_blank method bd17558
@tekin @heathd tekin Stop HtmlAttachment slug generation complaining
friendly_id doesn't like generating slugs for HtmlAttachment because it will use
the scope on the base class Attachment, and that doesn't have the necessary
friendly_id helpers mixed in (because it doesn't do slugs).

By specifying the scope here explicitly, we force friendly_id to go through the
correct class. It also means that we HtmlAttachment slugs are now scoped to
their owning edition, meaning that two HtmlAttachments can share the same slug
assuming they are attached to a different edition.
@tekin @heathd tekin "confirm" is now a data attribute a9c1f28
@tekin @heathd tekin Don't use invalid locale in tests eb796c2
@tekin @heathd tekin assert_equal_hash is now redundant
Hash#diff is now deprecated in Rails, besides which assert_equal in MiniTest is
now smart enough to show proper diffs for hashes, making this custom assertion
@tekin @heathd tekin Don't create through deeply nested association
Deeply nested through associations are now read-only and attempting to modify
them raises a HasManyThroughNestedAssociationsAreReadonly exception.
@tekin @heathd tekin Replace assert_include with assert_includes 86093b3
@tekin @heathd tekin Tweak unfiltered_scope method
This complex AR scope needed a slight adjustment to ensure the generated SQL is
valid and has all the required columns accessible.
@tekin @heathd tekin Generate valid sub-query
The SQL generated by Rails 4 is subtly different from Rails 3. This gets things
working again.
@tekin @heathd tekin Don't call deprecated globalize method
required_translated_attributes has been deprecated in globalize as it relies on
some very specific internals of ActiveRecord. Instead, we simply set any
translated attributes that aren't blank.
@tekin @heathd tekin Globalize changes
The with_required_attributes method is deprecated in the globalize gem and
doesn't appear to do anything useful.

This also updates a scope ordering to be explicit about which column is used for
the ordering as globalize no longer magically infers ordering based on
translated columns.
@tekin @heathd tekin Correct use of `except` method
Passing in an array to the `except` method does not do what is intended.
@tekin @heathd tekin Explicitly set ordering when building test data
The way that ActiveRecord now sets and saves these associations means that the
auto-ordering does not work when you add attachments as an array. This sets the
ordering explicitly in these tests.
@tekin @heathd tekin Simplify consultation participation tests ed1139f
@tekin @heathd tekin Remove unused procomputed relation count
This precomputed value is no longer used anywhere in the app so getting rid of
it. There is a pending migration to remove the column from the database once
this code has been successfully deployed.
@tekin @heathd tekin Inline consultation-specific test
The indirection of putting the test behind a helper method is not helpful,
especially as the Consultation model is the only one that it applies to.
@tekin @heathd tekin Update conditional presence validation syntax
The previous syntax no longer works. The new syntax requires that the valid URI
validation check be done separately.
@tekin @heathd tekin Remove redundant ActiveRcord bug workaround code
The workaround for the ActiveRecord bug is no longer required. In fact, it
appears to have the opposite effect now! Reworded the regression test to
hopefully make it clearer what it is covering.
@tekin @heathd tekin Be explicit about datetime format we want
The default precision when coercing a DateTime to a JSON-encoded string has
changed between Rails 3 and 4 (it now includes 3 fractional digits by default).
This updates the tests to be more robust
@tekin @heathd tekin No need to explicitly save CIP titles as blank
The with_translations scope is primarily meant for loading translations of a
particular locale, but it is often used in whitehall as a way of pre-fetching
the translations to avoid n+1 queries. The version of the with_translations
method in pre-Rails 4 globalize used to invoke with_required_attributes as well,
which had the effect of excluding any instances that didn't have all required
attributes set in the database. The effect of this was that calling
with_translations on CorporateInformationPages would return an empty set,
because they do not have an explicit title saved in the database as their titles
are derived from their CorporateInformationPageType. We got around this by
setting their titles to a blank string in the database (rather than leaving
them to be NULL). Now, in Rails 4-globalize, the with_translations scope no
longer calls `with_required_attributes` (the method itself is also deprecated),
making the little dance redundant.

I've kept the test in here as a regression, although rewritten it slightly to
focus on the important thing - that the scope still loads the instances.

 # Please enter the commit message for your changes. Lines starting
@tekin @heathd tekin Update stubbed test to pass with newer Rails
Yet another reason why relying on stubbing of Rails internals (and in fact
stubbing in general) in your tests is almost always a bad idea.
@tekin @heathd tekin Get rid of low-value tests
Most of the tests provided little value and were more complicated than they
needed to be. This simplifies things down to a single test that covers the
important part of ensuring that role appointments persist between editions.
@tekin @heathd tekin Add additional test coverage for edition role appointments
This adds some missing coverage around exposing the role appointments in search
data when present.
@tekin @heathd tekin Instead of stubbing invalid thing do it for realz
This test was unnecessarily dependent on the internal implementation of the
method under test. Instead of stubbing out Active Record calls, just create the
real data conditions we want, i.e. an invalid featuring.
@tekin @heathd tekin dom_id helper is moving...
... It's now in ActionView::RecordIdentifier.
@tekin @heathd tekin Prompt as string to grouped options deprecated
The prompt must now be specified by passing in a hash of options.
@tekin @heathd tekin Fix suggestions controller tests
Need to be explicit about the format and also the keys on the assigned attribute
are symbols, not strings.
@tekin @heathd tekin This patch is no longer required 52be1b7
@tekin @heathd tekin Don't inherit Decorator from Struct
This was causing Rail's content_tag_for helper to blow up because (as of Rails
4), that method wraps the passed in record in an array and iterates over it (so
that multiple records can be passed in and handled). The problem is that a
Struct is only meant to be a simple data structure, and as such, is enumerable
(it enumerates over its attributes).

This worked with Rails 3 because that version of the helper called `to_ary` on
the passed in record(s) only if it responded to it instead of wrapping in an
array and iterating.

Besides all this, inheriting from Struct is a bit of an anti-pattern[1],
especially for anything more complex than a simple data container.

[1] http://blog.steveklabnik.com/posts/2012-09-01-random-ruby-tricks--struct-new
@tekin @heathd tekin Ensure SupportingPage#organisations are unique
This has many through no longer magically uniqueifies the organisations that are
linked to the polices of the supporting page. This makes that explicit in the
@tekin @heathd tekin Go through test_helper
This will break with Rails 4.1
@tekin @heathd tekin Rename clashing method name
There is a private "failure" method in newer versions of
ActiveSupport::TestCase. This will help future upgrades
@tekin @heathd tekin Use patched globalize gem
A change made to the globalize gem that made the belongs_to association
on the Translation model "touch" the owning translated model[1]. This causes
issues when trying to destroy translated instances that are using Rails'
optimistic locking: When destroying a translated instance, the associated
translations are destroyed first, which "touch"es the owning instance
(incrementing the lock_version), making the in-memory lock_version out-of-date,
resulting in the destroy failing with a ActiveRecord::StaleObject error.

This is ultimately a bug in ActiveRecord (it should be able to cope with such a
configuration), but fixing it is non-trivial. For now use a forked version of
globalize that does not touch the association, as this isn't needed
in whitehall (it was introduced to invalidate timestamp-based cache keys when a
translation is destroyed on a model).

[1]: globalize/globalize#330
@tekin @heathd tekin Get rid of unhelpful stubbing
This makes refactoring the controller code hard.
@tekin @heathd tekin Don't use magic finders on Classifications
The friendly_id magic find override module doesn't play nice with Rails STI,
which is a problem for Topics and TopicalEvents. For these models, use the new
recommended method of finding instances based on their slug, which is to go via
the `friendly` scope.

Eventually, all code should be updated to use this instead of the magic find
override module as it isn't very stable and keeps breaking with new releases of
Rails[1]. Doing this is before the upgrade to Rails 4 is complete is going to be
hard however, so deferring until later.

[1] norman/friendly_id#607
@tekin @heathd tekin Use decimal (not hex) HTML entity codes
Rails now generates error messages with the decimal representation of HTML
entity codes.
@tekin @heathd tekin Tidy up un-cached code
This changes things such that the code no longer ties to a specific string for
the Cache-Control header.

Setting Cache-Control to 'no-cache' makes the rest of the directive redundant
in this case. This cleans up the code and the tests to make them more robust by
using the available helpers instead of explicitly setting and checking header
@tekin @heathd tekin Use friendly scope on MinisterialRole find 5288e3e
@tekin @heathd tekin Add pry-byebug to aid debugging
This has been very helpful during the upgrade process so adding it as a
permanent development gem here.
@tekin @heathd tekin Improve test coverage around localised routing
This makes the expected behaviour around localised routes a bit more explicit.

We've done this to give us more confidence whilst we refactor the localised
routing patches to deal with an issue around default url options and
specifically  the way routing behaves when :format is set to a default on
non-localised routes.
@tekin @heathd tekin Patch bug in Rails routing
Whitehall.atom_feed_maker was having trouble generating urls for non-localised
resources, e.g. topics. This turned out to be due to a bug in Rails routing code
that meant the default format set in atom_feed_maker was being lost. This
patches Rails to fix the issue. There is also a pull request on Rails to fix it
there too:

@tekin @heathd tekin Get around stricter Rails routing
Rails routing is now much stricter about matching valid routes, especially when
it comes to matching routes against inherited controller classes - it will no
longer match a route to a base class like EditionsController unless there are
explicit routes mapping to its actions. This rewrites and reorganises the
controller test to make sure that valid routes are used, appropriate
controllers are tested and that the required test routes exist.
@tekin @heathd tekin Remove unnecessary stubbing in test
This was broken by the fact that we're no longer calling the deprecated `#all`
method in the controller code. Only stub when absolutely necessary people!
@tekin @heathd tekin Fix attachment ordering on new records
The code that set the ordering on new attachments fails when creating a brand
new attachable thing with more than one attachment. This appears to be because
the query generated to calculate the maximum available ordering is not correctly
setting the newly generated ID of the attachable thing, and thus no matching
attachments are being found. The fix is to explicitly generate the query to get
the maximum ordering, making sure the ID of the attachable thing is used.
@tekin @heathd tekin Don't use deprecated distinct: true in count scope 8c53526
@tekin @heathd tekin Avoid issues with ActionController::Parameters
The code is modifying an ActionController::Parameters instance when it sets the
:creator_id. This causes an ActiveModel::ForbiddenAttributesError to be raised
in  the build_statistics_announcement_date_change method when an attempt is made
to reverse_merge in the previous date's values. We can avoid this issue by
converting it into a plain old hash before passing it to the model code. This is
safe as an error would have already been raised if any unsafe parameters had
been sent with the request.
@tekin @heathd tekin Ensure valid locale before saving translation
Means failing earlier, plus prevents the change in the next commit from breaking
an import that has translation fields but no valid locale set.
@tekin @heathd tekin Globlize bug workaround
There appears to be a bug in globalize that is causing update_attributes to
succeed even with invalid attributes when called in an I18n.with_locale block.
By also explicitly setting the locale in the update_attributes call, we get
around the bug.
@tekin @heathd tekin Maintain ordering of inapplicable nations
The forms for editions display the potentially inapplicable nations in a set
order (Scotland, Wales, Northern Ireland). This was previously maintained by
building NationInapplicabilities in the controller and sorting the association
based on the nations. This no longer works in Rails 4 (the order of items in an
association cannot be manipulated in this way). Instead of doing this work in
the controller, we can build the form fields starting from the ordered nations.
@tekin @heathd tekin SCSS Deprecation
The extra .css in SCSS files is unnecessary and is deprecated.
@tekin @heathd tekin Make test selectors less brittle 493116d
@tekin @heathd tekin Get around code reloading issue
A strange interaction with Rails auto code-reloading and this class is happening
which is causing the following exception to be raised:

   ArgumentError A copy of EditionServiceCoordinator has been removed from the

Being more explicit about the namespace of the classes referenced here makes the
problem go away.
@tekin @heathd tekin Fix issue with invalid AttachmentData
The upgrade to Rails 4 broke mass-assignment of FileAttachments whilst the
associated Attachment file was awaiting virus scanning. The fix is to ensure
that an AttachmentData record will still be valid whilst awaiting virus

This change is required because ActiveRecord now loads the associated
AttachmentData *before* it checks if the nested attributes should be assigned or
rejected because of the reject_if proc. This made the FileAttachment invalid for
newly-uploaded FilAttachments that are still awaiting virus scanning because of
the presence check on the AttachmentData `file` attribute.
@tekin @heathd tekin Don't store ActionController::Parameters in session
Storing an instance of ActionController::Parameters in the session for the
filter options breaks `redirect_to session_filters` because:

  ActionController::ActionControllerError: Cannot redirect to a parameter hash!
@tekin @heathd tekin uniq_by is deprecated 2f1cdb9
@tekin @heathd tekin Skipping ActiveRecord no longer necessary
We no longer need to skip the loading of ActiveRecord when compiling assets.
@tekin @heathd tekin Don't ignore /bin directory
The rails-generated binstubs should be included in the git repository, otherwise
they need to be generated by each developer locally.

See https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs for more
@tekin @heathd tekin Use latest shared_mustache
This newer version of shared_mustache gets around an issue where the latest
sprockets-rails was using the blank vendor version of template.js in
shared_mustache instead of the local copy in whitehall when loading non-compiled
assets in non-production environments. This was causing a javascript-enabled
cucumber feature to fail. Because template.js is no longer present in
shared_mustache, we now need a copy in the repository.
@tekin @heathd tekin Set explicit rows for text areas
Rails 3 had default options for text area tags:

  DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }

This was removed in Rails 4. This commit only sets the rows as the width of
text areas is defined with CSS.
@tekin @heathd tekin Replace "locale" column with "primary_locale"
The fact that we are using a column called "locale" on the editions table to
signify the locale for non-english editions causes an issue with later
versions of the globalize gem.

This is the second phase of migrating this column to a new name of
"primary_locale". We pre-emptively added the column to the table in
3f2a376. This commit includes a
migration to sync the `primary_locale` column with `locale` on

At this stage we do not yet remove the old locale column, to avoid
breaking existing running processes which expect the `locale` field to
be present still. We deprecate the `locale` column in the `Edition`
model however.

Once this code has been deployed, the pending migration can be run to
safely drop the old column and the `deprecated_columns` directive can be
@tekin @heathd tekin Update non-english locale fields JavaScript
The DOM selector changed when the locale column was renamed. Whilst I was here I
also tidied up the tests for the JS and changed the behaviour slightly so that
instead of hiding the locale fields on-load, the "js-hidden" class is applied to
the fieldset so that they are hidden right away (on JS-enabled browsers at
least). This prevents them briefly flashing up whilst the JavaScript is being
loaded and evaluated on the page.
@tekin @heathd tekin Add note regarding globalize fork
@heathd has got a patch in to the main globalize fork that deals with the issue
my fork works around. Unfortunately, master branch globalize has been updated
for Rails 4.2 compatibility and is therefor not compatible with this version of
whitehall. Either the patch will need to be backported, or we'll have to wait
until whitehall is updated for Rails 4.2 before moving to the main fork of
@tekin @heathd tekin Use release of rack-test
A new version of rack-test has finally been released, meaning we no longer need
to reference a github reference for the params with arrays of hashes fix.
@heathd heathd Avoid 'Cannot redirect to a parameter hash' error
Rails 4 introduced a [protection against passing parameters hash into
`redirect_to`](rails/rails#16170) as a security

In some circumstances the `session[:document_filters]` could contain a
paramters hash (I suspect this may only be the case for a session which
was serialized into someones session cookie in the pre-rails-4 whitehall
app and deserialized in this release).

Adding this `.to_h` forces the hash to always be converted to a ruby

It's safe to pass these parameters to redirect_to because they are all
features which are intended to be controlled by user input. The redirect
is just a feature to ensure consistency of urls.
@heathd heathd merged commit e354265 into master Feb 19, 2015

1 check passed

default Build #5179 succeeded on Jenkins
@heathd heathd deleted the upgrade-to-rails-4 branch Feb 19, 2015


fofr commented Feb 19, 2015

๐ŸŽ‰ 4๏ธโƒฃ ๐ŸŽˆ

tekin commented Feb 20, 2015




Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment