ambitious-activerecord 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
1
 
2
- # Gem::Specification for Ambitious-activerecord-0.1.0
2
+ # Gem::Specification for Ambitious-activerecord-0.1.1
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{ambitious-activerecord}
7
- s.version = "0.1.0"
8
- s.date = %q{2008-01-29}
7
+ s.version = "0.1.1"
8
+ s.date = %q{2008-02-16}
9
9
  s.summary = %q{An ambitious adapter for ActiveRecord}
10
10
  s.email = %q{chris@ozmm.org}
11
11
  s.homepage = %q{http://ambition.rubyforge.org/}
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.files = ["lib/ambition/adapters/active_record/base.rb", "lib/ambition/adapters/active_record/query.rb", "lib/ambition/adapters/active_record/select.rb", "lib/ambition/adapters/active_record/slice.rb", "lib/ambition/adapters/active_record/sort.rb", "lib/ambition/adapters/active_record/statements.rb", "lib/ambition/adapters/active_record.rb", "test/benchmark.rb", "test/chaining_test.rb", "test/count_test.rb", "test/enumerable_test.rb", "test/helper.rb", "test/join_test.rb", "test/profiler.rb", "test/ruby_test.rb", "test/select_test.rb", "test/slice_test.rb", "test/sort_test.rb", "test/source_test.rb", "test/types_test.rb", "Manifest", "ambitious-activerecord.gemspec"]
17
17
  s.test_files = ["test/chaining_test.rb", "test/count_test.rb", "test/enumerable_test.rb", "test/join_test.rb", "test/ruby_test.rb", "test/select_test.rb", "test/slice_test.rb", "test/sort_test.rb", "test/source_test.rb", "test/types_test.rb"]
18
18
  s.add_dependency(%q<activerecord>, [">= 1.15.0"])
19
- s.add_dependency(%q<ambition>, [">= 0.5.0"])
19
+ s.add_dependency(%q<ambition>, [">= 0.5.1"])
20
20
  end
21
21
 
22
22
 
@@ -24,7 +24,7 @@ end
24
24
  #
25
25
  # require 'rake'
26
26
  #
27
- # Version = '0.1.0'
27
+ # Version = '0.1.1'
28
28
  #
29
29
  # begin
30
30
  # require 'rubygems'
@@ -42,7 +42,7 @@ end
42
42
  # p.url = "http://ambition.rubyforge.org/"
43
43
  # p.test_pattern = 'test/*_test.rb'
44
44
  # p.version = Version
45
- # p.dependencies << 'ambition >=0.5.0'
45
+ # p.dependencies << 'ambition >=0.5.1'
46
46
  # end
47
47
  #
48
48
  # rescue LoadError
@@ -24,11 +24,11 @@ module Ambition
24
24
  hash[:order] = order.join(', ')
25
25
  end
26
26
 
27
- if clauses[:slice].last =~ /LIMIT (\d+)/
27
+ if Array(clauses[:slice]).last =~ /LIMIT (\d+)/
28
28
  hash[:limit] = $1.to_i
29
29
  end
30
30
 
31
- if clauses[:slice].last =~ /OFFSET (\d+)/
31
+ if Array(clauses[:slice]).last =~ /OFFSET (\d+)/
32
32
  hash[:offset] = $1.to_i
33
33
  end
34
34
 
@@ -81,6 +81,11 @@ module Ambition
81
81
  "#{right} IN (#{left})"
82
82
  end
83
83
 
84
+ def nil?(column)
85
+ left = "#{owner.table_name}.#{quote_column_name column}"
86
+ negated? ? not_equal(left, nil) : self.==(left, nil)
87
+ end
88
+
84
89
  def downcase(column)
85
90
  "LOWER(#{owner.table_name}.#{quote_column_name column})"
86
91
  end
@@ -1,67 +1,69 @@
1
- $:.unshift File.dirname(__FILE__) + '/../../../lib'
2
- %w( rubygems ambition ambition/adapters/active_record benchmark ).each { |f| require f }
1
+ unless defined? Test
2
+ $:.unshift File.dirname(__FILE__) + '/../../../lib'
3
+ %w( rubygems ambition/adapters/active_record benchmark ).each { |f| require f }
3
4
 
4
- class User < ActiveRecord::Base
5
- def self.reflections
6
- return @reflections if @reflections
7
- @reflections = {}
8
- @reflections[:ideas] = Reflection.new(:has_many, 'user_id', :ideas, 'ideas')
9
- @reflections[:invites] = Reflection.new(:has_many, 'referrer_id', :invites, 'invites')
10
- @reflections[:profile] = Reflection.new(:has_one, 'user_id', :profile, 'profiles')
11
- @reflections[:account] = Reflection.new(:belongs_to, 'account_id', :account, 'accounts')
12
- @reflections
13
- end
5
+ class User < ActiveRecord::Base
6
+ def self.reflections
7
+ return @reflections if @reflections
8
+ @reflections = {}
9
+ @reflections[:ideas] = Reflection.new(:has_many, 'user_id', :ideas, 'ideas')
10
+ @reflections[:invites] = Reflection.new(:has_many, 'referrer_id', :invites, 'invites')
11
+ @reflections[:profile] = Reflection.new(:has_one, 'user_id', :profile, 'profiles')
12
+ @reflections[:account] = Reflection.new(:belongs_to, 'account_id', :account, 'accounts')
13
+ @reflections
14
+ end
14
15
 
15
- def self.table_name
16
- 'users'
16
+ def self.table_name
17
+ 'users'
18
+ end
17
19
  end
18
- end
19
20
 
20
- class Reflection < Struct.new(:macro, :primary_key_name, :name, :table_name)
21
- end
21
+ class Reflection < Struct.new(:macro, :primary_key_name, :name, :table_name)
22
+ end
22
23
 
23
- Times = 10000
24
+ Times = 10000
24
25
 
25
- Benchmark.bm(30) do |x|
26
- x.report 'simple select' do
27
- Times.times do
28
- User.select { |u| u.id == 20 }.to_hash
26
+ Benchmark.bm(30) do |x|
27
+ x.report 'simple select' do
28
+ Times.times do
29
+ User.select { |u| u.id == 20 }.to_hash
30
+ end
29
31
  end
30
- end
31
32
 
32
- x.report 'simple select w/ eval' do
33
- Times.times do
34
- User.select { |u| u.created_at == Time.now }.to_hash
33
+ x.report 'simple select w/ eval' do
34
+ Times.times do
35
+ User.select { |u| u.created_at == Time.now }.to_hash
36
+ end
35
37
  end
36
- end
37
38
 
38
- x.report 'dual select' do
39
- Times.times do
40
- User.select { |u| u.id == 20 && u.age > 20 }.to_hash
39
+ x.report 'dual select' do
40
+ Times.times do
41
+ User.select { |u| u.id == 20 && u.age > 20 }.to_hash
42
+ end
41
43
  end
42
- end
43
44
 
44
- x.report 'join select' do
45
- Times.times do
46
- User.select { |u| u.id == 20 && u.ideas.name =~ /stuff/ }.to_hash
45
+ x.report 'join select' do
46
+ Times.times do
47
+ User.select { |u| u.id == 20 && u.ideas.name =~ /stuff/ }.to_hash
48
+ end
47
49
  end
48
- end
49
50
 
50
- x.report 'dual select w/ sort' do
51
- Times.times do
52
- User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.to_hash
51
+ x.report 'dual select w/ sort' do
52
+ Times.times do
53
+ User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.to_hash
54
+ end
53
55
  end
54
- end
55
56
 
56
- x.report 'dual select w/ sort & first' do
57
- Times.times do
58
- User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.first(20).to_hash
57
+ x.report 'dual select w/ sort & first' do
58
+ Times.times do
59
+ User.select { |u| u.id == 20 && u.age > 20 }.sort_by { |u| u.id }.first(20).to_hash
60
+ end
59
61
  end
60
- end
61
62
 
62
- x.report "it's complicated" do
63
- Times.times do
64
- User.select { |u| (u.id == 20 && u.age > 20) || u.profile.name == 'Jon' }.sort_by { |u| [u.id, -u.name] }.first(20).to_hash
63
+ x.report "it's complicated" do
64
+ Times.times do
65
+ User.select { |u| (u.id == 20 && u.age > 20) || u.profile.name == 'Jon' }.sort_by { |u| [u.id, -u.name] }.first(20).to_hash
66
+ end
65
67
  end
66
68
  end
67
69
  end
@@ -25,6 +25,10 @@ end
25
25
  module ActiveRecord
26
26
  module ConnectionAdapters
27
27
  class MysqlAdapter
28
+ def initialize(*args)
29
+ super
30
+ end
31
+
28
32
  def connect(*args)
29
33
  true
30
34
  end
@@ -52,6 +52,16 @@ context "Different types" do
52
52
  sql.should == "SELECT * FROM users WHERE users.name IS NOT NULL"
53
53
  end
54
54
 
55
+ specify "nil?" do
56
+ sql = User.select { |m| m.name.nil? }.to_s
57
+ sql.should == "SELECT * FROM users WHERE users.name IS NULL"
58
+ end
59
+
60
+ specify "!nil?" do
61
+ sql = User.select { |m| !m.name.nil? }.to_s
62
+ sql.should == "SELECT * FROM users WHERE users.name IS NOT NULL"
63
+ end
64
+
55
65
  specify "Time" do
56
66
  sql = User.select { |m| m.name == Time.now }.to_s
57
67
  sql.should == "SELECT * FROM users WHERE users.name = '#{Time.now.to_s(:db)}'"
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ambitious-activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2008-01-29 00:00:00 -08:00
6
+ version: 0.1.1
7
+ date: 2008-02-16 00:00:00 -08:00
8
8
  summary: An ambitious adapter for ActiveRecord
9
9
  require_paths:
10
10
  - lib
@@ -89,5 +89,5 @@ dependencies:
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 0.5.0
92
+ version: 0.5.1
93
93
  version: