From 61916e408d86d19d1659cd8042de6503aecc6c98 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 12 Mar 2010 14:34:13 -0800 Subject: Add a bunch of specs for attribute type casting. --- spec/arel/algebra/integration/basic_spec.rb | 58 ++++------------------------- 1 file changed, 8 insertions(+), 50 deletions(-) (limited to 'spec/arel') 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 -- cgit v1.2.3