om 1.8.1 → 1.9.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/Rakefile +1 -1
  2. data/container_spec.rb +14 -14
  3. data/lib/om.rb +12 -9
  4. data/lib/om/samples/mods_article.rb +9 -9
  5. data/lib/om/tree_node.rb +6 -6
  6. data/lib/om/version.rb +1 -1
  7. data/lib/om/xml.rb +33 -31
  8. data/lib/om/xml/container.rb +12 -12
  9. data/lib/om/xml/document.rb +19 -18
  10. data/lib/om/xml/dynamic_node.rb +50 -45
  11. data/lib/om/xml/named_term_proxy.rb +13 -13
  12. data/lib/om/xml/node_generator.rb +3 -3
  13. data/lib/om/xml/template_registry.rb +26 -18
  14. data/lib/om/xml/term.rb +46 -30
  15. data/lib/om/xml/term_value_operators.rb +56 -52
  16. data/lib/om/xml/term_xpath_generator.rb +57 -51
  17. data/lib/om/xml/terminology.rb +10 -8
  18. data/lib/om/xml/terminology_based_solrizer.rb +90 -0
  19. data/lib/om/xml/validation.rb +19 -19
  20. data/lib/om/xml/vocabulary.rb +4 -4
  21. data/lib/tasks/om.rake +6 -4
  22. data/om.gemspec +2 -1
  23. data/spec/fixtures/mods_article.rb +90 -0
  24. data/spec/fixtures/mods_articles/hydrangea_article1.xml +2 -2
  25. data/spec/integration/differentiated_elements_spec.rb +2 -2
  26. data/spec/integration/element_value_spec.rb +13 -13
  27. data/spec/integration/proxies_and_ref_spec.rb +15 -15
  28. data/spec/integration/querying_documents_spec.rb +18 -24
  29. data/spec/integration/rights_metadata_integration_example_spec.rb +18 -18
  30. data/spec/integration/selective_querying_spec.rb +1 -1
  31. data/spec/integration/serialization_spec.rb +13 -13
  32. data/spec/integration/set_reentrant_terminology_spec.rb +10 -10
  33. data/spec/integration/xpathy_stuff_spec.rb +16 -16
  34. data/spec/spec_helper.rb +2 -2
  35. data/spec/unit/container_spec.rb +29 -28
  36. data/spec/unit/document_spec.rb +50 -49
  37. data/spec/unit/dynamic_node_spec.rb +45 -57
  38. data/spec/unit/named_term_proxy_spec.rb +16 -16
  39. data/spec/unit/node_generator_spec.rb +7 -7
  40. data/spec/unit/nokogiri_sanity_spec.rb +30 -30
  41. data/spec/unit/om_spec.rb +5 -5
  42. data/spec/unit/template_registry_spec.rb +69 -69
  43. data/spec/unit/term_builder_spec.rb +77 -77
  44. data/spec/unit/term_spec.rb +73 -79
  45. data/spec/unit/term_value_operators_spec.rb +191 -186
  46. data/spec/unit/term_xpath_generator_spec.rb +43 -37
  47. data/spec/unit/terminology_builder_spec.rb +85 -85
  48. data/spec/unit/terminology_spec.rb +98 -98
  49. data/spec/unit/validation_spec.rb +22 -22
  50. data/spec/unit/xml_serialization_spec.rb +22 -21
  51. data/spec/unit/xml_spec.rb +7 -7
  52. data/spec/unit/xml_terminology_based_solrizer_spec.rb +109 -0
  53. metadata +57 -17
  54. checksums.yaml +0 -7
  55. data/.rspec +0 -1
  56. data/.rubocop.yml +0 -1
  57. data/.rubocop_todo.yml +0 -382
  58. data/.travis.yml +0 -10
  59. data/gemfiles/gemfile.rails3 +0 -11
  60. data/gemfiles/gemfile.rails4 +0 -10
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "OM::XML::Term::Builder" do
4
-
4
+
5
5
  before(:each) do
6
6
  @test_terminology_builder = OM::XML::Terminology::Builder.new do |t|
7
7
  t.fruit_trees {
8
8
  t.citrus(:attributes=>{"citric_acid"=>"true"}, :index_as=>[:facetable]) {
9
9
  t.randomness
10
10
  }
11
- t.stone_fruit(:path=>"prunus", :attributes=>{:genus=>"Prunus"})
11
+ t.stone_fruit(:path=>"prunus", :attributes=>{:genus=>"Prunus"})
12
12
  t.peach(:ref=>[:fruit_trees, :stone_fruit], :attributes=>{:subgenus=>"Amygdalus", :species=>"Prunus persica"})
13
13
  t.nectarine(:ref=>[:fruit_trees, :peach], :attributes=>{:cultivar=>"nectarine"})
14
14
  t.almond(:ref=>[:fruit_trees, :peach], :attributes=>{:species=>"Prunus dulcis"})
@@ -17,184 +17,184 @@ describe "OM::XML::Term::Builder" do
17
17
  t.banana(:ref=>:coconut)
18
18
  t.pineapple(:ref=>:banana)
19
19
  end
20
-
21
- @citrus = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :citrus)
20
+
21
+ @citrus = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :citrus)
22
22
  @stone_fruit = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :stone_fruit)
