lucid_works 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -339,7 +339,7 @@ module LucidWorks
339
339
  rescue RestClient::Conflict, # 409
340
340
  RestClient::UnprocessableEntity, # 422
341
341
  RestClient::InternalServerError => e # 500
342
- payload[:exception] = e
342
+ payload[:exceptionion] = e
343
343
  attach_errors_to_model(e.response)
344
344
  false
345
345
  rescue RestClient::Exception => exception
@@ -0,0 +1,60 @@
1
+ module LucidWorks
2
+
3
+ class Collection
4
+
5
+ class Synonym
6
+ include ActiveModel::Validations
7
+ extend ActiveModel::Naming
8
+
9
+ attr_reader :id, :collection, :persisted
10
+ attr_accessor :mapping
11
+
12
+ validates_presence_of :mapping
13
+ validates_each :mapping, :allow_blank => true do |model, attr, value|
14
+ model.errors.add(attr, 'must be a comma-separated list') if value =~ /=>/ || value.split(',').size < 2
15
+ end
16
+
17
+ def initialize(attributes = {})
18
+ @id = attributes[:id]
19
+ @collection = attributes[:collection]
20
+ @mapping = attributes[:mapping]
21
+ @persisted = attributes[:persisted] || false
22
+ end
23
+
24
+ def persisted?
25
+ @persisted
26
+ end
27
+
28
+ def save
29
+ return false unless valid?
30
+ if persisted?
31
+ settings.synonym_list[id] = mapping
32
+ else
33
+ settings.synonym_list << mapping
34
+ end
35
+ settings.save
36
+ @persisted = true
37
+ rescue
38
+ false
39
+ end
40
+
41
+ def update_attributes(attrs_and_values)
42
+ attrs_and_values.each do |attr,value|
43
+ self.send("#{attr}=", value)
44
+ end
45
+ save
46
+ end
47
+
48
+ def destroy
49
+ settings.synonym_list.delete_at(id)
50
+ settings.save
51
+ end
52
+
53
+ private
54
+
55
+ def settings
56
+ collection.settings
57
+ end
58
+ end
59
+ end
60
+ end
@@ -46,6 +46,16 @@ module LucidWorks
46
46
  data
47
47
  end
48
48
 
49
+ def synonyms
50
+ @synomyms ||= settings.synonym_list.each_with_index.map do |mapping, index|
51
+ Synonym.new(:id => index, :collection => self, :mapping => mapping, :persisted => true)
52
+ end
53
+ end
54
+
55
+ def build_synonym(attributes = {})
56
+ Synonym.new(attributes.merge(:collection => self))
57
+ end
58
+
49
59
  def prime_activities
50
60
  self.activities!.sort!{|a,b|a.id <=> b.id}
51
61
  num_created = 0
@@ -1,3 +1,3 @@
1
1
  module LucidWorks
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.9"
3
3
  end
data/lib/lucid_works.rb CHANGED
@@ -36,6 +36,7 @@ require 'lucid_works/collection/activity/history'
36
36
  require 'lucid_works/collection/info'
37
37
  require 'lucid_works/collection/index'
38
38
  require 'lucid_works/collection/settings'
39
+ require 'lucid_works/collection/synonym'
39
40
  require 'lucid_works/crawler'
40
41
  require 'lucid_works/datasource'
