Commit Graph

10 Commits

Author SHA1 Message Date
Elliot Winkler a4045a1f9b Remove Rails 3.x, Ruby 1.9.2, Ruby 1.9.3
Ruby 1.9.3 will be end-of-lifed on February 23, 2015. We might as well
remove support for it now.
2015-02-09 10:52:22 -07:00
Elliot Winkler 9ba21381d7 Handle RangeErrors emitted now in ActiveRecord 4.2
In Rails 4.2, ActiveRecord was changed such that if you attempt to set
an attribute to a value and that value is outside the range of the
column, then it will raise a RangeError. For instance, an integer column
with a limit of 2 (i.e. a smallint) only accepts values between -32768
and +32767.

This means that if you try to do any of these three things, a RangeError
could be raised:

* Use validate_numericality_of along with any of the comparison
  submatchers and a value that sits on either side of the boundary.
* Use allow_value with a value that sits outside the range.
* Use validates_inclusion_of against an integer column. (Here we attempt
  to set that column to a non-integer value to verify that the attribute
  does not allow said value. That value is really a string version of a
  large number, so if the column does not take large numbers then the
  matcher could blow up.)

Ancillary changes in this commit:

* Remove ValidationMessageFinder and ExceptionMessageFinder in favor of
  Validator, StrictValidator, and ValidatorWithCapturedRangeError.
* The allow_value matcher now uses an instance of Validator under the
  hood. StrictValidator and/or ValidatorWithCapturedRangeError may be
  mixed into the Validator object as needed.
2015-01-22 21:05:09 -07:00
Elliot Winkler 547d8b762f Fix AR matcher tests for Rails 4.2 2014-12-25 00:45:06 -05:00
Elliot Winkler c22d7c89e0 Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
Elliot Winkler 218293ad07 Fix several issues with strong parameters matcher
* Instead of decorating controller params, use our "Doublespeak"
  mini-library to stub ActionController::Parameters. This prevents from
  interfering with the params object if it is used in various ways, i.e.
  if `params.fetch(...).permit(...)` is used instead of
  `params.require(...).permit(...)`.
* Fix compat with Rails 4.1, where the verb for #update is PATCH not
  PUT
* Track multiple calls to #permit within a given controller action
* Fix so that if the route for your action requires params (such as
  :id) then you can specify those params
2014-04-22 09:37:30 -05:00
John Feminella e8aef07295 Updates RailsShim to be explicit about which Rails pieces it needs 2013-12-16 12:37:33 -05:00
Elliot Winkler a026afb800 Fix validates_confirmation_of matcher so that it works under Rails 4
Rails 4 changed how validates_confirmation_of works so that the error
message is applied to the confirmation attribute, not the original
attribute.
2013-08-16 16:17:26 -06:00
Elliot Winkler 2b68f3859b Use relations to define conditions and order on associations
In Rails 4, the following construct:

  has_many :children, conditions: { adopted: true }

changes to:

  has_many :children, lambda { where(adopted: true) }

As a result, the way we check the conditions attached to a has_many
changes too: instead of accessing `reflection.options`, we have to use
`reflection.scope` -- this which refers to the lambda above, so we have
to evaluate it and then grab the `where` from the Relation that the
lambda returns.
2013-08-16 16:17:22 -06:00
Derek Prior + Elliot Winkler 9a333d12b4 Fix set_the_flash_matcher for Rails 4
The "flashes" instance variable that lives within FlashHash has changed
in Rails 4. I have added a shim to get the proper name.

Additionally, the set_the_flash matcher will dup the flash hash for the
controller on which it operates. As #dup does a shallow copy we need to
make sure to also copy the instance variables within the flash hash when
we do this. The Rails 4 version of FlashHash has an extra @discard
variable unlike the Rails 3 version so we make sure to copy that.
2013-08-16 16:00:10 -06:00
Derek Prior c4927b73f2 Fix render_with_layout_matcher on Rails 4.
Rails 4 moved the layouts ivar from `@layouts` to `@_layouts`.

This change introduces what I have (for now) called the 'RailsShim'. The
idea is that this single class will house the rail version workarounds,
which can then be reused through the code. This paid off here because
both the spec and the implementation need access to the layouts ivar.
2013-08-16 15:32:08 -06:00