23
- @peach = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :peach)
24
- @nectarine = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :nectarine)
25
- @almond = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :almond)
26
- @pineapple = @test_terminology_builder.retrieve_term_builder(:pineapple)
23
+ @peach = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :peach)
24
+ @nectarine = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :nectarine)
25
+ @almond = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :almond)
26
+ @pineapple = @test_terminology_builder.retrieve_term_builder(:pineapple)
27
27
  end
28
-
28
+
29
29
  before(:each) do
30
- @test_builder = OM::XML::Term::Builder.new("term1")
30
+ @test_builder = OM::XML::Term::Builder.new("term1")
31
31
  @test_builder_2 = OM::XML::Term::Builder.new("term2")
32
32
  end
33
-
33
+
34
34
  describe '#new' do
35
35
  it "should set terminology_builder attribute if provided" do
36
- mock_terminology_builder = double("TerminologyBuilder")
37
- expect(OM::XML::Term::Builder.new("term1", mock_terminology_builder).terminology_builder).to eq(mock_terminology_builder)
36
+ mock_terminology_builder = mock("TerminologyBuilder")
37
+ OM::XML::Term::Builder.new("term1", mock_terminology_builder).terminology_builder.should == mock_terminology_builder
38
38
  end
39
39
  end
40
-
40
+
41
41
  describe "configuration methods" do
42
42
  it "should set the corresponding .settings value return the mapping object" do
43
43
  [:path, :index_as, :required, :type, :variant_of, :path, :attributes, :default_content_path].each do |method_name|
44
- expect(@test_builder.send(method_name, "#{method_name.to_s}foo")).to eq(@test_builder)
45
- expect(@test_builder.settings[method_name]).to eq("#{method_name.to_s}foo")
44
+ @test_builder.send(method_name, "#{method_name.to_s}foo").should == @test_builder
45
+ @test_builder.settings[method_name].should == "#{method_name.to_s}foo"
46
46
  end
47
47
  end
48
48
  it "should be chainable" do
49
- test_builder = OM::XML::Term::Builder.new("chainableTerm").index_as(:facetable, :searchable, :sortable, :displayable).required(true).type(:text)
49
+ test_builder = OM::XML::Term::Builder.new("chainableTerm").index_as(:facetable, :searchable, :sortable, :displayable).required(true).type(:text)
50
50
  resulting_settings = test_builder.settings
51
- expect(resulting_settings[:index_as]).to eq([:facetable, :searchable, :sortable, :displayable])
52
- expect(resulting_settings[:required]).to eq(true)
53
- expect(resulting_settings[:type]).to eq(:text)
51
+ resulting_settings[:index_as].should == [:facetable, :searchable, :sortable, :displayable]
52
+ resulting_settings[:required].should == true
53
+ resulting_settings[:type].should == :text
54
54
  end
55
55
  end
56
56
 
57
57
  describe "settings" do
58
58
  describe "defaults" do
59
59
  it "should be set" do
60
- expect(@test_builder.settings[:required]).to eq(false)
61
- expect(@test_builder.settings[:type]).to eq(:string)
62
- expect(@test_builder.settings[:variant_of]).to be_nil
63
- expect(@test_builder.settings[:attributes]).to be_nil
64
- expect(@test_builder.settings[:default_content_path]).to be_nil
60
+ @test_builder.settings[:required].should == false
61
+ @test_builder.settings[:type].should == :string
62
+ @test_builder.settings[:variant_of].should be_nil
63
+ @test_builder.settings[:attributes].should be_nil
64
+ @test_builder.settings[:default_content_path].should be_nil
65
65
  end
66
66
  end
67
67
  describe ":data_type" do
68
68
  it "is deprecated and should be assinged to the :type setting" do
69
69
  deprecated_term = OM::XML::Term::Builder.new("depreated_term").data_type(:thing)
70
- expect(deprecated_term.settings[:type]).to eq(:thing)
71
- end
70
+ deprecated_term.settings[:type].should == :thing
71
+ end
72
72
  end
73
73
  end
74
-
74
+
75
75
  describe ".add_child" do
76
76
  it "should insert the given Term Builder into the current Term Builder's children" do
77
77
  @test_builder.add_child(@test_builder_2)
78
- expect(@test_builder.children[@test_builder_2.name]).to eq(@test_builder_2)
79
- expect(@test_builder.ancestors).to include(@test_builder_2)
78
+ @test_builder.children[@test_builder_2.name].should == @test_builder_2
79
+ @test_builder.ancestors.should include(@test_builder_2)
80
80
  end
