spec/integration/relation_spec.rb in active-fedora-11.0.0.rc1 vs spec/integration/relation_spec.rb in active-fedora-11.0.0.rc2

- old
+ new

@@ -13,65 +13,62 @@ after :all do Object.send(:remove_const, :Library) Object.send(:remove_const, :Book) end - subject { Library.all } + subject(:libraries) { Library.all } it "is a relation" do - expect(subject.class).to be ActiveFedora::Relation + expect(libraries.class).to be ActiveFedora::Relation end - it "is enumerable" do - expect(subject).to respond_to(:each_with_index) - end + it { is_expected.to respond_to(:each_with_index) } context "when some records exist" do before do Library.create end let!(:library1) { Library.create } describe "is cached" do before do - subject.to_a # trigger initial load + libraries.to_a # trigger initial load end - it "is loaded" do - expect(subject).to be_loaded - end + it { is_expected.to be_loaded } + it "does not reload" do expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each - subject[0] + libraries[0] end end describe "#find" do it "finds one of them" do - expect(subject.find(library1.id)).to eq library1 + expect(libraries.find(library1.id)).to eq library1 end it "finds with a block" do - expect(subject.find { |l| l.id == library1.id }).to eq library1 + expect(libraries.find { |l| l.id == library1.id }).to eq library1 end end describe "#select" do it "finds with a block" do - expect(subject.select { |l| l.id == library1.id }).to eq [library1] + expect(libraries.select { |l| l.id == library1.id }).to eq [library1] end end context "unpermitted methods" do it "excludes them" do - expect { subject.sort! }.to raise_error NoMethodError + expect { libraries.sort! }.to raise_error NoMethodError end end context "when limit is applied" do - subject { Library.create books: [Book.create, Book.create] } + subject(:libraries) { Library.create books: [Book.create, Book.create] } it "limits the number of books" do - expect(subject.books.limit(1).size).to eq 1 + expect(libraries.books.limit(1).size).to eq 1 end end end end