acts_as_cleo 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/Rakefile +2 -9
  2. data/VERSION +1 -1
  3. data/acts_as_cleo.gemspec +14 -10
  4. data/lib/acts_as_cleo/acts_as_cleo.rb +0 -1
  5. data/lib/acts_as_cleo/instance_methods.rb +22 -11
  6. data/lib/acts_as_cleo.rb +6 -2
  7. data/lib/acts_as_cleo_connection/acts_as_cleo_connection.rb +3 -7
  8. data/lib/acts_as_cleo_connection/acts_methods.rb +2 -0
  9. data/lib/acts_as_cleo_connection/instance_methods.rb +27 -4
  10. data/lib/cleo/base_server.rb +3 -0
  11. data/lib/cleo/cleo.rb +22 -2
  12. data/lib/cleo/connection_server.rb +22 -11
  13. data/lib/cleo/element.rb +2 -1
  14. data/lib/cleo/element_server.rb +2 -1
  15. data/lib/generators/acts_as_cleo/install/install_generator.rb +3 -2
  16. data/lib/generators/acts_as_cleo/install/templates/install.rb +2 -2
  17. data/lib/generators/acts_as_cleo/install/templates/update.rb +2 -2
  18. data/lib/generators/acts_as_cleo/update/update_generator.rb +4 -2
  19. data/test/db/testing_db.sqlite +0 -0
  20. data/test/helper.rb +5 -1
  21. data/test/models/author.rb +5 -0
  22. data/test/models/book.rb +3 -7
  23. data/test/models/category.rb +10 -0
  24. data/test/unit/{test_active_record_callback_hooks.rb → acts_as_cleo/test_active_record_callback_hooks.rb} +3 -3
  25. data/test/unit/{test_acts_methods.rb → acts_as_cleo/test_acts_methods.rb} +2 -2
  26. data/test/unit/{test_class_methods.rb → acts_as_cleo/test_class_methods.rb} +2 -2
  27. data/test/unit/{test_instance_methods.rb → acts_as_cleo/test_instance_methods.rb} +1 -3
  28. data/test/unit/acts_as_cleo_connection/test_active_record_callbacks.rb +29 -0
  29. data/test/unit/acts_as_cleo_connection/test_acts_methods.rb +34 -0
  30. data/test/unit/{test_cleo.rb → cleo/test_cleo.rb} +7 -1
  31. data/test/unit/{test_model_to_cleo.rb → xml/test_model_to_cleo.rb} +3 -3
  32. data/test/unit/xml/test_model_to_cleo_connection_test.rb +33 -0
  33. data/test/unit/{test_result_parser.rb → xml/test_result_parser.rb} +1 -1
  34. metadata +38 -34
  35. data/lib/acts_as_cleo/result.rb +0 -16
data/Rakefile CHANGED
@@ -30,17 +30,10 @@ require 'rake/testtask'
30
30
  Rake::TestTask.new(:test) do |test|
31
31
  test.libs << 'lib' << 'test'
32
32
  test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
33
+ # test.pattern = 'test/**/work_*.rb'
34
+ test.verbose = false
34
35
  end
35
36
 
36
- #require 'rcov/rcovtask'
37
- #Rcov::RcovTask.new do |test|
38
- # test.libs << 'test'
39
- # test.pattern = 'test/**/test_*.rb'
40
- # test.verbose = true
41
- # test.rcov_opts << '--exclude "gems/*"'
42
- #end
43
-
44
37
  task :default => :test
45
38
 
46
39
  require 'rdoc/task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.0.1
data/acts_as_cleo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "acts_as_cleo"
8
- s.version = "3.0.0"
8
+ s.version = "3.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert R. Meyer"]
12
- s.date = "2012-04-11"
12
+ s.date = "2012-04-26"
13
13
  s.description = "LinkedIn Open Source type ahead tool's REST API as a ruby gem. Now with Reddis support."
14
14
  s.email = "Blue.Dog.Archolite@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
30
30
  "lib/acts_as_cleo/class_methods.rb",
31
31
  "lib/acts_as_cleo/instance_methods.rb",
32
32
  "lib/acts_as_cleo/private_methods.rb",
33
- "lib/acts_as_cleo/result.rb",
34
33
  "lib/acts_as_cleo/version.rb",