81
81
  end
82
82
  describe ".retrieve_child" do
83
83
  it "should fetch the child identified by the given name" do
84
84
  @test_builder.add_child(@test_builder_2)
85
- expect(@test_builder.retrieve_child(@test_builder_2.name)).to eq(@test_builder.children[@test_builder_2.name])
85
+ @test_builder.retrieve_child(@test_builder_2.name).should == @test_builder.children[@test_builder_2.name]
86
86
  end
87
87
  end
88
88
  describe ".children" do
89
89
  it "should return a hash of Term Builders that are the children of the current object, indexed by name" do
90
90
  @test_builder.add_child(@test_builder_2)
91
- expect(@test_builder.children[@test_builder_2.name]).to eq(@test_builder_2)
91
+ @test_builder.children[@test_builder_2.name].should == @test_builder_2
92
92
  end
93
93
  end
94
-
94
+
95
95
  describe ".build" do
96
96
  it "should build a Term with the given settings and generate its xpath values" do
97
- test_builder = OM::XML::Term::Builder.new("requiredTextFacet").index_as([:facetable, :searchable, :sortable, :displayable]).required(true).type(:text)
97
+ test_builder = OM::XML::Term::Builder.new("requiredTextFacet").index_as([:facetable, :searchable, :sortable, :displayable]).required(true).type(:text)
98
98
  result = test_builder.build
99
- expect(result).to be_instance_of OM::XML::Term
100
- expect(result.index_as).to eq([:facetable, :searchable, :sortable, :displayable])
101
- expect(result.required).to eq(true)
102
- expect(result.type).to eq(:text)
103
-
104
- expect(result.xpath).to eq(OM::XML::TermXpathGenerator.generate_absolute_xpath(result))
105
- expect(result.xpath_constrained).to eq(OM::XML::TermXpathGenerator.generate_constrained_xpath(result))
106
- expect(result.xpath_relative).to eq(OM::XML::TermXpathGenerator.generate_relative_xpath(result))
99
+ result.should be_instance_of OM::XML::Term
100
+ result.index_as.should == [:facetable, :searchable, :sortable, :displayable]
101
+ result.required.should == true
102
+ result.type.should == :text
103
+
104
+ result.xpath.should == OM::XML::TermXpathGenerator.generate_absolute_xpath(result)
105
+ result.xpath_constrained.should == OM::XML::TermXpathGenerator.generate_constrained_xpath(result)
106
+ result.xpath_relative.should == OM::XML::TermXpathGenerator.generate_relative_xpath(result)
107
107
  end
108
108
  it "should create proxy terms if :proxy is set" do
109
109
  test_builder = OM::XML::Term::Builder.new("my_proxy").proxy([:foo, :bar])
110
110
  result = test_builder.build
111
- expect(result).to be_kind_of OM::XML::NamedTermProxy
111
+ result.should be_kind_of OM::XML::NamedTermProxy
112
112
  end
113
113
  it "should set path to match name if it is empty" do
114
- expect(@test_builder.settings[:path]).to be_nil
115
- expect(@test_builder.build.path).to eq(@test_builder.name.to_s)
114
+ @test_builder.settings[:path].should be_nil
115
+ @test_builder.build.path.should == @test_builder.name.to_s
116
116
  end
117
117
  it "should work recursively, calling .build on any of its children" do
118
- allow_any_instance_of(OM::XML::Term).to receive(:generate_xpath_queries!)
118
+ OM::XML::Term.any_instance.stub(:generate_xpath_queries!)
119
119
  built_child1 = OM::XML::Term.new("child1")
120
120
  built_child2 = OM::XML::Term.new("child2")
121
121
 
122
- mock1 = double("Builder1", :build => built_child1 )
123
- mock2 = double("Builder2", :build => built_child2 )
124
- allow(mock1).to receive(:name).and_return("child1")
125
- allow(mock2).to receive(:name).and_return("child2")
122
+ mock1 = mock("Builder1", :build => built_child1 )
123
+ mock2 = mock("Builder2", :build => built_child2 )
124
+ mock1.stub(:name).and_return("child1")
125
+ mock2.stub(:name).and_return("child2")
126
126
 
127
127
  @test_builder.children = {:mock1=>mock1, :mock2=>mock2}
128
128
  result = @test_builder.build
129
- expect(result.children[:child1]).to eq(built_child1)
130
- expect(result.children[:child2]).to eq(built_child2)
131
- expect(result.children.length).to eq(2)
129
+ result.children[:child1].should == built_child1
130
+ result.children[:child2].should == built_child2
131
+ result.children.length.should == 2
132
132
  end
133
133
  end
134
-
134
+
135
135
  describe ".lookup_refs" do
