mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Refactor method.
This commit is contained in:
parent
ed5b3ee269
commit
5d1027b180
2 changed files with 6 additions and 3 deletions
|
@ -47,13 +47,17 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
def collection?
|
||||
if @subject.class.respond_to?(:reflect_on_association) &&
|
||||
reflection = @subject.class.reflect_on_association(@attribute)
|
||||
if reflection
|
||||
[:has_many, :has_and_belongs_to_many].include?(reflection.macro)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def reflection
|
||||
@subject.class.respond_to?(:reflect_on_association) &&
|
||||
@subject.class.reflect_on_association(@attribute)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
|
||||
|
||||
context "a required attribute" do
|
||||
before do
|
||||
define_model :example, :attr => :string do
|
||||
|
|
Loading…
Add table
Reference in a new issue