Refactor method.
This commit is contained in:
parent
ed5b3ee269
commit
5d1027b180
|
@ -47,13 +47,17 @@ module Shoulda # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection?
|
def collection?
|
||||||
if @subject.class.respond_to?(:reflect_on_association) &&
|
if reflection
|
||||||
reflection = @subject.class.reflect_on_association(@attribute)
|
|
||||||
[:has_many, :has_and_belongs_to_many].include?(reflection.macro)
|
[:has_many, :has_and_belongs_to_many].include?(reflection.macro)
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reflection
|
||||||
|
@subject.class.respond_to?(:reflect_on_association) &&
|
||||||
|
@subject.class.reflect_on_association(@attribute)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
|
describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher do
|
||||||
|
|
||||||
context "a required attribute" do
|
context "a required attribute" do
|
||||||
before do
|
before do
|
||||||
define_model :example, :attr => :string do
|
define_model :example, :attr => :string do
|
||||||
|
|
Loading…
Reference in New Issue