mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
basic rename functionality
This commit is contained in:
parent
4366f8658e
commit
346d9c6bde
6 changed files with 37 additions and 8 deletions
|
@ -17,6 +17,7 @@ require 'sql_algebra/relations/projection_relation'
|
|||
require 'sql_algebra/relations/selection_relation'
|
||||
require 'sql_algebra/relations/order_relation'
|
||||
require 'sql_algebra/relations/range_relation'
|
||||
require 'sql_algebra/relations/rename_relation'
|
||||
require 'sql_algebra/relations/join'
|
||||
|
||||
require 'sql_algebra/predicates/predicate'
|
||||
|
|
|
@ -5,6 +5,10 @@ class Attribute
|
|||
@relation, @attribute_name, @aliaz = relation, attribute_name, aliaz
|
||||
end
|
||||
|
||||
def aliazz(aliaz)
|
||||
Attribute.new(relation, attribute_name, aliaz)
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
relation == other.relation and attribute_name == other.attribute_name
|
||||
end
|
||||
|
|
|
@ -32,6 +32,10 @@ class Relation
|
|||
def order(*attributes)
|
||||
OrderRelation.new(self, *attributes)
|
||||
end
|
||||
|
||||
def rename(attribute, aliaz)
|
||||
RenameRelation.new(self, attribute, aliaz)
|
||||
end
|
||||
end
|
||||
include Operations
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@ describe Attribute do
|
|||
@relation2 = TableRelation.new(:bar)
|
||||
end
|
||||
|
||||
describe 'aliaz' do
|
||||
it "manufactures an aliased attributed" do
|
||||
pending
|
||||
end
|
||||
end
|
||||
|
||||
describe '#eql?' do
|
||||
it "obtains if the relation and attribute name are identical" do
|
||||
Attribute.new(@relation1, :attribute_name).should be_eql(Attribute.new(@relation1, :attribute_name))
|
||||
|
|
|
@ -48,6 +48,12 @@ describe Relation do
|
|||
end
|
||||
end
|
||||
|
||||
describe Relation, '#rename' do
|
||||
it "manufactures a rename relation" do
|
||||
@relation1.rename(@attribute1, :foo).should == RenameRelation.new(@relation1, @attribute1, :foo)
|
||||
end
|
||||
end
|
||||
|
||||
describe Relation, '#select' do
|
||||
before do
|
||||
@predicate = EqualityPredicate.new(@attribute1, @attribute2)
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
||||
|
||||
describe TableRelation, '#to_sql' do
|
||||
it "returns a simple SELECT query" do
|
||||
TableRelation.new(:users).to_sql.should == SelectBuilder.new do |s|
|
||||
select do
|
||||
column :users, :name
|
||||
column :users, :id
|
||||
describe TableRelation do
|
||||
describe '#to_sql' do
|
||||
it "returns a simple SELECT query" do
|
||||
TableRelation.new(:users).to_sql.should == SelectBuilder.new do |s|
|
||||
select do
|
||||
column :users, :name
|
||||
column :users, :id
|
||||
end
|
||||
from :users
|
||||
end
|
||||
from :users
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#attributes' do
|
||||
it 'manufactures attributes corresponding to columns in the table' do
|
||||
pending
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue