Hi Chris
How are your tests setup? Is this an integration test? A cucumber scenario? And
have you read:
http://freelancing-god.github.com/ts/en/testing.html
Also: deltas are disabled by default in the test environment - so you'll need
to explicitly turn them on - and you'll probably want standard updates, and to
hide the delta output (once you have it working, anyway):
ThinkingSphinx.deltas_enabled = true
ThinkingSphinx.updates_enabled = true
ThinkingSphinx.suppress_delta_output = true
Additionally - you're using strings in a few places in your index definition
where you shouldn't:
indexes submissions.group_id, :as => :submission_group_id
has user_id, created_at
has submissions.group_id, :as => :group_id
Best to use symbols for aliases (that's what TS expects) - and use associations
normally, otherwise you're introducing SQL snippets. Which works, but TS can't
make as many assumptions. Also, if you're using the normal associations and
columns, then TS can figure out the type itself :)
Cheers
--
Pat
On 29/10/2010, at 3:54 PM, chris wrote:
> It seems that if I manually reindex the table `system("rake ts:rebuild
> RAILS_ENV=test")` the tests then pass.
>
> Is there something that I am missing that is preventing the auto-
> reindexing in test mode? (all works in development when running
> through the browser)
>
>
>
> On Oct 28, 6:21 pm, chris <[email protected]> wrote:
>> I am working on an app that allow posts to be made. On the front end
>> the user has the ability to select groups they wish to post to which
>> are then added to a hidden field in the form.
>>
>> After the post model is filled with the form data and saved the
>> post_observer class then looks up the groups that the user selected
>> and inserts them, along with the post id into a submissions table to
>> tie the group and post together.
>>
>> I need to be able to look up the post by group and to do that I have
>> group:
>> ===
>> class Post
>> ...
>> define_index do
>> ...
>> indexes submissions.group_id, :as => "submission_group_id"
>> has :user_id, :created_at
>> has "submissions.group_id", :type => :integer, :as => "group_id"
>> set_property :delta => true
>> end
>> end
>>
>> class PostObserver < ActiveRecord::Observer
>> def after_save(post)
>> Submission.create(...) if requires_save? # prevent a never-
>> ending recursive call
>> end
>> end
>>
>> def Submission
>> after_save :set_post_delta_flag
>> ...
>> def set_post_delta_flag
>> post.delta = true
>> post.save!
>> end
>> end
>>
>> The method flow seems to be all good, but the tests are failing. I
>> have two sets of tests one that looks up my the Post.user_id attribute
>> which passes, it is just the tests that look up via the
>> submissions.group_id that fail, the Post method of which is shown
>> below.
>>
>> def self.find_for_group(group_id, filter, page=1)
>> Post.search filter, :with => {:group_id => group_id}, :match_mode
>> => :any, :page => page, :per_page => 10
>> end
>>
>> So it seems that the problem is either the association is not made
>> properly, or things are not being rebuilt property after saving the
>> submission.
>>
>> Thanks for any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en.