spec/active_triples/resource_spec.rb in active-triples-0.7.3 vs spec/active_triples/resource_spec.rb in active-triples-0.7.4

- old
+ new

@@ -88,10 +88,50 @@ expect(subject.rdf_subject).to eq RDF::URI('http://example.org/moomin') end end end + describe "#reload" do + context 'with a repository' do + let(:resource) { DummyResourceWithRepo.new } + let(:repository) { RDF::Repository.new } + before do + class DummyResourceWithRepo < ActiveTriples::Resource + configure repository: :default + property :title, predicate: RDF::DC.title + end + ActiveTriples::Repositories.add_repository :default, repository + + resource.title = "bla" + end + after do + Object.send(:remove_const, :DummyResourceWithRepo) + ActiveTriples::Repositories.clear_repositories! + end + + context "and a persisted resource" do + before do + resource.persist! + resource.title = 'Foo' + resource.reload + end + subject { resource.title } + it { is_expected.to eq ['Foo'] } + end + + context "and a b-node" do + before do + expect(repository).not_to receive(:query).with(subject: resource.rdf_subject) + resource.reload + resource.title = 'Foo' + end + subject { resource.title } + it { is_expected.to eq ['Foo'] } + end + end + end + describe "#persisted?" do context 'with a repository' do before do repository = RDF::Repository.new allow(subject).to receive(:repository).and_return(repository) @@ -120,9 +160,10 @@ it "should return true" do expect(subject).to be_persisted end end + context "and then reloaded" do before do subject.reload end