136
136
  it "should return an empty array if no refs are declared" do
137
- expect(@test_builder.lookup_refs).to eq([])
137
+ @test_builder.lookup_refs.should == []
138
138
  end
139
139
  it "should should look up the referenced TermBuilder from the terminology_builder" do
140
- expect(@peach.lookup_refs).to eq([@stone_fruit])
140
+ @peach.lookup_refs.should == [@stone_fruit]
141
141
  end
142
142
  it "should support recursive refs" do
143
- expect(@almond.lookup_refs).to eq([@peach, @stone_fruit])
143
+ @almond.lookup_refs.should == [@peach, @stone_fruit]
144
144
  end
145
145
  it "should raise an error if the TermBuilder does not have a reference to a terminology builder" do
146
- expect { OM::XML::Term::Builder.new("referrer").ref("bongos").lookup_refs }.to raise_error(StandardError,"Cannot perform lookup_ref for the referrer builder. It doesn't have a reference to any terminology builder")
146
+ lambda { OM::XML::Term::Builder.new("referrer").ref("bongos").lookup_refs }.should raise_error(StandardError,"Cannot perform lookup_ref for the referrer builder. It doesn't have a reference to any terminology builder")
147
147
  end
148
148
  it "should raise an error if the referece points to a nonexistent term builder" do
149
149
  tb = OM::XML::Term::Builder.new("mork",@test_terminology_builder).ref(:characters, :aliens)
150
- expect { tb.lookup_refs }.to raise_error(OM::XML::Terminology::BadPointerError,"This TerminologyBuilder does not have a root TermBuilder defined that corresponds to \":characters\"")
150
+ lambda { tb.lookup_refs }.should raise_error(OM::XML::Terminology::BadPointerError,"This TerminologyBuilder does not have a root TermBuilder defined that corresponds to \":characters\"")
151
151
  end
152
152
  it "should raise an error with informative error when given circular references" do
153
- expect { @pineapple.lookup_refs }.to raise_error(OM::XML::Terminology::CircularReferenceError,"Circular reference in Terminology: :pineapple => :banana => :coconut => :pineapple")
153
+ lambda { @pineapple.lookup_refs }.should raise_error(OM::XML::Terminology::CircularReferenceError,"Circular reference in Terminology: :pineapple => :banana => :coconut => :pineapple")
154
154
  end
155
155
  end
156
-
157
- describe ".resolve_refs!" do
156
+
157
+ describe ".resolve_refs!" do
158
158
  it "should do nothing if settings don't include a :ref" do
159
159
  settings_pre = @test_builder.settings
160
160
  children_pre = @test_builder.children
161
161
 
162
162
  @test_builder.resolve_refs!
163
- expect(@test_builder.settings).to eq(settings_pre)
164
- expect(@test_builder.children).to eq(children_pre)
163
+ @test_builder.settings.should == settings_pre
164
+ @test_builder.children.should == children_pre
165
165
  end
166
166
  it "should should look up the referenced TermBuilder, use its settings and duplicate its children without changing the name" do
167
167
  term_builder = OM::XML::Term::Builder.new("orange",@test_terminology_builder).ref(:fruit_trees, :citrus)
168
168
  term_builder.resolve_refs!
169
169
  # Make sure children and settings were copied
170
- expect(term_builder.settings).to eq(@citrus.settings.merge(:path=>"citrus"))
171
- expect(term_builder.children).to eq(@citrus.children)
172
-
170
+ term_builder.settings.should == @citrus.settings.merge(:path=>"citrus")
171
+ term_builder.children.should == @citrus.children
172
+
173
173
  # Make sure name and parent of both the term_builder and its target were left alone
174
- expect(term_builder.name).to eq(:orange)
175
- expect(@citrus.name).to eq(:citrus)
174
+ term_builder.name.should == :orange
175
+ @citrus.name.should == :citrus
176
176
  end
177
177
  it "should set path based on the ref's path if set" do
178
178
  [@peach,@almond].each { |x| x.resolve_refs! }
179
- expect(@peach.settings[:path]).to eq("prunus")
180
- expect(@almond.settings[:path]).to eq("prunus")
179
+ @peach.settings[:path].should == "prunus"
180
+ @almond.settings[:path].should == "prunus"
181
181
  end
182
182
  it "should set path based on the first ref's name if no path is set" do
183
183
  orange_builder = OM::XML::Term::Builder.new("orange",@test_terminology_builder).ref(:fruit_trees, :citrus)
184
184
  orange_builder.resolve_refs!
185
- expect(orange_builder.settings[:path]).to eq("citrus")
185
+ orange_builder.settings[:path].should == "citrus"
186
186
  end