35
34
  "lib/acts_as_cleo_connection/acts_as_cleo_connection.rb",
36
35
  "lib/acts_as_cleo_connection/acts_methods.rb",
@@ -70,16 +69,21 @@ Gem::Specification.new do |s|
70
69
  "test/fixtures/electronics.yml",
71
70
  "test/fixtures/movies.yml",
72
71
  "test/helper.rb",
72
+ "test/models/author.rb",
73
73
  "test/models/book.rb",
74
+ "test/models/category.rb",
74
75
  "test/models/movie.rb",
75
76
  "test/test_install_generator.rb",
76
- "test/unit/test_active_record_callback_hooks.rb",
77
- "test/unit/test_acts_methods.rb",
78
- "test/unit/test_class_methods.rb",
79
- "test/unit/test_cleo.rb",
80
- "test/unit/test_instance_methods.rb",
81
- "test/unit/test_model_to_cleo.rb",
82
- "test/unit/test_result_parser.rb"
77
+ "test/unit/acts_as_cleo/test_active_record_callback_hooks.rb",
78
+ "test/unit/acts_as_cleo/test_acts_methods.rb",
79
+ "test/unit/acts_as_cleo/test_class_methods.rb",
80
+ "test/unit/acts_as_cleo/test_instance_methods.rb",
81
+ "test/unit/acts_as_cleo_connection/test_active_record_callbacks.rb",
82
+ "test/unit/acts_as_cleo_connection/test_acts_methods.rb",
83
+ "test/unit/cleo/test_cleo.rb",
84
+ "test/unit/xml/test_model_to_cleo.rb",
85
+ "test/unit/xml/test_model_to_cleo_connection_test.rb",
86
+ "test/unit/xml/test_result_parser.rb"
83
87
  ]
84
88
  s.homepage = "http://github.com/blue-dog-archolite/acts_as_cleo"
85
89
  s.licenses = ["MIT"]
@@ -5,7 +5,6 @@ require File.dirname(__FILE__) + '/instance_methods'
5
5
 
6
6
  module ActsAsCleo
7
7
  include ActsMethods
8
-
9
8
  end
10
9
 
11
10
  ActiveRecord::Base.extend ActsAsCleo
@@ -49,22 +49,32 @@ module ActsAsCleo
49
49
 
50
50
  cr.name = self.send(self.cleo_config[:name]).to_s.downcase
51
51
  cr.name = cr.term.first if cr.name.blank?
52
+ cr.name = cr.name.gsub('&', 'and')
52
53
 
53
- score = self.send(self.cleo_config[:score])
54
-
55
- if score.nil?
56
- cr.score = 0
57
- elsif score.respond_to?("count")
58
- cr.score = score.count
59
- else
60
- cr.score = score
61
- end
54
+ cr.score = self.cleo_score
62
55
 
63
56
  cr
64
57
  end
65
58
 
66
59
  alias :as_cleo :to_cleo_result
67
60
 
61
+ def cleo_score
62
+ s = self.send(self.cleo_config[:score])
63
+
64
+ begin
65
+ return Float(s)
66
+ rescue ArgumentError => e
67
+ if s.nil?
68
+ return 0
69
+ elsif s.respond_to?("count")
70
+ return s.count
71
+ end
72
+ end
73
+
74
+ return s
75
+ end
76
+
77
+
68
78
  def record_type
69
79
  self.cleo_config[:type]
70
80
  end
@@ -76,8 +86,9 @@ module ActsAsCleo
76
86
  private
77
87
  def clean_terms_for_storage(to_process)
78
88
  to_process = to_process.compact.flatten.reject(&:blank?)
79
- to_process.collect!{|i| i.split(/\s+/) }.compact.uniq
80
- to_process.reject{|i| drop_words.include?(i) }
89
+ to_process.collect!{|i| i.split(/\W+/).collect(&:strip) }.compact
90
+ to_process = to_process.reject{|i| drop_words.include?(i) }
91
+ to_process.uniq
81
92
  end
82
93
 
83
94
  def drop_words
data/lib/acts_as_cleo.rb CHANGED
@@ -1,6 +1,10 @@
1
+ #Cleo Servers and Configuration
1
2
  require File.dirname(__FILE__) + '/cleo/cleo'
