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

Created a test for has_many :through presence validation issue #9823

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -901,4 +901,11 @@ def test_has_many_through_with_polymorphic_source
readers(:michael_authorless).update(first_post_id: 1)
assert_equal [posts(:thinking)], person.reload.first_posts
end

def test_creating_new_object_passes_presence_validation
club = members(:groucho).clubs.create!

member = Member.new(clubs: [club])
assert member.valid?, "Creating a new member with a club should pass club and member uniqueness validations"
end
end
2 changes: 2 additions & 0 deletions activerecord/test/models/membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Membership < ActiveRecord::Base
class CurrentMembership < Membership
belongs_to :member
belongs_to :club

validates_presence_of :member, :club
end

class SelectedMembership < Membership
Expand Down