187
- # It should not be a problem if multiple TermBuilders refer to the same child TermBuilder since the parent-child relationship is set up after calling TermBuilder.build
188
- # it "should result in clean trees of Terms after building"
189
-
187
+ # It should not be a problem if multiple TermBuilders refer to the same child TermBuilder since the parent-child relationship is set up after calling TermBuilder.build
188
+ it "should result in clean trees of Terms after building"
189
+
190
190
  it "should preserve any extra settings specific to this builder (for variant terms)" do
191
191
  tb = OM::XML::Term::Builder.new("orange",@test_terminology_builder).ref(:fruit_trees, :citrus).attributes(:color=>"orange").required(true)
192
192
  tb.resolve_refs!
193
- expect(tb.settings).to eq({:path=>"citrus", :attributes=>{"citric_acid"=>"true", :color=>"orange"}, :required=>true, :type=>:string, :index_as=>[:facetable]})
193
+ tb.settings.should == {:path=>"citrus", :attributes=>{"citric_acid"=>"true", :color=>"orange"}, :required=>true, :type=>:string, :index_as=>[:facetable]}
194
194
  end
195
195
  it "should aggregate all settings from refs, combining them with a cascading approach" do
196
196
  @almond.resolve_refs!
197
- expect(@almond.settings[:attributes]).to eq({:genus=>"Prunus",:subgenus=>"Amygdalus", :species=>"Prunus dulcis"})
197
+ @almond.settings[:attributes].should == {:genus=>"Prunus",:subgenus=>"Amygdalus", :species=>"Prunus dulcis"}
198
198
  end
199
199
  end
200
200
  end
@@ -3,54 +3,46 @@ require 'spec_helper'
3
3
  describe OM::XML::Term do
4
4
  describe "without a type" do
5
5
  subject { OM::XML::Term.new(:test_term) }
6
-
7
- describe (:type) do
8
- subject { super().send((:type)) }
9
- it { is_expected.to eq(:string) }
10
- end
6
+ its (:type) { should == :string }
11
7
  end
12
8
  describe "when type is specified" do
13
9
  subject { OM::XML::Term.new(:test_term, :type=>:date)}
14
-
15
- describe (:type) do
16
- subject { super().send((:type)) }
17
- it { is_expected.to eq(:date) }
18
- end
10
+ its (:type) { should == :date }
19
11
  end
20
12
 
21
13
  describe "a big test" do
22
14
  before(:each) do