3
+
4
+ #Cleo Element Model and Acts As Functionality
2
5
  require File.dirname(__FILE__) + '/acts_as_cleo/acts_as_cleo'
3
6
  require File.dirname(__FILE__) + '/xml/result'
4
7
 
5
- #require File.dirname(__FILE__) + '/acts_as_cleo_connection/acts_as_cleo_connection'
6
- #require File.dirname(__FILE__) + '/xml/connection'
8
+ #Cleo Connection Model and Acts As Functionality
9
+ require File.dirname(__FILE__) + '/acts_as_cleo_connection/acts_as_cleo_connection'
10
+ require File.dirname(__FILE__) + '/xml/connection'
@@ -1,10 +1,6 @@
1
- #Load Cleo
2
- require File.dirname(__FILE__ + '/cleo')
3
-
4
- #Load CleoConnection modules
5
- %w{acts_methods class_methods instance_methods}.each do |l|
6
- require File.dirname(__FILE__ + "/acts_as_cleo_connection/#{l}"
7
- end
1
+ #Load ActsAsCleoConnection files
2
+ require File.dirname(__FILE__) + '/acts_methods'
3
+ require File.dirname(__FILE__) + '/instance_methods'
8
4
 
9
5
  module ActsAsCleoConnection
10
6
  include ActsMethods
@@ -12,11 +12,13 @@ module ActsAsCleoConnection
12
12
  cattr_accessor :cleo_target
13
13
  cattr_accessor :cleo_origin
14
14
  cattr_accessor :cleo_type
15
+ cattr_accessor :cleo_strength
15
16
 
16
17
  #Set taggign calls
17
18
  self.cleo_origin = opts[:origin]
18
19
  self.cleo_target = opts[:target]
19
20
  self.cleo_type = opts[:type]
21
+ self.cleo_strength = opts[:strengh]
20
22
  end
21
23
  end
22
24
  end
@@ -1,19 +1,42 @@
1
1
  module ActsAsCleoConnection
2
2
  module InstanceMethods
3
3
  def create_cleo_connection
4
- Cleo::Connection.create(self)
4
+ Cleo::ConnectionServer.create(self)
5
5
  end
6
6
 
7
7
  def update_cleo_connection
8
- Cleo::Connection.update(self)
8
+ Cleo::ConnectionServer.update(self)
9
9
  end
10
10
 
11
11
  def remove_cleo_connection
12
- Cleo::Connection.delete(self)
12
+ Cleo::ConnectionServer.delete(self)
13
13
  end
14
14
 
15
15
  def disable_cleo_connection
16
- Cleo::Connection.disable(self)
16
+ Cleo::ConnectionServer.disable(self)
17
17
  end
18
+
19
+ def to_cleo_connection
20
+ source = self.send("#{cleo_origin}")
21
+ target = self.send("#{cleo_target}")
22
+ type = self.respond_to?("#{cleo_type}") ? self.send("#{cleo_type}") : cleo_type
23
+ return nil if target.blank? || source.blank?
24
+
25
+ is_active = self.respond_to?(:active) ? self.active : nil
26
+ str = target.cleo_score + source.cleo_score
27
+
28
+ result = Cleo::Xml::Connection.new
29
+
30
+ result.source = source.cleo_id
31
+ result.target = target.cleo_id
32
+ result.active = is_active
33
+ result.strength = str
34
+ result.type = type
35
+
36
+ return result
37
+ end
38
+
39
+ alias :as_connection :to_cleo_connection
40
+
18
41
  end
19
42
  end
@@ -1,3 +1,6 @@
1
+ require 'net/http'
2
+ require 'cgi'
3
+
1
4
  module Cleo
2
5
  class Base
3
6
  cattr_accessor :async
data/lib/cleo/cleo.rb CHANGED
@@ -1,14 +1,22 @@
1
1
  #Load Cleo Sub Modules
2
+
2
3
  require File.dirname(__FILE__) + '/base_server'
3
4
  require File.dirname(__FILE__) + '/connection_server'
4
5
  require File.dirname(__FILE__) + '/element_server'
5
6
  require File.dirname(__FILE__) + '/service'
7
+ require File.dirname(__FILE__) + '/element'
8
+
9
+ require 'resque'
10
+
6
11
 
7
12
  module Cleo
8
13
  def self.query(query)
9
14
  Cleo::ElementServer.query(query)
10
15
  end
11
16
 
17
+ def self.network_query(source_id, query)
18
+ end
19
+
12
20
  def self.net_http
13
21
  uri = URI.parse(Cleo::Service.url)
14
22
  Net::HTTP.new(uri.host, uri.port)
@@ -21,9 +29,21 @@ module Cleo
21
29
  end
22
30
 
23
31
  def self.flush
24
- uri = URI.parse Cleo::Service.url + "elements/flush"
32
+ Cleo.flush_elements and Cleo.flush_connections
33
+ end
34
+
35
+ def self.flush_connections
36
+ uri = URI.parse Cleo::Service.connection_server_url + "flush"
37
+ request = Net::HTTP::Post.new(uri.path)
38
+ response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
39
+ Cleo::Service.good_response_code?(response)
40
+ end
41
+
42
+ def self.flush_elements
43
+ uri = URI.parse Cleo::Service.element_server_url + "flush"
25
44
  request = Net::HTTP::Post.new(uri.path)
26
- Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
45
+ response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
46
+ Cleo::Service.good_response_code?(response)
27
47
  end
28
48
 
29
49
  def self.configure(new_config)
@@ -15,27 +15,38 @@ module Cleo
15
15
  end
16
16
 
17
17
  def self.execute_create(con)
18
+ obj = con.as_connection unless con.is_a?(Cleo::Xml::Connection)
19
+ return true if obj.blank?
20
+
21
+ uri = URI.parse Cleo::Service.connection_server_url + "_"
22
+ request = Net::HTTP::Post.new(uri.path)
23
+
24
+ request.body = obj.to_xml
25
+ request.content_type = 'application/xml'
26
+
27
+ response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
28
+
29
+ return good_response_code?(response)
18
30
  end
19
31
 
20
32
  def self.execute_disable(con)
33
+ sender = con.as_connection unless con.is_a?(Cleo::Xml::Connection)
34
+ return true if sender.blank?
35
+
36
+ sender.active = false
37
+
38
+ return self.execute_update(sender)
21
39
  end
22
40
 
23
41
  def self.execute_delete(con)
24
- self.execute_disable(con)
42
+ return self.execute_disable(con)
25
43
  end
26
44
 
27
45
  def self.execute_update(con)
28
- source = con.send("#{cleo_source}")
29
- target = con.send("#{cleo_target}")
30
-
31
- sender = Cleo::Xml::Connection.new(:source => source.cleo_id,
32
- :target => target.cleo_id,
33
- :active => con.active,
34
- :strength => con.strength,
35
- :type => con.cleo_type
36
- )
46
+ sender = con.as_connection unless con.is_a?(Cleo::Xml::Connection)
47
+ return true if sender.blank?
37
48
 
38
- uri = URI.parse Cleo::Service.connection_url + "_"
49
+ uri = URI.parse Cleo::Service.connection_server_url + "_"
39
50
  request = Net::HTTP::Post.new(uri.path)
40
51
 
41
52
  request.body = sender.to_xml
data/lib/cleo/element.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Cleo
2
2
  class Element < ActiveRecord::Base
3
- self.table_name = 'references'
3
+ self.table_name = 'cleo_references'
4
+ attr_accessible :record_type, :record_id
4
5
  end
5
6
  end
@@ -66,7 +66,8 @@ module Cleo
66
66
  def self.execute_create(obj)
67
67
  obj = obj.to_cleo_result unless obj.is_a?(Cleo::Xml::Result)
68
68
 
69
- uri = URI.parse self.url + "_"
69
+
70
+ uri = URI.parse Cleo::Service.element_server_url + "_"
70
71
  request = Net::HTTP::Post.new(uri.path)
71
72
 
72
73
  request.body = obj.to_xml
@@ -13,10 +13,11 @@ module ActsAsCleo
13
13
 
14
14
  #Config file
15
15
  copy_file 'cleo.yml', "config/cleo.yml"
16
- copy_file 'cleo_initalizer.rb', 'config/initalizers/cleo_initalizer.rb'
16
+ copy_file 'cleo_initalizer.rb', 'config/initializers/cleo_initalizer.rb'
17
17
 
18
18
  #Resque workers
19
- copy_file "jobs/cleo_processor.rb", "app/jobs/cleo_processor.rb"
19
+ copy_file "jobs/cleo_connection_processor.rb", "app/jobs/cleo_connection_processor.rb"
20
+ copy_file "jobs/cleo_element_processor.rb", "app/jobs/cleo_element_processor.rb"
20
21
 
21
22
  #create migration
22
23
  migration_template 'install.rb', 'db/migrate/install_acts_as_cleo.rb'
@@ -1,6 +1,6 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :references do
3
+ create_table :cleo_references do |t|
4
4
  t.timestamps
5
5
  t.string :record_type
6
6
  t.integer :record_id
@@ -8,6 +8,6 @@ class <%= migration_class_name %> < ActiveRecord::Migration
8
8
  end
9
9
 
10
10
  def down
11
- drop_table :references
11
+ drop_table :cleo_references
12
12
  end
13
13
  end
@@ -1,9 +1,9 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def up
3
- add_index :references, :record_type, :unique => false
3
+ add_index :cleo_references, :record_type, :unique => false
4
4
  end
5
5
 
6
6
  def down
7
- remove_index :references, :column => :record_type
7
+ remove_index :cleo_references, :column => :record_type
8
8
  end
9
9
  end
@@ -14,9 +14,11 @@ module ActsAsCleo
14
14
  %w{update create delete}.each do |life|
15
15
  remove_file "app/jobs/#{life}.rb"
16
16
  end
17
+ remove_file "app/jobs/cleo_processor.rb"
17
18
 
18
- #new general processor
19
- copy_file "jobs/cleo_processor.rb", "app/jobs/cleo_processor.rb"
19
+ #Resque workers
20
+ copy_file "jobs/cleo_connection_processor.rb", "app/jobs/cleo_connection_processor.rb"
21
+ copy_file "jobs/cleo_element_processor.rb", "app/jobs/cleo_element_processor.rb"
20
22
 
21
23
  #create migration
22
24
  migration_template 'update.rb', 'db/migrate/update_acts_as_cleo.rb'
Binary file
data/test/helper.rb CHANGED
@@ -21,7 +21,9 @@ require File.dirname(__FILE__) + '/../lib/xml/result'
21
21
 
22
22
  #require acts_as_cleo
23
23
  require File.dirname(__FILE__) + '/../lib/acts_as_cleo/acts_as_cleo'
24
- #require File.dirname(__FILE__) + '/../lib/acts_as_cleo_connection'
24
+
25
+ #require acts_as_cleo_connection
26
+ require File.dirname(__FILE__) + '/../lib/acts_as_cleo_connection/acts_as_cleo_connection'
25
27
 
26
28
  begin
27
29
  Bundler.setup(:default, :development)
@@ -61,7 +63,9 @@ class Test::Unit::TestCase
61
63
  end
62
64
 
63
65
  def teardown
66
+ Author.destroy_all
64
67
  Book.destroy_all
68
+ Category.destroy_all
65
69
  Movie.destroy_all
66
70
  end
67
71
  end
@@ -0,0 +1,5 @@
1
+ class Author < ActiveRecord::Base
2
+ acts_as_cleo
3
+ has_many :categories
4
+ has_many :books
5
+ end
data/test/models/book.rb CHANGED
@@ -1,11 +1,7 @@
1
- # Table fields for 'books'
2
- # - id
3
- # - category_id
4
- # - name
5
- # - author
6
-
7
1
  class Book < ActiveRecord::Base
8
- belongs_to :category
2
+ has_many :category
3
+ belongs_to :author
4
+
9
5
 
10
6
  acts_as_cleo :terms => %w{name author}, :score => "cleo_score", :name => "name"
11
7
 
@@ -0,0 +1,10 @@
1
+ class Category < ActiveRecord::Base
2
+ acts_as_cleo_connection :origin => "book", :target => "author", :type => "call_for_type_method"
3
+
4
+ belongs_to :book
5
+ belongs_to :author
6
+
7
+ def call_for_type_method(name_return = false)
8
+ return "InThisCase#{self.class.name}"
9
+ end
10
+ end
@@ -1,8 +1,8 @@
1
- require 'helper'
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  class TestActiveRecordCallbacHooks < Test::Unit::TestCase
4
4
  should "have all callbacks functioning properly" do
5
- book = Book.new(:name => "set cleo id", :author => "Rob Meyer")
5
+ book = Book.new(:name => "set cleo id", :author => Author.new(:name => "Rob Meyer"))
6
6
  assert_nil book.cleo_id
7
7
  assert_nil Cleo::Element.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book.id])
8
8
 
@@ -19,7 +19,7 @@ class TestActiveRecordCallbacHooks < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  should "update cleo on record update" do
22
- book = Book.new(:name => "update cleo", :author => "Rob Meyer")
22
+ book = Book.new(:name => "update cleo", :author => Author.new(:name => "Rob Meyer"))
23
23
  assert book.save!
24
24
  cleo_record = Cleo::ElementServer.find(book.cleo_id)
25
25
  assert_not_nil cleo_record
@@ -1,10 +1,10 @@
1
- require 'helper'
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  #Literally checking that the acts_as_cleo tag takes args and sets them as expected
4
4
  class TestActsAsMethods < Test::Unit::TestCase
5
5
 
6
6
  should "respond to and return as_cleo" do
7
- book = Book.new(:name => 'Wedge\'s Life', :author => "Luke Skywalker")
7
+ book = Book.new(:name => 'Wedge\'s Life', :author => Author.create(:name => "Luke Skywalker"))
8
8
  assert_equal %w{name author}, book.cleo_config[:terms]
9
9
  assert_equal "name", book.cleo_config[:name]
10
10
  assert_equal "Book", book.cleo_config[:type]
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  class TestClassMethods < Test::Unit::TestCase
4
4
  should "respond to query call" do
@@ -6,7 +6,7 @@ class TestClassMethods < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  should "find record with book name" do
9
- book = Book.create(:name => "Otherland", :author => "Tad Williams")
9
+ book = Book.create(:name => "Otherland", :author => Author.create(:name => "Tad Williams"))
10
10
  assert Cleo::ElementServer.create(book)
