Skip to content

Instantly share code, notes, and snippets.

@gudata
Created July 18, 2010 13:51
Show Gist options
  • Save gudata/480408 to your computer and use it in GitHub Desktop.
Save gudata/480408 to your computer and use it in GitHub Desktop.
require 'spec_helper'
require "machinist/mongoid"
describe Mongo do
context "Working with Buy" do
before(:each) do
@buy = Buy.make
@apartment = PropertyType.make(:apartment)
@office = PropertyType.make(:office)
@search_criteria_apartment = SearchCriteria.new(:property_type_id => @apartment.id)
@search_criteria_office = SearchCriteria.new(:property_type_id => @office.id)
end
it "should be able to delete all the elements" do
@buy.search_criterias.should be_empty
@buy.search_criterias << @search_criteria_apartment
@buy.search_criterias << @search_criteria_office
@buy.save
founded = Buy.find(@buy.id)
founded.search_criterias.should have(2).documents
t1 = Term.new(:name => "1", :position => 1, :tag => "price", :value => 1)
@search_criteria_office.terms << t1
@search_criteria_office.save
seach_criteria = Buy.find(@buy.id).search_criterias.find(@search_criteria_office.id)
seach_criteria.terms.should have(1).terms
t2 = Term.new(:name => "2", :position => 3, :tag => "area", :value => 31)
@search_criteria_office.terms << [t2]
@search_criteria_office.save
seach_criteria = Buy.find(@buy.id).search_criterias.find(@search_criteria_office.id)
seach_criteria.terms.should have(2).terms
@search_criteria_office.terms.delete_all
@search_criteria_office.terms = []
@search_criteria_office.save
seach_criteria = Buy.find(@buy.id).search_criterias.find(@search_criteria_office.id)
ap seach_criteria.terms
seach_criteria.terms.should have(0).terms
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment