Permalink
Browse files

fixes - all specs pass running rake

  • Loading branch information...
1 parent 549ba1a commit c0ead774fb827412bccbe3bd13feab68f8957668 @kristianmandrup committed Aug 10, 2012
Showing with 12 additions and 6 deletions.
  1. +10 −4 lib/virtus/attribute.rb
  2. +1 −1 lib/virtus/extensions.rb
  3. +1 −1 spec/unit/virtus/class_methods/attributes_spec.rb
View
@@ -61,15 +61,21 @@ class Attribute
# @api private
def self.build(*args)
options = args.extract_options!
- type = args.last.kind_of?(Symbol) ? Object : args.pop
- args.map do |name|
+ type_arg = args.last
+ type = case type_arg.class.to_s
+ when 'Symbol' #, 'String'
+ Object
+ else
+ args.pop
+ end
+ attrs = args.map do |name|
build_one name, type, options
end
+ attrs.size == 1 ? attrs.first : attrs
end
def self.build_one(name, type = Object, options = {})
- attribute_class = determine_type(type) or
- raise ArgumentError, "#{type.inspect} does not map to an attribute type"
+ attribute_class = determine_type(type) or raise ArgumentError, "#{type.inspect} does not map to an attribute type"
attribute_options = attribute_class.merge_options(type, options)
attribute_class.new(name, attribute_options)
end
View
@@ -50,7 +50,7 @@ def self.extended(object)
# @api public
def attribute(*args)
attributes = Attribute.build(*args)
- attributes.each {|attribute| virtus_add_attribute(attribute) }
+ [attributes].flatten.each {|attribute| virtus_add_attribute(attribute) }
self
end
@@ -17,6 +17,6 @@
it 'returns a deprecation warning' do
subject
- $stderr.string.should =~ /\A#{object}.attributes is deprecated. Use #{object}.attribute_set instead: #{__FILE__}:4\b/
+ $stderr.string.should =~ /\A#{object}.attributes is deprecated for getting the set of attributes. Use #{object}.attribute_set instead: #{__FILE__}:4\b/
end
end

0 comments on commit c0ead77

Please sign in to comment.