11
11
  book_cleo_id = book.cleo_id
12
12
  assert Cleo::ElementServer.find(book_cleo_id)
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  class TestInstanceMethods < Test::Unit::TestCase
4
4
  def setup
@@ -10,6 +10,4 @@ class TestInstanceMethods < Test::Unit::TestCase
10
10
  assert @b.respond_to?(resp), "ActiveRecord Model with acts_as_cleo should respond to #{resp}"
11
11
  end
12
12
  end
13
-
14
- #TODO write tests for the functionality of each of the instance methods
15
13
  end
@@ -0,0 +1,29 @@
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
+
3
+ class TestActiveRecordCallbacHooks < Test::Unit::TestCase
4
+ def setup
5
+ @author = Author.create(:name => "Von Himler")
6
+ @book = Book.create(:name => "Rise and Fall", :author => @author)
7
+ end
8
+
9
+ should "have callbacks functioning properly" do
10
+ category = Category.new(:name => "Sweetness")
11
+ category.book = @book
12
+ category.author = @author
13
+
14
+ assert_nothing_raised do
15
+ category.save!
16
+ end
17
+
18
+ book = Book.create(:name => "Fall and Rise", :author => @author)
19
+ category.book = book
20
+
21
+ assert_nothing_raised do
22
+ category.save!
23
+ end
24
+
25
+ # assert_nothing_raised do
26
+ category.destroy
27
+ # end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
+
3
+ class TestActiveRecordCallbacHooks < Test::Unit::TestCase
4
+ def setup
5
+ @book = Book.create(:name => "Otherland book 1")
6
+ @author = Author.create(:name => "Tad Williams")
7
+ @con = Category.new(:book => @book, :author => @author)
8
+ end
9
+
10
+ should "have acts_as_cleo_connection hooks and respond to them as expected" do
11
+ con = Category.new(:book => @book, :author => @author)
12
+
13
+ assert_not_nil con.book
14
+ assert_not_nil con.author
15
+ assert_equal con.author, @author
16
+ assert_equal con.book, @book
17
+
18
+ assert con.respond_to?(:cleo_target)
19
+ assert con.respond_to?(:cleo_origin)
20
+ assert con.respond_to?(:cleo_type)
21
+
22
+ assert con.respond_to?(:to_cleo_connection)
23
+ assert con.respond_to?(:as_connection)
24
+
25
+ assert con.respond_to?(:create_cleo_connection)
26
+ assert con.respond_to?(:update_cleo_connection)
27
+ assert con.respond_to?(:remove_cleo_connection)
28
+
29
+ assert_equal con.cleo_origin, "book"
30
+ assert_equal con.cleo_target, "author"
31
+ assert_equal con.cleo_type, "call_for_type_method"
32
+ assert_equal con.send("call_for_type_method"), "InThisCaseCategory"
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  class TestCleo < Test::Unit::TestCase
4
4
  def setup
@@ -7,6 +7,12 @@ class TestCleo < Test::Unit::TestCase
7
7
  @wedge = Cleo::Xml::Result.parse(contents, :singluar => true)
8
8
  end
9
9
 
10
+ should "call to Element server from query call" do
11
+ assert_nothing_raised do
12
+ Cleo.query("what the hell")
13
+ end
14
+ end
15
+
10
16
  should "create then destroy Testing Object " do
11
17
  code = Cleo::ElementServer.create(@wedge)
12
18
  assert code
@@ -1,8 +1,8 @@
1
- require 'helper'
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  class TestModelToCleo < Test::Unit::TestCase
4
4
  should "convert from model to cleo result" do
5
- b = Book.new(:name => "Suncrusher", :author => "Tad Williams")
5
+ b = Book.new(:name => "Suncrusher", :author => Author.create(:name => "Tad Williams"))
6
6
  assert b.respond_to?("as_cleo")
7
7
  assert b.respond_to?("to_cleo_result")
8
8
 
@@ -13,6 +13,6 @@ class TestModelToCleo < Test::Unit::TestCase
13
13
 
14
14
  assert_equal cb.name, b.name.downcase
15
15
  assert_equal cb.score, b.cleo_score
16
- assert_equal 3, cb.terms.count
16
+ assert_equal 2, cb.terms.count
17
17
  end
18
18
  end
@@ -0,0 +1,33 @@
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
+
3
+ class TestModelToCleoConnection < Test::Unit::TestCase
4
+ def setup
5
+ @book = Book.create(:name => "Otherland book 1")
6
+ @author = Author.create(:name => "Tad Williams")
7
+ @con = Category.new(:name => "SiFi", :book => @book, :author => @author)
8
+ end
9
+
10
+ should "convert from model to cleo connection" do
11
+ assert @con.respond_to?(:cleo_target)
12
+ assert @con.respond_to?(:cleo_origin)
13
+
14
+ assert @con.respond_to?(:to_cleo_connection)
15
+ assert @con.respond_to?(:as_connection)
16
+
17
+ cb = nil
18
+ assert_nothing_raised do
19
+ cb = @con.as_connection
20
+ end
21
+
22
+ assert_equal cb.target, @con.send("#{@con.cleo_target}").cleo_id
23
+ assert_equal cb.source, @con.send("#{@con.cleo_origin}").cleo_id
24
+
25
+ cb = nil
26
+ assert_nothing_raised do
27
+ cb = @con.to_cleo_connection
28
+ end
29
+
30
+ assert_equal cb.target, @con.send("#{@con.cleo_target}").cleo_id
31
+ assert_equal cb.source, @con.send("#{@con.cleo_origin}").cleo_id
32
+ end
33
+ end
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(File.expand_path(__FILE__))}/../helper"
1
+ require "#{File.dirname(File.expand_path(__FILE__))}/../../helper"
2
2
 
3
3
  class TestResult < Test::Unit::TestCase
