|
56 | 56 | end
|
57 | 57 | create_table :namespaced_models do |t|
|
58 | 58 | t.string :name
|
| 59 | + t.integer :another_private_value |
59 | 60 | end
|
60 | 61 | create_table :uniq_users, :id => false do |t|
|
61 | 62 | t.string :name
|
@@ -181,6 +182,10 @@ def hex_changed?
|
181 | 182 | def will_save_change_to_short_name?
|
182 | 183 | false
|
183 | 184 | end
|
| 185 | + |
| 186 | + def will_save_change_to__tags? |
| 187 | + false |
| 188 | + end |
184 | 189 | end
|
185 | 190 |
|
186 | 191 | class DisabledBoolean < ActiveRecord::Base
|
@@ -216,20 +221,16 @@ def self.table_name_prefix
|
216 | 221 | class Namespaced::Model < ActiveRecord::Base
|
217 | 222 | include AlgoliaSearch
|
218 | 223 |
|
219 |
| - algoliasearch do |
| 224 | + algoliasearch :synchronous => true do |
220 | 225 | attribute :customAttr do
|
221 | 226 | 40 + another_private_value
|
222 | 227 | end
|
223 | 228 | attribute :myid do
|
224 | 229 | id
|
225 | 230 | end
|
| 231 | + searchableAttributes ['customAttr'] |
226 | 232 | tags ['static_tag1', 'static_tag2']
|
227 | 233 | end
|
228 |
| - |
229 |
| - private |
230 |
| - def another_private_value |
231 |
| - 2 |
232 |
| - end |
233 | 234 | end
|
234 | 235 |
|
235 | 236 | class UniqUser < ActiveRecord::Base
|
@@ -583,6 +584,23 @@ class SerializedObject < ActiveRecord::Base
|
583 | 584 | color.delete
|
584 | 585 | end
|
585 | 586 |
|
| 587 | + it "should detect attribute changes even in a transaction" do |
| 588 | + color = Color.new :name => "dark-blue", :short_name => "blue" |
| 589 | + color.save |
| 590 | + |
| 591 | + color.instance_variable_get("@algolia_must_reindex").should == nil |
| 592 | + Color.transaction do |
| 593 | + color.name = "red" |
| 594 | + color.save |
| 595 | + color.not_indexed = "strstr" |
| 596 | + color.save |
| 597 | + color.instance_variable_get("@algolia_must_reindex").should == true |
| 598 | + end |
| 599 | + color.instance_variable_get("@algolia_must_reindex").should == nil |
| 600 | + |
| 601 | + color.delete |
| 602 | + end |
| 603 | + |
586 | 604 | it "should detect change with algolia_dirty? method" do
|
587 | 605 | ebook = Ebook.new :name => "My life", :author => "Myself", :premium => false, :released => true
|
588 | 606 |
|
@@ -614,16 +632,36 @@ class SerializedObject < ActiveRecord::Base
|
614 | 632 | end
|
615 | 633 |
|
616 | 634 | describe 'Namespaced::Model' do
|
| 635 | + before(:all) do |
| 636 | + Namespaced::Model.index.clear_index! |
| 637 | + end |
| 638 | + |
617 | 639 | it "should have an index name without :: hierarchy" do
|
618 | 640 | Namespaced::Model.index_name.should == "Namespaced_Model"
|
619 | 641 | end
|
620 | 642 |
|
621 | 643 | it "should use the block to determine attribute's value" do
|
622 |
| - m = Namespaced::Model.new |
| 644 | + m = Namespaced::Model.new(another_private_value: 2) |
623 | 645 | attributes = Namespaced::Model.algoliasearch_settings.get_attributes(m)
|
624 | 646 | attributes['customAttr'].should == 42
|
625 | 647 | attributes['myid'].should == m.id
|
626 | 648 | end
|
| 649 | + |
| 650 | + it "should always update when there is no custom _changed? function" do |
| 651 | + m = Namespaced::Model.create!(another_private_value: 2) |
| 652 | + results = Namespaced::Model.search(42) |
| 653 | + expect(results.size).to eq(1) |
| 654 | + expect(results[0].id).to eq(m.id) |
| 655 | + |
| 656 | + m.update!(another_private_value: 5) |
| 657 | + |
| 658 | + results = Namespaced::Model.search(42) |
| 659 | + expect(results.size).to eq(0) |
| 660 | + |
| 661 | + results = Namespaced::Model.search(45) |
| 662 | + expect(results.size).to eq(1) |
| 663 | + expect(results[0].id).to eq(m.id) |
| 664 | + end |
627 | 665 | end
|
628 | 666 |
|
629 | 667 | describe 'UniqUsers' do
|
|
0 commit comments