friendlyfashion-thinking-sphinx 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/HISTORY +244 -0
  2. data/LICENCE +20 -0
  3. data/README.textile +235 -0
  4. data/features/abstract_inheritance.feature +10 -0
  5. data/features/alternate_primary_key.feature +27 -0
  6. data/features/attribute_transformation.feature +22 -0
  7. data/features/attribute_updates.feature +77 -0
  8. data/features/deleting_instances.feature +67 -0
  9. data/features/direct_attributes.feature +11 -0
  10. data/features/excerpts.feature +21 -0
  11. data/features/extensible_delta_indexing.feature +9 -0
  12. data/features/facets.feature +88 -0
  13. data/features/facets_across_model.feature +29 -0
  14. data/features/field_sorting.feature +18 -0
  15. data/features/handling_edits.feature +94 -0
  16. data/features/retry_stale_indexes.feature +24 -0
  17. data/features/searching_across_models.feature +20 -0
  18. data/features/searching_by_index.feature +40 -0
  19. data/features/searching_by_model.feature +175 -0
  20. data/features/searching_with_find_arguments.feature +56 -0
  21. data/features/sphinx_detection.feature +25 -0
  22. data/features/sphinx_scopes.feature +68 -0
  23. data/features/step_definitions/alpha_steps.rb +16 -0
  24. data/features/step_definitions/beta_steps.rb +7 -0
  25. data/features/step_definitions/common_steps.rb +201 -0
  26. data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
  27. data/features/step_definitions/facet_steps.rb +96 -0
  28. data/features/step_definitions/find_arguments_steps.rb +36 -0
  29. data/features/step_definitions/gamma_steps.rb +15 -0
  30. data/features/step_definitions/scope_steps.rb +19 -0
  31. data/features/step_definitions/search_steps.rb +94 -0
  32. data/features/step_definitions/sphinx_steps.rb +35 -0
  33. data/features/sti_searching.feature +19 -0
  34. data/features/support/env.rb +27 -0
  35. data/features/support/lib/generic_delta_handler.rb +8 -0
  36. data/features/thinking_sphinx/database.example.yml +3 -0
  37. data/features/thinking_sphinx/db/.gitignore +1 -0
  38. data/features/thinking_sphinx/db/fixtures/alphas.rb +8 -0
  39. data/features/thinking_sphinx/db/fixtures/authors.rb +1 -0
  40. data/features/thinking_sphinx/db/fixtures/betas.rb +11 -0
  41. data/features/thinking_sphinx/db/fixtures/boxes.rb +9 -0
  42. data/features/thinking_sphinx/db/fixtures/categories.rb +1 -0
  43. data/features/thinking_sphinx/db/fixtures/cats.rb +3 -0
  44. data/features/thinking_sphinx/db/fixtures/comments.rb +24 -0
  45. data/features/thinking_sphinx/db/fixtures/developers.rb +31 -0
  46. data/features/thinking_sphinx/db/fixtures/dogs.rb +3 -0
  47. data/features/thinking_sphinx/db/fixtures/extensible_betas.rb +10 -0
  48. data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
  49. data/features/thinking_sphinx/db/fixtures/gammas.rb +10 -0
  50. data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
  51. data/features/thinking_sphinx/db/fixtures/people.rb +1001 -0
  52. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
  53. data/features/thinking_sphinx/db/fixtures/posts.rb +10 -0
  54. data/features/thinking_sphinx/db/fixtures/robots.rb +8 -0
  55. data/features/thinking_sphinx/db/fixtures/tags.rb +27 -0
  56. data/features/thinking_sphinx/db/migrations/create_alphas.rb +8 -0
  57. data/features/thinking_sphinx/db/migrations/create_animals.rb +5 -0
  58. data/features/thinking_sphinx/db/migrations/create_authors.rb +3 -0
  59. data/features/thinking_sphinx/db/migrations/create_authors_posts.rb +6 -0
  60. data/features/thinking_sphinx/db/migrations/create_betas.rb +5 -0
  61. data/features/thinking_sphinx/db/migrations/create_boxes.rb +5 -0
  62. data/features/thinking_sphinx/db/migrations/create_categories.rb +3 -0
  63. data/features/thinking_sphinx/db/migrations/create_comments.rb +10 -0
  64. data/features/thinking_sphinx/db/migrations/create_developers.rb +7 -0
  65. data/features/thinking_sphinx/db/migrations/create_extensible_betas.rb +5 -0
  66. data/features/thinking_sphinx/db/migrations/create_gammas.rb +3 -0
  67. data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
  68. data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
  69. data/features/thinking_sphinx/db/migrations/create_people.rb +13 -0
  70. data/features/thinking_sphinx/db/migrations/create_posts.rb +6 -0
  71. data/features/thinking_sphinx/db/migrations/create_robots.rb +4 -0
  72. data/features/thinking_sphinx/db/migrations/create_taggings.rb +5 -0
  73. data/features/thinking_sphinx/db/migrations/create_tags.rb +4 -0
  74. data/features/thinking_sphinx/models/alpha.rb +23 -0
  75. data/features/thinking_sphinx/models/andrew.rb +17 -0
  76. data/features/thinking_sphinx/models/animal.rb +5 -0
  77. data/features/thinking_sphinx/models/author.rb +3 -0
  78. data/features/thinking_sphinx/models/beta.rb +13 -0
  79. data/features/thinking_sphinx/models/box.rb +8 -0
  80. data/features/thinking_sphinx/models/cat.rb +3 -0
  81. data/features/thinking_sphinx/models/category.rb +4 -0
  82. data/features/thinking_sphinx/models/comment.rb +10 -0
  83. data/features/thinking_sphinx/models/developer.rb +21 -0
  84. data/features/thinking_sphinx/models/dog.rb +3 -0
  85. data/features/thinking_sphinx/models/extensible_beta.rb +9 -0
  86. data/features/thinking_sphinx/models/fox.rb +5 -0
  87. data/features/thinking_sphinx/models/gamma.rb +5 -0
  88. data/features/thinking_sphinx/models/genre.rb +3 -0
  89. data/features/thinking_sphinx/models/medium.rb +5 -0
  90. data/features/thinking_sphinx/models/music.rb +10 -0
  91. data/features/thinking_sphinx/models/person.rb +24 -0
  92. data/features/thinking_sphinx/models/post.rb +22 -0
  93. data/features/thinking_sphinx/models/robot.rb +12 -0
  94. data/features/thinking_sphinx/models/tag.rb +3 -0
  95. data/features/thinking_sphinx/models/tagging.rb +4 -0
  96. data/lib/cucumber/thinking_sphinx/external_world.rb +12 -0
  97. data/lib/cucumber/thinking_sphinx/internal_world.rb +137 -0
  98. data/lib/cucumber/thinking_sphinx/sql_logger.rb +28 -0
  99. data/lib/thinking-sphinx.rb +1 -0
  100. data/lib/thinking_sphinx/action_controller.rb +31 -0
  101. data/lib/thinking_sphinx/active_record/attribute_updates.rb +53 -0
  102. data/lib/thinking_sphinx/active_record/collection_proxy.rb +47 -0
  103. data/lib/thinking_sphinx/active_record/collection_proxy_with_scopes.rb +27 -0
  104. data/lib/thinking_sphinx/active_record/delta.rb +67 -0
  105. data/lib/thinking_sphinx/active_record/has_many_association.rb +44 -0
  106. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +21 -0
  107. data/lib/thinking_sphinx/active_record/log_subscriber.rb +61 -0
  108. data/lib/thinking_sphinx/active_record/scopes.rb +110 -0
  109. data/lib/thinking_sphinx/active_record.rb +386 -0
  110. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +87 -0
  111. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +62 -0
  112. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +188 -0
  113. data/lib/thinking_sphinx/association.rb +230 -0
  114. data/lib/thinking_sphinx/attribute.rb +405 -0
  115. data/lib/thinking_sphinx/auto_version.rb +40 -0
  116. data/lib/thinking_sphinx/bundled_search.rb +44 -0
  117. data/lib/thinking_sphinx/class_facet.rb +20 -0
  118. data/lib/thinking_sphinx/configuration.rb +375 -0
  119. data/lib/thinking_sphinx/context.rb +76 -0
  120. data/lib/thinking_sphinx/core/string.rb +15 -0
  121. data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
  122. data/lib/thinking_sphinx/deltas.rb +28 -0
  123. data/lib/thinking_sphinx/deploy/capistrano.rb +99 -0
  124. data/lib/thinking_sphinx/excerpter.rb +23 -0
  125. data/lib/thinking_sphinx/facet.rb +135 -0
  126. data/lib/thinking_sphinx/facet_search.rb +170 -0
  127. data/lib/thinking_sphinx/field.rb +98 -0
  128. data/lib/thinking_sphinx/index/builder.rb +315 -0
  129. data/lib/thinking_sphinx/index/faux_column.rb +118 -0
  130. data/lib/thinking_sphinx/index.rb +159 -0
  131. data/lib/thinking_sphinx/join.rb +37 -0
  132. data/lib/thinking_sphinx/property.rb +187 -0
  133. data/lib/thinking_sphinx/railtie.rb +43 -0
  134. data/lib/thinking_sphinx/search.rb +1061 -0
  135. data/lib/thinking_sphinx/search_methods.rb +439 -0
  136. data/lib/thinking_sphinx/sinatra.rb +7 -0
  137. data/lib/thinking_sphinx/source/internal_properties.rb +51 -0
  138. data/lib/thinking_sphinx/source/sql.rb +174 -0
  139. data/lib/thinking_sphinx/source.rb +194 -0
  140. data/lib/thinking_sphinx/tasks.rb +142 -0
  141. data/lib/thinking_sphinx/test.rb +55 -0
  142. data/lib/thinking_sphinx/version.rb +3 -0
  143. data/lib/thinking_sphinx.rb +297 -0
  144. data/spec/fixtures/data.sql +32 -0
  145. data/spec/fixtures/database.yml.default +3 -0
  146. data/spec/fixtures/models.rb +164 -0
  147. data/spec/fixtures/structure.sql +146 -0
  148. data/spec/spec_helper.rb +61 -0
  149. data/spec/sphinx_helper.rb +60 -0
  150. data/spec/support/rails.rb +25 -0
  151. data/spec/thinking_sphinx/active_record/delta_spec.rb +122 -0
  152. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +173 -0
  153. data/spec/thinking_sphinx/active_record/scopes_spec.rb +176 -0
  154. data/spec/thinking_sphinx/active_record_spec.rb +573 -0
  155. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +145 -0
  156. data/spec/thinking_sphinx/association_spec.rb +250 -0
  157. data/spec/thinking_sphinx/attribute_spec.rb +552 -0
  158. data/spec/thinking_sphinx/auto_version_spec.rb +103 -0
  159. data/spec/thinking_sphinx/configuration_spec.rb +326 -0
  160. data/spec/thinking_sphinx/context_spec.rb +126 -0
  161. data/spec/thinking_sphinx/core/array_spec.rb +9 -0
  162. data/spec/thinking_sphinx/core/string_spec.rb +9 -0
  163. data/spec/thinking_sphinx/excerpter_spec.rb +49 -0
  164. data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
  165. data/spec/thinking_sphinx/facet_spec.rb +359 -0
  166. data/spec/thinking_sphinx/field_spec.rb +127 -0
  167. data/spec/thinking_sphinx/index/builder_spec.rb +532 -0
  168. data/spec/thinking_sphinx/index/faux_column_spec.rb +36 -0
  169. data/spec/thinking_sphinx/index_spec.rb +189 -0
  170. data/spec/thinking_sphinx/search_methods_spec.rb +156 -0
  171. data/spec/thinking_sphinx/search_spec.rb +1455 -0
  172. data/spec/thinking_sphinx/source_spec.rb +267 -0
  173. data/spec/thinking_sphinx/test_spec.rb +20 -0
  174. data/spec/thinking_sphinx_spec.rb +204 -0
  175. metadata +524 -0
