From a7aacd29460aa137c3b06ee214ff8ffdff8ee365 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Mon, 26 May 2008 21:02:23 -0700 Subject: reorganizing tests --- spec/arel/algebra/unit/predicates/binary_spec.rb | 33 ++++ spec/arel/algebra/unit/predicates/equality_spec.rb | 27 +++ spec/arel/algebra/unit/predicates/in_spec.rb | 10 ++ .../arel/algebra/unit/primitives/attribute_spec.rb | 169 ++++++++++++++++++ .../algebra/unit/primitives/expression_spec.rb | 39 +++++ spec/arel/algebra/unit/primitives/value_spec.rb | 15 ++ spec/arel/algebra/unit/relations/alias_spec.rb | 16 ++ spec/arel/algebra/unit/relations/delete_spec.rb | 9 + spec/arel/algebra/unit/relations/group_spec.rb | 10 ++ spec/arel/algebra/unit/relations/insert_spec.rb | 9 + spec/arel/algebra/unit/relations/join_spec.rb | 26 +++ spec/arel/algebra/unit/relations/order_spec.rb | 11 ++ spec/arel/algebra/unit/relations/project_spec.rb | 34 ++++ spec/arel/algebra/unit/relations/relation_spec.rb | 188 +++++++++++++++++++++ spec/arel/algebra/unit/relations/skip_spec.rb | 10 ++ spec/arel/algebra/unit/relations/table_spec.rb | 39 +++++ spec/arel/algebra/unit/relations/take_spec.rb | 10 ++ spec/arel/algebra/unit/relations/update_spec.rb | 9 + spec/arel/algebra/unit/relations/where_spec.rb | 18 ++ spec/arel/algebra/unit/session/session_spec.rb | 84 +++++++++ 20 files changed, 766 insertions(+) create mode 100644 spec/arel/algebra/unit/predicates/binary_spec.rb create mode 100644 spec/arel/algebra/unit/predicates/equality_spec.rb create mode 100644 spec/arel/algebra/unit/predicates/in_spec.rb create mode 100644 spec/arel/algebra/unit/primitives/attribute_spec.rb create mode 100644 spec/arel/algebra/unit/primitives/expression_spec.rb create mode 100644 spec/arel/algebra/unit/primitives/value_spec.rb create mode 100644 spec/arel/algebra/unit/relations/alias_spec.rb create mode 100644 spec/arel/algebra/unit/relations/delete_spec.rb create mode 100644 spec/arel/algebra/unit/relations/group_spec.rb create mode 100644 spec/arel/algebra/unit/relations/insert_spec.rb create mode 100644 spec/arel/algebra/unit/relations/join_spec.rb create mode 100644 spec/arel/algebra/unit/relations/order_spec.rb create mode 100644 spec/arel/algebra/unit/relations/project_spec.rb create mode 100644 spec/arel/algebra/unit/relations/relation_spec.rb create mode 100644 spec/arel/algebra/unit/relations/skip_spec.rb create mode 100644 spec/arel/algebra/unit/relations/table_spec.rb create mode 100644 spec/arel/algebra/unit/relations/take_spec.rb create mode 100644 spec/arel/algebra/unit/relations/update_spec.rb create mode 100644 spec/arel/algebra/unit/relations/where_spec.rb create mode 100644 spec/arel/algebra/unit/session/session_spec.rb (limited to 'spec/arel/algebra') diff --git a/spec/arel/algebra/unit/predicates/binary_spec.rb b/spec/arel/algebra/unit/predicates/binary_spec.rb new file mode 100644 index 0000000000..9022a543d1 --- /dev/null +++ b/spec/arel/algebra/unit/predicates/binary_spec.rb @@ -0,0 +1,33 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Binary do + before do + @relation = Table.new(:users) + @attribute1 = @relation[:id] + @attribute2 = @relation[:name] + class ConcreteBinary < Binary + end + end + + describe '#bind' do + before do + @another_relation = @relation.alias + end + + describe 'when both operands are attributes' do + it "manufactures an expression with the attributes bound to the relation" do + ConcreteBinary.new(@attribute1, @attribute2).bind(@another_relation). \ + should == ConcreteBinary.new(@another_relation[@attribute1], @another_relation[@attribute2]) + end + end + + describe 'when an operand is a value' do + it "manufactures an expression with unmodified values" do + ConcreteBinary.new(@attribute1, "asdf").bind(@another_relation). \ + should == ConcreteBinary.new(@attribute1.find_correlate_in(@another_relation), "asdf".find_correlate_in(@another_relation)) + end + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/predicates/equality_spec.rb b/spec/arel/algebra/unit/predicates/equality_spec.rb new file mode 100644 index 0000000000..9a56ed5eaf --- /dev/null +++ b/spec/arel/algebra/unit/predicates/equality_spec.rb @@ -0,0 +1,27 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Equality do + before do + @relation1 = Table.new(:users) + @relation2 = Table.new(:photos) + @attribute1 = @relation1[:id] + @attribute2 = @relation2[:user_id] + end + + describe '==' do + it "obtains if attribute1 and attribute2 are identical" do + Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2) + Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1) + end + + it "obtains if the concrete type of the predicates are identical" do + Equality.new(@attribute1, @attribute2).should_not == Binary.new(@attribute1, @attribute2) + end + + it "is commutative on the attributes" do + Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1) + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/predicates/in_spec.rb b/spec/arel/algebra/unit/predicates/in_spec.rb new file mode 100644 index 0000000000..91c154763c --- /dev/null +++ b/spec/arel/algebra/unit/predicates/in_spec.rb @@ -0,0 +1,10 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe In do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb new file mode 100644 index 0000000000..bab9fad3d5 --- /dev/null +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -0,0 +1,169 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Attribute do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + + describe Attribute::Transformations do + describe '#as' do + it "manufactures an aliased attributed" do + @attribute.as(:alias).should == Attribute.new(@relation, @attribute.name, :alias => :alias, :ancestor => @attribute) + end + end + + describe '#bind' do + it "manufactures an attribute with the relation bound and self as an ancestor" do + derived_relation = @relation.where(@relation[:id].eq(1)) + @attribute.bind(derived_relation).should == Attribute.new(derived_relation, @attribute.name, :ancestor => @attribute) + end + + it "returns self if the substituting to the same relation" do + @attribute.bind(@relation).should == @attribute + end + end + + describe '#to_attribute' do + it "returns self" do + @attribute.to_attribute.should == @attribute + end + end + end + + describe '#column' do + it "returns the corresponding column in the relation" do + @attribute.column.should == @relation.column_for(@attribute) + end + end + + describe '#engine' do + it "delegates to its relation" do + Attribute.new(@relation, :id).engine.should == @relation.engine + end + end + + describe Attribute::Congruence do + describe '/' do + before do + @aliased_relation = @relation.alias + @doubly_aliased_relation = @aliased_relation.alias + end + + describe 'when dividing two unrelated attributes' do + it "returns 0.0" do + (@relation[:id] / @relation[:name]).should == 0.0 + end + end + + describe 'when dividing two matching attributes' do + it 'returns a the highest score for the most similar attributes' do + (@aliased_relation[:id] / @relation[:id]) \ + .should == (@aliased_relation[:id] / @relation[:id]) + (@aliased_relation[:id] / @relation[:id]) \ + .should < (@aliased_relation[:id] / @aliased_relation[:id]) + end + end + end + end + + describe Attribute::Predications do + before do + @attribute = Attribute.new(@relation, :name) + end + + describe '#eq' do + it "manufactures an equality predicate" do + @attribute.eq('name').should == Equality.new(@attribute, 'name') + end + end + + describe '#lt' do + it "manufactures a less-than predicate" do + @attribute.lt(10).should == LessThan.new(@attribute, 10) + end + end + + describe '#lteq' do + it "manufactures a less-than or equal-to predicate" do + @attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10) + end + end + + describe '#gt' do + it "manufactures a greater-than predicate" do + @attribute.gt(10).should == GreaterThan.new(@attribute, 10) + end + end + + describe '#gteq' do + it "manufactures a greater-than or equal-to predicate" do + @attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10) + end + end + + describe '#matches' do + it "manufactures a match predicate" do + @attribute.matches(/.*/).should == Match.new(@attribute, /.*/) + end + end + + describe '#in' do + it "manufactures an in predicate" do + @attribute.in(1..30).should == In.new(@attribute, (1..30)) + end + end + end + + describe Attribute::Expressions do + before do + @attribute = Attribute.new(@relation, :name) + end + + describe '#count' do + it "manufactures a count Expression" do + @attribute.count.should == Count.new(@attribute) + end + end + + describe '#sum' do + it "manufactures a sum Expression" do + @attribute.sum.should == Sum.new(@attribute) + end + end + + describe '#maximum' do + it "manufactures a maximum Expression" do + @attribute.maximum.should == Maximum.new(@attribute) + end + end + + describe '#minimum' do + it "manufactures a minimum Expression" do + @attribute.minimum.should == Minimum.new(@attribute) + end + end + + describe '#average' do + it "manufactures an average Expression" do + @attribute.average.should == Average.new(@attribute) + end + end + end + + describe Attribute::Orderings do + describe '#asc' do + it 'manufactures an ascending ordering' do + pending + end + end + + describe '#desc' do + it 'manufactures a descending ordering' do + pending + end + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/primitives/expression_spec.rb b/spec/arel/algebra/unit/primitives/expression_spec.rb new file mode 100644 index 0000000000..10bdb56302 --- /dev/null +++ b/spec/arel/algebra/unit/primitives/expression_spec.rb @@ -0,0 +1,39 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Expression do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + + describe Expression::Transformations do + before do + @expression = Count.new(@attribute) + end + + describe '#bind' do + it "manufactures an attribute with a rebound relation and self as the ancestor" do + derived_relation = @relation.where(@relation[:id].eq(1)) + @expression.bind(derived_relation).should == Count.new(@attribute.bind(derived_relation), nil, @expression) + end + + it "returns self if the substituting to the same relation" do + @expression.bind(@relation).should == @expression + end + end + + describe '#as' do + it "manufactures an aliased expression" do + @expression.as(:alias).should == Expression.new(@attribute, :alias, @expression) + end + end + + describe '#to_attribute' do + it "manufactures an attribute with the expression as an ancestor" do + @expression.to_attribute.should == Attribute.new(@expression.relation, @expression.alias, :ancestor => @expression) + end + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/primitives/value_spec.rb b/spec/arel/algebra/unit/primitives/value_spec.rb new file mode 100644 index 0000000000..8774ca78c5 --- /dev/null +++ b/spec/arel/algebra/unit/primitives/value_spec.rb @@ -0,0 +1,15 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Value do + before do + @relation = Table.new(:users) + end + + describe '#bind' do + it "manufactures a new value whose relation is the provided relation" do + Value.new(1, @relation).bind(another_relation = Table.new(:photos)).should == Value.new(1, another_relation) + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/alias_spec.rb b/spec/arel/algebra/unit/relations/alias_spec.rb new file mode 100644 index 0000000000..c87a0ca2dd --- /dev/null +++ b/spec/arel/algebra/unit/relations/alias_spec.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Alias do + before do + @relation = Table.new(:users) + end + + describe '==' do + it "obtains if the objects are the same" do + Alias.new(@relation).should_not == Alias.new(@relation) + (aliaz = Alias.new(@relation)).should == aliaz + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/delete_spec.rb b/spec/arel/algebra/unit/relations/delete_spec.rb new file mode 100644 index 0000000000..075e59e724 --- /dev/null +++ b/spec/arel/algebra/unit/relations/delete_spec.rb @@ -0,0 +1,9 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Deletion do + before do + @relation = Table.new(:users) + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/group_spec.rb b/spec/arel/algebra/unit/relations/group_spec.rb new file mode 100644 index 0000000000..050de2993d --- /dev/null +++ b/spec/arel/algebra/unit/relations/group_spec.rb @@ -0,0 +1,10 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Group do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/insert_spec.rb b/spec/arel/algebra/unit/relations/insert_spec.rb new file mode 100644 index 0000000000..184cd2a926 --- /dev/null +++ b/spec/arel/algebra/unit/relations/insert_spec.rb @@ -0,0 +1,9 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Insert do + before do + @relation = Table.new(:users) + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/join_spec.rb b/spec/arel/algebra/unit/relations/join_spec.rb new file mode 100644 index 0000000000..5b512cc7f6 --- /dev/null +++ b/spec/arel/algebra/unit/relations/join_spec.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Join do + before do + @relation1 = Table.new(:users) + @relation2 = Table.new(:photos) + @predicate = @relation1[:id].eq(@relation2[:user_id]) + end + + describe 'hashing' do + it 'implements hash equality' do + InnerJoin.new(@relation1, @relation2, @predicate) \ + .should hash_the_same_as(InnerJoin.new(@relation1, @relation2, @predicate)) + end + end + + describe '#attributes' do + it 'combines the attributes of the two relations' do + join = InnerJoin.new(@relation1, @relation2, @predicate) + join.attributes.should == + (@relation1.attributes + @relation2.attributes).collect { |a| a.bind(join) } + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/order_spec.rb b/spec/arel/algebra/unit/relations/order_spec.rb new file mode 100644 index 0000000000..0e1b1a0e54 --- /dev/null +++ b/spec/arel/algebra/unit/relations/order_spec.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Order do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + end +end + \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/project_spec.rb b/spec/arel/algebra/unit/relations/project_spec.rb new file mode 100644 index 0000000000..b71acf5e91 --- /dev/null +++ b/spec/arel/algebra/unit/relations/project_spec.rb @@ -0,0 +1,34 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Project do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + + describe '#attributes' do + before do + @projection = Project.new(@relation, @attribute) + end + + it "manufactures attributes associated with the projection relation" do + @projection.attributes.should == [@attribute].collect { |a| a.bind(@projection) } + end + end + + describe '#externalizable?' do + describe 'when the projections are attributes' do + it 'returns false' do + Project.new(@relation, @attribute).should_not be_externalizable + end + end + + describe 'when the projections include an aggregation' do + it "obtains" do + Project.new(@relation, @attribute.sum).should be_externalizable + end + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb new file mode 100644 index 0000000000..3286f373f5 --- /dev/null +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -0,0 +1,188 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Relation do + before do + @relation = Table.new(:users) + @attribute1 = @relation[:id] + @attribute2 = @relation[:name] + end + + describe '[]' do + describe 'when given an', Attribute do + it "return the attribute congruent to the provided attribute" do + @relation[@attribute1].should == @attribute1 + end + end + + describe 'when given a', Symbol, String do + it "returns the attribute with the same name, if it exists" do + @relation[:id].should == @attribute1 + @relation['id'].should == @attribute1 + @relation[:does_not_exist].should be_nil + end + end + end + + describe Relation::Operable do + describe 'joins' do + before do + @predicate = @relation[:id].eq(@relation[:id]) + end + + describe '#join' do + describe 'when given a relation' do + it "manufactures an inner join operation between those two relations" do + @relation.join(@relation).on(@predicate). \ + should == InnerJoin.new(@relation, @relation, @predicate) + end + end + + describe "when given a string" do + it "manufactures a join operation with the string passed through" do + @relation.join(arbitrary_string = "ASDF").should == Join.new(arbitrary_string, @relation) + end + end + + describe "when given something blank" do + it "returns self" do + @relation.join.should == @relation + end + end + end + + describe '#outer_join' do + it "manufactures a left outer join operation between those two relations" do + @relation.outer_join(@relation).on(@predicate). \ + should == OuterJoin.new(@relation, @relation, @predicate) + end + end + end + + describe '#project' do + it "manufactures a projection relation" do + @relation.project(@attribute1, @attribute2). \ + should == Project.new(@relation, @attribute1, @attribute2) + end + + describe "when given blank attributes" do + it "returns self" do + @relation.project.should == @relation + end + end + end + + describe '#alias' do + it "manufactures an alias relation" do + @relation.alias.relation.should == Alias.new(@relation).relation + end + end + + describe '#where' do + before do + @predicate = Equality.new(@attribute1, @attribute2) + end + + it "manufactures a where relation" do + @relation.where(@predicate).should == Where.new(@relation, @predicate) + end + + it "accepts arbitrary strings" do + @relation.where("arbitrary").should == Where.new(@relation, "arbitrary") + end + + describe 'when given a blank predicate' do + it 'returns self' do + @relation.where.should == @relation + end + end + end + + describe '#order' do + it "manufactures an order relation" do + @relation.order(@attribute1, @attribute2).should == Order.new(@relation, @attribute1, @attribute2) + end + + describe 'when given a blank ordering' do + it 'returns self' do + @relation.order.should == @relation + end + end + end + + describe '#take' do + it "manufactures a take relation" do + @relation.take(5).should == Take.new(@relation, 5) + end + + describe 'when given a blank number of items' do + it 'returns self' do + @relation.take.should == @relation + end + end + end + + describe '#skip' do + it "manufactures a skip relation" do + @relation.skip(4).should == Skip.new(@relation, 4) + end + + describe 'when given a blank number of items' do + it 'returns self' do + @relation.skip.should == @relation + end + end + end + + describe '#group' do + it 'manufactures a group relation' do + @relation.group(@attribute1, @attribute2).should == Group.new(@relation, @attribute1, @attribute2) + end + + describe 'when given blank groupings' do + it 'returns self' do + @relation.group.should == @relation + end + end + end + + describe Relation::Operable::Writable do + describe '#delete' do + it 'manufactures a deletion relation' do + Session.start do + mock(Session.new).delete(Deletion.new(@relation)) + @relation.delete + end + end + end + + describe '#insert' do + it 'manufactures an insertion relation' do + Session.start do + record = {@relation[:name] => 'carl'} + mock(Session.new).create(Insert.new(@relation, record)) + @relation.insert(record) + end + end + end + + describe '#update' do + it 'manufactures an update relation' do + Session.start do + assignments = {@relation[:name] => Value.new('bob', @relation)} + mock(Session.new).update(Update.new(@relation, assignments)) + @relation.update(assignments) + end + end + end + end + end + + describe Relation::Enumerable do + it "implements enumerable" do + @relation.collect.should == @relation.session.read(@relation) + @relation.first.should == @relation.session.read(@relation).first + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/skip_spec.rb b/spec/arel/algebra/unit/relations/skip_spec.rb new file mode 100644 index 0000000000..ff57e03d1c --- /dev/null +++ b/spec/arel/algebra/unit/relations/skip_spec.rb @@ -0,0 +1,10 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Skip do + before do + @relation = Table.new(:users) + @skipped = 4 + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/table_spec.rb b/spec/arel/algebra/unit/relations/table_spec.rb new file mode 100644 index 0000000000..4821d92299 --- /dev/null +++ b/spec/arel/algebra/unit/relations/table_spec.rb @@ -0,0 +1,39 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Table do + before do + @relation = Table.new(:users) + end + + describe '[]' do + describe 'when given a', Symbol do + it "manufactures an attribute if the symbol names an attribute within the relation" do + @relation[:id].should == Attribute.new(@relation, :id) + @relation[:does_not_exist].should be_nil + end + end + + describe 'when given an', Attribute do + it "returns the attribute if the attribute is within the relation" do + @relation[@relation[:id]].should == @relation[:id] + end + + it "returns nil if the attribtue is not within the relation" do + another_relation = Table.new(:photos) + @relation[another_relation[:id]].should be_nil + end + end + + describe 'when given an', Expression do + before do + @expression = @relation[:id].count + end + + it "returns the Expression if the Expression is within the relation" do + @relation[@expression].should be_nil + end + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/take_spec.rb b/spec/arel/algebra/unit/relations/take_spec.rb new file mode 100644 index 0000000000..6f8b4fd36e --- /dev/null +++ b/spec/arel/algebra/unit/relations/take_spec.rb @@ -0,0 +1,10 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Take do + before do + @relation = Table.new(:users) + @taken = 4 + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/update_spec.rb b/spec/arel/algebra/unit/relations/update_spec.rb new file mode 100644 index 0000000000..c27afb48b2 --- /dev/null +++ b/spec/arel/algebra/unit/relations/update_spec.rb @@ -0,0 +1,9 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Update do + before do + @relation = Table.new(:users) + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/relations/where_spec.rb b/spec/arel/algebra/unit/relations/where_spec.rb new file mode 100644 index 0000000000..3f37b53138 --- /dev/null +++ b/spec/arel/algebra/unit/relations/where_spec.rb @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Where do + before do + @relation = Table.new(:users) + @predicate = @relation[:id].eq(1) + end + + describe '#initialize' do + it "manufactures nested where relations if multiple predicates are provided" do + another_predicate = @relation[:name].lt(2) + Where.new(@relation, @predicate, another_predicate). \ + should == Where.new(Where.new(@relation, another_predicate), @predicate) + end + end + end +end \ No newline at end of file diff --git a/spec/arel/algebra/unit/session/session_spec.rb b/spec/arel/algebra/unit/session/session_spec.rb new file mode 100644 index 0000000000..e17b5d638a --- /dev/null +++ b/spec/arel/algebra/unit/session/session_spec.rb @@ -0,0 +1,84 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Session do + before do + @relation = Table.new(:users) + @session = Session.new + end + + describe '::start' do + describe '::instance' do + it "it is a singleton within the started session" do + Session.start do + Session.new.should == Session.new + end + end + + it "is a singleton across nested sessions" do + Session.start do + outside = Session.new + Session.start do + Session.new.should == outside + end + end + end + + it "manufactures new sessions outside of the started session" do + Session.new.should_not == Session.new + end + end + end + + describe Session::CRUD do + before do + @insert = Insert.new(@relation, @relation[:name] => 'nick') + @update = Update.new(@relation, @relation[:name] => 'nick') + @delete = Deletion.new(@relation) + @read = @relation + end + + describe '#create' do + it "executes an insertion on the connection" do + mock(@insert).call + @session.create(@insert) + end + end + + describe '#read' do + it "executes an selection on the connection" do + mock(@read).call + @session.read(@read) + end + + it "is memoized" do + mock(@read).call.once + @session.read(@read) + @session.read(@read) + end + end + + describe '#update' do + it "executes an update on the connection" do + mock(@update).call + @session.update(@update) + end + end + + describe '#delete' do + it "executes a delete on the connection" do + mock(@delete).call + @session.delete(@delete) + end + end + end + + describe 'Transactions' do + describe '#begin' do + end + + describe '#end' do + end + end + end +end \ No newline at end of file -- cgit v1.2.3 From 20b28b441b651d0404d64049253898c061a039be Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 27 May 2008 14:37:11 -0700 Subject: using in memory relations as results from sql relation Conflicts: lib/arel/algebra/primitives/expression.rb lib/arel/algebra/relations/relation.rb --- spec/arel/algebra/unit/primitives/attribute_spec.rb | 12 ++++++++++-- spec/arel/algebra/unit/primitives/expression_spec.rb | 2 +- spec/arel/algebra/unit/relations/relation_spec.rb | 10 +++++----- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'spec/arel/algebra') diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index bab9fad3d5..dcac5abf65 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -26,8 +26,16 @@ module Arel end describe '#to_attribute' do - it "returns self" do - @attribute.to_attribute.should == @attribute + describe 'when the given relation is the same as the attributes relation' do + it "returns self" do + @attribute.to_attribute(@relation).should == @attribute + end + end + + describe 'when the given relation differs from the attributes relation' do + it 'binds to the new relation' do + @attribute.to_attribute(new_relation = @relation.alias).should == @attribute.bind(new_relation) + end end end end diff --git a/spec/arel/algebra/unit/primitives/expression_spec.rb b/spec/arel/algebra/unit/primitives/expression_spec.rb index 10bdb56302..dfd2100048 100644 --- a/spec/arel/algebra/unit/primitives/expression_spec.rb +++ b/spec/arel/algebra/unit/primitives/expression_spec.rb @@ -31,7 +31,7 @@ module Arel describe '#to_attribute' do it "manufactures an attribute with the expression as an ancestor" do - @expression.to_attribute.should == Attribute.new(@expression.relation, @expression.alias, :ancestor => @expression) + @expression.to_attribute(@relation).should == Attribute.new(@relation, @expression.alias, :ancestor => @expression) end end end diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb index 3286f373f5..9707f2887c 100644 --- a/spec/arel/algebra/unit/relations/relation_spec.rb +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -40,7 +40,7 @@ module Arel describe "when given a string" do it "manufactures a join operation with the string passed through" do - @relation.join(arbitrary_string = "ASDF").should == Join.new(arbitrary_string, @relation) + @relation.join(arbitrary_string = "ASDF").should == StringJoin.new(@relation, arbitrary_string) end end @@ -159,7 +159,7 @@ module Arel describe '#insert' do it 'manufactures an insertion relation' do Session.start do - record = {@relation[:name] => 'carl'} + record = { @relation[:name] => 'carl' } mock(Session.new).create(Insert.new(@relation, record)) @relation.insert(record) end @@ -169,7 +169,7 @@ module Arel describe '#update' do it 'manufactures an update relation' do Session.start do - assignments = {@relation[:name] => Value.new('bob', @relation)} + assignments = { @relation[:name] => Value.new('bob', @relation) } mock(Session.new).update(Update.new(@relation, assignments)) @relation.update(assignments) end @@ -180,8 +180,8 @@ module Arel describe Relation::Enumerable do it "implements enumerable" do - @relation.collect.should == @relation.session.read(@relation) - @relation.first.should == @relation.session.read(@relation).first + @relation.collect.should == @relation.session.read(@relation).collect + @relation.first.should == @relation.session.read(@relation).first end end end -- cgit v1.2.3 From dc7b51883b1cc8ad7e525b7315fb575ae77a5b3d Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 17 May 2009 16:20:40 -0400 Subject: Whitespace --- spec/arel/algebra/unit/predicates/binary_spec.rb | 8 +-- spec/arel/algebra/unit/predicates/equality_spec.rb | 10 ++-- spec/arel/algebra/unit/predicates/in_spec.rb | 2 +- .../arel/algebra/unit/primitives/attribute_spec.rb | 58 +++++++++++----------- .../algebra/unit/primitives/expression_spec.rb | 12 ++--- spec/arel/algebra/unit/primitives/value_spec.rb | 2 +- spec/arel/algebra/unit/relations/alias_spec.rb | 4 +- spec/arel/algebra/unit/relations/delete_spec.rb | 2 +- spec/arel/algebra/unit/relations/group_spec.rb | 2 +- spec/arel/algebra/unit/relations/insert_spec.rb | 2 +- spec/arel/algebra/unit/relations/join_spec.rb | 6 +-- spec/arel/algebra/unit/relations/order_spec.rb | 2 +- spec/arel/algebra/unit/relations/project_spec.rb | 10 ++-- spec/arel/algebra/unit/relations/relation_spec.rb | 36 +++++++------- spec/arel/algebra/unit/relations/skip_spec.rb | 2 +- spec/arel/algebra/unit/relations/table_spec.rb | 10 ++-- spec/arel/algebra/unit/relations/take_spec.rb | 2 +- spec/arel/algebra/unit/relations/update_spec.rb | 2 +- spec/arel/algebra/unit/relations/where_spec.rb | 6 +-- spec/arel/algebra/unit/session/session_spec.rb | 22 ++++---- 20 files changed, 100 insertions(+), 100 deletions(-) (limited to 'spec/arel/algebra') diff --git a/spec/arel/algebra/unit/predicates/binary_spec.rb b/spec/arel/algebra/unit/predicates/binary_spec.rb index 9022a543d1..14fd7ab21b 100644 --- a/spec/arel/algebra/unit/predicates/binary_spec.rb +++ b/spec/arel/algebra/unit/predicates/binary_spec.rb @@ -9,19 +9,19 @@ module Arel class ConcreteBinary < Binary end end - + describe '#bind' do before do @another_relation = @relation.alias end - + describe 'when both operands are attributes' do it "manufactures an expression with the attributes bound to the relation" do ConcreteBinary.new(@attribute1, @attribute2).bind(@another_relation). \ should == ConcreteBinary.new(@another_relation[@attribute1], @another_relation[@attribute2]) end end - + describe 'when an operand is a value' do it "manufactures an expression with unmodified values" do ConcreteBinary.new(@attribute1, "asdf").bind(@another_relation). \ @@ -30,4 +30,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/predicates/equality_spec.rb b/spec/arel/algebra/unit/predicates/equality_spec.rb index 9a56ed5eaf..af91f8b51b 100644 --- a/spec/arel/algebra/unit/predicates/equality_spec.rb +++ b/spec/arel/algebra/unit/predicates/equality_spec.rb @@ -8,20 +8,20 @@ module Arel @attribute1 = @relation1[:id] @attribute2 = @relation2[:user_id] end - - describe '==' do + + describe '==' do it "obtains if attribute1 and attribute2 are identical" do Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2) Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1) end - + it "obtains if the concrete type of the predicates are identical" do Equality.new(@attribute1, @attribute2).should_not == Binary.new(@attribute1, @attribute2) end - + it "is commutative on the attributes" do Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute2, @attribute1) end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/predicates/in_spec.rb b/spec/arel/algebra/unit/predicates/in_spec.rb index 91c154763c..a8a15ce4e3 100644 --- a/spec/arel/algebra/unit/predicates/in_spec.rb +++ b/spec/arel/algebra/unit/predicates/in_spec.rb @@ -7,4 +7,4 @@ module Arel @attribute = @relation[:id] end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index dcac5abf65..89e338e377 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -6,32 +6,32 @@ module Arel @relation = Table.new(:users) @attribute = @relation[:id] end - + describe Attribute::Transformations do describe '#as' do it "manufactures an aliased attributed" do @attribute.as(:alias).should == Attribute.new(@relation, @attribute.name, :alias => :alias, :ancestor => @attribute) end end - + describe '#bind' do it "manufactures an attribute with the relation bound and self as an ancestor" do derived_relation = @relation.where(@relation[:id].eq(1)) @attribute.bind(derived_relation).should == Attribute.new(derived_relation, @attribute.name, :ancestor => @attribute) end - + it "returns self if the substituting to the same relation" do @attribute.bind(@relation).should == @attribute end end - + describe '#to_attribute' do describe 'when the given relation is the same as the attributes relation' do it "returns self" do @attribute.to_attribute(@relation).should == @attribute end end - + describe 'when the given relation differs from the attributes relation' do it 'binds to the new relation' do @attribute.to_attribute(new_relation = @relation.alias).should == @attribute.bind(new_relation) @@ -39,32 +39,32 @@ module Arel end end end - + describe '#column' do it "returns the corresponding column in the relation" do @attribute.column.should == @relation.column_for(@attribute) end end - + describe '#engine' do it "delegates to its relation" do Attribute.new(@relation, :id).engine.should == @relation.engine end end - + describe Attribute::Congruence do describe '/' do before do @aliased_relation = @relation.alias @doubly_aliased_relation = @aliased_relation.alias end - + describe 'when dividing two unrelated attributes' do it "returns 0.0" do (@relation[:id] / @relation[:name]).should == 0.0 end end - + describe 'when dividing two matching attributes' do it 'returns a the highest score for the most similar attributes' do (@aliased_relation[:id] / @relation[:id]) \ @@ -75,98 +75,98 @@ module Arel end end end - + describe Attribute::Predications do before do @attribute = Attribute.new(@relation, :name) end - + describe '#eq' do it "manufactures an equality predicate" do @attribute.eq('name').should == Equality.new(@attribute, 'name') end end - + describe '#lt' do it "manufactures a less-than predicate" do @attribute.lt(10).should == LessThan.new(@attribute, 10) end end - + describe '#lteq' do it "manufactures a less-than or equal-to predicate" do @attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10) end end - + describe '#gt' do it "manufactures a greater-than predicate" do @attribute.gt(10).should == GreaterThan.new(@attribute, 10) end end - + describe '#gteq' do it "manufactures a greater-than or equal-to predicate" do @attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10) end end - + describe '#matches' do it "manufactures a match predicate" do @attribute.matches(/.*/).should == Match.new(@attribute, /.*/) end end - + describe '#in' do it "manufactures an in predicate" do @attribute.in(1..30).should == In.new(@attribute, (1..30)) end end end - + describe Attribute::Expressions do before do - @attribute = Attribute.new(@relation, :name) + @attribute = Attribute.new(@relation, :name) end - + describe '#count' do it "manufactures a count Expression" do @attribute.count.should == Count.new(@attribute) end end - + describe '#sum' do it "manufactures a sum Expression" do @attribute.sum.should == Sum.new(@attribute) end end - + describe '#maximum' do it "manufactures a maximum Expression" do @attribute.maximum.should == Maximum.new(@attribute) end end - + describe '#minimum' do it "manufactures a minimum Expression" do @attribute.minimum.should == Minimum.new(@attribute) end end - + describe '#average' do it "manufactures an average Expression" do @attribute.average.should == Average.new(@attribute) end - end + end end - + describe Attribute::Orderings do describe '#asc' do it 'manufactures an ascending ordering' do pending end end - + describe '#desc' do it 'manufactures a descending ordering' do pending @@ -174,4 +174,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/primitives/expression_spec.rb b/spec/arel/algebra/unit/primitives/expression_spec.rb index dfd2100048..82d12d53f9 100644 --- a/spec/arel/algebra/unit/primitives/expression_spec.rb +++ b/spec/arel/algebra/unit/primitives/expression_spec.rb @@ -6,29 +6,29 @@ module Arel @relation = Table.new(:users) @attribute = @relation[:id] end - + describe Expression::Transformations do before do @expression = Count.new(@attribute) end - + describe '#bind' do it "manufactures an attribute with a rebound relation and self as the ancestor" do derived_relation = @relation.where(@relation[:id].eq(1)) @expression.bind(derived_relation).should == Count.new(@attribute.bind(derived_relation), nil, @expression) end - + it "returns self if the substituting to the same relation" do @expression.bind(@relation).should == @expression end end - + describe '#as' do it "manufactures an aliased expression" do @expression.as(:alias).should == Expression.new(@attribute, :alias, @expression) end end - + describe '#to_attribute' do it "manufactures an attribute with the expression as an ancestor" do @expression.to_attribute(@relation).should == Attribute.new(@relation, @expression.alias, :ancestor => @expression) @@ -36,4 +36,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/primitives/value_spec.rb b/spec/arel/algebra/unit/primitives/value_spec.rb index 8774ca78c5..45208e6c5d 100644 --- a/spec/arel/algebra/unit/primitives/value_spec.rb +++ b/spec/arel/algebra/unit/primitives/value_spec.rb @@ -12,4 +12,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/alias_spec.rb b/spec/arel/algebra/unit/relations/alias_spec.rb index c87a0ca2dd..a5d716a638 100644 --- a/spec/arel/algebra/unit/relations/alias_spec.rb +++ b/spec/arel/algebra/unit/relations/alias_spec.rb @@ -5,7 +5,7 @@ module Arel before do @relation = Table.new(:users) end - + describe '==' do it "obtains if the objects are the same" do Alias.new(@relation).should_not == Alias.new(@relation) @@ -13,4 +13,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/delete_spec.rb b/spec/arel/algebra/unit/relations/delete_spec.rb index 075e59e724..7578e12a3e 100644 --- a/spec/arel/algebra/unit/relations/delete_spec.rb +++ b/spec/arel/algebra/unit/relations/delete_spec.rb @@ -6,4 +6,4 @@ module Arel @relation = Table.new(:users) end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/group_spec.rb b/spec/arel/algebra/unit/relations/group_spec.rb index 050de2993d..58f9252356 100644 --- a/spec/arel/algebra/unit/relations/group_spec.rb +++ b/spec/arel/algebra/unit/relations/group_spec.rb @@ -7,4 +7,4 @@ module Arel @attribute = @relation[:id] end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/insert_spec.rb b/spec/arel/algebra/unit/relations/insert_spec.rb index 184cd2a926..feb1a5eae4 100644 --- a/spec/arel/algebra/unit/relations/insert_spec.rb +++ b/spec/arel/algebra/unit/relations/insert_spec.rb @@ -6,4 +6,4 @@ module Arel @relation = Table.new(:users) end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/join_spec.rb b/spec/arel/algebra/unit/relations/join_spec.rb index 5b512cc7f6..f5a8bd32aa 100644 --- a/spec/arel/algebra/unit/relations/join_spec.rb +++ b/spec/arel/algebra/unit/relations/join_spec.rb @@ -7,14 +7,14 @@ module Arel @relation2 = Table.new(:photos) @predicate = @relation1[:id].eq(@relation2[:user_id]) end - + describe 'hashing' do it 'implements hash equality' do InnerJoin.new(@relation1, @relation2, @predicate) \ .should hash_the_same_as(InnerJoin.new(@relation1, @relation2, @predicate)) end end - + describe '#attributes' do it 'combines the attributes of the two relations' do join = InnerJoin.new(@relation1, @relation2, @predicate) @@ -23,4 +23,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/order_spec.rb b/spec/arel/algebra/unit/relations/order_spec.rb index 0e1b1a0e54..4f163894c8 100644 --- a/spec/arel/algebra/unit/relations/order_spec.rb +++ b/spec/arel/algebra/unit/relations/order_spec.rb @@ -8,4 +8,4 @@ module Arel end end end - \ No newline at end of file + diff --git a/spec/arel/algebra/unit/relations/project_spec.rb b/spec/arel/algebra/unit/relations/project_spec.rb index b71acf5e91..9f4358ea54 100644 --- a/spec/arel/algebra/unit/relations/project_spec.rb +++ b/spec/arel/algebra/unit/relations/project_spec.rb @@ -6,24 +6,24 @@ module Arel @relation = Table.new(:users) @attribute = @relation[:id] end - + describe '#attributes' do before do @projection = Project.new(@relation, @attribute) end - + it "manufactures attributes associated with the projection relation" do @projection.attributes.should == [@attribute].collect { |a| a.bind(@projection) } end end - + describe '#externalizable?' do describe 'when the projections are attributes' do it 'returns false' do Project.new(@relation, @attribute).should_not be_externalizable end end - + describe 'when the projections include an aggregation' do it "obtains" do Project.new(@relation, @attribute.sum).should be_externalizable @@ -31,4 +31,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb index 9707f2887c..adf82847ac 100644 --- a/spec/arel/algebra/unit/relations/relation_spec.rb +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -7,14 +7,14 @@ module Arel @attribute1 = @relation[:id] @attribute2 = @relation[:name] end - + describe '[]' do describe 'when given an', Attribute do it "return the attribute congruent to the provided attribute" do @relation[@attribute1].should == @attribute1 end end - + describe 'when given a', Symbol, String do it "returns the attribute with the same name, if it exists" do @relation[:id].should == @attribute1 @@ -23,13 +23,13 @@ module Arel end end end - + describe Relation::Operable do describe 'joins' do before do @predicate = @relation[:id].eq(@relation[:id]) end - + describe '#join' do describe 'when given a relation' do it "manufactures an inner join operation between those two relations" do @@ -37,13 +37,13 @@ module Arel should == InnerJoin.new(@relation, @relation, @predicate) end end - + describe "when given a string" do it "manufactures a join operation with the string passed through" do - @relation.join(arbitrary_string = "ASDF").should == StringJoin.new(@relation, arbitrary_string) + @relation.join(arbitrary_string = "ASDF").should == StringJoin.new(@relation, arbitrary_string) end end - + describe "when given something blank" do it "returns self" do @relation.join.should == @relation @@ -64,7 +64,7 @@ module Arel @relation.project(@attribute1, @attribute2). \ should == Project.new(@relation, @attribute1, @attribute2) end - + describe "when given blank attributes" do it "returns self" do @relation.project.should == @relation @@ -97,36 +97,36 @@ module Arel end end end - + describe '#order' do it "manufactures an order relation" do @relation.order(@attribute1, @attribute2).should == Order.new(@relation, @attribute1, @attribute2) end - + describe 'when given a blank ordering' do it 'returns self' do @relation.order.should == @relation end end end - + describe '#take' do it "manufactures a take relation" do @relation.take(5).should == Take.new(@relation, 5) end - + describe 'when given a blank number of items' do it 'returns self' do @relation.take.should == @relation end end end - + describe '#skip' do it "manufactures a skip relation" do @relation.skip(4).should == Skip.new(@relation, 4) end - + describe 'when given a blank number of items' do it 'returns self' do @relation.skip.should == @relation @@ -138,14 +138,14 @@ module Arel it 'manufactures a group relation' do @relation.group(@attribute1, @attribute2).should == Group.new(@relation, @attribute1, @attribute2) end - + describe 'when given blank groupings' do it 'returns self' do @relation.group.should == @relation end end end - + describe Relation::Operable::Writable do describe '#delete' do it 'manufactures a deletion relation' do @@ -177,7 +177,7 @@ module Arel end end end - + describe Relation::Enumerable do it "implements enumerable" do @relation.collect.should == @relation.session.read(@relation).collect @@ -185,4 +185,4 @@ module Arel end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/skip_spec.rb b/spec/arel/algebra/unit/relations/skip_spec.rb index ff57e03d1c..a41913436e 100644 --- a/spec/arel/algebra/unit/relations/skip_spec.rb +++ b/spec/arel/algebra/unit/relations/skip_spec.rb @@ -7,4 +7,4 @@ module Arel @skipped = 4 end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/table_spec.rb b/spec/arel/algebra/unit/relations/table_spec.rb index 4821d92299..dfe457043c 100644 --- a/spec/arel/algebra/unit/relations/table_spec.rb +++ b/spec/arel/algebra/unit/relations/table_spec.rb @@ -5,7 +5,7 @@ module Arel before do @relation = Table.new(:users) end - + describe '[]' do describe 'when given a', Symbol do it "manufactures an attribute if the symbol names an attribute within the relation" do @@ -18,22 +18,22 @@ module Arel it "returns the attribute if the attribute is within the relation" do @relation[@relation[:id]].should == @relation[:id] end - + it "returns nil if the attribtue is not within the relation" do another_relation = Table.new(:photos) @relation[another_relation[:id]].should be_nil end end - + describe 'when given an', Expression do before do @expression = @relation[:id].count end - + it "returns the Expression if the Expression is within the relation" do @relation[@expression].should be_nil end end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/take_spec.rb b/spec/arel/algebra/unit/relations/take_spec.rb index 6f8b4fd36e..2bc17db5a1 100644 --- a/spec/arel/algebra/unit/relations/take_spec.rb +++ b/spec/arel/algebra/unit/relations/take_spec.rb @@ -7,4 +7,4 @@ module Arel @taken = 4 end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/update_spec.rb b/spec/arel/algebra/unit/relations/update_spec.rb index c27afb48b2..e9642ffc99 100644 --- a/spec/arel/algebra/unit/relations/update_spec.rb +++ b/spec/arel/algebra/unit/relations/update_spec.rb @@ -6,4 +6,4 @@ module Arel @relation = Table.new(:users) end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/relations/where_spec.rb b/spec/arel/algebra/unit/relations/where_spec.rb index 3f37b53138..6c3074a3a5 100644 --- a/spec/arel/algebra/unit/relations/where_spec.rb +++ b/spec/arel/algebra/unit/relations/where_spec.rb @@ -6,13 +6,13 @@ module Arel @relation = Table.new(:users) @predicate = @relation[:id].eq(1) end - + describe '#initialize' do it "manufactures nested where relations if multiple predicates are provided" do - another_predicate = @relation[:name].lt(2) + another_predicate = @relation[:name].lt(2) Where.new(@relation, @predicate, another_predicate). \ should == Where.new(Where.new(@relation, another_predicate), @predicate) end end end -end \ No newline at end of file +end diff --git a/spec/arel/algebra/unit/session/session_spec.rb b/spec/arel/algebra/unit/session/session_spec.rb index e17b5d638a..ca0a43f278 100644 --- a/spec/arel/algebra/unit/session/session_spec.rb +++ b/spec/arel/algebra/unit/session/session_spec.rb @@ -6,7 +6,7 @@ module Arel @relation = Table.new(:users) @session = Session.new end - + describe '::start' do describe '::instance' do it "it is a singleton within the started session" do @@ -23,13 +23,13 @@ module Arel end end end - + it "manufactures new sessions outside of the started session" do Session.new.should_not == Session.new end end end - + describe Session::CRUD do before do @insert = Insert.new(@relation, @relation[:name] => 'nick') @@ -37,34 +37,34 @@ module Arel @delete = Deletion.new(@relation) @read = @relation end - + describe '#create' do it "executes an insertion on the connection" do mock(@insert).call @session.create(@insert) end end - + describe '#read' do it "executes an selection on the connection" do mock(@read).call @session.read(@read) end - + it "is memoized" do mock(@read).call.once @session.read(@read) @session.read(@read) end end - + describe '#update' do it "executes an update on the connection" do mock(@update).call @session.update(@update) end end - + describe '#delete' do it "executes a delete on the connection" do mock(@delete).call @@ -72,13 +72,13 @@ module Arel end end end - + describe 'Transactions' do describe '#begin' do end - + describe '#end' do end end end -end \ No newline at end of file +end -- cgit v1.2.3 From 16707d1b96365ab569e7a5e47a3d694c14d4132c Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 17 May 2009 16:44:38 -0400 Subject: Add spec for Attribute#inspect --- spec/arel/algebra/unit/primitives/attribute_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/arel/algebra') diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index 89e338e377..afcf1237e0 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -7,6 +7,12 @@ module Arel @attribute = @relation[:id] end + describe "#inspect" do + it "returns a simple, short inspect string" do + @attribute.inspect.should == "" + end + end + describe Attribute::Transformations do describe '#as' do it "manufactures an aliased attributed" do -- cgit v1.2.3 From 10c4b42c35f61145ac6ebb8d36f504344eef47cd Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 17 May 2009 18:21:56 -0400 Subject: Fix bug in Order equality where Descending.new(attribute) was == Ascending.new(attribute) --- spec/arel/algebra/unit/primitives/attribute_spec.rb | 4 ++-- spec/arel/algebra/unit/relations/order_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'spec/arel/algebra') diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index afcf1237e0..2ca63ba48e 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -169,13 +169,13 @@ module Arel describe Attribute::Orderings do describe '#asc' do it 'manufactures an ascending ordering' do - pending + @attribute.asc.should == Ascending.new(@attribute) end end describe '#desc' do it 'manufactures a descending ordering' do - pending + @attribute.desc.should == Descending.new(@attribute) end end end diff --git a/spec/arel/algebra/unit/relations/order_spec.rb b/spec/arel/algebra/unit/relations/order_spec.rb index 4f163894c8..8b3c932fb9 100644 --- a/spec/arel/algebra/unit/relations/order_spec.rb +++ b/spec/arel/algebra/unit/relations/order_spec.rb @@ -6,6 +6,16 @@ module Arel @relation = Table.new(:users) @attribute = @relation[:id] end + + describe "#==" do + it "returns true when the Orders are for the same attribute and direction" do + Ascending.new(@attribute).should == Ascending.new(@attribute) + end + + it "returns false when the Orders are for a diferent direction" do + Ascending.new(@attribute).should_not == Descending.new(@attribute) + end + end end end -- cgit v1.2.3 From 082079169caab2a00f62d9de9c4bdb5dcbc591aa Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 18 May 2009 01:49:50 -0400 Subject: Better inspect output for Expressions --- spec/arel/algebra/unit/primitives/expression_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/arel/algebra') diff --git a/spec/arel/algebra/unit/primitives/expression_spec.rb b/spec/arel/algebra/unit/primitives/expression_spec.rb index 82d12d53f9..768bb492a7 100644 --- a/spec/arel/algebra/unit/primitives/expression_spec.rb +++ b/spec/arel/algebra/unit/primitives/expression_spec.rb @@ -7,6 +7,12 @@ module Arel @attribute = @relation[:id] end + describe "#inspect" do + it "returns a simple, short inspect string" do + @attribute.count.inspect.should == ">" + end + end + describe Expression::Transformations do before do @expression = Count.new(@attribute) -- cgit v1.2.3