Skip to content
Browse files

Added missing dependencies to gemspec. Added spec of projecting a count.

  • Loading branch information...
1 parent 73fddf0 commit 55190634c773131592810fad2f5b568b8f1869e2 @nathansobo committed Mar 3, 2011
Showing with 43 additions and 7 deletions.
  1. +1 −0 .rspec
  2. +1 −0 .rvmrc
  3. +18 −0 README.md
  4. +2 −0 Rakefile
  5. +6 −6 lib/prequel/expressions/set_function.rb
  6. +4 −0 prequel.gemspec
  7. +10 −1 spec/prequel/relations/projection_spec.rb
  8. +1 −0 spec/spec_helper.rb
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2-p136
View
18 README.md
@@ -0,0 +1,18 @@
+TODO:
+relations
+----------
+test pulling counts out of the database
+add group by
+add order by
+add left outer join
+add limit and offset
+add union
+
+record functionality
+--------------------
+validations
+reload
+black and white listing
+
+
+pull into hyperarchy, get model specs passing
View
2 Rakefile
@@ -1,6 +1,8 @@
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "prequel/version"
+task :default => :spec
+
desc "Build prequel #{Prequel::VERSION}"
task :build do
system "gem build prequel.gemspec"
View
12 lib/prequel/expressions/set_function.rb
@@ -1,22 +1,22 @@
module Prequel
module Expressions
class SetFunction < Expression
- attr_reader :expression, :type
+ attr_reader :expression, :name
- def initialize(expression, type)
- @expression, @type = expression, type
+ def initialize(expression, name)
+ @expression, @name = expression, name
end
def resolve_in_relations(relations)
- SetFunction.new(expression.resolve_in_relations(relations), type)
+ SetFunction.new(expression.resolve_in_relations(relations), name)
end
def resolve_in_query(query)
- SetFunction.new(expression.resolve_in_query(query), type)
+ SetFunction.new(expression.resolve_in_query(query), name)
end
def to_sql
- "#{type}(#{expression.to_sql})"
+ "#{name}(#{expression.to_sql})"
end
end
end
View
4 prequel.gemspec
@@ -14,9 +14,13 @@ Gem::Specification.new do |s|
s.summary = "A ground-up relational algebraic ORM."
s.description = "Prequel is the database library I've always wanted."
+ s.add_dependency('i18n', '>= 0.5.0')
s.add_dependency('activesupport', '>= 3.0.4')
s.add_dependency('sequel', '>= 3.20.0')
+
s.add_development_dependency "rspec"
+ s.add_development_dependency "rr"
+ s.add_development_dependency "pg"
s.files = Dir.glob("lib/**/*") + %w(LICENSE README.md)
s.require_path = 'lib'
View
11 spec/prequel/relations/projection_spec.rb
@@ -89,8 +89,17 @@ class Comment < Prequel::Record
end
end
- context "when the projection is embedded in a join" do
+ context "when projecting a count" do
+ it "returns a single result" do
+ DB[:blogs] << { :id => 1, :user_id => 1, :title => "Blog 1"}
+ DB[:blogs] << { :id => 2, :user_id => 1, :title => "Blog 2"}
+ DB[:blogs] << { :id => 3, :user_id => 3, :title => "Blog 3"}
+
+ Blog.where(:user_id => 1).project(:id.count).all.first.count.should == 2
+ end
+ end
+ context "when the projection is embedded in a join" do
it "constructs the appropriate composite tuples" do
DB[:blogs] << { :id => 1, :user_id => 1, :title => "Blog 1"}
DB[:posts] << { :id => 1, :blog_id => 1, :title => "Blog 1, Post 1"}
View
1 spec/spec_helper.rb
@@ -1,4 +1,5 @@
require 'rubygems'
+require 'rspec'
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'prequel'

0 comments on commit 5519063

Please sign in to comment.
Something went wrong with that request. Please try again.