@@ -0,0 +1,32 @@
1
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Ellie','K','Ford','38 Mills Street','Eagle Farm Bc','QLD','4009','Ellie.K.Ford@mailinator.com','1970/1/23 00:00:00', 3, 'CricketTeam');
2
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Aaliyah','E','Allen','71 Murphy Street','Wyola West','WA','6407','Aaliyah.E.Allen@dodgit.com','1980/3/23 00:00:00', 3, 'CricketTeam');
3
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Callum','C','Miah','89 Dalgarno Street','Bullawa Creek','NSW','2390','Callum.C.Miah@trashymail.com','1973/3/25 00:00:00', 3, 'CricketTeam');
4
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Finley','L','Buckley','18 Queen Street','Manly Vale','NSW','2093','Finley.L.Buckley@spambob.com','1962/11/20 00:00:00', 3, 'CricketTeam');
5
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Poppy','A','Hilton','36 Nerrigundah Drive','Nyora','VIC','3987','Poppy.A.Hilton@dodgit.com','1972/10/30 00:00:00', 3, 'CricketTeam');
6
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Eloise','Z','Kennedy','18 Mt Berryman Road','Lilydale','QLD','4344','Eloise.Z.Kennedy@spambob.com','1973/9/28 00:00:00', 3, 'CricketTeam');
7
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Shannon','L','Manning','60 Ocean Pde','Greenvale','QLD','4816','Shannon.L.Manning@dodgit.com','1956/6/13 00:00:00', 3, 'FootballTeam');
8
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Oscar','C','Lawson','43 Feather Street','Battery Hill','QLD','4551','Oscar.C.Lawson@spambob.com','1979/10/17 00:00:00', 3, 'CricketTeam');
9
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('female','Sofia','K','Bray','26 Clifton Street','Pental Island','VIC','3586','Sofia.K.Bray@mailinator.com','1970/5/10 00:00:00', 3, 'CricketTeam');
10
+ insert into `people` (gender, first_name, middle_initial, last_name, street_address, city, state, postcode, email, birthday, team_id, team_type) values('male','Andrew','N','Byrne','35 Cecil Street','Monash Park','NSW','2111','Andrew.N.Byrne@spambob.com','1983/2/16 00:00:00', 3, 'CricketTeam');
11
+
12
+ insert into `alphas` (name) values ('one');
13
+ insert into `alphas` (name) values ('two');
14
+ insert into `alphas` (name) values ('three');
15
+ insert into `alphas` (name) values ('four');
16
+ insert into `alphas` (name) values ('five');
17
+ insert into `alphas` (name) values ('six');
18
+ insert into `alphas` (name) values ('seven');
19
+ insert into `alphas` (name) values ('eight');
20
+ insert into `alphas` (name) values ('nine');
21
+ insert into `alphas` (name) values ('ten');
22
+
23
+ insert into `betas` (name) values ('one');
24
+ insert into `betas` (name) values ('two');
25
+ insert into `betas` (name) values ('three');
26
+ insert into `betas` (name) values ('four');
27
+ insert into `betas` (name) values ('five');
28
+ insert into `betas` (name) values ('six');
29
+ insert into `betas` (name) values ('seven');
30
+ insert into `betas` (name) values ('eight');
31
+ insert into `betas` (name) values ('nine');
32
+ insert into `betas` (name) values ('ten');
@@ -0,0 +1,3 @@
1
+ username: root
2
+ password:
3
+ host: localhost
@@ -0,0 +1,164 @@
1
+ class Tag < ActiveRecord::Base
2
+ belongs_to :person
3
+ belongs_to :football_team
4
+ belongs_to :cricket_team
5
+ end
6
+
7
+ class FootballTeam < ActiveRecord::Base
8
+ has_many :tags
9
+ has_many :people, :through => :tags
10
+ end
11
+
12
+ class CricketTeam < ActiveRecord::Base
13
+ has_many :people, :foreign_key => :team_id
14
+
15
+ define_index do
16
+ indexes :name
17
+ has "SELECT cricket_team_id, id FROM tags", :source => :query, :as => :tags
18
+ end
19
+ end
20
+
21
+ class Contact < ActiveRecord::Base
22
+ belongs_to :person
23
+ end
24
+
25
+ class Friendship < ActiveRecord::Base
26
+ belongs_to :person
27
+ belongs_to :friend, :class_name => "Person", :foreign_key => :friend_id
28
+
29
+ define_index do
30
+ indexes "'something'", :as => :something
31
+ has person_id, friend_id
32
+
33
+ set_property :latitude_attr => :person_id
34
+ set_property :longitude_attr => :person_id
35
+ end
36
+
37
+ sphinx_scope(:reverse) {
38
+ {:order => "@weight ASC"}
39
+ }
40
+ end
41
+
42
+ class Link < ActiveRecord::Base
43
+ has_and_belongs_to_many :people
44
+ end
45
+
46
+ class Person < ActiveRecord::Base
47
+ belongs_to :team, :polymorphic => :true
48
+ belongs_to :source, :polymorphic => :true
49
+ has_many :contacts
50
+
51
+ has_many :friendships
52
+ has_many :friends, :through => :friendships
53
+
54
+ has_many :tags
55
+ has_many :football_teams, :through => :tags
56
+
57
+ has_and_belongs_to_many :links
58
+
59
+ define_index do
60
+ indexes [first_name, middle_initial, last_name], :as => :name
61
+ indexes team.name, :as => :team_name
62
+ indexes contacts.phone_number, :as => :phone_numbers
63
+ indexes city, :prefixes => true, :facet => true
64
+ indexes state, :infixes => true, :facet => true
65
+
66
+ has [first_name, middle_initial, last_name], :as => :name_sort
67
+ has team.name, :as => :team_name_sort
68
+
69
+ has [:id, :team_id], :as => :ids
70
+ has team(:id), :as => :team_id
71
+ has football_teams(:id), :as => :football_team_id
72
+
73
+ has contacts.phone_number, :as => :phone_number_sort
74
+ has contacts(:id), :as => :contact_ids
75
+
76
+ has birthday, :facet => true
77
+
78
+ has friendships.person_id, :as => :friendly_ids
79
+
80
+ has :id, :as => :latitude
81
+ has :id, :as => :longitude
82
+
83
+ set_property :delta => true
84
+ end
85
+ end
86
+
87
+ class Parent < Person
88
+ end
89
+
90
+ module Admin
91
+ class Person < ::Person
92
+ end
93
+ end
94
+
95
+ class Child < Person
96
+ belongs_to :parent
97
+ define_index do
98
+ indexes [parent.first_name, parent.middle_initial, parent.last_name], :as => :parent_name
99
+ end
100
+ end
101
+
102
+ class Teenager < Child
103
+ end
104
+
105
+ class Alpha < ActiveRecord::Base
106
+ has_many :betas, :class_name => 'Beta'
107
+ has_many :thetas
108
+
109
+ define_index do
110
+ indexes :name, :sortable => true
111
+
112
+ has :id, :as => :lat
113
+ has :id, :as => :lng
114
+
115
+ set_property :field_weights => {"name" => 10}
116
+ end
117
+
118
+ def big_name
119
+ name.upcase
120
+ end
121
+
122
+ def sphinx_attributes
123
+ :existing
124
+ end
125
+ end
126
+
127
+ class Beta < ActiveRecord::Base
128
+ has_many :gammas
129
+
130
+ define_index do
131
+ indexes :name, :sortable => true
132
+
133
+ has :id, :as => :lat
134
+ has :id, :as => :lon
135
+
136
+ set_property :delta => true
137
+ end
138
+
139
+ def excerpts
140
+ false
141
+ end
142
+
143
+ def matching_fields
144
+ :foo
145
+ end
146
+ end
147
+
148
+ class Gamma < ActiveRecord::Base
149
+ #
150
+ end
151
+
152
+ class Theta < ActiveRecord::Base
153
+ #
154
+ end
155
+
156
+ class Search < ActiveRecord::Base
157
+ #
158
+ end
159
+
160
+ class BigFoo < ActiveRecord::Base
161
+ define_index do
162
+ indexes name
163
+ end
164
+ end
@@ -0,0 +1,146 @@
1
+ DROP TABLE IF EXISTS `people`;
2
+
3
+ CREATE TABLE `people` (
4
+ `id` int(11) NOT NULL auto_increment,
5
+ `first_name` varchar(50) NULL,
6
+ `middle_initial` varchar(10) NULL,
7
+ `last_name` varchar(50) NULL,
8
+ `gender` varchar(10) NULL,
9
+ `street_address` varchar(200) NULL,
10
+ `city` varchar(100) NULL,
11
+ `state` varchar(100) NULL,
12
+ `postcode` varchar(10) NULL,
13
+ `email` varchar(100) NULL,
14
+ `birthday` datetime NULL,
15
+ `team_id` int(11) NULL,
16
+ `team_type` varchar(50) NULL,
17
+ `type` varchar(50) NULL,
18
+ `parent_id` varchar(50) NULL,
19
+ `source_id` int(11) NULL,
20
+ `source_type` varchar(50) NULL,
21
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
22
+ PRIMARY KEY (`id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24
+
25
+ DROP TABLE IF EXISTS `friendships`;
26
+
27
+ CREATE TABLE `friendships` (
28
+ `id` int(11) NOT NULL auto_increment,
29
+ `person_id` int(11) NOT NULL,
30
+ `friend_id` int(11) NOT NULL,
31
+ `created_at` datetime NOT NULL,
32
+ `created_on` date NULL,
33
+ `updated_at` datetime NOT NULL,
34
+ PRIMARY KEY (`id`)
35
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36
+
37
+ DROP TABLE IF EXISTS `football_teams`;
38
+
39
+ CREATE TABLE `football_teams` (
40
+ `id` int(11) NOT NULL auto_increment,
41
+ `name` varchar(50) NOT NULL,
42
+ `state` varchar(50) NOT NULL,
43
+ `league` varchar(50) NOT NULL,
44
+ PRIMARY KEY (`id`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
46
+
47
+ DROP TABLE IF EXISTS `cricket_teams`;
48
+
49
+ CREATE TABLE `cricket_teams` (
50
+ `id` int(11) NOT NULL auto_increment,
51
+ `name` varchar(50) NOT NULL,
52
+ `state` varchar(50) NOT NULL,
53
+ PRIMARY KEY (`id`)
54
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
55
+
56
+ DROP TABLE IF EXISTS `contacts`;
57
+
58
+ CREATE TABLE `contacts` (
59
+ `id` int(11) NOT NULL auto_increment,
60
+ `phone_number` varchar(50) NOT NULL,
61
+ `person_id` int(11) NOT NULL,
62
+ PRIMARY KEY (`id`)
63
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
64
+
65
+ DROP TABLE IF EXISTS `alphas`;
66
+
67
+ CREATE TABLE `alphas` (
68
+ `id` int(11) NOT NULL auto_increment,
69
+ `name` varchar(50) NOT NULL,
70
+ `value` int(11),
71
+ `cost` decimal(10,6),
72
+ PRIMARY KEY (`id`)
73
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
74
+
75
+ DROP TABLE IF EXISTS `betas`;
76
+
77
+ CREATE TABLE `betas` (
78
+ `id` int(11) NOT NULL auto_increment,
79
+ `name` varchar(50) NOT NULL,
80
+ `alpha_id` int(11),
81
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
82
+ PRIMARY KEY (`id`)
83
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
84
+
85
+ DROP TABLE IF EXISTS `gammas`;
86
+
87
+ CREATE TABLE `gammas` (
88
+ `id` int(11) NOT NULL auto_increment,
89
+ `name` varchar(50) NOT NULL,
90
+ `value` int(11),
91
+ `beta_id` int(11),
92
+ PRIMARY KEY (`id`)
93
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
94
+
95
+ DROP TABLE IF EXISTS `thetas`;
96
+
97
+ CREATE TABLE `thetas` (
98
+ `id` int(11) NOT NULL auto_increment,
99
+ `name` varchar(50) NOT NULL,
100
+ `value` int(11),
101
+ `alpha_id` int(11),
102
+ PRIMARY KEY (`id`)
103
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
104
+
105
+ DROP TABLE IF EXISTS `searches`;
106
+
107
+ CREATE TABLE `searches` (
108
+ `id` int(11) NOT NULL auto_increment,
109
+ `name` varchar(50) NOT NULL,
110
+ PRIMARY KEY (`id`)
111
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
112
+
113
+ DROP TABLE IF EXISTS `tags`;
114
+
115
+ CREATE TABLE `tags` (
116
+ `id` int(11) NOT NULL auto_increment,
117
+ `person_id` int(11) NOT NULL,
118
+ `football_team_id` int(11) NOT NULL,
119
+ `cricket_team_id` int(11) NOT NULL,
120
+ `name` varchar(50) NOT NULL,
121
+ PRIMARY KEY (`id`)
122
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
123
+
124
+ DROP TABLE IF EXISTS `links`;
125
+
126
+ CREATE TABLE `links` (
127
+ `id` int(11) NOT NULL auto_increment,
128
+ `url` varchar(50) NOT NULL,
129
+ `description` varchar(200),
130
+ PRIMARY KEY (`id`)
131
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
132
+
133
+ DROP TABLE IF EXISTS `links_people`;
134
+
135
+ CREATE TABLE `links_people` (
136
+ `link_id` int(11) NOT NULL,
137
+ `person_id` int(11) NOT NULL
138
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
139
+
140
+ DROP TABLE IF EXISTS `big_foos`;
141
+
142
+ CREATE TABLE `big_foos` (
143
+ `id` bigint NOT NULL auto_increment,
144
+ `name` varchar(50) NOT NULL,
145
+ PRIMARY KEY (`id`)
146
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -0,0 +1,61 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ Dir[File.join(File.dirname(__FILE__), '../vendor/*/lib')].each do |path|
3
+ $:.unshift path
4
+ end
5
+
6
+ require 'fileutils'
7
+ require 'logger'
8
+ require 'bundler'
9
+
10
+ Bundler.require :default, :development
11
+
12
+ require 'active_support/core_ext/module/attribute_accessors'
13
+ require "#{File.dirname(__FILE__)}/sphinx_helper"
14
+
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ ThinkingSphinx::Configuration.instance
18
+ ThinkingSphinx::ActiveRecord::LogSubscriber.logger = Logger.new(StringIO.new)
19
+
20
+ RSpec.configure do |config|
21
+ %w( tmp tmp/config tmp/log tmp/db ).each do |path|
22
+ FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
23
+ end
24
+
25
+ sphinx = SphinxHelper.new
26
+ sphinx.setup_mysql
27
+
28
+ ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)
29
+
30
+ require "#{File.dirname(__FILE__)}/fixtures/models"
31
+ ThinkingSphinx.context.define_indexes
32
+
33
+ config.before :each do
34
+ %w( tmp tmp/config tmp/log tmp/db ).each do |path|
35
+ FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
36
+ end
37
+
38
+ ThinkingSphinx.updates_enabled = true
39
+ ThinkingSphinx.deltas_enabled = true
40
+ ThinkingSphinx.suppress_delta_output = true
41
+
42
+ ThinkingSphinx::Configuration.instance.reset
43
+ end
44
+
45
+ config.after :all do
46
+ FileUtils.rm_r "#{Dir.pwd}/tmp" rescue nil
47
+ end
48
+ end
49
+
50
+ def minimal_result_hashes(*instances)
51
+ instances.collect do |instance|
52
+ {
53
+ :weight => 21,
54
+ :attributes => {
55
+ 'sphinx_internal_id' => instance.id,
56
+ 'sphinx_internal_class' => instance.class.name,
57
+ 'class_crc' => instance.class.name.to_crc32
58
+ }
59
+ }
60
+ end
61
+ end
@@ -0,0 +1,60 @@
1
+ require 'active_record'
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+ require 'active_record/connection_adapters/postgresql_adapter'
4
+ require 'yaml'
5
+
6
+ class SphinxHelper
7
+ attr_accessor :host, :username, :password, :socket
8
+ attr_reader :path
9
+
10
+ def initialize
11
+ @host = 'localhost'
12
+ @username = 'root'
13
+ @password = ''
14
+
15
+ if File.exist?('spec/fixtures/database.yml')
16
+ config = YAML.load(File.open('spec/fixtures/database.yml'))
17
+ @host = config['host']
18
+ @username = config['username']
19
+ @password = config['password']
20
+ @socket = config['socket']
21
+ @sslca = config['sslca']
22
+ @sslcert = config['sslcert']
23
+ @sslkey = config['sslkey']
24
+ end
25
+
26
+ @path = File.expand_path(File.dirname(__FILE__))
27
+ end
28
+
29
+ def setup_mysql
30
+ ActiveRecord::Base.establish_connection(
31
+ :adapter => mysql_adapter,
32
+ :database => 'thinking_sphinx',
33
+ :username => @username,
34
+ :password => @password,
35
+ :host => @host,
36
+ :socket => @socket,
37
+ :sslca => @sslca,
38
+ :sslcert => @sslcert,
39
+ :sslkey => @sslkey
40
+ )
41
+ ActiveRecord::Base.logger = Logger.new(File.open('tmp/activerecord.log', 'a'))
42
+
43
+ structure = File.open('spec/fixtures/structure.sql') { |f| f.read.chomp }
44
+ structure.split(';').each { |table|
45
+ ActiveRecord::Base.connection.execute table
46
+ }
47
+
48
+ File.open('spec/fixtures/data.sql') { |f|
49
+ while line = f.gets
50
+ ActiveRecord::Base.connection.execute line unless line.blank?
51
+ end
52
+ }
53
+ end
54
+
55
+ private
56
+
57
+ def mysql_adapter
58
+ defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'
59
+ end
60
+ end
@@ -0,0 +1,25 @@
1
+ module Rails
2
+ def self.root
3
+ File.join(Dir.pwd, 'tmp')
4
+ end
5
+
6
+ def self.env
7
+ @@environment ||= 'development'
8
+ end
9
+
10
+ def self.env=(env)
11
+ @@environment = env
12
+ end
13
+
14
+ def self.application
15
+ @@application ||= begin
16
+ railties = Struct.new(:engines).new([])
17
+ Struct.new(:paths, :railties).new(Hash.new([]), railties)
18
+ end
19
+ end
20
+ end
21
+
22
+ ActiveSupport::Inflector.inflections do |inflect|
23
+ inflect.plural /^beta$/i, 'betas'
24
+ inflect.singular /^betas$/i, 'beta'
25
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ThinkingSphinx::ActiveRecord::Delta" do
4
+ it "should call the toggle_delta method after a save" do
5
+ @beta = Beta.new(:name => 'beta')
6
+ @beta.should_receive(:toggle_delta).at_least(1).times.and_return(true)
7
+
8
+ @beta.save
9
+ end
10
+
11
+ it "should call the toggle_delta method after a save!" do
12
+ @beta = Beta.new(:name => 'beta')
13
+ @beta.should_receive(:toggle_delta).at_least(1).times.and_return(true)
14
+
15
+ @beta.save!
16
+ end
17
+
18
+ describe "suspended_delta method" do
19
+ before :each do
20
+ ThinkingSphinx.deltas_suspended = false
21
+ Person.sphinx_indexes.first.delta_object.stub!(:` => "")
22
+ end
23
+
24
+ it "should execute the argument block with deltas disabled" do
25
+ ThinkingSphinx.should_receive(:deltas_suspended=).once.with(true)
26
+ ThinkingSphinx.should_receive(:deltas_suspended=).once.with(false)
27
+ lambda { Person.suspended_delta { raise 'i was called' } }.should(
28
+ raise_error(Exception)
29
+ )
30
+ end
31
+
32
+ it "should restore deltas_enabled to its original setting" do
33
+ ThinkingSphinx.deltas_suspended = true
34
+ ThinkingSphinx.should_receive(:deltas_suspended=).twice.with(true)
35
+ Person.suspended_delta { 'no-op' }
36
+ end
37
+
38
+ it "should restore deltas_enabled to its original setting even if there was an exception" do
39
+ ThinkingSphinx.deltas_suspended = true
40
+ ThinkingSphinx.should_receive(:deltas_suspended=).twice.with(true)
41
+ lambda { Person.suspended_delta { raise 'bad error' } }.should(
42
+ raise_error(Exception)
43
+ )
44
+ end
45
+
46
+ it "should reindex by default after the code block is run" do
47
+ Person.should_receive(:index_delta)
48
+ Person.suspended_delta { 'no-op' }
49
+ end
50
+
51
+ it "should not reindex after the code block if false is passed in" do
52
+ Person.should_not_receive(:index_delta)
53
+ Person.suspended_delta(false) { 'no-op' }
54
+ end
55
+ end
56
+
57
+ describe "toggle_delta method" do
58
+ it "should set the delta value to true" do
59
+ @person = Person.new
60
+
61
+ @person.delta.should be_false
62
+ @person.send(:toggle_delta)
63
+ @person.delta.should be_true
64
+ end
65
+ end
66
+
67
+ describe "index_delta method" do
68
+ before :each do
69
+ ThinkingSphinx::Configuration.stub!(:environment => "spec")
70
+ ThinkingSphinx.deltas_enabled = true
71
+ ThinkingSphinx.updates_enabled = true
72
+ ThinkingSphinx.stub!(:sphinx_running? => true)
73
+ Person.delta_objects.first.stub!(:` => "", :toggled => true)
74
+
75
+ @person = Person.new
76
+ Person.stub!(:search_for_id => false)
77
+ @person.stub!(:sphinx_document_id => 1)
78
+
79
+ @client = Riddle::Client.new
80
+ @client.stub!(:update => true)
81
+ ThinkingSphinx::Configuration.instance.stub!(:client => @client)
82
+ end
83
+
84
+ it "shouldn't index if delta indexing is disabled" do
85
+ ThinkingSphinx.deltas_enabled = false
86
+ Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
87
+ @client.should_not_receive(:update)
88
+
89
+ @person.send(:index_delta)
90
+ end
91
+
92
+ it "shouldn't index if index updating is disabled" do
93
+ ThinkingSphinx.updates_enabled = false
94
+ Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
95
+
96
+ @person.send(:index_delta)
97
+ end
98
+
99
+ it "shouldn't index if the environment is 'test'" do
100
+ ThinkingSphinx.deltas_enabled = nil
101
+ ThinkingSphinx::Configuration.stub!(:environment => "test")
102
+ Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
103
+
104
+ @person.send(:index_delta)
105
+ end
106
+
107
+ it "should call indexer for the delta index" do
108
+ Person.sphinx_indexes.first.delta_object.should_receive(:`).with(
109
+ "#{ThinkingSphinx::Configuration.instance.bin_path}indexer --config \"#{ThinkingSphinx::Configuration.instance.config_file}\" --rotate person_delta"
110
+ )
111
+
112
+ @person.send(:index_delta)
113
+ end
114
+
115
+ it "should update the deleted attribute if in the core index" do
116
+ Person.stub!(:search_for_id => true)
117
+ @client.should_receive(:update)
118
+
119
+ @person.send(:index_delta)
120
+ end
121
+ end
122
+ end