Skip to content

Commit

Permalink
Add tests for virtual_delegate has_one
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Jun 8, 2018
1 parent f33a768 commit 836ea6a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/lib/extensions/ar_virtual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 836ea6a

Please sign in to comment.