Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add required/optional qual's to belongs_to/has_one #1058

Merged
merged 1 commit into from
Oct 18, 2017

Conversation

mcmire
Copy link
Collaborator

@mcmire mcmire commented Oct 3, 2017

Rails 5 made two changes to belongs_to associations:

  • required and optional were added as options (which add and remove
    a presence validation on the association, respectively)
  • required was made the default

In addition, a required option was also added to has_one.

These new qualifiers allow us to test these options appropriately.

Credit: Shia rise.shia@gmail.com


Fixes #956, #870, #861.


message =
'Expected Child to have a belongs_to association called parent ' +
'(the association should have been defined with `optional: true`, ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]

@@ -279,13 +279,92 @@
end
end

def belonging_to_parent(options = {})
define_model :parent
context 'given an association with neither :required nor :optional specified' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]

)

if diff
lines << "Diff:"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

@@ -6,6 +6,8 @@
require "shoulda/matchers/active_record/association_matchers/order_matcher"
require "shoulda/matchers/active_record/association_matchers/through_matcher"
require "shoulda/matchers/active_record/association_matchers/dependent_matcher"
require "shoulda/matchers/active_record/association_matchers/required_matcher"
require "shoulda/matchers/active_record/association_matchers/optional_matcher"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

@@ -6,6 +6,8 @@
require "shoulda/matchers/active_record/association_matchers/order_matcher"
require "shoulda/matchers/active_record/association_matchers/through_matcher"
require "shoulda/matchers/active_record/association_matchers/dependent_matcher"
require "shoulda/matchers/active_record/association_matchers/required_matcher"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

Rails 5 made two changes to `belongs_to` associations:

* `required` and `optional` were added as options (which add and remove
  a presence validation on the association, respectively)
* `required` was made the default

In addition, a `required` option was also added to `has_one`.

These new qualifiers allow us to test these options appropriately.

Credit: Shia <rise.shia@gmail.com>
@mcmire mcmire force-pushed the add-optional-and-required branch from dd37208 to 3af3d9f Compare October 7, 2017 04:38
@mcmire mcmire requested a review from guialbuk October 9, 2017 01:19
@mcmire
Copy link
Collaborator Author

mcmire commented Oct 9, 2017

@guialbuk Would you mind reviewing this? :)

@guialbuk guialbuk merged commit 0d81aa6 into master Oct 18, 2017
@guialbuk guialbuk deleted the add-optional-and-required branch October 18, 2017 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants