Skip to content

Commit

Permalink
Corrected method call to :loaded! in HasManyAssociation (fixes #383)
Browse files Browse the repository at this point in the history
  • Loading branch information
dchandekstark committed Apr 4, 2014
1 parent 81378f5 commit bf13b91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/active_fedora/associations/has_many_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def count_records
# If there's nothing in the database and @target has no new records
# we are certain the current target is an empty array. This is a
# documented side-effect of the method that may avoid an extra SELECT.
@target ||= [] and loaded if count == 0
@target ||= [] and loaded! if count == 0

return count
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/associations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class Publisher < ActiveFedora::Base

it "should let you shift onto the association" do
@library.new_record?.should be_true
@library.books.size == 0
@library.books.size.should == 0
@library.books.should == []
@library.book_ids.should ==[]
@library.book_ids.should == []
@library.books << @book
@library.books.should == [@book]
@library.book_ids.should ==[@book.pid]
Expand Down
14 changes: 12 additions & 2 deletions spec/integration/has_many_associations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "Looking up collection members" do
describe "Collection members" do
before :all do
class Library < ActiveFedora::Base
has_many :books
Expand All @@ -14,7 +14,17 @@ class Book < ActiveFedora::Base
Object.send(:remove_const, :Book)
Object.send(:remove_const, :Library)
end
describe "of has_many" do
describe "size of has_many" do
let(:library) { Library.create }
context "when no members" do
it "should cache the count" do
expect(library.books).not_to be_loaded
expect(library.books.size).to eq(0)
expect(library.books).to be_loaded
end
end
end
describe "looking up has_many" do
let(:book) { Book.create }
let(:library) { Library.create() }
before do
Expand Down

0 comments on commit bf13b91

Please sign in to comment.