module Shoulda::Matchers::ActiveRecord
Matchers for your active record models¶ ↑
These matchers will test the associations for your ActiveRecord models.
describe User do it { should have_one(:profile) } it { should have_many(:dogs) } it { should have_many(:messes).through(:dogs) } it { should belong_to(:lover) } end
Public Instance Methods
accept_nested_attributes_for(name)
click to toggle source
Ensures that the model can accept nested attributes for the specified association.
Options:
-
allow_destroy
- Whether or not to allow destroy -
limit
- Max number of nested attributes -
update_only
- Only allow updates
Example:
it { should accept_nested_attributes_for(:friends) } it { should accept_nested_attributes_for(:friends). allow_destroy(true). limit(4) } it { should accept_nested_attributes_for(:friends). update_only(true) }
# File lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb, line 20 def accept_nested_attributes_for(name) AcceptNestedAttributesForMatcher.new(name) end