aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-08-12 14:55:31 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-08-12 14:55:31 -0700
commit196b4e05b7390ac31e12a17ae224b1cf35e4becd (patch)
treebc5a5e56f8311bd68feb628d89a04e845585f3b5 /spec
parent1036749e394e5f7f039e75cdec7675f9ca5047b0 (diff)
downloadrails-196b4e05b7390ac31e12a17ae224b1cf35e4becd.tar.gz
rails-196b4e05b7390ac31e12a17ae224b1cf35e4becd.tar.bz2
rails-196b4e05b7390ac31e12a17ae224b1cf35e4becd.zip
tables can fetch attributes
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/attributes_spec.rb41
-rw-r--r--spec/arel/table_spec.rb12
2 files changed, 52 insertions, 1 deletions
diff --git a/spec/arel/attributes_spec.rb b/spec/arel/attributes_spec.rb
new file mode 100644
index 0000000000..8b437dff9b
--- /dev/null
+++ b/spec/arel/attributes_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+module Arel
+ describe 'Attributes' do
+ describe 'for' do
+ it 'returns the correct constant for strings' do
+ [:string, :text, :binary].each do |type|
+ column = Struct.new(:type).new type
+ Attributes.for(column).should == Attributes::String
+ end
+ end
+
+ it 'returns the correct constant for ints' do
+ column = Struct.new(:type).new :integer
+ Attributes.for(column).should == Attributes::Integer
+ end
+
+ it 'returns the correct constant for floats' do
+ column = Struct.new(:type).new :float
+ Attributes.for(column).should == Attributes::Float
+ end
+
+ it 'returns the correct constant for decimals' do
+ column = Struct.new(:type).new :decimal
+ Attributes.for(column).should == Attributes::Decimal
+ end
+
+ it 'returns the correct constant for boolean' do
+ column = Struct.new(:type).new :boolean
+ Attributes.for(column).should == Attributes::Boolean
+ end
+
+ it 'returns the correct constant for time' do
+ [:date, :datetime, :timestamp, :time].each do |type|
+ column = Struct.new(:type).new type
+ Attributes.for(column).should == Attributes::Time
+ end
+ end
+ end
+ end
+end
diff --git a/spec/arel/table_spec.rb b/spec/arel/table_spec.rb
index 20c962c26a..c52a111489 100644
--- a/spec/arel/table_spec.rb
+++ b/spec/arel/table_spec.rb
@@ -6,14 +6,24 @@ module Arel
@relation = Table.new(:users)
end
+ describe 'columns' do
+ it 'returns a list of columns' do
+ columns = @relation.columns
+ columns.length.should == 2
+ columns.map { |x| x.name }.sort.should == %w{ name id }.sort
+ end
+ end
+
describe '[]' do
describe 'when given a', Symbol do
it "manufactures an attribute if the symbol names an attribute within the relation" do
column = @relation[:id]
- #.should == Attributes::Integer.new(@relation, :id)
+ column.name.should == 'id'
+ column.should be_kind_of Attributes::Integer
end
end
+ ### FIXME: this seems like a bad requirement.
#describe 'when given an', Attribute do
# it "returns the attribute if the attribute is within the relation" do
# @relation[@relation[:id]].should == @relation[:id]