-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor spec, finish specs for active_record
- Loading branch information
Showing
13 changed files
with
144 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
spec/internal/app/models/post.rb → spec/internal/app/models/model_with_disk.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# coding: utf-8 | ||
class ModelWithDiskRubrics < ActiveRecord::Base | ||
belongs_to :model_with_disk | ||
belongs_to :rubrics | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# coding: utf-8 | ||
class ModelWithRt < ActiveRecord::Base | ||
has_many :model_with_rt_rubrics | ||
has_many :rubrics, :through => :model_with_rt_rubrics | ||
|
||
define_index('model_with_rt') do | ||
indexes 'name', :as => :name | ||
has 'region_id', :type => :integer, :as => :region_id | ||
has :rubrics, :type => :multi, :source => :ranged_query, :query => "SELECT {{model_with_rt_id}} AS id, rubric_id AS rubrics FROM model_with_rt_rubrics WHERE id>=$start AND id<=$end; SELECT MIN(id), MAX(id) FROM model_with_rt_rubrics" | ||
set_property :rt => true | ||
end | ||
|
||
def mva_sphinx_attributes_for_rubrics | ||
model_with_rt_rubrics.map(&:rubric_id) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# coding: utf-8 | ||
class ModelWithSecondDisk < ActiveRecord::Base | ||
|
||
define_index('model_with_second_disk') do | ||
indexes 'content', :as => :content | ||
has 'region_id', :type => :integer, :as => :region_id | ||
end | ||
|
||
define_secondary_index('model_with_second_disk_delta') do | ||
indexes 'content', :as => :content | ||
has 'region_id', :type => :integer, :as => :region_id | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# coding: utf-8 | ||
class Rubric < ActiveRecord::Base | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
ActiveRecord::Schema.define do | ||
create_table(:posts, :force => true) do |t| | ||
create_table(:model_with_disks, :force => true) do |t| | ||
t.string :content | ||
t.integer :region_id | ||
t.timestamps | ||
end | ||
|
||
create_table(:model_with_second_disks, :force => true) do |t| | ||
t.string :content | ||
t.integer :region_id | ||
t.timestamps | ||
end | ||
|
||
create_table(:model_with_rts, :force => true) do |t| | ||
t.string :content | ||
t.integer :region_id | ||
t.timestamps | ||
end | ||
|
||
create_table(:model_with_rt_rubrics, :force => true) do |t| | ||
t.string :model_with_rt_id | ||
t.integer :rubric_id | ||
t.timestamps | ||
end | ||
|
||
create_table(:rubrics, :force => true) do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
# coding: utf-8 | ||
require 'spec_helper' | ||
|
||
describe 'ActiveRecord::Base extensions' do | ||
describe 'ActiveRecord::Base extension' do | ||
|
||
before(:all){ ThinkingSphinx.context.define_indexes } | ||
|
||
describe '.max_matches' do | ||
subject { Post.max_matches } | ||
subject { ActiveRecord::Base.max_matches } | ||
it { should be_a(Integer) } | ||
it { should eq 5000 } | ||
end | ||
|
||
describe '.define_secondary_index' do | ||
|
||
subject { ModelWithSecondDisk.sphinx_indexes.detect{ |x| x.name == 'model_with_second_disk_delta' } } | ||
it { should_not be_nil } | ||
its(:merged_with_core) { should be_true } | ||
end | ||
|
||
describe '.reset_indexes' do | ||
before { ModelWithDisk.reset_indexes } | ||
after { ModelWithDisk.define_indexes } | ||
|
||
subject { ModelWithDisk } | ||
its(:sphinx_index_blocks) { should be_empty } | ||
its(:sphinx_indexes) { should be_empty } | ||
its(:sphinx_facets) { should be_empty } | ||
its(:defined_indexes?) { should be_false } | ||
end | ||
|
||
describe '.rt_indexed_by_sphinx?' do | ||
it { ModelWithRt.rt_indexed_by_sphinx?.should be_true } | ||
end | ||
|
||
describe '.methods_for_mva_attributes' do | ||
it { ModelWithRt.methods_for_mva_attributes.should eq [:mva_sphinx_attributes_for_rubrics] } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters