From 196b4e05b7390ac31e12a17ae224b1cf35e4becd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 12 Aug 2010 14:55:31 -0700 Subject: tables can fetch attributes --- spec/arel/attributes_spec.rb | 41 +++++++++++++++++++++++++++++++++++++++++ spec/arel/table_spec.rb | 12 +++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 spec/arel/attributes_spec.rb (limited to 'spec') 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] -- cgit v1.2.3