dm-sql-finders 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,10 @@
1
1
  module DataMapper
2
2
  class Adapters::DataObjectsAdapter
3
- def select_statement(query)
3
+ def select_statement_with_query(query)
4
4
  SQLFinders::SQLBuilder.new(self, query).select_statement
5
5
  end
6
+
7
+ alias_method :select_statement_without_query, :select_statement
8
+ alias_method :select_statement, :select_statement_with_query
6
9
  end
7
10
  end
@@ -20,6 +20,8 @@ module DataMapper
20
20
  end
21
21
 
22
22
  def select_statement
23
+ return @adapter.send(:select_statement_without_query, @query) unless @query.kind_of?(SQLFinders::Query)
24
+
23
25
  statement = [
24
26
  columns_fragment,
25
27
  from_fragment,
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module SQLFinders
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,12 +1,26 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe DataMapper::Adapters::DataObjectsAdapter do
4
- context "querying by SQL" do
4
+ before(:each) do
5
+ @bob = User.create(:username => "Bob", :role => "Manager")
6
+ @fred = User.create(:username => "Fred", :role => "Tea Boy")
7
+ end
8
+
9
+ context "query without SQL" do
5
10
  before(:each) do
6
- @bob = User.create(:username => "Bob", :role => "Manager")
7
- @fred = User.create(:username => "Fred", :role => "Tea Boy")
11
+ @users = User.all(:username => "Bob")
12
+ @sql, @bind_values = User.repository.adapter.send(:select_statement, @users.query)
8
13
  end
9
14
 
15
+ it "behaves unchanged" do
16
+ @users.to_a.count.should == 1
17
+ @users.to_a.first.should == @bob
18
+ @sql.should == %{SELECT "id", "username", "role" FROM "users" WHERE "username" = ? ORDER BY "id"}
19
+ @bind_values.should == ["Bob"]
20
+ end
21
+ end
22
+
23
+ context "querying by SQL" do
10
24
  context "with a basic SELECT statement" do
11
25
  before(:each) do
12
26
  @users = User.by_sql { |u| ["SELECT #{u.*} FROM #{u} WHERE #{u.role} = ?", "Manager"] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-sql-finders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dm-core
16
- requirement: &6758340 !ruby/object:Gem::Requirement
16
+ requirement: &13789500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *6758340
24
+ version_requirements: *13789500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: dm-do-adapter
27
- requirement: &6757000 !ruby/object:Gem::Requirement
27
+ requirement: &13785560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *6757000
35
+ version_requirements: *13785560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &6755440 !ruby/object:Gem::Requirement
38
+ requirement: &13783660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.6'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *6755440
46
+ version_requirements: *13783660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: dm-migrations
49
- requirement: &6754500 !ruby/object:Gem::Requirement
49
+ requirement: &13782460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.2.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *6754500
57
+ version_requirements: *13782460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: dm-aggregates
60
- requirement: &6753640 !ruby/object:Gem::Requirement
60
+ requirement: &13779440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.2.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *6753640
68
+ version_requirements: *13779440
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: dm-sqlite-adapter
71
- requirement: &6752280 !ruby/object:Gem::Requirement
71
+ requirement: &13778640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 1.2.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *6752280
79
+ version_requirements: *13778640
80
80
  description: ! "dm-sql-finders add #by_sql to your DataMapper models and provides
81
81
  a clean mechanism for using\n the names of the properties in
82
82
  your model, instead of the actual fields in the database. Any SQL\n is