Skip to content

Commit

Permalink
string IDs are now quoted correctly [#5064 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
wsc authored and josevalim committed Jul 13, 2010
1 parent 44e7fba commit b520d60
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 2 deletions.
Expand Up @@ -35,7 +35,7 @@ def construct_quoted_owner_attributes(reflection)
@owner.class.base_class.name.to_s,
reflection.klass.columns_hash["#{as}_type"]) }
elsif reflection.macro == :belongs_to
{ reflection.klass.primary_key => @owner[reflection.primary_key_name] }
{ reflection.klass.primary_key => @owner.class.quote_value(@owner[reflection.primary_key_name]) }
else
{ reflection.primary_key_name => owner_quoted_id }
end
Expand Down
Expand Up @@ -6,9 +6,12 @@
require 'models/sponsor'
require 'models/organization'
require 'models/member_detail'
require 'models/minivan'
require 'models/dashboard'
require 'models/speedometer'

class HasOneThroughAssociationsTest < ActiveRecord::TestCase
fixtures :member_types, :members, :clubs, :memberships, :sponsors, :organizations
fixtures :member_types, :members, :clubs, :memberships, :sponsors, :organizations, :minivans, :dashboards, :speedometers

def setup
@member = members(:groucho)
Expand Down Expand Up @@ -202,4 +205,11 @@ def test_save_of_record_with_loaded_has_one_through
Club.find(@club.id, :include => :sponsored_member).save!
end
end

def test_value_is_properly_quoted
minivan = Minivan.find('m1')
assert_nothing_raised do
minivan.dashboard
end
end
end
3 changes: 3 additions & 0 deletions activerecord/test/fixtures/dashboards.yml
@@ -0,0 +1,3 @@
cool_first:
dashboard_id: d1
name: my_dashboard
4 changes: 4 additions & 0 deletions activerecord/test/fixtures/minivans.yml
@@ -0,0 +1,4 @@
cool_first:
minivan_id: m1
name: my_minivan
speedometer_id: s1
4 changes: 4 additions & 0 deletions activerecord/test/fixtures/speedometers.yml
@@ -0,0 +1,4 @@
cool_first:
speedometer_id: s1
name: my_speedometer
dashboard_id: d1
3 changes: 3 additions & 0 deletions activerecord/test/models/dashboard.rb
@@ -0,0 +1,3 @@
class Dashboard < ActiveRecord::Base
set_primary_key :dashboard_id
end
6 changes: 6 additions & 0 deletions activerecord/test/models/minivan.rb
@@ -0,0 +1,6 @@
class Minivan < ActiveRecord::Base
set_primary_key :minivan_id

belongs_to :speedometer
has_one :dashboard, :through => :speedometer
end
4 changes: 4 additions & 0 deletions activerecord/test/models/speedometer.rb
@@ -0,0 +1,4 @@
class Speedometer < ActiveRecord::Base
set_primary_key :speedometer_id
belongs_to :dashboard
end
17 changes: 17 additions & 0 deletions activerecord/test/schema/schema.rb
Expand Up @@ -164,6 +164,11 @@ def create_table(*args, &block)
t.string :address_country
t.string :gps_location
end

create_table :dashboards, :force => true, :id => false do |t|
t.string :dashboard_id
t.string :name
end

create_table :developers, :force => true do |t|
t.string :name
Expand Down Expand Up @@ -290,6 +295,12 @@ def create_table(*args, &block)
t.boolean :favourite
t.integer :lock_version, :default => 0
end

create_table :minivans, :force => true, :id => false do |t|
t.string :minivan_id
t.string :name
t.string :speedometer_id
end

create_table :minimalistics, :force => true do |t|
end
Expand Down Expand Up @@ -452,6 +463,12 @@ def create_table(*args, &block)
t.string :name
t.integer :ship_id
end

create_table :speedometers, :force => true, :id => false do |t|
t.string :speedometer_id
t.string :name
t.string :dashboard_id
end

create_table :sponsors, :force => true do |t|
t.integer :club_id
Expand Down

0 comments on commit b520d60

Please sign in to comment.