Permalink
Browse files

SetProjection#fetch_sql & #merge delegate to #operand.

  • Loading branch information...
1 parent ef0c3c7 commit bd123ae6c9b31b128c6dd8fb6a87a221a30e705c Sharon Ly & Nathan Sobo committed Nov 4, 2008
View
4 lib/unison/relations/ordering.rb
@@ -47,6 +47,10 @@ def set
operand.set
end
+ def push
+ operand.push
+ end
+
def composed_sets
operand.composed_sets
end
View
8 lib/unison/relations/set_projection.rb
@@ -50,19 +50,19 @@ def has_attribute?(attribute)
end
def fetch_arel
- Arel::Project.new( operand.fetch_arel, *projected_set.fetch_arel.attributes )
+ operand.fetch_arel
end
def tuple_class
projected_set.tuple_class
end
def new_tuple(attributes)
- projected_set.new_tuple(attributes)
+ operand.new_tuple(attributes)
end
- def merge(tuples)
- projected_set.merge(tuples)
+ def merge(composite_tuples)
+ operand.merge(composite_tuples)
end
def push
View
11 spec/unit/relations/inner_join_spec.rb
@@ -354,6 +354,7 @@ def predicate
before do
origin.connection[:users].delete
origin.connection[:photos].delete
+ origin.connection[:cameras].delete
end
context "when #composed_sets.size == 2" do
@@ -366,8 +367,8 @@ def predicate
join.push
- users_projection.pull.should == users_projection.tuples
- photos_projection.pull.should == photos_projection.tuples
+ users_set.fetch.should == users_projection.tuples
+ photos_set.fetch.should == photos_projection.tuples
end
end
@@ -388,9 +389,9 @@ def predicate
join.push
- users_projection.pull.should == users_projection.tuples
- photos_projection.pull.should == photos_projection.tuples
- cameras_projection.pull.should == cameras_projection.tuples
+ users_set.fetch.should == users_projection.tuples
+ photos_set.fetch.should == photos_projection.tuples
+ cameras_set.fetch.should == cameras_projection.tuples
end
end
end
View
39 spec/unit/relations/ordering_spec.rb
@@ -71,42 +71,9 @@ def order_by_attribute_2
end
describe "#push" do
- before do
- origin.connection[:users].delete
- origin.connection[:photos].delete
- end
-
- context "when the Ordering contains PrimitiveTuples" do
- before do
- ordering.composed_sets.length.should == 1
- end
-
- it "calls #push on the given Repository with self" do
- origin.fetch(ordering).should be_empty
- ordering.push
- origin.fetch(ordering).should == ordering.tuples
- end
- end
-
- context "when the Ordering contains CompositeTuples" do
- before do
- @ordering = users_set.join(photos_set).on(photos_set[:user_id].eq(users_set[:id])).order_by(users_set[:name])
- ordering.should_not be_empty
- ordering.composed_sets.length.should == 2
- end
-
- it "pushes a SetProjection of each Set represented in the Ordering to the given Repository" do
- users_projection = ordering.project(users_set)
- photos_projection = ordering.project(photos_set)
- mock.proxy(origin).push(users_projection)
- mock.proxy(origin).push(photos_projection)
-
- origin.fetch(users_projection).should be_empty
- origin.fetch(photos_projection).should be_empty
- ordering.push
- origin.fetch(users_projection).should == users_projection.tuples
- origin.fetch(photos_projection).should == photos_projection.tuples
- end
+ it "delegates to its #operand" do
+ mock.proxy(operand).push
+ ordering.push
end
end
View
8 spec/unit/relations/selection_spec.rb
@@ -61,11 +61,11 @@ module Relations
mock.proxy(origin).push(users_projection)
mock.proxy(origin).push(photos_projection)
- origin.fetch(users_projection).should be_empty
- origin.fetch(photos_projection).should be_empty
+ users_set.fetch.should be_empty
+ photos_set.fetch.should be_empty
selection.push
- origin.fetch(users_projection).should == users_projection.tuples
- origin.fetch(photos_projection).should == photos_projection.tuples
+ users_set.fetch.should == users_projection.tuples
+ photos_set.fetch.should == photos_projection.tuples
end
end
end
View
38 spec/unit/relations/set_projection_spec.rb
@@ -24,29 +24,21 @@ module Relations
end
describe "#new_tuple" do
- it "delegates to #projected_set" do
- attributes = {:id => 1, :name => 'Vacation Photos'}
- projection.new_tuple(attributes).should == projected_set.new_tuple(attributes)
+ it "delegates to #operand" do
+ attributes = {:users__id => "sharon", :users__name => 'Sharon Ly', :photos__id => "sharon_photo", :photos__name => "Sharon's Face"}
+ projection.new_tuple(attributes).should == operand.new_tuple(attributes)
end
end
describe "#fetch_sql" do
- it "returns select attributes from operand" do
- projection.fetch_sql.should be_like("
- SELECT DISTINCT `users`.`id`, `users`.`name`, `users`.`hobby`, `users`.`team_id`, `users`.`developer`, `users`.`show_fans`
- FROM `users`
- INNER JOIN `photos`
- ON `photos`.`user_id` = `users`.`id`"
- )
+ it "delegates to #operand" do
+ projection.fetch_sql.should == operand.fetch_sql
end
end
describe "#fetch_arel" do
- it "returns an Arel representation of the relation" do
- projection.fetch_arel.should == Arel::Project.new(
- operand.fetch_arel,
- *users_set.fetch_arel.attributes
- )
+ it "delegates to #operand" do
+ projection.fetch_arel.should == operand.fetch_arel
end
end
@@ -56,9 +48,10 @@ module Relations
origin.connection[:users].delete
mock.proxy(operand).push
- origin.fetch(projection).should be_empty
+
+ projected_set.fetch.should be_empty
projection.push
- origin.fetch(projection).should == projection.tuples
+ projected_set.fetch.should == projection.tuples
end
end
@@ -119,12 +112,13 @@ module Relations
end
describe "#merge" do
- it "calls #merge on the #projected_set" do
- tuple = User.new(:id => 100, :name => "Jan")
- mock.proxy(projected_set).merge([tuple])
- projected_set.should_not include(tuple)
+ it "calls #merge on the #operand" do
+ tuple = CompositeTuple.new(User.find("jan"), Photo.new(:id => "jan_photo", :user_id => "jan")).pushed
+ mock.proxy(operand).merge([tuple])
+
+ operand.should_not include(tuple)
projection.merge([tuple])
- projected_set.should include(tuple)
+ operand.should include(tuple)
end
end
View
8 spec/unit/relations/singleton_relation_spec.rb
@@ -100,11 +100,11 @@ def operand
mock.proxy(origin).push(users_projection)
mock.proxy(origin).push(accounts_projection)
- origin.fetch(users_projection).should be_empty
- origin.fetch(accounts_projection).should be_empty
+ users_set.fetch.should be_empty
+ accounts_set.fetch.should be_empty
singleton_relation.push
- origin.fetch(users_projection).should == users_projection.tuples
- origin.fetch(accounts_projection).should == accounts_projection.tuples
+ users_set.fetch.should == users_projection.tuples
+ accounts_set.fetch.should == accounts_projection.tuples
end
end
end
View
6 spec/unit/repository_spec.rb
@@ -28,7 +28,7 @@ module Unison
end
context "when passed a SetProjection" do
- it "returns an array of Relation#tuple_class instances based on the result of a query using Relation#fetch_sql" do
+ it "returns an array of CompositeTuples based on the result of a query using SetProjection#fetch_sql" do
projection = users_set \
.join(photos_set) \
.on(users_set[:id].eq(photos_set[:user_id])) \
@@ -37,7 +37,9 @@ module Unison
results = origin.fetch(projection)
results.should_not be_empty
results.each do |result|
- result.class.should == Photo
+ result.class.should == CompositeTuple
+ result.left.class.should == User
+ result.right.class.should == Photo
end
end
end

0 comments on commit bd123ae

Please sign in to comment.