Permalink
Browse files

Fix one-arg on loaded collection (fixes #8)

  • Loading branch information...
ernie committed Jan 11, 2012
1 parent 9afbe22 commit f4a9d1e76f2cac83f9556b6cd12933953ff45a34
Showing with 21 additions and 3 deletions.
  1. +5 −1 .travis.yml
  2. +5 −1 lib/valium.rb
  3. +1 −1 lib/valium/version.rb
  4. +10 −0 spec/valium/valium_spec.rb
View
@@ -1,6 +1,10 @@
rvm:
- 1.8.7
- 1.9.2
+ - 1.9.3
- ree
- rbx
- - ruby-head
+ - ruby-head
+
+env:
+ - RAILS=3-2-stable
View
@@ -93,7 +93,11 @@ def value_of(*args)
end
if loaded? && (empty? || args.all? {|a| first.attributes.has_key? a})
- to_a.map {|record| args.map {|a| record[a]}}
+ if args.size > 1
+ to_a.map {|record| args.map {|a| record[a]}}
+ else
+ to_a.map {|record| record[args[0]]}
+ end
else
scoping { klass.value_of *args }
end
View
@@ -1,3 +1,3 @@
module Valium
- VERSION = "0.4.0"
+ VERSION = "0.5.0"
end
View
@@ -149,5 +149,15 @@
it { should have(10).elements }
it { should eq Person.first.widgets.map(&:id) }
end
+
+ context 'with an association after call #collection= for that association' do
+ subject do
+ Person.new do |person|
+ person.widgets = Widget.limit(10)
+ end
+ end
+
+ specify { subject.widgets.value_of(:id).should == Widget.limit(10).value_of(:id) }
+ end
end

0 comments on commit f4a9d1e

Please sign in to comment.