aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-02 21:10:35 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-02 21:10:35 -0800
commit6647a1e08eb9dc3512628882bcf60d421df74228 (patch)
tree204eebc8e9c6e6711331706dbd14815164db2eda /spec
parentc54392872f024d55e8a23ead3065e6119a52b234 (diff)
downloadrails-6647a1e08eb9dc3512628882bcf60d421df74228.tar.gz
rails-6647a1e08eb9dc3512628882bcf60d421df74228.tar.bz2
rails-6647a1e08eb9dc3512628882bcf60d421df74228.zip
scalars are now lifted; the heavy lifting is done by the operations on relation (select, join, etc.)
Diffstat (limited to 'spec')
-rw-r--r--spec/active_relation/unit/predicates/binary_spec.rb2
-rw-r--r--spec/active_relation/unit/predicates/relation_inclusion_spec.rb19
-rw-r--r--spec/active_relation/unit/relations/insertion_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/join_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/relation_spec.rb18
-rw-r--r--spec/active_relation/unit/relations/selection_spec.rb6
-rw-r--r--spec/active_relation/unit/relations/update_spec.rb4
-rw-r--r--spec/active_relation/unit/session/session_spec.rb4
8 files changed, 30 insertions, 27 deletions
diff --git a/spec/active_relation/unit/predicates/binary_spec.rb b/spec/active_relation/unit/predicates/binary_spec.rb
index f6466d9105..677d8f3ab4 100644
--- a/spec/active_relation/unit/predicates/binary_spec.rb
+++ b/spec/active_relation/unit/predicates/binary_spec.rb
@@ -55,7 +55,7 @@ module ActiveRelation
end
it 'appropriately quotes scalars' do
- ConcreteBinary.new(@attribute1, "1-asdf").to_sql.should be_like("
+ ConcreteBinary.new(@attribute1, "1-asdf".bind(@relation1)).to_sql.should be_like("
`users`.`id` <=> 1
")
end
diff --git a/spec/active_relation/unit/predicates/relation_inclusion_spec.rb b/spec/active_relation/unit/predicates/relation_inclusion_spec.rb
index 0ac7ccb6e2..af5846b747 100644
--- a/spec/active_relation/unit/predicates/relation_inclusion_spec.rb
+++ b/spec/active_relation/unit/predicates/relation_inclusion_spec.rb
@@ -3,23 +3,16 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
module ActiveRelation
describe RelationInclusion do
before do
- foo = Table.new(:foo)
- @relation1 = foo.project(foo[:id])
- @relation2 = Table.new(:bar)
- @attribute = @relation1[:id]
- end
-
- describe RelationInclusion, '==' do
- it "obtains if attribute1 and attribute2 are identical" do
- RelationInclusion.new(@attribute, @relation1).should == RelationInclusion.new(@attribute, @relation1)
- RelationInclusion.new(@attribute, @relation1).should_not == RelationInclusion.new(@attribute, @relation2)
- end
+ users = Table.new(:users)
+ @relation = users.project(users[:id])
+ @attribute = @relation[:id]
end
describe RelationInclusion, '#to_sql' do
it "manufactures subselect sql" do
- RelationInclusion.new(@attribute, @relation1).to_sql.should be_like("
- `foo`.`id` IN (SELECT `foo`.`id` FROM `foo`)
+ # remove when sufficient coverage of sql strategies exists
+ RelationInclusion.new(@attribute, @relation).to_sql.should be_like("
+ `users`.`id` IN (SELECT `users`.`id` FROM `users`)
")
end
end
diff --git a/spec/active_relation/unit/relations/insertion_spec.rb b/spec/active_relation/unit/relations/insertion_spec.rb
index b2b239097a..91bf7773c1 100644
--- a/spec/active_relation/unit/relations/insertion_spec.rb
+++ b/spec/active_relation/unit/relations/insertion_spec.rb
@@ -8,7 +8,7 @@ module ActiveRelation
describe '#to_sql' do
it 'manufactures sql inserting the data for one item' do
- Insertion.new(@relation, @relation[:name] => "nick").to_sql.should be_like("
+ Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)).to_sql.should be_like("
INSERT
INTO `users`
(`users`.`name`) VALUES ('nick')
diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb
index 64d41effc5..a424239c4b 100644
--- a/spec/active_relation/unit/relations/join_spec.rb
+++ b/spec/active_relation/unit/relations/join_spec.rb
@@ -81,7 +81,7 @@ module ActiveRelation
.aggregate(@relation2[:user_id], @relation2[:id].count) \
.group(@relation2[:user_id]) \
.rename(@relation2[:id].count, :cnt) \
- .as(:photo_count)
+ .as('photo_count')
end
describe '#attributes' do
diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb
index 3af3b8aa9c..8f35760801 100644
--- a/spec/active_relation/unit/relations/relation_spec.rb
+++ b/spec/active_relation/unit/relations/relation_spec.rb
@@ -89,7 +89,7 @@ module ActiveRelation
end
it "accepts arbitrary strings" do
- @relation.select("arbitrary").should == Selection.new(@relation, "arbitrary")
+ @relation.select("arbitrary").should == Selection.new(@relation, Scalar.new("arbitrary", @relation))
end
end
@@ -100,9 +100,17 @@ module ActiveRelation
end
describe '#aggregate' do
+ before do
+ @expression1 = @attribute1.sum
+ @expression2 = @attribute2.sum
+ end
+
it 'manufactures a group relation' do
@relation.aggregate(@expression1, @expression2).group(@attribute1, @attribute2). \
- should == Aggregation.new(@relation, :expressions => [@expresion, @expression2], :groupings => [@attribute1, @attribute2])
+ should == Aggregation.new(@relation,
+ :expressions => [@expression1, @expression2],
+ :groupings => [@attribute1, @attribute2]
+ )
end
end
@@ -119,7 +127,8 @@ module ActiveRelation
describe '#insert' do
it 'manufactures an insertion relation' do
Session.start do
- mock(Session.new).create(Insertion.new(@relation, record = {@relation[:name] => 'carl'}))
+ record = {@relation[:name] => 'carl'}
+ mock(Session.new).create(Insertion.new(@relation, record.bind(@relation)))
@relation.insert(record).should == @relation
end
end
@@ -128,7 +137,8 @@ module ActiveRelation
describe '#update' do
it 'manufactures an update relation' do
Session.start do
- mock(Session.new).update(Update.new(@relation, assignments = {@relation[:name] => 'bob'}))
+ assignments = {@relation[:name] => Scalar.new('bob', @relation)}
+ mock(Session.new).update(Update.new(@relation, assignments.bind(@relation)))
@relation.update(assignments).should == @relation
end
end
diff --git a/spec/active_relation/unit/relations/selection_spec.rb b/spec/active_relation/unit/relations/selection_spec.rb
index 3a18d4ae6e..d5e0c6a9f6 100644
--- a/spec/active_relation/unit/relations/selection_spec.rb
+++ b/spec/active_relation/unit/relations/selection_spec.rb
@@ -4,12 +4,12 @@ module ActiveRelation
describe Selection do
before do
@relation = Table.new(:users)
- @predicate = Equality.new(@relation[:id], 1)
+ @predicate = Equality.new(@relation[:id], 1.bind(@relation))
end
describe '#initialize' do
it "manufactures nested selection relations if multiple predicates are provided" do
- @predicate2 = LessThan.new(@relation[:age], 2)
+ @predicate2 = LessThan.new(@relation[:age], 2.bind(@relation))
Selection.new(@relation, @predicate, @predicate2). \
should == Selection.new(Selection.new(@relation, @predicate2), @predicate)
end
@@ -39,7 +39,7 @@ module ActiveRelation
end
it "allows arbitrary sql" do
- Selection.new(@relation, "asdf").to_sql.should be_like("
+ Selection.new(@relation, "asdf".bind(@relation)).to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`
FROM `users`
WHERE asdf
diff --git a/spec/active_relation/unit/relations/update_spec.rb b/spec/active_relation/unit/relations/update_spec.rb
index 2cd3eb9d11..cad14fd5ec 100644
--- a/spec/active_relation/unit/relations/update_spec.rb
+++ b/spec/active_relation/unit/relations/update_spec.rb
@@ -8,14 +8,14 @@ module ActiveRelation
describe '#to_sql' do
it 'manufactures sql updating attributes' do
- Update.new(@relation, @relation[:name] => "nick").to_sql.should be_like("
+ Update.new(@relation, @relation[:name] => "nick".bind(@relation)).to_sql.should be_like("
UPDATE `users`
SET `users`.`name` = 'nick'
")
end
it 'manufactures sql updating a selection relation' do
- Update.new(@relation.select(@relation[:id].equals(1)), @relation[:name] => "nick").to_sql.should be_like("
+ Update.new(@relation.select(@relation[:id].equals(1)), @relation[:name] => "nick".bind(@relation)).to_sql.should be_like("
UPDATE `users`
SET `users`.`name` = 'nick'
WHERE `users`.`id` = 1
diff --git a/spec/active_relation/unit/session/session_spec.rb b/spec/active_relation/unit/session/session_spec.rb
index 1ac69976b5..89d96ef323 100644
--- a/spec/active_relation/unit/session/session_spec.rb
+++ b/spec/active_relation/unit/session/session_spec.rb
@@ -32,8 +32,8 @@ module ActiveRelation
describe Session::CRUD do
before do
- @insert = Insertion.new(@relation, @relation[:name] => 'nick')
- @update = Update.new(@relation, @relation[:name] => 'nick')
+ @insert = Insertion.new(@relation, @relation[:name] => 'nick'.bind(@relation))
+ @update = Update.new(@relation, @relation[:name] => 'nick'.bind(@relation))
@delete = Deletion.new(@relation)
@select = @relation
end