Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Commits on Mar 29, 2015
  1. @maurogeorge @mcmire

    Add documentation to validate_absence_of on qualifier

    maurogeorge authored mcmire committed
    [ci skip]
  2. @mcmire

    Refactor specs for numericality matcher

    mcmire authored
    Mainly, use some metaprogramming to add tests that combine the
    qualifiers in various ways. This paves the way to add a #strict
    qualifier and yet test its interaction with other qualifiers completely.
  3. @mcmire

    Improve failure messages for #fail_with_message_including

    mcmire authored
    This improves our internal matcher so that it mirrors
    #fail_with_message. In other words, when it fails it will now say:
    
        Expectation should have failed with:
          Some message goes here
        Actually failed with:
          Some other message goes here
        However, the expectation did not fail.
Commits on Mar 15, 2015
  1. @mcmire

    validate_after_scope_change? use compact before retrieving max

    Florence Foo authored mcmire committed
    Otherwise produces error "ArgumentError: comparison of NilClass with
    String failed" if the resultant contains a combinations of strings and
    nils.
Commits on Mar 13, 2015
  1. @lucianosousa @mcmire

    Update shoulda-matchers.gemspec

    lucianosousa authored mcmire committed
    finishing drop support to ruby 1.9.x
  2. @mcmire
Commits on Mar 12, 2015
  1. @cpytel

    Add "About thoughtbot" section to readme

    cpytel authored
    * Move thanks to contributors to the top
    * Remove credits section
    * Introduce new "About thoughtbot" section.
Commits on Mar 1, 2015
  1. @mcmire
  2. @eLobato @mcmire

    Update copyright year in README

    eLobato authored mcmire committed
  3. @mcmire

    Permit matcher now supports subparameters

    mcmire authored
    Previously we were taking ActionController::Parameters and completely
    overriding #require, forcing it to return `self`, i.e, the entire
    ActionController::Parameters object. This meant that we broke its
    functionality, which is to return a slice of the params hash instead.
    The consequence of this is that attempting to call #permit on a slice of
    the params hash obtained via #require would not work:
    
    ``` ruby
    params = ActionController::Parameters.new(
      { "course" => { "foo" => "bar" } }
    )
    params.require(:course)
    params.require(:course).permit(:foo)
    ```
    
    This commit fixes the permit matcher so that #require is proxied
    instead, retaining the existing behavior.
    
    This commit also adds a qualifier, #on, for asserting that your action
    places a restriction on a slice of the params hash. The `permit` matcher
    will properly track calls on child `params` instances. For example:
    
    ``` ruby
    class UsersController < ActionController::Base
      def create
        User.create!(user_params)
        ...
      end
    
      private
    
      def user_params
        params.require(:user).permit(:name, :age)
      end
    end
    
    describe UsersController do
      it { should permit(:name, :age).for(:create).on(:user) }
    end
    ```
    
    If this fails, you'll get the following error message:
    
    ```
    Expected POST #create to restrict parameters for :user to :name and :age,
    but restricted parameters were :first_name and :last_name.
    ```
  4. @mcmire

    Omit newest private modules from docs

    mcmire authored
    [ci skip]
  5. @mcmire
  6. @mcmire
  7. @mcmire

    Doublespeak: Only store original method once

    mcmire authored
    If a method for a class is doubled more than once within the same test
    run, the original implementation of that method will change from double
    to double, even if the double is deactivated correctly. Say we have two
    distinct tests that both double the same method. Here is how that method
    will be overridden as it goes along:
    
        A) START: original method
        B) ACTIVATE (1st test): method is doubled
        C) DEACTIVATE (1st test): calls original method (A)
        D) ACTIVATE (2nd test): original method (C) stored; method is again
                                doubled
        E) DEACTIVATE (2nd test): calls original method (C)
    
    With this commit, this changes to:
    
        A) START: original method
        B) ACTIVATE (1st test): method is doubled
        C) DEACTIVATE (1st test): calls original method (A)
        D) ACTIVATE (2nd test): original method not stored again; method is
                                again doubled
        E) DEACTIVATE (2nd test): calls original method (A)
  8. @mcmire

    Doublespeak: Introduce a better MethodCall

    mcmire authored
    MethodCall is used to represent a method call made on a double. It
    stores the object the call was made on, the name of the method, any
    arguments or block sent to the method, and the double itself. There were
    quite a few places where we were using an (args, block) or (object,
    args, block) tuple. We also already had a MethodCall class, and
    additionally a MethodCallWithName class, and the two were basically the
    same. These usages have all been collapsed.
  9. @mcmire
  10. @mcmire

    Rewrite the tests for #permit

    mcmire authored
    * Use `permit` directly instead of manually building the matcher
    * Some tests were being tested by calling #matches? directly when they
      shouldn't have been, and some tests were duplicated
    * Rename helper methods that define controllers to express intent better
    * Don't make a global class (SimulatedError), keep the class local to
      the example group
    * Use lambdas for that use `raise_error`
  11. @mcmire
  12. @mcmire
  13. @mcmire

    Upgrade pry to master version

    mcmire authored
    The latest commit of pry removes a lot of annoying warnings.
    Unfortunately a new release has not been issued yet, so just use the
    master branch for now.
