ssickles-tire 0.4.2 → 0.4.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/lib/tire.rb +3 -18
  2. data/lib/tire/alias.rb +35 -11
  3. data/lib/tire/index.rb +76 -34
  4. data/lib/tire/results/collection.rb +13 -38
  5. data/lib/tire/results/item.rb +0 -19
  6. data/lib/tire/rubyext/to_json.rb +21 -0
  7. data/lib/tire/search.rb +8 -7
  8. data/lib/tire/search/scan.rb +8 -8
  9. data/lib/tire/search/sort.rb +1 -1
  10. data/lib/tire/version.rb +38 -7
  11. data/test/integration/reindex_test.rb +2 -2
  12. data/test/integration/scan_test.rb +1 -1
  13. data/test/test_helper.rb +3 -27
  14. data/test/unit/index_alias_test.rb +17 -3
  15. data/test/unit/index_test.rb +18 -30
  16. data/test/unit/results_collection_test.rb +0 -60
  17. data/test/unit/results_item_test.rb +0 -37
  18. data/test/unit/rubyext_test.rb +3 -3
  19. data/test/unit/search_test.rb +6 -1
  20. data/test/unit/tire_test.rb +0 -15
  21. data/tire.gemspec +13 -30
  22. metadata +41 -153
  23. data/lib/tire/model/callbacks.rb +0 -40
  24. data/lib/tire/model/import.rb +0 -26
  25. data/lib/tire/model/indexing.rb +0 -128
  26. data/lib/tire/model/naming.rb +0 -100
  27. data/lib/tire/model/percolate.rb +0 -99
  28. data/lib/tire/model/persistence.rb +0 -72
  29. data/lib/tire/model/persistence/attributes.rb +0 -143
  30. data/lib/tire/model/persistence/finders.rb +0 -66
  31. data/lib/tire/model/persistence/storage.rb +0 -71
  32. data/lib/tire/model/search.rb +0 -305
  33. data/lib/tire/rubyext/hash.rb +0 -8
  34. data/lib/tire/rubyext/ruby_1_8.rb +0 -54
  35. data/lib/tire/rubyext/symbol.rb +0 -11
  36. data/lib/tire/utils.rb +0 -17
  37. data/test/integration/active_model_indexing_test.rb +0 -51
  38. data/test/integration/active_model_searchable_test.rb +0 -114
  39. data/test/integration/active_record_searchable_test.rb +0 -446
  40. data/test/integration/mongoid_searchable_test.rb +0 -309
  41. data/test/integration/persistent_model_test.rb +0 -117
  42. data/test/models/active_model_article.rb +0 -31
  43. data/test/models/active_model_article_with_callbacks.rb +0 -49
  44. data/test/models/active_model_article_with_custom_document_type.rb +0 -7
  45. data/test/models/active_model_article_with_custom_index_name.rb +0 -7
  46. data/test/models/active_record_models.rb +0 -122
  47. data/test/models/mongoid_models.rb +0 -97
  48. data/test/models/persistent_article.rb +0 -11
  49. data/test/models/persistent_article_in_namespace.rb +0 -12
  50. data/test/models/persistent_article_with_casting.rb +0 -28
  51. data/test/models/persistent_article_with_defaults.rb +0 -11
  52. data/test/models/persistent_articles_with_custom_index_name.rb +0 -10
  53. data/test/models/supermodel_article.rb +0 -17
  54. data/test/models/validated_model.rb +0 -11
  55. data/test/unit/active_model_lint_test.rb +0 -17
  56. data/test/unit/model_callbacks_test.rb +0 -116
  57. data/test/unit/model_import_test.rb +0 -71
  58. data/test/unit/model_persistence_test.rb +0 -516
  59. data/test/unit/model_search_test.rb +0 -899