4
4
  def test_parser_gets_correct_element
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_cleo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000Z
12
+ date: 2012-04-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: happymapper
16
- requirement: &70296838476020 !ruby/object:Gem::Requirement
16
+ requirement: &70263526410340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70296838476020
24
+ version_requirements: *70263526410340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70296838475540 !ruby/object:Gem::Requirement
27
+ requirement: &70263526412300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70296838475540
35
+ version_requirements: *70263526412300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: resque
38
- requirement: &70296838475060 !ruby/object:Gem::Requirement
38
+ requirement: &70263526430940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70296838475060
46
+ version_requirements: *70263526430940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &70296838474580 !ruby/object:Gem::Requirement
49
+ requirement: &70263530219160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70296838474580
57
+ version_requirements: *70263530219160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &70296838474100 !ruby/object:Gem::Requirement
60
+ requirement: &70263530311400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.12'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70296838474100
68
+ version_requirements: *70263530311400
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &70296838473620 !ruby/object:Gem::Requirement
71
+ requirement: &70263530329100 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70296838473620
79
+ version_requirements: *70263530329100
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &70296838473140 !ruby/object:Gem::Requirement
82
+ requirement: &70263538508380 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.8.3
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70296838473140
90
+ version_requirements: *70263538508380
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: simplecov
93
- requirement: &70296838472660 !ruby/object:Gem::Requirement
93
+ requirement: &70263538660980 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70296838472660
101
+ version_requirements: *70263538660980
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ruby-debug19
104
- requirement: &70296838472180 !ruby/object:Gem::Requirement
104
+ requirement: &70263538799200 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70296838472180
112
+ version_requirements: *70263538799200
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: fixtures
115
- requirement: &70296838471700 !ruby/object:Gem::Requirement
115
+ requirement: &70263538798720 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70296838471700
123
+ version_requirements: *70263538798720
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: sqlite3
126
- requirement: &70296838471220 !ruby/object:Gem::Requirement
126
+ requirement: &70263538798180 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70296838471220
134
+ version_requirements: *70263538798180
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: database_cleaner
137
- requirement: &70296838470740 !ruby/object:Gem::Requirement
137
+ requirement: &70263538797680 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70296838470740
145
+ version_requirements: *70263538797680
146
146
  description: LinkedIn Open Source type ahead tool's REST API as a ruby gem. Now with
147
147
  Reddis support.
148
148
  email: Blue.Dog.Archolite@gmail.com
@@ -165,7 +165,6 @@ files:
165
165
  - lib/acts_as_cleo/class_methods.rb
166
166
  - lib/acts_as_cleo/instance_methods.rb
167
167
  - lib/acts_as_cleo/private_methods.rb
168
- - lib/acts_as_cleo/result.rb
169
168
  - lib/acts_as_cleo/version.rb
170
169
  - lib/acts_as_cleo_connection/acts_as_cleo_connection.rb
171
170
  - lib/acts_as_cleo_connection/acts_methods.rb
@@ -205,16 +204,21 @@ files:
205
204
  - test/fixtures/electronics.yml
206
205
  - test/fixtures/movies.yml
207
206
  - test/helper.rb
207
+ - test/models/author.rb
208
208
  - test/models/book.rb
209
+ - test/models/category.rb
209
210
  - test/models/movie.rb
210
211
  - test/test_install_generator.rb
211
- - test/unit/test_active_record_callback_hooks.rb
212
- - test/unit/test_acts_methods.rb
213
- - test/unit/test_class_methods.rb
214
- - test/unit/test_cleo.rb
215
- - test/unit/test_instance_methods.rb
216
- - test/unit/test_model_to_cleo.rb
217
- - test/unit/test_result_parser.rb
212
+ - test/unit/acts_as_cleo/test_active_record_callback_hooks.rb
213
+ - test/unit/acts_as_cleo/test_acts_methods.rb
214
+ - test/unit/acts_as_cleo/test_class_methods.rb
215
+ - test/unit/acts_as_cleo/test_instance_methods.rb
216
+ - test/unit/acts_as_cleo_connection/test_active_record_callbacks.rb
217
+ - test/unit/acts_as_cleo_connection/test_acts_methods.rb
218
+ - test/unit/cleo/test_cleo.rb
219
+ - test/unit/xml/test_model_to_cleo.rb
220
+ - test/unit/xml/test_model_to_cleo_connection_test.rb
221
+ - test/unit/xml/test_result_parser.rb
218
222
  homepage: http://github.com/blue-dog-archolite/acts_as_cleo
219
223
  licenses:
220
224
  - MIT
@@ -1,16 +0,0 @@
1
- module Cleo
2
- class Result
3
- include HappyMapper
4
- tag 'element'
5
-
6
- has_many :term, String, :tag => 'term'
7
- element :id, Integer
8
- element :name, String
9
- element :score, Float
10
- element :timestamp, Time
11
- element :title, String
12
- element :url, String
13
-
14
- alias :terms :term
15
- end
16
- end