23
- @test_name_part = OM::XML::Term.new(:namePart, {}).generate_xpath_queries!
24
- @test_volume = OM::XML::Term.new(:volume, :path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
25
- @test_date = OM::XML::Term.new(:namePart, :attributes=>{:type=> "date"})
26
- @test_person = OM::XML::Term.new(:namePart, :attributes=>{:type=> :none})
15
+ @test_name_part = OM::XML::Term.new(:namePart, {}).generate_xpath_queries!
16
+ @test_volume = OM::XML::Term.new(:volume, :path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
17
+ @test_date = OM::XML::Term.new(:namePart, :attributes=>{:type=> "date"})
18
+ @test_person = OM::XML::Term.new(:namePart, :attributes=>{:type=> :none})
27
19
  @test_affiliation = OM::XML::Term.new(:affiliation)
28
- @test_role_code = OM::XML::Term.new(:roleTerm, :attributes=>{:type=>"code"})
29
- @test_type = OM::XML::Term.new(:class)
20
+ @test_role_code = OM::XML::Term.new(:roleTerm, :attributes=>{:type=>"code"})
21
+ @test_type = OM::XML::Term.new(:class)
30
22
  end
31
23
 
32
24
  describe '#new' do
33
25
  it "should set path from mapper name if no path is provided" do
34
- expect(@test_name_part.path).to eq("namePart")
26
+ @test_name_part.path.should == "namePart"
35
27
  end
36
28
  it "should populate the xpath values if no options are provided" do
37
29
  local_mapping = OM::XML::Term.new(:namePart)
38
- expect(local_mapping.xpath_relative).to be_nil
39
- expect(local_mapping.xpath).to be_nil
40
- expect(local_mapping.xpath_constrained).to be_nil
30
+ local_mapping.xpath_relative.should be_nil
31
+ local_mapping.xpath.should be_nil
32
+ local_mapping.xpath_constrained.should be_nil
41
33
  end
42
34
  end
43
35
 
44
36
  describe 'inner_xml' do
45
37
  it "should be a kind of Nokogiri::XML::Node" do
46
- skip
47
- expect(@test_mapping.inner_xml).to be_kind_of(Nokogiri::XML::Node)
38
+ pending
39
+ @test_mapping.inner_xml.should be_kind_of(Nokogiri::XML::Node)
48
40
  end
49
41
  end
50
42
 
51
43
  describe '#from_node' do
52
44
  it "should create a mapper from a nokogiri node" do
53
- skip "probably should do this in the Builder"
45
+ pending "probably should do this in the Builder"
54
46
  ng_builder = Nokogiri::XML::Builder.new do |xml|
55
47
  xml.mapper(:name=>"person", :path=>"name") {
56
48
  xml.attribute(:name=>"type", :value=>"personal")
@@ -63,17 +55,17 @@ describe OM::XML::Term do
63
55
  # node = Nokogiri::XML::Document.parse( '<mapper name="first_name" path="namePart"><attribute name="type" value="given"/><attribute name="another_attribute" value="myval"/></mapper>' ).root
64
56
  node = ng_builder.doc.root
65
57
  mapper = OM::XML::Term.from_node(node)
66
- expect(mapper.name).to eq(:person)
67
- expect(mapper.path).to eq("name")
68
- expect(mapper.attributes).to eq({:type=>"personal"})
69
- expect(mapper.internal_xml).to eq(node)
58
+ mapper.name.should == :person
59
+ mapper.path.should == "name"
60
+ mapper.attributes.should == {:type=>"personal"}
61
+ mapper.internal_xml.should == node
70
62
 
71
63
  child = mapper.children[:first_name]
72
64
 
73
- expect(child.name).to eq(:first_name)
74
- expect(child.path).to eq("namePart")
75
- expect(child.attributes).to eq({:type=>"given", :another_attribute=>"myval"})
76
- expect(child.internal_xml).to eq(node.xpath("./mapper").first)
65
+ child.name.should == :first_name
66
+ child.path.should == "namePart"
67
+ child.attributes.should == {:type=>"given", :another_attribute=>"myval"}
68
+ child.internal_xml.should == node.xpath("./mapper").first
77
69
  end
78
70
  end
79
71
 
@@ -83,29 +75,30 @@ describe OM::XML::Term do
83
75
 
84
76
  describe ".retrieve_term" do
85
77
  it "should crawl down into mapper children to find the desired term" do
86
- mock_role = double("mapper", :children =>{:text=>"the target"})
87
- mock_conference = double("mapper", :children =>{:role=>mock_role})
88
- expect(@test_name_part).to receive(:children).and_return({:conference=>mock_conference})
89
- expect(@test_name_part.retrieve_term(:conference, :role, :text)).to eq("the target")
78
+ mock_role = mock("mapper", :children =>{:text=>"the target"})
79
+ mock_conference = mock("mapper", :children =>{:role=>mock_role})
80
+ @test_name_part.should_receive(:children).and_return({:conference=>mock_conference})
81
+ @test_name_part.retrieve_term(:conference, :role, :text).should == "the target"
90
82
  end
91
83
  it "should return an empty hash if no term can be found" do
92
- expect(@test_name_part.retrieve_term(:journal, :issue, :end_page)).to eq(nil)
84
+ @test_name_part.retrieve_term(:journal, :issue, :end_page).should == nil
93
85
  end
94
86
  end
95
87
 
96
88
  describe 'inner_xml' do
97
89
  it "should be a kind of Nokogiri::XML::Node" do
98
- skip
99
- expect(@test_name_part.inner_xml).to be_kind_of(Nokogiri::XML::Node)
90
+ pending
91
+ @test_name_part.inner_xml.should be_kind_of(Nokogiri::XML::Node)
100
92
  end
101
93
  end
102
94
 
103
95
  describe "getters/setters" do
104
96
  it "should set the corresponding .settings value and return the current value" do
105
97
  # :index_as is a special case
98
+
106
99
  [:path, :required, :type, :variant_of, :path, :attributes, :default_content_path, :namespace_prefix].each do |method_name|
107
- expect(@test_name_part.send(method_name.to_s+"=", "#{method_name.to_s}foo")).to eq("#{method_name.to_s}foo")
108
- expect(@test_name_part.send(method_name)).to eq("#{method_name.to_s}foo")
100
+ @test_name_part.send((method_name.to_s+"=").to_sym, "#{method_name.to_s}foo")
101
+ @test_name_part.send(method_name).should == "#{method_name.to_s}foo"
109
102
  end
110
103
  end
111
104
  end
@@ -114,7 +107,7 @@ describe OM::XML::Term do
114
107
  subject {
115
108
  class TestTerminology
116
109
  include OM::XML::Document
117
-
110
+
118
111
  set_terminology do |t|
119
112
  t.as_array :index_as => [:not_searchable]
120
113
  t.as_symbol :index_as => :not_searchable
@@ -125,75 +118,76 @@ describe OM::XML::Term do
125
118
  }
126
119
 
127
120
  it "should accept an array as an :index_as value" do
128
- expect(subject.terminology.terms[:as_array].index_as).to be_a_kind_of(Array)
129
- expect(subject.terminology.terms[:as_array].index_as).to eq([:not_searchable])
121
+ subject.terminology.terms[:as_array].index_as.should be_a_kind_of(Array)
122
+ subject.terminology.terms[:as_array].index_as.should == [:not_searchable]
130
123
  end
131
124
  it "should accept a plain symbol as a value to :index_as" do
132
- expect(subject.terminology.terms[:as_symbol].index_as).to be_a_kind_of(Array)
133
- expect(subject.terminology.terms[:as_symbol].index_as).to eq([:not_searchable])
125
+ subject.terminology.terms[:as_symbol].index_as.should be_a_kind_of(Array)
126
+ subject.terminology.terms[:as_symbol].index_as.should == [:not_searchable]
134
127
  end
135
128
  end
136
129
  it "should have a .terminology attribute accessor" do
137
- expect(@test_volume).to respond_to :terminology
138
- expect(@test_volume).to respond_to :terminology=
130
+ @test_volume.should respond_to :terminology
131
+ @test_volume.should respond_to :terminology=
139
132
  end
140
133
  describe ".ancestors" do
141
134
  it "should return an array of Terms that are the ancestors of the current object, ordered from the top/root of the hierarchy" do
142
135
  @test_volume.set_parent(@test_name_part)
143
- expect(@test_volume.ancestors).to eq([@test_name_part])
136
+ @test_volume.ancestors.should == [@test_name_part]
144
137
  end
145
138
  end
146
139
  describe ".parent" do
147
140
  it "should retrieve the immediate parent of the given object from the ancestors array" do
148
- # @test_name_part.expects(:ancestors).returns(["ancestor1","ancestor2","ancestor3"])
149
141
  @test_name_part.ancestors = ["ancestor1","ancestor2","ancestor3"]
150
- expect(@test_name_part.parent).to eq("ancestor3")
142
+ @test_name_part.parent.should == "ancestor3"
151
143
  end
152
144
  end
153
145
  describe ".children" do
154
146
  it "should return a hash of Terms that are the children of the current object, indexed by name" do
155
147
  @test_volume.add_child(@test_name_part)
156
- expect(@test_volume.children[@test_name_part.name]).to eq(@test_name_part)
148
+ @test_volume.children[@test_name_part.name].should == @test_name_part
157
149
  end
158
150
  end
159
151
  describe ".retrieve_child" do
160
152
  it "should fetch the child identified by the given name" do
161
153
  @test_volume.add_child(@test_name_part)
162
- expect(@test_volume.retrieve_child(@test_name_part.name)).to eq(@test_volume.children[@test_name_part.name])
154
+ @test_volume.retrieve_child(@test_name_part.name).should == @test_volume.children[@test_name_part.name]
163
155
  end
164
156
  end
165
157
  describe ".set_parent" do
166
158
  it "should insert the mapper into the given parent" do
167
159
  @test_name_part.set_parent(@test_volume)
168
- expect(@test_name_part.ancestors).to include(@test_volume)
169
- expect(@test_volume.children[@test_name_part.name]).to eq(@test_name_part)
160
+ @test_name_part.ancestors.should include(@test_volume)
161
+ @test_volume.children[@test_name_part.name].should == @test_name_part
170
162
  end
171
163
  end
172
164
  describe ".add_child" do
173
165
  it "should insert the given mapper into the current mappers children" do
174
166
  @test_volume.add_child(@test_name_part)
175
- expect(@test_volume.children[@test_name_part.name]).to eq(@test_name_part)
176
- expect(@test_name_part.ancestors).to include(@test_volume)
167
+ @test_volume.children[@test_name_part.name].should == @test_name_part
168
+ @test_name_part.ancestors.should include(@test_volume)
177
169
  end
178
170
  end
179
171
 
180
172
  describe "generate_xpath_queries!" do
181
173
  it "should return the current object" do
182
- expect(@test_name_part.generate_xpath_queries!).to eq(@test_name_part)
174
+ @test_name_part.generate_xpath_queries!.should == @test_name_part
183
175
  end
184
176
  it "should regenerate the xpath values" do
185
- expect(@test_volume.xpath_relative).to be_nil
186
- expect(@test_volume.xpath).to be_nil
187
- expect(@test_volume.xpath_constrained).to be_nil
188
- expect(@test_volume.generate_xpath_queries!).to eq(@test_volume)
189
- expect(@test_volume.xpath_relative).to eq('detail[@type="volume"]')
190
- expect(@test_volume.xpath).to eq('//detail[@type="volume"]')
191
- expect(@test_volume.xpath_constrained).to eq('//detail[@type="volume" and contains(number, "#{constraint_value}")]'.gsub('"', '\"'))
177
+ @test_volume.xpath_relative.should be_nil
178
+ @test_volume.xpath.should be_nil
179
+ @test_volume.xpath_constrained.should be_nil
180
+
181
+ @test_volume.generate_xpath_queries!.should == @test_volume
182
+
183
+ @test_volume.xpath_relative.should == 'detail[@type="volume"]'
184
+ @test_volume.xpath.should == '//detail[@type="volume"]'
185
+ @test_volume.xpath_constrained.should == '//detail[@type="volume" and contains(number, "#{constraint_value}")]'.gsub('"', '\"')
192
186
  end
193
187
  it "should trigger update on any child objects" do
194
- mock_child = double("child term")
195
- expect(mock_child).to receive(:generate_xpath_queries!).exactly(3).times
196
- expect(@test_name_part).to receive(:children).and_return({1=>mock_child, 2=>mock_child, 3=>mock_child})
188
+ mock_child = mock("child term")
189
+ mock_child.should_receive(:generate_xpath_queries!).exactly(3).times
190
+ @test_name_part.should_receive(:children).and_return({1=>mock_child, 2=>mock_child, 3=>mock_child})
197
191
  @test_name_part.generate_xpath_queries!
198
192
  end
199
193
  end
@@ -201,9 +195,9 @@ describe OM::XML::Term do
201
195
  describe "#xml_builder_template" do
202
196
 
203
197
  it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
204
- expect(@test_date.xml_builder_template).to eq('xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )')
205
- expect(@test_person.xml_builder_template).to eq('xml.namePart( \'#{builder_new_value}\' )')
206
- expect(@test_affiliation.xml_builder_template).to eq('xml.affiliation( \'#{builder_new_value}\' )')
198
+ @test_date.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
199
+ @test_person.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\' )'
200
+ @test_affiliation.xml_builder_template.should == 'xml.affiliation( \'#{builder_new_value}\' )'
207
201
  end
208
202
 
209
203
  it "should accept extra options" do
@@ -212,37 +206,37 @@ describe OM::XML::Term do
212
206
  e1 = %q{xml.roleTerm( '#{builder_new_value}', 'type'=>'code', 'authority'=>'marcrelator' )}
213
207
  e2 = %q{xml.roleTerm( '#{builder_new_value}', 'authority'=>'marcrelator', 'type'=>'code' )}
214
208
  got = @test_role_code.xml_builder_template(:attributes=>{"authority"=>"marcrelator"})
215
- expect([e1, e2]).to include(got)
209
+ [e1, e2].should include(got)
216
210
  end
217
211
 
218
212
  it "should work for namespaced nodes" do
219
213
  @ical_date = OM::XML::Term.new(:ical_date, :path=>"ical:date")
220
- expect(@ical_date.xml_builder_template).to eq("xml[\'ical\'].date( '\#{builder_new_value}' )")
214
+ @ical_date.xml_builder_template.should == "xml[\'ical\'].date( '\#{builder_new_value}' )"
221
215
  @ical_date = OM::XML::Term.new(:ical_date, :path=>"date", :namespace_prefix=>"ical")
222
- expect(@ical_date.xml_builder_template).to eq("xml[\'ical\'].date( '\#{builder_new_value}' )")
216
+ @ical_date.xml_builder_template.should == "xml[\'ical\'].date( '\#{builder_new_value}' )"
223
217
  end
224
218
 
225
219
  it "should work for nodes with default_content_path" do
226
- expect(@test_volume.xml_builder_template).to eq("xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }")
220
+ @test_volume.xml_builder_template.should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
227
221
  end
228
222
 
229
223
  it "should support terms that are attributes" do
230
224
  @type_attribute_term = OM::XML::Term.new(:type_attribute, :path=>{:attribute=>:type})
231
- expect(@type_attribute_term.xml_builder_template).to eq("xml.@type( '\#{builder_new_value}' )")
225
+ @type_attribute_term.xml_builder_template.should == "xml.@type( '\#{builder_new_value}' )"
232
226
  end
233
227
 
234
228
  it "should support terms with namespaced attributes" do
235
229
  @french_title = OM::XML::Term.new(:french_title, :path=>"title", :attributes=>{"xml:lang"=>"fre"})
236
- expect(@french_title.xml_builder_template).to eq("xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )")
230
+ @french_title.xml_builder_template.should == "xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )"
237
231
  end
238
232
 
239
233
  it "should support terms that are namespaced attributes" do
240
234
  @xml_lang_attribute_term = OM::XML::Term.new(:xml_lang_attribute, :path=>{:attribute=>"xml:lang"})
241
- expect(@xml_lang_attribute_term.xml_builder_template).to eq("xml.@xml:lang( '\#{builder_new_value}' )")
235
+ @xml_lang_attribute_term.xml_builder_template.should == "xml.@xml:lang( '\#{builder_new_value}' )"
242
236
  end
243
-
237
+
244
238
  it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block) for terms that share a name with an existing method on the builder" do
245
- expect(@test_type.xml_builder_template).to eq('xml.class_( \'#{builder_new_value}\' )')
239
+ @test_type.xml_builder_template.should == 'xml.class_( \'#{builder_new_value}\' )'
246
240
  end
247
241
  end
248
242
  end