lucid_works 0.6.20 → 0.6.21
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.
- data/lib/lucid_works/field.rb +7 -4
- data/lib/lucid_works/gem_version.rb +1 -1
- data/spec/lib/lucid_works/field_spec.rb +31 -13
- metadata +1 -1
data/lib/lucid_works/field.rb
CHANGED
@@ -67,17 +67,20 @@ module LucidWorks
|
|
67
67
|
validates_each :name, :allow_blank => true do |model, attr, value|
|
68
68
|
model.errors.add(attr, 'must be unique') if model.collection.fields.any? {|f| f.name == value }
|
69
69
|
end
|
70
|
+
validates_each :short_field_boost do |model, attr, value|
|
71
|
+
model.errors.add(attr, "cannot be set to \"#{value}\" for a non-indexed field") if value == 'none' && !model.indexed?
|
72
|
+
end
|
70
73
|
validates_each :include_in_results do |model, attr, value|
|
71
|
-
model.errors.add(attr, 'a field must be stored to be included in results')
|
74
|
+
model.errors.add(attr, 'a field must be stored to be included in results') if value == true && !model.stored?
|
72
75
|
end
|
73
76
|
validates_each :highlight do |model, attr, value|
|
74
|
-
model.errors.add(attr, 'a field must be stored to be highlighted')
|
77
|
+
model.errors.add(attr, 'a field must be stored to be highlighted') if value == true && !model.stored?
|
75
78
|
end
|
76
79
|
validates_each :facet do |model, attr, value|
|
77
|
-
model.errors.add(attr, 'a field must be indexed to be facetable')
|
80
|
+
model.errors.add(attr, 'a field must be indexed to be facetable') if value == true && !model.indexed?
|
78
81
|
end
|
79
82
|
validates_each :use_in_find_similar do |model, attr, value|
|
80
|
-
model.errors.add(attr, 'a field must be indexed for it to be used for find-similar')
|
83
|
+
model.errors.add(attr, 'a field must be indexed for it to be used for find-similar') if value == true && !model.indexed?
|
81
84
|
end
|
82
85
|
|
83
86
|
def t_field_type
|
@@ -26,35 +26,53 @@ describe LucidWorks::Field do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context :
|
29
|
+
context :short_field_boost do
|
30
|
+
it "cannot be set to 'none' for a non-indexed field" do
|
31
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :short_field_boost => 'none').tap do |field|
|
32
|
+
field.should_not be_valid
|
33
|
+
field.errors[:short_field_boost].should == ['cannot be set to "none" for a non-indexed field']
|
34
|
+
end
|
35
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :short_field_boost => true).should be_valid
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context :include_in_results do
|
30
40
|
it "requires the field to be stored" do
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => false, :include_in_results => true).tap do |field|
|
42
|
+
field.should_not be_valid
|
43
|
+
field.errors[:include_in_results].should == ["a field must be stored to be included in results"]
|
44
|
+
end
|
45
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => true, :include_in_results => true).should be_valid
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
37
49
|
context :highlight do
|
38
50
|
it "requires the field to be stored" do
|
39
|
-
|
40
|
-
|
41
|
-
|
51
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => false, :highlight => true).tap do |field|
|
52
|
+
field.should_not be_valid
|
53
|
+
field.errors[:highlight].should == ["a field must be stored to be highlighted"]
|
54
|
+
end
|
55
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :stored => true, :highlighted => true).should be_valid
|
42
56
|
end
|
43
57
|
end
|
44
58
|
|
45
59
|
context :facet do
|
46
60
|
it "requires the field to be indexed" do
|
47
|
-
|
48
|
-
|
49
|
-
|
61
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :facet => true).tap do |field|
|
62
|
+
field.should_not be_valid
|
63
|
+
field.errors[:facet].should == ["a field must be indexed to be facetable"]
|
64
|
+
end
|
65
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :facet => true).should be_valid
|
50
66
|
end
|
51
67
|
end
|
52
68
|
|
53
69
|
context :use_in_find_similar do
|
54
70
|
it "requires the field to be indexed" do
|
55
|
-
|
56
|
-
|
57
|
-
|
71
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => false, :use_in_find_similar => true).tap do |field|
|
72
|
+
field.should_not be_valid
|
73
|
+
field.errors[:use_in_find_similar].should == ["a field must be indexed for it to be used for find-similar"]
|
74
|
+
end
|
75
|
+
LucidWorks::Field.new(:parent => @collection, :name => 'my_field', :indexed => true, :use_in_find_similar => true).should be_valid
|
58
76
|
end
|
59
77
|
end
|
60
78
|
end
|