diff options
author | Carl Lerche <carllerche@mac.com> | 2010-03-12 14:34:13 -0800 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-03-12 14:34:13 -0800 |
commit | 61916e408d86d19d1659cd8042de6503aecc6c98 (patch) | |
tree | 28cbadb9b39b44d993a033af5cf254655cdab58a /spec/arel/algebra | |
parent | 83c27c0b5e2e341307b7a160d831fb930a9552b4 (diff) | |
download | rails-61916e408d86d19d1659cd8042de6503aecc6c98.tar.gz rails-61916e408d86d19d1659cd8042de6503aecc6c98.tar.bz2 rails-61916e408d86d19d1659cd8042de6503aecc6c98.zip |
Add a bunch of specs for attribute type casting.
Diffstat (limited to 'spec/arel/algebra')
-rw-r--r-- | spec/arel/algebra/integration/basic_spec.rb | 58 |
1 files changed, 8 insertions, 50 deletions
diff --git a/spec/arel/algebra/integration/basic_spec.rb b/spec/arel/algebra/integration/basic_spec.rb index 6ade5c40ac..7aa4f7305c 100644 --- a/spec/arel/algebra/integration/basic_spec.rb +++ b/spec/arel/algebra/integration/basic_spec.rb @@ -1,50 +1,5 @@ require 'spec_helper' -module Arel - module Testing - class Engine - attr_reader :rows - - def initialize - @rows = [] - end - - def supports(operation) - false - end - - def read(relation) - @rows.dup.map { |r| Row.new(relation, r) } - end - - def create(insert) - @rows << insert.record.tuple - insert - end - end - end -end - -class Thing < Arel::Relation - attr_reader :engine, :attributes - - def initialize(engine, attributes) - @engine, @attributes = engine, [] - attributes.each do |name, type| - @attributes << type.new(self, name) - end - end - - def format(attribute, value) - value - end - - def insert(row) - insert = super Arel::Row.new(self, row) - insert.record - end -end - def have_rows(expected) simple_matcher "have rows" do |given, matcher| found, got, expected = [], [], expected.map { |r| r.tuple } @@ -101,11 +56,14 @@ module Arel describe "Relation" do before :all do - @engine = Testing::Engine.new - @relation = Thing.new(@engine, - :id => Attributes::Integer, - :name => Attributes::String, - :age => Attributes::Integer) + @engine = Testing::Engine.new + @relation = Model.build do |r| + r.engine @engine + + r.attribute :id, Attributes::Integer + r.attribute :name, Attributes::String + r.attribute :age, Attributes::Integer + end end describe "..." do |