dbd 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Guardfile +0 -1
- data/HISTORY.txt +9 -0
- data/README.md +47 -39
- data/bin/test_1.rb +4 -4
- data/bin/test_5.rb +4 -4
- data/docs/test.rb +11 -11
- data/lib/dbd.rb +2 -2
- data/lib/dbd/context.rb +65 -0
- data/lib/dbd/context_fact.rb +76 -0
- data/lib/dbd/errors.rb +1 -1
- data/lib/dbd/fact.rb +37 -37
- data/lib/dbd/fact/collection.rb +5 -5
- data/lib/dbd/fact/factory.rb +6 -6
- data/lib/dbd/graph.rb +2 -2
- data/lib/dbd/resource.rb +25 -24
- data/lib/dbd/version.rb +1 -1
- data/spec/lib/dbd/context/context_spec.rb +74 -0
- data/spec/lib/dbd/context_fact/methods_spec.rb +79 -0
- data/spec/lib/dbd/context_fact/new_spec.rb +51 -0
- data/spec/lib/dbd/context_fact/test_factories_spec.rb +24 -0
- data/spec/lib/dbd/errors/errors_spec.rb +30 -0
- data/spec/lib/dbd/fact/collection/collection_spec.rb +58 -58
- data/spec/lib/dbd/fact/factory/factory_spec.rb +3 -3
- data/spec/lib/dbd/fact/methods_spec.rb +12 -12
- data/spec/lib/dbd/fact/new_spec.rb +9 -9
- data/spec/lib/dbd/fact/subject/test_factories_spec.rb +4 -4
- data/spec/lib/dbd/fact/test_factories_spec.rb +18 -18
- data/spec/lib/dbd/graph/add_to_graph_spec.rb +22 -22
- data/spec/lib/dbd/graph/from_csv_spec.rb +16 -16
- data/spec/lib/dbd/graph/test_factories_spec.rb +11 -11
- data/spec/lib/dbd/graph/to_csv_spec.rb +18 -18
- data/spec/lib/dbd/performance_spec.rb +4 -4
- data/spec/lib/dbd/resource/collection_spec.rb +28 -30
- data/spec/lib/dbd/resource/new_spec.rb +10 -11
- data/spec/lib/dbd/resource/test_factories_spec.rb +8 -7
- data/spec/lib/dbd/version/version_spec.rb +9 -0
- data/spec/test_factories/context.rb +16 -0
- data/spec/test_factories/{provenance_fact.rb → context_fact.rb} +6 -6
- data/spec/test_factories/fact.rb +23 -23
- data/spec/test_factories/fact/subject.rb +1 -1
- data/spec/test_factories/graph.rb +7 -7
- data/spec/test_factories/resource.rb +15 -10
- metadata +20 -16
- data/lib/dbd/provenance_fact.rb +0 -77
- data/lib/dbd/provenance_resource.rb +0 -63
- data/spec/lib/dbd/provenance_fact/methods_spec.rb +0 -78
- data/spec/lib/dbd/provenance_fact/new_spec.rb +0 -51
- data/spec/lib/dbd/provenance_fact/test_factories_spec.rb +0 -24
- data/spec/lib/dbd/provenance_resource/provenance_resource_spec.rb +0 -75
- data/spec/test_factories/provenance_resource.rb +0 -16
| @@ -16,22 +16,22 @@ module Dbd | |
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 18 | 
             
                describe '#from_CSV reads back a csv exported graph correctly' do
         | 
| 19 | 
            -
                  describe 'for a graph with only  | 
| 19 | 
            +
                  describe 'for a graph with only context_facts' do
         | 
