squeel 0.8.5 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - ree
5
- - jruby
6
5
  - rbx
7
6
  - rbx-2.0
8
7
  - ruby-head
data/Gemfile CHANGED
@@ -3,13 +3,35 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
 
6
- if ENV['RAILS_VERSION'] == 'release'
7
- gem 'activesupport'
8
- gem 'activerecord'
6
+ rails = ENV['RAILS'] || 'master'
7
+ arel = ENV['AREL'] || 'master'
8
+
9
+ arel_opts = case arel
10
+ when /\// # A path
11
+ {:path => arel}
12
+ when /^v/ # A tagged version
13
+ {:git => 'git://github.com/rails/arel.git', :tag => arel}
14
+ else
15
+ {:git => 'git://github.com/rails/arel.git', :branch => arel}
16
+ end
17
+
18
+ gem 'arel', arel_opts
19
+
20
+ case rails
21
+ when /\// # A path
22
+ gem 'activesupport', :path => "#{rails}/activesupport"
23
+ gem 'activemodel', :path => "#{rails}/activemodel"
24
+ gem 'activerecord', :path => "#{rails}/activerecord"
25
+ when /^v/ # A tagged version
26
+ git 'git://github.com/rails/rails.git', :tag => rails do
27
+ gem 'activesupport'
28
+ gem 'activemodel'
29
+ gem 'activerecord'
30
+ end
9
31
  else
10
- gem 'arel', :git => 'git://github.com/rails/arel.git'
11
- git 'git://github.com/rails/rails.git' do
32
+ git 'git://github.com/rails/rails.git', :branch => rails do
12
33
  gem 'activesupport'
34
+ gem 'activemodel'
13
35
  gem 'activerecord'
14
36
  end
15
37
  end
@@ -4,8 +4,6 @@ module Squeel
4
4
  module AssociationPreload
5
5
 
6
6
  def preload_associations(records, associations, preload_options={})
7
- records = Array.wrap(records).compact.uniq
8
- return if records.empty?
9
7
  super(records, Visitors::SymbolVisitor.new.accept(associations), preload_options)
10
8
  end
11
9
 
@@ -64,7 +64,11 @@ module Squeel
64
64
  def prepare_relation_for_association_merge!(r, association_name)
65
65
  r.where_values.map! {|w| Squeel::Visitors::PredicateVisitor.can_visit?(w) ? {association_name => w} : w}
66
66
  r.having_values.map! {|h| Squeel::Visitors::PredicateVisitor.can_visit?(h) ? {association_name => h} : h}
67
- r.joins_values.map! {|j| [Symbol, Hash, Nodes::Stub, Nodes::Join].include?(j.class) ? {association_name => j} : j}
67
+ r.group_values.map! {|g| Squeel::Visitors::AttributeVisitor.can_visit?(g) ? {association_name => g} : g}
68
+ r.order_values.map! {|o| Squeel::Visitors::AttributeVisitor.can_visit?(o) ? {association_name => o} : o}
69
+ r.select_values.map! {|s| Squeel::Visitors::AttributeVisitor.can_visit?(s) ? {association_name => s} : s}
70
+ r.joins_values.map! {|j| [Symbol, Hash, Nodes::Stub, Nodes::Join, Nodes::KeyPath].include?(j.class) ? {association_name => j} : j}
71
+ r.includes_values.map! {|i| [Symbol, Hash, Nodes::Stub, Nodes::Join, Nodes::KeyPath].include?(i.class) ? {association_name => i} : i}
68
72
  end
69
73
 
70
74
  def build_arel
@@ -1,3 +1,3 @@
1
1
  module Squeel
2
- VERSION = "0.8.5"
2
+ VERSION = "0.8.6"
3
3
  end
data/spec/console.rb CHANGED
@@ -8,12 +8,13 @@ Dir[File.expand_path('../../spec/{helpers,support,blueprints}/*.rb', __FILE__)].
8
8
  end
9
9
 
10
10
  Sham.define do
