aboutsummaryrefslogtreecommitdiffstats
path: root/spec/integration
diff options
context:
space:
mode:
Diffstat (limited to 'spec/integration')
-rw-r--r--spec/integration/scratch_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/integration/scratch_spec.rb b/spec/integration/scratch_spec.rb
new file mode 100644
index 0000000000..6426d2478d
--- /dev/null
+++ b/spec/integration/scratch_spec.rb
@@ -0,0 +1,37 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe 'Relational Algebra' do
+ before do
+ User = TableRelation.new(:users)
+ Photo = TableRelation.new(:photos)
+ Camera = TableRelation.new(:cameras)
+ user = User.select(User[:id] == 1)
+ @user_photos = (user << Photo).on(user[:id] == Photo[:user_id])
+ end
+
+ it 'simulates User.has_many :photos' do
+ @user_photos.to_sql.should == SelectBuilder.new do
+ select { all }
+ from :users do
+ left_outer_join :photos do
+ equals { column :users, :id; column :photos, :user_id }
+ end
+ end
+ where do
+ equals { column :users, :id; value 1 }
+ end
+ end
+ @user_photos.to_sql.to_s.should be_like("""
+ SELECT *
+ FROM users
+ LEFT OUTER JOIN photos
+ ON users.id = photos.user_id
+ WHERE
+ users.id = 1
+ """)
+ end
+
+ it 'simulating a User.has_many :cameras :through => :photos' do
+ user_cameras = (@user_photos << Camera).on(@user_photos[:camera_id] == Camera[:id])
+ end
+end \ No newline at end of file