Commits on Feb 20, 2015
  1. @seanpdoyle

    Cache Bundler on Travis

    seanpdoyle authored
    With Container based CI, public projects can cache the results of
    `bundle install`
Commits on Feb 18, 2015
  1. @mcmire

    allow_value: Raise error if attr sets value differently

    Anthony Navarre + Elliot Winkler authored mcmire committed
    `allow_value` will now raise a CouldNotSetAttribute error if the
    attribute in question cannot be changed from a non-nil value to a nil
    value, or vice versa. In other words, these are the exact cases in which
    the error will occur:
    
    * If you're testing whether the attribute allows `nil`, but the
      attribute detects and ignores nil. (For instance, you have a model
      that `has_secure_password`. This will add a #password= method to your
      model that is defined in a such a way that you cannot clear the
      password by setting it to nil -- nothing happens.)
    * If you're testing whether the attribute allows a non-nil value, but
      the attribute fails to set that value. (For instance, you have an
      ActiveRecord model. If ActiveRecord cannot typecast the value in the
      context of the column, then it will do nothing, and the attribute will be
      effectively set to nil.)
    
    What's the reasoning behind this change? Simply put, if you are assuming
    that the attribute is changing but in fact it is not, then the test
    you're writing isn't the test that actually gets run. We feel that this
    is dishonest and produces an invalid test.
Commits on Feb 17, 2015
  1. @mcmire

    Uniqueness: Fix default behavior for case-insensitive models

    Anthony Navarre + Elliot Winkler authored mcmire committed
    If you have a model that has a uniqueness validation using
    `case_sensitive: false`, and you are testing against but do not qualify
    the matcher with `case_insensitive`, then the matcher will pass
    unexpectedly. Take this model for instance:
    
        class Product < ActiveRecord::Base
          validates_uniqueness_of :name, case_sensitive: false
        end
    
    Currently, the following test passes. With this commit, it will now
    (correctly) fail:
    
        describe Product do
          it { is_expected.to validate_uniqueness_of(:name) }
        end
Commits on Feb 16, 2015
  1. @mcmire

    master == 3.0.0.alpha

    mcmire authored
    There is no gem release associated with this commit, this is only so
    that people who are testing against the master branch will see that the
    version is not 2.8.0.
    
    [ci skip]
Commits on Feb 14, 2015
  1. @mcmire
  2. @mcmire

    Uniqueness: Fix when scope set to nil beforehand

    mcmire authored
    Switch the order of how the column type is detected so that string comes
    last. This fixes a bug where if the scope was a text column but was set
    to nil before running the matcher, the matcher would fail.
Commits on Feb 13, 2015
  1. @mcmire

    Uniqueness: Support PG array columns for scopes

    mcmire authored
    Please note that array columns do not work properly between Rails 4.0
    and 4.2.
    
    * If you set an array-of-date or array-of-time attribute to an
      array, it will fail to hold that value. This is an issue with
      timestamp-aware attributes and is fixed in Rails 4.2.
    
    * Even if this worked, the uniqueness validator cannot cope with array
      columns, producing an invalid query. This will be fixed in 4.1.10.
  2. @guilhermeFranco @mcmire

    Fix enum attribute name verification

    guilhermeFranco authored mcmire committed
    Fix `define_enum_for` so that it actually tests that the attribute is
    present in the list of defined enums, as you could fool it by merely
    defining a class method that was the pluralized version of the attribute
    name. In the same vein, passing a pluralized version of the attribute
    name to `define_enum_for` would erroneously pass, and now it fails.
  3. @mcmire
Commits on Feb 12, 2015
  1. @mcmire
  2. @mcmire

    Uniqueness: Support UUID columns that end in "f"

    mcmire authored
    This commit fixes the uniqueness matcher so that when qualified with
    `scoped_to` and one of the scopes is a UUID column that happens to end
    in an "f", the matcher is able to generate a proper next value during
    testing and doesn't error.
  3. @mcmire
  4. @mcmire

    Add support for Postgres

    mcmire authored
    When running tests, you can now switch between running them against a
    SQLite or PostgreSQL database. This is accomplished by modifying the
    unit and acceptance tests so that when they generate and load the test
    Rails application, database.yml is replaced with content that will
    configure the database appropriately.
  5. @mcmire

    Changes to CommandRunner

    mcmire authored
    * Use full output instead of elided output on failure
    * Refactor debugging code a bit
    * Use :chdir option to Process.spawn instead of Dir.chdir
Commits on Feb 11, 2015
  1. @mcmire

    Uniqueness: Add missing tests for scopes w/ datetime + Time

    mcmire authored
    Here, we are basically testing the logic that generates a next value for
    a scope attribute, in the case that that attribute is a Time object
    instead of a DateTime object.
Something went wrong with that request. Please try again.