11
- name { Faker::Name.name }
12
- title { Faker::Lorem.sentence }
13
- body { Faker::Lorem.paragraph }
14
- salary {|index| 30000 + (index * 1000)}
15
- tag_name { Faker::Lorem.words(3).join(' ') }
16
- note { Faker::Lorem.words(7).join(' ') }
11
+ name { Faker::Name.name }
12
+ title { Faker::Lorem.sentence }
13
+ body { Faker::Lorem.paragraph }
14
+ salary {|index| 30000 + (index * 1000)}
15
+ tag_name { Faker::Lorem.words(3).join(' ') }
16
+ note { Faker::Lorem.words(7).join(' ') }
17
+ object_name { Faker::Lorem.words(1).first }
17
18
  end
18
19
 
19
20
  Schema.create
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'faker'
4
4
 
5
5
  module ActiveRecord
6
6
  class SQLCounter
7
- IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/,
7
+ IGNORED_SQL = [/^PRAGMA /, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/,
8
8
  /SELECT name\s+FROM sqlite_master\s+WHERE type = 'table' AND NOT name = 'sqlite_sequence'/]
9
9
 
10
10
  # FIXME: this needs to be refactored so specific database can add their own
@@ -37,6 +37,7 @@ Sham.define do
37
37
  salary {|index| 30000 + (index * 1000)}
38
38
  tag_name { Faker::Lorem.words(3).join(' ') }
39
39
  note { Faker::Lorem.words(7).join(' ') }
40
+ object_name { Faker::Lorem.words(1).first }
40
41
  end
41
42
 
42
43
  RSpec.configure do |config|
@@ -642,6 +642,18 @@ module Squeel
642
642
  person.comments.loaded?.should be true
643
643
  end
644
644
 
645
+ it 'includes a belongs_to association even if the child model has no primary key' do
646
+ relation = UnidentifiedObject.where{person_id < 120}.includes(:person)
647
+ queries = queries_for do
648
+ vals = relation.to_a
649
+ vals.should have(8).items
650
+ end
651
+
652
+ queries.should have(2).queries
653
+
654
+ queries.last.should match /IN \(1, ?34, ?67, ?100\)/
655
+ end
656
+
645
657
  end
646
658
 
647
659
  end
@@ -15,6 +15,11 @@ class Person < ActiveRecord::Base
15
15
  has_many :authored_article_comments, :through => :articles,
16
16
  :source => :comments
17
17
  has_many :notes, :as => :notable
18
+ has_many :unidentified_objects
19
+ end
20
+
21
+ class UnidentifiedObject < ActiveRecord::Base
22
+ belongs_to :person
18
23
  end
19
24
 
20
25
  class Article < ActiveRecord::Base
@@ -50,6 +55,11 @@ module Schema
50
55
  t.integer :salary
51
56
  end
52
57
 
58
+ create_table :unidentified_objects, :id => false, :force => true do |t|
59
+ t.integer :person_id
60
+ t.string :name
61
+ end
62
+
53
63
  create_table :articles, :force => true do |t|
54
64
  t.integer :person_id
55
65
  t.string :title
@@ -82,6 +92,9 @@ module Schema
82
92
 
83
93
  10.times do
84
94
  person = Person.make
95
+ 2.times do
96
+ UnidentifiedObject.create(:person => person, :name => Sham.object_name)
97
+ end
85
98
  Note.make(:notable => person)
86
99
  3.times do
87
100
  article = Article.make(:person => person)
metadata CHANGED
@@ -1,127 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: squeel
3
- version: !ruby/object:Gem::Version
4
- hash: 53
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.6
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 8
9
- - 5
10
- version: 0.8.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Ernie Miller
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-02 00:00:00 -04:00
12
+ date: 2011-08-01 00:00:00.000000000 -04:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: activerecord
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70148779727860 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
34
23
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activesupport
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70148779727860
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &70148779727360 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
30
+ requirements:
42
31
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 3
47
- - 0
48
- version: "3.0"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
49
34
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rspec
53
35
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70148779727360
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &70148779726900 !ruby/object:Gem::Requirement
55
40
  none: false
56
- requirements:
41
+ requirements:
57
42
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 23
60
- segments:
61
- - 2
62
- - 6
63
- - 0
43
+ - !ruby/object:Gem::Version
64
44
  version: 2.6.0
65
45
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: machinist
69
46
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70148779726900
48
+ - !ruby/object:Gem::Dependency
49
+ name: machinist
50
+ requirement: &70148779726440 !ruby/object:Gem::Requirement
71
51
  none: false