@@ -1,49 +0,0 @@
1
- # Example ActiveModel class with callbacks
2
-
3
- require 'rubygems'
4
- require 'active_model'
5
-
6
- class ActiveModelArticleWithCallbacks
7
-
8
- include ActiveModel::AttributeMethods
9
- include ActiveModel::Validations
10
- include ActiveModel::Serialization
11
- include ActiveModel::Serializers::JSON
12
- include ActiveModel::Naming
13
-
14
- extend ActiveModel::Callbacks
15
- define_model_callbacks :save, :destroy
16
-
17
- include Tire::Model::Search
18
- include Tire::Model::Callbacks
19
-
20
- attr_reader :attributes
21
-
22
- def initialize(attributes = {})
23
- @attributes = attributes
24
- end
25
-
26
- def method_missing(id, *args, &block)
27
- attributes[id.to_sym] || attributes[id.to_s] || super
28
- end
29
-
30
- def persisted?
31
- true
32
- end
33
-
34
- def save
35
- _run_save_callbacks do
36
- STDERR.puts "[Saving ...]"
37
- end
38
- end
39
-
40
- def destroy
41
- _run_destroy_callbacks do
42
- STDERR.puts "[Destroying ...]"
43
- @destroyed = true
44
- end
45
- end
46
-
47
- def destroyed?; !!@destroyed; end
48
-
49
- end
@@ -1,7 +0,0 @@
1
- # Example ActiveModel class with custom document type
2
-
3
- require File.expand_path('../active_model_article', __FILE__)
4
-
5
- class ActiveModelArticleWithCustomDocumentType < ActiveModelArticle
6
- document_type 'my_custom_type'
7
- end
@@ -1,7 +0,0 @@
1
- # Example ActiveModel class with custom index name
2
-
3
- require File.expand_path('../active_model_article', __FILE__)
4
-
5
- class ActiveModelArticleWithCustomIndexName < ActiveModelArticle
6
- index_name 'custom-index-name'
7
- end
@@ -1,122 +0,0 @@
1
- require 'active_record'
2
-
3
- class ActiveRecordArticle < ActiveRecord::Base
4
- has_many :comments, :class_name => "ActiveRecordComment", :foreign_key => "article_id"
5
- has_many :stats, :class_name => "ActiveRecordStat", :foreign_key => "article_id"
6
-
7
- include Tire::Model::Search
8
- include Tire::Model::Callbacks
9
-
10
- tire do
11
- mapping do
12
- indexes :title, :type => 'string', :boost => 10, :analyzer => 'snowball'
13
- indexes :created_at, :type => 'date'
14
-
15
- indexes :comments do
16
- indexes :author
17
- indexes :body
18
- end
19
- end
20
- end
21
-
22
- def to_indexed_json
23
- {
24
- :title => title,
25
- :length => length,
26
-
27
- :comments => comments.map { |c| { :_type => 'active_record_comment',
28
- :_id => c.id,
29
- :author => c.author,
30
- :body => c.body } },
31
- :stats => stats.map { |s| { :pageviews => s.pageviews } }
32
- }.to_json
33
- end
34
-
35
- def length
36
- title.length
37
- end
38
-
39
- def comment_authors
40
- comments.map(&:author).to_sentence
41
- end
42
- end
43
-
44
- class ActiveRecordComment < ActiveRecord::Base
45
- belongs_to :article, :class_name => "ActiveRecordArticle", :foreign_key => "article_id"
46
- end
47
-
48
- class ActiveRecordStat < ActiveRecord::Base
49
- belongs_to :article, :class_name => "ActiveRecordArticle", :foreign_key => "article_id"
50
- end
51
-
52
- class ActiveRecordClassWithTireMethods < ActiveRecord::Base
53
-
54
- def self.mapping
55
- "THIS IS MY MAPPING!"
56
- end
57
-
58
- def index
59
- "THIS IS MY INDEX!"
60
- end
61
-
62
- include Tire::Model::Search
63
- include Tire::Model::Callbacks
64
-
65
- tire do
66
- mapping do
67
- indexes :title, :type => 'string', :analyzer => 'snowball'
68
- end
69
- end
70
- end
71
-
72
- class ActiveRecordClassWithDynamicIndexName < ActiveRecord::Base
73
- include Tire::Model::Search
74
- include Tire::Model::Callbacks
75
-
76
- index_name do
77
- "dynamic" + '_' + "index"
78
- end
79
- end
80
-
81
- # Used in test for multiple class instances in one index,
82
- # and single table inheritance (STI) support.
83
-
84
- class ActiveRecordModelOne < ActiveRecord::Base
85
- include Tire::Model::Search
86
- include Tire::Model::Callbacks
87
- self.table_name = 'active_record_model_one'
88
- index_name 'active_record_model_one'
89
- end
90
-
91
- class ActiveRecordModelTwo < ActiveRecord::Base
92
- include Tire::Model::Search
93
- include Tire::Model::Callbacks
94
- self.table_name = 'active_record_model_two'
95
- index_name 'active_record_model_two'
96
- end
97
-
98
- class ActiveRecordAsset < ActiveRecord::Base
99
- include Tire::Model::Search
100
- include Tire::Model::Callbacks
101
- end
102
-
103
- class ActiveRecordVideo < ActiveRecordAsset
104
- index_name 'active_record_assets'
105
- end
106
-
107
- class ActiveRecordPhoto < ActiveRecordAsset
108
- index_name 'active_record_assets'
109
- end
110
-
111
- # Namespaced ActiveRecord models
112
-
113
- module ActiveRecordNamespace
114
- def self.table_name_prefix
115
- 'active_record_namespace_'
116
- end
117
- end
118
-
119
- class ActiveRecordNamespace::MyModel < ActiveRecord::Base
120
- include Tire::Model::Search
121
- include Tire::Model::Callbacks
122
- end
@@ -1,97 +0,0 @@
1
- require 'mongoid'
2
-
3
- class MongoidArticle
4
-
5
- include Mongoid::Document
6
-
7
-
8
- has_many :comments, :class_name => "MongoidComment", :foreign_key => "article_id"
9
- has_many :stats, :class_name => "MongoidStat", :foreign_key => "article_id"
10
-
11
- # def index
12
- # "KEEP OFF MY INDEX!!!"
13
- # end
14
- #
15
- # def self.settings
16
- # "KEEP OFF MY SETTINGS!!!"
17
- # end
18
-
19
- include Tire::Model::Search
20
- include Tire::Model::Callbacks
21
-
22
- tire do
23
- mapping do
24
- indexes :title, :type => 'string', :boost => 10, :analyzer => 'snowball'
25
- indexes :created_at, :type => 'date'
26
-
27
- indexes :comments do
28
- indexes :author
29
- indexes :body
30
- end
31
- end
32
- end
33
-
34
- # tire.mapping do
35
- # indexes :title, :type => 'string', :boost => 10, :analyzer => 'snowball'
36
- # end
37
-
38
- def to_indexed_json
39
- {
40
- :title => title,
41
- :length => length,
42
-
43
- :comments => comments.map { |c| { :_type => 'mongoid_comment',
44
- :_id => c.id,
45
- :author => c.author,
46
- :body => c.body } },
47
- :stats => stats.map { |s| { :pageviews => s.pageviews } }
48
- }.to_json
49
- end
50
-
51
- def length
52
- title.length
53
- end
54
-
55
- def comment_authors
56
- comments.map(&:author).to_sentence
57
- end
58
- end
59
-
60
- class MongoidComment
61
-
62
- include Mongoid::Document
63
-
64
-
65
- belongs_to :article, :class_name => "MongoidArticle", :foreign_key => "article_id"
66
- end
67
-
68
- class MongoidStat
69
-
70
- include Mongoid::Document
71
-
72
-
73
- belongs_to :article, :class_name => "MongoidArticle", :foreign_key => "article_id"
74
- end
75
-
76
- class MongoidClassWithTireMethods
77
-
78
- include Mongoid::Document
79
-
80
-
81
- def self.mapping
82
- "THIS IS MY MAPPING!"
83
- end
84
-
85
- def index
86
- "THIS IS MY INDEX!"
87
- end
88
-
89
- include Tire::Model::Search
90
- include Tire::Model::Callbacks
91
-
92
- tire do
93
- mapping do
94
- indexes :title, :type => 'string', :analyzer => 'snowball'
95
- end
96
- end
97
- end
@@ -1,11 +0,0 @@
1
- # Example class with ElasticSearch persistence
2
-
3
- class PersistentArticle
4
-
5
- include Tire::Model::Persistence
6
-
7
- property :title
8
- property :published_on
9
- property :tags
10
-
11
- end
@@ -1,12 +0,0 @@
1
- # Example namespaced class with ElasticSearch persistence
2
- #
3
- # The `document_type` is `my_namespace/persistent_article_in_namespace`
4
- #
5
-
6
- module MyNamespace
7
- class PersistentArticleInNamespace
8
- include Tire::Model::Persistence
9
-
10
- property :title
11
- end
12
- end
@@ -1,28 +0,0 @@
1
- class Author
2
- attr_accessor :first_name, :last_name
3
- def initialize(attributes)
4
- @first_name = HashWithIndifferentAccess.new(attributes)[:first_name]
5
- @last_name = HashWithIndifferentAccess.new(attributes)[:last_name]
6
- end
7
- end
8
-
9
- class Comment
10
- def initialize(params); @attributes = HashWithIndifferentAccess.new(params); end
11
- def method_missing(method_name, *arguments); @attributes[method_name]; end
12
- def as_json(*); @attributes; end
13
- end
14
-
15
- class PersistentArticleWithCastedItem
16
- include Tire::Model::Persistence
17
-
18
- property :title
19
- property :author, :class => Author
20
- property :stats
21
- end
22
-
23
- class PersistentArticleWithCastedCollection
24
- include Tire::Model::Persistence
25
-
26
- property :title
27
- property :comments, :class => [Comment]
28
- end
@@ -1,11 +0,0 @@
1
- class PersistentArticleWithDefaults
2
-
3
- include Tire::Model::Persistence
4
-
5
- property :title
6
- property :published_on
7
- property :tags, :default => []
8
- property :hidden, :default => false
9
- property :options, :default => {:switches => []}
10
-
11
- end
@@ -1,10 +0,0 @@
1
- # Example class with ElasticSearch persistence and custom index name
2
-
3
- class PersistentArticleWithCustomIndexName
4
-
5
- include Tire::Model::Persistence
6
-
7
- property :title
8
-
9
- index_name 'custom-index-name'
10
- end
@@ -1,17 +0,0 @@
1
- # Example ActiveModel class for testing :searchable mode
2
-
3
- require 'rubygems'
4
- require 'redis/persistence'
5
-
6
- class SupermodelArticle
7
- include Redis::Persistence
8
-
9
- include Tire::Model::Search
10
- include Tire::Model::Callbacks
11
-
12
- property :title
13
-
14
- mapping do
15
- indexes :title, :type => 'string', :boost => 15, :analyzer => 'czech'
16
- end
17
- end
@@ -1,11 +0,0 @@
1
- # Example ActiveModel with validations
2
-
3
- class ValidatedModel
4
-
5
- include Tire::Model::Persistence
6
-
7
- property :name
8
-
9
- validates_presence_of :name
10
-
11
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Tire
4
- module Model
5
-
6
- class ActiveModelLintTest < Test::Unit::TestCase
7
-
8
- include ActiveModel::Lint::Tests
9
-
10
- def setup
11
- @model = PersistentArticle.new :title => 'Test'
12
- end
13
-
14
- end
15
-
16
- end
17
- end
@@ -1,116 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ModelOne
4
- extend ActiveModel::Naming
5
- include Tire::Model::Search
6
- include Tire::Model::Callbacks
7
-
8
- def save; false; end
9
- def destroy; false; end
10
- end
11
-
12
- class ModelTwo
13
- extend ActiveModel::Naming
14
- extend ActiveModel::Callbacks
15
- define_model_callbacks :save, :destroy
16
-
17
- include Tire::Model::Search
18
- include Tire::Model::Callbacks
19
-
20
- def save; _run_save_callbacks {}; end
21
- def destroy; _run_destroy_callbacks { @destroyed = true }; end
22
-
23
- def destroyed?; !!@destroyed; end
24
- end
25
-
26
- class ModelThree
27
- extend ActiveModel::Naming
28
- extend ActiveModel::Callbacks
29
- define_model_callbacks :save, :destroy
30
-
31
- include Tire::Model::Search
32
- include Tire::Model::Callbacks
33
-
34
- def save; _run_save_callbacks {}; end
35
- def destroy; _run_destroy_callbacks {}; end
36
- end
37
-
38
- class ModelWithoutTireAutoCallbacks
39
- extend ActiveModel::Naming
40
- extend ActiveModel::Callbacks
41
- define_model_callbacks :save, :destroy
42
-
43
- include Tire::Model::Search
44
- # DO NOT include Callbacks
45
-
46
- def save; _run_save_callbacks {}; end
47
- def destroy; _run_destroy_callbacks {}; end
48
- end
49
-
50
- module Tire
51
- module Model
52
-
53
- class ModelCallbacksTest < Test::Unit::TestCase
54
-
55
- context "Model without ActiveModel callbacks" do
56
-
57
- should "not execute any callbacks" do
58
- m = ModelOne.new
59
- m.tire.expects(:update_index).never
60
-
61
- m.save
62
- m.destroy
63
- end
64
-
65
- end
66
-
67
- context "Model with ActiveModel callbacks and implemented destroyed? method" do
68
-
69
- should "execute the callbacks" do
70
- m = ModelTwo.new
71
- m.tire.expects(:update_index).twice
72
-
73
- m.save
74
- m.destroy
75
- end
76
-
77
- end
78
-
79
- context "Model with ActiveModel callbacks without destroyed? method implemented" do
80
-
81
- should "have the destroyed? method added" do
82
- assert_respond_to ModelThree.new, :destroyed?
83
- end
84
-
85
- should "execute the callbacks" do
86
- m = ModelThree.new
87
- m.tire.expects(:update_index).twice
88
-
89
- m.save
90
- m.destroy
91
- end
92
-
93
- end
94
-
95
- context "Model without Tire::Callbacks included" do
96
-
97
- should "respond to Tire update_index callbacks" do
98
- assert_respond_to ModelWithoutTireAutoCallbacks, :after_update_elasticsearch_index
99
- assert_respond_to ModelWithoutTireAutoCallbacks, :before_update_elasticsearch_index
100
- end
101
-
102
- should "not execute the update_index hooks" do
103
- m = ModelWithoutTireAutoCallbacks.new
104
- m.tire.expects(:update_index).never
105
-
106
- m.save
107
- m.destroy
108
- end
109
- end
110
-
111
- # ---------------------------------------------------------------------------
112
-
113
- end
114
-
115
- end
116
- end