| 20 20 |  | 
| 21 | 
            -
                    let(:graph) { TestFactories::Graph. | 
| 21 | 
            +
                    let(:graph) { TestFactories::Graph.only_context }
         | 
| 22 22 |  | 
| 23 23 | 
             
                    it 'round_trip validates' do
         | 
| 24 24 | 
             
                      validate_round_trip(graph)
         | 
| 25 25 | 
             
                    end
         | 
| 26 26 |  | 
| 27 | 
            -
                    it 'for a  | 
| 27 | 
            +
                    it 'for a context_fact, the context_subject must be equal (nil)' do
         | 
| 28 28 | 
             
                      graph_from_CSV = round_tripped_graph(graph)
         | 
| 29 | 
            -
                       | 
| 30 | 
            -
                       | 
| 29 | 
            +
                      context_fact = graph_from_CSV.first
         | 
| 30 | 
            +
                      context_fact.context_subject.should be_nil
         | 
| 31 31 | 
             
                    end
         | 
| 32 32 | 
             
                  end
         | 
| 33 33 |  | 
| 34 | 
            -
                  describe 'for a graph with facts and  | 
| 34 | 
            +
                  describe 'for a graph with facts and context_facts' do
         | 
| 35 35 |  | 
| 36 36 | 
             
                    let(:graph) { TestFactories::Graph.full }
         | 
| 37 37 |  | 
| @@ -47,15 +47,15 @@ module Dbd | |
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 49 | 
             
                describe '#from_CSV reads back _two_ csv exported graphs correctly' do
         | 
| 50 | 
            -
                  describe 'for a graph with facts and  | 
| 50 | 
            +
                  describe 'for a graph with facts and context_facts' do
         | 
| 51 51 |  | 
| 52 | 
            -
                    let(: | 
| 53 | 
            -
                    let(:graph_facts) { TestFactories::Graph.only_facts( | 
| 54 | 
            -
                    let(: | 
| 52 | 
            +
                    let(:graph_context) { TestFactories::Graph.only_context }
         | 
| 53 | 
            +
                    let(:graph_facts) { TestFactories::Graph.only_facts(graph_context.first.subject) }
         | 
| 54 | 
            +
                    let(:graph_context_csv) { graph_context.to_CSV }
         | 
| 55 55 | 
             
                    let(:graph_facts_csv) { graph_facts.to_CSV }
         | 
| 56 56 |  | 
| 57 57 | 
             
                    let(:graph_from_2_csv_s) do
         | 
| 58 | 
            -
                      stream_1 = StringIO.new( | 
| 58 | 
            +
                      stream_1 = StringIO.new(graph_context_csv)
         | 
| 59 59 | 
             
                      stream_2 = StringIO.new(graph_facts_csv)
         | 
| 60 60 | 
             
                      graph = described_class.new
         | 
| 61 61 | 
             
                      graph.from_CSV(stream_1)
         | 
| @@ -64,21 +64,21 @@ module Dbd | |
| 64 64 |  | 
| 65 65 | 
             
                    it 'round_trip validates' do
         | 
| 66 66 | 
             
                      # we do not have full graph equivalence yet
         | 
| 67 | 
            -
                      graph_from_2_csv_s.first.should be_equivalent( | 
| 67 | 
            +
                      graph_from_2_csv_s.first.should be_equivalent(graph_context.first)
         | 
| 68 68 | 
             
                      graph_from_2_csv_s.last.should be_equivalent(graph_facts.last)
         | 
| 69 69 | 
             
                    end
         | 
| 70 70 |  | 
| 71 71 | 
             
                    it 'a string concat of 2 CSV files works to logically concat them' do
         | 
| 72 | 
            -
                      graph_from_2_csv_s.to_CSV.should == ( | 
| 72 | 
            +
                      graph_from_2_csv_s.to_CSV.should == (graph_context_csv + graph_facts_csv)
         | 
| 73 73 | 
             
                    end
         | 
| 74 74 | 
             
                  end
         | 
| 75 75 | 
             
                end
         | 
| 76 76 |  | 
| 77 77 | 
             
                describe '#from_CSV reads special cases correctly' do
         | 
| 78 78 |  | 
| 79 | 
            -
                  let(: | 
| 80 | 
            -
                  let(:resource) { TestFactories::Resource.empty( | 
| 81 | 
            -
                  let(:special_fact) { TestFactories::Fact.fact_with_special_chars( | 
| 79 | 
            +
                  let(:context_subject) { TestFactories::Fact::Subject.fixed_context_subject }
         | 
| 80 | 
            +
                  let(:resource) { TestFactories::Resource.empty(context_subject) }
         | 
| 81 | 
            +
                  let(:special_fact) { TestFactories::Fact.fact_with_special_chars(context_subject, resource.subject) }
         | 
| 82 82 |  | 
| 83 83 | 
             
                  it 'as object' do
         | 
| 84 84 | 
             
                    resource << special_fact
         | 
| @@ -2,42 +2,42 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            module TestFactories
         | 
| 4 4 | 
             
              describe Graph do
         | 
| 5 | 
            -
                describe 'with only  | 
| 5 | 
            +
                describe 'with only context_facts' do
         | 
| 6 6 |  | 
| 7 | 
            -
                  let(: | 
| 7 | 
            +
                  let(:only_context) { described_class.only_context }
         | 
| 8 8 |  | 
| 9 9 | 
             
                  it 'is a Graph' do
         | 
| 10 | 
            -
                     | 
| 10 | 
            +
                    only_context.should be_a(described_class.factory_for)
         | 
| 11 11 | 
             
                  end
         | 
| 12 12 |  | 
| 13 13 | 
             
                  it 'has some facts' do
         | 
| 14 | 
            -
                     | 
| 14 | 
            +
                    only_context.size.should >= 2
         | 
| 15 15 | 
             
                  end
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 18 | 
             
                describe 'with only facts' do
         | 
| 19 19 |  | 
| 20 20 | 
             
                  let(:subject) { described_class.new_subject }
         | 
| 21 | 
            -
                  let(: | 
| 22 | 
            -
                  let(: | 
| 21 | 
            +
                  let(:only_facts_without_context_subject) { described_class.only_facts }
         | 
| 22 | 
            +
                  let(:only_facts_with_context_subject) { described_class.only_facts(subject) }
         | 
| 23 23 |  | 
| 24 | 
            -
                  describe ' | 
| 24 | 
            +
                  describe 'only_facts_without_context_subject' do
         | 
| 25 25 | 
             
                    it 'is a Graph' do
         | 
| 26 | 
            -
                       | 
| 26 | 
            +
                      only_facts_without_context_subject.should be_a(described_class.factory_for)
         | 
| 27 27 | 
             
                    end
         | 
| 28 28 |  | 
| 29 29 | 
             
                    it 'has some facts' do
         | 
| 30 | 
            -
                       | 
| 30 | 
            +
                      only_facts_without_context_subject.size.should >= 2
         | 
| 31 31 | 
             
                    end
         | 
| 32 32 | 
             
                  end
         | 
| 33 33 |  | 
| 34 34 | 
             
                  describe 'only_facts_with_subject' do
         | 
| 35 35 | 
             
                    it 'is a Graph' do
         | 
| 36 | 
            -
                       | 
| 36 | 
            +
                      only_facts_with_context_subject.should be_a(described_class.factory_for)
         | 
| 37 37 | 
             
                    end
         | 
| 38 38 |  | 
| 39 39 | 
             
                    it 'has the set subject' do
         | 
| 40 | 
            -
                       | 
| 40 | 
            +
                      only_facts_with_context_subject.first.context_subject.should == subject
         | 
| 41 41 | 
             
                    end
         | 
| 42 42 | 
             
                  end
         | 
| 43 43 | 
             
                end
         | 
| @@ -8,19 +8,19 @@ module Dbd | |
| 8 8 | 
             
                  Fact.factory.new_subject
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 | 
            -
                let(: | 
| 12 | 
            -
                let(: | 
| 13 | 
            -
                let(:fact_2_3) { TestFactories::Fact::Collection.fact_2_3( | 
| 14 | 
            -
                let(:fact_special_characters) { TestFactories::Fact::fact_with_special_chars( | 
| 11 | 
            +
                let(:context_facts) { TestFactories::Fact::Collection.context_facts(new_subject) }
         | 
| 12 | 
            +
                let(:context_fact_1) { context_facts.first }
         | 
| 13 | 
            +
                let(:fact_2_3) { TestFactories::Fact::Collection.fact_2_3(context_fact_1.subject) }
         | 
| 14 | 
            +
                let(:fact_special_characters) { TestFactories::Fact::fact_with_special_chars(context_fact_1.subject, new_subject) }
         | 
| 15 15 |  | 
| 16 16 | 
             
                let(:subject_valid_regexp) { Fact::Subject.valid_regexp }
         | 
| 17 17 | 
             
                let(:id_valid_regexp) { Fact::ID.valid_regexp }
         | 
| 18 18 | 
             
                let(:time_stamp_valid_regexp) { TimeStamp.valid_regexp }
         | 
| 19 19 |  | 
| 20 | 
            -
                describe '#to_CSV with only  | 
| 20 | 
            +
                describe '#to_CSV with only context_facts' do
         | 
| 21 21 | 
             
                  before do
         | 
| 22 | 
            -
                     | 
| 23 | 
            -
                      subject <<  | 
| 22 | 
            +
                    context_facts.each do |context_fact|
         | 
| 23 | 
            +
                      subject << context_fact
         | 
| 24 24 | 
             
                    end
         | 
| 25 25 | 
             
                  end
         | 
| 26 26 |  | 
| @@ -36,7 +36,7 @@ module Dbd | |
| 36 36 | 
             
                    subject.to_CSV.should match(/\A"[^",]+","[^",]+","[^",]*","[^",]+"/)
         | 
| 37 37 | 
             
                  end
         | 
| 38 38 |  | 
| 39 | 
            -
                  describe 'with a single  | 
| 39 | 
            +
                  describe 'with a single context_fact collection' do
         | 
| 40 40 | 
             
                    it 'has three logical lines (but one with embedded newline)' do
         | 
| 41 41 | 
             
                      subject.to_CSV.lines.count.should == 4
         | 
| 42 42 | 
             
                    end
         | 
| @@ -46,7 +46,7 @@ module Dbd | |
| 46 46 | 
             
                    end
         | 
| 47 47 | 
             
                  end
         | 
| 48 48 |  | 
| 49 | 
            -
                  describe 'has all attributes of the  | 
| 49 | 
            +
                  describe 'has all attributes of the context_collection' do
         | 
| 50 50 |  | 
| 51 51 | 
             
                    let(:first_line) do
         | 
| 52 52 | 
             
                      subject.to_CSV.lines.to_a.first.chomp
         | 
| @@ -60,7 +60,7 @@ module Dbd | |
| 60 60 | 
             
                      first_line.split(',')[1][1..-2].should match(time_stamp_valid_regexp)
         | 
| 61 61 | 
             
                    end
         | 
| 62 62 |  | 
| 63 | 
            -
                    it 'has an empty third value (signature of a  | 
| 63 | 
            +
                    it 'has an empty third value (signature of a context_fact)' do
         | 
| 64 64 | 
             
                      first_line.split(',')[2].should == '""'
         | 
| 65 65 | 
             
                    end
         | 
| 66 66 |  | 
| @@ -69,7 +69,7 @@ module Dbd | |
| 69 69 | 
             
                    end
         | 
| 70 70 |  | 
| 71 71 | 
             
                    it 'has data_predicate as 5th value' do
         | 
| 72 | 
            -
                      first_line.split(',')[4].should == '" | 
| 72 | 
            +
                      first_line.split(',')[4].should == '"context:visibility"'
         | 
| 73 73 | 
             
                    end
         | 
| 74 74 |  | 
| 75 75 | 
             
                    it 'has object as 6th value' do
         | 
| @@ -127,8 +127,8 @@ module Dbd | |
| 127 127 | 
             
                      first_line.split(',')[1][1..-2].should match(time_stamp_valid_regexp)
         | 
| 128 128 | 
             
                    end
         | 
| 129 129 |  | 
| 130 | 
            -
                    it 'has  | 
| 131 | 
            -
                      first_line.split(',')[2].should == "\"#{ | 
| 130 | 
            +
                    it 'has context_fact_1.subject as third value' do
         | 
| 131 | 
            +
                      first_line.split(',')[2].should == "\"#{context_fact_1.subject.to_s}\""
         | 
| 132 132 | 
             
                    end
         | 
| 133 133 |  | 
| 134 134 | 
             
                    it 'has subject as 4th value' do
         | 
| @@ -145,11 +145,11 @@ module Dbd | |
| 145 145 | 
             
                  end
         | 
| 146 146 | 
             
                end
         | 
| 147 147 |  | 
| 148 | 
            -
                describe '#to_CSV with  | 
| 148 | 
            +
                describe '#to_CSV with context_facts and facts' do
         | 
| 149 149 |  | 
| 150 150 | 
             
                  before do
         | 
| 151 | 
            -
                     | 
| 152 | 
            -
                      subject <<  | 
| 151 | 
            +
                    context_facts.each do |context_fact|
         | 
| 152 | 
            +
                      subject << context_fact
         | 
| 153 153 | 
             
                    end
         | 
| 154 154 | 
             
                    fact_2_3.each do |fact|
         | 
| 155 155 | 
             
                      subject << fact
         | 
| @@ -164,8 +164,8 @@ module Dbd | |
| 164 164 | 
             
                describe '#to_CSV_file' do
         | 
| 165 165 |  | 
| 166 166 | 
             
                  before do
         | 
| 167 | 
            -
                     | 
| 168 | 
            -
                      subject <<  | 
| 167 | 
            +
                    context_facts.each do |context_fact|
         | 
| 168 | 
            +
                      subject << context_fact
         | 
| 169 169 | 
             
                    end
         | 
| 170 170 | 
             
                    fact_2_3.each do |fact|
         | 
| 171 171 | 
             
                      subject << fact
         | 
| @@ -11,23 +11,23 @@ module Dbd | |
| 11 11 | 
             
                  Fact.factory.new_subject
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 | 
            -
                let(: | 
| 14 | 
            +
                let(:context_fact_1) { TestFactories::ContextFact.visibility(new_subject) }
         | 
| 15 15 |  | 
| 16 16 | 
             
                NUMBER_OF_FACTS = 10_000
         | 
| 17 17 |  | 
| 18 18 | 
             
                describe "#{NUMBER_OF_FACTS} facts" do
         | 
| 19 19 | 
             
                  it 'reports and checks the used time' do
         | 
| 20 20 | 
             
                    graph = Graph.new
         | 
| 21 | 
            -
                    graph <<  | 
| 21 | 
            +
                    graph << context_fact_1
         | 
| 22 22 | 
             
                    # Rehearsal
         | 
| 23 23 | 
             
                    NUMBER_OF_FACTS.times do |counter|
         | 
| 24 | 
            -
                      data_fact = TestFactories::Fact.data_fact( | 
| 24 | 
            +
                      data_fact = TestFactories::Fact.data_fact(context_fact_1, new_subject)
         | 
| 25 25 | 
             
                      graph << data_fact
         | 
| 26 26 | 
             
                    end
         | 
| 27 27 | 
             
                    # Actual
         | 
| 28 28 | 
             
                    start = Time.now
         | 
| 29 29 | 
             
                    NUMBER_OF_FACTS.times do |counter|
         | 
| 30 | 
            -
                      data_fact = TestFactories::Fact.data_fact( | 
| 30 | 
            +
                      data_fact = TestFactories::Fact.data_fact(context_fact_1, new_subject)
         | 
| 31 31 | 
             
                      graph << data_fact
         | 
| 32 32 | 
             
                    end
         | 
| 33 33 | 
             
                    duration = Time.now - start
         | 
| @@ -3,10 +3,8 @@ require 'spec_helper' | |
| 3 3 | 
             
            module Dbd
         | 
| 4 4 | 
             
              describe Resource do
         | 
| 5 5 |  | 
| 6 | 
            -
                let(: | 
| 7 | 
            -
             | 
| 8 | 
            -
                let(:resource) { described_class.new(provenance_subject: provenance_subject) }
         | 
| 9 | 
            -
             | 
| 6 | 
            +
                let(:context_subject) { TestFactories::ContextFact.new_subject }
         | 
| 7 | 
            +
                let(:resource) { described_class.new(context_subject: context_subject) }
         | 
| 10 8 | 
             
                let(:resource_subject) { resource.subject }
         | 
| 11 9 |  | 
| 12 10 | 
             
                describe 'the fact collection' do
         | 
| @@ -14,11 +12,11 @@ module Dbd | |
| 14 12 | 
             
                  let(:fact_2_with_subject) { TestFactories::Fact.fact_2_with_subject }
         | 
| 15 13 | 
             
                  let(:fact_3_with_subject) { TestFactories::Fact.fact_3_with_subject }
         | 
| 16 14 | 
             
                  let(:fact_without_subject) { TestFactories::Fact.data_fact }
         | 
| 17 | 
            -
                  let(: | 
| 15 | 
            +
                  let(:fact_with_context) { TestFactories::Fact.data_fact(context_subject, nil) }
         | 
| 18 16 | 
             
                  let(:fact_with_resource_subject) { TestFactories::Fact.data_fact(nil, resource_subject) }
         | 
| 19 | 
            -
                  let(: | 
| 20 | 
            -
                  let(: | 
| 21 | 
            -
                  let(: | 
| 17 | 
            +
                  let(:fact_with_context_and_resource_subject) { TestFactories::Fact.data_fact(context_subject, resource_subject) }
         | 
| 18 | 
            +
                  let(:fact_with_incorrect_context) { TestFactories::Fact.data_fact(TestFactories::ContextFact.new_subject, resource_subject) }
         | 
| 19 | 
            +
                  let(:context_fact_visibility) { TestFactories::ContextFact.visibility }
         | 
| 22 20 |  | 
| 23 21 | 
             
                  it 'enumerable functions work' do
         | 
| 24 22 | 
             
                    resource.to_a.should == []
         | 
| @@ -28,22 +26,22 @@ module Dbd | |
| 28 26 |  | 
| 29 27 | 
             
                    it 'can add a two facts (no subject set)' do
         | 
| 30 28 | 
             
                      resource << fact_without_subject
         | 
| 31 | 
            -
                      resource <<  | 
| 29 | 
            +
                      resource << fact_with_context
         | 
| 32 30 | 
             
                      resource.size.should == 2
         | 
| 33 31 | 
             
                    end
         | 
| 34 32 |  | 
| 35 | 
            -
                    it 'complains if a  | 
| 36 | 
            -
                      lambda{ resource <<  | 
| 33 | 
            +
                    it 'complains if a context_subject is added' do
         | 
| 34 | 
            +
                      lambda{ resource << context_fact_visibility }.should raise_error(
         | 
| 37 35 | 
             
                        ArgumentError,
         | 
| 38 | 
            -
                        'Trying to add a  | 
| 36 | 
            +
                        'Trying to add a ContextFact to a Resource.')
         | 
| 39 37 | 
             
                     end
         | 
| 40 38 |  | 
| 41 39 | 
             
                    describe 'checks and sets subject :' do
         | 
| 42 40 | 
             
                      describe 'adding a fact with subject :' do
         | 
| 43 41 | 
             
                        describe 'when the subject of the fact is equal to the resource_subject' do
         | 
| 44 42 | 
             
                          it 'inserts the fact unaltered' do
         | 
| 45 | 
            -
                            resource <<  | 
| 46 | 
            -
                            resource.first.should be_equal( | 
| 43 | 
            +
                            resource << fact_with_context_and_resource_subject
         | 
| 44 | 
            +
                            resource.first.should be_equal(fact_with_context_and_resource_subject)
         | 
| 47 45 | 
             
                          end
         | 
| 48 46 | 
             
                        end
         | 
| 49 47 |  | 
| @@ -60,7 +58,7 @@ module Dbd | |
| 60 58 | 
             
                      describe 'adding a fact without subject' do
         | 
| 61 59 |  | 
| 62 60 | 
             
                        before(:each) do
         | 
| 63 | 
            -
                          resource <<  | 
| 61 | 
            +
                          resource << fact_with_context
         | 
| 64 62 | 
             
                        end
         | 
| 65 63 |  | 
| 66 64 | 
             
                        let(:fact_in_resource) do
         | 
| @@ -68,12 +66,12 @@ module Dbd | |
| 68 66 | 
             
                        end
         | 
| 69 67 |  | 
| 70 68 | 
             
                        it 'insert the same instance' do
         | 
| 71 | 
            -
                          fact_in_resource.should be_equal( | 
| 69 | 
            +
                          fact_in_resource.should be_equal(fact_with_context)
         | 
| 72 70 | 
             
                        end
         | 
| 73 71 |  | 
| 74 72 | 
             
                        it 'has kept the other attributes' do
         | 
| 75 | 
            -
                          ( | 
| 76 | 
            -
                            fact_in_resource.send(attr).should ==  | 
| 73 | 
            +
                          (fact_with_context.class.attributes - [:subject]).each do |attr|
         | 
| 74 | 
            +
                            fact_in_resource.send(attr).should == fact_with_context.send(attr)
         | 
| 77 75 | 
             
                          end
         | 
| 78 76 | 
             
                        end
         | 
| 79 77 |  | 
| @@ -83,26 +81,26 @@ module Dbd | |
| 83 81 | 
             
                      end
         | 
| 84 82 | 
             
                    end
         | 
| 85 83 |  | 
| 86 | 
            -
                    describe 'checks and sets  | 
| 87 | 
            -
                      describe 'adding a fact with a  | 
| 88 | 
            -
                        describe 'when the  | 
| 84 | 
            +
                    describe 'checks and sets context_subject :' do
         | 
| 85 | 
            +
                      describe 'adding a fact with a context_fact subject :' do
         | 
| 86 | 
            +
                        describe 'when the context_subject of the fact is equal to the context_subject of the resource' do
         | 
| 89 87 | 
             
                          it 'inserts the fact unaltered' do
         | 
| 90 | 
            -
                            resource <<  | 
| 91 | 
            -
                            resource.single.should be_equal( | 
| 88 | 
            +
                            resource << fact_with_context_and_resource_subject
         | 
| 89 | 
            +
                            resource.single.should be_equal(fact_with_context_and_resource_subject)
         | 
| 92 90 | 
             
                          end
         | 
| 93 91 | 
             
                        end
         | 
| 94 92 |  | 
| 95 | 
            -
                        describe 'when the  | 
| 93 | 
            +
                        describe 'when the context_subject of the fact is not equal to the resource' do
         | 
| 96 94 | 
             
                          it 'raises a SetOnceError' do
         | 
| 97 | 
            -
                            lambda{ resource <<  | 
| 95 | 
            +
                            lambda{ resource << fact_with_incorrect_context }.should raise_error(
         | 
| 98 96 | 
             
                              RubyPeterV::SetOnceError,
         | 
| 99 | 
            -
                              "Value of  | 
| 100 | 
            -
                              "trying to set it to #{resource. | 
| 97 | 
            +
                              "Value of context_subject was #{fact_with_incorrect_context.context_subject}, " \
         | 
| 98 | 
            +
                              "trying to set it to #{resource.context_subject}")
         | 
| 101 99 | 
             
                          end
         | 
| 102 100 | 
             
                        end
         | 
| 103 101 | 
             
                      end
         | 
| 104 102 |  | 
| 105 | 
            -
                      describe 'adding a fact without  | 
| 103 | 
            +
                      describe 'adding a fact without context_subject' do
         | 
| 106 104 |  | 
| 107 105 | 
             
                        before(:each) do
         | 
| 108 106 | 
             
                          resource << fact_with_resource_subject
         | 
| @@ -114,8 +112,8 @@ module Dbd | |
| 114 112 | 
             
                          fact_in_resource.should be_equal(fact_with_resource_subject)
         | 
| 115 113 | 
             
                        end
         | 
| 116 114 |  | 
| 117 | 
            -
                        it 'has set the  | 
| 118 | 
            -
                         fact_in_resource. | 
| 115 | 
            +
                        it 'has set the context_subject to the Resource context_subject' do
         | 
| 116 | 
            +
                         fact_in_resource.context_subject.should == context_subject
         | 
| 119 117 | 
             
                        end
         | 
| 120 118 | 
             
                      end
         | 
| 121 119 | 
             
                    end
         | 
| @@ -3,9 +3,8 @@ require 'spec_helper' | |
| 3 3 | 
             
            module Dbd
         | 
| 4 4 | 
             
              describe Resource do
         | 
| 5 5 |  | 
| 6 | 
            -
                let(: | 
| 7 | 
            -
             | 
| 8 | 
            -
                let(:resource) { described_class.new(provenance_subject: provenance_subject) }
         | 
| 6 | 
            +
                let(:context_subject) { TestFactories::ContextFact.new_subject }
         | 
| 7 | 
            +
                let(:resource) { described_class.new(context_subject: context_subject) }
         | 
| 9 8 |  | 
| 10 9 | 
             
                describe '.new_subject' do
         | 
| 11 10 | 
             
                  it 'returns a Fact#new_subject' do
         | 
| @@ -14,13 +13,13 @@ module Dbd | |
| 14 13 | 
             
                end
         | 
| 15 14 |  | 
| 16 15 | 
             
                describe '.new' do
         | 
| 17 | 
            -
                  describe 'with a  | 
| 16 | 
            +
                  describe 'with a context_subject argument' do
         | 
| 18 17 | 
             
                    it 'has created a subject' do
         | 
| 19 18 | 
             
                      resource.subject.should be_a(described_class.new_subject.class)
         | 
| 20 19 | 
             
                    end
         | 
| 21 20 |  | 
| 22 | 
            -
                    it 'has stored the  | 
| 23 | 
            -
                      resource. | 
| 21 | 
            +
                    it 'has stored the context_subject' do
         | 
| 22 | 
            +
                      resource.context_subject.should == context_subject
         | 
| 24 23 | 
             
                    end
         | 
| 25 24 | 
             
                  end
         | 
| 26 25 |  | 
| @@ -29,14 +28,14 @@ module Dbd | |
| 29 28 | 
             
                      explicit_subject = described_class.new_subject
         | 
| 30 29 | 
             
                      described_class.new(
         | 
| 31 30 | 
             
                        subject: explicit_subject,
         | 
| 32 | 
            -
                         | 
| 31 | 
            +
                        context_subject: context_subject).subject.should == explicit_subject
         | 
| 33 32 | 
             
                    end
         | 
| 34 33 | 
             
                  end
         | 
| 35 34 |  | 
| 36 | 
            -
                  describe 'with a nil  | 
| 37 | 
            -
                    it 'raises a  | 
| 38 | 
            -
                      lambda { described_class.new( | 
| 39 | 
            -
                        should raise_error  | 
| 35 | 
            +
                  describe 'with a nil context_subject argument' do
         | 
| 36 | 
            +
                    it 'raises a ContextError' do
         | 
| 37 | 
            +
                      lambda { described_class.new(context_subject: nil) } .
         | 
| 38 | 
            +
                        should raise_error ContextError
         | 
| 40 39 | 
             
                    end
         | 
| 41 40 | 
             
                  end
         | 
| 42 41 | 
             
                end
         | 
| @@ -3,21 +3,22 @@ require 'spec_helper' | |
| 3 3 | 
             
            module TestFactories
         | 
| 4 4 | 
             
              describe Resource do
         | 
| 5 5 |  | 
| 6 | 
            -
                let(: | 
| 6 | 
            +
                let(:context_subject) { TestFactories::ContextFact.new_subject }
         | 
| 7 7 |  | 
| 8 8 | 
             
                describe "TestFactories::Resource" do
         | 
| 9 9 | 
             
                  it ".empty works" do
         | 
| 10 | 
            -
                    described_class. | 
| 10 | 
            +
                    resource = described_class.empty(context_subject)
         | 
| 11 | 
            +
                    resource.context_subject.should == context_subject
         | 
| 11 12 | 
             
                  end
         | 
| 12 13 |  | 
| 13 | 
            -
                   | 
| 14 | 
            -
                    it "works with explicit  | 
| 15 | 
            -
                      described_class.facts_resource( | 
| 14 | 
            +
                  describe ".facts_resource" do
         | 
| 15 | 
            +
                    it "works with explicit context_subject" do
         | 
| 16 | 
            +
                      described_class.facts_resource(context_subject)
         | 
| 16 17 | 
             
                    end
         | 
| 17 18 |  | 
| 18 | 
            -
                    it "works without explicit  | 
| 19 | 
            +
                    it "works without explicit context_subject" do
         | 
| 19 20 | 
             
                      resource = described_class.facts_resource()
         | 
| 20 | 
            -
                      resource. | 
| 21 | 
            +
                      resource.context_subject.should_not be_nil
         | 
| 21 22 | 
             
                    end
         | 
| 22 23 | 
             
                  end
         | 
| 23 24 | 
             
                end
         |