41
42
  require 'lucid_works/datasource/index'
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+ require 'lucid_works/collection/synonym'
3
+
4
+ describe LucidWorks::Collection::Synonym do
5
+ before do
6
+ @server = connect_to_live_server.tap {|server| server.reset_collections! }
7
+ load_collection
8
+ end
9
+
10
+ def load_collection
11
+ @collection = @server.collection('collection1')
12
+ end
13
+ alias :reload_collection :load_collection
14
+
15
+ describe "validations" do
16
+ it "requires a mapping" do
17
+ synonym = LucidWorks::Collection::Synonym.new(:mapping => "")
18
+ synonym.should_not be_valid
19
+ synonym.errors[:mapping].should == ["can't be blank"]
20
+ end
21
+
22
+ it "requires the mapping to be a list" do
23
+ synonym = LucidWorks::Collection::Synonym.new(:mapping => "car")
24
+ synonym.should_not be_valid
25
+ synonym.errors[:mapping].should == ["must be a comma-separated list"]
26
+ end
27
+
28
+ it "does not allow '=>' style mappings (for now)" do
29
+ synonym = LucidWorks::Collection::Synonym.new(:mapping => "car => auto")
30
+ synonym.should_not be_valid
31
+ synonym.errors[:mapping].should == ["must be a comma-separated list"]
32
+ end
33
+ end
34
+
35
+ describe :save do
36
+ context "when valid" do
37
+ subject { LucidWorks::Collection::Synonym.new(:collection => @collection, :mapping => "car, auto") }
38
+
39
+ it "gets saved in the collection settings" do
40
+ subject.save
41
+ reload_collection.settings.synonym_list.should include("car, auto")
42
+ end
43
+
44
+ it "returns true" do
45
+ subject.save.should be(true)
46
+ end
47
+
48
+ it "is persisted" do
49
+ subject.save
50
+ subject.should be_persisted
51
+ end
52
+ end
53
+
54
+ context "when invalid" do
55
+ subject { LucidWorks::Collection::Synonym.new(:collection => @collection, :mapping => "car") }
56
+
57
+ it "doesn't get saved in the collection settings" do
58
+ subject.save
59
+ reload_collection.settings.synonym_list.should_not include("car")
60
+ end
61
+
62
+ it "returns false" do
63
+ subject.save.should be(false)
64
+ end
65
+
66
+ it "is not persisted" do
67
+ subject.save
68
+ subject.should_not be_persisted
69
+ end
70
+ end
71
+
72
+ context "when orphan" do
73
+ subject { LucidWorks::Collection::Synonym.new(:mapping => "car, auto") }
74
+
75
+ it "returns false" do
76
+ subject.save.should be(false)
77
+ end
78
+
79
+ it "is not persisted" do
80
+ subject.save
81
+ subject.should_not be_persisted
82
+ end
83
+ end
84
+ end
85
+
86
+ describe :update_attributes do
87
+ it "updates the collection settings" do
88
+ @collection.synonyms[0].update_attributes(:mapping => "lawyer, clown")
89
+ reload_collection.should have(8).synonyms
90
+ @collection.synonyms[0].mapping.should == "lawyer, clown"
91
+ end
92
+ end
93
+
94
+ describe :destroy do
95
+ it "removes the mapping from the collection settings" do
96
+ @collection.synonyms[0].destroy
97
+ reload_collection.should have(7).synonyms
98
+ @collection.synonyms.should_not include("lawyer, attorney")
99
+ end
100
+ end
101
+ end
@@ -118,6 +118,29 @@ describe LucidWorks::Collection do
118
118
  end
119
119
  end
120
120
 
121
+ describe "#synonyms" do
122
+ before do
123
+ @collection = @server.collection('collection1')
124
+ end
125
+
126
+ it "returns a list of synonyms" do
127
+ @collection.should have(8).synonyms
128
+ end
129
+
130
+ it "sets the synonyms' mapping" do
131
+ @collection.synonyms.first.mapping.should == "lawyer, attorney"
132
+ end
133
+
134
+ it "associates each synonym to the collection" do
135
+ @collection.synonyms.first.collection.should be(@collection)
136
+ end
137
+
138
+ it "assigns an id to each synonym" do
139
+ @collection.synonyms.first.id.should == 0
140
+ @collection.synonyms.last.id.should == 7
141
+ end
142
+ end
143
+
121
144
  describe "#info" do
122
145
  before :all do
123
146
  @collection = LucidWorks::Collection.first(:parent => @server)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lucid_works
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.8
5
+ version: 0.6.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Pierson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-19 00:00:00 -04:00
13
+ date: 2011-05-19 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -112,6 +112,7 @@ files:
112
112
  - lib/lucid_works/collection/index.rb
113
113
  - lib/lucid_works/collection/info.rb
114
114
  - lib/lucid_works/collection/settings.rb
115
+ - lib/lucid_works/collection/synonym.rb
115
116
  - lib/lucid_works/crawler.rb
116
117
  - lib/lucid_works/datasource.rb
117
118
  - lib/lucid_works/datasource/crawldata.rb
@@ -142,6 +143,7 @@ files:
142
143
  - spec/lib/lucid_works/collection/activity/status_spec.rb
143
144
  - spec/lib/lucid_works/collection/activity_spec.rb
144
145
  - spec/lib/lucid_works/collection/prime_activities_spec.rb
146
+ - spec/lib/lucid_works/collection/synonym_spec.rb
145
147
  - spec/lib/lucid_works/collection_spec.rb
146
148
  - spec/lib/lucid_works/datasource/history_spec.rb
147
149
  - spec/lib/lucid_works/datasource/schedule_spec.rb
@@ -190,6 +192,7 @@ test_files:
190
192
  - spec/lib/lucid_works/collection/activity/status_spec.rb
191
193
  - spec/lib/lucid_works/collection/activity_spec.rb
192
194
  - spec/lib/lucid_works/collection/prime_activities_spec.rb
195
+ - spec/lib/lucid_works/collection/synonym_spec.rb
193
196
  - spec/lib/lucid_works/collection_spec.rb
194
197
  - spec/lib/lucid_works/datasource/history_spec.rb
195
198
  - spec/lib/lucid_works/datasource/schedule_spec.rb