activerecord 2.3.14 → 2.3.15
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/active_record/base.rb +11 -5
- data/lib/active_record/validations.rb +5 -5
- data/lib/active_record/version.rb +1 -1
- data/test/cases/finder_test.rb +28 -0
- metadata +9 -14
data/Rakefile
CHANGED
@@ -192,7 +192,7 @@ spec = Gem::Specification.new do |s|
|
|
192
192
|
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
193
193
|
end
|
194
194
|
|
195
|
-
s.add_dependency('activesupport', '= 2.3.
|
195
|
+
s.add_dependency('activesupport', '= 2.3.15' + PKG_BUILD)
|
196
196
|
|
197
197
|
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
|
198
198
|
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"
|
data/lib/active_record/base.rb
CHANGED
@@ -1897,7 +1897,11 @@ module ActiveRecord #:nodoc:
|
|
1897
1897
|
# end
|
1898
1898
|
self.class_eval <<-EOS, __FILE__, __LINE__ + 1
|
1899
1899
|
def self.#{method_id}(*args)
|
1900
|
-
options = args.
|
1900
|
+
options = if args.length > #{attribute_names.size}
|
1901
|
+
args.extract_options!
|
1902
|
+
else
|
1903
|
+
{}
|
1904
|
+
end
|
1901
1905
|
attributes = construct_attributes_from_arguments(
|
1902
1906
|
[:#{attribute_names.join(',:')}],
|
1903
1907
|
args
|
@@ -2333,17 +2337,17 @@ module ActiveRecord #:nodoc:
|
|
2333
2337
|
# And for value objects on a composed_of relationship:
|
2334
2338
|
# { :address => Address.new("123 abc st.", "chicago") }
|
2335
2339
|
# # => "address_street='123 abc st.' and address_city='chicago'"
|
2336
|
-
def sanitize_sql_hash_for_conditions(attrs, default_table_name = quoted_table_name)
|
2340
|
+
def sanitize_sql_hash_for_conditions(attrs, default_table_name = quoted_table_name, top_level = true)
|
2337
2341
|
attrs = expand_hash_conditions_for_aggregates(attrs)
|
2338
2342
|
|
2339
2343
|
conditions = attrs.map do |attr, value|
|
2340
2344
|
table_name = default_table_name
|
2341
2345
|
|
2342
|
-
|
2346
|
+
if not value.is_a?(Hash)
|
2343
2347
|
attr = attr.to_s
|
2344
2348
|
|
2345
2349
|
# Extract table name from qualified attribute names.
|
2346
|
-
if attr.include?('.')
|
2350
|
+
if attr.include?('.') and top_level
|
2347
2351
|
attr_table_name, attr = attr.split('.', 2)
|
2348
2352
|
attr_table_name = connection.quote_table_name(attr_table_name)
|
2349
2353
|
else
|
@@ -2351,8 +2355,10 @@ module ActiveRecord #:nodoc:
|
|
2351
2355
|
end
|
2352
2356
|
|
2353
2357
|
attribute_condition("#{attr_table_name}.#{connection.quote_column_name(attr)}", value)
|
2358
|
+
elsif top_level
|
2359
|
+
sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s), false)
|
2354
2360
|
else
|
2355
|
-
|
2361
|
+
raise ActiveRecord::StatementInvalid
|
2356
2362
|
end
|
2357
2363
|
end.join(' AND ')
|
2358
2364
|
|
@@ -602,14 +602,14 @@ module ActiveRecord
|
|
602
602
|
# Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time:
|
603
603
|
#
|
604
604
|
# class Person < ActiveRecord::Base
|
605
|
-
# validates_length_of :first_name, :maximum=>30
|
606
|
-
# validates_length_of :last_name, :maximum=>30, :message=>"less than %{count} if you don't mind"
|
605
|
+
# validates_length_of :first_name, :maximum => 30
|
606
|
+
# validates_length_of :last_name, :maximum => 30, :message => "less than %{count} if you don't mind"
|
607
607
|
# validates_length_of :fax, :in => 7..32, :allow_nil => true
|
608
608
|
# validates_length_of :phone, :in => 7..32, :allow_blank => true
|
609
609
|
# validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name"
|
610
|
-
# validates_length_of :
|
611
|
-
# validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with %{count} characters... don't play me
|
612
|
-
# validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least %{count} words
|
610
|
+
# validates_length_of :zip_code, :minimum => 5, :too_short => "please enter at least %{count} characters"
|
611
|
+
# validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with %{count} characters... don't play me"
|
612
|
+
# validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least %{count} words"), :tokenizer => lambda {|str| str.scan(/\w+/) }
|
613
613
|
# end
|
614
614
|
#
|
615
615
|
# Configuration options:
|
data/test/cases/finder_test.rb
CHANGED
@@ -66,6 +66,18 @@ end
|
|
66
66
|
class FinderTest < ActiveRecord::TestCase
|
67
67
|
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers
|
68
68
|
|
69
|
+
def test_find_by_id_with_hash
|
70
|
+
assert_raises(ActiveRecord::StatementInvalid) do
|
71
|
+
Post.find_by_id(:limit => 1)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_find_by_title_and_id_with_hash
|
76
|
+
assert_raises(ActiveRecord::StatementInvalid) do
|
77
|
+
Post.find_by_title_and_id('foo', :limit => 1)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
69
81
|
def test_find
|
70
82
|
assert_equal(topics(:first).title, Topic.find(1).title)
|
71
83
|
end
|
@@ -363,6 +375,22 @@ class FinderTest < ActiveRecord::TestCase
|
|
363
375
|
}
|
364
376
|
end
|
365
377
|
|
378
|
+
def test_hash_condition_find_with_improper_nested_hashes
|
379
|
+
assert_raise(ActiveRecord::StatementInvalid) {
|
380
|
+
Company.find(:first, :conditions => { :name => { :companies => { :id => 1 }}})
|
381
|
+
}
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_hash_condition_find_with_dot_in_nested_column_name
|
385
|
+
assert_raise(ActiveRecord::StatementInvalid) {
|
386
|
+
Company.find(:first, :conditions => { :name => { "companies.id" => 1 }})
|
387
|
+
}
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_hash_condition_find_with_dot_in_column_name_okay
|
391
|
+
assert Company.find(:first, :conditions => { "companies.id" => 1 })
|
392
|
+
end
|
393
|
+
|
366
394
|
def test_hash_condition_find_with_escaped_characters
|
367
395
|
Company.create("name" => "Ain't noth'n like' \#stuff")
|
368
396
|
assert Company.find(:first, :conditions => { :name => "Ain't noth'n like' \#stuff" })
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 2
|
8
7
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
8
|
+
- 15
|
9
|
+
version: 2.3.15
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- David Heinemeier Hansson
|
@@ -15,22 +14,21 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2013-01-08 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activesupport
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
24
|
requirements:
|
26
25
|
- - "="
|
27
26
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 31
|
29
27
|
segments:
|
30
28
|
- 2
|
31
29
|
- 3
|
32
|
-
-
|
33
|
-
version: 2.3.
|
30
|
+
- 15
|
31
|
+
version: 2.3.15
|
34
32
|
type: :runtime
|
35
33
|
version_requirements: *id001
|
36
34
|
description: Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties database tables and classes together for business objects, like Customer or Subscription, that can find, save, and destroy themselves without resorting to manual SQL.
|
@@ -396,6 +394,7 @@ files:
|
|
396
394
|
- test/schema/sqlite_specific_schema.rb
|
397
395
|
- examples/associations.png
|
398
396
|
- examples/performance.rb
|
397
|
+
has_rdoc: true
|
399
398
|
homepage: http://www.rubyonrails.org
|
400
399
|
licenses: []
|
401
400
|
|
@@ -406,27 +405,23 @@ rdoc_options:
|
|
406
405
|
require_paths:
|
407
406
|
- lib
|
408
407
|
required_ruby_version: !ruby/object:Gem::Requirement
|
409
|
-
none: false
|
410
408
|
requirements:
|
411
409
|
- - ">="
|
412
410
|
- !ruby/object:Gem::Version
|
413
|
-
hash: 3
|
414
411
|
segments:
|
415
412
|
- 0
|
416
413
|
version: "0"
|
417
414
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
418
|
-
none: false
|
419
415
|
requirements:
|
420
416
|
- - ">="
|
421
417
|
- !ruby/object:Gem::Version
|
422
|
-
hash: 3
|
423
418
|
segments:
|
424
419
|
- 0
|
425
420
|
version: "0"
|
426
421
|
requirements: []
|
427
422
|
|
428
423
|
rubyforge_project: activerecord
|
429
|
-
rubygems_version: 1.
|
424
|
+
rubygems_version: 1.3.6
|
430
425
|
signing_key:
|
431
426
|
specification_version: 3
|
432
427
|
summary: Implements the ActiveRecord pattern for ORM.
|