diff --git a/spec/lib/extensions/ar_virtual_spec.rb b/spec/lib/extensions/ar_virtual_spec.rb index b0b0f2a3cbd0..584e364b215b 100644 --- a/spec/lib/extensions/ar_virtual_spec.rb +++ b/spec/lib/extensions/ar_virtual_spec.rb @@ -622,11 +622,15 @@ def self.connection include VirtualFields end + + class CompSys < ComputerSystem + end end after do TestOtherClass.remove_connection Object.send(:remove_const, :TestOtherClass) + Object.send(:remove_const, :CompSys) end it "delegates to another table" do @@ -644,6 +648,15 @@ def self.connection sql = TestOtherClass.all.select(:id, :ocol1, TestOtherClass.arel_attribute(:col1).as("x")).to_sql expect(sql).to match(/"test_classes"."col1"/i) end + + it "delegates has_one relationships with limit 1" do + CompSys.virtual_delegate :name, :to => :operating_system, :prefix => true + comp_sys = CompSys.create! + OperatingSystem.create(:name => "foo", :computer_system_id => comp_sys.id) + OperatingSystem.create(:name => "bar", :computer_system_id => comp_sys.id) + query = CompSys.all.select(:id, :operating_system_name) + expect(query.map(&:operating_system_name)).to match_array(["foo"]) + end end end