Skip to content

Commit c35cc65

Browse files
committed
spec changes: add prefix-less test
also prep for dropping name2
1 parent e52c4af commit c35cc65

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

spec/db/models.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def book_with_most_bookmarks
116116
virtual_has_many :famous_co_authors, :uses => [:book_with_most_bookmarks, {:books => :co_authors}]
117117

118118
def self.create_with_books(count)
119-
create!(:name => "foo").tap { |author| author.create_books(count) }
119+
create!(:name => "foo", :blurb => "blah blah blah").tap { |author| author.create_books(count) }
120120
end
121121

122122
def create_books(count, create_attrs = {})
@@ -147,6 +147,9 @@ class Book < VirtualTotalTestBase
147147
virtual_delegate :name, :to => :author, :prefix => true, :type => :string
148148
# this tests delegates to named child attribute
149149
virtual_delegate :author_name2, :to => "author.name", :type => :string
150+
# delegate without a prefix
151+
virtual_delegate :blurb, :to => :author, :type => :string
152+
150153
# delegate to a polymorphic
151154
virtual_delegate :description, :to => :current_photo, :prefix => true, :type => :string, :allow_nil => true
152155

spec/db/schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
t.integer "teacher_id", :index => true
88
t.string "name"
99
t.string "nickname"
10+
t.string "blurb"
1011
end
1112

1213
create_table "books", :force => true do |t|

spec/virtual_includes_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
let(:author_name) { "foo" }
77
let(:book_name) { "bar" }
8+
let(:blurb_text) { "blah blah blah" }
9+
810
# NOTE: each of the 1 authors has an array of books. so this value is [[Book, Book]]
911
let(:named_books) { [Book.where.not(:name => nil).order(:id).load] }
1012

@@ -41,8 +43,8 @@
4143
end
4244

4345
it "preloads virtual_attribute (:uses => :author, :uses => :author)" do
44-
expect(Book.includes(:author_name, :author_name2)).to preload_values(:author_name, author_name)
45-
expect(Book.includes(:author_name2 => {})).to preload_values(:author_name, author_name)
46+
expect(Book.includes(:author_name, :blurb)).to preload_values(:author_name, author_name)
47+
expect(Book.includes(:author_name => {})).to preload_values(:blurb, blurb_text)
4648
end
4749

4850
it "preloads virtual_attribute (:uses => :upper_author_name) (:uses => :author_name)" do
@@ -526,7 +528,7 @@
526528
end
527529

528530
it "handles hash form of delegates" do
529-
expect(Book.replace_virtual_fields([{:author_name => {}}, {:author_name2 => {}}])).to eq([:author, :author])
531+
expect(Book.replace_virtual_fields([{:author_name => {}}, {:blurb => {}}])).to eq([:author, :author])
530532
end
531533

532534
it "handles non-'includes' virtual_attributes" do

0 commit comments

Comments
 (0)