Refactor method.

This commit is contained in:
Gabe Berke-Williams 2012-04-24 17:01:50 -05:00
parent ed5b3ee269
commit 5d1027b180
2 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -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