72
- requirements:
52
+ requirements:
73
53
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 27
76
- segments:
77
- - 1
78
- - 0
79
- - 6
54
+ - !ruby/object:Gem::Version
80
55
  version: 1.0.6
81
56
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: faker
85
57
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *70148779726440
59
+ - !ruby/object:Gem::Dependency
60
+ name: faker
61
+ requirement: &70148779725980 !ruby/object:Gem::Requirement
87
62
  none: false
88
- requirements:
63
+ requirements:
89
64
  - - ~>
90
- - !ruby/object:Gem::Version
91
- hash: 49
92
- segments:
93
- - 0
94
- - 9
95
- - 5
65
+ - !ruby/object:Gem::Version
96
66
  version: 0.9.5
97
67
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: sqlite3
101
68
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *70148779725980
70
+ - !ruby/object:Gem::Dependency
71
+ name: sqlite3
72
+ requirement: &70148779725520 !ruby/object:Gem::Requirement
103
73
  none: false
104
- requirements:
74
+ requirements:
105
75
  - - ~>
106
- - !ruby/object:Gem::Version
107
- hash: 29
108
- segments:
109
- - 1
110
- - 3
111
- - 3
76
+ - !ruby/object:Gem::Version
112
77
  version: 1.3.3
113
78
  type: :development
114
- version_requirements: *id006
115
- description: "\n Squeel unlocks the power of ARel in your Rails 3 application with\n a handy block-based syntax. You can write subqueries, access named\n functions provided by your RDBMS, and more, all without writing\n SQL strings.\n "
116
- email:
79
+ prerelease: false
80
+ version_requirements: *70148779725520
81
+ description: ! "\n Squeel unlocks the power of ARel in your Rails 3 application
82
+ with\n a handy block-based syntax. You can write subqueries, access named\n
83
+ \ functions provided by your RDBMS, and more, all without writing\n SQL
84
+ strings.\n "
85
+ email:
117
86
  - ernie@metautonomo.us
118
87
  executables: []
119
-
120
88
  extensions: []
121
-
122
89
  extra_rdoc_files: []
123
-
124
- files:
90
+ files:
125
91
  - .gitignore
126
92
  - .travis.yml
127
93
  - .yardopts
@@ -207,45 +173,42 @@ files:
207
173
  has_rdoc: true
208
174
  homepage: http://metautonomo.us/projects/squeel
209
175
  licenses: []
176
+ post_install_message: ! '
210
177
 
211
- post_install_message: |+
212
-
213
178
  *** Thanks for installing Squeel! ***
179
+
214
180
  Be sure to check out http://metautonomo.us/projects/squeel/ for a
215
- walkthrough of Squeel's features, and click the donate link if
216
- you're feeling especially appreciative. It'd help me justify this
181
+
182
+ walkthrough of Squeel''s features, and click the donate link if
183
+
184
+ you''re feeling especially appreciative. It''d help me justify this
185
+
217
186
  "open source" stuff to my lovely wife. :)
218
-
219
- rdoc_options: []
220
187
 
221
- require_paths:
188
+
189
+ '
190
+ rdoc_options: []
191
+ require_paths:
222
192
  - lib
223
- required_ruby_version: !ruby/object:Gem::Requirement
193
+ required_ruby_version: !ruby/object:Gem::Requirement
224
194
  none: false
225
- requirements:
226
- - - ">="
227
- - !ruby/object:Gem::Version
228
- hash: 3
229
- segments:
230
- - 0
231
- version: "0"
232
- required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ! '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
200
  none: false
234
- requirements:
235
- - - ">="
236
- - !ruby/object:Gem::Version
237
- hash: 3
238
- segments:
239
- - 0
240
- version: "0"
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
241
205
  requirements: []
242
-
243
206
  rubyforge_project: squeel
244
- rubygems_version: 1.5.2
207
+ rubygems_version: 1.6.2
245
208
  signing_key:
246
209
  specification_version: 3
247
210
  summary: ActiveRecord 3, improved.
248
- test_files:
211
+ test_files:
249
212
  - spec/blueprints/articles.rb
250
213
  - spec/blueprints/comments.rb
251
214
  - spec/blueprints/notes.rb